2003-09-16 03:07:21 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
/// Library of functions and constants for module glossary
|
|
|
|
/// (replace glossary with the name of your module and delete this line)
|
|
|
|
|
2003-09-16 18:51:40 +00:00
|
|
|
require_once("$CFG->dirroot/files/mimetypes.php");
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
define("GLOSSARY_SHOW_ALL_CATEGORIES", 0);
|
|
|
|
define("GLOSSARY_SHOW_NOT_CATEGORISED", -1);
|
2003-10-21 04:55:22 +00:00
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
define("GLOSSARY_STANDARD_VIEW", 0);
|
|
|
|
define("GLOSSARY_CATEGORY_VIEW", 1);
|
2003-10-22 04:15:08 +00:00
|
|
|
define("GLOSSARY_DATE_VIEW", 2);
|
2003-11-03 02:26:44 +00:00
|
|
|
define("GLOSSARY_ADDENTRY_VIEW", 3);
|
|
|
|
define("GLOSSARY_IMPORT_VIEW", 4);
|
|
|
|
define("GLOSSARY_EXPORT_VIEW", 5);
|
|
|
|
define("GLOSSARY_APPROVAL_VIEW", 6);
|
2003-09-21 17:08:41 +00:00
|
|
|
|
2003-10-19 03:40:36 +00:00
|
|
|
define("GLOSSARY_FORMAT_SIMPLE", 0);
|
|
|
|
define("GLOSSARY_FORMAT_CONTINUOUS", 1);
|
|
|
|
|
2003-09-16 03:07:21 +00:00
|
|
|
function glossary_add_instance($glossary) {
|
|
|
|
/// Given an object containing all the necessary data,
|
|
|
|
/// (defined by the form in mod.html) this function
|
|
|
|
/// will create a new instance and return the id number
|
|
|
|
/// of the new instance.
|
|
|
|
|
2003-10-29 23:33:54 +00:00
|
|
|
if ( !isset($glossary->globalglossary) ) {
|
|
|
|
$glossary->globalglossary = 0;
|
|
|
|
} elseif ( !isadmin() ) {
|
|
|
|
$glossary->globalglossary = 0;
|
|
|
|
}
|
|
|
|
|
2003-09-16 03:07:21 +00:00
|
|
|
$glossary->timecreated = time();
|
|
|
|
$glossary->timemodified = $glossary->timecreated;
|
|
|
|
|
|
|
|
# May have to add extra stuff in here #
|
|
|
|
|
|
|
|
return insert_record("glossary", $glossary);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function glossary_update_instance($glossary) {
|
|
|
|
/// Given an object containing all the necessary data,
|
|
|
|
/// (defined by the form in mod.html) this function
|
|
|
|
/// will update an existing instance with new data.
|
2003-10-31 13:40:34 +00:00
|
|
|
global $CFG;
|
2003-10-29 23:33:54 +00:00
|
|
|
if ( !isadmin() ) {
|
|
|
|
unset($glossary->globalglossary);
|
|
|
|
}
|
|
|
|
|
2003-09-16 03:07:21 +00:00
|
|
|
$glossary->timemodified = time();
|
|
|
|
$glossary->id = $glossary->instance;
|
|
|
|
|
2003-10-31 13:40:34 +00:00
|
|
|
$return = update_record("glossary", $glossary);
|
|
|
|
if ($return and $glossary->defaultapproval) {
|
|
|
|
execute_sql("update {$CFG->prefix}glossary_entries SET approved = 1 where approved != 1 and glossaryid = " . $glossary->id,false);
|
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2003-10-31 13:40:34 +00:00
|
|
|
return $return;
|
2003-09-16 03:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function glossary_delete_instance($id) {
|
|
|
|
/// Given an ID of an instance of this module,
|
|
|
|
/// this function will permanently delete the instance
|
|
|
|
/// and any data that depends on it.
|
|
|
|
|
|
|
|
if (! $glossary = get_record("glossary", "id", "$id")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = true;
|
|
|
|
|
|
|
|
# Delete any dependent records here #
|
|
|
|
|
|
|
|
if (! delete_records("glossary", "id", "$glossary->id")) {
|
|
|
|
$result = false;
|
2003-10-31 15:26:28 +00:00
|
|
|
} else {
|
|
|
|
if ($categories = get_records("glossary_categories","glossaryid",$glossary->id)) {
|
|
|
|
$cats = "";
|
|
|
|
foreach ( $categories as $cat ) {
|
|
|
|
$cats .= "$cat->id,";
|
|
|
|
}
|
|
|
|
$cats = substr($cats,0,-1);
|
|
|
|
if ($cats) {
|
|
|
|
delete_records_select("glossary_entries_categories", "categoryid in ($cats)");
|
|
|
|
delete_records("glossary_categories", "glossaryid", $glossary->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $entries = get_records("glossary_entries", "glossaryid", $glossary->id) ) {
|
|
|
|
$ents = "";
|
|
|
|
foreach ( $entries as $entry ) {
|
|
|
|
$ents .= "$entry->id,";
|
|
|
|
}
|
|
|
|
$ents = substr($ents,0,-1);
|
|
|
|
if ($ents) {
|
|
|
|
delete_records_select("glossary_comments", "entryid in ($ents)");
|
2003-11-03 02:26:44 +00:00
|
|
|
delete_records_select("glossary_alias", "entryid in ($ents)");
|
2003-10-31 15:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete_records("glossary_entries", "glossaryid", "$glossary->id");
|
2003-09-16 03:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_user_outline($course, $user, $mod, $glossary) {
|
|
|
|
/// Return a small object with summary information about what a
|
|
|
|
/// user has done with a given particular instance of this module
|
|
|
|
/// Used for user activity reports.
|
|
|
|
/// $return->time = the time they did it
|
|
|
|
/// $return->info = a short text description
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_user_complete($course, $user, $mod, $glossary) {
|
|
|
|
/// Print a detailed representation of what a user has done with
|
|
|
|
/// a given particular instance of this module, for user activity reports.
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_recent_activity($course, $isteacher, $timestart) {
|
|
|
|
/// Given a course and a time, this module should find recent activity
|
|
|
|
/// that has occurred in glossary activities and print it out.
|
|
|
|
/// Return true if there was output, or false is there was none.
|
|
|
|
|
|
|
|
global $CFG, $THEME;
|
|
|
|
|
|
|
|
if (!$logs = get_records_select("log", "time > '$timestart' AND ".
|
|
|
|
"course = '$course->id' AND ".
|
|
|
|
"module = 'glossary' AND ".
|
|
|
|
"action = 'add %' ", "time ASC")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = false;
|
|
|
|
if ($entries) {
|
|
|
|
$strftimerecent = get_string("strftimerecent");
|
|
|
|
$content = true;
|
|
|
|
print_headline(get_string("newentries", "glossary").":");
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
$date = userdate($entry->timemodified, $strftimerecent);
|
|
|
|
echo "<p><font size=1>$date - $entry->firstname $entry->lastname<br>";
|
|
|
|
echo "\"<a href=\"$CFG->wwwroot/mod/glossary/$entry->url\">";
|
|
|
|
echo "$entry->concept";
|
|
|
|
echo "</a>\"</font></p>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_cron () {
|
|
|
|
/// Function to be run periodically according to the moodle cron
|
|
|
|
/// This function searches for things that need to be done, such
|
|
|
|
/// as sending out mail, toggling flags etc ...
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_grades($glossaryid) {
|
|
|
|
/// Must return an array of grades for a given instance of this module,
|
|
|
|
/// indexed by user. It also returns a maximum allowed grade.
|
|
|
|
|
|
|
|
$return->grades = NULL;
|
|
|
|
$return->maxgrade = NULL;
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2003-09-29 15:27:30 +00:00
|
|
|
function glossary_get_participants($glossaryid) {
|
|
|
|
//Returns the users with data in one glossary
|
|
|
|
//(users with records in glossary_entries, students)
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
//Get students
|
|
|
|
$students = get_records_sql("SELECT DISTINCT u.*
|
|
|
|
FROM {$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}glossary_entries g
|
|
|
|
WHERE g.glossaryid = '$glossaryid' and
|
|
|
|
u.id = g.userid");
|
|
|
|
|
|
|
|
//Return students array (it contains an array of unique users)
|
|
|
|
return ($students);
|
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Any other glossary functions go here. Each of them must have a name that
|
|
|
|
/// starts with glossary_
|
|
|
|
|
|
|
|
function glossary_log_info($log) {
|
|
|
|
global $CFG;
|
|
|
|
return get_record_sql("SELECT g.*, u.firstname, u.lastname
|
|
|
|
FROM {$CFG->prefix}glossary_entries g,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE g.glossaryid = '$log->info'
|
|
|
|
AND u.id = '$log->userid'");
|
|
|
|
}
|
|
|
|
|
2003-11-03 02:26:44 +00:00
|
|
|
function glossary_get_entries($glossaryid, $entrylist, $pivot = "") {
|
2003-09-16 03:07:21 +00:00
|
|
|
global $CFG;
|
2003-11-03 02:26:44 +00:00
|
|
|
if ($pivot) {
|
|
|
|
$pivot .= ",";
|
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2003-11-03 02:26:44 +00:00
|
|
|
return get_records_sql("SELECT $pivot id,userid,concept,definition,format
|
2003-09-16 03:07:21 +00:00
|
|
|
FROM {$CFG->prefix}glossary_entries
|
|
|
|
WHERE glossaryid = '$glossaryid'
|
|
|
|
AND id IN ($entrylist)");
|
|
|
|
}
|
2003-11-03 02:26:44 +00:00
|
|
|
function glossary_get_entries_sorted($glossary, $where="", $orderby="", $pivot = "") {
|
2003-10-21 04:55:22 +00:00
|
|
|
global $CFG;
|
|
|
|
if ($where) {
|
|
|
|
$where = " and $where";
|
|
|
|
}
|
|
|
|
if ($orderby) {
|
|
|
|
$orderby = " ORDER BY $orderby";
|
|
|
|
}
|
2003-11-03 02:26:44 +00:00
|
|
|
if ($pivot) {
|
|
|
|
$pivot .= ",";
|
|
|
|
}
|
|
|
|
return get_records_sql("SELECT $pivot *
|
2003-10-21 04:55:22 +00:00
|
|
|
FROM {$CFG->prefix}glossary_entries
|
|
|
|
WHERE (glossaryid = $glossary->id or sourceglossaryid = $glossary->id) $where $orderby");
|
|
|
|
}
|
|
|
|
|
2003-11-03 02:26:44 +00:00
|
|
|
function glossary_get_entries_by_category($glossary, $cat, $where="", $orderby="", $pivot = "") {
|
2003-10-21 04:55:22 +00:00
|
|
|
global $CFG;
|
|
|
|
if ($where) {
|
|
|
|
$where = " and $where";
|
|
|
|
}
|
|
|
|
if ($orderby) {
|
|
|
|
$orderby = " ORDER BY $orderby";
|
|
|
|
}
|
2003-11-03 02:26:44 +00:00
|
|
|
if ($pivot) {
|
|
|
|
$pivot .= ",";
|
|
|
|
}
|
|
|
|
return get_records_sql("SELECT $pivot ge.*
|
2003-10-21 04:55:22 +00:00
|
|
|
FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories c
|
|
|
|
WHERE (ge.id = c.entryid and c.categoryid = $cat) and
|
|
|
|
(ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) $where $orderby");
|
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
function glossary_print_entry($course, $cm, $glossary, $entry, $tab="",$cat="") {
|
2003-09-23 12:34:47 +00:00
|
|
|
global $THEME, $USER, $CFG;
|
2003-10-21 04:55:22 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
if ($entry->approved or ($USER->id == $entry->userid and !isteacher($course->id)) or $tab == GLOSSARY_APPROVAL_VIEW) {
|
2003-10-21 04:55:22 +00:00
|
|
|
$permissiongranted = 0;
|
|
|
|
$formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
|
|
|
|
$functionname = "glossary_print_entry_by_format";
|
|
|
|
|
|
|
|
$basicformat = ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
|
|
|
|
$glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS);
|
|
|
|
if ( !$basicformat ) {
|
|
|
|
if ( file_exists($formatfile) ) {
|
|
|
|
include_once($formatfile);
|
|
|
|
if (function_exists($functionname) ) {
|
|
|
|
$permissiongranted = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$permissiongranted = 1;
|
2003-09-16 18:51:40 +00:00
|
|
|
}
|
2003-09-18 23:53:05 +00:00
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
if ( !$basicformat and $permissiongranted ) {
|
|
|
|
glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab,$cat);
|
|
|
|
} else {
|
|
|
|
switch ( $glossary->displayformat ) {
|
|
|
|
case GLOSSARY_FORMAT_SIMPLE:
|
|
|
|
glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab,$cat);
|
|
|
|
break;
|
|
|
|
case GLOSSARY_FORMAT_CONTINUOUS:
|
|
|
|
glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab,$cat);
|
|
|
|
break;
|
|
|
|
}
|
2003-10-19 03:40:36 +00:00
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-05 12:46:51 +00:00
|
|
|
function glossary_print_entry_concept($entry) {
|
2003-11-03 02:26:44 +00:00
|
|
|
echo $entry->concept;
|
2003-11-05 12:46:51 +00:00
|
|
|
}
|
2003-10-28 16:10:36 +00:00
|
|
|
|
|
|
|
function glossary_print_entry_definition($entry) {
|
|
|
|
$definition = str_ireplace($entry->concept,"<nolink>$entry->concept</nolink>",$entry->definition);
|
|
|
|
echo format_text($definition, $entry->format);
|
|
|
|
}
|
|
|
|
|
2003-11-05 12:46:51 +00:00
|
|
|
function glossary_print_entry_aliases($course, $cm, $glossary, $entry,$tab="",$cat="", $mode = 'print') {
|
|
|
|
$return = '';
|
|
|
|
if ( $aliases = get_records("glossary_alias","entryid",$entry->id) ) {
|
|
|
|
foreach ($aliases as $alias) {
|
|
|
|
if ($alias->alias) {
|
|
|
|
if ($return == '') {
|
|
|
|
$return = '<select style="font-size:8pt">';
|
|
|
|
}
|
|
|
|
$return .= "<option>$alias->alias</option>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($return != '') {
|
|
|
|
$return .= '</select>';
|
|
|
|
// $return = "<table border=0 align=$align><tr><td>$return</td></tr></table>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($mode == 'print') {
|
|
|
|
echo $return;
|
|
|
|
} else {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat="", $mode = 'print') {
|
|
|
|
global $THEME, $USER;
|
|
|
|
|
|
|
|
$importedentry = ($entry->sourceglossaryid == $glossary->id);
|
|
|
|
$isteacher = isteacher($course->id);
|
|
|
|
$ismainglossary = $glossary->mainglossary;
|
|
|
|
|
|
|
|
$return = "<font size=1>";
|
|
|
|
|
|
|
|
if (!$entry->approved) {
|
|
|
|
$return .= get_string("entryishidden","glossary");
|
|
|
|
}
|
|
|
|
$count = count_records("glossary_comments","entryid",$entry->id);
|
|
|
|
if ($count) {
|
|
|
|
$return .= " <a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count ";
|
|
|
|
if ($count == 1) {
|
|
|
|
$return .= get_string("comment", "glossary");
|
|
|
|
} else {
|
|
|
|
$return .= get_string("comments", "glossary");
|
|
|
|
}
|
|
|
|
$return .= "</a>";
|
|
|
|
}
|
|
|
|
$return .= "</font>";
|
|
|
|
if ( $glossary->allowcomments and !isguest()) {
|
|
|
|
$return .= " <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) {
|
|
|
|
// only teachers can export entries so check it out
|
|
|
|
if ($isteacher and !$ismainglossary and !$importedentry) {
|
|
|
|
$mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
|
|
|
|
if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry
|
|
|
|
|
|
|
|
$return .= " <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> ";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $entry->sourceglossaryid ) {
|
|
|
|
$icon = "minus.gif"; // graphical metaphor (minus) for deleting an imported entry
|
|
|
|
} else {
|
|
|
|
$icon = "../../pix/t/delete.gif";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exported entries can be updated/deleted only by teachers in the main glossary
|
|
|
|
if ( !$importedentry and ($isteacher or !$ismainglossary) ) {
|
|
|
|
$return .= " <a title=\"" . get_string("delete") . "\" href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\"><img src=\"";
|
|
|
|
$return .= $icon;
|
|
|
|
$return .= "\" height=11 width=11 border=0></a> ";
|
|
|
|
|
|
|
|
$return .= " <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 ) {
|
|
|
|
$return .= " <font size=-1>" . get_string("exportedentry","glossary") . "</font>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$return .= " "; // just to make up a little the output in Mozilla ;)
|
|
|
|
if ($mode == 'print') {
|
|
|
|
echo $return;
|
|
|
|
} else {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $tab, $cat) {
|
|
|
|
|
|
|
|
$aliases = glossary_print_entry_aliases($course, $cm, $glossary, $entry, $tab, $cat,"html");
|
|
|
|
$icons = glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat,"html");
|
|
|
|
if ( $aliases ) {
|
|
|
|
echo '<table border="0" width="100%" align="center"><tr>' .
|
|
|
|
'<td align="right" width="50%" valign=top><font size=1>' .
|
|
|
|
get_string("aliases","glossary") . ': ' . $aliases . '</td>' .
|
|
|
|
'<td align=right width="50%" valign=top>'.
|
|
|
|
$icons .
|
|
|
|
'</td></tr></table>';
|
|
|
|
} else {
|
|
|
|
echo "<p align=right>$icons";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-01 20:27:21 +00:00
|
|
|
function glossary_print_entry_attachment($entry,$format=NULL,$align="right") {
|
2003-10-28 16:10:36 +00:00
|
|
|
/// 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
|
|
|
|
if ($entry->attachment) {
|
|
|
|
$glossary = get_record("glossary","id",$entry->glossaryid);
|
|
|
|
$entry->course = $glossary->course; //used inside print_attachment
|
|
|
|
echo "<table border=0 align=$align><tr><td>";
|
|
|
|
echo glossary_print_attachments($entry,$format,$align);
|
|
|
|
echo "</td></tr></table>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_entry_approval($cm, $entry, $tab) {
|
|
|
|
if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
|
|
|
|
echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
|
|
|
|
}
|
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab="",$cat="") {
|
2003-09-16 03:07:21 +00:00
|
|
|
global $THEME, $USER;
|
|
|
|
|
|
|
|
$colour = $THEME->cellheading2;
|
|
|
|
|
|
|
|
echo "\n<TR>";
|
2003-10-28 16:10:36 +00:00
|
|
|
echo "<TD WIDTH=100% class=\"generalbox\" valign=\"top\" BGCOLOR=\"#FFFFFF\">";
|
|
|
|
glossary_print_entry_approval($cm, $entry, $tab);
|
|
|
|
glossary_print_entry_attachment($entry,"html","right");
|
|
|
|
echo "<b>";
|
|
|
|
glossary_print_entry_concept($entry);
|
|
|
|
echo ":</b> ";
|
|
|
|
glossary_print_entry_definition($entry);
|
2003-11-05 12:46:51 +00:00
|
|
|
glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$tab,$cat);
|
2003-09-16 03:07:21 +00:00
|
|
|
echo "</td>";
|
|
|
|
echo "</TR>";
|
|
|
|
}
|
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab="",$cat="") {
|
2003-10-19 03:40:36 +00:00
|
|
|
global $THEME, $USER;
|
|
|
|
if ($entry) {
|
2003-10-28 16:10:36 +00:00
|
|
|
glossary_print_entry_approval($cm, $entry, $tab);
|
|
|
|
glossary_print_entry_attachment($entry,"html","right");
|
|
|
|
glossary_print_entry_concept($entry);
|
|
|
|
echo " ";
|
|
|
|
glossary_print_entry_definition($entry);
|
2003-11-05 12:46:51 +00:00
|
|
|
glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $tab, $cat);
|
2003-10-16 05:15:59 +00:00
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_search_entries($searchterms, $glossary, $includedefinition) {
|
|
|
|
/// Returns a list of entries found using an array of search terms
|
|
|
|
/// eg word +word -word
|
|
|
|
///
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (!isteacher($glossary->course)) {
|
|
|
|
$glossarymodule = get_record("modules", "name", "glossary");
|
2003-09-18 14:18:04 +00:00
|
|
|
$onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id";
|
2003-09-16 03:07:21 +00:00
|
|
|
$onlyvisibletable = ", {$CFG->prefix}course_modules cm";
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$onlyvisible = "";
|
|
|
|
$onlyvisibletable = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Some differences in syntax for PostgreSQL
|
|
|
|
if ($CFG->dbtype == "postgres7") {
|
|
|
|
$LIKE = "ILIKE"; // case-insensitive
|
|
|
|
$NOTLIKE = "NOT ILIKE"; // case-insensitive
|
|
|
|
$REGEXP = "~*";
|
|
|
|
$NOTREGEXP = "!~*";
|
|
|
|
} else {
|
|
|
|
$LIKE = "LIKE";
|
|
|
|
$NOTLIKE = "NOT LIKE";
|
|
|
|
$REGEXP = "REGEXP";
|
|
|
|
$NOTREGEXP = "NOT REGEXP";
|
|
|
|
}
|
|
|
|
|
|
|
|
$conceptsearch = "";
|
|
|
|
$definitionsearch = "";
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($searchterms as $searchterm) {
|
|
|
|
if ($conceptsearch) {
|
|
|
|
$conceptsearch.= " OR ";
|
|
|
|
}
|
|
|
|
if ($definitionsearch) {
|
|
|
|
$definitionsearch.= " OR ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (substr($searchterm,0,1) == "+") {
|
|
|
|
$searchterm = substr($searchterm,1);
|
|
|
|
$conceptsearch.= " e.concept $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
|
|
|
|
$definitionsearch .= " e.definition $REGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
|
|
|
|
} else if (substr($searchterm,0,1) == "-") {
|
|
|
|
$searchterm = substr($searchterm,1);
|
|
|
|
$conceptsearch .= " e.concept $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
|
|
|
|
$definitionsearch .= " e.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
|
|
|
|
} else {
|
|
|
|
$conceptsearch .= " e.concept $LIKE '%$searchterm%' ";
|
|
|
|
$definitionsearch .= " e.definition $LIKE '%$searchterm%' ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-16 05:15:59 +00:00
|
|
|
if ( !$includedefinition ) {
|
|
|
|
$definitionsearch = "0";
|
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
|
|
|
|
$selectsql = "{$CFG->prefix}glossary_entries e,
|
|
|
|
{$CFG->prefix}glossary g $onlyvisibletable
|
|
|
|
WHERE ($conceptsearch OR $definitionsearch)
|
2003-09-29 03:06:30 +00:00
|
|
|
AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible
|
2003-10-21 04:55:22 +00:00
|
|
|
AND g.id = $glossary->id AND e.approved != 0";
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2003-10-21 13:27:48 +00:00
|
|
|
return get_records_sql("SELECT e.*
|
|
|
|
FROM $selectsql ORDER BY e.concept ASC");
|
2003-09-16 03:07:21 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 18:51:40 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-09-30 02:17:09 +00:00
|
|
|
function glossary_print_attachments($entry, $return=NULL, $align="left") {
|
2003-09-16 18:51:40 +00:00
|
|
|
// 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
|
2003-10-01 01:35:45 +00:00
|
|
|
// if attachment is an image, $align set its aligment.
|
2003-09-16 18:51:40 +00:00
|
|
|
global $CFG;
|
2003-10-01 01:35:45 +00:00
|
|
|
|
|
|
|
$newentry = $entry;
|
|
|
|
if ( $newentry->sourceglossaryid ) {
|
|
|
|
$newentry->glossaryid = $newentry->sourceglossaryid;
|
|
|
|
}
|
2003-09-16 18:51:40 +00:00
|
|
|
|
2003-10-01 01:35:45 +00:00
|
|
|
$filearea = glossary_file_area_name($newentry);
|
2003-09-16 18:51:40 +00:00
|
|
|
|
|
|
|
$imagereturn = "";
|
|
|
|
$output = "";
|
|
|
|
|
2003-10-01 01:35:45 +00:00
|
|
|
if ($basedir = glossary_file_area($newentry)) {
|
2003-09-16 18:51:40 +00:00
|
|
|
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
|
2003-09-30 02:17:09 +00:00
|
|
|
$imagereturn .= "<br /><img src=\"$CFG->wwwroot/$ffurl\" align=$align>";
|
2003-09-16 18:51:40 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
function glossary_print_tabbed_table_start($data, $currenttab, $tTHEME = NULL) {
|
2003-09-18 23:53:05 +00:00
|
|
|
|
|
|
|
if ( !$tTHEME ) {
|
|
|
|
global $THEME;
|
|
|
|
$tTHEME = $THEME;
|
|
|
|
}
|
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
$tablecolor = $tTHEME->TabTableBGColor;
|
|
|
|
$currenttabcolor = $tTHEME->ActiveTabColor;
|
|
|
|
$tabcolor = $tTHEME->InactiveTabColor;
|
|
|
|
$inactivefontcolor = $tTHEME->InactiveFontColor;
|
2003-09-18 23:53:05 +00:00
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
$tablewidth = $tTHEME->TabTableWidth;
|
|
|
|
$tabsperrow = $tTHEME->TabsPerRow;
|
|
|
|
$tabseparation = $tTHEME->TabSeparation;
|
2003-09-18 23:53:05 +00:00
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
$tabs = count($data);
|
|
|
|
$tabwidth = (int) (100 / $tabsperrow);
|
2003-09-18 23:53:05 +00:00
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
$currentrow = ( $currenttab - ( $currenttab % $tabsperrow) ) / $tabsperrow;
|
|
|
|
|
|
|
|
$numrows = (int) ( $tabs / $tabsperrow ) + 1;
|
2003-09-18 23:53:05 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
<center>
|
2003-10-15 16:12:38 +00:00
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="<?php p($tablewidth) ?>">
|
2003-09-18 23:53:05 +00:00
|
|
|
<tr>
|
|
|
|
<td width="100%">
|
|
|
|
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
|
|
|
2003-09-29 03:06:30 +00:00
|
|
|
<?php
|
2003-10-15 16:12:38 +00:00
|
|
|
$tabproccessed = 0;
|
|
|
|
for ($row = 0; $row < $numrows; $row++) {
|
2003-09-18 23:53:05 +00:00
|
|
|
echo "<tr>\n";
|
2003-10-15 16:12:38 +00:00
|
|
|
if ( $row != $currentrow ) {
|
|
|
|
for ($col = 0; $col < $tabsperrow; $col++) {
|
|
|
|
if ( $tabproccessed < $tabs ) {
|
2003-09-29 03:06:30 +00:00
|
|
|
if ( $col == 0 ) {
|
2003-10-15 16:12:38 +00:00
|
|
|
echo "<td width=\"$tabseparation\" align=\"center\"> </td>";
|
2003-09-29 03:06:30 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
if ($tabproccessed == $currenttab) {
|
|
|
|
$currentcolor = $currenttabcolor;
|
2003-10-19 05:02:45 +00:00
|
|
|
$currentstyle = 'generaltabselected';
|
2003-09-18 23:53:05 +00:00
|
|
|
} else {
|
2003-10-15 16:12:38 +00:00
|
|
|
$currentcolor = $tabcolor;
|
2003-10-19 05:02:45 +00:00
|
|
|
$currentstyle = 'generaltab';
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
2003-10-19 05:02:45 +00:00
|
|
|
echo "<td class=\"$currentstyle\" width=\"$tabwidth%\" bgcolor=\"$currentcolor\" align=\"center\"><b>";
|
2003-10-15 16:12:38 +00:00
|
|
|
if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
|
|
|
|
echo "<a href=\"" . $data[$tabproccessed]->link . "\">";
|
2003-09-23 12:34:47 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
|
2003-10-16 05:15:59 +00:00
|
|
|
if ( !$data[$tabproccessed]->link ) {
|
|
|
|
echo "<font color=\"$inactivefontcolor\">";
|
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
echo $data[$tabproccessed]->caption;
|
2003-10-16 05:15:59 +00:00
|
|
|
if ( !$data[$tabproccessed]->link ) {
|
|
|
|
echo "</font>";
|
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
|
|
|
|
if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
|
2003-09-23 12:34:47 +00:00
|
|
|
echo "</a>";
|
|
|
|
}
|
|
|
|
echo "</b></td>";
|
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
if ( $col < $tabsperrow ) {
|
|
|
|
echo "<td width=\"$tabseparation\" align=\"center\"> </td>";
|
2003-09-23 12:34:47 +00:00
|
|
|
}
|
2003-09-18 23:53:05 +00:00
|
|
|
} else {
|
2003-10-15 16:12:38 +00:00
|
|
|
$currentcolor = "";
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
$tabproccessed++;
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-10-15 16:12:38 +00:00
|
|
|
$firsttabincurrentrow = $tabproccessed;
|
|
|
|
$tabproccessed += $tabsperrow;
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
echo "</tr><tr><td colspan=" . (2* $tabsperrow) . " ></td></tr>\n";
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
|
|
|
echo "<tr>\n";
|
2003-10-15 16:12:38 +00:00
|
|
|
$tabproccessed = $firsttabincurrentrow;
|
|
|
|
for ($col = 0; $col < $tabsperrow; $col++) {
|
|
|
|
if ( $tabproccessed < $tabs ) {
|
2003-09-29 03:06:30 +00:00
|
|
|
if ( $col == 0 ) {
|
2003-10-15 16:12:38 +00:00
|
|
|
echo "<td width=\"$tabseparation\" align=\"center\"> </td>";
|
2003-09-29 03:06:30 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
if ($tabproccessed == $currenttab) {
|
|
|
|
$currentcolor = $currenttabcolor;
|
2003-10-19 05:07:29 +00:00
|
|
|
$currentstyle = 'generaltabselected';
|
2003-09-18 23:53:05 +00:00
|
|
|
} else {
|
2003-10-15 16:12:38 +00:00
|
|
|
$currentcolor = $tabcolor;
|
2003-10-19 05:07:29 +00:00
|
|
|
$currentstyle = 'generaltab';
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
2003-10-19 05:07:29 +00:00
|
|
|
echo "<td class=\"$currentstyle\" width=\"$tabwidth%\" bgcolor=\"$currentcolor\" align=\"center\"><b>";
|
2003-10-15 16:12:38 +00:00
|
|
|
if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
|
|
|
|
echo "<a href=\"" . $data[$tabproccessed]->link . "\">";
|
2003-09-23 12:34:47 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
|
2003-10-16 05:15:59 +00:00
|
|
|
if ( !$data[$tabproccessed]->link ) {
|
|
|
|
echo "<font color=\"$inactivefontcolor\">";
|
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
echo $data[$tabproccessed]->caption;
|
2003-10-16 05:15:59 +00:00
|
|
|
if ( !$data[$tabproccessed]->link ) {
|
|
|
|
echo "</font>";
|
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
|
|
|
|
if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
|
2003-09-23 12:34:47 +00:00
|
|
|
echo "</a>";
|
|
|
|
}
|
|
|
|
echo "</b></td>";
|
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
if ($col < $tabsperrow) {
|
|
|
|
echo "<td width=\"$tabseparation\" align=\"center\"> </td>";
|
2003-09-23 12:34:47 +00:00
|
|
|
}
|
2003-09-18 23:53:05 +00:00
|
|
|
} else {
|
2003-10-15 16:12:38 +00:00
|
|
|
if ($numrows > 1) {
|
|
|
|
$currentcolor = $tabcolor;
|
2003-09-18 23:53:05 +00:00
|
|
|
} else {
|
2003-10-15 16:12:38 +00:00
|
|
|
$currentcolor = "";
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
echo "<td colspan = " . (2 * ($tabsperrow - $col)) . " bgcolor=\"$currentcolor\" align=\"center\">";
|
2003-09-18 23:53:05 +00:00
|
|
|
echo "</td>";
|
|
|
|
|
2003-10-15 16:12:38 +00:00
|
|
|
$col = $tabsperrow;
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
2003-10-15 16:12:38 +00:00
|
|
|
$tabproccessed++;
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
?>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2003-10-15 16:12:38 +00:00
|
|
|
<td width="100%" bgcolor="<?php p($tablecolor) ?>"><hr></td>
|
2003-09-18 23:53:05 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2003-10-15 16:12:38 +00:00
|
|
|
<td width="100%" bgcolor="<?php p($tablecolor) ?>">
|
2003-09-18 23:53:05 +00:00
|
|
|
<center>
|
2003-09-29 03:06:30 +00:00
|
|
|
<?php
|
2003-09-18 23:53:05 +00:00
|
|
|
}
|
|
|
|
|
2003-09-29 03:06:30 +00:00
|
|
|
function glossary_print_tabbed_table_end() {
|
2003-09-18 23:53:05 +00:00
|
|
|
echo "</center><p></td></tr></table></center>";
|
|
|
|
}
|
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
function glossary_print_approval_menu($cm, $glossary, $l, $sortkey, $sortorder = "",$tab=GLOSSARY_STANDARD_VIEW) {
|
|
|
|
if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '<center>' . get_string("explainalphabet","glossary") . '<p>';
|
2003-10-20 16:42:49 +00:00
|
|
|
}
|
2003-10-21 04:55:22 +00:00
|
|
|
glossary_print_special_links($cm, $glossary,$l, $tab);
|
|
|
|
|
|
|
|
glossary_print_alphabet_links($cm, $glossary,$l, $tab);
|
|
|
|
|
|
|
|
glossary_print_all_links($cm, $glossary,$l, $tab);
|
|
|
|
|
|
|
|
glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
|
|
|
|
}
|
|
|
|
|
2003-11-03 02:26:44 +00:00
|
|
|
function glossary_print_addentry_menu($cm, $glossary, $l, $sortkey, $sortorder = "", $tab=GLOSSARY_STANDARD_VIEW) {
|
|
|
|
echo '<center>' . get_string("explainaddentry","glossary") . '<p>';
|
|
|
|
}
|
|
|
|
|
2003-11-04 03:54:01 +00:00
|
|
|
function glossary_print_import_menu($cm, $glossary, $l, $sortkey, $sortorder = "", $tab=GLOSSARY_STANDARD_VIEW) {
|
|
|
|
echo '<center>' . get_string("explainimport","glossary") . '<p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_export_menu($cm, $glossary, $l, $sortkey, $sortorder = "", $tab=GLOSSARY_STANDARD_VIEW) {
|
|
|
|
echo '<center>' . get_string("explainexport","glossary") . '<p>';
|
|
|
|
}
|
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder = "", $tab=GLOSSARY_STANDARD_VIEW) {
|
2003-10-22 04:15:08 +00:00
|
|
|
if ( $tab != GLOSSARY_DATE_VIEW ) {
|
|
|
|
if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
|
|
|
|
echo '<center>' . get_string("explainalphabet","glossary") . '<p>';
|
|
|
|
}
|
2003-10-21 04:55:22 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
glossary_print_special_links($cm, $glossary,$l, $tab);
|
2003-10-21 04:55:22 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
glossary_print_alphabet_links($cm, $glossary,$l, $tab);
|
|
|
|
|
|
|
|
glossary_print_all_links($cm, $glossary,$l, $tab);
|
|
|
|
} else {
|
|
|
|
glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
|
|
|
|
}
|
2003-10-21 04:55:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
|
|
|
|
global $CFG, $THEME;
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '<table border=0 width=100%>';
|
|
|
|
echo '<tr>';
|
2003-10-21 04:55:22 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '<td align=center width=20%>';
|
2003-10-21 04:55:22 +00:00
|
|
|
if ( isteacher($course->id) ) {
|
|
|
|
$options['id'] = $cm->id;
|
|
|
|
$options['cat'] = $cat;
|
|
|
|
echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get");
|
|
|
|
}
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '</td>';
|
2003-10-21 04:55:22 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '<td align=center width=60%>';
|
|
|
|
echo '<b>';
|
2003-10-21 04:55:22 +00:00
|
|
|
|
|
|
|
$menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary");
|
|
|
|
$menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary");
|
2003-10-20 16:42:49 +00:00
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
$categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
|
2003-10-22 04:15:08 +00:00
|
|
|
$selected = '';
|
2003-10-21 04:55:22 +00:00
|
|
|
if ( $categories ) {
|
|
|
|
foreach ($categories as $currentcategory) {
|
|
|
|
$url = $currentcategory->id;
|
|
|
|
if ( $category ) {
|
|
|
|
if ($currentcategory->id == $category->id) {
|
|
|
|
$selected = $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$menu[$url] = $currentcategory->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !$selected ) {
|
|
|
|
$selected = GLOSSARY_SHOW_NOT_CATEGORISED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $category ) {
|
|
|
|
echo $category->name;
|
|
|
|
} else {
|
|
|
|
if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
|
|
|
|
|
|
|
|
echo get_string("entrieswithoutcategory","glossary");
|
|
|
|
$selected = GLOSSARY_SHOW_NOT_CATEGORISED;
|
|
|
|
|
|
|
|
} elseif ( $cat == GLOSSARY_SHOW_ALL_CATEGORIES ) {
|
|
|
|
|
|
|
|
echo get_string("allcategories","glossary");
|
|
|
|
$selected = GLOSSARY_SHOW_ALL_CATEGORIES;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '</b></td>';
|
|
|
|
echo '<td align=center width=20%>';
|
2003-10-21 04:55:22 +00:00
|
|
|
|
|
|
|
echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&tab=" . GLOSSARY_CATEGORY_VIEW . "&cat=", $menu, "catmenu", $selected, "",
|
|
|
|
"", "", false);
|
2003-10-20 16:42:49 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '</td>';
|
|
|
|
echo '</tr>';
|
2003-10-21 04:55:22 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '</table>';
|
2003-10-21 04:55:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_all_links($cm, $glossary, $l, $tab) {
|
|
|
|
global $CFG;
|
|
|
|
if ( $glossary->showall and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
|
|
|
|
$strallentries = get_string("allentries", "glossary");
|
2003-10-22 04:15:08 +00:00
|
|
|
if ( $l == 'ALL' ) {
|
2003-10-21 04:55:22 +00:00
|
|
|
echo "<b>$strallentries</b>";
|
|
|
|
} else {
|
|
|
|
$strexplainall = strip_tags(get_string("explainall","glossary"));
|
|
|
|
echo "<a title=\"$strexplainall\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=ALL&tab=$tab\">$strallentries</a>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_special_links($cm, $glossary, $l, $tab) {
|
|
|
|
global $CFG;
|
|
|
|
if ( $glossary->showspecial and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
|
|
|
|
$strspecial = get_string("special", "glossary");
|
2003-10-22 04:15:08 +00:00
|
|
|
if ( $l == 'SPECIAL' ) {
|
2003-10-20 16:42:49 +00:00
|
|
|
echo "<b>$strspecial</b> | ";
|
|
|
|
} else {
|
|
|
|
$strexplainspecial = strip_tags(get_string("explainspecial","glossary"));
|
2003-10-21 04:55:22 +00:00
|
|
|
echo "<a title=\"$strexplainspecial\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=SPECIAL&tab=$tab\">$strspecial</a> | ";
|
2003-10-20 16:42:49 +00:00
|
|
|
}
|
2003-09-23 12:34:47 +00:00
|
|
|
}
|
2003-10-21 04:55:22 +00:00
|
|
|
}
|
2003-10-20 16:42:49 +00:00
|
|
|
|
2003-10-21 04:55:22 +00:00
|
|
|
function glossary_print_alphabet_links($cm, $glossary,$l, $tab) {
|
|
|
|
global $CFG;
|
|
|
|
if ( $glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
|
2003-11-04 12:36:55 +00:00
|
|
|
$alphabet = explode(",", get_string("alphabet"));
|
2003-10-20 16:42:49 +00:00
|
|
|
$letters_by_line = 14;
|
|
|
|
for ($i = 0; $i < count($alphabet); $i++) {
|
|
|
|
if ( $l == $alphabet[$i] and $l) {
|
|
|
|
echo "<b>$alphabet[$i]</b>";
|
|
|
|
} else {
|
2003-10-21 04:55:22 +00:00
|
|
|
echo "<a href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&l=$alphabet[$i]&tab=$tab\">$alphabet[$i]</a>";
|
2003-10-20 16:42:49 +00:00
|
|
|
}
|
|
|
|
if ((int) ($i % $letters_by_line) != 0 or $i == 0) {
|
2003-10-22 04:15:08 +00:00
|
|
|
echo ' | ';
|
2003-10-20 16:42:49 +00:00
|
|
|
} else {
|
2003-10-22 04:15:08 +00:00
|
|
|
echo '<br>';
|
2003-10-20 16:42:49 +00:00
|
|
|
}
|
2003-10-19 03:40:36 +00:00
|
|
|
}
|
2003-10-20 16:42:49 +00:00
|
|
|
}
|
2003-10-21 04:55:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab) {
|
|
|
|
global $CFG;
|
|
|
|
$strsort = get_string("sortchronogically", "glossary");
|
|
|
|
$strsortbycreation = get_string("sortbycreation", "glossary");
|
|
|
|
$strsortbylastupdate = get_string("sortbylastupdate", "glossary");
|
2003-10-20 16:42:49 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
$neworder = '';
|
2003-10-20 16:42:49 +00:00
|
|
|
if ( $sortorder ) {
|
2003-10-22 04:15:08 +00:00
|
|
|
if ( $sortorder == 'asc' ) {
|
|
|
|
$neworder = '&sortorder=desc';
|
2003-10-20 16:42:49 +00:00
|
|
|
$ordertitle = get_string("descending","glossary");
|
|
|
|
} else {
|
2003-10-22 04:15:08 +00:00
|
|
|
$neworder = '&sortorder=asc';
|
2003-10-20 16:42:49 +00:00
|
|
|
$ordertitle = get_string("ascending","glossary");
|
|
|
|
}
|
|
|
|
$icon = " <img src=\"$sortorder.gif\" border=0 width=16 height=16>";
|
|
|
|
} else {
|
2003-10-22 04:15:08 +00:00
|
|
|
if ( $sortkey != 'CREATION' and $sortkey != 'UPDATE' ) {
|
2003-10-20 16:42:49 +00:00
|
|
|
$icon = "";
|
|
|
|
$ordertitle = get_string("ascending","glossary");
|
|
|
|
} else {
|
|
|
|
$ordertitle = get_string("descending","glossary");
|
2003-10-22 04:15:08 +00:00
|
|
|
$neworder = '&sortorder=desc';
|
|
|
|
$icon = ' <img src="asc.gif" border=0 width=16 height=16>';
|
2003-10-20 16:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-22 04:15:08 +00:00
|
|
|
$cicon = '';
|
|
|
|
$cneworder = '';
|
|
|
|
$cbtag = '';
|
|
|
|
$cendbtag = '';
|
2003-10-20 16:42:49 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
$uicon = '';
|
|
|
|
$uneworder = '';
|
|
|
|
$ubtag = '';
|
|
|
|
$uendbtag = '';
|
2003-10-20 16:42:49 +00:00
|
|
|
|
2003-10-22 04:15:08 +00:00
|
|
|
if ( $sortkey == 'CREATION' ) {
|
2003-10-20 16:42:49 +00:00
|
|
|
$cicon = $icon;
|
|
|
|
$cneworder = $neworder;
|
|
|
|
$cordertitle = $ordertitle;
|
|
|
|
$uordertitle = get_string("ascending","glossary");
|
2003-10-22 04:15:08 +00:00
|
|
|
$cbtag = '<b>';
|
|
|
|
$cendbtag = '</b>';
|
|
|
|
} elseif ($sortkey == 'UPDATE') {
|
2003-10-20 16:42:49 +00:00
|
|
|
$uicon = $icon;
|
|
|
|
$uneworder = $neworder;
|
|
|
|
$cordertitle = get_string("ascending","glossary");
|
|
|
|
$uordertitle = $ordertitle;
|
2003-10-22 04:15:08 +00:00
|
|
|
$ubtag = '<b>';
|
|
|
|
$uendbtag = '</b>';
|
2003-10-20 16:42:49 +00:00
|
|
|
} else {
|
|
|
|
$cordertitle = get_string("ascending","glossary");
|
|
|
|
$uordertitle = get_string("ascending","glossary");
|
|
|
|
}
|
2003-10-21 04:55:22 +00:00
|
|
|
echo "<br>$strsort: $ubtag<a title=\"$strsortbylastupdate $uordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=UPDATE$uneworder&tab=$tab\">$strsortbylastupdate$uicon</a>$uendbtag | ".
|
|
|
|
"$cbtag<a title=\"$strsortbycreation $cordertitle\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&sortkey=CREATION$cneworder&tab=$tab\">$strsortbycreation$cicon</a>$cendbtag</p>";
|
2003-09-21 17:08:41 +00:00
|
|
|
}
|
2003-09-29 03:06:30 +00:00
|
|
|
|
|
|
|
function glossary_sort_entries ( $entry0, $entry1 ) {
|
|
|
|
if ( strtolower(ltrim($entry0->concept)) < strtolower(ltrim($entry1->concept)) ) {
|
|
|
|
return -1;
|
|
|
|
} elseif ( strtolower(ltrim($entry0->concept)) > strtolower(ltrim($entry1->concept)) ) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-16 05:15:59 +00:00
|
|
|
function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
|
|
|
|
global $THEME, $CFG, $USER;
|
|
|
|
|
2003-10-28 16:10:36 +00:00
|
|
|
$colour = $THEME->cellheading2;
|
2003-10-16 05:15:59 +00:00
|
|
|
|
|
|
|
$user = get_record("user", "id", $comment->userid);
|
|
|
|
$strby = get_string("writtenby","glossary");
|
|
|
|
|
|
|
|
echo "<table class=\"generalbox\" BORDER=1 CELLSPACING=0 valign=top cellpadding=0 width=70% border=0><tr><td>";
|
|
|
|
|
|
|
|
echo "\n<TABLE width=\"100%\" BORDER=0 CELLSPACING=0 valign=top cellpadding=5><tr>";
|
|
|
|
|
|
|
|
echo "\n<TD BGCOLOR=\"$THEME->cellheading\" WIDTH=25% VALIGN=TOP align=right >";
|
|
|
|
print_user_picture($user->id, $course->id, $user->picture);
|
|
|
|
echo "<br><FONT SIZE=2>$strby $user->firstname $user->lastname</font>";
|
|
|
|
echo "<br><FONT SIZE=1>(".get_string("lastedited").": ".userdate($comment->timemodified).")</FONT></small><br>";
|
|
|
|
echo "</TD>";
|
2003-10-22 04:15:08 +00:00
|
|
|
|
2003-10-28 16:10:36 +00:00
|
|
|
echo "<TD valign=top WIDTH=75% BGCOLOR=\"$THEME->cellcontent\">";
|
2003-10-16 05:15:59 +00:00
|
|
|
if ($comment) {
|
2003-10-22 04:15:08 +00:00
|
|
|
echo format_text($comment->comment, $comment->format);
|
2003-10-16 05:15:59 +00:00
|
|
|
} else {
|
2003-10-22 04:15:08 +00:00
|
|
|
echo "<center>";
|
2003-10-16 05:15:59 +00:00
|
|
|
print_string("nocomment", "glossary");
|
2003-10-22 04:15:08 +00:00
|
|
|
echo "</center>";
|
2003-10-16 05:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "<p align=right>";
|
2003-10-22 04:15:08 +00:00
|
|
|
if ( (time() - $comment->timemodified < $CFG->maxeditingtime and $USER->id == $comment->userid) or isteacher($course->id) ) {
|
2003-10-16 05:15:59 +00:00
|
|
|
echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id&cid=$comment->id&action=edit\"><img alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a> ";
|
2003-10-22 04:15:08 +00:00
|
|
|
}
|
|
|
|
if ( $USER->id == $comment->userid or isteacher($course->id) ) {
|
2003-10-16 05:15:59 +00:00
|
|
|
echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id&cid=$comment->id&action=delete\"><img alt=\"" . get_string("delete") . "\" src=\"../../pix/t/delete.gif\" height=11 width=11 border=0></a>";
|
2003-10-22 04:15:08 +00:00
|
|
|
}
|
2003-10-16 05:15:59 +00:00
|
|
|
echo "</td>";
|
2003-10-22 04:15:08 +00:00
|
|
|
|
2003-10-16 05:15:59 +00:00
|
|
|
echo "</tr></TABLE>\n";
|
|
|
|
|
|
|
|
echo "</td></tr></table>";
|
|
|
|
}
|
|
|
|
|
2003-10-28 16:10:36 +00:00
|
|
|
function glossary_print_dynaentry($courseid, $entries) {
|
|
|
|
global $THEME, $USER;
|
2003-10-18 20:23:29 +00:00
|
|
|
|
2003-10-28 16:10:36 +00:00
|
|
|
$colour = $THEME->cellheading2;
|
2003-10-18 20:23:29 +00:00
|
|
|
|
2003-10-28 16:10:36 +00:00
|
|
|
echo "\n<center><table width=95% border=0><tr>";
|
|
|
|
echo "<td width=100%\">";
|
|
|
|
if ( $entries ) {
|
|
|
|
foreach ( $entries as $entry ) {
|
|
|
|
if (! $glossary = get_record("glossary", "id", $entry->glossaryid)) {
|
|
|
|
error("Glossary ID was incorrect or no longer exists");
|
2003-10-18 20:23:29 +00:00
|
|
|
}
|
2003-10-28 16:10:36 +00:00
|
|
|
if (! $course = get_record("course", "id", $glossary->course)) {
|
|
|
|
error("Glossary is misconfigured - don't know what course it's from");
|
|
|
|
}
|
2003-10-29 23:33:54 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $glossary->course) ) {
|
2003-10-28 16:10:36 +00:00
|
|
|
error("Glossary is misconfigured - don't know what course module it is ");
|
|
|
|
}
|
|
|
|
glossary_print_entry($course, $cm, $glossary, $entry);
|
2003-10-18 20:23:29 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-28 16:10:36 +00:00
|
|
|
echo "</td>";
|
|
|
|
echo "</tr></table></center>";
|
|
|
|
}
|
2003-11-01 20:27:21 +00:00
|
|
|
|
2003-11-06 15:07:34 +00:00
|
|
|
function glossary_generate_export_file($glossary, $l = "", $cat = 0) {
|
2003-11-01 20:27:21 +00:00
|
|
|
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));
|
|
|
|
|
2003-11-04 03:54:01 +00:00
|
|
|
if ( $entries = get_records("glossary_entries","glossaryid",$glossary->id) ) {
|
|
|
|
$status = fwrite ($h,glossary_start_tag("ENTRIES",2,true));
|
|
|
|
foreach ($entries as $entry) {
|
2003-11-06 15:07:34 +00:00
|
|
|
$permissiongranted = 1;
|
|
|
|
if ( $l ) {
|
|
|
|
switch ( $l ) {
|
|
|
|
case "ALL":
|
|
|
|
case "SPECIAL":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$permissiongranted = ($entry->concept[ strlen($l)-1 ] == $l);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $cat ) {
|
|
|
|
switch ( $cat ) {
|
|
|
|
case GLOSSARY_SHOW_ALL_CATEGORIES:
|
|
|
|
break;
|
|
|
|
case GLOSSARY_SHOW_NOT_CATEGORISED:
|
|
|
|
$permissiongranted = !record_exists("glossary_entries_categories","entryid",$entry->id);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$permissiongranted = record_exists("glossary_entries_categories","entryid",$entry->id, "categoryid",$cat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $entry->approved and $permissiongranted ) {
|
2003-11-04 03:54:01 +00:00
|
|
|
$status = fwrite($h,glossary_start_tag("ENTRY",3,true));
|
|
|
|
fwrite($h,glossary_full_tag("CONCEPT",4,false,$entry->concept));
|
|
|
|
fwrite($h,glossary_full_tag("DEFINITION",4,false,$entry->definition));
|
|
|
|
fwrite($h,glossary_full_tag("FORMAT",4,false,$entry->format));
|
|
|
|
fwrite($h,glossary_full_tag("USEDYNALINK",4,false,$entry->usedynalink));
|
|
|
|
fwrite($h,glossary_full_tag("CASESENSITIVE",4,false,$entry->casesensitive));
|
|
|
|
fwrite($h,glossary_full_tag("FULLMATCH",4,false,$entry->fullmatch));
|
|
|
|
fwrite($h,glossary_full_tag("TEACHERENTRY",4,false,$entry->teacherentry));
|
|
|
|
|
|
|
|
if ( $catentries = get_records("glossary_entries_categories","entryid",$entry->id) ) {
|
|
|
|
$status = fwrite ($h,glossary_start_tag("CATEGORIES",4,true));
|
|
|
|
foreach ($catentries as $catentry) {
|
|
|
|
$category = get_record("glossary_categories","id",$catentry->categoryid);
|
|
|
|
|
|
|
|
$status = fwrite ($h,glossary_start_tag("CATEGORY",5,true));
|
|
|
|
fwrite($h,glossary_full_tag("NAME",6,false,$category->name));
|
|
|
|
$status = fwrite($h,glossary_end_tag("CATEGORY",5,true));
|
|
|
|
}
|
|
|
|
$status = fwrite($h,glossary_end_tag("CATEGORIES",4,true));
|
|
|
|
}
|
2003-11-01 20:27:21 +00:00
|
|
|
|
2003-11-04 03:54:01 +00:00
|
|
|
$status =fwrite($h,glossary_end_tag("ENTRY",3,true));
|
2003-11-01 20:27:21 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-04 03:54:01 +00:00
|
|
|
$status =fwrite ($h,glossary_end_tag("ENTRIES",2,true));
|
|
|
|
|
2003-11-01 20:27:21 +00:00
|
|
|
}
|
2003-11-04 03:54:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
$status =fwrite ($h,glossary_end_tag("INFO",1,true));
|
|
|
|
|
2003-11-01 20:27:21 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-04 03:54:01 +00:00
|
|
|
function glossary_read_imported_file($file) {
|
|
|
|
require_once "../../lib/xmlize.php";
|
|
|
|
$h = fopen($file,"r");
|
|
|
|
$line = '';
|
|
|
|
if ($h) {
|
|
|
|
while ( !feof($h) ) {
|
|
|
|
$char = fread($h,1024);
|
|
|
|
$line .= $char;
|
|
|
|
}
|
|
|
|
fclose($h);
|
|
|
|
}
|
|
|
|
return xmlize($line);
|
|
|
|
}
|
2003-11-01 20:27:21 +00:00
|
|
|
//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;
|
|
|
|
}
|
2003-11-04 12:36:55 +00:00
|
|
|
?>
|