Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / journal / view.php
blob7dad3fcd826344832bba1210e1d0445b240664e0
1 <?php // $Id$
3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = required_param('id', PARAM_INT); // Course Module ID
8 if (! $cm = get_coursemodule_from_id('journal', $id)) {
9 error("Course Module ID was incorrect");
12 if (! $course = get_record("course", "id", $cm->course)) {
13 error("Course is misconfigured");
16 require_login($course->id, true, $cm);
18 if (! $journal = get_record("journal", "id", $cm->instance)) {
19 error("Course module is incorrect");
22 add_to_log($course->id, "journal", "view", "view.php?id=$cm->id", $journal->id, $cm->id);
24 if (! $cw = get_record("course_sections", "id", $cm->section)) {
25 error("Course module is incorrect");
28 $strjournal = get_string("modulename", "journal");
29 $strjournals = get_string("modulenameplural", "journal");
31 $navigation = build_navigation('', $cm);
32 print_header_simple(format_string($journal->name), '', $navigation, '', '', true,
33 update_module_button($cm->id, $course->id, $strjournal), navmenu($course, $cm));
35 /// Check to see if groups are being used here
36 $groupmode = groupmode($course, $cm);
37 $currentgroup = setup_and_print_groups($course, $groupmode, "view.php?id=$cm->id");
39 if (isteacher($course->id)) {
40 $entrycount = journal_count_entries($journal, $currentgroup);
42 echo '<div class="reportlink"><a href="report.php?id='.$cm->id.'">'.
43 get_string('viewallentries','journal', $entrycount).'</a></div>';
47 $journal->intro = trim($journal->intro);
49 if (!empty($journal->intro)) {
50 print_box( format_text($journal->intro, $journal->introformat), 'generalbox', 'intro');
53 echo '<br />';
55 $timenow = time();
57 if ($course->format == 'weeks' and $journal->days) {
58 $timestart = $course->startdate + (($cw->section - 1) * 604800);
59 if ($journal->days) {
60 $timefinish = $timestart + (3600 * 24 * $journal->days);
61 } else {
62 $timefinish = $course->enddate;
64 } else { // Have no time limits on the journals
66 $timestart = $timenow - 1;
67 $timefinish = $timenow + 1;
68 $journal->days = 0;
71 if ($timenow > $timestart) {
73 print_simple_box_start('center');
75 if ($timenow < $timefinish) {
76 $options = array ('id' => "$cm->id");
77 echo '<center>';
78 if (!isguest()) {
79 print_single_button('edit.php', $options, get_string('startoredit','journal'));
81 echo '</center>';
85 if ($entry = get_record('journal_entries', 'userid', $USER->id, 'journal', $journal->id)) {
87 if (empty($entry->text)) {
88 echo '<p align="center"><b>'.get_string('blankentry','journal').'</b></p>';
89 } else {
90 echo format_text($entry->text, $entry->format);
93 } else {
94 echo '<span class="warning">'.get_string('notstarted','journal').'</span>';
97 print_simple_box_end();
99 if ($timenow < $timefinish) {
100 if (!empty($entry->modified)) {
101 echo '<div class="lastedit"><strong>'.get_string('lastedited').':</strong> ';
102 echo userdate($entry->modified);
103 echo ' ('.get_string('numwords', '', count_words($entry->text)).')';
104 echo "</div>";
106 if (!empty($journal->days)) {
107 echo '<div class="editend"><strong>'.get_string('editingends', 'journal').':</strong> ';
108 echo userdate($timefinish).'</div>';
110 } else {
111 echo '<div class="editend"><strong>'.get_string('editingended', 'journal').':</strong> ';
112 echo userdate($timefinish).'</div>';
115 if (!empty($entry->entrycomment) or !empty($entry->rating)) {
116 $grades = make_grades_menu($journal->assessed);
117 print_heading(get_string('feedback'));
118 journal_print_feedback($course, $entry, $grades);
122 } else {
123 echo '<div class="warning">'.get_string('notopenuntil', 'journal').': ';
124 echo userdate($timestart).'</div>';
128 print_footer($course);