Menu Docs
From PikaDocs
We needed a reference to the values that many of our menus actually represent in the database (mostly for reporting purposes). We simply re-purposed the admin menu editor feature (system-menus.php), made it display only and added an item to display the users list as well.
- Step 1. Copy system-menus.php to a new file (we use menus-display.php).
- Step 2. In the new file: Add this line of code:
pl_menu_set_temp('user_id', $pk->fetchStaffArray());
Which adds the staff menu to the list, just above this line:
$plTemplate["page_title"] = "Menus";
- Step 3. Delete these lines of code, since we want all users to have access to this:
if (!pika_authorize("system", $dummy))
{
$plTemplate["content"] = "Access denied";
$plTemplate["nav"] = "<a href=site_map.php class=light>$pikaNavRootLabel</a> > Menus";
echo pl_template($plTemplate, 'templates/default.html');
echo pl_bench('results');
exit();
}
- Step 4. Replace this section:
case 'edit':
$C .= "<form action='system-ops.php' method=POST>";
$C .= "<textarea name=values rows=20 cols=80>";
$menu_items = pl_menu_get($menu);
while (list($key, $val) = each($menu_items))
{
$C .= "{$key} | {$val}\n";
}
$C .= "</textarea><br>
<input type=hidden name='action' value='save_menu'>
<input type=hidden name='menu' value='$menu'>
<input type=submit value='Save'></form>";
$plTemplate["nav"] = "<a href=site_map.php class=light>$pikaNavRootLabel</a> > <a href=system-menus.php class=light>Menus</a> > editing $menu";
break;
case 'compose':
die();
$C .= "<form action='system-ops.php' method=POST>";
$C .= "<p>Menu Name:<br>\n <input name='menu'></p>";
$C .= "<textarea name=values rows=20 cols=80>";
$C .= "</textarea><br>
<input type=hidden name='action' value='add_menu'>
<input type=hidden name='menu' value='$menu'>
<input type=submit value='Add'></form>";
$plTemplate["nav"] = "<a href=site_map.php class=light>$pikaNavRootLabel</a> > <a href=system-menus.php class=light>Menus</a> > editing $menu";
break;
With this section:
case 'show':
$menu_items = pl_menu_get($menu);
$C .= "<table cellspacing='1' cellpadding='2' border='2'><tr><th>Database Value</th><th>Description</th></tr>";
while (list($key, $val) = each($menu_items))
{
$C .= "<tr><td align='right'>{$key}</td><td>{$val}</td></tr>\n";
}
$C .= "</table>";
$plTemplate["nav"] = "<a href=site_map.php class=light>$pikaNavRootLabel</a> > <a href=menus-display.php class=light>Menus</a> > displaying $menu";
break;
Since we don't want anyone to be editing these Menus, only displaying them.
- Step 5. Change:
$C .= "<p>Click on a menu to edit it:</p>\n";
to:
$C .= "<p>Click on a menu to display it:</p>\n";
- Step 6. Add:
$C .= "<li><a href='menus-display.php?screen=show&menu=user_id'>Staff</a><br>\n";
Just before:
while (list($key, $val) = each($menu_list))
{
$C .= "<li><a href='system-menus.php?screen=edit&menu=$val'>$val</a><br>\n";
- Step 7. Change the last line above to:
$C .= "<li><a href='menus-display.php?screen=show&menu=$val'>$val</a><br>\n";
That's it. You should now have a page that will display the menus to any valid user and also dump the user menu (to get user id's).
