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();
}
function periodChange() {
var f=document.editFrm;
f.period.value='1';
var f=document.editFrm;
f.workperiod.value='1';
f.submit();
}
......@@ -130,16 +130,19 @@ $q->Clear();
// Get the current timesheet period
if (intval($obj->timesheet_period)) {
$period = new CDate();
$period->setMonth($obj->timesheet_period);
$period->setDate($obj->timesheet_period,DATE_FORMAT_UNIXTIME);
} else {
$period = new CDate();
$obj->timesheet_period = $period->getDate();
}
// Get the current timesheet status
if (intval($obj->timesheet_status))
$status = $obj->timesheet_status;
else
else {
$status = 0;
$obj->timesheet_status = 0;
}
// Get the current timesheet creation date
if (intval($obj->timesheet_date)) {
......@@ -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)
echo '<input type="hidden" name="del" 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
// or in case of addition of a new timesheet it will contain '0' as value
......@@ -193,7 +196,7 @@ if (intval($obj->timesheet_worked)) {
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() == 2) echo "selected"; ?> value="2"><? echo dPformSafe('February'); ?></option>
<option <?php if ($period->getMonth() == 3) echo "selected"; ?> value="3"><? echo dPformSafe('March'); ?></option>
......@@ -209,7 +212,7 @@ if (intval($obj->timesheet_worked)) {
</select>
<?php
// 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() == 2) echo "selected"; echo 'value="2">' . dPformSafe('February') .'</option>';
// echo '<option '; if ($period->getMonth() == 3) echo "selected"; echo 'value="3">' . dPformSafe('March') . '</option>';
......
......@@ -30,17 +30,22 @@ if (!$obj->bind( $_POST )) {
}
// detect if a deleete operation has to be processed
$period = dPgetParam($_POST, 'period', 0);
$workperiod = dPgetParam($_POST, 'workperiod', 0);
$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_period = $_POST["ts_period"];
$obj->timesheet_date = $_POST["timesheet_date"];
$obj->timesheet_creator = $_POST["timesheet_creator"];
$obj->timesheet_worked = $_POST["timesheet_worked"];
// sanity checking
if (!intval($obj->timesheet_status)) {
$obj->timesheet_status = 0;
}
$AppUI->setMsg( 'Timesheet' );
if ($del) {
// check if there are dependencies on this object
......@@ -65,7 +70,7 @@ if ($del) {
$AppUI->setMsg( "Timesheet status updated", UI_MSG_ALERT);
$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)) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
......@@ -79,7 +84,7 @@ if ($del) {
if (($msg = $obj->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$isNotNew = $_POST['timesheet_id'];
$isNotNew = $obj->timesheet_id; //_POST['timesheet_id'];
$AppUI->setMsg( $isNotNew ? 'Timesheet updated' : 'Timesheet inserted', UI_MSG_OK);
}
$AppUI->redirect("m=timesheet" );
......
......@@ -54,6 +54,8 @@ class CTimesheet extends CDpObject {
}
function check() {
if (!intval($this->timesheet_status))
$this->timesheet_status=0;
if ( $this->timesheet_id == "0" ) {
$this->init();
}
......@@ -64,7 +66,7 @@ class CTimesheet extends CDpObject {
$q = new DBQuery();
$q->addTable('timesheet');
$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_worked'], true);
$q->exec();
......@@ -83,9 +85,9 @@ class CTimesheet extends CDpObject {
function project_store()
{
// Get the current timesheet period
if (intval($_POST['timesheet_period'])) {
if (intval($_POST['ts_period'])) {
$period = new CDate();
$period->setMonth($_POST['timesheet_period']);
$period->setMonth($_POST['ts_period']);
}
else
$period = new CDate();
......@@ -158,6 +160,8 @@ class CTimesheet extends CDpObject {
}
}
else {
if (!intval($this->timesheet_status))
$this->timesheet_status=0;
$q = new DBQuery;
$q->addTable('timesheet');
$q->addInsert('timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked',
......@@ -174,8 +178,9 @@ class CTimesheet extends CDpObject {
$q = new DBQuery();
$q->setDelete('timesheet_project');
$q->addWhere('timesheet_id = '. $this->timesheet_id );
$q->exec();
echo db_error();
if (!$q->exec()) {
return db_error();
}
$q->clear();
$q->setDelete('timesheet');
$q->addWhere('timesheet_id = '. $this->timesheet_id );
......@@ -192,13 +197,12 @@ class CTimesheet extends CDpObject {
$this->_action='updated';
$q = new DBQuery();
$q->addTable('timesheet');
$q->addUpdate('timesheet_status', $stat);
$q->addUpdate('timesheet_status', $this->timesheet_status);
$q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!$q->exec()) {
return db_error();
}
// Why is this needed ??
echo $q;
if ($stat>0) {
$this->project_purge();
$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