Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Cleaning a lot of code in edit.php and view.php

- Removing more notices when debug is ON
- Added a new feature: Now the entries have a default approval status... Not approved entries are shown on a teachers-only frame from which they can be approved or not prior to be visible by everyone.
  • Loading branch information...
commit c76e673ab527e77025b1249041cfd097b501efdc 1 parent 016f1be
willcast authored
View
38 mod/glossary/approve.php
@@ -0,0 +1,38 @@
+<?php
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ require_variable($id); // Course Module ID
+ optional_variable($eid); // Entry ID
+
+ optional_variable($tab,GLOSSARY_APPROVAL_VIEW);
+ optional_variable($l,"ALL");
+
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("Course Module ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $cm->course)) {
+ error("Course is misconfigured");
+ }
+
+ if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+ error("Course module is incorrect");
+ }
+
+ require_login($course->id);
+ if (!isteacher($course->id)) {
+ error("You must be a teacher to use this page.");
+ }
+ $newentry->id = $eid;
+ $newentry->approved = 1;
+
+ if (! update_record("glossary_entries", $newentry)) {
+ error("Could not update your glossary");
+ } else {
+ add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid");
+ }
+ redirect("view.php?id=$cm->id&tab=$tab&l=ALL");
+ die;
+?>
View
BIN  mod/glossary/check.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
10 mod/glossary/comment.html
@@ -28,10 +28,12 @@
helpbutton("textformat", get_string("helpformatting"));
print_string("formattexttype");
echo ":&nbsp;";
- if (!$form->format) {
- $form->format = $defaultformat;
+ if (!isset($form->format)) {
+ if (!$form->format) {
+ $form->format = $defaultformat;
+ }
}
- choose_from_menu(format_text_menu(), "format", $format->format, "");
+ choose_from_menu(format_text_menu(), "format", $form->format, "");
echo "</p>";
?>
</td>
@@ -40,7 +42,7 @@
<td colspan=2>
<p align=center>
<?php
- if ($comment->id) {
+ if (isset($comment->id)) {
echo "<input type=\"hidden\" name=cid value=\"$comment->id\">";
}
?>
View
12 mod/glossary/comment.php
@@ -150,7 +150,7 @@
$newentry->entryid = $entry->id;
$newentry->comment = $form->text;
$newentry->format = $form->format;
- $newentry->timemodified = $comment->timemodified;
+ $newentry->timemodified = time();
if ( $action == "add" ) {
$newentry->userid = $USER->id;
@@ -185,9 +185,13 @@
$defaultformat = FORMAT_MOODLE;
$onsubmit = "";
}
-
- $form->text = $comment->comment;
- $form->format = $comment->format;
+ if (isset($comment) ) {
+ $form->text = $comment->comment;
+ $form->format = $comment->format;
+ } else {
+ $form->text = "";
+ $form->format = $defaultformat;
+ }
include("comment.html");
}
}
View
9 mod/glossary/db/mysql.php
@@ -109,6 +109,15 @@ function glossary_upgrade($oldversion) {
execute_sql( "UPDATE `{$CFG->prefix}glossary`" .
" SET displayformat = 5 WHERE displayformat = 1");
}
+ if ( $oldversion < 2003102000 ) {
+ execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`" .
+ " ADD `defaultapproval` TINYINT(2) UNSIGNED NOT NULL default '1' AFTER `usedynalink`");
+
+ execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries`" .
+ " ADD `approved` TINYINT(2) UNSIGNED NOT NULL default '1' AFTER `fullmatch`");
+
+ execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'approve entry', 'glossary', 'name') ");
+ }
return true;
}
View
3  mod/glossary/db/mysql.sql
@@ -22,6 +22,7 @@ CREATE TABLE prefix_glossary (
showall tinyint(2) unsigned NOT NULL default '1',
allowcomments tinyint(2) unsigned NOT NULL default '0',
usedynalink tinyint(2) unsigned NOT NULL default '1',
+ defaultapproval tinyint(2) unsigned NOT NULL default '1',
timecreated int(10) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id)
@@ -46,6 +47,7 @@ CREATE TABLE prefix_glossary_entries (
usedynalink tinyint(2) unsigned NOT NULL default '1',
casesensitive tinyint(2) unsigned NOT NULL default '0',
fullmatch tinyint(2) unsigned NOT NULL default '1',
+ approved tinyint(2) unsigned NOT NULL default '1',
PRIMARY KEY (id)
) TYPE=MyISAM COMMENT='all glossary entries';
@@ -98,4 +100,5 @@ INSERT INTO prefix_log_display VALUES ('glossary', 'delete category', 'glossary'
INSERT INTO prefix_log_display VALUES ('glossary', 'add comment', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'update comment', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'delete comment', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'approve entry', 'glossary', 'name');
View
8 mod/glossary/deleteentry.php
@@ -7,6 +7,8 @@
require_variable($mode); // edit or delete
optional_variable($go); // commit the operation?
optional_variable($entry); // entry id
+ optional_variable($tab); // browsing entries by categories?
+ optional_variable($cat); // categoryID
$strglossary = get_string("modulename", "glossary");
$strglossaries = get_string("modulenameplural", "glossary");
@@ -72,8 +74,8 @@
print_simple_box_end();
}
print_footer($course);
- add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&currentview=$currentview&cat=$cat", $entry);
- redirect("view.php?id=$cm->id&currentview=$currentview&cat=$cat");
+ add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&tab=$tab&cat=$cat", $entry);
+ redirect("view.php?id=$cm->id&tab=$tab&cat=$cat");
} else { // the operation has not been confirmed yet so ask the user to do so
if ( $mode == "delete") {
print_simple_box_start("center","40%", "#FFBBBB");
@@ -86,7 +88,7 @@
<input type="hidden" name=mode value="delete">
<input type="hidden" name=go value="1">
<input type="hidden" name=entry value="<?php p($entry) ?>">
- <input type="hidden" name=currentview value=<?php p($currentview) ?>>
+ <input type="hidden" name=tab value=<?php p($tab) ?>>
<input type="hidden" name=cat=<?php p($cat) ?>>
<input type="submit" value=" <?php print_string("yes")?> ">
View
2  mod/glossary/dynalink.php
@@ -20,7 +20,7 @@ function glossary_dynamic_link($courseid, $text) {
}
$glossaries=substr($glossaries,0,-1);
- $entries = get_records_select("glossary_entries", "glossaryid IN ($glossaries) AND usedynalink = 1","glossaryid","id,glossaryid,concept,casesensitive,$GLOSSARY_CONCEPT_IS_ENTRY category,fullmatch");
+ $entries = get_records_select("glossary_entries", "glossaryid IN ($glossaries) AND usedynalink = 1 and approved != 0","glossaryid","id,glossaryid,concept,casesensitive,$GLOSSARY_CONCEPT_IS_ENTRY category,fullmatch");
$categories = get_records_select("glossary_categories", "glossaryid IN ($glossaries)", "glossaryid,id","id,glossaryid,name concept, 1 casesensitive,$GLOSSARY_CONCEPT_IS_CATEGORY category, 1 fullmatch");
if ( $entries and $categories ) {
$concepts = array_merge($entries, $categories);
View
82 mod/glossary/edit.html
@@ -4,29 +4,30 @@
<tr valign=top>
<td align=right><p><b><?php echo get_string("concept","glossary") ?>:</b></p></td>
<td>
- <INPUT type="text" name="concept" size=30 value="<?php p($form->concept) ?>">
+ <INPUT type="text" name="concept" size=30 value="<?php p($newentry->concept) ?>">
</td>
</tr>
<tr valign=top>
<td align=right><p><b><?php echo get_string("categories","glossary") ?>:</b></p></td>
<td>
- <?php
- $categories = get_records("glossary_categories","glossaryid",$glossary->id);
- echo "<select size=\"6\" name=\"categories[]\" multiple=\"yes\">";
- echo "<option value=\"0\">" . get_string("notcategorised","glossary") . "</optioon>";
+ <?php
+ $categories = get_records("glossary_categories","glossaryid",$glossary->id);
+ echo "<select size=\"6\" name=\"categories[]\" multiple=\"yes\">";
+ echo "<option value=\"0\">" . get_string("notcategorised","glossary") . "</optioon>";
- if ( $categories ) {
+ if ( $categories ) {
foreach ( $categories as $category ) {
- echo " <option ";
-
- if ( record_exists("glossary_entries_categories","entryid",$entry->id,"categoryid",$category->id) ) {
- echo "selected " ;
- }
- echo "value=\"$category->id\">$category->name</option>\n";
+ echo " <option ";
+ if (isset($newentry->id)) {
+ if ( record_exists("glossary_entries_categories","entryid",$newentry->id,"categoryid",$category->id) ) {
+ echo "selected " ;
+ }
+ }
+ echo "value=\"$category->id\">$category->name</option>\n";
}
- }
- ?>
- </select>
+ }
+ ?>
+ </select>
</td>
</tr>
<tr valign=top>
@@ -34,14 +35,18 @@
<td>
<select size="1" name="usedynalink">
<option value="1" <?php
- if ( $form->usedynalink ) {
- echo "selected";
+ if ( isset($newentry->usedynalink) ) {
+ if ($newentry->usedynalink) {
+ echo "selected";
+ }
}
?>
><?php echo get_string("yes") ?></option>
<option value="0" <?php
- if ( !$form->usedynalink ) {
- echo "selected";
+ if ( isset($newentry->usedynalink) ) {
+ if (!$newentry->usedynalink) {
+ echo "selected";
+ }
}
?>><?php echo get_string("no") ?>
</option>
@@ -53,14 +58,18 @@
<td>
<select size="1" name="casesensitive">
<option value="1" <?php
- if ( $form->casesensitive ) {
- echo "selected";
+ if ( isset($newentry->casesensitive) ) {
+ if ( $newentry->casesensitive ) {
+ echo "selected";
+ }
}
?>
><?php echo get_string("yes") ?></option>
<option value="0" <?php
- if ( !$form->casesensitive ) {
- echo "selected";
+ if ( isset($newentry->casesensitive) ) {
+ if ( !$newentry->casesensitive ) {
+ echo "selected";
+ }
}
?>><?php echo get_string("no") ?>
</option>
@@ -72,14 +81,18 @@
<td>
<select size="1" name="fullmatch">
<option value="1" <?php
- if ( $form->fullmatch ) {
- echo "selected";
+ if ( isset($newentry->fullmatch) ) {
+ if ( $newentry->fullmatch ) {
+ echo "selected";
+ }
}
?>
><?php echo get_string("yes") ?></option>
<option value="0" <?php
- if ( !$form->fullmatch ) {
- echo "selected";
+ if ( isset($newentry->fullmatch) ) {
+ if ( !$newentry->fullmatch ) {
+ echo "selected";
+ }
}
?>><?php echo get_string("no") ?>
</option>
@@ -103,16 +116,16 @@
</td>
<td>
<?php
- print_textarea($usehtmleditor, 20, 60, 680, 400, "text", $entry->text);
+ print_textarea($usehtmleditor, 20, 60, 680, 400, "text", $newentry->definition);
echo "<p align=right>";
helpbutton("textformat", get_string("helpformatting"));
print_string("formattexttype");
echo ":&nbsp;";
- if (!$form->format) {
- $form->format = $defaultformat;
+ if (!isset($newentry->format)) {
+ $newentry->format = $defaultformat;
}
- choose_from_menu(format_text_menu(), "format", $entry->format, "");
+ choose_from_menu(format_text_menu(), "format", $newentry->format, "");
echo "</p>";
?>
</td>
@@ -131,13 +144,14 @@
<tr>
<td colspan=2>
<p align=center>
- <?php if ($entry->id) {
- echo "<input type=\"hidden\" name=entry value=\"$entry->id\">";
+ <?php if (isset($newentry->id)) {
+ echo "<input type=\"hidden\" name=e value=\"$newentry->id\">";
}
?>
<input type="hidden" name=id value="<?=$cm->id ?>">
- <input type="hidden" name=currentview value="<?=$currentview ?>">
+ <input type="hidden" name=tab value="<?=$tab ?>">
<input type="hidden" name=cat value="<?=$cat ?>">
+ <input type="hidden" name=confirm value="1">
<input type="submit" value="<?php print_string("savechanges") ?>">
<input type="reset" value="<?php print_string("revert") ?>">
View
233 mod/glossary/edit.php
@@ -6,8 +6,9 @@
require_variable($id); // Course Module ID
optional_variable($e); // EntryID
+optional_variable($confirm,0); // proceed. Edit the edtry
-optional_variable($currentview); // categories if by category?
+optional_variable($tab); // categories if by category?
optional_variable($cat); // CategoryID
if (! $cm = get_record("course_modules", "id", $id)) {
@@ -27,124 +28,121 @@
if (! $glossary = get_record("glossary", "id", $cm->instance)) {
error("Course module is incorrect");
}
-
-if ($e) {
- $form = get_record("glossary_entries", "id", $e);
-
- $newentry->id = $form->id;
- $newentry->concept = $form->concept;
- $newentry->definition = $form->definition;
- $newentry->format = $form->format;
- $newentry->timemodified = time();
-
- $entry->id = $form->id;
- $entry->text = $form->definition;
- $entry->format = $form->format;
-} else {
- if ($form = data_submitted()) {
- /// If data submitted, then process and store.
- $timenow = time();
-
- $form->text = clean_text($form->text, $form->format);
-
- if ($entry) {
- $newentry->id = $entry;
- $newentry->course = $glossary->course;
- $newentry->glossaryid = $glossary->id;
- $newentry->concept = $form->concept;
- $newentry->definition = $form->text;
- $newentry->format = $form->format;
- $newentry->usedynalink = $form->usedynalink;
- $newentry->casesensitive = $form->casesensitive;
- $newentry->fullmatch = $form->fullmatch;
- $newentry->timemodified = time();
- $newentry->teacherentry = isteacher($course->id,$USER->id);
-
- $permissiongranted = 1;
- if ( !$glossary->allowduplicatedentries ) {
- $dupentries = get_records("glossary_entries","UCASE(concept)", strtoupper($newentry->concept));
- if ($dupentries) {
- foreach ($dupentries as $curentry) {
- if ( $glossary->id == $curentry->glossaryid ) {
- if ( $curentry->id != $entry ) {
- $permissiongranted = 0;
- }
- }
- }
- }
- }
- if ( $permissiongranted ) {
- $newentry->attachment = $_FILES["attachment"];
- if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
- $newentry->attachment = $newfilename;
- } else {
- unset($newentry->attachment);
- }
- if (! update_record("glossary_entries", $newentry)) {
- error("Could not update your glossary");
- } else {
- add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&eid=$newentry->id", "$newentry->id");
- }
- } else {
- error("Could not update this glossary entry because this concept already exist.");
- }
- } else {
- $newentry->userid = $USER->id;
- $newentry->course = $glossary->course;
- $newentry->glossaryid = $glossary->id;
- $newentry->concept = $form->concept;
- $newentry->definition = $form->text;
- $newentry->format = $form->format;
- $newentry->timecreated = time();
- $newentry->usedynalink = $form->usedynalink;
- $newentry->casesensitive = $form->casesensitive;
- $newentry->fullmatch = $form->fullmatch;
- $newentry->timemodified = time();
- $newentry->teacherentry = isteacher($course->id,$USER->id);
- $newentry->sourceglossaryid = 0;
-
- $permissiongranted = 1;
- if ( !$glossary->allowduplicatedentries ) {
- $dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept), "glossaryid", $glossary->id);
- if ($dupentries) {
- $permissiongranted = 0;
+if ( $confirm ) {
+ $form = data_submitted();
+
+ $timenow = time();
+ $form->text = clean_text($form->text, $form->format);
+
+ $newentry->course = $glossary->course;
+ $newentry->glossaryid = $glossary->id;
+
+ $newentry->concept = $form->concept;
+ $newentry->definition = $form->text;
+ $newentry->format = $form->format;
+ $newentry->usedynalink = $form->usedynalink;
+ $newentry->casesensitive = $form->casesensitive;
+ $newentry->fullmatch = $form->fullmatch;
+ $newentry->timemodified = $timenow;
+
+ if ($e) {
+ $newentry->id = $e;
+
+ $permissiongranted = 1;
+ if ( !$glossary->allowduplicatedentries ) {
+ if ($dupentries = get_records("glossary_entries","UCASE(concept)", strtoupper($newentry->concept))) {
+ foreach ($dupentries as $curentry) {
+ if ( $glossary->id == $curentry->glossaryid ) {
+ if ( $curentry->id != $entry ) {
+ $permissiongranted = 0;
+ break;
}
+ }
}
- if ( $permissiongranted ) {
- if (! $newentry->id = insert_record("glossary_entries", $newentry)) {
- error("Could not insert this new entry");
- } else {
- $newentry->attachment = $_FILES["attachment"];
- if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
- $newentry->attachment = $newfilename;
- } else {
- unset($newentry->attachment);
- }
- set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);
-
- add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id&currentview=$currentview&cat=$cat", "$newentry->id");
- }
+ }
+ }
+
+ if ( $permissiongranted ) {
+ $newentry->attachment = $_FILES["attachment"];
+ if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
+ $newentry->attachment = $newfilename;
+ } else {
+ unset($newentry->attachment);
+ }
+ if (! update_record("glossary_entries", $newentry)) {
+ error("Could not update your glossary");
+ } else {
+ add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&eid=$newentry->id&tab=$tab&cat=$cat", "$newentry->id");
+ }
+ } else {
+ error("Could not update this glossary entry because this concept already exist.");
+ }
+ } else {
+ $newentry->userid = $USER->id;
+ $newentry->timecreated = $timenow;
+ $newentry->sourceglossaryid = 0;
+ $newentry->approved = $glossary->defaultapproval or isteacher($course->id);
+ $newentry->teacherentry = isteacher($course->id);
+
+ $permissiongranted = 1;
+ if ( !$glossary->allowduplicatedentries ) {
+ if ($dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept), "glossaryid", $glossary->id)) {
+ $permissiongranted = 0;
+ }
+ }
+ if ( $permissiongranted ) {
+ if (! $newentry->id = insert_record("glossary_entries", $newentry)) {
+ error("Could not insert this new entry");
+ } else {
+ $newentry->attachment = $_FILES["attachment"];
+ if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
+ $newentry->attachment = $newfilename;
} else {
- error("Could not insert this glossary entry because this concept already exist.");
- }
- }
-
- delete_records("glossary_entries_categories","entryid",$entry);
-
- if ( $categories ) {
- $newcategory->entryid = $newentry->id;
- foreach ($categories as $category) {
- if ( $category > 0 ) {
- $newcategory->categoryid =$category;
- insert_record("glossary_entries_categories",$newcategory);
- } else {
- break;
- }
+ unset($newentry->attachment);
}
- }
- redirect("view.php?id=$cm->id&eid=$newentry->id");
- die;
- }
+ set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);
+ add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id&tab=$tab&cat=$cat", "$newentry->id");
+ }
+ } else {
+ error("Could not insert this glossary entry because this concept already exist.");
+ }
+ }
+
+ delete_records("glossary_entries_categories","entryid",$e);
+
+ if ( $categories ) {
+ $newcategory->entryid = $newentry->id;
+ foreach ($categories as $category) {
+ if ( $category > 0 ) {
+ $newcategory->categoryid =$category;
+ insert_record("glossary_entries_categories",$newcategory);
+ } else {
+ break;
+ }
+ }
+ }
+ redirect("view.php?id=$cm->id&eid=$newentry->id");
+ die;
+} else {
+ if ($e) {
+ $form = get_record("glossary_entries", "id", $e);
+
+ $newentry->id = $form->id;
+ $newentry->concept = $form->concept;
+ $newentry->definition = $form->definition;
+ $newentry->format = $form->format;
+ $newentry->timemodified = time();
+ $newentry->approved = $glossary->defaultapproval or isteacher($course->id);
+ $newentry->usedynalink = $form->usedynalink;
+ $newentry->casesensitive = $form->casesensitive;
+ $newentry->fullmatch = $form->fullmatch;
+ } else {
+ $newentry->concept = "";
+ $newentry->definition = "";
+ $newentry->usedynalink = 1;
+ $newentry->casesensitive = 0;
+ $newentry->fullmatch = 1;
+ }
}
/// Otherwise fill and print the form.
@@ -160,11 +158,6 @@
$onsubmit = "";
}
-if (empty($entry)) {
- $entry->text = "";
- $entry->format = $defaultformat;
-}
-
print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->
<A HREF=\"index.php?id=$course->id\">$strglossaries</A> ->
View
9 mod/glossary/formats/2.php
@@ -1,6 +1,6 @@
<?PHP // $Id$
-function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $currentview="",$cat="") {
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $tab="",$cat="") {
global $THEME, $CFG, $USER;
$colour = $THEME->cellheading2;
@@ -16,7 +16,10 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
print_user_picture($user->id, $course->id, $user->picture);
}
echo "</td>";
- echo "<td nowrap width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
+ echo "<td nowrap valign=\"top\" width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
+ if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
+ echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
+ }
if ($entry->attachment) {
$entry->course = $glossary->course;
echo "<table border=0 align=right><tr><td>";
@@ -36,7 +39,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
echo "\n<td width=100% bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
if ($entry) {
echo format_text($entry->definition, $entry->format);
- glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat);
+ glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat);
} else {
echo "<center>";
View
11 mod/glossary/formats/3.php
@@ -1,6 +1,6 @@
<?PHP // $Id$
-function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $currentview="",$cat="") {
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $tab="",$cat="") {
global $THEME, $CFG, $USER;
$colour = $THEME->cellheading2;
@@ -16,8 +16,11 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
print_user_picture($user->id, $course->id, $user->picture);
}
echo "</td>";
- echo "<td nowrap width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
+ echo "<td align=\"top\" nowrap width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
if ($entry) {
+ if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
+ echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
+ }
echo "<b>$entry->concept</b><br />";
echo "<font size=\"2\">$strby $user->firstname $user->lastname</font>";
echo "&nbsp;&nbsp;<font size=1>(".get_string("lastedited").": ".
@@ -27,7 +30,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
echo "\n<tr>";
echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostside\">&nbsp;</td>";
- echo "\n<td width=100% bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
+ echo "\n<td width=100% align=\"top\" bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
if ($entry) {
if ($entry->attachment) {
$entry->course = $course->id;
@@ -42,7 +45,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
}
echo format_text($entry->definition, $entry->format);
- glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat);
+ glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat);
} else {
echo "<center>";
View
38 mod/glossary/formats/4.php
@@ -0,0 +1,38 @@
+<?PHP // $Id$
+
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab="",$cat="") {
+ global $THEME, $USER;
+
+ if ( $entry ) {
+ $colour = $THEME->cellheading2;
+
+ echo "\n<table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
+
+ echo "\n<tr>";
+ echo "<td width=100% bgcolor=\"$colour\">";
+ $entry->course = $course->id;
+ if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
+ echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
+ }
+ if ($entry->attachment) {
+ echo "<table border=0 align=right><tr><td>";
+ echo glossary_print_attachments($entry, "html");
+ echo "</td></tr></table>";
+ }
+ echo "<b>" . get_string("question","glossary") . ":</b> $entry->concept<br>";
+ echo "&nbsp;&nbsp;<font size=1>".get_string("lastedited").": ".userdate($entry->timemodified)."</font></tr>";
+ echo "\n<tr><td width=100% bgcolor=\"$THEME->cellcontent\">";
+ echo "<b>" . get_string("answer","glossary") . ":</b> " . format_text($entry->definition, $entry->format);
+
+ glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat);
+ echo "</td></tr></table>\n";
+
+ } else {
+ echo "<center>";
+ print_string("noentry", "glossary");
+ echo "</center>";
+ }
+
+}
+
+?>
View
44 mod/glossary/formats/5.php
@@ -0,0 +1,44 @@
+<?PHP // $Id$
+
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab="",$cat="") {
+ global $THEME, $USER;
+
+ $colour = $THEME->cellheading2;
+
+ echo "\n<table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
+
+ echo "\n<tr>";
+ echo "<td width=100% bgcolor=\"$colour\">";
+ if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
+ echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
+ }
+ if ($entry->attachment) {
+ $entry->course = $course->id;
+ echo "<table border=0 align=right><tr><td>";
+ echo glossary_print_attachments($entry, "html");
+ echo "</td></tr></table>";
+ }
+ echo "<b>$entry->concept</b><br>";
+ if ($entry) {
+ echo "&nbsp;&nbsp;<font size=1>".get_string("lastedited").": ".userdate($entry->timemodified)."</font>";
+ }
+ echo "</tr>";
+
+ echo "\n<tr><td width=100% bgcolor=\"$THEME->cellcontent\">";
+ if ($entry) {
+ echo format_text($entry->definition, $entry->format);
+
+ glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat);
+
+ } else {
+ echo "<center>";
+ print_string("noentry", "glossary");
+ echo "</center>";
+ }
+ echo "</td></tr>";
+
+ echo "</table>\n";
+
+}
+
+?>
View
342 mod/glossary/lib.php
@@ -7,8 +7,10 @@
define("GLOSSARY_SHOW_ALL_CATEGORIES", 0);
define("GLOSSARY_SHOW_NOT_CATEGORISED", -1);
+
define("GLOSSARY_STANDARD_VIEW", 0);
define("GLOSSARY_CATEGORY_VIEW", 1);
+define("GLOSSARY_APPROVAL_VIEW", 2);
define("GLOSSARY_FORMAT_SIMPLE", 0);
define("GLOSSARY_FORMAT_CONTINUOUS", 1);
@@ -184,49 +186,79 @@ function glossary_get_entries($glossaryid, $entrylist) {
WHERE glossaryid = '$glossaryid'
AND id IN ($entrylist)");
}
+function glossary_get_entries_sorted($glossary, $where="", $orderby="") {
+global $CFG;
+ if ($where) {
+ $where = " and $where";
+ }
+ if ($orderby) {
+ $orderby = " ORDER BY $orderby";
+ }
+ return get_records_sql("SELECT *
+ FROM {$CFG->prefix}glossary_entries
+ WHERE (glossaryid = $glossary->id or sourceglossaryid = $glossary->id) $where $orderby");
+}
+
+function glossary_get_entries_by_category($glossary, $cat, $where="", $orderby="") {
+global $CFG;
+ if ($where) {
+ $where = " and $where";
+ }
+ if ($orderby) {
+ $orderby = " ORDER BY $orderby";
+ }
+ return get_records_sql("SELECT ge.*
+ FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories c
+ WHERE (ge.id = c.entryid and c.categoryid = $cat) and
+ (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) $where $orderby");
+}
-function glossary_print_entry($course, $cm, $glossary, $entry, $currentview="",$cat="") {
+function glossary_print_entry($course, $cm, $glossary, $entry, $tab="",$cat="") {
global $THEME, $USER, $CFG;
-
- $permissiongranted = 0;
- $formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
- $functionname = "glossary_print_entry_by_format";
-
- $basicformat = ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
- $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS);
- if ( !$basicformat ) {
- if ( file_exists($formatfile) ) {
- include_once($formatfile);
- if (function_exists($functionname) ) {
- $permissiongranted = 1;
- }
+
+ if ($entry->approved or $USER->id == $entry->userid or $tab == GLOSSARY_APPROVAL_VIEW) {
+ $permissiongranted = 0;
+ $formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
+ $functionname = "glossary_print_entry_by_format";
+
+ $basicformat = ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
+ $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS);
+ if ( !$basicformat ) {
+ if ( file_exists($formatfile) ) {
+ include_once($formatfile);
+ if (function_exists($functionname) ) {
+ $permissiongranted = 1;
+ }
+ }
+ } else {
+ $permissiongranted = 1;
}
- } else {
- $permissiongranted = 1;
- }
- if ( !$basicformat and $permissiongranted ) {
- glossary_print_entry_by_format($course, $cm, $glossary, $entry,$currentview,$cat);
- } else {
- switch ( $glossary->displayformat ) {
- case GLOSSARY_FORMAT_SIMPLE:
- glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview,$cat);
- break;
- case GLOSSARY_FORMAT_CONTINUOUS:
- glossary_print_entry_continuous($course, $cm, $glossary, $entry,$currentview,$cat);
- break;
+ if ( !$basicformat and $permissiongranted ) {
+ glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab,$cat);
+ } else {
+ switch ( $glossary->displayformat ) {
+ case GLOSSARY_FORMAT_SIMPLE:
+ glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab,$cat);
+ break;
+ case GLOSSARY_FORMAT_CONTINUOUS:
+ glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab,$cat);
+ break;
+ }
}
}
-
}
-function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview="",$cat="") {
+function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab="",$cat="") {
global $THEME, $USER;
$colour = $THEME->cellheading2;
echo "\n<TR>";
- echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
+ echo "<TD WIDTH=100% valign=\"top\" BGCOLOR=\"#FFFFFF\">";
+ if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
+ echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
+ }
if ($entry->attachment) {
$entry->course = $course->id;
echo "<table border=0 align=right><tr><td>";
@@ -235,14 +267,17 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$curren
}
echo "<b>$entry->concept</b>: ";
echo format_text($entry->definition, $entry->format);
- glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat);
+ glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat);
echo "</td>";
echo "</TR>";
}
-function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$currentview="",$cat="") {
+function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab="",$cat="") {
global $THEME, $USER;
if ($entry) {
+ if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
+ echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
+ }
if ($entry->attachment) {
$entry->course = $course->id;
echo "<table border=0 align=right><tr><td>";
@@ -252,31 +287,34 @@ function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$curren
echo " $entry->concept ";
echo format_text($entry->definition, $entry->format);
- glossary_print_entry_icons($course, $cm, $glossary, $entry, $currentview, $cat);
+ glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat);
}
}
-function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview="",$cat="") {
+function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat="") {
global $THEME, $USER;
$importedentry = ($entry->sourceglossaryid == $glossary->id);
$isteacher = isteacher($course->id);
$ismainglossary = $glossary->mainglossary;
- echo "<p align=\"right\">";
+ echo "<p align=\"right\"><font size=1>";
+ if (!$entry->approved) {
+ echo get_string("entryishidden","glossary");
+ }
$count = count_records("glossary_comments","entryid",$entry->id);
if ($count) {
- echo "<font size=1><a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count ";
+ echo " <a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count ";
if ($count == 1) {
print_string("comment", "glossary");
} else {
print_string("comments", "glossary");
}
- echo "</a></font> ";
+ echo "</a>";
}
-
+ echo "</font>";
if ( $glossary->allowcomments ) {
- echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id\"><img alt=\"" . get_string("addcomment","glossary") . "\" src=\"comment.gif\" height=16 width=16 border=0></a> ";
+ echo " <a href=\"comment.php?id=$cm->id&eid=$entry->id\"><img alt=\"" . get_string("addcomment","glossary") . "\" src=\"comment.gif\" height=16 width=16 border=0></a> ";
}
if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
@@ -285,7 +323,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview
$mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry
- echo "<a href=\"exportentry.php?id=$cm->id&entry=$entry->id&currentview=$currentview&cat=$cat\"><img alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
+ echo " <a href=\"exportentry.php?id=$cm->id&entry=$entry->id&tab=$tab&cat=$cat\"><img alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
}
}
@@ -298,13 +336,13 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview
// Exported entries can be updated/deleted only by teachers in the main glossary
if ( !$importedentry and ($isteacher or !$ismainglossary) ) {
- echo "<a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&currentview=$currentview&cat=$cat\"><img alt=\"" . get_string("delete") . "\"src=\"";
+ echo " <a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\"><img alt=\"" . get_string("delete") . "\"src=\"";
echo $icon;
echo "\" height=11 width=11 border=0></a> ";
- echo "<a href=\"edit.php?id=$cm->id&e=$entry->id&currentview=$currentview&cat=$cat\"><img alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
+ echo " <a href=\"edit.php?id=$cm->id&e=$entry->id&tab=$tab&cat=$cat\"><img alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
} elseif ( $importedentry ) {
- echo "<font size=-1>" . get_string("exportedentry","glossary") . "</font>";
+ echo " <font size=-1>" . get_string("exportedentry","glossary") . "</font>";
}
}
}
@@ -376,12 +414,12 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) {
{$CFG->prefix}glossary g $onlyvisibletable
WHERE ($conceptsearch OR $definitionsearch)
AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible
- AND g.id = $glossary->id";
+ AND g.id = $glossary->id AND e.approved != 0";
- $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
+// $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
- return get_records_sql("SELECT e.concept, e.definition, e.userid, e.timemodified, e.id, e.format FROM
- $selectsql ORDER BY e.concept ASC $limit");
+ return get_records_sql("SELECT e.concept, e.definition, e.userid, e.timemodified, e.id, e.format
+ FROM $selectsql ORDER BY e.concept ASC $limit");
}
function glossary_file_area_name($entry) {
@@ -710,39 +748,135 @@ function glossary_print_tabbed_table_end() {
echo "</center><p></td></tr></table></center>";
}
-function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder = "") {
-global $CFG, $THEME;
- $strselectletter = get_string("selectletter", "glossary");
- $strspecial = get_string("special", "glossary");
- $strallentries = get_string("allentries", "glossary");
- $strsort = get_string("sortchronogically", "glossary");
- $strsortbycreation = get_string("sortbycreation", "glossary");
- $strsortbylastupdate = get_string("sortbylastupdate", "glossary");
+function glossary_print_approval_menu($cm, $glossary, $l, $sortkey, $sortorder = "",$tab=GLOSSARY_STANDARD_VIEW) {
+ $entriesawaiting = get_string("entriesawaitingapproval", "glossary");
+ echo "<center>$entriesawaiting<p>";
- $output = "";
- if ($glossary->showalphabet) {
- $output .= get_string("explainalphabet","glossary").'<br />';
+ if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+ echo '<center>' . get_string("explainalphabet","glossary") . '<br /><p>';
}
+ glossary_print_special_links($cm, $glossary,$l, $tab);
+
+ glossary_print_alphabet_links($cm, $glossary,$l, $tab);
+
+ glossary_print_all_links($cm, $glossary,$l, $tab);
+
+ glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
+}
+
+function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder = "", $tab=GLOSSARY_STANDARD_VIEW) {
+ if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+ echo '<center>' . get_string("explainalphabet","glossary") . '<br /><p>';
+ }
+ glossary_print_special_links($cm, $glossary,$l, $tab);
+
+ glossary_print_alphabet_links($cm, $glossary,$l, $tab);
+
+ glossary_print_all_links($cm, $glossary,$l, $tab);
+
+ glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
+}
+
+function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
+global $CFG, $THEME;
+ echo "<table border=0 width=100%>";
+ echo "<tr>";
+
+ echo "<td align=center width=20%>";
+ if ( isteacher($course->id) ) {
+ $options['id'] = $cm->id;
+ $options['cat'] = $cat;
+ echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get");
+ }
+ echo "</td>";
+
+ echo "<td align=center width=60%>";
+ echo "<b>";
+
+ $menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary");
+ $menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary");
- echo "<center>$output<p>";
+ $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
+ $selected = "";
+ if ( $categories ) {
+ foreach ($categories as $currentcategory) {
+ $url = $currentcategory->id;
+ if ( $category ) {
+ if ($currentcategory->id == $category->id) {
+ $selected = $url;
+ }
+ }
+ $menu[$url] = $currentcategory->name;
+ }
+ }
+ if ( !$selected ) {
+ $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
+ }
+
+ if ( $category ) {
+ echo $category->name;
+ } else {
+ if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
+
+ echo get_string("entrieswithoutcategory","glossary");
+ $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
+
+ } elseif ( $cat == GLOSSARY_SHOW_ALL_CATEGORIES ) {
+
+ echo get_string("allcategories","glossary");
+ $selected = GLOSSARY_SHOW_ALL_CATEGORIES;
+
+ }
+ }
+ echo "</b></td>";
+ echo "<td align=center width=20%>";
+
+ echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&tab=" . GLOSSARY_CATEGORY_VIEW . "&cat=", $menu, "catmenu", $selected, "",
+ "", "", false);
- if ( $glossary->showspecial ) {
+ echo "</td>";
+ echo "</tr>";
+
+ echo "<tr><td colspan=3><hr></td></tr>";
+ echo "</table>";
+}
+
+function glossary_print_all_links($cm, $glossary, $l, $tab) {
+global $CFG;
+ if ( $glossary->showall and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+ $strallentries = get_string("allentries", "glossary");
+ if ( $l == "ALL" ) {
+ echo "<b>$strallentries</b>";
+ } else {
+ $strexplainall = strip_tags(get_string("explainall","glossary"));
+ echo "<a title=\"$strexplainall\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL&tab=$tab\">$strallentries</a>";
+ }
+ }
+}
+
+function glossary_print_special_links($cm, $glossary, $l, $tab) {
+global $CFG;
+ if ( $glossary->showspecial and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
+ $strspecial = get_string("special", "glossary");
if ( $l == "SPECIAL" ) {
echo "<b>$strspecial</b> | ";
} else {
$strexplainspecial = strip_tags(get_string("explainspecial","glossary"));
- echo "<a title=\"$strexplainspecial\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial</a> | ";
+ echo "<a title=\"$strexplainspecial\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL&tab=$tab\">$strspecial</a> | ";
}
}
+}
- if ( $glossary->showalphabet ) {
+function glossary_print_alphabet_links($cm, $glossary,$l, $tab) {
+global $CFG;
+ if ( $glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
$alphabet = explode("|", get_string("alphabet","glossary"));
$letters_by_line = 14;
for ($i = 0; $i < count($alphabet); $i++) {
if ( $l == $alphabet[$i] and $l) {
echo "<b>$alphabet[$i]</b>";
} else {
- echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]\">$alphabet[$i]</a>";
+ echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]&tab=$tab\">$alphabet[$i]</a>";
}
if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
echo " | ";
@@ -751,15 +885,14 @@ function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder =
}
}
}
+}
+
+function glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab) {
+global $CFG;
+ $strsort = get_string("sortchronogically", "glossary");
+ $strsortbycreation = get_string("sortbycreation", "glossary");
+ $strsortbylastupdate = get_string("sortbylastupdate", "glossary");
- if ( $glossary->showall ) {
- if ( $l == "ALL" ) {
- echo "<b>$strallentries</b>";
- } else {
- $strexplainall = strip_tags(get_string("explainall","glossary"));
- echo "<a title=\"$strexplainall\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries</a>";
- }
- }
$neworder = "";
if ( $sortorder ) {
if ( $sortorder == "asc" ) {
@@ -808,71 +941,8 @@ function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder =
$cordertitle = get_string("ascending","glossary");
$uordertitle = get_string("ascending","glossary");
}
- echo "<br>$strsort: $ubtag<a title=\"$strsortbylastupdate $uordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=UPDATE$uneworder\">$strsortbylastupdate$uicon</a>$uendbtag | ".
- "$cbtag<a title=\"$strsortbycreation $cordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder\">$strsortbycreation$cicon</a>$cendbtag</p>";
-}
-
-function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
-global $CFG, $THEME;
- echo "<table border=0 width=100%>";
- echo "<tr>";
-
- echo "<td align=center width=20%>";
- if ( isteacher($course->id) ) {
- $options['id'] = $cm->id;
- $options['cat'] = $cat;
- echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get");
- }
- echo "</td>";
-
- echo "<td align=center width=60%>";
- echo "<b>";
-
- $menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary");
- $menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary");
-
- $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
- if ( $categories ) {
- foreach ($categories as $currentcategory) {
- $url = $currentcategory->id;
- if ( $category ) {
- if ($currentcategory->id == $category->id) {
- $selected = $url;
- }
- }
- $menu[$url] = $currentcategory->name;
- }
- }
- if ( !$selected ) {
- $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
- }
-
- if ( $category ) {
- echo $category->name;
- } else {
- if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
-
- echo get_string("entrieswithoutcategory","glossary");
- $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
-
- } elseif ( $cat == GLOSSARY_SHOW_ALL_CATEGORIES ) {
-
- echo get_string("allcategories","glossary");
- $selected = GLOSSARY_SHOW_ALL_CATEGORIES;
-
- }
- }
- echo "</b></td>";
- echo "<td align=center width=20%>";
-
- echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&currentview=categories&cat=", $menu, "catmenu", $selected, "",
- "", "", false);
-
- echo "</td>";
- echo "</tr>";
-
- echo "<tr><td colspan=3><hr></td></tr>";
- echo "</table>";
+ echo "<br>$strsort: $ubtag<a title=\"$strsortbylastupdate $uordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=UPDATE$uneworder&tab=$tab\">$strsortbylastupdate$uicon</a>$uendbtag | ".
+ "$cbtag<a title=\"$strsortbycreation $cordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder&tab=$tab\">$strsortbycreation$cicon</a>$cendbtag</p>";
}
function glossary_sort_entries ( $entry0, $entry1 ) {
View
19 mod/glossary/mod.html
@@ -132,6 +132,25 @@
</TD>
</TR>
<TR valign=top>
+ <TD align=right><P><B><?php echo get_string("defaultapproval", "glossary") ?>:</B></P></TD>
+ <TD>
+ <select size="1" name="defaultapproval">
+ <option value="1" <?php
+ if ( $form->defaultapproval ) {
+ echo "selected";
+ }
+ ?>
+ ><?php echo get_string("yes") ?></option>
+ <option value="0" <?php
+ if ( !$form->defaultapproval ) {
+ echo "selected";
+ }
+ ?>><?php echo get_string("no") ?>
+ </option>
+ </select> <?php helpbutton("defaultapproval", get_string("defaultapproval", "glossary"), "glossary") ?>
+ </TD>
+</TR>
+<TR valign=top>
<td colspan=2><hr>
</tr>
</tr>
View
2  mod/glossary/version.php
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003101800; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2003102000; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)
$release = "0.5 development"; // User-friendly version number
View
310 mod/glossary/view.php
@@ -10,7 +10,7 @@
optional_variable($search, ""); // search string
optional_variable($includedefinition); // include definition in search function?
- optional_variable($currentview,""); // browsing entries by categories?
+ optional_variable($tab); // browsing entries by categories?
optional_variable($cat); // categoryID
optional_variable($sortkey,""); // Sorted view: CREATION or UPDATE
@@ -36,19 +36,41 @@
add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id");
- if ( $sortorder ) {
- $sortorder = strtolower($sortorder);
+/// checking for valid values for sortorder and sortkey
+ if ( $sortorder = strtolower($sortorder) ) {
if ($sortorder != "asc" and $sortorder != "desc") {
$sortorder = "";
+ } else {
+ $l = "";
+ $search ="";
}
}
- if ( $sortorder ) {
- $l = "";
- $search ="";
+ if ( $sortkey = strtoupper($sortkey) ) {
+ if ($sortkey != "CREATION" and $sortkey != "UPDATE") {
+ $sortkey = "";
+ }
}
- $search = trim(strip_tags($search));
- if ($search and !$entryid) {
+ if ( $sortkey or $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
+ if ( !$sortkey and $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
+ $sortkey = "CREATION";
+ $sortorder = "asc";
+ }
+ if ( !$sortorder ) {
+ $sortorder = "asc";
+ }
+ if ($sortkey == "CREATION") {
+ $orderby = "timecreated $sortorder";
+ } else {
+ $orderby = "timemodified $sortorder";
+ }
+ } else {
+ $orderby = "concept ASC";
+ }
+
+// creating matrix of words to search if apply
+ $search = trim(strip_tags($search));
+ if ($search and !$eid) {
$l = "";
$searchterms = explode(" ", $search); // Search for words independently
foreach ($searchterms as $key => $searchterm) {
@@ -57,27 +79,26 @@
}
}
$search = trim(implode(" ", $searchterms));
- $currentview = "";
+ $tab = GLOSSARY_STANDARD_VIEW;
} elseif ($eid) {
$search = "";
}
-
+
$alphabet = explode("|", get_string("alphabet","glossary"));
- if ($l == "" and $search == "" and $sortkey == "" and ($eid == "" or $eid == 0)) {
+ if ($l == "" and $search == "" and $sortkey == "" and !$eid) {
+ // if the user is just entering the glossary...
$l = $alphabet[0];
} elseif ($eid) {
$l = "";
}
- if ($currentview) {
+ $category = "";
+ if ($tab == GLOSSARY_CATEGORY_VIEW) {
$l = "";
- $currentview = strtolower($currentview);
- if ($currentview) {
- if ($cat > 0) {
- $category = get_record("glossary_categories", "id", $cat);
- if (!$category) {
- $cat = "";
- }
+ if ($cat > 0) {
+ $category = get_record("glossary_categories", "id", $cat);
+ if (!$category) {
+ $cat = "";
}
}
}
@@ -107,20 +128,21 @@
/// Info box
if ( $glossary->intro ) {
- print_simple_box_start("center","70%");
+ print_simple_box_start("center","70%");
echo '<p align="center">';
echo $glossary->intro;
echo '</p>';
print_simple_box_end();
- }
+ }
/// Add button
-
- if (isteacher($course->id) or ($glossary->studentcanpost) and !isguest($course->id)) {
- $options = array ("id" => "$cm->id");
- echo '<center><p>';
- print_single_button("edit.php", $options, $straddentry);
- echo '</p></center>';
+ if (!isguest()) {
+ if ( isteacher($course->id) or $glossary->studentcanpost ) {
+ $options = array ("id" => "$cm->id");
+ echo '<center><p>';
+ print_single_button("edit.php", $options, $straddentry);
+ echo '</p></center><p>';
+ }
}
@@ -141,18 +163,6 @@
/// Tabbed browsing sections
- echo '<p align="center">';
- $data[0]->link = "view.php?id=$id";
- $data[0]->caption = get_string("standardview", "glossary");
-
- $data[1]->link = "view.php?id=$id&currentview=categories";
- $data[1]->caption = get_string("categoryview", "glossary");
-
- if ($currentview) {
- $currenttab = GLOSSARY_CATEGORY_VIEW; //1;
- } else {
- $currenttab = GLOSSARY_STANDARD_VIEW; //0;
- }
$glossary_tCFG->TabTableBGColor = $THEME->cellheading;
$glossary_tCFG->ActiveTabColor = $THEME->cellheading;
$glossary_tCFG->InactiveTabColor = $THEME->cellcontent2;
@@ -162,113 +172,140 @@
$glossary_tCFG->TabsPerRow = 5;
$glossary_tCFG->TabSeparation = 4;
- glossary_print_tabbed_table_start($data, $currenttab, $glossary_tCFG);
- echo "<center>";
- if ($currentview) {
- glossary_print_categories_menu($course, $cm, $glossary, $cat, $category);
- $currentcategory = "";
+ echo '<p align="center">';
+ $data[0]->link = "view.php?id=$id";
+ $data[0]->caption = get_string("standardview", "glossary");
+
+ $data[1]->link = "view.php?id=$id&tab=".GLOSSARY_CATEGORY_VIEW;
+ $data[1]->caption = get_string("categoryview", "glossary");
+
+ if (isteacher($course->id)) {
+ $data[2]->link = "view.php?id=$id&tab=".GLOSSARY_APPROVAL_VIEW;
+ $data[2]->caption = get_string("waitingapproval", "glossary");
+ }
- } else {
- glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder);
- if ($l or $sortkey) {
- $currentletter = "";
- } elseif ($search) {
- echo "<h3>$strsearch: $search</h3>";
- }
- echo "<hr>";
+ if ($tab == GLOSSARY_APPROVAL_VIEW and !isteacher($course->id)) {
+ $tab = GLOSSARY_STANDARD_VIEW;
+ }
+
+/// printing header of the current tab
+ echo "<center>";
+ glossary_print_tabbed_table_start($data, $tab, $glossary_tCFG);
+ switch ($tab) {
+ case GLOSSARY_CATEGORY_VIEW:
+ glossary_print_categories_menu($course, $cm, $glossary, $cat, $category);
+ break;
+ case GLOSSARY_APPROVAL_VIEW:
+ glossary_print_approval_menu($cm, $glossary, $l, $sortkey, $sortorder,$tab);
+ break;
+ case GLOSSARY_STANDARD_VIEW:
+ default:
+ glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder,$tab);
+ if ($search) {
+ echo "<h3>$strsearch: $search</h3>";
+ }
+ break;
}
+ echo "<hr>";
/// Printing the entries
- if ($search) { // looking for a term
- $allentries = glossary_search_entries($searchterms, $glossary, $includedefinition);
- } elseif ($eid) { // looking for an entry
- $allentries = get_records("glossary_entries", "id", $eid);
- } elseif ($currentview and $cat == GLOSSARY_SHOW_ALL_CATEGORIES) { // Browsing all categories
- $sql = "SELECT gec.id gecid, gc.name, gc.id CID, ge.*
- FROM {$CFG->prefix}glossary_entries ge,
- {$CFG->prefix}glossary_entries_categories gec,
- {$CFG->prefix}glossary_categories gc
- WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND
- gec.entryid = ge.id AND
- gc.id = gec.categoryid ";
- if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
- $sql .= "ORDER BY gc.name, ge.timecreated";
- } else {
- $sql .= "ORDER BY gc.name, ge.concept";
- }
- $allentries = get_records_sql($sql);
- } else { // looking for terms that begin with a specify letter or entries with no category associated
- if ( $sortkey == "CREATION" or $sortkey == "UPDATE" or $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
- if ( !$sortkey and $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
- $sortkey = "CREATION";
- $sortorder = "asc";
- }
- if ( !$sortorder ) {
- $sortorder = "asc";
+ switch ($tab) {
+ case GLOSSARY_CATEGORY_VIEW:
+ if ($cat == GLOSSARY_SHOW_ALL_CATEGORIES) {
+ $sql = "SELECT gec.id gecid, gc.name, gc.id CID, ge.*
+ FROM {$CFG->prefix}glossary_entries ge,
+ {$CFG->prefix}glossary_entries_categories gec,
+ {$CFG->prefix}glossary_categories gc
+ WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND
+ gec.entryid = ge.id AND
+ gc.id = gec.categoryid";
+
+ if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
+ $sql .= " ORDER BY gc.name, ge.timecreated";
+ } else {
+ $sql .= " ORDER BY gc.name, ge.concept";
+ }
+ $allentries = get_records_sql($sql);
+ } else {
+ if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
+ $allentries = glossary_get_entries_sorted($glossary, "",$orderby);
+ } else {
+ $allentries = glossary_get_entries_by_category($glossary, $cat, "",$orderby);
+ }
}
- if ($sortkey == "CREATION") {
- $orderby = "timecreated $sortorder";
- } else {
- $orderby = "timemodified $sortorder";
- }
- } else {
- $orderby = "concept ASC";
- }
- $ownentries = get_records("glossary_entries", "glossaryid", $glossary->id, $orderby);
- $importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id, $orderby);
-
- if ($ownentries and $importedentries) {
- $allentries = array_merge($ownentries, $importedentries);
- usort($allentries, glossary_sort_entries);
- } elseif ($importedentries) {
- $allentries = $importedentries;
- } elseif ($ownentries) {
- $allentries = $ownentries;
- }
+ $currentcategory = "";
+ break;
+ case GLOSSARY_APPROVAL_VIEW:
+ $allentries = glossary_get_entries_sorted($glossary, "approved = 0",$orderby);
+ $currentletter = "";
+ break;
+ case GLOSSARY_STANDARD_VIEW:
+ if ($search) { // looking for a term
+ $allentries = glossary_search_entries($searchterms, $glossary, $includedefinition);
+ } elseif ($eid) { // looking for an entry
+ $allentries = get_records_select("glossary_entries", "id = $eid");
+ } elseif ( $l or $sortkey ) {
+ $where = "";
+ if ($l != "ALL" and $l != "SPECIAL") {
+ switch ($CFG->dbtype) {
+ case "postgres7":
+ $where = "substr(ucase(concept),1," . strlen($l) . ") = '" . strtoupper($l) . "'";
+ break;
+ case "mysql":
+ $where = "left(ucase(concept)," . strlen($l) . ") = '$l'";
+ break;
+ default:
+ $where = "";
+ }
+ }
+ $allentries = glossary_get_entries_sorted($glossary, $where,$orderby);
+ }
+ $currentletter = "";
+ break;
}
+ $dumpeddefinitions = 0;
if ($allentries) {
if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
echo "<table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=left bgcolor=\"#FFFFFF\">";
}
- $dumpeddefinitions = 0;
foreach ($allentries as $entry) {
$dumptoscreen = 0;
$firstletter = strtoupper(substr(ltrim($entry->concept), 0, strlen($l)));
if ($l) {
if ($l == "ALL" or $sortkey == "CREATION" or $sortkey == "UPDATE" or $firstletter == $l) {
if ($currentletter != $firstletter[0]) {
- $currentletter = $firstletter[0];
+ if ($entry->approved or $USER->id == $entry->userid or $tab == GLOSSARY_APPROVAL_VIEW) {
+ $currentletter = $firstletter[0];
- if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
- if ($dumpeddefinitions > 0) {
- echo "</table></center><p>";
+ if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
+ if ($dumpeddefinitions > 0) {
+ echo "</table></center><p>";
+ }
+ echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
+ }
+ if ($l == "ALL" and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+ echo "<b>$currentletter</b>";
}
- echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
- }
- if ($l == "ALL" and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
- echo "<b>$currentletter</b>";
- }
- if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
- echo "\n</center></td></tr></table></center>";
- if ($dumpeddefinitions > 0) {
- echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5>";
+ if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
+ echo "\n</center></td></tr></table></center>";
+ if ($dumpeddefinitions > 0) {
+ echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5>";
+ }
}
}
- }
- $dumptoscreen = 1;
+ $dumptoscreen = 1;
+ }
} elseif ($l == "SPECIAL" and ord($firstletter) != ord("Ñ") and
(ord($firstletter) < ord("A") or ord($firstletter) > ord("Z"))) {
$dumptoscreen = 1;
}
} else {
- if ($currentview) {
+ if ($tab == GLOSSARY_CATEGORY_VIEW) {
if ($category) { // if we are browsing a category
- if (record_exists("glossary_entries_categories", "entryid", $entry->id, "categoryid", $category->id)) {
$dumptoscreen = 1;
- }
} else {
if ($cat == GLOSSARY_SHOW_NOT_CATEGORISED) { // Not categorized
if (! record_exists("glossary_entries_categories", "entryid", $entry->id)) {
@@ -276,19 +313,22 @@
}
} else { // All categories
if ($currentcategory != $entry->CID) {
- $currentcategory = $entry->CID;
- if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
- if ($dumpeddefinitions > 0) {
- echo "</table></center><p>";
+ if ($entry->approved or $USER->id == $entry->userid or $tab == GLOSSARY_APPROVAL_VIEW) {
+ $currentcategory = $entry->CID;
+ if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
+ if ($dumpeddefinitions > 0) {
+ echo "</table></center><p>";
+ }
+ echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=10><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
}
- echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=10><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
- }
- if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
- echo "<center>";
- }
- echo "<b>$entry->name</b>";
- if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
- echo "</center><p>";
+ if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
+ echo "<center>";
+ }
+ echo "<b>$entry->name</b>";
+ if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
+ echo "</center><p>";
+ }
+ $dumptoscreen = 1;
}
}
@@ -323,7 +363,7 @@
$entry->definition = highlight($search, $definition);
}
- glossary_print_entry($course, $cm, $glossary, $entry, $currentview, $cat);
+ glossary_print_entry($course, $cm, $glossary, $entry, $tab, $cat);
if ($glossary->displayformat != GLOSSARY_FORMAT_SIMPLE) {
echo "<p>";
@@ -342,11 +382,13 @@
}
print_simple_box_end();
} else {
- if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
- echo "</td></tr></table>";
- }
- if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
- echo "\n</table></center>";
+ switch ($glossary->displayformat) {
+ case GLOSSARY_FORMAT_CONTINUOUS:
+ echo "</td></tr></table>";
+ break;
+ case GLOSSARY_FORMAT_SIMPLE:
+ echo "\n</table></center>";
+ break;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.