-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionlib.php
More file actions
437 lines (381 loc) · 16.1 KB
/
functionlib.php
File metadata and controls
437 lines (381 loc) · 16.1 KB
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
437
<?
require_once('logging.php');
function safe($str) {
return mysql_real_escape_string(trim($str));
}
function safearray($array) {
foreach ($array as $key=>$value) $returnarray[$key] = safe($value);
return $returnarray;
}
function myquery($query) {
$debug = FALSE;
$result = mysql_query($query) or $error = TRUE;
if (isset($error)) {
if ($debug == TRUE) die(mysql_error() . '<br />' . $query);
else {
$logresult = write_log(mysql_error(), "/home/filedraw/logs/sqlerrors.log");
die('A database error has occurred. Please contact <a href="mailto:tntlab@odu.edu">tntlab@odu.edu</a> and describe what specific actions you took that led to this error.');
}
} else return ($result);
}
function redirect($page) {
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/$page");
exit;
}
function meanof8($val1, $val2, $val3, $val4, $val5, $val6, $val7, $val8) {
$numzeros = 0;
$items = array($val1, $val2, $val3, $val4, $val5, $val6, $val7, $val8);
foreach ($items as $num) if ($num == 0) $numzeros++;
if ($numzeros == 8) return(0);
return(array_sum($items) / (8 - $numzeros));
}
function mysql_insert_array ($my_table, $my_array, $test = FALSE, $quoted = TRUE) {
if ($quoted == TRUE) {
$sep = '","';
$endquote = '"';
} else {
$sep = ',';
$endquote = '';
}
$keys = array_keys($my_array);
$values = array_values($my_array);
if ($quoted == TRUE) $values = safearray($values);
$sql = 'INSERT INTO ' . $my_table . ' (' . safe(implode(',', $keys)) . ') VALUES (' . $endquote . implode($sep, $values) . $endquote . ')';
if ($test == FALSE) return(myquery($sql));
else die($sql);
return(0);
}
function linkify($str) {
return ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" target=\"blank\" rel=\"nofollow\">\\0</a>", $str);
}
function mysql_update_array ($my_table, $my_array, $whereclause, $test = FALSE, $quoted = TRUE) {
if ($quoted == TRUE) $sep = '"'; else $sep = '';
$sql = 'UPDATE `' . $my_table . '` SET ';
foreach ($my_array as $key=>$value) {
if ($quoted == TRUE) $value = safe($value);
$sql .= safe($key) . ' = ' . $sep . $value . $sep . ', ';
}
$sql = substr($sql, 0, -2) . " WHERE " . $whereclause;
if ($test == FALSE) return(myquery($sql));
else die($sql);
return(0);
}
function mailer($to, $subject, $message, $type) {
$headers = 'From: ODU socialPsych <tntlab@odu.edu>' . "\r\n" .
'Reply-To: ODU socialPsych <tntlab@odu.edu>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sqldata = array(
"`to`"=>"'" . $to . "'",
"`subject`"=>"'" . $subject . "'",
"`message`"=>"'" . safe($message) . "'",
"`headers`"=>"'" . $headers . "'",
"`dateAdded`"=>"NOW()",
"`type`"=>$type
);
mysql_insert_array("mailQueue", $sqldata, FALSE, FALSE);
}
function unixToText($unixDate) {
if ($unixDate - time() > -30) return 'A few seconds ago';
elseif ($unixDate - time() > -90) return 'About a minute ago';
elseif ($unixDate - time() > -150) return 'About two minutes ago';
elseif ($unixDate - time() > -300) return 'Less than five minutes ago';
elseif ($unixDate - time() > -600) return 'Less than ten miunutes ago';
elseif ($unixDate - time() > -1800) return 'Less than half an hour ago';
elseif ($unixDate - time() > -3600) return 'Less than an hour ago';
elseif ($unixDate - time() > -5400) return 'About an hour ago';
elseif ($unixDate - time() > -86400) return 'About ' . round(-($unixDate - time()) / 3600) . ' hours ago';
elseif (date("Ymd",$unixDate) >= date("Ymd",time()-86400)) return 'Yesterday';
elseif (date("Ymd",$unixDate) >= date("Ymd",time()-(86400*2))) return 'Two days ago';
elseif (date("Ymd",$unixDate) >= date("Ymd",time()-(86400*3))) return 'Three days ago';
elseif (date("Ymd",$unixDate) >= date("Ymd",time()-(86400*4))) return 'Four days ago';
elseif (date("Ymd",$unixDate) >= date("Ymd",time()-(86400*5))) return 'Five days ago';
elseif (date("Ymd",$unixDate) >= date("Ymd",time()-(86400*6))) return 'Six days ago';
elseif (date("YW",$unixDate) >= date("YW",time()-(86400*7*1.5))) return 'About a week ago';
elseif (date("YW",$unixDate) >= date("YW",time()-floor((86400*7*2.5)))) return 'About two weeks ago';
elseif (date("YW",$unixDate) >= date("YW",time()-floor((86400*7*3.5)))) return 'About three weeks ago';
elseif (date("YW",$unixDate) >= date("YW",time()-floor((86400*7*5)))) return 'About a month ago';
else return date('F jS, Y', $unixDate+7200);
}
function printhead($style = NULL) {
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Expires" content="Fri, Jun 1 1999 12:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>socialPsych</title>
<meta name="Description" content="socialPsych: Online Social Network of the ODU Department of Psychology">
<meta name="Keywords" content="ODU, psychology, social network">
';
if ($_SERVER['PHP_SELF'] == "/certexam.php") echo '<script language="javascript" type="text/javascript" src="countDown.js"></script>';
echo '<script language="javascript" type="text/javascript">
function textLimit(field, maxlen) {
if (field.value.length > maxlen) {
field.value = field.value.substring(0, maxlen);
} }
</script>
<link type="text/css" rel="stylesheet" href="style.css" title="style">';
if ($style != NULL) {
echo '<style type="text/css">';
echo $style;
echo '</style>';
}
echo '</head>';
}
function newstartbody($imagebit = 0) {
echo '
<body bgcolor="#F6F6F6">
<div align="center">
<table id="maintable" width="763" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1" valign="top" bgcolor="#666666"><img src="images/spacer.gif" width="1" height="1" alt=""></td>
<td width="100%" valign="top" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#666666"><img id="mainspacer" src="images/spacer.gif" width="757" height="1" border="0" alt=""></td>
</tr>
<tr>
<td align="right">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#002B5F">
<tr>
<td align="left" valign="middle">
<a href="http://www.odu.edu/">
<div><img src="" alt="Old Dominion University" width="235" height="27" border="0"></div>
</a> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr>
<td bgcolor="#7F95AF"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="middle">
<a href="http://sci.odu.edu/">
<div><img border="0" src="" alt=""></div>
</a>
</td>
<td class="printfriendly" align="right" valign="middle"></td>
</tr>
</table>
<table width="100%" valign="top" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" bgcolor="#002B5F"><img src="images/spacer.gif" width="1" height="5" alt=""><br>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" alt=""><br>
</td>
</tr>
<tr>
<td width="100%" style="background-image: url(\'\')">
<table valign="top" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="http://sci.odu.edu/psychology">
<img src="" width="207" height="29" alt="" border="0"><br>
</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" alt=""><br>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#002B5F"><img src="images/spacer.gif" width="1" height="5" alt=""><br>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><img src="images/spacer.gif" width="1" height="10" alt=""></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10" align="left"><img src="images/spacer.gif" width="10" height="1" alt=""></td>
<td align="left" valign="top">
';
if ($imagebit == 1) echo '<p><center><img alt="" src=""></center></p>';
}
function startbody($imagebit = 0, $onload = FALSE) {
echo '
<body ';
if ($onload != FALSE) echo $onload . " ";
echo 'bgcolor="#F6F6F6">
<div align="center">
<table id="maintable" width="763" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1" valign="top" bgcolor="#666666"><img src="images/spacer.gif" width="1" height="1" alt=""></td>
<td width="100%" valign="top" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#666666"><img id="mainspacer" src="images/spacer.gif" width="757" height="1" border="0" alt=""></td>
</tr>
<tr>
<td align="right">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#002B5F">
<tr>
<td align="left" valign="middle">
<a href="http://www.odu.edu/">
<div><img src="images/gfx-logo-odu-crown.gif" alt="Old Dominion University" width="235" height="27" border="0"></div>
</a> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr>
<td bgcolor="#7F95AF"><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="middle">
<a href="http://sci.odu.edu/">
<div><img border="0" src="images/logo-cos.gif" alt="College of Sciences"></div>
</a>
</td>
<td class="printfriendly" align="right" valign="middle"></td>
</tr>
</table>
<table width="100%" valign="top" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" bgcolor="#002B5F"><img src="images/spacer.gif" width="1" height="5" alt=""><br>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" alt=""><br>
</td>
</tr>
<tr>
<td width="100%" style="background-image: url(\'images/hmenu_bg_dept1.gif\')">
<table valign="top" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="http://sci.odu.edu/psychology">
<img src="images/hmenu_department_of_psychology.png" width="207" height="29" alt="Department of Psychology" border="0"><br>
</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#FFFFFF"><img src="images/spacer.gif" width="1" height="1" alt=""><br>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#002B5F"><img src="images/spacer.gif" width="1" height="5" alt=""><br>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><img src="images/spacer.gif" width="1" height="10" alt=""></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10" align="left"><img src="images/spacer.gif" width="10" height="1" alt=""></td>
<td align="left" valign="top">
';
if ($imagebit == 1) echo '<p><center><img alt="" src="images/home-header.jpg"></center></p>';
}
function endbody() {
echo '</td>
<td width="10" align="left"><img src="images/spacer.gif" width="10" height="1" alt=""></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#000000"><img src="images/spacer.gif" width="1" height="1" alt=""></td>
</tr>
<tr>
<td align="center" class="footer" bgcolor="#002B5F"><img src="images/spacer.gif" width="1" height="7" alt=""><br>
© 2006, 2010 <a class="footerlink" href="http://odu.edu">Old Dominion University</a>, Norfolk, VA 23529
<br>
<img src="images/spacer.gif" width="1" height="7" alt=""><br>
</td>
</tr>
<tr>
<td bgcolor="#666666"><img src="images/spacer.gif" width="1" height="1" alt=""></td>
</tr>
</table>
</td>
<td width="1" valign="top" bgcolor="#666666"><img src="images/spacer.gif" width="1" height="1" alt=""></td>
<td width="4" valign="top" style="background-image:url(images/shadow-r.gif)"><img src="images/shadow-tr.gif" width="4" height="4" alt=""></td>
</tr>
<tr>
<td colspan="4">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" valign="top" align="left" style="background-image:url(images/shadow-b.gif)"><img src="images/shadow-bl.gif" width="4" height="5" alt=""></td>
<td width="50%" valign="top" align="right" style="background-image:url(images/shadow-b.gif)"><img src="images/shadow-br.gif" width="4" height="5" alt=""></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div align="center">
<table width="763" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"></td>
</tr>
</table>
</div>
</body>
</html> ';
}
function assertValidUpload($code)
{
if ($code == UPLOAD_ERR_OK) {
return;
}
switch ($code) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$msg = 'The image you uploaded was too large. Please try again with a smaller file.';
break;
case UPLOAD_ERR_PARTIAL:
$msg = 'Your upload halted early due to an error. Please try again.';
break;
case UPLOAD_ERR_NO_FILE:
$msg = 'You did not upload an image. Please select a valid image file and try again.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$msg = 'Server error. Please try again.';
break;
case UPLOAD_ERR_CANT_WRITE:
$msg = 'Server error. Please try again.';
break;
case UPLOAD_ERR_EXTENSION:
$msg = 'Server error. Please try again.';
break;
default:
$msg = 'Server error. Please try again.';
}
throw new Exception($msg);
}
function printmenu_start() {
require('leftmenu.php');
}
function printmenu_end() {
echo'</td></tr></table>';
}
?>