return ($this->behalfGroup ? $this->behalfGroup->config : $this->config);
}
+ // getConfirmSave returns confirm_save option for user.
+ function getConfirmSave() {
+ return true; // TODO: implement this properly.
+ // return ($this->behalfGroup ? $this->behalfGroup->config : $this->config);
+ }
+
// can - determines whether user has a right to do something.
function can($do_something) {
return in_array($do_something, $this->rights);
idx++;
{/foreach}
-// TODO: improve on conditional confirmSave.
-// Existing entry date for confirm save warnings.
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
var original_date = "{$entry_date}";
function confirmSave() {
return confirm("{$i18n.warn.confirm_save}");
}
}
-// TODO: improve on conditional confirmSave above.
+{/if}
// The fillProjectDropdown function populates the project combo box with
// projects associated with a selected client (client id is passed here as id).
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.28.4551 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.28.4552 | 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>
idx++;
{/foreach}
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
+var original_date = "{$entry_date}";
+
+function confirmSave() {
+ var date_on_save = document.getElementById("date").value;
+ if (original_date != date_on_save) {
+ return confirm("{$i18n.warn.confirm_save}");
+ }
+}
+{/if}
+
// The fillProjectDropdown function populates the project combo box with
// projects associated with a selected client (client id is passed here as id).
function fillProjectDropdown(id) {
{include file="time_script.tpl"}
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
+<script>
+var original_date = "{$entry_date}";
+
+function confirmSave() {
+ var date_on_save = document.getElementById("date").value;
+ if (original_date != date_on_save) {
+ return confirm("{$i18n.warn.confirm_save}");
+ }
+}
+</script>
+{/if}
+
{$forms.timeRecordForm.open}
<table cellspacing="4" cellpadding="7" border="0">
<tr>
<tr><td>{$forms.timeRecordForm.date.control}</td></tr>
<tr><td>{$i18n.label.note}:</td></tr>
<tr><td>{$forms.timeRecordForm.note.control}</td></tr>
- <tr><td align="center">{$forms.timeRecordForm.btn_save.control} {$forms.timeRecordForm.btn_delete.control}</td></tr>
+ <tr><td align="center">{$forms.timeRecordForm.btn_save.control} {$forms.timeRecordForm.btn_copy.control} {$forms.timeRecordForm.btn_delete.control}</td></tr>
</table>
</td>
</tr>
{include file="time_script.tpl"}
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
<script>
-// TODO: improve on conditional confirmSave.
-// Existing entry date for confirm save warnings.
var original_date = "{$entry_date}";
function confirmSave() {
return confirm("{$i18n.warn.confirm_save}");
}
}
-// TODO: improve on conditional confirmSave above.
</script>
+{/if}
{$forms.timeRecordForm.open}
<table cellspacing="4" cellpadding="7" border="0">
}
$item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']);
+$confirm_save = $user->getConfirmSave();
// Initialize variables.
$cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null;
// Hidden control for record id.
$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
$form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
-// TODO: improve on conditional confirmSave.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date();return(confirmSave())','value'=>$i18n->get('button.save')));
-$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
if ($request->isPost()) {
}
} // isPost
-// TODO: improve on conditional confirmSave.
-$smarty->assign('entry_date', $cl_date);
-
+if ($confirm_save) {
+ $smarty->assign('confirm_save', true);
+ $smarty->assign('entry_date', $cl_date);
+}
$smarty->assign('predefined_expenses', $predefined_expenses);
$smarty->assign('client_list', $client_list);
$smarty->assign('project_list', $project_list);
}
$item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']);
+$confirm_save = $user->getConfirmSave();
// Initialize variables.
$cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null;
// Hidden control for record id.
$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
$form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.save')));
-$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
if ($request->isPost()) {
}
} // isPost
+if ($confirm_save) {
+ $smarty->assign('confirm_save', true);
+ $smarty->assign('entry_date', $cl_date);
+}
$smarty->assign('predefined_expenses', $predefined_expenses);
$smarty->assign('client_list', $client_list);
$smarty->assign('project_list', $project_list);
}
$item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']);
+$confirm_save = $user->getConfirmSave();
// Initialize variables.
$cl_start = $cl_finish = $cl_duration = $cl_date = $cl_note = $cl_project = $cl_task = $cl_billable = null;
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_save click.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.save')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
if ($request->isPost()) {
}
}
+ // Save as new record.
+ if ($request->getParameter('btn_copy')) {
+ // We need to:
+ // 1) Prohibit saving into locked range.
+ // 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists.
+
+ // Now, step by step.
+ if ($err->no()) {
+ // 1) Prohibit saving into locked range.
+ if ($user->isDateLocked($new_date))
+ $err->add($i18n->get('error.range_locked'));
+
+ // 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists.
+ $uncompleted = ($cl_finish == '' && $cl_duration == '');
+ if ($uncompleted) {
+ $not_completed_rec = ttTimeHelper::getUncompleted($user_id);
+ if ($not_completed_rec) {
+ // We have another not completed record.
+ $err->add($i18n->get('error.uncompleted_exists')." <a href = 'time_edit.php?id=".$not_completed_rec['id']."'>".$i18n->get('error.goto_uncompleted')."</a>");
+ }
+ }
+ }
+
+ // Prohibit creating an overlapping record.
+ if ($err->no()) {
+ if (ttTimeHelper::overlaps($user_id, $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish))
+ $err->add($i18n->get('error.overlap'));
+ }
+
+ // Now, a new insert.
+ if ($err->no()) {
+
+ $id = ttTimeHelper::insert(array(
+ 'date'=>$new_date->toString(DB_DATEFORMAT),
+ 'user_id'=>$user_id,
+ 'group_id'=>$user->getGroup(),
+ 'org_id' => $user->org_id,
+ 'client'=>$cl_client,
+ 'project'=>$cl_project,
+ 'task'=>$cl_task,
+ 'start'=>$cl_start,
+ 'finish'=>$cl_finish,
+ 'duration'=>$cl_duration,
+ 'note'=>$cl_note,
+ 'billable'=>$cl_billable,
+ 'paid'=>$cl_paid));
+
+ // Insert a custom field if we have it.
+ $res = true;
+ if ($id && $custom_fields && $cl_cf_1) {
+ if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT)
+ $res = $custom_fields->insert($id, $custom_fields->fields[0]['id'], null, $cl_cf_1);
+ elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)
+ $res = $custom_fields->insert($id, $custom_fields->fields[0]['id'], $cl_cf_1, null);
+ }
+ if ($id && $res) {
+ header('Location: time.php?date='.$new_date->toString(DB_DATEFORMAT));
+ exit();
+ }
+ $err->add($i18n->get('error.db'));
+ }
+ }
+
if ($request->getParameter('btn_delete')) {
header("Location: time_delete.php?id=$cl_id");
exit();
}
} // isPost
+if ($confirm_save) {
+ $smarty->assign('confirm_save', true);
+ $smarty->assign('entry_date', $cl_date);
+}
$smarty->assign('client_list', $client_list);
$smarty->assign('project_list', $project_list);
$smarty->assign('task_list', $task_list);
}
$item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']);
+$confirm_save = $user->getConfirmSave();
// Initialize variables.
$cl_start = $cl_finish = $cl_duration = $cl_date = $cl_note = $cl_project = $cl_task = $cl_billable = null;
if ($user->can('manage_invoices') && $user->isPluginEnabled('ps'))
$form->addInput(array('type'=>'checkbox','name'=>'paid','value'=>$cl_paid));
$form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
-// TODO: improve on conditional confirmSave.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date();return(confirmSave())','value'=>$i18n->get('button.save')));
-$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
if ($request->isPost()) {
}
} // isPost
-// TODO: improve on conditional confirmSave.
-$smarty->assign('entry_date', $cl_date);
-
+if ($confirm_save) {
+ $smarty->assign('confirm_save', true);
+ $smarty->assign('entry_date', $cl_date);
+}
$smarty->assign('client_list', $client_list);
$smarty->assign('project_list', $project_list);
$smarty->assign('task_list', $task_list);