Пример #1
0
 /**
  * Assign the users to the track.
  *
  * @param array $elements An array of user information to assign to the track.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array An array to format as JSON and return to the Javascript.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     global $DB;
     $trkid = required_param('id', PARAM_INT);
     $track = new track($trkid);
     // Permissions.
     if (trackpage::can_enrol_into_track($track->id) !== true) {
         return array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram'));
     }
     foreach ($elements as $userid => $label) {
         if ($this->can_assign($track->id, $userid) === true) {
             usertrack::enrol($userid, $track->id);
         }
     }
     return array('result' => 'success', 'msg' => 'Success');
 }
Пример #2
0
 function can_do_add()
 {
     //note: actual permission checking happens in usertrackpopup.php
     $id = $this->required_param('id', PARAM_INT);
     return trackpage::can_enrol_into_track($id);
 }
Пример #3
0
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user and a track
  *
  * @param    int      $userid    The id of the user being associated to the track
  * @param    int      $trackid   The id of the track we are associating the user to
  *
  * @return   boolean             True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $trackid)
 {
     global $USER, $DB;
     //get the context for the "indirect" capability
     $context = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:track_enrol_userset_user', $USER->id);
     $allowed_clusters = array();
     // TODO: Ugly, this needs to be overhauled
     $tpage = new trackpage();
     if (!trackpage::can_enrol_into_track($trackid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if ($tpage->_has_capability('local/elisprogram:track_enrol', $trackid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the clusters and check the context against them
     $clusters = clustertrack::get_clusters($trackid);
     $allowedclusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid');
     // Query to get users associated to at least one enabling cluster.
     $clusterselect = '';
     if (empty($allowedclusters)) {
         $clusterselect = '0=1';
     } else {
         $clusterselect = 'clusterid IN (' . implode(',', $allowedclusters) . ')';
     }
     $select = "userid = ? AND " . $clusterselect;
     $params = array($userid);
     // User just needs to be in one of the possible clusters.
     if ($DB->record_exists_select(clusterassignment::TABLE, $select, $params)) {
         return true;
     }
     return false;
 }
Пример #4
0
 /**
  * Determine whether the current user can assign users to this track.
  *
  * @return bool Whether the user can assign users to this track or not.
  */
 public function can_do_add()
 {
     $id = $this->required_param('id', PARAM_INT);
     return trackpage::can_enrol_into_track($id);
 }
Пример #5
0
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user and a track
  * 
  * @param    int      $userid    The id of the user being associated to the track
  * @param    int      $trackid   The id of the track we are associating the user to
  * 
  * @return   boolean             True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $trackid)
 {
     global $USER;
     //get the context for the "indirect" capability
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:track:enrol_cluster_user', $USER->id);
     $allowed_clusters = array();
     if (!trackpage::can_enrol_into_track($trackid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if (trackpage::_has_capability('block/curr_admin:track:enrol', $trackid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the clusters and check the context against them
     $clusters = clustertrack::get_clusters($trackid);
     $allowed_clusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid');
     //query to get users associated to at least one enabling cluster
     $cluster_select = '';
     if (empty($allowed_clusters)) {
         $cluster_select = '0=1';
     } else {
         $cluster_select = 'clusterid IN (' . implode(',', $allowed_clusters) . ')';
     }
     $select = "userid = {$userid} AND {$cluster_select}";
     //user just needs to be in one of the possible clusters
     if (record_exists_select(CLSTUSERTABLE, $select)) {
         return true;
     }
     return false;
 }
Пример #6
0
$track = new track($trackid);
$userid = optional_param('userid', 0, PARAM_INT);
// get searching/sorting parameters
$sort = optional_param('sort', 'lastname', PARAM_ALPHA);
$alpha = optional_param('alpha', '', PARAM_ALPHA);
$namesearch = optional_param('namesearch', '', PARAM_MULTILANG);
$dir = optional_param('dir', 'ASC', PARAM_ALPHA);
if ($dir != 'ASC' && $dir != 'DESC') {
    $dir = 'ASC';
}
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 30, PARAM_INT);
$context = get_context_instance(context_level_base::get_custom_context_level('track', 'block_curr_admin'), $trackid);
//todo: integrate this better with user-track page?
//this checks permissions at the track level
if (!trackpage::can_enrol_into_track($trackid)) {
    //standard failure message
    require_capability('block/curr_admin:track:enrol', $context);
}
// add user to track
if ($userid) {
    //todo: integrate this better with user-track page?
    //this checks permissions at the user-track association level
    if (!usertrack::can_manage_assoc($userid, $trackid)) {
        //standard failure message
        require_capability('block/curr_admin:track:enrol', $context);
    }
    usertrack::enrol($userid, $trackid);
    // reload the main page with the new assignments
    $target = new trackuserpage(array('id' => $trackid));
    ?>