Browse Source

! Allow for index.php?action=calendar;event=1 or similar to go to the right page of the calendar and highlight the calendar item in question (currently in bold) to indicate what's going on. This will be used by the alerts system.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 years ago
parent
commit
8af76809b6

+ 33 - 1
Sources/Calendar.php

@@ -29,7 +29,7 @@ if (!defined('SMF'))
  */
 function CalendarMain()
 {
-	global $txt, $context, $modSettings, $scripturl, $options, $sourcedir, $user_info;
+	global $txt, $context, $modSettings, $scripturl, $options, $sourcedir, $user_info, $smcFunc;
 
 	// Permissions, permissions, permissions.
 	isAllowedTo('calendar_view');
@@ -56,6 +56,38 @@ function CalendarMain()
 	if (empty($modSettings['cal_enabled']))
 		fatal_lang_error('calendar_off', false);
 
+	// Did the specify an individual event ID? If so, let's splice the year/month in to what we would otherwise be doing.
+	if (isset($_GET['event']))
+	{
+		$evid = (int) $_GET['event'];
+		if ($evid > 0)
+		{
+			$request = $smcFunc['db_query']('', '
+				SELECT start_date
+				FROM {db_prefix}calendar
+				WHERE id_event = {int:event_id}',
+				array(
+					'event_id' => $evid,
+				)
+			);
+			if ($row = $smcFunc['db_fetch_assoc']($request))
+			{
+				// We know the format is going to be in yyyy-mm-dd from the database, so let's run with that.
+				list($_REQUEST['year'], $_REQUEST['month']) = explode('-', $row['start_date']);
+				$_REQUEST['year'] = (int) $_REQUEST['year'];
+				$_REQUEST['month'] = (int) $_REQUEST['month'];
+
+				// And we definitely don't want weekly view.
+				unset ($_GET['viewweek']);
+
+				// We might use this later.
+				$context['selected_event'] = $evid;
+			}
+			$smcFunc['db_free_result']($request);
+		}
+		unset ($_GET['event']);
+	}
+
 	// Set the page title to mention the calendar ;).
 	$context['page_title'] = $txt['calendar'];
 

+ 19 - 0
Sources/Subs-Calendar.php

@@ -154,6 +154,7 @@ function getEventRange($low_date, $high_date, $use_permissions = true)
 					'end_date' => $row['end_date'],
 					'is_last' => false,
 					'id_board' => $row['id_board'],
+					'is_selected' => !empty($context['selected_event']) && $context['selected_event'] == $row['id_event'],
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -170,6 +171,7 @@ function getEventRange($low_date, $high_date, $use_permissions = true)
 					'end_date' => $row['end_date'],
 					'is_last' => false,
 					'id_board' => $row['id_board'],
+					'is_selected' => !empty($context['selected_event']) && $context['selected_event'] == $row['id_event'],
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
 					'can_edit' => false,
@@ -888,6 +890,23 @@ function insertEvent(&$eventOptions)
 	// Store the just inserted id_event for future reference.
 	$eventOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}calendar', 'id_event');
 
+	// If this isn't tied to a topic, we need to notify people about it.
+	if (empty($eventOptions['topic']))
+	{
+		$smcFunc['db_insert']('insert',
+			'{db_prefix}background_tasks',
+			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
+			array('$sourcedir/tasks/EventNew-Notify.php', 'EventNew_Notify_Background', serialize(array(
+				'event_title' => $eventOptions['title'],
+				'event_id' => $eventOptions['id'],
+				'sender_id' => $eventOptions['member'],
+				'sender_name' => $eventOptions['member'] == $context['user']['id'] ? $context['user']['name'] : '',
+				'time' => time(),
+			)), 0),
+			array('id_task')
+		);
+	}
+
 	// Update the settings to show something calendar-ish was updated.
 	updateSettings(array(
 		'calendar_updated' => time(),

+ 1 - 1
Themes/default/Calendar.template.php

@@ -271,7 +271,7 @@ function template_show_month_grid($grid_name, $is_mini = false)
 									</a>
 								';
 							}
-							echo $event['link'], $event['is_last'] ? '' : '<br>';
+							echo $event['is_selected'] ? '<div class="sel_event">' . $event['link'] . '</div>' : $event['link'], $event['is_last'] ? '' : '<br>';
 						}
 
 						echo '</div>';

+ 4 - 0
Themes/default/css/index.css

@@ -719,6 +719,10 @@ div.pagesection div.floatright input, div.pagesection div.floatright select {
 .holiday > span {
 	color: rgb(0, 92, 255);
 }
+/* Events that are currently selected on the calendar. Won't see it much, probably. */
+.sel_event {
+	font-weight: bold;
+}
 
 /* Colors for warnings */
 .warn_mute {