Hi Abu, congratulations for your excelent work.
I need your help, I have a field called “Delegated to” wich only the admin can change:
$col = array();
$col[“title”] = “DELEGATED TO”;
$col[“name”] = “Deleg_to”; //field name in DB table
if ($level_acc==2){ //if user is administrator can change delegated to
$col[“editable”] = true;
$col[“edittype”] = “select”;
}
$col[“editoptions”] = array(“value”=>’1:Oswaldo;2:Rafael;3:Gaby;4:David’);
$cols[] = $col;
All others collumms can be edit by regular users (Oswaldo,Rafael,Gaby and David)
But now I want users to be able to edit the rows in which ones they are the delegates. I was traying with only one user but my attempts was unsuccsessful.
I am guiding me from demos/editing/column-access.php changing:
data.gender == ‘male’ from the example for data.Deleg_to !=’David’
And deleting all others parts of script. But is unsuccessful.
I hope you can help me.
Kind regards.
David
Hi David,
may you can change like this:
if ($level_acc==2){ $edit = “true”;}else{$edit=”false”;}
$col = array();
$col[“title”] = “DELEGATED TO”;
$col[“name”] = “Deleg_to”; //field name in DB table
$col[“editable”] = $edit;
$col[“edittype”] = “select”;
$col[“editoptions”] = array(“value”=>’1:Oswaldo;2:Rafael;3:Gaby;4:David’);
$cols[] = $col;
Regards,
Samsun
Thank you Samsun, your code is more clean that my code; but, can you helpme with the second part?:
“I want users to be able to edit the rows in which ones they are the delegates. I was traying with only one user but my attempts was unsuccsessful.
I am guiding me from demos/editing/column-access.php changing:
data.gender == ‘male’ from the example for data.Deleg_to !=’David’
And deleting all others parts of script. But is unsuccessful.”
Thank you again.
David
Assuming your logged in user id is available in $_SESSION[“user_id”], e.g. 1,2,3 or 4
You can put following in column Deleg_to:
$col[“editrules”] = array(“required”=>true, “readonly”=>true, “readonly-when”=>”check_client”);
And in HTML code, within script tag:
// readonly conditional function – when return true, field will be readonly
function check_client(formid)
{
var isAdmin = <?php echo ($level_acc==2) ? “1” : “0” ?>;
var currentUser = <?php echo $_SESSION[“user_id”] ?>;
if (isAdmin) return false;
Deleg_to = jQuery(“input[name=Deleg_to]:last, select[name=Deleg_to]:last”,formid).val();
Deleg_to = parseInt(Deleg_to);
if (Deleg_to == currentUser)
return false;
// for all others make it readonly
return true;
}