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