}
// normalizeDuration - converts a valid time duration string to format 00:00.
- static function normalizeDuration($value) {
+ static function normalizeDuration($value, $leadingZero = true) {
$time_value = $value;
// If we have a decimal format - convert to time format 00:00.
$mins = round($val * 60);
$hours = (string)((int)($mins / 60));
$mins = (string)($mins % 60);
- if (strlen($hours) == 1)
+ if ($leadingZero && strlen($hours) == 1)
$hours = '0'.$hours;
if (strlen($mins) == 1)
$mins = '0' . $mins;
// 0-99
if ((strlen($time_value) >= 1) && (strlen($time_value) <= 2) && !isset($time_a[1])) {
$hours = $time_a[0];
- if (strlen($hours) == 1)
+ if ($leadingZero && strlen($hours) == 1)
$hours = '0'.$hours;
return $hours.':00';
}
if ((strlen($time_value) >= 3) && (strlen($time_value) <= 4) && !isset($time_a[1])) {
if (strlen($time_value)==3) $time_value = '0'.$time_value;
$hours = substr($time_value,0,2);
- if (strlen($hours) == 1)
+ if ($leadingZero && strlen($hours) == 1)
$hours = '0'.$hours;
return $hours.':'.substr($time_value,2,2);
}
// 0:00-23:59 (24:00)
if ((strlen($time_value) >= 4) && (strlen($time_value) <= 5) && isset($time_a[1])) {
$hours = $time_a[0];
- if (strlen($hours) == 1)
+ if ($leadingZero && strlen($hours) == 1)
$hours = '0'.$hours;
return $hours.':'.$time_a[1];
}
}
return $dayTotals;
}
+
+ // insertDurationFromWeekView - inserts a new record in log tables from a week view post.
+ static function insertDurationFromWeekView($fields, $err) {
+ $err->add("Week view is work in progress. Inserting records is not yet implemented. Try again later.");
+ // $row_id, $day_header, $posted_duration, $start_date) { // TODO: potential fields?
+
+ return false; // Not implemented.
+ }
+
+
+ // modifyFromWeekView - modifies a duration of an existing record from a week view post.
+ static function modifyDurationFromWeekView($fields, $err) {
+ $err->add("Week view is work in progress. Editing records is not yet implemented. Try again later.");
+ return false;
+
+ // static function modifyDurationFromWeekView($tt_log_id, $new_duration, $user_id) {
+
+ // TODO: handle overlaps and potential other error conditions such as going beyond 24 hr mark. Other errors?
+ // If the entry has start time, check if new duration goes beyond the existing day.
+
+ // Future entries. Possibly do this check out of this function.
+ /*
+ * // Prohibit creating entries in future.
+ if (defined('FUTURE_ENTRIES') && !isTrue(FUTURE_ENTRIES)) {
+ $browser_today = new DateAndTime(DB_DATEFORMAT, $request->getParameter('browser_today', null));
+ if ($selected_date->after($browser_today))
+ $err->add($i18n->getKey('error.future_date'));
+ }
+ */
+
+ /*
+ * // Prohibit creating an overlapping record.
+ if ($err->no()) {
+ if (ttTimeHelper::overlaps($user->getActiveUser(), $cl_date, $cl_start, $cl_finish))
+ $err->add($i18n->getKey('error.overlap'));
+ }
+ */
+
+ $mdb2 = getConnection();
+
+ $sql = "update tt_log set duration = '$new_duration' where id = $tt_log_id and user_id = $user_id";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ return true;
+ }
}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.13.0.3701| Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.13.0.3702| Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
<td>{$forms.weekTimeForm.week_durations.control}</td>
</tr>
</table>
-<!--
<table>
<tr>
<td align="center" colspan="2">{$forms.weekTimeForm.btn_submit.control}</td>
</tr>
</table>
--->
{$forms.weekTimeForm.close}
'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'));
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();
+ $result = ttTimeHelper::insertDurationFromWeekView($fields, $err);
+ //$dataArray[$rowNumber]['row_id'],
+ //$dayHeader,
+ //$postedDuration,
+ //$startDate->toString(DB_DATEFORMAT));
+ } 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(
// Cannot complete, redirect for manual edit.
header('Location: time_edit.php?id='.$record_id);
exit();
- }
+ }*/
}
elseif ($request->getParameter('onBehalfUser')) {
if($user->canManageTeam()) {