Commit 8c173145 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Cleanup vw_idx_inc.php and add some debugging.

parent d77d2183
<?php <?php
/* /*
* Copyright (C) 2007, M2X * Copyright (C) 2007-2008, M2X
* *
* Authors: Jean-Paul Saman * Authors: Jean-Paul Saman
* *
...@@ -19,133 +19,150 @@ ...@@ -19,133 +19,150 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
function getMonthByName($month)
{
if ($month == 1)
$name = dPformSafe('January');
else if ($month == 2)
$name = dPformSafe('February');
else if ($month == 3)
$name = dPformSafe('March');
else if ($month == 4)
$name = dPformSafe('April');
else if ($month == 5)
$name = dPformSafe('May');
else if ($month == 6)
$name = dPformSafe('June');
else if ($month == 7)
$name = dPformSafe('July');
else if ($month == 8)
$name = dPformSafe('August');
else if ($month == 9)
$name = dPformSafe('September');
else if ($month == 10)
$name = dPformSafe('October');
else if ($month == 11)
$name = dPformSafe('November');
else if ($month == 12)
$name = dPformSafe('December');
return $name;
}
function printTableHeader()
{
GLOBAL $AppUI;
//prepare an html table with a head section
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">";
echo "<tr>";
echo "<th nowrap=\"nowrap\">&nbsp;</th>";
echo "<th nowrap=\"nowrap\">".$AppUI->_( 'Date' )."</th>";
echo "<th nowrap=\"nowrap\">".$AppUI->_( 'Period' )."</th>";
echo "<th nowrap=\"nowrap\">".$AppUI->_( 'Year' )."</th>";
echo "<th nowrap=\"nowrap\">".$AppUI->_( 'Worked' )."</th>";
echo "<th nowrap=\"nowrap\">".$AppUI->_( 'Submitter' )."</th>";
echo "<th nowrap=\"nowrap\">".$AppUI->_( 'Status' )."</th>";
echo "<th nowrap=\"nowrap\">&nbsp;</th>";
echo "</tr>";
}
function timesheets($type) function timesheets($type)
{ {
GLOBAL $AppUI, $canRead, $canEdit, $canDelete; GLOBAL $AppUI, $canRead, $canEdit, $canDelete;
if (!$canRead) { // lock out users that do not have at least readPermission on this module // lock out users that do not have at least readPermission on this module
if (!$canRead) {
$AppUI->redirect( "m=public&a=access_denied" ); $AppUI->redirect( "m=public&a=access_denied" );
} }
//prepare an html table with a head section
?> printTableHeader();
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr> // Retrieve the list of users that may access this module.
<th nowrap="nowrap">&nbsp;</th> if(isset($_REQUEST["user_filter_id"])){
<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
// Retrieve the list of users that may access this module.
if(isset($_REQUEST["user_filter_id"])){
$AppUI->setState("user_filter_id", $_REQUEST["user_filter_id"]); $AppUI->setState("user_filter_id", $_REQUEST["user_filter_id"]);
$user_filter_id = $_REQUEST["user_filter_id"]; $user_filter_id = $_REQUEST["user_filter_id"];
} else { } else {
$user_filter_id = $AppUI->getState('user_filter_id'); $user_filter_id = $AppUI->getState('user_filter_id');
if (!isset($user_filter_id)) { if (!isset($user_filter_id)) {
$user_filter_id = $AppUI->user_id; $user_filter_id = $AppUI->user_id;
$AppUI->setState('user_filter_id', $user_filter_id); $AppUI->setState('user_filter_id', $user_filter_id);
} }
} }
$perms =& $AppUI->acl(); $perms =& $AppUI->acl();
if ($canDelete) { if ($canDelete) {
$user_list = array( 0 => $AppUI->_("All", UI_OUTPUT_RAW)) + $perms->getPermittedUsers("timesheet"); $user_list = array( 0 => $AppUI->_("All", UI_OUTPUT_RAW)) + $perms->getPermittedUsers("timesheet");
} } else {
else {
$user_list = array( ) + $perms->getPermittedUsers("timesheet"); $user_list = array( ) + $perms->getPermittedUsers("timesheet");
} }
$user_combo = arraySelect($user_list, "user_filter_id", "class='text' onchange='javascript:document.searchform.submit()'", $user_filter_id, false); $user_combo = arraySelect($user_list, "user_filter_id", "class='text' onchange='javascript:document.searchform.submit()'", $user_filter_id, false);
echo "<tr><form name='searchform' action='?m=timesheet' method='post'> echo "<tr><form name='searchform' action='?m=timesheet' method='post'>
".$AppUI->_("Show timesheets for ").": $user_combo ".$AppUI->_("Show timesheets for ").": $user_combo </form></tr>";
</form></tr>";
// Pull all users // Pull all users
$q = new DBQuery; $q = new DBQuery();
$q->addQuery('user_id, contact_first_name, contact_last_name'); $q->addQuery('user_id, contact_first_name, contact_last_name');
$q->addTable('users'); $q->addTable('users');
$q->addTable('contacts'); $q->addTable('contacts');
$q->addWhere('user_contact = contact_id'); $q->addWhere('user_contact = contact_id');
$q->addOrder('contact_last_name, contact_first_name'); $q->addOrder('contact_last_name, contact_first_name');
$q->exec(); if (!$q->exec())
$users = array(); db_error();
while ( $row = $q->fetchRow()) { $users = array();
while ( $row = $q->fetchRow()) {
$users[$row['user_id']] = $row['contact_last_name'] . ', ' . $row['contact_first_name']; $users[$row['user_id']] = $row['contact_last_name'] . ', ' . $row['contact_first_name'];
} }
$q->Clear(); $q->Clear();
$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator, timesheet_worked'); $q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator, timesheet_worked');
$q->addTable('timesheet'); $q->addTable('timesheet');
if ($user_filter_id > 0) { if ($user_filter_id > 0) {
$q->addWhere('timesheet_creator = ' . $user_filter_id ); $q->addWhere('timesheet_creator = ' . $user_filter_id );
} } else {
else {
$q->addOrder('timesheet_creator'); $q->addOrder('timesheet_creator');
} }
$q->addOrder('timesheet_period'); $q->addOrder('timesheet_period');
if ($type >= 0) if ($type >= 0)
$q->addWhere('timesheet_status = '. $type ); $q->addWhere('timesheet_status = '. $type );
$month = $q->loadList(); $month = $q->loadList();
// add/show now gradually the timesheet // add/show now gradually the timesheet
foreach ($month as $row) { foreach ($month as $row) {
?> echo "<tr>";
<tr> echo "<td nowrap=\"nowrap\" width=\"20\">";
<td nowrap="nowrap" width="20"> if (($canEdit) && ($row["timesheet_status"]) < 1) {
<?php if (($canEdit) && ($row["timesheet_status"]) < 1) {
// call the edit site with the unique id of the timesheet item // 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 "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo dPshowImage( './images/icons/stock_edit-16.png', '16', '16' ); echo dPshowImage( './images/icons/stock_edit-16.png', '16', '16' );
echo "\n</a>"; echo "\n</a>";
} }
?> echo "</td>";
</td> echo "<td>";
<td> <?php
$date = new CDate(); $date = new CDate();
$date->setDate($row["timesheet_date"],DATE_FORMAT_UNIXTIME); $date->setDate($row["timesheet_date"],DATE_FORMAT_UNIXTIME);
echo '<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">'; echo '<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo $date->format( FMT_TIMESTAMP_DATE ); echo $date->format( FMT_TIMESTAMP_DATE );
echo "</a>"; echo "</a>";
?> </td> echo "</td>";
<td> <?php echo "<td>";
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">'; echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
$month = new CDate(); $period = new CDate();
$month->setMonth($row["timesheet_period"]); if (intval($row["timesheet_period"])<=12) {
if ($month->GetMonth() == 1) $period->setMonth($row["timesheet_period"]);
echo dPformSafe('January'); $period->setYear(2007);
else if ($month->getMonth() == 2) }
echo dPformSafe('February'); else
else if ($month->getMonth() == 3) $period->setDate($row["timesheet_period"],DATE_FORMAT_UNIXTIME);
echo dPformSafe('March'); /*debug >>*/echo "(". $row["timesheet_period"] . "," . $period->getMonth() . ") " ; //<< debug
else if ($month->getMonth() == 4) echo getMonthByName($period->getMonth());
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>"; echo "\n</a>";
?> echo "</td>";
</td> echo "<td>". $period->getYear() ."</td>";
<td> <?php echo $row["timesheet_worked"]; ?> </td> echo "<td>". $row["timesheet_worked"] ."</td>";
<td> <?php echo $users[$row["timesheet_creator"]]; ?> </td> echo "<td>". $users[$row["timesheet_creator"]] ."</td>";
<td> <?php echo "<td>";
$status = $row["timesheet_status"]; $status = $row["timesheet_status"];
if ($status == 0) if ($status == 0)
echo dPformSafe("Open for Editing"); echo dPformSafe("Open for Editing");
...@@ -153,22 +170,17 @@ foreach ($month as $row) { ...@@ -153,22 +170,17 @@ foreach ($month as $row) {
echo dPformSafe("Submitted"); // closed for normal users echo dPformSafe("Submitted"); // closed for normal users
else if ($status == 2) else if ($status == 2)
echo dPformSafe("Approved"); echo dPformSafe("Approved");
?> echo "</td>";
</td> echo "<td nowrap=\"nowrap\" width=\"20\">";
<td nowrap="nowrap" width="20"> <?php
if ($canDelete) { if ($canDelete) {
// call the edit site with the unique id of the timesheet item // 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 "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' ); echo dPshowImage( './images/icons/stock_delete-16.png', '16', '16' );
echo "\n</a>"; echo "\n</a>";
} }
?> echo "</td>";
</td> echo "</tr>";
</tr> }
<?php echo "</table>";
}
?>
</table>
<?php
} // end of function } // end of function
?> ?>
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