Automatic installer.php lang files by installer_builder (20070313)
[moodle.git] / mod / glossary / exportentry.php
blob378e1df680692dd92f3a41e61e60e0a4ea4508cc
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 if ($CFG->dbtype == 'postgres7' ) {
27 $lcase = 'lower';
28 } else {
29 $lcase = 'lcase';
32 if ( !isteacher($cm->course) ) {
33 $PermissionGranted = 0;
34 error('You must be a teacher to use this page.');
37 if (! $course = get_record('course', 'id', $cm->course)) {
38 error('Course is misconfigured');
41 if (! $glossary = get_record('glossary', 'id', $cm->instance)) {
42 error('Course module is incorrect');
45 $strglossaries = get_string('modulenameplural', 'glossary');
46 $entryalreadyexist = get_string('entryalreadyexist','glossary');
47 $entryexported = get_string('entryexported','glossary');
49 print_header_simple(format_string($glossary->name), '',
50 '<a href="index.php?id='.$course->id.'">'.$strglossaries.'</a> -> '.format_string($glossary->name),
51 '', '', true, '',
52 navmenu($course, $cm));
54 if ( $PermissionGranted ) {
55 $entry = get_record('glossary_entries', 'id', $entry);
57 if ( !$confirm ) {
58 echo '<center>';
59 $areyousure = get_string('areyousureexport','glossary');
60 notice_yesno ('<center><h2>'.format_string($entry->concept).'</h2><p align="center">'.$areyousure.'<br /><b>'.format_string($mainglossary->name).'</b>?',
61 'exportentry.php?id='.$id.'&amp;mode='.$mode.'&amp;hook='.$hook.'&amp;entry='.$entry->id.'&amp;confirm=1',
62 'view.php?id='.$cm->id.'&amp;mode='.$mode.'&amp;hook='.$hook);
64 } else {
65 if ( ! $mainglossary->allowduplicatedentries ) {
66 $dupentry = get_record('glossary_entries','glossaryid', $mainglossary->id, $lcase.'(concept)',moodle_strtolower(addslashes($entry->concept)));
67 if ( $dupentry ) {
68 $PermissionGranted = 0;
71 if ( $PermissionGranted ) {
73 $dbentry = new stdClass;
74 $dbentry->id = $entry->id;
75 $dbentry->glossaryid = $mainglossary->id;
76 $dbentry->sourceglossaryid = $glossary->id;
78 if (! update_record('glossary_entries', $dbentry)) {
79 error('Could not export the entry to the main glossary');
80 } else {
81 print_simple_box_start('center', '60%');
82 echo '<p align="center"><font size="3">'.$entryexported.'</font></p></font>';
84 print_continue('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
85 print_simple_box_end();
87 print_footer();
89 redirect('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
90 die;
92 } else {
93 print_simple_box_start('center', '60%', '#FFBBBB');
94 echo '<p align="center"><font size="3">'.$entryalreadyexist.'</font></p></font>';
95 echo '<p align="center">';
97 print_continue('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
99 print_simple_box_end();
102 } else {
103 print_simple_box_start('center', '60%', '#FFBBBB');
104 notice('A weird error was found while trying to export this entry. Operation cancelled.');
106 print_continue('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
108 print_simple_box_end();
111 print_footer();