b79bf3d2357d7c5cc3981331cf06cf82728ccccd
[fa-stable.git] / includes / data_checks.inc
1 <?php
2 function db_has_customers()
3 {
4         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."debtors_master");
5 }
6
7 function check_db_has_customers($msg)
8 {
9         global $path_to_root;
10     if (!db_has_customers()) 
11     {
12         display_error($msg, true);
13         end_page();
14         exit;   
15     }   
16 }
17
18 function db_has_currencies()
19 {
20         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."currencies");
21 }
22
23 function check_db_has_currencies($msg)
24 {
25         global $path_to_root;
26     if (!db_has_currencies()) 
27     {
28         display_error($msg, true);
29         end_page();
30         exit;   
31     }   
32 }
33
34 function db_has_sales_types()
35 {
36         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."sales_types");
37 }
38
39 function check_db_has_sales_types($msg)
40 {
41         global $path_to_root;
42     if (!db_has_sales_types()) 
43     {
44         display_error($msg, true);
45         end_page();
46         exit;   
47     }   
48 }
49
50 function db_has_item_tax_types()
51 {
52         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."item_tax_types");
53 }
54
55 function check_db_has_item_tax_types($msg)
56 {
57         global $path_to_root;
58     if (!db_has_item_tax_types()) 
59     {
60         display_error($msg, true);
61         end_page();
62         exit;   
63     }   
64 }
65
66 function db_has_tax_types()
67 {
68         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tax_types");
69 }
70
71 function check_db_has_tax_types($msg)
72 {
73         global $path_to_root;
74     if (!db_has_tax_types()) 
75     {
76         display_error($msg, true);
77         end_page();
78         exit;   
79     }   
80 }
81
82 function db_has_tax_groups()
83 {
84         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tax_groups");
85 }
86
87 function check_db_has_tax_groups($msg)
88 {
89         global $path_to_root;
90     if (!db_has_tax_groups()) 
91     {
92         display_error($msg, true);
93         end_page();
94         exit;   
95     }   
96 }
97
98 function db_has_movement_types()
99 {
100         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."movement_types");
101 }
102
103 function check_db_has_movement_types($msg)
104 {
105         global $path_to_root;
106     if (!db_has_movement_types()) 
107     {
108         display_error($msg, true);
109         end_page();
110         exit;   
111     }   
112 }
113
114 function db_has_bank_trans_types()
115 {
116         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_trans_types");
117 }
118
119 function check_db_has_bank_trans_types($msg)
120 {
121         global $path_to_root;
122     if (!db_has_bank_trans_types()) 
123     {
124         display_error($msg, true);
125         end_page();
126         exit;   
127     }   
128 }
129
130 function db_customer_has_branches($customer_id)
131 {
132         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE debtor_no='$customer_id'");
133 }
134
135 function db_has_customer_branches()
136 {
137         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch");
138 }
139
140 function check_db_has_customer_branches($msg)
141 {
142         global $path_to_root;
143     if (!db_has_customer_branches()) 
144     {
145         display_error($msg, true);
146         end_page();
147         exit;   
148     }   
149 }
150
151 function db_has_sales_people()
152 {
153         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."salesman");
154 }
155
156 function check_db_has_sales_people($msg)
157 {
158         global $path_to_root;
159     if (!db_has_sales_people()) 
160     {
161         display_error($msg, true);
162         end_page();
163         exit;   
164     }   
165 }
166
167 function db_has_sales_areas()
168 {
169         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."areas");
170 }
171
172 function check_db_has_sales_areas($msg)
173 {
174         global $path_to_root;
175     if (!db_has_sales_areas()) 
176     {
177         display_error($msg, true);
178         end_page();
179         exit;   
180     }   
181 }
182
183 function db_has_shippers()
184 {
185         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."shippers");
186 }
187
188 function check_db_has_shippers($msg)
189 {
190         global $path_to_root;
191     if (!db_has_shippers()) 
192     {
193         display_error($msg, true);
194         end_page();
195         exit;   
196     }   
197 }
198
199 function db_has_open_workorders()
200 {
201         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders WHERE closed=0");
202 }
203
204 function db_has_workorders()
205 {
206         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders");
207 }
208
209 function check_db_has_workorders($msg)
210 {
211         global $path_to_root;
212     if (!db_has_workorders()) 
213     {
214         display_error($msg, true);
215         end_page();
216         exit;   
217     }   
218 }
219
220 function db_has_open_dimensions()
221 {
222         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions WHERE closed=0");
223 }
224
225 function db_has_dimensions()
226 {
227         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions");
228 }
229
230 function check_db_has_dimensions($msg)
231 {
232         global $path_to_root;
233     if (!db_has_dimensions()) 
234     {
235         display_error($msg, true);
236         end_page();
237         exit;   
238     }   
239 }
240
241
242 function db_has_suppliers()
243 {
244         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."suppliers");
245 }
246
247 function check_db_has_suppliers($msg)
248 {
249         global $path_to_root;
250     if (!db_has_suppliers()) 
251     {
252         display_error($msg, true);
253         end_page();
254         exit;   
255     }   
256 }
257
258 function db_has_stock_items()
259 {
260         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master");
261 }
262
263 function check_db_has_stock_items($msg)
264 {
265         global $path_to_root;
266     if (!db_has_stock_items()) 
267     {
268         display_error($msg, true);
269         end_page();
270         exit;   
271     }   
272 }
273
274 function db_has_bom_stock_items()
275 {
276         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M' OR mb_flag='K')");
277 }
278
279 function check_db_has_bom_stock_items($msg)
280 {
281         global $path_to_root;
282     if (!db_has_bom_stock_items()) 
283     {
284         display_error($msg, true);
285         end_page();
286         exit;   
287     }   
288 }
289
290 function db_has_manufacturable_items()
291 {
292         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M')");
293 }
294
295 function check_db_has_manufacturable_items($msg)
296 {
297         global $path_to_root;
298     if (!db_has_manufacturable_items()) 
299     {
300         display_error($msg, true);
301         end_page();
302         exit;   
303     }   
304 }
305
306 function db_has_purchasable_items()
307 {
308         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='M' AND mb_flag!='K')");
309 }
310
311 function check_db_has_purchasable_items($msg)
312 {
313         global $path_to_root;
314     if (!db_has_purchasable_items()) 
315     {
316         display_error($msg, true);
317         end_page();
318         exit;   
319     }   
320 }
321
322 function db_has_costable_items()
323 {
324         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='D' AND mb_flag!='K')");
325 }
326
327 function check_db_has_costable_items($msg)
328 {
329         global $path_to_root;
330     if (!db_has_costable_items()) 
331     {
332         display_error($msg, true);
333         end_page();
334         exit;   
335     }   
336 }
337
338 function db_has_stock_categories()
339 {
340         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_category");
341 }
342
343 function check_db_has_stock_categories($msg)
344 {
345         global $path_to_root;
346     if (!db_has_stock_categories()) 
347     {
348         display_error($msg, true);
349         end_page();
350         exit;   
351     }   
352 }
353
354 function db_has_workcentres()
355 {
356         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workcentres");
357 }
358
359 function check_db_has_workcentres($msg)
360 {
361         global $path_to_root;
362     if (!db_has_workcentres()) 
363     {
364         display_error($msg, true);
365         end_page();
366         exit;   
367     }   
368 }
369
370 function db_has_locations()
371 {
372         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."locations");
373 }
374
375 function check_db_has_locations($msg)
376 {
377         global $path_to_root;
378     if (!db_has_locations()) 
379     {
380         display_error($msg, true);
381         end_page();
382         exit;   
383     }   
384 }
385
386 function db_has_bank_accounts()
387 {
388         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_accounts");
389 }
390
391 function check_db_has_bank_accounts($msg)
392 {
393         global $path_to_root;
394     if (!db_has_bank_accounts()) 
395     {
396         display_error($msg, true);
397         end_page();
398         exit;   
399     }   
400 }
401
402 function db_has_gl_accounts()
403 {
404         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_master");
405 }
406
407 function db_has_gl_account_groups()
408 {
409         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_types");
410 }
411
412 function check_db_has_gl_account_groups($msg)
413 {
414         global $path_to_root;
415     if (!db_has_gl_account_groups()) 
416     {
417         display_error($msg, true);
418         end_page();
419         exit;   
420     }   
421 }
422
423 function check_empty_result($sql)
424 {
425         $result = db_query($sql, "could not do check empty query");     
426         
427         $myrow = db_fetch_row($result);
428         return $myrow[0] > 0;           
429 }
430 //
431 //      Integer input check 
432 //      Return 1 if number has proper form and is within <min, max> range
433 //
434 function check_int($postname, $min=null, $max=null) {
435         if(!isset($_POST[$postname]))
436           return 0;
437     $num = input_num($postname);
438     if(!is_int($num)) 
439           return 0;
440     if (isset($min) && ($num<$min)) 
441           return 0;
442     if (isset($max) && ($num>$max)) 
443           return 0;
444     return 1;
445 }
446 //
447 //      Numeric input check.
448 //      Return 1 if number has proper form and is within <min, max> range
449 //
450 function check_num($postname, $min=null, $max=null) {
451         if(!isset($_POST[$postname]))
452           return 0;
453     $num = input_num($postname);
454     if ($num === false) 
455           return 0;
456     if (isset($min) && ($num<$min)) 
457           return 0;
458     if (isset($max) && ($num>$max)) 
459           return 0;
460     return 1;
461 }
462
463
464 ?>