Commit a93fa7d4 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Bugfixes:

- restricted timesheet_project and timesheets overview to current user only
- stored timesheet project details when status > 0 (is status submitted=1 and approved=2)
- fixed changing of timesheet_status and timesheet_period on 'new timesheet' action
- fixed addedit.php to display the right timesheet status even when status > 0.
- reworked addedit.php to put more code in functions. It uses showproject() or showtimesheetproject() function to print timesheet_project details.

Todo:
- introduce admin mode in which the admin can alter timesheets even when (status>0) and let admin see other peoples timesheet.
parent 623782c3
......@@ -13,7 +13,7 @@ if (!$canEdit) {
$obj = new CTimesheet();
// load the record data in case of that this script is used to edit the timesheet qith timesheet_id (transmitted via GET)
if (!$obj->load( $timesheet_id, false ) && $timesheet_id > 0) {
if (!$obj->load( $timesheet_id, false ) && ($timesheet_id > 0) ) {
// show some error messages using the dPFramework if loadOperation failed
// these error messages are nicely integrated with the frontend of dP
// use detailed error messages as often as possible
......@@ -205,13 +205,15 @@ else {
<td align="right" nowrap="nowrap"><?php echo $AppUI->_('Creation date'); ?>:&nbsp;</td>
<td width="100%">
<?php
echo $creation_date ? $creation_date->format( FMT_TIMESTAMP_DATE ) : "" ;
// echo $creation_date ? $creation_date->format( FMT_TIMESTAMP_DATE ) : "" ;
echo $creation_date->getYear() . "-" . $creation_date->getMonth() . "-" .
$creation_date->getDay();
?>
</td>
<td align="right" nowrap="nowarp"><?php echo $AppUI->_('Status'); ?>:&nbsp;</td>
<td width="100%" align="right"">
<?php
if ( ($canEdit) && ($status < 1) ) {
if ( ($canEdit) && ($status == 0) ) {
?>
<select name="timesheet_status" size="1" class="text" onChange="changeIt()">
<option <?php if ($status == 0) echo "selected"; ?> value="0"><? echo dPformSafe('Open for Editing');?></option>
......@@ -221,6 +223,9 @@ else {
<?php
}
else {
if ($status == 1)
echo dPformSafe('Submitted');
else if ($status == 1)
echo dPformSafe('Approved');
}
?>
......@@ -233,7 +238,7 @@ else {
<td>
<?php
// If $status is not "Open for Editing" then don't allow to change the status.
// There is one exception to this rule the 'administrator' can change the status.
// There is one exception to this rule the 'administrator' can always change the status.
if ($status == 0)
{
?>
......@@ -251,32 +256,26 @@ else {
</form>
</table>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr>
<th nowrap="nowrap">&nbsp;</th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Project' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Worked hours' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Project status' );?></th>
</tr>
<?php
$q->Clear();
$q->addQuery('project_id');
$q->addQuery('project_name');
$q->addQuery('project_status');
$q->addTable('projects');
$q->addOrder('project_name ASC');
$projects = $q->LoadList();
$timesheet_worked = 0;
foreach ($projects as $row) {
?>
<tr>
<td>&nbsp;</td>
<td><a href="?m=projects&a=view&project_id=<?php echo $row["project_id"]?>">
<?php echo $row["project_name"]; ?>
</a>
</td>
<td><?php
// Find all tasks in this timesheet period and account them to the project.
function showproject()
{
global $AppUI, $period, $obj;
$q = new DBQuery();
$q->addQuery('project_id');
$q->addQuery('project_name');
$q->addQuery('project_status');
$q->addTable('projects');
$q->addOrder('project_name ASC');
$projects = $q->LoadList();
$timesheet_worked = 0;
foreach ($projects as $row) {
echo '<tr>';
echo '<td>&nbsp;</td>';
echo '<td><a href="?m=projects&a=view&project_id="' . $row["project_id"] . '>' . $row["project_name"] . '</a>';
echo '</td>';
echo '<td>';
$project_id = $row["project_id"];
$t = new DBQuery;
$t->addQuery('task_id');
......@@ -309,24 +308,80 @@ foreach ($projects as $row) {
if (intval($logitem['task_log_date']))
{
$taskDate = new CDate($logitem['task_log_date']);
if ($period->GetMonth() == $taskDate->GetMonth())
if ($period->GetMonth() == $taskDate->GetMonth()) {
$amount = $amount + $logitem["task_log_hours"];
}
// else do not account the worked hours to the project for this month
}
}
}
echo $amount;
$timesheet_worked = $timesheet_worked + $amount;
?>
</td>
<td><?php echo $row["project_status"]; ?></td>
echo '</td>';
echo '<td>' . $row["project_status"] . '</td>';
echo '</tr>';
}
$obj->timesheet_worked = $timesheet_worked;
} // end of function showproject()
function showtimesheetproject()
{
global $timesheet_id;
$q = new DBQuery();
$q->addQuery('timesheet_id');
$q->addQuery('timesheet_project');
$q->addQuery('timesheet_project_amount');
$q->addTable('timesheet_project');
$q->addWhere('timesheet_id = ' . $timesheet_id);
$q->addOrder('timesheet_project ASC');
$timesheet = $q->LoadList();
foreach ($timesheet as $row) {
$p = new DBQuery();
$p->addQuery('project_id');
$p->addQuery('project_name');
$p->addQuery('project_status');
$p->addTable('projects');
$p->addWhere('project_id = ' . $row["timesheet_project"]);
$p->addOrder('project_name ASC');
$projects = $p->LoadList();
foreach ($projects as $project) {
echo '<tr>';
echo '<td>&nbsp;</td>';
echo '<td><a href="?m=projects&a=view&project_id="' . $row["timesheet_project"] . '>' . $project["project_name"] . '</a>';
echo '</td>';
echo '<td>' . $row["timesheet_project_amount"] . '</td>';
echo '<td>' . $project["project_status"] . '</td>';
echo '</tr>';
}
}
} // end of function showtimesheetproject()
?>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr>
<th nowrap="nowrap">&nbsp;</th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Project' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Worked hours' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Project status' );?></th>
</tr>
<?php
}
<form name="projectFrm" action="./index.php?m=timesheet" method="post">
<input type="hidden" name="dosql" value="do_timesheet_aed" />
<input type="hidden" name="projects" value="0" />
$obj->timesheet_worked = $timesheet_worked;
<input type="hidden" name="timesheet_id" value="<?php echo $timesheet_id;?>" />
<input type="hidden" name="timesheet_date" value="<?php echo $obj->timesheet_date;?>" />
<input type="hidden" name="timesheet_creator" value="<?php echo $obj->timesheet_creator;?>" />
<input type="hidden" name="timesheet_worked" value="<?php echo $obj->timesheet_worked;?>" />
<?php
if ($status == 0)
showproject();
else
showtimesheetproject();
?>
<script language="javascript">
workedHoursChange(<?php echo $obj->timesheet_worked; ?>);
</script>
</form>
</table>
......@@ -62,8 +62,7 @@ else if ($period) {
$AppUI->redirect();
} else {
$AppUI->setMsg( "Timesheet period changed", UI_MSG_ALERT);
//$AppUI->redirect( "m=timesheet&a=addedit&timesheet_id=".$obj->timesheet_id );
$AppUI->redirect();
$AppUI->redirect( "m=timesheet&a=addedit&timesheet_id=".$obj->timesheet_id );
}
}
else {
......
<?php
function timesheets($type)
{
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here
// as we are now within the tab box, we have to state (call) the needed information saved in the variables of the parent function
GLOBAL $AppUI, $canRead, $canEdit, $canDelete;
if (!$canRead) { // lock out users that do not have at least readPermission on this module
......@@ -40,6 +35,7 @@ $q->Clear();
$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator, timesheet_worked');
$q->addTable('timesheet');
$q->addWhere('timesheet_creator = ' . $AppUI->user_id );
if ($type >= 0)
$q->addWhere('timesheet_status = '. $type );
$month = $q->loadList();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment