Browse Source

! Allow linking of existing events to new topics (fixes #1224)

Signed-off-by: Michael Eshom <[email protected]>
Michael Eshom 10 years ago
parent
commit
a52aaf910d

+ 21 - 21
Sources/Calendar.php

@@ -243,7 +243,7 @@ function CalendarPost()
 			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
 
 		// New - and directing?
-		if ($_REQUEST['eventid'] == -1 && (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked'])))
+		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
 		{
 			$_REQUEST['calendar'] = 1;
 			require_once($sourcedir . '/Post.php');
@@ -327,26 +327,6 @@ function CalendarPost()
 			'span' => 1,
 		);
 		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
-
-		// Get list of boards that can be posted in.
-		$boards = boardsAllowedTo('post_new');
-		if (empty($boards))
-		{
-			// You can post new events but can't link them to anything...
-			$context['event']['categories'] = array();
-		}
-		else
-		{
-			// Load the list of boards and categories in the context.
-			require_once($sourcedir . '/Subs-MessageIndex.php');
-			$boardListOptions = array(
-				'included_boards' => in_array(0, $boards) ? null : $boards,
-				'not_redirection' => true,
-				'use_permissions' => true,
-				'selected_board' => $modSettings['cal_defaultboard'],
-			);
-			$context['event']['categories'] = getBoardList($boardListOptions);
-		}
 	}
 	else
 	{
@@ -370,6 +350,26 @@ function CalendarPost()
 			isAllowedTo('calendar_edit_own');
 	}
 
+	// Get list of boards that can be posted in.
+	$boards = boardsAllowedTo('post_new');
+	if (empty($boards))
+	{
+		// You can post new events but can't link them to anything...
+		$context['event']['categories'] = array();
+	}
+	else
+	{
+		// Load the list of boards and categories in the context.
+		require_once($sourcedir . '/Subs-MessageIndex.php');
+		$boardListOptions = array(
+			'included_boards' => in_array(0, $boards) ? null : $boards,
+			'not_redirection' => true,
+			'use_permissions' => true,
+			'selected_board' => $modSettings['cal_defaultboard'],
+		);
+		$context['event']['categories'] = getBoardList($boardListOptions);
+	}
+
 	// Template, sub template, etc.
 	loadTemplate('Calendar');
 	$context['sub_template'] = 'event_post';

+ 17 - 3
Sources/Post.php

@@ -309,6 +309,7 @@ function Post($post_errors = array())
 		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
 
 		$context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard'];
+		$context['event']['topic'] = !empty($topic) ? $topic : 0;
 	}
 
 	// See if any new replies have come along.
@@ -1905,18 +1906,31 @@ function Post2()
 			$span = !empty($modSettings['cal_allowspan']) && !empty($_REQUEST['span']) ? min((int) $modSettings['cal_maxspan'], (int) $_REQUEST['span'] - 1) : 0;
 			$start_time = mktime(0, 0, 0, (int) $_REQUEST['month'], (int) $_REQUEST['day'], (int) $_REQUEST['year']);
 
+			$board_query = '';
+			$board_params = array();
+
+			// Linking a previously non-linked event to a new post? 
+			if (empty($_REQUEST['evtopic']))
+			{
+				$board_query = ',
+					id_board = {int:board},
+					id_topic = {int:topic}';
+
+				$board_params = array('board' => $board, 'topic' => $topic);
+			}
+
 			$smcFunc['db_query']('', '
 				UPDATE {db_prefix}calendar
 				SET end_date = {date:end_date},
 					start_date = {date:start_date},
-					title = {string:title}
+					title = {string:title}' . $board_query . '
 				WHERE id_event = {int:id_event}',
-				array(
+				array_merge(array(
 					'end_date' => strftime('%Y-%m-%d', $start_time + $span * 86400),
 					'start_date' => strftime('%Y-%m-%d', $start_time),
 					'id_event' => $_REQUEST['eventid'],
 					'title' => $smcFunc['htmlspecialchars']($_REQUEST['evtitle'], ENT_QUOTES),
-				)
+				), $board_params)
 			);
 		}
 		updateSettings(array(

+ 1 - 1
Sources/Subs-Calendar.php

@@ -804,7 +804,7 @@ function getEventPoster($event_id)
  */
 function insertEvent(&$eventOptions)
 {
-	global $smcFunc;
+	global $smcFunc, $context;
 
 	// Add special chars to the title.
 	$eventOptions['title'] = $smcFunc['htmlspecialchars']($eventOptions['title'], ENT_QUOTES);

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

@@ -611,16 +611,16 @@ function template_event_post()
 	}
 
 	// If this is a new event let the user specify which board they want the linked post to be put into.
-	if ($context['event']['new'] && !empty($context['event']['categories']))
+	if (!empty($context['event']['categories']))
 	{
 		echo '
 							<li>
 								', $txt['calendar_link_event'], '
-								<input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board" checked onclick="toggleLinked(this.form);">
+								<input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board"', ($context['event']['new'] ? ' checked' : ''), ' onclick="toggleLinked(this.form);">
 							</li>
 							<li>
 								', $txt['calendar_post_in'], '
-								<select id="board" name="board" onchange="this.form.submit();">';
+								<select id="board" name="board" onchange="this.form.submit();"', ($context['event']['new'] ? '' : ' disabled'), '>';
 		foreach ($context['event']['categories'] as $category)
 		{
 			echo '

+ 1 - 0
Themes/default/Post.template.php

@@ -190,6 +190,7 @@ function template_main()
 						<fieldset id="event_main">
 							<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', ' id="caption_evtitle">', $txt['calendar_event_title'], '</span></legend>
 							<input type="text" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '" class="input_text">
+							<input type="hidden" name="evtopic" value="', $context['event']['topic'], '">
 							<div class="smalltext" style="white-space: nowrap;">
 								<input type="hidden" name="calendar" value="1">', $txt['calendar_year'], '
 								<select name="year" id="year" tabindex="', $context['tabindex']++, '" onchange="generateDays();">';