<?php
/************************************************************************
- * MXChange v0.2.1 Start: 07/24/2004 *
- * ================ Last change: 07/31/2004 *
+ * Mailer v0.2.1-FINAL Start: 07/24/2004 *
+ * =================== Last change: 07/31/2004 *
* *
* -------------------------------------------------------------------- *
* File : what-holiday.php *
* -------------------------------------------------------------------- *
* Kurzbeschreibung : Urlaubsschaltungen *
* -------------------------------------------------------------------- *
- * *
+ * $Revision:: $ *
+ * $Date:: $ *
+ * $Tag:: 0.2.1-FINAL $ *
+ * $Author:: $ *
+ * Needs to be in all Files and every File needs "svn propset *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
// Some security stuff...
if (!defined('__SECURITY')) {
- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
- require($INC);
-} elseif (!IS_MEMBER()) {
- LOAD_URL("modules.php?module=index");
-} elseif ((!EXT_IS_ACTIVE("holiday")) && (!IS_ADMIN())) {
- ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "holiday");
- return;
+ die();
+} elseif (!isMember()) {
+ redirectToIndexMemberOnlyModule();
}
// Add description as navigation point
-ADD_DESCR("member", basename(__FILE__));
+addMenuDescription('member', __FILE__);
+
+if ((!isExtensionActive('holiday')) && (!isAdmin())) {
+ loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('holiday'));
+ return;
+} // END - if
+
+// Init content array
+$content = array();
// Check for running mail orders in pool
-$result1 = SQL_QUERY_ESC("SELECT timestamp FROM "._MYSQL_PREFIX."_pool
-WHERE sender=%s ORDER BY timestamp DESC LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__);
+$result1 = SQL_QUERY_ESC("SELECT
+ `timestamp`
+FROM
+ `{?_MYSQL_PREFIX?}_pool`
+WHERE
+ `sender`=%s
+ORDER BY
+ `timestamp` DESC
+LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
// Check for sent mail orders in stats
-$result2 = SQL_QUERY_ESC("SELECT timestamp_ordered FROM "._MYSQL_PREFIX."_user_stats
-WHERE userid=%s ORDER BY timestamp_ordered DESC LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__);
-
-if ((SQL_NUMROWS($result1) == 1) || (SQL_NUMROWS($result2) == 1))
-{
+$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!
- list($stamp1) = SQL_FETCHROW($result1);
- list($stamp2) = SQL_FETCHROW($result2);
- if (empty($stamp1)) $stamp1 = 0;
- if (empty($stamp2)) $stamp2 = 0;
+ $content = merge_array($content, SQL_FETCHARRAY($result1));
+ $content = merge_array($content, SQL_FETCHARRAY($result2));
- if ((($stamp1 + $_CONFIG['holiday_lock']) > time()) || (($stamp2 + $_CONFIG['holiday_lock']) > time()))
- {
+ // 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 + $_CONFIG['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);
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('HOLIDAY_MEMBER_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 > (ONE_DAY * $_CONFIG['holiday_max'])) || ($START < time()) || ($END < time()))
- {
+ $TEST = $content['holiday_end'] - $START;
+ if (($TEST < 0) || ($TEST > (getConfig('ONE_DAY') * 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
- $result = 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
- $result = 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'] = secureString(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(), getMessage('HOLIDAY_MEMBER_SUBJECT'), $message);
// Send mail to all admins
- SEND_ADMIN_NOTIFICATION(HOLIDAY_ADMIN_SUBJECT, "admin_holiday_request", $_POST['comments'], $GLOBALS['userid']);
+ sendAdminNotification(getMessage('HOLIDAY_ADMIN_SUBJECT'), 'admin_holiday_request', $content, getMemberId());
// Create task
- $result = 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, addslashes($msg)), __FILE__, __LINE__);
+ createNewTask('{--HOLIDAY_ADMIN_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getMemberId());
// Display message
- LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_IS_ACTIVATED_NOW);
+ loadTemplate('admin_settings_saved', false, getMessage('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);
+ $result = SQL_QUERY_ESC("SELECT
+ `holiday_active`, `holiday_activated`
+FROM
+ `{?_MYSQL_PREFIX?}_user_data`
+WHERE
+ `userid`=%s
+LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
+ $content = merge_array($content, SQL_FETCHARRAY($result));
SQL_FREERESULT($result);
- if (($active == "Y") && (($locked + $_CONFIG['holiday_lock']) < time()))
- {
+ if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + 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)
- {
+ $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
- list($start, $end) = SQL_FETCHROW($result);
+ $content = merge_array($content, SQL_FETCHARRAY($result));
SQL_FREERESULT($result);
// Prepare it for the template
- define('__HOLIDAY_START', MAKE_DATETIME($start, "3"));
- define('__HOLIDAY_END' , MAKE_DATETIME($end , "3"));
+ $content['start'] = generateDateTime($content['holiday_start'], 3);
+ $content['end'] = generateDateTime($content['holiday_end'] , 3);
// Deactivate it now
- $result = 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__);
+ 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
- $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_holidays
-WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__);
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
+ `{?_MYSQL_PREFIX?}_user_holidays`
+WHERE
+ `userid`=%s
+LIMIT 1",
+ array(getMemberId()), __FILE__, __LINE__);
// Send email to admin
- SEND_ADMIN_NOTIFICATION(HOLIDAY_ADMIN_DEAC_SUBJ, "admin_holiday_deactivated", "", $GLOBALS['userid']);
+ sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', $content, getMemberId());
// Display message to user
- LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_DEACTIVATED_NOW);
- }
- else
- {
+ loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
+ } else {
// Display message to user
- LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_CANNOT_DEACTIVATE);
+ loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
}
- }
- elseif ($active == "Y")
- {
+ } elseif ($content['holiday_active'] == 'Y') {
// To fast!
- LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_LOCKED);
+ loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
}
-}
+} // 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 + $_CONFIG['holiday_lock']) < time())
- {
+ if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) {
// User can deactivate his holiday request
- switch ($active)
+ 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($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"));
- 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
- $result = 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() + ONE_DAY)), "start"));
- define('_START_MONTH', ADD_SELECTION("month", date("m", (time() + ONE_DAY)), "start"));
- define('_START_YEAR' , ADD_SELECTION("year" , date('Y', (time() + ONE_DAY)), "start"));
-
- // Calcualte ending date
- $D = date("d", time() + ONE_DAY + (ONE_DAY * $_CONFIG['holiday_max']));
- $M = date("m", time() + ONE_DAY + (ONE_DAY * $_CONFIG['holiday_max']));
- $Y = date('Y', time() + ONE_DAY + (ONE_DAY * $_CONFIG['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', $_CONFIG['holiday_max']);
-
- // Output form
- LOAD_TEMPLATE("member_holiday_form");
- break;
+ 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
+ $content = merge_array($content, SQL_FETCHARRAY($result));
+ SQL_FREERESULT($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;
+ }
+ break;
+
+ case 'N': // Display activation form
+ // Starting day
+ $content['start_day'] = addSelectionBox('day' , date('d', (time() + getConfig('ONE_DAY'))), 'start');
+ $content['start_month'] = addSelectionBox('month', date('m', (time() + getConfig('ONE_DAY'))), 'start');
+ $content['start_year'] = addSelectionBox('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
+ $content['end_day'] = addSelectionBox('day' , $D, 'end');
+ $content['end_month'] = addSelectionBox('month', $M, 'end');
+ $content['end_year'] = addSelectionBox('year' , $Y, 'end');
+
+ // Output form
+ loadTemplate('member_holiday_form', false, $content);
+ break;
}
- }
- else
- {
+ } else {
// To fast!
- LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_MEMBER_LOCKED);
+ loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
}
-}
-//
+} // END - if
+
+// [EOF]
?>