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