From fb443f1acffe509fd4356b23ab2434fb3823b9ea Mon Sep 17 00:00:00 2001 From: willcast Date: Sun, 21 Sep 2003 17:08:41 +0000 Subject: [PATCH] - Now the entries could be categorized. - Any entry could belongs to many categories - Improved main page and add entry look. - Added PostgreSQL7 squema (Thanks Janne Mikkonen!) - Deleting entries also delete its attachments if any. --- lang/en/glossary.php | 15 +- lang/es/glossary.php | 13 +- mod/glossary/db/mysql.php | 16 +-- mod/glossary/db/mysql.sql | 2 +- mod/glossary/db/postgres7.php | 13 ++ mod/glossary/db/postgres7.sql | 79 +++++++++++ mod/glossary/deleteentry.html | 2 + mod/glossary/deleteentry.php | 28 +++- mod/glossary/edit.html | 35 ++++- mod/glossary/edit.php | 16 ++- mod/glossary/editcategories.html | 30 ++++ mod/glossary/editcategories.php | 233 +++++++++++++++++++++++++++++++ mod/glossary/exportentry.php | 18 +-- mod/glossary/formats/1.php | 4 +- mod/glossary/formats/2.php | 4 +- mod/glossary/lib.php | 110 +++++++++++++-- mod/glossary/version.php | 2 +- mod/glossary/view.php | 208 ++++++++++++--------------- 18 files changed, 661 insertions(+), 167 deletions(-) create mode 100644 mod/glossary/db/postgres7.php create mode 100644 mod/glossary/db/postgres7.sql create mode 100644 mod/glossary/editcategories.html create mode 100644 mod/glossary/editcategories.php diff --git a/lang/en/glossary.php b/lang/en/glossary.php index 5a818631a1a..10130e3da49 100644 --- a/lang/en/glossary.php +++ b/lang/en/glossary.php @@ -3,21 +3,31 @@ $string['addentry'] = "Add entry"; $string['allentries'] = "ALL"; +$string['allcategories'] = "All Categories"; $string['allowduplicatedentries'] = "Duplicated entries allowed"; $string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"; -$string['areyousuredelete'] = "Are you sure you want to delete this entry?"; +$string['areyousuredelete'] = "Are you sure you want to delete it?"; $string['attachment'] = "Attachment"; -$string['categoryview'] = "By Category"; +$string['back'] = "Back"; +$string['categories'] = "Categories"; +$string['categoryview'] = "By category"; +$string['category'] = "Category"; +$string['categorydeleted'] = "Category deleted"; $string['concept'] = "Concept"; $string['concepts'] = "Concepts"; $string['definition'] = "Definition"; $string['definitions'] = "Definitions"; $string['deleteentry'] = "Delete entry"; +$string['deletingnoneemptycategory'] = "If a non empty category is deleted, its relations with their entries will also be deleted. If you wish to delete the entries, you will have to do so manually."; $string['displayformat'] = "Display format"; $string['displayformatdefault'] = "Simple, dictionary style"; $string['displayformat1'] = "Full without author."; $string['displayformat2'] = "Full with author."; +$string['entries'] = "Entries"; +$string['entrieswithoutcategory'] = "Entries without category"; +$string['entry'] = "Entry"; $string['editentry'] = "Edit entry"; +$string['editcategories'] = "Edit categories"; $string['entryalreadyexist'] = "Entry already exist."; $string['entrydeleted'] = "Entry deleted."; $string['entryexported'] = "Entry succesfully exported."; @@ -27,6 +37,7 @@ $string['mainglossary'] = "Main glossary"; $string['modulename'] = "Glossary"; $string['modulenameplural'] = "Glossaries"; $string['newglossaryentries'] = "New glossary entries:"; +$string['nocategorized'] = "No categorized"; $string['noentries'] = "No entries found in this section"; $string['noentry'] = "No entry found."; $string['searchconcept'] = "Search:"; diff --git a/lang/es/glossary.php b/lang/es/glossary.php index 26c9fed9835..81ca2d6b1d6 100644 --- a/lang/es/glossary.php +++ b/lang/es/glossary.php @@ -3,21 +3,31 @@ $string['addentry'] = "Agregar entrada"; $string['allentries'] = "TODAS"; +$string['allcategories'] = "Todas las categorías"; $string['allowduplicatedentries'] = "Permitir entradas duplicadas"; $string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|Ñ|O|P|Q|R|S|T|U|V|W|X|Y|Z"; -$string['areyousuredelete'] = "¿Está seguro que desea borrar esta entrada?"; +$string['areyousuredelete'] = "¿Está seguro que desea borrarla?"; $string['attachment'] = "Adjunto"; +$string['back'] = "Volver"; +$string['categories'] = "Categorías"; $string['categoryview'] = "Vista por Categoría"; +$string['category'] = "Categoría"; +$string['categorydeleted'] = "Categoría eliminada"; $string['concept'] = "Concepto"; $string['concepts'] = "Conceptos"; $string['definition'] = "Definición"; $string['definitions'] = "Definiciones"; $string['deleteentry'] = "Borrar entrada"; +$string['deletingnoneemptycategory'] = "Si una categoría es eliminada por consiguiente su relación con las entradas también lo será. Si desea eliminar las entradas, tendrá que hacerlo manualmente."; $string['displayformat'] = "Formato de muestra de entradas"; $string['displayformatdefault'] = "Simple, estilo diccionario"; $string['displayformat1'] = "Completo sin autor."; $string['displayformat2'] = "Completo con autor."; $string['editentry'] = "Editar entrada"; +$string['editcategories'] = "Editar categorías"; +$string['entries'] = "Entradas"; +$string['entrieswithoutcategory'] = "Entradas sin categoría"; +$string['entry'] = "Entrada"; $string['entryalreadyexist'] = "Esta entrada ya existe."; $string['entrydeleted'] = "Entrada borrada."; $string['entryexported'] = "Entrada exportada con éxito."; @@ -27,6 +37,7 @@ $string['mainglossary'] = "Glosario principal"; $string['modulename'] = "Glosario"; $string['modulenameplural'] = "Glosarios"; $string['newglossaryentries'] = "Nuevas entradas en el glosario:"; +$string['nocategorized'] = "Sin categoría"; $string['noentries'] = "No se encontraro entradas en esta sección"; $string['noentry'] = "No se econtró ninguna entrada."; $string['searchconcept'] = "Buscar:"; diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php index f80af4a5d39..2fcaae6ba7f 100644 --- a/mod/glossary/db/mysql.php +++ b/mod/glossary/db/mysql.php @@ -49,18 +49,10 @@ function glossary_upgrade($oldversion) { `entryid` INT(10) UNSIGNED NOT NULL default '0', PRIMARY KEY (`categoryid`, `entryid`) ) TYPE=MyISAM COMMENT='categories of each glossary entry'"); - - // creating a default category for every glossary - execute_sql("INSERT INTO `{$CFG->prefix}glossary_categories` (`glossaryid`, `name`) - SELECT `id`, '" . get_string("main","glossary") . "' FROM `{$CFG->prefix}glossary`"); - - - // setting the default category for every entry. - execute_sql("INSERT INTO `{$CFG->prefix}glossary_entries_categories` (`categoryid`, `entryid`) - SELECT c.id, e.id - FROM `{$CFG->prefix}glossary_entries` e, `{$CFG->prefix}glossary_categories` c - WHERE e.glossaryid = c.glossaryid"); - + } + + if ( $oldversion < 2003092100 ) { + execute_sql("ALTER TABLE `{$CFG->prefix}glossary_entries_categories` CHANGE `categoryid` `categoryid` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL "); } return true; diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql index 9c8cc9ea273..c72df48210d 100644 --- a/mod/glossary/db/mysql.sql +++ b/mod/glossary/db/mysql.sql @@ -58,7 +58,7 @@ CREATE TABLE prefix_glossary_categories ( # CREATE TABLE prefix_glossary_entries_categories ( - categoryid int(10) unsigned NOT NULL default '1', + categoryid int(10) unsigned NOT NULL default '0', entryid int(10) unsigned NOT NULL default '0', PRIMARY KEY (categoryid, entryid) ) TYPE=MyISAM COMMENT='categories of each glossary entry'; diff --git a/mod/glossary/db/postgres7.php b/mod/glossary/db/postgres7.php new file mode 100644 index 00000000000..1ede63bea4a --- /dev/null +++ b/mod/glossary/db/postgres7.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/mod/glossary/db/postgres7.sql b/mod/glossary/db/postgres7.sql new file mode 100644 index 00000000000..92fc5cf5c7e --- /dev/null +++ b/mod/glossary/db/postgres7.sql @@ -0,0 +1,79 @@ +# This file contains a complete database schema for all the +# tables used by this module, written in SQL + +# It may also contain INSERT statements for particular data +# that may be used, especially new entries in the table log_display + +# +# Table structure for table `glossary` +# + +CREATE TABLE prefix_glossary ( + id SERIAL, + course int4 NOT NULL default '0', + name varchar(255) NOT NULL default '', + studentcanpost int2 NOT NULL default '0', + allowduplicatedentries int2 NOT NULL default '0', + displayformat int2 NOT NULL default '0', + mainglossary int2 NOT NULL default '0', + showspecial int2 NOT NULL default '1', + showalphabet int2 NOT NULL default '1', + showall int2 NOT NULL default '1', + timecreated int4 NOT NULL default '0', + timemodified int4 NOT NULL default '0', + PRIMARY KEY (id) +); + +# +# Table structure for table `glossary_entries` +# + +CREATE TABLE prefix_glossary_entries ( + id SERIAL, + glossaryid int4 NOT NULL default '0', + userid int4 NOT NULL default '0', + concept varchar(255) NOT NULL default '', + definition text NOT NULL, + format int2 NOT NULL default '0', + attachment VARCHAR(100) NOT NULL default '', + timecreated int4 NOT NULL default '0', + timemodified int4 NOT NULL default '0', + teacherentry int2 NOT NULL default '0', + PRIMARY KEY(id) +); + +# +# Table structure for table `glossary_cageories` +# + +CREATE TABLE prefix_glossary_categories ( + id SERIAL, + glossaryid int4 NOT NULL default '0', + name varchar(255) NOT NULL default '', + PRIMARY KEY (id) +); + +# +# Table structure for table `glossary_entries_category` +# + +CREATE TABLE prefix_glossary_entries_categories ( + categoryid int4 NOT NULL default '0', + entryid int4 NOT NULL default '0', + PRIMARY KEY (categoryid, entryid) +); + +# +# Dumping data for table `log_display` +# + +INSERT INTO prefix_log_display VALUES ('glossary', 'add', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'update', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'view', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'view all', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'add entry', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'update entry', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'add category', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'update category', 'glossary', 'name'); +INSERT INTO prefix_log_display VALUES ('glossary', 'delete category', 'glossary', 'name'); + diff --git a/mod/glossary/deleteentry.html b/mod/glossary/deleteentry.html index 3b77ab110a6..e7721b139ac 100644 --- a/mod/glossary/deleteentry.html +++ b/mod/glossary/deleteentry.html @@ -4,6 +4,8 @@ + + "> " onclick="javascript:history.go(-1);"> diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php index 7f5be1af6fe..43082b14299 100644 --- a/mod/glossary/deleteentry.php +++ b/mod/glossary/deleteentry.php @@ -50,24 +50,38 @@ if ( isteacher($cm->id) or $glossary->studentcanpost ) { if ($go) { // the operation was confirmed. if ( $mode == "delete") { + glossary_delete_old_attachments($entry); delete_records("glossary_entries","id", $entry); print_simple_box_start("center","40%", "#FFBBBB"); echo "
$entrydeleted"; //CAMBIAR echo "
"; print_simple_box_end(); - } elseif ($mode == "edit") { } print_footer($course); - add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id", $entry); - redirect("view.php?id=$cm->id"); + add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id¤tview=$currentview&cat=$cat", $entry); + redirect("view.php?id=$cm->id¤tview=$currentview&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"); - echo "
$entryfields->concept
$strareyousuredelete"; //CAMBIAR - include("deleteentry.html"); - echo "
"; + echo "
$entryfields->concept
$strareyousuredelete"; + + ?> +
+ + + + + + > + > + + "> + " onclick="javascript:history.go(-1);"> + +
+
+ concept) ?>"> + +

