/** * Constructor for the base resource class * * Constructor for the base resource class. * If cmid is set create the cm, course, resource objects. * and do some checks to make sure people can be here, and so on. * * @param cmid integer, the current course module id - not set for new resources */ function resource_base($cmid = 0) { global $CFG, $COURSE; $this->navlinks = array(); if ($cmid) { if (!($this->cm = get_coursemodule_from_id('resource', $cmid))) { error("Course Module ID was incorrect"); } if (!($this->course = get_record("course", "id", $this->cm->course))) { error("Course is misconfigured"); } if (!($this->resource = get_record("resource", "id", $this->cm->instance))) { error("Resource ID was incorrect"); } $this->strresource = get_string("modulename", "resource"); $this->strresources = get_string("modulenameplural", "resource"); if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) { $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strresource); $navigation = build_navigation($this->navlinks, $this->cm); print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm)); notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}"); } } else { $this->course = $COURSE; } }
function definition_after_data() { global $CFG; parent::definition_after_data(); $mform =& $this->_form; if ($association_id = $mform->getElementValue('association_id')) { if ($record = get_record(CLSTCURTABLE, 'id', $association_id)) { //cluster stuff if ($cluster_record = get_record(CLSTTABLE, 'id', $record->clusterid)) { foreach ($this->cluster_fields as $id => $display) { $element =& $mform->getElement('cluster' . $id); $element->setValue($cluster_record->{$id}); } } //curriculum stuff $curriculum_sql = "SELECT cur.idnumber,\n cur.name,\n cur.description,\n cur.reqcredits,\n COUNT(curcrs.id) as numcourses\n FROM {$CFG->prefix}crlm_curriculum cur\n LEFT JOIN {$CFG->prefix}crlm_curriculum_course curcrs\n ON curcrs.curriculumid = cur.id\n WHERE cur.id = {$record->curriculumid}"; if ($curriculum_record = get_record_sql($curriculum_sql)) { foreach ($this->curriculum_fields as $id => $display) { $element =& $mform->getElement('curriculum' . $id); $element->setValue($curriculum_record->{$id}); } } //association stuff $autoenrol_element =& $mform->getElement('autoenrol'); $autoenrol_element->setValue($record->autoenrol); } } }
function migrate2utf8_netpublish_name($recordid) { global $CFG, $globallang; /// Some trivial checks if (empty($recordid)) { log_the_problem_somewhere(); return false; } if (!($netpublish = get_record('netpublish', 'id', $recordid))) { log_the_problem_somewhere(); return false; } if ($globallang) { $fromenc = $globallang; } else { $sitelang = $CFG->lang; $courselang = get_course_lang($netpublish->course); //Non existing! $userlang = get_main_teacher_lang($netpublish->course); //N.E.!! $fromenc = get_original_encoding($sitelang, $courselang, $userlang); } /// We are going to use textlib facilities /// Convert the text if ($fromenc != 'utf-8' && $fromenc != 'UTF-8') { $result = utfconvert($netpublish->name, $fromenc); $newpublish = new object(); $newpublish->id = $recordid; $newpublish->name = $result; migrate2utf8_update_record('netpublish', $newpublish); } /// And finally, just return the converted field return $result; }
public static function getRecordDataById($type, $id) { $sql = 'SELECT c.id, c.name, c.ctime, c.description, cv.view AS viewid, c.owner FROM {collectio}n c LEFT OUTER JOIN {collection_view} cv ON cv.collection = c.id WHERE id = ? ORDER BY cv.displayorder asc LIMIT 1;'; $record = get_record_sql($sql, array($id)); if (!$record) { return false; } $record->name = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->name)); $record->description = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->description)); // Created by if (intval($record->owner) > 0) { $record->createdby = get_record('usr', 'id', $record->owner); $record->createdbyname = display_name($record->createdby); } // Get all views included in that collection $sql = 'SELECT v.id, v.title FROM {view} v LEFT OUTER JOIN {collection_view} cv ON cv.view = v.id WHERE cv.collection = ?'; $views = recordset_to_array(get_recordset_sql($sql, array($id))); if ($views) { $record_views = array(); foreach ($views as $view) { if (isset($view->id)) { $record_views[$view->id] = $view->title; } } $record->views = $record_views; } return $record; }
/** * Processes the message (sends by email). * @param object $message the message to be sent */ function send_message($message) { //send an email //if fails saved as read message //first try to get preference $usertoemail = get_user_preferences('message_processor_email_email', '', $message->useridto); //if fails use user profile default if ($usertoemail == NULL) { $userto = get_record('user', 'id', $message->useridto); $usertoemail = $userto->email; } $userfrom = get_record('user', 'id', $message->useridfrom); if (email_to_user($usertoemail, $userfrom->email, $message->subject, $message->fullmessage, $message->fullmessagehtml)) { /// Move the entry to the other table $message->timeread = time(); $messageid = $message->id; unset($message->id); //if there is no more processor that want to process this can move message if (count_records('message_working', array('unreadmessageid' => $messageid)) == 0) { if (insert_record('message_read', $message)) { delete_records('message', 'id', $messageid); } } } else { //delete what we've processed and check if can move message if (count_records('message_working', 'unreadmessageid', $messageid) == 0) { if (insert_record('message_read', $message)) { delete_records('message', 'id', $messageid); } } } return true; }
function viewfolder($folderid, $userid, $level) { $prefix = ""; for ($i = 0; $i < $level; $i++) { $prefix .= ">"; } $fileprefix = $prefix . ">"; if ($folderid == -1) { $body = <<<END <option value="">ROOT</option> END; } else { $current_folder = get_record('file_folders', 'owner', $userid, 'ident', $folderid); $name = strtoupper(stripslashes($current_folder->name)); $body = <<<END <option value="">{$prefix} {$name}</option> END; } if ($files = get_records_select('files', "owner = ? AND folder = ?", array($userid, $folderid))) { foreach ($files as $file) { $filetitle = stripslashes($file->title); $body .= <<<END <option value="{$file->ident}">{$fileprefix} {$filetitle}</option> END; } } if ($folders = get_records_select('file_folders', "owner = ? AND parent = ? ", array($userid, $folderid))) { foreach ($folders as $folder) { $body .= viewfolder($folder->ident, $userid, $level + 1); } } return $body; }
function get_content() { global $CFG, $COURSE; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; if ($COURSE->id == $this->instance->pageid) { $course = $COURSE; } else { $course = get_record('course', 'id', $this->instance->pageid); } require_once $CFG->dirroot . '/course/lib.php'; $modinfo = get_fast_modinfo($course); $modfullnames = array(); foreach ($modinfo->cms as $cm) { if (!$cm->uservisible) { continue; } $modfullnames[$cm->modname] = $cm->modplural; } asort($modfullnames, SORT_LOCALE_STRING); foreach ($modfullnames as $modname => $modfullname) { if ($modname != 'label') { $this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/' . $modname . '/index.php?id=' . $this->instance->pageid . '">' . $modfullname . '</a>'; $this->content->icons[] = '<img src="' . $CFG->modpixpath . '/' . $modname . '/icon.gif" class="icon" alt="" />'; } } return $this->content; }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function question_dataset_dependent_items_form($submiturl, $question, $regenerate) { global $QTYPES, $SESSION, $CFG; $this->regenerate = $regenerate; $this->question = $question; $this->qtypeobj =& $QTYPES[$this->question->qtype]; // Validate the question category. if (!($category = get_record('question_categories', 'id', $question->category))) { print_error('categorydoesnotexist', 'question', $returnurl); } $this->category = $category; $this->categorycontext = get_context_instance_by_id($category->contextid); //get the dataset defintions for this question if (empty($question->id)) { $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->datasetdependent->definitionform->dataset); } else { if (empty($question->options)) { $this->get_question_options($question); } $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array()); } foreach ($this->datasetdefs as $datasetdef) { // Get maxnumber if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) { $this->maxnumber = $datasetdef->itemcount; } } foreach ($this->datasetdefs as $defid => $datasetdef) { if (isset($datasetdef->id)) { $this->datasetdefs[$defid]->items = get_records_sql(" SELECT itemnumber, definition, id, value\n FROM {$CFG->prefix}question_dataset_items\n WHERE definition = {$datasetdef->id} "); } } parent::moodleform($submiturl); }
public function __construct($id = 0, $data = null) { if (!empty($id)) { if (empty($data)) { if (!($data = get_record('interaction_instance', 'id', $id))) { throw new InteractionInstanceNotFoundException(get_string('interactioninstancenotfound', 'error', $id)); } } $this->id = $id; } else { $this->dirty = true; } if (empty($data)) { $data = array(); } foreach ((array) $data as $field => $value) { if (property_exists($this, $field)) { $this->{$field} = $value; } } if (empty($this->id)) { $this->ctime = time(); } $this->plugin = $this->get_plugin(); }
function kaltura_backup_one_mod($bf, $preferences, $resource) { global $CFG; if (is_numeric($resource)) { $kaltura_entry = get_record('kaltura_entries', 'id', $resource); } else { $kaltura_entry = get_record('kaltura_entries', 'id', $resource->id); } $status = true; //Start mod fwrite($bf, start_tag("MOD", 3, true)); //Print assignment data fwrite($bf, full_tag("ID", 4, false, $kaltura_entry->id)); fwrite($bf, full_tag("MODTYPE", 4, false, "kaltura")); fwrite($bf, full_tag("ENTRY_ID", 4, false, $kaltura_entry->entry_id)); fwrite($bf, full_tag("DIMENSIONS", 4, false, $kaltura_entry->dimensions)); fwrite($bf, full_tag("SIZE", 4, false, $kaltura_entry->size)); fwrite($bf, full_tag("CUSTOM_WIDTH", 4, false, $kaltura_entry->custom_width)); fwrite($bf, full_tag("DESIGN", 4, false, $kaltura_entry->design)); fwrite($bf, full_tag("TITLE", 4, false, $kaltura_entry->title)); fwrite($bf, full_tag("CONTEXT", 4, false, $kaltura_entry->context)); fwrite($bf, full_tag("ENTRY_TYPE", 4, false, $kaltura_entry->entry_type)); fwrite($bf, full_tag("MEDIA_TYPE", 4, false, $kaltura_entry->media_type)); //End mod $status = fwrite($bf, end_tag("MOD", 3, true)); return $status; }
function imagegallery_backup_one_mod($bf, $preferences, $imagegallery) { global $CFG; if (is_numeric($imagegallery)) { $imagegallery = get_record('imagegallery', 'id', $imagegallery); } $status = true; //Start mod fwrite($bf, start_tag("MOD", 3, true)); //Print imagegallery data fwrite($bf, full_tag("ID", 4, false, $imagegallery->id)); fwrite($bf, full_tag("MODTYPE", 4, false, "imagegallery")); fwrite($bf, full_tag("NAME", 4, false, $imagegallery->name)); fwrite($bf, full_tag("INTRO", 4, false, $imagegallery->intro)); fwrite($bf, full_tag("MAXBYTES", 4, false, $imagegallery->maxbytes)); fwrite($bf, full_tag("MAXWIDTH", 4, false, $imagegallery->maxwidth)); fwrite($bf, full_tag("MAXHEIGHT", 4, false, $imagegallery->maxheight)); fwrite($bf, full_tag("ALLOWSTUDENTUPLOAD", 4, false, $imagegallery->allowstudentupload)); fwrite($bf, full_tag("IMAGESPERPAGE", 4, false, $imagegallery->imagesperpage)); fwrite($bf, full_tag("TIMEMODIFIED", 4, false, $imagegallery->timemodified)); fwrite($bf, full_tag("REQUIRELOGIN", 4, false, $imagegallery->requirelogin)); fwrite($bf, full_tag("RESIZE", 4, false, $imagegallery->resize)); fwrite($bf, full_tag("DEFAULTCATEGORY", 4, false, $imagegallery->defaultcategory)); fwrite($bf, full_tag("SHADOW", 4, false, $imagegallery->shadow)); //if we've selected to backup users info, then execute backup_imagegallery_categories if (backup_userdata_selected($preferences, 'imagegallery', $imagegallery->id)) { $status = backup_imagegallery_categories($bf, $preferences, $imagegallery->id); } if (backup_userdata_selected($preferences, 'imagegallery', $imagegallery->id)) { $status = backup_imagegallery_images($bf, $preferences, $imagegallery->id); } //End mod $status = fwrite($bf, end_tag("MOD", 3, true)); return $status; }
function get_content() { global $USER; $isteacher = get_record('role_assignments', 'userid', $USER->id, 'roleid', '3'); // Is the $USER assigned as Teacher, anywhere in the system? $iscoursecreator = get_record('role_assignments', 'userid', $USER->id, 'roleid', '2'); // Is the $USER assigned as Course Creator, anywhere in the system? if ($this->content !== NULL) { return $this->content; } //echo "debug teacher=";print_r($isteacher); if (!isadmin($USER->id)) { if (empty($isteacher) and empty($iscoursecreator)) { return; } } if (!empty($this->instance->pinned) or $this->instance->pagetype === 'course-view') { // fancy html allowed only on course page and in pinned blocks for security reasons $filteropt = new stdClass(); $filteropt->noclean = true; } else { $filteropt = null; } $this->content = new stdClass(); $this->content->text = isset($this->config->text) ? format_text($this->config->text, FORMAT_HTML, $filteropt) : ''; $this->content->footer = ''; unset($filteropt); // memory footprint return $this->content; }
protected function __construct($course_id, $section_i) { global $CFG; //error_reporting(E_ALL); require_login($course_id); // 権限チェック $this->requireCapabilities($course_id); // 必要な関数が使用可能かチェック backup_required_functions(); // このタイミングで各モジュールのテーブルをアップグレード $return_to = $_SERVER['REQUEST_URI']; upgrade_backup_db($return_to); // 設定オブジェクトを生成 $this->prefs =& $this->createPreferences(); // ユニーク値をセット (Moodleコアはここにtime()が入っているのを期待しているのでそれに従う) $this->prefs->backup_unique_code = time(); // コースを取得 $this->course = get_record('course', 'id', $course_id); if (!$this->course) { throw new SharingCart_CourseException('Invalid ID'); } // セクションを取得 $this->section = get_record('course_sections', 'course', $course_id, 'section', $section_i); if (!$this->section) { throw new SharingCart_SectionException('Invalid ID'); } }
/** * Sign up a new user ready for confirmation. * Password is passed in plaintext. * * @param object $user new user object (with system magic quotes) * @param boolean $notify print notice with link and terminate */ function user_signup($user, $notify = true) { global $CFG; require_once $CFG->dirroot . '/user/profile/lib.php'; $user->password = hash_internal_user_password($user->password); if (!($user->id = insert_record('user', $user))) { print_error('auth_emailnoinsert', 'auth'); } /// Save any custom profile field information profile_save_data($user); $user = get_record('user', 'id', $user->id); events_trigger('user_created', $user); if (!send_confirmation_email($user)) { print_error('auth_emailnoemail', 'auth'); } if ($notify) { global $CFG; $emailconfirm = get_string('emailconfirm'); $navlinks = array(); $navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($emailconfirm, $emailconfirm, $navigation); notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php"); } else { return true; } }
function definition_after_data() { global $CFG; parent::definition_after_data(); $mform =& $this->_form; if ($association_id = $mform->getElementValue('association_id')) { if ($record = get_record(CLSTTRKTABLE, 'id', $association_id)) { if ($cluster_record = get_record(CLSTTABLE, 'id', $record->clusterid)) { foreach ($this->cluster_fields as $id => $display) { $element =& $mform->getElement('cluster' . $id); $element->setValue($cluster_record->{$id}); } } $track_sql = "SELECT trk.*,\n cur.name AS parcur,\n (SELECT COUNT(*)\n FROM {$CFG->prefix}crlm_track_class\n WHERE trackid = trk.id ) as class\n FROM {$CFG->prefix}crlm_track trk\n JOIN {$CFG->prefix}crlm_curriculum cur\n ON trk.curid = cur.id\n WHERE trk.defaulttrack = 0\n AND trk.id = {$record->trackid}"; if ($track_record = get_record_sql($track_sql)) { foreach ($this->track_fields as $id => $display) { $element =& $mform->getElement('track' . $id); $element->setValue($track_record->{$id}); } } $autoenrol_element =& $mform->getElement('autoenrol'); $autoenrol_element->setValue($record->autoenrol); } } }
function definition() { global $CFG; $mform =& $this->_form; // this hack is needed for different settings of each subtype if (!empty($this->_instance)) { if ($res = get_record('resource', 'id', (int) $this->_instance)) { $type = $res->type; } else { error('incorrect assignment'); } } else { $type = required_param('type', PARAM_ALPHA); } $mform->addElement('hidden', 'type', $type); $mform->setDefault('type', $type); require $CFG->dirroot . '/mod/resource/type/' . $type . '/resource.class.php'; $resclass = 'resource_' . $type; $this->_resinstance = new $resclass(); //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); // $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment')); $mform->addElement('text', 'name', get_string('name'), array('size' => '48')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); $mform->addElement('htmleditor', 'summary', get_string('summary')); $mform->setType('summary', PARAM_RAW); $mform->setHelpButton('summary', array('summary', get_string('summary'), 'resource')); // summary should be optional again MDL-9485 //$mform->addRule('summary', get_string('required'), 'required', null, 'client'); $mform->addElement('header', 'typedesc', get_string('resourcetype' . $type, 'resource')); $this->_resinstance->setup_elements($mform); $this->standard_coursemodule_elements(array('groups' => false, 'groupmembersonly' => true, 'gradecat' => false)); $this->add_action_buttons(); }
/** * Loads data from the database. * Note: even if the function fails, it may still have overwritten some or all existing data in the object. * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table) * @return bool True if successful, or false otherwise */ function load($id) { // Make sure the ID is valid if (!is_int($id) || $id <= 0) { echo "<hr><pre>ID = "; print_r($id); echo "</pre><hr>"; return false; } // Fetch the course module data if (!($this->cm = get_coursemodule_from_id('sloodle', $id))) { return false; } // Load from the primary table: Sloodle instance if (!($this->sloodle_module_instance = get_record('sloodle', 'id', $this->cm->instance))) { return false; } // Check that it is the correct type if ($this->sloodle_module_instance->type != SLOODLE_TYPE_CTRL) { return false; } // Load from the secondary table: Distributor instance if (!($this->sloodle_controller_instance = get_record('sloodle_controller', 'sloodleid', $this->cm->instance))) { return false; } return true; }
function test_grade_outcome_delete() { $grade_outcome = new grade_outcome($this->grade_outcomes[0]); $this->assertTrue(method_exists($grade_outcome, 'delete')); $this->assertTrue($grade_outcome->delete()); $this->assertFalse(get_record('grade_outcomes', 'id', $grade_outcome->id)); }
/** * TODO comment this */ function process_data($data) { global $CFG, $USER; foreach ($data->unit as $idx => $v) { $qual = get_record('ilp_qual_units', 'UniqueReferenceNumber', $idx, 'courseid', $data->course_id); if (empty($qual)) { $course = get_record('course', 'id', $data->course_id); $qualificationunits = $this->db->return_table_values('ofqual_qualification_units', array('UniqueReferenceNumber' => array('=' => "'{$idx}'"), 'qualificationid' => array('=' => "'{$course->idnumber}'"))); if (!empty($qualificationunits)) { $qual = new stdClass(); $q = $qualificationunits[0]; $qual->courseid = $data->course_id; //$qual->academic_year = $q['academic_year']; $qual->qualificationid = $q['QualificationID']; $qual->UniqueReferenceNumber = $q['UniqueReferenceNumber']; $qual->title = $q['Title']; $qual->unitownerreference = $q['UnitOwnerReference']; $qual->selected = !empty($v) ? 1 : 0; $qual->title = mysql_real_escape_string($qual->title); $qual->title = str_replace("'", "", $qual->title); insert_record('ilp_qual_units', $qual); } } else { $qual->title = mysql_real_escape_string($qual->title); $qual->title = str_replace("'", "", $qual->title); $qual->selected = !empty($v) ? 1 : 0; update_record('ilp_qual_units', $qual); } } }
function survey_backup_one_mod($bf, $preferences, $survey) { $status = true; if (is_numeric($survey)) { $survey = get_record('survey', 'id', $survey); } //Start mod fwrite($bf, start_tag("MOD", 3, true)); //Print choice data fwrite($bf, full_tag("ID", 4, false, $survey->id)); fwrite($bf, full_tag("MODTYPE", 4, false, "survey")); fwrite($bf, full_tag("TEMPLATE", 4, false, $survey->template)); fwrite($bf, full_tag("DAYS", 4, false, $survey->days)); fwrite($bf, full_tag("TIMECREATED", 4, false, $survey->timecreated)); fwrite($bf, full_tag("TIMEMODIFIED", 4, false, $survey->timemodified)); fwrite($bf, full_tag("NAME", 4, false, $survey->name)); fwrite($bf, full_tag("INTRO", 4, false, $survey->intro)); fwrite($bf, full_tag("QUESTIONS", 4, false, $survey->questions)); //if we've selected to backup users info, then execute backup_survey_answers and //backup_survey_analysis if (backup_userdata_selected($preferences, 'survey', $survey->id)) { $status = backup_survey_answers($bf, $preferences, $survey->id); $status = backup_survey_analysis($bf, $preferences, $survey->id); } //End mod $status = fwrite($bf, end_tag("MOD", 3, true)); return $status; }
function block_check_opensettings($courseid) { //do this once on page load to prevent overload on loops //see if Open Meta, Open Course, Groups, Groupings are enabled $openshare = get_record("block", "name", "openshare"); //print "Open Meta block status:".$openshare->visible; $opencourse = get_record("block_openshare_courses", "courseid", $courseid); //print "<br/>Open Course Status:".$opencourse->status; //we need to know what "resource" module's id# is so we can signify glass door on resources only $resmod = get_record("modules", "name", "resource"); //we need to know how the open_licenses table has as ids for copyright and cc default $ccid = get_record("block_openshare_licenses", "name", "CC by-nc-sa"); $cid = get_record("block_openshare_licenses", "name", "copyright"); /* Check grouping on submit $opengroup = get_record("groups", "courseid", $courseid, "name", "Course Members"); //print "<br/>Course Members Group status:".$opengroup->id.$opengroup->name; $opengrouping = get_record("groupings", "courseid", $courseid, "name", "Closed"); //print "<br/>Closed Grouping status:".$opengrouping->id.$opengrouping->name; $opengroupinggroup = get_record("groupings_groups", "groupingid", $opengrouping->id, "groupid", $opengroup->id); //print "<br/>Grouping Group status:".$opengroupinggroup->id; */ return array("ccid" => $ccid->id, "cid" => $cid->id, "resid" => $resmod->id, "ometa" => $openshare->visible, "ocourse" => $opencourse->status); }
/** * Loads data from the database. * Note: even if the function fails, it may still have overwritten some or all existing data in the object. * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table) * @return bool True if successful, or false otherwise */ function load($id) { // Make sure the ID is valid $id = (int) $id; if ($id <= 0) { return false; } // Fetch the course module data if (!($this->cm = get_coursemodule_from_id('assignment', $id))) { sloodle_debug("Failed to load course module instance #{$id}.<br/>"); return false; } // Make sure the module is visible if ($this->cm->visible == 0) { sloodle_debug("Error: course module instance #{$id} not visible.<br/>"); return false; } // Load from the primary table: assignment instance if (!($this->moodle_assignment_instance = get_record('assignment', 'id', $this->cm->instance))) { sloodle_debug("Failed to load assignment with instance ID #{$cm->instance}.<br/>"); return false; } // Make sure this assignment is of the correct type if ($this->moodle_assignment_instance->assignmenttype != 'sloodleobject') { sloodle_debug("ERROR assignment \"{$this->moodle_assignment_instance->name}\" is not of type 'sloodleobject' (actual type: '{$this->moodle_assignment_instance->assignmenttype}')."); return false; } // Attempt to construct the assignment object $this->assignment = new assignment_sloodleobject($this->cm->id, $this->moodle_assignment_instance, $this->cm); return true; }
function requestfriendship_submit(Pieform $form, $values) { global $USER, $SESSION, $id, $goto; $loggedinid = $USER->get('id'); $user = get_record('usr', 'id', $id); // friend db record $f = new StdClass(); $f->ctime = db_format_timestamp(time()); // notification info $n = new StdClass(); $n->url = profile_url($USER, false); $n->users = array($user->id); $n->fromuser = $loggedinid; $lang = get_user_language($user->id); $displayname = display_name($USER, $user); $n->strings = new stdClass(); $n->strings->urltext = (object) array('key' => 'Requests'); $f->owner = $id; $f->requester = $loggedinid; $f->message = $values['message']; insert_record('usr_friend_request', $f); $n->subject = get_string_from_language($lang, 'requestedfriendlistsubject', 'group'); if (isset($values['message']) && !empty($values['message'])) { $n->message = get_string_from_language($lang, 'requestedfriendlistmessageexplanation', 'group', $displayname) . $values['message']; } else { $n->message = get_string_from_language($lang, 'requestedfriendlistinboxmessage', 'group', $displayname); } require_once 'activity.php'; activity_occurred('maharamessage', $n); handle_event('addfriendrequest', array('requester' => $loggedinid, 'owner' => $id)); $SESSION->add_ok_msg(get_string('friendformrequestsuccess', 'group', display_name($id))); redirect($goto); }
/** * Write the info about the given module instance into the backup file * * @param resource $bf backup file resource * @param object $preferences Backup settings * @param object $stampcoll Stampcoll record (if object) or its ID (if numeric) * @return boolean True if success, False if failure */ function stampcoll_backup_one_mod($bf, $preferences, $stampcoll) { if (is_numeric($stampcoll)) { $stampcoll = get_record('stampcoll', 'id', $stampcoll); } $status = true; $status = $status && fwrite($bf, start_tag('MOD', 3, true)); $status = $status && fwrite($bf, full_tag('ID', 4, false, $stampcoll->id)); $status = $status && fwrite($bf, full_tag('MODTYPE', 4, false, 'stampcoll')); $status = $status && fwrite($bf, full_tag('MODVERSION', 4, false, stampcoll_modversion())); $status = $status && fwrite($bf, full_tag('NAME', 4, false, $stampcoll->name)); $status = $status && fwrite($bf, full_tag('TEXT', 4, false, $stampcoll->text)); $status = $status && fwrite($bf, full_tag('FORMAT', 4, false, $stampcoll->format)); $status = $status && fwrite($bf, full_tag('IMAGE', 4, false, $stampcoll->image)); $status = $status && fwrite($bf, full_tag('TIMEMODIFIED', 4, false, $stampcoll->timemodified)); $status = $status && fwrite($bf, full_tag('DISPLAYZERO', 4, false, $stampcoll->displayzero)); $status = $status && fwrite($bf, full_tag('ANONYMOUS', 4, false, $stampcoll->anonymous)); //If we've selected to backup users info, then backup collected stamps if (backup_userdata_selected($preferences, 'stampcoll', $stampcoll->id)) { $status = $status && stampcoll_backup_collected_stamps($bf, $preferences, $stampcoll->id); } //End module tag $status = $status && fwrite($bf, end_tag('MOD', 3, true)); return $status; }
function deletepost_submit(Pieform $form, $values) { global $SESSION, $USER; $objectionable = get_record_sql("SELECT fp.id\n FROM {interaction_forum_post} fp\n JOIN {objectionable} o\n ON (o.objecttype = 'forum' AND o.objectid = fp.id)\n WHERE fp.id = ?\n AND o.resolvedby IS NULL\n AND o.resolvedtime IS NULL", array($values['post'])); if ($objectionable !== false) { // Trigger activity. $data = new StdClass(); $data->postid = $values['post']; $data->message = ''; $data->reporter = $USER->get('id'); $data->ctime = time(); $data->event = DELETE_OBJECTIONABLE_POST; activity_occurred('reportpost', $data, 'interaction', 'forum'); } update_record('interaction_forum_post', array('deleted' => 1), array('id' => $values['post'])); $SESSION->add_ok_msg(get_string('deletepostsuccess', 'interaction.forum')); // Figure out which parent record to redirect us to. If the parent record is deleted, // keep moving up the chain until you find one that's not deleted. $postrec = new stdClass(); $postrec->parent = $values['parent']; do { $postrec = get_record('interaction_forum_post', 'id', $postrec->parent, null, null, null, null, 'id, deleted, parent'); } while ($postrec && $postrec->deleted && $postrec->parent); $redirecturl = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic']; if ($postrec && $postrec->parent) { $redirecturl .= '&post=' . $postrec->id; } redirect($redirecturl); }
function save_question_options($question) { if ($answer = get_record("question_answers", "question", $question->id)) { // Existing answer, so reuse it $answer->answer = $question->feedback; $answer->feedback = $question->feedback; $answer->fraction = $question->fraction; if (!update_record("question_answers", $answer)) { $result = new stdClass(); $result->error = "Could not update quiz answer!"; return $result; } } else { $answer = new stdClass(); $answer->question = $question->id; $answer->answer = $question->feedback; $answer->feedback = $question->feedback; $answer->fraction = $question->fraction; if (!($answer->id = insert_record("question_answers", $answer))) { $result = new stdClass(); $result->error = "Could not insert quiz answer!"; return $result; } } return true; }
function validation($data, $files) { global $COURSE, $CFG; $errors = parent::validation($data, $files); $textlib = textlib_get_instance(); $name = trim(stripslashes($data['name'])); if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) { if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) { if (groups_get_group_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupnameexists', 'group', $name); } } if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) { // enforce password policy only if changing password $errmsg = ''; if (!check_password_policy($data['enrolmentkey'], $errmsg)) { $errors['enrolmentkey'] = $errmsg; } } } else { if (groups_get_group_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupnameexists', 'group', $name); } } return $errors; }
function validation($usernew) { global $CFG; $usernew = (object) $usernew; $user = get_record('user', 'id', $usernew->id); $err = array(); // validate email if (!validate_email($usernew->email)) { $err['email'] = get_string('invalidemail'); } else { if ($usernew->email !== $user->email and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) { $err['email'] = get_string('emailexists'); } } if ($usernew->email === $user->email and over_bounce_threshold($user)) { $err['email'] = get_string('toomanybounces'); } /// Next the customisable profile fields $err += profile_validation($usernew); if (count($err) == 0) { return true; } else { return $err; } }
/** * Starts the backup of a whole module instance * * @param object $bf Backup file * @param object $preferences Backup preferences * @param object $pagemenu A full pagemenu record object * @return boolean **/ function pagemenu_backup_one_mod($bf, $preferences, $pagemenu) { $status = true; if (is_numeric($pagemenu)) { $pagemenu = get_record('pagemenu', 'id', $pagemenu); } // Start mod fwrite($bf, start_tag('MOD', 3, true)); // Print pagemenu data fwrite($bf, full_tag('ID', 4, false, $pagemenu->id)); fwrite($bf, full_tag('MODTYPE', 4, false, 'pagemenu')); fwrite($bf, full_tag('NAME', 4, false, $pagemenu->name)); fwrite($bf, full_tag('DISPLAYNAME', 4, false, $pagemenu->displayname)); fwrite($bf, full_tag('USEASTAB', 4, false, $pagemenu->useastab)); fwrite($bf, full_tag('TABORDER', 4, false, $pagemenu->taborder)); fwrite($bf, full_tag('TIMEMODIFIED', 4, false, $pagemenu->timemodified)); // Backup Links if (!($status = backup_pagemenu_links($bf, $preferences, $pagemenu))) { debugging('Link Backup Failed!'); } // End mod if ($status) { $status = fwrite($bf, end_tag('MOD', 3, true)); } return $status; }
function lms_get_folder($installid, $foldername, $user) { // look for the installid folder first. if (!($folder = get_record('file_folders', 'owner', $user->ident, 'name', $installid))) { // we have to make it. $folder = new StdClass(); $folder->name = $installid; $folder->owner = $user->ident; $folder->files_owner = $user->ident; $folder->parent = -1; $folder->access = 'user' . $user->ident; // ew $folder->ident = insert_record('file_folders', $folder); } if (!($subfolder = get_record('file_folders', 'owner', $user->ident, 'name', $foldername, 'parent', $folder->ident))) { // we have to make it. $subfolder = new StdClass(); $subfolder->name = $foldername; $subfolder->owner = $user->ident; $subfolder->files_owner = $user->ident; $subfolder->parent = $folder->ident; $subfolder->access = 'user' . $user->ident; // ew $subfolder->ident = insert_record('file_folders', $subfolder); } return $subfolder; }