]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15106 towards data mod dml conversion
authorskodak <skodak>
Thu, 5 Jun 2008 19:26:57 +0000 (19:26 +0000)
committerskodak <skodak>
Thu, 5 Jun 2008 19:26:57 +0000 (19:26 +0000)
26 files changed:
mod/data/backuplib.php
mod/data/comment.php
mod/data/css.php
mod/data/edit.php
mod/data/export.php
mod/data/field.php
mod/data/field/checkbox/field.class.php
mod/data/field/date/field.class.php
mod/data/field/file/field.class.php
mod/data/field/file/mod.html
mod/data/field/latlong/field.class.php
mod/data/field/latlong/kml.php
mod/data/field/latlong/mod.html
mod/data/field/menu/field.class.php
mod/data/field/multimenu/field.class.php
mod/data/field/number/field.class.php
mod/data/field/picture/field.class.php
mod/data/field/picture/mod.html
mod/data/field/radiobutton/field.class.php
mod/data/field/textarea/field.class.php
mod/data/field/url/field.class.php
mod/data/filter.php
mod/data/import.php
mod/data/index.php
mod/data/js.php
mod/data/lib.php

index c8a1e1e108f5908c9b2e02785bdc32d216f2467d..3065e8bf89ab1e12f3fb5f2e7bf5a798fed015c4 100644 (file)
     //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,"/");
index bed2afe83ff4bc5666e740d637b9a81ad1292bd6..b486812535b952881385f52a0f08216699a2baf9 100755 (executable)
     $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.'&amp;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.'&amp;page='.$page);
             } else {
                 print_error('cannotsavecomment');
 
         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.'&amp;page='.$page, get_string('commentdeleted', 'data'));
 
             } else {    //print confirm delete form
index 00469ed2ed45092576c5fc01bb63d68807846f8f..393d9eacbeb3c1e4f3ddc5067b64f63137b87cfb 100755 (executable)
@@ -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);
index b699caace0d76ce70e842d92d8d41eb7f1abfed5..25a4f3f512e42f92bfafb6baf6d2391f4ffc2cf8 100755 (executable)
         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
         }
     }
 
 /// 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)) {
 
             $record->groupid = $currentgroup;
             $record->timemodified = time();
-            update_record('data_records',$record);
+            $DB->update_record('data_records', $record);
 
             /// Update all content
             $field = NULL;
             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.
      * 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){
 /// 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) {
index 81283e10a1ef9829ccc8f42d838dd6d6d97bafc8..a3e8fdba1b119217dd1035d87dc39cab68242118 100644 (file)
@@ -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])) {
index c041ce4e3229af3333217e70245856b70e5e7eb4..2a62ffacf5142c82b750490bbcfed73553171f33 100755 (executable)
         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&amp;mode=display&amp;fid=$fid", $fid, $cm->id);
 
 
         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);
 
                             $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');
                             }
                         }
                 $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');
         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
 
             $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);
         echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
         echo '<label for="defaultsort">'.get_string('defaultsortfield','data').'</label>';
         echo '<select id="defaultsort" name="defaultsort">';
-        if ($fields = get_records('data_fields','dataid',$data->id)) {
+        if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id))) {
             echo '<optgroup label="'.get_string('fields', 'data').'">';
             foreach ($fields as $field) {
                 if ($data->defaultsort == $field->id) {
index 3cf433cab665cc59d145ce1c559bf757e6fc71ca..a4e88626c12535ff1319ac1e241ba377449ef469 100755 (executable)
@@ -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);
index 2bf672251c3ca716e6d8b59493026f11259fba2b..fb32f20d733dccb8eecf392b047bf78a6d8dd2fe 100755 (executable)
@@ -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);
         }
     }
index b0e2aa809d00d3e0e6a96c654bd0e74ffaf456b9..702012be61047ca1b9cd3452c1a7f8113bf46261 100755 (executable)
@@ -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:
index 9fd3c6030754d7e4fc739f7de8e45b6332df0df9..29227cd4401df06b72f34ea48be2cc516cd24012 100755 (executable)
@@ -12,7 +12,7 @@
             <?php echo get_string('maxsize', 'data'); ?></label></td>
         <td class="c1">
             <?php
-                $course->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');
             ?>
