From 0784202319542207fb7d54312af7e3f2e7171568 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 16 Sep 2003 03:07:21 +0000 Subject: [PATCH] New Glossary module, version 0.1 - by Williams Castillo! --- mod/glossary/README.txt | 30 +++ mod/glossary/backuplib.php | 146 +++++++++++++ mod/glossary/db/mysql.php | 30 +++ mod/glossary/db/mysql.sql | 62 ++++++ mod/glossary/deleteentry.html | 11 + mod/glossary/deleteentry.php | 79 +++++++ mod/glossary/edit.html | 61 ++++++ mod/glossary/edit.php | 139 ++++++++++++ mod/glossary/export.gif | Bin 0 -> 855 bytes mod/glossary/exportentry.php | 111 ++++++++++ mod/glossary/icon.gif | Bin 0 -> 554 bytes mod/glossary/index.php | 77 +++++++ mod/glossary/lib.php | 395 ++++++++++++++++++++++++++++++++++ mod/glossary/mod.html | 115 ++++++++++ mod/glossary/restorelib.php | 140 ++++++++++++ mod/glossary/version.php | 13 ++ mod/glossary/view.php | 219 +++++++++++++++++++ 17 files changed, 1628 insertions(+) create mode 100644 mod/glossary/README.txt create mode 100644 mod/glossary/backuplib.php create mode 100644 mod/glossary/db/mysql.php create mode 100644 mod/glossary/db/mysql.sql create mode 100644 mod/glossary/deleteentry.html create mode 100644 mod/glossary/deleteentry.php create mode 100644 mod/glossary/edit.html create mode 100644 mod/glossary/edit.php create mode 100644 mod/glossary/export.gif create mode 100644 mod/glossary/exportentry.php create mode 100644 mod/glossary/icon.gif create mode 100644 mod/glossary/index.php create mode 100644 mod/glossary/lib.php create mode 100644 mod/glossary/mod.html create mode 100644 mod/glossary/restorelib.php create mode 100644 mod/glossary/version.php create mode 100644 mod/glossary/view.php diff --git a/mod/glossary/README.txt b/mod/glossary/README.txt new file mode 100644 index 0000000000..1f4b462043 --- /dev/null +++ b/mod/glossary/README.txt @@ -0,0 +1,30 @@ +Glossary version 0.1 +---------------------- + + +By Williams Castillo (castillow@tutopia.com) + + +This is the Glossary module created and maintained by Williams Castillo. + +It allows to create main and secondary glossaries within courses. Some of its features are: +- Entries could be added by teachers (default) or by student (optional) +- Entries from a secondary glossary could be exported by the teacher to the main glossary of the course. +- The course creator could specify if a glossary should or should not allow duplicated entries. +- You can browse entries by its first letters or all-in-one-page. +- YOu can search by concept (and optionally by definition). +- + + +Quick install instructions + +1) Copy the files inside lang/en (glossary.php and help/*.*) to your lang/en folder. Please, forgive my english... I tried to do my best... I'll appreciate if you send me correct translations of these files (I've also included the spanish translation as well). +2) Create a folder inside your moodle/mod folder and copy all other files inside it. +3) Visit your admin page to install the module +4) Enjoy it. + + +Please, send me your comments and suggestions. It will help me improve this module. + +All the best, +Will diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php new file mode 100644 index 0000000000..37532e6ec6 --- /dev/null +++ b/mod/glossary/backuplib.php @@ -0,0 +1,146 @@ +id) + // | + // | + // | + // glossary_entries + // (UL,pk->id, fk->glossaryid) + // + // Meaning: pk->primary key field of the table + // fk->foreign key to link with parent + // nt->nested field (recursive data) + // CL->course level info + // UL->user level info + // files->table may have files) + // + //----------------------------------------------------------- + + function glossary_backup_mods($bf,$preferences) { + + global $CFG; + + $status = true; + + //Iterate over glossary table + $glossaries = get_records ("glossary","course",$preferences->backup_course,"id"); + if ($glossaries) { + foreach ($glossaries as $glossary) { + //Start mod + fwrite ($bf,start_tag("MOD",3,true)); + //Print glossary data + fwrite ($bf,full_tag("ID",4,false,$glossary->id)); + fwrite ($bf,full_tag("MODTYPE",4,false,"glossary")); + fwrite ($bf,full_tag("NAME",4,false,$glossary->name)); + fwrite ($bf,full_tag("STUDENTCANPOST",4,false,$glossary->studentcanpost)); + fwrite ($bf,full_tag("ALLOWDUPLICATEDENTRIES",4,false,$glossary->allowduplicatedentries)); + fwrite ($bf,full_tag("DISPLAYFORMAT",4,false,$glossary->displayformat)); + fwrite ($bf,full_tag("MAINGLOSSARY",4,false,$glossary->mainglossary)); + fwrite ($bf,full_tag("TIMECREATED",4,false,$glossary->timecreated)); + fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$glossary->timemodified)); + + backup_glossary_entries($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo); + + //End mod + $status =fwrite ($bf,end_tag("MOD",3,true)); + } + } + return $status; + } + + //Backup glossary_entries contents made by teachers (executed from glossary_backup_mods) + function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) { + + global $CFG; + + $status = true; + + $glossary_entries = get_records("glossary_entries","glossaryid",$glossary,"id"); + //If there is submissions + if ($glossary_entries) { + $dumped_entries = 0; + + //Iterate over each answer + foreach ($glossary_entries as $glo_ent) { + //Start answer + + //Print submission contents + if ( $glo_ent->teacherentry or $userinfo) { + $dumped_entries++; + if ($dumped_entries == 1) { + //Write start tag + $status =fwrite ($bf,start_tag("ENTRIES",4,true)); + } + $status =fwrite ($bf,start_tag("ENTRY",5,true)); + + fwrite ($bf,full_tag("ID",6,false,$glo_ent->id)); + fwrite ($bf,full_tag("USERID",6,false,$glo_ent->userid)); + fwrite ($bf,full_tag("CONCEPT",6,false,$glo_ent->concept)); + fwrite ($bf,full_tag("DEFINITION",6,false,$glo_ent->definition)); + fwrite ($bf,full_tag("FORMAT",6,false,$glo_ent->format)); + fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry)); + + $status =fwrite ($bf,end_tag("ENTRY",5,true)); + } + } + if ( $dumped_entries > 0 ) { + //Write end tag + $status =fwrite ($bf,end_tag("ENTRIES",4,true)); + } + } + return $status; + } + + + ////Return an array of info (name,value) + function glossary_check_backup_mods($course,$user_data=false,$backup_unique_code) { + //First the course data + $info[0][0] = get_string("modulenameplural","glossary"); + if ($ids = glossary_ids ($course)) { + $info[0][1] = count($ids); + } else { + $info[0][1] = 0; + } + + //Now, if requested, the user_data + if ($user_data) { + $info[1][0] = get_string("concepts","glossary"); + if ($ids = glossary_entries_ids_by_course ($course)) { + $info[1][1] = count($ids); + } else { + $info[1][1] = 0; + } + } + return $info; + } + + + // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE + + //Returns an array of glossaries id + function glossary_ids ($course) { + + global $CFG; + + return get_records_sql ("SELECT a.id, a.course + FROM {$CFG->prefix}glossary a + WHERE a.course = '$course'"); + } + + //Returns an array of glossary_answers id + function glossary_entries_ids_by_course ($course) { + + global $CFG; + + return get_records_sql ("SELECT s.id , s.glossaryid + FROM {$CFG->prefix}glossary_entries s, + {$CFG->prefix}glossary a + WHERE a.course = '$course' AND + s.glossaryid = a.id"); + } +?> diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php new file mode 100644 index 0000000000..b8c2e655da --- /dev/null +++ b/mod/glossary/db/mysql.php @@ -0,0 +1,30 @@ +prefix}glossary` ". + " ADD `allowduplicatedentries` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `studentcanpost` , ". + " ADD `displayformat` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `allowduplicatedentries` , ". + " ADD `mainglossary` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `displayformat` "); + + execute_sql(" ALTER TABLE `{$CFG->prefix}glossary_entries` ". + " ADD timecreated INT(10) UNSIGNED NOT NULL default '0' AFTER `format` , ". + " ADD timemodified INT(10) UNSIGNED NOT NULL default '0' AFTER `timecreated` , ". + " ADD teacherentry TINYINT(2) UNSIGNED NOT NULL default '0' AFTER `timemodified` "); + + execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'delete', 'glossary', 'name') "); + execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'delete entry', 'glossary', 'name') "); + + } + + return true; +} + +?> + diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql new file mode 100644 index 0000000000..b3c6615b15 --- /dev/null +++ b/mod/glossary/db/mysql.sql @@ -0,0 +1,62 @@ +# 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 int(10) unsigned NOT NULL auto_increment, + course int(10) unsigned NOT NULL default '0', + name varchar(255) NOT NULL default '', + studentcanpost tinyint(2) unsigned NOT NULL default '0', + + allowduplicatedentries tinyint(2) unsigned NOT NULL default '0', + displayformat tinyint(2) unsigned NOT NULL default '0', + mainglossary tinyint(2) unsigned NOT NULL default '0', + + timecreated int(10) unsigned NOT NULL default '0', + timemodified int(10) unsigned NOT NULL default '0', + PRIMARY KEY (id) +) TYPE=MyISAM COMMENT='all glossaries'; + +# +# Table structure for table `glossary_entries` +# + +CREATE TABLE prefix_glossary_entries ( + id int(10) unsigned NOT NULL auto_increment, + glossaryid int(10) unsigned NOT NULL default '0', + userid int(10) unsigned NOT NULL default '0', + + concept varchar(255) NOT NULL default '', + definition text NOT NULL, + format tinyint(2) unsigned NOT NULL default '0', + timecreated int(10) unsigned NOT NULL default '0', + timemodified int(10) unsigned NOT NULL default '0', + + teacherentry tinyint(2) unsigned NOT NULL default '0', + + PRIMARY KEY (id) +) TYPE=MyISAM COMMENT='all glossary entries'; + +# +# 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'); \ No newline at end of file diff --git a/mod/glossary/deleteentry.html b/mod/glossary/deleteentry.html new file mode 100644 index 0000000000..3b77ab110a --- /dev/null +++ b/mod/glossary/deleteentry.html @@ -0,0 +1,11 @@ +
+ + + + + + + "> + " onclick="javascript:history.go(-1);"> + +
\ No newline at end of file diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php new file mode 100644 index 0000000000..7f5be1af6f --- /dev/null +++ b/mod/glossary/deleteentry.php @@ -0,0 +1,79 @@ +course)) { + error("Course is misconfigured"); + } + + require_login($course->id); + + if (isguest()) { + error("Guests are not allowed to edit ir delete entries", $_SERVER["HTTP_REFERER"]); + } + + if (! $glossary = get_record("glossary", "id", $cm->instance)) { + error("Glossary is incorrect"); + } + + $entryfields = get_record("glossary_entries", "id", $entry); + $strareyousuredelete = get_string("areyousuredelete","glossary"); + + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + 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 data submitted, then process and store. + + if ($mode == "edit" or $mode == "delete" ) { + echo "

"; + if ( isteacher($cm->id) or $glossary->studentcanpost ) { + if ($go) { // the operation was confirmed. + if ( $mode == "delete") { + 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"); + } 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 "
"; + print_simple_box_end(); + } elseif ($mode == "edit") { + } + } + } else { + error("You are not allowed to edit or delete entries"); + } + } else { + } + print_footer($course); +?> diff --git a/mod/glossary/edit.html b/mod/glossary/edit.html new file mode 100644 index 0000000000..55ad7a99ed --- /dev/null +++ b/mod/glossary/edit.html @@ -0,0 +1,61 @@ +
action="edit.php"> + + + + + + + + + + + + +
+ + "; + if ($usehtmleditor) { + helpbutton("richtext", get_string("helprichtext"), "moodle", true, true); + } else { + emoticonhelpbutton("theform", "text"); + } + ?> +
+
+
+ : +

+ +

+ +text); ?> + +

+format, ""); + echo ""; + helpbutton("textformat", get_string("helpformatting")); + echo ""; + if ($entry->id) { + echo "id\">"; + } +?> +

+ +

+ +"> +"> +

+
+ + + diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php new file mode 100644 index 0000000000..98d2ee6d95 --- /dev/null +++ b/mod/glossary/edit.php @@ -0,0 +1,139 @@ +course)) { + error("Course is misconfigured"); + } + + require_login($course->id); + + if (isguest()) { + error("Guests are not allowed to edit glossaries", $_SERVER["HTTP_REFERER"]); + } + + 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->concept = $form->concept; + $newentry->definition = $form->text; + $newentry->format = $form->format; + $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 ( $curentry->id != $entry) { + $PermissionGranted = 0; + } + } + } + } + if ( $PermissionGranted ) { + 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->glossaryid = $glossary->id; + $newentry->concept = $form->concept; + $newentry->definition = $form->text; + $newentry->format = $form->format; + $newentry->timecreated = time(); + $newentry->timemodified = time(); + $newentry->teacherentry = isteacher($course->id,$USER->id); + + $PermissionGranted = 1; + if ( !$glossary->allowduplicatedentries ) { + $dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept)); + if ($dupentries) { + $PermissionGranted = 0; + } + } + if ( $PermissionGranted ) { + if (! $newentry->id = insert_record("glossary_entries", $newentry)) { + error("Could not insert a new glossary entry"); + } else { + add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id", "$newentry->id"); + } + } else { + error("Could not insert this glossary entry because this concept already exist."); + } + } + + redirect("view.php?id=$cm->id&eid=$newentry->id"); + die; + } + } +/// Otherwise fill and print the form. + + $strglossary = get_string("modulename", "glossary"); + $strglossaries = get_string("modulenameplural", "glossary"); + $stredit = get_string("edit"); + + if ($usehtmleditor = can_use_richtext_editor()) { + $defaultformat = FORMAT_HTML; + $onsubmit = "onsubmit=\"copyrichtext(theform.text);\""; + } else { + $defaultformat = FORMAT_MOODLE; + $onsubmit = ""; + } + + if (empty($entry)) { + $entry->text = ""; + $entry->format = $defaultformat; + } + + print_header("$course->shortname: $glossary->name", "$course->fullname", + "wwwroot/course/view.php?id=$course->id\">$course->shortname -> + id\">$strglossaries -> + id\">$glossary->name -> $stredit", "theform.text", + "", true, "", navmenu($course, $cm)); + + echo "
\n"; + + print_simple_box( text_to_html($glossary->name) , "center"); + + echo "
"; + + include("edit.html"); + + print_footer($course); + +?> diff --git a/mod/glossary/export.gif b/mod/glossary/export.gif new file mode 100644 index 0000000000000000000000000000000000000000..d27efa2316b86ca1c66bb5c8adf24a069fa4db87 GIT binary patch literal 855 zcmb7@v5J#X5QV2$#brrnA*s|V#j*-xK+#5niXd#twMZezGChp=Pp4A#EVG=G85{Z(eN}8lgh9m{rNTWqFue0XVF;!O$ z)vU2pW@@e$YFQLqx~aQ*sAoa(HcZ1cLL*_MRns(GGc=hBHDW+R2^Mz@MjL6gXwEWJ zHOI}uEXyBbsoc%OJj*T=T!veOMdBVP-deh4SYnSnz@(cv@DBtIp+*d7D0vD8gV9DB zt*qqgnwk^tSwZ5Du~ZQrNv_z1f=kcvBuA1a0JwNg(6}W^@&J==;(!UmID{H8py>n) z4hEx*bk>UMHP_UfWMc%0KgLo;W-YL-zbM*9YoBdN1=Vt|^|mOBv87YnZiWlFd8p+# zta8vMA-GBm{$MZ|4u_-BXgnTICX?xOI-AYr^Z8=2ST2{V z)oQ(7Z#J9lc6;9Y??e9opKE`1c11qPezn$rLN48sXS**R9-n@Bz0course, "mainglossary",1); + if ( ! $mainglossary ) { + $PermissionGranted = 0; + } + } + + if ( !isteacher($cm->course) ) { + $PermissionGranted = 0; + error("You must be a teacher to use this page."); + } + + 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"); + } + + $strglossaries = get_string("modulenameplural", "glossary"); + $entryalreadyexist = get_string("entryalreadyexist","glossary"); + $entryexported = get_string("entryexported","glossary"); + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + print_header("$course->shortname: $glossary->name", "$course->fullname", + "$navigation id>$strglossaries -> $glossary->name", + "", "", true, "", + navmenu($course, $cm)); + + if ( $PermissionGranted ) { + $entry = get_record("glossary_entries", "id", $entry); + + if ( !$confirm ) { + 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 ); + + } else { + if ( ! $mainglossary->allowduplicatedentries ) { + $dupentry = get_record("glossary_entries","glossaryid", $mainglossary->id, "UCASE(concept)",strtoupper($entry->concept)); + if ( $dupentry ) { + $PermissionGranted = 0; + } + } + if ( $PermissionGranted ) { + $newentry->userid = $entry->userid; + $newentry->glossaryid = $mainglossary->id; + $newentry->concept = $entry->concept; + $newentry->definition = $entry->definition; + $newentry->format = $entry->format; + $newentry->timecreated = $entry->timecreated; + $newentry->timemodified = $entry->timemodified; + $newentry->teacherentry = $entry->teacherentry; + + if (! $newentry->id = insert_record("glossary_entries", $newentry) ) { + error("Could not export the entry to the main glossary"); + } else { + + add_to_log($course->id, "glossary", "add entry", + "view.php?id=$cm->id&eid=".$entry->id, "$newentry->id"); + + print_simple_box_start("center", "60%", "$THEME->cellheading"); + echo "

$entryexported

"; + print_continue("view.php?id=$cm->id&eid=".$entry->id); + print_simple_box_end(); + + print_footer(); + + redirect("view.php?id=$cm->id&eid=".$entry->id); + die; + } + } else { + print_simple_box_start("center", "60%", "#FFBBBB"); + echo "

$entryalreadyexist

"; + echo "

"; + + print_continue("view.php?id=$cm->id&eid=".$entry->id); + + print_simple_box_end(); + } + } + } else { + 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_simple_box_end(); + } + + print_footer(); +?> \ No newline at end of file diff --git a/mod/glossary/icon.gif b/mod/glossary/icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..a2d6f78feaee37c99429ed791c1d091e61afd33b GIT binary patch literal 554 zcmZ?wbhEHb6krfwc*ekB!@xf$y88U}gT6K{y)!5Ki5r%bWxsy+cK4yR2{N{c4BD;D z&6zG?tvTg>f;!a|6%Q}pYS0c1XHc9|(G?mVwz#F!TifcwzT->R%+C#u`v3p`o%`p~ z7>t7%B#XsdCVS;g=IlhOwPEGVnKMHewLBQ40|gCUy?zj&W3#HbKTX#o#m&D|*5m5Uiyh7NYxDX7UA?NJ z(>{OwaCpo5w6wIxPp{v9{IJ75CXvH9ib3<`{l`I?PLYxpm+zk}w+Mg#{k@l>RkKmZ z%9g1!LQ3Z>nOfCY6v80i+S3sc9JYGl%+jEEpuG#@8&+*x7Rhg1Ea|l{rnaHBu1Pn1 zdBfxjM-OH2Sp;xsyEDkY{PZeH-F98+#7afqt2Zu(dis9-^5yZfC!c7&zJ)OgUscHY7MI`^~d4Om^yZZdN;&V7T$n5q5sxFp)hE7*BJV zGAYh6WL%ga%+Jedb<(15qbq!imRUL&T^j*Gwa9ndx)LLX!tjA@A7SV#o>kP6tygSgq GU=09V2ip(; literal 0 HcmV?d00001 diff --git a/mod/glossary/index.php b/mod/glossary/index.php new file mode 100644 index 0000000000..ff005c6334 --- /dev/null +++ b/mod/glossary/index.php @@ -0,0 +1,77 @@ +id); + + add_to_log($course->id, "glossary", "view all", "index.php?id=$course->id", ""); + + +/// Get all required strings + + $strglossarys = get_string("modulenameplural", "glossary"); + $strglossary = get_string("modulename", "glossary"); + + +/// Print the header + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + print_header("$course->shortname: $strglossarys", "$course->fullname", "$navigation $strglossarys"); + +/// Get all the appropriate data + + if (! $glossarys = get_all_instances_in_course("glossary", $course)) { + notice("There are no glossaries", "../../course/view.php?id=$course->id"); + die; + } + +/// Print the list of instances (your module will probably extend this) + + $timenow = time(); + $strname = get_string("name"); + $strweek = get_string("week"); + $strtopic = get_string("topic"); + + if ($course->format == "weeks") { + $table->head = array ($strweek, $strname); + $table->align = array ("CENTER", "LEFT"); + } else if ($course->format == "topics") { + $table->head = array ($strtopic, $strname); + $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT"); + } else { + $table->head = array ($strname); + $table->align = array ("LEFT", "LEFT", "LEFT"); + } + + foreach ($glossarys as $glossary) { + $link = "coursemodule\">$glossary->name"; + + if ($course->format == "weeks" or $course->format == "topics") { + $table->data[] = array ($glossary->section, $link); + } else { + $table->data[] = array ($link); + } + } + + echo "
"; + + print_table($table); + +/// Finish the page + + print_footer($course); + +?> diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php new file mode 100644 index 0000000000..b86611b8c5 --- /dev/null +++ b/mod/glossary/lib.php @@ -0,0 +1,395 @@ +timecreated = time(); + $glossary->timemodified = $glossary->timecreated; + + # May have to add extra stuff in here # + + return insert_record("glossary", $glossary); +} + + +function glossary_update_instance($glossary) { +/// Given an object containing all the necessary data, +/// (defined by the form in mod.html) this function +/// will update an existing instance with new data. + + $glossary->timemodified = time(); + $glossary->id = $glossary->instance; + + # May have to add extra stuff in here # + + return update_record("glossary", $glossary); +} + + +function glossary_delete_instance($id) { +/// Given an ID of an instance of this module, +/// this function will permanently delete the instance +/// and any data that depends on it. + + if (! $glossary = get_record("glossary", "id", "$id")) { + return false; + } + + $result = true; + + # Delete any dependent records here # + + if (! delete_records("glossary", "id", "$glossary->id")) { + $result = false; + } + delete_records("glossary_entries", "glossaryid", "$glossary->id"); + + return $result; +} + +function glossary_user_outline($course, $user, $mod, $glossary) { +/// Return a small object with summary information about what a +/// user has done with a given particular instance of this module +/// Used for user activity reports. +/// $return->time = the time they did it +/// $return->info = a short text description + + return $return; +} + +function glossary_user_complete($course, $user, $mod, $glossary) { +/// Print a detailed representation of what a user has done with +/// a given particular instance of this module, for user activity reports. + + return true; +} + +function glossary_print_recent_activity($course, $isteacher, $timestart) { +/// Given a course and a time, this module should find recent activity +/// that has occurred in glossary activities and print it out. +/// Return true if there was output, or false is there was none. + + global $CFG, $THEME; + + if (!$logs = get_records_select("log", "time > '$timestart' AND ". + "course = '$course->id' AND ". + "module = 'glossary' AND ". + "action = 'add %' ", "time ASC")) { + return false; + } + + echo "

ANTES

"; + foreach ($logs as $log) { + //Create a temp valid module structure (course,id) + $tempmod->course = $log->course; + $tempmod->id = $log->info; + //Obtain the visible property from the instance + $modvisible = instance_is_visible($log->module,$tempmod); + echo "

ADENTRO => ANTES

"; + + //Only if the mod is visible + if ($modvisible) { + $entries[$log->info] = glossary_log_info($log); + $entries[$log->info]->time = $log->time; + $entries[$log->info]->url = $log->url; + } + echo "

ADENTRO => DESPUES

"; + } + + echo "

DESPUES

"; + + $content = false; + if ($entries) { + $strftimerecent = get_string("strftimerecent"); + $content = true; + print_headline(get_string("newentries", "glossary").":"); + foreach ($entries as $entry) { + $date = userdate($entry->timemodified, $strftimerecent); + echo "

$date - $entry->firstname $entry->lastname
"; + echo "\"wwwroot/mod/glossary/$entry->url\">"; + echo "$entry->concept"; + echo "\"

"; + } + } + + return $content; +} + +function glossary_cron () { +/// Function to be run periodically according to the moodle cron +/// This function searches for things that need to be done, such +/// as sending out mail, toggling flags etc ... + + global $CFG; + + return true; +} + +function glossary_grades($glossaryid) { +/// Must return an array of grades for a given instance of this module, +/// indexed by user. It also returns a maximum allowed grade. + + $return->grades = NULL; + $return->maxgrade = NULL; + + return $return; +} + + +////////////////////////////////////////////////////////////////////////////////////// +/// Any other glossary functions go here. Each of them must have a name that +/// starts with glossary_ + +function glossary_log_info($log) { + global $CFG; + return get_record_sql("SELECT g.*, u.firstname, u.lastname + FROM {$CFG->prefix}glossary_entries g, + {$CFG->prefix}user u + WHERE g.glossaryid = '$log->info' + AND u.id = '$log->userid'"); +} + +function glossary_get_entries($glossaryid, $entrylist) { + global $CFG; + + return get_records_sql("SELECT id,userid,concept,definition,format + FROM {$CFG->prefix}glossary_entries + WHERE glossaryid = '$glossaryid' + AND id IN ($entrylist)"); +} + +function glossary_print_entry($course, $cm, $glossary, $entry) { + switch ( $glossary->displayformat ) { + case 0: + echo "
"; + glossary_print_entry_with_user($course, $cm, $glossary, $entry); + echo "
"; + break; + case 1: + echo "
"; + glossary_print_entry_without_user($course, $cm, $glossary, $entry); + echo "
"; + break; + case 2: +// echo "
"; + glossary_print_short_entries($course, $cm, $glossary, $entry); +// echo "
"; + break; + } +} +function glossary_print_entry_with_user($course, $cm, $glossary, $entry) { + global $THEME, $USER; + +// if ($entry->timemarked < $entry->modified) { + $colour = $THEME->cellheading2; +// } else { +// $colour = $THEME->cellheading; +// } + + $user = get_record("user", "id", $entry->userid); + $strby = get_string("writtenby","glossary"); + + echo "\n"; + + echo "\n"; + echo "\n"; + echo ""; + + echo "\n"; + + echo "
cellheading\" WIDTH=35 VALIGN=TOP>"; + if ($entry) { + print_user_picture($user->id, $course->id, $user->picture); + } + echo ""; + if ($entry) { + echo "$entry->concept
$strby $user->firstname $user->lastname"; + echo "  (".get_string("lastedited").": ".userdate($entry->timemodified).")"; + } + echo "
cellcontent\">"; + if ($entry) { + echo format_text($entry->definition, $entry->format); + + glossary_print_entry_icons($course, $cm, $glossary, $entry); + + } else { + echo "
"; + print_string("noentry", "glossary"); + echo "
"; + } + echo "
\n"; +} + +function glossary_print_entry_without_user($course, $cm, $glossary, $entry) { + global $THEME, $USER; + +// if ($entry->timemarked < $entry->modified) { + $colour = $THEME->cellheading2; +// } else { +// $colour = $THEME->cellheading; +// } + + echo "\n"; + + echo "\n"; + echo ""; + + echo "\n"; + + echo "
$entry->concept
"; + if ($entry) { + echo "  ".get_string("lastedited").": ".userdate($entry->timemodified).""; + } + echo "
cellcontent\">"; + if ($entry) { + echo format_text($entry->definition, $entry->format); + + glossary_print_entry_icons($course, $cm, $glossary, $entry); + + } else { + echo "
"; + print_string("noentry", "glossary"); + echo "
"; + } + echo "
\n"; +} + +function glossary_print_short_entries($course, $cm, $glossary, $entry) { + global $THEME, $USER; + + $colour = $THEME->cellheading2; + + echo "\n"; + echo "$entry->concept: "; + echo format_text($entry->definition, $entry->format); + glossary_print_entry_icons($course, $cm, $glossary, $entry); + echo ""; + echo ""; +} + +function glossary_print_entry_icons($course, $cm, $glossary, $entry) { + global $THEME, $USER; + + if (isteacher($course->id) or $glossary->studentcanpost and $entry->userid == $USER->id) { + echo "

"; + if (isteacher($course->id) and !$glossary->mainglossary) { + $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id); + if ( $mainglossary ) { +/* link_to_popup_window ("$CFG->wwwroot/mod/glossary/exportentry.php?id=$cm->id&entry=$entry->id", + "popup", + "\""", + 400, 500, get_string("exporttomainglossary","glossary"), "none"); +*/ + + echo "id&entry=$entry->id\">\"" "; + + } + } + echo "id&mode=delete&entry=$entry->id\">\"" "; + echo "id&e=$entry->id\">\"""; + } +} + +function glossary_search_entries($searchterms, $glossary, $includedefinition) { +/// Returns a list of entries found using an array of search terms +/// eg word +word -word +/// + + global $CFG; + + if (!isteacher($glossary->course)) { + $glossarymodule = get_record("modules", "name", "glossary"); + $onlyvisible = " AND f.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id"; + $onlyvisibletable = ", {$CFG->prefix}course_modules cm"; + } else { + + $onlyvisible = ""; + $onlyvisibletable = ""; + } + + /// Some differences in syntax for PostgreSQL + if ($CFG->dbtype == "postgres7") { + $LIKE = "ILIKE"; // case-insensitive + $NOTLIKE = "NOT ILIKE"; // case-insensitive + $REGEXP = "~*"; + $NOTREGEXP = "!~*"; + } else { + $LIKE = "LIKE"; + $NOTLIKE = "NOT LIKE"; + $REGEXP = "REGEXP"; + $NOTREGEXP = "NOT REGEXP"; + } + + $conceptsearch = ""; + $definitionsearch = ""; + + + foreach ($searchterms as $searchterm) { + if (strlen($searchterm) < 2) { + continue; + } + if ($conceptsearch) { + $conceptsearch.= " OR "; + } + if ($definitionsearch) { + $definitionsearch.= " OR "; + } + + if (substr($searchterm,0,1) == "+") { + $searchterm = substr($searchterm,1); + $conceptsearch.= " e.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; + $definitionsearch .= " e.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; + } else if (substr($searchterm,0,1) == "-") { + $searchterm = substr($searchterm,1); + $conceptsearch .= " e.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; + $definitionsearch .= " e.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' "; + } else { + $conceptsearch .= " e.concept $LIKE '%$searchterm%' "; + $definitionsearch .= " e.definition $LIKE '%$searchterm%' "; + } + } + + if ( !$includedefinition ) { + $definitionsearch = "0"; + } + + $selectsql = "{$CFG->prefix}glossary_entries e, + {$CFG->prefix}glossary g $onlyvisibletable + WHERE ($conceptsearch OR $definitionsearch) + AND e.glossaryid = g.id $onlyvisible + AND g.id = $glossary->id"; + + $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"); +} + +function glossary_get_participants($glossaryid) { +//Returns the users with data in one glossary +//(users with records in glossary_entries, students) + + global $CFG; + + //Get students + $students = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}glossary_entries g + WHERE g.glossaryid = '$glossaryid' and + u.id = g.userid"); + + //Return students array (it contains an array of unique users) + return ($students); +} + +?> \ No newline at end of file diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html new file mode 100644 index 0000000000..5cdda4b525 --- /dev/null +++ b/mod/glossary/mod.html @@ -0,0 +1,115 @@ + + + +

