Better layout. Copyright notes. Mailto links. (2. run)
[fa-stable.git] / admin / company_preferences.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 $page_security =10;
13 $path_to_root="..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_("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 (strlen($_POST['coy_name'])==0)
30         {
31                 $input_error = 1;
32                 display_error(_("The company name must be entered."));
33                 set_focus('coy_name');
34         }
35         if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '')
36         {
37                 $user_comp = user_company();
38                 $result = $_FILES['pic']['error'];
39                 $filename = $comp_path . "/$user_comp/images";
40                 if (!file_exists($filename))
41                 {
42                         mkdir($filename);
43                 }
44                 $filename .= "/".$_FILES['pic']['name'];
45
46                  //But check for the worst
47                 if (strtoupper(substr(trim($_FILES['pic']['name']), strlen($_FILES['pic']['name']) - 3)) != 'JPG')
48                 {
49                         display_notification(_('Only jpg files are supported - a file extension of .jpg is expected'));
50                         $input_error = 1;
51                 }
52                 elseif ( $_FILES['pic']['size'] > ($max_image_size * 1024))
53                 { //File Size Check
54                         display_notification(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $max_image_size);
55                         $input_error = 1;
56                 }
57                 elseif ( $_FILES['pic']['type'] == "text/plain" )
58                 {  //File type Check
59                         display_notification( _('Only graphics files can be uploaded'));
60                         $input_error = 1;
61                 }
62                 elseif (file_exists($filename))
63                 {
64                         $result = unlink($filename);
65                         if (!$result)
66                         {
67                                 display_error(_('The existing image could not be removed'));
68                                 $input_error = 1;
69                         }
70                 }
71
72                 if ($input_error != 1)
73                 {
74                         $result  =  move_uploaded_file($_FILES['pic']['tmp_name'], $filename);
75                         $_POST['coy_logo'] = $_FILES['pic']['name'];
76                         if(!$result) 
77                                 display_error(_('Error uploading logo file'));
78                 }
79         }
80         if ($input_error != 1)
81         {
82                 update_company_setup($_POST['coy_name'], $_POST['coy_no'], $_POST['gst_no'], $_POST['tax_prd'], $_POST['tax_last'],
83                         $_POST['postal_address'], $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['coy_logo'], $_POST['domicile'],
84                         $_POST['use_dimension'], $_POST['custom1_name'], $_POST['custom2_name'], $_POST['custom3_name'],
85                         $_POST['custom1_value'], $_POST['custom2_value'], $_POST['custom3_value'],
86                         $_POST['curr_default'], $_POST['f_year'], check_value('no_item_list'), check_value('no_customer_list'),
87                         check_value('no_supplier_list'), $_POST['base_sales']);
88
89                 display_notification_centered(_("Company setup has been updated."));
90         }
91         set_focus('coy_name');
92         $Ajax->activate('_page_body');
93 } /* end of if submit */
94
95 //---------------------------------------------------------------------------------------------
96
97
98 start_form(true);
99
100 $myrow = get_company_prefs();
101
102 $_POST['coy_name'] = $myrow["coy_name"];
103 $_POST['gst_no'] = $myrow["gst_no"];
104 $_POST['tax_prd'] = $myrow["tax_prd"];
105 $_POST['tax_last'] = $myrow["tax_last"];
106 $_POST['coy_no']  = $myrow["coy_no"];
107 $_POST['postal_address']  = $myrow["postal_address"];
108 $_POST['phone']  = $myrow["phone"];
109 $_POST['fax']  = $myrow["fax"];
110 $_POST['email']  = $myrow["email"];
111 $_POST['coy_logo']  = $myrow["coy_logo"];
112 $_POST['domicile']  = $myrow["domicile"];
113 $_POST['use_dimension']  = $myrow["use_dimension"];
114 $_POST['base_sales']  = $myrow["base_sales"];
115 $_POST['no_item_list']  = $myrow["no_item_list"];
116 $_POST['no_customer_list']  = $myrow["no_customer_list"];
117 $_POST['no_supplier_list']  = $myrow["no_supplier_list"];
118 $_POST['custom1_name']  = $myrow["custom1_name"];
119 $_POST['custom2_name']  = $myrow["custom2_name"];
120 $_POST['custom3_name']  = $myrow["custom3_name"];
121 $_POST['custom1_value']  = $myrow["custom1_value"];
122 $_POST['custom2_value']  = $myrow["custom2_value"];
123 $_POST['custom3_value']  = $myrow["custom3_value"];
124 $_POST['curr_default']  = $myrow["curr_default"];
125 $_POST['f_year']  = $myrow["f_year"];
126
127 start_outer_table($table_style2);
128
129 table_section(1);
130
131 text_row_ex(_("Name (to appear on reports):"), 'coy_name', 42, 50);
132 textarea_row(_("Address:"), 'postal_address', $_POST['postal_address'], 35, 5);
133
134 text_row_ex(_("Phone Number:"), 'phone', 25, 55);
135 text_row_ex(_("Fax Number:"), 'fax', 25);
136 email_row_ex(_("Email Address:"), 'email', 25, 55);
137
138 text_row_ex(_("Official Company Number:"), 'coy_no', 25);
139 text_row_ex(_("GSTNo:"), 'gst_no', 25);
140
141 text_row_ex(_("Tax Periods:"), 'tax_prd', 10, 10, '', null, null, _('Months.'));
142 text_row_ex(_("Tax Last Period:"), 'tax_last', 10, 10, '', null, null, _('Months back.'));
143
144 currencies_list_row(_("Home Currency:"), 'curr_default', $_POST['curr_default']);
145
146 table_section(2);
147
148 fiscalyears_list_row(_("Fiscal Year:"), 'f_year', $_POST['f_year']);
149 label_row(_("Company Logo:"), $_POST['coy_logo']);
150 label_row(_("New Company Logo (.jpg)") . ":", "<input type='file' id='pic' name='pic'>");
151
152 text_row_ex(_("Domicile:"), 'domicile', 25, 55);
153
154 number_list_row(_("Use Dimensions:"), 'use_dimension', null, 0, 2);
155 sales_types_list_row(_("Base for auto price calculations:"), 'base_sales', $_POST['base_sales'], false,
156     _('No base price list') );
157
158 check_row(_("Search Item List"), 'no_item_list', $_POST['no_item_list']);
159 check_row(_("Search Customer List"), 'no_customer_list', $_POST['no_customer_list']);
160 check_row(_("Search Supplier List"), 'no_supplier_list', $_POST['no_supplier_list']);
161
162 start_row();
163 end_row();
164 label_row(_("Custom Field Name"), _("Custom Field Value"));
165
166 start_row();
167 text_cells(null, 'custom1_name', $_POST['custom1_name'], 25, 25);
168 text_cells(null, 'custom1_value', $_POST['custom1_value'], 30, 30);
169 end_row();
170
171 start_row();
172 text_cells(null, 'custom2_name', $_POST['custom2_name'], 25, 25);
173 text_cells(null, 'custom2_value', $_POST['custom2_value'], 30, 30);
174 end_row();
175
176 start_row();
177 text_cells(null, 'custom3_name', $_POST['custom3_name'], 25, 25);
178 text_cells(null, 'custom3_value', $_POST['custom3_value'], 30, 30);
179 end_row();
180
181 end_outer_table(1);
182
183 hidden('coy_logo', $_POST['coy_logo']);
184 submit_center('update', _("Update"), true, '', true);
185
186 end_form(2);
187 //-------------------------------------------------------------------------------------------------
188
189 end_page();
190
191 ?>