tagging as ATutor 1.5.4-release
[atutor.git] / admin / modules / index.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
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_ADMIN);
18
19 $dir_name = str_replace(array('.','..'), '', $_GET['mod_dir']);
20
21 $args = '';
22
23 if (isset($_GET['enabled'])  && $_GET['enabled'])  {  $args .= 'enabled=1';      }
24 if (isset($_GET['disabled']) && $_GET['disabled']) {  $args .= SEP.'disabled=1'; }
25 if (isset($_GET['missing'])  && $_GET['missing'])  {  $args .= SEP.'missing=1';  }
26 if (isset($_GET['core'])     && $_GET['core'])     {  $args .= SEP.'core=1';     }
27 if (isset($_GET['standard']) && $_GET['standard']) {  $args .= SEP.'standard=1'; }
28 if (isset($_GET['extra'])    && $_GET['extra'])    {  $args .= SEP.'extra=1';    }
29
30 if (isset($_GET['reset_filter'])) {
31         header('Location: '.$_SERVER['PHP_SELF']);
32         exit;
33 }
34
35 if (isset($_GET['mod_dir'], $_GET['enable'])) {
36         $module =& $moduleFactory->getModule($_GET['mod_dir']);
37         if (!$module->isEnabled() && !$module->isCore() && !$module->isMissing()) {
38                 $module->enable();
39                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
40         }
41
42         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
43         exit;
44 } else if (isset($_GET['mod_dir'], $_GET['disable'])) {
45         $module =& $moduleFactory->getModule($_GET['mod_dir']);
46         if ($module->isCore()) {
47                 // core modules cannot be disabled!
48                 $msg->addError('DISABLE_CORE_MODULE');
49         } else if ($module->isMissing()) {
50                 $msg->addError('DISABLE_MISSING_MODULE');
51         } else if ($module->isEnabled()) {
52                 $module->disable();
53                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
54         }
55         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
56         exit;
57 } else if (isset($_GET['mod_dir'], $_GET['details'])) {
58         header('Location: details.php?mod='.$_GET['mod_dir'] . SEP . $args);
59         exit;
60
61 } else if (isset($_GET['disable']) || isset($_GET['enable']) || isset($_GET['details'])) {
62         $msg->addError('NO_ITEM_SELECTED');
63         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
64         exit;
65 }
66
67 require(AT_INCLUDE_PATH.'header.inc.php'); 
68
69 $module_status_bits = $module_type_bits = 0;
70
71 if (isset($_GET['enabled']))  { $module_status_bits += AT_MODULE_STATUS_ENABLED;  }
72 if (isset($_GET['disabled'])) { $module_status_bits += AT_MODULE_STATUS_DISABLED; }
73 if (isset($_GET['missing']))  { $module_status_bits += AT_MODULE_STATUS_MISSING;  }
74
75 if (isset($_GET['core']))     {  $module_type_bits += AT_MODULE_TYPE_CORE;     }
76 if (isset($_GET['standard'])) {  $module_type_bits += AT_MODULE_TYPE_STANDARD; }
77 if (isset($_GET['extra']))    {  $module_type_bits += AT_MODULE_TYPE_EXTRA;    }
78
79 if ($module_status_bits == 0) {
80         $module_status_bits = AT_MODULE_STATUS_DISABLED | AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_MISSING;
81         $_GET['enabled'] = $_GET['disabled'] = $_GET['missing'] = 1;
82 }
83
84 if ($module_type_bits == 0) {
85         $module_type_bits = AT_MODULE_TYPE_STANDARD + AT_MODULE_TYPE_EXTRA;
86         $_GET['standard'] = $_GET['extra'] = 1;
87 }
88
89
90 $module_list = $moduleFactory->getModules($module_status_bits, $module_type_bits, $sort = TRUE);
91 $keys = array_keys($module_list);
92 ?>
93 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
94         <div class="input-form">
95                 <div class="row">
96                         <h3><?php echo _AT('results_found', count($keys)); ?></h3>
97                 </div>
98
99                 <div class="row">
100                         <?php echo _AT('type'); ?><br />
101                         <input type="checkbox" name="core" value="1" id="t0" <?php if (isset($_GET['core'])) { echo 'checked="checked"'; } ?> /><label for="t0"><?php echo _AT('core'); ?></label>
102
103                         <input type="checkbox" name="standard" value="1" id="t1" <?php if (isset($_GET['standard'])) { echo 'checked="checked"'; } ?> /><label for="t1"><?php echo _AT('standard'); ?></label> 
104
105                         <input type="checkbox" name="extra" value="1" id="t2" <?php if (isset($_GET['extra'])) { echo 'checked="checked"'; } ?> /><label for="t2"><?php echo _AT('extra'); ?></label> 
106                 </div>
107
108
109                 <div class="row">
110                         <?php echo _AT('status'); ?><br />
111                         <input type="checkbox" name="enabled" value="1" id="s0" <?php if (isset($_GET['enabled'])) { echo 'checked="checked"'; } ?> /><label for="s0"><?php echo _AT('enabled'); ?></label> 
112
113                         <input type="checkbox" name="disabled" value="1" id="s1" <?php if (isset($_GET['disabled'])) { echo 'checked="checked"'; } ?> /><label for="s1"><?php echo _AT('disabled'); ?></label> 
114
115                         <input type="checkbox" name="missing" value="1" id="s2" <?php if (isset($_GET['missing'])) { echo 'checked="checked"'; } ?> /><label for="s2"><?php echo _AT('missing'); ?></label> 
116                 </div>
117
118                 <div class="row buttons">
119                         <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
120                         <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
121                 </div>
122         </div>
123 </form>
124
125 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="form">
126
127 <input type="hidden" name="enabled" value="<?php echo (int) isset($_GET['enabled']); ?>" />
128 <input type="hidden" name="disabled" value="<?php echo (int) isset($_GET['disabled']); ?>" />
129 <input type="hidden" name="core" value="<?php echo (int) isset($_GET['core']); ?>" />
130 <input type="hidden" name="standard" value="<?php echo (int) isset($_GET['standard']); ?>" />
131 <input type="hidden" name="extra" value="<?php echo (int) isset($_GET['extra']); ?>" />
132 <input type="hidden" name="missing" value="<?php echo (int) isset($_GET['missing']); ?>" />
133
134 <table class="data" summary="" rules="cols">
135 <colgroup>
136                 <col />
137                 <col class="sort" />
138                 <col span="4" />
139 <thead>
140 <tr>
141         <th scope="col">&nbsp;</th>
142         <th scope="col"><?php echo _AT('module_name'); ?></th>
143         <th scope="col"><?php echo _AT('type'); ?></th>
144         <th scope="col"><?php echo _AT('status'); ?></th>
145         <th scope="col"><?php echo _AT('cron'); ?></th>
146         <th scope="col"><?php echo _AT('directory_name'); ?></th>
147 </tr>
148 </thead>
149 <tfoot>
150 <tr>
151         <td colspan="6">
152                 <input type="submit" name="details" value="<?php echo _AT('details'); ?>" />
153                 <input type="submit" name="enable"  value="<?php echo _AT('enable'); ?>" />
154                 <input type="submit" name="disable" value="<?php echo _AT('disable'); ?>" />
155         </td>
156 </tr>
157 </tfoot>
158 <tbody>
159 <?php foreach($keys as $dir_name) : $module =& $module_list[$dir_name]; ?>
160
161         <tr onmousedown="document.form['t_<?php echo $dir_name; ?>'].checked = true; rowselect(this);" id="r_<?php echo $dir_name; ?>">
162                 <td valign="top"><input type="radio" id="t_<?php echo $dir_name; ?>" name="mod_dir" value="<?php echo $dir_name; ?>" /></td>
163                 <td nowrap="nowrap" valign="top"><label for="t_<?php echo $dir_name; ?>"><?php echo $module->getName(); ?></label></td>
164                 <td valign="top"><?php
165                         if ($module->isCore()) {
166                                 echo '<strong>'._AT('core').'</strong>';
167                         } else if ($module->isStandard()) {
168                                 echo _AT('standard');
169                         } else {
170                                 echo _AT('extra');
171                         }
172                         ?></td>
173                 <td valign="top"><?php
174                         if ($module->isEnabled()) {
175                                 echo _AT('enabled');
176                         } else if ($module->isMissing()) {
177                                 echo '<strong>'._AT('missing').'</strong>';
178                         } else {
179                                 echo '<em>'._AT('disabled').'</em>';
180                         }
181                         ?></td>
182                 <td valign="top" align="center">
183                         <?php if ($module->getCronInterval()): ?>
184                                 <?php echo _AT('minutes', $module->getCronInterval()); ?>
185                         <?php else: ?>
186                                 -
187                         <?php endif; ?>
188                 </td>
189                 <td valign="top"><code><?php echo $dir_name; ?>/</code></td>
190         </tr>
191 <?php endforeach; ?>
192 <?php if (!$keys): ?>
193         <tr>
194                 <td colspan="6"><?php echo _AT('none_found'); ?></td>
195         </tr>
196 <?php endif; ?>
197 </tbody>
198 </table>
199 </form>
200
201 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>