From: willcast Date: Tue, 28 Oct 2003 16:10:36 +0000 (+0000) Subject: - New encapsulated functions in order to make easier to create new display formats X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1d9ddaaf2e5c1962d6c40501ddb3c08a9c639d02;p=moodle.git - New encapsulated functions in order to make easier to create new display formats - Fixed problem when showing 'ALL' in alphabet frame - Disabled unnecessary fields when selecting DO NOT AUTOMATICALY LINK THIS ENTRY in the adde entry screen --- diff --git a/mod/glossary/deleteentry.html b/mod/glossary/deleteentry.html index e7721b139a..0629aa0f47 100644 --- a/mod/glossary/deleteentry.html +++ b/mod/glossary/deleteentry.html @@ -1,6 +1,6 @@
- + diff --git a/mod/glossary/edit.html b/mod/glossary/edit.html index 7a22b1cf15..a2b17d7b46 100644 --- a/mod/glossary/edit.html +++ b/mod/glossary/edit.html @@ -1,5 +1,5 @@
- action="edit.php" enctype="multipart/form-data"> + action="edit.php" enctype="multipart/form-data"> @@ -33,24 +33,18 @@ @@ -148,6 +142,11 @@ echo "id\">"; } ?> + + + + + @@ -166,7 +165,7 @@ diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php index 76c8fcb8b3..2a2413ebc4 100644 --- a/mod/glossary/edit.php +++ b/mod/glossary/edit.php @@ -30,7 +30,9 @@ if (! $glossary = get_record("glossary", "id", $cm->instance)) { } if ( $confirm ) { $form = data_submitted(); - + if ( !isset($form->usedynalink) ) { + $form->usedynalink = 0; + } $timenow = time(); $form->text = clean_text($form->text, $form->format); diff --git a/mod/glossary/formats/2.php b/mod/glossary/formats/2.php index 17d8b0fd38..2b495f6184 100644 --- a/mod/glossary/formats/2.php +++ b/mod/glossary/formats/2.php @@ -14,31 +14,27 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $tab="" echo "\n"; - echo ""; + echo ""; + echo ""; - echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; - echo ""; + echo ""; + echo ""; + + echo "\n"; + echo "\n"; + echo "\n"; - echo "\n"; - echo "\n

:

:

- + +usedynalink) ) { + if ($newentry->usedynalink) { + $selected = "checked"; + } + } +?> + onclick="return lockoptions('form','usedynalink', items)">
"; if ($entry) { print_user_picture($user->id, $course->id, $user->picture); - } - echo "cellheading\" class=\"forumpostheader\">"; - if ( $tab == GLOSSARY_APPROVAL_VIEW ) { - echo "id&eid=$entry->id&tab=$tab\">"; - } - if ($entry->attachment) { - $entry->course = $glossary->course; - echo "
"; - echo glossary_print_attachments($entry, "html"); - echo "
"; - } - if ($entry) { - echo "$entry->concept
"; + + echo "
cellheading\" class=\"forumpostheader\">"; + + glossary_print_entry_approval($cm, $entry, $tab); + glossary_print_entry_attachment($entry,"html","right"); + + echo ""; + glossary_print_entry_concept($entry); + echo "
"; + echo "$strby $user->firstname $user->lastname"; echo "  (".get_string("lastedited").": ". userdate($entry->timemodified).")"; - } - echo "
 cellcontent\" class=\"forumpostmessage\">"; - if ($entry) { - echo format_text($entry->definition, $entry->format); + echo "\n
 cellcontent\" class=\"forumpostmessage\">"; + + glossary_print_entry_definition($entry); glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat); } else { diff --git a/mod/glossary/formats/3.php b/mod/glossary/formats/3.php index 0c2155e798..8c2652a24d 100644 --- a/mod/glossary/formats/3.php +++ b/mod/glossary/formats/3.php @@ -14,24 +14,21 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $tab="" echo "\n"; if ($entry) { print_user_picture($user->id, $course->id, $user->picture); - } - echo "cellheading\" class=\"forumpostheader\">"; - if ($entry) { - if ( $tab == GLOSSARY_APPROVAL_VIEW ) { - echo "id&eid=$entry->id&tab=$tab\">"; - } - echo "$entry->concept
"; + echo "
cellheading\" class=\"forumpostheader\">"; + glossary_print_entry_approval($cm, $entry, $tab); + echo ""; + glossary_print_entry_concept($entry); + echo "
"; echo "$strby $user->firstname $user->lastname"; echo "  (".get_string("lastedited").": ". userdate($entry->timemodified).")"; - } - echo "
 cellcontent\" class=\"forumpostmessage\">"; - echo "\n
 cellcontent\" class=\"forumpostmessage\">"; - if ($entry) { if ($entry->attachment) { $entry->course = $course->id; if (strlen($entry->definition)%2) { @@ -39,11 +36,9 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $tab="" } else { $align = "left"; } - echo "
"; - echo glossary_print_attachments($entry); - echo "
"; + glossary_print_entry_attachment($entry,"",$align); } - echo format_text($entry->definition, $entry->format); + glossary_print_entry_definition($entry); glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat); diff --git a/mod/glossary/formats/4.php b/mod/glossary/formats/4.php index 58769a1295..246eb536fa 100644 --- a/mod/glossary/formats/4.php +++ b/mod/glossary/formats/4.php @@ -6,31 +6,29 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab="", if ( $entry ) { $colour = $THEME->cellheading2; - echo "\n"; + echo '
'; - echo "\n"; + echo ''; echo ""; - echo "\n'; + echo "
"; $entry->course = $course->id; - if ( $tab == GLOSSARY_APPROVAL_VIEW ) { - echo "id&eid=$entry->id&tab=$tab\">"; - } - if ($entry->attachment) { - echo "
"; - echo glossary_print_attachments($entry, "html"); - echo "
"; - } - echo "" . get_string("question","glossary") . ": $entry->concept
"; - echo "  ".get_string("lastedited").": ".userdate($entry->timemodified)."
cellcontent\">"; - echo "" . get_string("answer","glossary") . ": " . format_text($entry->definition, $entry->format); + glossary_print_entry_approval($cm, $entry, $tab); + glossary_print_entry_attachment($entry,"html","right"); + + echo '' . get_string("question","glossary") . ': '; + echo glossary_print_entry_concept($entry) . '
'; + echo '  ' . get_string("lastedited").': '.userdate($entry->timemodified) . '
cellcontent\">"; + echo '' . get_string("answer","glossary") . ': '; + echo glossary_print_entry_definition($entry); + glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat); - echo "
\n"; + echo '
'; } else { - echo "
"; + echo '
'; print_string("noentry", "glossary"); - echo "
"; + echo '
'; } } diff --git a/mod/glossary/formats/5.php b/mod/glossary/formats/5.php index 0e798470b5..e4ec470028 100644 --- a/mod/glossary/formats/5.php +++ b/mod/glossary/formats/5.php @@ -9,27 +9,18 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab="", echo "\n"; echo ""; - if ( $tab == GLOSSARY_APPROVAL_VIEW ) { - echo "id&eid=$entry->id&tab=$tab\">"; - } - if ($entry->attachment) { - $entry->course = $course->id; - echo "
"; - echo glossary_print_attachments($entry, "html"); - echo "
"; - } - echo "$entry->concept
"; + glossary_print_entry_approval($cm, $entry, $tab); if ($entry) { + glossary_print_entry_attachment($entry,"html","right"); + echo ""; + glossary_print_entry_concept($entry); + echo "
"; echo "  ".get_string("lastedited").": ".userdate($entry->timemodified).""; - } - echo ""; - - echo "\ncellcontent\">"; - if ($entry) { - echo format_text($entry->definition, $entry->format); - + echo ""; + echo "\ncellcontent\">"; + + glossary_print_entry_definition($entry); glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat); - } else { echo "
"; print_string("noentry", "glossary"); diff --git a/mod/glossary/index.php b/mod/glossary/index.php index c85fa8deaf..346c85689f 100644 --- a/mod/glossary/index.php +++ b/mod/glossary/index.php @@ -66,7 +66,7 @@ $link = "coursemodule\">$glossary->name"; } - $count = count_records("glossary_entries", "glossaryid", $glossary->id); + $count = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}glossary_entries where (glossaryid = $glossary->id or sourceglossaryid = $glossary->id)"); if ($course->format == "weeks" or $course->format == "topics") { if (empty($glossary->section)) { diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 76fb8c2f05..55f55cc32a 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -249,6 +249,33 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $tab="",$cat="") } } } +function glossary_print_entry_concept($entry) { + echo $entry->concept; +} + +function glossary_print_entry_definition($entry) { + $definition = str_ireplace($entry->concept,"$entry->concept",$entry->definition); + echo format_text($definition, $entry->format); +} + +function glossary_print_entry_attachment($entry,$format,$align) { +/// 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 "
"; + echo glossary_print_attachments($entry,$format,$align); + echo "
"; + } +} + +function glossary_print_entry_approval($cm, $entry, $tab) { + if ( $tab == GLOSSARY_APPROVAL_VIEW ) { + echo "id&eid=$entry->id&tab=$tab\">"; + } +} function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab="",$cat="") { global $THEME, $USER; @@ -256,19 +283,14 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab="" $colour = $THEME->cellheading2; echo "\n"; - echo ""; - if ( $tab == GLOSSARY_APPROVAL_VIEW ) { - echo "id&eid=$entry->id&tab=$tab\">"; - } - if ($entry->attachment) { - $entry->course = $course->id; - echo "
"; - echo glossary_print_attachments($entry,"html"); - echo "
"; - } - echo "$entry->concept: "; - echo format_text($entry->definition, $entry->format); - glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat); + echo ""; + glossary_print_entry_approval($cm, $entry, $tab); + glossary_print_entry_attachment($entry,"html","right"); + echo ""; + glossary_print_entry_concept($entry); + echo ": "; + glossary_print_entry_definition($entry); + glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat); echo ""; echo ""; } @@ -276,21 +298,15 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab="" function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab="",$cat="") { global $THEME, $USER; if ($entry) { - if ( $tab == GLOSSARY_APPROVAL_VIEW ) { - echo "id&eid=$entry->id&tab=$tab\">"; - } - if ($entry->attachment) { - $entry->course = $course->id; - echo "
"; - echo glossary_print_attachments($entry, "html"); - echo "
"; - } - echo " $entry->concept "; - echo format_text($entry->definition, $entry->format); - + 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); glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat); } } + function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat="") { global $THEME, $USER; @@ -953,11 +969,7 @@ function glossary_sort_entries ( $entry0, $entry1 ) { function glossary_print_comment($course, $cm, $glossary, $entry, $comment) { global $THEME, $CFG, $USER; -// if ($entry->timemarked < $entry->modified) { - $colour = $THEME->cellheading2; -// } else { -// $colour = $THEME->cellheading; -// } + $colour = $THEME->cellheading2; $user = get_record("user", "id", $comment->userid); $strby = get_string("writtenby","glossary"); @@ -972,7 +984,7 @@ function glossary_print_comment($course, $cm, $glossary, $entry, $comment) { echo "
(".get_string("lastedited").": ".userdate($comment->timemodified).")
"; echo ""; - echo "cellcontent\">"; + echo "cellcontent\">"; if ($comment) { echo format_text($comment->comment, $comment->format); } else { @@ -995,30 +1007,28 @@ function glossary_print_comment($course, $cm, $glossary, $entry, $comment) { echo ""; } - function glossary_print_dynaentry($courseid, $entries) { - global $THEME, $USER; - - $colour = $THEME->cellheading2; - - echo "\n
"; - echo ""; + echo "
"; - if ( $entries ) { - foreach ( $entries as $entry ) { +function glossary_print_dynaentry($courseid, $entries) { + global $THEME, $USER; - if (! $glossary = get_record("glossary", "id", $entry->glossaryid)) { - error("Glossary ID was incorrect or no longer exists"); - } - if (! $course = get_record("course", "id", $glossary->course)) { - error("Glossary is misconfigured - don't know what course it's from"); - } - if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $courseid) ) { - error("Glossary is misconfigured - don't know what course module it is "); - } + $colour = $THEME->cellheading2; - glossary_print_entry($course, $cm, $glossary, $entry); + echo "\n
"; + echo ""; - echo "
"; + if ( $entries ) { + foreach ( $entries as $entry ) { + if (! $glossary = get_record("glossary", "id", $entry->glossaryid)) { + error("Glossary ID was incorrect or no longer exists"); } + if (! $course = get_record("course", "id", $glossary->course)) { + error("Glossary is misconfigured - don't know what course it's from"); + } + if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $courseid) ) { + error("Glossary is misconfigured - don't know what course module it is "); + } + glossary_print_entry($course, $cm, $glossary, $entry); } - echo "
"; } + echo "
"; +} ?> diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 183ecf9ef0..14725e28c7 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -34,13 +34,18 @@ } add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", "$glossary->id"); +/// stablishing default tab + $framebydefault = GLOSSARY_STANDARD_VIEW; + if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) { + $framebydefault = GLOSSARY_DATE_VIEW; + } /// checking for valid values for sortorder and sortkey if ( $sortorder = strtolower($sortorder) ) { if ($sortorder != 'asc' and $sortorder != 'desc') { $sortorder = ''; } else { - $l = ''; + $l = ''; /// if we are sorting by date, reset the searching by terms or letters $search = ''; } } @@ -49,22 +54,31 @@ $sortkey = ''; } } +/// in this point: +/// $sortkey = CREATION | UPDATE | '' +/// $sortorder = asc | desc | '' + + if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) { + $tab = $framebydefault; - if ( $sortkey or $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) { - if ( !$sortkey and $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS) { + if ( !$sortkey ) { $sortkey = 'CREATION'; - $sortorder = 'asc'; } if ( !$sortorder ) { $sortorder = 'asc'; } } else { - $orderby = 'concept ASC'; + if ( !$sortkey ) { + $sortkey = 'concept'; + } + if ( !$sortorder ) { + $sortorder = 'asc'; + } } // creating matrix of words to search if apply $search = trim(strip_tags($search)); - if ($search and !$eid) { + if ($search and !$eid) { /// searching terms $l = ''; $searchterms = explode(' ', $search); // Search for words independently foreach ($searchterms as $key => $searchterm) { @@ -73,18 +87,18 @@ } } $search = trim(implode(' ', $searchterms)); - $tab = GLOSSARY_STANDARD_VIEW; - } elseif ($eid) { + $tab = $framebydefault; + } elseif ($eid) { /// searching a specify entry $search = ''; } $alphabet = explode('|', get_string("alphabet","glossary")); - if ($l == '' and $search == '' and $sortkey == '' and !$eid) { + if ($l == '' and $search == '' and !$eid) { // if the user is just entering the glossary... if ($tab != GLOSSARY_APPROVAL_VIEW) { $l = $alphabet[0]; } else { - $l = 'ALL'; + $l = 'ALL'; /// show ALL by default in the waiting approval frame } } elseif ($eid) { $l = ''; @@ -167,15 +181,16 @@ $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"); + $data[GLOSSARY_DATE_VIEW]->link = "view.php?id=$id&tab=".GLOSSARY_DATE_VIEW; + if ( $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) { + $data[GLOSSARY_STANDARD_VIEW]->link = "view.php?id=$id"; + $data[GLOSSARY_CATEGORY_VIEW]->link = "view.php?id=$id&tab=".GLOSSARY_CATEGORY_VIEW; + } + if (isteacher($course->id)) { $data[GLOSSARY_APPROVAL_VIEW]->caption = get_string("waitingapproval", "glossary"); $data[GLOSSARY_APPROVAL_VIEW]->link = ""; @@ -185,10 +200,10 @@ $data[GLOSSARY_APPROVAL_VIEW]->caption .= "
(" . count($hiddenentries) . " " . get_string("entries","glossary") . ")"; $data[GLOSSARY_APPROVAL_VIEW]->link = "view.php?id=$id&tab=".GLOSSARY_APPROVAL_VIEW; } elseif ( $tab == GLOSSARY_APPROVAL_VIEW ) { - $tab = GLOSSARY_STANDARD_VIEW; + $tab = $framebydefault; } } elseif ( $tab == GLOSSARY_APPROVAL_VIEW ) { - $tab = GLOSSARY_STANDARD_VIEW; + $tab = $framebydefault; } /// printing header of the current tab @@ -220,6 +235,17 @@ /// Printing the entries + switch ($sortkey) { + case 'CREATION': + $orderby = "timecreated $sortorder"; + break; + case 'UPDATE': + $orderby = "timemodified $sortorder"; + break; + default: + $orderby = "$sortkey $sortorder"; + } + switch ($tab) { case GLOSSARY_CATEGORY_VIEW: if ($cat == GLOSSARY_SHOW_ALL_CATEGORIES) { @@ -259,11 +285,6 @@ } 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) { @@ -402,10 +423,10 @@ } else { switch ($glossary->displayformat) { case GLOSSARY_FORMAT_CONTINUOUS: - echo ''; + echo '

'; break; case GLOSSARY_FORMAT_SIMPLE: - echo '

'; + echo '

'; break; } }