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