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

Cleanup vw_idx_inc.php and add some debugging.

parent d77d2183
<?php
/*
* Copyright (C) 2007, M2X
* Copyright (C) 2007-2008, M2X
*
* Authors: Jean-Paul Saman
*
......@@ -19,156 +19,168 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
function timesheets($type)
function getMonthByName($month)
{
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
// 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"]);
$user_filter_id = $_REQUEST["user_filter_id"];
} else {
$user_filter_id = $AppUI->getState('user_filter_id');
if (!isset($user_filter_id)) {
$user_filter_id = $AppUI->user_id;
$AppUI->setState('user_filter_id', $user_filter_id);
}
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;
}
$perms =& $AppUI->acl();
if ($canDelete) {
$user_list = array( 0 => $AppUI->_("All", UI_OUTPUT_RAW)) + $perms->getPermittedUsers("timesheet");
}
else {
$user_list = array( ) + $perms->getPermittedUsers("timesheet");
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>";
}
$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'>
".$AppUI->_("Show timesheets for ").": $user_combo
</form></tr>";
function timesheets($type)
{
GLOBAL $AppUI, $canRead, $canEdit, $canDelete;
// 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'];
}
// lock out users that do not have at least readPermission on this module
if (!$canRead) {
$AppUI->redirect( "m=public&a=access_denied" );
}
$q->Clear();
$q->addQuery('timesheet_id, timesheet_date, timesheet_status, timesheet_period, timesheet_creator, timesheet_worked');
$q->addTable('timesheet');
if ($user_filter_id > 0) {
$q->addWhere('timesheet_creator = ' . $user_filter_id );
}
else {
$q->addOrder('timesheet_creator');
}
$q->addOrder('timesheet_period');
printTableHeader();
if ($type >= 0)
$q->addWhere('timesheet_status = '. $type );
$month = $q->loadList();
// 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"]);
$user_filter_id = $_REQUEST["user_filter_id"];
} else {
$user_filter_id = $AppUI->getState('user_filter_id');
if (!isset($user_filter_id)) {
$user_filter_id = $AppUI->user_id;
$AppUI->setState('user_filter_id', $user_filter_id);
}
}
// 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 for normal users
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
$perms =& $AppUI->acl();
if ($canDelete) {
$user_list = array( 0 => $AppUI->_("All", UI_OUTPUT_RAW)) + $perms->getPermittedUsers("timesheet");
} else {
$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);
echo "<tr><form name='searchform' action='?m=timesheet' method='post'>
".$AppUI->_("Show timesheets for ").": $user_combo </form></tr>";
// 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');
if (!$q->exec())
db_error();
$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 ($user_filter_id > 0) {
$q->addWhere('timesheet_creator = ' . $user_filter_id );
} else {
$q->addOrder('timesheet_creator');
}
$q->addOrder('timesheet_period');
if ($type >= 0)
$q->addWhere('timesheet_status = '. $type );
$month = $q->loadList();
// add/show now gradually the timesheet
foreach ($month as $row) {
echo "<tr>";
echo "<td nowrap=\"nowrap\" width=\"20\">";
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>";
}
echo "</td>";
echo "<td>";
$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>";
echo "</td>";
echo "<td>";
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
$period = new CDate();
if (intval($row["timesheet_period"])<=12) {
$period->setMonth($row["timesheet_period"]);
$period->setYear(2007);
}
else
$period->setDate($row["timesheet_period"],DATE_FORMAT_UNIXTIME);
/*debug >>*/echo "(". $row["timesheet_period"] . "," . $period->getMonth() . ") " ; //<< debug
echo getMonthByName($period->getMonth());
echo "\n</a>";
echo "</td>";
echo "<td>". $period->getYear() ."</td>";
echo "<td>". $row["timesheet_worked"] ."</td>";
echo "<td>". $users[$row["timesheet_creator"]] ."</td>";
echo "<td>";
$status = $row["timesheet_status"];
if ($status == 0)
echo dPformSafe("Open for Editing");
else if ($status == 1)
echo dPformSafe("Submitted"); // closed for normal users
else if ($status == 2)
echo dPformSafe("Approved");
echo "</td>";
echo "<td nowrap=\"nowrap\" width=\"20\">";
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>";
}
echo "</td>";
echo "</tr>";
}
echo "</table>";
} // 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