Commit 3645f69f authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents 3bd1f8b6 e5683623
......@@ -31,15 +31,10 @@ require(dirname(dirname(__FILE__)) . '/init.php');
$itemid = param_variable('itemid');
$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();
if (!delete_records('site_menu','id',$itemid)) {
json_reply('local', get_string('deletefailed','admin'));
}
echo json_encode($result);
json_reply(false,get_string('deletedsuccessfully','admin'));
?>
......@@ -31,16 +31,14 @@ require(dirname(dirname(__FILE__)) . '/init.php');
$pagename = param_alpha('pagename');
$data['pagename'] = $pagename;
try {
$page = get_record('site_content','name',$pagename);
$data['content'] = $page->content;
$data['error'] = false;
$data['message'] = get_string('loadedsitecontent');
}
catch (Exception $e) {
$data['error'] = 'local';
$data['message'] = get_string('failedloadingsitecontent');
if (!$page = @get_record('site_content','name',$pagename)) {
json_reply('local',get_string('failedloadingsitecontent','admin'));
}
$data['content'] = $page->content;
$data['error'] = false;
$data['message'] = get_string('loadedsitecontent','admin');
json_headers();
echo json_encode($data);
?>
......@@ -191,21 +191,32 @@ function edititem(item) {
menuitem.parentNode.insertBefore(newrow,menuitem);
}
// Receive standard json error message
function get_json_status(data) {
var errtype = 'global';
if (!data.error) {
errtype = 'info';
}
else if (data.error == 'local') {
errtype = 'error';
}
else {
global_error_handler(data);
}
if (errtype != 'global') {
displayMessage(data.message,errtype);
getitems();
processingStop();
}
}
// Request deletion of a menu item from the db
function delitem(itemid) {
processingStart();
//displayMessage(get_string('deletingmenuitem','admin'),'info');
logDebug(get_string('deletingmenuitem','admin'));
var d = loadJSONDoc('deletemenuitem.json.php',{'itemid':itemid});
d.addCallback(function(data) {
if (data.success) {
logDebug(get_string('menuitemdeleted','admin'));
getitems();
}
else {
displayMessage(get_string('deletefailed','admin'),'error');
}
processingStop();
});
d.addCallback(get_json_status);
}
// Send the menu item in the form to the database.
......@@ -222,7 +233,8 @@ function saveitem(formid) {
return false;
}
processingStart();
displayMessage(get_string('savingmenuitem','admin'),'info');
//displayMessage(get_string('savingmenuitem','admin'),'info');
logDebug(get_string('savingmenuitem','admin'));
var data = {'type':f.type[0].checked ? 'externallink' : 'adminfile',
'name':name,
'linkedto':linkedto,
......@@ -234,21 +246,7 @@ function saveitem(formid) {
var d = sendXMLHttpRequest(req,queryString(data));
d.addCallback(function (result) {
var data = evalJSONRequest(result);
var errtype = 'global';
if (!data.error) {
errtype = 'info';
}
else if (data.error == 'local') {
errtype = 'error';
}
else {
global_error_handler(data);
}
if (errtype != 'global') {
displayMessage(data.message,errtype);
getitems();
processingStop();
}
get_json_status(data);
});
d.addErrback(function() {
displayMessage(get_string('unknownerror'),'error');
......
......@@ -32,40 +32,35 @@ $public = (int) param_boolean('public');
$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();
if ($menuitems) {
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;
$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();
if ($menuitems) {
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 {
json_reply('local',get_string('failedloadingsitemenu','admin'));
}
$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');
}
$result['menuitems'] = array_values($rows);
$result['error'] = false;
$result['message'] = get_string('sitemenuloaded','admin');
json_headers();
echo json_encode($result);
?>
......@@ -43,7 +43,7 @@ else if ($type == 'externallink') {
$data->url = $linkedto;
}
else { // Bad menu item type
json_reply('local',get_string('badmenuitemtype'));
json_reply('local',get_string('badmenuitemtype','admin'));
}
$data->title = $name;
......@@ -62,7 +62,7 @@ if ($itemid == 'new') {
insert_record('site_menu', $data);
}
catch (Exception $e) {
json_reply('local',get_string('savefailed'));
json_reply('local',get_string('savefailed','admin'));
}
}
else {
......@@ -71,7 +71,7 @@ else {
update_record('site_menu', $data, 'id');
}
catch (Exception $e) {
json_reply('local',get_string('savefailed'));
json_reply('local',get_string('savefailed','admin'));
}
}
......
......@@ -94,6 +94,9 @@ class ArtefactTypeProfile extends ArtefactType {
if (!empty($data['owner'])) {
if ($a = get_record('artefact', 'artefacttype', $type, 'owner', $data['owner'])) {
return parent::__construct($a->id, $a);
}
else {
$this->owner = $data['owner'];
}
}
$this->ctime = time();
......
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