X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=week.php;h=fb2dcaa6af1ca72b1d7b6fa9cfc2d4e03ee29bab;hb=7e31ec9db2a079cb231416b8243a8efc52a92ad9;hp=d457837b5d0b80df12e216a7be59ab626b06c10c;hpb=9c4ab146c232549bc5276189be3eb2daf82a3169;p=timetracker.git diff --git a/week.php b/week.php index d457837b..fb2dcaa6 100644 --- a/week.php +++ b/week.php @@ -33,6 +33,7 @@ import('form.Table'); import('form.TextField'); import('ttUserHelper'); import('ttTeamHelper'); +import('ttWeekViewHelper'); import('ttClientHelper'); import('ttTimeHelper'); import('DateAndTime'); @@ -73,7 +74,7 @@ if ($user->isPluginEnabled('cf')) { $smarty->assign('custom_fields', $custom_fields); } -// TODO: how is this plugin supposed to work for week view? +// Use Monthly Quotas plugin, if applicable. if ($user->isPluginEnabled('mq')){ require_once('plugins/MonthlyQuota.class.php'); $quota = new MonthlyQuota(); @@ -106,15 +107,18 @@ $cl_project = $request->getParameter('project', ($request->getMethod()=='POST'? $_SESSION['project'] = $cl_project; $cl_task = $request->getParameter('task', ($request->getMethod()=='POST'? null : @$_SESSION['task'])); $_SESSION['task'] = $cl_task; +$cl_note = trim($request->getParameter('note')); // 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); +$dayHeaders = ttWeekViewHelper::getDayHeadersForWeek($startDate->toString(DB_DATEFORMAT)); +$lockedDays = ttWeekViewHelper::getLockedDaysForWeek($startDate->toString(DB_DATEFORMAT)); +// Get already existing records. +$records = ttWeekViewHelper::getRecordsForInterval($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT)); +// Build data array for the table. Format is described in the function. +$dataArray = ttWeekViewHelper::getDataForWeekView($records, $dayHeaders); // Build day totals (total durations for each day in week). -$dayTotals = ttTimeHelper::getDayTotals($dataArray, $dayHeaders); +$dayTotals = ttWeekViewHelper::getDayTotals($dataArray, $dayHeaders); // Define rendering class for a label field to the left of durations. class LabelCellRenderer extends DefaultCellRenderer { @@ -125,14 +129,13 @@ class LabelCellRenderer extends DefaultCellRenderer { $this->setOptions(array('style'=>'text-align: center; font-weight: bold;')); } // Special handling for not billable entries. - /* // TODO: this does not work and should be coded properly. if ($row > 0) { - $row_id = $table->getValueAt($row,1+$column)['row_id']; - $billable = ttTimeHelper::parseFromWeekViewRow($row_id, 'bl'); + $row_id = $table->getValueAtName($row,'row_id'); + $billable = ttWeekViewHelper::parseFromWeekViewRow($row_id, 'bl'); if (!$billable) { - $this->setOptions(array('class'=>'not_billable')); // TODO: Should not we add options instead? How does it work exactly? + $this->setOptions(array('style'=>'color: red;')); // TODO: style it properly in CSS. } - }*/ + } $this->setValue(htmlspecialchars($value)); // This escapes HTML for output. return $this->toString(); } @@ -148,7 +151,7 @@ class TimeCellRenderer extends DefaultCellRenderer { if ($lockedDays[$column-1]) $field->setEnabled(false); $field->setFormName($table->getFormName()); - $field->setSize(2); + $field->setStyle('width: 60px;'); // TODO: need to style everything properly, eventually. $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. @@ -179,8 +182,7 @@ if ($user->canManageTeam()) { } // Create week_durations table. -$table = new Table('week_durations'); -// $table->setIAScript('markModified'); // TODO: write a script to mark table or particular cells as modified. +$table = new Table('week_durations', 'week_view_table'); $table->setTableOptions(array('width'=>'100%','cellspacing'=>'1','cellpadding'=>'3','border'=>'0')); $table->setRowOptions(array('class'=>'tableHeaderCentered')); $table->setData($dataArray); @@ -257,6 +259,7 @@ if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) { 'datakeys'=>array('id','name'), 'empty'=>array(''=>$i18n->getKey('dropdown.select')))); } +$form->addInput(array('type'=>'textarea','name'=>'note','style'=>'width: 250px; height:'.NOTE_INPUT_HEIGHT.'px;','value'=>$cl_note)); // Add other controls. $form->addInput(array('type'=>'calendar','name'=>'date','value'=>$cl_date)); // calendar @@ -309,8 +312,8 @@ if ($request->isPost()) { // Process the table of values. if ($err->no()) { - // 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. + // Obtain values. Iterate through posted parameters one by one, + // see if value changed, apply one change at a time until we see an error. $result = true; $rowNumber = 0; // Iterate through existing rows. @@ -345,20 +348,24 @@ if ($request->isPost()) { $fields = array(); $fields['row_id'] = $dataArray[$rowNumber]['row_id']; if (!$fields['row_id']) { - // Special handling for row 0, a new entry. Need to construct row_id. + // Special handling for row 0, a new entry. Need to construct new row_id. $record = array(); $record['client_id'] = $cl_client; $record['billable'] = $cl_billable ? '1' : '0'; $record['project_id'] = $cl_project; $record['task_id'] = $cl_task; $record['cf_1_value'] = $cl_cf_1; - $fields['row_id'] = ttTimeHelper::makeRecordIdentifier($record).'_0'; + $fields['row_id'] = ttWeekViewHelper::makeRowIdentifier($record).'_0'; + // Note: no need to check for a possible conflict with an already existing row + // because we are doing an insert that does not affect already existing data. + + $fields['note'] = $cl_note; } $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, $custom_fields, $err); + $result = ttWeekViewHelper::insertDurationFromWeekView($fields, $custom_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()); @@ -366,7 +373,7 @@ if ($request->isPost()) { $fields = array(); $fields['tt_log_id'] = $dataArray[$rowNumber][$dayHeader]['tt_log_id']; $fields['duration'] = $postedDuration; - $result = ttTimeHelper::modifyDurationFromWeekView($fields, $err); + $result = ttWeekViewHelper::modifyDurationFromWeekView($fields, $err); } if (!$result) break; // Break out of the loop in case of first error. } @@ -405,6 +412,7 @@ $smarty->assign('task_list', $task_list); $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('onload', 'onLoad="fillDropdowns()"'); $smarty->assign('timestring', $startDate->toString($user->date_format).' - '.$endDate->toString($user->date_format)); +$smarty->assign('time_records', $records); $smarty->assign('title', $i18n->getKey('title.time')); $smarty->assign('content_page_name', 'week.tpl');