[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/manual/ -> manage.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Manual user enrolment UI.
  19   *
  20   * @package    enrol_manual
  21   * @copyright  2010 Petr Skoda {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require('../../config.php');
  26  require_once($CFG->dirroot.'/enrol/manual/locallib.php');
  27  
  28  $enrolid      = required_param('enrolid', PARAM_INT);
  29  $roleid       = optional_param('roleid', -1, PARAM_INT);
  30  $extendperiod = optional_param('extendperiod', 0, PARAM_INT);
  31  $extendbase   = optional_param('extendbase', 3, PARAM_INT);
  32  
  33  $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST);
  34  $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
  35  $context = context_course::instance($course->id, MUST_EXIST);
  36  
  37  require_login($course);
  38  $canenrol = has_capability('enrol/manual:enrol', $context);
  39  $canunenrol = has_capability('enrol/manual:unenrol', $context);
  40  
  41  // Note: manage capability not used here because it is used for editing
  42  // of existing enrolments which is not possible here.
  43  
  44  if (!$canenrol and !$canunenrol) {
  45      // No need to invent new error strings here...
  46      require_capability('enrol/manual:enrol', $context);
  47      require_capability('enrol/manual:unenrol', $context);
  48  }
  49  
  50  if ($roleid < 0) {
  51      $roleid = $instance->roleid;
  52  }
  53  $roles = get_assignable_roles($context);
  54  $roles = array('0'=>get_string('none')) + $roles;
  55  
  56  if (!isset($roles[$roleid])) {
  57      // Weird - security always first!
  58      $roleid = 0;
  59  }
  60  
  61  if (!$enrol_manual = enrol_get_plugin('manual')) {
  62      throw new coding_exception('Can not instantiate enrol_manual');
  63  }
  64  
  65  $instancename = $enrol_manual->get_instance_name($instance);
  66  
  67  $PAGE->set_url('/enrol/manual/manage.php', array('enrolid'=>$instance->id));
  68  $PAGE->set_pagelayout('admin');
  69  $PAGE->set_title($enrol_manual->get_instance_name($instance));
  70  $PAGE->set_heading($course->fullname);
  71  navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id'=>$course->id)));
  72  
  73  // Create the user selector objects.
  74  $options = array('enrolid' => $enrolid, 'accesscontext' => $context);
  75  
  76  $potentialuserselector = new enrol_manual_potential_participant('addselect', $options);
  77  $currentuserselector = new enrol_manual_current_participant('removeselect', $options);
  78  
  79  // Build the list of options for the enrolment period dropdown.
  80  $unlimitedperiod = get_string('unlimited');
  81  $periodmenu = array();
  82  for ($i=1; $i<=365; $i++) {
  83      $seconds = $i * 86400;
  84      $periodmenu[$seconds] = get_string('numdays', '', $i);
  85  }
  86  // Work out the apropriate default setting.
  87  if ($extendperiod) {
  88      $defaultperiod = $extendperiod;
  89  } else {
  90      $defaultperiod = $instance->enrolperiod;
  91  }
  92  
  93  // Build the list of options for the starting from dropdown.
  94  $timeformat = get_string('strftimedatefullshort');
  95  $today = time();
  96  $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
  97  
  98  // Enrolment start.
  99  $basemenu = array();
 100  if ($course->startdate > 0) {
 101      $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')';
 102  }
 103  $basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
 104  
 105  // Process add and removes.
 106  if ($canenrol && optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
 107      $userstoassign = $potentialuserselector->get_selected_users();
 108      if (!empty($userstoassign)) {
 109          foreach($userstoassign as $adduser) {
 110              switch($extendbase) {
 111                  case 2:
 112                      $timestart = $course->startdate;
 113                      break;
 114                  case 3:
 115                  default:
 116                      $timestart = $today;
 117                      break;
 118              }
 119  
 120              if ($extendperiod <= 0) {
 121                  $timeend = 0;
 122              } else {
 123                  $timeend = $timestart + $extendperiod;
 124              }
 125              $enrol_manual->enrol_user($instance, $adduser->id, $roleid, $timestart, $timeend);
 126          }
 127  
 128          $potentialuserselector->invalidate_selected_users();
 129          $currentuserselector->invalidate_selected_users();
 130  
 131          //TODO: log
 132      }
 133  }
 134  
 135  // Process incoming role unassignments.
 136  if ($canunenrol && optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
 137      $userstounassign = $currentuserselector->get_selected_users();
 138      if (!empty($userstounassign)) {
 139          foreach($userstounassign as $removeuser) {
 140              $enrol_manual->unenrol_user($instance, $removeuser->id);
 141          }
 142  
 143          $potentialuserselector->invalidate_selected_users();
 144          $currentuserselector->invalidate_selected_users();
 145  
 146          //TODO: log
 147      }
 148  }
 149  
 150  
 151  echo $OUTPUT->header();
 152  echo $OUTPUT->heading($instancename);
 153  
 154  $addenabled = $canenrol ? '' : 'disabled="disabled"';
 155  $removeenabled = $canunenrol ? '' : 'disabled="disabled"';
 156  
 157  ?>
 158  <form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div>
 159    <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
 160  
 161    <table summary="" class="roleassigntable generaltable generalbox boxaligncenter" cellspacing="0">
 162      <tr>
 163        <td id="existingcell">
 164            <p><label for="removeselect"><?php print_string('enrolledusers', 'enrol'); ?></label></p>
 165            <?php $currentuserselector->display() ?>
 166        </td>
 167        <td id="buttonscell">
 168            <div id="addcontrols">
 169                <input name="add" <?php echo $addenabled; ?> id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
 170  
 171                <div class="enroloptions">
 172  
 173                <p><label for="menuroleid"><?php print_string('assignrole', 'enrol_manual') ?></label><br />
 174                <?php echo html_writer::select($roles, 'roleid', $roleid, false); ?></p>
 175  
 176                <p><label for="menuextendperiod"><?php print_string('enrolperiod', 'enrol') ?></label><br />
 177                <?php echo html_writer::select($periodmenu, 'extendperiod', $defaultperiod, $unlimitedperiod); ?></p>
 178  
 179                <p><label for="menuextendbase"><?php print_string('startingfrom') ?></label><br />
 180                <?php echo html_writer::select($basemenu, 'extendbase', $extendbase, false); ?></p>
 181  
 182                </div>
 183            </div>
 184  
 185            <div id="removecontrols">
 186                <input name="remove" id="remove" <?php echo $removeenabled; ?> type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
 187            </div>
 188        </td>
 189        <td id="potentialcell">
 190            <p><label for="addselect"><?php print_string('enrolcandidates', 'enrol'); ?></label></p>
 191            <?php $potentialuserselector->display() ?>
 192        </td>
 193      </tr>
 194    </table>
 195  </div></form>
 196  <?php
 197  
 198  
 199  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1