-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.php
More file actions
139 lines (123 loc) · 4.08 KB
/
utils.php
File metadata and controls
139 lines (123 loc) · 4.08 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
<?php
/************************************************************************
*
* utils.php
*
* a collection of utilities used by the rest of the expungement generator
*
* Copyright 2011 Michael Hollander
*
************************************************************************/
// checks to see if a person is logged in
// @return TRUE if the person is logged in and false if not
function isLoggedIn()
{
if(isset($_SESSION['loginUserID']))
return TRUE;
else
return FALSE;
}
// @return if the user is logged in, returns the logged in user; otherwise returns null
function getLoggedInUserName()
{
return ($_SESSION['loginUserFirst'] . " " . $_SESSION['loginUserLast']);
}
// print a key only if it is set in the "GET" variables
function printIfSet($key)
{
if(isset($_GET[$key]))
print $_GET[$key];
}
// gets a "person" from the getvars
// @return a hash with each value from the get vars escaped etc... to be html and sql safe
function getPersonFromGetVars()
{
//
if ($GLOBALS['debug'])
{
print "POST VARS: <br />";
foreach ($_POST as $name=>$value)
{
print "$name: $value <br/>";
}
}
$urlPerson = array();
$urlPerson['First'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personFirst"])));
$urlPerson['Last'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personLast"])));
$urlPerson['Street'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personStreet"])));
$urlPerson['City'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personCity"]))); $personState = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personState"])));
$urlPerson['State'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personState"]))); $personState = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personState"])));
$urlPerson['Zip'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personZip"])));
$urlPerson['SID'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personSID"])));
$urlPerson['PP'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personPP"])));
$urlPerson['SSN'] = mysql_escape_string(htmlspecialchars(stripslashes($_POST["personSSN"])));
$urlPerson['Alias'] = explode(",", mysql_escape_string(htmlspecialchars(stripslashes($_POST["personAlias"]))));
return $urlPerson;
}
// zips all of the files in the array and returns the location of the zipfile.
// @return the name of the zipfile archive or null if there was a problem making the zipfile.
function zipFiles($files, $dataDir)
{
$zip = new ZipArchive();
$zipFileName = $dataDir . time() . ".zip";
if ($zip->open($zipFileName, ZipArchive::CREATE)===TRUE )
{
foreach ($files as $index=>$file)
{
if($zip->addFile($file, basename($file)) && $GLOBALS['debug'])
print "added $file to archive <br />";
}
if ($zip->close())
return $zipFileName;
}
// if we couldn't open the zip file or save the zip file, return null
return NULL;
}
// removes all of the files in $files from the OS
function cleanupFiles($files)
{
foreach ($files as $file)
{
if (file_exists($file))
{
try
{
unlink($file);
}
catch (Exception $e) {}
}
}
}
// calculates date1-date2 in years
function dateDifference($date1, $date2)
{
$difference = ((int)$date1->format('Y')) - ((int)$date2->format('Y'));
// now check to see if date2 is later in the year than date1
// (z = number of days since jan 1)
if (((int)$date1->format('z')) > ((int)$date2->format('z')))
return $difference;
else
return $difference-1;
}
// @return a date in the form YYYY-MM-DD
// @param a date in the form MM/DD/YYYY
function dateConvert($docketDate)
{
if (preg_match("/\d{1,2}\/\d{1,2}\/\d{2,4}/",$docketDate))
{
$mysqlDate = new DateTime($docketDate);
return $mysqlDate->format('Y-m-d');
}
else
return ("0000-00-00");
}
// @return bool True if a file with the case id passed in exists in the pdf file dir, false if not
// @param id - the ID of the expungement that we are looking for a PDF for
function doesPDFExistForCaseId($id)
{
$filename = $GLOBALS['docketSheetsDir'] . $id;
if(file_exists($filename))
return TRUE;
else
return FALSE;
}