Skip to content

Commit

Permalink
- Improved printer-friendly version
Browse files Browse the repository at this point in the history
- Cosmetic change in the main view of a glossary.
  • Loading branch information
willcast committed Nov 18, 2003
1 parent b694b2b commit 4f3e59c
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 333 deletions.
276 changes: 161 additions & 115 deletions mod/glossary/print.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@


require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
global $CFG;


require_variable($id); // Course Module ID require_variable($id); // Course Module ID
require_variable($mode,"letter"); // format to show the entries require_variable($mode,"letter"); // mode to show the entries
optional_variable($sortkey,"UPDATE"); // Sorting key if TAB = GLOSSARY_DATE_VIEW optional_variable($hook,"ALL"); // what to show
optional_variable($sortorder,"asc"); // Sorting order if TAB = GLOSSARY_DATE_VIEW optional_variable($sortkey,"UPDATE"); // Sorting key
optional_variable($hook,"ALL"); optional_variable($sortorder,"asc"); // Sorting order
optional_variable($eid); optional_variable($offset); // number of entries to bypass
optional_variable($search);


if (! $cm = get_record("course_modules", "id", $id)) { if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect"); error("Course Module ID was incorrect");
Expand All @@ -24,148 +22,196 @@
error("Course module is incorrect"); error("Course module is incorrect");
} }


global $CFG;
if ( !$entriesbypage = $glossary->entbypage ) {
$entriesbypage = $CFG->glossary_entbypage;
}

if ($course->category) { if ($course->category) {
require_login($course->id); require_login($course->id);
if (isguest()) { if (isguest()) {
error("You must be logged to use this page."); error("You must be logged to use this page.");
} }
} }


