2004-09-12 16:24:41 +00:00
|
|
|
<?php // $Id$
|
2005-10-05 18:27:40 +00:00
|
|
|
require_once('../../config.php');
|
|
|
|
require_once('lib.php');
|
2004-08-21 20:20:58 +00:00
|
|
|
|
2005-12-07 06:21:58 +00:00
|
|
|
$id = required_param('id', PARAM_INT); // course module ID
|
2006-03-08 00:08:51 +00:00
|
|
|
$entry = required_param('entry', PARAM_INT); // Entry ID
|
2005-12-07 06:21:58 +00:00
|
|
|
$confirm = optional_param('confirm', 0, PARAM_INT); // confirmation
|
2004-08-29 22:57:41 +00:00
|
|
|
|
2005-12-07 06:21:58 +00:00
|
|
|
$hook = optional_param('hook', '', PARAM_ALPHANUM);
|
|
|
|
$mode = optional_param('mode', '', PARAM_ALPHA);
|
2004-08-21 20:20:58 +00:00
|
|
|
|
2005-02-17 08:38:50 +00:00
|
|
|
global $USER, $CFG;
|
2004-08-21 20:20:58 +00:00
|
|
|
|
|
|
|
$PermissionGranted = 1;
|
|
|
|
|
2006-08-08 22:09:55 +00:00
|
|
|
$cm = get_coursemodule_from_id('glossary', $id);
|
2004-08-21 20:20:58 +00:00
|
|
|
if ( ! $cm ) {
|
|
|
|
$PermissionGranted = 0;
|
|
|
|
} else {
|
2008-08-17 11:18:21 +00:00
|
|
|
$mainglossary = $DB->get_record('glossary', array('course'=>$cm->course, 'mainglossary'=>1));
|
2004-08-21 20:20:58 +00:00
|
|
|
if ( ! $mainglossary ) {
|
|
|
|
$PermissionGranted = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-10-22 17:03:37 +00:00
|
|
|
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-08-14 05:55:40 +00:00
|
|
|
require_capability('mod/glossary:export', $context);
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2008-06-08 10:43:39 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
|
2008-06-06 03:15:53 +00:00
|
|
|
print_error('coursemisconf');
|
2003-09-16 03:07:21 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 10:43:39 +00:00
|
|
|
if (! $glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
|
2008-06-06 03:15:53 +00:00
|
|
|
print_error('invalidid', 'glossary');
|
2003-09-16 03:07:21 +00:00
|
|
|
}
|
|
|
|
|
2005-10-05 18:27:40 +00:00
|
|
|
$strglossaries = get_string('modulenameplural', 'glossary');
|
|
|
|
$entryalreadyexist = get_string('entryalreadyexist','glossary');
|
|
|
|
$entryexported = get_string('entryexported','glossary');
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation('', $cm);
|
2007-04-16 21:16:38 +00:00
|
|
|
print_header_simple(format_string($glossary->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2004-08-21 20:20:58 +00:00
|
|
|
if ( $PermissionGranted ) {
|
2008-06-08 10:43:39 +00:00
|
|
|
$entry = $DB->get_record('glossary_entries', array('id'=>$entry));
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2004-08-21 20:20:58 +00:00
|
|
|
if ( !$confirm ) {
|
2007-01-12 06:57:33 +00:00
|
|
|
echo '<div class="boxaligncenter">';
|
2005-10-05 18:27:40 +00:00
|
|
|
$areyousure = get_string('areyousureexport','glossary');
|
2007-01-12 06:57:33 +00:00
|
|
|
notice_yesno ('<h2>'.format_string($entry->concept).'</h2><p align="center">'.$areyousure.'<br /><b>'.format_string($mainglossary->name).'</b>?',
|
2005-10-05 18:27:40 +00:00
|
|
|
'exportentry.php?id='.$id.'&mode='.$mode.'&hook='.$hook.'&entry='.$entry->id.'&confirm=1',
|
|
|
|
'view.php?id='.$cm->id.'&mode='.$mode.'&hook='.$hook);
|
2007-01-12 06:57:33 +00:00
|
|
|
echo '</div>';
|
2004-08-21 20:20:58 +00:00
|
|
|
} else {
|
|
|
|
if ( ! $mainglossary->allowduplicatedentries ) {
|
2008-06-08 10:43:39 +00:00
|
|
|
$dupentry = $DB->get_record('glossary_entries', array('glossaryid'=>$mainglossary->id, 'lower(concept)'=>moodle_strtolower($entry->concept)));
|
2004-08-21 20:20:58 +00:00
|
|
|
if ( $dupentry ) {
|
|
|
|
$PermissionGranted = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $PermissionGranted ) {
|
2005-10-05 18:27:40 +00:00
|
|
|
|
|
|
|
$dbentry = new stdClass;
|
|
|
|
$dbentry->id = $entry->id;
|
|
|
|
$dbentry->glossaryid = $mainglossary->id;
|
|
|
|
$dbentry->sourceglossaryid = $glossary->id;
|
2003-09-29 03:06:30 +00:00
|
|
|
|
2008-06-08 10:43:39 +00:00
|
|
|
if (! $DB->update_record('glossary_entries', $dbentry)) {
|
2008-06-06 03:15:53 +00:00
|
|
|
print_error('cantexportentry', 'glossary');
|
2004-08-21 20:20:58 +00:00
|
|
|
} else {
|
2005-10-05 18:27:40 +00:00
|
|
|
print_simple_box_start('center', '60%');
|
|
|
|
echo '<p align="center"><font size="3">'.$entryexported.'</font></p></font>';
|
2003-09-29 03:06:30 +00:00
|
|
|
|
2005-10-05 18:27:40 +00:00
|
|
|
print_continue('view.php?id='.$cm->id.'&mode=entry&hook='.$entry->id);
|
2003-09-29 03:06:30 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
|
2004-08-21 20:20:58 +00:00
|
|
|
print_footer();
|
2003-09-29 03:06:30 +00:00
|
|
|
|
2005-10-05 18:27:40 +00:00
|
|
|
redirect('view.php?id='.$cm->id.'&mode=entry&hook='.$entry->id);
|
2004-08-21 20:20:58 +00:00
|
|
|
die;
|
|
|
|
}
|
|
|
|
} else {
|
2005-10-05 18:27:40 +00:00
|
|
|
print_simple_box_start('center', '60%', '#FFBBBB');
|
|
|
|
echo '<p align="center"><font size="3">'.$entryalreadyexist.'</font></p></font>';
|
|
|
|
echo '<p align="center">';
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2005-10-05 18:27:40 +00:00
|
|
|
print_continue('view.php?id='.$cm->id.'&mode=entry&hook='.$entry->id);
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2004-08-21 20:20:58 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2005-10-05 18:27:40 +00:00
|
|
|
print_simple_box_start('center', '60%', '#FFBBBB');
|
|
|
|
notice('A weird error was found while trying to export this entry. Operation cancelled.');
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2005-10-05 18:27:40 +00:00
|
|
|
print_continue('view.php?id='.$cm->id.'&mode=entry&hook='.$entry->id);
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2004-08-21 20:20:58 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2004-08-21 20:20:58 +00:00
|
|
|
print_footer();
|
2003-09-16 18:51:40 +00:00
|
|
|
?>
|