f427e34e713ee7ed209cd57183a469fa0b4b0c1d
[atutor.git] / docs / mods / _standard / course_tools / modules.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 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 $savant->assign('num_modules', $num_modules);
134 $savant->assign('num_main', $num_main);
135 $savant->assign('current_modules', $_current_modules);
136 $savant->display('instructor/course_tools/modules.tmpl.php');
137 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>