Commit ae9ecf4a authored by Jean-Paul Saman's avatar Jean-Paul Saman

Make delete, changing status and period work. Make status and period fields in...

Make delete, changing status and period work. Make status and period fields in addedit.php readonly when the timesheet has been submitted and approved.

TODO:
- delete from vw_idx_*.php files doesn't work.
- changing status and period on new file creates a duplicate record.
parent 0df84b4f
...@@ -45,14 +45,19 @@ $titleBlock->show(); ...@@ -45,14 +45,19 @@ $titleBlock->show();
if (confirm( "<?php echo $AppUI->_('Really delete this timesheet ?');?>" )) { if (confirm( "<?php echo $AppUI->_('Really delete this timesheet ?');?>" )) {
var f = document.editFrm; var f = document.editFrm;
f.del.value='1'; f.del.value='1';
f.timesheet_id = id;
f.submit(); f.submit();
} }
} }
function changeStat(stat) { function changeIt() {
var f=document.editFrm; var f=document.editFrm;
f.timesheet_status = stat; f.stat.value='1';
f.submit();
}
function periodChange() {
var f=document.editFrm;
f.period.value='1';
f.submit(); f.submit();
} }
...@@ -120,7 +125,9 @@ else { ...@@ -120,7 +125,9 @@ else {
// the value of del will be zero by default (do not delete) // 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) // 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;?>" /> <input type="hidden" name="del" value="0" />
<input type="hidden" name="stat" value="0" />
<input type="hidden" name="period" value="0" />
<?php <?php
// the value of timesheet_id will be the id of the timesheet to edit // the value of timesheet_id will be the id of the timesheet to edit
...@@ -145,7 +152,10 @@ else { ...@@ -145,7 +152,10 @@ else {
</td> </td>
<td align="right" nowrap="nowarp"><?php echo $AppUI->_('Period'); ?>:&nbsp;</td> <td align="right" nowrap="nowarp"><?php echo $AppUI->_('Period'); ?>:&nbsp;</td>
<td width="100%"> <td width="100%">
<select name="timesheet_period" size="1' class="text"> <?php
if ( ($canEdit) && ($status < 1) ) {
?>
<select name="timesheet_period" size="1' class="text" onChange="periodChange();">
<option <?php if ($period->getMonth() == 1) echo "selected"; ?> value="1"><? echo dPformSafe('January'); ?></option> <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() == 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() == 3) echo "selected"; ?> value="3"><? echo dPformSafe('March'); ?></option>
...@@ -159,6 +169,23 @@ else { ...@@ -159,6 +169,23 @@ else {
<option <?php if ($period->getMonth() == 11) echo "selected"; ?> value="11"><? echo dPformSafe('November'); ?></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> <option <?php if ($period->getMonth() == 12) echo "selected"; ?> value="12"><? echo dPformSafe('December'); ?></option>
</select> </select>
<?php
}
else {
if ($period->getMonth() == 1) echo dPformSafe('January');
else if ($period->getMonth() == 2) echo dPformSafe('February');
else if ($period->getMonth() == 3) echo dPformSafe('March');
else if ($period->getMonth() == 4) echo dPformSafe('April');
else if ($period->getMonth() == 5) echo dPformSafe('May');
else if ($period->getMonth() == 6) echo dPformSafe('June');
else if ($period->getMonth() == 7) echo dPformSafe('July');
else if ($period->getMonth() == 8) echo dPformSafe('August');
else if ($period->getMonth() == 9) echo dPformSafe('September');
else if ($period->getMonth() == 10) echo dPformSafe('October');
else if ($period->getMonth() == 11) echo dPformSafe('November');
else if ($period->getMonth() == 12) echo dPformSafe('December');
}
?>
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -170,11 +197,20 @@ else { ...@@ -170,11 +197,20 @@ else {
</td> </td>
<td align="right" nowrap="nowarp"><?php echo $AppUI->_('Status'); ?>:&nbsp;</td> <td align="right" nowrap="nowarp"><?php echo $AppUI->_('Status'); ?>:&nbsp;</td>
<td width="100%" align="right""> <td width="100%" align="right"">
<select name="timesheet_status" size="1" class="text"> <?php
if ( ($canEdit) && ($status < 1) ) {
?>
<select name="timesheet_status" size="1" class="text" onChange="changeIt()">
<option <?php if ($status == 0) echo "selected"; ?> value="0"><? echo dPformSafe('Open for Editing');?></option> <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 == 1) echo "selected"; ?> value="1"><? echo dPformSafe('Submitted');?></option>
<option <?php if ($status == 2) echo "selected"; ?> value="2"><? echo dPformSafe('Approved');?></option> <option <?php if ($status == 2) echo "selected"; ?> value="2"><? echo dPformSafe('Approved');?></option>
</select> </select>
<?php
}
else {
echo dPformSafe('Approved');
}
?>
</td> </td>
</tr> </tr>
</table> </table>
......
...@@ -19,8 +19,9 @@ if (!$obj->bind( $_POST )) { ...@@ -19,8 +19,9 @@ if (!$obj->bind( $_POST )) {
} }
// detect if a deleete operation has to be processed // detect if a deleete operation has to be processed
$stat = dPgetParam($_POST, 'stat', 0 ); $period = dPgetParam($_POST, 'period', 0);
$del = dPgetParam( $_POST, 'del', 0 ); $stat = dPgetParam($_POST, 'stat', 0);
$del = dPgetParam($_POST, 'del', 0);
$obj->timesheet_id = $_POST["timesheet_id"]; $obj->timesheet_id = $_POST["timesheet_id"];
$obj->timesheet_status = $_POST["timesheet_status"]; $obj->timesheet_status = $_POST["timesheet_status"];
...@@ -28,27 +29,44 @@ $obj->timesheet_period = $_POST["timesheet_period"]; ...@@ -28,27 +29,44 @@ $obj->timesheet_period = $_POST["timesheet_period"];
$obj->timesheet_date = $_POST["timesheet_date"]; $obj->timesheet_date = $_POST["timesheet_date"];
$obj->timesheet_creator = $_POST["timesheet_creator"]; $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' ); $AppUI->setMsg( 'Timesheet' );
if ($del) { if ($del) {
// check if there are dependencies on this object (not relevant for timesheet, left here for show-purposes) // check if there are dependencies on this object
if (!$obj->canDelete( $msg )) { if (!$obj->canDelete( $msg )) {
$AppUI->setMsg( $msg, UI_MSG_ERROR ); $AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect(); $AppUI->redirect();
} }
// see how easy it is to run database commands with the object oriented architecture ! // 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 // simply delete a quote from db and have detailed error or success report
if (($msg = $obj->delete())) { if ($msg = $obj->delete()) {
$AppUI->setMsg( $msg, UI_MSG_ERROR ); // message with error flag $AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect(); $AppUI->redirect();
} else { } else {
$AppUI->setMsg( "Timesheet deleted", UI_MSG_ALERT); // message with success flag $AppUI->setMsg( "Timesheet deleted", UI_MSG_ALERT);
$AppUI->redirect( "m=timesheet" ); $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 else if ($stat) {
// no sql command is necessary here! :-) if ($msg = $obj->change_status($obj->timesheet_status)) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
} else {
$AppUI->setMsg( "Timesheet status updated", UI_MSG_ALERT);
$AppUI->redirect( "m=timesheet&a=addedit&timesheet_id=".$obj->timesheet_id );
}
}
else if ($period) {
if ($msg = $obj->change_period($obj->timesheet_period)) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
} else {
$AppUI->setMsg( "Timesheet period changed", UI_MSG_ALERT);
$AppUI->redirect( "m=timesheet&a=addedit&timesheet_id=".$obj->timesheet_id );
}
}
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
if (($msg = $obj->store())) { if (($msg = $obj->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR ); $AppUI->setMsg( $msg, UI_MSG_ERROR );
} else { } else {
......
...@@ -44,9 +44,9 @@ foreach ($month as $row) { //parse the array of timesheet ...@@ -44,9 +44,9 @@ foreach ($month as $row) { //parse the array of timesheet
?> ?>
<tr> <tr>
<td nowrap="nowrap" width="20"> <td nowrap="nowrap" width="20">
<?php if ($canEdit) { <?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="./index.php?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>";
} }
...@@ -55,7 +55,7 @@ foreach ($month as $row) { //parse the array of timesheet ...@@ -55,7 +55,7 @@ foreach ($month as $row) { //parse the array of timesheet
<td> <?php <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="./index.php?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> ?> </td>
...@@ -102,7 +102,7 @@ foreach ($month as $row) { //parse the array of timesheet ...@@ -102,7 +102,7 @@ foreach ($month as $row) { //parse the array of timesheet
<td nowrap="nowrap" width="20"> <?php <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="./index.php?m=timesheet&a=deletet&timesheet_id=' . $row["timesheet_id"] . '">'; echo "\n".'<a href="?m=timesheet&a=delete&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>";
} }
......
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