forked from anuko/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
invoices.php
94 lines (80 loc) · 3.53 KB
/
invoices.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/* Copyright (c) Anuko International Ltd. https://www.anuko.com
License: See license.txt */
require_once('initialize.php');
import('form.Form');
import('ttGroupHelper');
// Access checks.
if (!(ttAccessAllowed('manage_invoices') || ttAccessAllowed('view_client_invoices'))) {
header('Location: access_denied.php');
exit();
}
if (!$user->isPluginEnabled('iv')) {
header('Location: feature_disabled.php');
exit();
}
// End of access checks.
$sort_option_1 = $sort_order_1 = $sort_option_2 = $sort_order_2 = null;
if ($request->isPost()) {
$sort_option_1 = $request->getParameter('sort_option_1');
$sort_order_1 = $request->getParameter('sort_order_1');
$sort_option_2 = $request->getParameter('sort_option_2');
$sort_order_2 = $request->getParameter('sort_order_2');
}
$invoices = ttGroupHelper::getActiveInvoices();
$form = new Form('invoicesForm');
// Prepare an array of sort options.
$sort_options['name'] = $i18n->get('label.invoice');
$sort_options['client'] = $i18n->get('label.client');
$sort_options['date'] = $i18n->get('label.date');
$form->addInput(array('type'=>'combobox',
'name'=>'sort_option_1',
'class'=>'dropdown-field-with-button',
'onchange'=>'this.form.sorting_changed.value=1;this.form.submit();',
'data'=>$sort_options,
'value'=>$sort_option_1));
$form->addInput(array('type'=>'combobox',
'name'=>'sort_option_2',
'class'=>'dropdown-field-with-button',
'onchange'=>'this.form.sorting_changed.value=1;this.form.submit();',
'data'=>$sort_options,
'value'=>$sort_option_2,
'empty'=>array(''=>$i18n->get('dropdown.no'))));
// Prepare an array of sort order.
$sort_order['ascending'] = $i18n->get('dropdown.ascending');
$sort_order['descending'] = $i18n->get('dropdown.descending');
$form->addInput(array('type'=>'combobox',
'name'=>'sort_order_1',
'class'=>'dropdown-field-with-button',
'onchange'=>'this.form.sorting_changed.value=1;this.form.submit();',
'data'=>$sort_order,
'value'=>$sort_order_1));
$form->addInput(array('type'=>'combobox',
'name'=>'sort_order_2',
'class'=>'dropdown-field-with-button',
'onchange'=>'this.form.sorting_changed.value=1;this.form.submit();',
'data'=>$sort_order,
'value'=>$sort_order_2));
$form->addInput(array('type'=>'hidden','name'=>'sorting_changed'));
if ($request->isPost()) {
// Validate user input.
if (!ttInvoiceHelper::validSortOption($sort_option_1)) $err->add($i18n->get('error.field'), $i18n->get('label.sort'));
if (!ttInvoiceHelper::validSortOption($sort_option_2, true)) $err->add($i18n->get('error.field'), $i18n->get('label.sort'));
if (!ttInvoiceHelper::validSortOrder($sort_order_1)) $err->add($i18n->get('error.field'), $i18n->get('label.sort'));
if (!ttInvoiceHelper::validSortOrder($sort_order_2)) $err->add($i18n->get('error.field'), $i18n->get('label.sort'));
if ($sort_option_1 == $sort_option_2) $err->add($i18n->get('error.field'), $i18n->get('label.sort'));
if ($err->no() && $request->getParameter('sorting_changed')) {
// User changed sorting. Get invoices sorted accordingly.
$sort_options = array('sort_option_1'=>$sort_option_1,
'sort_order_1'=>$sort_order_1,
'sort_option_2'=>$sort_option_2,
'sort_order_2'=>$sort_order_2);
$invoices = ttGroupHelper::getActiveInvoices($sort_options);
}
}
$smarty->assign('invoices', $invoices);
$smarty->assign('show_sorting_options', count($invoices) > 1);
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('title', $i18n->get('title.invoices'));
$smarty->assign('content_page_name', 'invoices.tpl');
$smarty->display('index.tpl');