/** * block contents * * @return object */ public function get_content() { global $CFG, $COURSE, $USER; if ($this->content !== NULL) { return $this->content; } if ($COURSE->id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM); } else { $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (has_capability('block/enrol_survey:edit', $context)) { $editpage = get_string('editpage', 'block_enrol_survey'); $this->content->text .= "<a href={$CFG->wwwroot}/blocks/enrol_survey/edit_survey.php?id={$this->instance->id}>{$editpage}</a><br />"; } if (has_capability('block/enrol_survey:take', $context) && cm_get_crlmuserid($USER->id) !== false) { // MUST have ELIS user record to take survey! see: survey.php if (!empty($this->config->force_user) && !is_survey_taken($USER->id, $this->instance->id)) { redirect("{$CFG->wwwroot}/blocks/enrol_survey/survey.php?id={$this->instance->id}"); } $takepage = get_string('takepage', 'block_enrol_survey'); $this->content->text .= "<a href={$CFG->wwwroot}/blocks/enrol_survey/survey.php?id={$this->instance->id}>{$takepage}</a><br />"; } return $this->content; }
/** * Handle a role assignment by creating an equivalent class enrolment or * instructor assignment (if applicable). */ static function role_assigned($data) { require_once CURMAN_DIRLOCATION . '/lib/student.class.php'; require_once CURMAN_DIRLOCATION . '/lib/instructor.class.php'; global $CURMAN; if (!($context = get_context_instance_by_id($data->contextid))) { $context = get_context_instance($data->contextid, $data->itemid); } if (!empty($context) && $context->contextlevel == context_level_base::get_custom_context_level('class', 'block_curr_admin')) { $cmuserid = cm_get_crlmuserid($data->userid); if ($data->roleid == $CURMAN->config->enrolment_role_sync_student_role) { // add enrolment record $student = new student(); $student->userid = $cmuserid; $student->classid = $context->instanceid; // NOTE: student::add checks if the student is already // enrolled, so we don't have to check here $student->add(); } if ($data->roleid == $CURMAN->config->enrolment_role_sync_instructor_role) { // add instructor record if (!instructor::user_is_instructor_of_class($cmuserid, $context->instanceid)) { $instructor = new instructor(); $instructor->userid = $cmuserid; $instructor->classid = $context->instanceid; $instructor->add(); } } } return true; }
/** * block contents * * @return object */ public function get_content() { global $CFG, $COURSE, $USER, $PAGE; if ($this->content !== NULL) { return $this->content; } if ($COURSE->id == SITEID) { $context = context_system::instance(); } else { $context = context_course::instance($COURSE->id); } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; $mymoodle = 0; if (strcmp('my-index', $PAGE->pagetype) == 0) { $mymoodle = 1; } if (has_capability('block/enrolsurvey:edit', $context)) { $editpage = get_string('editpage', 'block_enrolsurvey'); $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/edit_survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$editpage}</a><br\n/>"; } if (has_capability('block/enrolsurvey:take', $context) && cm_get_crlmuserid($USER->id) !== false) { // MUST have ELIS user record to take survey! if (!empty($this->config->force_user) && !is_survey_taken($USER->id, $this->instance->id)) { redirect("{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}"); } $takepage = get_string('takepage', 'block_enrolsurvey'); $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$takepage}</a><br\n/>"; } // $this->content->text .= "<br/> crontime = {$this->config->cron_time}"; return $this->content; }
function can_do_default() { global $USER; $id = $this->required_param('id', PARAM_INT); // TODO: Ugly, this needs to be overhauled $cpage = new pmclasspage(); return $cpage->_has_capability('local/elisreports:view', $id) || instructor::user_is_instructor_of_class(cm_get_crlmuserid($USER->id), $id); }
function can_view_cluster() { global $USER; $context = get_context_instance(CONTEXT_SYSTEM); $crlm_uid = cm_get_crlmuserid($USER->id); if (empty($crlm_uid)) { $crlm_uid = -1; } return $this->can_view_admin() || has_capability('block/curr_admin:viewgroupreports', $context) || record_exists(CLSTASSTABLE, 'userid', $crlm_uid, 'leader', 1); }
function can_do_default() { global $USER; $id = $this->required_param('id', PARAM_INT); $cmuserid = cm_get_crlmuserid($USER->id); if ($cmuserid != 0 && $cmuserid == $id) { return true; } return usermanagementpage::_has_capability('block/php_report:view'); }
/** * List the certificates available to be printed. * @return unknown_type */ function action_default() { global $CFG, $USER, $CURMAN; // This is for a Moodle user, so get the Curriculum user id. $cuserid = cm_get_crlmuserid($USER->id); $curasses = curriculumstudent::get_completed_for_user($cuserid); if (count($curasses) == 0) { print_string('certificates_none_earned', 'block_curr_admin'); return; } print_string('certificates_earned', 'block_curr_admin'); echo "<UL>\n"; foreach ($curasses as $curass) { echo "<LI><a href=\"certificate.php?id={$curass->id}\">{$curass->curriculum->name}</a>\n"; } echo "</UL>\n"; }
function display_default() { global $CFG, $USER, $OUTPUT; $context = context_system::instance(); if (has_capability('local/elisprogram:manage', $context) || has_capability('local/elisprogram:config', $context)) { echo $OUTPUT->heading(get_string('admin_dashboard', 'local_elisprogram')); echo $OUTPUT->box(html_writer::tag('p', get_string('elis_doc_class_link', 'local_elisprogram'))); echo $OUTPUT->box(html_writer::tag('p', $this->last_cron_runtimes())); $healthpg = new healthpage(); if ($healthpg->can_do_default()) { echo $OUTPUT->box(html_writer::tag('p', get_string('health_check_link', 'local_elisprogram', $CFG))); } // Output ELIS version info echo $OUTPUT->box($this->elis_versions()); } if ($cmuid = cm_get_crlmuserid($USER->id)) { $user = new user($cmuid); echo $user->get_dashboard(); } }
$usernew = get_record('user', 'id', $USER->id); foreach ((array) $usernew as $variable => $value) { $USER->{$variable} = $value; } if (!is_survey_taken($USER->id, $instanceid) && empty($incomplete)) { $dataobject = new object(); $dataobject->blockinstanceid = $instanceid; $dataobject->userid = $USER->id; insert_record('block_enrol_survey_taken', $dataobject); } if (!empty($formdata->save_exit)) { redirect($CFG->wwwroot . '/course/view.php?id=' . $COURSE->id); } } } $toform = array(); $u = new user(cm_get_crlmuserid($USER->id)); $toform = get_object_vars($u); $customdata = get_records('user_info_data', 'userid', $USER->id); if (!empty($customdata)) { foreach ($customdata as $cd) { $customfields = get_record('user_info_field', 'id', $cd->fieldid); $toform[$customfields->shortname] = $cd->data; } } $survey_form->set_data($toform); $blockname = get_string('blockname', 'block_enrol_survey'); print_header($blockname, $blockname, build_navigation($blockname)); print_heading($block->config->title); $survey_form->display(); print_footer();
* @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ require_once '../../config.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elispm::lib('deprecatedlib.php'); require_once elispm::lib('data/user.class.php'); //needed to use $OUTPUT when displaying summary info $sys_context = context_system::instance(); $PAGE->set_context($sys_context); //determine which program we are operating on (or 'na' for non-program courses) $programid = required_param('programid', PARAM_CLEAN); //determine which state we're in $showcompleted = required_param('showcompleted', PARAM_INT); $showcompleted = $showcompleted == 1 ? true : false; if ($cmuid = cm_get_crlmuserid($USER->id)) { //need the current PM user, since that's where the dashboard is defined $user = new user($cmuid); if ($programid == 'na') { //non-program courses list($classes, $completecourses, $totalcourses) = $user->get_dashboard_nonprogram_data(array(), $showcompleted); if ($totalcourses > 0) { //send back the table to display $table = $user->get_dashboard_nonprogram_table($classes); if (count($table->data) > 0) { //actually have something to display echo html_writer::table($table); } if (!$showcompleted) { //send back the summary text to output $summary = $user->get_dashboard_program_summary($completecourses, $totalcourses, false);
/** * Specifies an SQL statement that will retrieve users and their cluster assignment info, class enrolments, * and resource info * * @param array $columns The list of columns automatically calculated * by get_select_columns() * @return array The report's main sql statement with optional params */ function get_report_sql($columns) { global $USER; $cm_user_id = cm_get_crlmuserid($USER->id); $filter_array = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'userid', $this->filter); // ELIS-4699: so not == to invalid cm/pm userid $filter_user_id = isset($filter_array[0]['value']) ? $filter_array[0]['value'] : -1; $params = array('p_completestatus' => STUSTATUS_PASSED); $permissions_filter = 'TRUE '; // ELIS-3993 -- Do not display any results if no user ID was supplied by the filter if ($filter_user_id == -1) { $permissions_filter = ' FALSE'; } else { if ($filter_user_id != $cm_user_id || $this->execution_mode != php_report::EXECUTION_MODE_INTERACTIVE) { // obtain all course contexts where this user can view reports $contexts = get_contexts_by_capability_for_user('user', $this->access_capability, $this->userid); $filter_obj = $contexts->get_filter('id', 'user'); $filter_sql = $filter_obj->get_sql(false, 'usr', SQL_PARAMS_NAMED); if (isset($filter_sql['where'])) { if ($filter_sql['where'] == 'FALSE') { // This user does not have permission to view the requested data $this->nopermission = true; $permissions_filter = 'FALSE'; } else { $permissions_filter = $filter_sql['where']; $params += $filter_sql['where_parameters']; } } } } // Figure out the number of completed credits for the curriculum $numcomplete_subquery = "SELECT sum(innerclsenr.credits)\n FROM {" . student::TABLE . "} innerclsenr\n JOIN {" . pmclass::TABLE . "} innercls ON innercls.id = innerclsenr.classid\n JOIN {" . course::TABLE . "} innercrs ON innercls.courseid = innercrs.id\n JOIN {" . curriculumcourse::TABLE . "} innercurcrs\n ON innercurcrs.courseid = innercrs.id\n WHERE innerclsenr.userid = usr.id\n AND innercurcrs.curriculumid = cur.id\n AND innerclsenr.completestatusid = :p_completestatus"; // Main query $sql = "SELECT {$columns},\n cur.id IS NULL AS isnull,\n crs.name AS course_name,\n clsenr.credits AS credits,\n clsenr.grade AS grade,\n clsenr.completetime AS date_completed,\n clsenr.completestatusid AS status,\n curass.timeexpired AS expires,\n usr.firstname AS firstname,\n usr.lastname AS lastname,\n cur.reqcredits AS reqcnt,\n ({$numcomplete_subquery}) AS acqcnt\n FROM {" . course::TABLE . "} crs\n JOIN {" . pmclass::TABLE . "} cls\n ON cls.courseid=crs.id\n JOIN {" . student::TABLE . "} clsenr\n ON clsenr.classid=cls.id\n JOIN {" . user::TABLE . "} usr\n ON usr.id = clsenr.userid\n LEFT JOIN ({" . curriculumstudent::TABLE . "} curass\n JOIN {" . curriculum::TABLE . "} cur\n ON cur.id = curass.curriculumid\n JOIN {" . curriculumcourse::TABLE . "} curcrs\n ON curcrs.curriculumid = cur.id)\n ON curass.userid = usr.id\n AND curcrs.courseid = crs.id\n LEFT JOIN {" . coursecompletion::TABLE . "} crscomp\n ON crscomp.courseid = crs.id\n LEFT JOIN {" . GRDTABLE . "} grd\n ON grd.classid = cls.id\n AND grd.userid = usr.id\n AND grd.completionid = crscomp.id\n AND grd.locked = 1\n WHERE {$permissions_filter}\n "; return array($sql, $params); }
/** * Main display function. * * Fetch and display (or download) the required data. * * @param string $sort The column to sort results by. * @param string $dir The direction to sort by. * @param int $page The page number to display results for. * @param int $perpage The number of results per page. * @param string $search A string to search for. * @param string $alpha An initial to filter results by. * @param string $download The format to download the report in. */ function main($sort = '', $dir = '', $page = 0, $perpage = 20, $download = '', $frompage = '') { global $CFG, $USER; $context = get_context_instance(CONTEXT_SYSTEM, SITEID); $canaccessum = false; if (has_capability('block/curr_admin:viewreports', $context)) { $this->usrid = cm_get_param('user', 0); $canaccessum = true; } else { if (has_capability('block/curr_admin:viewgroupreports', $context)) { // Verify userid $this->usrid = cm_get_param('user', 0); if (!cm_can_access_userreport($this->usrid)) { error("No access allowed."); } $canaccessum = false; } else { if (has_capability('block/curr_admin:viewownreports', $context)) { // Make sure only this user. if (!($this->usrid = cm_get_crlmuserid($USER->id))) { error("No account found."); } } else { error("No access allowed."); } } } $user = new user($this->usrid); $this->baseurl .= '&user='******'&hideins=' . $this->hideins; $this->set_title('Individual User Report for ' . cm_fullname($user)); if (empty($download)) { $output = ''; if ($frompage == '') { $frompage = 'users'; } $pagename = get_string("report{$frompage}", 'block_curr_admin'); $bc = '<span class="breadcrumb"><a href="index.php?s=rep&section=rept&type=' . $frompage . '">' . $pagename . '</a> » ' . $this->title . '</span>'; $output .= cm_print_heading_block($bc, '', true); $output .= '<br />' . "\n"; } $this->get_data(!empty($download)); $this->add_column('courseidnumber', 'Course ID', 'left', false); $this->add_column('coursename', 'Course Name', 'left', false); $this->add_column('classidnumber', 'Class ID', 'left', false); if (!empty($this->_maxexams)) { for ($i = 1; $i <= $this->_maxexams; $i++) { $this->add_column('ccgrade' . $i, 'Exam ' . $i, 'left', false); $this->add_column('cctimegraded' . $i, 'Date ' . $i, 'left', false); } } $this->add_column('classgrade', 'Class Grade', 'left', false); $this->add_column('credits', 'Credits', 'left', false); $this->add_column('datecomplete', 'Completed', 'left', false); $this->add_column('completestatus', 'Status', 'left', false); // $this->add_column('nextdue', 'Next Due', 'left', true); // $this->add_column('insid', 'Instructor ID', 'left', true); /* if (!$this->hideins) { $this->add_column('insname', 'Instructor Name', 'left', true); } */ $this->set_default_sort('coursename', 'ASC'); $this->sort = !empty($sort) ? $sort : $this->defsort; $this->dir = !empty($dir) ? $dir : $this->defdir; $this->page = 0; $this->perpage = 9999; if (empty($download)) { $tlink = $CFG->wwwroot . '/curriculum/index.php'; $toptions = array('s' => 'rep', 'section' => 'rept', 'type' => 'transcript', 'user' => $this->usrid); $tlabel = get_string('transcript', 'block_curr_admin'); $output .= '<div class="trans-button">' . print_single_button($tlink, $toptions, $tlabel, NULL, NULL, true) . '</div>'; if (!empty($this->rawdata)) { $output .= $this->print_download_menu(); } $output .= '<br />'; $output .= '<fieldset>' . "\n"; /* $output .= '<form action="index.php" method="post">'; $output .= '<input type="hidden" name="s" value="rep" />'; $output .= '<input type="hidden" name="section" value="rept" />'; $output .= '<input type="hidden" name="type" value="induser" />'; $output .= '<input type="hidden" name="sort" value="' . $this->sort . '" />'; $output .= '<input type="hidden" name="dir" value="' . $this->dir . '" />'; $output .= '<input type="hidden" name="user" value="' . $this->usrid . '" />'; $output .= 'Hide instructor name <input type="checkbox" name="hideins" value="1" ' . (!empty($this->hideins) ? ' checked' : '') . ' /> '; $output .= '<input type="submit" value="Update Display" />'; $output .= '</form><br />'; */ if (empty($user->origenroldate)) { if (empty($user->timecreated)) { $origdate = get_string('unknown', 'block_curr_admin'); } else { $origdate = cm_timestamp_to_date($user->timecreated); } } else { if (!($origdate = cm_timestring_to_date($user->origenroldate))) { $origdate = get_string('unknown', 'block_curr_admin'); } } $output .= '<legend>' . get_string('user_information', 'block_curr_admin') . '</legend>'; $output .= '<div style="float: left; width: 50%;"><b>' . get_string('user_id', 'block_curr_admin') . '</b> '; if ($canaccessum) { $output .= '<a href="' . $CFG->wwwroot . '/curriculum/index.php?s=usr&userid=' . $user->id . '&action=view">' . $user->idnumber . '</a></div>'; } else { $output .= $user->idnumber . '</div>'; } $output .= '<div style="float: left; width: 50%;"><b>' . get_string('student_email', 'block_curr_admin') . ':</b> ' . $user->email . '</div><br />'; $output .= '<div style="float: left; width: 50%;"><b>' . get_string('firstname', 'block_curr_admin') . ':</b> ' . $user->firstname . '</div>'; $output .= '<div style="float: left; width: 50%;"><b>' . get_string('original_reg_date', 'block_curr_admin') . ':</b> ' . $origdate . '</div><br />'; $output .= '<div style="float: left; width: 35%;"><b>' . get_string('lastname', 'block_curr_admin') . ':</b> ' . $user->lastname . '</div><br />'; $output .= '</fieldset><br />'; if (!empty($this->rawdata)) { foreach ($this->rawdata as $curid => $curlist) { $output .= '<strong>' . $curlist->curriculumname . ' - ' . get_string('enrolled_classes', 'block_curr_admin') . '</strong>'; $this->data = $curlist->data; $output .= $this->display(); unset($this->table); $output .= '<br /><br />'; } } else { $output .= '<h2>' . get_string('no_classes_completed', 'block_curr_admin') . '</h2>'; } $output .= $this->print_footer(); echo $output; } else { $this->download($download); } }
/** * 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; }
function can_do_default() { global $USER; $id = $this->required_param('id', PARAM_INT); return cmclasspage::_has_capability('block/curr_admin:viewreports', $id) || instructor::user_is_instructor_of_class(cm_get_crlmuserid($USER->id), $id); }
/** * Find a list of organization folders that the user has access to. * * @param $CFG * @param int $muserid The Moodle user id. * @param string $username The Moodle user name. * @param int $oid The organization id. * @return array Alfresco repository folder names. */ function find_organization_folders($muserid, $username) { global $CFG, $CURMAN, $USER; require_once $CFG->libdir . '/ddllib.php'; // Ensure that the cluster table actually exists before we query it. $table = new XMLDBTable('crlm_cluster'); if (!table_exists($table)) { return false; } if (!file_exists($CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php')) { return false; } require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; // Convert moodle userid to CM userid $cmuserid = cm_get_crlmuserid($muserid); $obj = new cm_context_set(); $timenow = time(); $contextlevelnum = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $capability = "'block/repository:vieworganizationcontent'"; $like = sql_ilike(); $child_path = sql_concat('c_parent.path', "'/%'"); // Select clusters and sub-clusters for the current user // to which they have the vieworganization capability // TODO: Add this capability to the user when they are first assigned to a cluster $sql = "SELECT DISTINCT clst.id AS clusterid\n FROM {$CURMAN->db->prefix_table(CLSTTABLE)} clst\n WHERE EXISTS ( SELECT 'x'\n FROM {$CURMAN->db->prefix_table('context')} c\n JOIN {$CURMAN->db->prefix_table('context')} c_parent\n ON c.path {$like} {$child_path}\n OR c.path = c_parent.path\n JOIN {$CURMAN->db->prefix_table('role_assignments')} ra\n ON ra.contextid = c_parent.id\n AND ra.userid = {$muserid}\n AND (ra.timeend = 0 OR ra.timeend >= {$timenow})\n JOIN {$CURMAN->db->prefix_table('role_capabilities')} rc\n ON ra.roleid = rc.roleid\n WHERE c_parent.instanceid = clst.id\n AND c.contextlevel = {$contextlevelnum}\n AND c_parent.contextlevel = {$contextlevelnum}\n AND rc.capability = {$capability}\n )\n OR EXISTS ( SELECT 'x'\n FROM {$CURMAN->db->prefix_table(CLSTASSTABLE)} ca\n WHERE ca.clusterid = clst.id\n AND ca.userid = {$cmuserid})\n "; $viewable_clusters = $CURMAN->db->get_records_sql($sql); $cluster_info = array(); if ($viewable_clusters) { foreach ($viewable_clusters as $cluster) { if (!($new_cluster_info = $this->load_cluster_info($cluster->clusterid))) { continue; } else { $cluster_info[$cluster->clusterid] = $new_cluster_info; } } } else { return false; } if (empty($cluster_info)) { return false; } // There may be multiple clusters that this user is assigned to... $org_folders = array(); foreach ($cluster_info as $cluster) { // Get the extra cluster data and ensure it is present before proceeding. $clusterdata = clusterclassification::get_for_cluster($cluster); if (empty($clusterdata->params)) { continue; } $clusterparams = unserialize($clusterdata->params); // Make sure this cluster has the Alfresco shared folder property defined if (empty($clusterparams['alfresco_shared_folder'])) { continue; } // Make sure we can get the storage space from Alfresco for this organization. if (!($uuid = $this->get_organization_store($cluster->id))) { continue; } $org_folders[$cluster->name] = array('uuid' => $uuid, 'id' => $cluster->id); } return $org_folders; }
function action_default() { global $CFG, $CURMAN, $USER; $context = get_context_instance(CONTEXT_SYSTEM); if (has_capability('block/curr_admin:managecurricula', $context)) { echo print_heading_block('Administrator Dashboard', '', true); echo '<p>'; echo get_string('elis_doc_class_link', 'block_curr_admin'); echo '</p><p>'; echo $this->last_cron_runtimes(); echo '</p>'; $healthpg = new healthpage(); if ($healthpg->can_do_default()) { echo '<p>', get_string('health_check_link', 'block_curr_admin', $CFG->wwwroot), '</p>'; } echo print_heading(get_string('elisversion', 'block_curr_admin') . ': ' . $CURMAN->release, 'right', '4', 'main', true); } if ($cmuid = cm_get_crlmuserid($USER->id)) { $user = new user($cmuid); echo $user->get_dashboard(); } }
/** * Specifies an SQL statement that will produce the required report * * @param array $columns The list of columns automatically calculated * by get_select_columns() * @return string The report's main sql statement */ function get_report_sql($columns) { global $CFG, $CURMAN; $this->get_filter_values(); $cm_user_id = cm_get_crlmuserid($this->userid); if (empty($cm_user_id)) { $cm_user_id = 0; } // Three different queries depending upon the segmentation filter // Main query $sql = "SELECT {$columns}, usr.lastname AS lastname, cur.name AS curriculum_name, crs.name AS course_name, cls.idnumber AS class_name\n FROM {$CURMAN->db->prefix_table(CURTABLE)} cur\n JOIN {$CURMAN->db->prefix_table(CURCRSTABLE)} curcrs\n ON curcrs.curriculumid = cur.id\n JOIN {$CURMAN->db->prefix_table(CRSTABLE)} crs\n ON crs.id = curcrs.courseid\n JOIN {$CURMAN->db->prefix_table(CLSTABLE)} cls\n ON cls.courseid=crs.id\n JOIN {$CURMAN->db->prefix_table(STUTABLE)} enrol\n ON enrol.classid=cls.id\n JOIN {$CURMAN->db->prefix_table(USRTABLE)} usr\n ON usr.id = clsenr.userid\n "; return $sql; }
/** * List the certificates available to be printed. * TODO: Figure out a better way of displaying all of the cert entity types */ public function display_default() { global $CFG, $USER, $OUTPUT; // This is for a Moodle user, so get the Curriculum user id. $cuserid = cm_get_crlmuserid($USER->id); $link = ''; $attributes = array(); $text = ''; if (empty($cuserid)) { print_error('notelisuser', 'local_elisprogram'); } if (empty(elis::$config->local_elisprogram->disablecertificates)) { $curasses = curriculumstudent::get_completed_for_user($cuserid); if (count($curasses) == 0) { print_string('certificates_none_earned', 'local_elisprogram'); } else { print_string('certificates_earned', 'local_elisprogram'); echo html_writer::start_tag('ul'); foreach ($curasses as $curass) { $attributes['href'] = 'certificate.php?id=' . $curass->id; $attributes['target'] = '_blank'; $text = $curass->curriculum->name; $link = html_writer::tag('a', $text, $attributes); echo html_writer::tag('li', $link); } echo html_writer::end_tag('ul'); } } if (isset(elis::$config->local_elisprogram->disablecoursecertificates) && empty(elis::$config->local_elisprogram->disablecoursecertificates)) { $records = get_user_certificates($cuserid); $this->display_entity_certificates($records); $records->close(); } }
/** * Gets the autocomplete search SQL for the autocomplete UI * Note that this is the SQL used to select a value, not the SQL used in the report SQL * @param string $q The query string * @return string The SQL query */ public function get_search_results($q) { global $CFG, $DB, $USER; $q = explode(' ', $q); // Get enabled instance and custom fields. $displayinstancefields = $this->get_display_instance_fields(); $searchinstancefields = $this->get_search_instance_fields(); $displaycustomfields = $this->get_display_custom_fields(); $searchcustomfields = $this->get_search_custom_fields(); $configuredforcedcustomvals = $this->get_configured_forced_custom_vals(); if (empty($searchcustomfields) && empty($searchinstancefields)) { echo get_string('filt_autoc_no_fields_enabled', 'local_eliscore'); die; } // Assemble SELECT. $select = array('i.id'); foreach ($displayinstancefields as $field => $label) { $select[] = 'i.' . $field; } foreach ($displaycustomfields as $fieldinfo) { $select[] = 'f' . $fieldinfo['fieldid'] . '.data as ' . strtolower($fieldinfo['shortname']); } $select = 'SELECT ' . implode(',', $select); // Assemble FROM/JOINs. $joins = array('JOIN {context} c ON c.instanceid=i.id AND c.contextlevel=' . $this->contextlevel); foreach ($displaycustomfields as $fieldinfo) { $table = $this->custom_fields_data_tables[$fieldinfo['datatype']]; $alias = 'f' . $fieldinfo['fieldid']; $joins[] = ' LEFT JOIN {' . $table . '} ' . $alias . ' ON ' . $alias . '.contextid=c.id AND ' . $alias . '.fieldid=' . $fieldinfo['fieldid']; } foreach ($this->forced_custom_vals as $fieldshortname => $forcedval) { if (isset($this->custom_fields[$fieldshortname]) && !isset($displaycustomfields[$fieldshortname])) { $fieldinfo = $this->custom_fields[$fieldshortname]; $table = $this->custom_fields_data_tables[$fieldinfo['datatype']]; $alias = 'f' . $fieldinfo['fieldid']; $joins[] = ' LEFT JOIN {' . $table . '} ' . $alias . ' ON ' . $alias . '.contextid=c.id AND ' . $alias . '.fieldid=' . $fieldinfo['fieldid']; } } if ($this->config_allowed() !== true) { foreach ($configuredforcedcustomvals as $fieldshortname => $fieldinfo) { if (!isset($this->custom_fields[$fieldshortname]) && !isset($displaycustomfields[$fieldshortname])) { $table = $this->custom_fields_data_tables[$fieldinfo['datatype']]; $alias = 'f' . $fieldinfo['fieldid']; $joins[] = ' LEFT JOIN {' . $table . '} ' . $alias . ' ON ' . $alias . '.contextid=c.id AND ' . $alias . '.fieldid=' . $fieldinfo['fieldid']; } } } $from = 'FROM {' . $this->instancetable . '} i ' . implode(' ', $joins); // Assemble WHERE. $search = array(); $searchparams = array(); foreach ($q as $i => $qword) { // Add search SQL for each instance field. $searchbyfield = array(); foreach ($searchinstancefields as $field => $label) { $searchbyfield[] = 'i.' . $field . ' LIKE ?'; $searchparams[] = '%' . $qword . '%'; } // Add search SQL for each custom field. foreach ($searchcustomfields as $fieldinfo) { $searchbyfield[] = 'f' . $fieldinfo['fieldid'] . '.data LIKE ?'; $searchparams[] = '%' . $qword . '%'; } $search[] = implode(' OR ', $searchbyfield); } // Get code-forced custom vals. foreach ($this->forced_custom_vals as $fieldshortname => $forcedval) { if (isset($this->custom_fields[$fieldshortname])) { $fieldinfo = $this->custom_fields[$fieldshortname]; $search[] = 'f' . $fieldinfo['fieldid'] . '.data = ?'; $searchparams[] = $forcedval; } } // Get configured forced custom vals. if ($this->config_allowed() !== true) { foreach ($configuredforcedcustomvals as $fieldshortname => $fieldinfo) { if (isset($USER->profile[$fieldshortname])) { $search[] = 'f' . $fieldinfo['fieldid'] . '.data = ?'; $searchparams[] = $USER->profile[$fieldshortname]; } } } if (!empty($this->_restriction_sql)) { $search[] = $this->_restriction_sql; } // Construct permissions SQL filter. $contextname = $this->context_level_map[$this->contextlevel]; $permsfilter = array(); $permparams = array(); // Obtain all course contexts where this user can view reports. $contexts = get_contexts_by_capability_for_user($contextname, $this->parent_report_instance->access_capability, $this->parent_report_instance->userid); $filterobj = $contexts->get_filter('id', $contextname); $filtersql = $filterobj->get_sql(false, ''); if (isset($filtersql['where'])) { $permsfilter[] = $filtersql['where']; $permparams = $filtersql['where_parameters']; if (!is_array($permparams)) { $permparams = array(); } // ELIS-5807 -- Always be sure to include the user accessing the filter in the results! if ($contextname === 'user' && ($cmuserid = cm_get_crlmuserid($USER->id))) { $permsfilter[] = 'i.id = ?'; $permparams[] = $cmuserid; } } if (!empty($permsfilter)) { $search[] = '(' . implode(') OR (', $permsfilter) . ')'; } $where = 'WHERE (' . implode(') AND (', $search) . ')'; // Assemble + run the query. $sql = $select . ' ' . $from . ' ' . $where . ' GROUP BY i.id LIMIT 0,20'; $params = array_merge($searchparams, $permparams); return $DB->get_records_sql($sql, $params); }
/** * Determines whether the current user can view this report, based on being logged in * and php_report:view capability * @return boolean True if permitted, otherwise false */ function can_view_report() { //Check for report view capability if (!isloggedin() || isguestuser()) { return false; } $this->require_dependencies(); // make sure the current user has the capability for SOME user $contexts = get_contexts_by_capability_for_user('user', $this->access_capability, $this->userid); if (!$contexts->is_empty()) { return true; } // Since user is logged-in AND HAVE VALID PM/CM userid, then they should // always be able to see their own courses/classes, but NOT schedule if ($this->execution_mode != php_report::EXECUTION_MODE_SCHEDULED && cm_get_crlmuserid($this->userid)) { return true; } return false; }
/** * Specifies an SQL statement that will retrieve users and their cluster assignment info, class enrolments, * and resource info * * @param array $columns The list of columns automatically calculated * by get_select_columns() * @return string The report's main sql statement */ function get_report_sql($columns) { global $CFG, $CURMAN, $USER; require_once CURMAN_DIRLOCATION . '/lib/student.class.php'; $incomplete_status = STUSTATUS_NOTCOMPLETE; $cm_user_id = cm_get_crlmuserid($USER->id); $filter_array = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'userid', $this->filter); $filter_user_id = isset($filter_array[0]['value']) ? $filter_array[0]['value'] : 0; if ($filter_user_id == $cm_user_id && $this->execution_mode == php_report::EXECUTION_MODE_INTERACTIVE) { // always allow the user to see their own report but not necessarily schedule it $permissions_filter = 'TRUE'; } else { // obtain all course contexts where this user can view reports $contexts = get_contexts_by_capability_for_user('user', $this->access_capability, $this->userid); $permissions_filter = $contexts->sql_filter_for_context_level('crlmuser.id', 'user'); } //tracks progress used by this user $total_progress_subquery = "SELECT cls.id AS classid, stu.userid as userid, COUNT(*) AS numprogress, COUNT(clsgr.id) AS stucomplete\n FROM {$CURMAN->db->prefix_table(CRSCOMPTABLE)} comp\n JOIN {$CURMAN->db->prefix_table(CLSTABLE)} cls\n ON cls.courseid = comp.courseid\n LEFT JOIN {$CURMAN->db->prefix_table(STUTABLE)} stu\n ON stu.classid = cls.id\n LEFT JOIN {$CURMAN->db->prefix_table(GRDTABLE)} clsgr\n ON clsgr.classid = cls.id\n AND clsgr.userid = stu.userid\n AND clsgr.locked = 1\n AND clsgr.grade >= comp.completion_grade\n AND clsgr.completionid = comp.id\n GROUP BY cls.id, stu.userid\n "; //gets the pretest score for this user $pretest_query = $this->get_max_test_score_sql('_elis_course_pretest'); //gets the posttest score for this user $posttest_query = $this->get_max_test_score_sql('_elis_course_posttest'); //main query $sql = "SELECT {$columns},\n crs.id AS courseid,\n cls.starttimehour AS starttimehour,\n cls.starttimeminute AS starttimeminute,\n cls.endtimehour AS endtimehour,\n cls.endtimeminute AS endtimeminute\n FROM {$CURMAN->db->prefix_table(CLSTABLE)} cls\n JOIN {$CURMAN->db->prefix_table(STUTABLE)} enrol\n ON enrol.classid = cls.id\n JOIN {$CURMAN->db->prefix_table(USRTABLE)} crlmuser\n ON crlmuser.id = enrol.userid\n JOIN {$CFG->prefix}user user\n ON user.idnumber = crlmuser.idnumber\n JOIN {$CURMAN->db->prefix_table(CLSMOODLETABLE)} clsmdl\n ON clsmdl.classid = cls.id\n LEFT JOIN {$CURMAN->db->prefix_table(CRSTABLE)} crs\n ON crs.id = cls.courseid\n LEFT JOIN ({$pretest_query}) pretest\n ON pretest.classid = cls.id\n AND pretest.userid = crlmuser.id\n LEFT JOIN ({$posttest_query}) posttest\n ON posttest.classid = cls.id\n AND posttest.userid = crlmuser.id"; // add custom field joins if they exist if (isset($this->custom_joins) && is_array($this->custom_joins)) { foreach ($this->custom_joins as $custom_join) { $sql .= $custom_join; } } $sql .= " WHERE {$permissions_filter}"; return $sql; }
/** * Get the data to display for this table page. * * @param bool $download Flag to not include HTML for report download. * @return array An array of data records. */ function get_data($download = false) { global $CURMAN, $CFG, $USER; /// Don't include users with the 'groupleader' role at the site level. $context = get_context_instance(CONTEXT_SYSTEM, SITEID); $procid = get_field('role', 'id', 'shortname', 'groupleader'); $LIKE = $CURMAN->db->sql_compare(); if ($CURMAN->db->_dbconnection->databaseType == 'postgres7') { $FULLNAME = 'usr.firstname || \' \' || COALESCE(usr.mi, \'\') || \' \' || usr.lastname'; } else { $FULLNAME = 'CONCAT(usr.firstname,\' \',IFNULL(usr.mi, \'\'),\' \',usr.lastname)'; } $cselect = 'SELECT COUNT(DISTINCT usr.id) '; $select = "SELECT usr.id as id,\n usr.idnumber as idnumber,\n usr.email as email,\n MAX(usr.timecreated) as timecreated,\n usr.birthdate as birthdate,\n usr.gender as gender,\n usr.country as country,\n clst.name as clustername,\n MAX(clsgrd.timegraded) as timegraded,\n {$FULLNAME} as student,\n curass.curriculumid as curriculumid,\n cras1.curriculumid as cras1id, cras2.curriculumid as cras2id, cras3.curriculumid as cras3id\n "; $tables = "FROM " . $CURMAN->db->prefix_table(USRTABLE) . " usr\n LEFT JOIN {$CFG->prefix}user mu ON mu.idnumber = usr.idnumber\n LEFT JOIN {$CFG->prefix}role_assignments ra ON (ra.roleid = {$procid}) AND ra.contextid = {$context->id} AND ra.userid = mu.id\n LEFT JOIN " . $CURMAN->db->prefix_table(CLSGRTABLE) . " clsgrd ON clsgrd.userid = usr.id\n LEFT JOIN " . $CURMAN->db->prefix_table(CLSTUSERTABLE) . " uclst ON uclst.userid = usr.id\n LEFT JOIN " . $CURMAN->db->prefix_table(CLSTTABLE) . " clst ON clst.id = uclst.clusterid\n LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " curass ON curass.userid = usr.id\n LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " cras1 ON cras1.userid = usr.id\n LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " cras2 ON cras2.userid = usr.id AND (cras2.id != cras1.id)\n LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " cras3 ON cras3.userid = usr.id AND (cras3.id != cras1.id) AND (cras3.id != cras2.id)\n "; $timenow = time(); $yearago = $timenow - 365 * 24 * 60 * 60; $yearagostr = date('Y/m/d', $yearago); $where = "(ra.id IS NULL) "; $group = "GROUP BY usr.id "; if (!has_capability('block/curr_admin:viewreports', $context)) { if (has_capability('block/curr_admin:viewgroupreports', $context)) { $clstid = get_field(CLSTUSERTABLE, 'clusterid', 'userid', cm_get_crlmuserid($USER->id)); $where .= "AND (uclst.clusterid = {$clstid}) "; } } if ($this->extrasql) { $where .= (!empty($where) ? ' AND ' : '') . $this->extrasql . ' '; } if (!empty($where)) { $where = 'WHERE ' . $where . ' '; } if (!empty($this->sort)) { $sort = 'ORDER BY ' . $this->sort . ' ' . $this->dir . ' '; } else { $sort = ''; } if (!empty($this->perpage)) { if ($CURMAN->db->_dbconnection->databaseType == 'postgres7') { $limit = 'LIMIT ' . $this->perpage . ' OFFSET ' . $this->page * $this->perpage; } else { $limit = 'LIMIT ' . $this->page * $this->perpage . ', ' . $this->perpage; } } else { $limit = ''; } /// Count the total number of results. $sql = $cselect . $tables . $where; $this->numrecs = $CURMAN->db->count_records_sql($sql); /// Get the current 'page' of results. $sql = $select . $tables . $where . $group . $sort . $limit; $this->data = $CURMAN->db->get_records_sql($sql); $context = get_context_instance(CONTEXT_SYSTEM, SITEID); if (!empty($this->data)) { $curricula = get_records(CURTABLE); $countries = cm_get_list_of_countries(); foreach ($this->data as $di => $datum) { $datum->currentclassid = 0; $datum->currentclass = ''; $datum->lastclassid = 0; $datum->lastclass = ''; $context = get_context_instance(CONTEXT_SYSTEM, SITEID); $timenow = time(); if (!$download) { // if (has_capability('block/curr_admin:viewlocationusers', $context)) { $datum->student = '<a href="index.php?s=rep&section=rept&type=' . 'induser&frompage=enrol&user='******'">' . $datum->student . '</a>'; // } } if ($datum->timecreated > 0) { $datum->origenroldate = cm_timestamp_to_date($datum->timecreated); } else { $datum->origenroldate = get_string('unknown', 'block_curr_admin'); } $datum->birthdate = cm_timestring_to_date($datum->birthdate); $datum->timegraded = $datum->timegraded > 0 ? cm_timestamp_to_date($datum->timegraded) : ''; switch ($datum->gender) { case 'M': case 'm': $datum->gender = get_string('male', 'block_curr_admin'); break; case 'F': case 'f': $datum->gender = get_string('female', 'block_curr_admin'); break; default: $datum->gender = get_string('unknown', 'block_curr_admin'); break; } $datum->curricula = ''; if (!empty($datum->cras1id)) { $datum->curricula .= $curricula[$datum->cras1id]->name; } if (!empty($datum->cras2id)) { $datum->curricula .= !empty($datum->curricula) ? ',' : '' . $curricula[$datum->cras2id]->name; } if (!empty($datum->cras3id)) { $datum->curricula .= !empty($datum->curricula) ? ',' : '' . $curricula[$datum->cras3id]->name; } if (!empty($datum->country) && isset($countries[$datum->country])) { $datum->country = $countries[$datum->country]; } $this->data[$di] = $datum; } } }
/** * Get the data to display for this table page. * * @param bool $download Flag to not include HTML for report download. * @return array An array of data records. */ function get_data($download = false) { global $CURMAN, $USER, $CFG; $context = get_context_instance(CONTEXT_SYSTEM); /// Get records for each user, where: /// - they are in a curriculum, and /// - the courses in that curriculum have a status of 2 (PASSED), and /// - all required courses in that curriculum have a status of 2 (PASSED), and /// - the total number of credits for the passed courses is equal to or greater than the number of credits required for the curriculum $LIKE = $CURMAN->db->sql_compare(); if ($CURMAN->db->_dbconnection->databaseType == 'postgres7') { $FULLNAME = 'usr.firstname || \' \' || COALESCE(usr.mi, \'\') || \' \' || usr.lastname'; } else { $FULLNAME = 'CONCAT(usr.firstname,\' \',IFNULL(usr.mi, \'\'),\' \',usr.lastname)'; } $cselect = 'SELECT COUNT(*) '; //, cc.reqcredits as reqcredits, SUM(cce.credits) AS numcredits '; $select = "SELECT curass.id AS curasid,\n cc.name AS curname,\n clst.name as clustername,\n usr.idnumber AS idnumber,\n usr.id AS id,\n {$FULLNAME} as student,\n usr.transfercredits as transfercredits,\n cc.reqcredits as reqcredits,\n SUM(cce.credits) AS numcredits,\n MAX(cce.completetime) AS completiondate "; $tables = "FROM {$CFG->prefix}crlm_curriculum_assignment curass\n INNER JOIN {$CFG->prefix}crlm_user usr ON curass.userid = usr.id\n INNER JOIN {$CFG->prefix}crlm_curriculum cc ON curass.curriculumid = cc.id\n INNER JOIN {$CFG->prefix}crlm_curriculum_course ccc ON ccc.curriculumid = cc.id\n INNER JOIN {$CFG->prefix}crlm_class ccl ON ccl.courseid = ccc.courseid\n INNER JOIN {$CFG->prefix}crlm_class_enrolment cce ON (cce.classid = ccl.id) AND (cce.userid = curass.userid)\n LEFT JOIN " . $CURMAN->db->prefix_table(CLSTUSERTABLE) . " uclst ON uclst.userid = usr.id\n LEFT JOIN " . $CURMAN->db->prefix_table(CLSTTABLE) . " clst ON clst.id = uclst.clusterid "; $where = ""; $groupby = "GROUP BY curass.id "; //HAVING numcredits > cc.reqcredits "; /// The "HAVING" clause limits the returns to completed CURRICULA only. if (!has_capability('block/curr_admin:viewreports', $context)) { if (has_capability('block/curr_admin:viewgroupreports', $context)) { $clstid = get_field(CLSTUSERTABLE, 'clusterid', 'userid', cm_get_crlmuserid($USER->id)); $where .= "(uclst.clusterid = {$clstid}) "; } } if ($this->extrasql['where']) { $where .= (!empty($where) ? ' AND ' : '') . $this->extrasql['where'] . ' '; } if (!empty($where)) { $where = 'WHERE ' . $where . ' '; } if (isset($this->extrasql['groupby'])) { $groupby .= ' ' . $this->extrasql['groupby'] . ' '; } if (!empty($this->sort)) { $sort = 'ORDER BY ' . $this->sort . ' ' . $this->dir . ' '; } else { $sort = ''; } if (!empty($this->perpage)) { if ($CURMAN->db->_dbconnection->databaseType == 'postgres7') { $limit = 'LIMIT ' . $this->perpage . ' OFFSET ' . $this->page * $this->perpage; } else { $limit = 'LIMIT ' . $this->page * $this->perpage . ', ' . $this->perpage; } } else { $limit = ''; } /// Count the total number of results. /// Because we are using a "GROUP BY", to determine the actual number of rows returned, we need to COUNT the entire data query. $sql = $cselect . ' FROM (' . $select . $tables . $where . $groupby . ') AS numrecs'; $this->numrecs = $CURMAN->db->count_records_sql($sql); /// Get the current 'page' of results. $sql = $select . $tables . $where . $groupby . $sort . $limit; $this->data = $CURMAN->db->get_records_sql($sql); $context = get_context_instance(CONTEXT_SYSTEM, SITEID); if (!empty($this->data)) { foreach ($this->data as $di => $datum) { $context = get_context_instance(CONTEXT_SYSTEM, SITEID); if (!$download) { $datum->student = '<a href="index.php?s=rep&section=rept&type=' . 'induser&frompage=curricula&user='******'">' . $datum->student . '</a> ' . ' ' . '<a href="index.php?s=rep&section=rept&type=' . 'transcript&frompage=curricula&user='******'">' . get_string('transcript', 'block_curr_admin') . '</a>'; $datum->completiondate = $datum->completiondate > 0 ? userdate($datum->completiondate, '%b %d, %Y') : '-'; } $this->data[$di] = $datum; } } }
require_login(); } if ($COURSE->id == SITEID) { $context = context_system::instance(); } else { $context = context_course::instance($COURSE->id); } require_capability('block/enrolsurvey:take', $context); if (cm_get_crlmuserid($USER->id) === false) { // ***TBD*** print_error(get_string('noelisuser', 'block_enrolsurvey')); } //set the page context to either the system or course context $PAGE->set_context($context); $moodle_user = get_complete_user_data('id', $USER->id); $elis_user = new user(cm_get_crlmuserid($USER->id)); $elis_user->load(); $courseobj = new stdClass(); $courseobj->courseid = $course->id; $courseobj->mymoodle = $mymoodle; $surveyform = new survey_form($CFG->wwwroot . '/blocks/enrolsurvey/survey.php?id=' . $instanceid, $courseobj); if ($surveyform->is_cancelled()) { if ($mymoodle == 1) { redirect($CFG->wwwroot . '/my'); } else { redirect($CFG->wwwroot . '/course/view.php?id=' . $course->id); } } else { if ($formdata = $surveyform->get_data()) { $customfields = get_customfields(); $profilefields = get_profilefields();
function __construct(&$items, $pageurl) { global $USER; $this->cuserid = cm_get_crlmuserid($USER->id); $columns = array('courseid' => array('header' => get_string('course_idnumber', 'local_elisprogram')), 'coursename' => array('header' => get_string('course', 'local_elisprogram')), 'classname' => array('header' => get_string('class', 'local_elisprogram')), 'startdate' => array('header' => get_string('class_startdate', 'local_elisprogram')), 'enddate' => array('header' => get_string('class_enddate', 'local_elisprogram')), 'timeofday' => array('header' => get_string('timeofday', 'local_elisprogram')), 'instructor' => array('header' => get_string('instructor', 'local_elisprogram'))); $this->yui_formatters = array('timeofday' => 'cmFormatTimeRange', 'startdate' => 'cmFormatDate', 'enddate' => 'cmFormatDate'); $this->yui_parsers = array(); $this->yui_sorters = array('timeofday' => 'cmSortTimeRange'); parent::__construct($items, $columns, $pageurl); //$this->table->width = '80%'; // TBD }
/** * Get the default repository location. * * @uses $CFG, $COURSE, $USER * @param int $cid A course record ID. * @param int $uid A user record ID. * @param bool $shared A flag to indicate whether the user is currently located in the shared repository area. * @param int $oid A userset record ID. * @return string The UUID of the last location the user was browsing files in. */ function get_default_browsing_location(&$cid, &$uid, &$shared, &$oid) { global $CFG, $COURSE, $USER, $DB; // If the default location is not set at all, just return nothing now. if (!isset($this->config->default_browse)) { return false; } elseif (isset($this->config->default_browse)) { // Handle determining if the user can actually access the chosen default location. if (empty($cid)) { $cid = $COURSE->id; } $syscontext = context_system::instance(); if ($cid == SITEID) { $context = $syscontext; } else { $context = context_course::instance($cid); } /* **** Disable following block for ELIS-7127 **** // If on ELIS Files page or in course context - default to course page if we have access to it if ($cid != SITEID && (has_capability('repository/elisfiles:viewcoursecontent', $context) || has_capability('repository/elisfiles:createcoursecontent', $context))) { $shared = 0; $uid = 0; return $this->get_course_store($cid); } else if ($cid == SITEID && $uid == 0 && (has_capability('repository/elisfiles:viewsitecontent', $context) || has_capability('repository/elisfiles:createsitecontent', $context))) { // If on home page and not in user context - default to Company Home if we have access to it $root = $this->get_root(); if (!empty($root->uuid)) { $shared = 0; $uid = 0; return $root->uuid; } } **** END Disable block for ELIS-7127 **** */ $oid = 0; /** * ELIS-7452: We're gonna go thru all possible browing locations * in pre-determined order: * User > Site > Shared [> Userset > Course] * but we'll put desired default_browsing location first! */ $browsing_locs = array(ELIS_FILES_BROWSE_USER_FILES, ELIS_FILES_BROWSE_SITE_FILES, ELIS_FILES_BROWSE_SHARED_FILES, ELIS_FILES_BROWSE_COURSE_FILES, ELIS_FILES_BROWSE_USERSET_FILES); $default_entry = array_search($this->config->default_browse, $browsing_locs); if ($default_entry !== false) { array_splice($browsing_locs, $default_entry, 1); } $browsing_locs = array_merge(array($this->config->default_browse), $browsing_locs); // If a user does not have permission to access the default location, fall through to the next // lower level to see if they can access that location. // TBD: MUST CHECK FOR CAPABILITIES AY ANY CONTEXT LEVEL!!! foreach ($browsing_locs as $browse_loc) { switch ($browse_loc) { case ELIS_FILES_BROWSE_SITE_FILES: if (has_capability('repository/elisfiles:viewsitecontent', $syscontext) || has_capability('repository/elisfiles:createsitecontent', $syscontext)) { $root = $this->get_root(); if (!empty($root->uuid)) { $shared = 0; $uid = 0; $cid = 0; return $root->uuid; } } break; case ELIS_FILES_BROWSE_SHARED_FILES: // Get the non context based permissions $capabilities = array( 'repository/elisfiles:viewsharedcontent' => false, 'repository/elisfiles:createsharedcontent'=> false ); $this->get_other_capabilities($USER, $capabilities); $has_permission = $capabilities['repository/elisfiles:viewsharedcontent'] || $capabilities['repository/elisfiles:createsharedcontent'] || has_capability('repository/elisfiles:viewsitecontent', $syscontext) || has_capability('repository/elisfiles:createsitecontent', $syscontext); if ($has_permission) { $shared = true; $uid = 0; $cid = 0; return $this->suuid; } break; case ELIS_FILES_BROWSE_COURSE_FILES: $has_permission = false; if ($cid == SITEID && $COURSE->id != SITEID) { $cid = $COURSE->id; } if (!$cid || $cid == SITEID) { // TBD: no valid $COURSE so just find first one??? $courses = enrol_get_my_courses(); if (empty($courses)) { $cid = 0; break; } foreach ($courses as $course) { $context = context_course::instance($course->id); $has_permission = has_capability('repository/elisfiles:viewcoursecontent', $context) || has_capability('repository/elisfiles:createcoursecontent', $context) || has_capability('repository/elisfiles:viewsitecontent', $syscontext) || has_capability('repository/elisfiles:createsitecontent', $syscontext); if ($has_permission) { $cid = $course->id; break; } } } if ($cid && $cid != SITEID) { if (!$has_permission) { $context = context_course::instance($cid); $has_permission = has_capability('repository/elisfiles:viewcoursecontent', $context) || has_capability('repository/elisfiles:createcoursecontent', $context) || has_capability('repository/elisfiles:viewsitecontent', $syscontext) || has_capability('repository/elisfiles:createsitecontent', $syscontext); } if ($has_permission) { $shared = 0; $uid = 0; return $this->get_course_store($cid); } } $cid = 0; break; case ELIS_FILES_BROWSE_USER_FILES: $context = context_user::instance($USER->id); $has_permission = has_capability('repository/elisfiles:viewowncontent', $syscontext) || has_capability('repository/elisfiles:createowncontent', $syscontext) || has_capability('repository/elisfiles:viewowncontent', $context) || has_capability('repository/elisfiles:createowncontent', $context) || has_capability('repository/elisfiles:viewsitecontent', $syscontext) || has_capability('repository/elisfiles:createsitecontent', $syscontext); if ($has_permission) { if (empty($this->uuuid)) { $this->uuuid = $this->elis_files_userdir($USER->username); } if (($uuid = $this->uuuid) !== false) { $shared = 0; $uid = $USER->id; $cid = 0; return $uuid; } } break; case ELIS_FILES_BROWSE_USERSET_FILES: if (!file_exists($CFG->dirroot.'/local/elisprogram/accesslib.php')) { break; } require_once($CFG->dirroot.'/local/elisprogram/accesslib.php'); require_once($CFG->dirroot.'/local/elisprogram/lib/setup.php'); require_once($CFG->dirroot.'/local/elisprogram/lib/deprecatedlib.php'); $crlm_user = cm_get_crlmuserid($USER->id); if ($crlm_user === false) { break; } $contextclass = \local_eliscore\context\helper::get_class_for_level(CONTEXT_ELIS_USERSET); $assignments = $DB->get_records('local_elisprogram_uset_asign', array('userid' => $crlm_user)); // TBD: just get the first valid userset store??? foreach ($assignments as $cluster_assignment) { $context = $contextclass::instance($cluster_assignment->clusterid); $has_permission = has_capability('repository/elisfiles:viewusersetcontent', $context) || has_capability('repository/elisfiles:createusersetcontent', $context) || has_capability('repository/elisfiles:viewsitecontent', $syscontext) || has_capability('repository/elisfiles:createsitecontent', $syscontext); if ($has_permission) { $uuid = $this->get_userset_store($cluster_assignment->clusterid); if (!empty($uuid)) { $oid = $cluster_assignment->clusterid; $shared = 0; $uid = 0; $cid = 0; return $uuid; } } } break; } } } return false; }
/** * Check for access to the specified user. * (currently, this only verifies cluster groups) * */ function cm_can_access_userreport($touserid, $fromuserid = 0) { global $USER, $CURMAN; if ($fromuserid == 0) { $fromuserid = cm_get_crlmuserid($USER->id); } // check if there is a cluster that contains both users return $CURMAN->db->record_exists_sql('SELECT c1.id FROM ' . $CURMAN->db->prefix_table(CLSTUSERTABLE) . ' c1 INNER JOIN ' . $CURMAN->db->prefix_table(CLSTUSERTABLE) . ' c2 ON c1.clusterid = c2.clusterid WHERE c1.userid = ' . $touserid . ' AND c2.userid = ' . $fromuserid); }
function cluster_profile_update_handler($userdata) { global $CURMAN, $CFG; // make sure a CM user exists cm_moodle_user_to_cm($userdata); $cuid = cm_get_crlmuserid($userdata->id); if (empty($cuid)) { // not a curriculum user -- (guest?) return true; } $usrtable = $CURMAN->db->prefix_table(USRTABLE); $clstproftable = $CURMAN->db->prefix_table(CLSTPROFTABLE); $clstasstable = $CURMAN->db->prefix_table(CLSTASSTABLE); // the cluster assignments that the plugin wants to exist $new_assignments = "(SELECT DISTINCT cu.id as userid, cp.clusterid\n FROM {$CFG->prefix}crlm_cluster_profile cp\n INNER JOIN {$CFG->prefix}crlm_user cu ON cu.id = {$cuid}\n INNER JOIN {$CFG->prefix}user mu on cu.idnumber=mu.idnumber AND mu.mnethostid = {$CFG->mnet_localhost_id}\n WHERE (SELECT COUNT(*)\n FROM {$CFG->prefix}crlm_cluster_profile cp1\n JOIN (SELECT i.userid, i.fieldid, i.data FROM {$CFG->prefix}user_info_data i\n WHERE i.userid = {$userdata->id}\n UNION\n SELECT {$userdata->id} as userid, uif.id as fieldid, uif.defaultdata as data\n FROM {$CFG->prefix}user_info_field uif\n LEFT JOIN {$CFG->prefix}user_info_data i ON i.userid={$userdata->id} AND uif.id = i.fieldid\n WHERE i.id IS NULL\n ) inf ON inf.fieldid = cp1.fieldid AND inf.data = cp1.value\n WHERE cp.clusterid=cp1.clusterid AND inf.userid = mu.id)\n = (SELECT COUNT(*) FROM {$CFG->prefix}crlm_cluster_profile cp1 WHERE cp.clusterid = cp1.clusterid))"; // delete existing assignments that should not be there any more if ($CFG->dbfamily == 'postgres') { $delete = "DELETE FROM {$clstasstable}\n WHERE id IN (\n SELECT id FROM {$clstasstable} a\n LEFT OUTER JOIN {$new_assignments} b ON a.clusterid = b.clusterid AND a.userid = b.userid\n WHERE a.userid = {$cuid} AND b.clusterid IS NULL\n ) AND plugin='profile'"; } else { $delete = "DELETE a FROM {$clstasstable} a\n LEFT OUTER JOIN {$new_assignments} b ON a.clusterid = b.clusterid AND a.userid = b.userid\n WHERE a.userid = {$cuid} AND b.clusterid IS NULL AND a.plugin='profile'"; } $CURMAN->db->execute_sql($delete, false); // add new assignments $insert = "INSERT INTO {$clstasstable}\n (clusterid, userid, plugin)\n SELECT a.clusterid, a.userid, 'profile'\n FROM {$new_assignments} a\n LEFT OUTER JOIN {$clstasstable} b ON a.clusterid = b.clusterid AND a.userid = b.userid AND b.plugin='profile'\n WHERE a.userid = {$cuid} AND b.clusterid IS NULL"; $CURMAN->db->execute_sql($insert, false); cluster::cluster_update_assignments(null, $cuid); return true; }
require_once dirname(__FILE__) . '/../../config.php'; require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php'; require_once elispm::lib('deprecatedlib.php'); // cm_get_crlmuserid() require_once elispm::lib('data/user.class.php'); require_once elispm::lib('data/course.class.php'); require_once elispm::lib('data/certificatesettings.class.php'); require_once elispm::lib('data/certificateissued.class.php'); require_once elispm::lib('data/student.class.php'); require_once elispm::lib('data/instructor.class.php'); $ciid = required_param('id', PARAM_INT); // Issued certificate id $csid = required_param('csid', PARAM_INT); // certificate setting id global $USER; $cmuserid = cm_get_crlmuserid($USER->id); $student = new user($cmuserid); $student->load(); if (empty($student->id)) { return get_string('studentnotfound', 'local_elisprogram'); } // Retrieve the certificate settings record $certsettingrec = new certificatesettings($csid); $certsettingrec->load(); // Check if the record exists or if the certificate is disabled if (empty($certsettingrec->id) and !empty($certsettingrec->disable)) { // Passing hard coded error code to disallow administrators from changing them to // custom strings echo get_string('errorfindingcertsetting', 'local_elisprogram', 'Error 11'); } // Retrieve the certificate issued record
function __construct(&$items) { global $USER; $this->cuserid = cm_get_crlmuserid($USER->id); $columns = array('coursename' => get_string('coursename', 'block_curr_admin'), 'courseid' => get_string('course_id', 'block_curr_admin'), 'classname' => ''); parent::__construct($items, $columns, ''); $this->table->width = '80%'; }