MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / journal / edit.php
blobd3d547c33d5b15e65c92afaa945356617ef9d5c3
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 $navlinks = array();
79 $navlinks[] = array('name' => $strjournals, 'link' => "index.php?id=$course->id", 'type' => 'activity');
80 $navlinks[] = array('name' => format_string($journal->name), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
81 $navlinks[] = array('name' => $stredit, 'link' => '', 'type' => 'action');
82 $navigation = build_navigation($navlinks);
84 print_header_simple(format_string($journal->name), "", $navigation, "",
85 "", true, "", navmenu($course, $cm));
87 echo "<center>\n";
89 print_simple_box( format_text($journal->intro, $journal->introformat) , "center");
91 echo "<br />";
93 include("edit.html");
95 if ($usehtmleditor) {
96 use_html_editor("text");
98 echo "</center>\n";
99 print_footer($course);