/** * Sets up the fields necessary for enabling cluster theming * * @return boolean Returns true to indicate success */ function cluster_themes_install() { //retrieve the cluster context $cluster_context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); //set up the cluster theme category $theme_category = new field_category(); $theme_category->name = get_string('cluster_theme_category', 'crlm_cluster_themes'); //set up the theme priority field $theme_priority_field = new field(); $theme_priority_field->shortname = 'cluster_themepriority'; $theme_priority_field->name = get_string('cluster_theme_priority', 'crlm_cluster_themes'); $theme_priority_field->datatype = 'int'; //set up the field and category $theme_priority_field = field::ensure_field_exists_for_context_level($theme_priority_field, $cluster_context, $theme_category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'text', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_themes/cluster_themepriority'); field_owner::ensure_field_owner_exists($theme_priority_field, 'manual', $owner_options); //set up the field for selecting the applicable theme $theme_field = new field(); $theme_field->shortname = 'cluster_theme'; $theme_field->name = get_string('cluster_theme', 'crlm_cluster_themes'); $theme_field->datatype = 'char'; //set up the field and category $theme_field = field::ensure_field_exists_for_context_level($theme_field, $cluster_context, $theme_category); $owner_options = array('control' => 'menu', 'options_source' => 'themes', 'required' => 0, 'edit_capability' => '', 'view_capability' => '', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_themes/cluster_theme'); field_owner::ensure_field_owner_exists($theme_field, 'manual', $owner_options); return true; }
/** * Appends additional data to query parameters based on existence of theme priority field * * @param string $cluster_id_field The field to join on for the cluster id * @param string $select The current select clause * @param string $join The current join clause */ function cluster_display_priority_append_sort_data($cluster_id_field, &$select, &$join) { global $CURMAN; //make sure we can get the field we need for ordering if ($theme_priority_field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_DISPLAY_PRIORITY_FIELD)) and $contextlevel = context_level_base::get_custom_context_level('cluster', 'block_curr_admin')) { $field_data_table = $CURMAN->db->prefix_table($theme_priority_field->data_table()); //use this for easier naming in terms of sorting $select .= ', field_data.data AS priority '; $join .= "LEFT JOIN ({$CURMAN->db->prefix_table('context')} context\n JOIN {$field_data_table} field_data\n ON field_data.contextid = context.id\n AND field_data.fieldid = {$theme_priority_field->id})\n\n ON context.contextlevel = {$contextlevel}\n AND context.instanceid = {$cluster_id_field} "; } }
/** * Check if the user has the given capability for the requested user */ function _has_capability($capability, $id = null) { $id = $id ? $id : $this->required_param('id', PARAM_INT); // user contexts are different -- we rely on the cache because clusters // require special logic usermanagementpage::get_contexts($capability); $cached = usermanagementpage::check_cached($capability, $id); if ($cached !== null) { return $cached; } $context = get_context_instance(context_level_base::get_custom_context_level('user', 'block_curr_admin'), $id); return has_capability($capability, $context); }
/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ function pre_post_test_install() { global $CFG; require_once $CFG->dirroot . '/curriculum/config.php'; require_once CURMAN_DIRLOCATION . '/lib/customfield.class.php'; $course_ctx_lvl = context_level_base::get_custom_context_level('course', 'block_curr_admin'); // Pre-test field $field = new field(); $field->shortname = '_elis_course_pretest'; $field->name = get_string('pre_test_field_name', 'crlm_pre_post_test'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('pre_post_test_category_name', 'crlm_pre_post_test'); $field = field::ensure_field_exists_for_context_level($field, 'course', $category); // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = ''; $owner->param_control = 'menu'; $owner->param_options_source = 'completion_elements'; $owner->add(); } // Post-test field $field = new field(); $field->shortname = '_elis_course_posttest'; $field->name = get_string('post_test_field_name', 'crlm_pre_post_test'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('pre_post_test_category_name', 'crlm_pre_post_test'); $field = field::ensure_field_exists_for_context_level($field, 'course', $category); // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = ''; $owner->param_control = 'menu'; $owner->param_options_source = 'completion_elements'; $owner->add(); } return true; }
/** * items in the form */ public function definition() { global $CURMAN, $CFG; parent::definition(); $mform =& $this->_form; $mform->addElement('hidden', 'id'); $mform->addElement('text', 'name', get_string('cluster_name', 'block_curr_admin') . ':'); $mform->addRule('name', get_string('required'), 'required', NULL, 'client'); $mform->setHelpButton('name', array('clusterform/name', get_string('cluster_name', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('textarea', 'display', get_string('cluster_description', 'block_curr_admin') . ':', array('cols' => 40, 'rows' => 2)); $mform->setHelpButton('display', array('clusterform/display', get_string('cluster_description', 'block_curr_admin'), 'block_curr_admin')); $current_cluster_id = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : ''; //obtain the non-child clusters that we could become the child of, with availability //determined based on the edit capability $contexts = clusterpage::get_contexts('block/curr_admin:cluster:edit'); $non_child_clusters = cluster_get_non_child_clusters($current_cluster_id, $contexts); //parent dropdown $mform->addElement('select', 'parent', get_string('cluster_parent', 'block_curr_admin') . ':', $non_child_clusters); $mform->setHelpButton('parent', array('clusterform/parent', get_string('cluster_parent', 'block_curr_admin'), 'block_curr_admin')); // allow plugins to add their own fields $plugins = get_list_of_plugins('curriculum/cluster'); $mform->addElement('header', 'userassociationfieldset', get_string('userassociation', 'block_curr_admin')); foreach ($plugins as $plugin) { require_once CURMAN_DIRLOCATION . '/cluster/' . $plugin . '/lib.php'; call_user_func('cluster_' . $plugin . '_edit_form', $this); } // custom fields $fields = field::get_for_context_level('cluster'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }
function cluster_classification_install() { global $CFG; require_once $CFG->dirroot . '/curriculum/config.php'; require_once CURMAN_DIRLOCATION . '/lib/customfield.class.php'; require_once CURMAN_DIRLOCATION . '/plugins/cluster_classification/clusterclassification.class.php'; $cluster_ctx_lvl = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $field = new field(); $field->shortname = CLUSTER_CLASSIFICATION_FIELD; $field->name = get_string('classification_field_name', 'crlm_cluster_classification'); $field->datatype = 'char'; $category = new field_category(); $category->name = get_string('classification_category_name', 'crlm_cluster_classification'); $field = field::ensure_field_exists_for_context_level($field, 'cluster', $category); // make sure we're set as owner if (!isset($field->owners['cluster_classification'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'cluster_classification'; $owner->add(); } // make sure 'manual' is an owner if (!isset($field->owners['manual'])) { $owner = new field_owner(); $owner->fieldid = $field->id; $owner->plugin = 'manual'; $owner->param_view_capability = ''; $owner->param_edit_capability = 'moodle/user:update'; $owner->param_control = 'menu'; $owner->param_options_source = 'cluster_classifications'; $owner->add(); } // make sure we have a default value set if (!field_data::get_for_context_and_field(NULL, $field)) { field_data::set_for_context_and_field(NULL, $field, 'regular'); } $default = new clusterclassification(); $default->shortname = 'regular'; $default->name = get_string('cluster', 'block_curr_admin'); $default->param_autoenrol_curricula = 1; $default->param_autoenrol_tracks = 1; $default->add(); return true; }
function definition() { $form =& $this->_form; $form->addElement('hidden', 'id'); $form->setType('id', PARAM_INT); // common form elements (copied from /user/profile/definelib.php) $form->addElement('header', '_commonsettings', get_string('profilecommonsettings', 'admin')); $strrequired = get_string('required'); $form->addElement('text', 'shortname', get_string('profileshortname', 'admin'), 'maxlength="100" size="25"'); $form->addRule('shortname', $strrequired, 'required', null, 'client'); $form->setType('shortname', PARAM_SAFEDIR); $form->addElement('text', 'name', get_string('profilename', 'admin'), 'size="50"'); $form->addRule('name', $strrequired, 'required', null, 'client'); $form->setType('name', PARAM_MULTILANG); $level = $this->_customdata->required_param('level', PARAM_ACTION); $ctxlvl = context_level_base::get_custom_context_level($level, 'block_curr_admin'); $categories = field_category::get_for_context_level($ctxlvl); $choices = array(); foreach ($categories as $category) { $choices[$category->id] = $category->name; } $form->addElement('select', 'categoryid', get_string('profilecategory', 'admin'), $choices); $form->addElement('htmleditor', 'description', get_string('profiledescription', 'admin')); $form->setHelpButton('description', array('text', get_string('helptext'))); $choices = array('text' => get_string('field_datatype_text', 'block_curr_admin'), 'char' => get_string('field_datatype_char', 'block_curr_admin'), 'int' => get_string('field_datatype_int', 'block_curr_admin'), 'num' => get_string('field_datatype_num', 'block_curr_admin'), 'bool' => get_string('field_datatype_bool', 'block_curr_admin')); $form->addElement('select', 'datatype', get_string('field_datatype', 'block_curr_admin'), $choices); $form->addElement('advcheckbox', 'forceunique', get_string('profileforceunique', 'admin')); $form->setAdvanced('forceunique'); $form->addElement('advcheckbox', 'multivalued', get_string('field_multivalued', 'block_curr_admin')); $form->setAdvanced('multivalued'); $form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"'); $form->setType('defaultdata', PARAM_MULTILANG); $plugins = get_list_of_plugins('curriculum/plugins'); foreach ($plugins as $plugin) { if (is_readable(CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php')) { include_once CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php'; if (function_exists("{$plugin}_field_edit_form_definition")) { call_user_func("{$plugin}_field_edit_form_definition", $this); } } } $this->add_action_buttons(true); }
function sync_profile_field_from_moodle($field) { global $CURMAN; $level = context_level_base::get_custom_context_level('user', 'block_curr_admin'); if (!isset($field->owners['moodle_profile']) || $field->owners['moodle_profile']->exclude == cm_moodle_profile::sync_to_moodle) { // not owned by the Moodle plugin, or set to sync to Moodle return true; } if (!$CURMAN->db->record_exists('user_info_field', 'shortname', $field->shortname)) { // no Moodle field to sync with return true; } $dest = $field->data_table(); $src = 'user_info_data'; $mfieldid = $CURMAN->db->get_field('user_info_field', 'id', 'shortname', $field->shortname); $joins = "JOIN {$CURMAN->db->prefix_table('crlm_user')} cu ON usr.idnumber = cu.idnumber\n JOIN {$CURMAN->db->prefix_table('context')} ctx ON ctx.instanceid = cu.id AND ctx.contextlevel = {$level}\n JOIN {$CURMAN->db->prefix_table($src)} src ON src.userid = usr.id AND src.fieldid = {$mfieldid}"; // insert field values that don't already exist $sql = "INSERT INTO {$CURMAN->db->prefix_table($dest)}\n (contextid, fieldid, data)\n SELECT ctx.id AS contextid, {$field->id} AS fieldid, src.data\n FROM {$CURMAN->db->prefix_table('user')} usr\n {$joins}\n LEFT JOIN {$CURMAN->db->prefix_table($dest)} dest ON dest.contextid = ctx.id AND dest.fieldid = {$field->id}\n WHERE dest.id IS NULL"; $CURMAN->db->execute_sql($sql, false); // update already-existing values $sql = "UPDATE {$CURMAN->db->prefix_table($dest)} dest\n JOIN {$CURMAN->db->prefix_table('user')} usr\n {$joins}\n SET dest.data = src.data\n WHERE dest.fieldid = {$field->id}\n AND dest.contextid = ctx.id"; $CURMAN->db->execute_sql($sql, false); }
/** * ELIS(TM): Enterprise Learning Intelligence Suite * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage curriculummanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ function xmldb_crlm_cluster_groups_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; if ($result && $oldversion < 2010080602) { require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php'; require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php'; $field = new field(field::get_for_context_level_with_name('cluster', 'cluster_group')); if (isset($field->owners['manual'])) { $owner = new field_owner($field->owners['manual']); $owner->param_help_file = 'crlm_cluster_groups/cluster_groups'; $owner->update(); } } if ($result && $oldversion < 2010080603) { //retrieve the cluster context $context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); //get the cluster classification category $category = new field_category(); $category->name = get_string('cluster_group_category', 'crlm_cluster_groups'); $field = new field(); $field->shortname = 'cluster_groupings'; $field->name = get_string('autoenrol_groupings', 'crlm_cluster_classification'); $field->datatype = 'bool'; $field = field::ensure_field_exists_for_context_level($field, $context, $category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_groups/cluster_groupings'); field_owner::ensure_field_owner_exists($field, 'manual', $owner_options); } if ($result && $oldversion < 2010080604) { if ($field = new field(field::get_for_context_level_with_name('cluster', 'cluster_site_course_group'))) { $field->shortname = 'cluster_groupings'; $field->update(); } } return $result; }
/** * Check if curricula values are displayed * * @return bool True means there are curricula values to display. */ function check_curricula() { $customfields = array(); if ($this->_show_curricula === null) { // Check for output columns $filters = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'filter-summarycolumns', $this->filter); $cols = $filters[0]['value']; // Check if any curricula fields are displayed. foreach ($cols as $col => $value) { if (substr($col, 0, 4) === 'cur_' && $value) { $this->_show_curricula = true; break; } else { if (substr($col, 0, 7) === 'custom_' && $value) { $customfields[substr($col, 7)] = 1; } } } } if ($this->_show_curricula === null) { $level = context_level_base::get_custom_context_level('curriculum', 'block_curr_admin'); // Check for custom fields to display $curriculumfields = get_records('crlm_field_contextlevel', 'contextlevel', $level); foreach ($curriculumfields as $field) { if (array_key_exists($field->fieldid, $customfields)) { $this->_show_curricula = true; break; } } } if ($this->_show_curricula === null) { // Check for filters $filters = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'filter-ccc-curriculum-name', $this->filter); if (!empty($filters[0]['value'])) { $this->_show_curricula = true; } } if ($this->_show_curricula === null) { $this->_show_curricula = false; } return $this->_show_curricula; }
/** * Return the maximum test score SQL statement * * @param string $field_shortname field short name to be used in get_field request * * @return string The appropriate SQL statement */ function get_max_test_score_sql($field_shortname) { global $CURMAN, $CFG; $course_context_level = context_level_base::get_custom_context_level('course', 'block_curr_admin'); if ($field_id = get_field('crlm_field', 'id', 'shortname', $field_shortname)) { $field = new field($field_id); $data_table = $CURMAN->db->prefix_table($field->data_table()); $sql = "SELECT MAX(clsgrd.grade) AS score,\n class.id AS classid,\n clsgrd.userid AS userid\n FROM {$data_table} d\n JOIN {$CURMAN->db->prefix_table('context')} ctxt\n ON d.contextid = ctxt.id\n AND ctxt.contextlevel = {$course_context_level}\n JOIN {$CURMAN->db->prefix_table(CRSCOMPTABLE)} comp\n ON d.data = comp.idnumber\n JOIN {$CURMAN->db->prefix_table(CLSTABLE)} class\n ON class.courseid = ctxt.instanceid\n JOIN {$CURMAN->db->prefix_table(GRDTABLE)} clsgrd\n ON clsgrd.classid = class.id\n AND clsgrd.locked = 1\n AND clsgrd.completionid = comp.id\n WHERE d.fieldid = {$field_id}\n GROUP BY class.id, clsgrd.userid\n "; } else { $sql = "SELECT NULL AS score, NULL AS classid, NULL as userid FROM {$CFG->prefix}user"; } return $sql; }
function html_header($course, $wdir, $formfield = "") { global $CFG, $ME, $USER, $id, $shared, $userid, $oid, $uuid, $repo, $canedit; /// Get the appropriate context for the site, course or organization. if (!empty($oid)) { $cluster_context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $oid); } if ($id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM, SITEID); } else { $context = get_context_instance(CONTEXT_COURSE, $id); } /// Make sure that we have the correct 'base' UUID for a course or user storage area as well /// as checking for correct permissions. if (!empty($userid) && !empty($id)) { $personalfiles = false; if (!empty($USER->access['rdef'])) { foreach ($USER->access['rdef'] as $ucontext) { if ($personalfiles) { continue; } if (isset($ucontext['block/repository:viewowncontent']) && $ucontext['block/repository:viewowncontent'] == CAP_ALLOW) { $personalfiles = true; } } } if (!$personalfiles) { $capabilityname = get_capability_string('block/repository:viewowncontent'); print_error('nopermissions', '', '', $capabilityname); exit; } if (empty($uuid)) { $uuid = $repo->get_user_store($userid); } } else { if (empty($userid) && !empty($shared)) { $sharedfiles = false; if (!empty($USER->access['rdef'])) { foreach ($USER->access['rdef'] as $ucontext) { if ($sharedfiles) { continue; } if (isset($ucontext['block/repository:viewsharedcontent']) && $ucontext['block/repository:viewsharedcontent'] == CAP_ALLOW) { $sharedfiles = true; } } } if (!$sharedfiles) { $capabilityname = get_capability_string('block/repository:viewsharedcontent'); print_error('nopermissions', '', '', $capabilityname); exit; } if (empty($uuid)) { $uuid = $repo->suuid; } } else { if (!empty($id) && empty($oid) && $id != SITEID) { require_capability('block/repository:viewcoursecontent', $context, $USER->id); if (empty($uuid)) { $uuid = $repo->get_course_store($id); } } else { if (!empty($oid)) { require_capability('block/repository:vieworganizationcontent', $cluster_context, $USER->id); if (empty($uuid)) { $uuid = $repo->get_organization_store($oid); } } else { require_capability('block/repository:viewsitecontent', $context, $USER->id); if (empty($uuid)) { if ($root = $repo->get_root()) { $uuid = $root->uuid; } } } } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>coursefiles</title> <script type="text/javascript"> //<![CDATA[ function set_value(params) { /// function's argument is an object containing necessary values /// to export parent window (url,isize,itype,iwidth,iheight, imodified) /// set values when user click's an image name. var upper = window.parent; var insimg = upper.document.getElementById('f_url'); try { if(insimg != null) { if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1) { alert("<?php print_string("notimage", "editor"); ?> "); return false; } for(field in params) { var value = params[field]; switch(field) { case "url" : upper.document.getElementById('f_url').value = value; upper.ipreview.location.replace('<?php echo $CFG->wwwroot; ?> /lib/editor/htmlarea/popups/preview.php?id='+ <?php print $course->id; ?> +'&imageurl='+ value); break; case "isize" : upper.document.getElementById('isize').value = value; break; case "itype" : upper.document.getElementById('itype').value = value; break; case "iwidth": upper.document.getElementById('f_width').value = value; break; case "iheight": upper.document.getElementById('f_height').value = value; break; } } } else { for(field in params) { var value = params[field]; switch(field) { case "url" : //upper.document.getElementById('f_href').value = value; upper.opener.document.getElementById('f_href').value = value; upper.close(); break; //case "imodified" : upper.document.getElementById('imodified').value = value; break; //case "isize" : upper.document.getElementById('isize').value = value; break; //case "itype" : upper.document.getElementById('itype').value = value; break; } } } } catch(e) { if ( window.tinyMCE != "undefined" || window.TinyMCE != "undefined" ) { upper.opener.Dialog._return(params.url); upper.close(); } else { alert("Something odd just occurred!!!"); } } return false; } function set_dir(strdir) { // sets wdir values var upper = window.parent.document; if(upper) { for(var i = 0; i < upper.forms.length; i++) { var f = upper.forms[i]; if(f.wdir != undefined) { //TODO: this needs to be replaced since it never seems to be used try { f.wdir.value = strdir; } catch (e) { } } } } } function set_rename(strfile) { var upper = window.parent.document; //ERROR: element irename does not exist needs to be replaced with proper element // upper.getElementById('irename').value = strfile; //this or next line // upper.getElementById('irename').file.value = strfile; return true; } function reset_value() { var upper = window.parent.document; for(var i = 0; i < upper.forms.length; i++) { var f = upper.forms[i]; for(var j = 0; j < f.elements.length; j++) { var e = f.elements[j]; // Do not reset submit, button, hidden, or select-one types if(e.type != "submit" && e.type != "button" && e.type != "hidden" && e.type != "select-one") { try { e.value = ""; } catch (e) { } } } } //ERROR: there is no element irename this needs to be replaced with the proper element // upper.getElementById('irename').value = 'xx'; var prev = window.parent.ipreview; if(prev != null) { prev.location.replace('about:blank'); } var uploader = window.parent.document.forms['uploader']; if(uploader != null) { uploader.reset(); } set_dir('<?php print $wdir; ?> '); return true; } //]]> </script> <style type="text/css"> body { background-color: white; margin-top: 2px; margin-left: 4px; margin-right: 4px; } body,p,table,td,input,select,a { font-family: Tahoma, sans-serif; font-size: 11px; } select { position: absolute; top: -20px; left: 0px; } img.icon { vertical-align:middle; margin-right:4px; width:16px; height:16px; border:0px; } </style> </head> <body onload="reset_value();"> <?php }
function definition() { global $USER, $CFG, $COURSE, $CURMAN; parent::definition(); if (!empty($this->_customdata['obj'])) { $obj = $this->_customdata['obj']; if (empty($obj->startdate) || $obj->startdate == 0) { $this->set_data(array('disablestart' => '1')); } if (empty($obj->enddate) || $obj->enddate == 0) { $this->set_data(array('disableend' => '1')); } if (isset($obj->starttimeminute) && isset($obj->starttimehour)) { $this->set_data(array('starttime' => array('minute' => $obj->starttimeminute, 'hour' => $obj->starttimehour))); } if (isset($obj->endtimeminute) && isset($obj->endtimehour)) { $this->set_data(array('endtime' => array('minute' => $obj->endtimeminute, 'hour' => $obj->endtimehour))); } } $mform =& $this->_form; $mform->addElement('hidden', 'id'); // If there is no custom data for the course, create some if (empty($this->_customdata['obj']->course->name) || empty($this->_customdata['obj']->id)) { $courses = array(); if (!empty($USER->id)) { $contexts = get_contexts_by_capability_for_user('course', 'block/curr_admin:class:create', $USER->id); // get listing of available ELIS courses $courses = course_get_listing('name', 'ASC', 0, 0, '', '', $contexts); } // Add course select $attributes = array('onchange' => 'update_trk_multiselect(); '); $selections = array(); if (!empty($courses)) { foreach ($courses as $course) { $selections[$course->id] = '(' . $course->idnumber . ')' . $course->name; } } $mform->addElement('select', 'courseid', get_string('course', 'block_curr_admin') . ':', $selections, $attributes); $mform->setHelpButton('courseid', array('cmclassform/course', get_string('course', 'block_curr_admin'), 'block_curr_admin')); $firstcourse = reset($courses); $this->firstcourse = $firstcourse; if (false !== $firstcourse && empty($this->_customdata['obj']->id)) { $this->add_track_multi_select($firstcourse->id); } elseif (!empty($courses)) { $this->add_track_multi_select($this->_customdata['obj']->courseid); } } else { $extra_params = array(); $mform->addElement('static', 'courseid', get_string('course', 'block_curr_admin') . ':'); // Get current action and set param accordingly $current_action = optional_param('action', 'view', PARAM_ALPHA); $extra_params['action'] = $current_action; $extra_params['s'] = 'crs'; // Want to set the url for the course $extra_params['id'] = $this->_customdata['obj']->courseid; // Course id $course_url = $this->get_moodle_url($extra_params); $course_name = '(' . $this->_customdata['obj']->course->idnumber . ')' . '<a href="' . $course_url . '" >' . $this->_customdata['obj']->course->name . '</a>'; $this->set_data(array('courseid' => $course_name)); $mform->setHelpButton('courseid', array('cmclassform/course', get_string('course', 'block_curr_admin'), 'block_curr_admin')); $this->add_track_multi_select($this->_customdata['obj']->courseid); } if (!empty($this->_customdata['obj']->courseid)) { $mform->freeze('courseid'); } else { $mform->addRule('courseid', get_string('required'), 'required', NULL, 'client'); } // Done adding course select //get_string('general'); $mform->addElement('text', 'idnumber', get_string('class_idnumber', 'block_curr_admin') . ':'); $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client'); $mform->setType('idnumber', PARAM_TEXT); $mform->setHelpButton('idnumber', array('cmclassform/idnumber', get_string('class_idnumber', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('date_selector', 'startdate', get_string('class_startdate', 'block_curr_admin') . ':', array('optional' => true, 'disabled' => 'disabled')); $mform->setHelpButton('startdate', array('cmclassform/startdate', get_string('class_startdate', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('date_selector', 'enddate', get_string('class_enddate', 'block_curr_admin') . ':', array('optional' => true)); // They may very likely be a much better way of checking for this... if (empty($obj->starttimehour) and empty($obj->starttimeminute)) { $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => $CURMAN->config->time_format_12h)); } else { $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => $CURMAN->config->time_format_12h)); } $mform->setHelpButton('starttime', array('cmclassform/starttime', get_string('class_starttime', 'block_curr_admin'), 'block_curr_admin')); // Do the same thing for the endtime if (empty($obj->endtimehour) and empty($obj->endtimeminute)) { $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => $CURMAN->config->time_format_12h)); } else { $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => $CURMAN->config->time_format_12h)); } $mform->addElement('text', 'maxstudents', get_string('class_maxstudents', 'block_curr_admin') . ':'); $mform->setType('maxstudents', PARAM_INT); $mform->setHelpButton('maxstudents', array('cmclassform/maxstudents', get_string('class_maxstudents', 'block_curr_admin'), 'block_curr_admin')); // Environment selector $envs = environment_get_listing(); $envs = $envs ? $envs : array(); $o_envs = array(get_string('none', 'block_curr_admin')); foreach ($envs as $env) { $o_envs[$env->id] = $env->name; } $mform->addElement('select', 'environmentid', get_string('environment', 'block_curr_admin') . ':', $o_envs); $mform->setHelpButton('environmentid', array('cmclassform/environment', get_string('environment', 'block_curr_admin'), 'block_curr_admin')); // Course selector if (empty($this->_customdata['obj']->moodlecourseid)) { $this->add_moodle_course_select(); } else { global $CURMAN; $coursename = $CURMAN->db->get_field('course', 'fullname', 'id', $this->_customdata['obj']->moodlecourseid); $mform->addElement('static', 'class_attached_course', get_string('class_attached_course', 'block_curr_admin') . ':', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$this->_customdata['obj']->moodlecourseid}\">{$coursename}</a>"); $mform->setHelpButton('class_attached_course', array('cmclassform/moodlecourseid', get_string('moodlecourse', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('hidden', 'moodlecourseid'); } $mform->addElement('checkbox', 'enrol_from_waitlist', get_string('waitlistenrol', 'block_curr_admin') . ':'); $mform->setHelpButton('enrol_from_waitlist', array('cmclassform/waitlistenrol', get_string('waitlistenrol', 'block_curr_admin'), 'block_curr_admin')); // custom fields $fields = field::get_for_context_level('class'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('class', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }
/** * Make Custom Filter Options * * This function handles filters that require custom values (languages, countries, etc). * * @param array $options The options array (so far) * @param string $group The name of the group the option belongs to * @param string $name The name of the option * @param array $tables An array of table names for lookups. * @return array The options array with customized settings * @uses $CFG */ function make_filter_options_custom($options, $group, $name) { global $CFG; switch ($group) { case 'curriculum': switch ($name) { case 'name': $records = get_records('crlm_curriculum', '', '', 'name', 'id,name'); $options['choices'] = array(); if (is_array($records)) { foreach ($records as $record) { $options['choices'][$record->id] = $record->name; } } $id = $this->_uniqueid . $group . '-name'; $child = $this->_uniqueid . 'course-name'; $path = $CFG->wwwroot . '/curriculum/lib/filtering/helpers/courses.php'; $options['numeric'] = 1; $options['talias'] = $this->tables[$group]['crlm_curriculum']; $options['dbfield'] = 'id'; $options['onchange'] = "dependentselect_updateoptions('{$id}','{$child}','{$path}')"; $options['multiple'] = 'multiple'; break; default: break; } //curriculum customfield filter condition, linking users to to curricula based on //curriculum assignments and curriculum-course associations $options['wrapper'] = " INNER JOIN {$CFG->prefix}crlm_curriculum_assignment cca" . " ON c.instanceid = cca.curriculumid"; //use EXISTS clause because we might need to connect based on several conditions $options['subqueryprefix'] = 'EXISTS'; //just link based on user id (override with additional condition on //on curriculum id elsewhere if needed) $options['extraconditions'] = "AND u.id = cca.userid"; //tell the filter we're operating on the curriculum context level $options['contextlevel'] = context_level_base::get_custom_context_level('curriculum', 'block_curr_admin'); break; case 'course': switch ($name) { case 'name': $records = get_records('crlm_course', '', '', 'name', 'id,name'); $options['choices'] = array(); if (is_array($records)) { foreach ($records as $record) { $options['choices'][$record->id] = $record->name; } } $id = $this->_uniqueid . $group . '-name'; $child = $this->_uniqueid . 'class-idnumber'; $path = $CFG->wwwroot . '/curriculum/lib/filtering/helpers/classes.php'; $options['numeric'] = 1; $options['talias'] = $this->tables['class']['crlm_class']; $options['dbfield'] = 'courseid'; $options['onchange'] = "dependentselect_updateoptions('{$id}','{$child}','{$path}')"; $options['multiple'] = 'multiple'; break; default: break; } $options['wrapper'] = " INNER JOIN {$CFG->prefix}crlm_class cls" . " ON c.instanceid=cls.courseid"; break; case 'class': $options['wrapper'] = " INNER JOIN {$CFG->prefix}crlm_class cls" . " ON c.instanceid=cls.id"; switch ($name) { case 'idnumber': $records = get_records('crlm_class', '', '', 'idnumber', 'id,idnumber'); $options['choices'] = array(); if (is_array($records)) { foreach ($records as $record) { $options['choices'][$record->id] = $record->idnumber; } } $options['numeric'] = 1; $options['talias'] = $this->tables[$group]['crlm_class']; $options['dbfield'] = 'id'; $options['multiple'] = 'multiple'; break; case 'environmentid': $records = get_records('crlm_environment', '', '', 'name', 'id,name'); $options['choices'] = array(); if (is_array($records)) { foreach ($records as $record) { $options['choices'][$record->id] = $record->name; } } $options['numeric'] = 1; $options['talias'] = $this->tables[$group]['crlm_class']; $options['table'] = 'crlm_class'; $options['dbfield'] = 'environmentid'; $options['multiple'] = 'multiple'; $options['wrapper'] = ''; $options['outerfield'] = 'u.id'; break; default: break; } $pos = strpos($name, 'customfield-'); if ($pos !== false) { //tell the filter we're operating on the class context level $options['contextlevel'] = context_level_base::get_custom_context_level('class', 'block_curr_admin'); } break; default: break; } $options['innerfield'] = $this->_innerfield[$group]; $options['wrapper'] .= $this->_wrapper[$group]; return $options; }
/** * Contructor * @param array array of visible user fields * @param string base url used for submission/return, null if the same of current page * @param array extra page parameters */ function cm_user_filtering($fieldnames = null, $baseurl = null, $extraparams = null) { if (empty($fieldnames)) { $fieldnames = array('realname' => 0, 'lastname' => 1, 'firstname' => 1, 'idnumber' => 1, 'email' => 0, 'city' => 1, 'country' => 1, 'username' => 0, 'language' => 1, 'clusterid' => 1, 'curriculumid' => 1, 'inactive' => 1); $fields = field::get_for_context_level(context_level_base::get_custom_context_level('user', 'block_curr_admin')); $fields = $fields ? $fields : array(); foreach ($fields as $field) { $fieldnames["field_{$field->shortname}"] = 1; } } /// Remove filters if missing capability... $context = get_context_instance(CONTEXT_SYSTEM); if (!has_capability('block/curr_admin:viewreports', $context)) { if (has_capability('block/curr_admin:viewgroupreports', $context)) { unset($fieldnames['clusterid']); } } parent::user_filtering($fieldnames, $baseurl, $extraparams); }
function delete() { $level = context_level_base::get_custom_context_level('curriculum', 'block_curr_admin'); $result = track::delete_for_curriculum($this->id); $result = $result && clustercurriculum::delete_for_curriculum($this->id); $result = $result && curriculumcourse::delete_for_curriculum($this->id); $result = $result && curriculumstudent::delete_for_curriculum($this->id); $result = $result && taginstance::delete_for_curriculum($this->id); $result = $result && delete_context($level, $this->id); return $result && $this->data_delete_record(); }
function _cluster_allowed($id) { global $CURMAN; if (isset($this->contexts['cluster'])) { $ctxlvl = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $context = get_context_instance($ctxlvl, $id); $ancestorids = substr(str_replace('/', ',', $context->path), 1); $sql = "SELECT COUNT(*)\n FROM {$CURMAN->db->prefix_table('context')} ctx\n WHERE id IN ({$ancestorids})\n AND instanceid IN (" . implode(',', $this->contexts['cluster']) . ")\n AND contextlevel = {$ctxlvl}"; return $CURMAN->db->count_records_sql($sql) != 0; } return false; }
public function delete() { $level = context_level_base::get_custom_context_level('course', 'block_curr_admin'); $return = curriculumcourse::delete_for_course($this->id); $return = $return && cmclass::delete_for_course($this->id); $return = $return && taginstance::delete_for_course($this->id); $return = $return && coursetemplate::delete_for_course($this->id); $return = $return && delete_context($level, $this->id); return $return && $this->data_delete_record(); }
function delete() { $status = true; if (!empty($this->id)) { instructor::delete_for_class($this->id); student::delete_for_class($this->id); trackassignmentclass::delete_for_class($this->id); classmoodlecourse::delete_for_class($this->id); student_grade::delete_for_class($this->id); attendance::delete_for_class($this->id); taginstance::delete_for_class($this->id); waitlist::delete_for_class($this->id); classmoodlecourse::delete_for_class($this->id); $level = context_level_base::get_custom_context_level('class', 'block_curr_admin'); $result = delete_context($level, $this->id); $status = $this->data_delete_record(); } return $status; }
/** * Sets up the fields necessary for enabling cluster groups * * @return boolean Returns true to indicate success */ function cluster_groups_install() { //retrieve the cluster context $cluster_context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); //set up the cluster group category $group_category = new field_category(); $group_category->name = get_string('cluster_group_category', 'crlm_cluster_groups'); //set up the field that allows users to turn the groupings on $group_field = new field(); $group_field->shortname = 'cluster_group'; $group_field->name = get_string('cluster_group', 'crlm_cluster_groups'); $group_field->datatype = 'bool'; //set up the field and category $group_field = field::ensure_field_exists_for_context_level($group_field, $cluster_context, $group_category); //set up the field owner $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_groups/cluster_groups'); field_owner::ensure_field_owner_exists($group_field, 'manual', $owner_options); //retrieve the cluster context $context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $field = new field(); $field->shortname = 'cluster_groupings'; $field->name = get_string('autoenrol_groupings', 'crlm_cluster_classification'); $field->datatype = 'bool'; $field = field::ensure_field_exists_for_context_level($field, $context, $group_category); $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_groups/cluster_groupings'); field_owner::ensure_field_owner_exists($field, 'manual', $owner_options); return true; }
function validation($data, $files) { global $CFG, $CURMAN; $errors = parent::validation($data, $files); // Use a default for 'id' if we're doing an add if (!$data['id']) { $data['id'] = 0; } if (!empty($data['username'])) { if (!$this->check_unique(USRTABLE, 'username', $data['username'], $data['id'])) { $errors['username_group'] = get_string('badusername', 'block_curr_admin'); } } else { if (!$data['id'] && empty($data['id_same_user'])) { $errors['username_group'] = get_string('required'); } } if (!empty($data['idnumber'])) { if (!$this->check_unique(USRTABLE, 'idnumber', $data['idnumber'], $data['id'])) { $errors['idnumber'] = get_string('badidnumber', 'block_curr_admin'); } } // Validate the supplied email addresses as best we can... if (!empty($data['email'])) { if (!$this->check_unique(USRTABLE, 'email', $data['email'], $data['id'])) { $errors['email'] = get_string('emailexists'); } } if (!empty($data['email2'])) { if (!$this->check_unique(USRTABLE, 'email', $data['email2'], $data['id'])) { $errors['email2'] = get_string('emailexists'); } } if (!empty($data['contactemail'])) { if (!$this->check_unique(USRTABLE, 'email', $data['contactemail'], $data['id'])) { $errors['contactemail'] = get_string('emailexists'); } } // validate custom profile fields $fields = field::get_for_context_level(context_level_base::get_custom_context_level('user', 'block_curr_admin')); $fields = $fields ? $fields : array(); if ($data['id']) { $context = get_context_instance(context_level_base::get_custom_context_level('user', 'block_curr_admin'), $data['id']); $contextid = $context->id; } else { $contextid = 0; } foreach ($fields as $field) { $field = new field($field); $key = "field_{$field->shortname}"; if ($field->multivalued) { $manual = new field_owner($field->owners['manual']); $fielddata = isset($data[$key]) ? $data[$key] : array(); if ($manual->param_required) { if (empty($fielddata)) { $errors[$key] = get_string('required'); } else { if (!empty($manual->param_options)) { $options = explode("\n", $manual->param_options); array_walk($options, 'trim_cr'); // TBD: defined below foreach ($fielddata as $entry) { if (!in_array($entry, $options)) { $errors[$key] = get_string('required'); break; } } } } } if (!isset($errors[$key]) && $field->forceunique && $contextid) { $where = "contextid != {$contextid} AND fieldid = {$field->id}"; if ($recs = get_records_select($field->data_table(), $where, 'contextid, data')) { $curcontext = -1; $vals = null; foreach ($recs as $rec) { if ($curcontext != $rec->contextid) { if (!empty($vals)) { $adif = array_diff($vals, $fielddata); if (empty($adif)) { $errors[$key] = get_string('valuealreadyused'); // TBD^^^ "[These/This combination of] values already uesd!" $vals = null; break; } } $curcontext = $rec->contextid; $vals = array(); } $vals[] = $rec->data; } if (!empty($vals)) { $adif = array_diff($vals, $fielddata); if (empty($adif)) { $errors[$key] = get_string('valuealreadyused'); // TBD^^^ "[These/This combination of] values already uesd!" } } } } } else { if ($field->forceunique) { // NON-MULTIVALUED case $fielddata = $CURMAN->db->get_record($field->data_table(), 'fieldid', $field->id, 'data', $data[$key]); //print_object($fielddata); if ($fielddata && $fielddata->contextid != $contextid) { $errors[$key] = get_string('valuealreadyused'); } } } } return $errors; }
* @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ require_once '../../../../config.php'; require_once $CFG->dirroot . '/curriculum/config.php'; require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php'; require_once $CFG->dirroot . '/blocks/php_report/sharedlib.php'; // Get required yui javascript for ajax calls require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_connection', "{$CFG->wwwroot}/curriculum/js/associate.class.js", "{$CFG->wwwroot}/curriculum/js/customfields.js"), true); $lang_file = 'rlreport_individual_course_progress'; $site = get_site(); $block_id = required_param('instance', PARAM_RAW); $fieldidlist = optional_param('fieldidlist', null, PARAM_TEXT); $fieldnamelist = optional_param('fieldnamelist', null, PARAM_TEXT); // Get custom course fields by context level $context = context_level_base::get_custom_context_level('course', 'block_curr_admin'); $fields = field::get_for_context_level($context); $fields = $fields ? $fields : array(); //Unserialize fieldidlist to check against field list if (isset($fieldidlist)) { $fieldidlist = @unserialize(base64_decode($fieldidlist)); } if (isset($fieldnamelist)) { $fieldnamelist = @unserialize(base64_decode($fieldnamelist)); } $categories = field_category::get_for_context_level($context); $categories = $categories ? $categories : array(); // divide the fields into categories $fieldsbycategory = array(); foreach ($categories as $category) { $fieldsbycategory[$category->name] = array();
/** * items in the form * * @uses $USER */ public function definition() { global $USER; $this->set_data($this->_customdata['obj']); $mform =& $this->_form; $mform->addElement('hidden', 'id'); $curs = array(); if (!empty($USER->id)) { // TBD: and/or capability 'block/curr_admin:curriculum:edit|view' ? // WAS: 'block/curr_admin:track:create' ??? $contexts = get_contexts_by_capability_for_user('curriculum', 'block/curr_admin:curriculum:view', $USER->id); $curs = curriculum_get_listing('name', 'ASC', 0, 0, '', '', $contexts); } if (empty($this->_customdata['obj']->id)) { $curid_options = array(); if (!empty($curs)) { foreach ($curs as $cur) { $curid_options[$cur->id] = '(' . $cur->idnumber . ') ' . $cur->name; } } $mform->addElement('select', 'curid', get_string('curriculum', 'block_curr_admin') . ':', $curid_options); $mform->addRule('curid', get_string('required'), 'required', NULL, 'client'); $mform->setHelpButton('curid', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin')); } else { // Track editing, do not allow the user to change curriculum $mform->addElement('static', 'curidstatic', get_string('curriculum', 'block_curr_admin') . ':', $curs[$this->_customdata['obj']->curid]->name); $mform->setHelpButton('curidstatic', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('hidden', 'curid'); } $mform->addElement('text', 'idnumber', get_string('track_idnumber', 'block_curr_admin') . ':'); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client'); $mform->addRule('idnumber', null, 'maxlength', 100); $mform->setHelpButton('idnumber', array('trackform/idnumber', get_string('track_idnumber', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('text', 'name', get_string('track_name', 'block_curr_admin') . ':'); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'maxlength', 255); $mform->addRule('name', get_string('required'), 'required', NULL, 'client'); $mform->setHelpButton('name', array('trackform/name', get_string('track_name', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('textarea', 'description', get_string('track_description', 'block_curr_admin') . ':'); $mform->setType('description', PARAM_CLEAN); $mform->setHelpButton('description', array('trackform/description', get_string('track_description', 'block_curr_admin'), 'block_curr_admin')); $mform->addElement('date_selector', 'startdate', get_string('track_startdate', 'block_curr_admin') . ':', array('optional' => true)); $mform->addElement('date_selector', 'enddate', get_string('track_enddate', 'block_curr_admin') . ':', array('optional' => true)); $mform->setHelpButton('startdate', array('trackform/startdate', get_string('startdate', 'block_curr_admin'), 'block_curr_admin')); if (!empty($this->_customdata['obj']->id)) { $trackassignobj = new trackassignmentclass(array('trackid' => $this->_customdata['obj']->id)); } // Only show auto-create checkbox if the track does not have any classes assigned if (!isset($trackassignobj) or 0 == $trackassignobj->count_assigned_classes_from_track()) { $mform->addElement('checkbox', 'autocreate', get_string('track_autocreate', 'block_curr_admin') . ':'); $mform->setHelpButton('autocreate', array('trackform/autocreate', get_string('track_autocreate', 'block_curr_admin'), 'block_curr_admin')); } // custom fields $fields = field::get_for_context_level('track'); $fields = $fields ? $fields : array(); $lastcat = null; $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('track', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM); require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php'; foreach ($fields as $rec) { $field = new field($rec); if (!isset($field->owners['manual'])) { continue; } if ($lastcat != $rec->categoryid) { $lastcat = $rec->categoryid; $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname)); } manual_field_add_form_element($this, $context, $field); } $this->add_action_buttons(); }
/** * Return a boolean to indicate whether or not this filter is displayed * depending upon whether any custom fields are found for this user * @param string $field_type type of custom field to check * @return boolean true if the filter is to show */ function check_for_custom_fields($field_type) { // Get custom course fields by context level $context = context_level_base::get_custom_context_level($field_type, 'block_curr_admin'); $fields = field::get_for_context_level($context); $fields = $fields ? $fields : array(); $testfields = array(); foreach ($fields as $field) { //make sure the current user can access this field in at least one //course context $owners = field_owner::get_for_field($field); if (!block_php_report_field_accessible($owners)) { continue; } return true; } return false; }
$clusters = cluster_get_listing('id', 'ASC', 0); $clusters_fixed_cnt = 0; foreach ($clusters as $clusid => $clusdata) { if ($clusdata->parent > 0) { $select = "id='{$clusdata->parent}'"; $parent_cnt = $CURMAN->db->count_records_select(CLSTTABLE, $select); if ($parent_cnt < 1) { mtrace('Cluster ID:' . $clusid . ' Name:' . $clusdata->name . ' converted to top-level'); $newclusdata = new stdClass(); $newclusdata->id = $clusdata->id; $newclusdata->parent = 0; $newclusdata->depth = 1; // Update the records in crlm_cluster table $result = update_record(CLSTTABLE, $newclusdata); // Blank out the depth and path for associated records and child records in context table $cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $cluster_context_instance = get_context_instance($cluster_context_level, $clusid); $instance_id = $cluster_context_instance->id; $sql = "UPDATE {$CFG->prefix}context\n SET depth=0, path=NULL\n WHERE id={$instance_id} OR path LIKE '%/{$instance_id}/%'"; $feedback = ""; execute_sql($sql, $feedback); $clusters_fixed_cnt++; } } } if ($clusters_fixed_cnt > 0) { mtrace("Rebuilding context paths..."); build_context_path(); } else { mtrace("No orphaned clusters found!"); }
/** * 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; }
if (empty($uuid) && empty($dd)) { if ($uuid = $repo->get_repository_location($id, $userid, $shared, $oid)) { redirect($CFG->wwwroot . '/file/repository/alfresco/link.php?id=' . $id . '&userid=' . $userid . '&shared=' . $shared . '&oid=' . $oid . '&uuid=' . $uuid, '', 0); } if ($uuid = $repo->get_default_browsing_location($id, $userid, $shared)) { redirect($CFG->wwwroot . '/file/repository/alfresco/link.php?id=' . $id . '&userid=' . $userid . '&shared=' . $shared . '&oid=' . $oid . '&uuid=' . $uuid, '', 0); } } } @header('Content-Type: text/html; charset=utf-8'); if (!alfresco_user_request()) { print_error('nopermissions'); } /// Get the context instance for where we originated viewing this browser from. if (!empty($oid)) { $cluster_context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $oid); } if ($id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM, SITEID); } else { $context = get_context_instance(CONTEXT_COURSE, $id); } /// Determine whether the current user has editing persmissions. $canedit = false; if (empty($userid) && empty($shared)) { if (!empty($oid) && has_capability('block/repository:createorganizationcontent', $cluster_context, $USER->id) || $id == SITEID && has_capability('block/repository:createsitecontent', $context, $USER->id) || $id != SITEID && has_capability('block/repository:createcoursecontent', $context, $USER->id)) { $canedit = true; } } else { if (empty($userid) && $shared == 'true') { if (!empty($USER->access['rdef'])) {
/** * Specifies the data representing the average test score per user * * @param string $field_shortname field short name to be used in get_field request * * @return numeric The calculated value */ function get_average_test_score($field_shortname) { global $CURMAN; $result = get_string('na', 'rlreport_course_usage_summary'); //Get the course context $course_context_level = context_level_base::get_custom_context_level('course', 'block_curr_admin'); //Get the field id of the field shortname to use in the data table if ($field_id = get_field('crlm_field', 'id', 'shortname', $field_shortname)) { $field = new field($field_id); $data_table = $CURMAN->db->prefix_table($field->data_table()); //main query $sql = "SELECT AVG(clsgrd.grade) AS score\n FROM {$data_table} d\n JOIN {$CURMAN->db->prefix_table('context')} ctxt\n ON d.contextid = ctxt.id\n AND ctxt.contextlevel = {$course_context_level}\n JOIN {$CURMAN->db->prefix_table(CRSCOMPTABLE)} comp\n ON d.data = comp.idnumber\n JOIN {$CURMAN->db->prefix_table(CLSTABLE)} class\n ON class.courseid = ctxt.instanceid\n JOIN {$CURMAN->db->prefix_table(CLSGRTABLE)} clsgrd\n ON clsgrd.classid = class.id\n AND clsgrd.locked = 1\n AND clsgrd.completionid = comp.id\n JOIN {$CURMAN->db->prefix_table(STUTABLE)} enrol\n ON enrol.classid = class.id\n AND enrol.userid = clsgrd.userid"; if (empty($CURMAN->config->legacy_show_inactive_users)) { $sql .= " JOIN {$CURMAN->db->prefix_table(USRTABLE)} usr ON usr.id = enrol.userid"; } //get permissions sql bit if ($this->need_permissions()) { $permissions_filter = ' AND ' . $this->get_permissions(); } else { $permissions_filter = ''; } if ($this->filter_statement || $this->need_permissions()) { $sql .= " WHERE EXISTS (\n SELECT *\n FROM {$CURMAN->db->prefix_table(STUTABLE)} enrol2\n JOIN {$CURMAN->db->prefix_table(CLSTABLE)} class\n ON class.id = enrol2.classid\n JOIN {$CURMAN->db->prefix_table(CURCRSTABLE)} curcrs\n ON curcrs.courseid = class.courseid\n JOIN {$CURMAN->db->prefix_table(CURASSTABLE)} curass\n ON curcrs.curriculumid = curass.curriculumid\n AND curass.userid = enrol2.userid\n WHERE enrol.id = enrol2.id\n AND d.fieldid = {$field_id}\n {$this->filter_statement}\n {$permissions_filter}\n )"; } else { $sql .= " WHERE d.fieldid = {$field_id}"; } if (empty($CURMAN->config->legacy_show_inactive_users)) { $sql .= ' AND usr.inactive = 0'; } $avg_crs_grd = 0; if ($avg_crs_grd_record = get_record_sql($sql)) { $avg_crs_grd = $avg_crs_grd_record->score; } } //Format as a percentage return round($avg_crs_grd) . '%'; }
/** * Hook that gets called after a CM entity is added through this page * (Note: this function should only use the id field from the supplied cm entity * as the rest of the data is not guaranteed to be there) * * @param object $cm_entity The CM entity added */ function after_cm_entity_add($cm_entity) { global $USER, $CURMAN; //make sure a valid role is set if (!empty($CURMAN->config->default_cluster_role_id) && record_exists('role', 'id', $CURMAN->config->default_cluster_role_id)) { //get the context instance for capability checking $context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $context_instance = get_context_instance($context_level, $cm_entity->id); //assign the appropriate role if the user does not have the edit capability if (!has_capability('block/curr_admin:cluster:edit', $context_instance)) { role_assign($CURMAN->config->default_cluster_role_id, $USER->id, 0, $context_instance->id); } } }
/** * Perform all necessary tasks to add a student enrolment to the system. * * @param array $checks what checks to perform before adding enrolling the * user. e.g. array('prereq' => 1, 'waitlist' => 1) will check that * prerequisites are satisfied, and that the class is not full * @param boolean $notify whether or not notifications should be sent if a * check fails */ function add($checks = array(), $notify = false) { global $CURMAN, $CFG, $USER; $status = true; if ($CURMAN->db->record_exists(STUTABLE, 'userid', $this->userid, 'classid', $this->classid)) { // already enrolled -- pretend we succeeded return true; } // check that the student can be enrolled first if (!empty($checks['prereq'])) { // check prerequisites $cmclass = new cmclass($this->classid); // get all the curricula that the user is in $curricula = curriculumstudent::get_curricula($this->userid); foreach ($curricula as $curriculum) { $curcrs = new curriculumcourse(); $curcrs->courseid = $cmclass->courseid; $curcrs->curriculumid = $curriculum->curid; if (!$curcrs->prerequisites_satisfied($this->userid)) { // prerequisites not satisfied if ($notify) { $data = new stdClass(); $data->userid = $this->userid; $data->classid = $this->classid; //$data->trackid = $trackid; events_trigger('crlm_prereq_unsatisfied', $data); } $status = new Object(); $status->message = get_string('unsatisfiedprereqs', 'block_curr_admin'); $status->code = 'unsatisfiedprereqs'; return $status; } } } if (!empty($checks['waitlist'])) { // check class enrolment limit $cmclass = new cmclass($this->classid); $limit = $cmclass->maxstudents; if (!empty($limit) && $limit <= student::count_enroled($this->classid)) { // class is full // put student on wait list $wait_list = new waitlist($this); $wait_list->timecreated = time(); $wait_list->position = 0; $wait_list->add(); if ($notify) { $subject = get_string('user_waitlisted', 'block_curr_admin'); $a = new object(); $a->user = $this->user->idnumber; $a->cmclass = $cmclass->idnumber; $message = get_string('user_waitlisted_msg', 'block_curr_admin', $a); $from = $user = get_admin(); notification::notify($message, $user, $from); email_to_user($user, $from, $subject, $message); } $status = new Object(); $status->message = get_string('user_waitlisted', 'block_curr_admin'); $status->code = 'user_waitlisted'; return $status; } } //set end time based on class duration $studentclass = new cmclass($this->classid); if (empty($this->endtime)) { if (isset($studentclass->duration) && $studentclass->duration) { $this->endtime = $this->enrolmenttime + $studentclass->duration; } else { // no class duration -> no end time $this->endtime = 0; } } $status = $this->data_insert_record(); // TBD: we should check this! /// Get the Moodle user ID or create a new account for this user. if (!($muserid = cm_get_moodleuserid($this->userid))) { $user = new user($this->userid); if (!($muserid = $user->synchronize_moodle_user(true, true))) { $status = new Object(); $status->message = get_string('errorsynchronizeuser', 'block_curr_admin'); $muserid = false; } } /// Enrol them into the Moodle class. if ($moodlecourseid = moodle_get_course($this->classid)) { if ($mcourse = get_record('course', 'id', $moodlecourseid)) { $enrol = $mcourse->enrol; if (!$enrol) { $enrol = $CFG->enrol; } if ($CURMAN->config->restrict_to_elis_enrolment_plugin && $enrol != 'elis') { $status = new Object(); $status->message = get_string('error_not_using_elis_enrolment', 'block_curr_admin'); return $status; } $timestart = $this->enrolmenttime; $timeend = $this->endtime; if ($role = get_default_course_role($mcourse)) { $context = get_context_instance(CONTEXT_COURSE, $mcourse->id); if (!empty($muserid)) { if (!role_assign($role->id, $muserid, 0, $context->id, $timestart, $timeend, 0, 'manual')) { $status = new Object(); $status->message = get_string('errorroleassign', 'block_curr_admin'); } } } } } else { if (!empty($muserid)) { $sturole = $CURMAN->config->enrolment_role_sync_student_role; // ELIS-2776: must still trigger events for notifications $ra = new stdClass(); $ra->roleid = !empty($sturole) ? $sturole : get_field('role', 'id', 'shortname', 'student'); $ra->contextid = context_level_base::get_custom_context_level('class', 'block_curr_admin'); // TBD $ra->userid = $muserid; $ra->component = ''; // TBD: 'enrol_elis' $ra->itemid = $this->classid; // TBD $ra->timemodified = time(); $ra->modifierid = empty($USER->id) ? 0 : $USER->id; events_trigger('role_assigned', $ra); } } return $status; }