Moved scripts in "docs" one level up into root folder. In addition, removed "docs...
[atutor.git] / mods / _core / modules / index.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id: index.php 10499 2010-12-09 17:16:28Z cindy $
13
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 admin_authenticate(AT_ADMIN_PRIV_MODULES);
17
18 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
19
20 $dir_name = str_replace(array('.','..'), '', $_GET['mod_dir']);
21
22 $args = '';
23
24 if (isset($_GET['enabled'])  && $_GET['enabled'])  {  $args .= 'enabled=1';      }
25 if (isset($_GET['disabled']) && $_GET['disabled']) {  $args .= SEP.'disabled=1'; }
26 if (isset($_GET['missing'])  && $_GET['missing'])  {  $args .= SEP.'missing=1';  }
27 if (isset($_GET['partially_uninstalled'])  && $_GET['partially_uninstalled'])  {  $args .= SEP.'partially_uninstalled=1';  }
28 if (isset($_GET['core'])     && $_GET['core'])     {  $args .= SEP.'core=1';     }
29 if (isset($_GET['standard']) && $_GET['standard']) {  $args .= SEP.'standard=1'; }
30 if (isset($_GET['extra'])    && $_GET['extra'])    {  $args .= SEP.'extra=1';    }
31
32 if (isset($_GET['reset_filter'])) {
33         header('Location: '.$_SERVER['PHP_SELF']);
34         exit;
35 }
36
37 if (isset($_GET['mod_dir'], $_GET['enable'])) {
38         $module = $moduleFactory->getModule($_GET['mod_dir']);
39         if (!$module->isEnabled() && !$module->isCore() && !$module->isMissing() && !$module->isPartiallyUninstalled()) {
40                 $module->enable();
41                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
42         }
43
44         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
45         exit;
46 } else if (isset($_GET['mod_dir'], $_GET['disable'])) {
47         $module = $moduleFactory->getModule($_GET['mod_dir']);
48         if ($module->isCore()) {
49                 // core modules cannot be disabled!
50                 $msg->addError('DISABLE_CORE_MODULE');
51         } else if ($module->isMissing()) {
52                 $msg->addError('DISABLE_MISSING_MODULE');
53         } else if ($module->isPartiallyUninstalled()) {
54                 $msg->addError('DISABLE_PARTIALLY_UNINSTALLED_MODULE');
55         } else if ($module->isEnabled()) {
56                 $module->disable();
57                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
58         }
59         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
60         exit;
61 } else if (isset($_GET['mod_dir'], $_GET['details'])) {
62         header('Location: details.php?mod='.$_GET['mod_dir'] . SEP . $args);
63         exit;
64
65 } else if (isset($_GET['mod_dir'], $_GET['uninstall'])) {
66         $module = $moduleFactory->getModule($_GET['mod_dir']);
67
68         $module_folder = '../../../mods/'.$_GET['mod_dir'];
69         // check if the module has been un-installed
70         if (!file_exists($module_folder))
71         {
72                 $msg->addError('ALREADY_UNINSTALLED');
73         }
74
75         // only extra modules can be uninstalled
76         if (!$module->isExtra()) {
77                 $msg->addError('ONLY_UNINSTALL_EXTRA_MODULE');
78         } 
79         // check if the module is installed via "Available Extra Modules"
80         // which are the modules can be un-installed 
81         else if (!file_exists($module_folder.'/module_uninstall.php') || !is_writable($module_folder))
82         {
83                 $msg->addError('CANNOT_UNINSTALL_MANUAL_MODULE');
84         }
85         
86   if (!$msg->containsErrors())
87         {
88                 header('Location: module_uninstall_step_1.php?mod=' . urlencode($_GET['mod_dir']) . SEP.'args='.urlencode($args));
89                 exit;
90         }
91
92 } else if (isset($_GET['mod_dir'], $_GET['export'])) {
93         $module = $moduleFactory->getModule($_GET['mod_dir']);
94
95         $module_folder = '../../../mods/'.$_GET['mod_dir'];
96         // check if the module has been un-installed
97         if (!file_exists($module_folder))
98         {
99                 $msg->addError('ITEM_NOT_FOUND');
100         }
101
102         // only extra modules can be uninstalled
103         if (!$module->isExtra()) {
104                 $msg->addError('ONLY_EXPORT_EXTRA_MODULE');
105         } 
106         
107   if (!$msg->containsErrors())
108         {
109                 require(AT_INCLUDE_PATH.'classes/zipfile.class.php');                           /* for zipfile */
110                 
111                 $zipfile = new zipfile();
112                 $zipfile->add_dir('../../../mods/'.$_GET['mod_dir'].'/', $_GET['mod_dir'].'/');
113                 $zipfile->close();
114                 $zipfile->send_file($_GET['mod_dir']);
115                 exit;
116         }
117
118 } else if (isset($_GET['disable']) || isset($_GET['enable']) || isset($_GET['details']) || isset($_GET['uninstall']) || isset($_GET['export'])) {
119         $msg->addError('NO_ITEM_SELECTED');
120         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
121         exit;
122 }
123
124 require(AT_INCLUDE_PATH.'header.inc.php'); 
125
126 $module_status_bits = $module_type_bits = 0;
127
128 if ($_GET['enabled'])  { $module_status_bits += AT_MODULE_STATUS_ENABLED;  }
129 if ($_GET['disabled']) {        $module_status_bits += AT_MODULE_STATUS_DISABLED; }
130 if ($_GET['missing'])  {        $module_status_bits += AT_MODULE_STATUS_MISSING;  }
131 if ($_GET['partially_uninstalled'])  {  $module_status_bits += AT_MODULE_STATUS_PARTIALLY_UNINSTALLED;  }
132
133 if ($_GET['core'])     {  $module_type_bits += AT_MODULE_TYPE_CORE;     }
134 if ($_GET['standard']) {  $module_type_bits += AT_MODULE_TYPE_STANDARD; }
135 if ($_GET['extra'])    {  $module_type_bits += AT_MODULE_TYPE_EXTRA;    }
136
137 if ($module_status_bits == 0) {
138         $module_status_bits = AT_MODULE_STATUS_DISABLED | AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_MISSING | AT_MODULE_STATUS_PARTIALLY_UNINSTALLED;
139         $_GET['enabled'] = $_GET['disabled'] = $_GET['missing'] = $_GET['partially_uninstalled'] = 1;
140 }
141
142 if ($module_type_bits == 0) {
143         $module_type_bits = AT_MODULE_TYPE_STANDARD + AT_MODULE_TYPE_EXTRA;
144         $_GET['standard'] = $_GET['extra'] = 1;
145 }
146
147
148 $module_list = $moduleFactory->getModules($module_status_bits, $module_type_bits, $sort = TRUE);
149 $keys = array_keys($module_list);
150 ?>
151 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
152         <div class="input-form">
153                 <div class="row">
154                         <h3><?php echo _AT('results_found', count($keys)); ?></h3>
155                 </div>
156
157                 <div class="row">
158                         <?php echo _AT('type'); ?><br />
159                         <input type="checkbox" name="core" value="1" id="t0" <?php if ($_GET['core']) { echo 'checked="checked"'; } ?> /><label for="t0"><?php echo _AT('core'); ?></label>
160
161                         <input type="checkbox" name="standard" value="1" id="t1" <?php if ($_GET['standard']) { echo 'checked="checked"'; } ?> /><label for="t1"><?php echo _AT('standard'); ?></label> 
162
163                         <input type="checkbox" name="extra" value="1" id="t2" <?php if ($_GET['extra']) { echo 'checked="checked"'; } ?> /><label for="t2"><?php echo _AT('extra'); ?></label> 
164                 </div>
165
166
167                 <div class="row">
168                         <?php echo _AT('status'); ?><br />
169                         <input type="checkbox" name="enabled" value="1" id="s0" <?php if ($_GET['enabled']) { echo 'checked="checked"'; } ?> /><label for="s0"><?php echo _AT('enabled'); ?></label> 
170
171                         <input type="checkbox" name="disabled" value="1" id="s1" <?php if ($_GET['disabled']) { echo 'checked="checked"'; } ?> /><label for="s1"><?php echo _AT('disabled'); ?></label> 
172
173                         <input type="checkbox" name="missing" value="1" id="s2" <?php if ($_GET['missing']) { echo 'checked="checked"'; } ?> /><label for="s2"><?php echo _AT('missing'); ?></label> 
174
175                         <input type="checkbox" name="partially_uninstalled" value="1" id="s3" <?php if ($_GET['partially_uninstalled']) { echo 'checked="checked"'; } ?> /><label for="s3"><?php echo _AT('partially_uninstalled'); ?></label> 
176                 </div>
177
178                 <div class="row buttons">
179                         <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
180                         <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
181                 </div>
182         </div>
183 </form>
184
185 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="form">
186
187 <input type="hidden" name="enabled" value="<?php echo (int) $_GET['enabled']; ?>" />
188 <input type="hidden" name="disabled" value="<?php echo (int) $_GET['disabled']; ?>" />
189 <input type="hidden" name="core" value="<?php echo (int) $_GET['core']; ?>" />
190 <input type="hidden" name="standard" value="<?php echo (int) $_GET['standard']; ?>" />
191 <input type="hidden" name="extra" value="<?php echo (int) $_GET['extra']; ?>" />
192 <input type="hidden" name="missing" value="<?php echo (int) $_GET['missing']; ?>" />
193 <input type="hidden" name="partially_uninstalled" value="<?php echo (int) $_GET['partially_uninstalled']; ?>" />
194
195 <table class="data" summary="" rules="cols">
196 <colgroup>
197                 <col />
198                 <col class="sort" />
199                 <col span="4" />
200 </colgroup>
201 <thead>
202 <tr>
203         <th scope="col">&nbsp;</th>
204         <th scope="col"><?php echo _AT('module_name'); ?></th>
205         <th scope="col"><?php echo _AT('type'); ?></th>
206         <th scope="col"><?php echo _AT('status'); ?></th>
207         <th scope="col"><?php echo _AT('cron'); ?></th>
208         <th scope="col"><?php echo _AT('directory_name'); ?></th>
209 </tr>
210 </thead>
211 <tfoot>
212 <tr>
213         <td colspan="6">
214                 <input type="submit" name="details" value="<?php echo _AT('details'); ?>" />
215                 <input type="submit" name="enable"  value="<?php echo _AT('enable'); ?>" />
216                 <input type="submit" name="disable" value="<?php echo _AT('disable'); ?>" />
217                 <input type="submit" name="uninstall" value="<?php echo _AT('uninstall'); ?>" />
218                 <input type="submit" name="export" value="<?php echo _AT('export'); ?>" />
219         </td>
220 </tr>
221 </tfoot>
222 <tbody>
223
224
225
226 <?php foreach($keys as $dir_name) : $module =& $module_list[$dir_name]; $i++; $readme = get_readme(AT_INCLUDE_PATH.'../mods/'.$dir_name);?>
227
228         <tr onmousedown="document.form['t_<?php echo $i; ?>'].checked = true; rowselect(this);" id="r_<?php echo $i; ?>">
229                 <td valign="top"><input type="radio" id="t_<?php echo $i; ?>" name="mod_dir" value="<?php echo $dir_name; ?>" /></td>
230                 <td nowrap="nowrap" valign="top"><label for="t_<?php echo $i; ?>"><?php echo $module->getName(); if ($readme <> '') echo '&nbsp;<a href="#" onclick="ATutor.poptastic(\''.AT_BASE_HREF.'mods/'.$dir_name.'/'.$readme.'\');return false;">'._AT('view_readme').'</a>'; ?></label></td>
231                 <td valign="top"><?php
232                         if ($module->isCore()) {
233                                 echo '<strong>'._AT('core').'</strong>';
234                         } else if ($module->isStandard()) {
235                                 echo _AT('standard');
236                         } else {
237                                 echo _AT('extra');
238                         }
239                         ?></td>
240                 <td valign="top"><?php
241                         if ($module->isEnabled()) {
242                                 echo _AT('enabled');
243                         } else if ($module->isMissing()) {
244                                 echo '<strong>'._AT('missing').'</strong>';
245                         } else if ($module->isPartiallyUninstalled()) {
246                                 echo _AT('partially_uninstalled');
247                         } else {
248                                 echo '<strong>'._AT('disabled').'</strong>';
249                         }
250                         ?></td>
251                 <td valign="top" align="center">
252                         <?php if ($module->getCronInterval()): ?>
253                                 <?php echo _AT('minutes', $module->getCronInterval()); ?>
254                         <?php else: ?>
255                                 -
256                         <?php endif; ?>
257                 </td>
258                 <td valign="top"><code><?php echo $dir_name; ?>/</code></td>
259         </tr>
260 <?php endforeach; ?>
261 <?php if (!$keys): ?>
262         <tr>
263                 <td colspan="6"><?php echo _AT('none_found'); ?></td>
264         </tr>
265 <?php endif; ?>
266 </tbody>
267 </table>
268 </form>
269
270 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>