:

+ + id); + echo " + +

:

@@ -37,9 +62,6 @@ $form->format = $defaultformat; } choose_from_menu(format_text_menu(), "format", $entry->format, ""); - if ($entry->id) { - echo "id\">"; - } echo "

"; ?> @@ -58,7 +80,14 @@

+ id) { + echo "id\">"; + } + ?> + + + "> ">

diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php index 969e7c9c844..74578c0c7a5 100644 --- a/mod/glossary/edit.php +++ b/mod/glossary/edit.php @@ -7,6 +7,9 @@ require_once("lib.php"); require_variable($id); // Course Module ID optional_variable($e); // EntryID +optional_variable($currentview); // categories if by category? +optional_variable($cat); // CategoryID + if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); } @@ -110,14 +113,23 @@ if ($e) { } 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", "$newentry->id"); + add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id¤tview=$currentview&cat=$cat", "$newentry->id"); } } else { error("Could not insert this glossary entry because this concept already exist."); } } - redirect("view.php?id=$cm->id&eid=$newentry->id"); + delete_records("glossary_entries_categories","entryid",$entry); + + if ( $categories ) { + $newcategory->entryid = $newentry->id; + foreach ($categories as $category) { + $newcategory->categoryid =$category; + insert_record("glossary_entries_categories",$newcategory); + } + } + redirect("view.php?id=$cm->id&eid=$newentry->id¤tview=$currentview&cat=$cat"); die; } } diff --git a/mod/glossary/editcategories.html b/mod/glossary/editcategories.html new file mode 100644 index 00000000000..fdfc0d156eb --- /dev/null +++ b/mod/glossary/editcategories.html @@ -0,0 +1,30 @@ + + +
action="editcategories.php"> + + + + + + + +

