X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/7e9b290b40c6f9f2efe6a7e28fae630bdffeca1e..88134e6891875e698d71e06806e9c0ddde5c03bd:/week.php diff --git a/week.php b/week.php index fa791504..34efd56e 100644 --- a/week.php +++ b/week.php @@ -109,6 +109,7 @@ $_SESSION['task'] = $cl_task; // Get the data we need to display week view. // Get column headers, which are day numbers in month. $dayHeaders = ttTimeHelper::getDayHeadersForWeek($startDate->toString(DB_DATEFORMAT)); +$lockedDays = ttTimeHelper::getLockedDaysForWeek($startDate->toString(DB_DATEFORMAT)); // Build data array for the table. Format is described in the function.. $dataArray = ttTimeHelper::getDataForWeekView($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT), $dayHeaders); // Build day totals (total durations for each day in week). @@ -116,9 +117,10 @@ $dayTotals = ttTimeHelper::getDayTotals($dataArray, $dayHeaders); // TODO: refactoring ongoing down from here. -// 1) Start coding modification of existing records. -// 2) Then adding new records for existing rows. -// 3) Then add code and UI for adding a new row. +// 1) Handle editable - not editable records properly meaning that UI should reflect this. +// 2) Start coding modification of existing records. +// 3) Then adding new records for existing rows. +// 4) Then add code and UI for adding a new row. // Actually this is work in progress at this point, even documenting the array, as we still miss control IDs, and // editing entries is not yet implemented. When this is done, we will have to re-document the above. @@ -137,9 +139,19 @@ class TimeCellRenderer extends DefaultCellRenderer { function render(&$table, $value, $row, $column, $selected = false) { $field_name = $table->getValueAt($row,$column)['control_id']; // Our text field names (and ids) are like x_y (row_column). $field = new TextField($field_name); + // Disable control if the date is locked. + global $lockedDays; + if ($lockedDays[$column-1]) + $field->setEnabled(false); $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(); } @@ -260,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. @@ -276,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')); @@ -340,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( @@ -397,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()) {