Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c197e6070b
Fetching contributors…

Cannot retrieve contributors at this time

file 421 lines (373 sloc) 17.189 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
<?php // $Id$

/// This page prints a particular instance of glossary
    require_once("../../config.php");
    require_once("lib.php");
    
    require_variable($id); // Course Module ID
    optional_variable($l,""); // letter to look for
    optional_variable($eid); // Entry ID
    optional_variable($search, ""); // search string
    optional_variable($includedefinition); // include definition in search function?
    
    optional_variable($tab); // browsing entries by categories?
    optional_variable($cat); // categoryID

    optional_variable($sortkey,""); // Sorted view: CREATION or UPDATE
    optional_variable($sortorder,""); // it define the order of the sorting (ASC or DESC)

    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 (!$cm->visible and !isteacher($course->id)) {
        notice(get_string("activityiscurrentlyhidden"));
    }
    add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", "$glossary->id");
    

/// checking for valid values for sortorder and sortkey
    if ( $sortorder = strtolower($sortorder) ) {
        if ($sortorder != 'asc' and $sortorder != 'desc') {
            $sortorder = '';
        } else {
            $l = '';
            $search = '';
        }
    }
    if ( $sortkey = strtoupper($sortkey) ) {
        if ($sortkey != 'CREATION' and $sortkey != 'UPDATE') {
            $sortkey = '';
        }
    }

    if ( $sortkey or $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
        if ( !$sortkey and $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
            $sortkey = 'CREATION';
            $sortorder = 'asc';
        }
        if ( !$sortorder ) {
            $sortorder = 'asc';
        }
    } else {
        $orderby = 'concept ASC';
    }

// creating matrix of words to search if apply
    $search = trim(strip_tags($search));
    if ($search and !$eid) {
        $l = '';
        $searchterms = explode(' ', $search); // Search for words independently
        foreach ($searchterms as $key => $searchterm) {
            if (strlen($searchterm) < 2) {
                unset($searchterms[$key]);
            }
        }
        $search = trim(implode(' ', $searchterms));
        $tab = GLOSSARY_STANDARD_VIEW;
    } elseif ($eid) {
        $search = '';
    }

    $alphabet = explode('|', get_string("alphabet","glossary"));
    if ($l == '' and $search == '' and $sortkey == '' and !$eid) {
        // if the user is just entering the glossary...
        if ($tab != GLOSSARY_APPROVAL_VIEW) {
            $l = $alphabet[0];
        } else {
            $l = 'ALL';
        }
    } elseif ($eid) {
        $l = '';
    }
    
    $category = '';
    if ($tab == GLOSSARY_CATEGORY_VIEW) {
        $l = '';
        if ($cat > 0) {
            $category = get_record("glossary_categories", "id", $cat);
            if (!$category) {
                $cat = '';
            }
        }
    }
    
/// Printing the page header
    if ($course->category) {
        $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
}
$strglossaries = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary");
$strallcategories = get_string("allcategories", "glossary");
$straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");
print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
"$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> $glossary->name",
"", "", true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
print_heading($glossary->name);
/// Info box

if ( $glossary->intro ) {
print_simple_box_start('center','70%');
echo '<p align="center">';
echo $glossary->intro;
echo '</p>';
print_simple_box_end();
}

/// Add button
if (!isguest()) {
if ( isteacher($course->id) or $glossary->studentcanpost ) {
$options = array ("id" => "$cm->id");
echo '<center><p>';
print_single_button("edit.php", $options, $straddentry);
echo '</p></center>';
}
}
echo '<p>';

/// Search box

print_simple_box_start("center", "", $THEME->cellheading);
echo '<p>';
echo '<form method="POST" action="view.php">';
echo '<input type="submit" value="'.$strsearch.'" name="searchbutton"> ';
echo '<input type="text" name="search" size="20" value=""> ';
echo '<input type="checkbox" name="includedefinition" value="1">';
echo $strsearchindefinition;
echo '<input type="hidden" name="id" value="'.$cm->id.'">';
echo '</form>';
echo '</p>';
print_simple_box_end();


/// Tabbed browsing sections
echo '<p align="center">';
$glossary_tCFG->TabTableBGColor = $THEME->cellheading;
$glossary_tCFG->ActiveTabColor = $THEME->cellheading;
$glossary_tCFG->InactiveTabColor = $THEME->cellcontent2;
$glossary_tCFG->InactiveFontColor= $THEME->hidden;
$glossary_tCFG->TabTableWidth = "70%";
$glossary_tCFG->TabsPerRow = 4;
$glossary_tCFG->TabSeparation = 4;