:

+ +
+

+ + + + > + "> + " onclick="javascript:history.go(-1);"> +

+
+

+ + +
diff --git a/mod/glossary/editcategories.php b/mod/glossary/editcategories.php new file mode 100644 index 00000000000..bf2260e66b3 --- /dev/null +++ b/mod/glossary/editcategories.php @@ -0,0 +1,233 @@ +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."); + } + +// add_to_log($course->id, "glossary", "edit categories", "view.php?id=$cm->id", "$glossary->id"); + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strglossaries = get_string("modulenameplural", "glossary"); + $strglossary = get_string("modulename", "glossary"); + + print_header("$course->shortname: $glossary->name", "$course->fullname", + "$navigation id>$strglossaries -> $glossary->name", + "", "", true, update_module_button($cm->id, $course->id, $strglossary), + navmenu($course, $cm)); + + if ( $cat ) { + $category = get_record("glossary_categories","id",$cat); + + if ( $action == "edit" ) { + if ( $confirm ) { + $action = ""; + $CategoryObject->id = $cat; + $CategoryObject->name = $name; + + if ( !update_record("glossary_categories", $CategoryObject) ) { + error("Weird error. The category was not updated."); + + redirect("editcategories.php?id=$cm->id"); + } + + } else { + echo "

" . get_string("edit"). " " . get_string("category","glossary") . ""; + + $name = $category->name; + require "editcategories.html"; + print_footer(); + die; + } + } elseif ( $action == "delete" ) { + if ( $confirm ) { + + delete_records("glossary_entries_categories","categoryid", $cat); + delete_records("glossary_categories","id", $cat); + + print_simple_box_start("center","40%", "#FFBBBB"); + echo "

" . get_string("categorydeleted","glossary") ."
"; + echo ""; + print_simple_box_end(); + + print_footer($course); + + add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $cat); + + redirect("editcategories.php?id=$cm->id"); + } else { + echo "

" . get_string("delete"). " " . get_string("category","glossary") . ""; + + print_simple_box_start("center","40%", "#FFBBBB"); + echo "

$category->name
"; + + $num_entries = count_records("glossary_entries_categories","categoryid",$category->id); + if ( $num_entries ) { + print_string("deletingnoneemptycategory","glossary"); + } + echo "

"; + print_string("areyousuredelete","glossary"); + + ?> +

+ + + + + +
+ "> + + + $id); + print_single_button("editcategories.php", $options, get_string("no") ); + echo "
"; + echo "
"; + print_simple_box_end(); + } + } + } elseif ( $action == "add" ) { + if ( $confirm ) { + $dupcategory = get_record("glossary_categories","lcase(name)",strtolower($name)); + if ( $dupcategory ) { + echo "

" . get_string("add"). " " . get_string("category","glossary") . ""; + + print_simple_box_start("center","40%", "#FFBBBB"); + echo "

" . get_string("duplicatedcategory","glossary") ."
"; + echo ""; + print_simple_box_end(); + + print_footer($course); + + redirect("editcategories.php?id=$cm->id&action=add&&name=$name"); + + } else { + $action = ""; + $CategoryObject->name = $name; + $CategoryObject->glossaryid = $glossary->id; + + if ( ! $CategoryObject->id = insert_record("glossary_categories", $CategoryObject) ) { + error("Weird error. The category was not inserted."); + + redirect("editcategories.php?id=$cm->id"); + } else { + add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat); + } + } + } else { + echo "

" . get_string("add"). " " . get_string("category","glossary") . ""; + $name=""; + require "editcategories.html"; + } + } + + if ( $action ) { + + print_footer(); + die; + } + +?> + + +

