- 'editalways' applied to comments.
- some minor notices out.
- security bug solved:
+ users cannot edit any comment now.
+ users cannot delete any comment now.
+ users cannot edit any entry now.
+ users cannot delete any antry now.
Thanks to skodak, discovering the bug!!!
Merged from MOODLE_14_STABLE
/// Input section
if ( $action == "delete" ) {
+ if (($comment->userid <> $USER->id) and !isteacher($glossary->course)) {
+ error("You can't delete other people's comments!");
+ }
if ( $confirm ) {
delete_records("glossary_comments","id", $cid);
}
} else {
if ( $action == "edit" ) {
- if ( (time() - $comment->timemodified >= $CFG->maxeditingtime or
- $USER->id != $comment->userid) and !isteacher($course->id) ) {
- echo "<center><strong>";
+ $ineditperiod = ((time() - $comment->timemodified < $CFG->maxeditingtime) || $glossary->editalways);
+ if ( (!$ineditperiod || $USER->id != $comment->userid) and !isteacher($course->id) ) {
if ( $USER->id != $comment->userid ) {
- echo get_string("youarenottheauthor","glossary",$CFG->maxeditingtime);
+ error("You can't edit other people's comments!");
} elseif (time() - $comment->timemodified >= $CFG->maxeditingtime ) {
- echo get_string("maxtimehaspassed","glossary",$CFG->maxeditingtime);
+ error("You can't edit this. Time expired!");
}
- echo "</strong></center>";
- print_footer($course);
die;
}
}
"", "", true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
+ $entry = get_record("glossary_entries","id", $entry);
+
+ if (($entry->userid <> $USER->id) and !isteacher($course->id)) {
+ error("You can't delete other people's entries!");
+ }
+
/// If data submitted, then process and store.
if ($confirm) { // the operation was confirmed.
// if it is an imported entry, just delete the relation
- $entry = get_record("glossary_entries","id", $entry);
if ( $entry->sourceglossaryid ) {
$entry->glossaryid = $entry->sourceglossaryid;
} else { // the operation has not been confirmed yet so ask the user to do so
notice_yesno("<b>$entryfields->concept</b><p>$strareyousuredelete</p>",
- "deleteentry.php?id=$cm->id&mode=delete&confirm=1&entry=".s($entry)."&prevmode=$prevmode&hook=$hook",
+ "deleteentry.php?id=$cm->id&mode=delete&confirm=1&entry=".s($entry->concept)."&prevmode=$prevmode&hook=$hook",
"view.php?id=$cm->id&mode=$prevmode&hook=$hook");
}
$newentry->casesensitive = $form->casesensitive;
$newentry->fullmatch = $form->fullmatch;
$newentry->aliases = "";
+ $newentry->userid = $form->userid;
+ $newentry->timemodified = $form->timemodified;
if ( $aliases = get_records("glossary_alias","entryid",$e) ) {
foreach ($aliases as $alias) {
if (!isset($newentry->definition)) {
$newentry->definition = "";
}
+if (!isset($newentry->timemodified)) {
+ $newentry->timemodified = 0;
+}
$strglossary = get_string("modulename", "glossary");
$strglossaries = get_string("modulenameplural", "glossary");
$stredit = get_string("edit");
<A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "",
"", true, "", navmenu($course, $cm));
+$ineditperiod = ((time() - $newentry->timemodified < $CFG->maxeditingtime) || $glossary->editalways);
+if ( (!$ineditperiod || $USER->id != $newentry->userid) and !isteacher($course->id) and $e) {
+ if ( $USER->id != $newentry->userid ) {
+ error("You can't edit other people's entries!");
+ } elseif (!$ineditperiod) {
+ error("You can't edit this. Time expired!");
+ }
+ die;
+ }
+
echo '<p align="center"><font size="3"><b>' . stripslashes_safe($glossary->name);
echo '</b></font></p>';
//Decide if an entry is editable:
// -It isn't a imported entry (so nobody can edit a imported (from secondary to main) entry)) and
// -The user is teacher or he is a student with time permissions (edit period or editalways defined).
- $ineditperiod = (time() - $entry->timemodified < $CFG->maxeditingtime);
- if ( !$importedentry and ($isteacher or ($entry->userid == $USER->id and ($glossary->editalways or $ineditperiod)))) {
+ $ineditperiod = ((time() - $entry->timemodified < $CFG->maxeditingtime) || $glossary->editalways);
+ if ( !$importedentry and ($isteacher or ($entry->userid == $USER->id and $ineditperiod))) {
$return .= " <a title=\"" . get_string("delete") . "\" href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&prevmode=$mode&hook=$hook\"><img src=\"";
$return .= $icon;
$return .= "\" height=11 width=11 border=0></a> ";
echo format_text($comment->comment, $comment->format);
echo "<div align=right><p align=right>";
- if ( (time() - $comment->timemodified < $CFG->maxeditingtime and $USER->id == $comment->userid) or isteacher($course->id) ) {
+ $ineditperiod = ((time() - $comment->timemodified < $CFG->maxeditingtime) || $glossary->editalways);
+ if ( ($ineditperiod && $USER->id == $comment->userid) or isteacher($course->id) ) {
echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id&cid=$comment->id&action=edit\"><img
alt=\"" . get_string("edit") . "\" src=\"$CFG->pixpath/t/edit.gif\" height=11 width=11 border=0></a> ";
}