$data[GLOSSARY_STANDARD_VIEW]->link = "view.php?id=$id";
$data[GLOSSARY_STANDARD_VIEW]->caption = get_string("standardview", "glossary");
$data[GLOSSARY_CATEGORY_VIEW]->link = "view.php?id=$id&tab=".GLOSSARY_CATEGORY_VIEW;
$data[GLOSSARY_CATEGORY_VIEW]->caption = get_string("categoryview", "glossary");
$data[GLOSSARY_DATE_VIEW]->link = "view.php?id=$id&tab=".GLOSSARY_DATE_VIEW;
$data[GLOSSARY_DATE_VIEW]->caption = get_string("dateview", "glossary");

if (isteacher($course->id)) {
$data[GLOSSARY_APPROVAL_VIEW]->caption = get_string("waitingapproval", "glossary");
$data[GLOSSARY_APPROVAL_VIEW]->link = "";

$hiddenentries = get_records_select("glossary_entries","glossaryid = $glossary->id and approved = 0");
if ($hiddenentries) {
$data[GLOSSARY_APPROVAL_VIEW]->caption .= "<br><font size=1>(" . count($hiddenentries) . " " . get_string("entries","glossary") . ")</font>";
$data[GLOSSARY_APPROVAL_VIEW]->link = "view.php?id=$id&tab=".GLOSSARY_APPROVAL_VIEW;
} elseif ( $tab == GLOSSARY_APPROVAL_VIEW ) {
$tab = GLOSSARY_STANDARD_VIEW;
}
} elseif ( $tab == GLOSSARY_APPROVAL_VIEW ) {
$tab = GLOSSARY_STANDARD_VIEW;
}

/// printing header of the current tab
echo '<center>';
glossary_print_tabbed_table_start($data, $tab, $glossary_tCFG);
switch ($tab) {
case GLOSSARY_CATEGORY_VIEW:
glossary_print_categories_menu($course, $cm, $glossary, $cat, $category);
break;
case GLOSSARY_APPROVAL_VIEW:
glossary_print_approval_menu($cm, $glossary, $l, $sortkey, $sortorder,$tab);
break;
case GLOSSARY_DATE_VIEW:
if (!$sortkey) {
$sortkey = 'UPDATE';
}
if (!$sortorder) {
$sortorder = 'desc';
}
case GLOSSARY_STANDARD_VIEW:
default:
glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder,$tab);
if ($search) {
echo "<h3>$strsearch: $search</h3>";
}
break;
}
echo '<hr>';
/// Printing the entries

