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