Commit 3a302fd5 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files
parents 2df4aeb3 abdf5552
......@@ -31,6 +31,7 @@ require('init.php');
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('about'));
$smarty->assign('site_menu', site_menu());
$smarty->display('sitepage.tpl');
?>
......@@ -28,7 +28,8 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
$itemid = clean_requestdata('itemid', PARAM_INT, REQUEST_EITHER);
//$itemid = clean_requestdata('itemid', PARAM_INT, REQUEST_EITHER);
$itemid = param_variable('itemid');
$result = array();
try {
......
......@@ -37,10 +37,10 @@ $ijs .= "var adminfile = '" . get_string('adminfile') . "';\n";
$ijs .= <<< EOJS
// Request a list of menu items from the server
function getitems(menu) {
function getitems() {
logDebug(get_string('loadingmenuitems'));
processingStart();
var d = loadJSONDoc('getmenuitems.json.php',{'menu':menu});
var d = loadJSONDoc('getmenuitems.json.php',{'menu':selectedmenu});
d.addCallback(function(data) {
if (!data.error) {
logDebug(get_string('loadedmenuitems'));
......@@ -200,7 +200,7 @@ function delitem(itemid) {
d.addCallback(function(data) {
if (data.success) {
logDebug(get_string('menuitemdeleted'));
getitems(menu);
getitems();
}
else {
displayMessage(get_string('deletefailed'),'error');
......@@ -218,7 +218,7 @@ function saveitem(formid) {
'name':f.name.value,
'linkedto':f.linkedto.value,
'itemid':f.itemid.value,
'menu':menu};
'menu':selectedmenu};
var req = getXMLHttpRequest();
req.open('POST','updatemenu.json.php');
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
......@@ -237,7 +237,7 @@ function saveitem(formid) {
}
else {
displayMessage(data.message,errtype);
getitems(menu);
getitems();
processingStop();
}
});
......@@ -252,13 +252,29 @@ function getadminfiles() {
return null;
}
var menu = 'public';
addLoadEvent(function () {getitems(menu);});
function setmenu(menu) {
selectedmenu = menu;
var pub = get_string('loggedoutmenu');
var priv = get_string('loggedinmenu');
if (menu == 'public') {
priv = A({'href':'#'},priv);
priv.onclick = function (e) {stop(e); setmenu('private');};
}
else {
pub = A({'href':'#'},pub);
pub.onclick = function (e) {stop(e); setmenu('public');};
}
replaceChildNodes($('menuselect'), [pub, priv]);
getitems();
}
var selectedmenu = 'public';
addLoadEvent(function () {setmenu(selectedmenu);});
EOJS;
$style = '<style type="text/css">.invisible{display:none;} .menueditcell{width:200px;}</style>';
$strings = array('deletefailed','deletingmenuitem','menuitemdeleted','noadminfiles',
'edit','delete','update','cancel');
'edit','delete','update','cancel','add','loggedinmenu','loggedoutmenu');
$smarty = smarty(array(),array($style),$strings);
$smarty->assign('INLINEJAVASCRIPT',$ijs);
$smarty->display('admin/editmenu.tpl');
......
......@@ -66,7 +66,7 @@ $f = array(
'submit' => array(
'value' => get_string('savechanges'),
'type' => 'submit',
)
),
)
);
......
......@@ -28,8 +28,8 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
$menu = get_variable('menu');
$public = $menu == 'public' ? 1 : 0;
$menu = param_variable('menu');
$public = (int)($menu == 'public');
$result = array();
......
......@@ -28,8 +28,6 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
error_log('updatemenu.json.php');
function send_fail_message() {
$result = array();
$result['error'] = 'local';
......@@ -38,13 +36,11 @@ function send_fail_message() {
exit;
}
$type = get_variable('type');
$name = get_variable('name');
$linkedto = get_variable('linkedto');
$itemid = get_variable('itemid');
$menu = get_variable('menu');
error_log('updatemenu.json.php '.$type .' '. $name .' '. $linkedto .' '. $itemid);
$type = param_variable('type'); // external list or admin file
$name = param_variable('name');
$linkedto = param_variable('linkedto');
$itemid = param_variable('itemid');
$menu = param_variable('menu');
$data = new StdClass;
if ($type == 'adminfile') {
......@@ -58,12 +54,12 @@ else { // Bad menu item type
send_fail_message();
}
$data->title = $name;
$data->public = $menu == 'public' ? 1 : 0;
if ($itemid == 'new') {
$data->public = (int) ($menu == 'public');
// set displayorder to be after all the existing menu items
try {
$displayorders = get_rows('site_menu', '', '', '', 'displayorder');
$displayorders = get_rows('site_menu', 'public', $data->public, '', 'displayorder');
$max = 0;
foreach ($displayorders as $r) {
$max = $r['displayorder'] >= $max ? $r['displayorder'] + 1 : $max;
......
......@@ -94,6 +94,7 @@ if (!$SESSION->is_logged_in()) {
$smarty->assign('login_form', $loginform);
}
$smarty->assign('page_content', get_site_page_content($pagename));
$smarty->assign('site_menu', site_menu());
$smarty->display('index.tpl');
?>
......@@ -900,7 +900,25 @@ function main_nav() {
return $menu;
}
/**
* Site-level sidebar menu (list of links)
* There is no admin files table yet so just get the urls.
* @return $menu a data structure containing the site menu
*/
function site_menu() {
//$wwwroot = get_config('wwwroot'); (int)
global $SESSION;
$menu = array();
if ($menuitems = @get_records('site_menu','public',(int) !$SESSION->is_logged_in(),'displayorder')) {
foreach ($menuitems as $i) {
if ($i->url) {
$menu[] = array('name' => $i->title,
'link' => $i->url);
}
}
}
return $menu;
}
/**
* Always use this function for all emails to users
*
......
......@@ -594,7 +594,7 @@ function param_alpha($name) {
$value = param_variable($name);
}
if (preg_match('/^[a-zA-Z]$/',$value)) {
if (preg_match('/^[a-zA-Z]+$/',$value)) {
return $value;
}
......
......@@ -31,6 +31,7 @@ require('init.php');
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('privacy'));
$smarty->assign('site_menu', site_menu());
$smarty->display('sitepage.tpl');
?>
......@@ -31,6 +31,7 @@ require('init.php');
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('termsandconditions'));
$smarty->assign('site_menu', site_menu());
$smarty->display('sitepage.tpl');
?>
......@@ -2,6 +2,8 @@
<p>Admin menu editor</p>
<div id="menuselect"></div>
<table id="menuitemlist" class="menueditor"><tbody><tr><td></td></tr></tbody></table>
{include file="footer.tpl"}
<div class="sidebar">
Admin Menu here
<ul id="sitemenu">
{foreach from=$site_menu item=item}
<li><a href="{$item.link|escape}">{$item.name}</a></li>
{/foreach}
</ul>
</div>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment