|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 require_once("../../config.php"); 00004 require_once("lib.php"); 00005 00006 $id = required_param('id', PARAM_INT); // course module ID 00007 $confirm = optional_param('confirm', 0, PARAM_INT); // commit the operation? 00008 $entry = optional_param('entry', 0, PARAM_INT); // entry id 00009 $prevmode = required_param('prevmode', PARAM_ALPHA); 00010 $hook = optional_param('hook', '', PARAM_CLEAN); 00011 00012 $url = new moodle_url('/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode)); 00013 if ($confirm !== 0) { 00014 $url->param('confirm', $confirm); 00015 } 00016 if ($entry !== 0) { 00017 $url->param('entry', $entry); 00018 } 00019 if ($hook !== '') { 00020 $url->param('hook', $hook); 00021 } 00022 $PAGE->set_url($url); 00023 00024 $strglossary = get_string("modulename", "glossary"); 00025 $strglossaries = get_string("modulenameplural", "glossary"); 00026 $stredit = get_string("edit"); 00027 $entrydeleted = get_string("entrydeleted","glossary"); 00028 00029 00030 if (! $cm = get_coursemodule_from_id('glossary', $id)) { 00031 print_error("invalidcoursemodule"); 00032 } 00033 00034 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 00035 print_error('coursemisconf'); 00036 } 00037 00038 if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) { 00039 print_error('invalidentry'); 00040 } 00041 00042 require_login($course->id, false, $cm); 00043 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00044 $manageentries = has_capability('mod/glossary:manageentries', $context); 00045 00046 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { 00047 print_error('invalidid', 'glossary'); 00048 } 00049 00050 00051 $strareyousuredelete = get_string("areyousuredelete","glossary"); 00052 00053 if (($entry->userid != $USER->id) and !$manageentries) { // guest id is never matched, no need for special check here 00054 print_error('nopermissiontodelentry'); 00055 } 00056 $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); 00057 if (!$ineditperiod and !$manageentries) { 00058 print_error('errdeltimeexpired', 'glossary'); 00059 } 00060 00062 00063 if ($confirm and confirm_sesskey()) { // the operation was confirmed. 00064 // if it is an imported entry, just delete the relation 00065 00066 if ($entry->sourceglossaryid) { 00067 if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) { 00068 print_error('invalidcoursemodule'); 00069 } 00070 $newcontext = get_context_instance(CONTEXT_MODULE, $newcm->id); 00071 00072 $entry->glossaryid = $entry->sourceglossaryid; 00073 $entry->sourceglossaryid = 0; 00074 $DB->update_record('glossary_entries', $entry); 00075 00076 // move attachments too 00077 $fs = get_file_storage(); 00078 00079 if ($oldfiles = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id)) { 00080 foreach ($oldfiles as $oldfile) { 00081 $file_record = new stdClass(); 00082 $file_record->contextid = $newcontext->id; 00083 $fs->create_file_from_storedfile($file_record, $oldfile); 00084 } 00085 $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id); 00086 $entry->attachment = '1'; 00087 } else { 00088 $entry->attachment = '0'; 00089 } 00090 $DB->update_record('glossary_entries', $entry); 00091 00092 } else { 00093 $fs = get_file_storage(); 00094 $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id); 00095 $DB->delete_records("comments", array('itemid'=>$entry->id, 'commentarea'=>'glossary_entry', 'contextid'=>$context->id)); 00096 $DB->delete_records("glossary_alias", array("entryid"=>$entry->id)); 00097 $DB->delete_records("glossary_entries", array("id"=>$entry->id)); 00098 00099 // Update completion state 00100 $completion = new completion_info($course); 00101 if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) { 00102 $completion->update_state($cm, COMPLETION_INCOMPLETE, $entry->userid); 00103 } 00104 00105 //delete glossary entry ratings 00106 require_once($CFG->dirroot.'/rating/lib.php'); 00107 $delopt = new stdClass; 00108 $delopt->contextid = $context->id; 00109 $delopt->component = 'mod_glossary'; 00110 $delopt->ratingarea = 'entry'; 00111 $delopt->itemid = $entry->id; 00112 $rm = new rating_manager(); 00113 $rm->delete_ratings($delopt); 00114 } 00115 00116 add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry->id,$cm->id); 00117 redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook"); 00118 00119 } else { // the operation has not been confirmed yet so ask the user to do so 00120 $PAGE->navbar->add(get_string('delete')); 00121 $PAGE->set_title(format_string($glossary->name)); 00122 $PAGE->set_heading($course->fullname); 00123 echo $OUTPUT->header(); 00124 $areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>"; 00125 $linkyes = 'deleteentry.php'; 00126 $linkno = 'view.php'; 00127 $optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook); 00128 $optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook); 00129 00130 echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno)); 00131 00132 echo $OUTPUT->footer(); 00133 }