vw_idx_timesheets.php 3.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
// 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
	$AppUI->redirect( "m=public&a=access_denied" );
}
//prepare an html table with a head section
?>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr>
	<th nowrap="nowrap">&nbsp;</th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Date' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Month' );?></th>
Jean-Paul Saman's avatar
Jean-Paul Saman committed
18
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Worked' );?></th>
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Submitter' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Status' );?></th>
	<th nowrap="nowrap">&nbsp;</th>
</tr>
<?php
//Pull all users
$q = new DBQuery;
$q->addQuery('user_id, contact_first_name, contact_last_name');
$q->addTable('users');
$q->addTable('contacts');
$q->addWhere('user_contact = contact_id');
$q->addOrder('contact_last_name, contact_first_name');
$q->exec();
$users = array();
while ( $row = $q->fetchRow()) {
  $users[$row['user_id']] = $row['contact_last_name'] . ', ' . $row['contact_first_name'];
}
$q->Clear();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
37 38 39 40 41

$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator, timesheet_worked');
$q->addTable('timesheet');
//$q->addWhere('timesheet_status = 1');
$month = $q->loadList();
42 43

// add/show now gradually the timesheet
Jean-Paul Saman's avatar
Jean-Paul Saman committed
44
foreach ($month as $row) {
45 46 47
?>
<tr>
	<td nowrap="nowrap" width="20">

48
	<?php if (($canEdit) && ($row["timesheet_status"]) < 1) {
49
		// call the edit site with the unique id of the timesheet item
50
		echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
51 52 53 54 55 56 57 58
		echo dPshowImage( './images/icons/stock_edit-16.png', '16', '16' );
		echo "\n</a>";
	}
	?>
	</td>
	<td> <?php 
		$date = new CDate();
		$date->setDate($row["timesheet_date"],DATE_FORMAT_UNIXTIME);
59
		echo '<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
60 61 62 63
		echo $date->format( FMT_TIMESTAMP_DATE );
		echo "</a>";
	      ?> </td>
	<td> <?php 
Jean-Paul Saman's avatar
Jean-Paul Saman committed
64
		echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
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
		$month = new CDate();
		$month->setMonth($row["timesheet_period"]);
		if ($month->GetMonth() == 1)
			echo dPformSafe('January');
		else if ($month->getMonth() == 2)
			echo dPformSafe('February');
		else if ($month->getMonth() == 3)
			echo dPformSafe('March');
		else if ($month->getMonth() == 4)
			echo dPformSafe('April');
		else if ($month->getMonth() == 5)
			echo dPformSafe('May');
		else if ($month->getMonth() == 6)
			echo dPformSafe('June');
		else if ($month->getMonth() == 7)
			echo dPformSafe('July');
		else if ($month->getMonth() == 8)
			echo dPformSafe('August');
		else if ($month->getMonth() == 9)
			echo dPformSafe('September');
		else if ($month->getMonth() == 10)
			echo dPformSafe('October');
		else if ($month->getMonth() == 11)
			echo dPformSafe('November');
		else if ($month->getMonth() == 12)
			echo dPformSafe('December');
Jean-Paul Saman's avatar
Jean-Paul Saman committed
91
		echo "\n</a>";
92 93
	     ?>
        </td>
Jean-Paul Saman's avatar
Jean-Paul Saman committed
94
	<td> <?php echo $row["timesheet_worked"]; ?> </td>
95 96 97 98 99 100 101 102 103 104 105 106 107 108
	<td> <?php echo $users[$row["timesheet_creator"]]; ?> </td>
	<td> <?php 
		$status = $row["timesheet_status"]; 
		if ($status == 0)
			echo dPformSafe("Open for Editing");
		else if ($status == 1)
			echo dPformSafe("Submitted"); // closed
		else if ($status == 2)
			echo dPformSafe("Approved");
	     ?>
	</td>
	<td nowrap="nowrap" width="20"> <?php
		if ($canDelete) {
			// call the edit site with the unique id of the timesheet item
109
			echo "\n".'<a href="?m=timesheet&a=delete&timesheet_id=' . $row["timesheet_id"] . '">';
110 111 112 113 114 115 116 117 118 119
			echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' );
			echo "\n</a>";
		}
	     ?>
	</td>
</tr>
<?php
}
?>
</table>