+ +

action="editcategories.php"> + + + + + + + +
+ +
+ + +id,"name ASC"); + + if ( $categories ) { + foreach ($categories as $category) { + $num_entries = count_records("glossary_entries_categories","categoryid",$category->id); + ?> + + + + + + +
+ $category->name ($num_entries " . get_string("entries","glossary") . ")"; + ?> + + id&action=delete&cat=$category->id\">\"" "; + echo "id&action=edit&cat=$category->id\">\"""; + ?> +
+ +
+ id; + $options['action'] = "add"; + + echo ""; + echo ""; + + ?> + + +
"; + echo print_single_button("editcategories.php", $options, get_string("add") . " " . get_string("category","glossary"), "get"); + echo ""; + unset($options['action']); + $options['currentview'] = "categories"; + echo print_single_button("view.php", $options, get_string("back","glossary") ); + echo "
+ +
+

+ + + + + diff --git a/mod/glossary/exportentry.php b/mod/glossary/exportentry.php index 32b8ea1c644..35ea5ad9fe1 100644 --- a/mod/glossary/exportentry.php +++ b/mod/glossary/exportentry.php @@ -5,6 +5,9 @@ require_variable($id); // course module ID require_variable($entry); // Entry ID optional_variable($confirm); // confirmation + optional_variable($currentview); + optional_variable($cat); + global $THEME, $USER, $CFG; $PermissionGranted = 1; @@ -52,8 +55,8 @@ echo "
"; notice_yesno ("

$entry->concept

Seguro que desea agregar esta entrada a
$mainglossary->name?", - "exportentry.php?id=$id&entry=$entry->id&confirm=1", - "view.php?id=$cm->id&eid=".$entry->id ); + "exportentry.php?id=$id¤tview=$currentview&cat=$cat&entry=$entry->id&confirm=1", + "view.php?id=$cm->id¤tview=$currentview&cat=$cat&eid=".$entry->id ); } else { if ( ! $mainglossary->allowduplicatedentries ) { @@ -86,15 +89,14 @@ } } - add_to_log($course->id, "glossary", "add entry", - "view.php?id=$cm->id&eid=".$entry->id, "$newentry->id"); + add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id¤tview=$currentview&cat=$cat&eid=".$entry->id, "$newentry->id"); - print_continue("view.php?id=$cm->id&eid=".$entry->id); + print_continue("view.php?id=$cm->id¤tview=$currentview&cat=$cat&eid=".$entry->id); print_simple_box_end(); print_footer(); - redirect("view.php?id=$cm->id&eid=".$entry->id); + redirect("view.php?id=$cm->id¤tview=$currentview&cat=$cat&eid=".$entry->id); die; } } else { @@ -102,7 +104,7 @@ echo "

$entryalreadyexist

"; echo "

"; - print_continue("view.php?id=$cm->id&eid=".$entry->id); + print_continue("view.php?id=$cm->id¤tview=$currentview&cat=$cat&eid=".$entry->id); print_simple_box_end(); } @@ -111,7 +113,7 @@ print_simple_box_start("center", "60%", "#FFBBBB"); echo "

A weird error was found while trying to export this entry. Operation cancelled.

"; - print_continue("view.php?id=$cm->id&eid=".$entry->id); + print_continue("view.php?id=$cm->id¤tview=$currentview&cat=$cat&eid=".$entry->id); print_simple_box_end(); } diff --git a/mod/glossary/formats/1.php b/mod/glossary/formats/1.php index 2dc657689bb..25efe73f463 100644 --- a/mod/glossary/formats/1.php +++ b/mod/glossary/formats/1.php @@ -1,6 +1,6 @@ timemarked < $entry->modified) { @@ -30,7 +30,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry) { if ($entry) { echo format_text($entry->definition, $entry->format); - glossary_print_entry_icons($course, $cm, $glossary, $entry); + glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat); } else { echo "
"; diff --git a/mod/glossary/formats/2.php b/mod/glossary/formats/2.php index 70dd0c2079e..23231c0032c 100644 --- a/mod/glossary/formats/2.php +++ b/mod/glossary/formats/2.php @@ -1,7 +1,7 @@ timemarked < $entry->modified) { @@ -40,7 +40,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry) { if ($entry) { echo format_text($entry->definition, $entry->format); - glossary_print_entry_icons($course, $cm, $glossary, $entry); + glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat); } else { echo "
"; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index e9d7f357be7..8137f5dd3a0 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -5,6 +5,13 @@ require_once("$CFG->dirroot/files/mimetypes.php"); +$tCFG->TabTableBGColor = $THEME->cellcontent2; +$tCFG->TabTableWidth = "70%"; +$tCFG->ActiveTabColor = $THEME->cellcontent2; +$tCFG->InactiveTabColor = $THEME->cellheading2; +$tCFG->TabsPerRow = 5; +$tCFG->TabSeparation = 4; + function glossary_add_instance($glossary) { /// Given an object containing all the necessary data, /// (defined by the form in mod.html) this function @@ -161,7 +168,7 @@ function glossary_get_entries($glossaryid, $entrylist) { AND id IN ($entrylist)"); } -function glossary_print_entry($course, $cm, $glossary, $entry) { +function glossary_print_entry($course, $cm, $glossary, $entry,$currentview="",$cat="") { global $THEME, $USET, $CFG; $PermissionGranted = 0; @@ -180,14 +187,14 @@ function glossary_print_entry($course, $cm, $glossary, $entry) { } if ( $glossary->displayformat > 0 and $PermissionGranted ) { - glossary_print_entry_by_format($course, $cm, $glossary, $entry); + glossary_print_entry_by_format($course, $cm, $glossary, $entry,$currentview,$cat); } else { - glossary_print_entry_by_default($course, $cm, $glossary, $entry); + glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview,$cat); } } -function glossary_print_entry_by_default($course, $cm, $glossary, $entry) { +function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview="",$cat="") { global $THEME, $USER; $colour = $THEME->cellheading2; @@ -202,12 +209,12 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry) { } echo "$entry->concept: "; echo format_text($entry->definition, $entry->format); - glossary_print_entry_icons($course, $cm, $glossary, $entry); + glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat); echo ""; echo ""; } -function glossary_print_entry_icons($course, $cm, $glossary, $entry) { +function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview="",$cat="") { global $THEME, $USER; if (isteacher($course->id) or $glossary->studentcanpost and $entry->userid == $USER->id) { @@ -216,12 +223,12 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry) { $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id); if ( $mainglossary ) { - echo "id&entry=$entry->id\">\"" "; + echo "id&entry=$entry->id¤tview=$currentview&cat=$cat\">\"" "; } } - echo "id&mode=delete&entry=$entry->id\">\"" "; - echo "id&e=$entry->id\">\"""; + echo "id&mode=delete&entry=$entry->id¤tview=$currentview&cat=$cat\">\"" "; + echo "id&e=$entry->id¤tview=$currentview&cat=$cat\">\"""; } } @@ -597,4 +604,89 @@ function print_tabbed_table_end() { echo "

"; } +function glossary_print_alphabet_menu($cm, $glossary, $l) { +global $CFG, $THEME; + $strselectletter = get_string("selectletter", "glossary"); + $strspecial = get_string("special", "glossary"); + $strallentries = get_string("allentries", "glossary"); + + echo "
$strselectletter"; + + if ( $glossary->showspecial ) { + if ( $l == "SPECIAL" ) { + echo "

$strspecial | "; + } else { + echo "

wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL\">$strspecial | "; + } + } + + if ( $glossary->showalphabet ) { + $alphabet = explode("|", get_string("alphabet","glossary")); + $letters_by_line = 14; + for ($i = 0; $i < count($alphabet); $i++) { + if ( $l == $alphabet[$i] ) { + echo "$alphabet[$i]"; + } else { + echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]\">$alphabet[$i]"; + } + if ((int) ($i % $letters_by_line) != 0 or $i == 0) { + echo " | "; + } else { + echo "
"; + } + } + } + + if ( $glossary->showall ) { + if ( $l == "ALL" ) { + echo "$strallentries

"; + } else { + echo "wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL\">$strallentries

"; + } + } +} +function glossary_print_categories_menu($course, $cm, $glossary, $category) { +global $CFG, $THEME; + echo ""; + echo ""; + + echo ""; + + echo ""; + echo ""; + echo ""; + + echo ""; + echo "
"; + if ( isteacher($course->id) ) { + $options['id'] = $cm->id; + $options['cat'] = $cat; + echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get"); + } + echo ""; + echo ""; + if ( $category ) { + echo $category->name; + } else { + echo get_string("entrieswithoutcategory","glossary"); + } + echo ""; + $menu[0] = get_string("nocategorized","glossary"); + + $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC"); + if ( $categories ) { + foreach ($categories as $currentcategory) { + $url = $currentcategory->id; + if ($currentcategory->id == $category->id) { + $selected = $url; + } + $menu[$url] = $currentcategory->name; + } + } + + echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id¤tview=categories&cat=", $menu, "catmenu", $selected, get_string("jumpto"), + "", "", false); + + echo "