+
+ + + + + + + + + + + + + + + + + + +course); +if (!$mainglossary or $mainglossary->id == $form->instance ) { +?> + + + + +"; +} +?> +

:

+ +

:

+ +

:

+ +

:

+ +

:

+ +
+ + + + + + + + +"> +
+
diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php new file mode 100644 index 0000000000..73d6ea83c6 --- /dev/null +++ b/mod/glossary/restorelib.php @@ -0,0 +1,140 @@ +id) + // | + // | + // | + // glossary_entries + // (UL,pk->id, fk->glossaryid) + // + // Meaning: pk->primary key field of the table + // fk->foreign key to link with parent + // nt->nested field (recursive data) + // CL->course level info + // UL->user level info + // files->table may have files) + // + //----------------------------------------------------------- + + //This function executes all the restore procedure about this mod + function glossary_restore_mods($mod,$restore) { + + global $CFG; + + $status = true; + + //Get record from backup_ids + $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id); + + if ($data) { + //Now get completed xmlized object + $info = $data->info; + //traverse_xmlize($info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //Now, build the glossary record structure + $glossary->course = $restore->course_id; + $glossary->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); + $glossary->studentcanpost = backup_todb($info['MOD']['#']['STUDENTCANPOST']['0']['#']); + $glossary->allowduplicatedentries = backup_todb($info['MOD']['#']['ALLOWDUPLICATEDENTRIES']['0']['#']); + $glossary->displayformat = backup_todb($info['MOD']['#']['DISPLAYFORMAT']['0']['#']); + $glossary->mainglossary = backup_todb($info['MOD']['#']['MAINGLOSSARY']['0']['#']); + $glossary->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']); + $glossary->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); + + //The structure is equal to the db, so insert the glossary + $newid = insert_record ("glossary",$glossary); + + //Do some output + echo "
  • ".get_string("modulename","glossary")." \"".$glossary->name."\"
    "; + backup_flush(300); + + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,$mod->modtype, + $mod->id, $newid); + //Now check if want to restore user data and do it. + //Restore glossary_entries + $status = glossary_entries_restore_mods($newid,$info,$restore); + } else { + $status = false; + } + + //Finalize ul + echo "
