From e179048ec195a34859d4226df5f6150ca56993aa Mon Sep 17 00:00:00 2001 From: willcast Date: Tue, 16 Sep 2003 18:51:40 +0000 Subject: [PATCH] - 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. --- mod/glossary/README.txt | 5 +- mod/glossary/backuplib.php | 30 +++- mod/glossary/db/mysql.php | 76 +++++---- mod/glossary/db/mysql.sql | 105 ++++++------ mod/glossary/edit.html | 17 +- mod/glossary/edit.php | 272 +++++++++++++++++-------------- mod/glossary/exportentry.php | 39 +++-- mod/glossary/formats/1.php | 48 ++++++ mod/glossary/formats/2.php | 57 +++++++ mod/glossary/lib.php | 307 +++++++++++++++++++++++------------ mod/glossary/mod.html | 135 +++++++++++---- mod/glossary/restorelib.php | 62 ++++++- mod/glossary/version.php | 4 +- mod/glossary/view.php | 48 +++--- 14 files changed, 811 insertions(+), 394 deletions(-) create mode 100644 mod/glossary/formats/1.php create mode 100644 mod/glossary/formats/2.php diff --git a/mod/glossary/README.txt b/mod/glossary/README.txt index 1f4b462043..71fa1b67a0 100644 --- a/mod/glossary/README.txt +++ b/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. diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index 37532e6ec6..937cd8174c 100644 --- a/mod/glossary/backuplib.php +++ b/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 @@ 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 @@ 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 @@ } + //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 diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php index b8c2e655da..599dcc1c05 100644 --- a/mod/glossary/db/mysql.php +++ b/mod/glossary/db/mysql.php @@ -1,30 +1,46 @@ -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; -} - -?> - +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; +} + + + +?> + + + diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql index b3c6615b15..5a2da9a71e 100644 --- a/mod/glossary/db/mysql.sql +++ b/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'); \ No newline at end of file +# +# 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'); + diff --git a/mod/glossary/edit.html b/mod/glossary/edit.html index 55ad7a99ed..8a165d7df5 100644 --- a/mod/glossary/edit.html +++ b/mod/glossary/edit.html @@ -1,4 +1,4 @@ -
action="edit.php"> + action="edit.php" enctype="multipart/form-data"> "; - echo ""; @@ -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", - "\""", - 400, 500, get_string("exporttomainglossary","glossary"), "none"); -*/ echo "id&entry=$entry->id\">\"" "; @@ -392,4 +316,179 @@ function glossary_get_participants($glossaryid) { return ($students); } -?> \ No newline at end of file + +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 = "wwwroot/files/pix/$icon\" height=16 width=16 alt=\"$strpopupwindow\">"; + + if ($return == "html") { + $output .= "wwwroot/$ffurl\">$image "; + $output .= "wwwroot/$ffurl\">$file
"; + } 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 .= "
wwwroot/$ffurl\">"; + } else { + link_to_popup_window("/$ffurl", "attachment", $image, 500, 500, $strattachment); + echo "wwwroot/$ffurl\">$file"; + echo "
"; + } + } + } + } + } + + if ($return) { + return $output; + } + + return $imagereturn; +} + +?> diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html index 5cdda4b525..98c9f829d3 100644 --- a/mod/glossary/mod.html +++ b/mod/glossary/mod.html @@ -12,21 +12,21 @@ - + @@ -38,69 +38,140 @@ echo "selected"; } ?> - > + > +course); +if (!$mainglossary or $mainglossary->id == $form->instance ) { +?> + + + + +"; +} +?> + + + + -course); -if (!$mainglossary or $mainglossary->id == $form->instance ) { -?> - + + + + + -"; -} -?>
@@ -46,6 +46,21 @@ ?>

+ + + + + + +

:
(

+ + + +
+

"> diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php index 98d2ee6d95..969e7c9c84 100644 --- a/mod/glossary/edit.php +++ b/mod/glossary/edit.php @@ -1,139 +1,159 @@ 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", - "wwwroot/course/view.php?id=$course->id\">$course->shortname -> - id\">$strglossaries -> - id\">$glossary->name -> $stredit", "theform.text", - "", true, "", navmenu($course, $cm)); +print_header("$course->shortname: $glossary->name", "$course->fullname", + "wwwroot/course/view.php?id=$course->id\">$course->shortname -> + id\">$strglossaries -> + id\">$glossary->name -> $stredit", "theform.text", + "", true, "", navmenu($course, $cm)); - echo "

\n"; +echo "
\n"; - print_simple_box( text_to_html($glossary->name) , "center"); +print_simple_box( text_to_html($glossary->name) , "center"); - echo "
"; +echo "
"; - include("edit.html"); +include("edit.html"); - print_footer($course); +print_footer($course); ?> diff --git a/mod/glossary/exportentry.php b/mod/glossary/exportentry.php index 6a5ea264f8..32b8ea1c64 100644 --- a/mod/glossary/exportentry.php +++ b/mod/glossary/exportentry.php @@ -1,10 +1,11 @@ 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 "

$entryexported

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

$entryexported

"; + if ($newentry->attachment) { + $entry->course = $cm->course; + $newentry->course = $cm->course; + if ( !glossary_copy_attachments($entry, $newentry) ) { + echo "

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(); -?> \ No newline at end of file +?> diff --git a/mod/glossary/formats/1.php b/mod/glossary/formats/1.php new file mode 100644 index 0000000000..8661d2f315 --- /dev/null +++ b/mod/glossary/formats/1.php @@ -0,0 +1,48 @@ +timemarked < $entry->modified) { + $colour = $THEME->cellheading2; +// } else { +// $colour = $THEME->cellheading; +// } + echo "
"; + + echo "\n"; + + echo "\n"; + echo ""; + + echo "\n"; + + echo "
"; + if ($entry->attachment) { + $entry->course = $course->id; + echo "
"; + echo glossary_print_attachments($entry, "html"); + echo "
"; + } + echo "$entry->concept
"; + if ($entry) { + echo "  ".get_string("lastedited").": ".userdate($entry->timemodified).""; + } + echo "
cellcontent\">"; + if ($entry) { + echo format_text($entry->definition, $entry->format); + + glossary_print_entry_icons($course, $cm, $glossary, $entry); + + } else { + echo "
"; + print_string("noentry", "glossary"); + echo "
"; + } + echo "
\n"; + + echo "
"; + +} + +?> diff --git a/mod/glossary/formats/2.php b/mod/glossary/formats/2.php new file mode 100644 index 0000000000..618b3459f1 --- /dev/null +++ b/mod/glossary/formats/2.php @@ -0,0 +1,57 @@ +timemarked < $entry->modified) { + $colour = $THEME->cellheading2; +// } else { +// $colour = $THEME->cellheading; +// } + + $user = get_record("user", "id", $entry->userid); + $strby = get_string("writtenby","glossary"); + + echo "
"; + + echo "\n"; + + echo "\n"; + echo "\n"; + echo ""; + + echo "\n"; + + echo "
"; + if ($entry) { + print_user_picture($user->id, $course->id, $user->picture); + } + echo "cellheading\">"; + if ($entry->attachment) { + $entry->course = $glossary->course; + echo "
"; + echo glossary_print_attachments($entry, "html"); + echo "
"; + } + if ($entry) { + echo "$entry->concept
$strby $user->firstname $user->lastname"; + echo "  (".get_string("lastedited").": ".userdate($entry->timemodified).")"; + } + echo "
cellcontent\">"; + if ($entry) { + echo format_text($entry->definition, $entry->format); + + glossary_print_entry_icons($course, $cm, $glossary, $entry); + + } else { + echo "
"; + print_string("noentry", "glossary"); + echo "
"; + } + echo "
\n"; + + echo "
"; +} + +?> diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index b86611b8c5..3245838a37 100644 --- a/mod/glossary/lib.php +++ b/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,14 +86,12 @@ function glossary_print_recent_activity($course, $isteacher, $timestart) { return false; } - echo "

ANTES

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

ADENTRO => ANTES

"; //Only if the mod is visible if ($modvisible) { @@ -103,11 +99,8 @@ function glossary_print_recent_activity($course, $isteacher, $timestart) { $entries[$log->info]->time = $log->time; $entries[$log->info]->url = $log->url; } - echo "

ADENTRO => DESPUES

"; } - echo "

DESPUES

"; - $content = false; if ($entries) { $strftimerecent = get_string("strftimerecent"); @@ -169,108 +162,44 @@ function glossary_get_entries($glossaryid, $entrylist) { } function glossary_print_entry($course, $cm, $glossary, $entry) { - switch ( $glossary->displayformat ) { - case 0: - echo "
"; - glossary_print_entry_with_user($course, $cm, $glossary, $entry); - echo "
"; - break; - case 1: - echo "
"; - glossary_print_entry_without_user($course, $cm, $glossary, $entry); - echo "
"; - break; - case 2: -// echo "
"; - glossary_print_short_entries($course, $cm, $glossary, $entry); -// echo "
"; - break; - } -} -function glossary_print_entry_with_user($course, $cm, $glossary, $entry) { - global $THEME, $USER; - -// if ($entry->timemarked < $entry->modified) { - $colour = $THEME->cellheading2; -// } else { -// $colour = $THEME->cellheading; -// } - - $user = get_record("user", "id", $entry->userid); - $strby = get_string("writtenby","glossary"); - - echo "\n"; - - echo "\n"; - echo "\n"; - echo ""; - - echo "\n"; - - echo "
cellheading\" WIDTH=35 VALIGN=TOP>"; - if ($entry) { - print_user_picture($user->id, $course->id, $user->picture); - } - echo ""; - if ($entry) { - echo "$entry->concept
$strby $user->firstname $user->lastname"; - echo "  (".get_string("lastedited").": ".userdate($entry->timemodified).")"; - } - echo "
cellcontent\">"; - if ($entry) { - echo format_text($entry->definition, $entry->format); - - glossary_print_entry_icons($course, $cm, $glossary, $entry); - + 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 "
"; - print_string("noentry", "glossary"); - echo "
"; - } - echo "
\n"; -} - -function glossary_print_entry_without_user($course, $cm, $glossary, $entry) { - global $THEME, $USER; - -// if ($entry->timemarked < $entry->modified) { - $colour = $THEME->cellheading2; -// } else { -// $colour = $THEME->cellheading; -// } - - echo "\n"; - - echo "\n"; - echo ""; - - echo "\n"; - echo "
$entry->concept
"; - if ($entry) { - echo "  ".get_string("lastedited").": ".userdate($entry->timemodified).""; + $PermissionGranted = 1; } - echo "
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 "
"; - print_string("noentry", "glossary"); - echo "
"; + glossary_print_entry_by_default($course, $cm, $glossary, $entry); } - echo "
\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
$entry->concept: "; + echo ""; + if ($entry->attachment) { + $entry->course = $course->id; + echo "
"; + echo glossary_print_attachments($entry,"html"); + echo "
"; + } + echo "$entry->concept: "; echo format_text($entry->definition, $entry->format); glossary_print_entry_icons($course, $cm, $glossary, $entry); echo "

:

:

+

:

+ +

:

+

:

+ + ?>> + +

:

:

- + ?> + > - + +

:

+
diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php index 73d6ea83c6..dc8003774d 100644 --- a/mod/glossary/restorelib.php +++ b/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 @@ $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 @@ $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 @@ return $status; } -?> \ No newline at end of file + //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; + } + +?> diff --git a/mod/glossary/version.php b/mod/glossary/version.php index 262d1d662a..26836b06be 100644 --- a/mod/glossary/version.php +++ b/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 ?> diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 893df7ca5b..d2b864a27d 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -89,25 +89,27 @@
wwwroot/mod/glossary/view.php?id=$id&l=SPECIAL\">$strspecial | "; - - $middle = (int) ( (ord("Z") - ord("A")) / 2) ; - for ($i = ord("A"); $i <= ord("Z"); $i++) { - echo "wwwroot/mod/glossary/view.php?id=$id&l=" . chr($i) . "\">" . chr($i) . ""; - if ( $i - ord("A") - 1 != $middle ) { - echo " | "; - } else { - echo "
"; - } - - if ($i == ord("N") ) { - echo "wwwroot/mod/glossary/view.php?id=$id&l=Ñ\">Ñ | "; - } - + if ( $glossary->showspecial ) { + echo "

wwwroot/mod/glossary/view.php?id=$id&l=SPECIAL\">$strspecial | "; } - echo "wwwroot/mod/glossary/view.php?id=$id&l=ALL\">$strallentries

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

"; + } + if (isteacher($course->id) or $glossary->studentcanpost) { $options = array ("id" => "$cm->id"); echo "
"; @@ -151,7 +153,7 @@ if ( $CurrentLetter != $FirstLetter ) { $CurrentLetter = $FirstLetter; - if ( $glossary->displayformat == 2 ) { + if ( $glossary->displayformat == 0 ) { if ( $DumpedDefinitions != 1) { echo "

"; } @@ -159,7 +161,7 @@ } echo $CurrentLetter; - if ( $glossary->displayformat == 2 ) { + if ( $glossary->displayformat == 0 ) { echo "\n"; if ( $DumpedDefinitions != 1) { echo "\n

"; @@ -181,7 +183,7 @@ $definition = $entry->definition; if ( $DumpedDefinitions == 1 ) { - if ( $glossary->displayformat == 2 ) { + if ( $glossary->displayformat == 0 ) { echo "\n
"; } } @@ -191,7 +193,7 @@ } glossary_print_entry($course, $cm, $glossary, $entry); - if ( $glossary->displayformat != 2 ) { + if ( $glossary->displayformat != 0 ) { echo "

"; } } @@ -208,7 +210,7 @@ } print_simple_box_end(); } else { - if ( $glossary->displayformat == 2 ) { + if ( $glossary->displayformat == 0 ) { echo "\n

"; } } @@ -216,4 +218,4 @@ /// Finish the page print_footer($course); -?> \ No newline at end of file +?> -- 2.39.5