"; +} ?> diff --git a/mod/glossary/version.php b/mod/glossary/version.php index 73533470a47..aaf3e9b12bf 100644 --- a/mod/glossary/version.php +++ b/mod/glossary/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2003091800; // The current module version (Date: YYYYMMDDXX) +$module->version = 2003092100; // The current module version (Date: YYYYMMDDXX) $module->cron = 0; // Period for cron to check this module (secs) $release = "0.3.1 development"; // User-friendly version number diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 2b5119dda49..b3c31c138ae 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -15,37 +15,6 @@ optional_variable($currentview); // browsing entries by categories? optional_variable($cat); // categoryID - if ($l == "" and $search == "" and $eid == "") { - $l = "A"; - } - - if ( $currentview ) { - $currentview = strtolower($currentview); - if ( !$currentview ) { - $currentview = ""; - } else { - if ( !$cat ) { - $cat = 1; - } - $category = get_record("glossary_categories","id",$cat); - } - } - - $search = trim(strip_tags($search)); - - if ($search and !$entryid ) { - $l = ""; - $searchterms = explode(" ", $search); // Search for words independently - foreach ($searchterms as $key => $searchterm) { - if (strlen($searchterm) < 2) { - unset($searchterms[$key]); - } - } - $search = trim(implode(" ", $searchterms)); - } elseif ( $eid ) { - $search = ""; - } - if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); } @@ -59,117 +28,108 @@ } require_login($course->id); + if ( !$course->visible ) { + notice(get_string("activityiscurrentlyhidden")); + } add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id"); -/// Print the page header + $search = trim(strip_tags($search)); + if ($search and !$entryid ) { + $l = ""; + $searchterms = explode(" ", $search); // Search for words independently + foreach ($searchterms as $key => $searchterm) { + if (strlen($searchterm) < 2) { + unset($searchterms[$key]); + } + } + $search = trim(implode(" ", $searchterms)); + $currentview = ""; + } elseif ( $eid ) { + $search = ""; + } + if ($l == "" and $search == "" and ($eid == "" or $eid == 0) ) { + $l = "A"; + } elseif ( $eid ) { + $l = ""; + } + if ( $currentview ) { + $l = ""; + $currentview = strtolower($currentview); + if ( $currentview ) { + if ( $cat ) { + $category = get_record("glossary_categories","id",$cat); + } + if ( !$category ) { + $cat = ""; + } + } + } + +/// Printing the page header if ($course->category) { $navigation = "id\">$course->shortname ->"; } - $strglossaries = get_string("modulenameplural", "glossary"); - $strglossary = get_string("modulename", "glossary"); - $strselectletter = get_string("selectletter", "glossary"); - $strspecial = get_string("special", "glossary"); - $strallentries = get_string("allentries", "glossary"); - $strnoentries = get_string("noentries", "glossary"); - $straddentry = get_string("addentry", "glossary"); - $streditentry = get_string("editentry", "glossary"); - $strdeleteentry = get_string("deleteentry", "glossary"); + $strglossaries = get_string("modulenameplural", "glossary"); + $strglossary = get_string("modulename", "glossary"); + $strallcategories= get_string("allcategories", "glossary"); + $straddentry = get_string("addentry", "glossary"); + $strnoentries = get_string("noentries", "glossary"); print_header("$course->shortname: $glossary->name", "$course->fullname", "$navigation id>$strglossaries -> $glossary->name", "", "", true, update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm)); -/// Print the main part of the page - -/// Printing the navigation links (letters to look for) +/// Printing the header of the glossary echo "

