Activated strict SQL mode, minor SQL injection fix, fixed _vl() debug helper.
[fa-stable.git] / includes / ui / class.reflines_crud.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once $path_to_root.'/includes/db/class.reflines_db.inc';
13 include_once $path_to_root.'/includes/ui/class.crud_view.inc';
14
15 class fa_reflines extends simple_crud_view {
16
17         function __construct()
18         {
19                 parent::__construct('refs', new reflines_db(), array('clone' => false));
20
21                 $this->fields = array(
22                         'prefix',
23                         'description',
24                         'trans_type',
25                         'pattern',
26                         'default' => 'check',
27                 );
28
29         }
30
31         function list_view($Mode)
32         {
33                 global $systypes_array;
34
35                 start_table(TABLESTYLE);
36
37                 $th = array(_("Transaction type"), _("Prefix"),
38                         _("Pattern"), _("Default"), _("Memo"),  "", "");
39
40                 inactive_control_column($th);
41
42                 table_header($th);
43
44                 $k = 0;
45                 $data = $this->data_set->get_all(check_value('show_inactive') ? null : '!inactive', array('trans_type', 'prefix'));
46
47                 if (!$data) return false;
48
49                 while ($rec = db_fetch($data))
50                 {
51                         alt_table_row_color($k);
52
53                         label_cell($systypes_array[$rec['trans_type']]);
54                         label_cell($rec['prefix']);
55                         label_cell($rec['pattern']);
56                         label_cell($rec['default'] ? _("Yes") : _("No"));
57                         label_cell($rec['description']);
58
59                         if (check_value('show_inactive') && $rec['default'])
60                                 label_cell('');
61                         else
62                                 inactive_control_cell($rec["id"], $rec["inactive"], 'reflines', 'id');
63                         if ($this->options['update'])
64                                 echo $this->tool_button('Edit', $rec['id']);
65                         if ($this->options['delete']) {
66                                 echo $this->tool_button('Delete', $rec['id']);
67                         }
68                         end_row();
69                 }
70                 inactive_control_row($th);
71                 end_table(1);
72                 $this->_record_controls(true);
73
74                 return true;
75         }
76
77         function editor_view($Mode)
78         {
79                 global $systypes_array;
80
81                 $selected_id = $this->selected_id;
82
83                 // new or never used
84                 $fresh = $selected_id == $this->_none || !$this->data_set->is_used(get_post($this->name.'prefix'), get_post($this->name.'trans_type'));
85
86                 start_table(TABLESTYLE2);
87
88                 if ($fresh)
89                 {
90                         systypes_list_row(_("Transaction Type:"), $this->name.'trans_type');
91                         $prefix = text_input($this->name.'prefix', null, 5, 30);
92                 } else {
93                         label_row(_("Transaction Type:"), $systypes_array[get_post($this->name.'trans_type')]);
94                         hidden($this->name.'trans_type');
95                         $prefix = get_post($this->name.'prefix') . hidden($this->name.'prefix');
96                 }
97
98                 label_row(_("Reference Pattern:"), $prefix . text_input($this->name.'pattern', null, 30, 60));
99
100                 if (get_post($this->name.'default'))
101                         { label_row(_("Default for This Type:"), _("Yes")); hidden($this->name.'default', 1); }
102                 else
103                         check_row(_("Set as Default for This Type:"), $this->name.'default');
104
105                 text_row_ex(_("Memo:"), $this->name.'description', 30, 60);
106
107                 end_table(1);
108                 hidden($this->name.'selected_id', $selected_id);
109                 $this->_record_controls();
110         }
111
112         function show($Mode=null)
113         {
114                 parent::show($Mode);
115         }
116 }