Hiding General settings from Teachers

Re: Hiding General settings from Teachers

by sean behan -
Number of replies: 0
hi,
great! i wrote this earlier but got called away before i could post it.
here it is regardless...


it depends on which version of moodle you're running. in versions greater than 1.7, there is the is_siteadmin() funtion. this returns a true/false, based on the user's status on the site. located in lib/accesslib.php. prior to 1.7 you can call isadmin() .the function is defined in lib/deprecatedlib.php

$isadmin = isadmin(); //(version < 1.7)
or
$isadmin = is_siteadmin(); //(version > 1.7)


you could then do something like...

if($isadmin){ //function returned true
/* original code here */
} else { //it returned false
/* everyone else get the modified form */
}


Moodle has implemented the has_capability() function, much more flexible and compatible w/ the new roles system. also more complicated to implement. Here is a link to it's explanation in the moodle documentation.
http://docs.moodle.org/en/How_permissions_are_calculated

Another approach you could use is directly accessing the global $USER variable and check to see if the user is an admin. Most admins are given the 2nd account in the system (for security reasons, not the first) so you check if the admin's id equals 2. this condition could as well trigger the switch you need to make. example...

$isadmin = $USER->id; //

if($isadmin == 2) { /* orig. code here */ } else { /* old code here */ }
remember not to use the " = " sign. that will assign the the $isadmin variable
a value of 2. you need to use the " == " the double equals sign, checks that the variable is of the same value... or is identical to it.