diff --git a/lang/en/glossary.php b/lang/en/glossary.php
index 8bf6356ed14..3f3b9ebc39a 100644
--- a/lang/en/glossary.php
+++ b/lang/en/glossary.php
@@ -58,10 +58,12 @@ $string['explainspecial'] = "Shows entries that do not begin with a letter";
$string['explainalphabet'] = "Browse the glossary using this index";
$string['explainall'] = "Shows ALL entries on one page";
$string['exportedentry'] = "Exported entry";
+$string['exportglossary'] = "Export glossary";
$string['exporttomainglossary'] = "Export to main glossary";
$string['fillfields'] = "Concept and definition are mandatory fields.";
$string['fullmatch'] = "Match whole words only
(when automatically linked)";
$string['glossarytype'] = "Glossary Type";
+$string['glosssaryexported'] = "Glossary exported.";
$string['isglobal'] = "Is this glossary global?";
$string['mainglossary'] = "Main glossary";
$string['modulename'] = "Glossary";
@@ -73,6 +75,7 @@ $string['nocomment'] = "No comment found";
$string['nocomments'] = "(No comments found on this entry)";
$string['noentries'] = "No entries found in this section";
$string['noentry'] = "No entry found.";
+$string['printerfriendly'] = "Printer-friendly version";
$string['question'] = "Question";
$string['searchindefinition'] = "Search full text";
$string['secondaryglossary'] = "Secondary glossary";
diff --git a/mod/glossary/TODO.txt b/mod/glossary/TODO.txt
new file mode 100644
index 00000000000..321d027b137
--- /dev/null
+++ b/mod/glossary/TODO.txt
@@ -0,0 +1,15 @@
+Things that are in the inkpot yet:
+==================================
+
+
+- Allow to export/import entries (Working on it)
+ IMPORTING OPTIONS:
+ * New glossary o just append entries to the current one?
+ * With or withot categories?
+- Add Alias to concepts in order to use dynalinks on them.
+- Allow to set default values for glossaries and entries settings
+- Allow grading of entries
+ * Evaluation
+ * Self-evaluation?
+ * Co-evaluation?
+- Add printer friendly version of glossaries (Working on it)
diff --git a/mod/glossary/approve.php b/mod/glossary/approve.php
index 5254bb70f21..711d55145f9 100644
--- a/mod/glossary/approve.php
+++ b/mod/glossary/approve.php
@@ -33,6 +33,6 @@
} else {
add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid");
}
- redirect("view.php?id=$cm->id&tab=$tab&l=ALL",get_string("entryapproved","glossary"),1);
+ redirect("view.php?id=$cm->id&tab=$tab&l=$l",get_string("entryapproved","glossary"),1);
die;
?>
\ No newline at end of file
diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php
index c49d82de89e..059c8c8df63 100644
--- a/mod/glossary/edit.php
+++ b/mod/glossary/edit.php
@@ -196,6 +196,7 @@ print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullna
print_heading($glossary->name);
+
include("edit.html");
print_footer($course);
diff --git a/mod/glossary/editcategories.php b/mod/glossary/editcategories.php
index 1c50206d983..87d0e49d2d4 100644
--- a/mod/glossary/editcategories.php
+++ b/mod/glossary/editcategories.php
@@ -42,7 +42,7 @@
$strglossary = get_string("modulename", "glossary");
print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
- "$navigation id>$strglossaries -> id¤tview=categories>$glossary->name -> " . get_string("categories","glossary"),
+ "$navigation id>$strglossaries -> id&tab=GLOSSARY_CATEGORY_VIEW>$glossary->name -> " . get_string("categories","glossary"),
"", "", true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
diff --git a/mod/glossary/export.php b/mod/glossary/export.php
new file mode 100644
index 00000000000..d079f31bec9
--- /dev/null
+++ b/mod/glossary/export.php
@@ -0,0 +1,31 @@
+course)) {
+ error("Course is misconfigured");
+ }
+
+ if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+ error("Course module is incorrect");
+ }
+
+ require_login($course->id);
+ if (!isteacher($course->id)) {
+ error("You must be a teacher to use this page.");
+ }
+
+ glossary_generate_export_file($glossary);
+ redirect("view.php?id=$cm->id&tab=$tab&l=$l",get_string("glosssaryexported","glossary"),1);
+ die;
+?>
\ No newline at end of file
diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php
index 3c34c2b8dfd..86a233046ba 100644
--- a/mod/glossary/lib.php
+++ b/mod/glossary/lib.php
@@ -293,7 +293,7 @@ function glossary_print_entry_definition($entry) {
echo format_text($definition, $entry->format);
}
-function glossary_print_entry_attachment($entry,$format,$align) {
+function glossary_print_entry_attachment($entry,$format=NULL,$align="right") {
/// valid format values: html : Return the HTML link for the attachment as an icon
/// text : Return the HTML link for tha attachment as text
/// blank : Print the output to the screen
@@ -366,7 +366,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat
}
echo "";
if ( $glossary->allowcomments and !isguest()) {
- echo " id&eid=$entry->id\">
";
+ echo " id&eid=$entry->id\">
";
}
if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
@@ -375,7 +375,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat
$mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry
- echo " id&entry=$entry->id&tab=$tab&cat=$cat\"> ";
+ echo " id&entry=$entry->id&tab=$tab&cat=$cat\">
";
}
}
@@ -388,11 +388,11 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat
// Exported entries can be updated/deleted only by teachers in the main glossary
if ( !$importedentry and ($isteacher or !$ismainglossary) ) {
- echo " id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\">id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\">
";
- echo " id&e=$entry->id&tab=$tab&cat=$cat\">
";
+ echo " id&e=$entry->id&tab=$tab&cat=$cat\">
";
} elseif ( $importedentry ) {
echo " " . get_string("exportedentry","glossary") . "";
}
@@ -1066,4 +1066,160 @@ function glossary_print_dynaentry($courseid, $entries) {
echo "";
echo "";
}
-?>
+
+function glossary_generate_export_file($glossary) {
+global $CFG;
+ glossary_check_moddata_dir($glossary);
+ $h = glossary_open_xml($glossary);
+
+ $status = fwrite ($h,glossary_start_tag("INFO",1,true));
+ fwrite ($h,glossary_full_tag("NAME",2,false,$glossary->name));
+ fwrite ($h,glossary_full_tag("INTRO",2,false,$glossary->intro));
+ fwrite ($h,glossary_full_tag("STUDENTCANPOST",2,false,$glossary->studentcanpost));
+ fwrite ($h,glossary_full_tag("ALLOWDUPLICATEDENTRIES",2,false,$glossary->allowduplicatedentries));
+ fwrite ($h,glossary_full_tag("SHOWSPECIAL",2,false,$glossary->showspecial));
+ fwrite ($h,glossary_full_tag("SHOWALPHABET",2,false,$glossary->showalphabet));
+ fwrite ($h,glossary_full_tag("SHOWALL",2,false,$glossary->showall));
+ fwrite ($h,glossary_full_tag("ALLOWCOMMENTS",2,false,$glossary->allowcomments));
+ fwrite ($h,glossary_full_tag("USEDYNALINK",2,false,$glossary->usedynalink));
+ fwrite ($h,glossary_full_tag("DEFAULTAPPROVAL",2,false,$glossary->defaultapproval));
+ fwrite ($h,glossary_full_tag("GLOBALGLOSSARY",2,false,$glossary->globalglossary));
+ $status =fwrite ($h,glossary_end_tag("INFO",1,true));
+
+ if ( $entries = get_records("glossary_entries","glossaryid",$glossary->id) ) {
+ $status = fwrite ($h,glossary_start_tag("ENTRIES",1,true));
+ foreach ($entries as $entry) {
+ if ( $entry->approved ) {
+ $status = fwrite($h,glossary_start_tag("ENTRY",2,true));
+ fwrite($h,glossary_full_tag("ID",3,false,$entry->id));
+ fwrite($h,glossary_full_tag("CONCEPT",3,false,$entry->concept));
+ fwrite($h,glossary_full_tag("DEFINITION",3,false,$entry->definition));
+ fwrite($h,glossary_full_tag("FORMAT",3,false,$entry->format));
+ fwrite($h,glossary_full_tag("ATTACHMENT",3,false,$entry->attachment));
+ fwrite($h,glossary_full_tag("USEDYNALINK",3,false,$entry->usedynalink));
+ fwrite($h,glossary_full_tag("CASESENSITIVE",3,false,$entry->casesensitive));
+ fwrite($h,glossary_full_tag("FULLMATCH",3,false,$entry->fullmatch));
+ $status =fwrite($h,glossary_end_tag("ENTRY",2,true));
+ }
+ }
+ $status =fwrite ($h,glossary_end_tag("ENTRIES",1,true));
+ }
+
+ if ( $categories = get_records("glossary_categories","glossaryid",$glossary->id) ) {
+ $status = fwrite ($h,glossary_start_tag("CATEGORIES",1,true));
+ foreach ($categories as $category) {
+ $status = fwrite ($h,glossary_start_tag("CATEGORY",2,true));
+ fwrite($h,glossary_full_tag("NAME",3,false,$category->name));
+ if ( $catentries = get_records("glossary_entries_categories","categoryid",$category->id) ) {
+ $count = 0;
+ foreach ($catentries as $catentry) {
+ fwrite($h,glossary_full_tag("ENTRYID$count",3,false,$catentry->entryid));
+ $count++;
+ }
+ }
+ $status = fwrite($h,glossary_end_tag("CATEGORY",2,true));
+ }
+ $status = fwrite($h,glossary_end_tag("CATEGORIES",1,true));
+ }
+ $h = glossary_close_xml($h);
+}
+// Functions designed by Eloy Lafuente
+//
+//Function to create, open and write header of the xml file
+function glossary_open_xml($glossary) {
+
+ global $CFG;
+
+ $status = true;
+
+ //Open for writing
+
+ $file = $CFG->dataroot."/$glossary->course/glossary/". clean_filename($glossary->name) ."/glossary.xml";
+ $h = fopen($file,"w");
+ //Writes the header
+ $status = fwrite ($h,"\n");
+ if ($status) {
+ $status = fwrite ($h,glossary_start_tag("GLOSSARY",0,true));
+ }
+ if ($status) {
+ return $h;
+ } else {
+ return false;
+ }
+}
+
+//Close the file
+function glossary_close_xml($h) {
+ $status = fwrite ($h,glossary_end_tag("GLOSSARY",0,true));
+ return fclose($h);
+}
+
+//Return the xml start tag
+function glossary_start_tag($tag,$level=0,$endline=false) {
+ if ($endline) {
+ $endchar = "\n";
+ } else {
+ $endchar = "";
+ }
+ return str_repeat(" ",$level*2)."<".strtoupper($tag).">".$endchar;
+}
+
+//Return the xml end tag
+function glossary_end_tag($tag,$level=0,$endline=true) {
+ if ($endline) {
+ $endchar = "\n";
+ } else {
+ $endchar = "";
+ }
+ return str_repeat(" ",$level*2)."".strtoupper($tag).">".$endchar;
+}
+
+//Return the start tag, the contents and the end tag
+function glossary_full_tag($tag,$level=0,$endline=true,$content,$to_utf=true) {
+ $st = glossary_start_tag($tag,$level,$endline);
+ $co="";
+ if ($to_utf) {
+ $co = preg_replace("/\r\n|\r/", "\n", utf8_encode(htmlspecialchars($content)));
+ } else {
+ $co = preg_replace("/\r\n|\r/", "\n", htmlspecialchars($content));
+ }
+ $et = glossary_end_tag($tag,0,true);
+ return $st.$co.$et;
+}
+
+ //Function to check and create the needed moddata dir to
+ //save all the mod backup files. We always name it moddata
+ //to be able to restore it, but in restore we check for
+ //$CFG->moddata !!
+function glossary_check_moddata_dir($glossary) {
+
+ global $CFG;
+
+ $status = glossary_check_dir_exists($CFG->dataroot."/$glossary->course",true);
+ if ( $status ) {
+ $status = glossary_check_dir_exists($CFG->dataroot."/$glossary->course/glossary",true);
+ if ( $status ) {
+ $status = glossary_check_dir_exists($CFG->dataroot."/$glossary->course/glossary/". clean_filename($glossary->name),true);
+ }
+ }
+ return $status;
+}
+
+//Function to check if a directory exists
+//and, optionally, create it
+function glossary_check_dir_exists($dir,$create=false) {
+
+ global $CFG;
+
+ $status = true;
+ if(!is_dir($dir)) {
+ if (!$create) {
+ $status = false;
+ } else {
+ umask(0000);
+ $status = mkdir ($dir,$CFG->directorypermissions);
+ }
+ }
+ return $status;
+}
+?>
\ No newline at end of file
diff --git a/mod/glossary/print.gif b/mod/glossary/print.gif
new file mode 100644
index 00000000000..9180ca1060f
Binary files /dev/null and b/mod/glossary/print.gif differ
diff --git a/mod/glossary/print.php b/mod/glossary/print.php
new file mode 100644
index 00000000000..96894a8cef9
--- /dev/null
+++ b/mod/glossary/print.php
@@ -0,0 +1,136 @@
+course)) {
+ error("Course is misconfigured");
+ }
+
+ if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+ error("Course module is incorrect");
+ }
+
+ require_login($course->id);
+ if (isguest()) {
+ error("You must be logged to use this page.");
+ }
+
+/// Generating the SQL based on the format to show
+ switch ($tab) {
+ case GLOSSARY_CATEGORY_VIEW:
+ $entries = get_records_sql("SELECT c.name pivot, e.*
+ FROM {$CFG->prefix}glossary_entries e,
+ {$CFG->prefix}glossary_entries_categories ec,
+ {$CFG->prefix}glossary_categories as c
+ WHERE e.id = ec.entryid AND ec.categoryid = c.id AND
+ (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id)
+ AND e.approved != 0
+ ORDER BY c.name, e.concept");
+
+ break;
+
+ case GLOSSARY_DATE_VIEW:
+ //// Valid sorting values
+ switch ($sortkey) {
+ case 'CREATION':
+ $sortkey = 'timecreated';
+ break;
+
+ case 'UPDATE':
+ default:
+ $sortkey = 'timemodified';
+ break;
+ }
+ if ($sortorder != 'asc' and $sortorder != 'desc') {
+ $sortorder = 'asc';
+ }
+
+ $entries = get_records_sql("SELECT e.timemodified pivot, e.*
+ FROM {$CFG->prefix}glossary_entries e
+ WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id)
+ AND e.approved != 0
+ ORDER BY e.$sortkey $sortorder");
+
+ break;
+ case GLOSSARY_STANDARD_VIEW:
+ default:
+ switch ($CFG->dbtype) {
+ case "postgres7":
+ $pivot = "substring(e.concept, 1,1)";
+ break;
+
+ case "mysql":
+ $pivot = "left(e.concept,1)";
+ break;
+ default:
+ $pivot = "e.concept";
+ break;
+ }
+
+ $entries = get_records_sql("SELECT $pivot pivot, e.*
+ FROM {$CFG->prefix}glossary_entries e
+ WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id)
+ AND e.approved != 0
+ ORDER BY e.concept $sortorder");
+ break;
+ }
+
+
+ echo '
' . get_string("course") . ': ' . $course->fullname . '
';
+ echo get_string("modulename","glossary") . ': ' . $glossary->name . '
' . $groupheader . '
'; + } + } + if ( !$tableisopen ) { + echo '| '. $entry->concept . ': | '; + echo '';
+
+ if ( $entry->attachment) {
+ glossary_print_entry_attachment($entry);
+ }
+
+ echo format_text(" |
' . stripslashes_safe($glossary->name);
+ echo ' ';
+ echo '
';
+ echo '
'; print_single_button("edit.php", $options, $straddentry); echo '
'; + +/* + unset($options); + $options = array ("id" => "$cm->id"); + echo '
'; + print_single_button("export.php", $options, get_string("exportglossary","glossary")); + echo '