"; + + } else { + $status = false; + } + + return $status; + } + + //This function restores the glossary_entries + function glossary_entries_restore_mods($glossary_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the answers array + $entries = $info['MOD']['#']['ENTRIES']['0']['#']['ENTRY']; + + //Iterate over entries + for($i = 0; $i < sizeof($entries); $i++) { + $sub_info = $entries[$i]; + //traverse_xmlize($sub_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //We'll need this later!! + $oldid = backup_todb($sub_info['#']['ID']['0']['#']); + $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']); + + //Now, build the GLOSSARY_ENTRIES record structure + $entry->glossaryid = $glossary_id; + $entry->userid = backup_todb($sub_info['#']['USERID']['0']['#']); + $entry->concept = backup_todb($sub_info['#']['CONCEPT']['0']['#']); + $entry->definition = backup_todb($sub_info['#']['DEFINITION']['0']['#']); + $entry->timemodified = backup_todb($sub_info['#']['TIMEMODIFIED']['0']['#']); + $entry->teacherentry = backup_todb($sub_info['#']['TEACHERENTRY']['0']['#']); + + //We have to recode the userid field + $user = backup_getid($restore->backup_unique_code,"user",$entry->userid); + if ($user) { + $entry->userid = $user->new_id; + } + + if ( $entry->teacherentry or $restore->mods['glossary']->userinfo ) { + + //The structure is equal to the db, so insert the glossary_entries + $newid = insert_record ("glossary_entries",$entry); + + //Do some output + if (($i+1) % 50 == 0) { + echo "."; + if (($i+1) % 1000 == 0) { + echo "
"; + } + backup_flush(300); + } + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,"glossary_entries",$oldid, + $newid); + } else { + $status = false; + } + } + } + + return $status; + } + +?> \ No newline at end of file diff --git a/mod/glossary/version.php b/mod/glossary/version.php new file mode 100644 index 0000000000..262d1d662a --- /dev/null +++ b/mod/glossary/version.php @@ -0,0 +1,13 @@ +version = 2003091000; // The current module version (Date: YYYYMMDDXX) +$module->cron = 0; // Period for cron to check this module (secs) + +$release = "0.2 development"; // User-friendly version number + +?> diff --git a/mod/glossary/view.php b/mod/glossary/view.php new file mode 100644 index 0000000000..893df7ca5b --- /dev/null +++ b/mod/glossary/view.php @@ -0,0 +1,219 @@ + $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"); + } + + 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); + + add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id"); + +/// Print 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"); + + 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) + + echo "

