Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / journal / edit.php
blob79ed2eada6ee3d8148665ba29342108b47d9697e
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 $navigation = build_navigation($stredit, $cm);
79 print_header_simple(format_string($journal->name), "", $navigation, "",
80 "", true, "", navmenu($course, $cm));
82 echo "<center>\n";
84 print_simple_box( format_text($journal->intro, $journal->introformat) , "center");
86 echo "<br />";
88 include("edit.html");
90 if ($usehtmleditor) {
91 use_html_editor("text");
93 echo "</center>\n";
94 print_footer($course);