Added option to handle Jalali and Islamic Calendars
[fa-stable.git] / includes / ui / ui_lists.inc
1 <?php
2
3 include_once($path_to_root . "/includes/banking.inc");
4
5 $all_items = reserved_words::get_all();
6
7 // TDB for all list functions : if there is no data, display a link to the releveant
8 // page to add an item, eg. for locations, if no locations, link to Add Location
9
10 function supplier_list($name, $selected_id, $all_option=false, $submit_on_change=false)
11 {
12         if ($submit_on_change==true)
13                 echo "<select name='$name' onchange='this.form.submit();'>";
14         else
15                 echo "<select name='$name'>";
16
17         $company_currency = get_company_currency();
18
19         $supplier_sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ORDER BY supp_name";
20         $supplier_result = db_query($supplier_sql);
21
22         if ($selected_id == null)
23                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
24         if ($all_option == true)
25         {
26         if (reserved_words::get_all() == $selected_id)
27         {
28              echo "<option selected value='" . reserved_words::get_all(). "'>" . _("All Suppliers") . "</option>\n";
29         } 
30         else 
31         {
32              echo "<option value='" . reserved_words::get_all(). "'>" . _("All Suppliers") . "</option>\n";
33         }
34                 if ($selected_id == "") 
35                 {
36                         $selected_id = reserved_words::get_all();
37                 }
38         }
39
40         while ($supplier_row = db_fetch_row($supplier_result)) 
41         {
42                 if ($selected_id==$supplier_row[0]) 
43                 {
44                         echo "<option selected value='" . $supplier_row[0] . "'>";
45                 } 
46                 else 
47                 {
48                         echo "<option value='" . $supplier_row[0] . "'>";
49                 }
50                 echo $supplier_row[1];
51
52                 if ($supplier_row[2] != $company_currency)
53                         echo "&nbsp;-&nbsp;" . $supplier_row[2];
54                 echo  "</option>\n";
55                 if ($selected_id == "") 
56                 {
57                         $selected_id = $supplier_row[0];
58                         $_POST[$name] = $selected_id;
59                 }
60         }
61
62         echo "</select>";
63
64         db_free_result($supplier_result);
65 }
66
67 function supplier_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
68 {
69         if ($label != null)
70                 echo "<td>$label</td>\n";
71         echo "<td>";
72         supplier_list($name, $selected_id, $all_option, $submit_on_change);
73         echo "</td>\n";
74 }
75
76 function supplier_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
77 {
78         echo "<tr>\n";
79         supplier_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
80         echo "</tr>\n";
81 }
82
83 //----------------------------------------------------------------------------------------------
84
85 function customer_list($name, $selected_id, $all_option=false, $submit_on_change=false)
86 {
87         if ($submit_on_change==true)
88                 echo "<select name='$name' onchange='this.form.submit();'>";
89         else
90                 echo "<select name='$name'>";
91
92         $customer_sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ORDER BY name";
93         $customer_result = db_query($customer_sql);
94
95         $company_currency = get_company_currency();
96
97         if ($selected_id == null)
98                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
99         if (($all_option == true))
100         {
101         if (reserved_words::get_all() == $selected_id)
102         {
103              echo "<option selected value='" . reserved_words::get_all(). "'>" . _("All Customers") . "</option>\n";
104         } 
105         else 
106         {
107              echo "<option value='" . reserved_words::get_all(). "'>" . _("All Customers") . "</option>\n";
108         }
109                 if ($selected_id == "") 
110                 {
111                         $selected_id =  reserved_words::get_all();
112                 }
113         }
114
115         while ($customer_row = db_fetch_row($customer_result)) 
116         {
117                 if ($selected_id == $customer_row[0]) 
118                 {
119                         echo "<option selected value='" . $customer_row[0] . "'>";
120                 } 
121                 else 
122                 {
123                         echo "<option value='" . $customer_row[0] . "'>";
124                 }
125
126                 echo $customer_row[1];
127                 if ($customer_row[2] != $company_currency)
128                         echo "&nbsp;-&nbsp;" . $customer_row[2];
129
130                 echo  "</option>\n";
131                 // if no initial selection - set the first item
132                 // do we want to do this for all lists ???? probably
133                 if ($selected_id == "") 
134                 {
135                         $selected_id = $customer_row[0];
136                         $_POST[$name] = $selected_id;
137                 }
138         }
139
140         echo "</select>";
141
142         db_free_result($customer_result);
143 }
144
145 function customer_list_cells($label, $name, $selected_id, $all_option = false, $submit_on_change=false)
146 {
147         if ($label != null)
148                 echo "<td>$label</td>\n";
149         echo "<td>";
150         customer_list($name, $selected_id, $all_option, $submit_on_change);
151         echo "</td>\n";
152 }
153
154 function customer_list_row($label, $name, $selected_id, $all_option = false, $submit_on_change=false)
155 {
156         echo "<tr>\n";
157         customer_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
158         echo "</tr>\n";
159 }
160
161 //------------------------------------------------------------------------------------------------
162
163 function customer_branches_list($customer_id, $name, $selected_id,
164         $all_option = true, $enabled=true, $submit_on_change=false)
165 {
166         global $all_items;
167
168         if ($submit_on_change==true)
169                 echo "<select name='$name' onchange='this.form.submit();'>";
170         else
171                 echo "<select name='$name'>";
172
173         $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
174                 WHERE debtor_no='" . $customer_id . "'";
175         if ($enabled)
176                 $sql .= " AND disable_trans = 0";
177         $result = db_query($sql);
178
179         if ($selected_id == null)
180                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
181         if ($all_option == true)
182         {
183                 echo "<option ";
184                 if (reserved_words::get_all() == $selected_id)
185                         echo " selected ";
186                 echo "value='" . reserved_words::get_all(). "'>" . _("All Branches") . "</option>\n";
187
188                 if ($selected_id == "") 
189                 {
190                         $selected_id =  reserved_words::get_all();
191                 }
192         }
193
194         while ($row = db_fetch_row($result)) 
195         {
196                 if ($selected_id == $row[0]) 
197                 {
198                         echo "<option selected value='" . $row[0] . "'>";
199                 } 
200                 else 
201                 {
202                         echo "<option value='" . $row[0] . "'>";
203                 }
204                 echo $row[1] . "</option>\n";
205
206                 if ($selected_id == "") 
207                 {
208                         $selected_id = $row[0];
209                         $_POST[$name] = $selected_id;
210                 }
211         }
212
213         echo "</select>";
214         db_free_result($result);
215 }
216
217 function customer_branches_list_cells($label,$customer_id, $name, $selected_id, $all_option = true, $enabled=true, $submit_on_change=false)
218 {
219         if ($label != null)
220                 echo "<td>$label</td>\n";
221         echo "<td>";
222         customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
223         echo "</td>\n";
224 }
225
226 function customer_branches_list_row($label,$customer_id, $name, $selected_id, $all_option = true, $enabled=true, $submit_on_change=false)
227 {
228         echo "<tr>";
229         customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
230         echo "</tr>";
231 }
232
233 //------------------------------------------------------------------------------------------------
234
235 function locations_list($name, $selected_id, $all_option=false, $submit_on_change=false, $all_option_name="")
236 {
237         if ($submit_on_change == true)
238                 echo "<select name='$name' onchange='this.form.submit();'>";
239         else
240                 echo "<select name='$name'>";
241
242 //      if ($selected_id =="" AND isset($_SESSION['UserStockLocation']) AND $_SESSION['UserStockLocation'] !="") {
243 //              $selected_id = $_SESSION['UserStockLocation'];
244 //      }
245
246         $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
247         $result = db_query($sql);
248
249         if ($selected_id == null)
250                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
251         if ($all_option == true)
252         {
253                 echo "<option ";
254         if ($selected_id == reserved_words::get_all())
255              echo " selected ";
256                 echo " value='" . reserved_words::get_all(). "'>" . _("All Locations") . "</option>\n";
257
258                 if ($selected_id == "") {
259                         $selected_id = reserved_words::get_all();
260                 }
261         }
262
263         while ($row = db_fetch_row($result)) 
264         {
265                 if ($selected_id == $row[0]) 
266                 {
267                         echo "<option selected value='" . $row[0] . "'>";
268                 } 
269                 else 
270                 {
271                         echo "<option value='" . $row[0] . "'>";
272                 }
273                 echo $row[1] . "</option>\n";
274
275                 if ($selected_id == "") 
276                 {
277                         $selected_id = $row[0];
278                         $_POST[$name] = $selected_id;
279                 }
280         }
281
282         echo "</select>";
283
284         db_free_result($result);
285 }
286
287 function locations_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
288 {
289         if ($label != null)
290                 echo "<td>$label</td>\n";
291         echo "<td>";
292         locations_list($name, $selected_id, $all_option, $submit_on_change);
293         echo "</td>\n";
294 }
295
296 function locations_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
297 {
298         echo "<tr>";
299         locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
300         echo "</tr>\n";
301 }
302
303 //-----------------------------------------------------------------------------------------------
304
305 function currencies_list($name, &$selected_id, $submit_on_change=false)
306 {
307         if ($submit_on_change==true)
308                 echo "<select name='$name' onchange='this.form.submit();'>";
309         else
310                 echo "<select name='$name'>";
311
312         $company_currency = get_company_currency();
313
314         $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
315         $result = db_query($sql);
316
317         if ($selected_id == null)
318                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
319         while ($row = db_fetch_row($result)) 
320         {
321                 // default to the company currency
322                 if ($selected_id == "" && ($row[0] == $company_currency)) 
323                 {
324                         $selected_id = $row[0];
325                         $_POST[$name] = $selected_id;
326                 }
327
328                 if ($selected_id == $row[0]) 
329                 {
330                         echo "<option selected value='" . $row[0] . "'>";
331                 } 
332                 else 
333                 {
334                         echo "<option value='" . $row[0] . "'>";
335                 }
336                 echo $row[0] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
337         }
338
339         echo "</select>";
340         db_free_result($result);
341 }
342
343 function currencies_list_cells($label, $name, $selected_id)
344 {
345         if ($label != null)
346                 echo "<td>$label</td>\n";
347         echo "<td>";
348         currencies_list($name, $selected_id);
349         echo "</td>\n";
350 }
351
352 function currencies_list_row($label, $name, $selected_id)
353 {
354         echo "<tr>\n";
355         currencies_list_cells($label, $name, $selected_id);
356         echo "</tr>\n";
357 }
358
359 //---------------------------------------------------------------------------------------------------
360
361 function fiscalyears_list($name, &$selected_id, $submit_on_change=false)
362 {
363         if ($submit_on_change == true)
364                 echo "<select name='$name' onchange='this.form.submit();'>";
365         else
366                 echo "<select name='$name'>";
367
368         $company_year = get_company_pref('f_year');
369
370         $sql = "SELECT * FROM ".TB_PREF."fiscal_year ORDER BY begin";
371         $result = db_query($sql);
372
373         if ($selected_id == null)
374                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
375         while ($row = db_fetch_row($result)) 
376         {
377                 // default to the company current fiscal year
378                 if ($selected_id == "" && ($row[0] == $company_year)) 
379                 {
380                         $selected_id = $row[0];
381                         $_POST[$name] = $selected_id;
382                 }
383
384                 if ($selected_id == $row[0]) 
385                 {
386                         echo "<option selected value='" . $row[0] . "'>";
387                 } 
388                 else 
389                 {
390                         echo "<option value='" . $row[0] . "'>";
391                 }
392                 if ($row[3] == 0)
393                         $how = _('Active');
394                 else
395                         $how = _('Closed');
396                 $row[1] = sql2date($row[1]);    
397                 $row[2] = sql2date($row[2]);    
398                 echo $row[1] . "&nbsp;-&nbsp;" . $row[2] . "&nbsp;&nbsp;" . $how . "</option>\n";
399         }
400
401         echo "</select>";
402         db_free_result($result);
403 }
404
405 function fiscalyears_list_cells($label, $name, $selected_id)
406 {
407         if ($label != null)
408                 echo "<td>$label</td>\n";
409         echo "<td>";
410         fiscalyears_list($name, $selected_id);
411         echo "</td>\n";
412 }
413
414 function fiscalyears_list_row($label, $name, $selected_id)
415 {
416         echo "<tr>\n";
417         fiscalyears_list_cells($label, $name, $selected_id);
418         echo "</tr>\n";
419 }
420
421 //---------------------------------------------------------------------------------------------------
422
423 function simple_codeandname_list($sql, $name, &$selected_id,
424         $all_option=false, $all_option_name=null, $all_option_numeric=false, 
425         $submit_on_change=false, $returnzero=false)
426 {
427         if ($submit_on_change == true)
428                 echo "<select name='$name' onchange='this.form.submit();'>";
429         else
430                 echo "<select name='$name'>";
431
432         if ($selected_id == null)
433                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
434         if ($all_option == true)
435         {
436                 if ($returnzero)
437                         $reserved_word = 0;
438                 elseif ($all_option_numeric)
439                         $reserved_word = reserved_words::get_all_numeric();
440                 else
441                         $reserved_word = reserved_words::get_all();
442
443         if ($reserved_word == $selected_id)
444         {
445              echo "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
446         } 
447         else 
448         {
449              echo "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
450         }
451                 if ($selected_id == "") 
452                 {
453                         $selected_id =  $reserved_word;
454                 }
455         }
456
457         $result = db_query($sql);
458
459         while ($row = db_fetch_row($result)) 
460         {
461                 if ($selected_id == $row[0]) 
462                 {
463                         echo "<option selected value='" . $row[0] . "'>";
464                 } else {
465                         echo "<option value='" . $row[0] . "'>";
466                 }
467                 echo $row[1] . "</option>\n";
468
469                 if (!$returnzero && $selected_id == "") 
470                 {
471                         $selected_id = $row[0];
472                         $_POST[$name] = $selected_id;
473                 }
474         }
475
476         echo "</select>";
477         db_free_result($result);
478 }
479
480 //------------------------------------------------------------------------------------
481
482 function dimensions_list($name, &$selected_id, $no_option=false, $showname=null,
483         $submit_on_change=false, $showclosed=false, $showtype=1)
484 {
485         $sql = "SELECT id, CONCAT(reference,'  ',name) FROM ".TB_PREF."dimensions";
486         if ($showclosed || $showtype)
487         {
488                 $sql .= " WHERE";
489                 if ($showclosed)
490                         $sql .= " closed=0";
491                 if ($showclosed && $showtype)
492                         $sql .= " AND type_=$showtype";
493                 else if ($showtype)
494                         $sql .= " type_=$showtype";
495         }               
496         $sql .= " ORDER BY reference";  
497         simple_codeandname_list($sql, $name, &$selected_id, $no_option, $showname,      
498                 true, $submit_on_change, true);
499 }
500
501 function dimensions_list_cells($label, $name, $selected_id, $no_option=false, $showname=null, 
502         $showclosed=false, $showtype=0)
503 {
504         if ($label != null)
505                 echo "<td>$label</td>\n";
506         echo "<td>";
507         dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
508         echo "</td>\n";
509 }
510
511 function dimensions_list_row($label, $name, $selected_id, $no_option=false, $showname=null, 
512         $showclosed=false, $showtype=0)
513 {
514         echo "<tr>\n";
515         dimensions_list_cells($label, $name, $selected_id, $no_option, $showname, 
516                 $showclosed, $showtype);
517         echo "</tr>\n";
518 }
519
520 //---------------------------------------------------------------------------------------------------
521
522 function stock_items_list($name, $selected_id, $all_option=false, $submit_on_change=false, $extra="")
523 {
524         global $all_items;
525         if ($submit_on_change==true)
526                 echo "<select name='$name' onchange='this.form.submit();'>";
527         else if ($extra != "")  
528                 echo "<select name='$name' $extra>";
529         else
530                 echo "<select name='$name'>";
531
532         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
533                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id";
534         $result = db_query($sql);
535
536         if ($selected_id == null)
537                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
538         if (($all_option == true))
539         {
540         if ($all_items == $selected_id)
541         {
542              echo "<option selected value='$all_items'>" . _("All Items") . "</option>\n";
543         } 
544         else 
545         {
546              echo "<option value='$all_items'>" . _("All Items") . "</option>\n";
547         }
548                 if ($selected_id == "") 
549                 {
550                         $selected_id = $all_items;
551                 }
552         }
553
554         while ($row = db_fetch_row($result)) 
555         {
556                 if ($selected_id == $row[0]) 
557                 {
558                         echo "<option selected value='" . $row[0] . "'>";
559                 } 
560                 else 
561                 {
562                         echo "<option value='" . $row[0] . "'>";
563                 }
564                 echo (user_show_codes()?$row[0] . "&nbsp;-&nbsp;":"") . $row[2] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
565
566                 // if no initial selection - set the first item
567                 // do we want to do this for all lists ???? probably
568                 if ($selected_id == "") 
569                 {
570                         $selected_id = $row[0];
571                         $_POST[$name] = $selected_id;
572                 }
573         }
574
575         echo "</select>";
576         db_free_result($result);
577 }
578
579 function stock_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false, $extra="")
580 {
581         if ($label != null) 
582                 echo "<td>$label</td>\n";
583         echo "<td>";
584         stock_items_list($name, $selected_id, $all_option, $submit_on_change, $extra);
585         echo "</td>\n";
586 }
587
588 function stock_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
589 {
590         echo "<tr>\n";
591         stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
592         echo "</tr>\n";
593 }
594
595 //------------------------------------------------------------------------------------
596
597 function stock_bom_items_list($name, $selected_id, $all_option=false, $submit_on_change=false)
598 {
599         global $all_items;
600
601         if ($submit_on_change==true)
602                 echo "<select name='$name' onchange='this.form.submit();'>";
603         else
604                 echo "<select name='$name'>";
605
606         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
607                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
608                 AND (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='K')";
609         $result = db_query($sql);
610
611         if ($selected_id == null)
612                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
613         if (($all_option == true))
614         {
615         if ($all_items == $selected_id)
616         {
617              echo "<option selected value='$all_items'>" . _("All Items") . "</option>\n";
618         } 
619         else 
620         {
621              echo "<option value='$all_items'>" . _("All Items") . "</option>\n";
622         }
623                 if ($selected_id == "") 
624                 {
625                         $selected_id = $all_items;
626                 }
627         }
628
629         while ($row = db_fetch_row($result)) 
630         {
631                 if ($selected_id==$row[0]) 
632                 {
633                         echo "<option selected value='" . $row[0] . "'>";
634                 } 
635                 else 
636                 {
637                         echo "<option value='" . $row[0] . "'>";
638                 }
639                 echo (user_show_codes()?$row[0] . "&nbsp;-&nbsp;":"") . $row[2] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
640
641                 if ($selected_id == "") 
642                 {
643                         $selected_id = $row[0];
644                         $_POST[$name] = $selected_id;
645                 }
646         }
647
648         echo "</select>";
649         db_free_result($result);
650 }
651
652 function stock_bom_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
653 {
654         if ($label != null)
655                 echo "<td>$label</td>\n";
656         echo "<td>";
657         stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
658         echo "</td>\n";
659 }
660
661 function stock_bom_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
662 {
663         echo "<tr>\n";
664         stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
665         echo "</tr>\n";
666 }
667
668 //------------------------------------------------------------------------------------
669
670 function base_stock_items_list($sql, $name, &$selected_id,
671         $all_option=false, $all_option_name="", $submit_on_change=false, $extra="")
672 {
673         if ($submit_on_change==true)
674                 echo "<select name='$name' onchange='this.form.submit();'>";
675         else if ($extra != "")  
676                 echo "<select name='$name' $extra>";
677         else
678                 echo "<select name='$name'>";
679
680         $result = db_query($sql);
681
682         if ($selected_id == null)
683                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
684         if ($all_option == true)
685         {
686         if (reserved_words::get_all() == $selected_id)
687         {
688              echo "<option selected value='" . reserved_words::get_all(). "'>" . $all_option_name . "</option>\n";
689         } 
690         else 
691         {
692              echo "<option value='" . reserved_words::get_all(). "'>" . $all_option_name . "</option>\n";
693         }
694                 if ($selected_id == "") 
695                 {
696                         $selected_id =  reserved_words::get_all();
697                 }
698         }
699
700         while ($row = db_fetch_row($result)) 
701         {
702                 if ($selected_id == $row[0]) 
703                 {
704                         echo "<option selected value='" . $row[0] . "'>";
705                 } 
706                 else 
707                 {
708                         echo "<option value='" . $row[0] . "'>";
709                 }
710                 echo (user_show_codes()?$row[0] . "&nbsp;-&nbsp;":"") . $row[2] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
711
712                 if ($selected_id == "") 
713                 {
714                         $selected_id = $row[0];
715                         $_POST[$name] = $selected_id;
716                 }
717         }
718
719         echo "</select>";
720         db_free_result($result);
721 }
722
723 //------------------------------------------------------------------------------------
724
725 function stock_manufactured_items_list($name, $selected_id,
726         $all_option=false, $submit_on_change=false)
727 {
728         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
729                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
730                 AND (".TB_PREF."stock_master.mb_flag='M')";
731
732         base_stock_items_list($sql, $name, &$selected_id,       $all_option, _("All Items"),
733                 $submit_on_change);
734 }
735
736 function stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
737 {
738         if ($label != null)
739                 echo "<td>$label</td>\n";
740         echo "<td>";
741         stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
742         echo "</td>\n";
743 }
744
745 function stock_manufactured_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
746 {
747         echo "<tr>\n";
748         stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
749         echo "</tr>\n";
750 }
751
752 //------------------------------------------------------------------------------------
753
754 function stock_component_items_list($name, $parent_stock_id, &$selected_id,
755         $all_option=false, $submit_on_change=false)
756 {
757         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
758                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE
759                 ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
760                 AND stock_id != '$parent_stock_id'";
761
762         base_stock_items_list($sql, $name, &$selected_id,
763                 $all_option, _("All Items"), $submit_on_change);
764 }
765
766 //------------------------------------------------------------------------------------
767
768 function stock_purchasable_items_list($name, &$selected_id,
769         $all_option=false, $submit_on_change=false, $extra="")
770 {
771         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
772                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
773                 AND mb_flag !='M'";
774
775         base_stock_items_list($sql, $name, &$selected_id,
776                 $all_option, _("All Items"), $submit_on_change, $extra);
777 }
778
779 function stock_purchasable_items_list_cells($label, $name, &$selected_id, $all_option=false, $submit_on_change=false, $extra = "")
780 {
781         if ($label != null)
782                 echo "<td>$label</td>\n";
783         echo "<td>";
784         stock_purchasable_items_list($name, $selected_id, $all_option, $submit_on_change, $extra);
785         echo "</td>\n";
786 }
787
788 function stock_purchasable_items_list_row($label, $name, &$selected_id, $all_option=false, $submit_on_change=false)
789 {
790         echo "<tr>\n";
791         stock_purchasable_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
792         echo "</tr>\n";
793 }
794
795 //------------------------------------------------------------------------------------
796
797 function stock_costable_items_list($name, &$selected_id,
798         $all_option=false, $submit_on_change=false)
799 {
800         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
801                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
802                 AND mb_flag !='D'";
803
804         base_stock_items_list($sql, $name, &$selected_id,
805                 $all_option, _("All Items"), $submit_on_change);
806 }
807
808 //------------------------------------------------------------------------------------
809
810 function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
811 {
812         echo "<tr>";
813         if ($label != NULL)
814                 echo "<td>$label</td>\n";
815         echo "<td>";            
816         if ($enabled)
817                 echo "<select name='$name' onchange='this.form.submit();'>\n";
818         else
819                 echo "<select disabled name='$name'>\n";
820         if ($selected_id == null)
821                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
822         if ($selected_id == "")
823                 $_POST[$name] = $selected_id = "B";
824         echo "<option " . ($selected_id == 'M'?" selected ":"") . " value='M'>" . _("Manufactured"). "</option>\n";
825         echo "<option " . ($selected_id == 'B'?" selected ":"") . " value='B'>" . _("Purchased"). "</option>\n";
826         echo "<option " . ($selected_id == 'D'?" selected ":"") . " value='D'>" . _("Service"). "</option>\n";
827         echo "</select></td></tr>\n";
828 }
829
830 function stock_units_list_row($label, $name, $value, $enabled=true)
831 {
832         global $stock_units;
833
834         echo "<tr><td>$label</td>\n";
835         if ($enabled)
836                 echo "<td><select name='$name'>";
837         else
838                 echo "<td><select disabled name='$name'>";
839         
840         if ($value == null)
841                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
842         foreach ($stock_units as $unit) 
843         {
844                 if ($value == "")
845                         $_POST[$name] = $value = $unit;
846                 if ($value==$unit)
847                 {
848                         echo "<option selected value='$unit'>$unit</option>\n";
849                 } 
850                 else 
851                 {
852                         echo "<option value='$unit'>$unit</option>\n";
853                 }
854         }
855         echo "</select></td></tr>\n";
856 }
857
858 //------------------------------------------------------------------------------------
859
860 function tax_types_list($name, $selected_id,
861         $none_option=false, $none_option_name=null, $submit_on_change=false)
862 {
863         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."tax_types",
864                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
865 }
866
867 function tax_types_list_cells($label, $name, $selected_id, $none_option=false, 
868         $none_option_name=null, $submit_on_change=false)
869 {
870         if ($label != null)
871                 echo "<td>$label</td>\n";
872         echo "<td>";
873         tax_types_list($name, $selected_id, $none_option, $none_option_name, $submit_on_change);
874         echo "</td>\n";
875 }
876
877 function tax_types_list_row($label, $name, $selected_id, $none_option=false, 
878         $none_option_name=null, $submit_on_change=false)
879 {
880         echo "<tr>\n";
881         tax_types_list_cells($label, $name, $selected_id, $none_option, $none_option_name, $submit_on_change);
882         echo "</tr>\n";
883 }
884
885 //------------------------------------------------------------------------------------
886
887 function tax_groups_list($name, $selected_id,
888         $none_option=false, $none_option_name=null, $submit_on_change=false)
889 {
890         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."tax_groups ORDER BY id",
891                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
892 }
893
894 function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
895 {
896         if ($label != null)
897                 echo "<td>$label</td>\n";
898         echo "<td>";
899         tax_groups_list($name, $selected_id, false, null, $submit_on_change);
900         echo "</td>\n";
901 }
902
903 function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
904 {
905         echo "<tr>\n";
906         tax_groups_list_cells($label, $name, $selected_id, false, null, $submit_on_change);
907         echo "</tr>\n";
908 }
909
910 //------------------------------------------------------------------------------------
911
912 function item_tax_types_list($name, $selected_id)
913 {
914         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."item_tax_types ORDER BY id",
915                 $name, $selected_id);
916 }
917
918 function item_tax_types_list_cells($label, $name, $selected_id)
919 {
920         if ($label != null)
921                 echo "<td>$label</td>\n";
922         echo "<td>";
923         item_tax_types_list($name, $selected_id);
924         echo "</td>\n";
925 }
926
927 function item_tax_types_list_row($label, $name, $selected_id)
928 {
929         echo "<tr>\n";
930         item_tax_types_list_cells($label, $name, $selected_id);
931         echo "</tr>\n";
932 }
933
934 //------------------------------------------------------------------------------------
935
936 function shippers_list($name, $selected_id)
937 {
938         simple_codeandname_list("SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers",
939                 $name, $selected_id);
940 }
941
942 function shippers_list_cells($label, $name, $selected_id)
943 {
944         if ($label != null)
945                 echo "<td>$label</td>\n";
946         echo "<td>";
947         shippers_list($name, $selected_id);
948         echo "</td>\n";
949 }
950
951 function shippers_list_row($label, $name, $selected_id)
952 {
953         echo "<tr>\n";
954         shippers_list_cells($label, $name, $selected_id);
955         echo "</tr>\n";
956 }
957
958 //-------------------------------------------------------------------------------------
959
960 function sales_persons_list($name, $selected_id)
961 {
962         simple_codeandname_list("SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman",
963                 $name, $selected_id);
964 }
965
966 function sales_persons_list_cells($label, $name, $selected_id)
967 {
968         if ($label != null)
969                 echo "<td>$label</td>\n";
970         echo "<td>\n";
971         sales_persons_list($name, $selected_id);
972         echo "</td>\n";
973 }
974
975 function sales_persons_list_row($label, $name, $selected_id)
976 {
977         echo "<tr>\n";
978         sales_persons_list_cells($label, $name, $selected_id);
979         echo "</tr>\n";
980 }
981
982 //------------------------------------------------------------------------------------
983
984 function sales_areas_list($name, $selected_id)
985 {
986         simple_codeandname_list("SELECT area_code, description FROM ".TB_PREF."areas",
987                 $name, $selected_id);
988 }
989
990 function sales_areas_list_cells($label, $name, $selected_id)
991 {
992         if ($label != null)
993                 echo "<td>$label</td>\n";
994         echo "<td>";
995         sales_areas_list($name, $selected_id);
996         echo "</td>\n";
997 }
998
999 function sales_areas_list_row($label, $name, $selected_id)
1000 {
1001         echo "<tr>\n";
1002         sales_areas_list_cells($label, $name, $selected_id);
1003         echo "</tr>\n";
1004 }
1005
1006 //------------------------------------------------------------------------------------
1007
1008 function workorders_list($name, $selected_id)
1009 {
1010         simple_codeandname_list("SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0",
1011                 $name, $selected_id);
1012 }
1013
1014 function workorders_list_cells($label, $name, $selected_id)
1015 {
1016         if ($label != null)
1017                 echo "<td>$label</td>\n";
1018         echo "<td>";
1019         workorders_list($name, $selected_id);
1020         echo "</td>\n";
1021 }
1022
1023 function workorders_list_row($label, $name, $selected_id)
1024 {
1025         echo "<tr>\n";
1026         workorders_list_cells($label, $name, $selected_id);
1027         echo "</tr>\n";
1028 }
1029
1030 //------------------------------------------------------------------------------------
1031
1032 function payment_terms_list($name, $selected_id)
1033 {
1034         simple_codeandname_list("SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms",
1035                 $name, $selected_id);
1036 }
1037
1038 function payment_terms_list_cells($label, $name, $selected_id)
1039 {
1040         if ($label != null)
1041                 echo "<td>$label</td>\n";
1042         echo "<td>";
1043         payment_terms_list($name, $selected_id);
1044         echo "</td>\n";
1045 }
1046
1047 function payment_terms_list_row($label, $name, $selected_id)
1048 {
1049         echo "<tr>\n";
1050         payment_terms_list_cells($label, $name, $selected_id);
1051         echo "</tr>\n";
1052 }
1053
1054 //------------------------------------------------------------------------------------
1055
1056 function credit_status_list($name, $selected_id)
1057 {
1058         simple_codeandname_list("SELECT id, reason_description FROM ".TB_PREF."credit_status",
1059                 $name, $selected_id);
1060 }
1061
1062 function credit_status_list_cells($label, $name, $selected_id)
1063 {
1064         if ($label != null)
1065                 echo "<td>$label</td>\n";
1066         echo "<td>";
1067         credit_status_list($name, $selected_id);
1068         echo "</td>\n";
1069 }
1070
1071 function credit_status_list_row($label, $name, $selected_id)
1072 {
1073         echo "<tr>\n";
1074         credit_status_list_cells($label, $name, $selected_id);
1075         echo "</tr>\n";
1076 }
1077
1078 //-----------------------------------------------------------------------------------------------
1079
1080 function sales_types_list($name, $selected_id)
1081 {
1082         simple_codeandname_list("SELECT id, sales_type FROM ".TB_PREF."sales_types",
1083                 $name, $selected_id);
1084 }
1085
1086 function sales_types_list_cells($label, $name, $selected_id)
1087 {
1088         if ($label != null)
1089                 echo "<td>$label</td>\n";
1090         echo "<td>";
1091         sales_types_list($name, $selected_id);
1092         echo "</td>\n";
1093 }
1094
1095 function sales_types_list_row($label, $name, $selected_id)
1096 {
1097         echo "<tr>\n";
1098         sales_types_list_cells($label, $name, $selected_id);
1099         echo "</tr>\n";
1100 }
1101
1102 //-----------------------------------------------------------------------------------------------
1103
1104 function movement_types_list($name, $selected_id)
1105 {
1106         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."movement_types",
1107                 $name, $selected_id);
1108 }
1109
1110 function movement_types_list_cells($label, $name, $selected_id)
1111 {
1112         if ($label != null)
1113                 echo "<td>$label</td>\n";
1114         echo "<td>";
1115         movement_types_list($name, $selected_id);
1116         echo "</td>\n";
1117 }
1118
1119 function movement_types_list_row($label, $name, $selected_id)
1120 {
1121         echo "<tr>\n";
1122         movement_types_list_cells($label, $name, $selected_id);
1123         echo "</tr>\n";
1124 }
1125
1126 //-----------------------------------------------------------------------------------------------
1127
1128 function bank_trans_types_list($name, $selected_id)
1129 {
1130         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."bank_trans_types",
1131                 $name, $selected_id);
1132 }
1133
1134 function bank_trans_types_list_cells($label, $name, $selected_id)
1135 {
1136         if ($label != null)
1137                 echo "<td>$label</td>\n";
1138         echo "<td>";
1139         bank_trans_types_list($name, $selected_id);
1140         echo "</td>\n";
1141 }
1142
1143 function bank_trans_types_list_row($label, $name, $selected_id)
1144 {
1145         echo "<tr>\n";
1146         bank_trans_types_list_cells($label, $name, $selected_id);
1147         echo "</tr>\n";
1148 }
1149
1150 //-----------------------------------------------------------------------------------------------
1151
1152 function workcenter_list($name, $selected_id, $all_option=false)
1153 {
1154         global $all_items;
1155         echo "<select name='$name'>";
1156
1157         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1158         $result = db_query($sql);
1159
1160         if ($selected_id == null)
1161                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1162         if ($all_option == true)
1163         {
1164         if ($all_items == $selected_id)
1165         {
1166              echo "<option selected value='$all_items'>" . _("All Work Centres") . "</option>\n";
1167         } 
1168         else 
1169         {
1170              echo "<option value='$all_items'>" . _("All Work Centres") . "</option>\n";
1171         }
1172         }
1173
1174         while ($row = db_fetch_row($result)) 
1175         {
1176                 if ($selected_id == $row[0]) 
1177                 {
1178                         echo "<option selected value='" . $row[0] . "'>";
1179                 } 
1180                 else 
1181                 {
1182                         echo "<option value='" . $row[0] . "'>";
1183                 }
1184                 echo $row[1] . "</option>\n";
1185         }
1186
1187         echo "</select>";
1188         db_free_result($result);
1189 }
1190
1191 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1192 {
1193         if ($label != null)
1194                 echo "<td>$label</td>\n";
1195         echo "<td>";
1196         workcenter_list($name, $selected_id, $all_option);
1197         echo "</td>\n";
1198 }
1199
1200 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1201 {
1202         echo "<tr>\n";
1203         workcenter_list_cells($label, $name, $selected_id, $all_option);
1204         echo "</tr>\n";
1205 }
1206
1207 //-----------------------------------------------------------------------------------------------
1208
1209 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1210 {
1211         if ($submit_on_change==true)
1212                 echo "<select name='$name' onchange='this.form.submit();'>";
1213         else
1214                 echo "<select name='$name'>";
1215
1216         $company_currency = get_company_currency();
1217
1218         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1219                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1220                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1221         $result = db_query($sql);
1222
1223         if ($selected_id == null)
1224                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1225         while ($row = db_fetch_row($result)) 
1226         {
1227                 if ($selected_id == $row[0]) 
1228                 {
1229                         echo "<option selected value='" . $row[0] . "'>";
1230                 } 
1231                 else 
1232                 {
1233                         echo "<option value='" . $row[0] . "'>";
1234                 }
1235                 echo $row[1];
1236                 if ($company_currency != $row[2])
1237                         echo "&nbsp;-&nbsp;" . $row[2];
1238                 echo  "</option>\n";
1239                 if ($selected_id == "")
1240                 {
1241                         $selected_id = $row[0];
1242                         $_POST[$name] = $selected_id;
1243                 }       
1244         }
1245
1246         echo "</select>";
1247         db_free_result($result);
1248 }
1249
1250 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1251 {
1252         if ($label != null)
1253                 echo "<td>$label</td>\n";
1254         echo "<td>";
1255         bank_accounts_list($name, $selected_id, $submit_on_change);
1256         echo "</td>\n";
1257 }
1258
1259 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1260 {
1261         echo "<tr>\n";
1262         bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1263         echo "</tr>\n";
1264 }
1265
1266 //-----------------------------------------------------------------------------------------------
1267
1268 function class_list($name, $selected_id, $submit_on_change=false)
1269 {
1270         if ($submit_on_change==true)
1271                 echo "<select name='$name' onchange='this.form.submit();'>";
1272         else
1273                 echo "<select name='$name'>";
1274
1275         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1276         $result = db_query($sql);
1277
1278         if ($selected_id == null)
1279                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1280         while ($row = db_fetch_row($result)) 
1281         {
1282                 if ($selected_id == $row[0]) 
1283                 {
1284                         echo "<option selected value='" . $row[0] . "'>";
1285                 } 
1286                 else 
1287                 {
1288                         echo "<option value='" . $row[0] . "'>";
1289                 }
1290                 echo $row[1] . "</option>\n";
1291                 if ($selected_id == "")
1292                 {
1293                         $selected_id = $row[0];
1294                         $_POST[$name] = $selected_id;
1295                 }       
1296         }
1297
1298         echo "</select>";
1299         db_free_result($result);
1300 }
1301
1302 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1303 {
1304         if ($label != null)
1305                 echo "<td>$label</td>\n";
1306         echo "<td>";
1307         class_list($name, $selected_id, $submit_on_change);
1308         echo "</td>\n";
1309 }
1310
1311 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1312 {
1313         echo "<tr>\n";
1314         class_list_cells($label, $name, $selected_id, $submit_on_change);
1315         echo "</tr>\n";
1316 }
1317
1318 //-----------------------------------------------------------------------------------------------
1319
1320 function stock_categories_list($name, $selected_id)
1321 {
1322         simple_codeandname_list("SELECT category_id, description FROM ".TB_PREF."stock_category
1323                 ORDER BY category_id", $name, $selected_id);
1324 }
1325
1326 function stock_categories_list_cells($label, $name, $selected_id)
1327 {
1328         if ($label != null)
1329                 echo "<td>$label</td>\n";
1330         echo "<td>";
1331         stock_categories_list($name, $selected_id);
1332         echo "</td>\n";
1333 }
1334
1335 function stock_categories_list_row($label, $name, $selected_id)
1336 {
1337         echo "<tr>\n";
1338         stock_categories_list_cells($label, $name, $selected_id);
1339         echo "</tr>\n";
1340 }
1341
1342 //-----------------------------------------------------------------------------------------------
1343
1344 function gl_account_types_list($name, $selected_id, $all_option, $all_option_name,
1345         $all_option_numeric)
1346 {
1347         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."chart_types ORDER BY id",
1348                 $name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1349 }
1350
1351 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1352         $all_option_numeric=false)
1353 {
1354         if ($label != null)
1355                 echo "<td>$label</td>\n";
1356         echo "<td>";
1357         gl_account_types_list($name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1358         echo "</td>\n";
1359 }
1360
1361 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1362         $all_option_numeric=false)
1363 {
1364         echo "<tr>\n";
1365         gl_account_types_list_cells($label, $name, $selected_id, $all_option, 
1366                 $all_option_name, $all_option_numeric);
1367         echo "</tr>\n";
1368 }
1369
1370 //-----------------------------------------------------------------------------------------------
1371
1372 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false, 
1373         $show_group=false, $onchange="")
1374 {
1375         echo "<select name='$name'";
1376         if ($onchange != "")
1377                 echo " onchange='$onchange'";
1378         echo ">";
1379
1380         if ($skip_bank_accounts)
1381                 $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name
1382                         FROM (".TB_PREF."chart_master,".TB_PREF."chart_types) LEFT JOIN ".TB_PREF."bank_accounts ON ".TB_PREF."chart_master.account_code=".TB_PREF."bank_accounts.account_code
1383             WHERE ".TB_PREF."bank_accounts.account_code IS NULL
1384                         AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1385                         ORDER BY account_code;";
1386         else
1387                 $sql = "SELECT account_code, account_name,".TB_PREF."chart_types.name
1388                         FROM ".TB_PREF."chart_master, ".TB_PREF."chart_types
1389                         WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1390                         ORDER BY account_code";
1391
1392         if ($selected_id == null)
1393                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1394         $result = db_query($sql, "query chart master");
1395
1396         while ($row = db_fetch_row($result)) 
1397         {
1398                 if ($selected_id == $row[0]) 
1399                 {
1400                         echo "<option selected value='" . $row[0] . "'>";
1401                 } 
1402                 else 
1403                 {
1404                         echo "<option value='" . $row[0] . "'>";
1405                 }
1406                 //echo str_pad($row[0],6,'0', STR_PAD_LEFT) .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1407                 if ($show_group)
1408                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1409                 else    
1410                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1411
1412                 if ($selected_id == "")
1413                 {
1414                         $selected_id = $row[0];
1415                         $_POST[$name] = $selected_id;
1416                 }       
1417         }
1418
1419         echo "</select>";
1420         db_free_result($result);
1421 }
1422
1423 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1424         $show_group=false, $onchange="")
1425 {
1426         if ($label != null)
1427                 echo "<td>$label</td>\n";
1428         echo "<td>";
1429         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $onchange);
1430         echo "</td>\n";
1431 }
1432
1433 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1434         $show_group=false, $onchange="")
1435 {
1436         echo "<tr>\n";
1437         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts, 
1438                 $show_group, $onchange);
1439         echo "</tr>\n";
1440 }
1441
1442 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1443 {
1444         if ($submit_on_change == true)
1445                 echo "<select name='$name' onchange='this.form.submit();'>";
1446         else
1447                 echo "<select name='$name'>";
1448
1449         if (strlen($name_yes) == 0)     
1450         {
1451                 unset($name_yes);
1452         }
1453         if (strlen($name_no) == 0)      
1454         {
1455                 unset($name_no);
1456         }
1457
1458         if ($selected_id == null)
1459                 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1460     if ($selected_id == 0)
1461         echo "<option value=1>";
1462     else
1463         echo "<option selected value=1>";
1464         if (!isset($name_yes)) 
1465                 echo _("Yes") . "</option>\n"; 
1466         else 
1467                 echo $name_yes . "</option>\n"; 
1468         if ($selected_id == 0)
1469                 echo "<option selected value=0>";
1470         else    
1471         echo "<option value=0>";
1472         if (!isset($name_no)) 
1473                 echo _("No") . "</option>\n"; 
1474         else 
1475                 echo $name_no . "</option>\n"; 
1476         echo "</select>";
1477 }
1478
1479 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1480 {
1481         if ($label != null)
1482                 echo "<td>$label</td>\n";
1483         echo "<td>";
1484         yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1485         echo "</td>\n";
1486 }
1487
1488 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1489 {
1490         echo "<tr>\n";
1491         yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1492         echo "</tr>\n";
1493 }
1494
1495 //------------------------------------------------------------------------------------------------
1496
1497 function languages_list($name, &$selected_id)
1498 {
1499         global $installed_languages;
1500
1501         echo "<select name='$name'>";
1502
1503         if ($selected_id == null)
1504                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1505         foreach ($installed_languages as $lang) 
1506         {
1507                 echo "<option ";
1508                 if ($selected_id == $lang['code']) 
1509                         echo "selected ";
1510                 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1511         }
1512 }
1513
1514 function languages_list_cells($label, $name, $selected_id)
1515 {
1516         if ($label != null)
1517                 echo "<td>$label</td>\n";
1518         echo "<td>";
1519         languages_list($name, $selected_id);
1520         echo "</td>\n";
1521 }
1522
1523 function languages_list_row($label, $name, $selected_id)
1524 {
1525         echo "<tr>\n";
1526         languages_list_cells($label, $name, $selected_id);
1527         echo "</tr>\n";
1528 }
1529
1530 //------------------------------------------------------------------------------------------------
1531
1532 function bank_account_types_list($name, &$selected_id)
1533 {
1534         $bank_account_types = bank_account_types::get_all();
1535
1536         echo "<select name='$name'>";
1537
1538         if ($selected_id == null)
1539                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1540         foreach ($bank_account_types as $type) 
1541         {
1542         echo "<option ";
1543         if ($selected_id == "" || $selected_id == $type['id']) 
1544                 echo "selected ";
1545         echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1546         }
1547 }
1548
1549 function bank_account_types_list_cells($label, $name, $selected_id)
1550 {
1551         if ($label != null)
1552                 echo "<td>$label</td>\n";
1553         echo "<td>";
1554         bank_account_types_list($name, $selected_id);
1555         echo "</td>\n";
1556 }
1557
1558 function bank_account_types_list_row($label, $name, $selected_id)
1559 {
1560         echo "<tr>\n";
1561         bank_account_types_list_cells($label, $name, $selected_id);
1562         echo "</tr>\n";
1563 }
1564
1565 //------------------------------------------------------------------------------------------------
1566
1567 function payment_person_types_list($name, $selected_id, $related=null)
1568 {
1569         $types = payment_person_types::get_all();
1570
1571         echo "<select name='$name'";
1572         if ($related)
1573                 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1574         echo ">";
1575
1576         if ($selected_id == null)
1577                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1578         foreach ($types as $type) 
1579         {
1580                 if (payment_person_types::has_items($type['id'])) 
1581                 {
1582                         if ($selected_id == "")
1583                                 $_POST[$name] = $selected_id = $type['id'];
1584                     echo "<option ";
1585                 if ($selected_id == $type['id']) 
1586                         echo "selected ";
1587                     echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1588                 }
1589         }
1590 }
1591
1592 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1593 {
1594         if ($label != null)
1595                 echo "<td>$label</td>\n";
1596         echo "<td>";
1597         payment_person_types_list($name, $selected_id, $related);
1598         echo "</td>\n";
1599 }
1600
1601 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1602 {
1603         echo "<tr>\n";
1604         payment_person_types_list_cells($label, $name, $selected_id, $related);
1605         echo "</tr>\n";
1606 }
1607
1608 //------------------------------------------------------------------------------------------------
1609
1610 function wo_types_list($name, &$selected_id)
1611 {
1612         $types = wo_types::get_all();
1613
1614         echo "<select name='$name' onchange='this.form.submit();'>";
1615
1616         if ($selected_id == null)
1617                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1618         foreach ($types as $type) 
1619         {
1620             echo "<option ";
1621             if ($selected_id == $type['id']) 
1622                 echo "selected ";
1623             echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1624         }
1625         echo "</select>";
1626 }
1627
1628 function wo_types_list_row($label, $name, &$selected_id)
1629 {
1630         echo "<tr><td>$label</td><td>\n";
1631         wo_types_list($name, $selected_id);
1632         echo "</td></tr>\n";
1633 }
1634
1635 //------------------------------------------------------------------------------------------------
1636
1637 function dateformats_list_row($label, $name, $value)
1638 {
1639         global $dateformats;
1640
1641         echo "<tr><td>$label</td>\n";
1642         echo "<td><select name='$name'>";
1643
1644         if ($value == null)
1645                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1646         $counter = 0;
1647         foreach ($dateformats as $df) 
1648         {
1649
1650                 if ($value==$counter)
1651                 {
1652                         echo "<option selected value='$counter'>$df</option>\n";
1653                 } 
1654                 else 
1655                 {
1656                         echo "<option value='$counter'>$df</option>\n";
1657                 }
1658                 $counter++;
1659         }
1660         echo "</select></td></tr>\n";
1661 }
1662
1663 function dateseps_list_row($label, $name, $value)
1664 {
1665         global $dateseps;
1666
1667         echo "<tr><td>$label</td>\n";
1668         echo "<td><select name='$name'>";
1669
1670         if ($value == null)
1671                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1672         $counter = 0;
1673         foreach ($dateseps as $ds) 
1674         {
1675
1676                 if ($value==$counter)
1677                 {
1678                         echo "<option selected value='$counter'>$ds</option>\n";
1679                 } 
1680                 else 
1681                 {
1682                         echo "<option value='$counter'>$ds</option>\n";
1683                 }
1684                 $counter++;
1685         }
1686         echo "</select></td></tr>\n";
1687 }
1688
1689 function thoseps_list_row($label, $name, $value)
1690 {
1691         global $thoseps;
1692
1693         echo "<tr><td>$label</td>\n";
1694         echo "<td><select name='$name'>";
1695
1696         if ($value == null)
1697                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1698         $counter = 0;
1699         foreach ($thoseps as $ts) 
1700         {
1701
1702                 if ($value==$counter)
1703                 {
1704                         echo "<option selected value='$counter'>$ts</option>\n";
1705                 } 
1706                 else 
1707                 {
1708                         echo "<option value='$counter'>$ts</option>\n";
1709                 }
1710                 $counter++;
1711         }
1712         echo "</select></td></tr>\n";
1713 }
1714
1715 function decseps_list_row($label, $name, $value)
1716 {
1717         global $decseps;
1718
1719         echo "<tr><td>$label</td>\n";
1720         echo "<td><select name='$name'>";
1721
1722         if ($value == null)
1723                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1724         $counter = 0;
1725         foreach ($decseps as $ds) 
1726         {
1727
1728                 if ($value==$counter)
1729                 {
1730                         echo "<option selected value='$counter'>$ds</option>\n";
1731                 } 
1732                 else 
1733                 {
1734                         echo "<option value='$counter'>$ds</option>\n";
1735                 }
1736                 $counter++;
1737         }
1738         echo "</select></td></tr>\n";
1739 }
1740
1741 function themes_list_row($label, $name, $value)
1742 {
1743         global $themes;
1744
1745         echo "<tr><td>$label</td>\n";
1746         echo "<td><select name='$name'>";
1747
1748         if ($value == null)
1749                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1750         foreach ($themes as $th) 
1751         {
1752
1753                 if ($value==$th)
1754                 {
1755                         echo "<option selected value='$th'>$th</option>\n";
1756                 } 
1757                 else 
1758                 {
1759                         echo "<option value='$th'>$th</option>\n";
1760                 }
1761         }
1762         echo "</select></td></tr>\n";
1763 }
1764
1765 function pagesizes_list_row($label, $name, $value)
1766 {
1767         global $pagesizes;
1768
1769         echo "<tr><td>$label</td>\n";
1770         echo "<td><select name='$name'>";
1771
1772         if ($value == null)
1773                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1774         foreach ($pagesizes as $pz) 
1775         {
1776
1777                 if ($value==$pz)
1778                 {
1779                         echo "<option selected value='$pz'>$pz</option>\n";
1780                 } 
1781                 else 
1782                 {
1783                         echo "<option value='$pz'>$pz</option>\n";
1784                 }
1785         }
1786         echo "</select></td></tr>\n";
1787 }
1788
1789 function security_headings_list_row($label, $name, $value)
1790 {
1791         global $security_headings;
1792
1793         echo "<tr><td>$label</td>\n";
1794         echo "<td><select name='$name'>";
1795
1796         if ($value == null)
1797                 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
1798         $counter=0;
1799         foreach ($security_headings as $sh) 
1800         {
1801
1802                 if ($value==$counter)
1803                 {
1804                         echo "<option selected value='$counter'>$sh</option>\n";
1805                 } 
1806                 else 
1807                 {
1808                         echo "<option value='$counter'>$sh</option>\n";
1809                 }
1810                 $counter++;
1811         }
1812         echo "</select></td></tr>\n";
1813 }
1814
1815 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
1816 {
1817         global $systypes_array;
1818
1819         if ($label != null)
1820                 echo "<td>$label</td>\n";
1821     echo "<td><select name='$name'";
1822     if (submit_on_change)
1823         echo " onchange='this.form.submit();'>";
1824     else
1825         echo ">";
1826         if ($value == null)
1827                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1828     foreach ($systypes_array as $key=>$type)
1829     {
1830
1831                 if ($value==$key)
1832                 {
1833                         echo "<option selected value='$key'>".$type['name']."</option>\n";
1834                 } 
1835                 else 
1836                 {
1837                         echo "<option value='$key'>".$type['name']."</option>\n";
1838                 }
1839     }
1840     echo "</select></td>\n";
1841 }
1842
1843 function systypes_list_row($label, $name, $value, $submit_on_change=false)
1844 {
1845         echo "<tr>\n";
1846         systypes_list_cells($label, $name, $value, $submit_on_change);
1847         echo "</tr>\n";
1848 }
1849
1850 function cust_allocations_list_cells($label, $name, $selected)
1851 {
1852         if ($label != null)
1853                 label_cell($label);
1854         if ($selected == null)
1855                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1856         echo "<td><select name='$name'>";
1857         echo "<option " . ($selected == reserved_words::get_all()?" selected ":"") . " value='" . reserved_words::get_all(). "'>" . _("All Types"). "</option>\n";
1858         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
1859         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1860         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1861         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1862         echo "</select></td>\n";
1863 }
1864
1865 function supp_allocations_list_cells($name, $selected)
1866 {
1867         if ($selected == null)
1868                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1869         echo "<td><select name='$name'>";
1870         echo "<option " . ($selected == reserved_words::get_all()?" selected ":"") . " value='" . reserved_words::get_all(). "'>" . _("All Types"). "</option>\n";
1871         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Invoices"). "</option>\n";
1872         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1873         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1874         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1875         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Overdue Credit Notes"). "</option>\n";
1876         echo "</select></td>\n";
1877 }
1878
1879 function policy_list_cells($label, $name, $selected)
1880 {
1881         if ($selected == null)
1882         {
1883                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1884                 if ($selected == "")    
1885                         $_POST[$name] = $selected;
1886         }               
1887         if ($label != null)
1888                 label_cell($label);
1889         echo "<td><select name='$name'>";
1890         echo "<option " . ($selected == ''?" selected ":"") . " value=''>" . _("Automatically put balance on back order"). "</option>\n";
1891         echo "<option " . ($selected == 'CAN'?" selected ":"") . " value='CAN'>" . _("Cancel any quantites not delivered"). "</option>\n";
1892         echo "</select></td>\n";
1893 }
1894
1895 function policy_list_row($label, $name, $selected)
1896 {
1897         echo "<tr>\n";
1898         policy_list_cells($label, $name, $selected);
1899         echo "</tr>\n";
1900 }
1901
1902 function credit_type_list_cells($label, $name, $selected, $submit_on_change=false)
1903 {
1904         if ($selected == null)
1905         {
1906                 $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]);
1907                 if ($selected == "Return")      
1908                         $_POST[$name] = $selected;
1909         }               
1910         if ($label != null)
1911                 label_cell($label);
1912     echo "<td><select name='$name'";
1913     if ($submit_on_change)
1914         echo " onchange='this.form.submit();'>";
1915     else
1916         echo ">";
1917         echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
1918         echo "<option " . ($selected == 'WriteOff'?" selected ":"") . " value='WriteOff'>" . _("Items Written Off"). "</option>\n";
1919         echo "</select></td>\n";
1920 }
1921
1922 function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
1923 {
1924         echo "<tr>\n";
1925         credit_type_list_cells($label, $name, $selected, $submit_on_change);
1926         echo "</tr>\n";
1927 }
1928
1929 function number_list($name, $selected, $from, $to, $firstlabel="")
1930 {
1931         if ($selected == null)
1932         {
1933                 $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]);
1934                 if ($selected == $from) 
1935                         $_POST[$name] = $selected;
1936         }               
1937         echo "<select name='$name'>";
1938         for ($i = $from; $i <= $to; $i++)
1939     {
1940                 if ($i == 0 && $firstlabel != "")
1941                         $label = $firstlabel;
1942                 else
1943                         $label = $i;
1944                 if ($selected == $i)
1945                 {
1946                         echo "<option selected value='$i'>$label</option>\n";
1947                 } 
1948                 else 
1949                 {
1950                         echo "<option value='$i'>$label</option>\n";
1951                 }
1952     }
1953         echo "</select>\n";
1954 }
1955
1956 function number_list_cells($label, $name, $selected, $from, $to)
1957 {
1958         if ($label != null)
1959                 label_cell($label);
1960         echo "<td>\n";
1961         number_list($name, $selected, $from, $to);
1962         echo "</td>\n";
1963 }       
1964
1965 function number_list_row($label, $name, $selected, $from, $to)
1966 {
1967         echo "<tr>\n";
1968         number_list_cells($label, $name, $selected, $from, $to);
1969         echo "</tr>\n";
1970 }
1971 ?>