Added some set_time_limit()s in case of slow servers timing out.
[moodle-linuxchix.git] / mod / journal / edit.php
blob27ad00e81cf23da5e63647c0edcba0ef08393afe
1 <?php // $Id$
3 require_once("../../config.php");
5 $id = required_param('id', PARAM_INT); // Course Module ID
7 if (! $cm = get_coursemodule_from_id('journal', $id)) {
8 error("Course Module ID was incorrect");
11 if (! $course = get_record("course", "id", $cm->course)) {
12 error("Course is misconfigured");
15 require_login($course->id, false, $cm);
17 if (isguest()) {
18 error("Guests are not allowed to edit journals", $_SERVER["HTTP_REFERER"]);
21 if (! $journal = get_record("journal", "id", $cm->instance)) {
22 error("Course module is incorrect");
25 $entry = get_record("journal_entries", "userid", $USER->id, "journal", $journal->id);
28 /// If data submitted, then process and store.
30 if ($form = data_submitted()) {
32 $timenow = time();
34 //$form->text = clean_text($form->text, $form->format);
36 if ($entry) {
37 $newentry->id = $entry->id;
38 $newentry->text = $form->text;
39 $newentry->format = $form->format;
40 $newentry->modified = $timenow;
41 if (! update_record("journal_entries", $newentry)) {
42 error("Could not update your journal");
44 add_to_log($course->id, "journal", "update entry", "view.php?id=$cm->id", "$newentry->id", $cm->id);
45 } else {
46 $newentry->userid = $USER->id;
47 $newentry->journal = $journal->id;
48 $newentry->text = $form->text;
49 $newentry->format = $form->format;
50 $newentry->modified = $timenow;
51 if (! $newentry->id = insert_record("journal_entries", $newentry)) {
52 error("Could not insert a new journal entry");
54 add_to_log($course->id, "journal", "add entry", "view.php?id=$cm->id", "$newentry->id", $cm->id);
57 redirect("view.php?id=$cm->id");
58 die;
61 /// Otherwise fill and print the form.
63 $strjournal = get_string("modulename", "journal");
64 $strjournals = get_string("modulenameplural", "journal");
65 $stredit = get_string("edit");
67 if ($usehtmleditor = can_use_richtext_editor()) {
68 $defaultformat = FORMAT_HTML;
69 } else {
70 $defaultformat = FORMAT_MOODLE;
73 if (empty($entry)) {
74 $entry->text = "";
75 $entry->format = $defaultformat;
78 $crumbs[] = array('name' => $strjournals, 'link' => "index.php?id=$course->id", 'type' => 'activity');
79 $crumbs[] = array('name' => format_string($journal->name), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
80 $crumbs[] = array('name' => $stredit, 'link' => '', 'type' => 'action');
81 $navigation = build_navigation($crumbs);
83 print_header_simple(format_string($journal->name), "", $navigation, "",
84 "", true, "", navmenu($course, $cm));
86 echo "<center>\n";
88 print_simple_box( format_text($journal->intro, $journal->introformat) , "center");
90 echo "<br />";
92 include("edit.html");
94 if ($usehtmleditor) {
95 use_html_editor("text");
97 echo "</center>\n";
98 print_footer($course);