MDL-15109 glossary dml conversion

This commit is contained in:
skodak 2008-06-08 10:43:39 +00:00
parent ea05eebf92
commit ae8c356614
27 changed files with 558 additions and 628 deletions

View file

@ -13,11 +13,11 @@
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); 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'); print_error('invalidid', 'glossary');
} }
@ -26,11 +26,12 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:approve', $context); require_capability('mod/glossary:approve', $context);
$newentry = new object();
$newentry->id = $eid; $newentry->id = $eid;
$newentry->approved = 1; $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 $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'); print_error('cantupdateglossary', 'glossary');
} else { } else {
add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id); add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id);

View file

@ -29,13 +29,12 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
function glossary_backup_mods($bf,$preferences) { function glossary_backup_mods($bf,$preferences) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
//Iterate over glossary table //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) { if ($glossaries) {
foreach ($glossaries as $glossary) { foreach ($glossaries as $glossary) {
if (backup_mod_selected($preferences,'glossary',$glossary->id)) { if (backup_mod_selected($preferences,'glossary',$glossary->id)) {
@ -47,11 +46,10 @@
} }
function glossary_backup_one_mod($bf,$preferences,$glossary) { function glossary_backup_one_mod($bf,$preferences,$glossary) {
global $CFG, $DB;
global $CFG;
if (is_numeric($glossary)) { if (is_numeric($glossary)) {
$glossary = get_record('glossary','id',$glossary); $glossary = $DB->get_record('glossary', array('id'=>$glossary));
} }
$status = true; $status = true;
@ -100,12 +98,11 @@
//Backup glossary_categories and entries_categories contents (executed from glossary_backup_mods) //Backup glossary_categories and entries_categories contents (executed from glossary_backup_mods)
function backup_glossary_categories ($bf,$preferences,$glossary, $userinfo) { function backup_glossary_categories ($bf,$preferences,$glossary, $userinfo) {
global $CFG, $DB;
global $CFG;
$status = true; $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 there is categories
if ($glossary_categories) { if ($glossary_categories) {
$status =fwrite ($bf,start_tag("CATEGORIES",4,true)); $status =fwrite ($bf,start_tag("CATEGORIES",4,true));
@ -137,12 +134,11 @@
//Backup entries_categories contents (executed from backup_glossary_categories) //Backup entries_categories contents (executed from backup_glossary_categories)
function backup_glossary_entries_categories ($bf,$preferences,$categoryid) { function backup_glossary_entries_categories ($bf,$preferences,$categoryid) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
$entries = get_records("glossary_entries_categories","categoryid",$categoryid); $entries = $DB->get_records("glossary_entries_categories", array("categoryid"=>$categoryid));
if ($entries) { if ($entries) {
$status =fwrite ($bf,start_tag("ENTRIES",6,true)); $status =fwrite ($bf,start_tag("ENTRIES",6,true));
foreach ($entries as $entry) { foreach ($entries as $entry) {
@ -157,12 +153,11 @@
//Backup glossary_entries contents (executed from glossary_backup_mods) //Backup glossary_entries contents (executed from glossary_backup_mods)
function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) { function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {
global $CFG, $DB;
global $CFG;
$status = true; $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 there is entries
if ($glossary_entries) { if ($glossary_entries) {
$dumped_entries = 0; $dumped_entries = 0;
@ -219,12 +214,11 @@
//Backup glossary_comments contents (executed from backup_glossary_entries) //Backup glossary_comments contents (executed from backup_glossary_entries)
function backup_glossary_comments ($bf,$preferences,$entryid) { function backup_glossary_comments ($bf,$preferences,$entryid) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
$comments = get_records("glossary_comments","entryid",$entryid); $comments = $DB->get_records("glossary_comments", array("entryid"=>$entryid));
if ($comments) { if ($comments) {
$status =fwrite ($bf,start_tag("COMMENTS",6,true)); $status =fwrite ($bf,start_tag("COMMENTS",6,true));
foreach ($comments as $comment) { foreach ($comments as $comment) {
@ -245,12 +239,11 @@
//Backup glossary_ratings contents (executed from backup_glossary_entries) //Backup glossary_ratings contents (executed from backup_glossary_entries)
function backup_glossary_ratings ($bf,$preferences,$entryid) { function backup_glossary_ratings ($bf,$preferences,$entryid) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
$ratings = get_records("glossary_ratings","entryid",$entryid); $ratings = $DB->get_records("glossary_ratings", array("entryid"=>$entryid));
if ($ratings) { if ($ratings) {
$status =fwrite ($bf,start_tag("RATINGS",6,true)); $status =fwrite ($bf,start_tag("RATINGS",6,true));
foreach ($ratings as $rating) { foreach ($ratings as $rating) {
@ -270,12 +263,11 @@
//Backup glossary_alias contents (executed from backup_glossary_entries) //Backup glossary_alias contents (executed from backup_glossary_entries)
function backup_glossary_aliases ($bf,$preferences,$entryid) { function backup_glossary_aliases ($bf,$preferences,$entryid) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
$aliases = get_records("glossary_alias","entryid",$entryid); $aliases = $DB->get_records("glossary_alias", array("entryid"=>$entryid));
if ($aliases) { if ($aliases) {
$status =fwrite ($bf,start_tag("ALIASES",6,true)); $status =fwrite ($bf,start_tag("ALIASES",6,true));
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
@ -293,7 +285,6 @@
//Backup glossary files because we've selected to backup user info //Backup glossary files because we've selected to backup user info
//or current entry is a teacher entry //or current entry is a teacher entry
function backup_glossary_files($bf,$preferences,$glossary,$entry) { function backup_glossary_files($bf,$preferences,$glossary,$entry) {
global $CFG; global $CFG;
$status = true; $status = true;
@ -399,33 +390,28 @@
//Returns an array of glossaries id //Returns an array of glossaries id
function glossary_ids ($course) { function glossary_ids ($course) {
global $DB;
global $CFG; return $DB->get_records_sql ("SELECT a.id, a.course
FROM {glossary} a
return get_records_sql ("SELECT a.id, a.course WHERE a.course = ?", array($course));
FROM {$CFG->prefix}glossary a
WHERE a.course = '$course'");
} }
//Returns an array of glossary_answers id //Returns an array of glossary_answers id
function glossary_entries_ids_by_course ($course) { function glossary_entries_ids_by_course ($course) {
global $DB;
global $CFG; return $DB->get_records_sql ("SELECT s.id , s.glossaryid
FROM {glossary_entries} s, {glossary} a
return get_records_sql ("SELECT s.id , s.glossaryid WHERE a.course = ? AND s.glossaryid = a.id", array($course));
FROM {$CFG->prefix}glossary_entries s,
{$CFG->prefix}glossary a
WHERE a.course = '$course' AND
s.glossaryid = a.id");
} }
//Returns an array of glossary_answers id //Returns an array of glossary_answers id
function glossary_entries_ids_by_instance ($instanceid) { function glossary_entries_ids_by_instance ($instanceid) {
global $DB;
global $CFG; return $DB->get_records_sql ("SELECT s.id , s.glossaryid
FROM {glossary_entries} s
return get_records_sql ("SELECT s.id , s.glossaryid WHERE s.glossaryid = ?", array($instanceid));
FROM {$CFG->prefix}glossary_entries s
WHERE s.glossaryid = $instanceid");
} }
?> ?>

View file

@ -28,20 +28,20 @@ switch ($action) {
* Add new comment * Add new comment
*/ */
function glossary_comment_add() { function glossary_comment_add() {
global $USER; global $USER, $DB;
$eid = optional_param('eid', 0, PARAM_INT); // Entry ID $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'); 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'); print_error('invalidid', 'glossary');
} }
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) { if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (!$course = get_record('course', 'id', $cm->course)) { if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
@ -59,7 +59,7 @@ function glossary_comment_add() {
redirect("comments.php?id=$cm->id&eid=$entry->id"); redirect("comments.php?id=$cm->id&eid=$entry->id");
} }
if ($data = $mform->get_data()) { if ($data = $mform->get_data(false)) {
trusttext_after_edit($data->entrycomment, $context); trusttext_after_edit($data->entrycomment, $context);
$newcomment = new object(); $newcomment = new object();
@ -69,7 +69,7 @@ function glossary_comment_add() {
$newcomment->timemodified = time(); $newcomment->timemodified = time();
$newcomment->userid = $USER->id; $newcomment->userid = $USER->id;
if (!$newcomment->id = insert_record('glossary_comments', $newcomment)) { if (!$newcomment->id = $DB->insert_record('glossary_comments', $newcomment)) {
print_error('cannotinsertcomment'); print_error('cannotinsertcomment');
} else { } else {
add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newcomment->id", $cm->id); add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newcomment->id", $cm->id);
@ -88,24 +88,24 @@ function glossary_comment_add() {
* Deleting existing comments * Deleting existing comments
*/ */
function glossary_comment_delete() { function glossary_comment_delete() {
global $USER; global $USER, $DB;
$cid = optional_param('cid', 0, PARAM_INT); // Comment ID $cid = optional_param('cid', 0, PARAM_INT); // Comment ID
$confirm = optional_param('confirm', 0, PARAM_BOOL); // delete confirmation $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'); 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'); 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'); print_error('invalidid', 'glossary');
} }
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) { if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (!$course = get_record('course', 'id', $cm->course)) { if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
@ -119,7 +119,7 @@ function glossary_comment_delete() {
} }
if (data_submitted() and $confirm) { 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&eid=$entry->id", "$comment->id",$cm->id); add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&eid=$entry->id", "$comment->id",$cm->id);
redirect("comments.php?id=$cm->id&eid=$entry->id"); redirect("comments.php?id=$cm->id&eid=$entry->id");
@ -142,23 +142,23 @@ function glossary_comment_delete() {
* Edit existing comments * Edit existing comments
*/ */
function glossary_comment_edit() { function glossary_comment_edit() {
global $CFG, $USER; global $CFG, $USER, $DB;
$cid = optional_param('cid', 0, PARAM_INT); // Comment ID $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'); 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'); 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'); print_error('invalidid', 'glossary');
} }
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) { if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (!$course = get_record('course', 'id', $cm->course)) { if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
@ -179,7 +179,7 @@ function glossary_comment_edit() {
trusttext_prepare_edit($comment->entrycomment, $comment->format, can_use_html_editor(), $context); 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)); $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); trusttext_after_edit($data->entrycomment, $context);
$updatedcomment = new object(); $updatedcomment = new object();
@ -188,7 +188,7 @@ function glossary_comment_edit() {
$updatedcomment->format = $data->format; $updatedcomment->format = $data->format;
$updatedcomment->timemodified = time(); $updatedcomment->timemodified = time();
if (!update_record('glossary_comments', $updatedcomment)) { if (!$DB->update_record('glossary_comments', $updatedcomment)) {
print_error('cannotupdatecomment'); print_error('cannotupdatecomment');
} else { } else {
add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&eid=$entry->id", "$updatedcomment->id",$cm->id); add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&eid=$entry->id", "$updatedcomment->id",$cm->id);

View file

@ -7,21 +7,19 @@
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$eid = required_param('eid', PARAM_INT); // Entry ID $eid = required_param('eid', PARAM_INT); // Entry ID
global $USER, $CFG;
if (! $cm = get_coursemodule_from_id('glossary', $id)) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
if (! $glossary = get_record("glossary", "id", $cm->instance)) { if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidcousemodule'); print_error('invalidcousemodule');
} }
if (! $entry = get_record("glossary_entries", "id", $eid)) { if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) {
print_error('invalidentry'); 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>"); 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) { foreach ($comments as $comment) {
glossary_print_comment($course, $cm, $glossary, $entry, $comment); glossary_print_comment($course, $cm, $glossary, $entry, $comment);
echo '<br />'; echo '<br />';

View file

@ -20,11 +20,11 @@
print_error("invalidcoursemodule"); print_error("invalidcoursemodule");
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
if (! $entry = get_record("glossary_entries","id", $entry)) { if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) {
print_error('invalidentry'); print_error('invalidentry');
} }
@ -32,7 +32,7 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
$manageentries = has_capability('mod/glossary:manageentries', $context); $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'); print_error('invalidid', 'glossary');
} }
@ -62,7 +62,7 @@
$dbentry->id = $entry->id; $dbentry->id = $entry->id;
$dbentry->glossaryid = $entry->sourceglossaryid; $dbentry->glossaryid = $entry->sourceglossaryid;
$dbentry->sourceglossaryid = 0; $dbentry->sourceglossaryid = 0;
if (! update_record('glossary_entries', $dbentry)) { if (! $DB->update_record('glossary_entries', $dbentry)) {
print_error('cantupdateglossary', 'glossary'); print_error('cantupdateglossary', 'glossary');
} }
@ -70,10 +70,10 @@
if ( $entry->attachment ) { if ( $entry->attachment ) {
glossary_delete_old_attachments($entry); glossary_delete_old_attachments($entry);
} }
delete_records("glossary_comments", "entryid",$entry->id); $DB->delete_records("glossary_comments", array("entryid"=>$entry->id));
delete_records("glossary_alias", "entryid", $entry->id); $DB->delete_records("glossary_alias", array("entryid"=>$entry->id));
delete_records("glossary_ratings", "entryid", $entry->id); $DB->delete_records("glossary_ratings", array("entryid"=>$entry->id));
delete_records("glossary_entries","id", $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); add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook", $entry->id,$cm->id);

View file

@ -19,7 +19,7 @@ if (! $cm = get_coursemodule_from_id('glossary', $id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->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'); print_error('coursemisconf');
} }
@ -29,13 +29,13 @@ if ( isguest() ) {
print_error('guestnoedit', 'glossary', $_SERVER["HTTP_REFERER"]); 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'); print_error('invalidid', 'glossary');
} }
if ($e) { // if entry is specified 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'); print_error('invalidentry');
} }
$ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
@ -47,7 +47,7 @@ if ($e) { // if entry is specified
require_capability('mod/glossary:write', $context); 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 ($mform->is_cancelled()){
if ($e){ if ($e){
redirect("view.php?id=$cm->id&amp;mode=entry&amp;hook=$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"); redirect("view.php?id=$cm->id");
} }
} elseif ($fromform = $mform->get_data()) { } elseif ($fromform = $mform->get_data(false)) {
trusttext_after_edit($fromform->definition, $context); trusttext_after_edit($fromform->definition, $context);
if ( !isset($fromform->usedynalink) ) { if ( !isset($fromform->usedynalink) ) {
@ -93,7 +93,7 @@ if ($mform->is_cancelled()){
$todb->attachment = $newfilename; $todb->attachment = $newfilename;
} }
if (update_record('glossary_entries', $todb)) { if ($DB->update_record('glossary_entries', $todb)) {
add_to_log($course->id, "glossary", "update entry", add_to_log($course->id, "glossary", "update entry",
"view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id", "view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id",
$todb->id, $cm->id); $todb->id, $cm->id);
@ -108,11 +108,11 @@ if ($mform->is_cancelled()){
$todb->teacherentry = has_capability('mod/glossary:manageentries', $context); $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; $e = $todb->id;
$dir = glossary_file_area_name($todb); $dir = glossary_file_area_name($todb);
if ($mform->save_files($dir) and $newfilename = $mform->get_new_filename()) { 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", add_to_log($course->id, "glossary", "add entry",
"view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id", $todb->id,$cm->id); "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); $DB->delete_records("glossary_entries_categories", array("entryid"=>$e));
delete_records("glossary_alias", "entryid", $e); $DB->delete_records("glossary_alias", array("entryid"=>$e));
if (empty($fromform->notcategorised) && isset($fromform->categories)) { if (empty($fromform->notcategorised) && isset($fromform->categories)) {
$newcategory->entryid = $e; $newcategory->entryid = $e;
foreach ($fromform->categories as $category) { foreach ($fromform->categories as $category) {
if ( $category > 0 ) { if ( $category > 0 ) {
$newcategory->categoryid = $category; $newcategory->categoryid = $category;
insert_record("glossary_entries_categories", $newcategory, false); $DB->insert_record("glossary_entries_categories", $newcategory, false);
} else { } else {
break; break;
} }
@ -141,10 +141,10 @@ if ($mform->is_cancelled()){
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
$alias = trim($alias); $alias = trim($alias);
if ($alias) { if ($alias) {
unset($newalias); $newalias = new object();
$newalias->entryid = $e; $newalias->entryid = $e;
$newalias->alias = $alias; $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 { } else {
if ($e) { if ($e) {
$fromdb = get_record("glossary_entries", "id", $e); $fromdb = $DB->get_record("glossary_entries", array("id"=>$e));
$toform = new object(); $toform = new object();

View file

@ -20,16 +20,16 @@
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
if (! $glossary = get_record("glossary", "id", $cm->instance)) { if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if ($hook > 0) { 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 //Check it belongs to the same glossary
if ($category->glossaryid != $glossary->id) { if ($category->glossaryid != $glossary->id) {
print_error('invalidid', 'glossary'); print_error('invalidid', 'glossary');
@ -63,11 +63,12 @@
if ( $action == "edit" ) { if ( $action == "edit" ) {
if ( $confirm ) { if ( $confirm ) {
$action = ""; $action = "";
$cat = new object();
$cat->id = $hook; $cat->id = $hook;
$cat->name = $name; $cat->name = $name;
$cat->usedynalink = $usedynalink; $cat->usedynalink = $usedynalink;
if ( !update_record("glossary_categories", $cat) ) { if ( !$DB->update_record("glossary_categories", $cat) ) {
print_error('cannotupdatecategory'); print_error('cannotupdatecategory');
redirect("editcategories.php?id=$cm->id"); redirect("editcategories.php?id=$cm->id");
} else { } else {
@ -85,8 +86,8 @@
} elseif ( $action == "delete" ) { } elseif ( $action == "delete" ) {
if ( $confirm ) { if ( $confirm ) {
delete_records("glossary_entries_categories","categoryid", $hook); $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
delete_records("glossary_categories","id", $hook); $DB->delete_records("glossary_categories", array("id"=>$hook));
print_simple_box_start("center","40%", "#FFBBBB"); print_simple_box_start("center","40%", "#FFBBBB");
echo "<div style=\"text-align:center\">" . get_string("categorydeleted","glossary") ."</div>"; echo "<div style=\"text-align:center\">" . get_string("categorydeleted","glossary") ."</div>";
@ -103,7 +104,7 @@
print_simple_box_start("center","40%", "#FFBBBB"); print_simple_box_start("center","40%", "#FFBBBB");
echo "<div class=\"boxaligncenter\"><b>".format_text($category->name, FORMAT_PLAIN)."</b><br/>"; 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 ) { if ( $num_entries ) {
print_string("deletingnoneemptycategory","glossary"); print_string("deletingnoneemptycategory","glossary");
} }
@ -141,7 +142,7 @@
} elseif ( $action == "add" ) { } elseif ( $action == "add" ) {
if ( $confirm ) { if ( $confirm ) {
$ILIKE = sql_ilike(); $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 ) { if ( $dupcategory ) {
echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary"); echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary");
@ -153,11 +154,12 @@
} else { } else {
$action = ""; $action = "";
$cat = new object();
$cat->name = $name; $cat->name = $name;
$cat->usedynalink = $usedynalink; $cat->usedynalink = $usedynalink;
$cat->glossaryid = $glossary->id; $cat->glossaryid = $glossary->id;
if ( ! $cat->id = insert_record("glossary_categories", $cat) ) { if ( ! $cat->id = $DB->insert_record("glossary_categories", $cat) ) {
print_error('cannotinsertcategory'); print_error('cannotinsertcategory');
redirect("editcategories.php?id=$cm->id"); redirect("editcategories.php?id=$cm->id");
@ -192,12 +194,12 @@
<?php <?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 ) { if ( $categories ) {
echo '<table width="100%">'; echo '<table width="100%">';
foreach ($categories as $category) { 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> <tr>

View file

@ -13,11 +13,11 @@
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); 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'); print_error('invalidid', 'glossary');
} }

View file

@ -17,7 +17,7 @@
if ( ! $cm ) { if ( ! $cm ) {
$PermissionGranted = 0; $PermissionGranted = 0;
} else { } else {
$mainglossary = get_record('glossary','course',$cm->course, 'mainglossary',1); $mainglossary = $DB->get_record('glossary', array('course'=>$cm->course), 'mainglossary',1);
if ( ! $mainglossary ) { if ( ! $mainglossary ) {
$PermissionGranted = 0; $PermissionGranted = 0;
} }
@ -26,11 +26,11 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:export', $context); 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'); 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'); print_error('invalidid', 'glossary');
} }
@ -42,7 +42,7 @@
print_header_simple(format_string($glossary->name), '', $navigation, '', '', true, '', navmenu($course, $cm)); print_header_simple(format_string($glossary->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
if ( $PermissionGranted ) { if ( $PermissionGranted ) {
$entry = get_record('glossary_entries', 'id', $entry); $entry = $DB->get_record('glossary_entries', array('id'=>$entry));
if ( !$confirm ) { if ( !$confirm ) {
echo '<div class="boxaligncenter">'; echo '<div class="boxaligncenter">';
@ -53,7 +53,7 @@
echo '</div>'; echo '</div>';
} else { } else {
if ( ! $mainglossary->allowduplicatedentries ) { 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 ) { if ( $dupentry ) {
$PermissionGranted = 0; $PermissionGranted = 0;
} }
@ -65,7 +65,7 @@
$dbentry->glossaryid = $mainglossary->id; $dbentry->glossaryid = $mainglossary->id;
$dbentry->sourceglossaryid = $glossary->id; $dbentry->sourceglossaryid = $glossary->id;
if (! update_record('glossary_entries', $dbentry)) { if (! $DB->update_record('glossary_entries', $dbentry)) {
print_error('cantexportentry', 'glossary'); print_error('cantexportentry', 'glossary');
} else { } else {
print_simple_box_start('center', '60%'); print_simple_box_start('center', '60%');

View file

@ -15,11 +15,11 @@
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); 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'); print_error('invalidid', 'glossary');
} }

View file

@ -42,30 +42,26 @@ function glossary_filter($courseid, $text) {
} }
/// Make a list of glossary IDs for searching /// Make a list of glossary IDs for searching
$glossarylist = ''; $glossarylist = implode(',', array_keys($glossaries));
foreach ($glossaries as $glossaryid => $glossaryname) {
$glossarylist .= $glossaryid.',';
}
$glossarylist = substr($glossarylist,0,-1);
/// Pull out all the raw data from the database for entries, categories and aliases /// Pull out all the raw data from the database for entries, categories and aliases
$entries = get_records_select('glossary_entries', $entries = $DB->get_records_select('glossary_entries',
'glossaryid IN ('.$glossarylist.') AND usedynalink != 0 AND approved != 0 ', '', 'glossaryid IN ('.$glossarylist.') AND usedynalink != 0 AND approved != 0 ', '',
'id,glossaryid, concept, casesensitive, 0 AS category, fullmatch'); 'id,glossaryid, concept, casesensitive, 0 AS category, fullmatch');
$categories = get_records_select('glossary_categories', $categories = $DB->get_records_select('glossary_categories',
'glossaryid IN ('.$glossarylist.') AND usedynalink != 0', '', 'glossaryid IN ('.$glossarylist.') AND usedynalink != 0', '',
'id,glossaryid,name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch'); '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, $aliases = $DB->get_records_sql('SELECT ga.id, ge.glossaryid, ga.alias as concept, ge.concept as originalconcept,
casesensitive, 0 AS category, fullmatch casesensitive, 0 AS category, fullmatch
FROM '.$CFG->prefix.'glossary_alias ga, FROM {glossary_alias} ga,
'.$CFG->prefix.'glossary_entries ge {glossary_entries} ge
WHERE ga.entryid = ge.id WHERE ga.entryid = ge.id
AND ge.glossaryid IN ('.$glossarylist.') AND ge.glossaryid IN ('.$glossarylist.')
AND ge.usedynalink != 0 AND ge.usedynalink != 0
AND ge.approved != 0'); AND ge.approved != 0');
/// Combine them into one big list /// Combine them into one big list

View file

@ -10,7 +10,7 @@
admin_externalpage_setup('managemodules'); // this is hacky, tehre should be a special hidden page for it 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"); error ("Invalid Glossary Format");
} }
@ -22,7 +22,7 @@
} else { } else {
$displayformat->visible = 1; $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"); redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
die; die;
@ -35,7 +35,7 @@
$displayformat->sortkey = $form->sortkey; $displayformat->sortkey = $form->sortkey;
$displayformat->sortorder = $form->sortorder; $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"); redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
die; die;
} }

View file

@ -1,11 +1,10 @@
<?php // $Id$ <?php // $Id$
function glossary_show_entry_TEMPLATE($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1, $ratings=NULL, $aliases=true) { function glossary_show_entry_TEMPLATE($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1, $ratings=NULL, $aliases=true) {
global $CFG, $USER, $DB;
global $CFG, $USER;
$user = get_record('user', 'id', $entry->userid); $user = $DB->get_record('user', array('id'=>$entry->userid));
$strby = get_string('writtenby', 'glossary'); $strby = get_string('writtenby', 'glossary');
if ($entry) { if ($entry) {

View file

@ -1,10 +1,10 @@
<?php // $Id$ <?php // $Id$
function glossary_show_entry_encyclopedia($course, $cm, $glossary, $entry, $mode='',$hook='',$printicons=1,$ratings=NULL, $aliases=true) { 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'); $strby = get_string('writtenby', 'glossary');
$return = false; $return = false;
@ -22,6 +22,7 @@ function glossary_show_entry_encyclopedia($course, $cm, $glossary, $entry, $mode
echo '</div>'; echo '</div>';
$fullname = fullname($user); $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->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.$fullname.'</a>';
$by->date = userdate($entry->timemodified); $by->date = userdate($entry->timemodified);
echo '<span class="author">'.get_string('bynameondate', 'forum', $by).'</span>'; echo '<span class="author">'.get_string('bynameondate', 'forum', $by).'</span>';

View file

@ -1,10 +1,10 @@
<?php // $Id$ <?php // $Id$
function glossary_show_entry_fullwithauthor($course, $cm, $glossary, $entry, $mode="", $hook="", $printicons=1, $ratings=NULL, $aliases=true) { 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'); $strby = get_string('writtenby', 'glossary');
$return = false; $return = false;

View file

@ -3,7 +3,6 @@
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once("$CFG->dirroot/course/lib.php"); require_once("$CFG->dirroot/course/lib.php");
global $CFG, $USER;
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
@ -19,11 +18,11 @@
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); 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'); print_error('invalidid', 'glossary');
} }
@ -146,7 +145,7 @@
// course_modules and course_sections each contain a reference // course_modules and course_sections each contain a reference
// to each other, so we have to update one of them twice. // 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'); print_error('modulenotexist', 'debug', '', 'Glossary');
} }
$mod->module = $currmodule->id; $mod->module = $currmodule->id;
@ -162,13 +161,13 @@
print_error('cannotaddcoursemoduletosection'); print_error('cannotaddcoursemoduletosection');
} }
//We get the section's visible field status //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); 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); print_error('cannotupdatemod', '', '', $mod->coursemodule);
} }
add_to_log($course->id, "course", "add mod", add_to_log($course->id, "course", "add mod",
@ -208,9 +207,9 @@
if ( !$glossary->allowduplicatedentries ) { if ( !$glossary->allowduplicatedentries ) {
// checking if the entry is valid (checking if it is duplicated when should not be) // checking if the entry is valid (checking if it is duplicated when should not be)
if ( $newentry->casesensitive ) { 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 { } 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) { if ($dupentry) {
$permissiongranted = 0; $permissiongranted = 0;
@ -225,23 +224,23 @@
$newentry->approved = 1; $newentry->approved = 1;
$newentry->userid = $USER->id; $newentry->userid = $USER->id;
$newentry->teacherentry = 1; $newentry->teacherentry = 1;
$newentry->format = addslashes($xmlentry['#']['FORMAT'][0]['#']); $newentry->format = $xmlentry['#']['FORMAT'][0]['#'];
$newentry->timecreated = time(); $newentry->timecreated = time();
$newentry->timemodified = time(); $newentry->timemodified = time();
// Setting the default values if no values were passed // Setting the default values if no values were passed
if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) { if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) {
$newentry->usedynalink = addslashes($xmlentry['#']['USEDYNALINK'][0]['#']); $newentry->usedynalink = $xmlentry['#']['USEDYNALINK'][0]['#'];
} else { } else {
$newentry->usedynalink = $CFG->glossary_linkentries; $newentry->usedynalink = $CFG->glossary_linkentries;
} }
if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) { if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) {
$newentry->fullmatch = addslashes($xmlentry['#']['FULLMATCH'][0]['#']); $newentry->fullmatch = $xmlentry['#']['FULLMATCH'][0]['#'];
} else { } else {
$newentry->fullmatch = $CFG->glossary_fullmatch; $newentry->fullmatch = $CFG->glossary_fullmatch;
} }
if ( $newentry->id = insert_record("glossary_entries",$newentry) ) { if ( $newentry->id = $DB->insert_record("glossary_entries",$newentry) ) {
$importedentries++; $importedentries++;
$xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES $xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES
@ -251,10 +250,10 @@
$aliasname = $xmlalias['#']['NAME'][0]['#']; $aliasname = $xmlalias['#']['NAME'][0]['#'];
if (!empty($aliasname)) { if (!empty($aliasname)) {
unset($newalias); $newalias = new object();
$newalias->entryid = $newentry->id; $newalias->entryid = $newentry->id;
$newalias->alias = trim(addslashes($aliasname)); $newalias->alias = trim($aliasname);
$newalias->id = insert_record("glossary_alias",$newalias); $newalias->id = $DB->insert_record("glossary_alias",$newalias);
} }
} }
@ -263,16 +262,16 @@
$xmlcats = @$xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; // ignore missing CATEGORIES $xmlcats = @$xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; // ignore missing CATEGORIES
for($k = 0; $k < sizeof($xmlcats); $k++) { for($k = 0; $k < sizeof($xmlcats); $k++) {
$xmlcat = $xmlcats[$k]; $xmlcat = $xmlcats[$k];
unset($newcat);
$newcat->name = addslashes($xmlcat['#']['NAME'][0]['#']); $newcat = new object();
$newcat->usedynalink = addslashes($xmlcat['#']['USEDYNALINK'][0]['#']); $newcat->name = $xmlcat['#']['NAME'][0]['#'];
if ( !$category = get_record("glossary_categories","glossaryid",$glossary->id,"name",$newcat->name) ) { $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 // Create the category if it does not exist
unset($category); $category = new object();
$category->name = $newcat->name; $category->name = $newcat->name;
$category->glossaryid = $glossary->id; $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) // add to exception report (can't insert category)
$rejections .= "<tr><td>&nbsp;<strong>" . get_string("category","glossary") . ":</strong>$newcat->name</td>" . $rejections .= "<tr><td>&nbsp;<strong>" . get_string("category","glossary") . ":</strong>$newcat->name</td>" .
"<td>" . get_string("cantinsertcat","glossary"). "</td></tr>"; "<td>" . get_string("cantinsertcat","glossary"). "</td></tr>";
@ -282,10 +281,10 @@
} }
if ( $category ) { if ( $category ) {
// inserting the new relation // inserting the new relation
unset($entrycat); $entrycat = new opbject();
$entrycat->entryid = $newentry->id; $entrycat->entryid = $newentry->id;
$entrycat->categoryid = $category->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) // add to exception report (can't insert relation)
$rejections .= "<tr><td>&nbsp;<strong>" . get_string("category","glossary") . ":</strong>$newcat->name</td>" . $rejections .= "<tr><td>&nbsp;<strong>" . get_string("category","glossary") . ":</strong>$newcat->name</td>" .
"<td>" . get_string("cantinsertrel","glossary"). "</td></tr>"; "<td>" . get_string("cantinsertrel","glossary"). "</td></tr>";

View file

@ -92,7 +92,7 @@
// TODO: count only approved if not allowed to see them // 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 this glossary has RSS activated, calculate it
if ($show_rss) { if ($show_rss) {

View file

@ -180,17 +180,15 @@ function glossary_user_outline($course, $user, $mod, $glossary) {
function glossary_get_user_entries($glossaryid, $userid) { function glossary_get_user_entries($glossaryid, $userid) {
/// Get all the entries for a user in a glossary /// 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 return $DB->get_records_sql("SELECT e.*, u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}glossary g, FROM {glossary} g, {glossary_entries} e, {user} u
{$CFG->prefix}glossary_entries e, WHERE g.id = ?
{$CFG->prefix}user u
WHERE g.id = '$glossaryid'
AND e.glossaryid = g.id AND e.glossaryid = g.id
AND e.userid = '$userid' AND e.userid = ?
AND e.userid = u.id 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) { 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. /// that has occurred in glossary activities and print it out.
/// Return true if there was output, or false is there was none. /// 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 //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? $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, 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 ge.userid, u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}glossary_entries ge FROM {glossary_entries} ge
JOIN {$CFG->prefix}user u ON u.id = ge.userid JOIN {user} u ON u.id = ge.userid
WHERE ge.glossaryid IN ($glist) AND ge.timemodified > $timestart WHERE ge.glossaryid IN ($glist) AND ge.timemodified > ?
ORDER BY ge.timemodified ASC")) { ORDER BY ge.timemodified ASC", array($timestart))) {
return false; return false;
} }
@ -286,22 +284,17 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
function glossary_log_info($log) { function glossary_log_info($log) {
global $CFG; global $DB;
return get_record_sql("SELECT e.*, u.firstname, u.lastname return $DB->get_record_sql("SELECT e.*, u.firstname, u.lastname
FROM {$CFG->prefix}glossary_entries e, FROM {glossary_entries} e, {user} u
{$CFG->prefix}user u WHERE e.id = ? AND u.id = ?", array($log->info, $log->userid));
WHERE e.id = '$log->info'
AND u.id = '$log->userid'");
} }
function glossary_cron () { function glossary_cron () {
/// Function to be run periodically according to the moodle cron /// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such /// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ... /// as sending out mail, toggling flags etc ...
global $CFG;
return true; return true;
} }
@ -313,19 +306,20 @@ function glossary_cron () {
* @return array array of grades, false if none * @return array array of grades, false if none
*/ */
function glossary_get_user_grades($glossary, $userid=0) { 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 $sql = "SELECT u.id, u.id AS userid, avg(gr.rating) AS rawgrade
FROM {$CFG->prefix}user u, {$CFG->prefix}glossary_entries ge, FROM {user} u, {glossary_entries} ge, {glossary_ratings} gr
{$CFG->prefix}glossary_ratings gr
WHERE u.id = ge.userid AND ge.id = gr.entryid 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 $user
GROUP BY u.id"; 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 * @param int $userid specific user only, 0 mean all
*/ */
function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) { function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
global $CFG; global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
if ($glossary != null) { if ($glossary != null) {
@ -354,17 +348,17 @@ function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
} else { } else {
$sql = "SELECT g.*, cm.idnumber as cmidnumber $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"; WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
if ($rs = get_recordset_sql($sql)) { if ($rs = $DB->get_recordset_sql($sql)) {
while ($glossary = rs_fetch_next_record($rs)) { foreach ($rs as $glossary) {
if ($glossary->assessed) { if ($glossary->assessed) {
glossary_update_grades($glossary, 0, false); glossary_update_grades($glossary, 0, false);
} else { } else {
glossary_grade_item_update($glossary); 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) { function glossary_grade_item_update($glossary, $grades=NULL) {
global $CFG; 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)){ if(!empty($glossary->cmidnumber)){
$params = array('itemname'=>$glossary->name, 'idnumber'=>$glossary->cmidnumber); $params = array('itemname'=>$glossary->name, 'idnumber'=>$glossary->cmidnumber);
}else{ }else{
@ -425,26 +418,24 @@ function glossary_grade_item_delete($glossary) {
function glossary_get_participants($glossaryid) { function glossary_get_participants($glossaryid) {
//Returns the users with data in one glossary //Returns the users with data in one glossary
//(users with records in glossary_entries, students) //(users with records in glossary_entries, students)
global $DB;
global $CFG;
//Get students //Get students
$students = get_records_sql("SELECT DISTINCT u.id, u.id $students = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
FROM {$CFG->prefix}user u, FROM {user} u, {glossary_entries} g
{$CFG->prefix}glossary_entries g WHERE g.glossaryid = : AND u.id = g.userid", array($glossaryid));
WHERE g.glossaryid = '$glossaryid' and
u.id = g.userid");
//Return students array (it contains an array of unique users) //Return students array (it contains an array of unique users)
return ($students); return $students;
} }
function glossary_scale_used ($glossaryid,$scaleid) { function glossary_scale_used ($glossaryid,$scaleid) {
//This function returns if a scale is being used by one glossary //This function returns if a scale is being used by one glossary
global $DB;
$return = false; $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)) { if (!empty($rec) && !empty($scaleid)) {
$return = true; $return = true;
@ -461,7 +452,9 @@ function glossary_scale_used ($glossaryid,$scaleid) {
* @return boolean True if the scale is used by any glossary * @return boolean True if the scale is used by any glossary
*/ */
function glossary_scale_used_anywhere($scaleid) { 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; return true;
} else { } else {
return false; return false;
@ -477,8 +470,7 @@ function glossary_scale_used_anywhere($scaleid) {
//are included if detected and old formats are deleted and any glossary //are included if detected and old formats are deleted and any glossary
//using an invalid format is updated to the default (dictionary). //using an invalid format is updated to the default (dictionary).
function glossary_get_available_formats() { function glossary_get_available_formats() {
global $CFG, $DB;
global $CFG;
//Get available formats (plugin) and insert (if necessary) them into glossary_formats //Get available formats (plugin) and insert (if necessary) them into glossary_formats
$formats = get_list_of_plugins('mod/glossary/formats', 'TEMPLATE'); $formats = get_list_of_plugins('mod/glossary/formats', 'TEMPLATE');
@ -492,20 +484,20 @@ function glossary_get_available_formats() {
//Acummulate it as a valid format //Acummulate it as a valid format
$pluginformats[] = $format; $pluginformats[] = $format;
//If the format doesn't exist in the table //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 //Insert the record in glossary_formats
$gf = new object(); $gf = new object();
$gf->name = $format; $gf->name = $format;
$gf->popupformatname = $format; $gf->popupformatname = $format;
$gf->visible = 1; $gf->visible = 1;
insert_record("glossary_formats",$gf); $DB->insert_record("glossary_formats",$gf);
} }
} }
} }
} }
//Delete non_existent formats from glossary_formats table //Delete non_existent formats from glossary_formats table
$formats = get_records("glossary_formats"); $formats = $DB->get_records("glossary_formats");
foreach ($formats as $format) { foreach ($formats as $format) {
$todelete = false; $todelete = false;
//If the format in DB isn't a valid previously detected format then delete the record //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) { if ($todelete) {
//Delete the format //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 //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) { 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 //Now everything is ready in glossary_formats table
$formats = get_records("glossary_formats"); $formats = $DB->get_records("glossary_formats");
return $formats; return $formats;
} }
@ -541,20 +533,19 @@ function glossary_debug($debug,$text,$br=1) {
} }
function glossary_get_entries($glossaryid, $entrylist, $pivot = "") { function glossary_get_entries($glossaryid, $entrylist, $pivot = "") {
global $CFG; global $DB;
if ($pivot) { if ($pivot) {
$pivot .= ","; $pivot .= ",";
} }
return get_records_sql("SELECT $pivot id,userid,concept,definition,format return $DB->get_records_sql("SELECT $pivot id,userid,concept,definition,format
FROM {$CFG->prefix}glossary_entries FROM {glossary_entries}
WHERE glossaryid = '$glossaryid' WHERE glossaryid = ?
AND id IN ($entrylist)"); AND id IN ($entrylist)", array($glossaryid));
} }
function glossary_get_entries_search($concept, $courseid) { function glossary_get_entries_search($concept, $courseid) {
global $CFG, $DB;
global $CFG;
//Check if the user is an admin //Check if the user is an admin
$bypassadmin = 1; //This means NO (by default) $bypassadmin = 1; //This means NO (by default)
@ -570,55 +561,22 @@ function glossary_get_entries_search($concept, $courseid) {
$conceptlower = moodle_strtolower(trim($concept)); $conceptlower = moodle_strtolower(trim($concept));
return get_records_sql("SELECT e.*, g.name as glossaryname, cm.id as cmid, cm.course as courseid $params = array('courseid1'=>$courseid, 'courseid2'=>$courseid, 'conceptlower'=>$conceptlower, 'concept'=>$concept);
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 = "") { return $DB->get_records_sql("SELECT e.*, g.name as glossaryname, cm.id as cmid, cm.course as courseid
global $CFG; FROM {glossary_entries} e, {glossary} g,
if ($where) { {course_modules} cm, {modules} m
$where = " and $where"; WHERE m.name = 'glossary' AND
} cm.module = m.id AND
if ($orderby) { (cm.visible = 1 OR cm.visible = $bypassadmin OR
$orderby = " ORDER BY $orderby"; (cm.course = :courseid1 AND cm.visible = $bypassteacher)) AND
} g.id = cm.instance AND
if ($pivot) { e.glossaryid = g.id AND
$pivot .= ","; ( (e.casesensitive != 0 AND LOWER(concept) = :conceptlower) OR
} (e.casesensitive = 0 and concept = :concept)) AND
return get_records_sql("SELECT $pivot * (g.course = courseid2 OR g.globalglossary = 1) AND
FROM {$CFG->prefix}glossary_entries e.usedynalink != 0 AND
WHERE (glossaryid = $glossary->id or sourceglossaryid = $glossary->id) $where $orderby"); g.usedynalink != 0", $params);
}
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");
} }
function glossary_print_entry($course, $cm, $glossary, $entry, $mode='',$hook='',$printicons = 1, $displayformat = -1, $ratings = NULL, $printview = false) { 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) { function glossary_print_entry_definition($entry) {
global $DB;
$definition = $entry->definition; $definition = $entry->definition;
@ -715,7 +674,7 @@ function glossary_print_entry_definition($entry) {
$pat = '/('.$term.')/is'; $pat = '/('.$term.')/is';
$doNolinks[] = $pat; $doNolinks[] = $pat;
//Now the aliases //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) { foreach ($aliases as $alias) {
$term = preg_quote(trim($alias->alias),'/'); $term = preg_quote(trim($alias->alias),'/');
$pat = '/('.$term.')/is'; $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') { function glossary_print_entry_aliases($course, $cm, $glossary, $entry,$mode='',$hook='', $type = 'print') {
global $DB;
$return = ''; $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) { foreach ($aliases as $alias) {
if (trim($alias->alias)) { if (trim($alias->alias)) {
if ($return == '') { 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') { 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); $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)) { 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 // only teachers can export entries so check it out
if (has_capability('mod/glossary:export', $context) and !$ismainglossary and !$importedentry) { 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 if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry
$output = true; $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>'; $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') { function glossary_print_entry_commentslink($course, $cm, $glossary, $entry,$mode,$hook, $type = 'print') {
global $DB;
$return = ''; $return = '';
$count = count_records('glossary_comments','entryid',$entry->id); $count = $DB->count_records('glossary_comments', array('entryid'=>$entry->id));
if ($count) { if ($count) {
$return = ''; $return = '';
$return .= "<a href=\"comments.php?id=$cm->id&amp;eid=$entry->id\">$count "; $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 /// valid format values: html : Return the HTML link for the attachment as an icon
/// text : Return the HTML link for tha attachment as text /// text : Return the HTML link for tha attachment as text
/// blank : Print the output to the screen /// blank : Print the output to the screen
global $DB;
if ($entry->attachment) { 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 $entry->course = $glossary->course; //used inside print_attachment
if ($insidetable) { if ($insidetable) {
echo "<table border=\"0\" width=\"100%\" align=\"$align\"><tr><td align=\"$align\" nowrap=\"nowrap\">\n"; 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 // It returns all entries from all glossaries that matches the specified criteria
// within a given $course. It performs an $extended search if necessary. // 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. // It restrict the search to only one $glossary if the $glossary parameter is set.
global $CFG, $DB;
global $CFG;
if ( !$glossary ) { if ( !$glossary ) {
if ( $glossaries = get_records("glossary", "course", $course->id) ) { if ( $glossaries = $DB->get_records("glossary", array("course"=>$course->id)) ) {
$glos = ""; $glos = "";
foreach ( $glossaries as $glossary ) { foreach ( $glossaries as $glossary ) {
$glos .= "$glossary->id,"; $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))) { 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"; $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 { } else {
$onlyvisible = ""; $onlyvisible = "";
$onlyvisibletable = ""; $onlyvisibletable = "";
} }
/// Some differences in syntax for entrygreSQL if ($DB->sql_regex_supported()) {
switch ($CFG->dbfamily) { $REGEXP = $DB->sql_regex(true);
case 'postgres': $NOTREGEXP = $DB->sql_regex(false);
$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;
} }
$LIKE = $DB->sql_ilike(); // case-insensitive
$conceptsearch = ""; $searchcond = array();
$definitionsearch = ""; $params = array();
$i = 0;
$concat = $DB->sql_concat('e.concept', "' '", 'e.definition');
foreach ($searchterms as $searchterm) { foreach ($searchterms as $searchterm) {
if ($conceptsearch) { $i++;
$conceptsearch.= " OR ";
} $NOT = ''; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
if ($definitionsearch) { /// will use it to simulate the "-" operator with LIKE clause
$definitionsearch.= " OR ";
}
/// Under Oracle and MSSQL, trim the + and - operators and perform /// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE search /// simpler LIKE (or NOT LIKE) queries
if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') { if (!$DB->sql_regex_supported()) {
if (substr($searchterm, 0, 1) == '-') {
$NOT = ' NOT ';
}
$searchterm = trim($searchterm, '+-'); $searchterm = trim($searchterm, '+-');
} }
if (substr($searchterm,0,1) == "+") { // TODO: +- may not work for non latin languages
$searchterm = substr($searchterm,1);
$conceptsearch.= " e.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; if (substr($searchterm,0,1) == '+') {
$definitionsearch .= " e.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; $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) == "-") { } else if (substr($searchterm,0,1) == "-") {
$searchterm = substr($searchterm,1); $searchterm = trim($searchterm, '+-');
$conceptsearch .= " e.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; $searchterm = preg_quote($searchterm, '|');
$definitionsearch .= " e.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; $searchcond[] = "$concat $NOTREGEXP :ss$i";
$params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
} else { } else {
$conceptsearch .= " e.concept $LIKE '%$searchterm%' "; $searchcond[] = "$concat $NOT $LIKE :ss$i";
$definitionsearch .= " e.definition $LIKE '%$searchterm%' "; $params['ss'.$i] = "%$searchterm%";
} }
} }
$definitionsearch = !empty($extended) ? "OR $definitionsearch" : ''; if (empty($searchcond)) {
$totalcount = 0;
return array();
}
$selectsql = "{$CFG->prefix}glossary_entries e, $searchcond = implode(" AND ", $searchcond);
{$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 (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.* return $DB->get_records_sql($sql, $params);
FROM $selectsql ORDER BY e.concept ASC");
} }
function glossary_search_entries($searchterms, $glossary, $extended) { 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); return glossary_search($course,$searchterms,$extended,$glossary);
} }
function glossary_file_area_name($entry) { function glossary_file_area_name($entry) {
global $CFG; global $CFG, $DB;
// Creates a directory file name, suitable for make_upload_directory() // Creates a directory file name, suitable for make_upload_directory()
// I'm doing this workaround for make it works for delete_instance also // I'm doing this workaround for make it works for delete_instance also
// (when called from delete_instance, glossary is already deleted so // (when called from delete_instance, glossary is already deleted so
// getting the course from mdl_glossary does not work) // getting the course from mdl_glossary does not work)
$module = get_record("modules","name","glossary"); $module = $DB->get_record("modules", array("name"=>"glossary"));
$cm = get_record("course_modules","module",$module->id,"instance",$entry->glossaryid); $cm = $DB->get_record("course_modules", array("module"=>$module->id, "instance"=>$entry->glossaryid));
return "$cm->course/$CFG->moddata/glossary/$entry->glossaryid/$entry->id"; 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) { function glossary_delete_attachments($glossary) {
global $DB;
// Deletes all the user files in the attachments area for the glossary // 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; $deleted = 0;
foreach ($entries as $entry) { foreach ($entries as $entry) {
if ( $entry->attachment ) { if ( $entry->attachment ) {
@ -1170,12 +1141,11 @@ function glossary_copy_attachments($entry, $newentry) {
/// this function checks that entry /// this function checks that entry
/// for attachments, and if any are found, these are /// for attachments, and if any are found, these are
/// copied to the new glossary directory. /// copied to the new glossary directory.
global $CFG, $DB;
global $CFG;
$return = true; $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) { foreach ($entries as $curentry) {
$oldentry = new object(); $oldentry = new object();
$oldentry->id = $entry->id; $oldentry->id = $entry->id;
@ -1200,13 +1170,13 @@ function glossary_move_attachments($entry, $glossaryid) {
/// for attachments, and if any are found, these are /// for attachments, and if any are found, these are
/// moved to the new glossary directory. /// moved to the new glossary directory.
global $CFG; global $CFG, $DB;
require_once($CFG->dirroot.'/lib/uploadlib.php'); require_once($CFG->dirroot.'/lib/uploadlib.php');
$return = true; $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) { foreach ($entries as $entry) {
$oldentry = new object(); $oldentry = new object();
$oldentry->course = $entry->course; $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) { function glossary_print_categories_menu($cm, $glossary, $hook, $category) {
global $CFG, $DB;
global $CFG;
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $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_ALL_CATEGORIES] = get_string("allcategories","glossary");
$menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","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 = ''; $selected = '';
if ( $categories ) { if ( $categories ) {
foreach ($categories as $currentcategory) { foreach ($categories as $currentcategory) {
@ -1557,11 +1526,11 @@ function glossary_sort_entries ( $entry0, $entry1 ) {
} }
function glossary_print_comment($course, $cm, $glossary, $entry, $comment) { function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
global $CFG, $USER; global $CFG, $USER, $DB;
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $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'); $strby = get_string('writtenby','glossary');
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); $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) { function glossary_print_entry_ratings($course, $entry, $ratings = NULL) {
global $USER, $CFG, $DB;
global $USER, $CFG; $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid));
$glossarymod = $DB->get_record('modules', array('name'=>'glossary'));
$glossary = get_record('glossary', 'id', $entry->glossaryid); $cm = $DB->get_record_sql("SELECT *
$glossarymod = get_record('modules','name','glossary'); FROM {course_modules}
$cm = get_record_sql("select * from {$CFG->prefix}course_modules where course = $course->id WHERE course = ? AND module = ? and instance = ?", array($course->id, $glossarymod->id, $glossary->id));
and module = $glossarymod->id and instance = $glossary->id");
$context = get_context_instance(CONTEXT_MODULE, $cm->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) { function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) {
global $USER,$CFG; global $USER,$CFG, $DB;
echo '<div class="boxaligncenter">'; echo '<div class="boxaligncenter">';
echo '<table class="glossarypopup" cellspacing="0"><tr>'; echo '<table class="glossarypopup" cellspacing="0"><tr>';
echo '<td>'; echo '<td>';
if ( $entries ) { if ( $entries ) {
foreach ( $entries as $entry ) { 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'); 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'); print_error('coursemisconf');
} }
if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid, $glossary->course) ) { 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 //Get popupformatname
$format = get_record('glossary_formats','name',$dp); $format = $DB->get_record('glossary_formats', array('name'=>$dp));
$displayformat = $format->popupformatname; $displayformat = $format->popupformatname;
//Check displayformat variable and set to default if necessary //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) { function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
global $CFG; global $CFG, $DB;
$co = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $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("GLOBALGLOSSARY",2,false,$glossary->globalglossary);
$co .= glossary_full_tag("ENTBYPAGE",2,false,$glossary->entbypage); $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); $co .= glossary_start_tag("ENTRIES",2,true);
foreach ($entries as $entry) { foreach ($entries as $entry) {
$permissiongranted = 1; $permissiongranted = 1;
@ -1731,10 +1700,10 @@ function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
case GLOSSARY_SHOW_ALL_CATEGORIES: case GLOSSARY_SHOW_ALL_CATEGORIES:
break; break;
case GLOSSARY_SHOW_NOT_CATEGORISED: 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; break;
default: 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; 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("FULLMATCH",4,false,$entry->fullmatch);
$co .= glossary_full_tag("TEACHERENTRY",4,false,$entry->teacherentry); $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); $co .= glossary_start_tag("ALIASES",4,true);
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
$co .= glossary_start_tag("ALIAS",5,true); $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); $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); $co .= glossary_start_tag("CATEGORIES",4,true);
foreach ($catentries as $catentry) { 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_start_tag("CATEGORY",5,true);
$co .= glossary_full_tag("NAME",6,false,$category->name); $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") { function glossary_get_ratings($entryid, $sort="u.firstname ASC") {
/// Returns a list of ratings for a particular entry - sorted. /// Returns a list of ratings for a particular entry - sorted.
global $CFG; global $DB;
return get_records_sql("SELECT u.*, r.rating, r.time return $DB->get_records_sql("SELECT u.*, r.rating, r.time
FROM {$CFG->prefix}glossary_ratings r, FROM {glossary_ratings} r, {user} u
{$CFG->prefix}user u WHERE r.entryid = ? AND r.userid = u.id
WHERE r.entryid = '$entryid' ORDER BY $sort", array($entryid));
AND r.userid = u.id
ORDER BY $sort");
} }
function glossary_count_unrated_entries($glossaryid, $userid) { function glossary_count_unrated_entries($glossaryid, $userid) {
// How many unrated entries are in the given glossary for a given user? // How many unrated entries are in the given glossary for a given user?
global $CFG; global $DB;
if ($entries = get_record_sql("SELECT count(*) as num if ($entries = $DB->get_record_sql("SELECT count('x') as num
FROM {$CFG->prefix}glossary_entries FROM {glossary_entries}
WHERE glossaryid = '$glossaryid' WHERE glossaryid = ? AND userid <> ?", array($glossaryid, $userid))) {
AND userid <> '$userid' ")) {
if ($rated = get_record_sql("SELECT count(*) as num if ($rated = $DB->get_record_sql("SELECT count(*) as num
FROM {$CFG->prefix}glossary_entries e, FROM {glossary_entries} e, {glossary_ratings} r
{$CFG->prefix}glossary_ratings r WHERE e.glossaryid = ? AND e.id = r.entryid
WHERE e.glossaryid = '$glossaryid' AND r.userid = ?", array($glossaryid, $userid))) {
AND e.id = r.entryid
AND r.userid = '$userid'")) {
$difference = $entries->num - $rated->num; $difference = $entries->num - $rated->num;
if ($difference > 0) { if ($difference > 0) {
return $difference; 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. /// Return the mean rating of a entry given to the current user by others.
/// Scale is an array of possible ratings in the scale /// Scale is an array of possible ratings in the scale
/// Ratings is an optional simple array of actual ratings (just integers) /// Ratings is an optional simple array of actual ratings (just integers)
global $DB;
if (!$ratings) { if (!$ratings) {
$ratings = array(); $ratings = array();
if ($rates = get_records("glossary_ratings", "entryid", $entryid)) { if ($rates = $DB->get_records("glossary_ratings", array("entryid"=>$entryid))) {
foreach ($rates as $rate) { foreach ($rates as $rate) {
$ratings[] = $rate->rating; $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. /// Return a summary of entry ratings given to the current user by others.
/// Scale is an array of possible ratings in the scale /// Scale is an array of possible ratings in the scale
/// Ratings is an optional simple array of actual ratings (just integers) /// Ratings is an optional simple array of actual ratings (just integers)
global $DB;
if (!$ratings) { if (!$ratings) {
$ratings = array(); $ratings = array();
if ($rates = get_records("glossary_ratings", "entryid", $entryid)) { if ($rates = $DB->get_records("glossary_ratings", array("entryid"=>$entryid))) {
foreach ($rates as $rate) { foreach ($rates as $rate) {
$rating[] = $rate->rating; $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. /// Print the menu of ratings as part of a larger form.
/// If the entry has already been - set that value. /// If the entry has already been - set that value.
/// Scale is an array of ratings /// Scale is an array of ratings
global $DB;
static $strrate; 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; $rating->rating = -999;
} }
@ -2173,7 +2140,7 @@ function glossary_reset_course_form_defaults($course) {
* @param string optional type * @param string optional type
*/ */
function glossary_reset_gradebook($courseid, $type='') { function glossary_reset_gradebook($courseid, $type='') {
global $CFG; global $DB;
switch ($type) { switch ($type) {
case 'main' : $type = "AND g.mainglossary=1"; break; 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 $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 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=$courseid $type"; 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) { foreach ($glossarys as $glossary) {
glossary_grade_item_update($glossary, 'reset'); glossary_grade_item_update($glossary, 'reset');
} }
@ -2198,30 +2165,32 @@ function glossary_reset_gradebook($courseid, $type='') {
* @return array status array * @return array status array
*/ */
function glossary_reset_userdata($data) { function glossary_reset_userdata($data) {
global $CFG; global $CFG, $DB;
require_once($CFG->libdir.'/filelib.php'); require_once($CFG->libdir.'/filelib.php');
$componentstr = get_string('modulenameplural', 'glossary'); $componentstr = get_string('modulenameplural', 'glossary');
$status = array(); $status = array();
$allentriessql = "SELECT e.id $allentriessql = "SELECT e.id
FROM {$CFG->prefix}glossary_entries e FROM {glossary_entries} e
INNER JOIN {$CFG->prefix}glossary g ON e.glossaryid = g.id JOIN {glossary} g ON e.glossaryid = g.id
WHERE g.course = {$data->courseid}"; WHERE g.course = ?";
$allglossariessql = "SELECT g.id $allglossariessql = "SELECT g.id
FROM {$CFG->prefix}glossary g FROM {glossary} g
WHERE g.course={$data->courseid}"; WHERE g.course = ?";
$params = array($data->courseid);
// delete entries if requested // delete entries if requested
if (!empty($data->reset_glossary_all) 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))) { 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)"); $DB->delete_records_select('glossary_ratings', "entryid IN ($allentriessql)", $params);
delete_records_select('glossary_comments', "entryid IN ($allentriessql)"); $DB->delete_records_select('glossary_comments', "entryid IN ($allentriessql)", $params);
delete_records_select('glossary_entries', "glossaryid IN ($allglossariessql)"); $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) { foreach ($glossaries as $glossaryid=>$unused) {
fulldelete($CFG->dataroot."/$data->courseid/moddata/glossary/$glossaryid"); fulldelete($CFG->dataroot."/$data->courseid/moddata/glossary/$glossaryid");
} }
@ -2242,11 +2211,11 @@ function glossary_reset_userdata($data) {
$secondaryglossariessql = "$allglossariessql AND g.mainglossary=0"; $secondaryglossariessql = "$allglossariessql AND g.mainglossary=0";
if (in_array('main', $data->reset_glossary_types)) { if (in_array('main', $data->reset_glossary_types)) {
delete_records_select('glossary_ratings', "entryid IN ($mainentriessql)"); $DB->delete_records_select('glossary_ratings', "entryid IN ($mainentriessql)", $params);
delete_records_select('glossary_comments', "entryid IN ($mainentriessql)"); $DB->delete_records_select('glossary_comments', "entryid IN ($mainentriessql)", $params);
delete_records_select('glossary_entries', "glossaryid IN ($mainglossariessql)"); $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) { foreach ($glossaries as $glossaryid=>$unused) {
fulldelete("$CFG->dataroot/$data->courseid/moddata/glossary/$glossaryid"); 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); $status[] = array('component'=>$componentstr, 'item'=>get_string('resetglossaries', 'glossary'), 'error'=>false);
} else if (in_array('secondary', $data->reset_glossary_types)) { } else if (in_array('secondary', $data->reset_glossary_types)) {
delete_records_select('glossary_ratings', "entryid IN ($secondaryentriessql)"); $DB->delete_records_select('glossary_ratings', "entryid IN ($secondaryentriessql)", $params);
delete_records_select('glossary_comments', "entryid IN ($secondaryentriessql)"); $DB->delete_records_select('glossary_comments', "entryid IN ($secondaryentriessql)", $params);
delete_records_select('glossary_entries', "glossaryid IN ($secondaryglossariessql)"); $DB->delete_records_select('glossary_entries', "glossaryid IN ($secondaryglossariessql)", $params);
// remove exported source flag from entries in main glossary // remove exported source flag from entries in main glossary
execute_sql("UPDATE {$CFG->prefix}glossary_entries $DB->execute("UPDATE {glossary_entries
SET sourceglossaryid=0 SET sourceglossaryid=0
WHERE glossaryid IN ($mainglossariessql)", false); WHERE glossaryid IN ($mainglossariessql)", $params);
if ($glossaries = get_records_sql($secondaryglossariessql)) { if ($glossaries = $DB->get_records_sql($secondaryglossariessql, $params)) {
foreach ($glossaries as $glossaryid=>$unused) { foreach ($glossaries as $glossaryid=>$unused) {
fulldelete("$CFG->dataroot/$data->courseid/moddata/glossary/$glossaryid"); 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 // remove entries by users not enrolled into course
if (!empty($data->reset_glossary_notenrolled)) { if (!empty($data->reset_glossary_notenrolled)) {
$entriessql = "SELECT e.id, e.userid, e.glossaryid, u.id AS userexists, u.deleted AS userdeleted $entriessql = "SELECT e.id, e.userid, e.glossaryid, u.id AS userexists, u.deleted AS userdeleted
FROM {$CFG->prefix}glossary_entries e FROM {glossary_entries} e
INNER JOIN {$CFG->prefix}glossary g ON e.glossaryid = g.id JOIN {glossary} g ON e.glossaryid = g.id
LEFT OUTER JOIN {$CFG->prefix}user u ON e.userid = u.id LEFT JOIN {user} u ON e.userid = u.id
WHERE g.course = {$data->courseid} AND e.userid > 0"; WHERE g.course = ? AND e.userid > 0";
$course_context = get_context_instance(CONTEXT_COURSE, $data->courseid); $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
$notenrolled = array(); $notenrolled = array();
if ($rs = get_recordset_sql($entriessql)) { if ($rs = $DB->get_recordset_sql($entriessql, $params)) {
while ($entry = rs_fetch_next_record($rs)) { foreach ($rs as $entry) {
if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted
or !has_capability('moodle/course:view', $course_context , $entry->userid)) { or !has_capability('moodle/course:view', $course_context , $entry->userid)) {
delete_records('glossary_ratings', 'entryid', $entry->id); $DB->delete_records('glossary_ratings', array('entryid'=>$entry->id));
delete_records('glossary_comments', 'entryid', $entry->id); $DB->delete_records('glossary_comments', array('entryid'=>$entry->id));
delete_records('glossary_entries', 'id', $entry->id); $DB->delete_records('glossary_entries', array('id'=>$entry->id));
fulldelete("$CFG->dataroot/$data->courseid/moddata/glossary/$entry->glossaryid"); fulldelete("$CFG->dataroot/$data->courseid/moddata/glossary/$entry->glossaryid");
$notenrolled[$entry->userid] = true; $notenrolled[$entry->userid] = true;
} }
} }
rs_close($rs); $rs->close();
$status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'glossary'), 'error'=>false); $status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'glossary'), 'error'=>false);
} }
} }
// remove all ratings // remove all ratings
if (!empty($data->reset_glossary_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 // remove all grades from gradebook
if (empty($data->reset_gradebook_grades)) { if (empty($data->reset_gradebook_grades)) {
glossary_reset_gradebook($data->courseid); glossary_reset_gradebook($data->courseid);
@ -2321,7 +2290,7 @@ function glossary_reset_userdata($data) {
// remove all comments // remove all comments
if (!empty($data->reset_glossary_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); $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
} }

View file

@ -151,11 +151,12 @@ class mod_glossary_mod_form extends moodleform_mod {
} }
function definition_after_data() { function definition_after_data() {
global $COURSE, $DB;
parent::definition_after_data(); parent::definition_after_data();
global $COURSE;
$mform =& $this->_form; $mform =& $this->_form;
$mainglossaryel =& $mform->getElement('mainglossary'); $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'))){ if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
//secondary glossary, a main one already exists in this course. //secondary glossary, a main one already exists in this course.
$mainglossaryel->setValue(0); $mainglossaryel->setValue(0);

View file

@ -18,11 +18,11 @@
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); 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'); print_error('invalidid', 'glossary');
} }
@ -44,7 +44,7 @@
/// setting the default values for the display mode of the current glossary /// setting the default values for the display mode of the current glossary
/// only if the glossary is viewed by the first time /// 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; $printpivot = $dp->showgroup;
if ( $mode == '' and $hook == '' and $show == '') { if ( $mode == '' and $hook == '' and $show == '') {
$mode = $dp->defaultmode; $mode = $dp->defaultmode;
@ -88,7 +88,7 @@
case 'cat': /// Looking for a certain cat case 'cat': /// Looking for a certain cat
$tab = GLOSSARY_CATEGORY_VIEW; $tab = GLOSSARY_CATEGORY_VIEW;
if ( $hook > 0 ) { if ( $hook > 0 ) {
$category = get_record("glossary_categories","id",$hook); $category = $DB->get_record("glossary_categories", array("id"=>$hook));
} }
break; break;
@ -143,7 +143,7 @@
$alphabet = explode(",", get_string("alphabet")); $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 '<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("site") . ': <strong>' . format_string($site->fullname) . '</strong><br />';
echo get_string("course") . ': <strong>' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</strong><br />'; echo get_string("course") . ': <strong>' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</strong><br />';
@ -169,7 +169,7 @@
$pivottoshow = $currentpivot; $pivottoshow = $currentpivot;
if ( isset($entry->userispivot) ) { if ( isset($entry->userispivot) ) {
// printing the user icon if defined (only when browsing authors) // 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); $pivottoshow = fullname($user);
} }

View file

@ -8,11 +8,11 @@
$glossaryid = required_param('glossaryid', PARAM_INT); // The forum the rated posts are from $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'); 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'); print_error('invalidcourseid');
} }
@ -42,12 +42,12 @@
$returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id; $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) { foreach ((array)$data as $entryid => $rating) {
if (!is_numeric($entryid)) { if (!is_numeric($entryid)) {
continue; continue;
} }
if (!$entry = get_record('glossary_entries', 'id', $entryid)) { if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) {
continue; continue;
} }
@ -67,16 +67,16 @@
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 //Check if we must delete the rate
if ($rating == -999) { 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); glossary_update_grades($glossary, $entry->userid);
} else if ($rating != $oldrating->rating) { } else if ($rating != $oldrating->rating) {
$oldrating->rating = $rating; $oldrating->rating = $rating;
$oldrating->time = time(); $oldrating->time = time();
if (! update_record("glossary_ratings", $oldrating)) { if (! $DB->update_record("glossary_ratings", $oldrating)) {
print_error('cannotinsertrate', '', '', array($entry, $rating)); print_error('cannotinsertrate', '', '', array($entry, $rating));
} }
glossary_update_grades($glossary, $entry->userid); glossary_update_grades($glossary, $entry->userid);
@ -89,7 +89,7 @@
$newrating->entryid = $entry->id; $newrating->entryid = $entry->id;
$newrating->rating = $rating; $newrating->rating = $rating;
if (! insert_record("glossary_ratings", $newrating)) { if (! $DB->insert_record("glossary_ratings", $newrating)) {
print_error('cannotinsertrate', '', '', array($entry->id, $rating)); print_error('cannotinsertrate', '', '', array($entry->id, $rating));
} }
glossary_update_grades($glossary, $entry->userid); glossary_update_grades($glossary, $entry->userid);

View file

@ -8,15 +8,15 @@
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$sort = optional_param('sort', '', PARAM_ALPHA); $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'); 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'); 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'); print_error('invalidcourseid');
} }

View file

@ -5,8 +5,7 @@
//rss feeds generation. Foreach site glossary with rss enabled //rss feeds generation. Foreach site glossary with rss enabled
//build one XML rss structure. //build one XML rss structure.
function glossary_rss_feeds() { function glossary_rss_feeds() {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
@ -19,7 +18,7 @@
//It's working so we start... //It's working so we start...
} else { } else {
//Iterate over all glossaries //Iterate over all glossaries
if ($glossaries = get_records("glossary")) { if ($glossaries = $DB->get_records("glossary")) {
foreach ($glossaries as $glossary) { foreach ($glossaries as $glossary) {
if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) { 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 //This function return the XML rss contents about the glossary record passed as parameter
//It returns false if something is wrong //It returns false if something is wrong
function glossary_rss_feed($glossary) { function glossary_rss_feed($glossary) {
global $CFG, $DB;
global $CFG;
$status = true; $status = true;
@ -136,31 +134,32 @@
//This function returns "items" record array to be used to build the rss feed //This function returns "items" record array to be used to build the rss feed
//for a Type=with author glossary //for a Type=with author glossary
function glossary_rss_feed_withauthor($glossary, $newsince=0) { function glossary_rss_feed_withauthor($glossary, $newsince=0) {
global $CFG, $DB;
global $CFG;
$items = array(); $items = array();
$params = array('gid'=>$glossary->id, 'newsince'=>$newsince);
if ($newsince) { if ($newsince) {
$newsince = " AND e.timecreated > '$newsince'"; $newsince = "AND e.timecreated > :newsince";
} else { } else {
$newsince = ""; $newsince = "";
} }
if ($recs = get_records_sql ("SELECT e.id AS entryid, if ($recs = $DB->get_records_sql ("SELECT e.id AS entryid,
e.concept AS entryconcept, e.concept AS entryconcept,
e.definition AS entrydefinition, e.definition AS entrydefinition,
e.format AS entryformat, e.format AS entryformat,
e.timecreated AS entrytimecreated, e.timecreated AS entrytimecreated,
u.id AS userid, u.id AS userid,
u.firstname AS userfirstname, u.firstname AS userfirstname,
u.lastname AS userlastname u.lastname AS userlastname
FROM {$CFG->prefix}glossary_entries e, FROM {glossary_entries} e,
{$CFG->prefix}user u {user} u
WHERE e.glossaryid = '$glossary->id' AND WHERE e.glossaryid = :gid AND
u.id = e.userid AND u.id = e.userid AND
e.approved = 1 $newsince e.approved = 1 $newsince
ORDER BY e.timecreated desc")) { ORDER BY e.timecreated desc", $params)) {
//Are we just looking for new ones? If so, then return now. //Are we just looking for new ones? If so, then return now.
if ($newsince) { if ($newsince) {
@ -168,15 +167,13 @@
} }
//Iterate over each entry to get glossary->rssarticles records //Iterate over each entry to get glossary->rssarticles records
$articlesleft = $glossary->rssarticles; $articlesleft = $glossary->rssarticles;
$item = NULL;
$user = NULL;
$formatoptions = new object; $formatoptions = new object;
$formatoptions->trusttext = true; $formatoptions->trusttext = true;
foreach ($recs as $rec) { foreach ($recs as $rec) {
unset($item); $item = new object();
unset($user); $user = new user();
$item->title = $rec->entryconcept; $item->title = $rec->entryconcept;
$user->firstname = $rec->userfirstname; $user->firstname = $rec->userfirstname;
$user->lastname = $rec->userlastname; $user->lastname = $rec->userlastname;
@ -197,31 +194,32 @@
//This function returns "items" record array to be used to build the rss feed //This function returns "items" record array to be used to build the rss feed
//for a Type=without author glossary //for a Type=without author glossary
function glossary_rss_feed_withoutauthor($glossary, $newsince=0) { function glossary_rss_feed_withoutauthor($glossary, $newsince=0) {
global $CFG, $DB;
global $CFG;
$items = array(); $items = array();
$params = array('gid'=>$glossary->id, 'newsince'=>$newsince);
if ($newsince) { if ($newsince) {
$newsince = " AND e.timecreated > '$newsince'"; $newsince = "AND e.timecreated > :newsince";
} else { } else {
$newsince = ""; $newsince = "";
} }
if ($recs = get_records_sql ("SELECT e.id AS entryid, if ($recs = $DB->get_records_sql ("SELECT e.id AS entryid,
e.concept AS entryconcept, e.concept AS entryconcept,
e.definition AS entrydefinition, e.definition AS entrydefinition,
e.format AS entryformat, e.format AS entryformat,
e.timecreated AS entrytimecreated, e.timecreated AS entrytimecreated,
u.id AS userid, u.id AS userid,
u.firstname AS userfirstname, u.firstname AS userfirstname,
u.lastname AS userlastname u.lastname AS userlastname
FROM {$CFG->prefix}glossary_entries e, FROM {glossary_entries} e,
{$CFG->prefix}user u {user} u
WHERE e.glossaryid = '$glossary->id' AND WHERE e.glossaryid = :gid AND
u.id = e.userid AND u.id = e.userid AND
e.approved = 1 $newsince e.approved = 1 $newsince
ORDER BY e.timecreated desc")) { ORDER BY e.timecreated desc", $params)) {
//Are we just looking for new ones? If so, then return now. //Are we just looking for new ones? If so, then return now.
if ($newsince) { if ($newsince) {
@ -230,15 +228,13 @@
//Iterate over each entry to get glossary->rssarticles records //Iterate over each entry to get glossary->rssarticles records
$articlesleft = $glossary->rssarticles; $articlesleft = $glossary->rssarticles;
$item = NULL;
$user = NULL;
$formatoptions = new object; $formatoptions = new object;
$formatoptions->trusttext = true; $formatoptions->trusttext = true;
foreach ($recs as $rec) { foreach ($recs as $rec) {
unset($item); $item = new object();
unset($user); $user = new object();
$item->title = $rec->entryconcept; $item->title = $rec->entryconcept;
$user->firstname = $rec->userfirstname; $user->firstname = $rec->userfirstname;
$user->lastname = $rec->userlastname; $user->lastname = $rec->userlastname;

View file

@ -56,7 +56,7 @@ asort($formats);
$str = '<table>'; $str = '<table>';
foreach ($formats as $formatid=>$formatname) { foreach ($formats as $formatid=>$formatname) {
$recformat = get_record('glossary_formats','id',$formatid); $recformat = $DB->get_record('glossary_formats', array('id'=>$formatid));
$str .= '<tr>'; $str .= '<tr>';
$str .= '<td>' . $formatname . '</td>'; $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>"; $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>";

View file

@ -12,8 +12,8 @@
} }
if ($eid) { if ($eid) {
$entry = get_record("glossary_entries", "id", $eid); $entry = $DB->get_record("glossary_entries", array("id"=>$eid));
$glossary = get_record('glossary','id',$entry->glossaryid); $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid));
$entry->glossaryname = format_string($glossary->name,true); $entry->glossaryname = format_string($glossary->name,true);
if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) { if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) {
print_error("invalidcoursemodule"); print_error("invalidcoursemodule");
@ -39,7 +39,7 @@
} }
if (!empty($courseid)) { if (!empty($courseid)) {
$course = get_record("course", "id", $courseid); $course = $DB->get_record("course", array("id"=>$courseid));
if ($course->id != SITEID) { if ($course->id != SITEID) {
require_login($courseid); require_login($courseid);
} }

View file

@ -37,22 +37,23 @@
/// printpivot indicate if the pivot should be printed or not /// printpivot indicate if the pivot should be printed or not
$fullpivot = 1; $fullpivot = 1;
$params = array('gid1'=>$glossary->id, 'gid2'=>$glossary->id, 'myid'=>$USER->id, 'hook'=>$hook);
$userid = ''; $userid = '';
if ( !empty($USER->id) ) { if ( !empty($USER->id) ) {
$userid = "OR ge.userid = $USER->id"; $userid = "OR ge.userid = :myid";
} }
switch ($tab) { switch ($tab) {
case GLOSSARY_CATEGORY_VIEW: 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"; $sqlselect = "SELECT gec.id AS cid, ge.*, gec.entryid, gc.name AS glossarypivot";
$sqlfrom = "FROM {$CFG->prefix}glossary_entries ge, $sqlfrom = "FROM {glossary_entries} ge,
{$CFG->prefix}glossary_entries_categories gec, {glossary_entries_categories} gec,
{$CFG->prefix}glossary_categories gc"; {glossary_categories} gc";
$sqlwhere = "WHERE (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND $sqlwhere = "WHERE (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2) AND
ge.id = gec.entryid AND gc.id = gec.categoryid 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'; $sqlorderby = ' ORDER BY gc.name, ge.concept';
@ -60,10 +61,10 @@
$printpivot = 0; $printpivot = 0;
$sqlselect = "SELECT ge.*, concept AS glossarypivot"; $sqlselect = "SELECT ge.*, concept AS glossarypivot";
$sqlfrom = "FROM {$CFG->prefix}glossary_entries ge LEFT JOIN {$CFG->prefix}glossary_entries_categories gec $sqlfrom = "FROM {glossary_entries} ge LEFT JOIN {glossary_entries_categories} gec
ON ge.id = gec.entryid"; ON ge.id = gec.entryid";
$sqlwhere = "WHERE (glossaryid = '$glossary->id' OR sourceglossaryid = '$glossary->id') AND $sqlwhere = "WHERE (glossaryid = :gid1 OR sourceglossaryid = :gid2) AND
(ge.approved != 0 $userid) AND gec.entryid IS NULL"; (ge.approved <> 0 $userid) AND gec.entryid IS NULL";
$sqlorderby = ' ORDER BY concept'; $sqlorderby = ' ORDER BY concept';
@ -72,11 +73,11 @@
$printpivot = 0; $printpivot = 0;
$sqlselect = "SELECT ge.*, ce.entryid, c.name AS glossarypivot"; $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"; $sqlfrom = "FROM {glossary_entries} ge, {glossary_entries_categories} ce, {glossary_categories} c";
$sqlwhere = "WHERE ge.id = ce.entryid AND ce.categoryid = '$hook' AND $sqlwhere = "WHERE ge.id = ce.entryid AND ce.categoryid = :hook AND
ce.categoryid = c.id AND ge.approved != 0 AND ce.categoryid = c.id AND ge.approved != 0 AND
(ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2) AND
(ge.approved != 0 $userid)"; (ge.approved <> 0 $userid)";
$sqlorderby = ' ORDER BY c.name, ge.concept'; $sqlorderby = ' ORDER BY c.name, ge.concept';
@ -85,24 +86,25 @@
case GLOSSARY_AUTHOR_VIEW: case GLOSSARY_AUTHOR_VIEW:
$where = ''; $where = '';
$params['hookup'] = $textlib->strtoupper($hook);
if ( $sqlsortkey == 'firstname' ) { if ( $sqlsortkey == 'firstname' ) {
$usernamefield = sql_fullname('u.firstname' , 'u.lastname'); $usernamefield = $DB->sql_fullname('u.firstname' , 'u.lastname');
} else { } 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' ) { if ( $hook == 'ALL' ) {
$where = ''; $where = '';
} }
$sqlselect = "SELECT ge.*, $usernamefield AS glossarypivot, 1 AS userispivot "; $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 $sqlwhere = "WHERE ge.userid = u.id AND
(ge.approved != 0 $userid) (ge.approved <> 0 $userid)
$where AND $where AND
(ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id')"; (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2)";
$sqlorderby = "ORDER BY $usernamefield $sqlsortorder, ge.concept"; $sqlorderby = "ORDER BY $usernamefield $sqlsortorder, ge.concept";
break; break;
case GLOSSARY_APPROVAL_VIEW: case GLOSSARY_APPROVAL_VIEW:
@ -110,13 +112,15 @@
$printpivot = 0; $printpivot = 0;
$where = ''; $where = '';
$params['hookup'] = $textlib->strtoupper($hook);
if ($hook != 'ALL' and $hook != 'SPECIAL') { 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"; $sqlselect = "SELECT ge.*, ge.concept AS glossarypivot";
$sqlfrom = "FROM {$CFG->prefix}glossary_entries ge"; $sqlfrom = "FROM {glossary_entries} ge";
$sqlwhere = "WHERE (ge.glossaryid = '$glossary->id' OR ge.sourceglossaryid = '$glossary->id') AND $sqlwhere = "WHERE (ge.glossaryid = :gid1 OR ge.sourceglossaryid = :gid2) AND
ge.approved = 0 $where"; ge.approved = 0 $where";
if ( $sqlsortkey ) { if ( $sqlsortkey ) {
@ -130,136 +134,114 @@
case GLOSSARY_STANDARD_VIEW: case GLOSSARY_STANDARD_VIEW:
default: default:
$sqlselect = "SELECT ge.*, ge.concept AS glossarypivot"; $sqlselect = "SELECT ge.*, ge.concept AS glossarypivot";
$sqlfrom = "FROM {$CFG->prefix}glossary_entries ge"; $sqlfrom = "FROM {glossary_entries} ge";
$where = ''; $where = '';
$fullpivot = 0; $fullpivot = 0;
$LIKE = sql_ilike();
$NOTLIKE = 'NOT ' . $LIKE;
switch ( $mode ) { switch ( $mode ) {
case 'search': case 'search':
/// Some differences in syntax for PostgreSQL if ($DB->sql_regex_supported()) {
if ($CFG->dbfamily == "postgres") { $REGEXP = $DB->sql_regex(true);
$REGEXP = "~*"; $NOTREGEXP = $DB->sql_regex(false);
$NOTREGEXP = "!~*";
} else {
$REGEXP = "REGEXP";
$NOTREGEXP = "NOT REGEXP";
} }
$LIKE = $DB->sql_ilike(); // case-insensitive
$conceptsearch = ""; $searchcond = array();
$aliassearch = ""; $alcond = array();
$definitionsearch = ""; $params = array();
$i = 0;
$concat = $DB->sql_concat('ge.concept', "' '", 'ge.definition',"' '", "COALESCE(al.alial, '')");
$searchterms = explode(" ",$hook); $searchterms = explode(" ",$hook);
foreach ($searchterms as $searchterm) { foreach ($searchterms as $searchterm) {
$i++;
if ($conceptsearch) { $NOT = ''; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
$conceptsearch .= " AND "; /// will use it to simulate the "-" operator with LIKE clause
}
if ($aliassearch) {
$aliassearch .= " AND ";
}
if ($definitionsearch) {
$definitionsearch .= " AND ";
}
/// Under Oracle and MSSQL, trim the + and - operators and perform /// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE search /// simpler LIKE (or NOT LIKE) queries
if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') { if (!$DB->sql_regex_supported()) {
if (substr($searchterm, 0, 1) == '-') {
$NOT = ' NOT ';
}
$searchterm = trim($searchterm, '+-'); $searchterm = trim($searchterm, '+-');
} }
if (substr($searchterm,0,1) == "+") { if (substr($searchterm,0,1) == '+') {
$searchterm = substr($searchterm,1); $searchterm = trim($searchterm, '+-');
$conceptsearch .= " ge.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; if ($textlib->strlen($searchterm) < 2) {
$aliassearch .= " al.alias $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; continue;
$definitionsearch .= " ge.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; }
$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) == "-") { } else if (substr($searchterm,0,1) == "-") {
$searchterm = substr($searchterm,1); $searchterm = trim($searchterm, '+-');
$conceptsearch .= " ge.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; if ($textlib->strlen($searchterm) < 2) {
$aliassearch .= " al.alias $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; continue;
$definitionsearch .= " ge.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; }
$searchterm = preg_quote($searchterm, '|');
$searchcond[] = "$concat $NOTREGEXP :ss$i";
$params['ss'.$i] = "(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)";
} else { } else {
$conceptsearch .= " ge.concept $LIKE '%$searchterm%' "; if ($textlib->strlen($searchterm) < 2) {
$aliassearch .= " al.alias $LIKE '%$searchterm%' "; continue;
$definitionsearch .= " ge.definition $LIKE '%$searchterm%' "; }
$searchcond[] = "$concat $NOT $LIKE :ss$i";
$params['ss'.$i] = "%$searchterm%";
} }
} }
//Search in aliases first if (empty($searchcond)) {
$idaliases = ''; $where = " 1=2 "; // no search result
$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;
}
$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) ";
}
//Include search in definitions if requested
if ( $fullsearch ) {
$where .= " OR ($definitionsearch) )";
} else { } 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; break;
case 'term': case 'term':
$params['hook2'] = $hook;
$printpivot = 0; $printpivot = 0;
$sqlfrom .= " left join {$CFG->prefix}glossary_alias ga on ge.id = ga.entryid "; $sqlfrom .= " LEFT JOIN {glossary_alias} ga on ge.id = ga.entryid";
$where = "AND (ge.concept = '$hook' OR ga.alias = '$hook' ) $where = "AND (ge.concept = :hook OR ga.alias = :hook2) ";
";
break; break;
case 'entry': case 'entry':
$printpivot = 0; $printpivot = 0;
$where = "AND ge.id = '$hook'"; $where = "AND ge.id = :hook";
break; break;
case 'letter': case 'letter':
if ($hook != 'ALL' and $hook != 'SPECIAL') { 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') { if ($hook == 'SPECIAL') {
//Create appropiate IN contents //Create appropiate IN contents
$alphabet = explode(",", get_string("alphabet")); $alphabet = explode(",", get_string("alphabet"));
$sqlalphabet = ''; list($nia, $aparams) = $DB->get_in_or_equal($alphabet, SQL_PARAMS_NAMED, $start='a0', false);
for ($i = 0; $i < count($alphabet); $i++) { $params = array_merge($params, $aparams);
if ($i != 0) { $where = 'AND ' . $DB->sql_substr() . "(upper(concept),1,1) $nia";
$sqlalphabet .= ',';
}
$sqlalphabet .= '\''.$alphabet[$i].'\'';
}
$where = 'AND ' . sql_substr() . '(upper(concept),1,1) NOT IN (' . $textlib->strtoupper($sqlalphabet) . ')';
} }
break; break;
} }
$sqlwhere = "WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND $sqlwhere = "WHERE (ge.glossaryid = :gid1 or ge.sourceglossaryid = :gid2) AND
(ge.approved != 0 $userid) (ge.approved <> 0 $userid)
$where"; $where";
switch ( $tab ) { switch ( $tab ) {
case GLOSSARY_DATE_VIEW: case GLOSSARY_DATE_VIEW:
@ -273,7 +255,7 @@
} }
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; $limitfrom = $offset;
$limitnum = 0; $limitnum = 0;
@ -282,5 +264,5 @@
$limitnum = $entriesbypage; $limitnum = $entriesbypage;
} }
$allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby", $limitfrom, $limitnum); $allentries = $DB->get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby", $params, $limitfrom, $limitnum);
?> ?>

View file

@ -23,17 +23,17 @@
if (! $cm = get_coursemodule_from_id('glossary', $id)) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = get_record("course", "id", $cm->course)) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); 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'); print_error('invalidid', 'glossary');
} }
} else if (!empty($g)) { } else if (!empty($g)) {
if (! $glossary = get_record("glossary", "id", $g)) { if (! $glossary = $DB->get_record("glossary", array("id"=>$g))) {
print_error('invalidid', 'glossary'); 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'); print_error('invalidcourseid');
} }
if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id)) { 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 /// setting the default values for the display mode of the current glossary
/// only if the glossary is viewed by the first time /// 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 /// Based on format->defaultmode, we build the defaulttab to be showed sometimes
switch ($dp->defaultmode) { switch ($dp->defaultmode) {
case 'cat': case 'cat':
@ -146,7 +146,7 @@
case 'entry': /// Looking for a certain entry id case 'entry': /// Looking for a certain entry id
$tab = GLOSSARY_STANDARD_VIEW; $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; $displayformat = $dp->popupformatname;
} }
break; break;
@ -154,7 +154,7 @@
case 'cat': /// Looking for a certain cat case 'cat': /// Looking for a certain cat
$tab = GLOSSARY_CATEGORY_VIEW; $tab = GLOSSARY_CATEGORY_VIEW;
if ( $hook > 0 ) { if ( $hook > 0 ) {
$category = get_record("glossary_categories","id",$hook); $category = $DB->get_record("glossary_categories", array("id"=>$hook));
} }
break; break;
@ -268,7 +268,7 @@
/// Decide about to print the approval link /// Decide about to print the approval link
if (has_capability('mod/glossary:approve', $context)) { if (has_capability('mod/glossary:approve', $context)) {
/// Check we have pending entries /// 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) { if ($availableoptions) {
$availableoptions .= '<br />'; $availableoptions .= '<br />';
} }
@ -441,7 +441,7 @@
// printing the user icon if defined (only when browsing authors) // printing the user icon if defined (only when browsing authors)
echo '<th align="left">'; 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); print_user_picture($user, $course->id, $user->picture);
$pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
} else { } else {
@ -495,7 +495,7 @@
echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"".get_string("sendinratings", "glossary")."\" />"; echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"".get_string("sendinratings", "glossary")."\" />";
if ($glossary->scale < 0) { 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 ); print_scale_menu_helpbutton($course->id, $scale );
} }
} }