Show/Hide Toolbars

PHPRunner 9.8 Manual

Navigation: Advanced topics > Events > Global events

PHPrunner32x32     PHPRunner manual


Event: ModifyMenuItem

Scroll Prev Next More

 

Description

Function ModifyMenuItem is executed for each Menu item before a page is displayed in the browser. Use this event to modify or hide menu items.

Syntax

ModifyMenuItem($menuItem)

Arguments

$menuItem - menu item object.

Return value

True: menu item is shown.

False: menu item is hidden.

Methods

getLinkType() - get the link type. Link types are: Internal (link to a page generated by PHPRunner, e.g. List, Print etc.), External (link to any external web page), None (menu item is not a link, e.g. group or separator).

getUrl() - get the URL of external link.

setUrl($url) - set the link URL and make it external.

getParams() - get parameters of internal link.

setParams($params) - set parameters of internal link. These parameters may be also set on the Choose page screen using '...' button next to the List page. Parameters are concatenated with the link. E.g. if parameters are foo=bar&bar=foo, the link will be ..._list.php?foo=bar&bar=foo.

setTitle($title) - set the link title.

getTitle() - get the link title.

getTable() - get the table name, internal link points to.

setTable($table) - set the table name.

getPageType() - get the page type (List, Add, etc.).

setPageType($pType) - set the page type (List, Add, Search, Print, Report, Chart).

Applies to pages

All pages with Menu element. Insert your code into the Menu Item: Modify event.

Adding parameters to menu item

Menu Item: Modify event

if ($menuItem->getLinkType() == 'External')

  {

    $menuItem->setUrl('http://localhost/mn1/carsmodels_list.php');

  }

  else if($menuItem->getLinkType() == 'Internal')

  {

    $menuItem->setParams('id=30');

    if ($menuItem->getTable() == 'carsmake')

     {

        $menuItem->setTable('carsmodels');

     }

  }

  else

  {

    return false;

  }

  return true;

Hide some menu items based on the logged user

Hide some menu items based on the application users. If the menu item is the link to internal application page, you can assign the table permissions. However, if the menu item is an external link the permissions will have to be set in Menu Item: Modify event.

Menu Item: Modify event

if ($_SESSION["GroupID"]!="manager")

{

  $title = $menuItem->getTitle();

  if ($title=="Yahoo Finance")

     return false;

}

return true;

Display record counter next to each menu item

Display the record counter for each menu item. The code will validate if the menu item is an internal table or view and will concatenate the number of records with the menu item name.

Menu Item: Modify event

if($menuItem->getLinkType() == 'Internal')

{

  global $tables_data;

  $table=$menuItem->getTable();

  include_once(getabspath("include/".GetTableURL($table)."_settings.php"));

  $ps = new ProjectSettings($table);

  $table= $ps->getOriginalTableName();

  $rs=CustomQuery("select count(*) as c from " . AddTableWrappers($table));

  $data = db_fetch_array($rs);

  $menuItem->setTitle($menuItem->getTitle() . " (". $data["c"] . ")");

}

return true;

Hide some menu items in Mobile mode

  if ($menuItem->getTable() == 'Cars' && MobileDetected()) {

      return false;

  }

  return true;

 

Recommended predefined actions and sample events

Check to see if a specific record exists