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
This diff is collapsed.
<?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