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