$glossary->name

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

$strselectletter"; + + ?> +
+
+ + +
+ wwwroot/mod/glossary/view.php?id=$id&l=SPECIAL\">$strspecial | "; + + $middle = (int) ( (ord("Z") - ord("A")) / 2) ; + for ($i = ord("A"); $i <= ord("Z"); $i++) { + echo "wwwroot/mod/glossary/view.php?id=$id&l=" . chr($i) . "\">" . chr($i) . ""; + if ( $i - ord("A") - 1 != $middle ) { + echo " | "; + } else { + echo "
"; + } + + if ($i == ord("N") ) { + echo "wwwroot/mod/glossary/view.php?id=$id&l=Ñ\">Ñ | "; + } + + } + + 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 "
"; + } + + 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"; + } + +/// 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); + } else { // looking for terms that begin with a specify letter + $allentries = get_records("glossary_entries", "glossaryid", $glossary->id,"concept ASC"); + } + + if ( $allentries ) { + $DumpedDefinitions= 0; + foreach ($allentries as $entry) { + $DumpToScreen = 0; + $FirstLetter = strtoupper( ltrim( $entry->concept[0] ) ); + if ( $l ) { + if ( $l == "ALL" or $FirstLetter == $l) { + if ( $CurrentLetter != $FirstLetter ) { + $CurrentLetter = $FirstLetter; + + if ( $glossary->displayformat == 2 ) { + if ( $DumpedDefinitions != 1) { + echo "

