5ef9baa7a79796c3c3f2edf036047d9cff107378
[moodle.git] / mod / journal / index.php
1 <?PHP // $Id$
3     require("../../config.php");
4     require("lib.php");
6     require_variable($id);   // course
8     if (! $course = get_record("course", "id", $id)) {
9         error("Course ID is incorrect");
10     }
12     require_login($course->id);
13     add_to_log($course->id, "journal", "view all", "index.php?id=$course->id", "");
15     if ($course->category) {
16         $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
17     }
19     $strjournal = get_string("modulename", "journal");
20     $strjournals = get_string("modulenameplural", "journal");
21     $stredit = get_string("edit");
22     $strview = get_string("view");
23     $strweek = get_string("week");
24     $strtopic = get_string("topic");
25     $strquestion = get_string("question");
26     $stranswer = get_string("answer");
28     print_header("$course->shortname: $strjournals", "$course->fullname", "$navigation $strjournals", "");
31     if (! $journals = get_all_instances_in_course("journal", $course->id, "cw.section ASC")) {
32         notice("There are no journals", "../../course/view.php?id=$course->id");
33         die;
34     }
36     $timenow = time();
38     if ($course->format == "weeks") {
39         $table->head  = array ($strweek, $strquestion, $stranswer);
40         $table->align = array ("CENTER", "LEFT", "LEFT");
41     } else if ($course->format == "topics") {
42         $table->head  = array ($strtopic, $strquestion, $stranswer);
43         $table->align = array ("CENTER", "LEFT", "LEFT");
44     } else {
45         $table->head  = array ($strquestion, $stranswer);
46         $table->align = array ("LEFT", "LEFT");
47     }
49     foreach ($journals as $journal) {
51         $entry = get_record_sql("SELECT text FROM journal_entries 
52                                  WHERE user='$USER->id' AND journal='$journal->id'");
54         $journal->timestart  = $course->startdate + (($journal->section - 1) * 608400);
55         if ($journal->daysopen) {
56             $journal->timefinish = $journal->timestart + (3600 * 24 * $journal->daysopen);
57         } else {
58             $journal->timefinish = 9999999999;
59         }
60         $journalopen = ($journal->timestart < $timenow && $timenow < $journal->timefinish);
63         $text = text_to_html($entry->text)."<P ALIGN=right><A HREF=\"view.php?id=$journal->coursemodule\">";
64         if ($journalopen) {
65             $text .= "Edit</A></P>";
66         } else {
67             $text .= "View</A></P>";
68         }
69         if ($course->format == "weeks" or $course->format == "topics") {
70             $table->data[] = array ("$journal->section",
71                                     text_to_html($journal->intro),
72                                     $text);
73         } else {
74             $table->data[] = array (text_to_html($journal->intro),
75                                     $text);
76         }
77     }
79     echo "<BR>";
81     print_table($table);
83     print_footer($course);
84  
85 ?>