function init($object) { parent::init($object); if (!isset($this->settings['school']) or $this->settings['school'] = '') { $this->set_error('Couldnt bind to ldap server'); return $object; } if (!is_int($this->settings['school'])) { $this->settings['school'] = SchoolUtils::get_school_id_by_name($this->settings['school'], $this->db); } return $object; }
/** * Check for already existing and then add new course data into the database. * * @param integer $schoolid ID of the school the course belongs to * @param string $name code of the course e.g. B140 * @param string $description a title for the course e.g. Neuroscience BSc * @param object $db database connection * * @return bool depending on insert success */ static function add_course($schoolid, $name, $description, $db) { if ($name == '') { return false; } if (CourseUtils::course_exists($name, $db) === true) { return true; } if (!is_int($schoolid)) { //school name given not school id so convert $schoolid = SchoolUtils::get_school_id_by_name($schoolid, $db); if (!$schoolid) { return false; } } $result = $db->prepare("INSERT INTO courses VALUES (NULL, ?, ?, NULL, ?)"); $result->bind_param('ssi', $name, $description, $schoolid); $result->execute(); $result->close(); if ($db->errno != 0) { return false; } return true; }
$peer = 1; $external = 1; $stdset = 0; $mapping = 1; $neg_marking = 1; $selfEnroll = 0; if ($v[0] == 'Manual') { $selfEnroll = 1; $peer = 0; $external = 0; $stdset = 0; $mapping = 0; $neg_marking = 1; } $sms_api = $lti_i::sms_api($v); $schoolID = SchoolUtils::get_school_id_by_name($v[3], $mysqli); $modcreate = module_utils::add_modules($v[1], $v[5], 1, $schoolID, '', $sms_api, $selfEnroll, $peer, $external, $stdset, $mapping, $neg_marking, 0, $mysqli, 1, 0, 1, 1, '07/01'); if ($modcreate === false) { $problem = true; } } elseif (!module_utils::module_exists($v[1], $mysqli) and !$lti_i::allow_module_create($v)) { UserNotices::display_notice($string['NoModCreateTitle'], $string['NoModCreate'] . $v[1], '../artwork/exclamation_64.png', '#C00000'); echo "\n</body>\n</html>\n"; exit; } if (!$userObject->is_staff_user_on_module($v[1]) and $lti_i::allow_staff_module_register($v) and $userObject->has_role(array('Staff', 'Admin', 'SysAdmin')) and module_utils::is_allowed_add_team_members_by_name($v[1], $mysqli)) { UserUtils::add_staff_to_module_by_modulecode($userObject->get_user_ID(), $v[1], $mysqli); } elseif (!$userObject->is_staff_user_on_module($v[1]) and !$lti_i::allow_staff_module_register($v)) { UserNotices::display_notice($string['NotAddedToModuleTitle'], $string['NotAddedToModule'] . $v[1], '../artwork/exclamation_64.png', '#C00000'); echo "\n</body>\n</html>\n"; exit;
/** * Update any part of a modules DB record. * * @param integer $orig_moduleid - the code of the module to update * @param type $updateData - an array of key value pairs to update e.g 'fullname'=>'New full Name' * @param object $db - MySQLi database connection. * @return boolean */ public function update_module_by_code($orig_moduleid, $updateData, $db) { global $string; if ($orig_moduleid == '') { return false; } $orig_modinfo = $modinfo = module_utils::get_full_details_by_name($orig_moduleid, $db); if ($modinfo === false) { // The module must exist to update it! return false; } $orig_school_name = $modinfo['school']; $orig_school_id = $modinfo['schoolid']; $changed = false; foreach ($updateData as $key => $val) { $key = strtolower($key); if ($key == 'idmod') { //never change the id :-) continue; } if ($modinfo[$key] != $val) { $modinfo[$key] = $val; $changed = true; } } if (!$changed) { // Nothing has changed return return true; } // Check mandatory fields if ($modinfo['moduleid'] == '' and $modinfo['fullname'] == '') { return false; } if ($orig_school_name != $modinfo['school']) { // We have updated the school so we need to get the new id from the schools table if ($orig_school_id != $modinfo['schoolid']) { // Do nothing as the id has already been updated } else { // Lookup the schoolID $modinfo['schoolid'] = SchoolUtils::get_school_id_by_name($modinfo['school'], $db); if ($modinfo['schoolid'] === false) { // School not found ERROR return false; } } } $sql = "UPDATE modules SET \n moduleid = ?,\n fullname = ?,\n active = ?, \n vle_api = ?, \n checklist = ?, \n sms = ?, \n selfenroll = ?, \n schoolid = ?, \n neg_marking = ?, \n ebel_grid_template = ?, \n timed_exams = ?, \n exam_q_feedback = ?, \n add_team_members = ?,\n map_level = ?,\n academic_year_start = ?\n WHERE \n id = ?\n LIMIT 1\n "; $result = $db->prepare($sql); $result->bind_param('ssisssiiiiiiiisi', $modinfo['moduleid'], $modinfo['fullname'], $modinfo['active'], $modinfo['vle_api'], $modinfo['checklist'], $modinfo['sms'], $modinfo['selfenroll'], $modinfo['schoolid'], $modinfo['neg_marking'], $modinfo['ebel_grid_template'], $modinfo['timed_exams'], $modinfo['exam_q_feedback'], $modinfo['add_team_members'], $modinfo['map_level'], $modinfo['academic_year_start'], $modinfo['idMod']); $res = $result->execute(); // An array to convert DB fields to lang strings argghhh!!!! $lang_mappings = array('moduleid' => 'moduleid', 'fullname' => 'name', 'schoolid' => 'school', 'active' => 'active', 'vle_api' => 'objapi', 'checklist' => 'summativechecklist', 'sms' => 'smsapi', 'selfenroll' => 'allowselfenrol', 'neg_marking' => 'negativemarking', 'ebel_grid_template' => 'ebelgrid', 'timed_exams' => 'timedexams', 'exam_q_feedback' => 'questionbasedfeedback', 'add_team_members' => 'addteammembers', 'map_level' => 'map_level', 'academic_year_start' => 'academicyearstart'); if ($res === true) { // Log any changes $logger = new Logger($db); $userObject = UserObject::get_instance(); foreach ($modinfo as $key => $val) { $key = strtolower($key); if ($key == 'idmod') { continue; } if ($orig_modinfo[$key] != $val) { $logger->track_change('Module', $modinfo['idMod'], $userObject->get_user_ID(), $orig_modinfo[$key], $modinfo[$key], $string[$lang_mappings[$key]]); } } } return true; }