New file
[fa-stable.git] / gl / manage / gl_quick_entries.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("Quick Entries"));
8
9 include($path_to_root . "/gl/includes/gl_db.inc");
10
11 include($path_to_root . "/includes/ui.inc");
12
13 simple_page_mode(true);
14 //-----------------------------------------------------------------------------------
15
16 function can_process() 
17 {
18
19         if (strlen($_POST['description']) == 0) 
20         {
21                 display_error( _("The Quick Entry description cannot be empty."));
22                 set_focus('description');
23                 return false;
24         }
25
26         return true;
27 }
28
29 //-----------------------------------------------------------------------------------
30
31 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
32 {
33
34         if (can_process()) 
35         {
36
37         if ($selected_id != -1) 
38         {
39                 update_quick_entry($selected_id, $_POST['description'], $_POST['account'], $_POST['deposit']);
40                         display_notification(_('Selected quick entry has been updated'));
41         } 
42         else 
43         {
44                 add_quick_entry($_POST['description'], $_POST['account'], $_POST['deposit']);
45                         display_notification(_('New account class has been added'));
46         }
47                 $Mode = 'RESET';
48         }
49 }
50
51 //-----------------------------------------------------------------------------------
52
53 if ($Mode == 'Delete')
54 {
55
56         delete_quick_entry($selected_id);
57         display_notification(_('Selected quick entry has been deleted'));
58         $Mode = 'RESET';
59 }
60
61 //-----------------------------------------------------------------------------------
62 if ($Mode == 'RESET')
63 {
64         $selected_id = -1;
65         $_POST['description'] = $_POST['account'] = $_POST['deposit'] = '';
66 }
67 //-----------------------------------------------------------------------------------
68
69 $result = get_quick_entries();
70 start_form();
71 start_table($table_style);
72 $th = array(_("Description"), _("Account"), _("Deposit"), "", "");
73 table_header($th);
74
75 $k = 0;
76 while ($myrow = db_fetch($result)) 
77 {
78
79         alt_table_row_color($k);
80
81         if ($myrow["deposit"] == 0) 
82         {
83                 $bs_text = _("No");
84         } 
85         else 
86         {
87                 $bs_text = _("Yes");
88         }
89         label_cell($myrow['description']);
90         label_cell($myrow['account']." ".$myrow['account_name']);
91         label_cell($bs_text);
92         edit_button_cell("Edit".$myrow["id"], _("Edit"));
93         edit_button_cell("Delete".$myrow["id"], _("Delete"));
94         end_row();
95 }
96
97 end_table();
98 end_form();
99 echo '<br>';
100 //-----------------------------------------------------------------------------------
101
102 start_form();
103
104 start_table($table_style2);
105
106 if ($selected_id != -1) 
107 {
108         if ($Mode == 'Edit') 
109         {
110                 //editing an existing status code
111                 $myrow = get_quick_entry($selected_id);
112
113                 $_POST['id']  = $myrow["id"];
114                 $_POST['description']  = $myrow["description"];
115                 $_POST['account']  = $myrow["account"];
116                 $_POST['deposit']  = $myrow["deposit"];
117                 hidden('selected_id', $selected_id);
118         }
119
120
121 text_row_ex(_("Description:"), 'description', 50, 60);
122
123 gl_all_accounts_list_row(_("Account"), 'account', null, true);
124
125 yesno_list_row(_("Deposit:"), 'deposit', null, "", "", false);
126
127 end_table(1);
128
129 submit_add_or_update_center($selected_id == -1, '', true);
130
131 end_form();
132
133 //------------------------------------------------------------------------------------
134
135 end_page();
136
137 ?>