3 require_once('../../config.php');
4 require_once('lib.php');
5 require_once('edit_form.php');
9 $id = required_param('id', PARAM_INT
); // Course Module ID
10 $e = optional_param('e', 0, PARAM_INT
); // EntryID
11 $confirm = optional_param('confirm',0, PARAM_INT
); // proceed. Edit the edtry
13 $mode = optional_param('mode', '', PARAM_ALPHA
); // categories if by category?
14 $hook = optional_param('hook', '', PARAM_ALPHANUM
); // CategoryID
16 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
17 error("Course Module ID was incorrect");
20 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
22 if (! $course = get_record("course", "id", $cm->course
)) {
23 error("Course is misconfigured");
26 require_login($course->id
, false, $cm);
29 error("Guests are not allowed to edit glossaries", $_SERVER["HTTP_REFERER"]);
32 if (! $glossary = get_record("glossary", "id", $cm->instance
)) {
33 error("Course module is incorrect");
37 if ($e) { // if entry is specified
38 if (!$entry = get_record("glossary_entries", "id", $e)) {
39 error("Incorrect entry id");
41 $ineditperiod = ((time() - $entry->timecreated
< $CFG->maxeditingtime
) ||
$glossary->editalways
);
42 if (!has_capability('mod/glossary:manageentries', $context) and !($entry->userid
== $USER->id
and ($ineditperiod and has_capability('mod/glossary:write', $context)))) {
43 //expired edit time is the most probable cause here
44 error(get_string('erredittimeexpired', 'glossary'), "view.php?id=$cm->id&mode=entry&hook=$e");
47 require_capability('mod/glossary:write', $context);
50 $mform =& new mod_glossary_entry_form(null, compact('cm', 'glossary', 'hook', 'mode', 'e', 'context'));
51 if ($mform->is_cancelled()){
53 redirect("view.php?id=$cm->id&mode=entry&hook=$e");
55 redirect("view.php?id=$cm->id");
58 } elseif ($fromform = $mform->get_data()) {
59 trusttext_after_edit($fromform->definition
, $context);
61 if ( !isset($fromform->usedynalink
) ) {
62 $fromform->usedynalink
= 0;
64 if ( !isset($fromform->casesensitive
) ) {
65 $fromform->casesensitive
= 0;
67 if ( !isset($fromform->fullmatch
) ) {
68 $fromform->fullmatch
= 0;
73 $todb->course
= $glossary->course
;
74 $todb->glossaryid
= $glossary->id
;
76 $todb->concept
= trim($fromform->concept
);
77 $todb->definition
= $fromform->definition
;
78 $todb->format
= $fromform->format
;
79 $todb->usedynalink
= $fromform->usedynalink
;
80 $todb->casesensitive
= $fromform->casesensitive
;
81 $todb->fullmatch
= $fromform->fullmatch
;
82 $todb->timemodified
= $timenow;
85 if ( $glossary->defaultapproval
or has_capability('mod/glossary:approve', $context) ) {
91 $dir = glossary_file_area_name($todb);
92 if ($mform->save_files($dir) and $newfilename = $mform->get_new_filename()) {
93 $todb->attachment
= $newfilename;
96 if (update_record('glossary_entries', $todb)) {
97 add_to_log($course->id
, "glossary", "update entry",
98 "view.php?id=$cm->id&mode=entry&hook=$todb->id",
101 error("Could not update your glossary");
105 $todb->userid
= $USER->id
;
106 $todb->timecreated
= $timenow;
107 $todb->sourceglossaryid
= 0;
108 $todb->teacherentry
= has_capability('mod/glossary:manageentries', $context);
111 if ($todb->id
= insert_record("glossary_entries", $todb)) {
113 $dir = glossary_file_area_name($todb);
114 if ($mform->save_files($dir) and $newfilename = $mform->get_new_filename()) {
115 set_field("glossary_entries", "attachment", $newfilename, "id", $todb->id
);
117 add_to_log($course->id
, "glossary", "add entry",
118 "view.php?id=$cm->id&mode=entry&hook=$todb->id", $todb->id
,$cm->id
);
120 error("Could not insert this new entry");
125 delete_records("glossary_entries_categories", "entryid", $e);
126 delete_records("glossary_alias", "entryid", $e);
128 if (empty($fromform->notcategorised
) && isset($fromform->categories
)) {
129 $newcategory->entryid
= $e;
130 foreach ($fromform->categories
as $category) {
131 if ( $category > 0 ) {
132 $newcategory->categoryid
= $category;
133 insert_record("glossary_entries_categories", $newcategory, false);
139 if ( isset($fromform->aliases
) ) {
140 if ( $aliases = explode("\n", $fromform->aliases
) ) {
141 foreach ($aliases as $alias) {
142 $alias = trim($alias);
145 $newalias->entryid
= $e;
146 $newalias->alias
= $alias;
147 insert_record("glossary_alias", $newalias, false);
152 redirect("view.php?id=$cm->id&mode=entry&hook=$todb->id");
156 $fromdb = get_record("glossary_entries", "id", $e);
158 $toform = new object();
160 if ($categoriesarr = get_records_menu("glossary_entries_categories", "entryid", $e, '', 'id, categoryid')){
161 $toform->categories
= array_values($categoriesarr);
163 $toform->categories
= array(0);
165 $toform->concept
= $fromdb->concept
;
166 $toform->definition
= $fromdb->definition
;
167 $toform->format
= $fromdb->format
;
168 trusttext_prepare_edit($toform->definition
, $toform->format
, can_use_html_editor(), $context);
169 $toform->approved
= $glossary->defaultapproval
or has_capability('mod/glossary:approve', $context);
170 $toform->usedynalink
= $fromdb->usedynalink
;
171 $toform->casesensitive
= $fromdb->casesensitive
;
172 $toform->fullmatch
= $fromdb->fullmatch
;
173 $toform->aliases
= '';
174 $ineditperiod = ((time() - $fromdb->timecreated
< $CFG->maxeditingtime
) ||
$glossary->editalways
);
175 if ((!$ineditperiod ||
$USER->id
!= $fromdb->userid
) and !has_capability('mod/glossary:manageentries', $context)) {
176 if ( $USER->id
!= $fromdb->userid
) {
177 error(get_string('errcannoteditothers', 'glossary'));
178 } elseif (!$ineditperiod) {
179 error(get_string('erredittimeexpired', 'glossary'));
184 if ( $aliases = get_records_menu("glossary_alias", "entryid", $e, '', 'id, alias') ) {
185 $toform->aliases
= implode("\n", $aliases) . "\n";
187 $mform->set_data($toform);
191 $strglossary = get_string("modulename", "glossary");
192 $strglossaries = get_string("modulenameplural", "glossary");
193 $stredit = empty($e) ?
get_string('addentry', 'glossary') : get_string("edit");
196 $navlinks[] = array('name' => $strglossaries, 'link' => "index.php?id=$course->id", 'type' => 'activity');
197 $navlinks[] = array('name' => format_string($glossary->name
), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
198 $navlinks[] = array('name' => $stredit, 'link' => '', 'type' => 'title');
200 $navigation = build_navigation($navlinks);
202 print_header_simple(format_string($glossary->name
), "", $navigation, "",
203 "", true, "", navmenu($course, $cm));
207 print_heading(format_string($glossary->name
));
211 ///if ( $glossary->intro ) {
212 /// print_simple_box(format_text($glossary->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
215 /// Tabbed browsing sections
216 ///$tab = GLOSSARY_ADDENTRY_VIEW;
217 ///include("tabs.php");
220 require_capability('mod/glossary:write', $context);
225 ///glossary_print_tabbed_table_end();
228 print_footer($course);