1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-10 00:27:45 +02:00

Work on event calendar, including bringing 1.x and 2.x versions more in line

This commit is contained in:
SteveD
2013-04-11 20:48:55 +01:00
parent 9c694f2c9e
commit 327292ddc8
2 changed files with 152 additions and 113 deletions

View File

@@ -39,6 +39,11 @@ if (!defined('EC_DEFAULT_CATEGORY')) { define('EC_DEFAULT_CATEGORY','Default');
include_lan(e_PLUGIN.'calendar_menu/languages/'.e_LANGUAGE.'_class.php'); include_lan(e_PLUGIN.'calendar_menu/languages/'.e_LANGUAGE.'_class.php');
/**
* Class of useful data and functions for the event calendar plugin
* Included in all application files
*/
class ecal_class class ecal_class
{ {
public $pref; // Calendar prefs - now in a separate DB record. Use same name as legacy array to simplify change public $pref; // Calendar prefs - now in a separate DB record. Use same name as legacy array to simplify change
@@ -52,7 +57,7 @@ class ecal_class
var $cal_timedate; // Time/date stamp used by event calendar (user set) var $cal_timedate; // Time/date stamp used by event calendar (user set)
var $now_date; // Time/date array from $time_now var $now_date; // Time/date array from $time_now
var $site_date; // Time/date array from $site_timedate var $site_date; // Time/date array from $site_timedate
var $cal_date ; // Time/date array from $cal_timedate var $cal_date; // Time/date array from $cal_timedate
var $cal_super; // True if current user is a calendar supervisor var $cal_super; // True if current user is a calendar supervisor
var $extra_query; // Extra bit of mysql query used for non-supervisor (read) queries var $extra_query; // Extra bit of mysql query used for non-supervisor (read) queries
@@ -75,30 +80,31 @@ class ecal_class
public $days = array(EC_LAN_25, EC_LAN_19, EC_LAN_20, EC_LAN_21, EC_LAN_22, EC_LAN_23, EC_LAN_24); // Array Sunday..Saturday public $days = array(EC_LAN_25, EC_LAN_19, EC_LAN_20, EC_LAN_21, EC_LAN_22, EC_LAN_23, EC_LAN_24); // Array Sunday..Saturday
private $months = array(EC_LAN_0, EC_LAN_1, EC_LAN_2, EC_LAN_3, EC_LAN_4, EC_LAN_5, EC_LAN_6, private $months = array(EC_LAN_0, EC_LAN_1, EC_LAN_2, EC_LAN_3, EC_LAN_4, EC_LAN_5, EC_LAN_6,
EC_LAN_7, EC_LAN_8, EC_LAN_9, EC_LAN_10, EC_LAN_11); // 'Long' month names EC_LAN_7, EC_LAN_8, EC_LAN_9, EC_LAN_10, EC_LAN_11); // 'Long' month names
public $recur_type = array( public $recur_type = array(
'0' => EC_LAN_RECUR_00, // 'no' '0' => EC_LAN_RECUR_00, // 'no'
'1' => EC_LAN_RECUR_01, //'annual' '1' => EC_LAN_RECUR_01, //'annual'
'2' => EC_LAN_RECUR_02, //'biannual' '2' => EC_LAN_RECUR_02, //'biannual'
'3' => EC_LAN_RECUR_03, //'quarterly' '3' => EC_LAN_RECUR_03, //'quarterly'
'4' => EC_LAN_RECUR_04, //'monthly' '4' => EC_LAN_RECUR_04, //'monthly'
'5' => EC_LAN_RECUR_05, //'four weekly' '5' => EC_LAN_RECUR_05, //'four weekly'
'6' => EC_LAN_RECUR_06, //'fortnightly' '6' => EC_LAN_RECUR_06, //'fortnightly'
'7' => EC_LAN_RECUR_07, // 'weekly' '7' => EC_LAN_RECUR_07, // 'weekly'
'8' => EC_LAN_RECUR_00, // 'daily' '8' => EC_LAN_RECUR_00, // 'daily'
'100' => EC_LAN_RECUR_100, // 'Sunday in month' '100' => EC_LAN_RECUR_100, // 'Sunday in month'
'101' => EC_LAN_RECUR_101, // 'Monday in month' '101' => EC_LAN_RECUR_101, // 'Monday in month'
'102' => EC_LAN_RECUR_102, // 'Tuesday in month' '102' => EC_LAN_RECUR_102, // 'Tuesday in month'
'103' => EC_LAN_RECUR_103, // 'Wednesday in month' '103' => EC_LAN_RECUR_103, // 'Wednesday in month'
'104' => EC_LAN_RECUR_104, // 'Thursday in month' '104' => EC_LAN_RECUR_104, // 'Thursday in month'
'105' => EC_LAN_RECUR_105, // 'Friday in month' '105' => EC_LAN_RECUR_105, // 'Friday in month'
'106' => EC_LAN_RECUR_106 // 'Saturday in month' '106' => EC_LAN_RECUR_106 // 'Saturday in month'
); );
var $recur_week = array( var $recur_week = array(
'100' => EC_LAN_RECUR_1100, //'First' '100' => EC_LAN_RECUR_1100, //'First'
'200' => EC_LAN_RECUR_1200, //'Second' '200' => EC_LAN_RECUR_1200, //'Second'
'300' => EC_LAN_RECUR_1300, // 'Third' '300' => EC_LAN_RECUR_1300, // 'Third'
'400' => EC_LAN_RECUR_1400 // 'Fourth' '400' => EC_LAN_RECUR_1400 // 'Fourth'
); );
public function __construct() public function __construct()
@@ -108,7 +114,7 @@ class ecal_class
// Get all the times in terms of 'clock time' - i.e. allowing for TZ, DST, etc // Get all the times in terms of 'clock time' - i.e. allowing for TZ, DST, etc
// All the times in the DB should be 'absolute' - so if we compare with 'clock time' it should work out. // All the times in the DB should be 'absolute' - so if we compare with 'clock time' it should work out.
$this->time_now = time(); $this->time_now = $this->clockToAbs(time());
$this->site_timedate = $this->time_now + ($this->pref['time_offset'] * 3600); // Check sign of offset $this->site_timedate = $this->time_now + ($this->pref['time_offset'] * 3600); // Check sign of offset
$this->user_timedate = $this->time_now + TIMEOFFSET; $this->user_timedate = $this->time_now + TIMEOFFSET;
switch ($this->pref['eventpost_caltime']) switch ($this->pref['eventpost_caltime'])
@@ -171,6 +177,7 @@ class ecal_class
$this->date_separator = '/'; $this->date_separator = '/';
} }
} }
switch ($temp) switch ($temp)
{ // Event entry calendar { // Event entry calendar
case 2 : case 2 :
@@ -288,7 +295,7 @@ class ecal_class
switch ($this->java_format_code) switch ($this->java_format_code)
{ {
case 2 : case 2 :
return gmmktime($new_hour, $new_minute, 0, $tmp[1], $tmp[0], $tmp[2]); // dd-mm-yyyy return gmmktime($new_hour, $new_minute, 0, $tmp[1], $tmp[0], $tmp[2]); // dd-mm-yyyy
case 3 : case 3 :
return gmmktime($new_hour, $new_minute, 0, $tmp[0], $tmp[1], $tmp[2]); // mm-dd-yyyy return gmmktime($new_hour, $new_minute, 0, $tmp[0], $tmp[1], $tmp[2]); // mm-dd-yyyy
default : default :
@@ -424,18 +431,18 @@ class ecal_class
{ {
$e107 = e107::getInstance(); $e107 = e107::getInstance();
$log_titles = array( '1' => 'EC_ADM_01', $log_titles = array('1' => 'EC_ADM_01',
'2' => 'EC_ADM_02', '2' => 'EC_ADM_02',
'3' => 'EC_ADM_03', '3' => 'EC_ADM_03',
'4' => 'EC_ADM_04', '4' => 'EC_ADM_04',
'5' => 'EC_ADM_05', '5' => 'EC_ADM_05',
'6' => 'EC_ADM_06', '6' => 'EC_ADM_06',
'7' => 'EC_ADM_07', '7' => 'EC_ADM_07',
'8' => 'EC_ADM_08', '8' => 'EC_ADM_08',
'9' => 'EC_ADM_09', '9' => 'EC_ADM_09',
'10' => 'EC_ADM_10', '10' => 'EC_ADM_10',
'11' => 'EC_ADM_11' '11' => 'EC_ADM_11'
); );
// Do the notifies first // Do the notifies first
$cmessage = $log_titles[$event_type]."<br />"; $cmessage = $log_titles[$event_type]."<br />";
@@ -450,12 +457,14 @@ class ecal_class
switch ($event_type) switch ($event_type)
{ {
case 5 : case 5 :
case 1 : $e107->e_event->trigger('ecalnew', $edata_ec); case 1 :
break; $e107->e_event->trigger('ecalnew', $edata_ec);
break;
case 2 : case 2 :
case 3 : case 3 :
case 4 : $e107->e_event->trigger('ecaledit', $edata_ec); case 4 :
break; $e107->e_event->trigger('ecaledit', $edata_ec);
break;
} }
switch ($this->pref['eventpost_adminlog']) switch ($this->pref['eventpost_adminlog'])
@@ -499,27 +508,40 @@ class ecal_class
*/ */
function gmgetdate($date) function gmgetdate($date)
{ {
$value = getdate($date-date('Z')); $value = getdate($date-date('Z') + (date('I') ? 3600 : 0));
$value['month'] = $this->months[$value['mon'] - 1]; // Looks like getdate doesn't use the specified site language
$value['month'] = $this->months[$value['mon'] - 1]; // Looks like getdate doesn't use the specified site language
return $value; return $value;
} }
/**
* Turn a 'clock time' into an absolute time
*/
function clockToAbs($val)
{
$temp = getdate($val);
$temp['month'] = $this->months[$temp['mon'] - 1]; // Looks like getdate doesn't use the specified site language
return gmmktime($temp['hours'], $temp['minutes'], $temp['seconds'], $temp['mon'], $temp['mday'], $temp['year']);
}
//------------------------------------------------ //------------------------------------------------
// Recurring event handling // Recurring event handling
//------------------------------------------------ //------------------------------------------------
/** /**
* Internal utility - Generate a list of time/date based on a 'first event' date, an interval and start/finish times * Generate a list of regularly recurring events based on a 'first event' date, an interval and start/finish times
* All fields are Unix-style time/date stamps
* @param int $first_event
* @param int $last_event
* @param int $interval - interval between events (in seconds)
* @param int $start_time
* @param int $end_time - last date in time window
* *
* @return array of start date/time entries * All fields are Unix-style time/date stamps
* @param int $first_event Earliest possible date/time for first occurrence of event (may not be precisely what's required)
* @param int $last_event
* @param int $interval - interval between events (in seconds)
* @param int $start_time
* @param int $end_time - last date in time window
*
* @return array of start date/time entries
*/ */
protected function gen_recur_regular($first_event, $last_event, $interval, $start_time, $end_time) protected function gen_recur_regular($first_event, $last_event, $interval, $start_time, $end_time)
{ {
@@ -559,14 +581,22 @@ class ecal_class
/** /**
* Generate a list of recurring events based on a 'first event' date, an interval type and start/finish window * Generate a list of recurring events based on a 'first event' date, an interval type and start/finish window
* @param int $first_event - earliest date for events * Returns an array of start times
* @param int $last_event - latest time for date of event
* @param int $interval_type - numeric code defining the interval between events (N.B> day number zero is Sunday)
* @param int $start_time - start time for each event
* @param int $end_time - end time for each event
* *
* @return array of events (may be empty) * For day number, '0' = 'Sunday'
*
* $first_event, $last_event are the start/end dates from the definition of the recurring event in the DB
* $start_time, $end_time define the window currently of interest (usually a month)
*
* All parameters are Unix time stamps or numbers of seconds
* @param int $first_event - earliest date for events
* @param int $last_event - latest time for date of event
* @param int $interval_type - numeric code defining the interval between events (N.B> day number zero is Sunday)
* @param int $start_time - start time for each event
* @param int $end_time - end time for each event
*
* @return array of events (may be empty)
*/ */
public function gen_recur($first_event, $last_event, $interval_type, $start_time, $end_time) public function gen_recur($first_event, $last_event, $interval_type, $start_time, $end_time)
{ {
@@ -583,7 +613,10 @@ class ecal_class
$interval = array('5' => 28*86400, '6' => 14*86400, '7' => 7*86400, '8' => 86400); $interval = array('5' => 28*86400, '6' => 14*86400, '7' => 7*86400, '8' => 86400);
// Do the easy ones first // Do the easy ones first
if (array_key_exists($interval_type, $interval)) return $this->gen_recur_regular($first_event, $last_event, $interval[$interval_type], $start_time, $end_time); if (array_key_exists($interval_type, $interval))
{
return $this->gen_recur_regular($first_event, $last_event, $interval[$interval_type], $start_time, $end_time);
}
// We're messing around with months and years here // We're messing around with months and years here
$inc_array['year'] = 0; $inc_array['year'] = 0;
@@ -630,14 +663,14 @@ class ecal_class
// Now loop through using the increment - we may discard a few, but getting clever may be worse! // Now loop through using the increment - we may discard a few, but getting clever may be worse!
$cont = TRUE; $cont = TRUE;
do { do
{
$tstamp = gmmktime($event['hours'],$event['minutes'],$event['seconds'],$event['mon'],$event['mday'],$event['year']); $tstamp = gmmktime($event['hours'],$event['minutes'],$event['seconds'],$event['mon'],$event['mday'],$event['year']);
if ($interval_type >= 100) if ($interval_type >= 100)
{ // $tstamp has the first of the month { // $tstamp has the first of the month
$day_diff = $day_number - gmdate('w',$tstamp); $day_diff = $day_number - gmdate('w',$tstamp);
if ($day_diff <0) $day_diff += 7; if ($day_diff <0) $day_diff += 7;
$day_diff += (7 * $week_offset) - 7; $day_diff += (7 * $week_offset) - 7;
// echo "Day difference = ".$day_diff." Stamp=".$tstamp." Week day: ".$dofwk."<br />";
$tstamp += $day_diff*86400; $tstamp += $day_diff*86400;
} }
if ($tstamp >= $start_time) if ($tstamp >= $start_time)
@@ -660,7 +693,13 @@ class ecal_class
/** /**
* Generate comma separated list of fields for table, with optional alias prefix. * Generate comma separated list of fields for table, with optional alias prefix.
*
* @param string $table - optional table name/alias (prefixed to each field name if specified)
* @param string $list - comma separated list of required fields
* @param string $must_have - comma-separated list of mandatory fields - always included in the list
*
* @return string comma-separated list of fields for use in query
*/ */
function gen_field_list($table, $list, $must_have = '') function gen_field_list($table, $list, $must_have = '')
{ {
@@ -691,20 +730,20 @@ class ecal_class
/** /**
* Function to return all events between a given start and end date * Return all events between a given start and end date
* Potential option to hook in other routines here later * If $start_only is TRUE, only searches based on the start date/time
* @param int $start_time - earliest time for events * Potential option to hook in other routines here later
* @param int $end_time - latest time for start of event * @param int $start_time - earliest time for events
* @param boolean $start_only - TRUE to scan based on start time only. FALSE to select events which overlap the specified time window * @param int $end_time - latest time for start of event
* @param boolean|string $cat_filter = FALSE is 'no categories' - returns an empty array. * @param boolean $start_only - TRUE to scan based on start time only. FALSE to select events which overlap the specified time window
* @param boolean|string $cat_filter = FALSE is 'no categories' - returns an empty array.
* $cat_filter = '*' means 'all categories' * $cat_filter = '*' means 'all categories'
* otherwise $cat_filter mst be a comma-separated list of category IDs. * otherwise $cat_filter mst be a comma-separated list of category IDs.
* @param string $event_fields - comma separated list of fields to read from the event record; '*' for all fields * @param string $event_fields - comma separated list of fields to read from the event record; '*' for all fields
* @param string $cat_fields - comma separated list of fields to read from the category record; '*' for all fields * @param string $cat_fields - comma separated list of fields to read from the category record; '*' for all fields
* *
* @return array of events (may be empty) * @return array of events (may be empty)
*/ */
function get_events($start_time, $end_time, $start_only=FALSE, $cat_filter=0, $inc_recur=FALSE, $event_fields='*', $cat_fields='*') function get_events($start_time, $end_time, $start_only=FALSE, $cat_filter=0, $inc_recur=FALSE, $event_fields='*', $cat_fields='*')
{ {

View File

@@ -96,7 +96,7 @@ $ev_fields = array(
//-------------------------------------- //--------------------------------------
if ((isset($_POST['ne_insert']) || isset($_POST['ne_update'])) && ($cal_super || check_class($ecal_class->pref['eventpost_admin']))) if ((isset($_POST['ne_insert']) || isset($_POST['ne_update'])) && ($cal_super || check_class($ecal_class->pref['eventpost_admin'])))
{ {
$ev_start = $ecal_class->make_date($_POST['ne_hour'], $_POST['ne_minute'],$_POST['start_date']); $ev_start = $ecal_class->make_date($_POST['ne_hour'], $_POST['ne_minute'],$_POST['start_date']);
if (($_POST['ne_event'] == '') || !isset($_POST['qs'])) if (($_POST['ne_event'] == '') || !isset($_POST['qs']))
{ // Problem - tell user to go away - fields are blank (mostly checked by JS) { // Problem - tell user to go away - fields are blank (mostly checked by JS)
header('location:event.php?'.$ev_start.'.0.m3'); header('location:event.php?'.$ev_start.'.0.m3');
@@ -129,7 +129,7 @@ if ((isset($_POST['ne_insert']) || isset($_POST['ne_update'])) && ($cal_super |
$ev_title = $tp->toDB($_POST['ne_title']); $ev_title = $tp->toDB($_POST['ne_title']);
$ev_location = $tp->toDB($_POST['ne_location']); $ev_location = $tp->toDB($_POST['ne_location']);
$ev_event = $tp->toDB($_POST['ne_event']); $ev_event = $tp->toDB($_POST['ne_event']);
$ev_email = $tp >toDB($_POST['ne_email']); $ev_email = $tp->toDB($_POST['ne_email']);
$ev_thread = $tp->toDB($_POST['ne_thread']); $ev_thread = $tp->toDB($_POST['ne_thread']);
$temp_date = $ecal_class->gmgetdate($ecal_class->make_date(0,0,$_POST['start_date'])); $temp_date = $ecal_class->gmgetdate($ecal_class->make_date(0,0,$_POST['start_date']));
$ev_allday = intval($_POST['allday']); $ev_allday = intval($_POST['allday']);
@@ -150,23 +150,23 @@ if ((isset($_POST['ne_insert']) || isset($_POST['ne_update'])) && ($cal_super |
$report_msg = '.m3'; $report_msg = '.m3';
if (isset($_POST['ne_insert'])) if (isset($_POST['ne_insert']))
{ // Bits specific to inserting a new event { // Bits specific to inserting a new event
$qs = preg_replace("/ne./i", "", $_POST['qs']); $qs = preg_replace("/ne./i", "", $_POST['qs']);
if ($_POST['ec_gen_multiple']) if ($_POST['ec_gen_multiple'])
{ {
$mult_count = $ecal_class->gen_recur($ev_start,$ev_end,$recurring,$ev_start,$ev_end); $mult_count = $ecal_class->gen_recur($ev_start,$ev_end,$recurring,$ev_start,$ev_end);
} }
if ($mult_count <= 1) if ($mult_count <= 1)
{ {
$qry = " 0, '".intval($ev_start)."', '".intval($ev_end)."', '".$ev_allday."', '".$recurring."', '".time()."', '$ev_title', '$ev_location', '$ev_event', '".USERID.".".USERNAME."', '".$ev_email."', '".$ev_category."', '".$ev_thread."', '".intval($rec_m)."', '".intval($rec_y)."' "; $qry = " 0, '".intval($ev_start)."', '".intval($ev_end)."', '".$ev_allday."', '".$recurring."', '".time()."', '$ev_title', '$ev_location', '$ev_event', '".USERID.".".USERNAME."', '".$ev_email."', '".$ev_category."', '".$ev_thread."', '".intval($rec_m)."', '".intval($rec_y)."' ";
$sql->db_Insert('event', $qry); $sql->db_Insert('event', $qry);
$id = mysql_insert_id(); $id = mysql_insert_id();
$data = array('method'=>'create', 'table'=>'event', 'id'=>$id, 'plugin'=>'calendar_menu', 'function'=>'dbCalendarCreate'); $data = array('method'=>'create', 'table'=>'event', 'id'=>$id, 'plugin'=>'calendar_menu', 'function'=>'dbCalendarCreate');
$e_event->triggerHook($data); $e_event->triggerHook($data);
$ecal_class->cal_log(1,'db_Insert',$qry, $ev_start); $ecal_class->cal_log(1,'db_Insert',$qry, $ev_start);
$report_msg = '.m4'; $report_msg = '.m4';
} }
} }
if (isset($_POST['ne_update'])) if (isset($_POST['ne_update']))
@@ -261,13 +261,13 @@ else
$eveid = intval(varset($qs[2], 0)); $eveid = intval(varset($qs[2], 0));
} }
if ($action == '') if ($action == '')
{ {
$dateArray = $ecal_class->cal_date; // Use todays date $dateArray = $ecal_class->cal_date; // Use todays date
} }
else else
{ {
if (is_numeric($action)) if (is_numeric($action))
{ {
$dateArray = $ecal_class->gmgetdate($action); $dateArray = $ecal_class->gmgetdate($action);
} }
@@ -671,12 +671,12 @@ if ($action == 'ne' || $action == 'ed')
$ns->tablerender($caption, $text); $ns->tablerender($caption, $text);
require_once(FOOTERF); require_once(FOOTERF);
exit; exit();
} }
else else
{ {
header('location:'.e_PLUGIN.'calendar_menu/event.php'); header('location:'.e_PLUGIN.'calendar_menu/event.php');
exit; exit();
} }
} // End of "Enter New Event" } // End of "Enter New Event"
@@ -755,7 +755,7 @@ else
{ {
if ($ds == 'one') if ($ds == 'one')
{ // Show events from one day { // Show events from one day
// $tmp = getdate($action); // $tmp = $ecal_class->gmgetdate($action);
// $selected_day = $tmp['mday']; // $selected_day = $tmp['mday'];
// $selected_mon = $tmp['mon']; // $selected_mon = $tmp['mon'];
$start_time = intval($action); $start_time = intval($action);