Update from usntable branch.
[fa-stable.git] / admin / company_preferences.php
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 $page_security = 'SA_SETUPCOMPANY';
13 $path_to_root = "..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Company Setup"));
17
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20
21 include_once($path_to_root . "/admin/db/company_db.inc");
22 //-------------------------------------------------------------------------------------------------
23
24 if (isset($_POST['update']) && $_POST['update'] != "")
25 {
26
27         $input_error = 0;
28
29         if (!check_num('login_tout', 10))
30         {
31                 display_error(_("Login timeout must be positive number not less than 10."));
32                 set_focus('login_tout');
33                 $input_error = 1;
34         }
35         if (strlen($_POST['coy_name'])==0)
36         {
37                 $input_error = 1;
38                 display_error(_("The company name must be entered."));
39                 set_focus('coy_name');
40         }
41         if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '')
42         {
43                 $user_comp = user_company();
44                 $result = $_FILES['pic']['error'];
45                 $filename = $comp_path . "/$user_comp/images";
46                 if (!file_exists($filename))
47                 {
48                         mkdir($filename);
49                 }
50                 $filename .= "/".$_FILES['pic']['name'];
51
52                  //But check for the worst
53                 if (!in_array((substr(trim($_FILES['pic']['name']),-3)), 
54                         array('jpg','JPG','png','PNG')))
55                 {
56                         display_error(_('Only jpg and png files are supported - a file extension of .jpg or .png is expected'));
57                         $input_error = 1;
58                 }
59                 elseif ( $_FILES['pic']['size'] > ($max_image_size * 1024))
60                 { //File Size Check
61                         display_error(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $max_image_size);
62                         $input_error = 1;
63                 }
64                 elseif ( $_FILES['pic']['type'] == "text/plain" )
65                 {  //File type Check
66                         display_error( _('Only graphics files can be uploaded'));
67                         $input_error = 1;
68                 }
69                 elseif (file_exists($filename))
70                 {
71                         $result = unlink($filename);
72                         if (!$result)
73                         {
74                                 display_error(_('The existing image could not be removed'));
75                                 $input_error = 1;
76                         }
77                 }
78
79                 if ($input_error != 1)
80                 {
81                         $result  =  move_uploaded_file($_FILES['pic']['tmp_name'], $filename);
82                         $_POST['coy_logo'] = $_FILES['pic']['name'];
83                         if(!$result) 
84                                 display_error(_('Error uploading logo file'));
85                 }
86         }
87         if (check_value('del_coy_logo'))
88         {
89                 $user_comp = user_company();
90                 $filename = $comp_path . "/$user_comp/images/".$_POST['coy_logo'];
91                 if (file_exists($filename))
92                 {
93                         $result = unlink($filename);
94                         if (!$result)
95                         {
96                                 display_error(_('The existing image could not be removed'));
97                                 $input_error = 1;
98                         }
99                         else
100                                 $_POST['coy_logo'] = "";
101                 }
102         }
103         if ($_POST['add_pct'] == "")
104                 $_POST['add_pct'] = -1;
105         if ($input_error != 1)
106         {
107                 update_company_setup($_POST['coy_name'], $_POST['coy_no'], 
108                         $_POST['gst_no'], $_POST['tax_prd'], $_POST['tax_last'],
109                         $_POST['postal_address'], $_POST['phone'], $_POST['fax'], 
110                         $_POST['email'], $_POST['coy_logo'], $_POST['domicile'],
111                         $_POST['use_dimension'], $_POST['curr_default'], $_POST['f_year'], 
112                         check_value('no_item_list'), check_value('no_customer_list'), 
113                         check_value('no_supplier_list'), $_POST['base_sales'], 
114                         check_value('time_zone'), $_POST['add_pct'], $_POST['round_to'],
115                         $_POST['login_tout']);
116                 $_SESSION['wa_current_user']->timeout = $_POST['login_tout'];
117                 display_notification_centered(_("Company setup has been updated."));
118         }
119         set_focus('coy_name');
120         $Ajax->activate('_page_body');
121 } /* end of if submit */
122
123 //---------------------------------------------------------------------------------------------
124
125
126 start_form(true);
127 $myrow = get_company_prefs();
128
129 $_POST['coy_name'] = $myrow["coy_name"];
130 $_POST['gst_no'] = $myrow["gst_no"];
131 $_POST['tax_prd'] = $myrow["tax_prd"];
132 $_POST['tax_last'] = $myrow["tax_last"];
133 $_POST['coy_no']  = $myrow["coy_no"];
134 $_POST['postal_address']  = $myrow["postal_address"];
135 $_POST['phone']  = $myrow["phone"];
136 $_POST['fax']  = $myrow["fax"];
137 $_POST['email']  = $myrow["email"];
138 $_POST['coy_logo']  = $myrow["coy_logo"];
139 $_POST['domicile']  = $myrow["domicile"];
140 $_POST['use_dimension']  = $myrow["use_dimension"];
141 $_POST['base_sales']  = $myrow["base_sales"];
142 $_POST['no_item_list']  = $myrow["no_item_list"];
143 $_POST['no_customer_list']  = $myrow["no_customer_list"];
144 $_POST['no_supplier_list']  = $myrow["no_supplier_list"];
145 $_POST['curr_default']  = $myrow["curr_default"];
146 $_POST['f_year']  = $myrow["f_year"];
147 $_POST['time_zone']  = $myrow["time_zone"];
148 $_POST['version_id']  = $myrow["version_id"];
149 $_POST['add_pct'] = $myrow['add_pct'];
150 $_POST['login_tout'] = $myrow['login_tout'];
151 if ($_POST['add_pct'] == -1)
152         $_POST['add_pct'] = "";
153 $_POST['round_to'] = $myrow['round_to'];        
154 $_POST['del_coy_logo']  = 0;
155
156 start_outer_table($table_style2);
157
158 table_section(1);
159
160 text_row_ex(_("Name (to appear on reports):"), 'coy_name', 42, 50);
161 textarea_row(_("Address:"), 'postal_address', $_POST['postal_address'], 35, 6);
162 text_row_ex(_("Domicile:"), 'domicile', 25, 55);
163
164 text_row_ex(_("Phone Number:"), 'phone', 25, 55);
165 text_row_ex(_("Fax Number:"), 'fax', 25);
166 email_row_ex(_("Email Address:"), 'email', 25, 55);
167
168 text_row_ex(_("Official Company Number:"), 'coy_no', 25);
169 text_row_ex(_("GSTNo:"), 'gst_no', 25);
170
171 currencies_list_row(_("Home Currency:"), 'curr_default', $_POST['curr_default']);
172 fiscalyears_list_row(_("Fiscal Year:"), 'f_year', $_POST['f_year']);
173
174 table_section(2);
175
176 text_row_ex(_("Tax Periods:"), 'tax_prd', 10, 10, '', null, null, _('Months.'));
177 text_row_ex(_("Tax Last Period:"), 'tax_last', 10, 10, '', null, null, _('Months back.'));
178
179 label_row(_("Company Logo:"), $_POST['coy_logo']);
180 label_row(_("New Company Logo (.jpg)") . ":", "<input type='file' id='pic' name='pic'>");
181 check_row(_("Delete Company Logo:"), 'del_coy_logo', $_POST['del_coy_logo']);
182
183 number_list_row(_("Use Dimensions:"), 'use_dimension', null, 0, 2);
184 sales_types_list_row(_("Base for auto price calculations:"), 'base_sales', $_POST['base_sales'], false,
185     _('No base price list') );
186 text_row_ex(_("Add Price from Std Cost:"), 'add_pct', 10, 10, '', null, null, "%");
187 $curr = get_currency($_POST['curr_default']);
188 text_row_ex(_("Round to nearest:"), 'round_to', 10, 10, '', null, null, $curr['hundreds_name']);
189
190 check_row(_("Search Item List"), 'no_item_list', null);
191 check_row(_("Search Customer List"), 'no_customer_list', null);
192 check_row(_("Search Supplier List"), 'no_supplier_list', null);
193 label_row("", "&nbsp;");
194 check_row(_("Time Zone on Reports"), 'time_zone', $_POST['time_zone']);
195 text_row_ex(_("Login Timeout:"), 'login_tout', 10, 10, '', null, null, _('seconds'));
196 label_row(_("Version Id"), $_POST['version_id']);
197
198 end_outer_table(1);
199
200 hidden('coy_logo', $_POST['coy_logo']);
201 submit_center('update', _("Update"), true, '',  'default');
202
203 end_form(2);
204 //-------------------------------------------------------------------------------------------------
205
206 end_page();
207
208 ?>