X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-holiday.php;h=dd7c7a5731a09efe7ce123892af608a53e89301f;hb=ae2999848b6868bea711760789614c341c8cced3;hp=11f17185ff880fc79bb6666a71077a1ecc989b1b;hpb=d1637dad0b2ca0e5fb411ee0843f01bfb4cc94e0;p=mailer.git diff --git a/inc/modules/member/what-holiday.php b/inc/modules/member/what-holiday.php index 11f17185ff..dd7c7a5731 100644 --- a/inc/modules/member/what-holiday.php +++ b/inc/modules/member/what-holiday.php @@ -1,7 +1,7 @@ time()) || (($content['timestamp_ordered'] + getConfig('holiday_lock')) > time())) { // Mail order is to close away! - REQUEST_UNSET_POST('ok'); - REQUEST_UNSET_POST('stop'); + unsetPostRequestParameter('ok'); + unsetPostRequestParameter('stop'); if (($content['timestamp'] + getConfig('holiday_lock')) > time()) { // Mail found in pool @@ -98,7 +98,7 @@ if ((SQL_NUMROWS($result1) == 1) || (SQL_NUMROWS($result2) == 1)) { } // Display message and exit here - LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('HOLIDAY_MEMBER_ORDER'), generateDateTime($stamp, '1'))); + displayMessage('{%message,MEMBER_HOLIDAY_ORDER', generateDateTime($stamp, '1') . '%}'); return; } } // END - if @@ -109,196 +109,209 @@ SQL_FREERESULT($result2); if (isFormSent()) { // Check holiday request... - $START = mktime(0, 0, 0, REQUEST_POST('start_month'), REQUEST_POST('start_day'), REQUEST_POST('start_year')); - $content['holiday_end'] = mktime(0, 0, 0, REQUEST_POST('end_month') , REQUEST_POST('end_day') , REQUEST_POST('end_year') ); + $START = mktime(0, 0, 0, postRequestParameter('start_month'), postRequestParameter('start_day'), postRequestParameter('start_year')); + $content['holiday_end'] = mktime(0, 0, 0, postRequestParameter('end_month') , postRequestParameter('end_day') , postRequestParameter('end_year') ); // Test both values $TEST = $content['holiday_end'] - $START; - if (($TEST < 0) || ($TEST > (getConfig('one_day') * getConfig('holiday_max'))) || ($START < time()) || ($content['holiday_end'] < time())) { + if (($TEST < 0) || ($TEST > (getOneDay() * getConfig('holiday_max'))) || ($START < time()) || ($content['holiday_end'] < time())) { // Time test failed - REQUEST_UNSET_POST('ok'); + unsetPostRequestParameter('ok'); } else { // Everything went okay so let's store his request and send mails - SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_holidays` (`userid`, `holiday_start`, `holiday_end`, `comments`) VALUES ('%s','%s','%s','%s')", - array(getUserId(), $START, $content['holiday_end'], REQUEST_POST('comments')), __FILE__, __LINE__); + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_holidays` (`userid`,`holiday_start`,`holiday_end`,`comments`) VALUES ('%s','%s','%s','%s')", + array(getMemberId(), $START, $content['holiday_end'], postRequestParameter('comments')), __FILE__, __LINE__); // Activate holiday system SQL_QUERY_ESC("UPDATE - `{!_MYSQL_PREFIX!}_user_data` + `{?_MYSQL_PREFIX?}_user_data` SET `holiday_active`='N', `holiday_activated`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1", - array(getUserId()), __FILE__, __LINE__); + array(getMemberId()), __FILE__, __LINE__); // Prepare constants - define('_START_DAY' , REQUEST_POST('start_day')); - define('_START_MONTH', $GLOBALS['month_descr'][REQUEST_POST('start_month')]); - define('_START_YEAR' , REQUEST_POST('start_year')); - define('_END_DAY' , REQUEST_POST('end_day')); - define('_END_MONTH' , $GLOBALS['month_descr'][REQUEST_POST('end_month')]); - define('_END_YEAR' , REQUEST_POST('end_year')); + $content['start_day'] = bigintval(postRequestParameter('start_day')); + $content['start_month'] = $GLOBALS['month_descr'][postRequestParameter('start_month')]; + $content['start_year'] = bigintval(postRequestParameter('start_year')); + $content['end_day'] = bigintval(postRequestParameter('end_day')); + $content['end_month'] = $GLOBALS['month_descr'][postRequestParameter('end_month')]; + $content['end_year'] = bigintval(postRequestParameter('end_year')); + $content['comments'] = postRequestParameter('comments'); // Send mail to member - $message = LOAD_EMAIL_TEMPLATE('member_holiday_request', REQUEST_POST('comments'), getUserId()); - sendEmail(getUserId(), getMessage('HOLIDAY_MEMBER_SUBJECT'), $message); + $message = loadEmailTemplate('member_holiday_request', $content, getMemberId()); + sendEmail(getMemberId(), '{--MEMBER_HOLIDAY_SUBJECT--}', $message); // Send mail to all admins - sendAdminNotification(getMessage('HOLIDAY_ADMIN_SUBJECT'), 'admin_holiday_request', REQUEST_POST('comments'), getUserId()); + sendAdminNotification('{--ADMIN_HOLIDAY_SUBJECT--}', 'admin_holiday_request', $content, getMemberId()); - // Create task - createNewTask('{--HOLIDAY_ADMIN_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getUserId()); + // Create task (we ignore the task id here) + createNewTask('{--ADMIN_HOLIDAY_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getMemberId()); // Display message - LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_IS_ACTIVATED_NOW')); + displayMessage('{--MEMBER_HOLIDAY_IS_ACTIVATED_NOW--}'); } } // END - if // Holiday shall be ended now -if (REQUEST_ISSET_POST('stop')) { +if (isPostRequestParameterSet('stop')) { // Okay, end the holiday here... $result = SQL_QUERY_ESC("SELECT - `holiday_active`, `holiday_activated` + `holiday_active`,`holiday_activated` FROM - `{!_MYSQL_PREFIX!}_user_data` + `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s -LIMIT 1", array(getUserId()), __FILE__, __LINE__); - $content = merge_array($content, SQL_FETCHARRAY($result)); - SQL_FREERESULT($result); +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); - if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) { - // Load data - $result = SQL_QUERY_ESC("SELECT - `holiday_start`, `holiday_end` + // Do we have an entry? + if (SQL_NUMROWS($result) == 1) { + // Merge arrays + $content = merge_array($content, SQL_FETCHARRAY($result)); + + if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) { + // Load data + $result2 = SQL_QUERY_ESC("SELECT + `holiday_start`,`holiday_end` FROM - `{!_MYSQL_PREFIX!}_user_holidays` + `{?_MYSQL_PREFIX?}_user_holidays` WHERE `userid`=%s -LIMIT 1", array(getUserId()), __FILE__, __LINE__); - if (SQL_NUMROWS($result) == 1) { - // Data was found - $content = merge_array($content, SQL_FETCHARRAY($result)); - SQL_FREERESULT($result); - - // Prepare it for the template - define('__HOLIDAY_START', generateDateTime($content['holiday_start'], '3')); - define('__HOLIDAY_END' , generateDateTime($content['holiday_end'] , '3')); - - // Deactivate it now - SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); + if (SQL_NUMROWS($result2) == 1) { + // Data was found so merge it + $content = merge_array($content, SQL_FETCHARRAY($result2)); + + // Prepare it for the template + $content['start'] = generateDateTime($content['holiday_start'], 3); + $content['end'] = generateDateTime($content['holiday_end'] , 3); + + // Deactivate it now + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `holiday_active`='N', `holiday_activated`=0 WHERE `userid`=%s -LIMIT 1", array(getUserId()), __FILE__, __LINE__); +LIMIT 1", + array(getMemberId()), __FILE__, __LINE__); - // Remove entry - SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM - `{!_MYSQL_PREFIX!}_user_holidays` + // Remove entry + SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM + `{?_MYSQL_PREFIX?}_user_holidays` WHERE `userid`=%s -LIMIT 1", array(getUserId()), __FILE__, __LINE__); - - // Send email to admin - sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', array(), getUserId()); - - // Display message to user - LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW')); - } else { - // Display message to user - LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE')); +LIMIT 1", + array(getMemberId()), __FILE__, __LINE__); + + // Send email to admin + sendAdminNotification('{--ADMIN_HOLIDAY_DEACTIVATED_SUBJECT--}', 'admin_holiday_deactivated', $content, getMemberId()); + + // Display message to user + displayMessage('{--MEMBER_HOLIDAY_DEACTIVATED_NOW--}'); + } else { + // Display message to user + displayMessage('{--MEMBER_HOLIDAY_CANNOT_DEACTIVATE--}'); + } + + // Free result + SQL_FREERESULT($result2); + } elseif ($content['holiday_active'] == 'Y') { + // To fast! + displayMessage('{--MEMBER_HOLIDAY_LOCKED--}'); } - } elseif ($content['holiday_active'] == 'Y') { - // To fast! - LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED')); + } else { + // User not found + displayMessage('{--MEMBER_HOLIDAY_NOT_STOPPED_404--}'); } + + // Free result + SQL_FREERESULT($result); } // END - if // If something is wrong or link in menu is just clicked display form -if ((!isFormSent()) && (!REQUEST_ISSET_POST('stop'))) { +if ((!isFormSent()) && (!isPostRequestParameterSet('stop'))) { // Check if user is in holiday... $result = SQL_QUERY_ESC("SELECT - `holiday_active`, `holiday_activated` + `holiday_active`,`holiday_activated` FROM - `{!_MYSQL_PREFIX!}_user_data` + `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s -LIMIT 1", array(getUserId()), __FILE__, __LINE__); +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); $content = SQL_FETCHARRAY($result); SQL_FREERESULT($result); // Check for lock if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) { // User can deactivate his holiday request - switch ($content['holiday_active']) - { + switch ($content['holiday_active']) { case 'Y': // Display deactivation form // Load starting and ending date $result = SQL_QUERY_ESC("SELECT - `holiday_start`, `holiday_end` + `holiday_start`,`holiday_end` FROM - `{!_MYSQL_PREFIX!}_user_holidays` + `{?_MYSQL_PREFIX?}_user_holidays` WHERE `userid`=%s -LIMIT 1", array(getUserId()), __FILE__, __LINE__); +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); if (SQL_NUMROWS($result) == 1) { - // Data was found + // Data was found so merge it $content = merge_array($content, SQL_FETCHARRAY($result)); - SQL_FREERESULT($result); // Prepare it for the template - define('__HOLIDAY_START', generateDateTime($content['holiday_start'] , '3')); - define('__HOLIDAY_END' , generateDateTime($content['holiday_end'] , '3')); - define('__HOLIDAY_LOCK' , generateDateTime($content['holiday_activated'], '1')); + $content['start'] = generateDateTime($content['holiday_start'] , 3); + $content['end'] = generateDateTime($content['holiday_end'] , 3); + $content['lock'] = generateDateTime($content['holiday_activated'], 1); // Load template - LOAD_TEMPLATE('member_holiday_deactivate'); + loadTemplate('member_holiday_deactivate', false, $content); } else { // Free memory SQL_FREERESULT($result); // Remove entry and reload URL SQL_QUERY_ESC("UPDATE - `{!_MYSQL_PREFIX!}_user_data` + `{?_MYSQL_PREFIX?}_user_data` SET `holiday_active`='N' WHERE `userid`=%s -LIMIT 1", array(getUserId()), __FILE__, __LINE__); +LIMIT 1", + array(getMemberId()), __FILE__, __LINE__); redirectToUrl('modules.php?module=login&what=holiday'); return; } + + // Free result + SQL_FREERESULT($result); break; case 'N': // Display activation form - // Starting day - define('_START_DAY' , ADD_SELECTION('day' , date('d', (time() + getConfig('one_day'))), 'start')); - define('_START_MONTH', ADD_SELECTION('month', date('m', (time() + getConfig('one_day'))), 'start')); - define('_START_YEAR' , ADD_SELECTION('year' , date('Y', (time() + getConfig('one_day'))), 'start')); + // Cache timestamps + $startingStamp = time() + getOneDay(); + $endingStamp = $startingStamp + (getOneDay() * getConfig('holiday_max')); - // Calcualte ending date - $D = date('d', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max'))); - $M = date('m', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max'))); - $Y = date('Y', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max'))); + // Starting day + $content['start_day'] = addSelectionBox('day' , getDay($startingStamp) , 'start'); + $content['start_month'] = addSelectionBox('month', getMonth($startingStamp), 'start'); + $content['start_year'] = addSelectionBox('year' , getYear($startingStamp) , 'start'); // Ending day - define('_END_DAY' , ADD_SELECTION('day' , $D, 'end')); - define('_END_MONTH', ADD_SELECTION('month', $M, 'end')); - define('_END_YEAR' , ADD_SELECTION('year' , $Y, 'end')); - - // Copy value from configuration - define('__HOLIDAY_MAX', getConfig('holiday_max')); + $content['end_day'] = addSelectionBox('day' , getDay($endingStamp) , 'end'); + $content['end_month'] = addSelectionBox('month', getMonth($endingStamp), 'end'); + $content['end_year'] = addSelectionBox('year' , getYear($endingStamp) , 'end'); // Output form - LOAD_TEMPLATE('member_holiday_form'); + loadTemplate('member_holiday_form', false, $content); break; - } + } // END - switch } else { // To fast! - LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED')); + displayMessage('{--MEMBER_HOLIDAY_LOCKED--}'); } } // END - if