forked from ChelseaSchool/MyIEP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_school_history.php
executable file
·436 lines (388 loc) · 19.8 KB
/
edit_school_history.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<?php
/**
* @BRIEF history of student's previous schools
*
*/
//the authorization level for this page!
$MINIMUM_AUTHORIZATION_LEVEL = 100; //everybody
/**
* edit_school_history.php
*
* Copyright (c) 2005 Grasslands Regional Division #6
* All rights reserved
*
* Created: March 18, 2006
* By: M. Nielsen
* Modified:
*
*/
/* INPUTS: $_GET['student_id'] || $_POST['student_id']
*
*/
/**
* Path for IPP required files.
*/
$system_message = "";
define('IPP_PATH','./');
/* eGPS required files. */
require_once(IPP_PATH . 'etc/init.php');
require_once(IPP_PATH . 'include/db.php');
require_once(IPP_PATH . 'include/auth.php');
require_once(IPP_PATH . 'include/log.php');
require_once(IPP_PATH . 'include/user_functions.php');
require_once(IPP_PATH . 'include/navbar.php');
require_once(IPP_PATH . 'include/mail_functions.php');
header('Pragma: no-cache'); //don't cache this page!
if(isset($_POST['LOGIN_NAME']) && isset( $_POST['PASSWORD'] )) {
if(!validate( $_POST['LOGIN_NAME'] , $_POST['PASSWORD'] )) {
$system_message = $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
require(IPP_PATH . 'index.php');
exit();
}
} else {
if(!validate()) {
$system_message = $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
require(IPP_PATH . 'index.php');
exit();
}
}
//************* SESSION active past here **************************
$uid="";
if(isset($_GET['uid'])) $uid= $_GET['uid'];
if(isset($_POST['uid'])) $uid = $_POST['uid'];
//get the coordination of services for this student...
$history_query="SELECT * FROM school_history WHERE uid=$uid";
$history_result = mysql_query($history_query);
if(!$history_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$history_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
} else {
$history_row=mysql_fetch_array($history_result);
}
$student_id=$history_row['student_id'];
if($student_id=="") {
//we shouldn't be here without a student id.
echo "Unable to determine student_id from school history table. Fatal, quitting";
exit();
}
//check permission levels
$permission_level = getPermissionLevel($_SESSION['egps_username']);
if( $permission_level > $MINIMUM_AUTHORIZATION_LEVEL || $permission_level == NULL) {
$system_message = $system_message . "You do not have permission to view this page (IP: " . $_SERVER['REMOTE_ADDR'] . ")";
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
require(IPP_PATH . 'security_error.php');
exit();
}
$our_permission = getStudentPermission($student_id);
if($our_permission == "WRITE" || $our_permission == "ASSIGN" || $our_permission == "ALL") {
//we have write permission.
$have_write_permission = true;
} else {
$have_write_permission = false;
}
//************** validated past here SESSION ACTIVE WRITE PERMISSION CONFIRMED****************
$student_query = "SELECT * FROM student WHERE student_id = " . mysql_real_escape_string($student_id);
$student_result = mysql_query($student_query);
if(!$student_result) {
$error_message = $error_message . "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$student_query'<BR>";
$system_message=$system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
} else {$student_row= mysql_fetch_array($student_result);}
function parse_submission() {
//returns null on success else returns $szError
global $history_row;
//check that date is the correct pattern...
$regexp = '/^\d\d\d\d-\d\d?-\d\d?$/';
if(!preg_match($regexp,$_POST['start_date'])) return "Start Date must be in YYYY-MM-DD format<BR>";
if($_POST['end_date'] != "" && !preg_match($regexp,$_POST['end_date'])) return "End Date must be in YYYY-MM-DD format<BR>";
if(!$_POST['school_name']) return "School Name cannot be blank<BR>";
if($_POST['end_date'] == "" && $history_row['school_code']=="") return "You cannot leave end date blank on a school that is not within our district<BR>";
return NULL;
}
//check if we are moving this student...
if(isset($_POST['update_school_history'])) {
$retval=parse_submission();
if($retval != NULL) {
//no way...
$system_message = $system_message . $retval;
} else {
if($_POST['end_date']=="") $end_date = "NULL";
else $end_date = "'" . mysql_real_escape_string($_POST['end_date']) . "'";
if($history_row['end_date'] != "" && $_POST['end_date'] == "") {
//we need to set any other currently enrolled end date
//for this student to end now() ...student can only
//be enrolled in a single school at a time. so much for Keep it simple stupid.
$end_query="UPDATE school_history SET end_date=NOW() WHERE student_id=$student_id AND end_date IS NULL";
$end_result=mysql_query($end_query);
if(!$end_result) {
$error_message = $error_message . "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$end_query'<BR>";
$system_message=$system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
}
}
$update_query="UPDATE school_history SET start_date='" . mysql_real_escape_string($_POST['start_date']) . "', end_date=$end_date,school_name='" . mysql_real_escape_string($_POST['school_name']) . "', school_address='" . mysql_real_escape_string($_POST['school_address']) . "', ipp_present='" . mysql_real_escape_string($_POST['ipp_present']) . "',accommodations='" . mysql_real_escape_string($_POST['accommodations']) . "'";
if($_POST['grades']=="")
$update_query .= ",grades=NULL";
else
$update_query .= ",grades='" . mysql_real_escape_string($_POST['grades']) . "'";
$update_query .= " WHERE uid=$uid LIMIT 1";
$update_result=mysql_query($update_query);
if(!$update_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$update_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
} else {
if($history_row['end_date'] == "" && $_POST['end_date'] != "") $system_message .= "Student IPP has been moved to the IPP Archives<BR>";
//redirect...
header("Location: " . IPP_PATH . "school_history.php?MESSAGE=$system_message&student_id=" . $student_id);
}
}
}
//get enum fields for area...
function mysql_enum_values($tableName,$fieldName)
{
$result = mysql_query("DESCRIBE $tableName");
//then loop:
while($row = mysql_fetch_array($result))
{
//# row is mysql type, in format "int(11) unsigned zerofill"
//# or "enum('cheese','salmon')" etc.
ereg('^([^ (]+)(\((.+)\))?([ ](.+))?$',$row['Type'],$fieldTypeSplit);
//# split type up into array
$ret_fieldName = $row['Field'];
$fieldType = $fieldTypeSplit[1];// eg 'int' for integer.
$fieldFlags = $fieldTypeSplit[5]; // eg 'binary' or 'unsigned zerofill'.
$fieldLen = $fieldTypeSplit[3]; // eg 11, or 'cheese','salmon' for enum.
if (($fieldType=='enum' || $fieldType=='set') && ($ret_fieldName==$fieldName) )
{
$fieldOptions = split("','",substr($fieldLen,1,-1));
return $fieldOptions;
}
}
//if the funciton makes it this far, then it either
//did not find an enum/set field type, or it
//failed to find the the fieldname, so exit FALSE!
return FALSE;
}
$enum_options_type = mysql_enum_values("school_history","ipp_present");
/*************************** popup chooser support function ******************/
function createJavaScript($dataSource,$arrayName='rows'){
// validate variable name
if(!is_string($arrayName)){
$system_message = $system_message . "Error in popup chooser support function name supplied not a valid string (" . __FILE__ . ":" . __LINE__ . ")";
return FALSE;
}
// initialize JavaScript string
$javascript='<!--Begin popup array--><script>var '.$arrayName.'=[];';
// check if $dataSource is a file or a result set
if(is_file($dataSource)){
// read data from file
$row=file($dataSource);
// build JavaScript array
for($i=0;$i<count($row);$i++){
$javascript.=$arrayName.'['.$i.']="'.trim($row[$i]).'";';
}
}
// read data from result set
else{
// check if we have a valid result set
if(!$numRows=mysql_num_rows($dataSource)){
return('Invalid result set parameter');
}
for($i=0;$i<$numRows;$i++){
// build JavaScript array from result set
$javascript.=$arrayName.'['.$i.']="';
$tempOutput='';
//output only the first column
$row=mysql_fetch_array($dataSource);
$tempOutput.=$row[0].' ';
$javascript.=trim($tempOutput).'";';
}
}
$javascript.='</script><!--End popup array-->'."\n";
// return JavaScript code
return $javascript;
}
function echoJSServicesArray() {
global $system_message;
$coordlist_query="SELECT DISTINCT `school_name`, COUNT(`school_name`) AS `count` FROM school_history GROUP BY `school_name` ORDER BY `count` DESC LIMIT 200";
$coordlist_result = mysql_query($coordlist_query);
if(!$coordlist_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$coordlist_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
} else {
//call the function to create the javascript array...
echo createJavaScript($coordlist_result,"popuplist");
}
}
/************************ end popup chooser support funtion ******************/
?>
<!DOCTYPE HTML>
<HTML lang=en>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">
<TITLE><?php echo $page_title; ?></TITLE>
<style type="text/css" media="screen">
<!--
@import "<?php echo IPP_PATH;?>layout/greenborders.css";
-->
</style>
<script language="javascript" src="<?php echo IPP_PATH . "include/popcalendar.js"; ?>"></script>
<script language="javascript" src="<?php echo IPP_PATH . "include/popupchooser.js"; ?>"></script>
<script language="javascript" src="<?php echo IPP_PATH . "include/autocomplete.js"; ?>"></script>
<SCRIPT LANGUAGE="JavaScript">
function confirmChecked() {
var szGetVars = "strengthneedslist=";
var szConfirmMessage = "Are you sure you want to modify/delete the following:\n";
var count = 0;
form=document.strengthneedslist;
for(var x=0; x<form.elements.length; x++) {
if(form.elements[x].type=="checkbox") {
if(form.elements[x].checked) {
szGetVars = szGetVars + form.elements[x].name + "|";
szConfirmMessage = szConfirmMessage + "ID #" + form.elements[x].name + ",";
count++;
}
}
}
if(!count) { alert("Nothing Selected"); return false; }
if(confirm(szConfirmMessage))
return true;
else
return false;
}
function warnArchive() {
alert("Setting this end date will move this student to the IPP archives\nDo this only if the student has moved outside the district.\n(Use the move feature on the school history page to move schools within the district)"); return false;
}
function setOthersEnded() {
var szConfirmMessage = "Setting end date blank will set the currently enrolled schools\nto end effective today. (student can only be enrolled in one school)";
if(document.all.end_date.value == "") {
if(confirm(szConfirmMessage))
return true;
else
return false;
}
}
function noPermission() {
alert("You don't have the permission level necessary"); return false;
}
</SCRIPT>
<?php
//output the javascript array for the chooser popup
echoJSServicesArray();
?>
</HEAD>
<BODY>
<table class="shadow" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="shadow-topLeft"></td>
<td class="shadow-top"></td>
<td class="shadow-topRight"></td>
</tr>
<tr>
<td class="shadow-left"></td>
<td class="shadow-center" valign="top">
<table class="frame" width=620px align=center border="0">
<tr align="Center">
<td><center><img src="<?php echo $page_logo_path; ?>"></center></td>
</tr>
<tr><td>
<center><?php navbar("school_history.php?student_id=$student_id"); ?></center>
</td></tr>
<tr>
<td valign="top">
<div id="main">
<?php if ($system_message) { echo "<center><table width=\"80%\"><tr><td><p class=\"message\">" . $system_message . "</p></td></tr></table></center>";} ?>
<center><table><tr><td><center><p class="header">- IPP Edit School History-<BR>(<?php echo $student_row['first_name'] . " " . $student_row['last_name']; ?>)</p></center></td></tr></table></center>
<BR>
<!-- BEGIN edit history entry -->
<center>
<form name="edit_history" enctype="multipart/form-data" action="<?php echo IPP_PATH . "edit_school_history.php"; ?>" method="post" <?php if(!$have_write_permission) echo "onSubmit=\"return noPermission();\""; else if($history_row['school_code'] !="" && $history_row['end_date'] != "") echo "onSubmit=\"return setOthersEnded();\"";?>>
<table border="0" cellspacing="0" cellpadding ="0" width="80%">
<tr>
<td colspan="3">
<p class="info_text">Edit School History</p>
<input type="hidden" name="update_school_history" value="1">
<input type="hidden" name="uid" value="<?php echo $uid; ?>">
</td>
</tr>
<tr>
<td bgcolor="#E0E2F2" class="row_default">School Name:</td><td bgcolor="#E0E2F2" class="row_default">
<input type="text" tabindex="1" name="school_name" <?php if($history_row['school_code'] != "") echo "disabled"; ?> size="30" maxsize="255" value="<?php echo $history_row['school_name']; ?>" onkeypress="return autocomplete(this,event,popuplist)"> <img src="<?php echo IPP_PATH . "images/choosericon.png"; ?>" height="17" width="17" border=0 <?php if($history_row['school_code'] == "") { echo "onclick=\"popUpChooser(this,document.all.school_name);\""; } ?> >
<?php
if($history_row['school_code'] != "") {
echo "<input type=\"hidden\" name=\"school_name\" value=\"" . $history_row['school_name'] . "\">";
}
?>
</td>
<td valign="center" align="center" bgcolor="#E0E2F2" rowspan="7" class="row_default"><input type="submit" tabindex="6" name="update" value="update"></td>
</tr>
<tr>
<td valign="center" bgcolor="#E0E2F2" class="row_default">School Address (optional):</td><td bgcolor="#E0E2F2" class="row_default"><textarea spellcheck="true" name="school_address" tabindex="2" cols="30" rows="5" wrap="soft"><?php echo $history_row['school_address']; ?></textarea></td>
</tr>
<tr>
<td bgcolor="#E0E2F2" class="row_default">Start Date: (YYYY-MM-DD)</td>
<td bgcolor="#E0E2F2" class="row_default">
<input type="text" tabindex="3" name="start_date" value="<?php echo $history_row['start_date']; ?>"> <img src="<?php echo IPP_PATH . "images/calendaricon.gif"; ?>" height="17" width="17" border=0 onClick="popUpCalendar(this, document.all.start_date, 'yyyy-m-dd', 0, 0)">
</td>
</tr>
<tr>
<td bgcolor="#E0E2F2" class="row_default">End Date: (YYYY-MM-DD)</td>
<td bgcolor="#E0E2F2" class="row_default">
<input <?php if($history_row['end_date']=="") echo "onclick=\"warnArchive();\""; ?> type="text" tabindex="4" name="end_date" value="<?php echo $history_row['end_date']; ?>"> <img src="<?php echo IPP_PATH . "images/calendaricon.gif"; ?>" height="17" width="17" border=0 onClick="<?php if($history_row['end_date']=="") echo "warnArchive();";?>popUpCalendar(this, document.all.end_date, 'yyyy-m-dd', 0, 0)">
</td>
</tr>
<tr>
<td bgcolor="#E0E2F2" class="row_default">IPP Present?:</td>
<td bgcolor="#E0E2F2" class="row_default">
<?php
$tabindex=5;
foreach($enum_options_type as $i => $value) {
echo "<input type=\"radio\" name=\"ipp_present\" tabindex=\"$tabindex\" value=\"$value\"";
if($value == $history_row['ipp_present']) echo " checked";
echo ">$value ";
$tabindex++;
}
?>
</td>
</tr>
<tr>
<td bgcolor="#E0E2F2" class="row_default">Grades:</td>
<td bgcolor="#E0E2F2" class="row_default">
<input type="text" size="10" maxsize="254" tabindex="<?php echo $tabindex; $tabindex++; ?>" name="grades" value="<?php echo $history_row['grades']; ?>">
</td>
</tr>
<tr>
<td valign="center" bgcolor="#E0E2F2" class="row_default">Accommodations (optional):</td><td bgcolor="#E0E2F2" class="row_default"><textarea spellcheck="true" name="accommodations" tabindex="<?php echo $tabindex; ?>" cols="30" rows="5" wrap="soft"><?php echo $history_row['accommodations']; ?></textarea></td>
</tr>
</table>
</form>
</center>
<!-- END edit history entry -->
</div>
</td>
</tr>
</table></center>
</td>
<td class="shadow-right"></td>
</tr>
<tr>
<td class="shadow-left"> </td>
<td class="shadow-center">
<?php navbar("school_history.php?student_id=$student_id"); ?>
</td>
<td class="shadow-right"> </td>
</tr>
<tr>
<td class="shadow-bottomLeft"></td>
<td class="shadow-bottom"></td>
<td class="shadow-bottomRight"></td>
</tr>
</table>
<center></center>
</BODY>
</HTML>