index 99d9f7fab869e762b2d3b676f1ebb3dbef2d43f3..f12dcc57bb6f1702a2587ca9c4bb7c3962aae123 100755 (executable)
@@ -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);
         }
     }
 
index 45c449bdee391ea39d8d17dfca8753c3b4398553..690d8dc652f803f6c83022fa5b190fbd4a36e901 100644 (file)
@@ -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 '<Document>';
 
@@ -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;
     }
index d924d1104d3fb878a8dec4f8adbe7b669e0977e1..7cf519bf39e3e69d48023e699f038162eba7d650 100755 (executable)
@@ -29,7 +29,7 @@
             <option value="-2"<?php if($this->field->param2==-2) echo ' selected="selected"' ?>><?php echo get_string('latitude', 'data').'/'.get_string('longitude', 'data') ?></option>
             <?php
                 // Fetch all "suitable" other fields that exist for this database
-                $textfields = get_records_select('data_fields', 'dataid='.$this->data->id.' AND type="text"');
+                $textfields = $DB->get_records_select('data_fields', array('dataid'=>$this->data->id, 'type'=>'text'));
                 echo '<optgroup label="'.get_string('latlongotherfields', 'data').':">';
                 if(sizeof($textfields)>0) {
                     foreach($textfields as $textfield) {
index 16aba4d0e30a935dd3c34551ae39e04e9c0d3103..8ebe5e60f4b9959b3b98d2d1878c697162f947ac 100755 (executable)
@@ -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 === '') {
index 038a494faee5d92d1559f587c267262629f1e34f..e62d28601a4ff217bdeb3de222211ede82a70061 100755 (executable)
@@ -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 .= '<option value="' . s($option) . '"';
 
-            if (in_array(addslashes($option), $content)) {
+            if (in_array($option, $content)) {
                 // Selected by user.
                 $str .= ' selected = "selected"';
             }
@@ -160,16 +161,18 @@ class data_field_multimenu 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_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;
             }
index 371d725ca5af922b78343605889054316f729bfb..63a2cf387fdc56faa6f34e4c6083b1ce85d49a54 100755 (executable)
@@ -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;
             }
index a9f6e9a51ebd8c48436beb40e63f97a86ae8a7a5..b10940ce6d0cb44eba8365fb11a63e867e30c856 100755 (executable)
@@ -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
     }
index 66975535a2768a2d047d50c93d611bc868a1e7da..a8d3a65e55d31ca4309035cee8d4b89bf530fa82 100755 (executable)
@@ -44,7 +44,7 @@
             <?php echo get_string('maxsize', 'data'); ?></label></td>
         <td class="c1">
             <?php
-                $course->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');
             ?>
index e023ef391b5911fd9596221ce8b68a14eb33d36a..60bc325bcb278d3ebd44a46b84e7406ed17fd03c 100755 (executable)
@@ -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 = '';
         }
index 10032ea19aa2897b219b25ebd556f49309056015..8a3d0c6782d04d16f8bdb77579784dea6bd361aa 100755 (executable)
@@ -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);
         }
     }
 }
index 6754af116f151e90f2efdfc39fd3b84100a7578b..78ac6877058e667986b24cbf8d563a033e710bcd 100755 (executable)
@@ -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);
         }
     }
 
index c019304127688a0a74f8d35564361b83b99b50e1..90025272c43cdac18c5f5c5a7cfd8ed6ed71a4c5 100644 (file)
@@ -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;
                    '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;
             }
 
index 63f24a699b459910e3d0827b1a34990089100deb..26a11f959c9154a7ab7ad7df62d6259f9e6e75af 100755 (executable)
         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)) {
 
             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);
                         }
                     }
                             $replacements[] = '&gt;';
                             $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. 
                         } 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);
                         }
                     }
index 13a7666a794501e04964254d1d2bc914db71b5c7..e52c54e22d9a889c218a8b2c699451ddf063cc2d 100755 (executable)
 
         // 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 = '-';
         }
index 6972acf6412a76503a0ac4d69f950d2e3534ebab..0151721e860a1afeafc3adba4dcf95342941fa3b 100644 (file)
@@ -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);
index fd812ba6f5ba217a24988ea37d6a23741fe43c34..67ff6d09e333f87e457553dafb8d70ff61ffe3ff 100755 (executable)
@@ -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();