move code up one directory
[atutor.git] / mods / _core / modules / default_mods.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 if (isset($_POST['cancel'])) {
20         $msg->addFeedback('CANCELLED');
21         header('Location: ../courses.php');
22         exit;
23 }
24
25 if (isset($_POST['up'])) {
26         $up = key($_POST['up']);
27         $_new_modules  = array();
28         if (isset($_POST['main'])) {
29                 foreach ($_POST['main'] as $m) {
30                         if ($m == $up) {
31                                 $last_m = array_pop($_new_modules);
32                                 $_new_modules[] = $m;
33                                 $_new_modules[] = $last_m;
34                         } else {
35                                 $_new_modules[] = $m;
36                         }
37                 }
38
39                 $_POST['main'] = $_new_modules;
40         }
41         if (isset($_POST['home'])) {
42                 $_new_modules  = array();
43                 foreach ($_POST['home'] as $m) {
44                         if ($m == $up) {
45                                 $last_m = array_pop($_new_modules);
46                                 $_new_modules[] = $m;
47                                 $_new_modules[] = $last_m;
48                         } else {
49                                 $_new_modules[] = $m;
50                         }
51                 }
52                 $_POST['home'] = $_new_modules;
53         }
54
55         $_POST['submit'] = TRUE;
56 } else if (isset($_POST['down'])) {
57         $_new_modules  = array();
58
59         $down = key($_POST['down']);
60
61         if (isset($_POST['main'])) {
62                 foreach ($_POST['main'] as $m) {
63                         if ($m == $down) {
64                                 $found = TRUE;
65                                 continue;
66                         }
67                         $_new_modules[] = $m;
68                         if ($found) {
69                                 $_new_modules[] = $down;
70                                 $found = FALSE;
71                         }
72                 }
73
74                 $_POST['main'] = $_new_modules;
75         }
76
77         if (isset($_POST['home'])) {
78                 $_new_modules  = array();
79                 foreach ($_POST['home'] as $m) {
80                         if ($m == $down) {
81                                 $found = TRUE;
82                                 continue;
83                         }
84                         $_new_modules[] = $m;
85                         if ($found) {
86                                 $_new_modules[] = $down;
87                                 $found = FALSE;
88                         }
89                 }
90
91                 $_POST['home'] = $_new_modules;
92         }
93
94         $_POST['submit'] = TRUE;
95 }
96
97 if (isset($_POST['submit'])) {
98         if (isset($_POST['main'])) {
99                 $_POST['main'] = array_unique($_POST['main']);
100                 $_POST['main'] = array_filter($_POST['main']); // remove empties
101                 $main_defaults = implode('|', $_POST['main']);
102
103         } else {
104                 $main_defaults = '';
105         }
106
107         if (isset($_POST['home'])) {
108                 $_POST['home'] = array_unique($_POST['home']);
109                 $_POST['home'] = array_filter($_POST['home']); // remove empties
110                 $home_defaults = implode('|', $_POST['home']);
111         } else {
112                 $home_defaults = '';
113         }
114
115         if (!($_config_defaults['main_defaults'] == $main_defaults) && (strlen($main_defaults) < 256)) {
116                 $sql    = "REPLACE INTO ".TABLE_PREFIX."config VALUES('main_defaults', '$main_defaults')";
117                 $result = mysql_query($sql, $db);
118
119                 $sql    = "DELETE FROM ".TABLE_PREFIX."config WHERE name='main_defaults_2'";
120         } else if (!($_config_defaults['main_defaults'] == $main_defaults) && (strlen($main_defaults) > 255)) {
121                 // we don't have to worry about chopping in the middle since they'll be combined anyway
122                 $main_defaults_1 = substr($main_defaults, 0, 255);
123                 $main_defaults_2 = substr($main_defaults, 255);
124                 $sql    = "REPLACE INTO ".TABLE_PREFIX."config VALUES('main_defaults', '$main_defaults_1')";
125                 $result = mysql_query($sql, $db);
126
127                 $sql    = "REPLACE INTO ".TABLE_PREFIX."config VALUES('main_defaults_2', '$main_defaults_2')";
128         } else if ($_config_defaults['main_defaults'] == $main_defaults) {
129                 $sql    = "DELETE FROM ".TABLE_PREFIX."config WHERE name='main_defaults' OR name='name_defaults_2'";
130         }
131         $result = mysql_query($sql, $db);
132
133
134         if (!($_config_defaults['home_defaults'] == $home_defaults) && (strlen($home_defaults) < 256)) {
135                 $sql    = "REPLACE INTO ".TABLE_PREFIX."config VALUES('home_defaults', '$home_defaults')";
136                 $result = mysql_query($sql, $db);
137
138                 $sql    = "DELETE FROM ".TABLE_PREFIX."config WHERE name='home_defaults_2'";
139
140         } else  if (!($_config_defaults['home_defaults'] == $home_defaults) && (strlen($home_defaults) > 255)) {
141                 // we don't have to worry about chopping in the middle since they'll be combined anyway
142                 $home_defaults_1 = substr($home_defaults, 0, 255);
143                 $home_defaults_2 = substr($home_defaults, 255);
144                 $sql    = "REPLACE INTO ".TABLE_PREFIX."config VALUES('home_defaults', '$home_defaults_1')";
145                 $result = mysql_query($sql, $db);
146
147                 $sql    = "REPLACE INTO ".TABLE_PREFIX."config VALUES('home_defaults_2', '$home_defaults_2')";
148
149         } else if ($_config_defaults['home_defaults'] == $home_defaults) {
150                 $sql    = "DELETE FROM ".TABLE_PREFIX."config WHERE name='home_defaults' OR name='home_defaults_2'";
151         }
152         $result = mysql_query($sql, $db);
153
154         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
155         header('Location: '.$_SERVER['PHP_SELF']);
156         exit;
157 }
158
159
160 require(AT_INCLUDE_PATH.'header.inc.php');
161
162 $main_defaults = explode('|', $_config['main_defaults']);
163 $home_defaults = explode('|', $_config['home_defaults']);
164
165 $main_defaults = array_filter($main_defaults); // remove empties
166 $home_defaults = array_filter($home_defaults); // remove empties
167 ?>
168 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
169 <table class="data static" rules="rows" summary="">
170 <thead>
171 <tr>
172         <th scope="cols"><?php echo _AT('section'); ?></th>
173         <th><?php echo _AT('location'); ?></th>
174         <th><?php echo _AT('order'); ?></th>
175 </tr>
176 </thead>
177 <tfoot>
178 <tr>
179         <td colspan="3" style="text-align:right;">              
180                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s"  />
181                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"  />     
182         </td>
183 </tr>
184 </tfoot>
185 <tbody>
186 <?php 
187 $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED);
188 $keys = array_keys($module_list);
189
190 foreach ($keys as $dir_name) {
191         $module =& $module_list[$dir_name]; 
192
193         if ($module->getStudentTools()) {
194                 $student_tools[] = $module->getStudentTools();
195         }
196 }
197
198 $count = 0;
199
200 //main mods
201 $_current_modules = $main_defaults;
202 $num_main    = count($_current_modules);
203 //main and home merged
204 $_current_modules = array_merge($_current_modules, array_diff($home_defaults, $main_defaults));
205 $num_modules = count($_current_modules);
206 //all other mods
207 $_current_modules = array_merge($_current_modules, array_diff($student_tools, $_current_modules));
208
209
210 foreach ($_current_modules as $tool) :
211         $count++; 
212 ?>
213         <tr>
214                 <td><?php 
215                 if (isset($_pages[$tool]['title'])) {
216                         echo $_pages[$tool]['title'];
217                 } else {
218                         echo _AT($_pages[$tool]['title_var']);
219                 } ?></td>
220                 <td align="center">
221                         <?php if (in_array($tool, $main_defaults)): ?>
222                                 <input type="checkbox" name="main[]" value="<?php echo $tool; ?>" id="m<?php echo $tool; ?>" checked="checked" /><label for="m<?php echo $tool; ?>"><?php echo _AT('main_navigation'); ?></label>
223                         <?php else: ?>
224                                 <input type="checkbox" name="main[]" value="<?php echo $tool; ?>" id="m<?php echo $tool; ?>" /><label for="m<?php echo $tool; ?>"><?php echo _AT('main_navigation'); ?></label>
225                         <?php endif; ?>
226
227                         <?php if (in_array($tool, $home_defaults)): ?>
228                                 <input type="checkbox" name="home[]" value="<?php echo $tool; ?>" id="h<?php echo $tool; ?>" checked="checked" /><label for="h<?php echo $tool; ?>"><?php echo _AT('home'); ?></label>
229                         <?php else: ?>
230                                 <input type="checkbox" name="home[]" value="<?php echo $tool; ?>" id="h<?php echo $tool; ?>" /><label for="h<?php echo $tool; ?>"><?php echo _AT('home'); ?></label>
231                         <?php endif; ?>
232                 </td>
233                 <td align="right">
234                         <?php if (!in_array($tool, $home_defaults) && !in_array($tool, $main_defaults)): ?>
235                                 &nbsp;
236                         <?php else: ?>
237                                 <?php if (($count != $num_main+1) && ($count > 1)): ?>
238                                         <input type="submit" name="up[<?php echo $tool; ?>]" value="<?php echo _AT('move_up'); ?>" title="<?php echo _AT('move_up'); ?>" style="background-color: white; border: 1px solid; padding: 0px;" />
239                                 <?php else: ?>
240                                         <img src="images/clr.gif" alt="" width="12" />
241                                 <?php endif; ?>
242                                 <?php if (($count != $num_main) && ($count < $num_modules)): ?>
243                                         <input type="submit" name="down[<?php echo $tool; ?>]" value="<?php echo _AT('move_down'); ?>" title="<?php echo _AT('move_down'); ?>" style="background-color: white; border: 1px solid; padding: 0px;"/>
244                                 <?php else: ?>
245                                         <img src="images/clr.gif" alt="" width="12" />
246                                 <?php endif; ?>
247                         <?php endif; ?>
248                 </td>
249         </tr>
250 <?php 
251 endforeach; ?>
252 </tbody>
253 </table>
254 </form>
255
256 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>