Permalink
Browse files

- Display format of entries is now modular.

- Entries can have an optional file
- English help files.
- Now the alphabet is a language string so it is now usable in other languages.

KNOWN BUGS:
- It does not backup nor restore the attached files of the entries.
  • Loading branch information...
1 parent 83985dd commit e179048ec195a34859d4226df5f6150ca56993aa willcast committed Sep 16, 2003
View
5 mod/glossary/README.txt
@@ -20,8 +20,9 @@ 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.
+3) If you are using a them that uses its own set of icons (like cordoroyblue), you will need to copy the icon.gif and export.gif into your folder of custom icons.
+4) Visit your admin page to install the module
+5) Enjoy it.
Please, send me your comments and suggestions. It will help me improve this module.
View
30 mod/glossary/backuplib.php
@@ -10,7 +10,7 @@
// |
// |
// glossary_entries
- // (UL,pk->id, fk->glossaryid)
+ // (UL,pk->id, fk->glossaryid, files)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
@@ -41,6 +41,9 @@ function glossary_backup_mods($bf,$preferences) {
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("SHOWSPECIAL",4,false,$glossary->showspecial));
+ fwrite ($bf,full_tag("SHOWALPHABET",4,false,$glossary->showalphabet));
+ fwrite ($bf,full_tag("SHOWALL",4,false,$glossary->showall));
fwrite ($bf,full_tag("TIMECREATED",4,false,$glossary->timecreated));
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$glossary->timemodified));
@@ -83,6 +86,7 @@ function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {
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("ATTACHMENT",6,false,$glo_ent->attachment));
fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry));
$status =fwrite ($bf,end_tag("ENTRY",5,true));
@@ -97,6 +101,30 @@ function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {
}
+ //Backup glossary files because we've selected to backup user info
+ //and files are user info's level
+ function backup_glossary_files($bf,$preferences) {
+
+ global $CFG;
+
+ $status = true;
+
+ //First we check to moddata exists and create it as necessary
+ //in temp/backup/$backup_code dir
+ $status = check_and_create_moddata_dir($preferences->backup_unique_code);
+ //Now copy the forum dir
+ if ($status) {
+ //Only if it exists !! Thanks to Daniel Miksik.
+ if (is_dir($CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/glossary")) {
+ $status = backup_copy_file($CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/glossary",
+ $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/moddata/glossary");
+ }
+ }
+
+ 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
View
76 mod/glossary/db/mysql.php
@@ -1,30 +1,46 @@
-<?PHP
-
-function glossary_upgrade($oldversion) {
-/// This function does anything necessary to upgrade
-/// older versions to match current functionality
-
- global $CFG;
-
- if ($oldversion < 2003091000) {
-
- execute_sql(" ALTER TABLE `{$CFG->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;
-}
-
-?>
-
+<?PHP
+
+
+
+function glossary_upgrade($oldversion) {
+/// This function does anything necessary to upgrade
+/// older versions to match current functionality
+
+ global $CFG;
+
+ if ($oldversion < 2003091000) {
+ execute_sql(" ALTER TABLE `{$CFG->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') ");
+ }
+
+ if ( $oldversion < 2003091500 ) {
+ execute_sql(" ALTER TABLE `{$CFG->prefix}glossary_entries` ".
+ " ADD attachment VARCHAR(100) NOT NULL default '' AFTER `format`");
+ }
+
+ if ( $oldversion < 2003091600 ) {
+ execute_sql(" ALTER TABLE `{$CFG->prefix}glossary` ".
+ " ADD `showspecial` TINYINT(2) UNSIGNED DEFAULT '1' NOT NULL AFTER `mainglossary` , ".
+ " ADD `showalphabet` TINYINT(2) UNSIGNED DEFAULT '1' NOT NULL AFTER `showspecial` , ".
+ " ADD `showall` TINYINT(2) UNSIGNED DEFAULT '1' NOT NULL AFTER `showalphabet` ");
+ }
+
+ return true;
+}
+
+
+
+?>
+
+
+
View
105 mod/glossary/db/mysql.sql
@@ -1,62 +1,55 @@
# 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');
+#
+# 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',
+ showspecial tinyint(2) unsigned NOT NULL default '1',
+ showalphabet tinyint(2) unsigned NOT NULL default '1',
+ showall tinyint(2) unsigned NOT NULL default '1',
+ timecreated int(10) unsigned NOT NULL default '0',
+ timemodified int(10) unsigned NOT NULL default '0',
+ PRIMARY KEY (id)
+) 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',
+ attachment VARCHAR(100) NOT NULL default '',
+ 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');
+
View
17 mod/glossary/edit.html
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?=$onsubmit ?> action="edit.php">
+<FORM name="theform" method="post" <?=$onsubmit ?> action="edit.php" enctype="multipart/form-data">
<table>
<tr>
<td align=right>
@@ -46,6 +46,21 @@
?>
</p>
+<table border=0>
+<tr valign=top>
+ <td align=right><p><b><?php print_string("attachment", "glossary") ?>:<br \>(<?php print_string("optional") ?>)&nbsp;</b></p></td>
+ <td>
+ <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_max_upload_file_size() ?>">
+ <input type="file" name="attachment" size=40>
+ <?php
+ helpbutton("attachment", get_string("attachment", "glossary"), "glossary");
+ print_string("maxsize", "", display_size(get_max_upload_file_size()));
+ ?>
+ </td>
+
+</tr>
+</table>
+
<p align=center>
<input type="hidden" name=id value="<?=$cm->id ?>">
<input type="submit" value="<? print_string("savechanges") ?>">
View
272 mod/glossary/edit.php
@@ -1,139 +1,159 @@
<?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;
- }
- }
+global $CFG, $USER, $THEME;
+
+require_once("../../config.php");
+require_once("lib.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->course = $glossary->course;
+ $newentry->glossaryid = $glossary->id;
+ $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 ) {
+ $newentry->attachment = $_FILES["attachment"];
+ if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
+ $newentry->attachment = $newfilename;
+ } else {
+ unset($newentry->attachment);
+ }
+ if (! update_record("glossary_entries", $newentry)) {
+ error("Could not update your glossary");
+ } else {
+ add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&eid=$newentry->id", "$newentry->id");
+ }
+ } else {
+ error("Could not update this glossary entry because this concept already exist.");
+ }
+ } else {
+ $newentry->userid = $USER->id;
+ $newentry->course = $glossary->course;
+ $newentry->glossaryid = $glossary->id;
+ $newentry->concept = $form->concept;
+ $newentry->definition = $form->text;
+ $newentry->format = $form->format;
+ $newentry->timecreated = time();
+ $newentry->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 this new entry");
+ } else {
+ $newentry->attachment = $_FILES["attachment"];
+ if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
+ $newentry->attachment = $newfilename;
+ } else {
+ unset($newentry->attachment);
+ }
+ set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);
+
+ add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id", "$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");
+$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 ($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;
- }
+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));
+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";
+echo "<CENTER>\n";
- print_simple_box( text_to_html($glossary->name) , "center");
+print_simple_box( text_to_html($glossary->name) , "center");
- echo "<BR>";
+echo "<BR>";
- include("edit.html");
+include("edit.html");
- print_footer($course);
+print_footer($course);
?>
View
39 mod/glossary/exportentry.php
@@ -1,10 +1,11 @@
<?
require_once("../../config.php");
+ require_once("lib.php");
require_variable($id); // course module ID
require_variable($entry); // Entry ID
optional_variable($confirm); // confirmation
- global $THEME;
+ global $THEME, $USER, $CFG;
$PermissionGranted = 1;
@@ -70,23 +71,31 @@
$newentry->timecreated = $entry->timecreated;
$newentry->timemodified = $entry->timemodified;
$newentry->teacherentry = $entry->teacherentry;
+ $newentry->attachment = $entry->attachment;
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;
+ print_simple_box_start("center", "60%", "$THEME->cellheading");
+ echo "<p align=center><font size=3>$entryexported</font></p></font>";
+ if ($newentry->attachment) {
+ $entry->course = $cm->course;
+ $newentry->course = $cm->course;
+ if ( !glossary_copy_attachments($entry, $newentry) ) {
+ echo "<p align=\"center\">However, the attachment couldn't be exported.";
+ }
+ }
+
+ add_to_log($course->id, "glossary", "add entry",
+ "view.php?id=$cm->id&eid=".$entry->id, "$newentry->id");
+
+ 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");
@@ -108,4 +117,4 @@
}
print_footer();
-?>
+?>
View
48 mod/glossary/formats/1.php
@@ -0,0 +1,48 @@
+<?PHP // $Id$
+
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry) {
+ global $THEME, $USER;
+
+// if ($entry->timemarked < $entry->modified) {
+ $colour = $THEME->cellheading2;
+// } else {
+// $colour = $THEME->cellheading;
+// }
+ echo "<table width=70% border=0><tr><td>";
+
+ echo "\n<TABLE BORDER=1 CELLSPACING=0 width=100% valign=top cellpadding=10>";
+
+ echo "\n<TR>";
+ echo "<TD WIDTH=100% BGCOLOR=\"$colour\">";
+ if ($entry->attachment) {
+ $entry->course = $course->id;
+ echo "<table border=0 align=right><tr><td>";
+ echo glossary_print_attachments($entry, "html");
+ echo "</td></tr></table>";
+ }
+ echo "<b>$entry->concept</b><br>";
+ if ($entry) {
+ echo "&nbsp;&nbsp;<FONT SIZE=1>".get_string("lastedited").": ".userdate($entry->timemodified)."</FONT>";
+ }
+ echo "</TR>";
+
+ echo "\n<TR><TD WIDTH=100% BGCOLOR=\"$THEME->cellcontent\">";
+ if ($entry) {
+ echo format_text($entry->definition, $entry->format);
+
+ glossary_print_entry_icons($course, $cm, $glossary, $entry);
+
+ } else {
+ echo "<center>";
+ print_string("noentry", "glossary");
+ echo "</center>";
+ }
+ echo "</TD></TR>";
+
+ echo "</TABLE>\n";
+
+ echo "</td></tr></table>";
+
+}
+
+?>
View
57 mod/glossary/formats/2.php
@@ -0,0 +1,57 @@
+<?PHP // $Id$
+require_once("lib.php");
+
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry) {
+ global $THEME, $CFG, $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 "<table width=70% border=0><tr><td>";
+
+ echo "\n<TABLE BORDER=1 CELLSPACING=0 valign=top cellpadding=10>";
+
+ echo "\n<TR>";
+ echo "\n<TD ROWSPAN=2 BGCOLOR=\"$colour\" WIDTH=35 VALIGN=TOP>";
+ if ($entry) {
+ print_user_picture($user->id, $course->id, $user->picture);
+ }
+ echo "</TD>";
+ echo "<TD NOWRAP WIDTH=100% BGCOLOR=\"$THEME->cellheading\">";
+ if ($entry->attachment) {
+ $entry->course = $glossary->course;
+ echo "<table border=0 align=right><tr><td>";
+ echo glossary_print_attachments($entry, "html");
+ echo "</td></tr></table>";
+ }
+ 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";
+
+ echo "</td></tr></table>";
+}
+
+?>
View
307 mod/glossary/lib.php
@@ -3,9 +3,7 @@
/// 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
-
+require_once("$CFG->dirroot/files/mimetypes.php");
function glossary_add_instance($glossary) {
/// Given an object containing all the necessary data,
@@ -88,26 +86,21 @@ function glossary_print_recent_activity($course, $isteacher, $timestart) {
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");
@@ -169,108 +162,44 @@ function glossary_get_entries($glossaryid, $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);
-
+ global $THEME, $USET, $CFG;
+
+ $PermissionGranted = 0;
+ $formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
+ $functionname = "glossary_print_entry_by_format";
+
+ if ( $glossary->displayformat > 0 ) {
+ if ( file_exists($formatfile) ) {
+ include_once($formatfile);
+ if (function_exists($functionname) ) {
+ $PermissionGranted = 1;
+ }
+ }
} 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>";
+ $PermissionGranted = 1;
}
- 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);
-
+ if ( $glossary->displayformat > 0 and $PermissionGranted ) {
+ glossary_print_entry_by_format($course, $cm, $glossary, $entry);
} else {
- echo "<center>";
- print_string("noentry", "glossary");
- echo "</center>";
+ glossary_print_entry_by_default($course, $cm, $glossary, $entry);
}
- echo "</TD></TR>";
- echo "</TABLE>\n";
}
-function glossary_print_short_entries($course, $cm, $glossary, $entry) {
+function glossary_print_entry_by_default($course, $cm, $glossary, $entry) {
global $THEME, $USER;
$colour = $THEME->cellheading2;
echo "\n<TR>";
- echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\"><b>$entry->concept</b>: ";
+ echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
+ if ($entry->attachment) {
+ $entry->course = $course->id;
+ echo "<table border=0 align=right><tr><td>";
+ echo glossary_print_attachments($entry,"html");
+ echo "</td></tr></table>";
+ }
+ echo "<b>$entry->concept</b>: ";
echo format_text($entry->definition, $entry->format);
glossary_print_entry_icons($course, $cm, $glossary, $entry);
echo "</td>";
@@ -285,11 +214,6 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry) {
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> ";
@@ -392,4 +316,179 @@ function glossary_get_participants($glossaryid) {
return ($students);
}
-?>
+
+function glossary_file_area_name($entry) {
+// Creates a directory file name, suitable for make_upload_directory()
+ global $CFG;
+
+ return "$entry->course/$CFG->moddata/glossary/$entry->glossaryid/$entry->id";
+}
+
+function glossary_file_area($entry) {
+ return make_upload_directory( glossary_file_area_name($entry) );
+}
+
+function glossary_delete_old_attachments($entry, $exception="") {
+// Deletes all the user files in the attachments area for a entry
+// EXCEPT for any file named $exception
+
+ if ($basedir = glossary_file_area($entry)) {
+ if ($files = get_directory_list($basedir)) {
+ foreach ($files as $file) {
+ if ($file != $exception) {
+ unlink("$basedir/$file");
+// notify("Existing file '$file' has been deleted!");
+ }
+ }
+ }
+ if (!$exception) { // Delete directory as well, if empty
+ rmdir("$basedir");
+ }
+ }
+}
+
+function glossary_copy_attachments($entry, $newentry) {
+/// Given a entry object that is being copied to glossaryid,
+/// this function checks that entry
+/// for attachments, and if any are found, these are
+/// copied to the new glossary directory.
+
+ global $CFG;
+
+ $return = true;
+
+ if ($entries = get_records_select("glossary_entries", "id = '$entry->id' AND attachment <> ''")) {
+ foreach ($entries as $curentry) {
+ $oldentry->id = $entry->id;
+ $oldentry->course = $entry->course;
+ $oldentry->glossaryid = $curentry->glossaryid;
+ $oldentrydir = "$CFG->dataroot/".glossary_file_area_name($oldentry);
+ if (is_dir($oldentrydir)) {
+
+ $newentrydir = glossary_file_area($newentry);
+ if (! copy("$oldentrydir/$newentry->attachment", "$newentrydir/$newentry->attachment")) {
+ $return = false;
+ }
+ }
+ }
+ }
+ return $return;
+}
+
+function glossary_move_attachments($entry, $glossaryid) {
+/// Given a entry object that is being moved to glossaryid,
+/// this function checks that entry
+/// for attachments, and if any are found, these are
+/// moved to the new glossary directory.
+
+ global $CFG;
+
+ $return = true;
+
+ if ($entries = get_records_select("glossary_entries", "glossaryid = '$entry->id' AND attachment <> ''")) {
+ foreach ($entries as $entry) {
+ $oldentry->course = $entry->course;
+ $oldentry->glossaryid = $entry->glossaryid;
+ $oldentrydir = "$CFG->dataroot/".glossary_file_area_name($oldentry);
+ if (is_dir($oldentrydir)) {
+ $newentry = $oldentry;
+ $newentry->glossaryid = $glossaryid;
+ $newentrydir = "$CFG->dataroot/".glossary_file_area_name($newentry);
+ if (! @rename($oldentrydir, $newentrydir)) {
+ $return = false;
+ }
+ }
+ }
+ }
+ return $return;
+}
+
+function glossary_add_attachment($entry, $newfile) {
+// $entry is a full entry record, including course and glossary
+// $newfile is a full upload array from $_FILES
+// If successful, this function returns the name of the file
+
+ global $CFG;
+
+ if (empty($newfile['name'])) {
+ return "";
+ }
+
+ $newfile_name = clean_filename($newfile['name']);
+
+ if (valid_uploaded_file($newfile)) {
+ if (! $newfile_name) {
+ notify("This file had a wierd filename and couldn't be uploaded");
+
+ } else if (! $dir = glossary_file_area($entry)) {
+ notify("Attachment could not be stored");
+ $newfile_name = "";
+
+ } else {
+ if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
+ chmod("$dir/$newfile_name", $CFG->directorypermissions);
+ glossary_delete_old_attachments($entry, $newfile_name);
+ } else {
+ notify("An error happened while saving the file on the server");
+ $newfile_name = "";
+ }
+ }
+ } else {
+ $newfile_name = "";
+ }
+
+ return $newfile_name;
+}
+
+function glossary_print_attachments($entry, $return=NULL) {
+// if return=html, then return a html string.
+// if return=text, then return a text-only string.
+// otherwise, print HTML for non-images, and return image HTML
+
+ global $CFG;
+
+ $filearea = glossary_file_area_name($entry);
+
+ $imagereturn = "";
+ $output = "";
+
+ if ($basedir = glossary_file_area($entry)) {
+ if ($files = get_directory_list($basedir)) {
+ $strattachment = get_string("attachment", "glossary");
+ $strpopupwindow = get_string("popupwindow");
+ foreach ($files as $file) {
+ $icon = mimeinfo("icon", $file);
+ if ($CFG->slasharguments) {
+ $ffurl = "file.php/$filearea/$file";
+ } else {
+ $ffurl = "file.php?file=/$filearea/$file";
+ }
+ $image = "<img border=0 src=\"$CFG->wwwroot/files/pix/$icon\" height=16 width=16 alt=\"$strpopupwindow\">";
+
+ if ($return == "html") {
+ $output .= "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$image</a> ";
+ $output .= "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$file</a><br />";
+ } else if ($return == "text") {
+ $output .= "$strattachment $file:\n$CFG->wwwroot/$ffurl\n";
+
+ } else {
+ if ($icon == "image.gif") { // Image attachments don't get printed as links
+ $imagereturn .= "<br /><img src=\"$CFG->wwwroot/$ffurl\">";
+ } else {
+ link_to_popup_window("/$ffurl", "attachment", $image, 500, 500, $strattachment);
+ echo "<a target=_image href=\"$CFG->wwwroot/$ffurl\">$file</a>";
+ echo "<br />";
+ }
+ }
+ }
+ }
+ }
+
+ if ($return) {
+ return $output;
+ }
+
+ return $imagereturn;
+}
+
+?>
View
135 mod/glossary/mod.html
@@ -12,21 +12,21 @@
</TR>
<!-- More rows go in here... -->
<TR valign=top>
- <TD align=right><P><B><? echo get_string("canstudentpost", "glossary") ?>:</B></P></TD>
+ <TD align=right><P><B><? echo get_string("studentcanpost", "glossary") ?>:</B></P></TD>
<TD>
<select size="1" name="studentcanpost">
<option value="1" <?
if ( $form->studentcanpost ) {
echo "selected";
}
- ?>><? echo get_string("studentcanpost", "glossary") ?></option>
+ ?>><? echo get_string("yes") ?></option>
<option value="0" <?
if ( !$form->studentcanpost ) {
echo "selected";
}
- ?>><? echo get_string("studentcantpost", "glossary") ?>
+ ?>><? echo get_string("no") ?>
</option>
- </select> <? helpbutton("studentcanpost", get_string("canstudentpost", "glossary"), "glossary") ?>
+ </select> <? helpbutton("studentcanpost", get_string("studentcanpost", "glossary"), "glossary") ?>
</TD>
</TR>
<TR valign=top>
@@ -38,69 +38,140 @@
echo "selected";
}
?>
- ><? echo get_string("yesallowduplicates", "glossary") ?></option>
+ ><? echo get_string("yes") ?></option>
<option value="0" <?
if ( !$form->allowduplicatedentries ) {
echo "selected";
}
- ?>><? echo get_string("dontallowduplicates", "glossary") ?>
+ ?>><? echo get_string("no") ?>
</option>
</select> <? helpbutton("allowduplicatedentries", get_string("allowduplicatedentries", "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("glossarytype", "glossary") ?>:</B></P></TD>
+ <TD>
+ <select size="1" name="mainglossary">
+ <option value="1" <?
+ if ( $form->mainglossary ) {
+ echo "selected";
+ }
+ ?>><? echo get_string("mainglossary", "glossary") ?></option>
+ <option value="0" <?
+ if ( !$form->mainglossary ) {
+ echo "selected";
+ }
+ ?>><? echo get_string("secundaryglossary", "glossary") ?>
+ </option>
+ </select> <? helpbutton("mainglossary", get_string("mainglossary", "glossary"), "glossary") ?>
+ </TD>
+</TR>
+<?
+} else {
+ echo "<INPUT type=\"hidden\" name=mainglossary value=\"0\">";
+}
+?>
<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>
+ ?>><? echo get_string("displayformatdefault", "glossary") ?></option>
+<?
+ global $CFG;
+
+ $basedir = opendir("$CFG->dirroot/mod/glossary/formats");
+ while ($dir = readdir($basedir)) {
+ $firstchar = substr($dir, 0, 1);
+ if ($firstchar == "." or $dir == "CVS" or $dir == "_vti_cnf") {
+ continue;
+ }
+ if (filetype("$CFG->dirroot/mod/glossary/formats/$dir") == "dir") {
+ continue;
+ }
+ if ( $pos = strpos($dir, ".") ) {
+ $dir = substr($dir, 0, $pos );
+
+ echo "<option value=\"$dir\" ";
+ if ( $form->displayformat == $dir) {
+ echo "selected ";
+ }
+ echo ">";
+
+ echo get_string("displayformat$dir", "glossary")."</option>";
+ }
+ }
+
+?>
+
+ </select> <? helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
+ </TD>
+</TR>
+<TR valign=top>
+ <TD align=right><P><B><? echo get_string("showspecial", "glossary") ?>:</B></P></TD>
+ <TD>
+ <select size="1" name="showspecial">
<option value="1" <?
- if ( $form->displayformat == 1) {
+ if ( $form->showspecial ) {
echo "selected";
}
- ?>><? echo get_string("displayformatwouser", "glossary") ?></option>
-
- <option value="2" <?
- if ( $form->displayformat == 2) {
+ ?>
+ ><? echo get_string("yes") ?></option>
+ <option value="0" <?
+ if ( !$form->showspecial ) {
echo "selected";
}
- ?>><? echo get_string("displayformatsimple", "glossary") ?></option>
-
- </select> <? helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
+ ?>><? echo get_string("no") ?>
+ </option>
+ </select> <? helpbutton("shows", get_string("showspecial", "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 align=right><P><B><? echo get_string("showalphabet", "glossary") ?>:</B></P></TD>
<TD>
- <select size="1" name="mainglossary">
+ <select size="1" name="showalphabet">
<option value="1" <?
- if ( $form->mainglossary ) {
+ if ( $form->showalphabet ) {
echo "selected";
}
- ?>><? echo get_string("itisthemainglossary", "glossary") ?></option>
+ ?>
+ ><? echo get_string("yes") ?></option>
<option value="0" <?
- if ( !$form->mainglossary ) {
+ if ( !$form->showalphabet ) {
echo "selected";
}
- ?>><? echo get_string("itisntthemainglossary", "glossary") ?>
+ ?>><? echo get_string("no") ?>
</option>
- </select> <? helpbutton("mainglossary", get_string("mainglossary", "glossary"), "glossary") ?>
+ </select> <? helpbutton("shows", get_string("showalphabet", "glossary"), "glossary") ?>
+ </TD>
+</TR>
+<TR valign=top>
+ <TD align=right><P><B><? echo get_string("showall", "glossary") ?>:</B></P></TD>
+ <TD>
+ <select size="1" name="showall">
+ <option value="1" <?
+ if ( $form->showall ) {
+ echo "selected";
+ }
+ ?>
+ ><? echo get_string("yes") ?></option>
+ <option value="0" <?
+ if ( !$form->showall ) {
+ echo "selected";
+ }
+ ?>><? echo get_string("no") ?>
+ </option>
+ </select> <? helpbutton("shows", get_string("showall", "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) ?>">
View
62 mod/glossary/restorelib.php
@@ -10,7 +10,7 @@
// |
// |
// glossary_entries
- // (UL,pk->id, fk->glossaryid)
+ // (UL,pk->id, fk->glossaryid,files)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
@@ -45,6 +45,9 @@ function glossary_restore_mods($mod,$restore) {
$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->showspecial = backup_todb($info['MOD']['#']['SHOWSPECIAL']['0']['#']);
+ $glossary->showalphabet = backup_todb($info['MOD']['#']['SHOWALPHABET']['0']['#']);
+ $glossary->showall = backup_todb($info['MOD']['#']['SHOWALL']['0']['#']);
$glossary->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
$glossary->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
@@ -102,6 +105,7 @@ function glossary_entries_restore_mods($glossary_id,$info,$restore) {
$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->attachment = backup_todb($sub_info['#']['ATTACHMENT']['0']['#']);
$entry->timemodified = backup_todb($sub_info['#']['TIMEMODIFIED']['0']['#']);
$entry->teacherentry = backup_todb($sub_info['#']['TEACHERENTRY']['0']['#']);
@@ -137,4 +141,58 @@ function glossary_entries_restore_mods($glossary_id,$info,$restore) {
return $status;
}
-?>
+ //This function copies the glossary related info from backup temp dir to course moddata folder,
+ //creating it if needed and recoding everything (glossary id and entry id)
+ function glossary_restore_files ($oldgloid, $newgloid, $oldentryid, $newentryid, $restore) {
+
+ global $CFG;
+
+ $status = true;
+ $todo = false;
+ $moddata_path = "";
+ $forum_path = "";
+ $temp_path = "";
+
+ //First, we check to "course_id" exists and create is as necessary
+ //in CFG->dataroot
+ $dest_dir = $CFG->dataroot."/".$restore->course_id;
+ $status = check_dir_exists($dest_dir,true);
+
+ //First, locate course's moddata directory
+ $moddata_path = $CFG->dataroot."/".$restore->course_id."/".$CFG->moddata;
+
+ //Check it exists and create it
+ $status = check_dir_exists($moddata_path,true);
+
+ //Now, locate glossary directory
+ if ($status) {
+ $glossary_path = $moddata_path."/glossary";
+ //Check it exists and create it
+ $status = check_dir_exists($glossary_path,true);
+ }
+
+ //Now locate the temp dir we are restoring from
+ if ($status) {
+ $temp_path = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code.
+ "/moddata/glossary/".$oldgloid."/".$oldentryid;
+ //Check it exists
+ if (is_dir($temp_path)) {
+ $todo = true;
+ }
+ }
+
+ //If todo, we create the neccesary dirs in course moddata/glossary
+ if ($status and $todo) {
+ //First this glossary id
+ $this_glossary_path = $glossary_path."/".$newgloid;
+ $status = check_dir_exists($this_glossary_path,true);
+ //Now this entry id
+ $entry_glossary_path = $this_glossary_path."/".$newentryid;
+ //And now, copy temp_path to entry_glossary_path
+ $status = backup_copy_file($temp_path, $entry_glossary_path);
+ }
+
+ return $status;
+ }
+
+?>
View
4 mod/glossary/version.php
@@ -5,9 +5,9 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003091000; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2003091600; // 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
+$release = "0.3 development"; // User-friendly version number
?>
View
48 mod/glossary/view.php
@@ -89,25 +89,27 @@
</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> | ";
- }
-
+ if ( $glossary->showspecial ) {
+ echo "<p><a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=SPECIAL\">$strspecial</a> | ";
}
- echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=ALL\">$strallentries</a></p>";
-
+ if ( $glossary->showalphabet ) {
+ $alphabet = explode("|", get_string("alphabet","glossary"));
+ $letters_by_line = 14;
+ for ($i = 0; $i < count($alphabet); $i++) {
+ echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$id&l=$alphabet[$i]\">$alphabet[$i]</a>";
+ if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
+ echo " | ";
+ } else {
+ echo "<br>";
+ }
+ }
+ }
+
+ if ( $glossary->showall ) {
+ 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>";
@@ -151,15 +153,15 @@
if ( $CurrentLetter != $FirstLetter ) {
$CurrentLetter = $FirstLetter;
- if ( $glossary->displayformat == 2 ) {
+ if ( $glossary->displayformat == 0 ) {
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 ) {
+ if ( $glossary->displayformat == 0 ) {
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>";
@@ -181,7 +183,7 @@
$definition = $entry->definition;
if ( $DumpedDefinitions == 1 ) {
- if ( $glossary->displayformat == 2 ) {
+ if ( $glossary->displayformat == 0 ) {
echo "\n<center><TABLE BORDER=1 CELLSPACING=0 width=70% valign=top cellpadding=10>";
}
}
@@ -191,7 +193,7 @@
}
glossary_print_entry($course, $cm, $glossary, $entry);
- if ( $glossary->displayformat != 2 ) {
+ if ( $glossary->displayformat != 0 ) {
echo "<p>";
}
}
@@ -208,12 +210,12 @@
}
print_simple_box_end();
} else {
- if ( $glossary->displayformat == 2 ) {
+ if ( $glossary->displayformat == 0 ) {
echo "\n</TABLE></center>";
}
}
/// Finish the page
print_footer($course);
-?>
+?>

0 comments on commit e179048

Please sign in to comment.