forked from ChelseaSchool/MyIEP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
superuser_manage_coding.php
executable file
·280 lines (253 loc) · 12.2 KB
/
superuser_manage_coding.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
<?php
/** @file
* @brief manage code availability and validity (as superuser)
* @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 Filter input
*/
//the authorization level for this page!
$MINIMUM_AUTHORIZATION_LEVEL = 0; //only super administrator
/**
* 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');
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 **************************
//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();
}
//************** validated past here ****************
function parse_submission() {
//returns null on success else returns $szError
global $content,$fileName,$fileType;
$regexp='/^[0-9]*$/';
if(!preg_match($regexp, $_POST['code'])) return "You must supply a valid code number (numbers only)<BR>";
if(!$_POST['code_text']) return "You must supply a code description<BR>";
return NULL;
}
//check if we are adding a code...
if(isset($_POST['add_code'])) {
$retval=parse_submission();
if($retval != NULL) {
//no way...
$system_message = $system_message . $retval;
} else {
//we add the entry.
$insert_query = "INSERT INTO valid_coding (code_number,code_text) VALUES ('" . mysql_real_escape_string($_POST['code']) . "','" . mysql_real_escape_string($_POST['code_text']) . "')";
$insert_result = mysql_query($insert_query);
if(!$insert_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '" . $insert_query . "<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
} else {
//clear some fields
unset($_POST['code']);
unset($_POST['code_text']);
}
}
}
//check if we are deleting some entries...
if(isset($_POST['delete_x']) && $permission_level <= $IPP_MIN_DELETE_CODE) {
$delete_query = "DELETE FROM valid_coding WHERE ";
foreach($_POST as $key => $value) {
if(preg_match('/^(\d)*$/',$key))
$delete_query = $delete_query . "code_number=" . $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');
}
}
$code_query="SELECT * FROM valid_coding WHERE 1 ORDER by code_number ASC";
$code_result = mysql_query($code_query);
if(!$code_result) {
$error_message = "Database query failed (" . __FILE__ . ":" . __LINE__ . "): " . mysql_error() . "<BR>Query: '$code_query'<BR>";
$system_message= $system_message . $error_message;
IPP_LOG($system_message,$_SESSION['egps_username'],'ERROR');
}
?>
<!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 = "codelist=";
var szConfirmMessage = "Are you sure you want to delete the following:\n";
var count = 0;
form=document.codelist;
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 + form.elements[x].name + ",";
count++;
}
}
}
if(!count) { alert("Nothing Selected"); return false; }
if(confirm(szConfirmMessage))
return true;
else
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("main.php"); ?></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">-Manage Codes-</p></center></td></tr></table></center>
<BR>
<!-- BEGIN add code -->
<center>
<form name="add_code" enctype="multipart/form-data" action="<?php echo IPP_PATH . "superuser_manage_coding.php"; ?>" method="post">
<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_code" value="1">
</td>
</tr>
<tr>
<td valign="bottom" bgcolor="#E0E2F2" class="row_default">Code Number:</td>
<td bgcolor="#E0E2F2" class="row_default">
<input type="text" tabindex="1" name="code" value="<?php if(isset($_POST['code'])) echo $_POST['code']; ?>" size="10" maxsize="10">
</td>
<td valign="center" align="center" bgcolor="#E0E2F2" rowspan="2" class="row_default"><input type="submit" tabindex="3" value="add" value="add"></td>
</tr>
<tr>
<td valign="bottom" bgcolor="#E0E2F2" class="row_default">Code Description</td>
<td bgcolor="#E0E2F2" class="row_default">
<input type="text" tabindex="2" name="code_text" value="<?php if(isset($_POST['code_text'])) echo $_POST['code_text']; ?>" size="30" maxsize="254">
</td>
</tr>
</table>
</form>
</center>
<!-- END add code -->
<!-- BEGIN codes table -->
<form name="codelist" onSubmit="return confirmChecked();" enctype="multipart/form-data" action="<?php echo IPP_PATH . "superuser_manage_coding.php"; ?>" method="post">
<center><table width="80%" border="0" cellpadding="0" cellspacing="1">
<tr><td colspan="6">Codes:</td></tr>
<?php
$bgcolor = "#DFDFDF";
//print the header row...
echo "<tr><td bgcolor=\"#E0E2F2\"> </td><td align=\"center\" bgcolor=\"#E0E2F2\">Code</td><td align=\"center\" bgcolor=\"#E0E2F2\">Code Description</td></tr>\n";
while ($code_row=mysql_fetch_array($code_result)) { //current...
echo "<tr>\n";
echo "<td bgcolor=\"#E0E2F2\"><input type=\"checkbox\" name=\"" . $code_row['code_number'] . "\"></td>";
echo "<td bgcolor=\"$bgcolor\" class=\"row_default\">" . $code_row['code_number'] . "</td>\n";
echo "<td bgcolor=\"$bgcolor\" class=\"row_default\">" . $code_row['code_text'] . "</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 we have permissions also allow delete.
if($permission_level <= $IPP_MIN_DELETE_SCHOOL) {
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 codes 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("main.php"); ?>
<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>