ACP backend for menu block should pretty much be finished;

This should also work for the links block later on;
This commit is contained in:
Marc Alexander
2010-09-13 15:30:16 +00:00
parent 2f596b2b45
commit fb33da9e43
5 changed files with 199 additions and 73 deletions

View File

@@ -28,6 +28,16 @@
<label><input onchange="dE('url', 1)" type="radio" class="radio" name="link_is_cat" value="0"<!-- IF not S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl>
<!-- IF S_LINK_IS_CAT --><div id="url" style="display: none;"><!-- ELSE --><div id="url"><!-- ENDIF -->
<dl>
<dt>
<label for="link_tpye">{L_ACP_PORTAL_MENU_TYPE}:</label><br />
<span>{L_ACP_PORTAL_MENU_TYPE_EXP}</span>
</dt>
<dd>
<label><input type="radio" class="radio" name="link_type" value="1" id="link_type"<!-- IF S_LINK_IS_INT --> checked="checked"<!-- ENDIF --> />{L_ACP_PORTAL_MENU_INT}</label>
<label><input type="radio" class="radio" name="link_type" value="2"<!-- IF not S_LINK_IS_INT --> checked="checked"<!-- ENDIF --> /> {L_ACP_PORTAL_MENU_EXT}</label>
</dd>
</dl>
<dl>
<dt><label for="link_url">{L_LINK_URL}:</label></dt>
<dd><input name="link_url" type="text" id="link_url" value="{LINK_URL}" maxlength="255" /></dd>

View File

@@ -0,0 +1,110 @@
<!-- INCLUDE overall_header.html -->
<a name="maincontent"></a>
<h1>{L_TITLE}</h1>
<p>{L_TITLE_EXPLAIN}</p>
<!-- IF S_ERROR -->
<div class="errorbox">
<h3>{L_WARNING}</h3>
<p>{ERROR_MSG}</p>
</div>
<!-- ENDIF -->
<!-- IF S_EDIT -->
<form id="acp_portal_links" method="post" action="{U_ACTION}">
<fieldset>
<legend>{L_ACP_PORTAL_LINKS}</legend>
<dl>
<dt><label for="link_title">{L_LINK_TITLE}:</label></dt>
<dd><input name="link_title" type="text" id="link_title" value="{LINK_TITLE}" maxlength="255" /></dd>
</dl>
<dl>
<dt><label for="link_is_cat">{L_LINK_IS_CAT}:</label></dt>
<dd><label><input onchange="dE('url', -1)" type="radio" class="radio" name="link_is_cat" value="1" id="link_is_cat"<!-- IF S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="dE('url', 1)" type="radio" class="radio" name="link_is_cat" value="0"<!-- IF not S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl>
<!-- IF S_LINK_IS_CAT --><div id="url" style="display: none;"><!-- ELSE --><div id="url"><!-- ENDIF -->
<dl>
<dt>
<label for="link_tpye">{L_ACP_PORTAL_MENU_TYPE}:</label><br />
<span>{L_ACP_PORTAL_MENU_TYPE_EXP}</span>
</dt>
<dd>
<label><input type="radio" class="radio" name="link_type" value="1" id="link_type"<!-- IF S_LINK_IS_INT --> checked="checked"<!-- ENDIF --> />{L_ACP_PORTAL_MENU_INT}</label>
<label><input type="radio" class="radio" name="link_type" value="2"<!-- IF not S_LINK_IS_INT --> checked="checked"<!-- ENDIF --> /> {L_ACP_PORTAL_MENU_EXT}</label>
</dd>
</dl>
<dl>
<dt><label for="link_url">{L_LINK_URL}:</label></dt>
<dd><input name="link_url" type="text" id="link_url" value="{LINK_URL}" maxlength="255" /></dd>
</dl>
</div>
<p class="submit-buttons">
<input type="hidden" name="action" value="save" />
<input class="button1" type="submit" id="submit" name="submit" value="{L_SUBMIT}" />&nbsp;
<input class="button2" type="reset" id="reset" name="reset" value="{L_RESET}" />
{S_FORM_TOKEN}
</p>
</fieldset>
</form>
<!-- ELSE -->
<form id="acp_portal_links" method="post" action="{U_ACTION}">
<!-- IF SHOW_MODULE_OPTIONS -->
<fieldset>
<legend>{L_MODULE_OPTIONS}</legend>
<dl>
<dt><label for="module_name">{L_MODULE_NAME}:</label><br /><span>{L_MODULE_NAME_EXP}</span></dt>
<dd><input id="module_name" type="text" value="{MODULE_NAME}" name="module_name" maxlength="255" size="64" /></dd>
</dl>
<dl>
<dt><label for="module_image">{L_MODULE_IMAGE}:</label><br /><span>{L_MODULE_IMAGE_EXP}</span></dt>
<dd><input id="module_image" type="text" value="{MODULE_IMAGE}" name="module_image" maxlength="255" size="64" /></dd>
<!-- IF MODULE_IMAGE_SRC --><dd><img src="{MODULE_IMAGE_SRC}" alt="{L_MODULE_IMAGE}" /></dd><!-- ENDIF -->
</dl>
</fieldset>
<!-- ENDIF -->
<fieldset class="tabulated">
<legend>{L_ACP_PORTAL_LINKS}</legend>
<p class="quick">
<input class="button2" name="add" type="submit" value="{L_ADD_LINK}" />
</p>
<table cellspacing="1">
<thead>
<tr>
<th>{L_LINK_TITLE}</th>
<th>{L_LINK_URL}</th>
<th>{L_ACTION}</th>
</tr>
</thead>
<tbody>
<!-- BEGIN links -->
<!-- IF links.S_ROW_COUNT is even --><tr class="row1"><!-- ELSE --><tr class="row2"><!-- ENDIF -->
<td style="text-align: center;"<!-- IF links.S_LINK_IS_CAT --> class="row3" colspan="2"<!-- ENDIF -->>{links.LINK_TITLE}</td>
<!-- IF not links.S_LINK_IS_CAT --><td style="text-align: center;">{links.LINK_URL}</td><!-- ENDIF -->
<td style="text-align: center;">
<!-- IF links.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED}<!-- ELSE --><a href="{links.U_MOVE_UP}">{ICON_MOVE_UP}</a><!-- ENDIF -->&nbsp;
<!-- IF links.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED}<!-- ELSE --><a href="{links.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a><!-- ENDIF -->&nbsp;
<a href="{links.U_EDIT}">{ICON_EDIT}</a> <a href="{links.U_DELETE}">{ICON_DELETE}</a>
</td>
</tr>
<!-- END links -->
</tbody>
</table>
{S_FORM_TOKEN}
</fieldset>
</form>
<!-- ENDIF -->
<!-- INCLUDE overall_footer.html -->

