function cegep_sisdb_init() { global $CFG, $enroldb, $sisdb, $sisdbsource; // Verify if external database enrolment is enabled if (!in_array('database', explode(',', $CFG->enrol_plugins_enabled))) { print_error('errorenroldbnotavailable', 'block_cegep'); } // Prepare external enrolment database connection if ($enroldb = enroldb_connect()) { $enroldb->Execute("SET NAMES 'utf8'"); } else { error_log('[ENROL_DB] Could not make a connection'); print_error('dbconnectionfailed', 'error'); } // Prepare external SIS database connection if ($sisdb = sisdb_connect()) { $sisdb->Execute("SET NAMES 'utf8'"); } else { error_log('[SIS_DB] Could not make a connection'); print_error('dbconnectionfailed', 'error'); } // Prepare external SIS source database connection if ($sisdbsource = sisdbsource_connect()) { //$sisdbsource->Execute("SET NAMES 'utf8'"); } else { error_log('[SIS_DB_SOURCE] Could not make a connection'); print_error('dbconnectionfailed', 'error'); } }
/** * Returns the list of section numbers enrolled in a given course */ function cegep_dawson_courses_get_sections($courseidnumber, $courseid = 0, &$has_sections = false, $filter_term = 'all', &$echo_course = false) { global $CFG; $echo_course = false; if ($filter_term == 'all') { $echo_course = true; } $enroldb = enroldb_connect(); $select = "SELECT DISTINCT `coursegroup_id` FROM `{$CFG->enrol_remoteenroltable}` WHERE `{$CFG->enrol_remotecoursefield}` = '{$courseidnumber}' AND `{$CFG->enrol_remoterolefield}` = '{$CFG->block_cegep_studentrole}' AND `coursegroup_id` IS NOT NULL ORDER BY `coursegroup_id`"; $coursegroups_rs = $enroldb->Execute($select); if (!$coursegroups_rs) { trigger_error($enroldb->ErrorMsg() . ' STATEMENT: ' . $select, E_USER_ERROR); return false; } $sisdb = sisdb_connect(); $coursegroup_id = ''; $has_sections = false; $html = ''; $on_first = true; while (!$coursegroups_rs->EOF) { if ($on_first) { $html .= '<span class="cegep_section">'; } $coursegroup_id = $coursegroups_rs->fields['coursegroup_id']; $select = "SELECT * FROM `{$CFG->sisdb_name}`.`coursegroup` WHERE id = '{$coursegroup_id}'"; $coursegroup = $sisdb->Execute($select)->fields; if (!empty($coursegroup)) { if (!$on_first) { $html .= ', ' . strtolower(get_string("cegepsection", "block_cegep")) . ' ' . $coursegroup['group'] . ' (' . cegep_dawson_term_to_string($coursegroup['term']) . ')'; } else { $html .= get_string("cegepsection", "block_cegep") . ' ' . $coursegroup['group'] . ' (' . cegep_dawson_term_to_string($coursegroup['term']) . ')'; } if (!empty($filter_term) && $filter_term != 'all') { if ($coursegroup['term'] == $filter_term) { $echo_course = true; } } $has_sections = true; $coursegroups_rs->MoveNext(); if ($on_first) { $on_first = false; } } else { $coursegroups_rs->MoveNext(); } } if (!$has_sections) { $html .= '<span class="error">' . get_string("cegepnosections", "block_cegep") . '</span>'; } else { $html .= '</span>'; } $enroldb->Close(); $sisdb->Close(); return $html; }
// This module only available to teachers and admins $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); require_capability('moodle/course:update', $context, null, true, 'errormustbeteacher', 'block_cegep'); // Verify if external database enrolment is enabled if (!in_array('database', explode(',', $CFG->enrol_plugins_enabled))) { print_error('errorenroldbnotavailable', 'block_cegep'); } // Prepare external enrolment database connection if ($enroldb = enroldb_connect()) { $enroldb->Execute("SET NAMES 'utf8'"); } else { error_log('[ENROL_DB] Could not make a connection'); print_error('dbconnectionfailed', 'error'); } // Prepare external SIS database connection if ($sisdb = sisdb_connect()) { $sisdb->Execute("SET NAMES 'utf8'"); } else { error_log('[SIS_DB] Could not make a connection'); print_error('dbconnectionfailed', 'error'); } // Get system context for global Admin CEGEP permissions $syscontext = get_context_instance(CONTEXT_SYSTEM, 1); // Main switch switch ($action) { case 'enrol': if (is_siteadmin() || has_capability('block/cegep:enroladmin_course', $syscontext)) { cegep_enrol_admin(); } else { cegep_enrol(); }
function cegep_local_is_teacher($idnumber, $term) { global $CFG; if (function_exists('cegep_' . $CFG->block_cegep_name . '_is_teacher')) { return call_user_func('cegep_' . $CFG->block_cegep_name . '_is_teacher', $idnumber, $term); } else { // Prepare external SIS database connection if ($sisdb = sisdb_connect()) { $sisdb->Execute("SET NAMES 'utf8'"); } else { error_log('[SIS_DB] Could not make a connection'); print_error('dbconnectionfailed', 'error'); } $idnumber = cegep_local_get_real_teacher_idnumber($idnumber); $is_teacher = FALSE; $select = "SELECT idnumber FROM `{$CFG->sisdb_name}`.teacher_enrolment WHERE idnumber = '{$idnumber}' AND term >= {$term};"; $sisdb_rs = $sisdb->Execute($select); if (!$sisdb_rs->EOF) { $is_teacher = TRUE; } $sisdb->Close(); return $is_teacher; } }