コード例 #1
0
 function action_default()
 {
     global $USER, $CURMAN;
     $id = required_param('id', PARAM_INT);
     $contexts = clone trackpage::get_contexts('block/curr_admin:track:enrol');
     //look up student's cluster assignments with necessary capability
     $cluster_contexts = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:track:enrol_cluster_user', $USER->id);
     //calculate our filter condition based on cluster accessibility
     $cluster_filter = $cluster_contexts->sql_filter_for_context_level('clst.id', 'cluster');
     //query for getting tracks based on clusters
     $sql = "SELECT trk.id\n                FROM {$CURMAN->db->prefix_table(CLSTTABLE)} clst\n                JOIN {$CURMAN->db->prefix_table(CLSTTRKTABLE)} clsttrk\n                ON clst.id = clsttrk.clusterid\n                JOIN {$CURMAN->db->prefix_table(TRACKTABLE)} trk\n                ON clsttrk.trackid = trk.id\n                WHERE {$cluster_filter}";
     //assign the appropriate track ids
     $recordset = get_recordset_sql($sql);
     if ($recordset && $recordset->RecordCount() > 0) {
         if (!isset($contexts->contexts['track'])) {
             $contexts->contexts['track'] = array();
         }
         $new_tracks = array();
         while ($record = rs_fetch_next_record($recordset)) {
             $new_tracks[] = $record->id;
         }
         $contexts->contexts['track'] = array_merge($contexts->contexts['track'], $new_tracks);
     }
     $columns = array('idnumber' => get_string('track_idnumber', 'block_curr_admin'), 'name' => get_string('track_name', 'block_curr_admin'), 'description' => get_string('track_description', 'block_curr_admin'), 'numclasses' => get_string('num_classes', 'block_curr_admin'), 'manage' => '');
     $items = usertrack::get_tracks($id);
     $formatters = $this->create_link_formatters(array('idnumber', 'name'), 'trackpage', 'trackid');
     $this->print_list_view($items, $columns, $formatters, 'tracks');
     //get the listing specifically for this user
     $this->print_dropdown(track_get_listing('name', 'ASC', 0, 0, '', '', 0, 0, $contexts, $id), $items, 'userid', 'trackid', 'savenew', 'idnumber');
 }
コード例 #2
0
 function get_records($filter)
 {
     global $CURMAN, $USER;
     $id = $this->required_param('id', PARAM_INT);
     $sort = $this->optional_param('sort', 'name', PARAM_ALPHA);
     $dir = $this->optional_param('dir', 'ASC', PARAM_ALPHA);
     $pagenum = $this->optional_param('page', 0, PARAM_INT);
     $FULLNAME = sql_concat('usr.firstname', "' '", 'usr.lastname');
     $sql = "  FROM {$CURMAN->db->prefix_table(USRTABLE)} usr\n       LEFT OUTER JOIN {$CURMAN->db->prefix_table(CLSTASSTABLE)} ca ON ca.userid = usr.id AND ca.clusterid = {$id} AND ca.plugin = 'manual'\n                 WHERE ca.userid IS NULL";
     $extrasql = $filter->get_sql_filter();
     if ($extrasql) {
         $sql .= " AND {$extrasql}";
     }
     if (!clusterpage::_has_capability('block/curr_admin:cluster:enrol')) {
         //perform SQL filtering for the more "conditional" capability
         //get the context for the "indirect" capability
         $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster:enrol_cluster_user', $USER->id);
         $allowed_clusters = cluster::get_allowed_clusters($id);
         if (empty($allowed_clusters)) {
             $sql .= ' AND 0=1';
         } else {
             $cluster_filter = implode(',', $allowed_clusters);
             $sql .= " AND usr.id IN (\n                            SELECT userid FROM " . $CURMAN->db->prefix_table(CLSTUSERTABLE) . "\n                            WHERE clusterid IN ({$cluster_filter}))";
         }
     }
     $count = $CURMAN->db->count_records_sql('SELECT COUNT(usr.id) ' . $sql);
     if ($sort) {
         if ($sort == 'name') {
             $sort = 'lastname';
         }
         $sql .= " ORDER BY {$sort} {$dir}";
     }
     $users = $CURMAN->db->get_records_sql("SELECT usr.*, {$FULLNAME} AS name" . $sql, $pagenum * 30, 30);
     return array($users, $count);
 }
コード例 #3
0
 /**
  * Determines whether the current user is allowed to enrol users into the provided cluster
  *
  * @param   int      $clusterid  The id of the cluster we are checking permissions on
  *
  * @return  boolean              Whether the user is allowed to enrol users into the cluster
  *
  */
 static function can_enrol_into_cluster($clusterid)
 {
     global $USER;
     //check the standard capability
     if (clusterpage::_has_capability('block/curr_admin:cluster:enrol', $clusterid)) {
         return true;
     }
     $cluster = new cluster($clusterid);
     if (!empty($cluster->parent)) {
         //check to see if the current user has the secondary capability anywhere up the cluster tree
         $contexts = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster:enrol_cluster_user', $USER->id);
         return $contexts->context_allowed($clusterid, 'cluster');
     }
     return false;
 }