if ( $eid ) { /// stablishing flag variables
$mode = 'entry'; if ( $sortorder = strtolower($sortorder) ) {
if ($sortorder != 'asc' and $sortorder != 'desc') {
$sortorder = '';
}
} }
/// Generating the SQL based on the format to show if ( $sortkey = strtoupper($sortkey) ) {
switch ($mode) { if ($sortkey != 'CREATION' and
case "cat": $sortkey != 'UPDATE' and
$where = ''; $sortkey != 'FIRSTNAME' and
if ($hook) { $sortkey != 'LASTNAME'
if ( $hook != GLOSSARY_SHOW_ALL_CATEGORIES and $hook != GLOSSARY_SHOW_NOT_CATEGORISED ) { ) {
$where = 'and c.id = ' . $hook; $sortkey = '';
}
} }
$entries = get_records_sql("SELECT ec.id, 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 $where
ORDER BY c.name, e.concept");


switch ( $mode = strtolower($mode) ) {
case 'entry': /// Looking for a certain entry id
$tab = GLOSSARY_STANDARD_VIEW;
break; break;


case "date": case 'cat': /// Looking for a certain cat
//// Valid sorting values $tab = GLOSSARY_CATEGORY_VIEW;
switch ($sortkey) { if ( $hook > 0 ) {
case 'CREATION': $category = get_record("glossary_categories","id",$hook);
$sortkey = 'timecreated';
break;

case 'UPDATE':
default:
$sortkey = 'timemodified';
break;
}
if ($sortorder != 'asc' and $sortorder != 'desc') {
$sortorder = 'asc';
} }
break;


$entries = get_records_sql("SELECT e.timemodified pivot, e.* case 'approval': /// Looking for entries waiting for approval
FROM {$CFG->prefix}glossary_entries e $tab = GLOSSARY_APPROVAL_VIEW;
WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id) if ( !$hook and !$sortkey and !$sortorder) {
AND e.approved != 0 $hook = 'ALL';
ORDER BY e.$sortkey $sortorder"); }
break;


case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
$tab = GLOSSARY_STANDARD_VIEW;
break; break;
case "letter":
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;
}


if ( $hook ) { case 'date':
if ($hook != 'ALL' and $hook != 'SPECIAL') { $tab = GLOSSARY_DATE_VIEW;
switch ($CFG->dbtype) { if ( !$sortkey ) {
case 'postgres7': $sortkey = 'UPDATE';
$where = 'and substr(ucase(concept),1,' . strlen($hook) . ') = \'' . strtoupper($hook) . '\''; }
break; if ( !$sortorder ) {
case 'mysql': $sortorder = 'desc';
$where = 'and left(ucase(concept),' . strlen($hook) . ") = '" . strtoupper($hook) . "'"; }
break; break;
default:
$where = ''; case 'author': /// Looking for entries, browsed by author
} $tab = GLOSSARY_AUTHOR_VIEW;
} if ( !$hook ) {
} elseif ($eid) { $hook = 'ALL';
$where = " and e.id = $eid"; }
if ( !$sortkey ) {
$sortkey = 'FIRSTNAME';
}
if ( !$sortorder ) {
$sortorder = 'asc';
} }

$entries = get_records_sql("SELECT e.id, $pivot pivot, e.*
FROM {$CFG->prefix}glossary_entries e
WHERE (e.glossaryid = $glossary->id or e.sourceglossaryid = $glossary->id)
AND e.approved != 0 $where
ORDER BY e.concept $sortorder");
break; break;
}


echo '<p><STRONG>' . get_string("course") . ': <i>' . $course->fullname . '</i><br />'; case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
echo get_string("modulename","glossary") . ': <i>' . $glossary->name . '</i></STRONG></p>'; default:
$tab = GLOSSARY_STANDARD_VIEW;
if ( !$hook ) {
$hook = 'ALL';
}
break;
}


if ( !$entries ) { include_once("sql.php");
echo get_string("noentries","glossary");
exit; $entriesshown = 0;
$currentpivot = '';
if ( $hook == 'SPECIAL' ) {
$alphabet = explode(",", get_string("alphabet"));
} }

$groupheader = '';
$tableisopen = 0; $tableisopen = 0;
foreach ($entries as $entry) {
$site = get_record("course","id",1);
echo '<p align="right"><font size=-1>' . userdate(time()) . '</font></p>';
echo '<strong>' . $site->fullname . '</strong><br>';
echo get_string("course") . ': <strong>' . $course->fullname . '</strong><br \>';
echo get_string("modulename","glossary") . ': <strong>' . $glossary->name . '</strong><p>';

foreach ($allentries as $entry) {
/// Setting the pivot for the current entry
$pivot = $entry->pivot; $pivot = $entry->pivot;
if ( $CFG->dbtype != "postgres7" and $CFG->dbtype != "mysql" and $mode != "cat") { if ( !$fullpivot ) {
$pivot = $pivot[0]; $pivot = $pivot[0];
} }

///
/// Validating special cases not covered by the SQL statement
///

/// if we're browsing by alphabet and the current concept does not begin with
/// the letter we are look for.
$showentry = 1;
if ( $mode == 'letter' and $hook != 'SPECIAL' and $hook != 'ALL' ) {
if ( substr($entry->concept, 0, strlen($hook)) != $hook ) {
$showentry = 0;
}
}


if ($mode != "date") { /// if we're browsing for letter, looking for special characters not covered
if (strtoupper($groupheader) != strtoupper($pivot)) { /// in the alphabet
/// Printing th eheader of the group if ( $showentry and $hook == 'SPECIAL' ) {

$initial = $entry->concept[0];
if ($tableisopen) { for ($i = 0; $i < count($alphabet); $i++) {
echo '</table>'; $curletter = $alphabet[$i];
echo '</center>'; if ( $curletter == $initial ) {
$tableisopen = 0;
$showentry = 0;
break;
} }
$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>'; /// if we're browsing categories, looking for entries not categorised.
echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>'; if ( $showentry and $mode == 'cat' and $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
echo '<td width="75%">'; if ( record_exists("glossary_entries_categories", "entryid", $entry->id)) {
$showentry = 0;
}
}


if ( $entry->attachment) { /// if the entry is not approved, deal with it based on the current view and
glossary_print_entry_attachment($entry); /// user.
if ( $showentry and $mode != 'approval' ) {
if ( !$entry->approved and isteacher($course->id, $entry->userid) ) {
$showentry = 0;
}
} }


echo format_text("<nolink>$entry->definition</nolink>",$entry->format); /// ok, if it's a valid entry.. Print it.
if ( $showentry ) {

if ( $currentpivot != strtoupper($pivot) ) {

// print the group break if apply
if ( $printpivot ) {
$currentpivot = strtoupper($pivot);
if ( !$tableisopen ) {
echo '<table align="center" width="95%" bgcolor="#FFFFFF" style="border-style: solid; border-width: 1px;">';
$tableisopen = 1;
}

echo '<tr>';
$pivottoshow = $currentpivot;
if ( isset($entry->uid) ) {
// printing the user icon if defined (only when browsing authors)
echo '<td colspan="2" align="left" style="border-style: solid; border-width: 1px;">';
$pivottoshow = $entry->uname;
} else {
echo '<td colspan="2" align="center" style="border-style: solid; border-width: 1px;">';
}

echo "<strong><i>$pivottoshow</i></strong>" ;
echo '</td>';
echo '</tr>';
}
}


echo '</tr>'; echo '<tr>';
echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>';
echo '<td width="75%" style="border-style: solid; border-width: 1px;">';

if ( $entry->attachment) {
glossary_print_entry_attachment($entry);
}
echo strip_tags($entry->definition);

echo '<br><br></tr>';
}
} }
if ($tableisopen) { if ($tableisopen) {
echo '</table>'; echo '</table>';
echo '</center>';
} }
echo '<center><font size=-1>' . userdate(time()) . '</font></center>'
?> ?>
Loading

0 comments on commit 4f3e59c

Please sign in to comment.