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