Skip to content

Commit

Permalink
! Allow linking of existing events to new topics (fixes #1224)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Eshom <oldiesmann@oldiesmann.us>
  • Loading branch information
Oldiesmann committed Feb 19, 2014
1 parent 08bbc6d commit a52aaf9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
42 changes: 21 additions & 21 deletions Sources/Calendar.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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
{
Expand All @@ -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';
Expand Down
20 changes: 17 additions & 3 deletions Sources/Post.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Subs-Calendar.php
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Themes/default/Calendar.template.php
Expand Up @@ -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 '
Expand Down
1 change: 1 addition & 0 deletions Themes/default/Post.template.php
Expand Up @@ -190,6 +190,7 @@ function addPollOption()
<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();">';
Expand Down

0 comments on commit a52aaf9

Please sign in to comment.