Commit 0df84b4f authored by Jean-Paul Saman's avatar Jean-Paul Saman

Inserting and viewing timesheets work.

TODO:
- deleting
- updating
- admin mode
- adding project hours and total to timesheet
parents
<?php
// Create new timesheet or edit an existing one.
$timesheet_id = intval( dPgetParam( $_GET, "timesheet_id", 0 ) );
// check permissions for this record
$canEdit = !getDenyEdit( $m, $timesheet_id );
if (!$canEdit) {
$AppUI->redirect( "m=public&a=access_denied" );
}
// use the object oriented design of dP for loading the timesheet that should be edited
// therefore create a new instance of the Timesheet Class
$obj = new CTimesheet();
// load the record data in case of that this script is used to edit the timesheet qith timesheet_id (transmitted via GET)
if (!$obj->load( $timesheet_id, false ) && $timesheet_id > 0) {
// show some error messages using the dPFramework if loadOperation failed
// these error messages are nicely integrated with the frontend of dP
// use detailed error messages as often as possible
$AppUI->setMsg( 'Timesheet' );
$AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
$AppUI->redirect(); // go back to the calling location
}
// check if this record has dependancies to prevent deletion
$msg = '';
$canDelete = $obj->canDelete( $msg, $timesheet_id );
// setup the title block
// Fill the title block either with 'Edit' or with 'New' depending on
// if timesheet_id has been transmitted via GET or is empty
$ttl = $timesheet_id > 0 ? "Edit Timesheet" : "New Timesheet";
$titleBlock = new CTitleBlock( $ttl, 'timesheet.png', $m, "$m.$a" );
$titleBlock->addCrumb( "?m=timesheet", "view all timesheets" );
if ($canEdit && $timesheet_id > 0) {
$titleBlock->addCrumbDelete( 'delete timesheet', $canDelete, $msg );
}
$titleBlock->show();
// some javaScript code to submit the form and set the delete object flag for the form processing
?>
<script language="javascript">
function delIt(id) {
if (confirm( "<?php echo $AppUI->_('Really delete this timesheet ?');?>" )) {
var f = document.editFrm;
f.del.value='1';
f.timesheet_id = id;
f.submit();
}
}
function changeStat(stat) {
var f=document.editFrm;
f.timesheet_status = stat;
f.submit();
}
</script>
<?php
// use the css-style 'std' of the UI style theme to format the table
// create a form providing to add/edit a timesheet
//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'];
}
// Get current submitter name
if ("$obj->timesheet_creator" == "") {
$submitter = $users[$AppUI->user_id];
$obj->timesheet_creator = $AppUI->user_id;
}
else
$submitter = $users[$obj->timesheet_creator];
$q->Clear();
// Get the current timesheet period
if (intval($obj->timesheet_period)) {
$period = new CDate();
$period->setMonth($obj->timesheet_period);
}
else
$period = new CDate();
// Get the current timesheet status
if (intval($obj->timesheet_status))
$status = $obj->timesheet_status;
else
$status = 0;
// Get the current timesheet creation date
if (intval($obj->timesheet_date)) {
$creation_date = new CDate();
$creation_date->setDate($obj->timesheet_date,DATE_FORMAT_UNIXTIME);
}
else {
$creation_date = new CDate();
$obj->timesheet_date = $creation_date->getTime();
}
?>
<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
<form name="editFrm" action="./index.php?m=timesheet" method="post">
<?php
// if set, the value of dosql is automatically executed by the dP core application
// do_timesheet_aed.php will be the target of this form
// it will execute all database relevant commands
?>
<input type="hidden" name="dosql" value="do_timesheet_aed" />
<?php
// the del variable contains a bool flag deciding whether to run a delete operation on the given object with timesheet_id
// the value of del will be zero by default (do not delete)
// or in case of mouse click on the delete icon it will set to '1' by javaScript (delete object with given timesheet_id)
?>
<input type="hidden" name="del" value="<?php echo $timesheet_id;?>" />
<?php
// the value of timesheet_id will be the id of the timesheet to edit
// or in case of addition of a new timesheet it will contain '0' as value
?>
<input type="hidden" name="timesheet_id" value="<?php echo $timesheet_id;?>" />
<input type="hidden" name="timesheet_date" value="<?php echo $obj->timesheet_date;?>" />
<input type="hidden" name="timesheet_creator" value="<?php echo $obj->timesheet_creator;?>" />
<?php
// please notice that html tags that have no </closing tag> should be closed
// like you find it here (<tag />) for xhtml compliance
?>
<tr>
<td width="50%" valign="top">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="right" nowrap="nowarp"><?php echo $AppUI->_('Submitter'); ?>:&nbsp;</td>
<td width="100%">
<?php echo $submitter; ?>
</td>
<td align="right" nowrap="nowarp"><?php echo $AppUI->_('Period'); ?>:&nbsp;</td>
<td width="100%">
<select name="timesheet_period" size="1' class="text">
<option <?php if ($period->getMonth() == 1) echo "selected"; ?> value="1"><? echo dPformSafe('January'); ?></option>
<option <?php if ($period->getMonth() == 2) echo "selected"; ?> value="2"><? echo dPformSafe('February'); ?></option>
<option <?php if ($period->getMonth() == 3) echo "selected"; ?> value="3"><? echo dPformSafe('March'); ?></option>
<option <?php if ($period->getMonth() == 4) echo "selected"; ?> value="4"><? echo dPformSafe('April'); ?></option>
<option <?php if ($period->getMonth() == 5) echo "selected"; ?> value="5"><? echo dPformSafe('May'); ?></option>
<option <?php if ($period->getMonth() == 6) echo "selected"; ?> value="6"><? echo dPformSafe('June'); ?></option>
<option <?php if ($period->getMonth() == 7) echo "selected"; ?> value="7"><? echo dPformSafe('July'); ?></option>
<option <?php if ($period->getMonth() == 8) echo "selected"; ?> value="8"><? echo dPformSafe('August'); ?></option>
<option <?php if ($period->getMonth() == 9) echo "selected"; ?> value="9"><? echo dPformSafe('September'); ?></option>
<option <?php if ($period->getMonth() == 10) echo "selected"; ?> value="10"><? echo dPformSafe('October'); ?></option>
<option <?php if ($period->getMonth() == 11) echo "selected"; ?> value="11"><? echo dPformSafe('November'); ?></option>
<option <?php if ($period->getMonth() == 12) echo "selected"; ?> value="12"><? echo dPformSafe('December'); ?></option>
</select>
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?php echo $AppUI->_('Creation date'); ?>:&nbsp;</td>
<td width="100%">
<?php
echo $creation_date ? $creation_date->format( FMT_TIMESTAMP_DATE ) : "" ;
?>
</td>
<td align="right" nowrap="nowarp"><?php echo $AppUI->_('Status'); ?>:&nbsp;</td>
<td width="100%" align="right"">
<select name="timesheet_status" size="1" class="text">
<option <?php if ($status == 0) echo "selected"; ?> value="0"><? echo dPformSafe('Open for Editing');?></option>
<option <?php if ($status == 1) echo "selected"; ?> value="1"><? echo dPformSafe('Submitted');?></option>
<option <?php if ($status == 2) echo "selected"; ?> value="2"><? echo dPformSafe('Approved');?></option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
// If $status is not "Open for Editing" then don't allow to change the status.
// There is one exception to this rule the 'administrator' can change the status.
if ($status == 0)
{
?>
<input class="button" type="button" name="cancel" value="<?php echo $AppUI->_('cancel');?>" onClick="javascript:if(confirm('Are you sure you want to cancel.')){location.href = './index.php?m=timesheet';}" />
</td>
<td align="right">
<input class="button" type="submit" name="btnFuseAction" value="<?php echo $AppUI->_('submit');?>"/>
<?php }
else {
echo '&nbsp;</td><td align="right">&nbsp;';
}
?>
</td>
</tr>
</form>
</table>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr>
<th nowrap="nowrap">&nbsp;</th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Project' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Worked hours' );?></th>
<th nowrap="nowrap"><?php echo $AppUI->_( 'Project status' );?></th>
</tr>
<?php
$q->Clear();
$q->addQuery('project_id');
$q->addQuery('project_name');
$q->addQuery('project_status');
$q->addTable('projects');
$q->addOrder('project_name ASC');
$projects = $q->LoadList();
foreach ($projects as $row) {
?>
<tr>
<td>&nbsp;</td>
<td><a href="?m=projects&a=view&project_id=<?php echo $row["project_id"]?>">
<?php echo $row["project_name"]; ?>
</a>
</td>
<td><?php
$project_id = $row["project_id"];
$t = new DBQuery;
$t->addQuery('task_id');
$t->addQuery('task_name');
$t->addQuery('task_owner');
$t->addQuery('task_start_date');
$t->addQuery('task_hours_worked');
$t->addTable('tasks');
$t->addWhere('task_project = '. $project_id);
$t->addOrder('task_start_date DESC');
$tasks = $t->LoadList();
$t->Clear();
$amount = 0;
foreach ($tasks as $item) {
// Query the task_log table for actual start dates.
$t->addQuery('task_log_id');
$t->addQuery('task_log_name');
$t->addQuery('task_log_creator');
$t->addQuery('task_log_date');
$t->addQuery('task_log_hours');
$t->addTable('task_log');
$t->addWhere('task_log_task = '. $item["task_id"]);
// What if this is different then current user?
$t->addWhere('task_log_creator = ' . $AppUI->user_id);
$t->addOrder('task_log_date DESC');
// TODO: select on user and date
$log = $t->LoadList();
foreach ($log as $logitem) {
if (intval($logitem['task_log_date']))
{
$taskDate = new CDate($logitem['task_log_date']);
if ($period->GetMonth() == $taskDate->GetMonth())
$amount = $amount + $logitem["task_log_hours"];
// else do not account the worked hours to the project for this month
}
}
}
echo $amount;
?>
</td>
<td><?php echo $row["project_status"]; ?></td>
</tr>
<?php
}
?>
</table>
<?php
// this doSQL script is called from the addedit.php script
// its purpose is to use the CTimesheet class to interoperate with the database (store, edit, delete)
/* the following variables can be retreived via POST from timesheet/addedit.php:
** int timesheet_id is '0' if a new database object has to be stored or the id of an existing quote that should be overwritten or deleted in the db
** int timesheet_period the period of the timesheet that should be stored
** int del bool flag, in case of presence the row with the given timesheet_id has to be dropped from db
*/
// create a new instance of the timesheet class
$obj = new CTimesheet();
$msg = ''; // reset the message string
// bind the informations (variables) retrieved via post to the timesheet object
if (!$obj->bind( $_POST )) {
$AppUI->setMsg( $obj->getError(), UI_MSG_ERROR );
$AppUI->redirect();
}
// detect if a deleete operation has to be processed
$stat = dPgetParam($_POST, 'stat', 0 );
$del = dPgetParam( $_POST, 'del', 0 );
$obj->timesheet_id = $_POST["timesheet_id"];
$obj->timesheet_status = $_POST["timesheet_status"];
$obj->timesheet_period = $_POST["timesheet_period"];
$obj->timesheet_date = $_POST["timesheet_date"];
$obj->timesheet_creator = $_POST["timesheet_creator"];
echo "$obj_timesheet_id, $obj->timesheet_status, $obj->timesheet_period, $obj->timesheet_date, $obj->timesheet_creator";
$AppUI->setMsg( 'Timesheet' );
if ($del) {
// check if there are dependencies on this object (not relevant for timesheet, left here for show-purposes)
if (!$obj->canDelete( $msg )) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
}
// see how easy it is to run database commands with the object oriented architecture !
// simply delete a quote from db and have detailed error or success report
if (($msg = $obj->delete())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR ); // message with error flag
$AppUI->redirect();
} else {
$AppUI->setMsg( "Timesheet deleted", UI_MSG_ALERT); // message with success flag
$AppUI->redirect( "m=timesheet" );
}
} else {
// simply store the added/edited quote in database via the store method of the timesheet child class of the CDpObject provided ba the dPFramework
// no sql command is necessary here! :-)
if (($msg = $obj->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$isNotNew = @$_POST['timesheet_id'];
$AppUI->setMsg( $isNotNew ? 'Timesheet updated' : 'Timesheet inserted', UI_MSG_OK);
} $AppUI->redirect("m=timesheet" );
}
?>
<?php
// this is the index site for our timesheet module
// it is automatically appended on the applications main ./index.php
// by the dPframework
// we check for permissions on this module
$canRead = !getDenyRead( $m ); // retrieve module-based readPermission bool flag
$canEdit = !getDenyEdit( $m ); // retrieve module-based writePermission bool flag
// lock out users that do not have at least readPermission on this module
if (!$canRead) {
$AppUI->redirect( "m=public&a=access_denied" );
}
//save the workplace state (have a footprint on this site)
$AppUI->savePlace();
// retrieve any state parameters (temporary session variables that are not stored in db)
// saves the current tab box state
if (isset( $_GET['tab'] )) {
$AppUI->setState( 'TimesheetIdxTab', $_GET['tab'] );
}
$tab = $AppUI->getState( 'TimesheetIdxTab' ) !== NULL ? $AppUI->getState( 'TimesheetIdxTab' ) : 0;
$active = intval( !$AppUI->getState( 'TimesheetIdxTab' ) );
// we prepare the User Interface Design with the dPFramework
// setup the title block with Name, Icon and Help
$titleBlock = new CTitleBlock( 'Timesheet', 'timesheet.png', $m, "$m.$a" );
$titleBlock->addCell();
// adding the 'add'-Button if user has writePermissions
if ($canEdit) {
$titleBlock->addCell(
'<input type="submit" class="button" value="'.$AppUI->_('new timesheet').'">', '',
'<form action="?m=timesheet&a=addedit" method="post">', '</form>'
);
}
$titleBlock->show();
// now prepare and show the tabbed information boxes with the dPFramework
// The Period default for the timesheets (month,week)
// $period = $AppUI->getPref('TIMESHEET_PERIOD');
// build new tab box object
$tabBox = new CTabBox( "?m=timesheet", dPgetConfig('root_dir') . "/modules/timesheet/", $tab );
$tabBox->add( 'vw_idx_timesheets', 'All timesheets' );
$tabBox->add( 'vw_idx_open', 'Open timesheets' );
$tabBox->add( 'vw_idx_submitted', 'Submitted timesheets' );
$tabBox->add( 'vw_idx_approved', 'Approved timesheets' );
$tabBox->show();
?>
<?php
/*
* Name: Timesheet
* Directory: timesheet
* Version: 1.0.0
* Type: user
* UI Name: Timesheet
* UI Icon:
*/
// MODULE CONFIGURATION DEFINITION
$config = array();
$config['mod_name'] = 'Timesheet'; // name the module
$config['mod_version'] = '1.0.0'; // add a version number
$config['mod_directory'] = 'timesheet'; // tell dotProject where to find this module
$config['mod_setup_class'] = 'CSetupTimesheet'; // the name of the PHP setup class (used below)
$config['mod_type'] = 'user'; // 'core' for modules distributed with dP by standard, 'user' for additional modules from dotmods
$config['mod_ui_name'] = 'Timesheet'; // the name that is shown in the main menu of the User Interface
$config['mod_ui_icon'] = 'communicate.gif'; // name of a related icon
$config['mod_description'] = 'Timesheet module for hour registrations'; // some description of the module
$config['mod_config'] = true; // show 'configure' link in viewmods
// show module configuration with the dPframework (if requested via http)
if (@$a == 'setup') {
echo dPshowModuleConfig( $config );
}
class CSetupTimesheet {
function configure() { // configure this module
global $AppUI;
$AppUI->redirect( 'm=timesheet&a=configure' ); // load module specific configuration page
return true;
}
function remove() {
$q = new DBQuery;
$q->dropTable('timesheet');
$q->exec();
$q->clear();
$q->dropTable('timesheet_project');
$q->exec();
return null;
}
function upgrade( $old_version ) {
// use this to provide upgrade functionality between different versions; not relevant here
switch ( $old_version )
{
case "all": // upgrade from scratch (called from install)
case "0.9":
//do some alter table commands
case "1.0":
return true;
default:
return false;
}
return false;
}
function install() {
// prepare the creation of a dbTable
$sql = "( " .
" `timesheet_id` int(11) unsigned NOT NULL auto_increment," .
" `timesheet_period` int(11), " .
" `timesheet_status` int(4) NOT NULL default '0', " .
" `timesheet_date` int(11) NOT NULL default '0', " .
" `timesheet_creator` int(11) NOT NULL default '0', " .
" PRIMARY KEY (`timesheet_id`), " .
" UNIQUE KEY `timesheet_id` (`timesheet_id`) " .
") TYPE=MyISAM";
$q = new DBQuery;
$q->createTable('timesheet');
$q->createDefinition($sql);
$q->exec();
db_error();
$sql = "( " .
" `timesheet_queue_id` int(11) NOT NULL auto_increment, " .
" `timesheet_id` int(11) unsigned NOT NULL, " .
" `timesheet_project` int(11) NOT NULL default '0', " .
" `timesheet_project_amount` bigint(20) NOT NULL default '0', " .
" PRIMARY KEY (`timesheet_queue_id`) " .
") TYPE=MyISAM";
$q->clear();
$q->createTable('timesheet_project');
$q->createDefinition($sql);
$q->exec();
db_error();
return null;
}
}
?>
<?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>
<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>
<?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>
<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>
<?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>
<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>
<?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>
<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();
$sql = "SELECT * FROM `timesheet`";
$month = db_loadList( $sql );
// 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>
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