-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·263 lines (237 loc) · 7.13 KB
/
Copy pathfunctions.php
File metadata and controls
executable file
·263 lines (237 loc) · 7.13 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
<?php
////////////////////////////////////////////////////////
//
// FUNCTIONS GO HERE. . . .
//
////////////////////////////////////////////////////////
function thisQ() {
if (is_int(date('n')/3)) $qtr = date('n')/3;
else $qtr = floor(date('n')/3);
if (date('z') < 14) $qtr = 4;
return $qtr;
}
// Create a function for escaping the data.
function escape_data ($data) {
global $dbc;
// Address Magic Quotes.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
// Check for mysqli_real_escape_string($dbc, ) support.
if (function_exists('mysql_real_escape_string')) {
global $dbc; // Need the connection.
$data = mysqli_real_escape_string (trim($data), $dbc);
} else {
$data = mysqli_escape_string (trim($data));
}
// Return the escaped value.
return $data;
} // End of function.
function db_send($cols,$vals,$table,$type,$where='',$display='') {
global $dbc;
mysqli_report(MYSQLI_REPORT_OFF);
if($type=='insert'){
$c_sql=implode(',',$cols);
$v_sql='';
$i=0;
while(isset($vals[$i])){
if($i>0) $v_sql.=',';
if($vals[$i]=='NULL')
$v_sql.="".$vals[$i]."";
else
$v_sql.="'".$vals[$i]."'";
$i++;
}
$sql="INSERT INTO $table ($c_sql) VALUES ($v_sql)";
} elseif($type=='update' && $where!=''){
$v_sql='';
$i=0;
while(isset($vals[$i])){
if($i>0) $v_sql.=',';
$v_sql.=$cols[$i]."=".($vals[$i]=='NULL'?$vals[$i]:"'".$vals[$i]."'");
$i++;
}
$sql="UPDATE $table SET $v_sql WHERE $where";
} elseif($type=='delete'){
if(!is_array($cols))
$sql="DELETE FROM $table WHERE $cols=$vals";
else {
$sql="DELETE FROM $table WHERE ";
$i=0;
while(isset($vals[$i])){
$sql.=($i>0?" AND ":'').$cols[$i]."=".($vals[$i]=='NULL'?$vals[$i]:"'".$vals[$i]."'");
$i++;
}
}
}
// if($display==1) echo $sql;
return mysqli_query($dbc, $sql);
}
function short_name($name) {
$words = explode(" ", $name);
$first = $words[0];
$last = $words[1];
$init = strtoupper(substr($last, 0, 1));
$string = $first . " " . $init . ".";
return $string;
}
function debug_p($var, $title)
{
print "<p>$title</p><pre>";
print_r($var);
print "</pre>";
}
/*== getSlug() ==
returns an SEO-friendly string for use in a URL
====*/
function getSlug($text)
{
$text=str_replace(' ','-',strtolower(trim($text)));
return preg_replace("[^A-Za-z0-9-]", "", str_replace(' ','-',$text));
}
function client_health($client) {
global $dbc;
$thisQ = ceil(date('n')/3);
$query = "SELECT j.ClientID as cID, SUM(j.Hours) as hours, (CASE WHEN c.total_hours = 0 THEN 15 ELSE c.total_hours END) AS total, COUNT(*) as count
FROM journal j, clients c WHERE j.ClientID = c.id AND j.ClientID = ". $client . " AND YEAR(j.Date) = " . date('Y') . " AND j.Billable = 1 GROUP BY cID";
// echo $query;
$result = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($result);
$hours = (!$row['hours'])?1:$row['hours'];
$rtotal = (!$row['total'])?1:$row['total'];
// echo "hours: $hours / total: $rtotal";
// $tot = ($row['total'] == 0.00) ? 15 : $row['total'];
// $total = ($tot / 4) * $thisQ;
// $sub = $hours / $total;
$tot = $hours / $rtotal;
$mos = date('m') / 12;
$ct = $row['count'] * $mos;
$sub = $tot / $mos;
// echo "Q: $thisQ, mos: $mos, hours: $hours, tot: $tot, total: ".$row['total'].", count: ".$row['count'].", ct: $ct, sub: $sub";
if ($sub < .5) {
$health = 1;
} elseif ($sub >= .66) {
$health = 3;
} elseif ($sub < 0.66) {
$health = 2;
} else {
$health = 0;
}
// if ($sub > 1.2) {
// $health = 1;
// } elseif ($sub <= 1.2 && $sub >= 0.8) {
// $health = 3;
// } elseif ($sub < 0.8) {
// $health = 2;
// }
return $health;
}
function client_health_dots($client,$size) {
$health = client_health($client);
switch ($health) {
case 1:
$health_status = "red";
break;
case 2:
$health_status = "yellow";
break;
case 3:
$health_status = "green";
break;
case 4:
$health_status = "no";
break;
}
// $dot_div = "<div class='".$health_status."_dot'></div>";
$dot_div = "<img src=\"images/" . $health_status . "dot.gif\" alt=\"health\" width=\"$size\" height=\"$size\" border=\"0\" /><font style='display:none;'>$health</font>\n";
return $dot_div;
}
function client_health_color($client) {
$health = client_health($client);
switch ($health) {
case 1:
$health_status = "red";
break;
case 2:
$health_status = "yellow";
break;
case 3:
$health_status = "green";
break;
}
return $health_status;
}
function contact_pattern($client) {
global $dbc;
// $client = ($client)?$client:$_POST['id'];
// print_r($client);
// echo $client[0];
$health = 0;
$thisQ = ceil(date('n')/3);
$countQ = "SELECT SUM(Hours) AS total, COUNT(Hours) AS ct FROM journal WHERE ClientID = " . $client . " AND YEAR(Date) = " . date('Y');
// echo $countQ;
$countR = mysqli_query($dbc, $countQ);
$row = mysqli_fetch_assoc($countR);
$count = ($row['ct']=='' || $row['ct']==0) ? 1 : $row['ct'];
$total = $row['total'];
// $sub = ($thisQ * 3) / $count;
$sub = ($count / 12) / (date('m') / 12);
return $sub;
}
function contact_pattern_dots($client,$size) {
$sub = round(contact_pattern($client),2);
// echo $sub;
if ($sub < 0.34) {
$health = 1;
$health_status = "red";
} elseif ($sub >= 0.75) {
$health = 3;
$health_status = "green";
} elseif ($sub > 0.50 && $sub < 0.75) {
$health = 2;
$health_status = "yellow";
} else {
$health = 0;
$health_status = "no";
}
$dot_div = "<img src=\"images/" . $health_status . "dot.gif\" alt=\"health\" width=\"$size\" height=\"$size\" border=\"0\" /><font style='display:none;'>$health</font>\n";
return $dot_div;
// return $sub;
}
function mini_dash($client,$align) {
global $dbc;
$thisQ = ceil(date('n')/3);
$thisY = date('Y');
if (date('z') < 14) {
$thisQ = 4;
$thisY = $thisY - 1;
}
$hoursq = "SELECT SUM(Hours) FROM journal WHERE ClientID = " . $client . "
AND Billable = 1 AND YEAR(Date) = " . $thisY;
$hoursr = mysqli_query($dbc, $hoursq);
$hours = mysqli_fetch_row($hoursr);
$totr = mysqli_query($dbc, "SELECT * FROM clients WHERE ID = $client");
$tots = mysqli_fetch_assoc($totr);
$hoursTotal = $hours[0];
if ($hoursTotal >= ($tots['q_hours']/3) && $hoursTotal < (2*$tots['q_hours']/3)) { $fcolor = '#ff9900'; }
if ($hoursTotal >= (2*$tots['q_hours']/3)) { $fcolor = '#cc0033'; }
$tot = $tots['total_hours'];
$hoursleft = $tot - $hoursTotal;
// echo $tot . " - " . $hoursTotal;
echo "<table border=0 align='$align' width=350 valign='top'><tr>";
echo "<td align='$align'><span class='label'>$thisY (Q$thisQ YTD) Hrs. Used: </span><span class='resp' style='color: $fcolor;'><b>" . round($hoursTotal,2) .
"</b></span><span class='label'> of </span><span class='resp'><b>" . round($tot,2) . "</b></span> / <span class='resp' style='color: $fcolor;'><b>"
. round($hoursleft,2) . "</b></span> <span class='label'>remain</span></td>";
echo "</tr><tr>";
echo "<td align='$align'><span class='label'>Contact pattern: </span><span class='resp'><b>" . contact_pattern_dots($client,15) . "</b></span></td>";
echo "</tr></table>";
}
function acronymize($string) {
$words = explode(" ", $string);
$letters = "";
foreach ($words as $value) {
$letters .= strtoupper(substr($value, 0, 1));
}
return $letters;
}
?>