X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-holiday.php;h=2583ca37a076e2b4d593864581626f1ae536462c;hp=3f3c29223d518141df2ab51b9b6261a316b07326;hb=330dbb3e2b34450cd1665497506455e195a0a166;hpb=77cdaff2afb97ed32985ced906a3a95ee078c2ef diff --git a/inc/modules/member/what-holiday.php b/inc/modules/member/what-holiday.php index 3f3c29223d..2583ca37a0 100644 --- a/inc/modules/member/what-holiday.php +++ b/inc/modules/member/what-holiday.php @@ -1,7 +1,7 @@ time()) || (($stamp2 + getConfig('holiday_lock')) > time())) - { +$result2 = SQL_QUERY_ESC("SELECT + `timestamp_ordered` +FROM + `{?_MYSQL_PREFIX?}_user_stats` +WHERE + `userid`=%s +ORDER BY + `timestamp_ordered` DESC +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); + +if ((SQL_NUMROWS($result1) == 1) || (SQL_NUMROWS($result2) == 1)) { + // Mail order found + $content = merge_array($content, SQL_FETCHARRAY($result1)); + $content = merge_array($content, SQL_FETCHARRAY($result2)); + + // Fix missing entries + if (empty($content['timestamp'])) $content['timestamp'] = '0'; + if (empty($content['timestamp_ordered'])) $content['timestamp_ordered'] = '0'; + + if ((($content['timestamp'] + getConfig('holiday_lock')) > time()) || (($content['timestamp_ordered'] + getConfig('holiday_lock')) > time())) { // Mail order is to close away! - unset($_POST['ok']); - unset($_POST['stop']); + unsetPostRequestParameter('ok'); + unsetPostRequestParameter('stop'); - if (($stamp1 + getConfig('holiday_lock')) > time()) - { + if (($content['timestamp'] + getConfig('holiday_lock')) > time()) { // Mail found in pool - $stamp = $stamp1; - } - else - { + $stamp = $content['timestamp']; + } else { // Mail found in stats - $stamp = $stamp2; + $stamp = $content['timestamp_ordered']; } // Display message and exit here - LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_ORDER_1.MAKE_DATETIME($stamp, "1").HOLIDAY_MEMBER_ORDER_2); + displayMessage('{%message,MEMBER_HOLIDAY_ORDER', generateDateTime($stamp, '1') . '%}'); return; } -} +} // END - if // Free memory SQL_FREERESULT($result1); SQL_FREERESULT($result2); -if (isset($_POST['ok'])) -{ +if (isFormSent()) { // Check holiday request... - $START = mktime(0, 0, 0, $_POST['start_month'], $_POST['start_day'], $_POST['start_year']); - $END = mktime(0, 0, 0, $_POST['end_month'] , $_POST['end_day'] , $_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 = $END - $START; - if (($TEST < 0) || ($TEST > (getConfig('one_day') * getConfig('holiday_max'))) || ($START < time()) || ($END < time())) - { + $TEST = $content['holiday_end'] - $START; + if (($TEST < 0) || ($TEST > (getOneDay() * getConfig('holiday_max'))) || ($START < time()) || ($content['holiday_end'] < time())) { // Time test failed - unset($_POST['ok']); - } - else - { + 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($GLOBALS['userid'], $START, $END, $_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` -SET holiday_active='N', holiday_activated=UNIX_TIMESTAMP() -WHERE userid=%s LIMIT 1", - array($GLOBALS['userid']), __FILE__, __LINE__); + SQL_QUERY_ESC("UPDATE + `{?_MYSQL_PREFIX?}_user_data` +SET + `holiday_active`='N', `holiday_activated`=UNIX_TIMESTAMP() +WHERE + `userid`=%s +LIMIT 1", + array(getMemberId()), __FILE__, __LINE__); // Prepare constants - define('_START_DAY' , $_POST['start_day']); - define('_START_MONTH', $MONTH_DESCR[$_POST['start_month']]); - define('_START_YEAR' , $_POST['start_year']); - define('_END_DAY' , $_POST['end_day']); - define('_END_MONTH' , $MONTH_DESCR[$_POST['end_month']]); - define('_END_YEAR' , $_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 - $msg = LOAD_EMAIL_TEMPLATE("member_holiday_request", $_POST['comments'], $GLOBALS['userid']); - SEND_EMAIL($GLOBALS['userid'], HOLIDAY_MEMBER_SUBJECT, $msg); + $message = loadEmailTemplate('member_holiday_request', $content, getMemberId()); + sendEmail(getMemberId(), '{--MEMBER_HOLIDAY_SUBJECT--}', $message); // Send mail to all admins - SEND_ADMIN_NOTIFICATION(HOLIDAY_ADMIN_SUBJECT, "admin_holiday_request", $_POST['comments'], $GLOBALS['userid']); + sendAdminNotification('{--ADMIN_HOLIDAY_SUBJECT--}', 'admin_holiday_request', $content, getMemberId()); - // Create task - SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (userid, assigned_admin, status, task_type, subject, text, task_created) VALUES ('%s','0','NEW','HOLIDAY_REQUEST','%s','%s', UNIX_TIMESTAMP())", - array($GLOBALS['userid'], HOLIDAY_ADMIN_SUBJECT, $msg), __FILE__, __LINE__); + // Create task (we ignore the task id here) + createNewTask('{--ADMIN_HOLIDAY_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getMemberId()); // Display message - LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_IS_ACTIVATED_NOW); + displayMessage('{--MEMBER_HOLIDAY_IS_ACTIVATED_NOW--}'); } -} +} // END - if // Holiday shall be ended now -if (isset($_POST['stop'])) -{ +if (isPostRequestParameterSet('stop')) { // Okay, end the holiday here... - $result = SQL_QUERY_ESC("SELECT holiday_active, holiday_activated FROM `{!_MYSQL_PREFIX!}_user_data` -WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__); - list($active, $locked) = SQL_FETCHROW($result); - SQL_FREERESULT($result); + $result = SQL_QUERY_ESC("SELECT + `holiday_active`, `holiday_activated` +FROM + `{?_MYSQL_PREFIX?}_user_data` +WHERE + `userid`=%s +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); + + // 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` +WHERE + `userid`=%s +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); + if (SQL_NUMROWS($result2) == 1) { + // Data was found so merge it + $content = merge_array($content, SQL_FETCHARRAY($result2)); - if (($active == "Y") && (($locked + getConfig('holiday_lock')) < time())) - { - // Load data - $result = SQL_QUERY_ESC("SELECT holiday_start, holiday_end FROM `{!_MYSQL_PREFIX!}_user_holidays` -WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__); - if (SQL_NUMROWS($result) == 1) - { - // Data was found - list($start, $end) = SQL_FETCHROW($result); - SQL_FREERESULT($result); - - // Prepare it for the template - define('__HOLIDAY_START', MAKE_DATETIME($start, "3")); - define('__HOLIDAY_END' , MAKE_DATETIME($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($GLOBALS['userid']), __FILE__, __LINE__); - - // Remove entry - SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_holidays` -WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__); - - // Send email to admin - SEND_ADMIN_NOTIFICATION(HOLIDAY_ADMIN_DEAC_SUBJ, "admin_holiday_deactivated", array(), $GLOBALS['userid']); - - // Display message to user - LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_DEACTIVATED_NOW); - } - else - { - // Display message to user - LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_CANNOT_DEACTIVATE); + // 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(getMemberId()), __FILE__, __LINE__); + + // Remove entry + SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM + `{?_MYSQL_PREFIX?}_user_holidays` +WHERE + `userid`=%s +LIMIT 1", + array(getMemberId()), __FILE__, __LINE__); + + // Send email to admin + sendAdminNotification('{--ADMIN_HOLIDAY_DEAC_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--}'); } + } else { + // User not found + displayMessage('{--MEMBER_HOLIDAY_NOT_STOPPED_404--}'); } - elseif ($active == "Y") - { - // To fast! - LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_LOCKED); - } -} + + // Free result + SQL_FREERESULT($result); +} // END - if // If something is wrong or link in menu is just clicked display form -if ((!isset($_POST['ok'])) && (!isset($_POST['stop']))) -{ +if ((!isFormSent()) && (!isPostRequestParameterSet('stop'))) { // Check if user is in holiday... - $result = SQL_QUERY_ESC("SELECT holiday_active, holiday_activated FROM `{!_MYSQL_PREFIX!}_user_data` -WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__); - list($active, $locked) = SQL_FETCHROW($result); + $result = SQL_QUERY_ESC("SELECT + `holiday_active`, `holiday_activated` +FROM + `{?_MYSQL_PREFIX?}_user_data` +WHERE + `userid`=%s +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); + $content = SQL_FETCHARRAY($result); SQL_FREERESULT($result); // Check for lock - if (($locked + getConfig('holiday_lock')) < time()) - { + if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) { // User can deactivate his holiday request - switch ($active) - { - case "Y": // Display deactivation form - // Load starting and ending date - $result = SQL_QUERY_ESC("SELECT holiday_start, holiday_end FROM `{!_MYSQL_PREFIX!}_user_holidays` -WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__); - if (SQL_NUMROWS($result) == 1) - { - // Data was found - list($start, $end) = SQL_FETCHROW($result); + switch ($content['holiday_active']) { + case 'Y': // Display deactivation form + // Load starting and ending date + $result = SQL_QUERY_ESC("SELECT + `holiday_start`, `holiday_end` +FROM + `{?_MYSQL_PREFIX?}_user_holidays` +WHERE + `userid`=%s +LIMIT 1", array(getMemberId()), __FILE__, __LINE__); + if (SQL_NUMROWS($result) == 1) { + // Data was found so merge it + $content = merge_array($content, SQL_FETCHARRAY($result)); + + // Prepare it for the template + $content['start'] = generateDateTime($content['holiday_start'] , 3); + $content['end'] = generateDateTime($content['holiday_end'] , 3); + $content['lock'] = generateDateTime($content['holiday_activated'], 1); + + // Load template + 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` +SET + `holiday_active`='N' +WHERE + `userid`=%s +LIMIT 1", + array(getMemberId()), __FILE__, __LINE__); + redirectToUrl('modules.php?module=login&what=holiday'); + return; + } + + // Free result SQL_FREERESULT($result); - - // Prepare it for the template - define('__HOLIDAY_START', MAKE_DATETIME($start , "3")); - define('__HOLIDAY_END' , MAKE_DATETIME($end , "3")); - define('__HOLIDAY_LOCK' , MAKE_DATETIME($locked, "1")); - - // Load template - LOAD_TEMPLATE("member_holiday_deactivate"); - } - else - { - // Free memory - SQL_FREERESULT($result); - - // Remove entry and reload URL - SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` -SET holiday_active='N' -WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__); - LOAD_URL("modules.php?module=login&what=holiday"); - return; - } - 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")); - - // 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'))); - - // 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')); - - // Output form - LOAD_TEMPLATE("member_holiday_form"); - break; - } - } - else - { + break; + + case 'N': // Display activation form + // Cache timestamps + $startingStamp = time() + getOneDay(); + $endingStamp = $startingStamp + (getOneDay() * 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 + $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 + loadTemplate('member_holiday_form', false, $content); + break; + } // END - switch + } else { // To fast! - LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_LOCKED); + displayMessage('{--MEMBER_HOLIDAY_LOCKED--}'); } -} -// +} // END - if + +// [EOF] ?>