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