View File

@@ -336,6 +336,8 @@ class acp_portal
AND module_order > ' . $module_data['module_order'];
$db->sql_query($sql);
$cache->purge(); // make sure we don't get errors after re-adding a module
trigger_error($user->lang['SUCCESS_DELETE'] . adm_back_link($this->u_action));
}
}

View File

@@ -50,7 +50,9 @@ $lang = array_merge($lang, array(
'ACP_PORTAL_MENU_EXT' => 'External link',
'ACP_PORTAL_MENU_TITLE' => 'Title',
'ACP_PORTAL_MENU_URL' => 'URL',
'ACP_PORTAL_MENU_TYPE' => 'Type',
'ACP_PORTAL_MENU_TYPE' => 'Link type',
'ACP_PORTAL_MENU_TYPE_EXP' => 'If you have a link to a page of your board, choose "Internal link" in order to prevent unwanted logouts.',
'ACP_PORTAL_MENU_CREATE_CAT' => 'You need to create a category first.',
));
?>

View File

@@ -113,7 +113,7 @@ class portal_main_menu_module
$action = request_var('action', '');
$action = (isset($_POST['add'])) ? 'add' : $action;
$action = (isset($_POST['save'])) ? 'save' : $action;
$link_id = request_var('id', 0);
$link_id = request_var('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
$sql = 'SELECT module_id FROM ' . PORTAL_MODULES_TABLE . " WHERE module_classname = 'main_menu'";
$result = $db->sql_query($sql);
@@ -132,14 +132,14 @@ class portal_main_menu_module
{
// Save changes
case 'save':
$form_name = 'acp_portal';
if (!check_form_key($form_name))
if (!check_form_key('acp_portal'))
{
trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
}
$link_title = utf8_normalize_nfc(request_var('link_title', ' ', true));
$link_is_cat = request_var('link_is_cat', 0);
$link_type = (!$link_is_cat) ? request_var('link_type', 0) : B3_LINKS_CAT;
$link_url = ($link_is_cat) ? ' ' : request_var('link_url', ' ');
if (!$link_title)
@@ -152,22 +152,22 @@ class portal_main_menu_module
trigger_error($user->lang['NO_LINK_URL'] . adm_back_link($u_action), E_USER_WARNING);
}
if ($link_id)
if (isset($link_id) && $link_id < sizeof($links_urls))
{
$message = $user->lang['LINK_UPDATED'];
// always check if the links already exist
if(isset($link_titles[$link_id]) && isset($link_options[$link_id]) && isset($link_urls[$link_id]))
if(isset($links_titles[$link_id]) && isset($links_options[$link_id]) && ($link_is_cat || isset($links_urls[$link_id])))
{
$links_titles[$link_id] = $link_title;
$links_urls[$link_id] = htmlspecialchars_decode($link_url);
$links_options[$link_id] = ($link_is_cat) ? B3_LINKS_CAT : B3_LINKS_EXT; // Add internal link later on
$links_options[$link_id] = $link_type;
}
else
{
$links_titles[] = $link_title;
$links_urls[] = $link_url;
$links_options[] = ($link_is_cat) ? B3_LINKS_CAT : B3_LINKS_EXT; // Add internal link later on
$links_options[] = $link_type;
}
add_log('admin', 'LOG_PORTAL_LINK_UPDATED', $link_title);
@@ -178,15 +178,23 @@ class portal_main_menu_module
if($links_titles[0] == '')
{
if($link_type != B3_LINKS_CAT && sizeof($links_titles) < 1)
{
trigger_error($user->lang['ACP_PORTAL_MENU_CREATE_CAT'] . adm_back_link($u_action), E_USER_WARNING);
}
$links_titles[0] = $link_title;
$links_urls[0] = $link_url;
$links_options[0] = ($link_is_cat) ? B3_LINKS_CAT : B3_LINKS_EXT; // Add internal link later on
$links_options[0] = $link_type; // Add internal link later on
}
else
{
if($link_type != B3_LINKS_CAT && sizeof($links_titles) < 1)
{
trigger_error($user->lang['ACP_PORTAL_MENU_CREATE_CAT'] . adm_back_link($u_action), E_USER_WARNING);
}
$links_titles[] = $link_title;
$links_urls[] = $link_url;
$links_options[] = ($link_is_cat) ? B3_LINKS_CAT : B3_LINKS_EXT; // Add internal link later on
$links_options[] = $link_type; // Add internal link later on
}
//$config['board3_menu_count']++; // @todo: check if we need this
@@ -207,43 +215,38 @@ class portal_main_menu_module
// Delete link
case 'delete':
if (!$link_id)
if (!isset($link_id) && $link_id >= sizeof($links_urls))
{
trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
}
if (confirm_box(true))
{
$sql = 'SELECT link_title, link_order
FROM ' . PORTAL_LINKS_TABLE . "
WHERE link_id = $link_id";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$cur_link_title = $links_titles[$link_id];
// make sure we don't delete links that weren't supposed to be deleted
$title_ary = array('{remove_link}');
$links_titles[$link_id] = '{remove_link}';
$option_ary = array('{remove_link}');
$links_options[$link_id] = '{remove_link}';
$url_ary = array('{remove_link}');
$links_urls[$link_id] = '{remove_link}';
if ($row)
{
$row['link_title'] = (string) $row['link_title'];
$row['link_order'] = (int) $row['link_order'];
}
$links_titles = array_diff($links_titles, $title_ary);
$links_urls = array_diff($links_urls, $url_ary);
$links_options = array_diff($links_options, $url_ary);
$sql = 'DELETE FROM ' . PORTAL_LINKS_TABLE . " WHERE link_id = $link_id";
$db->sql_query($sql);
set_config('board3_links_urls', implode(';', $links_urls));
set_config('board3_links_options', implode(';', $links_options));
set_config('board3_links_titles', implode(';', $links_titles));
// Reset link order...
$sql = 'UPDATE ' . PORTAL_LINKS_TABLE . ' SET link_order = link_order - 1 WHERE link_order > ' . $row['link_order'];
$db->sql_query($sql);
$cache->destroy('_links');
//$cache->destroy('_links'); // @todo: check if we can remove this
set_portal_config('num_links', $config['board3_menu_count'] - 1, true);
add_log('admin', 'LOG_PORTAL_LINK_REMOVED', $row['link_title']);
add_log('admin', 'LOG_PORTAL_LINK_REMOVED', $cur_link_title);
}
else
{
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
'i' => $id,
'mode' => $mode,
'link_id' => $link_id,
'action' => 'delete',
)));
@@ -255,44 +258,42 @@ class portal_main_menu_module
case 'move_up':
case 'move_down':
if (!$link_id)
if (!isset($link_id) && $link_id >= sizeof($links_urls))
{
trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
}
// Get current order id...
$sql = 'SELECT link_order AS current_order
FROM ' . PORTAL_LINKS_TABLE . "
WHERE link_id = $link_id";
$result = $db->sql_query($sql);
$current_order = (int) $db->sql_fetchfield('current_order');
$db->sql_freeresult($result);
if ($current_order == 0 && $action == 'move_up')
// make sure we don't try to move a link where it can't be moved
if (($link_id == 0 && $action == 'move_up') || ($link_id == (sizeof($links_urls) - 1) && $action == 'move_down'))
{
break;
}
// on move_down, switch position with next order_id...
// on move_up, switch position with previous order_id...
$switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1;
/*
* on move_down, switch position with next order_id...
* on move_up, switch position with previous order_id...
* move up means a lower ID, move down means a higher ID
*/
$switch_order_id = ($action == 'move_down') ? $link_id + 1 : $link_id - 1;
// Update order values
$sql = 'UPDATE ' . PORTAL_LINKS_TABLE . "
SET link_order = $current_order
WHERE link_order = $switch_order_id
AND link_id <> $link_id";
$db->sql_query($sql);
// back up the info of the link we want to move
$cur_url = $links_urls[$link_id];
$cur_title = $links_titles[$link_id];
$cur_option = $links_options[$link_id];
// Only update the other entry too if the previous entry got updated
if ($db->sql_affectedrows())
{
$sql = 'UPDATE ' . PORTAL_LINKS_TABLE . "
SET link_order = $switch_order_id
WHERE link_order = $current_order
AND link_id = $link_id";
$db->sql_query($sql);
}
// move the info of the links we replace in the order
$links_urls[$link_id] = $links_urls[$switch_order_id];
$links_titles[$link_id] = $links_titles[$switch_order_id];
$links_options[$link_id] = $links_options[$switch_order_id];
// insert the info of the moved link
$links_urls[$switch_order_id] = $cur_url;
$links_titles[$switch_order_id] = $cur_title;
$links_options[$switch_order_id] = $cur_option;
set_config('board3_links_urls', implode(';', $links_urls));
set_config('board3_links_options', implode(';', $links_options));
set_config('board3_links_titles', implode(';', $links_titles));
break;
@@ -300,14 +301,15 @@ class portal_main_menu_module
case 'edit':
case 'add':
$template->assign_vars(array(
'LINK_TITLE' => (isset($links_titles[$link_id])) ? $links_titles[$link_id] : '',
'LINK_URL' => (isset($links_urls[$link_id]) && $links_options[$link_id] != B3_LINKS_CAT) ? $links_urls[$link_id] : '',
'LINK_TITLE' => (isset($links_titles[$link_id]) && $action != 'add') ? $links_titles[$link_id] : '',
'LINK_URL' => (isset($links_urls[$link_id]) && $links_options[$link_id] != B3_LINKS_CAT && $action != 'add') ? $links_urls[$link_id] : '',
'U_BACK' => $u_action,
//'U_BACK' => $u_action,
'U_ACTION' => $u_action . '&amp;id=' . $link_id,
'S_EDIT' => true,
'S_LINK_IS_CAT' => (!isset($links_options[$link_id]) || $links_options[$link_id] == B3_LINKS_CAT) ? true : false,
'S_LINK_IS_INT' => (isset($links_options[$link_id]) && $links_options[$link_id] == B3_LINKS_INT) ? true : false,
));
return;
@@ -318,8 +320,8 @@ class portal_main_menu_module
for ($i = 0; $i < sizeof($links_urls); $i++)
{
$template->assign_block_vars('links', array(
'LINK_TITLE' => $links_titles[$i],
'LINK_URL' => $links_urls[$i],
'LINK_TITLE' => ($action != 'add') ? $links_titles[$i] : '',
'LINK_URL' => ($action != 'add') ? $links_urls[$i] : '',
'U_EDIT' => $u_action . '&amp;action=edit&amp;id=' . $i,
'U_DELETE' => $u_action . '&amp;action=delete&amp;id=' . $i,