made a copy
[atutor.git] / tools / enrollment / verify_list.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/\r
6 /* Adaptive Technology Resource Centre / University of Toronto                  */\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.'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 /*************  INFO GATHERED  **************/\r
78 \r
79 require(AT_INCLUDE_PATH.'header.inc.php');\r
80 \r
81 \r
82 if ($_POST['verify']) {\r
83         for ($i=0; $i<$_POST['count']; $i++) {\r
84                 $info = array('fname' => $_POST['fname'.$i], 'lname' => $_POST['lname'.$i], 'email' => $_POST['email'.$i], 'uname' => $_POST['uname'.$i], 'remove' => $_POST['remove'.$i]);\r
85                 $students[] = checkUserInfo($info);\r
86 \r
87                 if (!empty($students[$i]['err_email']) || !empty($students[$i]['err_uname'])) {\r
88                         $still_errors = TRUE;\r
89                 }\r
90         }\r
91 \r
92         /**************************************************************************/\r
93         // !!!!!!STEP 3 - INSERT INTO DB !!!!!!!\r
94         if (!$still_errors && (isset($_POST['submit_unenr']) || isset($_POST['submit_enr']))) {                 \r
95 \r
96                 $enroll = 'y';\r
97                 if (isset($_POST['submit_unenr'])) {\r
98                         $enroll = 'n';\r
99                 }\r
100 \r
101                 add_users($students, $enroll, $_SESSION['course_id']);\r
102 \r
103                 $msg->printFeedbacks(); ?>\r
104 \r
105                 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="finalform" />\r
106                 <div class="input-form">\r
107                         <div class="row buttons">\r
108                                 <input type="submit" name="addmore" value="<?php echo _AT('add_more'); ?>" />\r
109                                 <input type="submit" name="return"  value="<?php echo _AT('done'); ?>" />\r
110                         </div>\r
111                 </div>\r
112                 </form><?php                            \r
113         }\r
114 \r
115 }\r
116 \r
117 // STEP 2 - INTERNAL VERIFICATION\r
118 if ($still_errors || !isset($_POST['verify']) || isset($_POST['resubmit'])) { ?>\r
119 \r
120         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">\r
121         <input type="hidden" name="verify" value="1" />\r
122         <input type="hidden" name="count" value="<?php echo count($students); ?>" />\r
123                 \r
124         <table class="data static" summary="" rules="cols">\r
125         <thead>\r
126         <tr>\r
127                 <th scope="col"><?php echo _AT('status');     ?></th>\r
128                 <th scope="col"><?php echo _AT('first_name'); ?></th>\r
129                 <th scope="col"><?php echo _AT('last_name');  ?></th>\r
130                 <th scope="col"><?php echo _AT('email');      ?></th>\r
131                 <th scope="col"><?php echo _AT('login_name'); ?></th>\r
132                 <th scope="col"><?php echo _AT('remove');     ?></th>\r
133         </tr>\r
134         </thead><?php\r
135 \r
136         $err_count = 0;\r
137         $i=0;\r
138         if (is_array($students)) {\r
139                 echo '<tbody>';\r
140                 foreach ($students as $student) {\r
141                         echo '<tr><small>';\r
142                         echo '<td><span style="color: red;">';\r
143 \r
144                         //give status\r
145                         if(!empty($student['err_email'])) {\r
146                                 echo $student['err_email'];\r
147                         }\r
148 \r
149                         if(!empty($student['err_uname'])) {\r
150                                 if(!empty($student['err_email'])) {\r
151                                         echo '<br />';\r
152                                 }\r
153                                 echo $student['err_uname'];\r
154                         }               \r
155                         if (empty($student['err_uname']) && empty($student['err_email'])) {\r
156                                  \r
157                                 if ($student['remove']) {\r
158                                         echo '</span><span style="color: purple;">'._AT('removed');\r
159                                 } else if ($student['err_disabled']) {\r
160                                         echo '</span><span style="color: purple;">'._AT('disabled');                                                            \r
161                                 } else if (!empty($student['exists'])) {\r
162                                         echo '</span><span style="color: green;">'._AT('ok').' - '.$student['exists'];\r
163                                 } else {\r
164                                         echo '</span><span style="color: green;">'._AT('ok');                                                           \r
165                                 }\r
166                         } else {\r
167                                 $err_count++;\r
168                         }\r
169                         echo '</span></td>';\r
170 \r
171                         if (empty($student['exists'])) {\r
172                                 echo '<td><input type="text" name="fname'.$i.'" value="'.$student['fname'].'" /></td>';\r
173                                 echo '<td><input type="text" name="lname'.$i.'" value="'.$student['lname'].'" /></td>';\r
174                                 echo '<td><input type="text" name="email'.$i.'" value="'.$student['email'].'" /></td>';         \r
175                                 echo '<td><input type="text" name="uname'.$i.'" value="'.$student['uname'].'" />';      \r
176                                 echo '<td><input type="checkbox" ';                                     \r
177                                 echo ($student['remove'] ? 'checked="checked" value="on"' : '');                                          \r
178                                 echo 'name="remove'.$i.'" />';\r
179                         } else {\r
180                                 echo '<input type="hidden" name="fname'.$i.'" value="'.$student['fname'].'" />';                \r
181                                 echo '<input type="hidden" name="lname'.$i.'" value="'.$student['lname'].'" />';                \r
182                                 echo '<input type="hidden" name="email'.$i.'" value="'.$student['email'].'" />';                \r
183                                 echo '<input type="hidden" name="uname'.$i.'" value="'.$student['uname'].'" />';                \r
184 \r
185                                 echo '<td>'.AT_print($student['fname'], 'members.first_name').'</td>';\r
186                                 echo '<td>'.AT_print($student['lname'], 'members.last_name').'</td>';\r
187                                 echo '<td>'.AT_print($student['email'], 'members.email').'</td>';\r
188                                 echo '<td>'.AT_print($student['uname'], 'members.login').'</td>';\r
189                                 echo '<td><input type="checkbox" ';                                     \r
190                                 echo ($student['remove'] ? 'checked="checked" value="on"' : '');                                          \r
191                                 echo 'name="remove'.$i.'" />';\r
192                         }\r
193                         $i++;\r
194                         echo '</tr>';\r
195                 }\r
196                 echo '</tbody>';\r
197         }\r
198 \r
199         $dsbld = '';\r
200         if ($still_errors || $err_count>0) {\r
201                 $dsbld = 'disabled="disabled"';\r
202         } ?>\r
203 \r
204         <tfoot>\r
205         <tr>\r
206                 <td colspan="6">\r
207                         <input type="submit" name="resubmit" value="<?php echo _AT('resubmit'); ?>" />\r
208                         <input type="submit" name="submit_enr" value="<?php echo _AT('list_add_enrolled_list'); ?>" <?php echo $dsbld; ?> />\r
209                 </td>\r
210         </tr>\r
211         </tfoot>\r
212 \r
213         </table>\r
214         </form><?php\r
215 }\r
216 \r
217 require(AT_INCLUDE_PATH.'footer.inc.php');\r
218 ?>