1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-13 01:54:12 +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
@@ -75,6 +80,7 @@ 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'
@@ -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 :
@@ -450,11 +457,13 @@ class ecal_class
switch ($event_type) switch ($event_type)
{ {
case 5 : case 5 :
case 1 : $e107->e_event->trigger('ecalnew', $edata_ec); case 1 :
$e107->e_event->trigger('ecalnew', $edata_ec);
break; break;
case 2 : case 2 :
case 3 : case 3 :
case 4 : $e107->e_event->trigger('ecaledit', $edata_ec); case 4 :
$e107->e_event->trigger('ecaledit', $edata_ec);
break; break;
} }
@@ -499,21 +508,34 @@ 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 * All fields are Unix-style time/date stamps
* @param int $first_event * @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 $last_event
* @param int $interval - interval between events (in seconds) * @param int $interval - interval between events (in seconds)
* @param int $start_time * @param int $start_time
@@ -560,6 +582,14 @@ 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
* Returns an array of start times
*
* 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 $first_event - earliest date for events
* @param int $last_event - latest time for date of event * @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 $interval_type - numeric code defining the interval between events (N.B> day number zero is Sunday)
@@ -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)
@@ -661,6 +694,12 @@ 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,9 +730,9 @@ 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
* If $start_only is TRUE, only searches based on the start date/time
* Potential option to hook in other routines here later * Potential option to hook in other routines here later
* @param int $start_time - earliest time for events * @param int $start_time - earliest time for events
* @param int $end_time - latest time for start of event * @param int $end_time - latest time for start of event

View File

@@ -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']);
@@ -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);