switch ($tab) {
case GLOSSARY_CATEGORY_VIEW:
if ($cat == GLOSSARY_SHOW_ALL_CATEGORIES) {
$sql = "SELECT gec.id gecid, gc.name, gc.id CID, ge.*
                        FROM {$CFG->prefix}glossary_entries ge,
                             {$CFG->prefix}glossary_entries_categories gec,
                             {$CFG->prefix}glossary_categories gc
                        WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND
                              gec.entryid = ge.id AND
                              gc.id = gec.categoryid";

if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
$sql .= ' ORDER BY gc.name, ge.timecreated';
} else {
$sql .= ' ORDER BY gc.name, ge.concept';
}
$allentries = get_records_sql($sql);
} else {
if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
$allentries = glossary_get_entries_sorted($glossary, '',$orderby);
} else {
$allentries = glossary_get_entries_by_category($glossary, $cat, '',$orderby);
}
}
$currentcategory = "";
break;
case GLOSSARY_APPROVAL_VIEW:
$allentries = glossary_get_entries_sorted($glossary, 'approved = 0',$orderby);
$currentletter = '';
break;
case GLOSSARY_DATE_VIEW:
$l = 'ALL';
case GLOSSARY_STANDARD_VIEW:
default:
if ($search) { // looking for a term
$allentries = glossary_search_entries($searchterms, $glossary, $includedefinition);
} elseif ($eid) { // looking for an entry
$allentries = get_records_select("glossary_entries", "id = $eid");
} elseif ( $l or $sortkey ) {
if ($sortkey == 'CREATION') {
$orderby = "timecreated $sortorder";
} else {
$orderby = "timemodified $sortorder";
}
$where = '';
if ($l != 'ALL' and $l != 'SPECIAL') {
switch ($CFG->dbtype) {
case 'postgres7':
$where = 'substr(ucase(concept),1,' . strlen($l) . ') = \'' . strtoupper($l) . '\'';
break;
case 'mysql':
$where = 'left(ucase(concept),' . strlen($l) . ") = '$l'";
break;
default:
$where = '';
}
}
$allentries = glossary_get_entries_sorted($glossary, $where,$orderby);
}
$currentletter = '';
break;
}
$dumpeddefinitions = 0;
if ($allentries) {
if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) {
echo '<table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=left bgcolor="#FFFFFF">';
        }
        foreach ($allentries as $entry) {
            $dumptoscreen = 0;
            $firstletter = strtoupper(substr(ltrim($entry->concept), 0, strlen($l)));
            if ($l) {
                if ($l == 'ALL' or $sortkey == 'CREATION' or $sortkey == 'UPDATE' or $firstletter == $l) {
                    if ($currentletter != $firstletter[0]) {
                        if ($entry->approved or ($USER->id == $entry->userid and !isteacher($course->id)) or $tab == GLOSSARY_APPROVAL_VIEW) {
                            $currentletter = $firstletter[0];
    
                            if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
                                if ($dumpeddefinitions > 0) {
                                    echo '</table></center><p>';
                                }
                                echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
}
if ($l == 'ALL' and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
echo "<b>$currentletter</b>";
}
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
echo '</center></td></tr></table></center>';
if ($dumpeddefinitions > 0) {
echo '<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=5>';
}
}
}
}
$dumptoscreen = 1;
} elseif ($l == 'SPECIAL' and ord($firstletter) != ord('Ñ') and
(ord($firstletter) < ord('A') or ord($firstletter) > ord('Z'))) {
$dumptoscreen = 1;
}
} else {
if ($tab == GLOSSARY_CATEGORY_VIEW) {
if ($category) { // if we are browsing a category
$dumptoscreen = 1;
} else {
if ($cat == GLOSSARY_SHOW_NOT_CATEGORISED) { // Not categorized
if (! record_exists("glossary_entries_categories", "entryid", $entry->id)) {
$dumptoscreen = 1;
}
} else { // All categories
if ($currentcategory != $entry->CID) {
if ($entry->approved or ($USER->id == $entry->userid and !isteacher($course->id)) or $tab == GLOSSARY_APPROVAL_VIEW) {
$currentcategory = $entry->CID;
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
if ($dumpeddefinitions > 0) {
echo '</table></center><p>';
}
echo "\n<center><table border=0 cellspacing=0 width=95% valign=top cellpadding=10><tr><td align=center bgcolor=\"$THEME->cellheading2\">";
}
if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
echo '<center>';
}
echo "<b>$entry->name</b>";
if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
echo '</center><p>';
}
}
}
$dumptoscreen = 1;
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
echo '</center></td></tr></table></center>';
if ($dumpeddefinitions > 0) {
echo '<center><table border=1 cellspacing=0 width=95% valign=top cellpadding=10>';
}
}
$dumptoscreen = 1;
}
}
} else {
$dumptoscreen = 1;
}
}
if ($dumptoscreen) {
$dumpeddefinitions++;
$concept = $entry->concept;
$definition = $entry->definition;
if ($dumpeddefinitions == 1) {
if ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
echo '<center><table border=1 cellspacing=0 width=95% valign=top cellpadding=10>';
}
}
if ($search) {
$entry->concept = highlight($search, $concept);
$entry->definition = highlight($search, $definition);
}
glossary_print_entry($course, $cm, $glossary, $entry, $tab, $cat);
if ($glossary->displayformat != GLOSSARY_FORMAT_SIMPLE) {
echo '<p>';
}
}
}
}
if (! $dumpeddefinitions) {
print_simple_box_start("center", "70%", "$THEME->cellheading2");
if (!$search) {
echo "<center>$strnoentries</center>";
} else {
echo '<center>';
print_string("searchhelp");
echo '</center>';
}
print_simple_box_end();
} else {
switch ($glossary->displayformat) {
case GLOSSARY_FORMAT_CONTINUOUS:
echo '</td></tr></table>';
break;
case GLOSSARY_FORMAT_SIMPLE:
echo '</table></center>';
break;
}
}
echo '</center>';
glossary_print_tabbed_table_end();

/// Finish the page
print_footer($course);
?>
Something went wrong with that request. Please try again.