]> git.mjollnir.org Git - moodle.git/commitdiff
New Glossary module, version 0.1 - by Williams Castillo!
authormoodler <moodler>
Tue, 16 Sep 2003 03:07:21 +0000 (03:07 +0000)
committermoodler <moodler>
Tue, 16 Sep 2003 03:07:21 +0000 (03:07 +0000)
17 files changed:
mod/glossary/README.txt [new file with mode: 0644]
mod/glossary/backuplib.php [new file with mode: 0644]
mod/glossary/db/mysql.php [new file with mode: 0644]
mod/glossary/db/mysql.sql [new file with mode: 0644]
mod/glossary/deleteentry.html [new file with mode: 0644]
mod/glossary/deleteentry.php [new file with mode: 0644]
mod/glossary/edit.html [new file with mode: 0644]
mod/glossary/edit.php [new file with mode: 0644]
mod/glossary/export.gif [new file with mode: 0644]
mod/glossary/exportentry.php [new file with mode: 0644]
mod/glossary/icon.gif [new file with mode: 0644]
mod/glossary/index.php [new file with mode: 0644]
mod/glossary/lib.php [new file with mode: 0644]
mod/glossary/mod.html [new file with mode: 0644]
mod/glossary/restorelib.php [new file with mode: 0644]
mod/glossary/version.php [new file with mode: 0644]
mod/glossary/view.php [new file with mode: 0644]

