Lock some fields in settings screen for teachers

Lock some fields in settings screen for teachers

by Peter Easton -
Number of replies: 2
I was wondering if there was a way to lock some of the fields on the course settings screen so that faculty can't change important settings like:
Category:
Full name:
Short name:
Course ID number:
Summary:
These are items that we set but any teacher can unset.

I can do it in the edit.html file but then they are locked for all.
And I didn't see any specific item in the roles that would cover it.

Pete
Average of ratings: -
In reply to Peter Easton

Re: Lock some fields in settings screen for teachers

by Ger Tielemans -

The trick is to change as little as possible:

  • so, put the input field inside the second part of a condition block:

if isteacher() { first part:DO NOT SHOW INPUT} //do nothing, teachers like that
                   else
                   { second part: SHOW HERE INPUT FIELD IN THE NORMAL WAY}

  • copy the code lines around and including the input field
  • put this in the first part
  • hide the echo of label text for this input field in the first part
  • change the value "text" into "hidden" for this input field

explanation: most of he time you have an input field, but if you remove that one, some html-input-pages (like mod.html) complain about an empty field.  

In reply to Ger Tielemans

Re: Lock some fields in settings screen for teachers

by Ger Tielemans -

Sorry, wrong example for this case, it should be:

if isadmin() { show input field with value "text"}

     else { hide input field with value "hidden"}


explanation: Moodle often fills the input field with a value from the database end writes at the end that (changed) value back into the database.

Remove or // the input field will disturb that procedure.