[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 require_login($course, false, $cm); 43 $context = context_module::instance($cm->id); 44 $manageentries = has_capability('mod/glossary:manageentries', $context); 45 46 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { 47 print_error('invalidid', 'glossary'); 48 } 49 50 51 $strareyousuredelete = get_string("areyousuredelete","glossary"); 52 53 if (($entry->userid != $USER->id) and !$manageentries) { // guest id is never matched, no need for special check here 54 print_error('nopermissiontodelentry'); 55 } 56 $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); 57 if (!$ineditperiod and !$manageentries) { 58 print_error('errdeltimeexpired', 'glossary'); 59 } 60 61 /// If data submitted, then process and store. 62 63 if ($confirm and confirm_sesskey()) { // the operation was confirmed. 64 // if it is an imported entry, just delete the relation 65 66 $origentry = fullclone($entry); 67 if ($entry->sourceglossaryid) { 68 if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) { 69 print_error('invalidcoursemodule'); 70 } 71 $newcontext = context_module::instance($newcm->id); 72 73 $entry->glossaryid = $entry->sourceglossaryid; 74 $entry->sourceglossaryid = 0; 75 $DB->update_record('glossary_entries', $entry); 76 77 // move attachments too 78 $fs = get_file_storage(); 79 80 if ($oldfiles = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id)) { 81 foreach ($oldfiles as $oldfile) { 82 $file_record = new stdClass(); 83 $file_record->contextid = $newcontext->id; 84 $fs->create_file_from_storedfile($file_record, $oldfile); 85 } 86 $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id); 87 $entry->attachment = '1'; 88 } else { 89 $entry->attachment = '0'; 90 } 91 $DB->update_record('glossary_entries', $entry); 92 93 } else { 94 $fs = get_file_storage(); 95 $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id); 96 $DB->delete_records("comments", array('itemid'=>$entry->id, 'commentarea'=>'glossary_entry', 'contextid'=>$context->id)); 97 $DB->delete_records("glossary_alias", array("entryid"=>$entry->id)); 98 $DB->delete_records("glossary_entries", array("id"=>$entry->id)); 99 100 // Update completion state 101 $completion = new completion_info($course); 102 if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) { 103 $completion->update_state($cm, COMPLETION_INCOMPLETE, $entry->userid); 104 } 105 106 //delete glossary entry ratings 107 require_once($CFG->dirroot.'/rating/lib.php'); 108 $delopt = new stdClass; 109 $delopt->contextid = $context->id; 110 $delopt->component = 'mod_glossary'; 111 $delopt->ratingarea = 'entry'; 112 $delopt->itemid = $entry->id; 113 $rm = new rating_manager(); 114 $rm->delete_ratings($delopt); 115 } 116 117 // Delete cached RSS feeds. 118 if (!empty($CFG->enablerssfeeds)) { 119 require_once($CFG->dirroot.'/mod/glossary/rsslib.php'); 120 glossary_rss_delete_file($glossary); 121 } 122 123 $event = \mod_glossary\event\entry_deleted::create(array( 124 'context' => $context, 125 'objectid' => $origentry->id, 126 'other' => array( 127 'mode' => $prevmode, 128 'hook' => $hook, 129 'concept' => $origentry->concept 130 ) 131 )); 132 $event->add_record_snapshot('glossary_entries', $origentry); 133 $event->trigger(); 134 135 // Reset caches. 136 if ($entry->usedynalink and $entry->approved) { 137 \mod_glossary\local\concept_cache::reset_glossary($glossary); 138 } 139 140 redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook"); 141 142 } else { // the operation has not been confirmed yet so ask the user to do so 143 $PAGE->navbar->add(get_string('delete')); 144 $PAGE->set_title($glossary->name); 145 $PAGE->set_heading($course->fullname); 146 echo $OUTPUT->header(); 147 $areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>"; 148 $linkyes = 'deleteentry.php'; 149 $linkno = 'view.php'; 150 $optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook); 151 $optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook); 152 153 echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno)); 154 155 echo $OUTPUT->footer(); 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |