diff --git a/mod/data/backuplib.php b/mod/data/backuplib.php index c8a1e1e108f..3065e8bf89a 100644 --- a/mod/data/backuplib.php +++ b/mod/data/backuplib.php @@ -37,12 +37,12 @@ //Return a content encoded to support interactivities linking. Every module function data_backup_mods($bf,$preferences) { - global $CFG; + global $CFG, $DB; $status = true; // iterate - if ($datas = get_records('data','course',$preferences->backup_course,"id")) { + if ($datas = $DB->get_records('data', array('course'=>$preferences->backup_course),"id")) { foreach ($datas as $data) { if (function_exists('backup_mod_selected')) { // Moodle 1.6 @@ -61,10 +61,10 @@ function data_backup_mods($bf,$preferences) { } function data_backup_one_mod($bf,$preferences,$data) { - global $CFG; + global $CFG, $DB; if (is_numeric($data)) { // backwards compatibility - $data = get_record('data','id',$data); + $data = $DB->get_record('data', array('id'=>$data)); } $instanceid = $data->id; @@ -125,10 +125,10 @@ function data_backup_one_mod($bf,$preferences,$data) { function backup_data_fields($bf,$preferences,$dataid){ - global $CFG; + global $CFG, $DB; $status = true; - $data_fields = get_records("data_fields","dataid",$dataid); + $data_fields = $DB->get_records("data_fields", array("dataid"=>$dataid)); //If there is submissions if ($data_fields) { @@ -165,10 +165,10 @@ function backup_data_fields($bf,$preferences,$dataid){ } function backup_data_content($bf,$preferences,$recordid){ - global $CFG; + global $CFG, $DB; $status = true; - $data_contents = get_records("data_content","recordid",$recordid); + $data_contents = $DB->get_records("data_content", array("recordid"=>$recordid)); //If there is submissions if ($data_contents) { @@ -197,9 +197,10 @@ function backup_data_content($bf,$preferences,$recordid){ } function backup_data_ratings($bf,$preferences,$recordid){ - global $CFG; + global $CFG, $DB; + $status = true; - $data_ratings = get_records("data_ratings","recordid",$recordid); + $data_ratings = $DB->get_records("data_ratings", array("recordid"=>$recordid)); //If there is submissions if ($data_ratings) { @@ -225,9 +226,10 @@ function backup_data_ratings($bf,$preferences,$recordid){ return $status; } function backup_data_comments($bf,$preferences,$recordid){ - global $CFG; + global $CFG, $DB; + $status = true; - $data_comments = get_records("data_comments","recordid",$recordid); + $data_comments = $DB->get_records("data_comments", array("recordid"=>$recordid)); //If there is submissions if ($data_comments) { @@ -275,11 +277,11 @@ function backup_data_files_instance($bf,$preferences,$instanceid) { } function backup_data_records($bf,$preferences,$dataid){ + global $CFG, $DB; - global $CFG; $status = true; - $data_records = get_records("data_records","dataid",$dataid); + $data_records = $DB->get_records("data_records", array("dataid"=>$dataid)); //If there is submissions if ($data_records) { //Write start tag @@ -312,7 +314,6 @@ function backup_data_records($bf,$preferences,$dataid){ } function backup_data_files($bf,$preferences) { - global $CFG; $status = true; @@ -333,8 +334,8 @@ function backup_data_files($bf,$preferences) { } function backup_data_file_instance($bf,$preferences,$instanceid) { - global $CFG; + $status = true; //First we check to moddata exists and create it as necessary @@ -396,7 +397,6 @@ function data_check_backup_mods($course,$user_data=false,$backup_unique_code,$in * @return string the content encoded */ function data_encode_content_links ($content,$preferences) { - global $CFG; $base = preg_quote($CFG->wwwroot,"/"); diff --git a/mod/data/comment.php b/mod/data/comment.php index bed2afe83ff..b486812535b 100755 --- a/mod/data/comment.php +++ b/mod/data/comment.php @@ -14,13 +14,13 @@ $confirm = optional_param('confirm','',PARAM_INT); - if (! $record = get_record('data_records', 'id', $rid)) { + if (! $record = $DB->get_record('data_records', array('id'=>$rid))) { print_error('invalidrecord', 'data'); } - if (! $data = get_record('data', 'id', $record->dataid)) { + if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) { print_error('invalidid', 'data'); } - if (! $course = get_record('course', 'id', $data->course)) { + if (! $course = $DB->get_record('course', array('id'=>$data->course))) { print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { @@ -32,7 +32,7 @@ $context = get_context_instance(CONTEXT_MODULE, $cm->id); if ($commentid) { - if (! $comment = get_record('data_comments', 'id', $commentid)) { + if (! $comment = $DB->get_record('data_comments', array('id'=>$commentid))) { print_error('commentmisconf'); } if ($comment->recordid != $record->id) { @@ -68,7 +68,7 @@ switch ($mode) { case 'add': - if (!$formadata = $mform->get_data()) { + if (!$formadata = $mform->get_data(false)) { break; // something is wrong here, try again } @@ -78,7 +78,7 @@ $newcomment->modified = time(); $newcomment->content = $formadata->content; $newcomment->recordid = $formadata->rid; - if (insert_record('data_comments',$newcomment)) { + if ($DB->insert_record('data_comments',$newcomment)) { redirect('view.php?rid='.$record->id.'&page='.$page); } else { print_error('cannotsavecomment'); @@ -97,7 +97,7 @@ $updatedcomment->format = $formadata->format; $updatedcomment->modified = time(); - if (update_record('data_comments',$updatedcomment)) { + if ($DB->update_record('data_comments', $updatedcomment)) { redirect('view.php?rid='.$record->id.'&page='.$page); } else { print_error('cannotsavecomment'); @@ -106,7 +106,7 @@ case 'delete': //deletes single comment from db if ($confirm and confirm_sesskey() and $comment) { - delete_records('data_comments','id',$comment->id); + $DB->delete_records('data_comments', array('id'=>$comment->id)); redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentdeleted', 'data')); } else { //print confirm delete form diff --git a/mod/data/css.php b/mod/data/css.php index 00469ed2ed4..393d9eacbeb 100755 --- a/mod/data/css.php +++ b/mod/data/css.php @@ -29,7 +29,7 @@ $d = optional_param('d', 0, PARAM_INT); // database id - if ($data = get_record('data', 'id', $d)) { + if ($data = $DB->get_record('data', array('id'=>$d))) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT'); header('Cache-control: max_age = '. $lifetime); diff --git a/mod/data/edit.php b/mod/data/edit.php index b699caace0d..25a4f3f512e 100755 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -37,18 +37,18 @@ if (! $cm = get_coursemodule_from_id('data', $id)) { print_error('invalidcoursemodule'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { print_error('coursemisconf'); } - if (! $data = get_record('data', 'id', $cm->instance)) { + if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) { print_error('invalidcoursemodule'); } } else { - if (! $data = get_record('data', 'id', $d)) { + if (! $data = $DB->get_record('data', array('id'=>$d))) { print_error('invalidid', 'data'); } - if (! $course = get_record('course', 'id', $data->course)) { + if (! $course = $DB->get_record('course', array('id'=>$data->course))) { print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { @@ -75,7 +75,7 @@ /// Can't use this if there are no fields if (has_capability('mod/data:managetemplates', $context)) { - if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database! + if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database! redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry } } @@ -141,14 +141,14 @@ /// Process incoming data for adding/updating records - if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/edit.php') and confirm_sesskey()) { + if ($datarecord = data_submitted(false) and confirm_sesskey()) { $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel'); // strings to be ignored in input data if ($rid) { /// Update some records /// All student edits are marked unapproved by default - $record = get_record('data_records','id',$rid); + $record = $DB->get_record('data_records', array('id'=>$rid)); /// reset approved flag after student edit if (!has_capability('mod/data:approve', $context)) { @@ -157,7 +157,7 @@ $record->groupid = $currentgroup; $record->timemodified = time(); - update_record('data_records',$record); + $DB->update_record('data_records', $record); /// Update all content $field = NULL; @@ -216,11 +216,11 @@ if (!$emptyform && $recordid = data_add_record($data, $currentgroup)) { //add instance to data_record /// Insert a whole lot of empty records to make sure we have them - $fields = get_records('data_fields','dataid',$data->id); + $fields = $DB->get_records('data_fields', array('dataid'=>$data->id)); foreach ($fields as $field) { $content->recordid = $recordid; $content->fieldid = $field->id; - insert_record('data_content',$content); + $DB->insert_record('data_content',$content); } //for each field in the add form, add it to the data_content. @@ -268,7 +268,7 @@ * Regular expression replacement section * ******************************************/ if ($data->addtemplate){ - $possiblefields = get_records('data_fields','dataid',$data->id,'id'); + $possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id'); ///then we generate strings to replace foreach ($possiblefields as $eachfield){ @@ -340,7 +340,7 @@ /// Finish the page // Print the stuff that need to come after the form fields. - if (!$fields = get_records('data_fields', 'dataid', $data->id)) { + if (!$fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) { print_error('nofieldindatabase', 'data'); } foreach ($fields as $eachfield) { diff --git a/mod/data/export.php b/mod/data/export.php index 81283e10a1e..a3e8fdba1b1 100644 --- a/mod/data/export.php +++ b/mod/data/export.php @@ -8,7 +8,7 @@ require_once('export_form.php'); $d = required_param('d', PARAM_INT); // database ID -if (! $data = get_record('data', 'id', $d)) { +if (! $data = $DB->get_record('data', array('id'=>$d))) { print_error('wrongdataid', 'data'); } @@ -16,7 +16,7 @@ if (! $cm = get_coursemodule_from_instance('data', $data->id, $data->course)) { print_error('invalidcoursemodule'); } -if(! $course = get_record('course', 'id', $cm->course)) { +if(! $course = $DB->get_record('course', array('id'=>$cm->course))) { print_error('invalidcourseid', '', '', $cm->course); } @@ -33,7 +33,7 @@ require_login($course->id, false, $cm); require_capability('mod/data:managetemplates', $context); // get fields for this database -$fieldrecords = get_records('data_fields','dataid', $data->id, 'id'); +$fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id'); if(empty($fieldrecords)) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -85,12 +85,12 @@ foreach($fields as $key => $field) { } } -$datarecords = get_records('data_records', 'dataid', $data->id); +$datarecords = $DB->get_records('data_records', array('dataid'=>$data->id)); ksort($datarecords); $line = 1; foreach($datarecords as $record) { // get content indexed by fieldid - if( $content = get_records('data_content', 'recordid', $record->id, 'fieldid', 'fieldid, content, content1, content2, content3, content4') ) { + if( $content = $DB->get_records('data_content', array('recordid'=>$record->id), 'fieldid', 'fieldid, content, content1, content2, content3, content4') ) { foreach($fields as $field) { $contents = ''; if(isset($content[$field->field->id])) { diff --git a/mod/data/field.php b/mod/data/field.php index c041ce4e322..2a62ffacf51 100755 --- a/mod/data/field.php +++ b/mod/data/field.php @@ -44,18 +44,18 @@ if (! $cm = get_coursemodule_from_id('data', $id)) { error('Course Module ID was incorrect'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { error('Course is misconfigured'); } - if (! $data = get_record('data', 'id', $cm->instance)) { + if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) { error('Course module is incorrect'); } } else { - if (! $data = get_record('data', 'id', $d)) { + if (! $data = $DB->get_record('data', array('id'=>$d))) { error('Data ID is incorrect'); } - if (! $course = get_record('course', 'id', $data->course)) { + if (! $course = $DB->get_record('course', array('id'=>$data->course))) { error('Course is misconfigured'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { @@ -74,7 +74,7 @@ switch ($mode) { case 'add': ///add a new field - if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){ + if (confirm_sesskey() and $fieldinput = data_submitted(false)){ //$fieldinput->name = data_clean_field_name($fieldinput->name); @@ -96,7 +96,7 @@ $field->insert_field(); /// Update some templates - data_append_new_field_to_templates($data, stripslashes($fieldinput->name)); + data_append_new_field_to_templates($data, $fieldinput->name); add_to_log($course->id, 'data', 'fields add', "field.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id); @@ -108,7 +108,7 @@ case 'update': ///update a field - if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/field.php')){ + if (confirm_sesskey() and $fieldinput = data_submitted(false)){ //$fieldinput->name = data_clean_field_name($fieldinput->name); @@ -168,7 +168,7 @@ $rec->id = $data->id; $rec->defaultsort = 0; $rec->defaultsortdir = 0; - if (!update_record('data', $rec)) { + if (!$DB->update_record('data', $rec)) { error('There was an error updating the database'); } } @@ -203,7 +203,7 @@ $rec->defaultsort = $defaultsort; $rec->defaultsortdir = $defaultsortdir; - if (update_record('data', $rec)) { + if ($DB->update_record('data', $rec)) { redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('changessaved'), 2); } else { error('There was an error updating the database'); @@ -250,7 +250,7 @@ data_print_header($course,$cm,$data,'fields'); - if (!record_exists('data_fields','dataid',$data->id)) { + if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { notify(get_string('nofieldindatabase','data')); // nothing in database notify(get_string('pleaseaddsome','data', 'preset.php?id='.$cm->id)); // link to presets @@ -260,7 +260,7 @@ $table->align = array('left','left','left', 'center'); $table->wrap = array(false,false,false,false); - if ($fff = get_records('data_fields','dataid',$data->id,'id')){ + if ($fff = $DB->get_records('data_fields', array('dataid'=>$data->id),'id')){ foreach ($fff as $ff) { $field = data_get_field($ff, $data); @@ -302,7 +302,7 @@ echo ''; echo ''.get_string('defaultsortfield','data').''; echo ''; - if ($fields = get_records('data_fields','dataid',$data->id)) { + if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) { echo ''; foreach ($fields as $field) { if ($data->defaultsort == $field->id) { diff --git a/mod/data/field/checkbox/field.class.php b/mod/data/field/checkbox/field.class.php index 3cf433cab66..a4e88626c12 100755 --- a/mod/data/field/checkbox/field.class.php +++ b/mod/data/field/checkbox/field.class.php @@ -31,12 +31,12 @@ class data_field_checkbox extends data_field_base { } function display_add_field($recordid=0) { - global $CFG; + global $CFG, $DB; $content = array(); if ($recordid) { - $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); + $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); $content = explode('##', $content); } @@ -87,22 +87,25 @@ class data_field_checkbox extends data_field_base { } function update_content($recordid, $value, $name='') { + global $DB; + $content = new object(); $content->fieldid = $this->field->id; $content->recordid = $recordid; $content->content = $this->format_data_field_checkbox_content($value); - if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; - return update_record('data_content', $content); + return $DB->update_record('data_content', $content); } else { - return insert_record('data_content', $content); + return $DB->insert_record('data_content', $content); } } function display_browse_field($recordid, $template) { + global $DB; - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){ + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $contentArr = array(); if (!empty($content->content)) { $contentArr = explode('##', $content->content); diff --git a/mod/data/field/date/field.class.php b/mod/data/field/date/field.class.php index 2bf672251c3..fb32f20d733 100755 --- a/mod/data/field/date/field.class.php +++ b/mod/data/field/date/field.class.php @@ -39,9 +39,10 @@ class data_field_date extends data_field_base { } function display_add_field($recordid=0) { + global $DB; if ($recordid) { - $content = (int) get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); + $content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); } else { $content = time(); } @@ -81,6 +82,7 @@ class data_field_date extends data_field_base { } function update_content($recordid, $value, $name='') { + global $DB; $names = explode('_',$name); $name = $names[2]; // day month or year @@ -94,20 +96,19 @@ class data_field_date extends data_field_base { $content->recordid = $recordid; $content->content = make_timestamp($this->year, $this->month, $this->day, 12, 0, 0, 0, false); - if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; - return update_record('data_content', $content); + return $DB->update_record('data_content', $content); } else { - return insert_record('data_content', $content); + return $DB->insert_record('data_content', $content); } } } function display_browse_field($recordid, $template) { + global $CFG, $DB; - global $CFG; - - if ($content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid)){ + if ($content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { return userdate($content, get_string('strftimedate'), 0); } } diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index b0e2aa809d0..702012be610 100755 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -30,9 +30,9 @@ class data_field_file extends data_field_base { } function display_add_field($recordid=0) { - global $CFG; + global $CFG, $DB; if ($recordid){ - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $contents[0] = $content->content; $contents[1] = $content->content1; } else { @@ -87,8 +87,9 @@ class data_field_file extends data_field_base { } function display_browse_field($recordid, $template) { - global $CFG; - if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + global $CFG, $DB; + + if (!$content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { return false; } $width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' '; @@ -109,13 +110,14 @@ class data_field_file extends data_field_base { // content: "a##b" where a is the file name, b is the display name function update_content($recordid, $value, $name) { - global $CFG; - if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + global $CFG, $DB; + + if (!$oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { // Quickly make one now! $oldcontent = new object; $oldcontent->fieldid = $this->field->id; $oldcontent->recordid = $recordid; - if ($oldcontent->id = insert_record('data_content', $oldcontent)) { + if ($oldcontent->id = $DB->insert_record('data_content', $oldcontent)) { print_error('cannotinsertempty', 'data'); } } @@ -137,7 +139,7 @@ class data_field_file extends data_field_base { if ($um->process_file_uploads($dir)) { $newfile_name = $um->get_new_filename(); $content->content = $newfile_name; - update_record('data_content',$content); + $DB->update_record('data_content',$content); } } break; @@ -145,7 +147,7 @@ class data_field_file extends data_field_base { case 'filename': // only changing alt tag $content->content1 = clean_param($value, PARAM_NOTAGS); - update_record('data_content', $content); + $DB->update_record('data_content', $content); break; default: diff --git a/mod/data/field/file/mod.html b/mod/data/field/file/mod.html index 9fd3c603075..29227cd4401 100755 --- a/mod/data/field/file/mod.html +++ b/mod/data/field/file/mod.html @@ -12,7 +12,7 @@ maxbytes = get_field('course', 'maxbytes', 'id', $this->data->course); + $course->maxbytes = $DB->get_field('course', 'maxbytes', array('id'=>$this->data->course)); $choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes); choose_from_menu($choices, 'param3', $this->field->param3, '', '', 0, false, false, 0, 'param3'); ?> diff --git a/mod/data/field/latlong/field.class.php b/mod/data/field/latlong/field.class.php index 99d9f7fab86..f12dcc57bb6 100755 --- a/mod/data/field/latlong/field.class.php +++ b/mod/data/field/latlong/field.class.php @@ -48,11 +48,12 @@ class data_field_latlong extends data_field_base { } function display_add_field($recordid=0) { - global $CFG; + global $CFG, $DB; + $lat = ''; $long = ''; if ($recordid) { - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $lat = $content->content; $long = $content->content1; } @@ -95,8 +96,9 @@ class data_field_latlong extends data_field_base { } function display_browse_field($recordid, $template) { - global $CFG; - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + global $CFG, $DB; + + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $lat = empty($content->content)? '':$content->content; $long = empty($content->content1)? '':$content->content1; if (empty($lat) or empty($long)) { @@ -153,6 +155,8 @@ class data_field_latlong extends data_field_base { } function update_content($recordid, $value, $name='') { + global $DB; + $content = new object; $content->fieldid = $this->field->id; $content->recordid = $recordid; @@ -169,11 +173,11 @@ class data_field_latlong extends data_field_base { default: break; } - if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; - return update_record('data_content', $content); + return $DB->update_record('data_content', $content); } else { - return insert_record('data_content', $content); + return $DB->insert_record('data_content', $content); } } diff --git a/mod/data/field/latlong/kml.php b/mod/data/field/latlong/kml.php index 45c449bdee3..690d8dc652f 100644 --- a/mod/data/field/latlong/kml.php +++ b/mod/data/field/latlong/kml.php @@ -13,38 +13,38 @@ $rid = optional_param('rid', 0, PARAM_INT); //record id if ($rid) { - if (! $record = get_record('data_records', 'id', $rid)) { + if (! $record = $DB->get_record('data_records', array('id'=>$rid))) { print_error('invalidrecord', 'data'); } - if (! $data = get_record('data', 'id', $record->dataid)) { + if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) { print_error('invalidid', 'data'); } - if (! $course = get_record('course', 'id', $data->course)) { + if (! $course = $DB->get_record('course', array('id'=>$data->course))) { print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { print_error('invalidcoursemodule'); } - if (! $field = get_record('data_fields', 'id', $fieldid)) { + if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) { print_error('invalidfieldid', 'data'); } if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type! print_error('invalidfieldtype', 'data'); } - if (! $content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $rid)) { + if (! $content = $DB->get_record('data_content', array('fieldid'=>$fieldid, 'recordid'=>$rid))) { print_error('nofieldcontent', 'data'); } } else { // We must have $d - if (! $data = get_record('data', 'id', $d)) { + if (! $data = $DB->get_record('data', array('id'=>$d))) { print_error('invalidid', 'data'); } - if (! $course = get_record('course', 'id', $data->course)) { + if (! $course = $DB->get_record('course', array('id'=>$data->course))) { print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { print_error('invalidcoursemodule'); } - if (! $field = get_record('data_fields', 'id', $fieldid)) { + if (! $field = $DB->get_record('data_fields', array('id'=>$fieldid))) { print_error('invalidfieldid', 'data'); } if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type! @@ -65,7 +65,7 @@ if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities' /// If we have an empty Database then redirect because this page is useless without data if (has_capability('mod/data:managetemplates', $context)) { - if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database! + if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) { // Brand new database! redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry } } @@ -88,7 +88,7 @@ if($rid) { // List one single item echo data_latlong_kml_placemark($pm); } else { // List all items in turn - $contents = get_records('data_content', 'fieldid', $fieldid); + $contents = $DB->get_records('data_content', array('fieldid'=>$fieldid)); echo ''; @@ -147,7 +147,7 @@ function data_latlong_kml_get_item_name($content, $field) { $name = ''; if($field->param2 > 0) { - $name = htmlspecialchars(get_field('data_content', 'content', 'fieldid', $field->param2, 'recordid', $content->recordid)); + $name = htmlspecialchars($DB->get_field('data_content', 'content', array('fieldid'=>$field->param2, 'recordid'=>$content->recordid))); }elseif($field->param2 == -2) { $name = $content->content . ', ' . $content->content1; } diff --git a/mod/data/field/latlong/mod.html b/mod/data/field/latlong/mod.html index d924d1104d3..7cf519bf39e 100755 --- a/mod/data/field/latlong/mod.html +++ b/mod/data/field/latlong/mod.html @@ -29,7 +29,7 @@ field->param2==-2) echo ' selected="selected"' ?>> data->id.' AND type="text"'); + $textfields = $DB->get_records_select('data_fields', array('dataid'=>$this->data->id, 'type'=>'text')); echo ''; if(sizeof($textfields)>0) { foreach($textfields as $textfield) { diff --git a/mod/data/field/menu/field.class.php b/mod/data/field/menu/field.class.php index 16aba4d0e30..8ebe5e60f4b 100755 --- a/mod/data/field/menu/field.class.php +++ b/mod/data/field/menu/field.class.php @@ -31,9 +31,10 @@ class data_field_menu extends data_field_base { } function display_add_field($recordid=0) { + global $DB; if ($recordid){ - $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); + $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); $content = trim($content); } else { $content = ''; @@ -58,13 +59,13 @@ class data_field_menu extends data_field_base { } function display_search_field($content = '') { - global $CFG; + global $CFG, $DB; $usedoptions = array(); $sql = "SELECT DISTINCT content - FROM {$CFG->prefix}data_content - WHERE fieldid={$this->field->id} AND content IS NOT NULL"; - if ($used = get_records_sql($sql)) { + FROM {data_content} + WHERE fieldid=: AND content IS NOT NULL"; + if ($used = $DB->get_records_sql($sql, array($this->field->id))) { foreach ($used as $data) { $value = $data->content; if ($value === '') { diff --git a/mod/data/field/multimenu/field.class.php b/mod/data/field/multimenu/field.class.php index 038a494faee..e62d28601a4 100755 --- a/mod/data/field/multimenu/field.class.php +++ b/mod/data/field/multimenu/field.class.php @@ -32,9 +32,10 @@ class data_field_multimenu extends data_field_base { function display_add_field($recordid=0) { + global $DB; if ($recordid){ - $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); + $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); $content = explode('##', $content); } else { $content = array(); @@ -63,7 +64,7 @@ class data_field_multimenu extends data_field_base { } function display_search_field($value = '') { - global $CFG; + global $CFG, $DB; if (is_array($value)){ $content = $value['selected']; @@ -80,9 +81,9 @@ class data_field_multimenu extends data_field_base { // display only used options $usedoptions = array(); $sql = "SELECT DISTINCT content - FROM {$CFG->prefix}data_content - WHERE fieldid={$this->field->id} AND content IS NOT NULL"; - if ($used = get_records_sql($sql)) { + FROM {data_content} + WHERE fieldid=? AND content IS NOT NULL"; + if ($used = $DB->get_records_sql($sql, array($this->field->id))) { foreach ($used as $data) { $valuestr = $data->content; if ($valuestr === '') { @@ -104,7 +105,7 @@ class data_field_multimenu extends data_field_base { $found = true; $str .= 'fieldid = $this->field->id; $content->recordid = $recordid; $content->content = $this->format_data_field_multimenu_content($value); - if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; - return update_record('data_content', $content); + return $DB->update_record('data_content', $content); } else { - return insert_record('data_content', $content); + return $DB->insert_record('data_content', $content); } } @@ -185,7 +188,7 @@ class data_field_multimenu extends data_field_base { if ($key === 'xxx') { continue; } - if (!in_array(stripslashes($val), $options)) { + if (!in_array($val, $options)) { continue; } $vals[] = $val; @@ -200,8 +203,9 @@ class data_field_multimenu extends data_field_base { function display_browse_field($recordid, $template) { + global $DB; - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { if (empty($content->content)) { return false; } diff --git a/mod/data/field/number/field.class.php b/mod/data/field/number/field.class.php index 371d725ca5a..63a2cf387fd 100755 --- a/mod/data/field/number/field.class.php +++ b/mod/data/field/number/field.class.php @@ -30,6 +30,8 @@ class data_field_number extends data_field_base { } function update_content($recordid, $value, $name='') { + global $DB; + $content = new object; $content->fieldid = $this->field->id; $content->recordid = $recordid; @@ -39,16 +41,18 @@ class data_field_number extends data_field_base { } else { $content->content = null; } - if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; - return update_record('data_content', $content); + return $DB->update_record('data_content', $content); } else { - return insert_record('data_content', $content); + return $DB->insert_record('data_content', $content); } } function display_browse_field($recordid, $template) { - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + global $DB; + + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { if (strlen($content->content) < 1) { return false; } diff --git a/mod/data/field/picture/field.class.php b/mod/data/field/picture/field.class.php index a9f6e9a51eb..b10940ce6d0 100755 --- a/mod/data/field/picture/field.class.php +++ b/mod/data/field/picture/field.class.php @@ -35,12 +35,13 @@ class data_field_picture extends data_field_file { } function display_add_field($recordid=0) { - global $CFG; + global $CFG, $DB; + $filepath = ''; $filename = ''; $description = ''; if ($recordid) { - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $filename = $content->content; $description = $content->content1; } @@ -79,8 +80,9 @@ class data_field_picture extends data_field_file { } function display_browse_field($recordid, $template) { - global $CFG; - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){ + global $CFG, $DB; + + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { if (isset($content->content)) { $contents[0] = $content->content; $contents[1] = $content->content1; @@ -118,9 +120,11 @@ class data_field_picture extends data_field_file { } function update_field() { + global $DB; + // Get the old field data so that we can check whether the thumbnail dimensions have changed - $oldfield = get_record('data_fields', 'id', $this->field->id); - if (!update_record('data_fields', $this->field)) { + $oldfield = $DB->get_record('data_fields', array('id'=>$this->field->id)); + if (!$DB->update_record('data_fields', $this->field)) { notify('updating of new field failed!'); return false; } @@ -128,7 +132,7 @@ class data_field_picture extends data_field_file { // Have the thumbnail dimensions changed? if ($oldfield && ($oldfield->param4 != $this->field->param4 || $oldfield->param5 != $this->field->param5)) { // Check through all existing records and update the thumbnail - if ($contents = get_records('data_content', 'fieldid', $this->field->id)) { + if ($contents = $DB->get_records('data_content', array('fieldid'=>$this->field->id))) { if (count($contents) > 20) { notify(get_string('resizingimages', 'data'), 'notifysuccess'); echo "\n\n"; @@ -146,8 +150,10 @@ class data_field_picture extends data_field_file { } function update_content($recordid, $value, $name) { + global $DB; + parent::update_content($recordid, $value, $name); - $content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid); + $content = $DB->get_record('data_content',array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); $this->update_thumbnail($content); // Regenerate the thumbnail } diff --git a/mod/data/field/picture/mod.html b/mod/data/field/picture/mod.html index 66975535a27..a8d3a65e55d 100755 --- a/mod/data/field/picture/mod.html +++ b/mod/data/field/picture/mod.html @@ -44,7 +44,7 @@ maxbytes = get_field('course', 'maxbytes', 'id', $this->data->course); + $course->maxbytes = $DB->get_field('course', 'maxbytes', array('id'=>$this->data->course)); $choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes); choose_from_menu($choices, 'param3', $this->field->param3, '', '', 0, false, false, 0, 'param3'); ?> diff --git a/mod/data/field/radiobutton/field.class.php b/mod/data/field/radiobutton/field.class.php index e023ef391b5..60bc325bcb2 100755 --- a/mod/data/field/radiobutton/field.class.php +++ b/mod/data/field/radiobutton/field.class.php @@ -32,10 +32,10 @@ class data_field_radiobutton extends data_field_base { function display_add_field($recordid=0) { - global $CFG; + global $CFG, $DB; if ($recordid){ - $content = trim(get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid)); + $content = trim($DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))); } else { $content = ''; } diff --git a/mod/data/field/textarea/field.class.php b/mod/data/field/textarea/field.class.php index 10032ea19aa..8a3d0c6782d 100755 --- a/mod/data/field/textarea/field.class.php +++ b/mod/data/field/textarea/field.class.php @@ -32,13 +32,13 @@ class data_field_textarea extends data_field_base { function display_add_field($recordid=0) { - global $CFG; + global $CFG, $DB; $text = ''; $format = 0; if ($recordid){ - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $text = $content->content; $format = $content->content1; } @@ -96,6 +96,8 @@ class data_field_textarea extends data_field_base { function update_content($recordid, $value, $name='') { + global $DB; + $content = new object; $content->fieldid = $this->field->id; $content->recordid = $recordid; @@ -107,11 +109,11 @@ class data_field_textarea extends data_field_base { $content->content = clean_param($value, PARAM_CLEAN); } - if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; - return update_record('data_content', $content); + return $DB->update_record('data_content', $content); } else { - return insert_record('data_content', $content); + return $DB->insert_record('data_content', $content); } } } diff --git a/mod/data/field/url/field.class.php b/mod/data/field/url/field.class.php index 6754af116f1..78ac6877058 100755 --- a/mod/data/field/url/field.class.php +++ b/mod/data/field/url/field.class.php @@ -30,11 +30,12 @@ class data_field_url extends data_field_base { } function display_add_field($recordid=0) { - global $CFG; + global $CFG, $DB; + $url = ''; $text = ''; if ($recordid) { - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $url = $content->content; $text = $content->content1; } @@ -67,7 +68,9 @@ class data_field_url extends data_field_base { } function display_browse_field($recordid, $template) { - if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { + global $DB; + + if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $url = empty($content->content)? '':$content->content; $text = empty($content->content1)? '':$content->content1; if (empty($url) or ($url == 'http://')) { @@ -93,6 +96,8 @@ class data_field_url extends data_field_base { } function update_content($recordid, $value, $name='') { + global $DB; + $content = new object; $content->fieldid = $this->field->id; $content->recordid = $recordid; @@ -110,11 +115,11 @@ class data_field_url extends data_field_base { break; } - if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { + if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; - return update_record('data_content', $content); + return $DB->update_record('data_content', $content); } else { - return insert_record('data_content', $content); + return $DB->insert_record('data_content', $content); } } diff --git a/mod/data/filter.php b/mod/data/filter.php index c0193041276..90025272c43 100644 --- a/mod/data/filter.php +++ b/mod/data/filter.php @@ -7,7 +7,7 @@ // Modified for data module by Vy-Shane SF. function data_filter($courseid, $text) { - global $CFG; + global $CFG, $DB; static $nothingtodo; static $contentlist; @@ -29,11 +29,11 @@ 'dr.id AS recordid, ' . 'dc.content AS content, ' . 'd.id AS dataid ' . - 'FROM '.$CFG->prefix.'data d, ' . - $CFG->prefix.'data_fields df, ' . - $CFG->prefix.'data_records dr, ' . - $CFG->prefix.'data_content dc ' . - "WHERE (d.course = '$courseid' or d.course = '".SITEID."')" . + 'FROM {data} d, ' . + '{data_fields} df, ' . + '{data_records} dr, ' . + '{data_content} dc ' . + "WHERE (d.course = ? or d.course = '".SITEID."')" . 'AND d.id = df.dataid ' . 'AND df.id = dc.fieldid ' . 'AND d.id = dr.dataid ' . @@ -41,7 +41,7 @@ "AND df.type = 'text' " . 'AND df.param1 = 1'; - if (!$datacontents = get_records_sql($sql)) { + if (!$datacontents = $DB->get_records_sql($sql, array($courseid))) { return $text; } diff --git a/mod/data/import.php b/mod/data/import.php index 63f24a699b4..26a11f959c9 100755 --- a/mod/data/import.php +++ b/mod/data/import.php @@ -38,18 +38,18 @@ if (! $cm = get_coursemodule_from_id('data', $id)) { print_error('invalidcoursemodule'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { print_error('coursemisconf'); } - if (! $data = get_record('data', 'id', $cm->instance)) { + if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) { print_error('invalidcoursemodule'); } } else { - if (! $data = get_record('data', 'id', $d)) { + if (! $data = $DB->get_record('data', array('id'=>$d))) { print_error('invalidid', 'data'); } - if (! $course = get_record('course', 'id', $data->course)) { + if (! $course = $DB->get_record('course', array('id'=>$data->course))) { print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { @@ -108,14 +108,14 @@ foreach ($records as $record) { if ($recordid = data_add_record($data, 0)) { // add instance to data_record - $fields = get_records('data_fields', 'dataid', $data->id, '', 'name, id, type'); + $fields = $DB->get_records('data_fields', array('dataid'=>$data->id), '', 'name, id, type'); // Insert new data_content fields with NULL contents: foreach ($fields as $field) { $content = new object(); $content->recordid = $recordid; $content->fieldid = $field->id; - if (! insert_record('data_content', $content)) { + if (! $DB->insert_record('data_content', $content)) { print_error('cannotinsertrecord', '', '', $recordid); } } @@ -137,7 +137,6 @@ $replacements[] = '>'; $value = preg_replace($patterns, $replacements, $value); } - $value = addslashes($value); // for now, only for "latlong" and "url" fields, but that should better be looked up from // $CFG->dirroot . '/mod/data/field/' . $field->type . '/field.class.php' // once there is stored how many contents the field can have. @@ -148,9 +147,9 @@ } else { $content->content = $value; } - $oldcontent = get_record('data_content', 'fieldid', $field->id, 'recordid', $recordid); + $oldcontent = $DB->get_record('data_content', array('fieldid'=>$field->id, 'recordid'=>$recordid)); $content->id = $oldcontent->id; - if (! update_record('data_content', $content)) { + if (! $DB->update_record('data_content', $content)) { print_error('cannotupdaterecord', '', '', $recordid); } } diff --git a/mod/data/index.php b/mod/data/index.php index 13a7666a794..e52c54e22d9 100755 --- a/mod/data/index.php +++ b/mod/data/index.php @@ -100,13 +100,10 @@ // TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page - $numrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix. - 'data_records r WHERE r.dataid ='.$data->id); + $numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id)); if ($data->approval == 1) { - $numunapprovedrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix. - 'data_records r WHERE r.dataid ='.$data->id. - ' AND r.approved <> 1'); + $numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id)); } else { $numunapprovedrecords = '-'; } diff --git a/mod/data/js.php b/mod/data/js.php index 6972acf6412..0151721e860 100644 --- a/mod/data/js.php +++ b/mod/data/js.php @@ -29,7 +29,7 @@ $d = optional_param('d', 0, PARAM_INT); // database id - if ($data = get_record('data', 'id', $d)) { + if ($data = $DB->get_record('data', array('id'=>$d))) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT'); header('Cache-control: max_age = '. $lifetime); diff --git a/mod/data/lib.php b/mod/data/lib.php index fd812ba6f5b..67ff6d09e33 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -177,7 +177,7 @@ class data_field_base { // Base class for Database Field Types (see field/*/ // Print the relevant form element to define the attributes for this field // viewable by teachers only. function display_edit_field() { - global $CFG; + global $CFG, $DB; if (empty($this->field)) { // No field has been defined yet, try and make one $this->define_default_field();