Integration of JsHttpRequest ajax transport class
[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                         $_POST[$name] = $unit['abbr'];
1053                 }
1054                 $descr = $unit['name'];
1055                 if ($value==$unit['abbr'])
1056                 {
1057                         echo "<option selected value='".$unit['abbr']."'>$descr</option>\n";
1058                 }
1059                 else
1060                 {
1061                         echo "<option value='".$unit['abbr']."'>$descr</option>\n";
1062                 }
1063         }
1064         echo "</select></td></tr>\n";
1065 }
1066
1067 //------------------------------------------------------------------------------------
1068
1069 function tax_types_list($name, $selected_id,
1070         $none_option=false, $none_option_name=null, $submit_on_change=false)
1071 {
1072         simple_codeandname_list("SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types",
1073                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
1074 }
1075
1076 function tax_types_list_cells($label, $name, $selected_id, $none_option=false,
1077         $none_option_name=null, $submit_on_change=false)
1078 {
1079         if ($label != null)
1080                 echo "<td>$label</td>\n";
1081         echo "<td>";
1082         tax_types_list($name, $selected_id, $none_option, $none_option_name, $submit_on_change);
1083         echo "</td>\n";
1084 }
1085
1086 function tax_types_list_row($label, $name, $selected_id, $none_option=false,
1087         $none_option_name=null, $submit_on_change=false)
1088 {
1089         echo "<tr>\n";
1090         tax_types_list_cells($label, $name, $selected_id, $none_option, $none_option_name, $submit_on_change);
1091         echo "</tr>\n";
1092 }
1093
1094 //------------------------------------------------------------------------------------
1095
1096 function tax_groups_list($name, $selected_id,
1097         $none_option=false, $none_option_name=null, $submit_on_change=false)
1098 {
1099         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."tax_groups ORDER BY id",
1100                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
1101 }
1102
1103 function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
1104 {
1105         if ($label != null)
1106                 echo "<td>$label</td>\n";
1107         echo "<td>";
1108         tax_groups_list($name, $selected_id, false, null, $submit_on_change);
1109         echo "</td>\n";
1110 }
1111
1112 function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
1113 {
1114         echo "<tr>\n";
1115         tax_groups_list_cells($label, $name, $selected_id, false, null, $submit_on_change);
1116         echo "</tr>\n";
1117 }
1118
1119 //------------------------------------------------------------------------------------
1120
1121 function item_tax_types_list($name, $selected_id)
1122 {
1123         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."item_tax_types ORDER BY id",
1124                 $name, $selected_id);
1125 }
1126
1127 function item_tax_types_list_cells($label, $name, $selected_id)
1128 {
1129         if ($label != null)
1130                 echo "<td>$label</td>\n";
1131         echo "<td>";
1132         item_tax_types_list($name, $selected_id);
1133         echo "</td>\n";
1134 }
1135
1136 function item_tax_types_list_row($label, $name, $selected_id)
1137 {
1138         echo "<tr>\n";
1139         item_tax_types_list_cells($label, $name, $selected_id);
1140         echo "</tr>\n";
1141 }
1142
1143 //------------------------------------------------------------------------------------
1144
1145 function shippers_list($name, $selected_id)
1146 {
1147         simple_codeandname_list("SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers",
1148                 $name, $selected_id);
1149 }
1150
1151 function shippers_list_cells($label, $name, $selected_id)
1152 {
1153         if ($label != null)
1154                 echo "<td>$label</td>\n";
1155         echo "<td>";
1156         shippers_list($name, $selected_id);
1157         echo "</td>\n";
1158 }
1159
1160 function shippers_list_row($label, $name, $selected_id)
1161 {
1162         echo "<tr>\n";
1163         shippers_list_cells($label, $name, $selected_id);
1164         echo "</tr>\n";
1165 }
1166
1167 //-------------------------------------------------------------------------------------
1168
1169 function sales_persons_list($name, $selected_id)
1170 {
1171         simple_codeandname_list("SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman",
1172                 $name, $selected_id);
1173 }
1174
1175 function sales_persons_list_cells($label, $name, $selected_id)
1176 {
1177         if ($label != null)
1178                 echo "<td>$label</td>\n";
1179         echo "<td>\n";
1180         sales_persons_list($name, $selected_id);
1181         echo "</td>\n";
1182 }
1183
1184 function sales_persons_list_row($label, $name, $selected_id, $submit_on_change=false)
1185 {
1186         echo "<tr>\n";
1187         sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1188         echo "</tr>\n";
1189 }
1190
1191 //------------------------------------------------------------------------------------
1192
1193 function sales_areas_list($name, $selected_id)
1194 {
1195         simple_codeandname_list("SELECT area_code, description FROM ".TB_PREF."areas",
1196                 $name, $selected_id);
1197 }
1198
1199 function sales_areas_list_cells($label, $name, $selected_id)
1200 {
1201         if ($label != null)
1202                 echo "<td>$label</td>\n";
1203         echo "<td>";
1204         sales_areas_list($name, $selected_id);
1205         echo "</td>\n";
1206 }
1207
1208 function sales_areas_list_row($label, $name, $selected_id)
1209 {
1210         echo "<tr>\n";
1211         sales_areas_list_cells($label, $name, $selected_id);
1212         echo "</tr>\n";
1213 }
1214
1215 //------------------------------------------------------------------------------------
1216
1217 function workorders_list($name, $selected_id)
1218 {
1219         simple_codeandname_list("SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0",
1220                 $name, $selected_id);
1221 }
1222
1223 function workorders_list_cells($label, $name, $selected_id)
1224 {
1225         if ($label != null)
1226                 echo "<td>$label</td>\n";
1227         echo "<td>";
1228         workorders_list($name, $selected_id);
1229         echo "</td>\n";
1230 }
1231
1232 function workorders_list_row($label, $name, $selected_id)
1233 {
1234         echo "<tr>\n";
1235         workorders_list_cells($label, $name, $selected_id);
1236         echo "</tr>\n";
1237 }
1238
1239 //------------------------------------------------------------------------------------
1240
1241 function payment_terms_list($name, $selected_id)
1242 {
1243         simple_codeandname_list("SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms",
1244                 $name, $selected_id);
1245 }
1246
1247 function payment_terms_list_cells($label, $name, $selected_id)
1248 {
1249         if ($label != null)
1250                 echo "<td>$label</td>\n";
1251         echo "<td>";
1252         payment_terms_list($name, $selected_id);
1253         echo "</td>\n";
1254 }
1255
1256 function payment_terms_list_row($label, $name, $selected_id)
1257 {
1258         echo "<tr>\n";
1259         payment_terms_list_cells($label, $name, $selected_id);
1260         echo "</tr>\n";
1261 }
1262
1263 //------------------------------------------------------------------------------------
1264
1265 function credit_status_list($name, $selected_id)
1266 {
1267         simple_codeandname_list("SELECT id, reason_description FROM ".TB_PREF."credit_status",
1268                 $name, $selected_id);
1269 }
1270
1271 function credit_status_list_cells($label, $name, $selected_id)
1272 {
1273         if ($label != null)
1274                 echo "<td>$label</td>\n";
1275         echo "<td>";
1276         credit_status_list($name, $selected_id);
1277         echo "</td>\n";
1278 }
1279
1280 function credit_status_list_row($label, $name, $selected_id)
1281 {
1282         echo "<tr>\n";
1283         credit_status_list_cells($label, $name, $selected_id);
1284         echo "</tr>\n";
1285 }
1286
1287 //-----------------------------------------------------------------------------------------------
1288
1289 function sales_types_list($name, $selected_id, $submit_on_change=false, $special_option=null)
1290 {
1291         simple_codeandname_list("SELECT id, sales_type FROM ".TB_PREF."sales_types",
1292                 $name, $selected_id,
1293                 isset($special_option), $special_option, true, $submit_on_change);
1294 }
1295
1296 function sales_types_list_cells($label, $name, $selected_id, $submit_on_change=false, $special_option=null)
1297 {
1298         if ($label != null)
1299                 echo "<td>$label</td>\n";
1300         echo "<td>";
1301         sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1302         echo "</td>\n";
1303 }
1304
1305 function sales_types_list_row($label, $name, $selected_id, $submit_on_change=false, $special_option=null)
1306 {
1307         echo "<tr>\n";
1308         sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1309         echo "</tr>\n";
1310 }
1311
1312 //-----------------------------------------------------------------------------------------------
1313
1314 function movement_types_list($name, $selected_id)
1315 {
1316         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."movement_types",
1317                 $name, $selected_id);
1318 }
1319
1320 function movement_types_list_cells($label, $name, $selected_id)
1321 {
1322         if ($label != null)
1323                 echo "<td>$label</td>\n";
1324         echo "<td>";
1325         movement_types_list($name, $selected_id);
1326         echo "</td>\n";
1327 }
1328
1329 function movement_types_list_row($label, $name, $selected_id)
1330 {
1331         echo "<tr>\n";
1332         movement_types_list_cells($label, $name, $selected_id);
1333         echo "</tr>\n";
1334 }
1335
1336 //-----------------------------------------------------------------------------------------------
1337
1338 function bank_trans_types_list($name, $selected_id)
1339 {
1340         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."bank_trans_types",
1341                 $name, $selected_id);
1342 }
1343
1344 function bank_trans_types_list_cells($label, $name, $selected_id)
1345 {
1346         if ($label != null)
1347                 echo "<td>$label</td>\n";
1348         echo "<td>";
1349         bank_trans_types_list($name, $selected_id);
1350         echo "</td>\n";
1351 }
1352
1353 function bank_trans_types_list_row($label, $name, $selected_id)
1354 {
1355         echo "<tr>\n";
1356         bank_trans_types_list_cells($label, $name, $selected_id);
1357         echo "</tr>\n";
1358 }
1359
1360 //-----------------------------------------------------------------------------------------------
1361
1362 function workcenter_list($name, $selected_id, $all_option=false)
1363 {
1364         global $all_items;
1365
1366         default_focus($name);
1367         echo "<select name='$name'>";
1368
1369         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1370         $result = db_query($sql);
1371
1372         if ($selected_id == null)
1373                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1374         if ($all_option == true)
1375         {
1376         if ($selected_id == $all_items)
1377         {
1378              echo "<option selected value='$all_items'>" . _("All Work Centres") . "</option>\n";
1379         }
1380         else
1381         {
1382              echo "<option value='$all_items'>" . _("All Work Centres") . "</option>\n";
1383         }
1384         }
1385
1386         while ($row = db_fetch_row($result))
1387         {
1388                 if ($selected_id == $row[0])
1389                 {
1390                         echo "<option selected value='" . $row[0] . "'>";
1391                 }
1392                 else
1393                 {
1394                         echo "<option value='" . $row[0] . "'>";
1395                 }
1396                 echo $row[1] . "</option>\n";
1397         }
1398
1399         echo "</select>";
1400         db_free_result($result);
1401 }
1402
1403 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1404 {
1405         default_focus($name);
1406         if ($label != null)
1407                 echo "<td>$label</td>\n";
1408         echo "<td>";
1409         workcenter_list($name, $selected_id, $all_option);
1410         echo "</td>\n";
1411 }
1412
1413 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1414 {
1415         echo "<tr>\n";
1416         workcenter_list_cells($label, $name, $selected_id, $all_option);
1417         echo "</tr>\n";
1418 }
1419
1420 //-----------------------------------------------------------------------------------------------
1421
1422 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1423 {
1424         default_focus($name);
1425         if ($submit_on_change==true)
1426                 echo "<select name='$name' onchange='this.form.submit();'>";
1427         else
1428                 echo "<select name='$name'>";
1429
1430         $company_currency = get_company_currency();
1431
1432         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1433                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1434                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1435         $result = db_query($sql);
1436
1437         if ($selected_id == null)
1438                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1439         while ($row = db_fetch_row($result))
1440         {
1441                 if ($selected_id == $row[0])
1442                 {
1443                         echo "<option selected value='" . $row[0] . "'>";
1444                 }
1445                 else
1446                 {
1447                         echo "<option value='" . $row[0] . "'>";
1448                 }
1449                 echo $row[1];
1450                 if ($company_currency != $row[2])
1451                         echo "&nbsp;-&nbsp;" . $row[2];
1452                 echo  "</option>\n";
1453                 if ($selected_id == "")
1454                 {
1455                         $selected_id = $row[0];
1456                         $_POST[$name] = $selected_id;
1457                 }
1458         }
1459
1460         echo "</select>";
1461         db_free_result($result);
1462 }
1463
1464 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1465 {
1466         if ($label != null)
1467                 echo "<td>$label</td>\n";
1468         echo "<td>";
1469         bank_accounts_list($name, $selected_id, $submit_on_change);
1470         echo "</td>\n";
1471 }
1472
1473 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1474 {
1475         echo "<tr>\n";
1476         bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1477         echo "</tr>\n";
1478 }
1479
1480 //-----------------------------------------------------------------------------------------------
1481
1482 function class_list($name, $selected_id, $submit_on_change=false)
1483 {
1484         default_focus($name);
1485         if ($submit_on_change==true)
1486                 echo "<select name='$name' onchange='this.form.submit();'>";
1487         else
1488                 echo "<select name='$name'>";
1489
1490         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1491         $result = db_query($sql);
1492
1493         if ($selected_id == null)
1494                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1495         while ($row = db_fetch_row($result))
1496         {
1497                 if ($selected_id == $row[0])
1498                 {
1499                         echo "<option selected value='" . $row[0] . "'>";
1500                 }
1501                 else
1502                 {
1503                         echo "<option value='" . $row[0] . "'>";
1504                 }
1505                 echo $row[1] . "</option>\n";
1506                 if ($selected_id == "")
1507                 {
1508                         $selected_id = $row[0];
1509                         $_POST[$name] = $selected_id;
1510                 }
1511         }
1512
1513         echo "</select>";
1514         db_free_result($result);
1515 }
1516
1517 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1518 {
1519         if ($label != null)
1520                 echo "<td>$label</td>\n";
1521         echo "<td>";
1522         class_list($name, $selected_id, $submit_on_change);
1523         echo "</td>\n";
1524 }
1525
1526 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1527 {
1528         echo "<tr>\n";
1529         class_list_cells($label, $name, $selected_id, $submit_on_change);
1530         echo "</tr>\n";
1531 }
1532
1533 //-----------------------------------------------------------------------------------------------
1534
1535 function stock_categories_list($name, $selected_id)
1536 {
1537         simple_codeandname_list("SELECT category_id, description FROM ".TB_PREF."stock_category
1538                 ORDER BY category_id", $name, $selected_id);
1539 }
1540
1541 function stock_categories_list_cells($label, $name, $selected_id)
1542 {
1543         if ($label != null)
1544                 echo "<td>$label</td>\n";
1545         echo "<td>";
1546         stock_categories_list($name, $selected_id);
1547         echo "</td>\n";
1548 }
1549
1550 function stock_categories_list_row($label, $name, $selected_id)
1551 {
1552         echo "<tr>\n";
1553         stock_categories_list_cells($label, $name, $selected_id);
1554         echo "</tr>\n";
1555 }
1556
1557 //-----------------------------------------------------------------------------------------------
1558
1559 function gl_account_types_list($name, $selected_id, $all_option, $all_option_name,
1560         $all_option_numeric)
1561 {
1562         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."chart_types ORDER BY id",
1563                 $name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1564 }
1565
1566 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1567         $all_option_numeric=false)
1568 {
1569         if ($label != null)
1570                 echo "<td>$label</td>\n";
1571         echo "<td>";
1572         gl_account_types_list($name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1573         echo "</td>\n";
1574 }
1575
1576 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1577         $all_option_numeric=false)
1578 {
1579         echo "<tr>\n";
1580         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1581                 $all_option_name, $all_option_numeric);
1582         echo "</tr>\n";
1583 }
1584
1585 //-----------------------------------------------------------------------------------------------
1586
1587 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
1588         $show_group=false, $params="")
1589 {
1590         default_focus($name);
1591         echo "<select name='$name'";
1592         if ($params != "")
1593                 echo " $params";
1594         echo ">";
1595
1596         if ($skip_bank_accounts)
1597                 $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name
1598                         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
1599             WHERE ".TB_PREF."bank_accounts.account_code IS NULL
1600                         AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1601                         ORDER BY account_code;";
1602         else
1603                 $sql = "SELECT account_code, account_name,".TB_PREF."chart_types.name
1604                         FROM ".TB_PREF."chart_master, ".TB_PREF."chart_types
1605                         WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1606                         ORDER BY account_code";
1607
1608         if ($selected_id == null)
1609                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1610         $result = db_query($sql, "query chart master");
1611
1612         while ($row = db_fetch_row($result))
1613         {
1614                 if ($selected_id == $row[0])
1615                 {
1616                         echo "<option selected value='" . $row[0] . "'>";
1617                 }
1618                 else
1619                 {
1620                         echo "<option value='" . $row[0] . "'>";
1621                 }
1622                 //echo str_pad($row[0],6,'0', STR_PAD_LEFT) .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1623                 if ($show_group)
1624                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1625                 else
1626                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1627
1628                 if ($selected_id == "")
1629                 {
1630                         $selected_id = $row[0];
1631                         $_POST[$name] = $selected_id;
1632                 }
1633         }
1634
1635         echo "</select>";
1636         db_free_result($result);
1637 }
1638
1639 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1640         $show_group=false, $params="")
1641 {
1642         if ($label != null)
1643                 echo "<td>$label</td>\n";
1644         echo "<td>";
1645         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $params);
1646         echo "</td>\n";
1647 }
1648
1649 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1650         $show_group=false, $params="")
1651 {
1652         echo "<tr>\n";
1653         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1654                 $show_group, $params);
1655         echo "</tr>\n";
1656 }
1657
1658 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1659 {
1660         default_focus($name);
1661         if ($submit_on_change == true)
1662                 echo "<select name='$name' onchange='this.form.submit();'>";
1663         else
1664                 echo "<select name='$name'>";
1665
1666         if (strlen($name_yes) == 0)
1667         {
1668                 unset($name_yes);
1669         }
1670         if (strlen($name_no) == 0)
1671         {
1672                 unset($name_no);
1673         }
1674
1675         if ($selected_id == null)
1676                 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1677     if ($selected_id == 0)
1678         echo "<option value=1>";
1679     else
1680         echo "<option selected value=1>";
1681         if (!isset($name_yes))
1682                 echo _("Yes") . "</option>\n";
1683         else
1684                 echo $name_yes . "</option>\n";
1685         if ($selected_id == 0)
1686                 echo "<option selected value=0>";
1687         else
1688         echo "<option value=0>";
1689         if (!isset($name_no))
1690                 echo _("No") . "</option>\n";
1691         else
1692                 echo $name_no . "</option>\n";
1693         echo "</select>";
1694 }
1695
1696 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1697 {
1698         if ($label != null)
1699                 echo "<td>$label</td>\n";
1700         echo "<td>";
1701         yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1702         echo "</td>\n";
1703 }
1704
1705 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1706 {
1707         echo "<tr>\n";
1708         yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1709         echo "</tr>\n";
1710 }
1711
1712 //------------------------------------------------------------------------------------------------
1713
1714 function languages_list($name, &$selected_id)
1715 {
1716         global $installed_languages;
1717
1718         default_focus($name);
1719         echo "<select name='$name'>";
1720
1721         if ($selected_id == null)
1722                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1723         foreach ($installed_languages as $lang)
1724         {
1725                 echo "<option ";
1726                 if ($selected_id == $lang['code'])
1727                         echo "selected ";
1728                 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1729         }
1730 }
1731
1732 function languages_list_cells($label, $name, $selected_id)
1733 {
1734         if ($label != null)
1735                 echo "<td>$label</td>\n";
1736         echo "<td>";
1737         languages_list($name, $selected_id);
1738         echo "</td>\n";
1739 }
1740
1741 function languages_list_row($label, $name, $selected_id)
1742 {
1743         echo "<tr>\n";
1744         languages_list_cells($label, $name, $selected_id);
1745         echo "</tr>\n";
1746 }
1747
1748 //------------------------------------------------------------------------------------------------
1749
1750 function bank_account_types_list($name, &$selected_id)
1751 {
1752         $bank_account_types = bank_account_types::get_all();
1753
1754         default_focus($name);
1755         echo "<select name='$name'>";
1756
1757         if ($selected_id == null)
1758                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1759         foreach ($bank_account_types as $type)
1760         {
1761         echo "<option ";
1762         if ($selected_id == "" || $selected_id == $type['id'])
1763                 echo "selected ";
1764         echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1765         }
1766 }
1767
1768 function bank_account_types_list_cells($label, $name, $selected_id)
1769 {
1770         if ($label != null)
1771                 echo "<td>$label</td>\n";
1772         echo "<td>";
1773         bank_account_types_list($name, $selected_id);
1774         echo "</td>\n";
1775 }
1776
1777 function bank_account_types_list_row($label, $name, $selected_id)
1778 {
1779         echo "<tr>\n";
1780         bank_account_types_list_cells($label, $name, $selected_id);
1781         echo "</tr>\n";
1782 }
1783
1784 //------------------------------------------------------------------------------------------------
1785
1786 function payment_person_types_list($name, $selected_id, $related=null)
1787 {
1788         $types = payment_person_types::get_all();
1789
1790         default_focus($name);
1791         echo "<select name='$name'";
1792         if ($related)
1793                 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1794         echo ">";
1795
1796         if ($selected_id == null)
1797                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1798         foreach ($types as $type)
1799         {
1800                 if (payment_person_types::has_items($type['id']))
1801                 {
1802                         if ($selected_id == "")
1803                                 $_POST[$name] = $selected_id = $type['id'];
1804                     echo "<option ";
1805                 if ($selected_id == $type['id'])
1806                         echo "selected ";
1807                     echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1808                 }
1809         }
1810 }
1811
1812 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1813 {
1814         if ($label != null)
1815                 echo "<td>$label</td>\n";
1816         echo "<td>";
1817         payment_person_types_list($name, $selected_id, $related);
1818         echo "</td>\n";
1819 }
1820
1821 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1822 {
1823         echo "<tr>\n";
1824         payment_person_types_list_cells($label, $name, $selected_id, $related);
1825         echo "</tr>\n";
1826 }
1827
1828 //------------------------------------------------------------------------------------------------
1829
1830 function wo_types_list($name, &$selected_id)
1831 {
1832         $types = wo_types::get_all();
1833
1834         default_focus($name);
1835         echo "<select name='$name' onchange='this.form.submit();'>";
1836
1837         if ($selected_id == null)
1838                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1839         foreach ($types as $type)
1840         {
1841             echo "<option ";
1842             if ($selected_id == $type['id'])
1843                 echo "selected ";
1844             echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1845         }
1846         echo "</select>";
1847 }
1848
1849 function wo_types_list_row($label, $name, &$selected_id)
1850 {
1851         echo "<tr><td>$label</td><td>\n";
1852         wo_types_list($name, $selected_id);
1853         echo "</td></tr>\n";
1854 }
1855
1856 //------------------------------------------------------------------------------------------------
1857
1858 function dateformats_list_row($label, $name, $value)
1859 {
1860         global $dateformats;
1861
1862         default_focus($name);
1863         echo "<tr><td>$label</td>\n";
1864         echo "<td><select name='$name'>";
1865
1866         if ($value == null)
1867                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1868         $counter = 0;
1869         foreach ($dateformats as $df)
1870         {
1871
1872                 if ($value==$counter)
1873                 {
1874                         echo "<option selected value='$counter'>$df</option>\n";
1875                 }
1876                 else
1877                 {
1878                         echo "<option value='$counter'>$df</option>\n";
1879                 }
1880                 $counter++;
1881         }
1882         echo "</select></td></tr>\n";
1883 }
1884
1885 function dateseps_list_row($label, $name, $value)
1886 {
1887         global $dateseps;
1888
1889         default_focus($name);
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         default_focus($name);
1917         echo "<tr><td>$label</td>\n";
1918         echo "<td><select name='$name'>";
1919
1920         if ($value == null)
1921                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1922         $counter = 0;
1923         foreach ($thoseps as $ts)
1924         {
1925
1926                 if ($value==$counter)
1927                 {
1928                         echo "<option selected value='$counter'>$ts</option>\n";
1929                 }
1930                 else
1931                 {
1932                         echo "<option value='$counter'>$ts</option>\n";
1933                 }
1934                 $counter++;
1935         }
1936         echo "</select></td></tr>\n";
1937 }
1938
1939 function decseps_list_row($label, $name, $value)
1940 {
1941         global $decseps;
1942
1943         default_focus($name);
1944         echo "<tr><td>$label</td>\n";
1945         echo "<td><select name='$name'>";
1946
1947         if ($value == null)
1948                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1949         $counter = 0;
1950         foreach ($decseps as $ds)
1951         {
1952
1953                 if ($value==$counter)
1954                 {
1955                         echo "<option selected value='$counter'>$ds</option>\n";
1956                 }
1957                 else
1958                 {
1959                         echo "<option value='$counter'>$ds</option>\n";
1960                 }
1961                 $counter++;
1962         }
1963         echo "</select></td></tr>\n";
1964 }
1965
1966 function themes_list_row($label, $name, $value)
1967 {
1968         global $path_to_root;
1969
1970         default_focus($name);
1971         $path = $path_to_root.'/themes/';
1972         $themes = array();
1973         $themedir = opendir($path);
1974         while(false !== ($fname = readdir($themedir))) {
1975             if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname)) {
1976                         $themes[] =  $fname;
1977             }
1978         }
1979         sort($themes);
1980         echo "<tr><td>$label</td>\n";
1981         echo "<td><select name='$name'>";
1982
1983         if ($value == null)
1984                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1985         foreach ($themes as $th)
1986         {
1987
1988                 if ($value==$th)
1989                 {
1990                         echo "<option selected value='$th'>$th</option>\n";
1991                 }
1992                 else
1993                 {
1994                         echo "<option value='$th'>$th</option>\n";
1995                 }
1996         }
1997         echo "</select></td></tr>\n";
1998 }
1999
2000 function pagesizes_list_row($label, $name, $value)
2001 {
2002         global $pagesizes;
2003
2004         default_focus($name);
2005         echo "<tr><td>$label</td>\n";
2006         echo "<td><select name='$name'>";
2007
2008         if ($value == null)
2009                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2010         foreach ($pagesizes as $pz)
2011         {
2012
2013                 if ($value==$pz)
2014                 {
2015                         echo "<option selected value='$pz'>$pz</option>\n";
2016                 }
2017                 else
2018                 {
2019                         echo "<option value='$pz'>$pz</option>\n";
2020                 }
2021         }
2022         echo "</select></td></tr>\n";
2023 }
2024
2025 function security_headings_list_row($label, $name, $value)
2026 {
2027         global $security_headings;
2028
2029         default_focus($name);
2030         echo "<tr><td>$label</td>\n";
2031         echo "<td><select name='$name'>";
2032
2033         if ($value == null)
2034                 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
2035         $counter=0;
2036         foreach ($security_headings as $sh)
2037         {
2038
2039                 if ($value==$counter)
2040                 {
2041                         echo "<option selected value='$counter'>$sh</option>\n";
2042                 }
2043                 else
2044                 {
2045                         echo "<option value='$counter'>$sh</option>\n";
2046                 }
2047                 $counter++;
2048         }
2049         echo "</select></td></tr>\n";
2050 }
2051
2052 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
2053 {
2054         global $systypes_array;
2055
2056         default_focus($name);
2057         if ($label != null)
2058                 echo "<td>$label</td>\n";
2059     echo "<td><select name='$name'";
2060     if ($submit_on_change)
2061         echo " onchange='this.form.submit();'>";
2062     else
2063         echo ">";
2064         if ($value == null)
2065                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2066     foreach ($systypes_array as $key=>$type)
2067     {
2068
2069                 if ($value==$key)
2070                 {
2071                         echo "<option selected value='$key'>".$type['name']."</option>\n";
2072                 }
2073                 else
2074                 {
2075                         echo "<option value='$key'>".$type['name']."</option>\n";
2076                 }
2077     }
2078     echo "</select></td>\n";
2079 }
2080
2081 function systypes_list_row($label, $name, $value, $submit_on_change=false)
2082 {
2083         echo "<tr>\n";
2084         systypes_list_cells($label, $name, $value, $submit_on_change);
2085         echo "</tr>\n";
2086 }
2087
2088 function cust_allocations_list_cells($label, $name, $selected)
2089 {
2090         global $all_items;
2091         default_focus($name);
2092         if ($label != null)
2093                 label_cell($label);
2094         if ($selected == null)
2095                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2096         echo "<td><select name='$name'>";
2097         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
2098         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
2099         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
2100         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
2101         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
2102         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Delivery Notes"). "</option>\n";
2103         echo "</select></td>\n";
2104 }
2105
2106 function supp_allocations_list_cells($name, $selected)
2107 {
2108         global $all_items;
2109
2110         default_focus($name);
2111         if ($selected == null)
2112                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2113         echo "<td><select name='$name'>";
2114         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
2115         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Invoices"). "</option>\n";
2116         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
2117         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
2118         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
2119         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Overdue Credit Notes"). "</option>\n";
2120         echo "</select></td>\n";
2121 }
2122
2123 function policy_list_cells($label, $name, $selected)
2124 {
2125         default_focus($name);
2126         if ($selected == null)
2127         {
2128                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2129                 if ($selected == "")
2130                         $_POST[$name] = $selected;
2131         }
2132         if ($label != null)
2133                 label_cell($label);
2134         echo "<td><select name='$name'>";
2135         echo "<option " . ($selected == ''?" selected ":"") . " value=''>" . _("Automatically put balance on back order"). "</option>\n";
2136         echo "<option " . ($selected == 'CAN'?" selected ":"") . " value='CAN'>" . _("Cancel any quantites not delivered"). "</option>\n";
2137         echo "</select></td>\n";
2138 }
2139
2140 function policy_list_row($label, $name, $selected)
2141 {
2142         echo "<tr>\n";
2143         policy_list_cells($label, $name, $selected);
2144         echo "</tr>\n";
2145 }
2146
2147 function credit_type_list_cells($label, $name, $selected, $submit_on_change=false)
2148 {
2149         default_focus($name);
2150         if ($selected == null)
2151         {
2152                 $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]);
2153                 if ($selected == "Return")
2154                         $_POST[$name] = $selected;
2155         }
2156         if ($label != null)
2157                 label_cell($label);
2158     echo "<td><select name='$name'";
2159     if ($submit_on_change)
2160         echo " onchange='this.form.submit();'>";
2161     else
2162         echo ">";
2163         echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
2164         echo "<option " . ($selected == 'WriteOff'?" selected ":"") . " value='WriteOff'>" . _("Items Written Off"). "</option>\n";
2165         echo "</select></td>\n";
2166 }
2167
2168 function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
2169 {
2170         echo "<tr>\n";
2171         credit_type_list_cells($label, $name, $selected, $submit_on_change);
2172         echo "</tr>\n";
2173 }
2174
2175 function number_list($name, $selected, $from, $to, $firstlabel="")
2176 {
2177         default_focus($name);
2178         if ($selected == null)
2179         {
2180                 $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]);
2181                 if ($selected == $from)
2182                         $_POST[$name] = $selected;
2183         }
2184         echo "<select name='$name'>";
2185         for ($i = $from; $i <= $to; $i++)
2186     {
2187                 if ($i == 0 && $firstlabel != "")
2188                         $label = $firstlabel;
2189                 else
2190                         $label = $i;
2191                 if ($selected == $i)
2192                 {
2193                         echo "<option selected value='$i'>$label</option>\n";
2194                 }
2195                 else
2196                 {
2197                         echo "<option value='$i'>$label</option>\n";
2198                 }
2199     }
2200         echo "</select>\n";
2201 }
2202
2203 function number_list_cells($label, $name, $selected, $from, $to)
2204 {
2205         if ($label != null)
2206                 label_cell($label);
2207         echo "<td>\n";
2208         number_list($name, $selected, $from, $to);
2209         echo "</td>\n";
2210 }
2211
2212 function number_list_row($label, $name, $selected, $from, $to)
2213 {
2214         echo "<tr>\n";
2215         number_list_cells($label, $name, $selected, $from, $to);
2216         echo "</tr>\n";
2217 }
2218 ?>