This repository was archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbudget.php
More file actions
416 lines (372 loc) · 17.9 KB
/
Copy pathbudget.php
File metadata and controls
416 lines (372 loc) · 17.9 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
<?php
include_once('globals.php');
include_once('checklogin.php');
$s_userid = $_SESSION['userID'];
$s_selectedGroup = $_SESSION['selectedGroup'];
$s_selectedGroupType = $_SESSION['selectedGroupType'];
$s_selectedSemester = $_SESSION['selectedSemester'];
function shorten($str, $num = 100)
{
if(strlen($str) > $num)
$str = substr($str, 0, $num).'...';
return $str;
}
//------Start of Code for Form Processing-----------------------//
//START Handling Budget Form Submission
if(isset($_POST['submit_budget']))
{
$i = 0;
$notify = true;
foreach($_POST['category'] as $row => $category)
{
$amount = $_POST['amount'][$row];
$desc = $_POST['desc'][$row];
if($desc == 'Foobar')
$notify = false;
if($amount != NULL && is_numeric($amount))
{
$i++;
$query = $db->query("INSERT INTO Budgets(iProjectID, iSemesterID, bCategory, bRequested, bDesc, bRequestedDate, bOrder) VALUES($s_selectedGroup, $s_selectedSemester, '$category', $amount, '$desc', now(), $i)") or die('There was a problem with your submission, please go back and try again');
}
}
if($notify)
{
//Send Automatic Email
$msg = "This is an auto-generated $appname notification to let you know that ". $currentGroup->getName() ." team has submitted a budget and is awaiting your review.\n\n";
$msg .= "--- $appname System Auto-Generated Message";
$headers = "From: \"$appname Support\" <$contactemail>\n";
$headers .= "To: jacobius@iit.edu";
$headers .= "\nContent-Type: text/plain;\n";
$headers .= "Content-Transfer-Encoding: 7bit;\n";
mail('', $currentGroup->getName() .' submitted a budget ' .$s_selectedCategoryName.'', $msg, $headers);
$message = 'Your submission was successful! Review your submission in the table below or at any time by clicking on the "Budget" tab of your IPRO.';
}
else
$message = 'Your test submission was successful!';
}
//START Handling New Category
if(isset($_POST['new_category_submit']) && !empty($_POST['new_category_amount']) && is_numeric($_POST['new_category_amount']))
{
//Get max order #
$query = $db->query("SELECT max(bOrder) as ordernum FROM Budgets WHERE iSemesterID=$s_selectedSemester AND iProjectID=$s_selectedGroup");
$ordernum = mysql_fetch_row($query);
$new_category=$_POST['new_category'];
$new_category_amount=$_POST['new_category_amount'];
$new_category_desc=$_POST['new_category_desc'];
$ordernum = $ordernum[0]+1;
$query_new_category = $db->query("INSERT INTO Budgets(iProjectID, iSemesterID, bCategory, bRequested, bDesc, bRequestedDate, bOrder) VALUES($s_selectedGroup, $s_selectedSemester, '$new_category', $new_category_amount, '$new_category_desc', now(), $ordernum)") or die('There was a problem with your submission, please go back and try again');
echo "<div id='info_msg'>New category has been added to your budget.</div>";
//Send Automatic Email
$msg = "This is an auto-generated $appname notification to let you know that ". $currentGroup->getName() ." team has submitted a new budget category and is awaiting your review.\n\n";
$msg .= "--- $appname Auto-Generated Massage";
$headers = "From: \"$appname Support\" <$contactemail>\n";
$headers .= "To: jacobius@iit.edu";
$headers .= "\nContent-Type: text/plain;\n";
$headers .= "Content-Transfer-Encoding: 7bit;\n";
mail('', $currentGroup->getName() .' submitted a new budget category ' .$s_selectedCategoryName.'', $msg, $headers);
}
if(isset($_GET['delete']) && is_numeric($_GET['proj']) && is_numeric($_GET['type']) && is_numeric($_GET['sem']) && isset($_GET['cat']))
{
$group = new Group($_GET['proj'], $_GET['type'], $_GET['sem'], $db);
if(!$group->isGroupMember($currentUser))
errorPage('Credentials Required', 'You are not a member of this group.', 403);
$db->query("DELETE FROM Budgets WHERE iProjectID=".$_GET['proj']." AND iSemesterID=".$_GET['sem']." AND bCategory='".mysql_real_escape_string($_GET['cat'])."'");
$message = 'Budget item successfully deleted.';
}
//------End of Code for Form Processing-------------------------//
//------Start XHTML Output--------------------------------------//
require('doctype.php');
require('appearance.php');
echo "<link rel=\"stylesheet\" href=\"skins/$skin/budget.css\" type=\"text/css\" title=\"$skin\" />\n";
foreach($altskins as $altskin)
echo "<link rel=\"alternate stylesheet\" href=\"skins/$altskin/budget.css\" type=\"text/css\" title=\"$altskin\" />\n";
?>
<title><?php echo $appname; ?> - Budget</title>
<script type="text/javascript">
<!--
function calc()
{
var one = document.budget_form.supplies_amount.value;
var two = document.budget_form.equipment_amount.value;
var three = document.budget_form.services_amount.value;
var four = document.budget_form.travel_amount.value;
var five = document.budget_form.participant_support_amount.value;
var six = document.budget_form.other1_amount.value;
var seven = document.budget_form.other2_amount.value;
var eight = document.budget_form.other3_amount.value;
var nine = document.budget_form.other4_amount.value;
var ten = document.budget_form.other5_amount.value;
var total = (one * 1) + (two * 1) + (three * 1) + (four * 1) + (five * 1) + (six * 1) + (seven * 1) + (eight * 1) + (nine * 1) + (ten * 1);
document.budget_form.total_amt.value = total;
}
function showEvent(id, x, y)
{
document.getElementById(id).style.top = (y + 20) + "px";
if(x > window.innerWidth / 2)
document.getElementById(id).style.left = (x - 200) + "px";
else
document.getElementById(id).style.left = x + "px";
document.getElementById(id).style.visibility = 'visible';
}
function hideEvent(id)
{
document.getElementById(id).style.visibility='hidden';
}
//-->
</script>
</head>
<body>
<?php
/**** begin html head *****/
require('htmlhead.php'); //starts main container
/****end html head content ****/
echo "<div id=\"topbanner\">";
echo $currentGroup->getName();
?>
</div>
<?php
$query = mysql_query("SELECT * FROM Budgets WHERE iProjectID=$s_selectedGroup AND iSemesterID=$s_selectedSemester");
$result = mysql_fetch_row($query);
if(!$result)
{
?>
<h4>Guidelines:</h4>
<ul>
<li>Please submit <b>only one budget form</b> per IPRO per semester. Before submitting, please consult with your teammates and instructor to make sure that you are responsible for filling out this form.</li>
<li>Fill in the dollar amount for each of the pre-defined categories; for those categories that you are not requesting any funds, please leave the dollar amount blank.</li>
<li>You have up to five budget categories you can define yourself if some expenses are not fitting the IPRO categories.</li>
<li>Use the "Explain" fields to briefly describe the requested amount for each category. The justification for the line item amounts must be clearly stated in the context of the project plan, goals and tasks and in terms of what is reasonable within the current semester.</li>
<li>Please note that the average IPRO team budget over many years has been on the order of $500; however, many teams require and request no funding, while others may have special needs that require extra investment.</li>
<li>It is advisable to be as realistic as possible rather than request highly conservative amounts, since we understand that the exact amount may vary and unexpected needs may develop over time.</li>
<li>Our aim is to assure that IPRO teams have sufficient funds to achieve success during the semester; however, we also have budget constraints and must manage our resources wisely.</li>
</ul>
<hr />
<h2 style="color: #cc0000;">Submit a Budget</h2>
<form method="post" id="budget_form" action="budget.php"><fieldset>
<table cellpadding="10" cellspacing="0" class="submit_budget">
<tr>
<td>
<h3><label for="supplies">Supplies:</label></h3>
<div class="label_desc">Lab supplies, office supplies, etc.</div>
<input type="hidden" id="supplies" name="category[]" value="Supplies" />
$ <input type="text" id="supplies_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="supplies_desc">Explain:</label><br />
<textarea id="supplies_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<h3><label for="equipment">Equipment:</label></h3>
<div class="label_desc">Purchase materials and/or parts for testing or construction.</div>
<input type="hidden" id="equipment" name="category[]" value="Equipment" />
$ <input type="text" id="equipment_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="equipment_desc">Explain:</label><br />
<textarea id="equipment_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<h3><label for="services">Services:</label></h3>
<div class="label_desc">Printing, rentals, consulting, patent searching, etc.</div>
<input type="hidden" id="services" name="category[]" value="Services" />
$ <input type="text" id="services_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="services_desc">Explain:</label><br />
<textarea id="services_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<h3><label for="travel">Travel/Meetings:</label></h3>
<div class="label_desc">Transportaion costs, meals, conference passes, etc.</div>
<input type="hidden" id="travel" name="category[]" value="Travel" />
$ <input type="text" id="travel_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="travel_desc">Explain:</label><br />
<textarea id="travel_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<h3><label for="participant_support">Participant Support:</label></h3>
<div class="label_desc">Incentives to participants of usability testing, product testing, user survey, focus groups, etc.</div>
<input type="hidden" id="participant_support" name="category[]" value="Participant Support" />
$ <input type="text" id="participant_support_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="participant_support_desc">Explain:</label><br />
<textarea id="participant_support_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<label for="other1"><small><strong>Define Your Own Category:</strong></small></label><br />
<input type="text" id="other1" name="category[]" /><br /><br />
$ <input type="text" id="other1_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="other1_desc">Explain:</label><br />
<textarea id="other1_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<label for="other2"><small><strong>Define Your Own Category:</strong></small></label><br />
<input type="text" id="other2" name="category[]" /><br /><br />
$ <input type="text" id="other2_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="other2_desc">Explain:</label><br />
<textarea id="other2_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<label for="other3"><small><strong>Define Your Own Category:</strong></small></label><br />
<input type="text" id="other3" name="category[]" /><br /><br />
$ <input type="text" id="other3_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="other3_desc">Explain:</label><br />
<textarea id="other3_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<label for="other4"><small><strong>Define Your Own Category:</strong></small></label><br />
<input type="text" id="other4" name="category[]" /><br /><br />
$ <input type="text" id="other4_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="other4_desc">Explain:</label><br />
<textarea id="other4_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td>
<label for="other5"><small><strong>Define Your Own Category:</strong></small></label><br />
<input type="text" id="other5" name="category[]" /><br /><br />
$ <input type="text" id="other5_amount" name="amount[]" size="5" onchange="calc()" />
</td>
<td>
<label for="other5_desc">Explain:</label><br />
<textarea id="other5_desc" name="desc[]" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<h3 style="color: #cc0000;"><label for="supplies">Total Amount:</label></h3>
$ <input type="text" id="total_amt" name="total_amt" size="5" onchange="calc()" />
<p>
<input type="submit" id="submit_budget" value="Submit Budget" name="submit_budget" />
</p>
</td>
</tr>
</table>
<input type="hidden" id="iProjectID" name="iProjectID" value="<?php echo $s_selectedGroup ?>" />
<input type="hidden" id="iSemesterID" name="iSemesterID" value="<?php echo $s_selectedSemester ?>" />
</fieldset></form>
<?php
}
else
{
echo "<h2>Submitted Budget</h2>";
$divs = array();
//Show details for each individual category
echo "<table class=\"budget\" cellpadding=\"10\" cellspacing=\"0\"><tr><th>Category</th><th>Requested</th><th>Approved</th><th>Reimbursed</th><th>Explanation</th><th>Status</th><th>Edit</th></tr>";
$query = mysql_query("SELECT * FROM Budgets WHERE iProjectID={$s_selectedGroup} AND iSemesterID={$s_selectedSemester} ORDER by bOrder");
$i = 0;
while($row = mysql_fetch_assoc($query))
{ //truncate the description to 50 characters
$desc = shorten( $row[bDesc], $num = 50 );
$i++;
if($i & 1)
echo '<tr class="shade">';
else
echo '<tr>';
echo "<td style=\"font-weight: bold\">$row[bCategory]</td>";
echo "<td>$ {$row['bRequested']}<div class=\"b_date\">{$row['bRequestedDate']}</div></td>";
if($row['bApprovedDate'] == NULL)
echo "<td class=\"b_date\" style=\"font-weight: bold\">Awaiting<br />Approval</td>";
else
echo "<td>$ {$row['bApproved']}<div class='b_date'>{$row['bApprovedDate']}</div></td>";
if($row['bReimbursed'] == NULL)
echo "<td class=\"b_date\" style=\"font-weight: bold\">None</td>";
else
echo "<td>$ {$row['bReimbursed']}<div class=\"b_date\">{$row['bReimbursedDate']}</div></td>";
echo "<td><a href=\"#\" onmouseover=\"showEvent('R".$row['bOrder']."',event.clientX+document.documentElement.scrollLeft, event.clientY+document.documentElement.scrollTop);\" onmouseout=\"hideEvent('R".$row['bOrder']."');\">".$desc."</a></td>";
if($row['bStatus'] == 'Completed')
echo "<td style=\"font-weight: bold\">{$row['bStatus']}</td>";
else
echo "<td>{$row['bStatus']}</td>";
echo "<td><span class=\"edit_desc\"><a href=\"edit_budget.php?bOrder={$row['bOrder']}&bDesc={$row['bDesc']}\">Revise</a>";
if($row['bApprovedDate'] == NULL)
echo " or <a href=\"budget.php?delete=true&proj={$row['iProjectID']}&type=$s_selectedGroupType&sem={$row['iSemesterID']}&cat=".urlencode($row['bCategory'])."\" title=\"Delete this item\">Delete</a>";
echo "</span></td></tr>";
$divs[$row[bOrder]] = "<div class=\"description\" id=\"R".$row['bOrder']."\">".str_replace("\n", "<br />", htmlspecialchars($row['bDesc']))."</div>";
}
//Total Amount
$total_amt = $db->query("SELECT sum(bRequested), sum(bApproved), sum(bReimbursed) from Budgets WHERE iProjectID=$s_selectedGroup AND iSemesterID=$s_selectedSemester GROUP BY iProjectID");
$total = mysql_fetch_row($total_amt);
echo "<tr class=\"budget_col_totals\"><td style=\"font-weight: bold\">TOTAL</td><td class=\"req_budget_total\">$".round($total[0],2)."</td><td class=\"app_budget_total\">$".round($total[1], 2)."</td><td>$".round($total[2], 2)."</td><td colspan=\"4\"> </td></tr>";
echo "</table>";
foreach($divs as $div)
echo $div;
echo "<p><a href=\"reimbursements.php\" style=\"font-weight: bold\">Reimbursement Guidelines</a></p>\n";
echo "<h3>History of Previously Requested Items:</h3>\n";
//Show details for each individual category
echo "<table class=\"budget\" cellpadding=\"10\" cellspacing=\"0\"><tr><th>Category</th><th>Requested</th><th>Approved</th><th>Explanation</th><th>Status</th></tr>";
$query = mysql_query("SELECT * FROM BudgetsHistory WHERE iProjectID={$s_selectedGroup} AND iSemesterID={$s_selectedSemester} ORDER by bOrder");
$divs = array();
while ($row = mysql_fetch_assoc($query))
{
//truncate the description to 50 characters
$desc = shorten( $row[bDesc], $num = 50 );
//spit out results in the table
echo "<tr>";
echo "<td>{$row['bCategory']}</td>";
echo "<td>$ {$row['bRequested']}<div class=\"b_date\">{$row['bRequestedDate']}</div></td>";
echo "<td>$ {$row['bApproved']}<div class=\"b_date\">{$row['bApprovedDate']}</div></td>";
echo "<td><a href=\"#\" onmouseover=\"showEvent('RR".$row['bOrder']."',event.clientX+document.documentElement.scrollLeft, event.clientY+document.documentElement.scrollTop);\" onmouseout=\"hideEvent('RR".$row['bOrder']."');\">".$desc."</a></td>";
echo "<td>{$row['bStatus']}</td></tr>";
$divs[$row['bOrder']] = "<div class=\"description\" id=\"RR".$row['bOrder']."\">".str_replace("\n", "<br />", htmlspecialchars($row['bDesc']))."</div>";
}
echo "</table>\n";
foreach($divs as $div)
echo $div;
?>
<br />
<h3>Create a New Budget Category:</h3>
<form method="post" name="new_category_form" id="new_category_form" action="budget.php">
<label for="new_category">New Category:</label>
<input type="text" id="new_category" name="new_category" />
<label for="new_category"> Amount:</label>
$ <input type="text" id="new_category_amount" name="new_category_amount" size="5" /><br /><br />
<label for="new_category_desc">Explain:</label><br />
<textarea id="new_category_desc" name="new_category_desc" rows="3" cols="50"></textarea><br />
<input type="submit" name="new_category_submit" value="Submit" />
</form>
<br />
<h2>Responses to this budget:</h2>
<?php
$sent_msgs = $db->query("SELECT * FROM BudgetEmails WHERE iProjectID=$s_selectedGroup AND iSemesterID=$s_selectedSemester");
while ($row = mysql_fetch_assoc($sent_msgs))
{
echo "<p><span style=\"font-size: smaller\">";
echo $row['bEmailDate'];
echo "</span><br />";
echo $row['bEmail'];
echo "</p>";
}
}
?>
<?php
//include rest of html layout file
require('htmlcontentfoot.php');// ends main container
?></body></html>