$glossary->name

" ; - if ( !$course->visible ) { - notice(get_string("activityiscurrentlyhidden")); - } - print_simple_box_start("center", "70%"); - echo "

$strselectletter"; - - ?> -
-
- - -
- showspecial ) { - echo "

wwwroot/mod/glossary/view.php?id=$id&l=SPECIAL\">$strspecial | "; - } - - if ( $glossary->showalphabet ) { - $alphabet = explode("|", get_string("alphabet","glossary")); - $letters_by_line = 14; - for ($i = 0; $i < count($alphabet); $i++) { - echo "wwwroot/mod/glossary/view.php?id=$id&l=$alphabet[$i]\">$alphabet[$i]"; - if ((int) ($i % $letters_by_line) != 0 or $i == 0) { - echo " | "; - } else { - echo "
"; - } + echo "
"; + ?> +
+
+ + +
+
"; + if (isteacher($course->id) or $glossary->studentcanpost) { + $options = array ("id" => "$cm->id"); + print_single_button("edit.php", $options, $straddentry ); } - } - - if ( $glossary->showall ) { - echo "wwwroot/mod/glossary/view.php?id=$id&l=ALL\">$strallentries

"; - } - - if (isteacher($course->id) or $glossary->studentcanpost) { - $options = array ("id" => "$cm->id"); - echo "
"; - print_single_button("edit.php", $options, $straddentry ); - echo "
"; - } - + echo "
"; print_simple_box_end(); echo "

"; - if ($l) { - $CurrentLetter = ""; - if ($l == "ALL" or $l == "SPECIAL") { - if ( $l == "ALL" ) { - echo "

$strallentries

"; - } elseif ($l == "SPECIAL") { - echo "

$strspecial

"; - } - } - } elseif( $search ) { - echo get_string("search") . ": $search"; - } - - $data[0]->link = "view.php?id=$id&l=$l&eid=$eid&search=$search&includedefinition=$includedefinition"; + $data[0]->link = "view.php?id=$id"; $data[0]->caption = get_string("standardview","glossary"); - $data[1]->link = "view.php?id=$id&l=$l&eid=$eid&search=$search&includedefinition=$includedefinition¤tview=categories&cat=$cat"; + $data[1]->link = "view.php?id=$id¤tview=categories"; $data[1]->caption = get_string("categoryview","glossary"); - - $tCFG->TabTableBGColor = $THEME->cellcontent2; - $tCFG->TabTableWidth = "70%"; - $tCFG->ActiveTabColor = $THEME->cellcontent2; - $tCFG->InactiveTabColor = $THEME->cellheading2; - $tCFG->TabsPerRow = 5; - $tCFG->TabSeparation = 4; - - if ( $cat ) { + + if ( $currentview ) { $CurrentTab = 1; } else { $CurrentTab = 0; } print_tabbed_table_start($data, $CurrentTab, $tCFG); echo "

"; - if ( $cat ) { - echo "$category->name
"; + if ( $currentview ) { + glossary_print_categories_menu($course, $cm, $glossary, $category); + } else { + glossary_print_alphabet_menu($cm, $glossary, $l); + + if ($l) { + $CurrentLetter = ""; + } elseif( $search ) { + echo "

" . get_string("search") . ": $search

"; + } + + echo "
"; } /// Printing the entries @@ -185,11 +145,11 @@ $DumpedDefinitions= 0; foreach ($allentries as $entry) { $DumpToScreen = 0; - $FirstLetter = strtoupper( ltrim( $entry->concept[0] ) ); + $FirstLetter = strtoupper( substr(ltrim($entry->concept),0,strlen($l) ) ); if ( $l ) { if ( $l == "ALL" or $FirstLetter == $l) { - if ( $CurrentLetter != $FirstLetter ) { - $CurrentLetter = $FirstLetter; + if ( $CurrentLetter != $FirstLetter[0] ) { + $CurrentLetter = $FirstLetter[0]; if ( $glossary->displayformat == 0 ) { if ( $DumpedDefinitions > 0) { @@ -197,7 +157,9 @@ } echo "\n
cellheading2\">"; } - echo "$CurrentLetter"; + if ( $l == "ALL" ) { + echo "$CurrentLetter"; + } if ( $glossary->displayformat == 0 ) { echo "\n
"; @@ -211,7 +173,19 @@ $DumpToScreen = 1; } } else { - $DumpToScreen = 1; + if ( $currentview ) { + if ( $category ) { + if ( record_exists("glossary_entries_categories","entryid",$entry->id, "categoryid",$category->id) ) { + $DumpToScreen = 1; + } + } else { + if ( ! record_exists("glossary_entries_categories","entryid",$entry->id) ) { + $DumpToScreen = 1; + } + } + } else { + $DumpToScreen = 1; + } } if ( $DumpToScreen ) { @@ -229,7 +203,7 @@ $entry->concept = highlight($search,$concept); $entry->definition = highlight($search,$definition); } - glossary_print_entry($course, $cm, $glossary, $entry); + glossary_print_entry($course, $cm, $glossary, $entry,$currentview,$cat); if ( $glossary->displayformat != 0 ) { echo "

";