Commit 5abe59c3 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Work around variable naming clash between CGI, JavaScript and PHP code. This...

Work around variable naming clash between CGI, JavaScript and PHP code. This made the content of timesheet_period revert to 1 on onChange().
parent 331b29ee
...@@ -91,8 +91,8 @@ $titleBlock->show(); ...@@ -91,8 +91,8 @@ $titleBlock->show();
} }
function periodChange() { function periodChange() {
var f=document.editFrm; var f=document.editFrm;
f.period.value='1'; f.workperiod.value='1';
f.submit(); f.submit();
} }
...@@ -130,16 +130,19 @@ $q->Clear(); ...@@ -130,16 +130,19 @@ $q->Clear();
// Get the current timesheet period // Get the current timesheet period
if (intval($obj->timesheet_period)) { if (intval($obj->timesheet_period)) {
$period = new CDate(); $period = new CDate();
$period->setMonth($obj->timesheet_period); $period->setDate($obj->timesheet_period,DATE_FORMAT_UNIXTIME);
} else { } else {
$period = new CDate(); $period = new CDate();
$obj->timesheet_period = $period->getDate();
} }
// Get the current timesheet status // Get the current timesheet status
if (intval($obj->timesheet_status)) if (intval($obj->timesheet_status))
$status = $obj->timesheet_status; $status = $obj->timesheet_status;
else else {
$status = 0; $status = 0;
$obj->timesheet_status = 0;
}
// Get the current timesheet creation date // Get the current timesheet creation date
if (intval($obj->timesheet_date)) { if (intval($obj->timesheet_date)) {
...@@ -169,7 +172,7 @@ if (intval($obj->timesheet_worked)) { ...@@ -169,7 +172,7 @@ if (intval($obj->timesheet_worked)) {
// 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)
echo '<input type="hidden" name="del" value="0" />'; echo '<input type="hidden" name="del" value="0" />';
echo '<input type="hidden" name="stat" value="0" />'; echo '<input type="hidden" name="stat" value="0" />';
echo '<input type="hidden" name="period" value="0" />'; echo '<input type="hidden" name="workperiod" value="0" />';
// 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
// or in case of addition of a new timesheet it will contain '0' as value // or in case of addition of a new timesheet it will contain '0' as value
...@@ -193,7 +196,7 @@ if (intval($obj->timesheet_worked)) { ...@@ -193,7 +196,7 @@ if (intval($obj->timesheet_worked)) {
if ( ($canEdit) && ($status < 1) ) { if ( ($canEdit) && ($status < 1) ) {
?> ?>
<select name="timesheet_period" size="1' class="text" onChange="periodChange();"> <select name="ts_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>
...@@ -209,7 +212,7 @@ if (intval($obj->timesheet_worked)) { ...@@ -209,7 +212,7 @@ if (intval($obj->timesheet_worked)) {
</select> </select>
<?php <?php
// FIXME: FOR SOME STUPID REASON THE FOLLOWING IS NOT EXACTLY THE SAME AS THE ABOVE. ??? // FIXME: FOR SOME STUPID REASON THE FOLLOWING IS NOT EXACTLY THE SAME AS THE ABOVE. ???
// echo '<select name="timesheet_period" size="1" class="text" onChange="periodChange();">'; // echo '<select name="ts_period" size="1" class="text" onChange="periodChange();">';
// echo '<option '; if ($period->getMonth() == 1) echo "selected"; echo 'value="1">' . dPformSafe('January') . '</option>'; // echo '<option '; if ($period->getMonth() == 1) echo "selected"; echo 'value="1">' . dPformSafe('January') . '</option>';
// echo '<option '; if ($period->getMonth() == 2) echo "selected"; echo 'value="2">' . dPformSafe('February') .'</option>'; // echo '<option '; if ($period->getMonth() == 2) echo "selected"; echo 'value="2">' . dPformSafe('February') .'</option>';
// echo '<option '; if ($period->getMonth() == 3) echo "selected"; echo 'value="3">' . dPformSafe('March') . '</option>'; // echo '<option '; if ($period->getMonth() == 3) echo "selected"; echo 'value="3">' . dPformSafe('March') . '</option>';
......
...@@ -30,17 +30,22 @@ if (!$obj->bind( $_POST )) { ...@@ -30,17 +30,22 @@ if (!$obj->bind( $_POST )) {
} }
// detect if a deleete operation has to be processed // detect if a deleete operation has to be processed
$period = dPgetParam($_POST, 'period', 0); $workperiod = dPgetParam($_POST, 'workperiod', 0);
$stat = dPgetParam($_POST, 'stat', 0); $stat = dPgetParam($_POST, 'stat', 0);
$del = dPgetParam($_POST, 'del', 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"];
$obj->timesheet_period = $_POST["timesheet_period"]; $obj->timesheet_period = $_POST["ts_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"];
$obj->timesheet_worked = $_POST["timesheet_worked"]; $obj->timesheet_worked = $_POST["timesheet_worked"];
// sanity checking
if (!intval($obj->timesheet_status)) {
$obj->timesheet_status = 0;
}
$AppUI->setMsg( 'Timesheet' ); $AppUI->setMsg( 'Timesheet' );
if ($del) { if ($del) {
// check if there are dependencies on this object // check if there are dependencies on this object
...@@ -65,7 +70,7 @@ if ($del) { ...@@ -65,7 +70,7 @@ if ($del) {
$AppUI->setMsg( "Timesheet status updated", UI_MSG_ALERT); $AppUI->setMsg( "Timesheet status updated", UI_MSG_ALERT);
$AppUI->redirect( "m=timesheet&a=addedit&timesheet_id=".$obj->timesheet_id ); $AppUI->redirect( "m=timesheet&a=addedit&timesheet_id=".$obj->timesheet_id );
} }
} else if ($period) { } else if ($workperiod) {
if ($msg = $obj->change_period($obj->timesheet_period)) { if ($msg = $obj->change_period($obj->timesheet_period)) {
$AppUI->setMsg( $msg, UI_MSG_ERROR ); $AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect(); $AppUI->redirect();
...@@ -79,7 +84,7 @@ if ($del) { ...@@ -79,7 +84,7 @@ if ($del) {
if (($msg = $obj->store())) { if (($msg = $obj->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR ); $AppUI->setMsg( $msg, UI_MSG_ERROR );
} else { } else {
$isNotNew = $_POST['timesheet_id']; $isNotNew = $obj->timesheet_id; //_POST['timesheet_id'];
$AppUI->setMsg( $isNotNew ? 'Timesheet updated' : 'Timesheet inserted', UI_MSG_OK); $AppUI->setMsg( $isNotNew ? 'Timesheet updated' : 'Timesheet inserted', UI_MSG_OK);
} }
$AppUI->redirect("m=timesheet" ); $AppUI->redirect("m=timesheet" );
......
...@@ -54,6 +54,8 @@ class CTimesheet extends CDpObject { ...@@ -54,6 +54,8 @@ class CTimesheet extends CDpObject {
} }
function check() { function check() {
if (!intval($this->timesheet_status))
$this->timesheet_status=0;
if ( $this->timesheet_id == "0" ) { if ( $this->timesheet_id == "0" ) {
$this->init(); $this->init();
} }
...@@ -64,7 +66,7 @@ class CTimesheet extends CDpObject { ...@@ -64,7 +66,7 @@ class CTimesheet extends CDpObject {
$q = new DBQuery(); $q = new DBQuery();
$q->addTable('timesheet'); $q->addTable('timesheet');
$q->addInsert('timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked', $q->addInsert('timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked',
$_POST['timesheet_period'].','.$_POST['timesheet_status'].','. $this->timesheet_period.','.$_POST['timesheet_status'].','.
$_POST['timesheet_date'].','.$_POST['timesheet_creator'].','. $_POST['timesheet_date'].','.$_POST['timesheet_creator'].','.
$_POST['timesheet_worked'], true); $_POST['timesheet_worked'], true);
$q->exec(); $q->exec();
...@@ -83,9 +85,9 @@ class CTimesheet extends CDpObject { ...@@ -83,9 +85,9 @@ class CTimesheet extends CDpObject {
function project_store() function project_store()
{ {
// Get the current timesheet period // Get the current timesheet period
if (intval($_POST['timesheet_period'])) { if (intval($_POST['ts_period'])) {
$period = new CDate(); $period = new CDate();
$period->setMonth($_POST['timesheet_period']); $period->setMonth($_POST['ts_period']);
} }
else else
$period = new CDate(); $period = new CDate();
...@@ -158,6 +160,8 @@ class CTimesheet extends CDpObject { ...@@ -158,6 +160,8 @@ class CTimesheet extends CDpObject {
} }
} }
else { else {
if (!intval($this->timesheet_status))
$this->timesheet_status=0;
$q = new DBQuery; $q = new DBQuery;
$q->addTable('timesheet'); $q->addTable('timesheet');
$q->addInsert('timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked', $q->addInsert('timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked',
...@@ -174,8 +178,9 @@ class CTimesheet extends CDpObject { ...@@ -174,8 +178,9 @@ class CTimesheet extends CDpObject {
$q = new DBQuery(); $q = new DBQuery();
$q->setDelete('timesheet_project'); $q->setDelete('timesheet_project');
$q->addWhere('timesheet_id = '. $this->timesheet_id ); $q->addWhere('timesheet_id = '. $this->timesheet_id );
$q->exec(); if (!$q->exec()) {
echo db_error(); return db_error();
}
$q->clear(); $q->clear();
$q->setDelete('timesheet'); $q->setDelete('timesheet');
$q->addWhere('timesheet_id = '. $this->timesheet_id ); $q->addWhere('timesheet_id = '. $this->timesheet_id );
...@@ -192,13 +197,12 @@ class CTimesheet extends CDpObject { ...@@ -192,13 +197,12 @@ class CTimesheet extends CDpObject {
$this->_action='updated'; $this->_action='updated';
$q = new DBQuery(); $q = new DBQuery();
$q->addTable('timesheet'); $q->addTable('timesheet');
$q->addUpdate('timesheet_status', $stat); $q->addUpdate('timesheet_status', $this->timesheet_status);
$q->addWhere('timesheet_id = ' . $this->timesheet_id); $q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!$q->exec()) { if (!$q->exec()) {
return db_error(); return db_error();
} }
// Why is this needed ?? // Why is this needed ??
echo $q;
if ($stat>0) { if ($stat>0) {
$this->project_purge(); $this->project_purge();
$this->project_store(); $this->project_store();
......
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