コード例 #4
0
 function get_records($filter)
 {
     global $USER;
     $sort = optional_param('sort', 'name', PARAM_ALPHA);
     $dir = optional_param('dir', 'ASC', PARAM_ALPHA);
     $pagenum = optional_param('page', 0, PARAM_INT);
     if ($sort == 'name') {
         $sort = 'lastname';
     }
     $extrasql = $filter->get_sql_filter();
     //filter based on cluster role assignments
     $context_set = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:user:edit', $USER->id);
     // Get list of users
     $items = usermanagement_get_users($sort, $dir, 30 * $pagenum, 30, $extrasql, $context_set);
     $numitems = usermanagement_count_users($extrasql, $context_set);
     return array($items, $numitems);
 }
コード例 #5
0
 /**
  * Determines whether the current user is allowed to enrol users into the provided curriculum
  *
  * @param   int      $curriculumid  The id of the curriculum we are checking permissions on
  *
  * @return  boolean                 Whether the user is allowed to enrol users into the curriculum
  *
  */
 static function can_enrol_into_curriculum($curriculumid)
 {
     global $USER;
     //check the standard capability
     if (curriculumpage::_has_capability('block/curr_admin:curriculum:enrol', $curriculumid)) {
         return true;
     }
     //get the context for the "indirect" capability
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:curriculum:enrol_cluster_user', $USER->id);
     //get the clusters and check the context against them
     $clusters = clustercurriculum::get_clusters($curriculumid);
     if (!empty($clusters)) {
         foreach ($clusters as $cluster) {
             if ($context->context_allowed($cluster->clusterid, 'cluster')) {
                 return true;
             }
         }
     }
     return false;
 }
コード例 #6
0
/**
 * Gets a curriculum listing with specific sort and other filters as a recordset.
 *
 * @param   string        $sort        Field to sort on.
 * @param   string        $dir         Direction of sort.
 * @param   int           $startrec    Record number to start at.
 * @param   int           $perpage     Number of records per page.
 * @param   string        $namesearch  Search string for curriculum name.
 * @param   string        $alpha       Start initial of curriculum name filter.
 * @param   array         $contexts    Contexts to search (in the form return by
 * @param   int           $userid      The id of the user we are assigning to curricula
 *
 * @return  recordset                  Returned recordset.
 */
