See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 3 require_once("../../config.php"); 4 require_once ("lib.php"); 5 6 $id = required_param('id', PARAM_INT); // course module ID 7 $confirm = optional_param('confirm', 0, PARAM_INT); // commit the operation? 8 $entry = optional_param('entry', 0, PARAM_INT); // entry id 9 $prevmode = required_param('prevmode', PARAM_ALPHA); 10 $hook = optional_param('hook', '', PARAM_CLEAN); 11 12 $url = new moodle_url('/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode)); 13 if ($confirm !== 0) { 14 $url->param('confirm', $confirm); 15 } 16 if ($entry !== 0) { 17 $url->param('entry', $entry); 18 } 19 if ($hook !== '') { 20 $url->param('hook', $hook); 21 } 22 $PAGE->set_url($url); 23 24 $strglossary = get_string("modulename", "glossary"); 25 $strglossaries = get_string("modulenameplural", "glossary"); 26 $stredit = get_string("edit"); 27 $entrydeleted = get_string("entrydeleted","glossary"); 28 29 30 if (! $cm = get_coursemodule_from_id('glossary', $id)) { 31 print_error("invalidcoursemodule"); 32 } 33 34 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 35 print_error('coursemisconf'); 36 } 37 38 if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) { 39 print_error('invalidentry'); 40 } 41 42 // Permission checks are based on the course module instance so make sure it is correct. 43 if ($cm->instance != $entry->glossaryid) { 44 print_error('invalidentry'); 45 } 46 47 require_login($course, false, $cm); 48 $context = context_module::instance($cm->id); 49 $manageentries = has_capability('mod/glossary:manageentries', $context); 50 51 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { 52 print_error('invalidid', 'glossary'); 53 } 54 55 56 $strareyousuredelete = get_string("areyousuredelete","glossary"); 57 58 if (($entry->userid != $USER->id) and !$manageentries) { // guest id is never matched, no need for special check here 59 print_error('nopermissiontodelentry'); 60 } 61 $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); 62 if (!$ineditperiod and !$manageentries) { 63 print_error('errdeltimeexpired', 'glossary'); 64 } 65 66 /// If data submitted, then process and store. 67 68 if ($confirm and confirm_sesskey()) { // the operation was confirmed. 69 // if it is an imported entry, just delete the relation 70 71 $origentry = fullclone($entry); 72 if ($entry->sourceglossaryid) { 73 if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) { 74 print_error('invalidcoursemodule'); 75 } 76 $newcontext = context_module::instance($newcm->id); 77 78 $entry->glossaryid = $entry->sourceglossaryid; 79 $entry->sourceglossaryid = 0; 80 $DB->update_record('glossary_entries', $entry); 81 82 // move attachments too 83 $fs = get_file_storage(); 84 85 if ($oldfiles = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id)) { 86 foreach ($oldfiles as $oldfile) { 87 $file_record = new stdClass(); 88 $file_record->contextid = $newcontext->id; 89 $fs->create_file_from_storedfile($file_record, $oldfile); 90 } 91 $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id); 92 $entry->attachment = '1'; 93 } else { 94 $entry->attachment = '0'; 95 } 96 $DB->update_record('glossary_entries', $entry); 97 98 } else { 99 $fs = get_file_storage(); 100 $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id); 101 $DB->delete_records("comments", array('itemid'=>$entry->id, 'commentarea'=>'glossary_entry', 'contextid'=>$context->id)); 102 $DB->delete_records("glossary_alias", array("entryid"=>$entry->id)); 103 $DB->delete_records("glossary_entries", array("id"=>$entry->id)); 104 105 // Update completion state 106 $completion = new completion_info($course); 107 if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) { 108 $completion->update_state($cm, COMPLETION_INCOMPLETE, $entry->userid); 109 } 110 111 //delete glossary entry ratings 112 require_once($CFG->dirroot.'/rating/lib.php'); 113 $delopt = new stdClass; 114 $delopt->contextid = $context->id; 115 $delopt->component = 'mod_glossary'; 116 $delopt->ratingarea = 'entry'; 117 $delopt->itemid = $entry->id; 118 $rm = new rating_manager(); 119 $rm->delete_ratings($delopt); 120 } 121 122 // Delete cached RSS feeds. 123 if (!empty($CFG->enablerssfeeds)) { 124 require_once($CFG->dirroot.'/mod/glossary/rsslib.php'); 125 glossary_rss_delete_file($glossary); 126 } 127 128 core_tag_tag::remove_all_item_tags('mod_glossary', 'glossary_entries', $origentry->id); 129 130 $event = \mod_glossary\event\entry_deleted::create(array( 131 'context' => $context, 132 'objectid' => $origentry->id, 133 'other' => array( 134 'mode' => $prevmode, 135 'hook' => $hook, 136 'concept' => $origentry->concept 137 ) 138 )); 139 $event->add_record_snapshot('glossary_entries', $origentry); 140 $event->trigger(); 141 142 // Reset caches. 143 if ($entry->usedynalink and $entry->approved) { 144 \mod_glossary\local\concept_cache::reset_glossary($glossary); 145 } 146 147 redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook"); 148 149 } else { // the operation has not been confirmed yet so ask the user to do so 150 $PAGE->navbar->add(get_string('delete')); 151 $PAGE->set_title($glossary->name); 152 $PAGE->set_heading($course->fullname); 153 echo $OUTPUT->header(); 154 $areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>"; 155 $linkyes = 'deleteentry.php'; 156 $linkno = 'view.php'; 157 $optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook); 158 $optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook); 159 160 echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno)); 161 162 echo $OUTPUT->footer(); 163 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body