$form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
$form->addInput(array('type'=>'checkboxgroup','name'=>'projects','layout'=>'H','data'=>$projects,'datakeys'=>array('id','name'),'value'=>$cl_projects));
$form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.add')));
-
+
if ($request->getMethod() == 'POST') {
// Validate user input.
if (!ttValidString($cl_name)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.thing_name'));
if (!ttValidString($cl_description, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.description'));
if ($errors->isEmpty()) {
- if (!ttTaskHelper::getTaskByName($cl_name)) {
+ if (!ttTaskHelper::getTaskByName($cl_name)) {
if (ttTaskHelper::insert(array(
'team_id' => $user->team_id,
'name' => $cl_name,
$errors->add($i18n->getKey('error.db'));
} else
$errors->add($i18n->getKey('error.task_exists'));
- }
-} // post
+ }
+} // POST
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('onload', 'onLoad="document.taskForm.name.focus()"');
header('Location: tasks.php');
exit();
}
-} // post
+} // POST
$smarty->assign('task_to_delete', $task_to_delete);
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$cl_task_id = (int)$request->getParameter('id');
$projects = ttTeamHelper::getActiveProjects($user->team_id);
-
+
if ($request->getMethod() == 'POST') {
$cl_name = trim($request->getParameter('name'));
$cl_description = trim($request->getParameter('description'));
$cl_name = $task['name'];
$cl_description = $task['description'];
$cl_status = $task['status'];
-
+
$assigned_projects = ttTaskHelper::getAssignedProjects($cl_task_id);
foreach ($assigned_projects as $project_item)
$cl_projects[] = $project_item['id'];
$form->addInput(array('type'=>'checkboxgroup','name'=>'projects','layout'=>'H','data'=>$projects,'datakeys'=>array('id','name'),'value'=>$cl_projects));
$form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save')));
$form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->getKey('button.copy')));
-
+
if ($request->getMethod() == 'POST') {
// Validate user input.
if (!ttValidString($cl_name)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.thing_name'));
if (!ttValidString($cl_description, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.description'));
if ($errors->isEmpty()) {
- if ($request->getParameter('btn_save')) {
+ if ($request->getParameter('btn_save')) {
$existing_task = ttTaskHelper::getTaskByName($cl_name);
if (!$existing_task || ($cl_task_id == $existing_task['id'])) {
// Update task information.
$errors->add($i18n->getKey('error.db'));
} else
$errors->add($i18n->getKey('error.task_exists'));
- }
-
+ }
+
if ($request->getParameter('btn_copy')) {
if (!ttTaskHelper::getTaskByName($cl_name)) {
if (ttTaskHelper::insert(array(
} else
$errors->add($i18n->getKey('error.task_exists'));
}
- }
-} // post
+ }
+} // POST
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('title', $i18n->getKey('title.edit_task'));
'style'=>'width: 250px;',
'value'=>$on_behalf_id,
'data'=>$user_list,
- 'datakeys'=>array('id','name'),
- ));
+ 'datakeys'=>array('id','name')));
$smarty->assign('on_behalf_control', 1);
}
}
// Dropdown for clients in MODE_TIME. Use all active clients.
if (MODE_TIME == $user->tracking_mode && in_array('cl', explode(',', $user->plugins))) {
- $active_clients = ttTeamHelper::getActiveClients($user->team_id, true);
- $form->addInput(array('type'=>'combobox',
- 'onchange'=>'fillProjectDropdown(this.value);',
- 'name'=>'client',
- 'style'=>'width: 250px;',
- 'value'=>$cl_client,
- 'data'=>$active_clients,
- 'datakeys'=>array('id', 'name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ $active_clients = ttTeamHelper::getActiveClients($user->team_id, true);
+ $form->addInput(array('type'=>'combobox',
+ 'onchange'=>'fillProjectDropdown(this.value);',
+ 'name'=>'client',
+ 'style'=>'width: 250px;',
+ 'value'=>$cl_client,
+ 'data'=>$active_clients,
+ 'datakeys'=>array('id', 'name'),
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
// Note: in other modes the client list is filtered to relevant clients only. See below.
}
'value'=>$cl_project,
'data'=>$project_list,
'datakeys'=>array('id','name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
// Dropdown for clients if the clients plugin is enabled.
if (in_array('cl', explode(',', $user->plugins))) {
'value'=>$cl_client,
'data'=>$client_list,
'datakeys'=>array('id', 'name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
}
}
'value'=>$cl_task,
'data'=>$task_list,
'datakeys'=>array('id','name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
}
// Add other controls.
if (!$user->canManageTeam() && defined('READONLY_START_FINISH') && isTrue(READONLY_START_FINISH)) {
// Make the start and finish fields read-only.
$form->getElement('start')->setEnable(false);
- $form->getElement('finish')->setEnable(false);
+ $form->getElement('finish')->setEnable(false);
}
if ((TYPE_DURATION == $user->record_type) || (TYPE_ALL == $user->record_type))
$form->addInput(array('type'=>'text','name'=>'duration','value'=>$cl_duration,'onchange'=>"formDisable('duration');"));
$form->addInput(array('type'=>'checkbox','name'=>'billable','data'=>1,'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'=>'submit','name'=>'btn_submit','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.submit')));
-
+
// If we have custom fields - add controls for them.
if ($custom_fields && $custom_fields->fields[0]) {
// Only one custom field is supported at this time.
if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT) {
- $form->addInput(array('type'=>'text','name'=>'cf_1','value'=>$cl_cf_1));
+ $form->addInput(array('type'=>'text','name'=>'cf_1','value'=>$cl_cf_1));
} else if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN) {
$form->addInput(array('type'=>'combobox','name'=>'cf_1',
'style'=>'width: 250px;',
'value'=>$cl_cf_1,
'data'=>$custom_fields->options,
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
}
}
-// Determine lock date. Time entries earlier than lock date cannot be created or modified.
+// Determine lock date. Time entries earlier than lock date cannot be created or modified.
$lock_interval = $user->lock_interval;
$lockdate = 0;
if ($lock_interval > 0) {
// Submit.
if ($request->getMethod() == 'POST') {
if ($request->getParameter('btn_submit')) {
-
+
// Validate user input.
if (in_array('cl', explode(',', $user->plugins)) && in_array('cm', explode(',', $user->plugins)) && !$cl_client)
$errors->add($i18n->getKey('error.client'));
if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $errors->add($i18n->getKey('error.field'), $custom_fields->fields[0]['label']);
}
if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode) {
- if (!$cl_project) $errors->add($i18n->getKey('error.project'));
+ if (!$cl_project) $errors->add($i18n->getKey('error.project'));
}
if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) {
if (!$cl_task) $errors->add($i18n->getKey('error.task'));
- }
+ }
if (!$cl_duration) {
if ('0' == $cl_duration)
$errors->add($i18n->getKey('error.field'), $i18n->getKey('label.duration'));
$errors->add($i18n->getKey('error.interval'), $i18n->getKey('label.finish'), $i18n->getKey('label.start'));
}
} else {
- if ((TYPE_START_FINISH == $user->record_type) || (TYPE_ALL == $user->record_type)) {
+ if ((TYPE_START_FINISH == $user->record_type) || (TYPE_ALL == $user->record_type)) {
$errors->add($i18n->getKey('error.empty'), $i18n->getKey('label.start'));
$errors->add($i18n->getKey('error.empty'), $i18n->getKey('label.finish'));
- }
+ }
if ((TYPE_DURATION == $user->record_type) || (TYPE_ALL == $user->record_type))
$errors->add($i18n->getKey('error.empty'), $i18n->getKey('label.duration'));
}
if ($selected_date->after($browser_today))
$errors->add($i18n->getKey('error.future_date'));
}
-
+
// Prohibit creating time entries in locked interval.
if($lockdate && $selected_date->before($lockdate))
$errors->add($i18n->getKey('error.period_locked'));
-
+
// Prohibit creating another uncompleted record.
if ($errors->isEmpty()) {
if (($not_completed_rec = ttTimeHelper::getUncompleted($user->getActiveUser())) && (($cl_finish == '') && ($cl_duration == '')))
$errors->add($i18n->getKey('error.uncompleted_exists')." <a href = 'time_edit.php?id=".$not_completed_rec['id']."'>".$i18n->getKey('error.goto_uncompleted')."</a>");
}
-
+
// Prohibit creating an overlapping record.
if ($errors->isEmpty()) {
if (ttTimeHelper::overlaps($user->getActiveUser(), $cl_date, $cl_start, $cl_finish))
$errors->add($i18n->getKey('error.overlap'));
- }
+ }
// Insert record.
if ($errors->isEmpty()) {
'duration' => $cl_duration,
'note' => $cl_note,
'billable' => $cl_billable));
-
+
// Insert a custom field if we have it.
$result = true;
if ($id && $custom_fields && $cl_cf_1) {
}
}
else if ($request->getParameter('btn_stop')) {
- // Stop button pressed to finish an uncompleted record.
- $record_id = $request->getParameter('record_id');
- $record = ttTimeHelper::getRecord($record_id, $user->getActiveUser());
- $browser_date = $request->getParameter('browser_date');
- $browser_time = $request->getParameter('browser_time');
-
- // Can we complete this record?
- if ($record['date'] == $browser_date // closing today's record
- && ttTimeHelper::isValidInterval($record['start'], $browser_time) // finish time is greater than start time
- && !ttTimeHelper::overlaps($user->getActiveUser(), $browser_date, $record['start'], $browser_time)) { // no overlap
+ // Stop button pressed to finish an uncompleted record.
+ $record_id = $request->getParameter('record_id');
+ $record = ttTimeHelper::getRecord($record_id, $user->getActiveUser());
+ $browser_date = $request->getParameter('browser_date');
+ $browser_time = $request->getParameter('browser_time');
+
+ // Can we complete this record?
+ if ($record['date'] == $browser_date // closing today's record
+ && ttTimeHelper::isValidInterval($record['start'], $browser_time) // finish time is greater than start time
+ && !ttTimeHelper::overlaps($user->getActiveUser(), $browser_date, $record['start'], $browser_time)) { // no overlap
$res = ttTimeHelper::update(array(
- 'id'=>$record['id'],
- 'date'=>$record['date'],
+ 'id'=>$record['id'],
+ 'date'=>$record['date'],
'user_id'=>$user->getActiveUser(),
- 'client'=>$record['client_id'],
- 'project'=>$record['project_id'],
- 'task'=>$record['task_id'],
- 'start'=>$record['start'],
+ 'client'=>$record['client_id'],
+ 'project'=>$record['project_id'],
+ 'task'=>$record['task_id'],
+ 'start'=>$record['start'],
'finish'=>$browser_time,
'note'=>$record['comment'],
'billable'=>$record['billable']));
if (!$res)
$errors->add($i18n->getKey('error.db'));
- } else {
+ } else {
// Cannot complete, redirect for manual edit.
header('Location: time_edit.php?id='.$record_id);
- exit();
- }
+ exit();
+ }
}
else if ($request->getParameter('onBehalfUser')) {
if($user->canManageTeam()) {
unset($_SESSION['behalf_id']);
unset($_SESSION['behalf_name']);
-
+
if($on_behalf_id != $user->id) {
$_SESSION['behalf_id'] = $on_behalf_id;
- $_SESSION['behalf_name'] = ttUserHelper::getUserName($on_behalf_id);
+ $_SESSION['behalf_name'] = ttUserHelper::getUserName($on_behalf_id);
}
header('Location: time.php');
exit();
}
}
-}
+} // POST
$week_total = ttTimeHelper::getTimeForWeek($user->getActiveUser(), $selected_date);
// Prohibit deleting invoiced records.
if ($time_rec['invoice_id']) die($i18n->getKey('error.sys'));
-
+
// Escape comment for presentation.
$time_rec['comment'] = htmlspecialchars($time_rec['comment']);
-
+
if ($request->getMethod() == 'POST') {
if ($request->getParameter('delete_button')) { // Delete button pressed.
-
+
// Determine if it's okay to delete the record.
$item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']);
// Determine lock date.
}
// Determine if the record is uncompleted.
$uncompleted = ($time_rec['duration'] == '0:00');
-
+
if($lockdate && $item_date->before($lockdate) && !$uncompleted) {
$errors->add($i18n->getKey('error.period_locked'));
}
-
+
if ($errors->isEmpty()) {
-
+
// Delete the record.
$result = ttTimeHelper::delete($cl_id, $user->getActiveUser());
}
}
if ($request->getParameter('cancel_button')) { // Cancel button pressed.
- header('Location: time.php');
- exit();
+ header('Location: time.php');
+ exit();
}
-}
-
+} // POST
+
$form = new Form('timeRecordForm');
$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
$form->addInput(array('type'=>'submit','name'=>'delete_button','value'=>$i18n->getKey('label.delete')));
if ($time_rec['invoice_id']) die($i18n->getKey('error.sys'));
$item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']);
-
+
// Initialize variables.
$cl_start = $cl_finish = $cl_duration = $cl_date = $cl_note = $cl_project = $cl_task = $cl_billable = null;
if ($request->getMethod() == 'POST') {
$cl_start = $time_rec['start'];
$cl_finish = $time_rec['finish'];
$cl_duration = $time_rec['duration'];
- $cl_date = $item_date->toString($user->date_format);
+ $cl_date = $item_date->toString($user->date_format);
$cl_note = $time_rec['comment'];
-
+
// If we have custom fields - obtain values for them.
if ($custom_fields) {
// Get custom field value for time record.
- $fields = $custom_fields->get($time_rec['id']);
- if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT)
+ $fields = $custom_fields->get($time_rec['id']);
+ if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT)
$cl_cf_1 = $fields[0]['value'];
else if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)
$cl_cf_1 = $fields[0]['option_id'];
}
-
+
$cl_billable = $time_rec['billable'];
-
+
// Add an info message to the form if we are editing an uncompleted record.
if (($cl_start == $cl_finish) && ($cl_duration == '0:00')) {
$cl_finish = '';
$messages->add($i18n->getKey('form.time_edit.uncompleted'));
}
}
-
+
// Initialize elements of 'timeRecordForm'.
$form = new Form('timeRecordForm');
// Dropdown for clients in MODE_TIME. Use all active clients.
if (MODE_TIME == $user->tracking_mode && in_array('cl', explode(',', $user->plugins))) {
- $active_clients = ttTeamHelper::getActiveClients($user->team_id, true);
- $form->addInput(array('type'=>'combobox',
- 'onchange'=>'fillProjectDropdown(this.value);',
- 'name'=>'client',
- 'style'=>'width: 250px;',
- 'value'=>$cl_client,
- 'data'=>$active_clients,
- 'datakeys'=>array('id', 'name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ $active_clients = ttTeamHelper::getActiveClients($user->team_id, true);
+ $form->addInput(array('type'=>'combobox',
+ 'onchange'=>'fillProjectDropdown(this.value);',
+ 'name'=>'client',
+ 'style'=>'width: 250px;',
+ 'value'=>$cl_client,
+ 'data'=>$active_clients,
+ 'datakeys'=>array('id', 'name'),
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
// Note: in other modes the client list is filtered to relevant clients only. See below.
}
'value'=>$cl_project,
'data'=>$project_list,
'datakeys'=>array('id','name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
// Dropdown for clients if the clients plugin is enabled.
if (in_array('cl', explode(',', $user->plugins))) {
$active_clients = ttTeamHelper::getActiveClients($user->team_id, true);
- // We need an array of assigned project ids to do some trimming.
+ // We need an array of assigned project ids to do some trimming.
foreach($project_list as $project)
$projects_assigned_to_user[] = $project['id'];
'value'=>$cl_client,
'data'=>$client_list,
'datakeys'=>array('id', 'name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
}
}
'value'=>$cl_task,
'data'=>$task_list,
'datakeys'=>array('id','name'),
- 'empty'=>array(''=>$i18n->getKey('dropdown.select'))
- ));
+ 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
}
-
+
// Add other controls.
if ((TYPE_START_FINISH == $user->record_type) || (TYPE_ALL == $user->record_type)) {
$form->addInput(array('type'=>'text','name'=>'start','value'=>$cl_start,'onchange'=>"formDisable('start');"));
if (!$user->canManageTeam() && defined('READONLY_START_FINISH') && isTrue(READONLY_START_FINISH)) {
// Make the start and finish fields read-only.
$form->getElement('start')->setEnable(false);
- $form->getElement('finish')->setEnable(false);
+ $form->getElement('finish')->setEnable(false);
}
if ((TYPE_DURATION == $user->record_type) || (TYPE_ALL == $user->record_type))
$form->addInput(array('type'=>'text','name'=>'duration','value'=>$cl_duration,'onchange'=>"formDisable('duration');"));
if ($custom_fields && $custom_fields->fields[0]) {
// Only one custom field is supported at this time.
if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT) {
- $form->addInput(array('type'=>'text','name'=>'cf_1','value'=>$cl_cf_1));
+ $form->addInput(array('type'=>'text','name'=>'cf_1','value'=>$cl_cf_1));
} else if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN) {
$form->addInput(array('type'=>'combobox',
'name'=>'cf_1',
'style'=>'width: 250px;',
'value'=>$cl_cf_1,
'data'=>$custom_fields->options,
- 'empty' => array('' => $i18n->getKey('dropdown.select'))
- ));
+ 'empty' => array('' => $i18n->getKey('dropdown.select'))));
}
}
// Hidden control for record id.
if (!ttValidDate($cl_date)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.date'));
if (!ttValidString($cl_note, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.note'));
// Finished validating user input.
-
+
// Determine lock date.
$lock_interval = $user->lock_interval;
$lockdate = 0;
// 1) Prohibit saving locked time entries in any form.
// 2) Prohibit saving completed unlocked entries into locked interval.
// 3) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists.
-
+
// Now, step by step.
if ($errors->isEmpty()) {
// 1) Prohibit saving locked time entries in any form.
if($lockdate && $item_date->before($lockdate))
- $errors->add($i18n->getKey('error.period_locked'));
+ $errors->add($i18n->getKey('error.period_locked'));
// 2) Prohibit saving completed unlocked entries into locked interval.
if($errors->isEmpty() && $lockdate && $new_date->before($lockdate))
- $errors->add($i18n->getKey('error.period_locked'));
+ $errors->add($i18n->getKey('error.period_locked'));
// 3) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists.
$uncompleted = ($cl_finish == '' && $cl_duration == '');
if ($uncompleted) {
}
}
}
-
+
// Prohibit creating an overlapping record.
if ($errors->isEmpty()) {
if (ttTimeHelper::overlaps($user->getActiveUser(), $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish, $cl_id))
$errors->add($i18n->getKey('error.overlap'));
- }
+ }
// Now, an update.
if ($errors->isEmpty()) {
$res = ttTimeHelper::update(array(
- 'id'=>$cl_id,
- 'date'=>$new_date->toString(DB_DATEFORMAT),
- 'user_id'=>$user->getActiveUser(),
- 'client'=>$cl_client,
- 'project'=>$cl_project,
- 'task'=>$cl_task,
- 'start'=>$cl_start,
- 'finish'=>$cl_finish,
- 'duration'=>$cl_duration,
- 'note'=>$cl_note,
- 'billable'=>$cl_billable));
-
+ 'id'=>$cl_id,
+ 'date'=>$new_date->toString(DB_DATEFORMAT),
+ 'user_id'=>$user->getActiveUser(),
+ 'client'=>$cl_client,
+ 'project'=>$cl_project,
+ 'task'=>$cl_task,
+ 'start'=>$cl_start,
+ 'finish'=>$cl_finish,
+ 'duration'=>$cl_duration,
+ 'note'=>$cl_note,
+ 'billable'=>$cl_billable));
+
// If we have custom fields - update values.
if ($res && $custom_fields) {
if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT)
}
}
}
-
+
// Save as new record.
if ($request->getParameter('btn_copy')) {
// We need to:
// 1) Prohibit saving into locked interval.
// 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists.
-
+
// Now, step by step.
if ($errors->isEmpty()) {
// 1) Prohibit saving into locked interval.
}
}
}
-
+
// Prohibit creating an overlapping record.
if ($errors->isEmpty()) {
if (ttTimeHelper::overlaps($user->getActiveUser(), $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish))
// Now, a new insert.
if ($errors->isEmpty()) {
-
+
$id = ttTimeHelper::insert(array(
'date'=>$new_date->toString(DB_DATEFORMAT),
'user_id'=>$user->getActiveUser(),
$errors->add($i18n->getKey('error.db'));
}
}
-
+
if ($request->getParameter('btn_delete')) {
header("Location: time_delete.php?id=$cl_id");
exit();
}
-} // End of if ($request->getMethod() == "POST")
+} // POST
$smarty->assign('client_list', $client_list);
$smarty->assign('project_list', $project_list);