moodle/mod/glossary/edit.php

193 lines
7.3 KiB
PHP
Raw Normal View History

<?php
require_once('../../config.php');
require_once('lib.php');
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
require_once('edit_form.php');
$cmid = required_param('cmid', PARAM_INT); // Course Module ID
$id = optional_param('id', 0, PARAM_INT); // EntryID
if (!$cm = get_coursemodule_from_id('glossary', $cmid)) {
2008-06-06 03:15:53 +00:00
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
2008-06-06 03:15:53 +00:00
print_error('coursemisconf');
}
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
2008-06-06 03:15:53 +00:00
print_error('invalidid', 'glossary');
}
$url = new moodle_url('/mod/glossary/edit.php', array('cmid'=>$cm->id));
if (!empty($id)) {
$url->param('id', $id);
}
$PAGE->set_url($url);
if ($id) { // if entry is specified
if (isguestuser()) {
print_error('guestnoedit', 'glossary', "$CFG->wwwroot/mod/glossary/view.php?id=$cmid");
}
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id, 'glossaryid'=>$glossary->id))) {
2008-06-06 03:15:53 +00:00
print_error('invalidentry');
}
$ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
if (!has_capability('mod/glossary:manageentries', $context) and !($entry->userid == $USER->id and ($ineditperiod and has_capability('mod/glossary:write', $context)))) {
if ($USER->id != $fromdb->userid) {
print_error('errcannoteditothers', 'glossary', "view.php?id=$cm->id&amp;mode=entry&amp;hook=$id");
} elseif (!$ineditperiod) {
print_error('erredittimeexpired', 'glossary', "view.php?id=$cm->id&amp;mode=entry&amp;hook=$id");
}
}
//prepare extra data
if ($aliases = $DB->get_records_menu("glossary_alias", array("entryid"=>$id), '', 'id, alias')) {
$entry->aliases = implode("\n", $aliases) . "\n";
}
if ($categoriesarr = $DB->get_records_menu("glossary_entries_categories", array('entryid'=>$id), '', 'id, categoryid')) {
// TODO: this fetches cats from both main and secondary glossary :-(
$entry->categories = array_values($categoriesarr);
}
} else { // new entry
require_capability('mod/glossary:write', $context);
// note: guest user does not have any write capability
$entry = new stdClass();
$entry->id = null;
}
$maxfiles = 99; // TODO: add some setting
$maxbytes = $course->maxbytes; // TODO: add some setting
$definitionoptions = array('trusttext'=>true, 'subdirs'=>false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes, 'context'=>$context);
$attachmentoptions = array('subdirs'=>false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
$entry = file_prepare_standard_editor($entry, 'definition', $definitionoptions, $context, 'mod_glossary', 'entry', $entry->id);
$entry = file_prepare_standard_filemanager($entry, 'attachment', $attachmentoptions, $context, 'mod_glossary', 'attachment', $entry->id);
$entry->cmid = $cm->id;
// create form and set initial data
$mform = new mod_glossary_entry_form(null, array('current'=>$entry, 'cm'=>$cm, 'glossary'=>$glossary,
'definitionoptions'=>$definitionoptions, 'attachmentoptions'=>$attachmentoptions));
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
if ($mform->is_cancelled()){
if ($id){
2010-07-18 08:39:58 +00:00
redirect("view.php?id=$cm->id&mode=entry&hook=$id");
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
} else {
redirect("view.php?id=$cm->id");
}
} else if ($entry = $mform->get_data()) {
$timenow = time();
$categories = empty($entry->categories) ? array() : $entry->categories;
unset($entry->categories);
$aliases = trim($entry->aliases);
unset($entry->aliases);
if (empty($entry->id)) {
$entry->glossaryid = $glossary->id;
$entry->timecreated = $timenow;
$entry->userid = $USER->id;
$entry->timecreated = $timenow;
$entry->sourceglossaryid = 0;
$entry->teacherentry = has_capability('mod/glossary:manageentries', $context);
}
2005-01-19 12:02:52 +00:00
$entry->concept = trim($entry->concept);
$entry->definition = ''; // updated later
$entry->definitionformat = FORMAT_HTML; // updated later
$entry->definitiontrust = 0; // updated later
$entry->timemodified = $timenow;
$entry->approved = 0;
$entry->usedynalink = isset($entry->usedynalink) ? $entry->usedynalink : 0;
$entry->casesensitive = isset($entry->casesensitive) ? $entry->casesensitive : 0;
$entry->fullmatch = isset($entry->fullmatch) ? $entry->fullmatch : 0;
if ($glossary->defaultapproval or has_capability('mod/glossary:approve', $context)) {
$entry->approved = 1;
}
if (empty($entry->id)) {
//new entry
$entry->id = $DB->insert_record('glossary_entries', $entry);
// Update completion state
$completion = new completion_info($course);
if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries && $entry->approved) {
$completion->update_state($cm, COMPLETION_COMPLETE);
}
add_to_log($course->id, "glossary", "add entry",
2009-04-20 10:49:31 +00:00
"view.php?id=$cm->id&amp;mode=entry&amp;hook=$entry->id", $entry->id, $cm->id);
} else {
//existing entry
$DB->update_record('glossary_entries', $entry);
add_to_log($course->id, "glossary", "update entry",
"view.php?id=$cm->id&amp;mode=entry&amp;hook=$entry->id",
$entry->id, $cm->id);
}
// save and relink embedded images and save attachments
$entry = file_postupdate_standard_editor($entry, 'definition', $definitionoptions, $context, 'mod_glossary', 'entry', $entry->id);
$entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $context, 'mod_glossary', 'attachment', $entry->id);
// store the updated value values
$DB->update_record('glossary_entries', $entry);
//refetch complete entry
$entry = $DB->get_record('glossary_entries', array('id'=>$entry->id));
// update entry categories
$DB->delete_records('glossary_entries_categories', array('entryid'=>$entry->id));
// TODO: this deletes cats from both both main and secondary glossary :-(
if (!empty($categories) and array_search(0, $categories) === false) {
foreach ($categories as $catid) {
$newcategory = new stdClass();
$newcategory->entryid = $entry->id;
$newcategory->categoryid = $catid;
$DB->insert_record('glossary_entries_categories', $newcategory, false);
2003-11-05 00:06:31 +00:00
}
}
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
// update aliases
$DB->delete_records('glossary_alias', array('entryid'=>$entry->id));
if ($aliases !== '') {
$aliases = explode("\n", $aliases);
foreach ($aliases as $alias) {
$alias = trim($alias);
if ($alias !== '') {
$newalias = new stdClass();
$newalias->entryid = $entry->id;
$newalias->alias = $alias;
$DB->insert_record('glossary_alias', $newalias, false);
2003-11-05 00:06:31 +00:00
}
}
2004-08-22 10:42:39 +00:00
}
2010-07-18 08:39:58 +00:00
redirect("view.php?id=$cm->id&mode=entry&hook=$entry->id");
}
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
if (!empty($id)) {
$PAGE->navbar->add(get_string('edit'));
}
$PAGE->set_title(format_string($glossary->name));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($glossary->name));
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
$mform->display();
echo $OUTPUT->footer();