9
9
optional_variable($e); // EntryID
10
10
optional_variable($confirm,0); // proceed. Edit the edtry
12
optional_variable($mode); // categories if by category?
13
optional_variable($hook); // CategoryID
12
$mode = optional_param('mode'); // categories if by category?
13
$hook = optional_param('hook'); // CategoryID
15
15
if (! $cm = get_record("course_modules", "id", $id)) {
16
16
error("Course Module ID was incorrect");
29
29
if (! $glossary = get_record("glossary", "id", $cm->instance)) {
30
30
error("Course module is incorrect");
33
if (!$glossary->studentcanpost && !isteacher($glossary->course)) {
34
error("You can't add/edit entries to this glossary!");
33
37
$form = data_submitted();
34
38
if ( !isset($form->usedynalink) ) {
41
45
$form->fullmatch = 0;
44
$form->text = clean_text($form->text, $form->format);
48
//$form->text = clean_text($form->text, $form->format);
46
50
$newentry->course = $glossary->course;
47
51
$newentry->glossaryid = $glossary->id;
49
$newentry->concept = trim($form->concept);
53
$newentry->concept = clean_text(trim($form->concept));
50
54
$newentry->definition = $form->text;
51
55
$newentry->format = $form->format;
52
56
$newentry->usedynalink = $form->usedynalink;
53
57
$newentry->casesensitive = $form->casesensitive;
54
58
$newentry->fullmatch = $form->fullmatch;
55
$newentry->timemodified = $timenow;
59
$newentry->timemodified = $timenow;
56
60
$newentry->approved = 0;
57
61
if ( $glossary->defaultapproval or isteacher($course->id) ) {
58
62
$newentry->approved = 1;
67
71
if ($usehtmleditor = can_use_richtext_editor()) {
68
72
$defaultformat = FORMAT_HTML;
69
$onsubmit = "onsubmit=\"copyrichtext(form.text);\"";
71
74
$defaultformat = FORMAT_MOODLE;
75
print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
76
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->
77
<A HREF=\"index.php?id=$course->id\">$strglossaries</A> ->
77
print_header_simple(strip_tags("$glossary->name"), "",
78
"<A HREF=\"index.php?id=$course->id\">$strglossaries</A> ->
78
79
<A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "form.text",
79
80
"", true, "", navmenu($course, $cm));
91
//We are updating an entry, so we compare current session user with
92
//existing entry user to avoid some potential problems if secureforms=off
93
//Perhaps too much security? Anyway thanks to skodak (Bug 1823)
94
$old = get_record('glossary_entries', 'id', $e);
95
$ineditperiod = ((time() - $old->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
96
if ( (!$ineditperiod || $USER->id != $old->userid) and !isteacher($course->id) and $e) {
97
if ( $USER->id != $old->userid ) {
98
error("You can't edit other people's entries!");
99
} elseif (!$ineditperiod) {
100
error("You can't edit this. Time expired!");
90
105
$newentry->id = $e;
92
107
$permissiongranted = 1;
93
108
if ( !$glossary->allowduplicatedentries ) {
94
if ($dupentries = get_records("glossary_entries","UCASE(concept)", strtoupper($newentry->concept))) {
109
$ucase = db_uppercase();
110
if ($dupentries = get_records("glossary_entries","$ucase(concept)", strtoupper($newentry->concept))) {
95
111
foreach ($dupentries as $curentry) {
96
112
if ( $glossary->id == $curentry->glossaryid ) {
97
113
if ( $curentry->id != $e ) {
115
131
error("Could not update your glossary");
117
133
add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&mode=entry&hook=$newentry->id", $newentry->id,$cm->id);
120
136
error("Could not update this glossary entry because this concept already exist.");
125
141
$newentry->timecreated = $timenow;
126
142
$newentry->sourceglossaryid = 0;
127
143
$newentry->teacherentry = isteacher($course->id);
129
145
$permissiongranted = 1;
130
146
if ( !$glossary->allowduplicatedentries ) {
131
if ($dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept), "glossaryid", $glossary->id)) {
147
$ucase = db_uppercase();
148
if ($dupentries = get_record("glossary_entries","$ucase(concept)", strtoupper($newentry->concept), "glossaryid", $glossary->id)) {
132
149
$permissiongranted = 0;
168
185
if ( isset($form->aliases) ) {
169
if ( $aliases = explode("\n",$form->aliases) ) {
186
if ( $aliases = explode("\n",clean_text($form->aliases)) ) {
170
187
foreach ($aliases as $alias) {
171
188
$alias = trim($alias);
195
212
$newentry->casesensitive = $form->casesensitive;
196
213
$newentry->fullmatch = $form->fullmatch;
197
214
$newentry->aliases = "";
215
$newentry->userid = $form->userid;
216
$newentry->timecreated = $form->timecreated;
199
218
if ( $aliases = get_records("glossary_alias","entryid",$e) ) {
200
219
foreach ($aliases as $alias) {
223
242
$newentry->casesensitive = $CFG->glossary_casesensitive;
225
244
$newentry->casesensitive = 0;
228
247
if (!isset($newentry->fullmatch)) {
229
248
if (isset($CFG->glossary_fullmatch)) {
230
249
$newentry->fullmatch = $CFG->glossary_fullmatch;
232
251
$newentry->fullmatch = 0;
235
254
if (!isset($newentry->definition)) {
236
255
$newentry->definition = "";
257
if (!isset($newentry->timecreated)) {
258
$newentry->timecreated = 0;
260
if (!isset($newentry->userid)) {
261
$newentry->userid = $USER->id;
238
263
$strglossary = get_string("modulename", "glossary");
239
264
$strglossaries = get_string("modulenameplural", "glossary");
240
265
$stredit = get_string("edit");
242
267
if ($usehtmleditor = can_use_richtext_editor()) {
243
268
$defaultformat = FORMAT_HTML;
244
$onsubmit = "onsubmit=\"copyrichtext(form.text);\"";
246
270
$defaultformat = FORMAT_MOODLE;
250
print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
251
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->
252
<A HREF=\"index.php?id=$course->id\">$strglossaries</A> ->
273
print_header_simple(strip_tags("$glossary->name"), "",
274
"<A HREF=\"index.php?id=$course->id\">$strglossaries</A> ->
253
275
<A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "",
254
276
"", true, "", navmenu($course, $cm));
278
$ineditperiod = ((time() - $newentry->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
279
if ( (!$ineditperiod || $USER->id != $newentry->userid) and !isteacher($course->id) and $e) {
280
if ( $USER->id != $newentry->userid ) {
281
error("You can't edit other people's entries!");
282
} elseif (!$ineditperiod) {
283
error("You can't edit this. Time expired!");
256
288
echo '<p align="center"><font size="3"><b>' . stripslashes_safe($glossary->name);
257
289
echo '</b></font></p>';