Moved scripts in "docs" one level up into root folder. In addition, removed "docs...
[atutor.git] / mods / _core / users / user_enrollment.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: user_enrollment.php 10142 2010-08-17 19:17:26Z hwong $
14 $_user_location = 'admin';
15
16 define('AT_INCLUDE_PATH', '../../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 admin_authenticate(AT_ADMIN_PRIV_ENROLLMENT);
19
20 if (isset($_POST['cancel'])) {
21         $msg->addFeedback('CANCELLED');
22         header('Location: '.AT_BASE_HREF.'mods/_core/users/users.php');
23         exit;
24 } else if (isset($_POST['enrolled_unenroll'])) {
25         $_POST['id'] = intval($_POST['id']);
26
27         if (!is_array($_POST['enrolled'])) {
28                 $msg->addError('NO_ITEM_SELECTED');
29         } else {
30                 $cids = implode(',', $_POST['enrolled']);
31                 $sql = "DELETE FROM ".TABLE_PREFIX."course_enrollment WHERE member_id={$_POST['id']} AND course_id IN ($cids)";
32                 mysql_query($sql, $db);
33
34                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
35                 header('Location: '.$_SERVER['PHP_SELF'] . '?id='.$_POST['id']);
36                 exit;
37         }
38 } else if (isset($_POST['pending_remove'])) {
39         $_POST['id'] = intval($_POST['id']);
40
41         if (!is_array($_POST['pending'])) {
42                 $msg->addError('NO_ITEM_SELECTED');
43         } else {
44                 $cids = implode(',', $_POST['pending']);
45                 $sql = "DELETE FROM ".TABLE_PREFIX."course_enrollment WHERE member_id={$_POST['id']} AND course_id IN ($cids)";
46                 mysql_query($sql, $db);
47
48                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
49                 header('Location: '.$_SERVER['PHP_SELF'] . '?id='.$_POST['id']);
50                 exit;
51         }
52 } else if (isset($_POST['pending_enroll'])) {
53         $_POST['id'] = intval($_POST['id']);
54
55         if (!is_array($_POST['pending'])) {
56                 $msg->addError('NO_ITEM_SELECTED');
57         } else {
58                 $cids = implode(',', $_POST['pending']);
59                 $sql = "UPDATE ".TABLE_PREFIX."course_enrollment SET approved='y' WHERE member_id={$_POST['id']} AND course_id IN ($cids)";
60                 mysql_query($sql, $db);
61
62                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
63                 header('Location: '.$_SERVER['PHP_SELF'] . '?id='.$_POST['id']);
64                 exit;
65         }
66 } else if (isset($_POST['not_enrolled_enroll'])) {
67         $_POST['id'] = intval($_POST['id']);
68
69         if (!is_array($_POST['not_enrolled'])) {
70                 $msg->addError('NO_ITEM_SELECTED');
71         } else {
72                 foreach ($_POST['not_enrolled'] as $cid) {
73                         $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ({$_POST['id']}, $cid, 'y', 0, '', 0)";
74                         mysql_query($sql, $db);
75                 }
76                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
77                 header('Location: '.$_SERVER['PHP_SELF'] . '?id='.$_POST['id']);
78                 exit;
79         }
80 }
81
82 $id = intval($_GET['id']);
83
84 // add the user's name to the page heading:
85 $_pages['mods/_core/users/user_enrollment.php']['title'] = _AT('enrollment').': '.get_display_name($id);
86
87 require(AT_INCLUDE_PATH.'header.inc.php');
88
89 $sql    = "SELECT login FROM ".TABLE_PREFIX."members WHERE member_id=$id";
90 $result = mysql_query($sql, $db);
91
92 if (!$row = mysql_fetch_assoc($result)) {
93         $msg->printErrors('USER_NOT_FOUND');
94         require(AT_INCLUDE_PATH.'footer.inc.php');
95         exit;
96 }
97
98 $enrollment = array();
99 $sql = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE member_id=$id";
100 $result = mysql_query($sql, $db);
101 while ($row = mysql_fetch_assoc($result)) {
102         $enrollment[$row['course_id']] = $row;
103 }
104
105 $instruct     = array();
106 $enrolled     = array();
107 $pending      = array();
108 $not_enrolled = array();
109
110 foreach ($system_courses as $cid => $course) {
111         if ($course['member_id'] == $id) {
112                 $instruct[] = $cid;
113         } else if (isset($enrollment[$cid]) && $enrollment[$cid]['approved'] == 'y') {
114                 $enrolled[] = $cid;
115         } else if (isset($enrollment[$cid]) && $enrollment[$cid]['approved'] == 'n') {
116                 $pending[] = $cid;
117         } else {
118                 $not_enrolled[] = $cid;
119         }
120 }
121
122 ?>
123
124 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $id; ?>">
125 <input type="hidden" name="id" value="<?php echo $id; ?>"/>
126 <div class="input-form" style="min-width: 400px; width: 45%; float: left; margin: 5px">
127         <div class="row">
128         <h3><?php echo _AT('instructor'); ?></h3>
129                 <?php if ($instruct): ?>
130                         <ul>
131                         <?php foreach ($instruct as $cid): ?>
132                                 <li><?php echo $system_courses[$cid]['title']; ?></li>
133                         <?php endforeach; ?>
134                         </ul>
135                 <?php else: ?>
136                         <?php echo _AT('none'); ?>
137                 <?php endif; ?>
138         </div>
139         <div class="row buttons">
140                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"/>
141         </div>
142 </div>
143
144 <div class="input-form" style="min-width: 400px; width: 45%; float: left; margin: 5px">
145         <div class="row">
146         <h3><?php echo _AT('enrolled'); ?></h3>
147                 <?php if ($enrolled): ?>
148                         <ul>
149                         <?php foreach ($enrolled as $cid): ?>
150                                 <li><input type="checkbox" name="enrolled[]" value="<?php echo $cid; ?>" id="c<?php echo $cid; ?>"/><label for="c<?php echo $cid; ?>"><?php echo $system_courses[$cid]['title']; ?></label></li>
151                         <?php endforeach; ?>
152                         </ul>
153                 <?php else: ?>
154                         <?php echo _AT('none'); ?>
155                 <?php endif; ?>
156         </div>
157         <div class="row buttons">
158         <?php if ($enrolled): ?>
159                 <input type="submit" name="enrolled_unenroll" value="<?php echo _AT('unenroll'); ?>"/>
160         <?php endif; ?>
161                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"/>
162         </div>
163
164 </div>
165
166 <div class="input-form" style="min-width: 400px; width: 45%; float: left; margin: 5px">
167         <div class="row">
168         <h3><?php echo _AT('pending_enrollment'); ?></h3>
169                 <?php if ($pending): ?>
170                         <ul>
171                         <?php foreach ($pending as $cid): ?>
172                                 <li><input type="checkbox" name="pending[]" value="<?php echo $cid; ?>" id="c<?php echo $cid; ?>"/><label for="c<?php echo $cid; ?>"><?php echo $system_courses[$cid]['title']; ?></label></li>
173                         <?php endforeach; ?>
174                         </ul>
175                 <?php else: ?>
176                         <?php echo _AT('none'); ?>
177                 <?php endif; ?>
178         </div>
179         <div class="row buttons">
180         <?php if ($pending): ?>
181                 <input type="submit" name="pending_remove" value="<?php echo _AT('remove'); ?>"/>
182                 <input type="submit" name="pending_enroll" value="<?php echo _AT('enroll'); ?>"/>
183         <?php endif; ?>
184                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"/>
185         </div>  
186 </div>
187
188 <div class="input-form" style="min-width: 400px; width: 45%; float: left; margin: 5px">
189         <div class="row">
190                 <h3><?php echo _AT('not_enrolled');?></h3>
191                         <?php if ($not_enrolled): ?>
192                                 <ul>
193                                 <?php foreach ($not_enrolled as $cid): ?>
194                                         <li><input type="checkbox" name="not_enrolled[]" value="<?php echo $cid; ?>" id="c<?php echo $cid; ?>"/><label for="c<?php echo $cid; ?>"><?php echo $system_courses[$cid]['title']; ?></label></li>
195                                 <?php endforeach; ?>
196                                 </ul>
197                         <?php else: ?>
198                                 <?php echo _AT('none'); ?>
199                         <?php endif; ?>
200         </div>
201         <div class="row buttons">
202         <?php if ($not_enrolled): ?>
203                 <input type="submit" name="not_enrolled_enroll" value="<?php echo _AT('enroll'); ?>"/>
204         <?php endif; ?>
205                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"/>
206         </div>
207 </div>
208 </form>
209
210 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>