-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.php
385 lines (341 loc) · 11.9 KB
/
func.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
<?php
function dbCon() {
// db connection config vars
require_once('config.php');
$user = DBUSER;
$pass = DBPWD;
$dbName = DBNAME;
$dbHost = DBHOST;
//Connect to Databasea
static $db= null;
$db = new mysqli($dbHost,$user,$pass,$dbName);
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
return $db;
}
function dbPrep($db,$query,$x,$prep) {
//Function to eliminate SQL injections.
$statement = $db->prepare("$query");
if ( $x !== 0 ) {
$statement->bind_param("$x", $prep);
}
$statement->execute();
$statement->bind_result($one);
while($statement->fetch()){
echo $one.'<br />';
}
$statement->free_result();
}
function dbROorig($query) {
//Use only for non-user set/built SQL to avoid injection!
$db=dbCon();
if(!$statement = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $statement->fetch_assoc()){
return array ($row);
# echo $row['team_name'] . '<br />';
}
$statement->free_result();
}
function dbRO($query) {
//Use only for non-user set/built SQL to avoid injection!
$db=dbCon();
if(!$statement = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $statement->fetch_assoc()){
$x=0;
echo "<tr>";
foreach ($row as $col_value) {
if ( $x == 0 ) {
if ( $col_value == 1 ) {
$color="cccccc";
echo "<td bgcolor=$color ><font color=\"red\">Primary</font></td>";
} else {
$color="ffffff";
echo "<td bgcolor=$color><font color=\"black\">Backup</font></td>";
}
} else {
if ( $x == $count ) {
echo "<td bgcolor=$color width=70%> <font size=2>$col_value</font> </td>";
} else {
echo "\t\t<td bgcolor=$color>$col_value </td>\n";
}
}
$x++;
}
echo "</tr>";
}
$statement->free_result();
}
function userCols($query, $atid) {
$db=dbCon();
if(!$statement = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = mysqli_fetch_array($statement, MYSQLI_NUM)) {
$select="";
if ( $row[2] !== NULL ) {
$s="|";
}
if ( $col_value == $row[0] ) {
$select.="<option selected=\"selected\" value=\"$row[1]$s$row[2]\">$row[0]</option>";
} else {
$select.="<option value=\"$row[1]$s$row[2]\">$row[0]</option>";
}
if ( $y == 0 ) {
$newselect.="<option value=\"$row[1]$s$row[2]\">$row[0]</option>";
#$newselect.="$select";
}
echo "$select";
}
$y=1;
$statement->free_result();
}
/*
function userColsTemp($atid) {
$db=dbCon();
if(!$statement = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
echo "$atid";
if ( $atid == "users" ) {
$query2="SELECT name,uid,u_tid FROM Users";
} elseif ( $atid == "teams" ) {
$query2="SELECT DISTINCT c.team_name,a.u_tid FROM Users a INNER JOIN Teams c ON a.u_tid = c.parent OR a.u_tid = c.tid AND c.tid not in (select parent from Teams Where parent<>0)
ORDER BY c.team_name";
} else {
$query2="SELECT name,uid,u_tid FROM Users where u_tid=$atid";
}
#$query2="SELECT name,uid,u_tid FROM Users $moo";
$result2 = mysql_query($query2) or die('Query failed: ' . mysql_error());
while ($line2 = mysql_fetch_array($result2, MYSQL_NUM)) {
$select="";
if ( $line2[2] !== NULL ) {
$s="|";
}
if ( $col_value == $line2[0] ) {
$select.="<option selected=\"selected\" value=\"$line2[1]$s$line2[2]\">$line2[0]</option>";
} else {
$select.="<option value=\"$line2[1]$s$line2[2]\">$line2[0]</option>";
}
if ( $y == 0 ) {
$newselect.="<option value=\"$line2[1]$s$line2[2]\">$line2[0]</option>";
#$newselect.="$select";
}
echo "$select";
}
$y=1;
}
*/
function genRO($query,$titles,$type,$name) {
//Use only for non-user set/built SQL to avoid injection!
echo "<b>$name</b><br><br>";
echo "<table border=1 width=65%>";
$db=dbCon();
if(!$statement = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
echo '<tr bgcolor="55aa44">';
$a="0";
$x=0;
foreach ($titles as $display) {
echo "<td><b>$display</b></td>";
}
echo "</tr>";
while($row = $statement->fetch_assoc()){
echo "<tr>";
$x=0;
if ( $a == 0 ) {
$color="cccccc";
$a=1;
} else {
$color="ffffff";
$a=0;
}
foreach ($row as $col_value) {
def($type,$col_value,$x,$color);
$x++;
}
echo "</tr>";
}
echo "</table>";
$statement->free_result();
}
function genRW($query,$titles,$type,$name,$input) {
//Function to prevent sql injections
echo "<br><b>$name</b>";
echo "<table border=1 width=65%>";
$db=dbCon();
echo '<tr bgcolor="55aa44">';
$a="0";
$x=0;
foreach ($titles as $display) {
echo "<td><b>$display</b></td>";
}
echo "</tr>";
$statement = $db->prepare($query);
$statement->bind_param('i', $input);
$statement->execute();
$result=$statement->get_result();
if($result->num_rows === 0) exit('No rows');
while($row = $result->fetch_assoc()){
echo "<tr>";
$x=0;
if ( $a == 0 ) {
$color="cccccc";
$a=1;
} else {
$color="ffffff";
$a=0;
}
foreach ($row as $col_value) {
def($type,$col_value,$x,$color);
$x++;
}
echo "</tr>";
}
echo "</table>";
$statement->free_result();
}
function genFields($query,$titles,$type,$name) {
//Use only for non-user set/built SQL to avoid injection!
echo "<b>$name</b>";
echo "<table border=1 width=65%>";
$db=dbCon();
if(!$statement = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
echo '<tr bgcolor="55aa44">';
$a="0";
$x=0;
foreach ($titles as $display) {
echo "<td><b>$display</b></td>";
}
echo "</tr>";
while($row = $statement->fetch_assoc()){
echo "<tr>";
$x=0;
if ( $a == 0 ) {
$color="cccccc";
$a=1;
} else {
$color="ffffff";
$a=0;
}
foreach ($row as $col_value) {
if ( $x == 0 ) {
$id=$col_value;
}
def($type,$col_value,$x,$color,$id);
$x++;
}
echo "</tr>";
}
$statement->free_result();
}
function def($type,$col_value,$x,$color,$id) {
//If Apps Page Display
if ( $type == 1 ) {
if ( $x == 2 ) {
if ( $col_value == 1 ) {
echo "<td bgcolor=$color> 24x7 </td>";
} else {
echo "<td bgcolor=$color> Next Business Day </td>";
}
} else {
echo "<td bgcolor=$color> $col_value </td>";
}
} elseif ($type == 2) {
if ( $col_value == 1 ) {
$call="<td bgcolor=$color ><font color=\"red\">Primary</font></td>";
} else {
$call="<td bgcolor=$color><font color=\"black\">Backup</font></td>";
}
if ( $x == 0 ) {
echo "$call";
} else {
if ( $x == 6 ) {
echo "<td bgcolor=$color width=70%> <font size=2>$col_value</font> </td>";
} else {
echo "<td bgcolor=$color>$col_value </td>";
}
}
} elseif ( $type == 3 ) {
if ( $x == 3 ) {
if ( $col_value == 1 ) {
echo "<td bgcolor=$color >Primary</td>";
} else {
echo "<td bgcolor=$color>Backup</td>";
}
} elseif ( $x == 4) {
//do nothing
} else {
echo "<td bgcolor=$color> $col_value </td>";
}
} elseif ( $type == 4 ) {
if ( $x == 0 ) {
echo "<form action=\"/mod.php\" method=\"post\">";
} elseif ( $x == 1 ) {
echo "<INPUT TYPE=\"hidden\" NAME=\"app_id\" VALUE=$col_value>";
} elseif ( $x == 2 ) {
echo "<td bgcolor=$color><input type=Text name=app value=$col_value size=50></td>";
} elseif ( $x == 3 ) {
echo "<td bgcolor=$color><select name=\"owner\">";
$query="SELECT tid,team_name from Teams";
getOpts($query,$id);
echo "</select></td>";
} elseif ( $x == 4 ) {
echo "<td bgcolor=$color><select name=\"crit\">";
$selected1="";
$selected2="";
if ( $col_value == 1 ) {
$selected1="Selected";
} else {
$selected2="selected";
}
echo "<option value=1 $selected1>24x7</option>";
echo "<option value=0 $selected2>Next Business Day</option>";
echo "</select></td>";
echo '<INPUT TYPE="hidden" NAME="type" VALUE=4>';
echo '<td><button type="submit" name="func" VALUE=2>Update</button></td>';
echo '<td><button type="submit" NAME="func" VALUE=0>Delete</button></td>';
echo "</form>";
}
} else {
echo "<td bgcolor=$color> $col_value </td>";
}
}
function getOpts($query,$id) {
//Use only for non-user set/built SQL to avoid injection!
$db=dbCon();
if(!$statement = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $statement->fetch_assoc()){
# return array ($row);
if ( $id === $row['tid'] ) {
$selected='Selected';
} else {
$selected='';
}
echo '<option value=' . $row['tid']. " $selected>" . $row['team_name']. '</option>';
}
$statement->free_result();
}
function build($db) {
$query="SELECT b.prim,c.team_name,a.name, a.phone1, a.phone2 FROM Users a INNER JOIN Teams c ON a.u_tid = c.parent OR a.u_tid = c.tid AND c.tid not in (select parent from Teams Where parent<>0)
INNER JOIN Cal b ON a.uid = b.c_uid AND (b.date_start < current_timestamp AND current_timestamp < b.date_end) ORDER BY c.team_name, b.prim desc";
$x=0;
$y='$one,$two,$three,$four,$five';
$prep="";
dbPrep($dbcon,$query,$x,$y,$prep);
}
function dbClose() {
//Close Database
$db=dbCon();
$db->close();
}
?>