]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15109 glossary dml conversion
authorskodak <skodak>
Sun, 8 Jun 2008 10:43:39 +0000 (10:43 +0000)
committerskodak <skodak>
Sun, 8 Jun 2008 10:43:39 +0000 (10:43 +0000)
27 files changed:
mod/glossary/approve.php
mod/glossary/backuplib.php
mod/glossary/comment.php
mod/glossary/comments.php
mod/glossary/deleteentry.php
mod/glossary/edit.php
mod/glossary/editcategories.php
mod/glossary/export.php
mod/glossary/exportentry.php
mod/glossary/exportfile.php
mod/glossary/filter.php
mod/glossary/formats.php
mod/glossary/formats/TEMPLATE/TEMPLATE_format.php
mod/glossary/formats/encyclopedia/encyclopedia_format.php
mod/glossary/formats/fullwithauthor/fullwithauthor_format.php
mod/glossary/import.php
mod/glossary/index.php
mod/glossary/lib.php
mod/glossary/mod_form.php
mod/glossary/print.php
mod/glossary/rate.php
mod/glossary/report.php
mod/glossary/rsslib.php
mod/glossary/settings.php
mod/glossary/showentry.php
mod/glossary/sql.php
mod/glossary/view.php

index 3c28926abcae8e1ad3d2ea5b1bdf7f7c5e20d206..cb3892552b9418f077c0b7ce115639aae32f2f96 100644 (file)
         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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidid', 'glossary');
     }
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     require_capability('mod/glossary:approve', $context);
 
+    $newentry = new object();
     $newentry->id = $eid;
     $newentry->approved     = 1;
     $newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
 
