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