Commit 1615c9cd authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use json_reply

parent f77cc5f9
......@@ -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','admin');
}
catch (Exception $e) {
$result['error'] = 'local';
$result['message'] = get_string('failedloadingsitemenu','admin');
}
$result['menuitems'] = array_values($rows);
$result['error'] = false;
$result['message'] = get_string('sitemenuloaded','admin');
json_headers();
echo json_encode($result);
?>
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