Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/glossary/exportentry.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require_once('../../config.php');
00004 require_once('lib.php');
00005 
00006 $id       = required_param('id', PARAM_INT);          // Entry ID
00007 $confirm  = optional_param('confirm', 0, PARAM_BOOL); // export confirmation
00008 $prevmode = required_param('prevmode', PARAM_ALPHA);
00009 $hook     = optional_param('hook', '', PARAM_CLEAN);
00010 
00011 $url = new moodle_url('/mod/glossary/exportentry.php', array('id'=>$id,'prevmode'=>$prevmode));
00012 if ($confirm !== 0) {
00013     $url->param('confirm', $confirm);
00014 }
00015 if ($hook !== 'ALL') {
00016     $url->param('hook', $hook);
00017 }
00018 $PAGE->set_url($url);
00019 
00020 if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id))) {
00021     print_error('invalidentry');
00022 }
00023 
00024 if ($entry->sourceglossaryid) {
00025     //already exported
00026     if (!$cm = get_coursemodule_from_id('glossary', $entry->sourceglossaryid)) {
00027         print_error('invalidcoursemodule');
00028     }
00029     redirect('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
00030 }
00031 
00032 if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
00033     print_error('invalidcoursemodule');
00034 }
00035 
00036 if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
00037     print_error('invalidid', 'glossary');
00038 }
00039 
00040 if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
00041     print_error('coursemisconf');
00042 }
00043 
00044 require_course_login($course->id, true, $cm);
00045 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
00046 require_capability('mod/glossary:export', $context);
00047 
00048 $returnurl = "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=".urlencode($hook);
00049 
00050 if (!$mainglossary = $DB->get_record('glossary', array('course'=>$cm->course, 'mainglossary'=>1))) {
00051     //main glossary not present
00052     redirect($returnurl);
00053 }
00054 
00055 if (!$maincm = get_coursemodule_from_instance('glossary', $mainglossary->id)) {
00056     print_error('invalidcoursemodule');
00057 }
00058 
00059 $context     = get_context_instance(CONTEXT_MODULE, $cm->id);
00060 $maincontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
00061 
00062 if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
00063     print_error('coursemisconf');
00064 }
00065 
00066 
00067 $strglossaries     = get_string('modulenameplural', 'glossary');
00068 $entryalreadyexist = get_string('entryalreadyexist','glossary');
00069 $entryexported     = get_string('entryexported','glossary');
00070 
00071 if (!$mainglossary->allowduplicatedentries) {
00072     if ($DB->record_exists_select('glossary_entries',
00073             'glossaryid = :glossaryid AND LOWER(concept) = :concept', array(
00074                 'glossaryid' => $mainglossary->id,
00075                 'concept'    => moodle_strtolower($entry->concept)))) {
00076         $PAGE->set_title(format_string($glossary->name));
00077         $PAGE->set_heading($course->fullname);
00078         echo $OUTPUT->header();
00079         echo $OUTPUT->notification(get_string('errconceptalreadyexists', 'glossary'));
00080         echo $OUTPUT->continue_button($returnurl);
00081         echo $OUTPUT->box_end();
00082         echo $OUTPUT->footer();
00083         die;
00084     }
00085 }
00086 
00087 if (!data_submitted() or !$confirm or !confirm_sesskey()) {
00088     $PAGE->set_title(format_string($glossary->name));
00089     $PAGE->set_heading(format_string($course->fullname));
00090     echo $OUTPUT->header();
00091     echo '<div class="boxaligncenter">';
00092     $areyousure = '<h2>'.format_string($entry->concept).'</h2><p align="center">'.get_string('areyousureexport','glossary').'<br /><b>'.format_string($mainglossary->name).'</b>?';
00093     $linkyes    = 'exportentry.php';
00094     $linkno     = 'view.php';
00095     $optionsyes = array('id'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
00096     $optionsno  = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
00097 
00098     echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
00099     echo '</div>';
00100     echo $OUTPUT->footer();
00101     die;
00102 
00103 } else {
00104     $entry->glossaryid       = $mainglossary->id;
00105     $entry->sourceglossaryid = $glossary->id;
00106 
00107     $DB->update_record('glossary_entries', $entry);
00108 
00109     // move attachments too
00110     $fs = get_file_storage();
00111 
00112     if ($oldfiles = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id)) {
00113         foreach ($oldfiles as $oldfile) {
00114             $file_record = new stdClass();
00115             $file_record->contextid = $maincontext->id;
00116             $fs->create_file_from_storedfile($file_record, $oldfile);
00117         }
00118         $fs->delete_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
00119         $entry->attachment = '1';
00120     } else {
00121         $entry->attachment = '0';
00122     }
00123     $DB->update_record('glossary_entries', $entry);
00124 
00125     redirect ($returnurl);
00126 }
00127 
 All Data Structures Namespaces Files Functions Variables Enumerations