This topic is locked
[SOLVED]

 disabling edit selected and delete selected on list page

1/30/2012 10:45:06 AM
PHPRunner General questions
F
Francesco_5000 author

i want to disable 'Edit selected'/'Delete selected' buttons if a user does not belong to certain groups. So I did the following... i've put a code snippet in the list page:

$sql2 = "SELECT GroupID FROM antitaccheggio_ugmembers WHERE UserName ='".$_SESSION["UserID"]."'";

$rs2=CustomQuery($sql2);

$data2=db_fetch_array($rs2);
$group2=$data2["GroupID"];
echo "<script>
window.group = '" . $group2. "';
</script>";


then i wrote this code in Javascript onload event



var ctrlEditSelected = $('#edit_selected'+pageid);
var ctrlDeleteSelected = $('#delete_selected'+pageid);
if ((group!=-1) || (group!=7))
{
ctrlEditSelected.hide();
ctrlDeleteSelected.hide();
}


as it's possible to see if I want to restrict access to only two groups, the code does not work... it's clear that I am wrong but I don't know where.
Apart this fact, I'm wondering if can get the same effect via php. I tried to follow this example: http://xlinesoft.com/phprunner/docs/disable_record_editing.htm , but



$record["deleteselected_link"] = false;

.
doesn't works.

C
cgphp 1/30/2012

In the "Before display" event:

$xt->assign("deleteselected_link",false);
F
Francesco_5000 author 1/30/2012



In the "Before display" event:

$xt->assign("deleteselected_link",false);



thank you Cristian as usual a very good answer, i want to post here the code, just in case someone else have the same problem:



// before display event
$sql2 = "SELECT GroupID FROM antitaccheggio_ugmembers WHERE UserName ='".$_SESSION["UserID"]."'";

$rs2=CustomQuery($sql2);

$data2=db_fetch_array($rs2);
$authorized_groups2 = array(-1,7);
$group2=$data2["GroupID"];
if ( (!in_array($group2,$authorized_groups2)) ) {
$xt->assign("deleteselected_link",false);

$xt->assign("editselected_link",false);
}