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