"; + } + echo "\n

cellheading\">"; + } + echo $CurrentLetter; + + if ( $glossary->displayformat == 2 ) { + echo "\n
"; + if ( $DumpedDefinitions != 1) { + echo "\n
"; + } + } + } + $DumpToScreen = 1; + } elseif ( $l == "SPECIAL" and ord($FirstLetter) != ord("Ñ") and (ord($FirstLetter)ord("Z")) ) { + $DumpToScreen = 1; + } + } else { + $DumpToScreen = 1; + } + + if ( $DumpToScreen ) { + $DumpedDefinitions++; + + $concept = $entry->concept; + $definition = $entry->definition; + + if ( $DumpedDefinitions == 1 ) { + if ( $glossary->displayformat == 2 ) { + echo "\n
"; + } + } + if ($search) { + $entry->concept = highlight($search,$concept); + $entry->definition = highlight($search,$definition); + } + glossary_print_entry($course, $cm, $glossary, $entry); + + if ( $glossary->displayformat != 2 ) { + echo "

"; + } + } + } + } + if ( ! $DumpedDefinitions ) { + print_simple_box_start("center", "70%","$THEME->cellheading"); + if ( !$search ) { + echo "

$strnoentries
"; + } else { + echo "
"; + print_string("searchhelp"); + echo "
"; + } + print_simple_box_end(); + } else { + if ( $glossary->displayformat == 2 ) { + echo "\n
"; + } + } + +/// Finish the page + print_footer($course); + +?> \ No newline at end of file -- 2.39.5