-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproj_maint.php
More file actions
329 lines (293 loc) · 11.3 KB
/
proj_maint.php
File metadata and controls
329 lines (293 loc) · 11.3 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
<?php
/**
* Simple function to replicate PHP 5 behaviour
*/
//$Header: /cvsroot/tsheet/timesheet.php/proj_maint.php,v 1.10 2005/05/17 03:38:37 vexil Exp $
// Authenticate
require("class.AuthenticationManager.php");
require("class.CommandMenu.php");
if (!$authenticationManager->isLoggedIn() || !$authenticationManager->hasAccess('aclProjects')) {
Header('Location: login.php?clearanceRequired=' . get_acl_level('aclProjects'));
exit;
}
//define the command menu & we get these variables from $_REQUEST:
// $month $day $year $client_id $proj_id $task_id
include("timesheet_menu.inc");
$contextUser = strtolower($_SESSION['contextUser']);
//set seleced project status to started when nothing is chosen in the dropdown list
$proj_status = isset($_REQUEST['proj_status']) ? $_REQUEST['proj_status'] : "Started";
//set up query
$query = "SELECT DISTINCT $PROJECT_TABLE.title, $PROJECT_TABLE.proj_id, $PROJECT_TABLE.client_id, ".
"$CLIENT_TABLE.organisation, $PROJECT_TABLE.description, " .
"DATE_FORMAT(start_date, '%M %d, %Y') as start_date, " .
"DATE_FORMAT(deadline, '%M %d, %Y') as deadline, ".
"$PROJECT_TABLE.proj_status, http_link, proj_leader ".
"FROM $PROJECT_TABLE, $CLIENT_TABLE, $USER_TABLE ".
"WHERE ";
if ($client_id != 0)
$query .= "$PROJECT_TABLE.client_id = $client_id AND ";
if ($proj_status !== 0 and $proj_status !== 'All' ) {
$query .= " $PROJECT_TABLE.proj_status = '$proj_status' AND ";
}
$query .= "$PROJECT_TABLE.proj_id > 0 AND $CLIENT_TABLE.client_id = $PROJECT_TABLE.client_id ".
"ORDER BY $PROJECT_TABLE.title";
if (isset($_POST['page']) && $_POST['page'] != 0) { $page = $_POST['page']; } else { $page=1; };
$results_per_page = $tsx_config->get("project_items_per_page");
$start_from = ($page-1) * $results_per_page;
$query .= " LIMIT $start_from, $results_per_page";
//$sql = “SELECT * FROM students ORDER BY name ASC LIMIT $start_from, 20”;
//$rs_result = mysql_query ($sql, $connection);
//execute the query
list($qh, $num) = dbQuery($query);
//build query for determining number of pages
$query2 = "SELECT DISTINCT $PROJECT_TABLE.title, $PROJECT_TABLE.proj_id, $PROJECT_TABLE.client_id, ".
"$CLIENT_TABLE.organisation, $PROJECT_TABLE.description, " .
"DATE_FORMAT(start_date, '%M %d, %Y') as start_date, " .
"DATE_FORMAT(deadline, '%M %d, %Y') as deadline, ".
"$PROJECT_TABLE.proj_status, http_link, proj_leader ".
"FROM $PROJECT_TABLE, $CLIENT_TABLE, $USER_TABLE ".
"WHERE ";
if ($client_id != 0)
$query2 .= "$PROJECT_TABLE.client_id = $client_id AND ";
if ($proj_status !== 0 and $proj_status !== 'All' ) {
$query2 .= " $PROJECT_TABLE.proj_status = '$proj_status' AND ";
}
$query2 .= "$PROJECT_TABLE.proj_id > 0 AND $CLIENT_TABLE.client_id = $PROJECT_TABLE.client_id ".
"ORDER BY $PROJECT_TABLE.title";
list($qh2, $num2) = dbQuery($query2);
function writePageLinks($page, $results_per_page, $num2)
{
if (($num2/$results_per_page) == (int)($num2/$results_per_page))
$numberOfPages = ($num2/$results_per_page);
else
$numberOfPages = 1+(int)($num2/$results_per_page);
if($numberOfPages > 1 && $num2 != 0)
{
//echo '<td width="16em" align="right">';
if($page > 1)
echo '<a href="javascript:change_page(\''.($page-1).'\')">Previous Page</a>';
else
echo 'Previous Page';
echo ' / ';
//echo '</td><td width="19em>"';
if ($numberOfPages > $page)
echo '<a href="javascript:change_page('.($page+1).')">Next Page</a>';
else
echo 'Next Page';
echo ' ( <b>';
echo $page." of ";
echo $numberOfPages;
echo '</b> )';
//echo '</td>';
}
}
?>
<html>
<head>
<title>Projects</title>
<?php
include ("header.inc");
?>
<script type="text/javascript" type="text/javascript">
function delete_project(clientId, projectId) {
if (confirm('Deleting a project will also delete all tasks and assignments associated ' +
'with that project. If any of these tasks have timesheet entries ' +
'they will become invalid and may cause errors. This action is not recommended. ' +
'Are you sure you want to delete this project?'))
location.href = 'proj_action.php?client_id=' + clientId + '&proj_id=' + projectId + '&action=delete';
}
function change_page(newPageValue)
{
document.projectFilter.page.value = newPageValue;
document.projectFilter.submit();
}
</script>
</head>
<body <?php include ("body.inc"); ?> >
<?php
include ("banner.inc");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="face_padding_cell">
<!-- include the timesheet face up until the heading start section -->
<?php include("timesheet_face_part_1.inc"); ?>
<form method="post" name="projectFilter" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<input type="hidden" name="page" value="English" />
<table width="100%" border="0">
<tr>
<td width="40%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="50"><tr><td>Client:</td></tr></table></td>
<td width="100%"><?php client_select_list($client_id, 0, false, false, true, false, "submit();", false); ?></td>
<td> Status: </td><td><?php proj_status_list_filter('proj_status', $proj_status, "submit();"); ?></td>
</tr>
</table>
</td>
<td align="center" nowrap class="outer_table_heading">
Projects
</td>
<td>
<?php writePageLinks($page, $results_per_page, $num2);?>
</td>
<td align="right" nowrap>
<a href="proj_add.php?client_id=<?php echo $client_id; ?>">Add new project</a>
</td>
</tr>
</table>
</form>
<!-- include the timesheet face up until the heading start section -->
<?php include("timesheet_face_part_2.inc"); ?>
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="outer_table">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_body">
<?php
//are there any results?
if ($num == 0) {
if ($client_id != 0)
print "<tr><td align=\"center\"><br />There are no projects for this client.<br /><br /></td></tr>";
else
print "<tr><td align=\"center\"><br />There are no projects.<br /><br /></td></tr>";
}
else {
//iterate through results
for($j=0; $j<$num; $j++) {
//get the current record
$data = dbResult($qh);
//strip slashes
$data["title"] = stripslashes($data["title"]);
$data["organisation"] = stripslashes($data["organisation"]);
$data["description"] = stripslashes($data["description"]);
list($billqh, $bill_num) = dbquery(
"SELECT sum(unix_timestamp(end_time) - unix_timestamp(start_time)) as total_time, ".
"sum(bill_rate * ((unix_timestamp(end_time) - unix_timestamp(start_time))/(60*60))) as billed ".
"FROM $TIMES_TABLE, $ASSIGNMENTS_TABLE, $RATE_TABLE ".
"WHERE end_time > 0 AND $TIMES_TABLE.proj_id = $data[proj_id] ".
"AND $ASSIGNMENTS_TABLE.proj_id = $data[proj_id] ".
"AND $ASSIGNMENTS_TABLE.rate_id = $RATE_TABLE.rate_id ".
"AND $ASSIGNMENTS_TABLE.username = $TIMES_TABLE.username ");
$bill_data = dbResult($billqh);
//start the row
?>
<tr>
<td>
<table width="100%" border="0"<?php if ($j+1<$num) print "class=\"section_body\""; ?>>
<tr>
<td valign="center">
<?php
if ($data["http_link"] != "")
print "<a href=\"$data[http_link]\"><span class=\"project_title\">$data[organisation] / $data[title]</span></a>";
else
print "<span class=\"project_title\">$data[organisation] / $data[title]</span>";
print " <span class=\"project_status\"><$data[proj_status]></span>"
?>
</td>
<td align="right">
<?php
if (isset($data["start_date"]) && $data["start_date"] != '' && $data["deadline"] != '')
print "<span class=\"label\">Start:</span> $data[start_date]<br /><span class=\"label\">Deadline:</span> $data[deadline]";
else
print " ";
?>
</td>
<td align="right" valign="top" nowrap>
<span class="label">Actions:</span>
<a href="proj_edit.php?client_id=<?php echo $client_id; ?>&proj_id=<?php echo $data["proj_id"]; ?>">Edit</a>,
<a href="project_user_rates_action.php?proj_id=<?php echo $data["proj_id"]; ?>&action=show_users">Bill Rates</a>,
<a href="javascript:delete_project(<?php echo $client_id; ?>,<?php echo $data["proj_id"]; ?>);">Delete</a>
</td>
</tr>
<tr>
<td colspan="2"><?php echo $data["description"]; ?><br /></td>
<td valign="top" align="right"><span class="label">Client:</span> <?php echo $data["organisation"]; ?></td>
</tr>
<tr>
<td colspan="3" width="100%">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="70%">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<span class="label">Total time:</span> <?php echo (isset($bill_data["total_time"]) ? formatSeconds($bill_data["total_time"]): "0h 0m"); ?><br />
<span class="label">Total bill:</span> <b>$<?php echo (isset($bill_data["billed"]) ? sprintf("%01.2f",$bill_data["billed"]): "0.00"); ?></b>
</td>
</tr>
<tr><td> </td></tr>
<?php
//display project leader
print "<tr><td><span class=\"label\">Project Leader:</span> $data[proj_leader] </td></tr>";
//display assigned users
list($qh2, $num_workers) = dbQuery("SELECT DISTINCT username FROM $ASSIGNMENTS_TABLE WHERE proj_id = $data[proj_id]");
if ($num_workers == 0) {
print "<tr><td><font size=\"-1\">Nobody assigned to this project</font></td></tr>\n";
}
else {
$workers = '';
print "<tr><td><span class=\"label\">Assigned Users:</span> ";
for ($k = 0; $k < $num_workers; $k++) {
$worker = dbResult($qh2);
$workers .= "$worker[username], ";
}
$workers = preg_replace("/, $/", "", $workers);
print $workers;
print "</td></tr>";
}
?>
</table>
</td>
<td width="30%">
<div class="project_task_list">
<a href="task_maint.php?proj_id=<?php echo $data["proj_id"]; ?>"><span class="label">Tasks:</span></a> <br />
<?php
//get tasks
list($qh3, $num_tasks) = dbQuery("SELECT name, task_id FROM $TASK_TABLE WHERE proj_id=$data[proj_id]");
//are there any tasks?
if ($num_tasks > 0) {
while ($task_data = dbResult($qh3)) {
$taskName = str_replace(" ", " ", $task_data["name"]);
print "<a href=\"javascript:void(0)\" onclick=window.open(\"task_info.php?proj_id=$data[proj_id]&task_id=$task_data[task_id]\",\"TaskInfo\",\"location=0,directories=no,status=no,menubar=no,resizable=1,width=550,height=220\")>$taskName</a><br />";
}
}
else
print "None.";
?>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</td>
</tr>
</tr>
<tr>
<td>
<center>
<?php writePageLinks($page, $results_per_page, $num2);?>
</center>
</td>
</tr>
</table>
<!-- include the timesheet face up until the end -->
<?php include("timesheet_face_part_3.inc"); ?>
</td>
</table>
<?php
include ("footer.inc");
?>
</body>
</HTML>
<?php
// vim:ai:ts=4:sw=4
?>