Using Mal rights in other menu's than Mambo's Mainmenu PDF Print E-mail

MAL has a module which you can use to replace the original mainmenu but what if you want to use other menu's like topmenu etc? Here we are describing what we do in our mal_mainmenu module so you can use this example to alter the other menu's

1) on line 203

Change

// establish the hierarchy of the menu

$children = array();

To

// establish the hierarchy of the menu
$skip = array(); //konlong added for access test
$children = array();


2) line 207-210

Change

foreach ($rows as $v ) {
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}

To

foreach ($rows as $v ) {
if (skipit($params, $v->id)) { //konlong added if clause for access test
$skip[$v->id] = 1;
continue;
}
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}


3) line 284-290

Change

$links = array();
foreach ($rows as $row) {
$links[] = mosGetMenuLink( $row, 0, $params );
}

To

$links = array();
foreach ($rows as $row) {
if (skipit($params, $row->id)) { //konlong added if clause for access test
continue;
}
$links[] = malGetMenuLink( $row, 0, $params );
}


4) line 314-357

Add

function skipit( &$params, $row_id) { //konlong added function for access test

global $database;
$mal_test_style = $params->get('mal_test_style');
$mal_user_acl = $params->get('mal_user_acl');
$mal_max_acl = $params->get('mal_max_acl');
$mal_acl = $mal_max_acl;
$sql = "SELECT `level` FROM mos_mal_siteaccess WHERE `typeid`='".$row_id."' AND `type`='". $params->get( 'menutype' ) ."'";
$database->setQuery($sql);
$mal_acl = $database->loadResult();
echo $database->getErrorMsg();
if (!isset($mal_acl)) {
$mal_acl = $mal_max_acl;
}

if ($mal_acl != $mal_max_acl ){
if (!$mal_test_style)
{ //Use a Ladder style Hiearchy to permit access
if ($mal_acl < 0 || $mal_user_acl > $mal_acl) {
return 1;
}
}else
{ //Permit access only if the Access rights are EQUAL
if ($mal_acl < 0 || $mal_user_acl != $mal_acl) {
return 1;
}
}
}
return 0;
}
} // End of function wrap
// konlong added query of component to obtain needed parameters
$query = "SELECT id FROM mos_components WHERE admin_menu_link = 'option=com_mal_siteaccess'";
$database->setQuery( $query );
$id = $database->loadResult();
$compt = new mosComponent( $database );
$compt->load( $id );
$kl_params = new mosParameters( $compt->params );
//$kl_params->get('mal_test_style')
//$kl_params->get('mal_user_acl')

before the line $params->def( 'menutype', 'mainmenu' );


5) line 373-407

Add

//konlong - get parameters and check access rights to menu as a whole
$params->set( 'mal_test_style', $kl_params->get('mal_test_style') );
$params->set( 'mal_user_acl', $kl_params->get('mal_user_acl') );
$params->set( 'mal_max_acl', $kl_params->get('mal_user_acl') );
$mal_u_acl = $params->get( 'mal_max_acl');
if ($my->id)
{
$database->setQuery("SELECT user_type "
."nFROM mos_mal_access"
."nWHERE id='".$my->id."'");
$mal_u_acl = $database->loadResult();
if (!isset($mal_u_acl))
{
$mal_u_acl = $params->get( 'mal_user_acl');
}
}
if ($mal_u_acl < 0) {
// This user has lost all access rights,
return;
}
/*
if (($kl_params->get('mal_test_style') && $mal_u_acl != $params->get('mal_user_acl'))
||
(!$kl_params->get('mal_test_style') && $mal_u_acl > $params->get('mal_user_acl'))){
// or the users access rights are not sufficient to view the menu.
return;
}
*/
$params->set( 'mal_user_acl', $mal_u_acl ); // Use the params array to pass the users access rights.

Before the line $menu_style = $params->get( 'menu_style', 'vert_indent' );


5) change all function calls with mos* to mal*.

Example mosShowVIMenu to malShowVIMenu

Or change the corresponding calls in our routines to the original mos* function.

 

 

 

 
< Prev
Mambobrothers