Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/roles/define.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00033     require_once(dirname(__FILE__) . '/../../config.php');
00034     require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
00035 
00036     $action = required_param('action', PARAM_ALPHA);
00037     if (!in_array($action, array('add', 'duplicate', 'edit', 'view'))) {
00038         throw new moodle_exception('invalidaccess');
00039     }
00040     if ($action != 'add') {
00041         $roleid = required_param('roleid', PARAM_INTEGER);
00042     } else {
00043         $roleid = 0;
00044     }
00045 
00047     $manageurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/manage.php';
00048     $defineurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/define.php';
00049     if ($action == 'duplicate') {
00050         $baseurl = $defineurl . '?action=add';
00051     } else {
00052         $baseurl = $defineurl . '?action=' . $action;
00053         if ($roleid) {
00054             $baseurl .= '&amp;roleid=' . $roleid;
00055         }
00056     }
00057 
00059     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00060     require_login();
00061     require_capability('moodle/role:manage', $systemcontext);
00062     admin_externalpage_setup('defineroles', '', array('action' => $action, 'roleid' => $roleid), $defineurl);
00063 
00065     if (optional_param('cancel', false, PARAM_BOOL)) {
00066         redirect($manageurl);
00067     }
00068 
00070     $showadvanced = get_user_preferences('definerole_showadvanced', false);
00071     if (optional_param('toggleadvanced', false, PARAM_BOOL)) {
00072         $showadvanced = !$showadvanced;
00073         set_user_preference('definerole_showadvanced', $showadvanced);
00074     }
00075 
00077     $roles = get_all_roles();
00078     $rolenames = role_fix_names($roles, $systemcontext, ROLENAME_ORIGINAL);
00079     $rolescount = count($roles);
00080 
00082     if ($action == 'view') {
00083         $definitiontable = new view_role_definition_table($systemcontext, $roleid);
00084     } else if ($showadvanced) {
00085         $definitiontable = new define_role_table_advanced($systemcontext, $roleid);
00086     } else {
00087         $definitiontable = new define_role_table_basic($systemcontext, $roleid);
00088     }
00089     $definitiontable->read_submitted_permissions();
00090     if ($action == 'duplicate') {
00091         $definitiontable->make_copy();
00092     }
00093 
00095     if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey() && $definitiontable->is_submission_valid()) {
00096         $definitiontable->save_changes();
00097         add_to_log(SITEID, 'role', $action, 'admin/roles/define.php?action=view&roleid=' .
00098                 $definitiontable->get_role_id(), $definitiontable->get_role_name(), '', $USER->id);
00099         redirect($manageurl);
00100     }
00101 
00103     echo $OUTPUT->header();
00104 
00105     $currenttab = 'manage';
00106     include('managetabs.php');
00107 
00108     if ($action == 'add') {
00109         $title = get_string('addinganewrole', 'role');
00110     } else if ($action == 'duplicate') {
00111         $title = get_string('addingrolebycopying', 'role', $rolenames[$roleid]->localname);
00112     } else if ($action == 'view') {
00113         $title = get_string('viewingdefinitionofrolex', 'role', $rolenames[$roleid]->localname);
00114     } else if ($action == 'edit') {
00115         $title = get_string('editingrolex', 'role', $rolenames[$roleid]->localname);
00116     }
00117     echo $OUTPUT->heading_with_help($title, 'roles', 'role');
00118 
00120     if ($action == 'add' || $action == 'duplicate') {
00121         $submitlabel = get_string('createthisrole', 'role');
00122     } else {
00123         $submitlabel = get_string('savechanges');
00124     }
00125 
00127     if ($action == 'view') {
00128         echo $OUTPUT->container_start('buttons');
00129         $options = array();
00130         $options['roleid'] = $roleid;
00131         $options['action'] = 'edit';
00132         echo $OUTPUT->single_button(new moodle_url($defineurl, $options), get_string('edit'));
00133         $options['action'] = 'reset';
00134         if ($definitiontable->get_archetype()) {
00135             echo $OUTPUT->single_button(new moodle_url($manageurl, $options), get_string('resetrole', 'role'));
00136         } else {
00137             echo $OUTPUT->single_button(new moodle_url($manageurl, $options), get_string('resetrolenolegacy', 'role'));
00138         }
00139         $options['action'] = 'duplicate';
00140         echo $OUTPUT->single_button(new moodle_url($defineurl, $options), get_string('duplicaterole', 'role'));
00141         echo $OUTPUT->single_button(new moodle_url($manageurl), get_string('listallroles', 'role'));
00142         echo $OUTPUT->container_end();
00143     }
00144 
00145     // Start the form.
00146     echo $OUTPUT->box_start('generalbox');
00147     if ($action == 'view') {
00148         echo '<div class="mform">';
00149     } else {
00150     ?>
00151 <form id="rolesform" class="mform" action="<?php echo $baseurl; ?>" method="post"><div>
00152 <input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
00153 <div class="submit buttons">
00154     <input type="submit" name="savechanges" value="<?php echo $submitlabel; ?>" />
00155     <input type="submit" name="cancel" value="<?php print_string('cancel'); ?>" />
00156 </div>
00157     <?php
00158     }
00159 
00160     // Print the form controls.
00161     $definitiontable->display();
00162 
00164     if ($action == 'view') {
00165         echo '</div>';
00166     } else {
00167         ?>
00168 <div class="submit buttons">
00169     <input type="submit" name="savechanges" value="<?php echo $submitlabel; ?>" />
00170     <input type="submit" name="cancel" value="<?php print_string('cancel'); ?>" />
00171 </div>
00172 </div></form>
00173         <?php
00174     }
00175     echo $OUTPUT->box_end();
00176 
00178     echo '<div class="backlink">';
00179     echo '<p><a href="' . $manageurl . '">' . get_string('backtoallroles', 'role') . '</a></p>';
00180     echo '</div>';
00181 
00182     echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations