Commit c85bca90 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents 1aca291f 93b2d818
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
$itemid = clean_requestdata('itemid', PARAM_INT, REQUEST_EITHER);
$result = array();
try {
delete_records('site_menu','id',$itemid);
$result['success'] = 'ok';
$result['message'] = get_string('deletedsuccessfully');
}
catch (Exception $e) {
$result['success'] = 'error';
$result['message'] = $e->getMessage();
}
echo json_encode($result);
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL',1);
define('ADMIN', 1);
define('MENUITEM','menueditor');
require(dirname(dirname(__FILE__)).'/init.php');
//require_once('form.php');
$thead = array(get_string('type'),get_string('name'),get_string('linkedto'),'');
$ijs = "var thead = TR(null,map(partial(TH,null),['" . implode($thead,"','") . "']));\n";
$ijs .= "var externallink = '" . get_string('externallink') . "';\n";
$ijs .= "var adminfile = '" . get_string('adminfile') . "';\n";
$ijs .= <<< EOJS
// Request a list of menu items from the server
function getitems(menu) {
logDebug(get_string('loadingmenuitems'));
processingStart();
var d = loadJSONDoc('getmenuitems.json.php',{'menu':menu});
d.addCallback(function(data) {
if (!data.error) {
logDebug(get_string('loadedmenuitems'));
displaymenuitems(data.menuitems);
processingStop();
}
else {
displayMessage(get_string('failedloadingmenuitems'),'error');
processingStop();
}
});
}
// Puts the list of menu items into the empty table.
function displaymenuitems(itemlist) {
var rows = map(formatrow,itemlist);
var table = $('menuitemlist');
var newrow = TR({'id':'additem','style':'background-color: #ddd;'},
TD({'colspan':4},addform()));
replaceChildNodes(table,TBODY(null,[thead,rows,newrow]));
}
// Creates one table row
function formatrow (item) {
// item has id, type, name, link, linkedto
var type = eval(item.type);
var linkedto = item.link == '' ? item.linkedto : A({'href':item.link},item.linkedto);
var del = INPUT({'type':'button','value':get_string('delete')});
del.onclick = function () { delitem(item.id); };
var edit = INPUT({'type':'button','value':get_string('edit')});
edit.onclick = function () { edititem(item); };
var cells = map(partial(TD,null),[type,item.name,linkedto,[del,edit]]);
return TR({'id':'menuitem_'+item.id,'class':'menueditcell'},cells);
}
// Returns the form which adds a new menu item
function addform(type) {
var item = {'id':'new'};
item.type = type ? type : 'externallist';
return newform(item);
}
// Creates the contents of a menu item edit form
// This is formatted as a table within the form (which is within a row of the table).
function editform(item) {
// item has id, type, name, link, linkedto
// The form has two radio buttons to select the type, external link or admin file
var elink = INPUT({'type':'radio','name':'type','value':'externallink'});
var afile = INPUT({'type':'radio','name':'type','value':'adminfile'});
// Either a save, a cancel button, or both.
var savecancel = [];
var save = INPUT({'type':'submit'});
// The link field will be a text box or a select in the case of an admin file.
var linkedto = null;
if (!item) {
// This is the 'add' form rather than the edit form
// Set defaults.
item = {'type':'externallist'};
}
if (!item.linkedto) {
item.linkedto = '';
item.name = '';
elink.onclick = function () { changeaddform('externallink'); };
afile.onclick = function () { changeaddform('adminfile'); };
// The save button says 'add', and there's no cancel button.
setNodeAttribute(save,'value',get_string('add'));
savecancel = [save];
}
else { // Editing an existing menu item.
// The save button says 'update' and there's a cancel button.
setNodeAttribute(save,'value',get_string('update'));
var cancel = INPUT({'type':'button','value':get_string('cancel')});
cancel.onclick = closeopenedits;
savecancel = [save,cancel];
elink.onclick = function () { changeeditform(item,'externallink'); };
afile.onclick = function () { changeeditform(item,'adminfile'); };
}
// A text field for the name
var name = INPUT({'type':'text','name':'name','value':item.name});
if (item.type == 'adminfile') {
var adminfiles = getadminfiles();
if (adminfiles == null) {
// There are no admin files, we don't need the select or save button
linkedto = get_string('noadminfiles');
savecancel = [cancel];
}
else {
// Select the currently selected file.
linkedto = INPUT({'type':'select','name':'linkedto'});
}
setNodeAttribute(afile,'checked',true);
}
else { // type = externallist
linkedto = INPUT({'type':'text','name':'linkedto','value':item.linkedto});
setNodeAttribute(elink,'checked',true);
}
var radios = [DIV(null,elink,eval('externallink')),DIV(null,afile,eval('adminfile'))];
var row = TR(null,map(partial(TD,{'class':'menueditcell'}),[radios,name,linkedto,savecancel]));
return TABLE(null,TBODY(null,row));
}
// Close all open edit forms
function closeopenedits() {
var rows = getElementsByTagAndClassName('tr',null,$('menuitemlist'));
for (var i=0; i<rows.length; i++) {
if (hasElementClass(rows[i],'edititem')) {
removeElement(rows[i]);
}
else if (hasElementClass(rows[i],'invisible')) {
removeElementClass(rows[i],'invisible');
}
}
}
// Change the type of an edit form
function changeeditform(item, type) {
item.type = type;
edititem(item);
}
// Change the type of the add form
function changeaddform(type) {
var newrow = TR({'id':'additem','style':'background-color: #ddd;'},
TD({'colspan':4},addform(type)));
swapDOM($('additem'),newrow);
}
// Return a new form element
function newform(item) {
var formid = 'form'+item.id;
var f = FORM({'id':formid,'method':'post','enctype':'multipart/form-data',
'encoding':'multipart/form-data','onsubmit':"return saveitem('"+formid+"');"},
editform(item),
INPUT({'type':'hidden','name':'itemid','value':item.id}));
return f;
}
// Open a new edit form
function edititem(item) {
closeopenedits();
var menuitem = $('menuitem_'+item.id);
addElementClass(menuitem,'invisible');
var newrow = TR({'class':'edititem','style':'background-color: #ddd;'},TD({'colspan':4},newform(item)));
menuitem.parentNode.insertBefore(newrow,menuitem);
}
// Request deletion of a menu item from the db
function delitem(itemid) {
processingStart();
logDebug(get_string('deletingmenuitem'));
var d = loadJSONDoc('deletemenuitem.json.php',{'itemid':itemid});
d.addCallback(function(data) {
if (data.success) {
logDebug(get_string('menuitemdeleted'));
getitems(menu);
}
else {
displayMessage(get_string('deletefailed'),'error');
}
processingStop();
});
}
// Send the menu item in the form to the database.
function saveitem(formid) {
processingStart();
displayMessage(get_string('savingmenuitem'),'info');
var f = $(formid);
var data = {'type':f.type[0].checked ? 'externallink' : 'adminfile',
'name':f.name.value,
'linkedto':f.linkedto.value,
'itemid':f.itemid.value,
'menu':menu};
var req = getXMLHttpRequest();
req.open('POST','updatemenu.json.php');
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
var d = sendXMLHttpRequest(req,queryString(data));
d.addCallback(function (result) {
var data = evalJSONRequest(result);
var errtype = 'global';
if (!data.error) {
errtype = 'info';
}
if (data.error == 'local') {
errtype = 'error';
}
if (errtype == 'global') {
global_error_handler(data);
}
else {
displayMessage(data.message,errtype);
getitems(menu);
processingStop();
}
});
d.addErrback(function() {
displayMessage(get_string('unknownerror'),'error');
processingStop();
});
return false;
}
function getadminfiles() {
return null;
}
var menu = 'public';
addLoadEvent(function () {getitems(menu);});
EOJS;
$style = '<style type="text/css">.invisible{display:none;} .menueditcell{width:200px;}</style>';
$strings = array('deletefailed','deletingmenuitem','menuitemdeleted','noadminfiles',
'edit','delete','update','cancel');
$smarty = smarty(array(),array($style),$strings);
$smarty->assign('INLINEJAVASCRIPT',$ijs);
$smarty->display('admin/editmenu.tpl');
?>
......@@ -43,7 +43,6 @@ $f = array(
'ajaxpost' => true,
'ajaxsuccessfunction' => 'contentSaved',
'ajaxformhandler' => 'savesitepage.json.php',
//'onsubmit' => 'return submitForm(\'editsitepage\',\'savesitepage.json.php\',contentSaved);',
'action' => '',
'elements' => array(
'pagename' => array(
......
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
$menu = get_variable('menu');
$public = $menu == 'public' ? 1 : 0;
$result = array();
try {
$menuitems = get_records('site_menu','public',$public,'displayorder');
// @todo: Get all the filenames of the files referred to in the $menuitems records.
// (files table doesn't exist yet)
$rows = array();
foreach ($menuitems as $i) {
$r = array();
$r['id'] = $i->id;
$r['name'] = $i->title;
if (empty($i->url) && !empty($i->file)) {
$r['type'] = 'adminfile';
$r['linkedto'] = $i->file; // @todo: substitute the appropriate filename.
// $r['link'] = ''; // @todo: provide a link to the file
}
else if (!empty($i->url) && empty($i->file)) {
$r['type'] = 'externallink';
$r['linkedto'] = $i->url;
// $r['link'] = $i->url;
}
else {
throw new Exception ('Exactly one of {file,url} should be set in site_menu table');
}
$rows[] = $r;
}
$result['menuitems'] = array_values($rows);
$result['error'] = false;
$result['message'] = get_string('sitemenuloaded');
}
catch (Exception $e) {
$result['error'] = 'local';
$result['message'] = get_string('failedloadingsitemenu');
}
echo json_encode($result);
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
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';
$result['message'] = get_string('savefailed');
echo json_encode($result);
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);
$data = new StdClass;
if ($type == 'adminfile') {
// Get file id.
$data->file = $linkedto;
}
else if ($type == 'externallink') {
$data->url = $linkedto;
}
else { // Bad menu item type
send_fail_message();
}
$data->title = $name;
$data->public = $menu == 'public' ? 1 : 0;
if ($itemid == 'new') {
// set displayorder to be after all the existing menu items
try {
$displayorders = get_rows('site_menu', '', '', '', 'displayorder');
$max = 0;
foreach ($displayorders as $r) {
$max = $r['displayorder'] >= $max ? $r['displayorder'] + 1 : $max;
}
$data->displayorder = $max;
insert_record('site_menu', $data);
}
catch (Exception $e) {
send_fail_message();
}
}
else {
$data->id = $itemid;
log_debug($data);
try {
update_record('site_menu', $data, 'id');
}
catch (Exception $e) {
send_fail_message();
}
}
$result = array();
$result['error'] = false;
$result['message'] = get_string('savedsuccessfully');
echo json_encode($result);
?>
......@@ -107,6 +107,14 @@ $string['forgotpassemailmessagehtml'] = '<p>Dear $fullname,</p>
<p><a href="' . get_config('wwwroot') . 'forgotpass.php?key=%s">' . get_config('wwwroot') . 'forgotpass.php?key=%s</a></p>';
// Admin menu editor
$string['adminfile'] = 'Admin file';
$string['externallink'] = 'External link';
$string['type'] = 'Type';
$string['name'] = 'Name';
$string['noadminfiles'] = 'No admin files';
$string['linkedto'] = 'Linked to';
// Admin site page editor
$string['discardpageedits'] = 'Discard your changes to this page?';
$string['pagecontents'] = 'Text to appear on the page';
......
......@@ -379,13 +379,13 @@
</TABLE>
<TABLE NAME="usr_group_member">
<FIELDS>
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="grp" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="member" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="group,member" />
<KEY NAME="groupfk" TYPE="foreign" FIELDS="group" REFTABLE="usr_group" REFFIELDS="id" />
<KEY NAME="primary" TYPE="primary" FIELDS="grp,member" />
<KEY NAME="grpfk" TYPE="foreign" FIELDS="grp" REFTABLE="usr_group" REFFIELDS="id" />
<KEY NAME="memberfk" TYPE="foreign" FIELDS="member" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
......@@ -571,12 +571,12 @@
<TABLE NAME="view_access_group">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="grp" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="view,group" />
<KEY NAME="primary" TYPE="primary" FIELDS="view,grp" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="groupfk" TYPE="foreign" FIELDS="group" REFTABLE="usr_group" REFFIELDS="id" />
<KEY NAME="grpfk" TYPE="foreign" FIELDS="grp" REFTABLE="usr_group" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_access_usr">
......@@ -602,6 +602,7 @@
<FIELD NAME="file" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="url" TYPE="text" NOTNULL="false" />
<FIELD NAME="displayorder" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="public" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<!--- public? -->
<!-- displayorder maybe should be the primary key -->
</FIELDS>
......
......@@ -705,9 +705,9 @@ class Form {
if (!function_exists($js_messages_function)) {
throw new FormException('No renderer message function "' . $js_messages_function . '"');
}
if (!isset($submitname)) {
throw new FormException('Submit element required for js messages');
}
}
if (!isset($submitname)) {
throw new FormException('Submit element required for js messages');
}
return $result . $js_messages_function($this->name,$submitname);
//return $result;
......@@ -738,7 +738,7 @@ class Form {
$result .= "var d = sendXMLHttpRequest(req,queryString(data));\n";
$result .= 'd.addCallback(function (result) {';
$result .= 'var data = evalJSONRequest(result);';
$result .= "var errtype = 'global'\n";
$result .= "var errtype = 'global';\n";
$result .= "if (!data.error) { errtype = 'info'; }\n";
$result .= "if (data.error == 'local') { errtype = 'error'; }\n";
$result .= "if (errtype == 'global') { global_error_handler(data); }\n";
......
{include file="header.tpl"}
<p>Admin menu editor</p>
<table id="menuitemlist" class="menueditor"><tbody><tr><td></td></tr></tbody></table>
{include file="footer.tpl"}
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