f7c1cd798c62b97b5fa011fe37b7d0c2705efd41
[atutor.git] / docs / mods / _core / modules / module_install_step_2.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /*                                                                      */
9 /* This program is free software. You can redistribute it and/or        */
10 /* modify it under the terms of the GNU General Public License          */
11 /* as published by the Free Software Foundation.                        */
12 /************************************************************************/
13 // $Id: 
14
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_MODULES);
18
19 require(AT_INCLUDE_PATH.'../mods/_core/modules/classes/ModuleParser.class.php');
20 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
21
22 // module content folder
23 $module_content_folder = AT_CONTENT_DIR . "module/";
24
25 if (isset($_GET["mod"])) $mod = str_replace(array('.','..'), '', $_GET['mod']);
26 else if (isset($_POST["mod"])) $mod = $_POST["mod"];
27
28 if (isset($_GET["new"])) $new = $_GET["new"];
29 else if (isset($_POST["new"])) $new = $_POST["new"];
30
31 if (isset($_GET["permission_granted"])) $permission_granted = $_GET["permission_granted"];
32 else if (isset($_POST["permission_granted"])) $permission_granted = $_POST["permission_granted"];
33
34 if (isset($_POST['submit_no']))
35 {
36         clr_dir('../../../mods/'.$_POST['mod']);
37         
38         // if write permission on the mods folder has been granted, re-direct to the page of removing permission,
39         // otherwise, back to start page.
40         if ($_POST['permission_granted']==1)
41                 header('Location: '.AT_BASE_HREF.'mods/_core/modules/module_install_step_3.php?cancelled=1');
42         else
43         {
44                 $msg->addFeedback('CANCELLED');
45                 header('Location: '.AT_BASE_HREF.'mods/_core/modules/install_modules.php');
46         }
47         
48         exit;
49
50 else if (isset($_POST['submit_yes'])) 
51 {
52         // install module
53         $module = $moduleFactory->getModule($_POST['mod']);
54         $module->load();
55         $module->install();
56
57         if ($msg->containsErrors()) 
58         {
59                 header('Location: '.AT_BASE_HREF.'mods/_core/modules/module_install_step_2.php?mod='.$addslashes($mod).SEP.'new=1'.SEP.'permission_granted='.$permission_granted);
60         } 
61         else 
62         {
63                 if ($_POST['permission_granted']==1)
64                 {
65                         header('Location: '.AT_BASE_HREF.'mods/_core/modules/module_install_step_3.php?installed=1');
66                 }
67                 else
68                 {
69                         $msg->addFeedback('MOD_INSTALLED');
70                         header('Location: '.AT_BASE_HREF.'mods/_core/modules/index.php');
71                 }
72         }
73         exit;
74 } else if (isset($_GET['submit'])) {
75         $args = '';
76
77         if (isset($_GET['enabled'])  && $_GET['enabled'])  {  $args .= 'enabled=1';      }
78         if (isset($_GET['disabled']) && $_GET['disabled']) {  $args .= SEP.'disabled=1'; }
79         if (isset($_GET['missing'])  && $_GET['missing'])  {  $args .= SEP.'missing=1';  }
80         if (isset($_GET['core'])     && $_GET['core'])     {  $args .= SEP.'core=1';     }
81         if (isset($_GET['standard']) && $_GET['standard']) {  $args .= SEP.'standard=1'; }
82         if (isset($_GET['extra'])    && $_GET['extra'])    {  $args .= SEP.'extra=1';    }
83
84         header('Location: index.php?'. $args);
85         exit;
86 }
87
88 // copy module from content folder into mods folder
89 if (isset($mod) && !isset($_GET['mod_in']))
90 {
91         copys($module_content_folder.$mod, '../../../mods/'.$mod);
92 }
93
94 require(AT_INCLUDE_PATH.'header.inc.php'); 
95
96 $moduleParser = new ModuleParser();
97
98 if (!file_exists('../../../mods/'.$mod.'/module.xml')) {
99 ?>
100 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
101 <input type="hidden" name="mod" value="<?php echo $mod; ?>" />
102 <input type="hidden" name="new" value="<?php echo $new; ?>" />
103 <input type="hidden" name="permission_granted" value="<?php echo $permission_granted; ?>" />
104 <div class="input-form">
105         <div class="row">
106                 <h3><?php echo $mod; ?></h3>
107         </div>
108
109         <div class="row">
110                 <?php echo _AT('missing_info'); ?>
111         </div>
112
113         <div class="row buttons">
114                 <input type="submit" name="submit" value="<?php echo _AT('back'); ?>" />
115                 <?php if (isset($new) && $new): ?>
116                         <input type="submit" name="install" value="<?php echo _AT('install'); ?>" />
117                 <?php endif; ?>
118         </div>
119
120 </div>
121 </form>
122 <?php
123         require(AT_INCLUDE_PATH.'footer.inc.php');
124         exit;
125 }
126
127 $readme = get_readme('../../../mods/'.$mod);
128
129 $moduleParser->parse(file_get_contents('../../../mods/'.$mod.'/module.xml'));
130
131 $module = $moduleFactory->getModule($mod);
132
133 $properties = $module->getProperties(array('maintainers', 'url', 'date', 'license', 'state', 'notes', 'version'));
134 ?>
135 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
136 <input type="hidden" name="mod" value="<?php echo $mod; ?>" />
137 <input type="hidden" name="new" value="<?php echo $new; ?>" />
138 <input type="hidden" name="permission_granted" value="<?php echo $permission_granted; ?>" />
139
140 <input type="hidden" name="enabled" value="<?php echo (int) isset($_GET['enabled']); ?>" />
141 <input type="hidden" name="disabled" value="<?php echo (int) isset($_GET['disabled']); ?>" />
142 <input type="hidden" name="core" value="<?php echo (int) isset($_GET['core']); ?>" />
143 <input type="hidden" name="standard" value="<?php echo (int) isset($_GET['standard']); ?>" />
144 <input type="hidden" name="extra" value="<?php echo (int) isset($_GET['extra']); ?>" />
145 <input type="hidden" name="missing" value="<?php echo (int) isset($_GET['missing']); ?>" />
146
147 <div class="input-form">
148         <div class="row">
149                 <h3><?php echo $module->getName(); ?></h3>
150         </div>
151
152         <div class="row">
153                 <?php echo _AT('description'); ?><br />
154                 <?php echo nl2br($module->getDescription($_SESSION['lang'])); if ($readme <> '') echo '<br /><a href="#" onclick="ATutor.poptastic(\''.AT_BASE_HREF.'mods/'.$mod.'/'.$readme.'\');return false;">'._AT('view_readme').'</a>'; ?>
155         </div>
156
157         <div class="row">
158                 <?php echo _AT('maintainers'); ?><br />
159                         <ul class="horizontal">
160                                 <?php foreach ($properties['maintainers'] as $maintainer): ?>
161                                         <li><?php echo $maintainer['name'] .' &lt;'.$maintainer['email'].'&gt;'; ?></li>
162                                 <?php endforeach; ?>
163                         </ul>
164         </div>
165
166         <div class="row">
167                 <?php echo _AT('url'); ?><br />
168                 <?php echo $properties['url']; ?>
169         </div>
170
171         <div class="row">
172                 <?php echo _AT('version'); ?><br />
173                 <?php echo $properties['version']; ?>
174         </div>
175
176         <div class="row">
177                 <?php echo _AT('date'); ?><br />
178                 <?php echo $properties['date']; ?>
179         </div>
180
181         <div class="row">
182                 <?php echo _AT('license'); ?><br />
183                 <?php echo $properties['license']; ?>
184         </div>
185
186         <div class="row">
187                 <?php echo _AT('state'); ?><br />
188                 <?php echo $properties['state']; ?>
189         </div>
190
191         <div class="row">
192                 <?php echo _AT('notes'); ?><br />
193                 <?php echo nl2br($properties['notes']); ?>
194         </div>
195
196         <?php if (is_array($module->_pages)): ?>
197                 <div class="row">
198                         <?php if (!isset($_GET['files'])): ?>
199                                 <a href="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES).SEP; ?>files#files"><?php echo _AT('files'); ?></a><br />
200                         <?php else: ?>
201                                 <?php $module_pages = array_keys($module->_pages); ?>
202                                 <?php natsort($module_pages); ?>
203                                 <a name="files"></a><?php echo _AT('files'); ?><br />
204                                 <ul style="margin-top: 0px;">
205                                         <?php foreach ($module_pages as $key): ?>
206                                                 <?php if (defined($key)) : continue; endif; ?>
207                                                 <li><kbd><?php echo $key; ?></kbd></li>
208                                         <?php endforeach; ?>
209                                 </ul>
210                         <?php endif; ?>
211                 </div>
212         <?php endif; ?>
213
214 <?php if (!isset($new)): ?>
215         <div class="row buttons">
216                 <input type="submit" name="submit" value="<?php echo _AT('back'); ?>" />
217         </div>
218 <?php endif; ?>
219 </div>
220 </form>
221 <?php if (isset($new)): ?>
222         <?php
223                 $hidden_vars['mod'] = $mod;
224                 $hidden_vars['new'] = '1';
225                 $hidden_vars['permission_granted'] = $permission_granted;
226                 
227                 $msg->addConfirm(array('ADD_MODULE', $mod), $hidden_vars);
228                 $msg->printConfirm();
229         ?>
230 <?php endif; ?>
231
232 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>