Block context - is it Moodle being dumb or me?

Re: How to prevent editing-teachers from adding activities or blocks?

by J. Chan -
Number of replies: 0

Hi Yu Zhang

Thanks for your reply. I've tried some changes in some of my files. Now some of the problem I have below are solved:

  1. allow them to see the "edit this page" button
  2. allow them to manage exisiting activities ONLY
  3. allow them to move, show or hide existing blocks ONLY
  4. not allow them to add activities (= not seeing the pull-down menu to add activities)
  5. not allow them to add blocks (= not seeing the pull-down menu to add blocks).

but, some other strange problems occur today. Perhaps see if my "changes" of the files are OK.

For #2 and #4, I don't want them to see the pull-down of new activities and the "delete" button, so I did some changes in the course/lib.php file: I added the bolded lines to the following script:

    if (course_allowed_module($course,'label') && empty($resourceallowed)) {
        $modnames['label'] = get_string('modulename', 'label');
    }
    $output .= ' ';
     if (isadmin() or iscreator()) {                                   
    $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=$USER->sesskey&add=",
                $modnames, "section$section", "", $straddactivity, 'mods', $straddactivity, true);
}
    if ($vertical) {
        $output .= '</div>';
    }

and I added some lines :

 if (isadmin() or iscreator()) {                                   
    return '<span class="commands">'."\n".$leftright.$move.
           '<a class="editing_update" title="'.$str->update.'" href="'.$path.'/mod.php?update='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->update.'" /></a>'."\n".
             '<a title="'.$str->lock.'" href="'.$path.'/lock.php?id='.$mod->id.
     '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/lock.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->lock.'" /></a>'.$unlock.

           '<a class="editing_delete" title="'.$str->delete.'" href="'.$path.'/mod.php?delete='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/delete.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->delete.'" /></a>'.
           "\n".$hideshow.$groupmode."\n".'</span>';
}else{

before:

    return '<span class="commands">'."\n".$leftright.$move.
           '<a class="editing_update" title="'.$str->update.'" href="'.$path.'/mod.php?update='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->update.'" /></a>'."\n".
             '<a title="'.$str->lock.'" href="'.$path.'/lock.php?id='.$mod->id.
     '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/lock.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->lock.'" /></a>'.$unlock.

Also, I commented out the following lines (i.e. the underlined lines):

/*'<a class="editing_delete" title="'.$str->delete.'" href="'.$path.'/mod.php?delete='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/delete.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->delete.'" /></a>'.
*/
           "\n".$hideshow.$groupmode."\n".'</span>';
}

For #5 (not allow them to add blocks), I worked on the lib/blocklib.php: I added the bolded line to:

    if ($page->blocks_default_position() == $position && $page->user_is_editing()) {
     if (isadmin() or iscreator()) {                                   
        blocks_print_adminblock($page, $pageblocks);
    }
}
}

// This iterates over an array of blocks and calculates the preferred width
// Parameter passed by reference for speed; it's not modified.

Now, the editing-teacher can edit the pages but cannot add or delete an activity, also cannot add block. He can still (#3 be allowed them to move, show or hide existing blocks ONLY ).

Some other problems occur that is related to my resource page. I'm not sure of they are related. See here.

Cheers

James