function curriculum_get_listing_recordset($sort = 'name', $dir = 'ASC', $startrec = 0, $perpage = 0, $namesearch = '', $alpha = '', $contexts = null, $userid = 0)
{
    global $USER, $CURMAN;
    $LIKE = $CURMAN->db->sql_compare();
    $select = 'SELECT cur.*, (SELECT COUNT(*) FROM ' . $CURMAN->db->prefix_table(CURCRSTABLE) . ' WHERE curriculumid = cur.id ) as courses ';
    $tables = 'FROM ' . $CURMAN->db->prefix_table(CURTABLE) . ' cur ';
    $join = '';
    $on = '';
    $where = array("cur.iscustom = '0'");
    if ($contexts !== null && !empty($namesearch)) {
        $namesearch = trim($namesearch);
        $where[] = "(name {$LIKE}  '%{$namesearch}%')";
    }
    if ($alpha) {
        $where[] = "(name {$LIKE} '{$alpha}%')";
    }
    if ($contexts !== null) {
        $where[] = $contexts->sql_filter_for_context_level('cur.id', 'curriculum');
    }
    if (!empty($userid)) {
        //get the context for the "indirect" capability
        $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:curriculum:enrol_cluster_user', $USER->id);
        $clusters = cluster_get_user_clusters($userid);
        $allowed_clusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid');
        $curriculum_context = cm_context_set::for_user_with_capability('curriculum', 'block/curr_admin:curriculum:enrol', $USER->id);
        $curriculum_filter = $curriculum_context->sql_filter_for_context_level('cur.id', 'curriculum');
        if (empty($allowed_clusters)) {
            $where[] = $curriculum_filter;
        } else {
            $allowed_clusters_list = implode(',', $allowed_clusters);
            //this allows both the indirect capability and the direct curriculum filter to work
            $where[] = "(\n                          cur.id IN (\n                            SELECT clstcur.curriculumid\n                            FROM {$CURMAN->db->prefix_table(CLSTCURTABLE)} clstcur\n                            WHERE clstcur.clusterid IN ({$allowed_clusters_list})\n                          )\n                          OR\n                          {$curriculum_filter}\n                        )";
        }
    }
    if (!empty($where)) {
        $where = 'WHERE ' . implode(' AND ', $where) . ' ';
    } else {
        $where = '';
    }
    if ($sort) {
        $sort = 'ORDER BY ' . $sort . ' ' . $dir . ' ';
    }
    if (!empty($perpage)) {
        if ($CURMAN->db->_dbconnection->databaseType == 'postgres7') {
            $limit = 'LIMIT ' . $perpage . ' OFFSET ' . $startrec;
        } else {
            $limit = 'LIMIT ' . $startrec . ', ' . $perpage;
        }
    } else {
        $limit = '';
    }
    $sql = $select . $tables . $join . $on . $where . $sort . $limit;
    return get_recordset_sql($sql);
}
コード例 #7
0
 function get_content()
 {
     global $CFG, $ADMIN, $USER, $CURMAN, $HTTPSPAGEREQUIRED;
     require_once $CFG->libdir . '/adminlib.php';
     require_once $CFG->dirroot . '/my/pagelib.php';
     // dependencies on page classes
     require_once $CFG->dirroot . '/curriculum/clusterpage.class.php';
     require_once $CFG->dirroot . '/curriculum/curriculumpage.class.php';
     require_once $CFG->dirroot . '/curriculum/coursepage.class.php';
     require_once $CFG->dirroot . '/curriculum/trackpage.class.php';
     // ELIS-1251 - Don't display a useless message if in the center column
     //        if ($this->instance->position == BLOCK_POS_CENTRE) {
     //            $this->content = new stdClass;
     //            $output = "This is content to display if in the middle...";
     //            $this->content->text = $output;
     //            $this->content->footer = '';
     //            return $this->content;
     //        }
     /// Display a link to the admin interface if on the main site index page and the current user has
     /// admin or developer access.
     //        if ($this->instance->pageid == SITEID &&
     //            has_capability('block/curr_admin:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
     //
     //            $this->content = new stdClass;
     //            $this->content->text   = '<a href="' . $CFG->wwwroot . '/curriculum/index.php">' .
     //                                     get_string('accesscurriculumadmin', 'block_curr_admin') . '</a>';
     //            $this->content->footer = '';
     //        }
     /// Determine the users CM access level.
     $access = cm_determine_access($USER->id);
     $this->title = get_string("blocktitle{$access}", 'block_curr_admin');
     if (empty($access) || $this->content !== NULL) {
         return $this->content;
     }
     //if we are not on a CM "newpage", disable the expansion of
     //entities in the curr admin tree (logic in curriculum/index.php)
     if (!isset($CURMAN->page)) {
         unset($USER->currentitypath);
     }
     //include the necessary javascript libraries for the YUI TreeView
     require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_treeview'));
     //for converting tree representation
     require_js('yui_json');
     //for asynch request dynamic loading
     require_js('yui_connection');
     //include our custom code that handles the YUI Treeview menu
     if (!empty($HTTPSPAGEREQUIRED)) {
         $wwwroot = $CFG->httpswwwroot;
     } else {
         $wwwroot = $CFG->wwwroot;
     }
     require_js($wwwroot . '/curriculum/js/menuitem.js');
     //CM entities for placement at the top of the menu
     $cm_entity_pages = array();
     $cm_entity_pages[] = new menuitem('root');
     $num_block_icons = isset($CURMAN->config->num_block_icons) ? $CURMAN->config->num_block_icons : 5;
     /*****************************************
      * Clusters
      *****************************************/
     if (!isset($CURMAN->config->display_clusters_at_top_level) || !empty($CURMAN->config->display_clusters_at_top_level)) {
         $manageclusters_css_class = block_curr_admin_get_item_css_class('manageclusters');
         $cluster_css_class = block_curr_admin_get_item_css_class('cluster_instance');
         require_once CURMAN_DIRLOCATION . '/lib/contexts.php';
         $context_result = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster:view', $USER->id);
         $extrafilters = array('contexts' => $context_result, 'parent' => 0);
         $num_records = cluster_count_records('', '', $extrafilters);
         if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', $extrafilters)) {
             foreach ($clusters as $cluster) {
                 $params = array('id' => $cluster->id, 'action' => 'view');
                 // count sub-clusters
                 $cluster_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view'), 'parent' => $cluster->id);
                 $cluster_count = cluster_count_records('', '', $cluster_filter);
                 // count associated curricula
                 $curriculum_filter = array('contexts' => curriculumpage::get_contexts('block/curr_admin:curriculum:view'));
                 $curriculum_count = clustercurriculum::count_curricula($cluster->id, $curriculum_filter);
                 $isLeaf = empty($cluster_count) && empty($curriculum_count);
                 $cm_entity_pages[] = block_curr_admin_get_menu_item('cluster', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf);
             }
         }
         if ($num_block_icons < $num_records) {
             $cm_entity_pages[] = block_curr_admin_get_menu_summary_item('cluster', $cluster_css_class, $num_records - $num_block_icons);
         }
     }
     /*****************************************
      * Curricula
      *****************************************/
     if (!empty($CURMAN->config->display_curricula_at_top_level)) {
         $managecurricula_css_class = block_curr_admin_get_item_css_class('managecurricula');
         $curriculum_css_class = block_curr_admin_get_item_css_class('curriculum_instance');
         require_once CURMAN_DIRLOCATION . '/curriculumpage.class.php';
         $num_records = curriculum_count_records('', '', curriculumpage::get_contexts('block/curr_admin:curriculum:view'));
         if ($curricula = get_records(CURTABLE, '', '', 'priority ASC, name ASC', '*', 0, $num_block_icons)) {
             foreach ($curricula as $curriculum) {
                 $params = array('id' => $curriculum->id, 'action' => 'view');
                 // count associated courses
                 $course_filter = array('contexts' => coursepage::get_contexts('block/curr_admin:course:view'));
                 $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter);
                 // count associated tracks
                 $track_contexts = trackpage::get_contexts('block/curr_admin:track:view');
                 $track_count = track_count_records('', '', $curriculum->id, 0, $track_contexts);
                 // count associated clusters
                 $cluster_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster:view'));
                 $cluster_count = clustercurriculum::count_clusters($curriculum->id, 0, $cluster_filter);
                 $isLeaf = empty($course_count) && empty($track_count) && empty($cluster_count);
                 $cm_entity_pages[] = block_curr_admin_get_menu_item('curriculum', $curriculum, 'root', $managecurricula_css_class, 0, $curriculum->id, $params, $isLeaf);
             }
         }
         if ($num_block_icons < $num_records) {
             $cm_entity_pages[] = block_curr_admin_get_menu_summary_item('curriculum', $curriculum_css_class, $num_records - $num_block_icons);
         }
     }
     global $SITE;
     //general cm pages
     $pages = array(new menuitem('dashboard', new menuitempage('dashboardpage'), 'root', '', block_curr_admin_get_item_css_class('dashboard')), new menuitem('admn', null, 'root', get_string('admin'), block_curr_admin_get_item_css_class('admn', true)), new menuitem('bulkuser', new menuitempage('bulkuserpage'), null, get_string('userbulk', 'admin'), block_curr_admin_get_item_css_class('bulkuser')));
     //show the Jasper report server link if applicable
     if (cm_jasper_link_enabled()) {
         //page action
         $jasper_link_params = array('action' => 'reportslist');
         //page instance
         $jasper_link_page = new menuitempage('jasperreportpage', '', $jasper_link_params);
         //styling for the link
         $jasper_link_css = block_curr_admin_get_item_css_class('reportslist');
         $pages[] = new menuitem('reportslist', $jasper_link_page, null, '', $jasper_link_css);
     }
     $pages = array_merge($pages, array(new menuitem('customfields', new menuitempage('customfieldpage', '', array('level' => 'user')), null, '', block_curr_admin_get_item_css_class('customfields')), new menuitem('clusterclassification', new menuitempage('clusterclassificationpage', 'plugins/cluster_classification/clusterclassificationpage.class.php'), null, get_string('cluster_classification', 'crlm_cluster_classification'), block_curr_admin_get_item_css_class('clusterclassification')), new menuitem('info', null, 'root', get_string('informationalelements', 'block_curr_admin'), block_curr_admin_get_item_css_class('info', true)), new menuitem('managetags', new menuitempage('tagpage'), null, '', block_curr_admin_get_item_css_class('managetags')), new menuitem('manageenvironments', new menuitempage('envpage'), null, '', block_curr_admin_get_item_css_class('manageenvironments')), new menuitem('users', null, 'root', '', block_curr_admin_get_item_css_class('users', true)), new menuitem('manageusers', new menuitempage('usermanagementpage'), null, '', block_curr_admin_get_item_css_class('manageusers')), new menuitem('manageclusters', new menuitempage('clusterpage'), null, '', block_curr_admin_get_item_css_class('manageclusters')), new menuitem('curr', null, 'root', get_string('curriculum', 'block_curr_admin'), block_curr_admin_get_item_css_class('curr', true)), new menuitem('certificatelist', new menuitempage('certificatelistpage'), null, '', block_curr_admin_get_item_css_class('certificatelist')), new menuitem('managecurricula', new menuitempage('curriculumpage'), null, '', block_curr_admin_get_item_css_class('managecurricula')), new menuitem('managecourses', new menuitempage('coursepage'), null, '', block_curr_admin_get_item_css_class('managecourses')), new menuitem('manageclasses', new menuitempage('cmclasspage'), null, '', block_curr_admin_get_item_css_class('manageclasses')), new menuitem('crscat', null, 'root', get_string('learningplan', 'block_curr_admin'), block_curr_admin_get_item_css_class('crscat', true)), new menuitem('currentcourses', new menuitempage('coursecatalogpage', '', array('action' => 'current')), null, '', block_curr_admin_get_item_css_class('currentcourses')), new menuitem('availablecourses', new menuitempage('coursecatalogpage', '', array('action' => 'available')), null, '', block_curr_admin_get_item_css_class('availablecourses')), new menuitem('waitlist', new menuitempage('coursecatalogpage', '', array('action' => 'waitlist')), null, get_string('waitlistcourses', 'block_curr_admin'), block_curr_admin_get_item_css_class('waitlist')), new menuitem('rept', null, 'root', get_string('reports', 'block_curr_admin'), block_curr_admin_get_item_css_class('rept', true))));
     if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $SITE->id))) {
         if ($CURMAN->config->site_course_cluster_groups) {
             $pages[] = new menuitem('frontpagegroups', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/index.php?id={$SITE->id}"), 'admn', get_string('frontpagegroups', 'crlm_cluster_groups'), block_curr_admin_get_item_css_class('manageclusters'));
         }
         if ($CURMAN->config->cluster_groupings) {
             $pages[] = new menuitem('frontpagegroupings', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/groupings.php?id={$SITE->id}"), 'admn', get_string('frontpagegroupings', 'crlm_cluster_groups'), block_curr_admin_get_item_css_class('manageclusters'));
         }
     }
     /**
      * This section adds all the necessary PHP reports to the menu
      */
     //get all report pages, including categories but not including the
     //topmost report element
     $report_pages = block_curr_admin_get_report_tree_items();
     //merge in the reporting page links
     $pages = array_merge($pages, $report_pages);
     if (empty($CURMAN->config->userdefinedtrack)) {
         $pages[] = new menuitem('managetracks', new menuitempage('trackpage'), null, '', block_curr_admin_get_item_css_class('managetracks'));
     }
     $access = cm_determine_access($USER->id);
     switch ($access) {
         case 'admin':
         case 'developer':
             $pages[] = new menuitem('configmanager', new menuitempage('configpage', '', array('section' => 'admn')), null, get_string('configuration'), block_curr_admin_get_item_css_class('configuration'));
             $pages[] = new menuitem('notifications', new menuitempage('notifications', 'notificationspage.class.php', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('notifications'));
             $pages[] = new menuitem('dataimport', new menuitempage('dataimportpage', 'elis_ip/elis_ip_page.php', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('integrationpoint'));
             $pages[] = new menuitem('defaultcls', new menuitempage('configclsdefaultpage', '', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('defaultcls'));
             $pages[] = new menuitem('defaultcrs', new menuitempage('configcrsdefaultpage', '', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('defaultcrs'));
             break;
         default:
             break;
     }
     //turn all pages that have no children into leaf nodes
     menuitemlisting::flag_leaf_nodes($pages);
     //combine the specific entity page listing with the general CM listing
     $menuitemlisting = new menuitemlisting(array_merge($cm_entity_pages, $pages));
     $tree = new treerepresentation($menuitemlisting);
     $this->content = new stdClass();
     $this->content->text = $tree->convert_to_markup();
     $this->content->footer = '';
     return $this->content;
 }
コード例 #8
0
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user and a class
  *
  * @param    int      $userid    The id of the user being associated to the class
  * @param    int      $classid   The id of the class 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, $classid)
 {
     global $USER;
     if (!cmclasspage::can_enrol_into_class($classid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if (cmclasspage::_has_capability('block/curr_admin:track:enrol', $classid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the context for the "indirect" capability
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:class:enrol_cluster_user', $USER->id);
     $allowed_clusters = array();
     $allowed_clusters = cmclass::get_allowed_clusters($classid);
     //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;
 }
コード例 #9
0
 /**
  * Returns an array of cluster ids that are children of the supplied cluster and
  * the current user has access to enrol users into
  *
  * @param   int        $clusterid  The cluster whose children we care about
  * @return  int array              The array of accessible cluster ids
  */
 public static function get_allowed_clusters($clusterid)
 {
     global $USER, $CURMAN;
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster:enrol_cluster_user', $USER->id);
     $allowed_clusters = array();
     //get the clusters and check the context against them
     $cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin');
     $cluster_context_instance = get_context_instance($cluster_context_level, $clusterid);
     $path = sql_concat('ctxt.path', "'/%'");
     $like = sql_ilike();
     //query to get sub-cluster contexts
     $cluster_permissions_sql = "SELECT clst.* FROM\n                                    {$CURMAN->db->prefix_table(CLSTTABLE)} clst\n                                    JOIN {$CURMAN->db->prefix_table('context')} ctxt\n                                    ON clst.id = ctxt.instanceid\n                                    AND ctxt.contextlevel = {$cluster_context_level}\n                                    AND '{$cluster_context_instance->path}' {$like} {$path}";
     if ($records = get_records_sql($cluster_permissions_sql)) {
         //filter the records based on what contexts have the cluster:enrol_cluster_user capability
         $allowed_clusters = $context->get_allowed_instances($records, 'cluster', 'id');
     }
     return $allowed_clusters;
 }
コード例 #10
0
 /**
  * Returns an array of cluster ids that are associated to the supplied class through tracks and
  * the current user has access to enrol users into
  * 
  * @param   int        $clsid  The class whose association ids we care about
  * @return  int array          The array of accessible cluster ids
  */
 public static function get_allowed_clusters($clsid)
 {
     global $USER;
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:class:enrol_cluster_user', $USER->id);
     $allowed_clusters = array();
     if (cmclasspage::_has_capability('block/curr_admin:class:enrol_cluster_user', $clsid)) {
         global $CURMAN;
         require_once CURMAN_DIRLOCATION . '/lib/usercluster.class.php';
         $cmuserid = cm_get_crlmuserid($USER->id);
         $userclusters = $CURMAN->db->get_records(CLSTUSERTABLE, 'userid', $cmuserid);
         foreach ($userclusters as $usercluster) {
             $allowed_clusters[] = $usercluster->clusterid;
         }
     }
     //we first need to go through tracks to get to clusters
     $track_listing = new trackassignmentclass(array('classid' => $clsid));
     $tracks = $track_listing->get_assigned_tracks();
     //iterate over the track ides, which are the keys of the array
     if (!empty($tracks)) {
         foreach (array_keys($tracks) as $track) {
             //get the clusters and check the context against them
             $clusters = clustertrack::get_clusters($track);
             $allowed_track_clusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid');
             //append all clusters that are allowed by the available clusters contexts
             foreach ($allowed_track_clusters as $allowed_track_cluster) {
                 $allowed_clusters[] = $allowed_track_cluster;
             }
         }
     }
     return $allowed_clusters;
 }
コード例 #11
0
ファイル: contexts.php プロジェクト: remotelearner/elis.cm
 /**
  * Fetch the contexts where the user has a given capability.  This only works
  * with the CM context levels.
  *
  * Assumes that the user does not have "too many" role assignments.  Assumes
  * the user has no "prevents"/"prohibits" roles.
  */
 static function for_user_with_capability($contextlevel, $capability, $userid, $doanything = true)
 {
     global $CURMAN;
     static $cm_context_parents = array('track' => array('curriculum'), 'course' => array('curriculum'), 'class' => array('course', 'track'), 'user' => array('cluster'));
     $obj = new cm_context_set();
     // if the user has the capability at the system level (or has the
     // managecurricula master capability), we can stop here
     if (has_capability($capability, get_context_instance(CONTEXT_SYSTEM), $userid, $doanything) || has_capability('block/curr_admin:managecurricula', get_context_instance(CONTEXT_SYSTEM), $userid, $doanything)) {
         $obj->contexts = array('system' => 1);
         return $obj;
     }
     $contexts = array($contextlevel => array());
     $timenow = time();
     // find all contexts at the given context level where the user has a direct
     // role assignment
     if (!($contextlevelnum = context_level_base::get_custom_context_level($contextlevel, 'block_curr_admin'))) {
         return $obj;
     }
     $sql = "SELECT c.*\n              FROM {$CURMAN->db->prefix_table('role_assignments')} ra\n              JOIN {$CURMAN->db->prefix_table('context')} c ON ra.contextid = c.id\n             WHERE ra.userid = {$userid}\n               AND (ra.timeend = 0 OR ra.timeend >= {$timenow})\n               AND c.contextlevel = {$contextlevelnum}";
     $possiblecontexts = $CURMAN->db->get_records_sql($sql);
     $possiblecontexts = $possiblecontexts ? $possiblecontexts : array();
     foreach ($possiblecontexts as $c) {
         if (has_capability($capability, $c, $userid, $doanything)) {
             $contexts[$contextlevel][] = $c->instanceid;
         }
     }
     if (empty($contexts[$contextlevel])) {
         unset($contexts[$contextlevel]);
     }
     // look in the parent contexts
     if (isset($cm_context_parents[$contextlevel])) {
         foreach ($cm_context_parents[$contextlevel] as $parentlevel) {
             $parent = cm_context_set::for_user_with_capability($parentlevel, $capability, $userid, $doanything);
             $contexts = array_merge($contexts, $parent->contexts);
         }
     }
     $obj->contexts = $contexts;
     return $obj;
 }
コード例 #12
0
ファイル: track.class.php プロジェクト: remotelearner/elis.cm
/**
 * Calculates the number of records in a listing as created by track_get_listing
 *
 * @param   string          $namesearch    Search string for curriculum name
 * @param   string          $alpha         Start initial of curriculum name filter
 * @param   int             $curriculumid  Necessary associated curriculum
 * @param   int             $clusterid     Necessary associated cluster
 * @param   cm_context_set  $contexts      Contexts to provide permissions filtering, of null if none
 * @return  int                            The number of records
 */
function track_count_records($namesearch = '', $alpha = '', $curriculumid = 0, $parentclusterid = 0, $contexts = null)
{
    global $CURMAN;
    $LIKE = $CURMAN->db->sql_compare();
    $where = array('defaulttrack = 0');
    if (!empty($namesearch)) {
        $where[] = "name {$LIKE} '%{$namesearch}%'";
    }
    if ($alpha) {
        $where[] = "(name {$LIKE} '{$alpha}%')";
    }
    if ($curriculumid) {
        $where[] = "(curid = {$curriculumid})";
    }
    if ($parentclusterid) {
        $where[] = "(id IN (SELECT trackid FROM {$CURMAN->db->prefix_table(CLSTTRKTABLE)}\n                            WHERE clusterid = {$parentclusterid}))";
    }
    if ($contexts !== null) {
        $where[] = $contexts->sql_filter_for_context_level('id', 'track');
    }
    $where = implode(' AND ', $where);
    return $CURMAN->db->count_records_select(TRACKTABLE, $where);
}
コード例 #13
0
ファイル: clustertree.php プロジェクト: remotelearner/elis.cm
 /**
  * Adds controls specific to this filter in the form.
  * @param object $mform a MoodleForm object to setup
  */
 function setupForm(&$mform)
 {
     global $USER, $CFG;
     /**
      * CSS includes
      */
     $mform->addElement('html', '<style>@import url("' . $CFG->wwwroot . '/lib/yui/treeview/assets/skins/sam/treeview-skin.css");</style>');
     /**(use "git add" and/or "git commit -a")
      * JavaScript includes
      */
     //include the necessary javascript libraries for the YUI TreeView
     require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_treeview'));
     //for converting tree representation
     require_js('yui_json');
     //for asynch request dynamic loading
     require_js('yui_connection');
     //include our custom code that handles the YUI Treeview menu
     require_js($CFG->wwwroot . '/curriculum/js/clustertree.js');
     /**
      * Get set up necessary CSS classes
      */
     $manageclusters_css_class = block_curr_admin_get_item_css_class('manageclusters');
     $cluster_css_class = block_curr_admin_get_item_css_class('cluster_instance');
     //figure out which capability to check
     if ($this->execution_mode == php_report::EXECUTION_MODE_SCHEDULED) {
         $capability = 'block/php_report:schedule';
     } else {
         $capability = 'block/php_report:view';
     }
     $context_result = cm_context_set::for_user_with_capability('cluster', $capability, $USER->id);
     $extrafilters = array('contexts' => $context_result, 'parent' => 0);
     $num_records = cluster_count_records('', '', $extrafilters);
     /**
      * TreeView-related work
      */
     //CM entities for placement at the top of the menu
     $cm_entity_pages = array();
     $cm_entity_pages[] = new menuitem('root');
     if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, 0, '', '', array('parent' => 0))) {
         foreach ($clusters as $cluster) {
             $params = array('id' => $cluster->id, 'action' => 'viewreport', 'execution_mode' => $this->execution_mode);
             $cluster_count = cluster_count_records('', '', array('parent' => $cluster->id));
             $isLeaf = empty($cluster_count);
             $cm_entity_pages[] = test_cluster_tree_get_menu_item('cluster', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf);
         }
     }
     $menuitemlisting = new menuitemlisting($cm_entity_pages);
     $tree = new checkbox_treerepresentation($menuitemlisting, $this->options['report_id']);
     $tree_html = $tree->convert_to_markup($this->_uniqueid, $this->execution_mode);
     $params = array($this->options['report_id'], $this->_uniqueid, $this->options['dropdown_button_text'], $this->options['tree_button_text']);
     $param_string = implode('", "', $params);
     /**
      * UI element setup
      */
     require_once $CFG->dirroot . '/curriculum/lib/filtering/equalityselect.php';
     $choices_array = array(0 => get_string('anyvalue', 'filters'));
     //set up cluster listing
     if ($records = cluster_get_listing('name', 'ASC', 0, 0, '', '', array('contexts' => $context_result))) {
         foreach ($records as $record) {
             if ($record->parent == 0) {
                 //merge in child clusters
                 $choices_array[$record->id] = $record->name;
                 $child_array = $this->find_child_clusters($records, $record->id);
                 $choices_array = $this->merge_array_keep_keys($choices_array, $child_array);
             }
         }
     }
     //get help text
     if (isset($this->options['help'])) {
         $this->_filterhelp = $this->options['help'];
     } else {
         $this->_filterhelp = null;
     }
     //add filterhelp and label to this filter
     //import required css for the fieldset
     $style = '<style>@import url("' . $CFG->wwwroot . '/curriculum/styles.css");</style>';
     //hack the nested fieldset into an html element
     $helptext = get_string('helpprefix2', $this->_filterhelp['1']) . ' (' . get_string('newwindow') . ')';
     $helpurl = '/help.php?module=' . $this->_filterhelp['2'] . '&amp;file=' . $this->_filterhelp['0'] . '.html&amp;forcelang=';
     $helplink = '<span class="helplink"><a title="' . $this->_filterhelp['1'] . '" href="' . $CFG->wwwroot . $helpurl . '"' . ' onclick="this.target=\'popup\'; return openpopup(\'' . $helpurl . '\', \'popup\', \'menubar=0,location=0,scrollbars,resizable,width=500,height=400\', 0);">' . ' <img class="iconhelp" alt="' . $helptext . '" src="' . $CFG->pixpath . '/help.gif"></a></span>';
     $nested_fieldset = false;
     $title = '';
     if ($this->options['fieldset']) {
         $nested_fieldset = '<fieldset class="nested clearfix" id="' . $this->_uniqueid . '_label' . '">' . "\n" . '<legend class="ftoggler">' . $this->_label . $helplink . '</legend>' . "\n";
     } else {
         $title = $this->_label . $helplink . '&nbsp;';
     }
     $mform->addElement('html', $style . $nested_fieldset);
     //cluster select dropdown
     $mform->addElement('select', $this->_uniqueid . '_dropdown', $title, $choices_array);
     //dropdown / cluster tree state storage
     $mform->addElement('hidden', $this->_uniqueid . '_usingdropdown');
     //default to showing dropdown if nothing has been persisted
     $report_shortname = $this->options['report_shortname'];
     $preferences = php_report_filtering_get_user_preferences($report_shortname);
     if (!isset($preferences["php_report_{$report_shortname}/{$this->_uniqueid}_usingdropdown"])) {
         $mform->setDefault($this->_uniqueid . '_usingdropdown', 1);
     }
     // dress it up like an mform element
     $tree_html = '<div class="fitem"><div class="fitemtitle"></div>' . $tree_html . '</div>';
     //cluster tree
     $mform->addElement('html', $tree_html);
     //list of explicitly selected elements
     $mform->addElement('hidden', $this->_uniqueid . '_listing');
     //list of selected and unexpanded elements
     $mform->addElement('hidden', $this->_uniqueid . '_unexpanded');
     //list of explicitly unselected elements
     $mform->addElement('hidden', $this->_uniqueid . '_clrunexpanded');
     /**
      * Work needed to initialize the state of necessary components
      */
     //parameters needed
     $params = array($this->options['report_id'], $this->_uniqueid, $this->options['dropdown_button_text'], $this->options['tree_button_text']);
     $param_string = implode('", "', $params);
     $mform->addElement('button', $this->_uniqueid . '_toggle', $this->options['dropdown_button_text'], array('onclick' => 'clustertree_toggle_tree("' . $param_string . '")'));
     //script to do the work
     $initialize_state_script = '<script type="text/javascript">
                                 clustertree_set_toggle_state("' . $param_string . '");
                                 </script>';
     $mform->addElement('html', $initialize_state_script);
     // close hacked nested fieldset
     if ($this->options['fieldset']) {
         $mform->addElement('html', '</fieldset>');
     }
 }
コード例 #14
0
$LIKE = $CURMAN->db->sql_compare();
$select = 'SELECT usr.*, ' . $FULLNAME . ' AS name, usr.lastname AS lastname ';
$sql = 'FROM ' . $CURMAN->db->prefix_table(USRTABLE) . ' usr ' . 'LEFT OUTER JOIN ' . $CURMAN->db->prefix_table(USRTRKTABLE) . ' ut ON ut.userid = usr.id AND ut.trackid = ' . $trackid . ' ' . 'WHERE ut.userid IS NULL ';
if (empty($CURMAN->config->legacy_show_inactive_users)) {
    $sql .= 'AND usr.inactive = 0 ';
}
if ($alpha) {
    $sql .= 'AND ' . $FULLNAME . ' ' . $LIKE . ' \'' . $alpha . '%\' ';
}
if ($namesearch) {
    $sql .= 'AND ' . $FULLNAME . ' ' . $LIKE . ' \'%' . $namesearch . '%\' ';
}
if (!trackpage::_has_capability('block/curr_admin:track:enrol', $trackid)) {
    //perform SQL filtering for the more "conditional" capability
    //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);
    //get the clusters and check the context against them
    $clusters = clustertrack::get_clusters($trackid);
    $allowed_clusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid');
    if (empty($allowed_clusters)) {
        $sql .= 'AND 0=1';
    } else {
        $cluster_filter = implode(',', $allowed_clusters);
        $sql .= "AND usr.id IN (\n                   SELECT userid FROM " . $CURMAN->db->prefix_table(CLSTUSERTABLE) . "\n                   WHERE clusterid IN ({$cluster_filter}))";
    }
}
// get the total number of matching users
$count = $CURMAN->db->count_records_sql('SELECT COUNT(usr.id) ' . $sql);
if ($sort) {
    $sql .= 'ORDER BY ' . $sort . ' ' . $dir . ' ';
}
コード例 #15
0
 function __construct(&$items, $columns, $pageurl, $decorators = array())
 {
     global $CURMAN, $USER;
     parent::__construct($items, $columns, $pageurl, $decorators);
     $id = required_param('id', PARAM_INT);
     if (!curriculumpage::_has_capability('block/curr_admin:curriculum:enrol', $id)) {
         $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:curriculum:enrol_cluster_user', $USER->id);
         $allowed_clusters = array();
         //get the clusters assigned to this curriculum
         $clusters = clustercurriculum::get_clusters($id);
         if (!empty($clusters)) {
             foreach ($clusters as $cluster) {
                 if ($context->context_allowed($cluster->clusterid, 'cluster')) {
                     $allowed_clusters[] = $cluster->id;
                 }
             }
         }
         $this->allowed_clusters = $allowed_clusters;
     }
 }
コード例 #16
0
 /**
  * Determines whether the current user is allowed to enrol users into the provided class
  *
  * @param   int      $classid  The id of the class we are checking permissions on
  *
  * @return  boolean            Whether the user is allowed to enrol users into the class
  *
  */
 static function can_enrol_into_class($classid)
 {
     global $USER;
     //check the standard capability
     if (cmclasspage::_has_capability('block/curr_admin:class:enrol', $classid) || cmclasspage::_has_capability('block/curr_admin:class:enrol_cluster_user', $classid)) {
         return true;
     }
     //get the context for the "indirect" capability
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:class:enrol_cluster_user', $USER->id);
     //we first need to go through tracks to get to clusters
     $track_listing = new trackassignmentclass(array('classid' => $classid));
     $tracks = $track_listing->get_assigned_tracks();
     //iterate over the track ides, which are the keys of the array
     if (!empty($tracks)) {
         foreach (array_keys($tracks) as $track) {
             //get the clusters and check the context against them
             $clusters = clustertrack::get_clusters($track);
             if (!empty($clusters)) {
                 foreach ($clusters as $cluster) {
                     if ($context->context_allowed($cluster->clusterid, 'cluster')) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }