tagging as ATutor 1.5.4-release
[atutor.git] / tools / modules.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg        */
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 authenticate(AT_PRIV_STYLES);
18
19 if (isset($_POST['up'])) {
20         $up = key($_POST['up']);
21         $_new_modules  = array();
22         if (isset($_POST['main'])) {
23                 foreach ($_POST['main'] as $m) {
24                         if ($m == $up) {
25                                 $last_m = array_pop($_new_modules);
26                                 $_new_modules[] = $m;
27                                 $_new_modules[] = $last_m;
28                         } else {
29                                 $_new_modules[] = $m;
30                         }
31                 }
32
33                 $_POST['main'] = $_new_modules;
34         }
35
36         if (isset($_POST['home'])) {
37                 $_new_modules  = array();
38                 foreach ($_POST['home'] as $m) {
39                         if ($m == $up) {
40                                 $last_m = array_pop($_new_modules);
41                                 $_new_modules[] = $m;
42                                 $_new_modules[] = $last_m;
43                         } else {
44                                 $_new_modules[] = $m;
45                         }
46                 }
47
48                 $_POST['home'] = $_new_modules;
49         }
50
51         $_POST['submit'] = TRUE;
52 } else if (isset($_POST['down'])) {
53         $_new_modules  = array();
54
55         $down = key($_POST['down']);
56
57         if (isset($_POST['main'])) {
58                 foreach ($_POST['main'] as $m) {
59                         if ($m == $down) {
60                                 $found = TRUE;
61                                 continue;
62                         }
63                         $_new_modules[] = $m;
64                         if ($found) {
65                                 $_new_modules[] = $down;
66                                 $found = FALSE;
67                         }
68                 }
69
70                 $_POST['main'] = $_new_modules;
71         }
72
73         if (isset($_POST['home'])) {
74                 $_new_modules  = array();
75                 foreach ($_POST['home'] as $m) {
76                         if ($m == $down) {
77                                 $found = TRUE;
78                                 continue;
79                         }
80                         $_new_modules[] = $m;
81                         if ($found) {
82                                 $_new_modules[] = $down;
83                                 $found = FALSE;
84                         }
85                 }
86
87                 $_POST['home'] = $_new_modules;
88         }
89
90         $_POST['submit'] = TRUE;
91 }
92
93 // 'search.php',  removed
94 if (isset($_POST['submit'])) {
95
96         if (isset($_POST['main'])) {
97                 $_POST['main'] = array_intersect($_POST['main'], $_modules);
98                 $_POST['main'] = array_unique($_POST['main']);
99                 $main_links = implode('|', $_POST['main']);
100         } else {
101                 $main_links = '';
102         }
103
104         if (isset($_POST['home'])) {
105                 $_POST['home'] = array_intersect($_POST['home'], $_modules);
106                 $_POST['home'] = array_unique($_POST['home']);
107                 $home_links = implode('|', $_POST['home']);
108         } else {
109                 $home_links = '';
110         }
111
112         $sql    = "UPDATE ".TABLE_PREFIX."courses SET home_links='$home_links', main_links='$main_links' WHERE course_id=$_SESSION[course_id]";
113         $result = mysql_query($sql, $db);
114
115         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
116         header('Location: modules.php');
117         exit;
118 }
119
120
121 require(AT_INCLUDE_PATH.'header.inc.php');
122
123
124 //being displayed
125 $_current_modules = array_slice($_pages[AT_NAV_COURSE], 1, -1); // removes index.php and tools/index.php
126 $num_main    = count($_current_modules);
127 //main and home merged
128 $_current_modules = array_merge( (array) $_current_modules, array_diff($_pages[AT_NAV_HOME],$_pages[AT_NAV_COURSE]) );
129 $num_modules = count($_current_modules);
130 //all other mods
131 $_current_modules = array_merge( (array) $_current_modules, array_diff($_modules, $_current_modules));
132
133 $count = 0;
134
135 ?>
136 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
137 <table class="data static" rules="rows" summary="">
138 <thead>
139 <tr>
140         <th scope="cols"><?php echo _AT('section'); ?></th>
141         <th><?php echo _AT('location'); ?></th>
142         <th><?php echo _AT('order'); ?></th>
143 </tr>
144 </thead>
145 <tfoot>
146 <tr>
147         <td colspan="3" style="text-align:right;"><input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" /></td>
148 </tr>
149 </tfoot>
150 <tbody>
151 <?php foreach ($_current_modules as $module): ?>
152 <?php $count++; ?>
153 <tr>
154         <td><?php 
155                 if (isset($_pages[$module]['title'])) {
156                         echo $_pages[$module]['title'];
157                 } else {
158                         echo _AT($_pages[$module]['title_var']);
159                 } ?></td>
160         <td>
161                 <?php if (in_array($module, $_pages[AT_NAV_COURSE])): ?>
162                         <input type="checkbox" name="main[]" value="<?php echo $module; ?>" id="m<?php echo $count; ?>" checked="checked" /><label for="m<?php echo $count; ?>"><?php echo _AT('main_navigation'); ?></label>
163                 <?php else: ?>
164                         <input type="checkbox" name="main[]" value="<?php echo $module; ?>" id="m<?php echo $count; ?>" /><label for="m<?php echo $count; ?>"><?php echo _AT('main_navigation'); ?></label>
165                 <?php endif; ?>
166
167                 <?php if (in_array($module, $_pages[AT_NAV_HOME])): ?>
168                         <input type="checkbox" name="home[]" value="<?php echo $module; ?>" id="h<?php echo $count; ?>" checked="checked" /><label for="h<?php echo $count; ?>"><?php echo _AT('home'); ?></label>
169                 <?php else: ?>
170                         <input type="checkbox" name="home[]" value="<?php echo $module; ?>" id="h<?php echo $count; ?>" /><label for="h<?php echo $count; ?>"><?php echo _AT('home'); ?></label>
171                 <?php endif; ?>
172         </td>
173         <td align="right">
174                 <?php if (!in_array($module, $_pages[AT_NAV_HOME]) && !in_array($module, $_pages[AT_NAV_COURSE])): ?>
175                         &nbsp;
176                 <?php else: ?>
177                         <?php if (($count != $num_main+1) && ($count > 1)): ?>
178                                 <input type="submit" name="up[<?php echo $module; ?>]" value="<?php echo _AT('move_up'); ?>" title="<?php echo _AT('move_up'); ?>" style="background-color: white; border: 1px solid; padding: 0px;" />
179                         <?php else: ?>
180                                 <img src="images/clr.gif" alt="" width="12" />
181                         <?php endif; ?>
182                         <?php if (($count != $num_main) && ($count < $num_modules)): ?>
183                                 <input type="submit" name="down[<?php echo $module; ?>]" value="<?php echo _AT('move_down'); ?>" title="<?php echo _AT('move_down'); ?>" style="background-color: white; border: 1px solid; padding: 0px;"/>
184                         <?php else: ?>
185                                 <img src="images/clr.gif" alt="" width="12" />
186                         <?php endif; ?>
187                 <?php endif; ?>
188         </td>
189 </tr>
190 <?php endforeach; ?>
191 </tbody>
192 </table>
193 </form>
194
195 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>