f0c268e91e66c98e9295813f260c7e89e7135b91
[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                 echo $row[1] . "&nbsp;-&nbsp;" . $row[2] . "&nbsp;&nbsp;" . $how . "</option>\n";
397         }
398
399         echo "</select>";
400         db_free_result($result);
401 }
402
403 function fiscalyears_list_cells($label, $name, $selected_id)
404 {
405         if ($label != null)
406                 echo "<td>$label</td>\n";
407         echo "<td>";
408         fiscalyears_list($name, $selected_id);
409         echo "</td>\n";
410 }
411
412 function fiscalyears_list_row($label, $name, $selected_id)
413 {
414         echo "<tr>\n";
415         fiscalyears_list_cells($label, $name, $selected_id);
416         echo "</tr>\n";
417 }
418
419 //---------------------------------------------------------------------------------------------------
420
421 function simple_codeandname_list($sql, $name, &$selected_id,
422         $all_option=false, $all_option_name=null, $all_option_numeric=false, 
423         $submit_on_change=false, $returnzero=false)
424 {
425         if ($submit_on_change == true)
426                 echo "<select name='$name' onchange='this.form.submit();'>";
427         else
428                 echo "<select name='$name'>";
429
430         if ($selected_id == null)
431                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
432         if ($all_option == true)
433         {
434                 if ($returnzero)
435                         $reserved_word = 0;
436                 elseif ($all_option_numeric)
437                         $reserved_word = reserved_words::get_all_numeric();
438                 else
439                         $reserved_word = reserved_words::get_all();
440
441         if ($reserved_word == $selected_id)
442         {
443              echo "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
444         } 
445         else 
446         {
447              echo "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
448         }
449                 if ($selected_id == "") 
450                 {
451                         $selected_id =  $reserved_word;
452                 }
453         }
454
455         $result = db_query($sql);
456
457         while ($row = db_fetch_row($result)) 
458         {
459                 if ($selected_id == $row[0]) 
460                 {
461                         echo "<option selected value='" . $row[0] . "'>";
462                 } else {
463                         echo "<option value='" . $row[0] . "'>";
464                 }
465                 echo $row[1] . "</option>\n";
466
467                 if (!$returnzero && $selected_id == "") 
468                 {
469                         $selected_id = $row[0];
470                         $_POST[$name] = $selected_id;
471                 }
472         }
473
474         echo "</select>";
475         db_free_result($result);
476 }
477
478 //------------------------------------------------------------------------------------
479
480 function dimensions_list($name, &$selected_id, $no_option=false, $showname=null,
481         $submit_on_change=false, $showclosed=false, $showtype=1)
482 {
483         $sql = "SELECT id, CONCAT(reference,'  ',name) FROM ".TB_PREF."dimensions";
484         if ($showclosed || $showtype)
485         {
486                 $sql .= " WHERE";
487                 if ($showclosed)
488                         $sql .= " closed=0";
489                 if ($showclosed && $showtype)
490                         $sql .= " AND type_=$showtype";
491                 else if ($showtype)
492                         $sql .= " type_=$showtype";
493         }               
494         $sql .= " ORDER BY reference";  
495         simple_codeandname_list($sql, $name, &$selected_id, $no_option, $showname,      
496                 true, $submit_on_change, true);
497 }
498
499 function dimensions_list_cells($label, $name, $selected_id, $no_option=false, $showname=null, 
500         $showclosed=false, $showtype=0)
501 {
502         if ($label != null)
503                 echo "<td>$label</td>\n";
504         echo "<td>";
505         dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
506         echo "</td>\n";
507 }
508
509 function dimensions_list_row($label, $name, $selected_id, $no_option=false, $showname=null, 
510         $showclosed=false, $showtype=0)
511 {
512         echo "<tr>\n";
513         dimensions_list_cells($label, $name, $selected_id, $no_option, $showname, 
514                 $showclosed, $showtype);
515         echo "</tr>\n";
516 }
517
518 //---------------------------------------------------------------------------------------------------
519
520 function stock_items_list($name, $selected_id, $all_option=false, $submit_on_change=false, $extra="")
521 {
522         global $all_items;
523         if ($submit_on_change==true)
524                 echo "<select name='$name' onchange='this.form.submit();'>";
525         else if ($extra != "")  
526                 echo "<select name='$name' $extra>";
527         else
528                 echo "<select name='$name'>";
529
530         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
531                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id";
532         $result = db_query($sql);
533
534         if ($selected_id == null)
535                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
536         if (($all_option == true))
537         {
538         if ($all_items == $selected_id)
539         {
540              echo "<option selected value='$all_items'>" . _("All Items") . "</option>\n";
541         } 
542         else 
543         {
544              echo "<option value='$all_items'>" . _("All Items") . "</option>\n";
545         }
546                 if ($selected_id == "") 
547                 {
548                         $selected_id = $all_items;
549                 }
550         }
551
552         while ($row = db_fetch_row($result)) 
553         {
554                 if ($selected_id == $row[0]) 
555                 {
556                         echo "<option selected value='" . $row[0] . "'>";
557                 } 
558                 else 
559                 {
560                         echo "<option value='" . $row[0] . "'>";
561                 }
562                 echo (user_show_codes()?$row[0] . "&nbsp;-&nbsp;":"") . $row[2] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
563
564                 // if no initial selection - set the first item
565                 // do we want to do this for all lists ???? probably
566                 if ($selected_id == "") 
567                 {
568                         $selected_id = $row[0];
569                         $_POST[$name] = $selected_id;
570                 }
571         }
572
573         echo "</select>";
574         db_free_result($result);
575 }
576
577 function stock_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false, $extra="")
578 {
579         if ($label != null) 
580                 echo "<td>$label</td>\n";
581         echo "<td>";
582         stock_items_list($name, $selected_id, $all_option, $submit_on_change, $extra);
583         echo "</td>\n";
584 }
585
586 function stock_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
587 {
588         echo "<tr>\n";
589         stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
590         echo "</tr>\n";
591 }
592
593 //------------------------------------------------------------------------------------
594
595 function stock_bom_items_list($name, $selected_id, $all_option=false, $submit_on_change=false)
596 {
597         global $all_items;
598
599         if ($submit_on_change==true)
600                 echo "<select name='$name' onchange='this.form.submit();'>";
601         else
602                 echo "<select name='$name'>";
603
604         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
605                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
606                 AND (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='K')";
607         $result = db_query($sql);
608
609         if ($selected_id == null)
610                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
611         if (($all_option == true))
612         {
613         if ($all_items == $selected_id)
614         {
615              echo "<option selected value='$all_items'>" . _("All Items") . "</option>\n";
616         } 
617         else 
618         {
619              echo "<option value='$all_items'>" . _("All Items") . "</option>\n";
620         }
621                 if ($selected_id == "") 
622                 {
623                         $selected_id = $all_items;
624                 }
625         }
626
627         while ($row = db_fetch_row($result)) 
628         {
629                 if ($selected_id==$row[0]) 
630                 {
631                         echo "<option selected value='" . $row[0] . "'>";
632                 } 
633                 else 
634                 {
635                         echo "<option value='" . $row[0] . "'>";
636                 }
637                 echo (user_show_codes()?$row[0] . "&nbsp;-&nbsp;":"") . $row[2] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
638
639                 if ($selected_id == "") 
640                 {
641                         $selected_id = $row[0];
642                         $_POST[$name] = $selected_id;
643                 }
644         }
645
646         echo "</select>";
647         db_free_result($result);
648 }
649
650 function stock_bom_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
651 {
652         if ($label != null)
653                 echo "<td>$label</td>\n";
654         echo "<td>";
655         stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
656         echo "</td>\n";
657 }
658
659 function stock_bom_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
660 {
661         echo "<tr>\n";
662         stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
663         echo "</tr>\n";
664 }
665
666 //------------------------------------------------------------------------------------
667
668 function base_stock_items_list($sql, $name, &$selected_id,
669         $all_option=false, $all_option_name="", $submit_on_change=false, $extra="")
670 {
671         if ($submit_on_change==true)
672                 echo "<select name='$name' onchange='this.form.submit();'>";
673         else if ($extra != "")  
674                 echo "<select name='$name' $extra>";
675         else
676                 echo "<select name='$name'>";
677
678         $result = db_query($sql);
679
680         if ($selected_id == null)
681                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
682         if ($all_option == true)
683         {
684         if (reserved_words::get_all() == $selected_id)
685         {
686              echo "<option selected value='" . reserved_words::get_all(). "'>" . $all_option_name . "</option>\n";
687         } 
688         else 
689         {
690              echo "<option value='" . reserved_words::get_all(). "'>" . $all_option_name . "</option>\n";
691         }
692                 if ($selected_id == "") 
693                 {
694                         $selected_id =  reserved_words::get_all();
695                 }
696         }
697
698         while ($row = db_fetch_row($result)) 
699         {
700                 if ($selected_id == $row[0]) 
701                 {
702                         echo "<option selected value='" . $row[0] . "'>";
703                 } 
704                 else 
705                 {
706                         echo "<option value='" . $row[0] . "'>";
707                 }
708                 echo (user_show_codes()?$row[0] . "&nbsp;-&nbsp;":"") . $row[2] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
709
710                 if ($selected_id == "") 
711                 {
712                         $selected_id = $row[0];
713                         $_POST[$name] = $selected_id;
714                 }
715         }
716
717         echo "</select>";
718         db_free_result($result);
719 }
720
721 //------------------------------------------------------------------------------------
722
723 function stock_manufactured_items_list($name, $selected_id,
724         $all_option=false, $submit_on_change=false)
725 {
726         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
727                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
728                 AND (".TB_PREF."stock_master.mb_flag='M')";
729
730         base_stock_items_list($sql, $name, &$selected_id,       $all_option, _("All Items"),
731                 $submit_on_change);
732 }
733
734 function stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
735 {
736         if ($label != null)
737                 echo "<td>$label</td>\n";
738         echo "<td>";
739         stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
740         echo "</td>\n";
741 }
742
743 function stock_manufactured_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
744 {
745         echo "<tr>\n";
746         stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
747         echo "</tr>\n";
748 }
749
750 //------------------------------------------------------------------------------------
751
752 function stock_component_items_list($name, $parent_stock_id, &$selected_id,
753         $all_option=false, $submit_on_change=false)
754 {
755         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
756                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE
757                 ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
758                 AND stock_id != '$parent_stock_id'";
759
760         base_stock_items_list($sql, $name, &$selected_id,
761                 $all_option, _("All Items"), $submit_on_change);
762 }
763
764 //------------------------------------------------------------------------------------
765
766 function stock_purchasable_items_list($name, &$selected_id,
767         $all_option=false, $submit_on_change=false, $extra="")
768 {
769         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
770                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
771                 AND mb_flag !='M'";
772
773         base_stock_items_list($sql, $name, &$selected_id,
774                 $all_option, _("All Items"), $submit_on_change, $extra);
775 }
776
777 function stock_purchasable_items_list_cells($label, $name, &$selected_id, $all_option=false, $submit_on_change=false, $extra = "")
778 {
779         if ($label != null)
780                 echo "<td>$label</td>\n";
781         echo "<td>";
782         stock_purchasable_items_list($name, $selected_id, $all_option, $submit_on_change, $extra);
783         echo "</td>\n";
784 }
785
786 function stock_purchasable_items_list_row($label, $name, &$selected_id, $all_option=false, $submit_on_change=false)
787 {
788         echo "<tr>\n";
789         stock_purchasable_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
790         echo "</tr>\n";
791 }
792
793 //------------------------------------------------------------------------------------
794
795 function stock_costable_items_list($name, &$selected_id,
796         $all_option=false, $submit_on_change=false)
797 {
798         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
799                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
800                 AND mb_flag !='D'";
801
802         base_stock_items_list($sql, $name, &$selected_id,
803                 $all_option, _("All Items"), $submit_on_change);
804 }
805
806 //------------------------------------------------------------------------------------
807
808 function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
809 {
810         echo "<tr>";
811         if ($label != NULL)
812                 echo "<td>$label</td>\n";
813         echo "<td>";            
814         if ($enabled)
815                 echo "<select name='$name' onchange='this.form.submit();'>\n";
816         else
817                 echo "<select disabled name='$name'>\n";
818         if ($selected_id == null)
819                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
820         if ($selected_id == "")
821                 $_POST[$name] = $selected_id = "B";
822         echo "<option " . ($selected_id == 'M'?" selected ":"") . " value='M'>" . _("Manufactured"). "</option>\n";
823         echo "<option " . ($selected_id == 'B'?" selected ":"") . " value='B'>" . _("Purchased"). "</option>\n";
824         echo "<option " . ($selected_id == 'D'?" selected ":"") . " value='D'>" . _("Service"). "</option>\n";
825         echo "</select></td></tr>\n";
826 }
827
828 function stock_units_list_row($label, $name, $value, $enabled=true)
829 {
830         global $stock_units;
831
832         echo "<tr><td>$label</td>\n";
833         if ($enabled)
834                 echo "<td><select name='$name'>";
835         else
836                 echo "<td><select disabled name='$name'>";
837         
838         if ($value == null)
839                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
840         foreach ($stock_units as $unit) 
841         {
842                 if ($value == "")
843                         $_POST[$name] = $value = $unit;
844                 if ($value==$unit)
845                 {
846                         echo "<option selected value='$unit'>$unit</option>\n";
847                 } 
848                 else 
849                 {
850                         echo "<option value='$unit'>$unit</option>\n";
851                 }
852         }
853         echo "</select></td></tr>\n";
854 }
855
856 //------------------------------------------------------------------------------------
857
858 function tax_types_list($name, $selected_id,
859         $none_option=false, $none_option_name=null, $submit_on_change=false)
860 {
861         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."tax_types",
862                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
863 }
864
865 function tax_types_list_cells($label, $name, $selected_id, $none_option=false, 
866         $none_option_name=null, $submit_on_change=false)
867 {
868         if ($label != null)
869                 echo "<td>$label</td>\n";
870         echo "<td>";
871         tax_types_list($name, $selected_id, $none_option, $none_option_name, $submit_on_change);
872         echo "</td>\n";
873 }
874
875 function tax_types_list_row($label, $name, $selected_id, $none_option=false, 
876         $none_option_name=null, $submit_on_change=false)
877 {
878         echo "<tr>\n";
879         tax_types_list_cells($label, $name, $selected_id, $none_option, $none_option_name, $submit_on_change);
880         echo "</tr>\n";
881 }
882
883 //------------------------------------------------------------------------------------
884
885 function tax_groups_list($name, $selected_id,
886         $none_option=false, $none_option_name=null, $submit_on_change=false)
887 {
888         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."tax_groups ORDER BY id",
889                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
890 }
891
892 function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
893 {
894         if ($label != null)
895                 echo "<td>$label</td>\n";
896         echo "<td>";
897         tax_groups_list($name, $selected_id, false, null, $submit_on_change);
898         echo "</td>\n";
899 }
900
901 function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
902 {
903         echo "<tr>\n";
904         tax_groups_list_cells($label, $name, $selected_id, false, null, $submit_on_change);
905         echo "</tr>\n";
906 }
907
908 //------------------------------------------------------------------------------------
909
910 function item_tax_types_list($name, $selected_id)
911 {
912         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."item_tax_types ORDER BY id",
913                 $name, $selected_id);
914 }
915
916 function item_tax_types_list_cells($label, $name, $selected_id)
917 {
918         if ($label != null)
919                 echo "<td>$label</td>\n";
920         echo "<td>";
921         item_tax_types_list($name, $selected_id);
922         echo "</td>\n";
923 }
924
925 function item_tax_types_list_row($label, $name, $selected_id)
926 {
927         echo "<tr>\n";
928         item_tax_types_list_cells($label, $name, $selected_id);
929         echo "</tr>\n";
930 }
931
932 //------------------------------------------------------------------------------------
933
934 function shippers_list($name, $selected_id)
935 {
936         simple_codeandname_list("SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers",
937                 $name, $selected_id);
938 }
939
940 function shippers_list_cells($label, $name, $selected_id)
941 {
942         if ($label != null)
943                 echo "<td>$label</td>\n";
944         echo "<td>";
945         shippers_list($name, $selected_id);
946         echo "</td>\n";
947 }
948
949 function shippers_list_row($label, $name, $selected_id)
950 {
951         echo "<tr>\n";
952         shippers_list_cells($label, $name, $selected_id);
953         echo "</tr>\n";
954 }
955
956 //-------------------------------------------------------------------------------------
957
958 function sales_persons_list($name, $selected_id)
959 {
960         simple_codeandname_list("SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman",
961                 $name, $selected_id);
962 }
963
964 function sales_persons_list_cells($label, $name, $selected_id)
965 {
966         if ($label != null)
967                 echo "<td>$label</td>\n";
968         echo "<td>\n";
969         sales_persons_list($name, $selected_id);
970         echo "</td>\n";
971 }
972
973 function sales_persons_list_row($label, $name, $selected_id)
974 {
975         echo "<tr>\n";
976         sales_persons_list_cells($label, $name, $selected_id);
977         echo "</tr>\n";
978 }
979
980 //------------------------------------------------------------------------------------
981
982 function sales_areas_list($name, $selected_id)
983 {
984         simple_codeandname_list("SELECT area_code, description FROM ".TB_PREF."areas",
985                 $name, $selected_id);
986 }
987
988 function sales_areas_list_cells($label, $name, $selected_id)
989 {
990         if ($label != null)
991                 echo "<td>$label</td>\n";
992         echo "<td>";
993         sales_areas_list($name, $selected_id);
994         echo "</td>\n";
995 }
996
997 function sales_areas_list_row($label, $name, $selected_id)
998 {
999         echo "<tr>\n";
1000         sales_areas_list_cells($label, $name, $selected_id);
1001         echo "</tr>\n";
1002 }
1003
1004 //------------------------------------------------------------------------------------
1005
1006 function workorders_list($name, $selected_id)
1007 {
1008         simple_codeandname_list("SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0",
1009                 $name, $selected_id);
1010 }
1011
1012 function workorders_list_cells($label, $name, $selected_id)
1013 {
1014         if ($label != null)
1015                 echo "<td>$label</td>\n";
1016         echo "<td>";
1017         workorders_list($name, $selected_id);
1018         echo "</td>\n";
1019 }
1020
1021 function workorders_list_row($label, $name, $selected_id)
1022 {
1023         echo "<tr>\n";
1024         workorders_list_cells($label, $name, $selected_id);
1025         echo "</tr>\n";
1026 }
1027
1028 //------------------------------------------------------------------------------------
1029
1030 function payment_terms_list($name, $selected_id)
1031 {
1032         simple_codeandname_list("SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms",
1033                 $name, $selected_id);
1034 }
1035
1036 function payment_terms_list_cells($label, $name, $selected_id)
1037 {
1038         if ($label != null)
1039                 echo "<td>$label</td>\n";
1040         echo "<td>";
1041         payment_terms_list($name, $selected_id);
1042         echo "</td>\n";
1043 }
1044
1045 function payment_terms_list_row($label, $name, $selected_id)
1046 {
1047         echo "<tr>\n";
1048         payment_terms_list_cells($label, $name, $selected_id);
1049         echo "</tr>\n";
1050 }
1051
1052 //------------------------------------------------------------------------------------
1053
1054 function credit_status_list($name, $selected_id)
1055 {
1056         simple_codeandname_list("SELECT id, reason_description FROM ".TB_PREF."credit_status",
1057                 $name, $selected_id);
1058 }
1059
1060 function credit_status_list_cells($label, $name, $selected_id)
1061 {
1062         if ($label != null)
1063                 echo "<td>$label</td>\n";
1064         echo "<td>";
1065         credit_status_list($name, $selected_id);
1066         echo "</td>\n";
1067 }
1068
1069 function credit_status_list_row($label, $name, $selected_id)
1070 {
1071         echo "<tr>\n";
1072         credit_status_list_cells($label, $name, $selected_id);
1073         echo "</tr>\n";
1074 }
1075
1076 //-----------------------------------------------------------------------------------------------
1077
1078 function sales_types_list($name, $selected_id)
1079 {
1080         simple_codeandname_list("SELECT id, sales_type FROM ".TB_PREF."sales_types",
1081                 $name, $selected_id);
1082 }
1083
1084 function sales_types_list_cells($label, $name, $selected_id)
1085 {
1086         if ($label != null)
1087                 echo "<td>$label</td>\n";
1088         echo "<td>";
1089         sales_types_list($name, $selected_id);
1090         echo "</td>\n";
1091 }
1092
1093 function sales_types_list_row($label, $name, $selected_id)
1094 {
1095         echo "<tr>\n";
1096         sales_types_list_cells($label, $name, $selected_id);
1097         echo "</tr>\n";
1098 }
1099
1100 //-----------------------------------------------------------------------------------------------
1101
1102 function movement_types_list($name, $selected_id)
1103 {
1104         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."movement_types",
1105                 $name, $selected_id);
1106 }
1107
1108 function movement_types_list_cells($label, $name, $selected_id)
1109 {
1110         if ($label != null)
1111                 echo "<td>$label</td>\n";
1112         echo "<td>";
1113         movement_types_list($name, $selected_id);
1114         echo "</td>\n";
1115 }
1116
1117 function movement_types_list_row($label, $name, $selected_id)
1118 {
1119         echo "<tr>\n";
1120         movement_types_list_cells($label, $name, $selected_id);
1121         echo "</tr>\n";
1122 }
1123
1124 //-----------------------------------------------------------------------------------------------
1125
1126 function bank_trans_types_list($name, $selected_id)
1127 {
1128         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."bank_trans_types",
1129                 $name, $selected_id);
1130 }
1131
1132 function bank_trans_types_list_cells($label, $name, $selected_id)
1133 {
1134         if ($label != null)
1135                 echo "<td>$label</td>\n";
1136         echo "<td>";
1137         bank_trans_types_list($name, $selected_id);
1138         echo "</td>\n";
1139 }
1140
1141 function bank_trans_types_list_row($label, $name, $selected_id)
1142 {
1143         echo "<tr>\n";
1144         bank_trans_types_list_cells($label, $name, $selected_id);
1145         echo "</tr>\n";
1146 }
1147
1148 //-----------------------------------------------------------------------------------------------
1149
1150 function workcenter_list($name, $selected_id, $all_option=false)
1151 {
1152         global $all_items;
1153         echo "<select name='$name'>";
1154
1155         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1156         $result = db_query($sql);
1157
1158         if ($selected_id == null)
1159                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1160         if ($all_option == true)
1161         {
1162         if ($all_items == $selected_id)
1163         {
1164              echo "<option selected value='$all_items'>" . _("All Work Centres") . "</option>\n";
1165         } 
1166         else 
1167         {
1168              echo "<option value='$all_items'>" . _("All Work Centres") . "</option>\n";
1169         }
1170         }
1171
1172         while ($row = db_fetch_row($result)) 
1173         {
1174                 if ($selected_id == $row[0]) 
1175                 {
1176                         echo "<option selected value='" . $row[0] . "'>";
1177                 } 
1178                 else 
1179                 {
1180                         echo "<option value='" . $row[0] . "'>";
1181                 }
1182                 echo $row[1] . "</option>\n";
1183         }
1184
1185         echo "</select>";
1186         db_free_result($result);
1187 }
1188
1189 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1190 {
1191         if ($label != null)
1192                 echo "<td>$label</td>\n";
1193         echo "<td>";
1194         workcenter_list($name, $selected_id, $all_option);
1195         echo "</td>\n";
1196 }
1197
1198 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1199 {
1200         echo "<tr>\n";
1201         workcenter_list_cells($label, $name, $selected_id, $all_option);
1202         echo "</tr>\n";
1203 }
1204
1205 //-----------------------------------------------------------------------------------------------
1206
1207 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1208 {
1209         if ($submit_on_change==true)
1210                 echo "<select name='$name' onchange='this.form.submit();'>";
1211         else
1212                 echo "<select name='$name'>";
1213
1214         $company_currency = get_company_currency();
1215
1216         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1217                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1218                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1219         $result = db_query($sql);
1220
1221         if ($selected_id == null)
1222                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1223         while ($row = db_fetch_row($result)) 
1224         {
1225                 if ($selected_id == $row[0]) 
1226                 {
1227                         echo "<option selected value='" . $row[0] . "'>";
1228                 } 
1229                 else 
1230                 {
1231                         echo "<option value='" . $row[0] . "'>";
1232                 }
1233                 echo $row[1];
1234                 if ($company_currency != $row[2])
1235                         echo "&nbsp;-&nbsp;" . $row[2];
1236                 echo  "</option>\n";
1237                 if ($selected_id == "")
1238                 {
1239                         $selected_id = $row[0];
1240                         $_POST[$name] = $selected_id;
1241                 }       
1242         }
1243
1244         echo "</select>";
1245         db_free_result($result);
1246 }
1247
1248 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1249 {
1250         if ($label != null)
1251                 echo "<td>$label</td>\n";
1252         echo "<td>";
1253         bank_accounts_list($name, $selected_id, $submit_on_change);
1254         echo "</td>\n";
1255 }
1256
1257 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1258 {
1259         echo "<tr>\n";
1260         bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1261         echo "</tr>\n";
1262 }
1263
1264 //-----------------------------------------------------------------------------------------------
1265
1266 function class_list($name, $selected_id, $submit_on_change=false)
1267 {
1268         if ($submit_on_change==true)
1269                 echo "<select name='$name' onchange='this.form.submit();'>";
1270         else
1271                 echo "<select name='$name'>";
1272
1273         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1274         $result = db_query($sql);
1275
1276         if ($selected_id == null)
1277                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1278         while ($row = db_fetch_row($result)) 
1279         {
1280                 if ($selected_id == $row[0]) 
1281                 {
1282                         echo "<option selected value='" . $row[0] . "'>";
1283                 } 
1284                 else 
1285                 {
1286                         echo "<option value='" . $row[0] . "'>";
1287                 }
1288                 echo $row[1] . "</option>\n";
1289                 if ($selected_id == "")
1290                 {
1291                         $selected_id = $row[0];
1292                         $_POST[$name] = $selected_id;
1293                 }       
1294         }
1295
1296         echo "</select>";
1297         db_free_result($result);
1298 }
1299
1300 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1301 {
1302         if ($label != null)
1303                 echo "<td>$label</td>\n";
1304         echo "<td>";
1305         class_list($name, $selected_id, $submit_on_change);
1306         echo "</td>\n";
1307 }
1308
1309 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1310 {
1311         echo "<tr>\n";
1312         class_list_cells($label, $name, $selected_id, $submit_on_change);
1313         echo "</tr>\n";
1314 }
1315
1316 //-----------------------------------------------------------------------------------------------
1317
1318 function stock_categories_list($name, $selected_id)
1319 {
1320         simple_codeandname_list("SELECT category_id, description FROM ".TB_PREF."stock_category
1321                 ORDER BY category_id", $name, $selected_id);
1322 }
1323
1324 function stock_categories_list_cells($label, $name, $selected_id)
1325 {
1326         if ($label != null)
1327                 echo "<td>$label</td>\n";
1328         echo "<td>";
1329         stock_categories_list($name, $selected_id);
1330         echo "</td>\n";
1331 }
1332
1333 function stock_categories_list_row($label, $name, $selected_id)
1334 {
1335         echo "<tr>\n";
1336         stock_categories_list_cells($label, $name, $selected_id);
1337         echo "</tr>\n";
1338 }
1339
1340 //-----------------------------------------------------------------------------------------------
1341
1342 function gl_account_types_list($name, $selected_id, $all_option, $all_option_name,
1343         $all_option_numeric)
1344 {
1345         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."chart_types ORDER BY id",
1346                 $name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1347 }
1348
1349 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1350         $all_option_numeric=false)
1351 {
1352         if ($label != null)
1353                 echo "<td>$label</td>\n";
1354         echo "<td>";
1355         gl_account_types_list($name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1356         echo "</td>\n";
1357 }
1358
1359 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1360         $all_option_numeric=false)
1361 {
1362         echo "<tr>\n";
1363         gl_account_types_list_cells($label, $name, $selected_id, $all_option, 
1364                 $all_option_name, $all_option_numeric);
1365         echo "</tr>\n";
1366 }
1367
1368 //-----------------------------------------------------------------------------------------------
1369
1370 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false, 
1371         $show_group=false, $onchange="")
1372 {
1373         echo "<select name='$name'";
1374         if ($onchange != "")
1375                 echo " onchange='$onchange'";
1376         echo ">";
1377
1378         if ($skip_bank_accounts)
1379                 $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name
1380                         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
1381             WHERE ".TB_PREF."bank_accounts.account_code IS NULL
1382                         AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1383                         ORDER BY account_code;";
1384         else
1385                 $sql = "SELECT account_code, account_name,".TB_PREF."chart_types.name
1386                         FROM ".TB_PREF."chart_master, ".TB_PREF."chart_types
1387                         WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1388                         ORDER BY account_code";
1389
1390         if ($selected_id == null)
1391                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1392         $result = db_query($sql, "query chart master");
1393
1394         while ($row = db_fetch_row($result)) 
1395         {
1396                 if ($selected_id == $row[0]) 
1397                 {
1398                         echo "<option selected value='" . $row[0] . "'>";
1399                 } 
1400                 else 
1401                 {
1402                         echo "<option value='" . $row[0] . "'>";
1403                 }
1404                 //echo str_pad($row[0],6,'0', STR_PAD_LEFT) .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1405                 if ($show_group)
1406                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1407                 else    
1408                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1409
1410                 if ($selected_id == "")
1411                 {
1412                         $selected_id = $row[0];
1413                         $_POST[$name] = $selected_id;
1414                 }       
1415         }
1416
1417         echo "</select>";
1418         db_free_result($result);
1419 }
1420
1421 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1422         $show_group=false, $onchange="")
1423 {
1424         if ($label != null)
1425                 echo "<td>$label</td>\n";
1426         echo "<td>";
1427         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $onchange);
1428         echo "</td>\n";
1429 }
1430
1431 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1432         $show_group=false, $onchange="")
1433 {
1434         echo "<tr>\n";
1435         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts, 
1436                 $show_group, $onchange);
1437         echo "</tr>\n";
1438 }
1439
1440 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1441 {
1442         if ($submit_on_change == true)
1443                 echo "<select name='$name' onchange='this.form.submit();'>";
1444         else
1445                 echo "<select name='$name'>";
1446
1447         if (strlen($name_yes) == 0)     
1448         {
1449                 unset($name_yes);
1450         }
1451         if (strlen($name_no) == 0)      
1452         {
1453                 unset($name_no);
1454         }
1455
1456         if ($selected_id == null)
1457                 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1458     if ($selected_id == 0)
1459         echo "<option value=1>";
1460     else
1461         echo "<option selected value=1>";
1462         if (!isset($name_yes)) 
1463                 echo _("Yes") . "</option>\n"; 
1464         else 
1465                 echo $name_yes . "</option>\n"; 
1466         if ($selected_id == 0)
1467                 echo "<option selected value=0>";
1468         else    
1469         echo "<option value=0>";
1470         if (!isset($name_no)) 
1471                 echo _("No") . "</option>\n"; 
1472         else 
1473                 echo $name_no . "</option>\n"; 
1474         echo "</select>";
1475 }
1476
1477 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1478 {
1479         if ($label != null)
1480                 echo "<td>$label</td>\n";
1481         echo "<td>";
1482         yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1483         echo "</td>\n";
1484 }
1485
1486 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1487 {
1488         echo "<tr>\n";
1489         yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1490         echo "</tr>\n";
1491 }
1492
1493 //------------------------------------------------------------------------------------------------
1494
1495 function languages_list($name, &$selected_id)
1496 {
1497         global $installed_languages;
1498
1499         echo "<select name='$name'>";
1500
1501         if ($selected_id == null)
1502                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1503         foreach ($installed_languages as $lang) 
1504         {
1505                 echo "<option ";
1506                 if ($selected_id == $lang['code']) 
1507                         echo "selected ";
1508                 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1509         }
1510 }
1511
1512 function languages_list_cells($label, $name, $selected_id)
1513 {
1514         if ($label != null)
1515                 echo "<td>$label</td>\n";
1516         echo "<td>";
1517         languages_list($name, $selected_id);
1518         echo "</td>\n";
1519 }
1520
1521 function languages_list_row($label, $name, $selected_id)
1522 {
1523         echo "<tr>\n";
1524         languages_list_cells($label, $name, $selected_id);
1525         echo "</tr>\n";
1526 }
1527
1528 //------------------------------------------------------------------------------------------------
1529
1530 function bank_account_types_list($name, &$selected_id)
1531 {
1532         $bank_account_types = bank_account_types::get_all();
1533
1534         echo "<select name='$name'>";
1535
1536         if ($selected_id == null)
1537                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1538         foreach ($bank_account_types as $type) 
1539         {
1540         echo "<option ";
1541         if ($selected_id == "" || $selected_id == $type['id']) 
1542                 echo "selected ";
1543         echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1544         }
1545 }
1546
1547 function bank_account_types_list_cells($label, $name, $selected_id)
1548 {
1549         if ($label != null)
1550                 echo "<td>$label</td>\n";
1551         echo "<td>";
1552         bank_account_types_list($name, $selected_id);
1553         echo "</td>\n";
1554 }
1555
1556 function bank_account_types_list_row($label, $name, $selected_id)
1557 {
1558         echo "<tr>\n";
1559         bank_account_types_list_cells($label, $name, $selected_id);
1560         echo "</tr>\n";
1561 }
1562
1563 //------------------------------------------------------------------------------------------------
1564
1565 function payment_person_types_list($name, $selected_id, $related=null)
1566 {
1567         $types = payment_person_types::get_all();
1568
1569         echo "<select name='$name'";
1570         if ($related)
1571                 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1572         echo ">";
1573
1574         if ($selected_id == null)
1575                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1576         foreach ($types as $type) 
1577         {
1578                 if (payment_person_types::has_items($type['id'])) 
1579                 {
1580                         if ($selected_id == "")
1581                                 $_POST[$name] = $selected_id = $type['id'];
1582                     echo "<option ";
1583                 if ($selected_id == $type['id']) 
1584                         echo "selected ";
1585                     echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1586                 }
1587         }
1588 }
1589
1590 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1591 {
1592         if ($label != null)
1593                 echo "<td>$label</td>\n";
1594         echo "<td>";
1595         payment_person_types_list($name, $selected_id, $related);
1596         echo "</td>\n";
1597 }
1598
1599 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1600 {
1601         echo "<tr>\n";
1602         payment_person_types_list_cells($label, $name, $selected_id, $related);
1603         echo "</tr>\n";
1604 }
1605
1606 //------------------------------------------------------------------------------------------------
1607
1608 function wo_types_list($name, &$selected_id)
1609 {
1610         $types = wo_types::get_all();
1611
1612         echo "<select name='$name' onchange='this.form.submit();'>";
1613
1614         if ($selected_id == null)
1615                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1616         foreach ($types as $type) 
1617         {
1618             echo "<option ";
1619             if ($selected_id == $type['id']) 
1620                 echo "selected ";
1621             echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1622         }
1623         echo "</select>";
1624 }
1625
1626 function wo_types_list_row($label, $name, &$selected_id)
1627 {
1628         echo "<tr><td>$label</td><td>\n";
1629         wo_types_list($name, $selected_id);
1630         echo "</td></tr>\n";
1631 }
1632
1633 //------------------------------------------------------------------------------------------------
1634
1635 function dateformats_list_row($label, $name, $value)
1636 {
1637         global $dateformats;
1638
1639         echo "<tr><td>$label</td>\n";
1640         echo "<td><select name='$name'>";
1641
1642         if ($value == null)
1643                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1644         $counter = 0;
1645         foreach ($dateformats as $df) 
1646         {
1647
1648                 if ($value==$counter)
1649                 {
1650                         echo "<option selected value='$counter'>$df</option>\n";
1651                 } 
1652                 else 
1653                 {
1654                         echo "<option value='$counter'>$df</option>\n";
1655                 }
1656                 $counter++;
1657         }
1658         echo "</select></td></tr>\n";
1659 }
1660
1661 function dateseps_list_row($label, $name, $value)
1662 {
1663         global $dateseps;
1664
1665         echo "<tr><td>$label</td>\n";
1666         echo "<td><select name='$name'>";
1667
1668         if ($value == null)
1669                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1670         $counter = 0;
1671         foreach ($dateseps as $ds) 
1672         {
1673
1674                 if ($value==$counter)
1675                 {
1676                         echo "<option selected value='$counter'>$ds</option>\n";
1677                 } 
1678                 else 
1679                 {
1680                         echo "<option value='$counter'>$ds</option>\n";
1681                 }
1682                 $counter++;
1683         }
1684         echo "</select></td></tr>\n";
1685 }
1686
1687 function thoseps_list_row($label, $name, $value)
1688 {
1689         global $thoseps;
1690
1691         echo "<tr><td>$label</td>\n";
1692         echo "<td><select name='$name'>";
1693
1694         if ($value == null)
1695                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1696         $counter = 0;
1697         foreach ($thoseps as $ts) 
1698         {
1699
1700                 if ($value==$counter)
1701                 {
1702                         echo "<option selected value='$counter'>$ts</option>\n";
1703                 } 
1704                 else 
1705                 {
1706                         echo "<option value='$counter'>$ts</option>\n";
1707                 }
1708                 $counter++;
1709         }
1710         echo "</select></td></tr>\n";
1711 }
1712
1713 function decseps_list_row($label, $name, $value)
1714 {
1715         global $decseps;
1716
1717         echo "<tr><td>$label</td>\n";
1718         echo "<td><select name='$name'>";
1719
1720         if ($value == null)
1721                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1722         $counter = 0;
1723         foreach ($decseps as $ds) 
1724         {
1725
1726                 if ($value==$counter)
1727                 {
1728                         echo "<option selected value='$counter'>$ds</option>\n";
1729                 } 
1730                 else 
1731                 {
1732                         echo "<option value='$counter'>$ds</option>\n";
1733                 }
1734                 $counter++;
1735         }
1736         echo "</select></td></tr>\n";
1737 }
1738
1739 function themes_list_row($label, $name, $value)
1740 {
1741         global $themes;
1742
1743         echo "<tr><td>$label</td>\n";
1744         echo "<td><select name='$name'>";
1745
1746         if ($value == null)
1747                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1748         foreach ($themes as $th) 
1749         {
1750
1751                 if ($value==$th)
1752                 {
1753                         echo "<option selected value='$th'>$th</option>\n";
1754                 } 
1755                 else 
1756                 {
1757                         echo "<option value='$th'>$th</option>\n";
1758                 }
1759         }
1760         echo "</select></td></tr>\n";
1761 }
1762
1763 function pagesizes_list_row($label, $name, $value)
1764 {
1765         global $pagesizes;
1766
1767         echo "<tr><td>$label</td>\n";
1768         echo "<td><select name='$name'>";
1769
1770         if ($value == null)
1771                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1772         foreach ($pagesizes as $pz) 
1773         {
1774
1775                 if ($value==$pz)
1776                 {
1777                         echo "<option selected value='$pz'>$pz</option>\n";
1778                 } 
1779                 else 
1780                 {
1781                         echo "<option value='$pz'>$pz</option>\n";
1782                 }
1783         }
1784         echo "</select></td></tr>\n";
1785 }
1786
1787 function security_headings_list_row($label, $name, $value)
1788 {
1789         global $security_headings;
1790
1791         echo "<tr><td>$label</td>\n";
1792         echo "<td><select name='$name'>";
1793
1794         if ($value == null)
1795                 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
1796         $counter=0;
1797         foreach ($security_headings as $sh) 
1798         {
1799
1800                 if ($value==$counter)
1801                 {
1802                         echo "<option selected value='$counter'>$sh</option>\n";
1803                 } 
1804                 else 
1805                 {
1806                         echo "<option value='$counter'>$sh</option>\n";
1807                 }
1808                 $counter++;
1809         }
1810         echo "</select></td></tr>\n";
1811 }
1812
1813 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
1814 {
1815         global $systypes_array;
1816
1817         if ($label != null)
1818                 echo "<td>$label</td>\n";
1819     echo "<td><select name='$name'";
1820     if (submit_on_change)
1821         echo " onchange='this.form.submit();'>";
1822     else
1823         echo ">";
1824         if ($value == null)
1825                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1826     foreach ($systypes_array as $key=>$type)
1827     {
1828
1829                 if ($value==$key)
1830                 {
1831                         echo "<option selected value='$key'>".$type['name']."</option>\n";
1832                 } 
1833                 else 
1834                 {
1835                         echo "<option value='$key'>".$type['name']."</option>\n";
1836                 }
1837     }
1838     echo "</select></td>\n";
1839 }
1840
1841 function systypes_list_row($label, $name, $value, $submit_on_change=false)
1842 {
1843         echo "<tr>\n";
1844         systypes_list_cells($label, $name, $value, $submit_on_change);
1845         echo "</tr>\n";
1846 }
1847
1848 function cust_allocations_list_cells($label, $name, $selected)
1849 {
1850         if ($label != null)
1851                 label_cell($label);
1852         if ($selected == null)
1853                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1854         echo "<td><select name='$name'>";
1855         echo "<option " . ($selected == reserved_words::get_all()?" selected ":"") . " value='" . reserved_words::get_all(). "'>" . _("All Types"). "</option>\n";
1856         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
1857         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1858         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1859         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1860         echo "</select></td>\n";
1861 }
1862
1863 function supp_allocations_list_cells($name, $selected)
1864 {
1865         if ($selected == null)
1866                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1867         echo "<td><select name='$name'>";
1868         echo "<option " . ($selected == reserved_words::get_all()?" selected ":"") . " value='" . reserved_words::get_all(). "'>" . _("All Types"). "</option>\n";
1869         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Invoices"). "</option>\n";
1870         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1871         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1872         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1873         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Overdue Credit Notes"). "</option>\n";
1874         echo "</select></td>\n";
1875 }
1876
1877 function policy_list_cells($label, $name, $selected)
1878 {
1879         if ($selected == null)
1880         {
1881                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1882                 if ($selected == "")    
1883                         $_POST[$name] = $selected;
1884         }               
1885         if ($label != null)
1886                 label_cell($label);
1887         echo "<td><select name='$name'>";
1888         echo "<option " . ($selected == ''?" selected ":"") . " value=''>" . _("Automatically put balance on back order"). "</option>\n";
1889         echo "<option " . ($selected == 'CAN'?" selected ":"") . " value='CAN'>" . _("Cancel any quantites not delivered"). "</option>\n";
1890         echo "</select></td>\n";
1891 }
1892
1893 function policy_list_row($label, $name, $selected)
1894 {
1895         echo "<tr>\n";
1896         policy_list_cells($label, $name, $selected);
1897         echo "</tr>\n";
1898 }
1899
1900 function credit_type_list_cells($label, $name, $selected, $submit_on_change=false)
1901 {
1902         if ($selected == null)
1903         {
1904                 $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]);
1905                 if ($selected == "Return")      
1906                         $_POST[$name] = $selected;
1907         }               
1908         if ($label != null)
1909                 label_cell($label);
1910     echo "<td><select name='$name'";
1911     if ($submit_on_change)
1912         echo " onchange='this.form.submit();'>";
1913     else
1914         echo ">";
1915         echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
1916         echo "<option " . ($selected == 'WriteOff'?" selected ":"") . " value='WriteOff'>" . _("Items Written Off"). "</option>\n";
1917         echo "</select></td>\n";
1918 }
1919
1920 function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
1921 {
1922         echo "<tr>\n";
1923         credit_type_list_cells($label, $name, $selected, $submit_on_change);
1924         echo "</tr>\n";
1925 }
1926
1927 function number_list($name, $selected, $from, $to, $firstlabel="")
1928 {
1929         if ($selected == null)
1930         {
1931                 $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]);
1932                 if ($selected == $from) 
1933                         $_POST[$name] = $selected;
1934         }               
1935         echo "<select name='$name'>";
1936         for ($i = $from; $i <= $to; $i++)
1937     {
1938                 if ($i == 0 && $firstlabel != "")
1939                         $label = $firstlabel;
1940                 else
1941                         $label = $i;
1942                 if ($selected == $i)
1943                 {
1944                         echo "<option selected value='$i'>$label</option>\n";
1945                 } 
1946                 else 
1947                 {
1948                         echo "<option value='$i'>$label</option>\n";
1949                 }
1950     }
1951         echo "</select>\n";
1952 }
1953
1954 function number_list_cells($label, $name, $selected, $from, $to)
1955 {
1956         if ($label != null)
1957                 label_cell($label);
1958         echo "<td>\n";
1959         number_list($name, $selected, $from, $to);
1960         echo "</td>\n";
1961 }       
1962
1963 function number_list_row($label, $name, $selected, $from, $to)
1964 {
1965         echo "<tr>\n";
1966         number_list_cells($label, $name, $selected, $from, $to);
1967         echo "</tr>\n";
1968 }
1969 ?>