From a52aaf910daf8d59eb62849e93fca0e6b5a729a6 Mon Sep 17 00:00:00 2001 From: Michael Eshom Date: Wed, 19 Feb 2014 16:03:46 -0500 Subject: [PATCH] ! Allow linking of existing events to new topics (fixes #1224) Signed-off-by: Michael Eshom --- Sources/Calendar.php | 42 ++++++++++++++-------------- Sources/Post.php | 20 +++++++++++-- Sources/Subs-Calendar.php | 2 +- Themes/default/Calendar.template.php | 6 ++-- Themes/default/Post.template.php | 1 + 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/Sources/Calendar.php b/Sources/Calendar.php index e653da4cce..0d3961eccf 100644 --- a/Sources/Calendar.php +++ b/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'; diff --git a/Sources/Post.php b/Sources/Post.php index b7919563ac..198ddb4373 100644 --- a/Sources/Post.php +++ b/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( diff --git a/Sources/Subs-Calendar.php b/Sources/Subs-Calendar.php index bc0ea2e3c3..610a321657 100644 --- a/Sources/Subs-Calendar.php +++ b/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); diff --git a/Themes/default/Calendar.template.php b/Themes/default/Calendar.template.php index 658ccb1d52..18bd1533e6 100644 --- a/Themes/default/Calendar.template.php +++ b/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 '
  • ', $txt['calendar_link_event'], ' - +
  • ', $txt['calendar_post_in'], ' - '; foreach ($context['event']['categories'] as $category) { echo ' diff --git a/Themes/default/Post.template.php b/Themes/default/Post.template.php index 3f8e2819ce..d9d9604b3a 100644 --- a/Themes/default/Post.template.php +++ b/Themes/default/Post.template.php @@ -190,6 +190,7 @@ function addPollOption()
    ', $txt['calendar_event_title'], ' +
    ', $txt['calendar_year'], '