forked from ChelseaSchool/MyIEP
/
strength_need_view.php
executable file
·395 lines (356 loc) · 18.8 KB
/
strength_need_view.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
<?php
/** @file
* @brief display student's strengths and needs
* @copyright 2014 Chelsea School
* @copyright 2005 Grasslands Regional Division #6
* @copyright This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @authors Rik Goldman, Sabre Goldman, Jason Banks, Alex, James, Paul, Bryan, TJ, Jonathan, Micah, Stephen, Joseph
* @author M. Nielson
* @todo
* 1. Filter input
* 2. Why not set whole header with PHP, rather than just pragma?
* 3. Set form character set (UTF-8)
* 4. Make all pages UTF-8 in html header or php
*
*/
//the authorization level for this page!
$MINIMUM_AUTHORIZATION_LEVEL = 100; //everybody
/** @remark page takes $_GET['student_id'] as input
*
*/
/**
* 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/supporting_functions.php');
header('Pragma: no-cache'); //don't cache this page!
//* @todo make authenication check a function with productive parameters
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 **************************
//* @todo confirm input should be a function
$student_id="";
if(isset($_GET['student_id'])) $student_id= $_GET['student_id'];
if(isset($_POST['student_id'])) $student_id = $_POST['student_id'];
if($student_id=="") {
//we shouldn't be here without a student id.
echo "You've entered this page without supplying a valid student id. Fatal, quitting";
exit();
}
//check permission levels
//* @todo permission level check should be a function
$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);}
//check if we are adding...
if(isset($_GET['add_strength_or_need']) && $have_write_permission) {
//minimal testing of input...
if($_GET['strength_or_need'] == "") $system_message = $system_message . "You must choose either strength or need<BR>";
else {
$add_query = "INSERT INTO area_of_strength_or_need (student_id, strength_or_need,description,is_valid) VALUES (" . mysql_real_escape_string($student_id) . ",'" . mysql_real_escape_string($_GET['strength_or_need']) . "','" . mysql_real_escape_string($_GET['description']) . "','Y')";
$add_result = mysql_query($add_query);
if(!$add_result) {
$error_message = $error_message . "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$add_query'<BR>";
$system_message=$system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
}
//reset the variables...
$_GET['strength_or_need'] = "";
}
//$system_message = $system_message . $add_query . "<BR>";
}
//check if we are deleting some entries...
if(isset($_GET['delete_x']) && $permission_level <= $IPP_MIN_DELETE_STRENGTH_NEED_PERMISSION && $have_write_permission ) {
$delete_query = "DELETE FROM area_of_strength_or_need WHERE ";
foreach($_GET as $key => $value) {
if(preg_match('/^(\d)*$/',$key))
$delete_query = $delete_query . "uid=" . $key . " or ";
}
//strip trailing 'or' and whitespace
$delete_query = substr($delete_query, 0, -4);
//$system_message = $system_message . $delete_query . "<BR>";
$delete_result = mysql_query($delete_query);
if(!$delete_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$delete_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
}
}
//check if we are setting some entries not ongoing (field='is_valid')...
if(isset($_GET['set_not_current_x']) && $have_write_permission ) {
$modify_query = "UPDATE area_of_strength_or_need SET is_valid='N' WHERE ";
foreach($_GET as $key => $value) {
if(preg_match('/^(\d)*$/',$key))
$modify_query = $modify_query . "uid=" . $key . " or ";
}
//strip trailing 'or' and whitespace
$modify_query = substr($modify_query, 0, -4);
//$system_message = $system_message . $delete_query . "<BR>";
$modify_result = mysql_query($modify_query);
if(!$modify_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$modify_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
}
}
//check if we are setting some entries ongoing field='is_valid'...
if(isset($_GET['set_current_x']) && $have_write_permission ) {
$modify_query = "UPDATE area_of_strength_or_need SET is_valid='Y' WHERE ";
foreach($_GET as $key => $value) {
if(preg_match('/^(\d)*$/',$key))
$modify_query = $modify_query . "uid=" . $key . " or ";
}
//strip trailing 'or' and whitespace
$modify_query = substr($modify_query, 0, -4);
//$system_message = $system_message . $delete_query . "<BR>";
$modify_result = mysql_query($modify_query);
if(!$modify_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$modify_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
}
}
//get the strengths/needs for this student...
$strength_query="SELECT * FROM area_of_strength_or_need WHERE student_id=$student_id ORDER BY is_valid ASC, strength_or_need ASC";
$strength_result = mysql_query($strength_query);
if(!$strength_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$strength_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
}
/** @fn
* @brief very unclear
* @description Why is code a function?
* @todo
* 1. Find out what calls this function and what it is intended to do
* 2. Rename this function so the name is effective and productive
*
*/
//get enum fields for area...
function mysql_enum_values($tableName,$fieldName)
{
$result = mysql_query("DESCRIBE $tableName");
//then loop:
while($row = mysql_fetch_array($result))
{
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_area = mysql_enum_values("area_of_strength_or_need","area");
?>
<!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">
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 noPermission() {
alert("You don't have the permission level necessary"); return false;
}
</SCRIPT>
</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("student_view.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"> Strengths and Needs (<?php echo $student_row['first_name'] . " " . $student_row['last_name']; ?>)-</p></center></td></tr></table></center>
<BR>
<!-- BEGIN add supervisor -->
<center>
<form name="add_strength_or_need" enctype="multipart/form-data" action="<?php echo IPP_PATH . "strength_need_view.php"; ?>" method="get" <?php if(!$have_write_permission) echo "onSubmit=\"return noPermission();\"" ?>>
<table border="0" cellspacing="0" cellpadding ="0" width="80%">
<tr>
<td colspan="3">
<p class="info_text">Edit and click 'Add'.</p>
<input type="hidden" name="add_strength_or_need" value="1">
<input type="hidden" name="student_id" value="<?php echo $student_id; ?>">
</td>
</tr>
<tr>
<td valign="bottom" bgcolor="#E0E2F2" class="row_default">Strength or Need:</td>
<td bgcolor="#E0E2F2" class="row_default">
<select name="strength_or_need" tabindex="1">
<option value="">-Choose-</option>
<option value="Strength" <?php if(isset($_GET['strength_or_need']) && $_GET['strength_or_need'] == 'Strength') echo "SELECTED"; ?>>Strength</option>
<option value="Need" <?php if(isset($_GET['strength_or_need']) && $_GET['strength_or_need'] == 'Need') echo "SELECTED"; ?>>Need</option>
</select>
</td>
<td valign="center" align="center" bgcolor="#E0E2F2" rowspan="2" class="row_default"><input type="submit" tabindex="3" name="add" value="add"></td>
</tr>
<tr>
<td valign="center" bgcolor="#E0E2F2" class="row_default">Description:</td><td bgcolor="#E0E2F2" class="row_default"><textarea spellcheck="true" name="description" tabindex="2" cols="30" rows="3" wrap="soft"><?php if(isset($_GET['description'])) echo $_GET['description']; ?></textarea></td>
</tr>
</table>
</form>
</center>
<!-- END add supervisor -->
<!-- BEGIN strength/needs table -->
<form name="strengthneedslist" onSubmit="return confirmChecked();" enctype="multipart/form-data" action="<?php echo IPP_PATH . "strength_need_view.php"; ?>" method="get">
<input type="hidden" name="student_id" value="<?php echo $student_id ?>">
<center><table width="80%" border="0" cellpadding="0" cellspacing="1">
<tr><td colspan="6">Strengths and Needs:</td></tr>
<?php
$bgcolor = "#DFDFDF";
//print the header row...
echo "<tr><td bgcolor=\"#E0E2F2\"> </td><td bgcolor=\"#E0E2F2\">UID</td><td align=\"center\" bgcolor=\"#E0E2F2\">Type</td><td align=\"center\" bgcolor=\"#E0E2F2\">Description (click to edit)</td><td align=\"center\" bgcolor=\"#E0E2F2\">Ongoing*</td></tr>\n";
while ($strength_row=mysql_fetch_array($strength_result)) { //current...
echo "<tr>\n";
echo "<td bgcolor=\"#E0E2F2\"><input type=\"checkbox\" name=\"" . $strength_row['uid'] . "\"></td>";
echo "<td bgcolor=\"$bgcolor\" class=\"row_default\">" . $strength_row['uid'] . "</td>";
echo "<td bgcolor=\"$bgcolor\" class=\"row_default\"><a href=\"" . IPP_PATH . "edit_strength_need.php?uid=" . $strength_row['uid'] . "\" class=\"editable_text\">" . $strength_row['strength_or_need'] ."</a></td>\n";
echo "<td bgcolor=\"$bgcolor\" class=\"row_default\"><a href=\"" . IPP_PATH . "edit_strength_need.php?uid=" . $strength_row['uid'] . "\" class=\"editable_text\">" . checkSpelling($strength_row['description']) . "</a></td>\n";
echo "<td bgcolor=\"$bgcolor\" class=\"row_default\"><center><a href=\"" . IPP_PATH . "edit_strength_need.php?uid=" . $strength_row['uid'] . "\" class=\"editable_text\">" . $strength_row['is_valid'] . "</a></center></td>\n";
echo "</tr>\n";
if($bgcolor=="#DFDFDF") $bgcolor="#CCCCCC";
else $bgcolor="#DFDFDF";
}
?>
<tr>
<td colspan="6" align="left">
<table>
<tr>
<td nowrap>
<img src="<?php echo IPP_PATH . "images/table_arrow.png"; ?>"> With Selected:
</td>
<td>
<?php
if($have_write_permission) {
echo "<INPUT NAME=\"set_not_current\" TYPE=\"image\" SRC=\"" . IPP_PATH . "images/smallbutton.php?title=Not+Ongoing\" border=\"0\" value=\"1\">";
echo "<INPUT NAME=\"set_current\" TYPE=\"image\" SRC=\"" . IPP_PATH . "images/smallbutton.php?title=Ongoing\" border=\"0\" value=\"1\">";
}
//if we have permissions also allow delete and set all.
if($permission_level <= $IPP_MIN_DELETE_STRENGTH_NEED_PERMISSION && $have_write_permission) {
echo "<INPUT NAME=\"delete\" TYPE=\"image\" SRC=\"" . IPP_PATH . "images/smallbutton.php?title=Delete\" border=\"0\" value=\"1\">";
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table></center>
</form>
<!-- end strength/needs table -->
</div>
</td>
</tr>
</table></center>
</td>
<td class="shadow-right"></td>
</tr>
<tr>
<td class="shadow-left"> </td>
<td class="shadow-center">
<?php navbar("student_view.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>