moodle/mod/journal/edit.php

97 lines
2.8 KiB
PHP
Raw Normal View History

2001-11-22 06:23:56 +00:00
<?PHP // $Id$
require_once("../../config.php");
2001-11-22 06:23:56 +00:00
require_variable($id); // Course Module ID
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
require_login($course->id);
if (isguest()) {
error("Guests are not allowed to edit journals", $_SERVER["HTTP_REFERER"]);
}
2001-11-22 06:23:56 +00:00
if (! $journal = get_record("journal", "id", $cm->instance)) {
error("Course module is incorrect");
}
$entry = get_record("journal_entries", "userid", $USER->id, "journal", $journal->id);
2001-11-22 06:23:56 +00:00
/// If data submitted, then process and store.
if ($form = data_submitted()) {
2001-11-22 06:23:56 +00:00
$timenow = time();
$form->text = clean_text($form->text, $form->format);
2002-10-12 06:20:56 +00:00
2001-11-22 06:23:56 +00:00
if ($entry) {
$newentry->id = $entry->id;
$newentry->text = $form->text;
$newentry->format = $form->format;
2001-11-22 06:23:56 +00:00
$newentry->modified = $timenow;
if (! update_record("journal_entries", $newentry)) {
error("Could not update your journal");
}
add_to_log($course->id, "journal", "update entry", "view.php?id=$cm->id", "$newentry->id");
2001-11-22 06:23:56 +00:00
} else {
$newentry->userid = $USER->id;
2001-11-22 06:23:56 +00:00
$newentry->journal = $journal->id;
$newentry->text = $form->text;
$newentry->format = $form->format;
2001-11-22 06:23:56 +00:00
$newentry->modified = $timenow;
if (! $newentry->id = insert_record("journal_entries", $newentry)) {
2001-11-22 06:23:56 +00:00
error("Could not insert a new journal entry");
}
add_to_log($course->id, "journal", "add entry", "view.php?id=$cm->id", "$newentry->id");
2001-11-22 06:23:56 +00:00
}
redirect("view.php?id=$cm->id");
die;
}
/// Otherwise fill and print the form.
2002-08-12 09:38:31 +00:00
$strjournal = get_string("modulename", "journal");
$strjournals = get_string("modulenameplural", "journal");
$stredit = get_string("edit");
2002-10-12 06:20:56 +00:00
if ($usehtmleditor = can_use_richtext_editor()) {
$defaultformat = FORMAT_HTML;
$onsubmit = "onsubmit=\"copyrichtext(theform.text);\"";
} else {
$defaultformat = FORMAT_MOODLE;
2002-12-30 15:47:54 +00:00
$onsubmit = "";
2002-10-12 06:20:56 +00:00
}
2002-12-30 15:47:54 +00:00
if (empty($entry)) {
2001-11-22 06:23:56 +00:00
$entry->text = "";
2002-10-12 06:20:56 +00:00
$entry->format = $defaultformat;
2001-11-22 06:23:56 +00:00
}
print_header("$course->shortname: $journal->name", "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->
<A HREF=\"index.php?id=$course->id\">$strjournals</A> ->
2003-06-06 13:53:55 +00:00
<A HREF=\"view.php?id=$cm->id\">$journal->name</A> -> $stredit", "theform.text",
2002-11-10 11:44:58 +00:00
"", true, "", navmenu($course, $cm));
2001-11-22 06:23:56 +00:00
echo "<CENTER>\n";
print_simple_box( text_to_html($journal->intro) , "center");
echo "<BR>";
include("edit.html");
print_footer($course);
?>