diff --git a/mod/glossary/README.txt b/mod/glossary/README.txt
new file mode 100644 (file)
index 0000000..1f4b462
--- /dev/null
@@ -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 (file)
index 0000000..37532e6
--- /dev/null
@@ -0,0 +1,146 @@
+<?PHP //$Id$
+    //This php script contains all the stuff to backup/restore
+    //glossary mods
+
+    //This is the "graphical" structure of the glossary mod:
+    //
+    //                     glossary                                      
+    //                    (CL,pk->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 (file)
index 0000000..b8c2e65
--- /dev/null
@@ -0,0 +1,30 @@
+<?PHP\r
+\r
+function glossary_upgrade($oldversion) {\r
+/// This function does anything necessary to upgrade \r
+/// older versions to match current functionality \r
+\r
+    global $CFG;\r
+\r
+    if ($oldversion < 2003091000) {\r
+\r
+        execute_sql(" ALTER TABLE `{$CFG->prefix}glossary` ".\r
+                    " ADD `allowduplicatedentries` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `studentcanpost` , ".\r
+                    " ADD `displayformat` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `allowduplicatedentries` , ".\r
+                    " ADD `mainglossary` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `displayformat` ");\r
+\r
+        execute_sql(" ALTER TABLE `{$CFG->prefix}glossary_entries` ".\r
+                    " ADD timecreated INT(10) UNSIGNED NOT NULL default '0' AFTER `format` , ".\r
+                    " ADD timemodified INT(10) UNSIGNED NOT NULL default '0' AFTER `timecreated` , ".\r
+                         " ADD teacherentry TINYINT(2) UNSIGNED NOT NULL default '0' AFTER `timemodified` ");\r
+\r
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'delete', 'glossary', 'name') ");\r
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'delete entry', 'glossary', 'name') ");\r
+\r
+    }\r
+\r
+    return true;\r
+}\r
+\r
+?>\r
+\r
diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql
new file mode 100644 (file)
index 0000000..b3c6615
--- /dev/null
@@ -0,0 +1,62 @@
+# This file contains a complete database schema for all the 
+\r
+# tables used by this module, written in SQL
+
+\r
+# It may also contain INSERT statements for particular data 
+\r
+# that may be used, especially new entries in the table log_display
+
+\r
+\r
+#\r
+# Table structure for table `glossary`\r
+#\r
+\r
+CREATE TABLE prefix_glossary (\r
+  id int(10) unsigned NOT NULL auto_increment,\r
+  course int(10) unsigned NOT NULL default '0',\r
+  name varchar(255) NOT NULL default '',\r
+  studentcanpost tinyint(2) unsigned NOT NULL default '0',\r
+\r
+  allowduplicatedentries tinyint(2) unsigned NOT NULL default '0',\r
+  displayformat tinyint(2) unsigned NOT NULL default '0',\r
+  mainglossary tinyint(2) unsigned NOT NULL default '0',\r
+  \r
+  timecreated int(10) unsigned NOT NULL default '0',\r
+  timemodified int(10) unsigned NOT NULL default '0',\r
+  PRIMARY KEY  (id)\r
+) TYPE=MyISAM COMMENT='all glossaries';\r
+\r
+#\r
+# Table structure for table `glossary_entries`\r
+#\r
+\r
+CREATE TABLE prefix_glossary_entries (\r
+  id int(10) unsigned NOT NULL auto_increment,\r
+  glossaryid int(10) unsigned NOT NULL default '0',\r
+  userid int(10) unsigned NOT NULL default '0',\r
+\r
+  concept varchar(255) NOT NULL default '',\r
+  definition text NOT NULL,\r
+  format tinyint(2) unsigned NOT NULL default '0',\r
+  timecreated int(10) unsigned NOT NULL default '0',\r
+  timemodified int(10) unsigned NOT NULL default '0',\r
+\r
+  teacherentry tinyint(2) unsigned NOT NULL default '0',\r
+\r
+  PRIMARY KEY  (id)\r
+) TYPE=MyISAM COMMENT='all glossary entries';\r
+\r
+#\r
+# Dumping data for table `log_display`\r
+#\r
+\r
+INSERT INTO prefix_log_display VALUES ('glossary', 'add', 'glossary', 'name');\r
+INSERT INTO prefix_log_display VALUES ('glossary', 'update', 'glossary', 'name');\r
+\r
+INSERT INTO prefix_log_display VALUES ('glossary', 'view', 'glossary', 'name');\r
+INSERT INTO prefix_log_display VALUES ('glossary', 'view all', 'glossary', 'name');\r
+\r
+INSERT INTO prefix_log_display VALUES ('glossary', 'add entry', 'glossary', 'name');\r
+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 (file)
index 0000000..3b77ab1
--- /dev/null
@@ -0,0 +1,11 @@
+<form name="form" method="post" action="deleteentry.php">
+
+<input type="hidden" name=id              value="<?php p($cm->id) ?>">
+<input type="hidden" name=mode         value="delete">
+<input type="hidden" name=go       value="1">
+<input type="hidden" name=entry         value="<?php echo $entry ?>">
+
+<input type="submit" value=" <?php print_string("yes")?> "> 
+<input type=button value=" <?php print_string("no")?> " onclick="javascript:history.go(-1);">
+
+</form>
\ No newline at end of file
diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php
new file mode 100644 (file)
index 0000000..7f5be1a
--- /dev/null
@@ -0,0 +1,79 @@
+<?PHP // $Id$
+
+       require_once("../../config.php");
+
+    require_variable($id);    // course module ID
+    require_variable($mode);  // edit or delete
+    optional_variable($go);  // commit the operation?
+    optional_variable($entry);  // edit or delete
+
+    $strglossary = get_string("modulename", "glossary");
+    $strglossaries = get_string("modulenameplural", "glossary");
+    $stredit = get_string("edit");
+    $entrydeleted = get_string("entrydeleted","glossary");
+
+
+    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");
+    }
+
+    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 = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+    print_header("$course->shortname: $glossary->name", "$course->fullname",
+                 "$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> $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 "<p>";
+       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 "<center>$entrydeleted"; //CAMBIAR
+                               echo "</center>";
+                               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 "<center><b>$entryfields->concept</b><br>$strareyousuredelete"; //CAMBIAR
+                               include("deleteentry.html");
+                               echo "</center>";
+                               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 (file)
index 0000000..55ad7a9
--- /dev/null
@@ -0,0 +1,61 @@
+<FORM name="theform" method="post" <?=$onsubmit ?> action="edit.php">
+<table>
+<tr>
+    <td align=right>
+    <font size="1">
+     <?PHP
+        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
+        echo "<br />";
+        if ($usehtmleditor) {
+           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
+        } else {
+           emoticonhelpbutton("theform", "text");
+        } 
+      ?>
+     <br />
+    </font>
+    </td>
+</tr>
+
+<tr>
+    <td align=center>    
+     <? echo get_string("concept","glossary") ?>: <INPUT type="text" name="concept" size=30 value="<? p($form->concept) ?>">     
+    </td>
+</tr>
+<tr>
+    <td align=center><p>
+     <? echo get_string("definition","glossary").":" ?>     
+    </td>
+</tr>
+
+</table>
+
+<? print_textarea($usehtmleditor, 20, 60, 630, 400, "text", $entry->text); ?>
+
+<p align=center>
+<?PHP
+   print_string("formattexttype");
+   echo ":&nbsp;";
+   choose_from_menu(format_text_menu(), "format", $entry->format, "");
+   echo "<font size=\"1\">";
+   helpbutton("textformat", get_string("helpformatting"));
+   echo "</font>";
+   if ($entry->id) {
+       echo "<input type=\"hidden\" name=entry value=\"$entry->id\">";
+   }
+?>
+</p>
+
+<p align=center>
+<input type="hidden" name=id value="<?=$cm->id ?>">
+<input type="submit" value="<? print_string("savechanges") ?>">
+<input type="reset" value="<? print_string("revert") ?>">
+</P>
+</form>
+
+<?PHP 
+   if ($usehtmleditor) { 
+       print_richedit_javascript("theform", "text", "no");
+   }
+?>
+
diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php
new file mode 100644 (file)
index 0000000..98d2ee6
--- /dev/null
@@ -0,0 +1,139 @@
+<?PHP // $Id$
+
+       require_once("../../config.php");
+
+    require_variable($id);    // Course Module ID 
+    optional_variable($e);    // EntryID
+
+    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");
+    }
+
+    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",
+                 "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> 
+                  <A HREF=\"index.php?id=$course->id\">$strglossaries</A> -> 
+                  <A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "theform.text",
+                  "", true, "", navmenu($course, $cm));
+
+    echo "<CENTER>\n";
+
+    print_simple_box( text_to_html($glossary->name) , "center");
+
+    echo "<BR>";
+
+       include("edit.html");
+
+    print_footer($course);
+
+?>
diff --git a/mod/glossary/export.gif b/mod/glossary/export.gif
new file mode 100644 (file)
index 0000000..d27efa2
Binary files /dev/null and b/mod/glossary/export.gif differ
diff --git a/mod/glossary/exportentry.php b/mod/glossary/exportentry.php
new file mode 100644 (file)
index 0000000..6a5ea26
--- /dev/null
@@ -0,0 +1,111 @@
+<?
+       require_once("../../config.php");
+
+       require_variable($id);    // course module ID
+       require_variable($entry);    // Entry ID
+       optional_variable($confirm);     // confirmation
+       global $THEME;
+
+       $PermissionGranted = 1;
+
+       $cm = get_record("course_modules","id",$id);
+       if ( ! $cm ) {
+               $PermissionGranted = 0;
+       } else {
+               $mainglossary = get_record("glossary","course",$cm->course, "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 = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    print_header("$course->shortname: $glossary->name", "$course->fullname",
+                 "$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> $glossary->name",
+                  "", "", true, "",
+                  navmenu($course, $cm));
+
+       if ( $PermissionGranted ) {
+               $entry = get_record("glossary_entries", "id", $entry);
+
+               if ( !$confirm ) {
+                       echo "<center>";
+
+                       notice_yesno ("<center><h2>$entry->concept</h2><p align=center>Seguro que desea agregar esta entrada a<br><b>$mainglossary->name</b>?",
+                               "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 "<p align=center><font size=3>$entryexported</font></p></font>";
+                    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 "<p align=center><font size=3>$entryalreadyexist</font></p></font>";
+                               echo "<p align=center>";
+
+                               print_continue("view.php?id=$cm->id&eid=".$entry->id);
+
+                           print_simple_box_end();
+                       }
+               }
+       } else {
+               print_simple_box_start("center", "60%", "#FFBBBB");
+               echo "<p align=center><font size=3>A weird error was found while trying to export this entry. Operation cancelled.</font></p></font>";
+
+                       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 (file)
index 0000000..a2d6f78
Binary files /dev/null and b/mod/glossary/icon.gif differ
diff --git a/mod/glossary/index.php b/mod/glossary/index.php
new file mode 100644 (file)
index 0000000..ff005c6
--- /dev/null
@@ -0,0 +1,77 @@
+<?PHP // $Id$
+
+/// This page lists all the instances of glossary in a particular course
+/// Replace glossary with the name of your module
+
+    require_once("../../config.php");
+    require_once("lib.php");
+
+    require_variable($id);   // course
+
+    if (! $course = get_record("course", "id", $id)) {
+        error("Course ID is incorrect");
+    }
+
+    require_login($course->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 = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    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 = "<A HREF=\"view.php?id=$glossary->coursemodule\">$glossary->name</A>";
+
+        if ($course->format == "weeks" or $course->format == "topics") {
+            $table->data[] = array ($glossary->section, $link);
+        } else {
+            $table->data[] = array ($link);
+        }
+    }
+
+    echo "<BR>";
+
+    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 (file)
index 0000000..b86611b
--- /dev/null
@@ -0,0 +1,395 @@
+<?PHP  // $Id$
+
+/// Library of functions and constants for module glossary
+/// (replace glossary with the name of your module and delete this line)
+
+
+$glossary_CONSTANT = 7;     /// for example
+
+
+function glossary_add_instance($glossary) {
+/// Given an object containing all the necessary data,
+/// (defined by the form in mod.html) this function
+/// will create a new instance and return the id number
+/// of the new instance.
+
+    $glossary->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 "<h1>ANTES</h1>";
+    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 "<h1>ADENTRO => ANTES</h1>";
+
+        //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 "<h1>ADENTRO => DESPUES</h1>";
+    }
+
+       echo "<h1>DESPUES</h1>";
+
+    $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 "<p><font size=1>$date - $entry->firstname $entry->lastname<br>";
+            echo "\"<a href=\"$CFG->wwwroot/mod/glossary/$entry->url\">";
+            echo "$entry->concept";
+            echo "</a>\"</font></p>";
+        }
+    }
+
+    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 "<table width=70% border=0><tr><td>";
+            glossary_print_entry_with_user($course, $cm, $glossary, $entry);
+            echo "</td></tr></table>";
+            break;
+       case 1:
+            echo "<table width=70% border=0><tr><td>";
+            glossary_print_entry_without_user($course, $cm, $glossary, $entry);
+            echo "</td></tr></table>";
+            break;
+        case 2:
+//            echo "<table width=70% border=0><tr><td>";
+            glossary_print_short_entries($course, $cm, $glossary, $entry);
+//            echo "</td></tr></table>";
+            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<TABLE BORDER=1 CELLSPACING=0 valign=top cellpadding=10>";
+
+    echo "\n<TR>";
+    echo "\n<TD ROWSPAN=2 BGCOLOR=\"$THEME->cellheading\" WIDTH=35 VALIGN=TOP>";
+    if ($entry) {
+       print_user_picture($user->id, $course->id, $user->picture);
+    }
+    echo "</TD>";
+    echo "<TD NOWRAP WIDTH=100% BGCOLOR=\"$colour\">";
+    if ($entry) {
+       echo "<b>$entry->concept</b><br><FONT SIZE=2>$strby $user->firstname $user->lastname</font>";
+        echo "&nbsp;&nbsp;<FONT SIZE=1>(".get_string("lastedited").": ".userdate($entry->timemodified).")</FONT></small>";
+    }
+    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);
+
+    } else {
+         echo "<center>";
+        print_string("noentry", "glossary");
+         echo "</center>";
+    }
+    echo "</TD></TR>";
+
+    echo "</TABLE>\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<TABLE BORDER=1 CELLSPACING=0 width=100% valign=top cellpadding=10>";
+
+    echo "\n<TR>";
+    echo "<TD WIDTH=100% BGCOLOR=\"$colour\"><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);
+
+    } else {
+         echo "<center>";
+        print_string("noentry", "glossary");
+         echo "</center>";
+    }
+    echo "</TD></TR>";
+
+    echo "</TABLE>\n";
+}
+
+function glossary_print_short_entries($course, $cm, $glossary, $entry) {
+    global $THEME, $USER;
+
+    $colour = $THEME->cellheading2;
+
+    echo "\n<TR>";
+    echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\"><b>$entry->concept</b>: ";
+    echo format_text($entry->definition, $entry->format);
+    glossary_print_entry_icons($course, $cm, $glossary, $entry);
+    echo "</td>";
+    echo "</TR>";
+}
+
+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 "<p align=right>";
+               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",
+                                                               "<img  alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0>",
+                                                       400, 500, get_string("exporttomainglossary","glossary"), "none");
+*/
+
+                               echo "<a href=\"exportentry.php?id=$cm->id&entry=$entry->id\"><img  alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
+
+                       }
+               }
+               echo "<a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id\"><img  alt=\"" . get_string("delete") . "\"src=\"../../pix/t/delete.gif\" height=11 width=11 border=0></a> ";
+               echo "<a href=\"edit.php?id=$cm->id&e=$entry->id\"><img  alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
+         }
+}
+
+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 (file)
index 0000000..5cdda4b
--- /dev/null
@@ -0,0 +1,115 @@
+<!-- This page defines the form to create or edit an instance of this module -->
+<!-- It is used from /course/mod.php.  The whole instance is available as $form. -->
+
+<FORM name="form" method="post" action="<?=$ME ?>">
+<CENTER>
+<TABLE cellpadding=5>
+<TR valign=top>
+    <TD align=right><P><B><? print_string("name") ?>:</B></P></TD>
+    <TD>
+        <INPUT type="text" name="name" size=30 value="<? p($form->name) ?>">
+    </TD>
+</TR>
+<!-- More rows go in here... -->
+<TR valign=top>
+    <TD align=right><P><B><? echo get_string("canstudentpost", "glossary") ?>:</B></P></TD>
+    <TD>
+  <select size="1" name="studentcanpost">
+  <option value="1" <? 
+   if ( $form->studentcanpost ) {
+      echo "selected";
+   }
+   ?>><? echo get_string("studentcanpost", "glossary") ?></option>
+  <option value="0" <? 
+   if ( !$form->studentcanpost ) {
+      echo "selected";
+   }
+   ?>><? echo get_string("studentcantpost", "glossary") ?>
+  </option>
+  </select> <? helpbutton("studentcanpost", get_string("canstudentpost", "glossary"), "glossary") ?>
+    </TD>
+</TR>
+<TR valign=top>
+    <TD align=right><P><B><? echo get_string("allowduplicatedentries", "glossary") ?>:</B></P></TD>
+    <TD>
+  <select size="1" name="allowduplicatedentries">
+  <option value="1" <? 
+   if ( $form->allowduplicatedentries ) {
+      echo "selected";
+   }
+   ?> 
+   ><? echo get_string("yesallowduplicates", "glossary") ?></option>
+  <option value="0" <? 
+   if ( !$form->allowduplicatedentries ) {
+      echo "selected";
+   }
+   ?>><? echo get_string("dontallowduplicates", "glossary") ?>
+  </option>
+  </select> <? helpbutton("allowduplicatedentries", get_string("allowduplicatedentries", "glossary"), "glossary") ?>
+    </TD>
+</TR>
+<TR valign=top>
+    <TD align=right><P><B><? echo get_string("displayformat", "glossary") ?>:</B></P></TD>
+    <TD>
+  <select size="1" name="displayformat">
+
+  <option value="0" <? 
+   if ( $form->displayformat == 0) {
+      echo "selected";
+   }
+  ?>><? echo get_string("displayformatwuser", "glossary") ?></option>
+
+  <option value="1" <? 
+   if ( $form->displayformat == 1) {
+      echo "selected";
+   }
+  ?>><? echo get_string("displayformatwouser", "glossary") ?></option>
+
+  <option value="2" <? 
+   if ( $form->displayformat == 2) {
+      echo "selected";
+   }
+  ?>><? echo get_string("displayformatsimple", "glossary") ?></option>
+
+  </select> <? helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
+    </TD>
+</TR>
+<?
+$mainglossary = get_record("glossary","mainglossary",1,"course",$form->course);
+if (!$mainglossary or $mainglossary->id == $form->instance ) {
+?>
+<TR valign=top>
+    <TD align=right><P><B><? echo get_string("isthisthemainglossary", "glossary") ?>:</B></P></TD>
+    <TD>
+  <select size="1" name="mainglossary">
+  <option value="1" <? 
+   if ( $form->mainglossary ) {
+      echo "selected";
+   }
+   ?>><? echo get_string("itisthemainglossary", "glossary") ?></option>
+  <option value="0" <? 
+   if ( !$form->mainglossary ) {
+      echo "selected";
+   }
+   ?>><? echo get_string("itisntthemainglossary", "glossary") ?>
+  </option>
+  </select> <? helpbutton("mainglossary", get_string("mainglossary", "glossary"), "glossary") ?>
+    </TD>
+</TR>
+<?
+} else {
+       echo "<INPUT type=\"hidden\" name=mainglossary value=\"0\">";
+}
+?>
+</TABLE>
+<!-- These hidden variables are always the same -->
+<INPUT type="hidden" name=course        value="<? p($form->course) ?>">
+<INPUT type="hidden" name=coursemodule  value="<? p($form->coursemodule) ?>">
+<INPUT type="hidden" name=section       value="<? p($form->section) ?>">
+<INPUT type="hidden" name=module        value="<? p($form->module) ?>">
+<INPUT type="hidden" name=modulename    value="<? p($form->modulename) ?>">
+<INPUT type="hidden" name=instance      value="<? p($form->instance) ?>">
+<INPUT type="hidden" name=mode          value="<? p($form->mode) ?>">
+<INPUT type="submit" value="<? print_string("savechanges") ?>">
+</CENTER>
+</FORM>
diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php
new file mode 100644 (file)
index 0000000..73d6ea8
--- /dev/null
@@ -0,0 +1,140 @@
+<?PHP //$Id$
+    //This php script contains all the stuff to backup/restore
+    //glossary mods
+
+    //This is the "graphical" structure of the glossary mod:
+    //
+    //                     glossary
+    //                    (CL,pk->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 "<ul><li>".get_string("modulename","glossary")." \"".$glossary->name."\"<br>";
+            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 "</ul>";
+
+        } 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 "<br>";
+                       }
+                 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 (file)
index 0000000..262d1d6
--- /dev/null
@@ -0,0 +1,13 @@
+<?PHP // $Id$
+
+/////////////////////////////////////////////////////////////////////////////////
+///  Code fragment to define the version of glossary
+///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
+/////////////////////////////////////////////////////////////////////////////////
+
+$module->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 (file)
index 0000000..893df7c
--- /dev/null
@@ -0,0 +1,219 @@
+<?PHP  // $Id$
+
+/// This page prints a particular instance of glossary
+
+    require_once("../../config.php");
+    require_once("lib.php");
+
+    require_variable($id);    // Course Module ID, or
+
+    optional_variable($l);     // letter to look for
+    optional_variable($eid);  // Entry ID
+    optional_variable($search, "");  // search string
+    optional_variable($includedefinition);  // include definition in search function?
+
+    if ($l == "" and $search == "" and $eid == "") {
+               $l = "A";
+    }
+
+    $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");
+    }
+
+    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 = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    $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 <A HREF=index.php?id=$course->id>$strglossaries</A> -> $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 "<p><center><b>$glossary->name<p>" ;
+
+    if ( !$course->visible ) {
+        notice(get_string("activityiscurrentlyhidden"));
+    }
+
+    print_simple_box_start("center", "70%");
+      echo "<CENTER>$strselectletter";
+
+       ?>
+       <form method="POST" action="view.php">
+         <? p(get_string("searchconcept","glossary")) ?> <input type="text" name="search" size="20" value=""> <br><? p(get_string("searchindefinition","glossary")) ?> <input type="checkbox" name="includedefinition" value="1">
+         <input type="submit" value="Search" name="searchbutton">
+         <input type="hidden" name="id" value="<? p($cm->id) ?>">
+       </form>
+       <?
+
+      echo "<p><a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=SPECIAL\">$strspecial</a> | ";
+
+      $middle = (int) ( (ord("Z") - ord("A")) / 2) ;
+      for ($i = ord("A"); $i <= ord("Z"); $i++) {
+         echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=" . chr($i) . "\">" . chr($i) . "</a>";
+         if ( $i - ord("A") - 1 != $middle ) {
+            echo " | ";
+         } else {
+            echo "<br>";
+         }
+
+         if ($i == ord("N") ) {
+            echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=Ñ\">Ñ</a> | ";
+         }
+
+      }
+
+      echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=ALL\">$strallentries</a></p>";
+
+      if (isteacher($course->id) or $glossary->studentcanpost) {
+         $options = array ("id" => "$cm->id");
+         echo "<CENTER>";
+         print_single_button("edit.php", $options, $straddentry );
+         echo "</CENTER>";
+      }
+
+    print_simple_box_end();
+
+    echo "<p align=center>";
+    if ($l) {
+               $CurrentLetter = "";
+               if ($l == "ALL" or $l == "SPECIAL") {
+                       if ( $l == "ALL" ) {
+                               echo "<h2>$strallentries</h2><p>";
+                       } elseif ($l == "SPECIAL") {
+                               echo "<h2>$strspecial</h2><p>";
+                       }
+               }
+       } 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 "</table></center><p>";
+                               }
+                               echo "\n<center><TABLE BORDER=0 CELLSPACING=0 width=70% valign=top cellpadding=10><tr><td align=center BGCOLOR=\"$THEME->cellheading\"><b>";
+                           }
+                           echo $CurrentLetter;
+
+                           if ( $glossary->displayformat == 2 ) {
+                               echo "\n</b></center></td></tr></TABLE></center>";
+                               if ( $DumpedDefinitions != 1) {
+                                       echo "\n<center><TABLE BORDER=1 CELLSPACING=0 width=70% valign=top cellpadding=10>";
+                               }
+                           }
+                       }
+                       $DumpToScreen = 1;
+                } elseif ( $l == "SPECIAL" and ord($FirstLetter) != ord("Ñ") and (ord($FirstLetter)<ord("A") or 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<center><TABLE BORDER=1 CELLSPACING=0 width=70% valign=top cellpadding=10>";
+                        }
+                 }
+                 if ($search) {
+                       $entry->concept = highlight($search,$concept);
+                       $entry->definition = highlight($search,$definition);
+                 }
+                    glossary_print_entry($course, $cm, $glossary, $entry);
+
+                                if ( $glossary->displayformat != 2 ) {
+                       echo "<p>";
+                 }
+            }
+        }
+    }
+       if ( ! $DumpedDefinitions ) {
+               print_simple_box_start("center", "70%","$THEME->cellheading");
+               if ( !$search ) {
+                       echo "<center>$strnoentries</center>";
+               } else {
+                       echo "<center>";
+                       print_string("searchhelp");
+                       echo "</center>";
+               }
+               print_simple_box_end();
+       } else {
+           if ( $glossary->displayformat == 2 ) {
+               echo "\n</TABLE></center>";
+           }
+       }
+
+/// Finish the page
+    print_footer($course);
+
+?>
\ No newline at end of file