00bec79d6e477a09f68f7b531a09539d76e2f99b
[atutor.git] / docs / mods / _core / enrolment / verify_list.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2010                                              */\r
6 /* Inclusive Design Institute                                           */\r
7 /* http://atutor.ca                                                                                                             */\r
8 /*                                                                                                                                              */\r
9 /* This program is free software. You can redistribute it and/or        */\r
10 /* modify it under the terms of the GNU General Public License          */\r
11 /* as published by the Free Software Foundation.                        */\r
12 /************************************************************************/\r
13 // $Id$\r
14 \r
15 define('AT_INCLUDE_PATH', '../../../include/');\r
16 require (AT_INCLUDE_PATH.'vitals.inc.php');\r
17 authenticate(AT_PRIV_ENROLLMENT);\r
18 require(AT_INCLUDE_PATH.'../mods/_core/enrolment/lib/enroll.inc.php');\r
19 \r
20 /************  GETTING INFO FROM CREATE/IMPORT CALLS  **********/\r
21 if (isset($_POST['addmore'])) {\r
22         //$msg->addFeedback('ADDMORE');\r
23         header('Location: create_course_list.php');\r
24         exit;\r
25 } else if (isset($_POST['return'])) {\r
26         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
27         header('Location: index.php');\r
28         exit;\r
29 } else if (isset($_POST['cancel'])) {\r
30         $msg->addFeedback('CANCELLED');\r
31         header('Location: index.php');  \r
32         exit;\r
33 } else if (isset($_POST['submit']) && !$_POST['verify']) {\r
34         //CREATE COURSE LIST!!!!!!\r
35         if ($_POST['from'] == 'create') {\r
36                 if (empty($_POST['first_name1']) && empty($_POST['last_name1']) && empty($_POST['email1'])) {\r
37                         $msg->addError('INCOMPLETE');\r
38                         header('Location: ./create_course_list.php');\r
39                         exit;\r
40                 } else {\r
41                         $j=1;\r
42                         while ($_POST['first_name'.$j] || $_POST['last_name'.$j] || $_POST['email'.$j]) {\r
43                                 $students[] = checkUserInfo(array('fname' => $_POST['first_name'.$j], 'lname' => $_POST['last_name'.$j], 'email' => $_POST['email'.$j]));\r
44                                 $j++;\r
45                         }\r
46                 }\r
47         } \r
48         //IMPORT COURSE LIST!!!!!!\r
49         else if ($_POST['from'] == 'import') {\r
50                 if ($_FILES['file']['size'] < 1) {\r
51                         $msg->addError('FILE_EMPTY');\r
52                         header('Location: ./import_course_list.php');\r
53                         exit;\r
54                 } else {\r
55                         $fp = fopen($_FILES['file']['tmp_name'],'r');\r
56                         $line_number=0;\r
57                         while ($data = fgetcsv($fp, 100000, ',')) {\r
58                                 $line_number++;\r
59                                 $num_fields = count($data);\r
60                                 if ($num_fields == 3) {\r
61                                         $students[] = checkUserInfo(array('fname' => $data[0], 'lname' => $data[1], 'email' => $data[2]));\r
62                                 } else if ($num_fields != 1) {\r
63                                         $errors = array('INCORRECT_FILE_FORMAT', $line_number);\r
64                                         $msg->addError($errors);\r
65                                         header('Location: ./import_course_list.php');\r
66                                         exit;\r
67                                 } else if (($num_fields == 1) && (trim($data[0]) != '')) {\r
68                                         $errors = array('INCORRECT_FILE_FORMAT', $line_number);\r
69                                         $msg->addError($errors);\r
70                                         header('Location: ./import_course_list.php');\r
71                                         exit;\r
72                                 }\r
73                         }\r
74                 }\r
75 \r
76         }\r
77\r
78 /*************  INFO GATHERED  **************/\r
79 \r
80 require(AT_INCLUDE_PATH.'header.inc.php');\r
81 \r
82 \r
83 if ($_POST['verify']) {\r
84         for ($i=0; $i<$_POST['count']; $i++) {\r
85                 $info = array('fname' => $_POST['fname'.$i], 'lname' => $_POST['lname'.$i], 'email' => $_POST['email'.$i], 'uname' => $_POST['uname'.$i], 'remove' => $_POST['remove'.$i]);\r
86                 $students[] = checkUserInfo($info);\r
87 \r
88                 if (!empty($students[$i]['err_email']) || !empty($students[$i]['err_uname'])) {\r
89                         $still_errors = TRUE;\r
90                 }\r
91         }\r
92 \r
93         /**************************************************************************/\r
94         // !!!!!!STEP 3 - INSERT INTO DB !!!!!!!\r
95         if (!$still_errors && (isset($_POST['submit_unenr']) || isset($_POST['submit_enr']))) {                 \r
96 \r
97                 $enroll = 'y';\r
98                 if (isset($_POST['submit_unenr'])) {\r
99                         $enroll = 'n';\r
100                 }\r
101 \r
102                 add_users($students, $enroll, $_SESSION['course_id']);\r
103 \r
104 \r
105                   ?>\r
106                  <div id="container">\r
107                 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="finalform" />\r
108                 <div class="input-form">\r
109                 <?php\r
110                 $msg->printFeedbacks();\r
111                 ?>\r
112                         <div class="row buttons">\r
113                                 <input type="submit" name="addmore" value="<?php echo _AT('add_more'); ?>" />\r
114                                 <input type="submit" name="return"  value="<?php echo _AT('done'); ?>" />\r
115                         </div>\r
116                 </div>\r
117                 </form></div><?php                              \r
118         }\r
119 \r
120 }\r
121 \r
122 // STEP 2 - INTERNAL VERIFICATION\r
123 if ($still_errors || !isset($_POST['verify']) || isset($_POST['resubmit'])) { ?>\r
124 \r
125         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">\r
126         <input type="hidden" name="verify" value="1" />\r
127         <input type="hidden" name="count" value="<?php echo count($students); ?>" />\r
128                 \r
129         <table class="data static" summary="" rules="cols">\r
130         <thead>\r
131         <tr>\r
132                 <th scope="col"><?php echo _AT('status');     ?></th>\r
133                 <th scope="col"><?php echo _AT('first_name'); ?></th>\r
134                 <th scope="col"><?php echo _AT('last_name');  ?></th>\r
135                 <th scope="col"><?php echo _AT('email');      ?></th>\r
136                 <th scope="col"><?php echo _AT('login_name'); ?></th>\r
137                 <th scope="col"><?php echo _AT('remove');     ?></th>\r
138         </tr>\r
139         </thead><?php\r
140 \r
141         $err_count = 0;\r
142         $i=0;\r
143         if (is_array($students)) {\r
144                 echo '<tbody>';\r
145                 foreach ($students as $student) {\r
146                         echo '<tr><small>';\r
147                         echo '<td><span style="color: red;">';\r
148 \r
149                         //give status\r
150                         if(!empty($student['err_email'])) {\r
151                                 echo $student['err_email'];\r
152                         }\r
153 \r
154                         if(!empty($student['err_uname'])) {\r
155                                 if(!empty($student['err_email'])) {\r
156                                         echo '<br />';\r
157                                 }\r
158                                 echo $student['err_uname'];\r
159                         }               \r
160                         if (empty($student['err_uname']) && empty($student['err_email'])) {\r
161                                  \r
162                                 if ($student['remove']) {\r
163                                         echo '</span><span style="color: purple;">'._AT('removed');\r
164                                 } else if ($student['err_disabled']) {\r
165                                         echo '</span><span style="color: purple;">'._AT('disabled');                                                            \r
166                                 } else if (!empty($student['exists'])) {\r
167                                         echo '</span><span style="color: green;">'._AT('ok').' - '.$student['exists'];\r
168                                 } else {\r
169                                         echo '</span><span style="color: green;">'._AT('ok');                                                           \r
170                                 }\r
171                         } else {\r
172                                 $err_count++;\r
173                         }\r
174                         echo '</span></td>';\r
175 \r
176                         if (empty($student['exists'])) {\r
177                                 echo '<td><input type="text" name="fname'.$i.'" value="'.$student['fname'].'" /></td>';\r
178                                 echo '<td><input type="text" name="lname'.$i.'" value="'.$student['lname'].'" /></td>';\r
179                                 echo '<td><input type="text" name="email'.$i.'" value="'.$student['email'].'" /></td>';         \r
180                                 echo '<td><input type="text" name="uname'.$i.'" value="'.$student['uname'].'" />';      \r
181                                 echo '<td><input type="checkbox" ';                                     \r
182                                 echo ($student['remove'] ? 'checked="checked" value="on"' : '');                                          \r
183                                 echo 'name="remove'.$i.'" />';\r
184                         } else {\r
185                                 echo '<input type="hidden" name="fname'.$i.'" value="'.$student['fname'].'" />';                \r
186                                 echo '<input type="hidden" name="lname'.$i.'" value="'.$student['lname'].'" />';                \r
187                                 echo '<input type="hidden" name="email'.$i.'" value="'.$student['email'].'" />';                \r
188                                 echo '<input type="hidden" name="uname'.$i.'" value="'.$student['uname'].'" />';                \r
189 \r
190                                 echo '<td>'.AT_print($student['fname'], 'members.first_name').'</td>';\r
191                                 echo '<td>'.AT_print($student['lname'], 'members.last_name').'</td>';\r
192                                 echo '<td>'.AT_print($student['email'], 'members.email').'</td>';\r
193                                 echo '<td>'.AT_print($student['uname'], 'members.login').'</td>';\r
194                                 echo '<td><input type="checkbox" ';                                     \r
195                                 echo ($student['remove'] ? 'checked="checked" value="on"' : '');                                          \r
196                                 echo 'name="remove'.$i.'" />';\r
197                         }\r
198                         $i++;\r
199                         echo '</tr>';\r
200                 }\r
201                 echo '</tbody>';\r
202         }\r
203 \r
204         $dsbld = '';\r
205         if ($still_errors || $err_count>0) {\r
206                 $dsbld = 'disabled="disabled"';\r
207         } ?>\r
208 \r
209         <tfoot>\r
210         <tr>\r
211                 <td colspan="6">\r
212                         <input type="submit" name="resubmit" value="<?php echo _AT('resubmit'); ?>" />\r
213                         <input type="submit" name="submit_enr" value="<?php echo _AT('list_add_enrolled_list'); ?>" <?php echo $dsbld; ?> />\r
214                 </td>\r
215         </tr>\r
216         </tfoot>\r
217 \r
218         </table>\r
219         </form><?php\r
220 }\r
221 \r
222 require(AT_INCLUDE_PATH.'footer.inc.php');\r
223 ?>