X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/6b4d39a350249fb3f71d49706d242e6d341c2200..88134e6891875e698d71e06806e9c0ddde5c03bd:/week.php diff --git a/week.php b/week.php index 8d3e2ba3..34efd56e 100644 --- a/week.php +++ b/week.php @@ -146,6 +146,12 @@ class TimeCellRenderer extends DefaultCellRenderer { $field->setFormName($table->getFormName()); $field->setSize(2); $field->setValue($table->getValueAt($row,$column)['duration']); + // Disable control when time entry mode is TYPE_START_FINISH and there is no value in control + // because we can't supply start and finish times in week view - there are no fields for them. + global $user; + if (!$field->getValue() && TYPE_START_FINISH == $user->record_type) { + $field->setEnabled(false); + } $this->setValue($field->getHtml()); return $this->toString(); } @@ -266,7 +272,7 @@ $form->addInput(array('type'=>'textarea','name'=>'note','style'=>'width: 600px; $form->addInput(array('type'=>'calendar','name'=>'date','value'=>$cl_date)); // calendar if ($user->isPluginEnabled('iv')) $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable)); -$form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_submit click. +$form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'get_date()')); // User current date, which gets filled in on btn_submit click. $form->addInput(array('type'=>'submit','name'=>'btn_submit','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.submit'))); // If we have custom fields - add controls for them. @@ -282,11 +288,14 @@ if ($custom_fields && $custom_fields->fields[0]) { 'empty'=>array(''=>$i18n->getKey('dropdown.select')))); } } +// TODO: the above needs to be refactored for week view. + + // Submit. if ($request->isPost()) { if ($request->getParameter('btn_submit')) { - +/* // Validate user input. if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) $err->add($i18n->getKey('error.client')); @@ -346,7 +355,68 @@ if ($request->isPost()) { if (ttTimeHelper::overlaps($user->getActiveUser(), $cl_date, $cl_start, $cl_finish)) $err->add($i18n->getKey('error.overlap')); } - +// TODO: refactor the above. +*/ + // Obtain values. Perhaps, it's best to iterate throigh posted parameters one by one, + // see if anything changed, and apply one change at a time until we see an error. + // TODO: check for locked days just in case. + $result = true; + $rowNumber = 0; + // Iterate through existing rows. + foreach ($dataArray as $row) { + // Iterate through days. + foreach ($dayHeaders as $key => $dayHeader) { + // Do not process locked days. + if ($lockedDays[$key]) continue; + // Make control id for the cell. + $control_id = $rowNumber.'_'.$dayHeader; + // Optain existing and posted durations. + $postedDuration = $request->getParameter($control_id); + $existingDuration = $dataArray[$rowNumber][$dayHeader]['duration']; + // If posted value is not null, check and normalize it. + if ($postedDuration) { + if (ttTimeHelper::isValidDuration($postedDuration)) { + $postedDuration = ttTimeHelper::normalizeDuration($postedDuration, false); // No leading zero. + } else { + $err->add($i18n->getKey('error.field'), $i18n->getKey('label.duration')); + $result = false; break; // Break out. Stop any further processing. + } + } + // Do not process if value has not changed. + if ($postedDuration == $existingDuration) + continue; + // Posted value is different. + if ($existingDuration == null) { + // Insert a new record here. + $fields = array(); + $fields['row_id'] = $dataArray[$rowNumber]['row_id']; + $fields['day_header'] = $dayHeader; + $fields['start_date'] = $startDate->toString(DB_DATEFORMAT); // To be able to determine date for the entry using $dayHeader. + $fields['duration'] = $postedDuration; + $fields['browser_today'] = $request->getParameter('browser_today', null); + $result = ttTimeHelper::insertDurationFromWeekView($fields, $err); + } elseif ($postedDuration == null || 0 == ttTimeHelper::toMinutes($postedDuration)) { + // Delete an already existing record here. + $result = ttTimeHelper::delete($dataArray[$rowNumber][$dayHeader]['tt_log_id'], $user->getActiveUser()); + } else { + $fields = array(); + $result = ttTimeHelper::modifyDurationFromWeekView($fields, $err); + //$result = ttTimeHelper::modifyDurationFromWeekView($dataArray[$rowNumber][$dayHeader]['tt_log_id'], $postedDuration, $user->getActiveUser()); + } + if (!$result) break; // Break out of the loop in case of first error. + } + if (!$result) break; // Break out of the loop in case of first error. + $rowNumber++; + } + if ($result) { + header('Location: week.php'); // Normal exit. + exit(); + } + $err->add($i18n->getKey('error.db')); + /* + // + // + // // Insert record. if ($err->no()) { $id = ttTimeHelper::insert(array( @@ -403,7 +473,7 @@ if ($request->isPost()) { // Cannot complete, redirect for manual edit. header('Location: time_edit.php?id='.$record_id); exit(); - } + }*/ } elseif ($request->getParameter('onBehalfUser')) { if($user->canManageTeam()) {