Some more progress with refactoring for subgroups.
[timetracker.git] / expense_edit.php
index 049bc4b..dd4a133 100644 (file)
@@ -29,6 +29,7 @@
 require_once('initialize.php');
 import('form.Form');
 import('ttTeamHelper');
+import('ttGroupHelper');
 import('DateAndTime');
 import('ttExpenseHelper');
 
@@ -43,7 +44,7 @@ if (!$user->isPluginEnabled('ex')) {
 }
 $cl_id = (int)$request->getParameter('id');
 // Get the expense item we are editing.
-$expense_item = ttExpenseHelper::getItem($cl_id, $user->getUser());
+$expense_item = ttExpenseHelper::getItem($cl_id);
 if (!$expense_item || $expense_item['invoice_id']) {
   // Prohibit editing not ours or invoiced items.
   header('Location: access_denied.php');
@@ -51,6 +52,7 @@ if (!$expense_item || $expense_item['invoice_id']) {
 }
 
 $item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']);
+$confirm_save = $user->getConfigOption('confirm_save');
 
 // Initialize variables.
 $cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null;
@@ -76,7 +78,7 @@ $form = new Form('expenseItemForm');
 
 // Dropdown for clients in MODE_TIME. Use all active clients.
 if (MODE_TIME == $user->tracking_mode && $user->isPluginEnabled('cl')) {
-  $active_clients = ttTeamHelper::getActiveClients($user->group_id, true);
+  $active_clients = ttGroupHelper::getActiveClients(true);
   $form->addInput(array('type'=>'combobox',
     'onchange'=>'fillProjectDropdown(this.value);',
     'name'=>'client',
@@ -101,7 +103,7 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t
 
   // Dropdown for clients if the clients plugin is enabled.
   if ($user->isPluginEnabled('cl')) {
-    $active_clients = ttTeamHelper::getActiveClients($user->group_id, true);
+    $active_clients = ttGroupHelper::getActiveClients(true);
     // We need an array of assigned project ids to do some trimming. 
     foreach($project_list as $project)
       $projects_assigned_to_user[] = $project['id'];
@@ -147,8 +149,10 @@ $form->addInput(array('type'=>'datefield','name'=>'date','maxlength'=>'20','valu
 // 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()) {
@@ -220,6 +224,10 @@ 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);