Commit 623782c3 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Removed code duplication by introducing a timesheets() php function that will...

Removed code duplication by introducing a timesheets() php function that will be called from every timesheet overview type (status: all=-1, open=0, submitted=2, approved=3).
parent 07386af7
......@@ -28,6 +28,7 @@ $obj->timesheet_status = $_POST["timesheet_status"];
$obj->timesheet_period = $_POST["timesheet_period"];
$obj->timesheet_date = $_POST["timesheet_date"];
$obj->timesheet_creator = $_POST["timesheet_creator"];
$obj->timesheet_worked = $_POST["timesheet_worked"];
$AppUI->setMsg( 'Timesheet' );
if ($del) {
......
<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here
include("vw_idx_inc.php");
// 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>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Submitter' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Status' );?></th>
<th nowrap="nowrap">&nbsp;</th>
</tr>
<?php
// retrieving some dynamic content using an easy database query
//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();
$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator');
$q->addTable('timesheet');
$q->addWhere('timesheet_status = 2');
$month = $q->loadList();
// add/show now gradually the timesheet
foreach ($month as $row) { //parse the array of timesheet
?>
<tr>
<td nowrap="nowrap" width="20">
<?php if ($canEdit) {
// call the edit site with the unique id of the timesheet item
echo "\n".'<a href="./index.php?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
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);
echo '<a href="./index.php?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo $date->format( FMT_TIMESTAMP_DATE );
echo "</a>";
?> </td>
<td> <?php
$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');
?>
</td>
<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
echo "\n".'<a href="./index.php?m=timesheet&a=deletet&timesheet_id=' . $row["timesheet_id"] . '">';
echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' );
echo "\n</a>";
}
?>
</td>
</tr>
<?php
}
?>
</table>
echo timesheets(2);
?>
<?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
$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>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Worked' );?></th>
<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();
$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator, timesheet_worked');
$q->addTable('timesheet');
if ($type >= 0)
$q->addWhere('timesheet_status = '. $type );
$month = $q->loadList();
// add/show now gradually the timesheet
foreach ($month as $row) {
?>
<tr>
<td nowrap="nowrap" width="20">
<?php if (($canEdit) && ($row["timesheet_status"]) < 1) {
// call the edit site with the unique id of the timesheet item
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
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);
echo '<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo $date->format( FMT_TIMESTAMP_DATE );
echo "</a>";
?> </td>
<td> <?php
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
$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');
echo "\n</a>";
?>
</td>
<td> <?php echo $row["timesheet_worked"]; ?> </td>
<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
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' );
echo "\n</a>";
}
?>
</td>
</tr>
<?php
}
?>
</table>
<?php
} // end of function
?>
<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here
include("vw_idx_inc.php");
// 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>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Submitter' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Status' );?></th>
<th nowrap="nowrap">&nbsp;</th>
</tr>
<?php
// retrieving some dynamic content using an easy database query
//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();
$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator');
$q->addTable('timesheet');
$q->addWhere('timesheet_status = 0');
$month = $q->loadList();
// add/show now gradually the timesheet
foreach ($month as $row) { //parse the array of timesheet
?>
<tr>
<td nowrap="nowrap" width="20">
<?php if ($canEdit) {
// call the edit site with the unique id of the timesheet item
echo "\n".'<a href="./index.php?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
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);
echo '<a href="./index.php?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo $date->format( FMT_TIMESTAMP_DATE );
echo "</a>";
?> </td>
<td> <?php
$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');
?>
</td>
<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
echo "\n".'<a href="./index.php?m=timesheet&a=deletet&timesheet_id=' . $row["timesheet_id"] . '">';
echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' );
echo "\n</a>";
}
?>
</td>
</tr>
<?php
}
?>
</table>
echo timesheets(0);
?>
<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here
include("vw_idx_inc.php");
// 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>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Submitter' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Status' );?></th>
<th nowrap="nowrap">&nbsp;</th>
</tr>
<?php
// retrieving some dynamic content using an easy database query
//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();
$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator');
$q->addTable('timesheet');
$q->addWhere('timesheet_status = 1');
$month = $q->loadList();
// add/show now gradually the timesheet
foreach ($month as $row) { //parse the array of timesheet
?>
<tr>
<td nowrap="nowrap" width="20">
<?php if ($canEdit) {
// call the edit site with the unique id of the timesheet item
echo "\n".'<a href="./index.php?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
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);
echo '<a href="./index.php?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo $date->format( FMT_TIMESTAMP_DATE );
echo "</a>";
?> </td>
<td> <?php
$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');
?>
</td>
<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
echo "\n".'<a href="./index.php?m=timesheet&a=deletet&timesheet_id=' . $row["timesheet_id"] . '">';
echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' );
echo "\n</a>";
}
?>
</td>
</tr>
<?php
}
?>
</table>
echo timesheets(1);
?>
<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here
include("vw_idx_inc.php");
// 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>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Worked' );?></th>
<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();
$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();
// add/show now gradually the timesheet
foreach ($month as $row) {
?>
<tr>
<td nowrap="nowrap" width="20">
<?php if (($canEdit) && ($row["timesheet_status"]) < 1) {
// call the edit site with the unique id of the timesheet item
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
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);
echo '<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo $date->format( FMT_TIMESTAMP_DATE );
echo "</a>";
?> </td>
<td> <?php
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
$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');
echo "\n</a>";
?>
</td>
<td> <?php echo $row["timesheet_worked"]; ?> </td>
<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
echo "\n".'<a href="?m=timesheet&a=delete&timesheet_id=' . $row["timesheet_id"] . '">';
echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' );
echo "\n</a>";
}
?>
</td>
</tr>
<?php
}
?>
</table>
echo timesheets(-1);
?>
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