How to modify code to hide certain options in course admin

How to modify code to hide certain options in course admin

by Andy Chauhan -
Number of replies: 4

My problem is the following. Teachers/Course creators are able to see 2 links on the left course admin links. "Teachers..." and "Students..." amongst other links like, course, backup, restore etc. I want to hide the links "Teachers..." and "Students..." for everybody except the admin. Since I do not want any teacher or course creator to enroll or unenroll students. I tried to modify the function print_course_admin_links() in moodleroot/course/lib.php but modification of that function does not seem to effect the output at all. Can somebody pinpoint and  please let me know, which function in which file do I need to modify in order to accomplish this.

Average of ratings: -
In reply to Andy Chauhan

Re: How to modify code to hide certain options in course admin

by Genner Cerna -
try editing the files under the block...
In reply to Genner Cerna

Re: How to modify code to hide certain options in course admin

by Andy Chauhan -
Can you please let me know the path and name of the file in the moodle system. Also the function that displays the "Teachers..." and "Students..." links. The best I could hunt down is given above. Also I have modified the code for 1.1, however I am now using 1.3, almost the same code, but somehow on changing the display function, the output on the webpage does not seem to change.
In reply to Andy Chauhan

Re: How to modify code to hide certain options in course admin

by Genner Cerna -

file to edit... blocks/admin/block_admin.php

see sample: (in this sample only admin see the said link but not teachers...change the condition if you need to... of comment the code that you need to hide from admin)

if (isadmin()) {
            $admindata[]="<a href=\"$CFG->wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...</a>";
            $adminicon[]="<img src=\"$CFG->pixpath/i/backup.gif\" height=16 width=16 alt=\"\">";
       
            $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."...</a>";
            $adminicon[]="<img src=\"$CFG->pixpath/i/restore.gif\" height=16 width=16 alt=\"\">";
       }

In reply to Genner Cerna

Working!!!!!!!!!!!

by Andy Chauhan -

Thank you very much. You have hit the nail. However, the code on my installation looks little different(I am using Moodle 1.3.1). But it worked anyway. I defined a variable in config.php called $CFG->TEACHER and $CFG->STUDENT = 0 or 1 depending on if you want to display "Teachers..." and "Students..." links in the admin menu so the the functionality can be changed on fly. Then I modified the code as shown below. Where START and END block indicate the start of my code and end of my code bock.

NOTE: The code in print_course_admin_links() in course/lib.php is almost identical to this, and I was trying to modify that......which did not work!.

//START BLOCK------------------------------------------------------------------------------------------------
                    if(isadmin() or $CFG->TEACHER==1){
//END BLOCK------------------------------------------------------------------------------------------------
                        $this->content->items[]='<a href="teacher.php?id='.$this->course->id.'">'.$this->course->teachers.'...</a>';
                        $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="">';
//START BLOCK------------------------------------------------------------------------------------------------
                    }
//END BLOCK------------------------------------------------------------------------------------------------
                }

                if (!$this->course->students) {
                    $this->course->students = get_string('defaultcoursestudents');
                }
//START BLOCK------------------------------------------------------------------------------------------------
                    if(isadmin() or $CFG->STUDENT==1){
//END BLOCK------------------------------------------------------------------------------------------------
                $this->content->items[]='<a href="student.php?id='.$this->course->id.'">'.$this->course->students.'...</a>';
                $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="">';
//START BLOCK------------------------------------------------------------------------------------------------
                    }
//END BLOCK------------------------------------------------------------------------------------------------