Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Printer-friendly version of the glossary

- First step in the export/import feature (export is done)
- Minor changes here and there
  • Loading branch information...
commit 4f4ca7b5e16cf221d2b9cc5b87972e1af05629c5 1 parent ec48239
willcast authored
3  lang/en/glossary.php
View
@@ -58,10 +58,12 @@
$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<br><small>(when automatically linked)</small>";
$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['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";
15 mod/glossary/TODO.txt
View
@@ -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)
2  mod/glossary/approve.php
View
@@ -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;
?>
1  mod/glossary/edit.php
View
@@ -196,6 +196,7 @@
print_heading($glossary->name);
+
include("edit.html");
print_footer($course);
2  mod/glossary/editcategories.php
View
@@ -42,7 +42,7 @@
$strglossary = get_string("modulename", "glossary");
print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
- "$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> <A HREF=view.php?id=$cm->id&currentview=categories>$glossary->name</a> -> " . get_string("categories","glossary"),
+ "$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> <A HREF=view.php?id=$cm->id&tab=GLOSSARY_CATEGORY_VIEW>$glossary->name</a> -> " . get_string("categories","glossary"),
"", "", true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
31 mod/glossary/export.php
View
@@ -0,0 +1,31 @@
+<?php
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ require_variable($id); // Course Module ID
+
+ optional_variable($tab,GLOSSARY_APPROVAL_VIEW);
+ optional_variable($l,"ALL");
+
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("Course Module ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $cm->course)) {
+ error("Course is misconfigured");
+ }
+
+ if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+ error("Course module is incorrect");
+ }
+
+ require_login($course->id);
+ 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;
+?>
168 mod/glossary/lib.php
View
@@ -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 "</font>";
if ( $glossary->allowcomments and !isguest()) {
- echo " <a href=\"comment.php?id=$cm->id&eid=$entry->id\"><img alt=\"" . get_string("addcomment","glossary") . "\" src=\"comment.gif\" height=16 width=16 border=0></a> ";
+ echo " <a title=\"" . get_string("addcomment","glossary") . "\" href=\"comment.php?id=$cm->id&eid=$entry->id\"><img src=\"comment.gif\" height=16 width=16 border=0></a> ";
}
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 " <a href=\"exportentry.php?id=$cm->id&entry=$entry->id&tab=$tab&cat=$cat\"><img alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
+ echo " <a title=\"" . get_string("exporttomainglossary","glossary") . "\" href=\"exportentry.php?id=$cm->id&entry=$entry->id&tab=$tab&cat=$cat\"><img src=\"export.gif\" height=11 width=11 border=0></a> ";
}
}
@@ -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 " <a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\"><img alt=\"" . get_string("delete") . "\"src=\"";
+ echo " <a title=\"" . get_string("delete") . "\" href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\"><img src=\"";
echo $icon;
echo "\" height=11 width=11 border=0></a> ";
- echo " <a href=\"edit.php?id=$cm->id&e=$entry->id&tab=$tab&cat=$cat\"><img alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
+ echo " <a title=\"" . get_string("edit") . "\" href=\"edit.php?id=$cm->id&e=$entry->id&tab=$tab&cat=$cat\"><img src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
} elseif ( $importedentry ) {
echo " <font size=-1>" . get_string("exportedentry","glossary") . "</font>";
}
@@ -1066,4 +1066,160 @@ function glossary_print_dynaentry($courseid, $entries) {
echo "</td>";
echo "</tr></table></center>";
}
-?>
+
+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,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\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;
+}
+?>
BIN  mod/glossary/print.gif
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 mod/glossary/print.php
View
@@ -0,0 +1,136 @@
+<?php
+
+ require_once("../../config.php");
+ require_once("lib.php");
+ global $CFG;
+
+ require_variable($id); // Course Module ID
+ require_variable($tab,GLOSSARY_STANDARD_VIEW); // format to show the entries
+ optional_variable($sortkey,"UPDATE"); // Sorting key if TAB = GLOSSARY_DATE_VIEW
+ optional_variable($sortorder,"asc"); // Sorting order if TAB = GLOSSARY_DATE_VIEW
+
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("Course Module ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $cm->course)) {
+ error("Course is misconfigured");
+ }
+
+ if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+ error("Course module is incorrect");
+ }
+
+ require_login($course->id);
+ 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 '<p><STRONG>' . get_string("course") . ': <i>' . $course->fullname . '</i><br />';
+ echo get_string("modulename","glossary") . ': <i>' . $glossary->name . '</i></STRONG></p>';
+
+ $groupheader = '';
+ $tableisopen = 0;
+ foreach ($entries as $entry) {
+ $pivot = $entry->pivot;
+ if ( $CFG->dbtype != "postgres7" and $CFG->dbtype != "mysql" and $tab != GLOSSARY_CATEGORY_VIEW) {
+ $pivot = $pivot[0];
+ }
+
+ if ($tab != GLOSSARY_DATE_VIEW) {
+ if ($groupheader != $pivot) {
+ /// Printing th eheader of the group
+
+ if ($tableisopen) {
+ echo '</table>';
+ echo '</center>';
+ $tableisopen = 0;
+ }
+ $groupheader = $pivot;
+ echo '<p align="center"><STRONG><font size="4" color="#0000FF">' . $groupheader . '</font></STRONG></p>';
+ }
+ }
+ if ( !$tableisopen ) {
+ echo '<center>';
+ echo '<table border="1" cellpadding="5" cellspacing="0" width="95%">';
+ $tableisopen = 1;
+ }
+
+ echo '<tr>';
+ echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>';
+ echo '<td width="75%">';
+
+ if ( $entry->attachment) {
+ glossary_print_entry_attachment($entry);
+ }
+
+ echo format_text("<nolink>$entry->definition</nolink>",$entry->format);
+
+ echo '</tr>';
+ }
+ if ($tableisopen) {
+ echo '</table>';
+ echo '</center>';
+ }
+?>
21 mod/glossary/view.php
View
@@ -134,9 +134,11 @@
"", "", true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
- print_heading($glossary->name);
-
-
+ echo '<p align="center"><font size="3"><b>' . stripslashes_safe($glossary->name);
+ echo ' <a title ="' . get_string("printerfriendly","glossary") . '" target="_blank" href="print.php?id=' . $cm->id . '&tab=' . $tab . '&sortkey=' . $sortkey . '&sortorder=' . $sortorder . '">';
+ echo '<img border=0 src="print.gif"/></a>';
+ echo '</b></font></p>';
+
/// Info box
if ( $glossary->intro ) {
@@ -145,16 +147,25 @@
print_simple_box_end();
}
-/// Add button
+/// Add buttons
+
if (!isguest()) {
if ( isteacher($course->id) or $glossary->studentcanpost ) {
+ unset($options);
$options = array ("id" => "$cm->id");
echo '<center><p>';
print_single_button("edit.php", $options, $straddentry);
echo '</p></center>';
}
}
- echo '<p>';
+
+/*
+ unset($options);
+ $options = array ("id" => "$cm->id");
+ echo '<center><p>';
+ print_single_button("export.php", $options, get_string("exportglossary","glossary"));
+ echo '</p></center>';
+*/
/// Search box
Please sign in to comment.
Something went wrong with that request. Please try again.