From: anuko Date: Sun, 12 Feb 2017 15:12:40 +0000 (+0000) Subject: Work in progress on predefined expenses. X-Git-Tag: timetracker_1.19-1~1579 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/commitdiff_plain/2df0ec3f98d0fa23102dc8362c4272ddebecf157?ds=inline Work in progress on predefined expenses. --- diff --git a/WEB-INF/lib/ttPredefinedExpenseHelper.class.php b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php new file mode 100644 index 00000000..4c33c427 --- /dev/null +++ b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php @@ -0,0 +1,98 @@ +team_id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + if ($val && $val['id']) + return $val; + } + return false; + } + + // delete - deletes a predefined expense from tt_predefined_expenses table. + static function delete($id) { + global $user; + + $mdb2 = getConnection(); + + $sql = "delete from tt_predefined_expenses where id = $id and team_id = $user->team_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + return true; + } + + // insert function inserts a new predefined expense into database. + static function insert($fields) + { + $mdb2 = getConnection(); + + $team_id = (int) $fields['team_id']; + $name = $fields['name']; + $cost = $fields['cost']; + + $sql = "insert into tt_predefined_expenses (team_id, name, cost) + values ($team_id, ".$mdb2->quote($name).", ".$mdb2->quote($cost).")"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + return true; + } + + // update function - updates a predefined expense in database. + static function update($fields) + { + $mdb2 = getConnection(); + + $predefined_expense_id = (int) $fields['id']; + $team_id = (int) $fields['team_id']; + $name = $fields['name']; + $cost = $fields['cost']; + + $sql = "update tt_predefined_expenses set name = ".$mdb2->quote($name).", cost = ".$mdb2->quote($cost). + " where id = $predefined_expense_id and team_id = $team_id"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } +} diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 0ea9f88b..93f60604 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.9.37.3574 | Copyright © Anuko | +  Anuko Time Tracker 1.9.37.3575 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/predefined_expenses.tpl b/WEB-INF/templates/predefined_expenses.tpl new file mode 100644 index 00000000..a254da39 --- /dev/null +++ b/WEB-INF/templates/predefined_expenses.tpl @@ -0,0 +1,32 @@ +{$forms.predefinedExpensesForm.open} + + + + +
+{if $user->canManageTeam()} + + + + + + + + {if $predefined_expenses} + {foreach $predefined_expenses as $predefined_expense} + + + + + + + {/foreach} + {/if} +
{$i18n.label.thing_name}{$i18n.label.cost}{$i18n.label.edit}{$i18n.label.delete}
{$predefined_expense['name']|escape}{$predefined_expense['cost']|escape}{$i18n.label.edit}{$i18n.label.delete}
+ + + +

{$forms.predefinedExpensesForm.btn_add.control}
+{/if} +
+{$forms.predefinedExpensesForm.close} diff --git a/predefined_expenses.php b/predefined_expenses.php new file mode 100644 index 00000000..4fa6d403 --- /dev/null +++ b/predefined_expenses.php @@ -0,0 +1,56 @@ +isPluginEnabled('ex')) { + header('Location: access_denied.php'); + exit(); +} + +$form = new Form('predefinedExpensesForm'); + +if ($request->isPost()) { + if ($request->getParameter('btn_add')) { + // The Add button clicked. Redirect to predefined_expense_add.php page. + header('Location: predefined_expense_add.php'); + exit(); + } +} else { + $form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->getKey('button.add'))); + $predefinedExpenses = ttTeamHelper::getPredefinedExpenses($user->team_id); +} + +$smarty->assign('forms', array($form->getName()=>$form->toArray())); +$smarty->assign('predefined_expenses', $predefinedExpenses); +$smarty->assign('title', $i18n->getKey('title.predefined_expenses')); +$smarty->assign('content_page_name', 'predefined_expenses.tpl'); +$smarty->display('index.tpl');