Hiding General settings from Teachers

Hiding General settings from Teachers

by Wes Sykes -
Number of replies: 5

I am new to using moodle and struggling to discover how to hide some general settings from teachers.

e.g. I do not want teachers to be able to change the following

  • full name
  • shortname
  • course ID number
  • Summary

Could anybody give me some idea as to what to do, if it can be done?

Thanks

Average of ratings: -
In reply to Wes Sykes

Re: Hiding General settings from Teachers

by Steve Hyndman -

You can't do this with roles. You will need to get into the code to accomplish this.

Steve

In reply to Wes Sykes

Re: Hiding General settings from Teachers

by sean behan -
if you have access to the code it is simple to change the type of the element being rendered. in this example i'll disable editing of the form element that is responsible for the course's fullname. you can apply this change to any element you like.

in course/edit_form.php around line 65, you can change the type of the element being rendered. for instance...

change 'text' to 'static' ...

$mform->addElement('text','fullname', get_string('fullname'),'maxlength="254" size="50"');

can be changed to...

$mform->addElement('static', 'fullname' ... //you don't need to adjust anything other than the first parameter of this function, from 'text' to 'static'.

if you do just this, you'll get an error when you try to update the form. you'll notice that there is a rule added to this element... about 3 lines down...

$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');

comment this line out with two forward slashes '//' like...

//$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');

this field is no longer a "required" element and so the form will now validate.

just be careful with this approach, because this will be applied to all courses, even new courses, that you the admin are creating... if it isn't required then you can create courses that are not valid. but this approach would work if you already have your catalog built and want to eliminate anyone from editing certain elements -even admins.

In reply to sean behan

Re: Hiding General settings from Teachers

by Wes Sykes -

Thanks for replying Sean what you have told me has helped a lot. 

Could you tell me if the is a role check for high level admin? 

I have tried $adminediting but teachers come under this heading and its teachers I want to block not the main administrators. 

Thanks again

Wes

In reply to sean behan

Re: Hiding General settings from Teachers

by Wes Sykes -

Hi Sean

know need to worry, I have discovered how to check the user role.

(using the has_capability() function) 

Thanks for your help

Wes

In reply to Wes Sykes

Re: Hiding General settings from Teachers

by sean behan -
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.