MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / glossary / exportentry.php
blobfd03e01c89e1e61effcf89c1ef48f8a5566b85ff
1 <?php // $Id$
2 require_once('../../config.php');
3 require_once('lib.php');
5 $id = required_param('id', PARAM_INT); // course module ID
6 $entry = required_param('entry', PARAM_INT); // Entry ID
7 $confirm = optional_param('confirm', 0, PARAM_INT); // confirmation
9 $hook = optional_param('hook', '', PARAM_ALPHANUM);
10 $mode = optional_param('mode', '', PARAM_ALPHA);
12 global $USER, $CFG;
14 $PermissionGranted = 1;
16 $cm = get_coursemodule_from_id('glossary', $id);
17 if ( ! $cm ) {
18 $PermissionGranted = 0;
19 } else {
20 $mainglossary = get_record('glossary','course',$cm->course, 'mainglossary',1);
21 if ( ! $mainglossary ) {
22 $PermissionGranted = 0;
26 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
27 require_capability('mod/glossary:export', $context);
29 if (! $course = get_record('course', 'id', $cm->course)) {
30 error('Course is misconfigured');
33 if (! $glossary = get_record('glossary', 'id', $cm->instance)) {
34 error('Course module is incorrect');
37 $strglossaries = get_string('modulenameplural', 'glossary');
38 $entryalreadyexist = get_string('entryalreadyexist','glossary');
39 $entryexported = get_string('entryexported','glossary');
41 $navlinks = array();
42 $navlinks[] = array('name' => $strglossaries, 'link' => "index.php?id=$course->id", 'type' => 'activity');
43 $navlinks[] = array('name' => format_string($glossary->name), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
45 $navigation = build_navigation($navlinks);
47 print_header_simple(format_string($glossary->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
49 if ( $PermissionGranted ) {
50 $entry = get_record('glossary_entries', 'id', $entry);
52 if ( !$confirm ) {
53 echo '<div class="boxaligncenter">';
54 $areyousure = get_string('areyousureexport','glossary');
55 notice_yesno ('<h2>'.format_string($entry->concept).'</h2><p align="center">'.$areyousure.'<br /><b>'.format_string($mainglossary->name).'</b>?',
56 'exportentry.php?id='.$id.'&amp;mode='.$mode.'&amp;hook='.$hook.'&amp;entry='.$entry->id.'&amp;confirm=1',
57 'view.php?id='.$cm->id.'&amp;mode='.$mode.'&amp;hook='.$hook);
58 echo '</div>';
59 } else {
60 if ( ! $mainglossary->allowduplicatedentries ) {
61 $dupentry = get_record('glossary_entries','glossaryid', $mainglossary->id, 'lower(concept)',moodle_strtolower(addslashes($entry->concept)));
62 if ( $dupentry ) {
63 $PermissionGranted = 0;
66 if ( $PermissionGranted ) {
68 $dbentry = new stdClass;
69 $dbentry->id = $entry->id;
70 $dbentry->glossaryid = $mainglossary->id;
71 $dbentry->sourceglossaryid = $glossary->id;
73 if (! update_record('glossary_entries', $dbentry)) {
74 error('Could not export the entry to the main glossary');
75 } else {
76 print_simple_box_start('center', '60%');
77 echo '<p align="center"><font size="3">'.$entryexported.'</font></p></font>';
79 print_continue('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
80 print_simple_box_end();
82 print_footer();
84 redirect('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
85 die;
87 } else {
88 print_simple_box_start('center', '60%', '#FFBBBB');
89 echo '<p align="center"><font size="3">'.$entryalreadyexist.'</font></p></font>';
90 echo '<p align="center">';
92 print_continue('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
94 print_simple_box_end();
97 } else {
98 print_simple_box_start('center', '60%', '#FFBBBB');
99 notice('A weird error was found while trying to export this entry. Operation cancelled.');
101 print_continue('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
103 print_simple_box_end();
106 print_footer();