-    if (! update_record("glossary_entries", $newentry)) {
+    if (! $DB->update_record("glossary_entries", $newentry)) {
         print_error('cantupdateglossary', 'glossary');
     } else {
         add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&amp;eid=$eid", "$eid",$cm->id);
index 2f0c0b3f9fda4a714fe132d1f4b6b4362b8e2fd6..961f21f7d462fbb4a7800f80ce7bcf0aad7637b1 100644 (file)
     //----------------------------------------------------------------------------------
 
     function glossary_backup_mods($bf,$preferences) {
-        
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
         //Iterate over glossary table
-        $glossaries = get_records ("glossary","course",$preferences->backup_course,"mainglossary");
+        $glossaries = $DB->get_records ("glossary", array("course"=>$preferences->backup_course), "mainglossary");
         if ($glossaries) {
             foreach ($glossaries as $glossary) {
                 if (backup_mod_selected($preferences,'glossary',$glossary->id)) {
     }
 
     function glossary_backup_one_mod($bf,$preferences,$glossary) {
-
-        global $CFG;
+        global $CFG, $DB;
     
         if (is_numeric($glossary)) {
-            $glossary = get_record('glossary','id',$glossary);
+            $glossary = $DB->get_record('glossary', array('id'=>$glossary));
         }
     
         $status = true;
 
     //Backup glossary_categories and entries_categories contents (executed from glossary_backup_mods)
     function backup_glossary_categories ($bf,$preferences,$glossary, $userinfo) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
-        $glossary_categories = get_records("glossary_categories","glossaryid",$glossary,"id");
+        $glossary_categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary),"id");
         //If there is categories
         if ($glossary_categories) {
             $status =fwrite ($bf,start_tag("CATEGORIES",4,true));
 
     //Backup entries_categories contents (executed from backup_glossary_categories)
     function backup_glossary_entries_categories ($bf,$preferences,$categoryid) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
-        $entries = get_records("glossary_entries_categories","categoryid",$categoryid);
+        $entries = $DB->get_records("glossary_entries_categories", array("categoryid"=>$categoryid));
         if ($entries) {
             $status =fwrite ($bf,start_tag("ENTRIES",6,true));
             foreach ($entries as $entry) {
 
     //Backup glossary_entries contents (executed from glossary_backup_mods)
     function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
-        $glossary_entries = get_records("glossary_entries","glossaryid",$glossary,"id");
+        $glossary_entries = $DB->get_records("glossary_entries", array("glossaryid"=>$glossary),"id");
         //If there is entries
         if ($glossary_entries) {            
             $dumped_entries = 0;
 
     //Backup glossary_comments contents (executed from backup_glossary_entries)
     function backup_glossary_comments ($bf,$preferences,$entryid) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
-        $comments = get_records("glossary_comments","entryid",$entryid);
+        $comments = $DB->get_records("glossary_comments", array("entryid"=>$entryid));
         if ($comments) {
             $status =fwrite ($bf,start_tag("COMMENTS",6,true));
             foreach ($comments as $comment) {
 
    //Backup glossary_ratings contents (executed from backup_glossary_entries)
     function backup_glossary_ratings ($bf,$preferences,$entryid) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
-        $ratings = get_records("glossary_ratings","entryid",$entryid);
+        $ratings = $DB->get_records("glossary_ratings", array("entryid"=>$entryid));
         if ($ratings) {
             $status =fwrite ($bf,start_tag("RATINGS",6,true));
             foreach ($ratings as $rating) {
    
     //Backup glossary_alias contents (executed from backup_glossary_entries)
     function backup_glossary_aliases ($bf,$preferences,$entryid) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
-        $aliases = get_records("glossary_alias","entryid",$entryid);
+        $aliases = $DB->get_records("glossary_alias", array("entryid"=>$entryid));
         if ($aliases) {
             $status =fwrite ($bf,start_tag("ALIASES",6,true));
             foreach ($aliases as $alias) {
     //Backup glossary files because we've selected to backup user info
     //or current entry is a teacher entry
     function backup_glossary_files($bf,$preferences,$glossary,$entry) {
-
         global $CFG;
 
         $status = true;
 
     //Returns an array of glossaries id
     function glossary_ids ($course) {
+        global $DB;
 
-        global $CFG;
-
-        return get_records_sql ("SELECT a.id, a.course
-                                 FROM {$CFG->prefix}glossary a
-                                 WHERE a.course = '$course'");
+        return $DB->get_records_sql ("SELECT a.id, a.course
+                                        FROM {glossary} a
+                                       WHERE a.course = ?", array($course));
     }
    
     //Returns an array of glossary_answers id
     function glossary_entries_ids_by_course ($course) {
+        global $DB;
 
-        global $CFG;
-
-        return get_records_sql ("SELECT s.id , s.glossaryid
-                                 FROM {$CFG->prefix}glossary_entries s,
-                                      {$CFG->prefix}glossary a
-                                 WHERE a.course = '$course' AND
-                                       s.glossaryid = a.id");
+        return $DB->get_records_sql ("SELECT s.id , s.glossaryid
+                                        FROM {glossary_entries} s, {glossary} a
+                                       WHERE a.course = ? AND s.glossaryid = a.id", array($course));
     }
 
     //Returns an array of glossary_answers id
     function glossary_entries_ids_by_instance ($instanceid) {
+        global $DB;
 
-        global $CFG;
-
-        return get_records_sql ("SELECT s.id , s.glossaryid
-                                 FROM {$CFG->prefix}glossary_entries s
-                                 WHERE s.glossaryid = $instanceid");
+        return $DB->get_records_sql ("SELECT s.id , s.glossaryid
+                                        FROM {glossary_entries} s
+                                       WHERE s.glossaryid = ?", array($instanceid));
     }
 ?>
index 6c4adbfb43427254366d9f633b36fa668ae9b740..7ad4ab35090757ff395c557a897ac50cbd882714 100644 (file)
@@ -28,20 +28,20 @@ switch ($action) {
  * Add new comment
  */
 function glossary_comment_add() {
-    global $USER;
+    global $USER, $DB;
 
     $eid = optional_param('eid', 0, PARAM_INT); // Entry ID
 
-    if (!$entry = get_record('glossary_entries', 'id', $eid)) {
+    if (!$entry = $DB->get_record('glossary_entries', array('id'=>$eid))) {
         print_error('invalidentry');
     }
-    if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) {
+    if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
         print_error('invalidid', 'glossary');
     }
     if (!$cm = get_coursemodule_from_instance('glossary', $glossary->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');
     }
 
@@ -59,7 +59,7 @@ function glossary_comment_add() {
         redirect("comments.php?id=$cm->id&amp;eid=$entry->id");
     }
 
-    if ($data = $mform->get_data()) {
+    if ($data = $mform->get_data(false)) {
         trusttext_after_edit($data->entrycomment, $context);
 
         $newcomment = new object();
@@ -69,7 +69,7 @@ function glossary_comment_add() {
         $newcomment->timemodified = time();
         $newcomment->userid       = $USER->id;
 
-        if (!$newcomment->id = insert_record('glossary_comments', $newcomment)) {
+        if (!$newcomment->id = $DB->insert_record('glossary_comments', $newcomment)) {
             print_error('cannotinsertcomment');
         } else {
             add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$newcomment->id", $cm->id);
@@ -88,24 +88,24 @@ function glossary_comment_add() {
  * Deleting existing comments
  */
 function glossary_comment_delete() {
-    global $USER;
+    global $USER, $DB;
 
     $cid     = optional_param('cid', 0, PARAM_INT);      // Comment ID
     $confirm = optional_param('confirm', 0, PARAM_BOOL); // delete confirmation
 
-    if (!$comment = get_record('glossary_comments', 'id', $cid)) {
+    if (!$comment = $DB->get_record('glossary_comments', array('id'=>$cid))) {
         print_error('invalidcomment');
     }
-    if (!$entry = get_record('glossary_entries', 'id', $comment->entryid)) {
+    if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
         print_error('invalidentry');
     }
-    if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) {
+    if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
         print_error('invalidid', 'glossary');
     }
     if (!$cm = get_coursemodule_from_instance('glossary', $glossary->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');
     }
 
@@ -119,7 +119,7 @@ function glossary_comment_delete() {
     }
 
     if (data_submitted() and $confirm) {
-        delete_records('glossary_comments','id', $cid);
+        $DB->delete_records('glossary_comments', array('id'=>$cid));
         add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$comment->id",$cm->id);
         redirect("comments.php?id=$cm->id&amp;eid=$entry->id");
 
@@ -142,23 +142,23 @@ function glossary_comment_delete() {
  * Edit existing comments
  */
 function glossary_comment_edit() {
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
 
     $cid = optional_param('cid', 0, PARAM_INT); // Comment ID
 
-    if (!$comment = get_record('glossary_comments', 'id', $cid)) {
+    if (!$comment = $DB->get_record('glossary_comments', array('id'=>$cid))) {
         print_error('invalidcomment');
     }
-    if (!$entry = get_record('glossary_entries', 'id', $comment->entryid)) {
+    if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
         print_error('invalidentry');
     }
-    if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) {
+    if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
         print_error('invalidid', 'glossary');
     }
     if (!$cm = get_coursemodule_from_instance('glossary', $glossary->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');
     }
 
@@ -179,7 +179,7 @@ function glossary_comment_edit() {
     trusttext_prepare_edit($comment->entrycomment, $comment->format, can_use_html_editor(), $context);
     $mform->set_data(array('cid'=>$cid, 'action'=>'edit', 'entrycomment'=>$comment->entrycomment, 'format'=>$comment->format));
 
-    if ($data = $mform->get_data()) {
+    if ($data = $mform->get_data(false)) {
         trusttext_after_edit($data->entrycomment, $context);
 
         $updatedcomment = new object();
@@ -188,7 +188,7 @@ function glossary_comment_edit() {
         $updatedcomment->format       = $data->format;
         $updatedcomment->timemodified = time();
 
-        if (!update_record('glossary_comments', $updatedcomment)) {
+        if (!$DB->update_record('glossary_comments', $updatedcomment)) {
             print_error('cannotupdatecomment');
         } else {
             add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$updatedcomment->id",$cm->id);
index 897d91bfae0a77a4708f02bef2d8463b23dd990e..09c769b844ffb771ef2ed10f71bc1c9fd5be5944 100644 (file)
@@ -7,21 +7,19 @@
     $id  = required_param('id', PARAM_INT);           // Course Module ID
     $eid = required_param('eid', PARAM_INT);          // Entry ID
 
-    global $USER, $CFG;
-
     if (! $cm = get_coursemodule_from_id('glossary', $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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidcousemodule');
     }
 
-    if (! $entry = get_record("glossary_entries", "id", $eid)) {
+    if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) {
         print_error('invalidentry');
     }
 
@@ -61,7 +59,7 @@
         print_heading("<a href=\"comment.php?action=add&amp;eid=$entry->id\">$straddcomment <img title=\"$straddcomment\" src=\"comment.gif\" class=\"iconsmall\" alt=\"$straddcomment\" /></a>");
     }
 
-    if ($comments = get_records("glossary_comments","entryid",$entry->id,"timemodified ASC")) {
+    if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) {
         foreach ($comments as $comment) {
             glossary_print_comment($course, $cm, $glossary, $entry, $comment);
             echo '<br />';
index e59663b56da3893e56c9530ff4df984afd2f63dd..035ead082e0140b0759203049c66f1e5e4c7dfac 100644 (file)
         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 (! $entry = get_record("glossary_entries","id", $entry)) {
+    if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) {
         print_error('invalidentry');
     }
 
@@ -32,7 +32,7 @@
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     $manageentries = has_capability('mod/glossary:manageentries', $context); 
     
-    if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidid', 'glossary');
     }
 
@@ -62,7 +62,7 @@
             $dbentry->id = $entry->id;
             $dbentry->glossaryid = $entry->sourceglossaryid;
             $dbentry->sourceglossaryid = 0;
-            if (! update_record('glossary_entries', $dbentry)) {
+            if (! $DB->update_record('glossary_entries', $dbentry)) {
                 print_error('cantupdateglossary', 'glossary');
             }
 
             if ( $entry->attachment ) {
                 glossary_delete_old_attachments($entry);
             }
-            delete_records("glossary_comments", "entryid",$entry->id);
-            delete_records("glossary_alias", "entryid", $entry->id);
-            delete_records("glossary_ratings", "entryid", $entry->id);
-            delete_records("glossary_entries","id", $entry->id);
+            $DB->delete_records("glossary_comments", array("entryid"=>$entry->id));
+            $DB->delete_records("glossary_alias", array("entryid"=>$entry->id));
+            $DB->delete_records("glossary_ratings", array("entryid"=>$entry->id));
+            $DB->delete_records("glossary_entries", array("id"=>$entry->id));
         }
 
         add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook", $entry->id,$cm->id);
index 3575db4c10c431355e39655f58ec6973ffa67714..a7f6938b8c95ec7822eb90b765acbc10d9ae5f5e 100644 (file)
@@ -19,7 +19,7 @@ if (! $cm = get_coursemodule_from_id('glossary', $id)) {
 
 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
-if (! $course = get_record("course", "id", $cm->course)) {
+if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
     print_error('coursemisconf');
 }
 
@@ -29,13 +29,13 @@ if ( isguest() ) {
     print_error('guestnoedit', 'glossary', $_SERVER["HTTP_REFERER"]);
 }
 
-if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
     print_error('invalidid', 'glossary');
 }
 
 
 if ($e) { // if entry is specified
-    if (!$entry  = get_record("glossary_entries", "id", $e)) {
+    if (!$entry  = $DB->get_record("glossary_entries", array("id"=>$e))) {
         print_error('invalidentry');
     }
     $ineditperiod = ((time() - $entry->timecreated <  $CFG->maxeditingtime) || $glossary->editalways);
@@ -47,7 +47,7 @@ if ($e) { // if entry is specified
     require_capability('mod/glossary:write', $context);
 }
 
-$mform =& new mod_glossary_entry_form(null, compact('cm', 'glossary', 'hook', 'mode', 'e', 'context'));
+$mform = new mod_glossary_entry_form(null, compact('cm', 'glossary', 'hook', 'mode', 'e', 'context'));
 if ($mform->is_cancelled()){
     if ($e){
         redirect("view.php?id=$cm->id&amp;mode=entry&amp;hook=$e");
@@ -55,7 +55,7 @@ if ($mform->is_cancelled()){
         redirect("view.php?id=$cm->id");
     }
 
-} elseif ($fromform = $mform->get_data()) {
+} elseif ($fromform = $mform->get_data(false)) {
     trusttext_after_edit($fromform->definition, $context);
 
     if ( !isset($fromform->usedynalink) ) {
@@ -93,7 +93,7 @@ if ($mform->is_cancelled()){
             $todb->attachment = $newfilename;
         }
 
-        if (update_record('glossary_entries', $todb)) {
+        if ($DB->update_record('glossary_entries', $todb)) {
             add_to_log($course->id, "glossary", "update entry",
                        "view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id",
                        $todb->id, $cm->id);
@@ -108,11 +108,11 @@ if ($mform->is_cancelled()){
         $todb->teacherentry = has_capability('mod/glossary:manageentries', $context);
 
 
-        if ($todb->id = insert_record("glossary_entries", $todb)) {
+        if ($todb->id = $DB->insert_record("glossary_entries", $todb)) {
             $e = $todb->id;
             $dir = glossary_file_area_name($todb);
             if ($mform->save_files($dir) and $newfilename = $mform->get_new_filename()) {
-                set_field("glossary_entries", "attachment", $newfilename, "id", $todb->id);
+                $DB->set_field("glossary_entries", "attachment", $newfilename, array("id"=>$todb->id));
             }
             add_to_log($course->id, "glossary", "add entry",
                        "view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id", $todb->id,$cm->id);
@@ -122,15 +122,15 @@ if ($mform->is_cancelled()){
 
     }
 
-    delete_records("glossary_entries_categories", "entryid", $e);
-    delete_records("glossary_alias", "entryid", $e);
+    $DB->delete_records("glossary_entries_categories", array("entryid"=>$e));
+    $DB->delete_records("glossary_alias", array("entryid"=>$e));
 
     if (empty($fromform->notcategorised) && isset($fromform->categories)) {
         $newcategory->entryid = $e;
         foreach ($fromform->categories as $category) {
             if ( $category > 0 ) {
                 $newcategory->categoryid = $category;
-                insert_record("glossary_entries_categories", $newcategory, false);
+                $DB->insert_record("glossary_entries_categories", $newcategory, false);
             } else {
                 break;
             }
@@ -141,10 +141,10 @@ if ($mform->is_cancelled()){
             foreach ($aliases as $alias) {
                 $alias = trim($alias);
                 if ($alias) {
-                    unset($newalias);
+                    $newalias = new object();
                     $newalias->entryid = $e;
                     $newalias->alias = $alias;
-                    insert_record("glossary_alias", $newalias, false);
+                    $DB->insert_record("glossary_alias", $newalias, false);
                 }
             }
         }
@@ -153,7 +153,7 @@ if ($mform->is_cancelled()){
 
 } else {
     if ($e) {
-        $fromdb = get_record("glossary_entries", "id", $e);
+        $fromdb = $DB->get_record("glossary_entries", array("id"=>$e));
 
         $toform = new object();
 
index 0413b2d3b0687a025290d97f9bed760422fdc989..422638f6c9295a800c211d480aac671f22c14841 100644 (file)
         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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidcoursemodule');
     }
 
     if ($hook > 0) {
-        if ($category = get_record("glossary_categories","id",$hook)) {
+        if ($category = $DB->get_record("glossary_categories", array("id"=>$hook))) {
             //Check it belongs to the same glossary
             if ($category->glossaryid != $glossary->id) {
                 print_error('invalidid', 'glossary');
         if ( $action == "edit" ) {
             if ( $confirm ) {
                 $action = "";
+                $cat = new object();
                 $cat->id = $hook;
                 $cat->name = $name;
                 $cat->usedynalink = $usedynalink;
 
-                if ( !update_record("glossary_categories", $cat) ) {
+                if ( !$DB->update_record("glossary_categories", $cat) ) {
                     print_error('cannotupdatecategory');
                     redirect("editcategories.php?id=$cm->id");
                 } else {
@@ -85,8 +86,8 @@
 
         } elseif ( $action == "delete" ) {
             if ( $confirm ) {
-                delete_records("glossary_entries_categories","categoryid", $hook);
-                delete_records("glossary_categories","id", $hook);
+                $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
+                $DB->delete_records("glossary_categories", array("id"=>$hook));
 
                 print_simple_box_start("center","40%", "#FFBBBB");
                 echo "<div style=\"text-align:center\">" . get_string("categorydeleted","glossary") ."</div>";
                 print_simple_box_start("center","40%", "#FFBBBB");
                 echo "<div class=\"boxaligncenter\"><b>".format_text($category->name, FORMAT_PLAIN)."</b><br/>";
 
-                $num_entries = count_records("glossary_entries_categories","categoryid",$category->id);
+                $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
                 if ( $num_entries ) {
                     print_string("deletingnoneemptycategory","glossary");
                 }
     } elseif ( $action == "add" ) {
         if ( $confirm ) {
             $ILIKE = sql_ilike();
-            $dupcategory = get_records_sql("SELECT * FROM {$CFG->prefix}glossary_categories WHERE name $ILIKE '$name' AND glossaryid=$glossary->id");
+            $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE name $ILIKE ? AND glossaryid=?", array($name, $glossary->id));
             if ( $dupcategory ) {
                 echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary");
 
 
             } else {
                 $action = "";
+                $cat = new object();
                 $cat->name = $name;
                 $cat->usedynalink = $usedynalink;
                 $cat->glossaryid = $glossary->id;
 
-                if ( ! $cat->id = insert_record("glossary_categories", $cat) ) {
+                if ( ! $cat->id = $DB->insert_record("glossary_categories", $cat) ) {
                     print_error('cannotinsertcategory');
 
                     redirect("editcategories.php?id=$cm->id");
         
 
 <?php
-    $categories = get_records("glossary_categories","glossaryid",$glossary->id,"name ASC");
+    $categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id), "name ASC");
 
     if ( $categories ) {
         echo '<table width="100%">';
         foreach ($categories as $category) {
-            $num_entries = count_records("glossary_entries_categories","categoryid",$category->id);
+            $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
 ?>
 
              <tr>
index 2fb96b1fb3ad878b180f791babec355ebd052ae2..a86c57f79874e3bd3a6dbc08e38be1ff01ef4e0a 100644 (file)
         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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidid', 'glossary');
     }
 
index 8df0522ac12ec4f3d37339d907e8149d32abb83c..df2ea235e19ec8a28b53ffd34790a5b266b07f15 100644 (file)
@@ -17,7 +17,7 @@
     if ( ! $cm ) {
         $PermissionGranted = 0;
     } else {
-        $mainglossary = get_record('glossary','course',$cm->course, 'mainglossary',1);
+        $mainglossary = $DB->get_record('glossary', array('course'=>$cm->course), 'mainglossary',1);
         if ( ! $mainglossary ) {
             $PermissionGranted = 0;
         }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     require_capability('mod/glossary:export', $context);
 
-    if (! $course = get_record('course', 'id', $cm->course)) {
+    if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
         print_error('coursemisconf');
     }
 
-    if (! $glossary = get_record('glossary', 'id', $cm->instance)) {
+    if (! $glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
         print_error('invalidid', 'glossary');
     }
 
@@ -42,7 +42,7 @@
     print_header_simple(format_string($glossary->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
 
     if ( $PermissionGranted ) {
-        $entry = get_record('glossary_entries', 'id', $entry);
+        $entry = $DB->get_record('glossary_entries', array('id'=>$entry));
 
         if ( !$confirm ) {
             echo '<div class="boxaligncenter">';
@@ -53,7 +53,7 @@
             echo '</div>';
         } else {
             if ( ! $mainglossary->allowduplicatedentries ) {
-                $dupentry = get_record('glossary_entries','glossaryid', $mainglossary->id, 'lower(concept)',moodle_strtolower(addslashes($entry->concept)));
+                $dupentry = $DB->get_record('glossary_entries', array('glossaryid'=>$mainglossary->id, 'lower(concept)'=>moodle_strtolower($entry->concept)));
                 if ( $dupentry ) {
                     $PermissionGranted = 0;
                 }
@@ -65,7 +65,7 @@
                 $dbentry->glossaryid       = $mainglossary->id;
                 $dbentry->sourceglossaryid = $glossary->id;
                 
-                if (! update_record('glossary_entries', $dbentry)) {
+                if (! $DB->update_record('glossary_entries', $dbentry)) {
                     print_error('cantexportentry', 'glossary');
                 } else {
                     print_simple_box_start('center', '60%');
index 69bc8369d1b0413ef4ce4c1c179f580d5c8c4231..12f4c301bc6dee75bbd066f430b85057ca49dac2 100644 (file)
         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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidid', 'glossary');
     }
 
index 31ddf06e787b7ff4fa29f3cc2deb98f3d22be493..d6f173827693e092cb7dd45f615078d9688e5a17 100644 (file)
@@ -42,30 +42,26 @@ function glossary_filter($courseid, $text) {
         }
 
     /// Make a list of glossary IDs for searching
-        $glossarylist = '';
-        foreach ($glossaries as $glossaryid => $glossaryname) {
-            $glossarylist .= $glossaryid.',';
-        }
-        $glossarylist = substr($glossarylist,0,-1);
+        $glossarylist = implode(',', array_keys($glossaries));
    
 
     /// Pull out all the raw data from the database for entries, categories and aliases
-        $entries = get_records_select('glossary_entries',
-                                      'glossaryid IN ('.$glossarylist.') AND usedynalink != 0 AND approved != 0 ', '',
-                                      'id,glossaryid, concept, casesensitive, 0 AS category, fullmatch');
-
-        $categories = get_records_select('glossary_categories',
-                                         'glossaryid IN ('.$glossarylist.') AND usedynalink != 0', '',
-                                         'id,glossaryid,name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch');
-
-        $aliases = get_records_sql('SELECT ga.id, ge.glossaryid, ga.alias as concept, ge.concept as originalconcept,
-                                           casesensitive, 0 AS category, fullmatch
-                                      FROM '.$CFG->prefix.'glossary_alias ga,
-                                           '.$CFG->prefix.'glossary_entries ge
-                                     WHERE ga.entryid = ge.id
-                                       AND ge.glossaryid IN ('.$glossarylist.')
-                                       AND ge.usedynalink != 0
-                                       AND ge.approved != 0');
+        $entries = $DB->get_records_select('glossary_entries',
+                                           'glossaryid IN ('.$glossarylist.') AND usedynalink != 0 AND approved != 0 ', '',
+                                           'id,glossaryid, concept, casesensitive, 0 AS category, fullmatch');
+
+        $categories = $DB->get_records_select('glossary_categories',
+                                              'glossaryid IN ('.$glossarylist.') AND usedynalink != 0', '',
+                                              'id,glossaryid,name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch');
+
+        $aliases = $DB->get_records_sql('SELECT ga.id, ge.glossaryid, ga.alias as concept, ge.concept as originalconcept,
+                                                casesensitive, 0 AS category, fullmatch
+                                           FROM {glossary_alias} ga,
+                                                {glossary_entries} ge
+                                          WHERE ga.entryid = ge.id
+                                                AND ge.glossaryid IN ('.$glossarylist.')
+                                                AND ge.usedynalink != 0
+                                                AND ge.approved != 0');
 
 
     /// Combine them into one big list
index e8e22839bb32bd82577165e5035fb2d585a94124..e59c2bff6773bc9a5ea8835a444d81be8c9c8a11 100644 (file)
@@ -10,7 +10,7 @@
 
     admin_externalpage_setup('managemodules'); // this is hacky, tehre should be a special hidden page for it
 
-    if ( !$displayformat = get_record("glossary_formats","id",$id) ) {
+    if ( !$displayformat = $DB->get_record("glossary_formats", array("id"=>$id))) {
         error ("Invalid Glossary Format");
     }
 
@@ -22,7 +22,7 @@
             } else {
                 $displayformat->visible = 1;
             }
-            update_record("glossary_formats",$displayformat);
+            $DB->update_record("glossary_formats",$displayformat);
         }
         redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
         die;
@@ -35,7 +35,7 @@
         $displayformat->sortkey     = $form->sortkey;
         $displayformat->sortorder   = $form->sortorder;
 
-        update_record("glossary_formats",$displayformat);
+        $DB->update_record("glossary_formats",$displayformat);
         redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
         die;
     }
index cc545746056b980257fb78d31cfd15f3f27fd80a..e593d9c17b7597dff9033e79466918e8649af982 100755 (executable)
@@ -1,11 +1,10 @@
 <?php  // $Id$
 
 function glossary_show_entry_TEMPLATE($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1, $ratings=NULL, $aliases=true) {
-
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
     
 
-    $user = get_record('user', 'id', $entry->userid);
+    $user = $DB->get_record('user', array('id'=>$entry->userid));
     $strby = get_string('writtenby', 'glossary');
 
     if ($entry) {
index 7d50b0eab983431496a5bd7638031c567e73b212..b40834b2425ff9e26e9af1ccff3166da4a7cbf88 100644 (file)
@@ -1,10 +1,10 @@
 <?php  // $Id$
 
 function glossary_show_entry_encyclopedia($course, $cm, $glossary, $entry, $mode='',$hook='',$printicons=1,$ratings=NULL, $aliases=true) {
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
 
 
-    $user = get_record('user', 'id', $entry->userid);
+    $user = $DB->get_record('user', array('id'=>$entry->userid));
     $strby = get_string('writtenby', 'glossary');
 
     $return = false;
@@ -22,6 +22,7 @@ function glossary_show_entry_encyclopedia($course, $cm, $glossary, $entry, $mode
         echo '</div>';
 
         $fullname = fullname($user);
+        $by = new object();
         $by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.$fullname.'</a>';
         $by->date = userdate($entry->timemodified);
         echo '<span class="author">'.get_string('bynameondate', 'forum', $by).'</span>';
index d4f4863b88b22cf8c503547b5de399c5a8f75859..cc2289c8e7bcfe0000799101be882a1c5ba73fa1 100644 (file)
@@ -1,10 +1,10 @@
 <?php  // $Id$
 
 function glossary_show_entry_fullwithauthor($course, $cm, $glossary, $entry, $mode="", $hook="", $printicons=1, $ratings=NULL, $aliases=true) {
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
 
 
-    $user = get_record('user', 'id', $entry->userid);
+    $user = $DB->get_record('user', array('id'=>$entry->userid));
     $strby = get_string('writtenby', 'glossary');
 
     $return = false;
index 1e6041a2f6bcf02c6fddd104c746244c5c1784da..cfebff2f0a61fb776bd972bf729d1b1748bfc74c 100644 (file)
@@ -3,7 +3,6 @@
     require_once("../../config.php");
     require_once("lib.php");
     require_once("$CFG->dirroot/course/lib.php");
-    global $CFG, $USER;
 
     $id = required_param('id', PARAM_INT);    // Course Module 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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidid', 'glossary');
     }
 
                     // course_modules and course_sections each contain a reference
                     // to each other, so we have to update one of them twice.
 
-                    if (! $currmodule = get_record("modules", "name", 'glossary')) {
+                    if (! $currmodule = $DB->get_record("modules", array("name"=>'glossary'))) {
                         print_error('modulenotexist', 'debug', '', 'Glossary');
                     }
                     $mod->module = $currmodule->id;
                         print_error('cannotaddcoursemoduletosection');
                     }
                     //We get the section's visible field status
-                    $visible = get_field("course_sections","visible","id",$sectionid);
+                    $visible = $DB->get_field("course_sections", "visible", array("id"=>$sectionid));
 
-                    if (! set_field("course_modules", "visible", $visible, "id", $mod->coursemodule)) {
+                    if (! $DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule))) {
                         print_error('cannotupdatemod', '', '', $mod->coursemodule);
                     }
 
-                    if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
+                    if (! $DB->set_field("course_modules", "section", $sectionid, array("id"=>$mod->coursemodule))) {
                         print_error('cannotupdatemod', '', '', $mod->coursemodule);
                     }
                     add_to_log($course->id, "course", "add mod",
                 if ( !$glossary->allowduplicatedentries ) {
                     // checking if the entry is valid (checking if it is duplicated when should not be)
                     if ( $newentry->casesensitive ) {
-                        $dupentry = get_record("glossary_entries","concept",$newentry->concept,"glossaryid",$glossary->id);
+                        $dupentry = $DB->get_record("glossary_entries", array("concept"=>$newentry->concept, "glossaryid"=>$glossary->id));
                     } else {
-                        $dupentry = get_record("glossary_entries","lower(concept)",moodle_strtolower($newentry->concept),"glossaryid",$glossary->id);
+                        $dupentry = $DB->get_record("glossary_entries", array("lower(concept)"=>moodle_strtolower($newentry->concept)), array("glossaryid"=>$glossary->id));
                     }
                     if ($dupentry) {
                         $permissiongranted = 0;
                 $newentry->approved         = 1;
                 $newentry->userid           = $USER->id;
                 $newentry->teacherentry     = 1;
-                $newentry->format           = addslashes($xmlentry['#']['FORMAT'][0]['#']);
+                $newentry->format           = $xmlentry['#']['FORMAT'][0]['#'];
                 $newentry->timecreated      = time();
                 $newentry->timemodified     = time();
 
                 // Setting the default values if no values were passed
                 if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) {
-                    $newentry->usedynalink      = addslashes($xmlentry['#']['USEDYNALINK'][0]['#']);
+                    $newentry->usedynalink      = $xmlentry['#']['USEDYNALINK'][0]['#'];
                 } else {
                     $newentry->usedynalink      = $CFG->glossary_linkentries;
                 }
                 if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) {
-                    $newentry->fullmatch        = addslashes($xmlentry['#']['FULLMATCH'][0]['#']);
+                    $newentry->fullmatch        = $xmlentry['#']['FULLMATCH'][0]['#'];
                 } else {
                     $newentry->fullmatch      = $CFG->glossary_fullmatch;
                 }
 
-                if ( $newentry->id = insert_record("glossary_entries",$newentry) )  {
+                if ( $newentry->id = $DB->insert_record("glossary_entries",$newentry) )  {
                     $importedentries++;
 
                     $xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES
                         $aliasname = $xmlalias['#']['NAME'][0]['#'];
 
                         if (!empty($aliasname)) {
-                            unset($newalias);
+                            $newalias = new object();
                             $newalias->entryid = $newentry->id;
-                            $newalias->alias = trim(addslashes($aliasname));
-                            $newalias->id = insert_record("glossary_alias",$newalias);
+                            $newalias->alias = trim($aliasname);
+                            $newalias->id = $DB->insert_record("glossary_alias",$newalias);
                         }
                     }
 
                         $xmlcats = @$xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; // ignore missing CATEGORIES
                         for($k = 0; $k < sizeof($xmlcats); $k++) {
                             $xmlcat = $xmlcats[$k];
-                            unset($newcat);
 
-                            $newcat->name = addslashes($xmlcat['#']['NAME'][0]['#']);
-                            $newcat->usedynalink = addslashes($xmlcat['#']['USEDYNALINK'][0]['#']);
-                            if ( !$category = get_record("glossary_categories","glossaryid",$glossary->id,"name",$newcat->name) ) {
+                            $newcat = new object();
+                            $newcat->name = $xmlcat['#']['NAME'][0]['#'];
+                            $newcat->usedynalink = $xmlcat['#']['USEDYNALINK'][0]['#'];
+                            if ( !$category = $DB->get_record("glossary_categories", array("glossaryid"=>$glossary->id,"name"=>$newcat->name))) {
                                 // Create the category if it does not exist
-                                unset($category);
+                                $category = new object();
                                 $category->name = $newcat->name;
                                 $category->glossaryid = $glossary->id;
-                                if ( !$category->id = insert_record("glossary_categories",$category)) {
+                                if ( !$category->id = $DB->insert_record("glossary_categories",$category)) {
                                     // add to exception report (can't insert category)
                                     $rejections .= "<tr><td>&nbsp;<strong>" . get_string("category","glossary") . ":</strong>$newcat->name</td>" .
                                                    "<td>" . get_string("cantinsertcat","glossary"). "</td></tr>";
                             }
                             if ( $category ) {
                                 // inserting the new relation
-                                unset($entrycat);
+                                $entrycat = new opbject();
                                 $entrycat->entryid    = $newentry->id;
                                 $entrycat->categoryid = $category->id;
-                                if ( !insert_record("glossary_entries_categories",$entrycat) ) {
+                                if ( !$DB->insert_record("glossary_entries_categories",$entrycat) ) {
                                     // add to exception report (can't insert relation)
                                     $rejections .= "<tr><td>&nbsp;<strong>" . get_string("category","glossary") . ":</strong>$newcat->name</td>" .
                                                    "<td>" . get_string("cantinsertrel","glossary"). "</td></tr>";
index 8e2976b4b020506556cc573df6ce31aa2242f34d..73607b7ae7ecade0cf0217204009f8857d94b258 100644 (file)
@@ -92,7 +92,7 @@
 
         // TODO: count only approved if not allowed to see them
 
-        $count = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}glossary_entries where (glossaryid = $glossary->id or sourceglossaryid = $glossary->id)");
+        $count = $DB->count_records_sql("SELECT COUNT(*) FROM {glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?)", array($glossary->id, $glossary->id));
 
         //If this glossary has RSS activated, calculate it
         if ($show_rss) {
index 755c09ff173e8606c9229f85515f004668ec231a..009b910188aa17081609db9769df12d4ce003e8b 100644 (file)
@@ -180,17 +180,15 @@ function glossary_user_outline($course, $user, $mod, $glossary) {
 
 function glossary_get_user_entries($glossaryid, $userid) {
 /// Get all the entries for a user in a glossary
-    global $CFG;
+    global $DB;
 
-    return get_records_sql("SELECT e.*, u.firstname, u.lastname, u.email, u.picture
-                              FROM {$CFG->prefix}glossary g,
-                                   {$CFG->prefix}glossary_entries e,
-                                   {$CFG->prefix}user u
-                             WHERE g.id = '$glossaryid'
+    return $DB->get_records_sql("SELECT e.*, u.firstname, u.lastname, u.email, u.picture
+                                   FROM {glossary} g, {glossary_entries} e, {user} u
+                             WHERE g.id = ?
                                AND e.glossaryid = g.id
-                               AND e.userid = '$userid'
+                               AND e.userid = ?
                                AND e.userid = u.id
-                          ORDER BY e.timemodified ASC");
+                          ORDER BY e.timemodified ASC", array($glossaryid, $userid));
 }
 
 function glossary_user_complete($course, $user, $mod, $glossary) {
@@ -214,7 +212,7 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
 /// that has occurred in glossary activities and print it out.
 /// Return true if there was output, or false is there was none.
 
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
 
     //TODO: use timestamp in approved field instead of changing timemodified when approving in 2.0
 
@@ -236,12 +234,12 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
 
     $glist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right?
 
-    if (!$entries = get_records_sql("SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid,
-                                            ge.userid, u.firstname, u.lastname, u.email, u.picture
-                                       FROM {$CFG->prefix}glossary_entries ge
-                                            JOIN {$CFG->prefix}user u ON u.id = ge.userid
-                                      WHERE ge.glossaryid IN ($glist) AND ge.timemodified > $timestart
-                                   ORDER BY ge.timemodified ASC")) {
+    if (!$entries = $DB->get_records_sql("SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid,
+                                                 ge.userid, u.firstname, u.lastname, u.email, u.picture
+                                            FROM {glossary_entries} ge
+                                            JOIN {user} u ON u.id = ge.userid
+                                           WHERE ge.glossaryid IN ($glist) AND ge.timemodified > ?
+                                        ORDER BY ge.timemodified ASC", array($timestart))) {
         return false;
     }
 
@@ -286,22 +284,17 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
 
 
 function glossary_log_info($log) {
-    global $CFG;
+    global $DB;
 
-    return get_record_sql("SELECT e.*, u.firstname, u.lastname
-                             FROM {$CFG->prefix}glossary_entries e,
-                                  {$CFG->prefix}user u
-                            WHERE e.id = '$log->info'
-                              AND u.id = '$log->userid'");
+    return $DB->get_record_sql("SELECT e.*, u.firstname, u.lastname
+                                  FROM {glossary_entries} e, {user} u
+                                 WHERE e.id = ? AND u.id = ?", array($log->info, $log->userid));
 }
 
 function glossary_cron () {
 /// Function to be run periodically according to the moodle cron
 /// This function searches for things that need to be done, such
 /// as sending out mail, toggling flags etc ...
-
-    global $CFG;
-
     return true;
 }
 
@@ -313,19 +306,20 @@ function glossary_cron () {
  * @return array array of grades, false if none
  */
 function glossary_get_user_grades($glossary, $userid=0) {
-    global $CFG;
+    global $DB;
 
-    $user = $userid ? "AND u.id = $userid" : "";
+    $params = array('userid'=>$userid, 'gid'=>$glossary->id);
+
+    $user = $userid ? "AND u.id = :userid" : "";
 
     $sql = "SELECT u.id, u.id AS userid, avg(gr.rating) AS rawgrade
-              FROM {$CFG->prefix}user u, {$CFG->prefix}glossary_entries ge,
-                   {$CFG->prefix}glossary_ratings gr
+              FROM {user} u, {glossary_entries} ge, {glossary_ratings} gr
              WHERE u.id = ge.userid AND ge.id = gr.entryid
-                   AND gr.userid != u.id AND ge.glossaryid = $glossary->id
+                   AND gr.userid != u.id AND ge.glossaryid = :gid
                    $user
           GROUP BY u.id";
 
-    return get_records_sql($sql);
+    return $DB->get_records_sql($sql, $params);
 }
 
 /**
@@ -335,7 +329,7 @@ function glossary_get_user_grades($glossary, $userid=0) {
  * @param int $userid specific user only, 0 mean all
  */
 function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
-    global $CFG;
+    global $CFG, $DB;
     require_once($CFG->libdir.'/gradelib.php');
 
     if ($glossary != null) {
@@ -354,17 +348,17 @@ function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
 
     } else {
         $sql = "SELECT g.*, cm.idnumber as cmidnumber
-                  FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
+                  FROM {glossary} g, {course_modules} cm, {modules} m
                  WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
-        if ($rs = get_recordset_sql($sql)) {
-            while ($glossary = rs_fetch_next_record($rs)) {
+        if ($rs = $DB->get_recordset_sql($sql)) {
+            foreach ($rs as $glossary) {
                 if ($glossary->assessed) {
                     glossary_update_grades($glossary, 0, false);
                 } else {
                     glossary_grade_item_update($glossary);
                 }
             }
-            rs_close($rs);
+            $rs->close();
         }
     }
 }
@@ -378,9 +372,8 @@ function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
  */
 function glossary_grade_item_update($glossary, $grades=NULL) {
     global $CFG;
-    if (!function_exists('grade_update')) { //workaround for buggy PHP versions
-        require_once($CFG->libdir.'/gradelib.php');
-    }
+    require_once($CFG->libdir.'/gradelib.php');
+
     if(!empty($glossary->cmidnumber)){
         $params = array('itemname'=>$glossary->name, 'idnumber'=>$glossary->cmidnumber);
     }else{
@@ -425,26 +418,24 @@ function glossary_grade_item_delete($glossary) {
 function glossary_get_participants($glossaryid) {
 //Returns the users with data in one glossary
 //(users with records in glossary_entries, students)
-
-    global $CFG;
+    global $DB;
 
     //Get students
-    $students = get_records_sql("SELECT DISTINCT u.id, u.id
-                                 FROM {$CFG->prefix}user u,
-                                      {$CFG->prefix}glossary_entries g
-                                 WHERE g.glossaryid = '$glossaryid' and
-                                       u.id = g.userid");
+    $students = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
+                                        FROM {user} u, {glossary_entries} g
+                                 WHERE g.glossaryid = : AND u.id = g.userid", array($glossaryid));
 
     //Return students array (it contains an array of unique users)
-    return ($students);
+    return $students;
 }
 
 function glossary_scale_used ($glossaryid,$scaleid) {
 //This function returns if a scale is being used by one glossary
+    global $DB;
 
     $return = false;
 
-    $rec = get_record("glossary","id","$glossaryid","scale","-$scaleid");
+    $rec = $DB->get_record("glossary", array("id"=>$glossaryid, "scale"=>-$scaleid));
 
     if (!empty($rec)  && !empty($scaleid)) {
         $return = true;
@@ -461,7 +452,9 @@ function glossary_scale_used ($glossaryid,$scaleid) {
  * @return boolean True if the scale is used by any glossary
  */
 function glossary_scale_used_anywhere($scaleid) {
-    if ($scaleid and record_exists('glossary', 'scale', -$scaleid)) {
+    global $DB;
+
+    if ($scaleid and $DB->record_exists('glossary', array('scale'=>-$scaleid))) {
         return true;
     } else {
         return false;
@@ -477,8 +470,7 @@ function glossary_scale_used_anywhere($scaleid) {
 //are included if detected and old formats are deleted and any glossary
 //using an invalid format is updated to the default (dictionary).
 function glossary_get_available_formats() {
-
-    global $CFG;
+    global $CFG, $DB;
 
     //Get available formats (plugin) and insert (if necessary) them into glossary_formats
     $formats = get_list_of_plugins('mod/glossary/formats', 'TEMPLATE');
@@ -492,20 +484,20 @@ function glossary_get_available_formats() {
                 //Acummulate it as a valid format
                 $pluginformats[] = $format;
                 //If the format doesn't exist in the table
-                if (!$rec = get_record('glossary_formats','name',$format)) {
+                if (!$rec = $DB->get_record('glossary_formats', array('name'=>$format))) {
                     //Insert the record in glossary_formats
                     $gf = new object();
                     $gf->name = $format;
                     $gf->popupformatname = $format;
                     $gf->visible = 1;
-                    insert_record("glossary_formats",$gf);
+                    $DB->insert_record("glossary_formats",$gf);
                 }
             }
         }
     }
 
     //Delete non_existent formats from glossary_formats table
-    $formats = get_records("glossary_formats");
+    $formats = $DB->get_records("glossary_formats");
     foreach ($formats as $format) {
         $todelete = false;
         //If the format in DB isn't a valid previously detected format then delete the record
@@ -515,18 +507,18 @@ function glossary_get_available_formats() {
 
         if ($todelete) {
             //Delete the format
-            delete_records('glossary_formats','name',$format->name);
+            $DB->delete_records('glossary_formats', array('name'=>$format->name));
             //Reasign existing glossaries to default (dictionary) format
-            if ($glossaries = get_records('glossary','displayformat',$format->name)) {
+            if ($glossaries = $DB->get_records('glossary', array('displayformat'=>$format->name))) {
                 foreach($glossaries as $glossary) {
-                    set_field('glossary','displayformat','dictionary','id',$glossary->id);
+                    $DB->set_field('glossary','displayformat','dictionary', array('id'=>$glossary->id));
                 }
             }
         }
     }
 
     //Now everything is ready in glossary_formats table
-    $formats = get_records("glossary_formats");
+    $formats = $DB->get_records("glossary_formats");
 
     return $formats;
 }
@@ -541,20 +533,19 @@ function glossary_debug($debug,$text,$br=1) {
 }
 
 function glossary_get_entries($glossaryid, $entrylist, $pivot = "") {
-    global $CFG;
+    global $DB;
     if ($pivot) {
        $pivot .= ",";
     }
 
-    return get_records_sql("SELECT $pivot id,userid,concept,definition,format
-                            FROM {$CFG->prefix}glossary_entries
-                            WHERE glossaryid = '$glossaryid'
-                            AND id IN ($entrylist)");
+    return $DB->get_records_sql("SELECT $pivot id,userid,concept,definition,format
+                                   FROM {glossary_entries}
+                                  WHERE glossaryid = ?
+                                        AND id IN ($entrylist)", array($glossaryid));
 }
 
 function glossary_get_entries_search($concept, $courseid) {
-
-    global $CFG;
+    global $CFG, $DB;
 
     //Check if the user is an admin
     $bypassadmin = 1; //This means NO (by default)
@@ -570,55 +561,22 @@ function glossary_get_entries_search($concept, $courseid) {
 
     $conceptlower = moodle_strtolower(trim($concept));
 
-    return get_records_sql("SELECT e.*, g.name as glossaryname, cm.id as cmid, cm.course as courseid
-                            FROM {$CFG->prefix}glossary_entries e,
-                                 {$CFG->prefix}glossary g,
-                                 {$CFG->prefix}course_modules cm,
-                                 {$CFG->prefix}modules m
-                            WHERE m.name = 'glossary' AND
-                                  cm.module = m.id AND
-                                  (cm.visible = 1 OR  cm.visible = $bypassadmin OR
-                                    (cm.course = '$courseid' AND cm.visible = $bypassteacher)) AND
-                                  g.id = cm.instance AND
-                                  e.glossaryid = g.id  AND
-                                  ( (e.casesensitive != 0 AND LOWER(concept) = '$conceptlower') OR
-                                    (e.casesensitive = 0 and concept = '$concept')) AND
-                                  (g.course = '$courseid' OR g.globalglossary = 1) AND
-                                  e.usedynalink != 0 AND
-                                  g.usedynalink != 0");
-}
-
-function glossary_get_entries_sorted($glossary, $where="", $orderby="", $pivot = "") {
-global $CFG;
-    if ($where) {
-       $where = " and $where";
-    }
-    if ($orderby) {
-       $orderby = " ORDER BY $orderby";
-    }
-    if ($pivot) {
-       $pivot .= ",";
-    }
-    return      get_records_sql("SELECT $pivot *
-                                 FROM {$CFG->prefix}glossary_entries
-                                 WHERE (glossaryid = $glossary->id or sourceglossaryid = $glossary->id) $where $orderby");
-}
+    $params = array('courseid1'=>$courseid, 'courseid2'=>$courseid, 'conceptlower'=>$conceptlower, 'concept'=>$concept);
 
-function glossary_get_entries_by_category($glossary, $hook, $where="", $orderby="", $pivot = "") {
-global $CFG;
-    if ($where) {
-       $where = " and $where";
-    }
-    if ($orderby) {
-       $orderby = " ORDER BY $orderby";
-    }
-    if ($pivot) {
-       $pivot .= ",";
-    }
-    return      get_records_sql("SELECT $pivot ge.*
-                                 FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories c
-                                 WHERE (ge.id = c.entryidid and c.categoryid = $hook) and
-                                             (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) $where $orderby");
+    return $DB->get_records_sql("SELECT e.*, g.name as glossaryname, cm.id as cmid, cm.course as courseid
+                                   FROM {glossary_entries} e, {glossary} g,
+                                        {course_modules} cm, {modules} m
+                                  WHERE m.name = 'glossary' AND
+                                        cm.module = m.id AND
+                                        (cm.visible = 1 OR  cm.visible = $bypassadmin OR
+                                            (cm.course = :courseid1 AND cm.visible = $bypassteacher)) AND
+                                        g.id = cm.instance AND
+                                        e.glossaryid = g.id  AND
+                                        ( (e.casesensitive != 0 AND LOWER(concept) = :conceptlower) OR
+                                          (e.casesensitive = 0 and concept = :concept)) AND
+                                        (g.course = courseid2 OR g.globalglossary = 1) AND
+                                         e.usedynalink != 0 AND
+                                         g.usedynalink != 0", $params);
 }
 
 function glossary_print_entry($course, $cm, $glossary, $entry, $mode='',$hook='',$printicons = 1, $displayformat  = -1, $ratings = NULL, $printview = false) {
@@ -693,6 +651,7 @@ function  glossary_print_entry_concept($entry) {
 }
 
 function glossary_print_entry_definition($entry) {
+    global $DB;
 
     $definition = $entry->definition;
 
@@ -715,7 +674,7 @@ function glossary_print_entry_definition($entry) {
     $pat = '/('.$term.')/is';
     $doNolinks[] = $pat;
     //Now the aliases
-    if ( $aliases = get_records('glossary_alias','entryid',$entry->id) ) {
+    if ( $aliases = $DB->get_records('glossary_alias', array('entryid'=>$entry->id))) {
         foreach ($aliases as $alias) {
             $term = preg_quote(trim($alias->alias),'/');
             $pat = '/('.$term.')/is';
@@ -821,8 +780,10 @@ function glossary_print_entry_definition($entry) {
 }
 
 function  glossary_print_entry_aliases($course, $cm, $glossary, $entry,$mode='',$hook='', $type = 'print') {
+    global $DB;
+
     $return = '';
-    if ( $aliases = get_records('glossary_alias','entryid',$entry->id) ) {
+    if ( $aliases = $DB->get_records('glossary_alias', array('entryid'=>$entry->id))) {
         foreach ($aliases as $alias) {
             if (trim($alias->alias)) {
                 if ($return == '') {
@@ -843,7 +804,7 @@ function  glossary_print_entry_aliases($course, $cm, $glossary, $entry,$mode='',
 }
 
 function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$hook='', $type = 'print') {
-    global $USER, $CFG;
+    global $USER, $CFG, $DB;
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
@@ -871,7 +832,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
     if (has_capability('mod/glossary:manageentries', $context) or (!empty($USER->id) and has_capability('mod/glossary:write', $context) and $entry->userid == $USER->id)) {
         // only teachers can export entries so check it out
         if (has_capability('mod/glossary:export', $context) and !$ismainglossary and !$importedentry) {
-            $mainglossary = get_record('glossary','mainglossary',1,'course',$course->id);
+            $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1,'course'=>$course->id));
             if ( $mainglossary ) {  // if there is a main glossary defined, allow to export the current entry
                 $output = true;
                 $return .= ' <a title="'.get_string('exporttomainglossary','glossary') . '" href="exportentry.php?id='.$cm->id.'&amp;entry='.$entry->id.'&amp;mode='.$mode.'&amp;hook='.$hook.'"><img src="export.gif" class="iconsmall" alt="'.get_string('exporttomainglossary','glossary').$altsuffix.'" /></a>';
@@ -916,9 +877,11 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
 }
 
 function glossary_print_entry_commentslink($course, $cm, $glossary, $entry,$mode,$hook, $type = 'print') {
+    global $DB;
+
     $return = '';
 
-    $count = count_records('glossary_comments','entryid',$entry->id);
+    $count = $DB->count_records('glossary_comments', array('entryid'=>$entry->id));
     if ($count) {
         $return = '';
         $return .= "<a href=\"comments.php?id=$cm->id&amp;eid=$entry->id\">$count ";
@@ -970,8 +933,10 @@ function glossary_print_entry_attachment($entry,$format=NULL,$align="right",$ins
 ///   valid format values: html  : Return the HTML link for the attachment as an icon
 ///                        text  : Return the HTML link for tha attachment as text
 ///                        blank : Print the output to the screen
+    global $DB;
+
     if ($entry->attachment) {
-          $glossary = get_record("glossary","id",$entry->glossaryid);
+          $glossary = $DB->get_record("glossary", array("id"=>$entry->glossaryid));
           $entry->course = $glossary->course; //used inside print_attachment
           if ($insidetable) {
               echo "<table border=\"0\" width=\"100%\" align=\"$align\"><tr><td align=\"$align\" nowrap=\"nowrap\">\n";
@@ -1001,10 +966,10 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
 // It returns all entries from all glossaries that matches the specified criteria
 //    within a given $course. It performs an $extended search if necessary.
 // It restrict the search to only one $glossary if the $glossary parameter is set.
+    global $CFG, $DB;
 
-    global $CFG;
     if ( !$glossary ) {
-        if ( $glossaries = get_records("glossary", "course", $course->id) ) {
+        if ( $glossaries = $DB->get_records("glossary", array("course"=>$course->id)) ) {
             $glos = "";
             foreach ( $glossaries as $glossary ) {
                 $glos .= "$glossary->id,";
@@ -1016,90 +981,95 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
     }
 
     if (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_COURSE, $glossary->course))) {
-        $glossarymodule = get_record("modules", "name", "glossary");
+        $glossarymodule = $DB->get_record("modules", array("name"=>"glossary"));
         $onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id";
-        $onlyvisibletable = ", {$CFG->prefix}course_modules cm";
+        $onlyvisibletable = ", {course_modules} cm";
     } else {
 
         $onlyvisible = "";
         $onlyvisibletable = "";
     }
 
-    /// Some differences in syntax for entrygreSQL
-    switch ($CFG->dbfamily) {
-    case 'postgres':
-        $LIKE = "ILIKE";   // case-insensitive
-        $NOTLIKE = "NOT ILIKE";   // case-insensitive
-        $REGEXP = "~*";
-        $NOTREGEXP = "!~*";
-    break;
-    case 'mysql':
-    default:
-        $LIKE = "LIKE";
-        $NOTLIKE = "NOT LIKE";
-        $REGEXP = "REGEXP";
-        $NOTREGEXP = "NOT REGEXP";
-    break;
+    if ($DB->sql_regex_supported()) {
+        $REGEXP    = $DB->sql_regex(true);
+        $NOTREGEXP = $DB->sql_regex(false);
     }
+    $LIKE = $DB->sql_ilike(); // case-insensitive
 
-    $conceptsearch = "";
-    $definitionsearch = "";
+    $searchcond = array();
+    $params     = array();
+    $i = 0;
+
+    $concat = $DB->sql_concat('e.concept', "' '", 'e.definition');
 
 
     foreach ($searchterms as $searchterm) {
-        if ($conceptsearch) {
-            $conceptsearch.= " OR ";
-        }
-        if ($definitionsearch) {
-            $definitionsearch.= " OR ";
-        }
+        $i++;
+
+        $NOT = ''; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
+                   /// will use it to simulate the "-" operator with LIKE clause
 
     /// Under Oracle and MSSQL, trim the + and - operators and perform
-    /// simpler LIKE search
-        if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
+    /// simpler LIKE (or NOT LIKE) queries
+        if (!$DB->sql_regex_supported()) {
+            if (substr($searchterm, 0, 1) == '-') {
+                $NOT = ' NOT ';
+            }
             $searchterm = trim($searchterm, '+-');
         }
 
-        if (substr($searchterm,0,1) == "+") {
-            $searchterm = substr($searchterm,1);
-            $conceptsearch.= " e.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
-            $definitionsearch .= " e.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
+        // TODO: +- may not work for non latin languages
+
+        if (substr($searchterm,0,1) == '+') {
+            $searchterm = trim($searchterm, '+-');
+            $searchterm = preg_quote($searchterm, '|');
+            $searchcond[] = "$concat $REGEXP :ss$i";
+            $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
+
         } else if (substr($searchterm,0,1) == "-") {
-            $searchterm = substr($searchterm,1);
-            $conceptsearch .= " e.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
-            $definitionsearch .= " e.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
+            $searchterm = trim($searchterm, '+-');
+            $searchterm = preg_quote($searchterm, '|');
+            $searchcond[] = "$concat $NOTREGEXP :ss$i";
+            $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
+
         } else {
-            $conceptsearch .= " e.concept $LIKE '%$searchterm%' ";
-            $definitionsearch .= " e.definition $LIKE '%$searchterm%' ";
+            $searchcond[] = "$concat $NOT $LIKE :ss$i";
+            $params['ss'.$i] = "%$searchterm%";
         }
     }
 
-    $definitionsearch = !empty($extended) ? "OR $definitionsearch" : '';
+    if (empty($searchcond)) {
+        $totalcount = 0;
+        return array();
+    }
+
+    $searchcond = implode(" AND ", $searchcond);
 
-    $selectsql = "{$CFG->prefix}glossary_entries e,
-                  {$CFG->prefix}glossary g $onlyvisibletable
-             WHERE ($conceptsearch $definitionsearch)
+    $sql = "SELECT e.*
+              FROM {glossary_entries} e, {glossary} g $onlyvisibletable
+             WHERE $searchcond
                AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible
-               AND g.id IN ($glos) AND e.approved != 0";
+               AND g.id IN ($glos) AND e.approved <> 0";
 
-    return get_records_sql("SELECT e.*
-                            FROM $selectsql ORDER BY e.concept ASC");
+    return $DB->get_records_sql($sql, $params);
 }
 
 function glossary_search_entries($searchterms, $glossary, $extended) {
-    $course = get_record("course","id",$glossary->course);
+    global $DB;
+
+    $course = $DB->get_record("course", array("id"=>$glossary->course));
     return glossary_search($course,$searchterms,$extended,$glossary);
 }
 
 function glossary_file_area_name($entry) {
-    global $CFG;
+    global $CFG, $DB;
 //  Creates a directory file name, suitable for make_upload_directory()
 
     // I'm doing this workaround for make it works for delete_instance also
     //  (when called from delete_instance, glossary is already deleted so
     //   getting the course from mdl_glossary does not work)
-    $module = get_record("modules","name","glossary");
-    $cm = get_record("course_modules","module",$module->id,"instance",$entry->glossaryid);
+    $module = $DB->get_record("modules", array("name"=>"glossary"));
+    $cm = $DB->get_record("course_modules", array("module"=>$module->id, "instance"=>$entry->glossaryid));
     return "$cm->course/$CFG->moddata/glossary/$entry->glossaryid/$entry->id";
 }
 
@@ -1137,8 +1107,9 @@ function glossary_delete_old_attachments($entry, $exception="") {
     }
 }
 function glossary_delete_attachments($glossary) {
+    global $DB;
 // Deletes all the user files in the attachments area for the glossary
-    if ( $entries = get_records("glossary_entries","glossaryid",$glossary->id) ) {
+    if ( $entries = $DB->get_records("glossary_entries", array("glossaryid"=>$glossary->id))) {
         $deleted = 0;
         foreach ($entries as $entry) {
             if ( $entry->attachment ) {
@@ -1170,12 +1141,11 @@ function glossary_copy_attachments($entry, $newentry) {
 /// this function checks that entry
 /// for attachments, and if any are found, these are
 /// copied to the new glossary directory.
-
-    global $CFG;
+    global $CFG, $DB;
 
     $return = true;
 
-    if ($entries = get_records_select("glossary_entries", "id = '$entry->id' AND attachment <> ''")) {
+    if ($entries = $DB->get_records_select("glossary_entries", "id = ? AND attachment <> ''", array($entry->id))) {
         foreach ($entries as $curentry) {
             $oldentry = new object();
             $oldentry->id = $entry->id;
@@ -1200,13 +1170,13 @@ function glossary_move_attachments($entry, $glossaryid) {
 /// for attachments, and if any are found, these are
 /// moved to the new glossary directory.
 
-    global $CFG;
+    global $CFG, $DB;
 
     require_once($CFG->dirroot.'/lib/uploadlib.php');
 
     $return = true;
 
-    if ($entries = get_records_select("glossary_entries", "glossaryid = '$entry->id' AND attachment <> ''")) {
+    if ($entries = $DB->get_records_select("glossary_entries", "glossaryid = ? AND attachment <> ''", array($entry->id))) {
         foreach ($entries as $entry) {
             $oldentry = new object();
             $oldentry->course = $entry->course;
@@ -1337,8 +1307,7 @@ function glossary_print_author_menu($cm, $glossary,$mode, $hook, $sortkey = '',
 }
 
 function glossary_print_categories_menu($cm, $glossary, $hook, $category) {
-
-     global $CFG;
+     global $CFG, $DB;
 
      $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
@@ -1360,7 +1329,7 @@ function glossary_print_categories_menu($cm, $glossary, $hook, $category) {
      $menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary");
      $menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary");
 
-     $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
+     $categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id), "name ASC");
      $selected = '';
      if ( $categories ) {
           foreach ($categories as $currentcategory) {
@@ -1557,11 +1526,11 @@ function glossary_sort_entries ( $entry0, $entry1 ) {
 }
 
 function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
-    $user = get_record('user', 'id', $comment->userid);
+    $user = $DB->get_record('user', array('id'=>$comment->userid));
     $strby = get_string('writtenby','glossary');
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
 
@@ -1607,13 +1576,13 @@ function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
 }
 
 function  glossary_print_entry_ratings($course, $entry, $ratings = NULL) {
+    global $USER, $CFG, $DB;
 
-    global $USER, $CFG;
-
-    $glossary = get_record('glossary', 'id', $entry->glossaryid);
-    $glossarymod = get_record('modules','name','glossary');
-    $cm = get_record_sql("select * from {$CFG->prefix}course_modules where course = $course->id
-                          and module = $glossarymod->id and instance = $glossary->id");
+    $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid));
+    $glossarymod = $DB->get_record('modules', array('name'=>'glossary'));
+    $cm = $DB->get_record_sql("SELECT *
+                                 FROM {course_modules}
+                                WHERE course = ? AND module = ? and instance = ?", array($course->id, $glossarymod->id, $glossary->id));
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
@@ -1644,17 +1613,17 @@ function  glossary_print_entry_ratings($course, $entry, $ratings = NULL) {
 }
 
 function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) {
-    global $USER,$CFG;
+    global $USER,$CFG, $DB;
 
     echo '<div class="boxaligncenter">';
     echo '<table class="glossarypopup" cellspacing="0"><tr>';
     echo '<td>';
     if ( $entries ) {
         foreach ( $entries as $entry ) {
-            if (! $glossary = get_record('glossary', 'id', $entry->glossaryid)) {
+            if (! $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
                 print_error('invalidid', 'glossary');
             }
-            if (! $course = get_record('course', 'id', $glossary->course)) {
+            if (! $course = $DB->get_record('course', array('id'=>$glossary->course))) {
                 print_error('coursemisconf');
             }
             if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid, $glossary->course) ) {
@@ -1669,7 +1638,7 @@ function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) {
             }
 
             //Get popupformatname
-            $format = get_record('glossary_formats','name',$dp);
+            $format = $DB->get_record('glossary_formats', array('name'=>$dp));
             $displayformat = $format->popupformatname;
 
             //Check displayformat variable and set to default if necessary
@@ -1693,7 +1662,7 @@ function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) {
 }
 
 function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
-    global $CFG;
+    global $CFG, $DB;
 
     $co  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 
@@ -1712,7 +1681,7 @@ function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
         $co .= glossary_full_tag("GLOBALGLOSSARY",2,false,$glossary->globalglossary);
         $co .= glossary_full_tag("ENTBYPAGE",2,false,$glossary->entbypage);
 
-        if ( $entries = get_records("glossary_entries","glossaryid",$glossary->id) ) {
+        if ( $entries = $DB->get_records("glossary_entries", array("glossaryid"=>$glossary->id))) {
             $co .= glossary_start_tag("ENTRIES",2,true);
             foreach ($entries as $entry) {
                 $permissiongranted = 1;
@@ -1731,10 +1700,10 @@ function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
                     case GLOSSARY_SHOW_ALL_CATEGORIES:
                     break;
                     case GLOSSARY_SHOW_NOT_CATEGORISED:
-                        $permissiongranted = !record_exists("glossary_entries_categories","entryid",$entry->id);
+                        $permissiongranted = !$DB->record_exists("glossary_entries_categories", array("entryid"=>$entry->id));
                     break;
                     default:
-                        $permissiongranted = record_exists("glossary_entries_categories","entryid",$entry->id, "categoryid",$hook);
+                        $permissiongranted = $DB->record_exists("glossary_entries_categories", array("entryid"=>$entry->id, "categoryid"=>$hook));
                     break;
                     }
                 }
@@ -1748,7 +1717,7 @@ function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
                     $co .= glossary_full_tag("FULLMATCH",4,false,$entry->fullmatch);
                     $co .= glossary_full_tag("TEACHERENTRY",4,false,$entry->teacherentry);
 
-                    if ( $aliases = get_records("glossary_alias","entryid",$entry->id) ) {
+                    if ( $aliases = $DB->get_records("glossary_alias", array("entryid"=>$entry->id))) {
                         $co .= glossary_start_tag("ALIASES",4,true);
                         foreach ($aliases as $alias) {
                             $co .= glossary_start_tag("ALIAS",5,true);
@@ -1757,10 +1726,10 @@ function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
                         }
                         $co .= glossary_end_tag("ALIASES",4,true);
                     }
-                    if ( $catentries = get_records("glossary_entries_categories","entryid",$entry->id) ) {
+                    if ( $catentries = $DB->get_records("glossary_entries_categories", array("entryid"=>$entry->id))) {
                         $co .= glossary_start_tag("CATEGORIES",4,true);
                         foreach ($catentries as $catentry) {
-                            $category = get_record("glossary_categories","id",$catentry->categoryid);
+                            $category = $DB->get_record("glossary_categories", array("id"=>$catentry->categoryid));
 
                             $co .= glossary_start_tag("CATEGORY",5,true);
                                 $co .= glossary_full_tag("NAME",6,false,$category->name);
@@ -1839,29 +1808,24 @@ function glossary_full_tag($tag,$level=0,$endline=true,$content) {
 
 function glossary_get_ratings($entryid, $sort="u.firstname ASC") {
 /// Returns a list of ratings for a particular entry - sorted.
-    global $CFG;
-    return get_records_sql("SELECT u.*, r.rating, r.time
-                              FROM {$CFG->prefix}glossary_ratings r,
-                                   {$CFG->prefix}user u
-                             WHERE r.entryid = '$entryid'
-                               AND r.userid = u.id
-                             ORDER BY $sort");
+    global $DB;
+    return $DB->get_records_sql("SELECT u.*, r.rating, r.time
+                                   FROM {glossary_ratings} r, {user} u
+                                  WHERE r.entryid = ? AND r.userid = u.id
+                               ORDER BY $sort", array($entryid));
 }
 
 function glossary_count_unrated_entries($glossaryid, $userid) {
 // How many unrated entries are in the given glossary for a given user?
-    global $CFG;
-    if ($entries = get_record_sql("SELECT count(*) as num
-                                   FROM {$CFG->prefix}glossary_entries
-                                  WHERE glossaryid = '$glossaryid'
-                                    AND userid <> '$userid' ")) {
-
-        if ($rated = get_record_sql("SELECT count(*) as num
-                                       FROM {$CFG->prefix}glossary_entries e,
-                                            {$CFG->prefix}glossary_ratings r
-                                      WHERE e.glossaryid = '$glossaryid'
-                                        AND e.id = r.entryid
-                                        AND r.userid = '$userid'")) {
+    global $DB;
+    if ($entries = $DB->get_record_sql("SELECT count('x') as num
+                                          FROM {glossary_entries}
+                                         WHERE glossaryid = ? AND userid <> ?", array($glossaryid, $userid))) {
+
+        if ($rated = $DB->get_record_sql("SELECT count(*) as num
+                                            FROM {glossary_entries} e, {glossary_ratings} r
+                                           WHERE e.glossaryid = ? AND e.id = r.entryid
+                                                 AND r.userid = ?", array($glossaryid, $userid))) {
             $difference = $entries->num - $rated->num;
             if ($difference > 0) {
                 return $difference;
@@ -1900,10 +1864,11 @@ function glossary_get_ratings_mean($entryid, $scale, $ratings=NULL) {
 /// Return the mean rating of a entry given to the current user by others.
 /// Scale is an array of possible ratings in the scale
 /// Ratings is an optional simple array of actual ratings (just integers)
+    global $DB;
 
     if (!$ratings) {
         $ratings = array();
-        if ($rates = get_records("glossary_ratings", "entryid", $entryid)) {
+        if ($rates = $DB->get_records("glossary_ratings", array("entryid"=>$entryid))) {
             foreach ($rates as $rate) {
                 $ratings[] = $rate->rating;
             }
@@ -1937,10 +1902,11 @@ function glossary_get_ratings_summary($entryid, $scale, $ratings=NULL) {
 /// Return a summary of entry ratings given to the current user by others.
 /// Scale is an array of possible ratings in the scale
 /// Ratings is an optional simple array of actual ratings (just integers)
+    global $DB;
 
     if (!$ratings) {
         $ratings = array();
-        if ($rates = get_records("glossary_ratings", "entryid", $entryid)) {
+        if ($rates = $DB->get_records("glossary_ratings", array("entryid"=>$entryid))) {
             foreach ($rates as $rate) {
                 $rating[] = $rate->rating;
             }
@@ -1975,10 +1941,11 @@ function glossary_print_rating_menu($entryid, $userid, $scale) {
 /// Print the menu of ratings as part of a larger form.
 /// If the entry has already been - set that value.
 /// Scale is an array of ratings
+    global $DB;
 
     static $strrate;
 
-    if (!$rating = get_record("glossary_ratings", "userid", $userid, "entryid", $entryid)) {
+    if (!$rating = $DB->get_record("glossary_ratings", array("userid"=>$userid, "entryid"=>$entryid))) {
         $rating->rating = -999;
     }
 
@@ -2173,7 +2140,7 @@ function glossary_reset_course_form_defaults($course) {
  * @param string optional type
  */
 function glossary_reset_gradebook($courseid, $type='') {
-    global $CFG;
+    global $DB;
 
     switch ($type) {
         case 'main'      : $type = "AND g.mainglossary=1"; break;
@@ -2182,10 +2149,10 @@ function glossary_reset_gradebook($courseid, $type='') {
     }
 
     $sql = "SELECT g.*, cm.idnumber as cmidnumber, g.course as courseid
-              FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
-             WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id AND g.course=$courseid $type";
+              FROM {glossary} g, {course_modules} cm, {modules} m
+             WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id AND g.course=? $type";
 
-    if ($glossarys = get_records_sql($sql)) {
+    if ($glossarys = $DB->get_records_sql($sql, array($courseid))) {
         foreach ($glossarys as $glossary) {
             glossary_grade_item_update($glossary, 'reset');
         }
@@ -2198,30 +2165,32 @@ function glossary_reset_gradebook($courseid, $type='') {
  * @return array status array
  */
 function glossary_reset_userdata($data) {
-    global $CFG;
+    global $CFG, $DB;
     require_once($CFG->libdir.'/filelib.php');
 
     $componentstr = get_string('modulenameplural', 'glossary');
     $status = array();
 
     $allentriessql = "SELECT e.id
-                        FROM {$CFG->prefix}glossary_entries e
-                             INNER JOIN {$CFG->prefix}glossary g ON e.glossaryid = g.id
-                       WHERE g.course = {$data->courseid}";
+                        FROM {glossary_entries} e
+                             JOIN {glossary} g ON e.glossaryid = g.id
+                       WHERE g.course = ?";
 
     $allglossariessql = "SELECT g.id
-                            FROM {$CFG->prefix}glossary g
-                           WHERE g.course={$data->courseid}";
+                           FROM {glossary} g
+                          WHERE g.course = ?";
+
+    $params = array($data->courseid);
 
     // delete entries if requested
     if (!empty($data->reset_glossary_all)
          or (!empty($data->reset_glossary_types) and in_array('main', $data->reset_glossary_types) and in_array('secondary', $data->reset_glossary_types))) {
 
-        delete_records_select('glossary_ratings', "entryid IN ($allentriessql)");
-        delete_records_select('glossary_comments', "entryid IN ($allentriessql)");
-        delete_records_select('glossary_entries', "glossaryid IN ($allglossariessql)");
+        $DB->delete_records_select('glossary_ratings', "entryid IN ($allentriessql)", $params);
+        $DB->delete_records_select('glossary_comments', "entryid IN ($allentriessql)", $params);
+        $DB->delete_records_select('glossary_entries', "glossaryid IN ($allglossariessql)", $params);
 
-        if ($glossaries = get_records_sql($allglossariessql)) {
+        if ($glossaries = $DB->get_records_sql($allglossariessql, $params)) {
             foreach ($glossaries as $glossaryid=>$unused) {
                 fulldelete($CFG->dataroot."/$data->courseid/moddata/glossary/$glossaryid");
             }
@@ -2242,11 +2211,11 @@ function glossary_reset_userdata($data) {
         $secondaryglossariessql = "$allglossariessql AND g.mainglossary=0";
 
         if (in_array('main', $data->reset_glossary_types)) {
-            delete_records_select('glossary_ratings', "entryid IN ($mainentriessql)");
-            delete_records_select('glossary_comments', "entryid IN ($mainentriessql)");
-            delete_records_select('glossary_entries', "glossaryid IN ($mainglossariessql)");
+            $DB->delete_records_select('glossary_ratings', "entryid IN ($mainentriessql)", $params);
+            $DB->delete_records_select('glossary_comments', "entryid IN ($mainentriessql)", $params);
+            $DB->delete_records_select('glossary_entries', "glossaryid IN ($mainglossariessql)", $params);
 
-            if ($glossaries = get_records_sql($mainglossariessql)) {
+            if ($glossaries = $DB->get_records_sql($mainglossariessql, $params)) {
                 foreach ($glossaries as $glossaryid=>$unused) {
                     fulldelete("$CFG->dataroot/$data->courseid/moddata/glossary/$glossaryid");
                 }
@@ -2260,15 +2229,15 @@ function glossary_reset_userdata($data) {
             $status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossaries', 'glossary'), 'error'=>false);
 
         } else if (in_array('secondary', $data->reset_glossary_types)) {
-            delete_records_select('glossary_ratings', "entryid IN ($secondaryentriessql)");
-            delete_records_select('glossary_comments', "entryid IN ($secondaryentriessql)");
-            delete_records_select('glossary_entries', "glossaryid IN ($secondaryglossariessql)");
+            $DB->delete_records_select('glossary_ratings', "entryid IN ($secondaryentriessql)", $params);
+            $DB->delete_records_select('glossary_comments', "entryid IN ($secondaryentriessql)", $params);
+            $DB->delete_records_select('glossary_entries', "glossaryid IN ($secondaryglossariessql)", $params);
             // remove exported source flag from entries in main glossary
-            execute_sql("UPDATE {$CFG->prefix}glossary_entries
-                            SET sourceglossaryid=0
-                          WHERE glossaryid IN ($mainglossariessql)", false);
+            $DB->execute("UPDATE {glossary_entries
+                             SET sourceglossaryid=0
+                           WHERE glossaryid IN ($mainglossariessql)", $params);
 
-            if ($glossaries = get_records_sql($secondaryglossariessql)) {
+            if ($glossaries = $DB->get_records_sql($secondaryglossariessql, $params)) {
                 foreach ($glossaries as $glossaryid=>$unused) {
                     fulldelete("$CFG->dataroot/$data->courseid/moddata/glossary/$glossaryid");
                 }
@@ -2286,32 +2255,32 @@ function glossary_reset_userdata($data) {
     // remove entries by users not enrolled into course
     if (!empty($data->reset_glossary_notenrolled)) {
         $entriessql = "SELECT e.id, e.userid, e.glossaryid, u.id AS userexists, u.deleted AS userdeleted
-                         FROM {$CFG->prefix}glossary_entries e
-                              INNER JOIN {$CFG->prefix}glossary g ON e.glossaryid = g.id
-                              LEFT OUTER JOIN {$CFG->prefix}user u ON e.userid = u.id
-                        WHERE g.course = {$data->courseid} AND e.userid > 0";
+                         FROM {glossary_entries} e
+                              JOIN {glossary} g ON e.glossaryid = g.id
+                              LEFT JOIN {user} u ON e.userid = u.id
+                        WHERE g.course = ? AND e.userid > 0";
 
         $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
         $notenrolled = array();
-        if ($rs = get_recordset_sql($entriessql)) {
-            while ($entry = rs_fetch_next_record($rs)) {
+        if ($rs = $DB->get_recordset_sql($entriessql, $params)) {
+            foreach ($rs as $entry) {
                 if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted
                   or !has_capability('moodle/course:view', $course_context , $entry->userid)) {
-                    delete_records('glossary_ratings', 'entryid', $entry->id);
-                    delete_records('glossary_comments', 'entryid', $entry->id);
-                    delete_records('glossary_entries', 'id', $entry->id);
+                    $DB->delete_records('glossary_ratings', array('entryid'=>$entry->id));
+                    $DB->delete_records('glossary_comments', array('entryid'=>$entry->id));
+                    $DB->delete_records('glossary_entries', array('id'=>$entry->id));
                     fulldelete("$CFG->dataroot/$data->courseid/moddata/glossary/$entry->glossaryid");
                     $notenrolled[$entry->userid] = true;
                 }
             }
-            rs_close($rs);
+            $rs->close();
             $status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'glossary'), 'error'=>false);
         }
     }
 
     // remove all ratings
     if (!empty($data->reset_glossary_ratings)) {
-        delete_records_select('glossary_ratings', "entryid IN ($allentriessql)");
+        $DB->delete_records_select('glossary_ratings', "entryid IN ($allentriessql)", $params);
         // remove all grades from gradebook
         if (empty($data->reset_gradebook_grades)) {
             glossary_reset_gradebook($data->courseid);
@@ -2321,7 +2290,7 @@ function glossary_reset_userdata($data) {
 
     // remove all comments
     if (!empty($data->reset_glossary_comments)) {
-        delete_records_select('glossary_comments', "entryid IN ($allentriessql)");
+        $DB->delete_records_select('glossary_comments', "entryid IN ($allentriessql)", $params);
         $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
     }
 
index cba6ee12ba9d0ad1392a06bb91d14081a4162a2a..b50c290e283e74531615aa61cd96ffae1f9e226e 100644 (file)
@@ -151,11 +151,12 @@ class mod_glossary_mod_form extends moodleform_mod {
     }
 
     function definition_after_data() {
+        global $COURSE, $DB;
+
         parent::definition_after_data();
-        global $COURSE;
         $mform    =& $this->_form;
         $mainglossaryel =& $mform->getElement('mainglossary');
-        $mainglossary = get_record('glossary', 'mainglossary', 1, 'course', $COURSE->id);
+        $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
         if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
             //secondary glossary, a main one already exists in this course.
             $mainglossaryel->setValue(0);
index c2390ba44c46e0010b0e9e320c4a9b278961ef8f..78bcbae260082a682f210bc10129562a2848a7e2 100644 (file)
         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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+    if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
         print_error('invalidid', 'glossary');
     }
 
@@ -44,7 +44,7 @@
 
 /// setting the default values for the display mode of the current glossary
 /// only if the glossary is viewed by the first time
-    if ( $dp = get_record('glossary_formats','name', addslashes($glossary->displayformat)) ) {
+    if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
         $printpivot = $dp->showgroup;
         if ( $mode == '' and $hook == '' and $show == '') {
             $mode      = $dp->defaultmode;
@@ -88,7 +88,7 @@
     case 'cat':    /// Looking for a certain cat
         $tab = GLOSSARY_CATEGORY_VIEW;
         if ( $hook > 0 ) {
-            $category = get_record("glossary_categories","id",$hook);
+            $category = $DB->get_record("glossary_categories", array("id"=>$hook));
         }
     break;
 
         $alphabet = explode(",", get_string("alphabet"));
     }
 
-    $site = get_record("course","id",1);
+    $site = $DB->get_record("course", array("id"=>1));
     echo '<p style="text-align:right"><span style="font-size:0.75em">' . userdate(time()) . '</span></p>';
     echo get_string("site") . ': <strong>' . format_string($site->fullname) . '</strong><br />';
     echo get_string("course") . ': <strong>' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</strong><br />';
                     $pivottoshow = $currentpivot;
                     if ( isset($entry->userispivot) ) {
                         // printing the user icon if defined (only when browsing authors)
-                        $user = get_record("user","id",$entry->userid);
+                        $user = $DB->get_record("user", array("id"=>$entry->userid));
                         $pivottoshow = fullname($user);
                     }
 
index 5e86bb0a45dcd86e39ce3ff023b0f96ae3fc9cda..f12396dcbc6d84fb159ccedfa3fa31559447c27d 100644 (file)
@@ -8,11 +8,11 @@
 
     $glossaryid = required_param('glossaryid', PARAM_INT); // The forum the rated posts are from
 
-    if (!$glossary = get_record('glossary', 'id', $glossaryid)) {
+    if (!$glossary = $DB->get_record('glossary', array('id'=>$glossaryid))) {
         print_error('invalidid', 'glossary');
     }
 
-    if (!$course = get_record('course', 'id', $glossary->course)) {
+    if (!$course = $DB->get_record('course', array('id'=>$glossary->course))) {
         print_error('invalidcourseid');
     }
 
         $returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id;
     }
 
-    if ($data = data_submitted()) {    // form submitted
+    if ($data = data_submitted(false)) {    // form submitted
         foreach ((array)$data as $entryid => $rating) {
             if (!is_numeric($entryid)) {
                 continue;
             }
-            if (!$entry = get_record('glossary_entries', 'id', $entryid)) {
+            if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) {
                 continue;
             }
 
                 continue;
             }
 
-            if ($oldrating = get_record("glossary_ratings", "userid", $USER->id, "entryid", $entry->id)) {
+            if ($oldrating = $DB->get_record("glossary_ratings", array("userid"=>$USER->id, "entryid"=>$entry->id))) {
                 //Check if we must delete the rate
                 if ($rating == -999) {
-                    delete_records('glossary_ratings','userid',$oldrating->userid, 'entryid',$oldrating->entryid);
+                    $DB->delete_records('glossary_ratings', array('userid'=>$oldrating->userid, 'entryid'=>$oldrating->entryid));
                     glossary_update_grades($glossary, $entry->userid);
 
                 } else if ($rating != $oldrating->rating) {
                     $oldrating->rating = $rating;
                     $oldrating->time = time();
-                    if (! update_record("glossary_ratings", $oldrating)) {
+                    if (! $DB->update_record("glossary_ratings", $oldrating)) {
                         print_error('cannotinsertrate', '', '', array($entry, $rating));
                     }
                     glossary_update_grades($glossary, $entry->userid);
@@ -89,7 +89,7 @@
                 $newrating->entryid = $entry->id;
                 $newrating->rating  = $rating;
 
-                if (! insert_record("glossary_ratings", $newrating)) {
+                if (! $DB->insert_record("glossary_ratings", $newrating)) {
                     print_error('cannotinsertrate', '', '', array($entry->id, $rating));
                 }
                 glossary_update_grades($glossary, $entry->userid);
index 6041af468aa8f84a1ebf1fa8da89d2a8375978bb..a5c9ae065884f4daaf75828824f4a1035a48f6ec 100644 (file)
@@ -8,15 +8,15 @@
     $id   = required_param('id', PARAM_INT);
     $sort = optional_param('sort', '', PARAM_ALPHA);
 
-    if (! $entry = get_record('glossary_entries', 'id', $id)) {
+    if (! $entry = $DB->get_record('glossary_entries', array('id'=>$id))) {
         print_error('invalidentry');
     }
 
-    if (! $glossary = get_record('glossary', 'id', $entry->glossaryid)) {
+    if (! $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
         print_error('invalidid', 'glossary');
     }
 
-    if (! $course = get_record('course', 'id', $glossary->course)) {
+    if (! $course = $DB->get_record('course', array('id'=>$glossary->course))) {
         print_error('invalidcourseid');
     }
 
index 73bccb12bbbbed437e36f3092a09de634494c7ca..f28861235c457c902ac3be8ff631825d7a5d60ca 100644 (file)
@@ -5,8 +5,7 @@
     //rss feeds generation. Foreach site glossary with rss enabled
     //build one XML rss structure.
     function glossary_rss_feeds() {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
@@ -19,7 +18,7 @@
         //It's working so we start...
         } else {
             //Iterate over all glossaries
-            if ($glossaries = get_records("glossary")) {
+            if ($glossaries = $DB->get_records("glossary")) {
                 foreach ($glossaries as $glossary) {
                     if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) {
 
@@ -83,8 +82,7 @@
     //This function return the XML rss contents about the glossary record passed as parameter
     //It returns false if something is wrong
     function glossary_rss_feed($glossary) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
     //This function returns "items" record array to be used to build the rss feed
     //for a Type=with author glossary
     function glossary_rss_feed_withauthor($glossary, $newsince=0) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $items = array();
 
+        $params = array('gid'=>$glossary->id, 'newsince'=>$newsince); 
+
         if ($newsince) {
-            $newsince = " AND e.timecreated > '$newsince'";
+            $newsince = "AND e.timecreated > :newsince";
         } else {
             $newsince = "";
         }
 
-        if ($recs = get_records_sql ("SELECT e.id AS entryid, 
-                                             e.concept AS entryconcept, 
-                                             e.definition AS entrydefinition, 
-                                             e.format AS entryformat, 
-                                             e.timecreated AS entrytimecreated, 
-                                             u.id AS userid, 
-                                             u.firstname AS userfirstname,
-                                             u.lastname AS userlastname
-                                      FROM {$CFG->prefix}glossary_entries e,
-                                           {$CFG->prefix}user u
-                                      WHERE e.glossaryid = '$glossary->id' AND
-                                            u.id = e.userid AND
-                                            e.approved = 1 $newsince
-                                      ORDER BY e.timecreated desc")) {
+        if ($recs = $DB->get_records_sql ("SELECT e.id AS entryid, 
+                                                  e.concept AS entryconcept, 
+                                                  e.definition AS entrydefinition, 
+                                                  e.format AS entryformat, 
+                                                  e.timecreated AS entrytimecreated, 
+                                                  u.id AS userid, 
+                                                  u.firstname AS userfirstname,
+                                                  u.lastname AS userlastname
+                                             FROM {glossary_entries} e,
+                                                  {user} u
+                                            WHERE e.glossaryid = :gid AND
+                                                  u.id = e.userid AND
+                                                  e.approved = 1 $newsince
+                                         ORDER BY e.timecreated desc", $params)) {
 
             //Are we just looking for new ones?  If so, then return now.
             if ($newsince) {
             }
             //Iterate over each entry to get glossary->rssarticles records
             $articlesleft = $glossary->rssarticles;
-            $item = NULL;
-            $user = NULL;
 
             $formatoptions = new object;
             $formatoptions->trusttext = true;
 
             foreach ($recs as $rec) {
-                unset($item);
-                unset($user);
+                $item = new object();
+                $user = new user();
                 $item->title = $rec->entryconcept;
                 $user->firstname = $rec->userfirstname;
                 $user->lastname = $rec->userlastname;
     //This function returns "items" record array to be used to build the rss feed
     //for a Type=without author glossary
     function glossary_rss_feed_withoutauthor($glossary, $newsince=0) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $items = array();
 
+        $params = array('gid'=>$glossary->id, 'newsince'=>$newsince); 
+
         if ($newsince) {
-            $newsince = " AND e.timecreated > '$newsince'";
+            $newsince = "AND e.timecreated > :newsince";
         } else {
             $newsince = "";
         }
 
-        if ($recs = get_records_sql ("SELECT e.id AS entryid,
-                                             e.concept AS entryconcept,
-                                             e.definition AS entrydefinition,
-                                             e.format AS entryformat,
-                                             e.timecreated AS entrytimecreated,
-                                             u.id AS userid,
-                                             u.firstname AS userfirstname,
-                                             u.lastname AS userlastname
-                                      FROM {$CFG->prefix}glossary_entries e,
-                                           {$CFG->prefix}user u
-                                      WHERE e.glossaryid = '$glossary->id' AND
-                                            u.id = e.userid AND
-                                            e.approved = 1 $newsince
-                                      ORDER BY e.timecreated desc")) {
+        if ($recs = $DB->get_records_sql ("SELECT e.id AS entryid,
+                                                  e.concept AS entryconcept,
+                                                  e.definition AS entrydefinition,
+                                                  e.format AS entryformat,
+                                                  e.timecreated AS entrytimecreated,
+                                                  u.id AS userid,
+                                                  u.firstname AS userfirstname,
+                                                  u.lastname AS userlastname
+                                             FROM {glossary_entries} e,
+                                                  {user} u
+                                            WHERE e.glossaryid = :gid AND
+                                                  u.id = e.userid AND
+                                                  e.approved = 1 $newsince
+                                         ORDER BY e.timecreated desc", $params)) {
 
             //Are we just looking for new ones?  If so, then return now.
             if ($newsince) {
 
             //Iterate over each entry to get glossary->rssarticles records
             $articlesleft = $glossary->rssarticles;
-            $item = NULL;
-            $user = NULL;
 
             $formatoptions = new object;
             $formatoptions->trusttext = true;
 
             foreach ($recs as $rec) {
-                unset($item);
-                unset($user);
+                $item = new object();
+                $user = new object();
                 $item->title = $rec->entryconcept;
                 $user->firstname = $rec->userfirstname;
                 $user->lastname = $rec->userlastname;
index ac23640c3e6aa20f8720018fbc07a6e6dc40f6df..0be9704834c84e03dc5e418ecd7b587db9d2f341 100644 (file)
@@ -56,7 +56,7 @@ asort($formats);
 
 $str = '<table>';
 foreach ($formats as $formatid=>$formatname) {
-    $recformat = get_record('glossary_formats','id',$formatid);
+    $recformat = $DB->get_record('glossary_formats', array('id'=>$formatid));
     $str .= '<tr>';
     $str .= '<td>' . $formatname . '</td>';
     $eicon = "<a title=\"".get_string("edit")."\" href=\"$CFG->wwwroot/mod/glossary/formats.php?id=$formatid&amp;mode=edit\"><img class=\"iconsmall\" src=\"../pix/t/edit.gif\" alt=\"".get_string("edit")."\" /></a>";
index 294143e27ea7cec9bac4629f4adc22e1fc52ab41..e3f1f6cad2116fef8bef4b697a3ce043fd30e027 100644 (file)
@@ -12,8 +12,8 @@
     }
 
     if ($eid) {
-        $entry = get_record("glossary_entries", "id", $eid);
-        $glossary = get_record('glossary','id',$entry->glossaryid);
+        $entry = $DB->get_record("glossary_entries", array("id"=>$eid));
+        $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid));
         $entry->glossaryname = format_string($glossary->name,true);
         if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) {
             print_error("invalidcoursemodule");
@@ -39,7 +39,7 @@
     }
 
     if (!empty($courseid)) {
-        $course = get_record("course", "id", $courseid);
+        $course = $DB->get_record("course", array("id"=>$courseid));
         if ($course->id != SITEID) {
             require_login($courseid);
         }
index 75279803fdb35f613d4016168253ca73a2fefe36..f86041d270a33cfae2b3f081455fcf12dcf34831 100644 (file)
@@ -4,7 +4,7 @@
  * SQL.PHP
  *    This file is include from view.php and print.php
  * @version $Id$
- * @copyright 2003 
+ * @copyright 2003
  **/
 
 /// Creating the SQL statements
     $textlib = textlib_get_instance();
 
 /// Calculate the SQL sortkey to be used by the SQL statements later
-    switch ( $sortkey ) {    
-        case "CREATION": 
+    switch ( $sortkey ) {
+        case "CREATION":
             $sqlsortkey = "timecreated";
             break;
-        case "UPDATE": 
+        case "UPDATE":
             $sqlsortkey = "timemodified";
             break;
-        case "FIRSTNAME": 
+        case "FIRSTNAME":
             $sqlsortkey = "firstname";
             break;
-        case "LASTNAME": 
+        case "LASTNAME":
             $sqlsortkey = "lastname";
             break;
     }
 /// printpivot indicate if the pivot should be printed or not
 
     $fullpivot = 1;
+    $params = array('gid1'=>$glossary->id, 'gid2'=>$glossary->id, 'myid'=>$USER->id, 'hook'=>$hook);
 
     $userid = '';
     if ( !empty($USER->id) ) {
-        $userid = "OR ge.userid = $USER->id";
+        $userid = "OR ge.userid = :myid";
     }
     switch ($tab) {
     case GLOSSARY_CATEGORY_VIEW:
-        if ($hook == GLOSSARY_SHOW_ALL_CATEGORIES  ) { 
+        if ($hook == GLOSSARY_SHOW_ALL_CATEGORIES  ) {
 
             $sqlselect = "SELECT gec.id AS cid, ge.*, gec.entryid, gc.name AS glossarypivot";
-            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge,
-                         {$CFG->prefix}glossary_entries_categories gec,
-                         {$CFG->prefix}glossary_categories gc";
-            $sqlwhere  = "WHERE (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND
+            $sqlfrom   = "FROM {glossary_entries} ge,
+                               {glossary_entries_categories} gec,
+                               {glossary_categories} gc";
+            $sqlwhere  = "WHERE (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2) AND
                           ge.id = gec.entryid AND gc.id = gec.categoryid AND
-                          (ge.approved != 0 $userid)";
+                          (ge.approved <> 0 $userid)";
 
             $sqlorderby = ' ORDER BY gc.name, ge.concept';
 
-        } elseif ($hook == GLOSSARY_SHOW_NOT_CATEGORISED ) { 
+        } elseif ($hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
 
             $printpivot = 0;
             $sqlselect = "SELECT ge.*, concept AS glossarypivot";
-            $sqlfrom   = "FROM {$CFG->prefix}glossary_entries ge LEFT JOIN {$CFG->prefix}glossary_entries_categories gec
-                          ON ge.id = gec.entryid";
-            $sqlwhere  = "WHERE (glossaryid = '$glossary->id' OR sourceglossaryid = '$glossary->id') AND
-                          (ge.approved != 0 $userid) AND gec.entryid IS NULL";
+            $sqlfrom   = "FROM {glossary_entries} ge LEFT JOIN {glossary_entries_categories} gec
+                               ON ge.id = gec.entryid";
+            $sqlwhere  = "WHERE (glossaryid = :gid1 OR sourceglossaryid = :gid2) AND
+                          (ge.approved <> 0 $userid) AND gec.entryid IS NULL";
 
 
             $sqlorderby = ' ORDER BY concept';
 
             $printpivot = 0;
             $sqlselect  = "SELECT ge.*, ce.entryid, c.name AS glossarypivot";
-            $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories ce, {$CFG->prefix}glossary_categories c";
-            $sqlwhere   = "WHERE ge.id = ce.entryid AND ce.categoryid = '$hook' AND
+            $sqlfrom    = "FROM {glossary_entries} ge, {glossary_entries_categories} ce, {glossary_categories} c";
+            $sqlwhere   = "WHERE ge.id = ce.entryid AND ce.categoryid = :hook AND
                                  ce.categoryid = c.id AND ge.approved != 0 AND
-                                 (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND
-                          (ge.approved != 0 $userid)";
+                                 (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2) AND
+                          (ge.approved <> 0 $userid)";
 
             $sqlorderby = ' ORDER BY c.name, ge.concept';
 
     case GLOSSARY_AUTHOR_VIEW:
 
         $where = '';
+        $params['hookup'] = $textlib->strtoupper($hook);
 
         if ( $sqlsortkey == 'firstname' ) {
-            $usernamefield = sql_fullname('u.firstname' , 'u.lastname');
+            $usernamefield = $DB->sql_fullname('u.firstname' , 'u.lastname');
         } else {
-            $usernamefield = sql_fullname('u.lastname' , 'u.firstname');
+            $usernamefield = $DB->sql_fullname('u.lastname' , 'u.firstname');
         }
-        $where = "AND " . sql_substr() . "(upper($usernamefield),1," .  $textlib->strlen($hook) . ") = '" . $textlib->strtoupper($hook) . "'";
+        $where = "AND " . $DB->sql_substr() . "(upper($usernamefield),1," .  $textlib->strlen($hook) . ") = :hookup";
 
         if ( $hook == 'ALL' ) {
             $where = '';
         }
 
         $sqlselect  = "SELECT ge.*, $usernamefield AS glossarypivot, 1 AS userispivot ";
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}user u";
+        $sqlfrom    = "FROM {glossary_entries} ge, {user} u";
         $sqlwhere   = "WHERE ge.userid = u.id  AND
-                             (ge.approved != 0 $userid)
-                             $where AND 
-                             (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id')";
+                             (ge.approved <> 0 $userid)
+                             $where AND
+                             (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2)";
         $sqlorderby = "ORDER BY $usernamefield $sqlsortorder, ge.concept";
     break;
     case GLOSSARY_APPROVAL_VIEW:
         $printpivot = 0;
 
         $where = '';
+        $params['hookup'] = $textlib->strtoupper($hook);
+
         if ($hook != 'ALL' and $hook != 'SPECIAL') {
-            $where = 'AND ' . sql_substr() . '(upper(concept),1,' .  $textlib->strlen($hook) . ') = \'' . $textlib->strtoupper($hook) . '\'';
+            $where = 'AND ' . $DB->sql_substr() . '(upper(concept),1,' .  $textlib->strlen($hook) . ') = :hookup';
         }
 
         $sqlselect  = "SELECT ge.*, ge.concept AS glossarypivot";
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
-        $sqlwhere   = "WHERE (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND
+        $sqlfrom    = "FROM {glossary_entries} ge";
+        $sqlwhere   = "WHERE (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2) AND
                              ge.approved = 0 $where";
-                             
+
         if ( $sqlsortkey ) {
             $sqlorderby = "ORDER BY $sqlsortkey $sqlsortorder";
         } else {
     case GLOSSARY_STANDARD_VIEW:
     default:
         $sqlselect  = "SELECT ge.*, ge.concept AS glossarypivot";
-        $sqlfrom    = "FROM {$CFG->prefix}glossary_entries ge";
+        $sqlfrom    = "FROM {glossary_entries} ge";
 
         $where = '';
         $fullpivot = 0;
-        $LIKE = sql_ilike();
-        $NOTLIKE = 'NOT ' . $LIKE;
 
         switch ( $mode ) {
-        case 'search': 
+        case 'search':
 
-            /// Some differences in syntax for PostgreSQL
-            if ($CFG->dbfamily == "postgres") {
-                $REGEXP = "~*";
-                $NOTREGEXP = "!~*";
-            } else {
-                $REGEXP = "REGEXP";
-                $NOTREGEXP = "NOT REGEXP";
+            if ($DB->sql_regex_supported()) {
+                $REGEXP    = $DB->sql_regex(true);
+                $NOTREGEXP = $DB->sql_regex(false);
             }
+            $LIKE = $DB->sql_ilike(); // case-insensitive
+
+            $searchcond = array();
+            $alcond     = array();
+            $params     = array();
+            $i = 0;
 
-            $conceptsearch = "";
-            $aliassearch = "";
-            $definitionsearch = "";
+            $concat = $DB->sql_concat('ge.concept', "' '", 'ge.definition',"' '", "COALESCE(al.alial, '')");
 
             $searchterms = explode(" ",$hook);
 
             foreach ($searchterms as $searchterm) {
+                $i++;
 
-                if ($conceptsearch) {
-                    $conceptsearch .= " AND ";
-                }
-                if ($aliassearch) {
-                    $aliassearch .= " AND ";
-                }
-                if ($definitionsearch) {
-                    $definitionsearch .= " AND ";
-                }
+                $NOT = ''; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
+                           /// will use it to simulate the "-" operator with LIKE clause
 
             /// Under Oracle and MSSQL, trim the + and - operators and perform
-            /// simpler LIKE search
-                if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
+            /// simpler LIKE (or NOT LIKE) queries
+                if (!$DB->sql_regex_supported()) {
+                    if (substr($searchterm, 0, 1) == '-') {
+                        $NOT = ' NOT ';
+                    }
                     $searchterm = trim($searchterm, '+-');
                 }
 
-                if (substr($searchterm,0,1) == "+") {
-                    $searchterm = substr($searchterm,1);
-                    $conceptsearch .= " ge.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
-                    $aliassearch .= " al.alias $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
-                    $definitionsearch .= " ge.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
+                if (substr($searchterm,0,1) == '+') {
+                    $searchterm = trim($searchterm, '+-');
+                    if ($textlib->strlen($searchterm) < 2) {
+                        continue;
+                    }
+                    $searchterm = preg_quote($searchterm, '|');
+                    $searchcond[] = "$concat $REGEXP :ss$i";
+                    $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
+
                 } else if (substr($searchterm,0,1) == "-") {
-                    $searchterm = substr($searchterm,1);
-                    $conceptsearch .= " ge.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
-                    $aliassearch .= " al.alias $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
-                    $definitionsearch .= " ge.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
+                    $searchterm = trim($searchterm, '+-');
+                    if ($textlib->strlen($searchterm) < 2) {
+                        continue;
+                    }
+                    $searchterm = preg_quote($searchterm, '|');
+                    $searchcond[] = "$concat $NOTREGEXP :ss$i";
+                    $params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
+
                 } else {
-                    $conceptsearch .= " ge.concept $LIKE '%$searchterm%' ";
-                    $aliassearch .= " al.alias $LIKE '%$searchterm%' ";
-                    $definitionsearch .= " ge.definition $LIKE '%$searchterm%' ";
-                }
-            }
-     
-            //Search in aliases first
-            $idaliases = '';
-            $listaliases = array();
-            $recaliases = get_records_sql ("SELECT al.id, al.entryid
-                                              FROM {$CFG->prefix}glossary_alias al,
-                                                   {$CFG->prefix}glossary_entries ge
-                                              WHERE (ge.glossaryid = '$glossary->id' OR
-                                                     ge.sourceglossaryid = '$glossary->id') AND
-                                                    (ge.approved != 0 $userid) AND
-                                                    ge.id = al.entryid AND
-                                                    $aliassearch");
-            //Process aliases id
-            if ($recaliases) {
-                foreach ($recaliases as $recalias) {
-                    $listaliases[] = $recalias->entryid;
+                    if ($textlib->strlen($searchterm) < 2) {
+                        continue;
+                    }
+                    $searchcond[] = "$concat $NOT $LIKE :ss$i";
+                    $params['ss'.$i] = "%$searchterm%";
                 }
-                $idaliases = implode (',',$listaliases);
             }
-           
-            //Add seach conditions in concepts and, if needed, in definitions
-            $printpivot = 0;
-            $where = "AND (( $conceptsearch) ";
 
-            //Include aliases id if found
-            if (!empty($idaliases)) {
-                $where .= " OR ge.id IN ($idaliases) ";
-            }
+            if (empty($searchcond)) {
+                $where = " 1=2 "; // no search result
 
-            //Include search in definitions if requested
-            if ( $fullsearch ) {
-                $where .= " OR ($definitionsearch) )";
             } else {
-                $where .= ")";
+                $searchcond = implode(" AND ", $searchcond);
+
+                $sqlselect  = "SELECT DISTINCT ge.*, ge.concept AS glossarypivot";
+                $sqlfrom    = "FROM {glossary_entries} ge
+                               LEFT JOIN {glossary_alias} al ON al.entryid = ge.id";
+                $where      = "AND ($searchcond)";
             }
 
         break;
-        
-        case 'term': 
+
+        case 'term':
+            $params['hook2'] = $hook;
             $printpivot = 0;
-            $sqlfrom .= " left join {$CFG->prefix}glossary_alias ga on ge.id = ga.entryid ";
-            $where = "AND (ge.concept = '$hook' OR ga.alias = '$hook' )
-                     ";
+            $sqlfrom .= " LEFT JOIN {glossary_alias} ga on ge.id = ga.entryid";
+            $where = "AND (ge.concept = :hook OR ga.alias = :hook2) ";
         break;
 
-        case 'entry': 
+        case 'entry':
             $printpivot = 0;
-            $where = "AND ge.id = '$hook'";
+            $where = "AND ge.id = :hook";
         break;
 
-        case 'letter': 
+        case 'letter':
             if ($hook != 'ALL' and $hook != 'SPECIAL') {
-                $where = 'AND ' . sql_substr() . '(upper(concept),1,' .  $textlib->strlen($hook) . ') = \'' . $textlib->strtoupper($hook) . '\'';
+                $params['hookup'] = $textlib->strtoupper($hook);
+                $where = 'AND ' . $DB->sql_substr() . '(upper(concept),1,' .  $textlib->strlen($hook) . ') = :hookup';
             }
             if ($hook == 'SPECIAL') {
                 //Create appropiate IN contents
                 $alphabet = explode(",", get_string("alphabet"));
-                $sqlalphabet = '';
-                for ($i = 0; $i < count($alphabet); $i++) {
-                    if ($i != 0) {
-                        $sqlalphabet .= ',';
-                    }
-                    $sqlalphabet .= '\''.$alphabet[$i].'\'';
-                }
-                $where = 'AND ' . sql_substr() . '(upper(concept),1,1) NOT IN (' . $textlib->strtoupper($sqlalphabet) . ')';
+                list($nia, $aparams) = $DB->get_in_or_equal($alphabet, SQL_PARAMS_NAMED, $start='a0', false);
+                $params = array_merge($params, $aparams);
+                $where = 'AND ' . $DB->sql_substr() . "(upper(concept),1,1) $nia";
             }
         break;
         }
-        
-        $sqlwhere   = "WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND
-                             (ge.approved != 0 $userid)
+
+        $sqlwhere   = "WHERE (ge.glossaryid = :gid1 or ge.sourceglossaryid = :gid2) AND
+                             (ge.approved <> 0 $userid)
                               $where";
         switch ( $tab ) {
-        case GLOSSARY_DATE_VIEW: 
+        case GLOSSARY_DATE_VIEW:
             $sqlorderby = "ORDER BY $sqlsortkey $sqlsortorder";
         break;
-        
-        case GLOSSARY_STANDARD_VIEW: 
+
+        case GLOSSARY_STANDARD_VIEW:
             $sqlorderby = "ORDER BY ge.concept";
         default:
         break;
         }
     break;
-    } 
-    $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
+    }
+    $count = $DB->count_records_sql("SELECT COUNT(DISTINCT(ge.id)) $sqlfrom $sqlwhere", $params);
 
     $limitfrom = $offset;
     $limitnum = 0;
-    
+
     if ( $offset >= 0 ) {
         $limitnum = $entriesbypage;
     }
 
-    $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby", $limitfrom, $limitnum);
+    $allentries = $DB->get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby", $params, $limitfrom, $limitnum);
 ?>
index e9673df27610e1d8dc81aaba2cf81d7f7ff02738..31b8dfced1713cfe9c32efc38950f453c15aaba5 100644 (file)
         if (! $cm = get_coursemodule_from_id('glossary', $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 (! $glossary = get_record("glossary", "id", $cm->instance)) {
+        if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
             print_error('invalidid', 'glossary');
         }
     } else if (!empty($g)) {
-        if (! $glossary = get_record("glossary", "id", $g)) {
+        if (! $glossary = $DB->get_record("glossary", array("id"=>$g))) {
             print_error('invalidid', 'glossary');
         }
-        if (! $course = get_record("course", "id", $glossary->course)) {
+        if (! $course = $DB->get_record("course", array("id"=>$glossary->course))) {
             print_error('invalidcourseid');
         }
         if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id)) {
@@ -68,7 +68,7 @@
 
 /// setting the default values for the display mode of the current glossary
 /// only if the glossary is viewed by the first time
-    if ( $dp = get_record('glossary_formats','name', addslashes($glossary->displayformat)) ) {
+    if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
     /// Based on format->defaultmode, we build the defaulttab to be showed sometimes
         switch ($dp->defaultmode) {
             case 'cat':
 
     case 'entry':  /// Looking for a certain entry id
         $tab = GLOSSARY_STANDARD_VIEW;
-        if ( $dp = get_record("glossary_formats","name", $glossary->displayformat) ) {
+        if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat)) ) {
             $displayformat = $dp->popupformatname;
         }
     break;
     case 'cat':    /// Looking for a certain cat
         $tab = GLOSSARY_CATEGORY_VIEW;
         if ( $hook > 0 ) {
-            $category = get_record("glossary_categories","id",$hook);
+            $category = $DB->get_record("glossary_categories", array("id"=>$hook));
         }
     break;
 
     /// Decide about to print the approval link
         if (has_capability('mod/glossary:approve', $context)) {
         /// Check we have pending entries
-            if ($hiddenentries = count_records_select('glossary_entries',"glossaryid  = $glossary->id and approved = 0")) {
+            if ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$glossary->id, 'approved'=>0))) {
                 if ($availableoptions) {
                     $availableoptions .= '<br />';
                 }
                     // printing the user icon if defined (only when browsing authors)
                         echo '<th align="left">';
 
-                        $user = get_record("user","id",$entry->userid);
+                        $user = $DB->get_record("user", array("id"=>$entry->userid));
                         print_user_picture($user, $course->id, $user->picture);
                         $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
                     } else {
 
         echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"".get_string("sendinratings", "glossary")."\" />";
         if ($glossary->scale < 0) {
-            if ($scale = get_record("scale", "id", abs($glossary->scale))) {
+            if ($scale = $DB->get_record("scale", array("id"=>abs($glossary->scale)))) {
                 print_scale_menu_helpbutton($course->id, $scale );
             }
         }