80ff7269dff293484263d9d5c5b651953b81281c
[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     echo "<select name='$name'".
647             ($submit_on_change ? " onchange='this.form.submit();'" : '').
648             ($extra=='' ? '' : " $extra").
649         ">";
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, $special_option=null)
1280 {
1281         simple_codeandname_list("SELECT id, sales_type FROM ".TB_PREF."sales_types",
1282                 $name, $selected_id, 
1283                 isset($special_option), $special_option, true, $submit_on_change);
1284 }
1285
1286 function sales_types_list_cells($label, $name, $selected_id, $submit_on_change=false, $special_option=null)
1287 {
1288         if ($label != null)
1289                 echo "<td>$label</td>\n";
1290         echo "<td>";
1291         sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1292         echo "</td>\n";
1293 }
1294
1295 function sales_types_list_row($label, $name, $selected_id, $submit_on_change=false, $special_option=null)
1296 {
1297         echo "<tr>\n";
1298         sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1299         echo "</tr>\n";
1300 }
1301
1302 //-----------------------------------------------------------------------------------------------
1303
1304 function movement_types_list($name, $selected_id)
1305 {
1306         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."movement_types",
1307                 $name, $selected_id);
1308 }
1309
1310 function movement_types_list_cells($label, $name, $selected_id)
1311 {
1312         if ($label != null)
1313                 echo "<td>$label</td>\n";
1314         echo "<td>";
1315         movement_types_list($name, $selected_id);
1316         echo "</td>\n";
1317 }
1318
1319 function movement_types_list_row($label, $name, $selected_id)
1320 {
1321         echo "<tr>\n";
1322         movement_types_list_cells($label, $name, $selected_id);
1323         echo "</tr>\n";
1324 }
1325
1326 //-----------------------------------------------------------------------------------------------
1327
1328 function bank_trans_types_list($name, $selected_id)
1329 {
1330         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."bank_trans_types",
1331                 $name, $selected_id);
1332 }
1333
1334 function bank_trans_types_list_cells($label, $name, $selected_id)
1335 {
1336         if ($label != null)
1337                 echo "<td>$label</td>\n";
1338         echo "<td>";
1339         bank_trans_types_list($name, $selected_id);
1340         echo "</td>\n";
1341 }
1342
1343 function bank_trans_types_list_row($label, $name, $selected_id)
1344 {
1345         echo "<tr>\n";
1346         bank_trans_types_list_cells($label, $name, $selected_id);
1347         echo "</tr>\n";
1348 }
1349
1350 //-----------------------------------------------------------------------------------------------
1351
1352 function workcenter_list($name, $selected_id, $all_option=false)
1353 {
1354         global $all_items;
1355
1356         default_focus($name);
1357         echo "<select name='$name'>";
1358
1359         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1360         $result = db_query($sql);
1361
1362         if ($selected_id == null)
1363                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1364         if ($all_option == true)
1365         {
1366         if ($selected_id == $all_items)
1367         {
1368              echo "<option selected value='$all_items'>" . _("All Work Centres") . "</option>\n";
1369         }
1370         else
1371         {
1372              echo "<option value='$all_items'>" . _("All Work Centres") . "</option>\n";
1373         }
1374         }
1375
1376         while ($row = db_fetch_row($result))
1377         {
1378                 if ($selected_id == $row[0])
1379                 {
1380                         echo "<option selected value='" . $row[0] . "'>";
1381                 }
1382                 else
1383                 {
1384                         echo "<option value='" . $row[0] . "'>";
1385                 }
1386                 echo $row[1] . "</option>\n";
1387         }
1388
1389         echo "</select>";
1390         db_free_result($result);
1391 }
1392
1393 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1394 {
1395         default_focus($name);
1396         if ($label != null)
1397                 echo "<td>$label</td>\n";
1398         echo "<td>";
1399         workcenter_list($name, $selected_id, $all_option);
1400         echo "</td>\n";
1401 }
1402
1403 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1404 {
1405         echo "<tr>\n";
1406         workcenter_list_cells($label, $name, $selected_id, $all_option);
1407         echo "</tr>\n";
1408 }
1409
1410 //-----------------------------------------------------------------------------------------------
1411
1412 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1413 {
1414         default_focus($name);
1415         if ($submit_on_change==true)
1416                 echo "<select name='$name' onchange='this.form.submit();'>";
1417         else
1418                 echo "<select name='$name'>";
1419
1420         $company_currency = get_company_currency();
1421
1422         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1423                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1424                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1425         $result = db_query($sql);
1426
1427         if ($selected_id == null)
1428                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1429         while ($row = db_fetch_row($result))
1430         {
1431                 if ($selected_id == $row[0])
1432                 {
1433                         echo "<option selected value='" . $row[0] . "'>";
1434                 }
1435                 else
1436                 {
1437                         echo "<option value='" . $row[0] . "'>";
1438                 }
1439                 echo $row[1];
1440                 if ($company_currency != $row[2])
1441                         echo "&nbsp;-&nbsp;" . $row[2];
1442                 echo  "</option>\n";
1443                 if ($selected_id == "")
1444                 {
1445                         $selected_id = $row[0];
1446                         $_POST[$name] = $selected_id;
1447                 }
1448         }
1449
1450         echo "</select>";
1451         db_free_result($result);
1452 }
1453
1454 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1455 {
1456         if ($label != null)
1457                 echo "<td>$label</td>\n";
1458         echo "<td>";
1459         bank_accounts_list($name, $selected_id, $submit_on_change);
1460         echo "</td>\n";
1461 }
1462
1463 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1464 {
1465         echo "<tr>\n";
1466         bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1467         echo "</tr>\n";
1468 }
1469
1470 //-----------------------------------------------------------------------------------------------
1471
1472 function class_list($name, $selected_id, $submit_on_change=false)
1473 {
1474         default_focus($name);
1475         if ($submit_on_change==true)
1476                 echo "<select name='$name' onchange='this.form.submit();'>";
1477         else
1478                 echo "<select name='$name'>";
1479
1480         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1481         $result = db_query($sql);
1482
1483         if ($selected_id == null)
1484                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1485         while ($row = db_fetch_row($result))
1486         {
1487                 if ($selected_id == $row[0])
1488                 {
1489                         echo "<option selected value='" . $row[0] . "'>";
1490                 }
1491                 else
1492                 {
1493                         echo "<option value='" . $row[0] . "'>";
1494                 }
1495                 echo $row[1] . "</option>\n";
1496                 if ($selected_id == "")
1497                 {
1498                         $selected_id = $row[0];
1499                         $_POST[$name] = $selected_id;
1500                 }
1501         }
1502
1503         echo "</select>";
1504         db_free_result($result);
1505 }
1506
1507 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1508 {
1509         if ($label != null)
1510                 echo "<td>$label</td>\n";
1511         echo "<td>";
1512         class_list($name, $selected_id, $submit_on_change);
1513         echo "</td>\n";
1514 }
1515
1516 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1517 {
1518         echo "<tr>\n";
1519         class_list_cells($label, $name, $selected_id, $submit_on_change);
1520         echo "</tr>\n";
1521 }
1522
1523 //-----------------------------------------------------------------------------------------------
1524
1525 function stock_categories_list($name, $selected_id)
1526 {
1527         simple_codeandname_list("SELECT category_id, description FROM ".TB_PREF."stock_category
1528                 ORDER BY category_id", $name, $selected_id);
1529 }
1530
1531 function stock_categories_list_cells($label, $name, $selected_id)
1532 {
1533         if ($label != null)
1534                 echo "<td>$label</td>\n";
1535         echo "<td>";
1536         stock_categories_list($name, $selected_id);
1537         echo "</td>\n";
1538 }
1539
1540 function stock_categories_list_row($label, $name, $selected_id)
1541 {
1542         echo "<tr>\n";
1543         stock_categories_list_cells($label, $name, $selected_id);
1544         echo "</tr>\n";
1545 }
1546
1547 //-----------------------------------------------------------------------------------------------
1548
1549 function gl_account_types_list($name, $selected_id, $all_option, $all_option_name,
1550         $all_option_numeric)
1551 {
1552         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."chart_types ORDER BY id",
1553                 $name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1554 }
1555
1556 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1557         $all_option_numeric=false)
1558 {
1559         if ($label != null)
1560                 echo "<td>$label</td>\n";
1561         echo "<td>";
1562         gl_account_types_list($name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1563         echo "</td>\n";
1564 }
1565
1566 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1567         $all_option_numeric=false)
1568 {
1569         echo "<tr>\n";
1570         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1571                 $all_option_name, $all_option_numeric);
1572         echo "</tr>\n";
1573 }
1574
1575 //-----------------------------------------------------------------------------------------------
1576
1577 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
1578         $show_group=false, $params="")
1579 {
1580         default_focus($name);
1581         echo "<select name='$name'";
1582         if ($params != "")
1583                 echo " $params";
1584         echo ">";
1585
1586         if ($skip_bank_accounts)
1587                 $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name
1588                         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
1589             WHERE ".TB_PREF."bank_accounts.account_code IS NULL
1590                         AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1591                         ORDER BY account_code;";
1592         else
1593                 $sql = "SELECT account_code, account_name,".TB_PREF."chart_types.name
1594                         FROM ".TB_PREF."chart_master, ".TB_PREF."chart_types
1595                         WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1596                         ORDER BY account_code";
1597
1598         if ($selected_id == null)
1599                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1600         $result = db_query($sql, "query chart master");
1601
1602         while ($row = db_fetch_row($result))
1603         {
1604                 if ($selected_id == $row[0])
1605                 {
1606                         echo "<option selected value='" . $row[0] . "'>";
1607                 }
1608                 else
1609                 {
1610                         echo "<option value='" . $row[0] . "'>";
1611                 }
1612                 //echo str_pad($row[0],6,'0', STR_PAD_LEFT) .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1613                 if ($show_group)
1614                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1615                 else
1616                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1617
1618                 if ($selected_id == "")
1619                 {
1620                         $selected_id = $row[0];
1621                         $_POST[$name] = $selected_id;
1622                 }
1623         }
1624
1625         echo "</select>";
1626         db_free_result($result);
1627 }
1628
1629 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1630         $show_group=false, $params="")
1631 {
1632         if ($label != null)
1633                 echo "<td>$label</td>\n";
1634         echo "<td>";
1635         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $params);
1636         echo "</td>\n";
1637 }
1638
1639 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1640         $show_group=false, $params="")
1641 {
1642         echo "<tr>\n";
1643         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1644                 $show_group, $params);
1645         echo "</tr>\n";
1646 }
1647
1648 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1649 {
1650         default_focus($name);
1651         if ($submit_on_change == true)
1652                 echo "<select name='$name' onchange='this.form.submit();'>";
1653         else
1654                 echo "<select name='$name'>";
1655
1656         if (strlen($name_yes) == 0)
1657         {
1658                 unset($name_yes);
1659         }
1660         if (strlen($name_no) == 0)
1661         {
1662                 unset($name_no);
1663         }
1664
1665         if ($selected_id == null)
1666                 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1667     if ($selected_id == 0)
1668         echo "<option value=1>";
1669     else
1670         echo "<option selected value=1>";
1671         if (!isset($name_yes))
1672                 echo _("Yes") . "</option>\n";
1673         else
1674                 echo $name_yes . "</option>\n";
1675         if ($selected_id == 0)
1676                 echo "<option selected value=0>";
1677         else
1678         echo "<option value=0>";
1679         if (!isset($name_no))
1680                 echo _("No") . "</option>\n";
1681         else
1682                 echo $name_no . "</option>\n";
1683         echo "</select>";
1684 }
1685
1686 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1687 {
1688         if ($label != null)
1689                 echo "<td>$label</td>\n";
1690         echo "<td>";
1691         yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1692         echo "</td>\n";
1693 }
1694
1695 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1696 {
1697         echo "<tr>\n";
1698         yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1699         echo "</tr>\n";
1700 }
1701
1702 //------------------------------------------------------------------------------------------------
1703
1704 function languages_list($name, &$selected_id)
1705 {
1706         global $installed_languages;
1707
1708         default_focus($name);
1709         echo "<select name='$name'>";
1710
1711         if ($selected_id == null)
1712                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1713         foreach ($installed_languages as $lang)
1714         {
1715                 echo "<option ";
1716                 if ($selected_id == $lang['code'])
1717                         echo "selected ";
1718                 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1719         }
1720 }
1721
1722 function languages_list_cells($label, $name, $selected_id)
1723 {
1724         if ($label != null)
1725                 echo "<td>$label</td>\n";
1726         echo "<td>";
1727         languages_list($name, $selected_id);
1728         echo "</td>\n";
1729 }
1730
1731 function languages_list_row($label, $name, $selected_id)
1732 {
1733         echo "<tr>\n";
1734         languages_list_cells($label, $name, $selected_id);
1735         echo "</tr>\n";
1736 }
1737
1738 //------------------------------------------------------------------------------------------------
1739
1740 function bank_account_types_list($name, &$selected_id)
1741 {
1742         $bank_account_types = bank_account_types::get_all();
1743
1744         default_focus($name);
1745         echo "<select name='$name'>";
1746
1747         if ($selected_id == null)
1748                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1749         foreach ($bank_account_types as $type)
1750         {
1751         echo "<option ";
1752         if ($selected_id == "" || $selected_id == $type['id'])
1753                 echo "selected ";
1754         echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1755         }
1756 }
1757
1758 function bank_account_types_list_cells($label, $name, $selected_id)
1759 {
1760         if ($label != null)
1761                 echo "<td>$label</td>\n";
1762         echo "<td>";
1763         bank_account_types_list($name, $selected_id);
1764         echo "</td>\n";
1765 }
1766
1767 function bank_account_types_list_row($label, $name, $selected_id)
1768 {
1769         echo "<tr>\n";
1770         bank_account_types_list_cells($label, $name, $selected_id);
1771         echo "</tr>\n";
1772 }
1773
1774 //------------------------------------------------------------------------------------------------
1775
1776 function payment_person_types_list($name, $selected_id, $related=null)
1777 {
1778         $types = payment_person_types::get_all();
1779
1780         default_focus($name);
1781         echo "<select name='$name'";
1782         if ($related)
1783                 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1784         echo ">";
1785
1786         if ($selected_id == null)
1787                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1788         foreach ($types as $type)
1789         {
1790                 if (payment_person_types::has_items($type['id']))
1791                 {
1792                         if ($selected_id == "")
1793                                 $_POST[$name] = $selected_id = $type['id'];
1794                     echo "<option ";
1795                 if ($selected_id == $type['id'])
1796                         echo "selected ";
1797                     echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1798                 }
1799         }
1800 }
1801
1802 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1803 {
1804         if ($label != null)
1805                 echo "<td>$label</td>\n";
1806         echo "<td>";
1807         payment_person_types_list($name, $selected_id, $related);
1808         echo "</td>\n";
1809 }
1810
1811 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1812 {
1813         echo "<tr>\n";
1814         payment_person_types_list_cells($label, $name, $selected_id, $related);
1815         echo "</tr>\n";
1816 }
1817
1818 //------------------------------------------------------------------------------------------------
1819
1820 function wo_types_list($name, &$selected_id)
1821 {
1822         $types = wo_types::get_all();
1823
1824         default_focus($name);
1825         echo "<select name='$name' onchange='this.form.submit();'>";
1826
1827         if ($selected_id == null)
1828                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1829         foreach ($types as $type)
1830         {
1831             echo "<option ";
1832             if ($selected_id == $type['id'])
1833                 echo "selected ";
1834             echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1835         }
1836         echo "</select>";
1837 }
1838
1839 function wo_types_list_row($label, $name, &$selected_id)
1840 {
1841         echo "<tr><td>$label</td><td>\n";
1842         wo_types_list($name, $selected_id);
1843         echo "</td></tr>\n";
1844 }
1845
1846 //------------------------------------------------------------------------------------------------
1847
1848 function dateformats_list_row($label, $name, $value)
1849 {
1850         global $dateformats;
1851
1852         default_focus($name);
1853         echo "<tr><td>$label</td>\n";
1854         echo "<td><select name='$name'>";
1855
1856         if ($value == null)
1857                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1858         $counter = 0;
1859         foreach ($dateformats as $df)
1860         {
1861
1862                 if ($value==$counter)
1863                 {
1864                         echo "<option selected value='$counter'>$df</option>\n";
1865                 }
1866                 else
1867                 {
1868                         echo "<option value='$counter'>$df</option>\n";
1869                 }
1870                 $counter++;
1871         }
1872         echo "</select></td></tr>\n";
1873 }
1874
1875 function dateseps_list_row($label, $name, $value)
1876 {
1877         global $dateseps;
1878
1879         default_focus($name);
1880         echo "<tr><td>$label</td>\n";
1881         echo "<td><select name='$name'>";
1882
1883         if ($value == null)
1884                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1885         $counter = 0;
1886         foreach ($dateseps as $ds)
1887         {
1888
1889                 if ($value==$counter)
1890                 {
1891                         echo "<option selected value='$counter'>$ds</option>\n";
1892                 }
1893                 else
1894                 {
1895                         echo "<option value='$counter'>$ds</option>\n";
1896                 }
1897                 $counter++;
1898         }
1899         echo "</select></td></tr>\n";
1900 }
1901
1902 function thoseps_list_row($label, $name, $value)
1903 {
1904         global $thoseps;
1905
1906         default_focus($name);
1907         echo "<tr><td>$label</td>\n";
1908         echo "<td><select name='$name'>";
1909
1910         if ($value == null)
1911                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1912         $counter = 0;
1913         foreach ($thoseps as $ts)
1914         {
1915
1916                 if ($value==$counter)
1917                 {
1918                         echo "<option selected value='$counter'>$ts</option>\n";
1919                 }
1920                 else
1921                 {
1922                         echo "<option value='$counter'>$ts</option>\n";
1923                 }
1924                 $counter++;
1925         }
1926         echo "</select></td></tr>\n";
1927 }
1928
1929 function decseps_list_row($label, $name, $value)
1930 {
1931         global $decseps;
1932
1933         default_focus($name);
1934         echo "<tr><td>$label</td>\n";
1935         echo "<td><select name='$name'>";
1936
1937         if ($value == null)
1938                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1939         $counter = 0;
1940         foreach ($decseps as $ds)
1941         {
1942
1943                 if ($value==$counter)
1944                 {
1945                         echo "<option selected value='$counter'>$ds</option>\n";
1946                 }
1947                 else
1948                 {
1949                         echo "<option value='$counter'>$ds</option>\n";
1950                 }
1951                 $counter++;
1952         }
1953         echo "</select></td></tr>\n";
1954 }
1955
1956 function themes_list_row($label, $name, $value)
1957 {
1958         global $path_to_root;
1959
1960         default_focus($name);
1961         $path = $path_to_root.'/themes/';
1962         $themes = array();
1963         $themedir = opendir($path);
1964         while(false !== ($fname = readdir($themedir))) {
1965             if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname)) {
1966                         $themes[] =  $fname;
1967             }
1968         }
1969         sort($themes);
1970         echo "<tr><td>$label</td>\n";
1971         echo "<td><select name='$name'>";
1972
1973         if ($value == null)
1974                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1975         foreach ($themes as $th)
1976         {
1977
1978                 if ($value==$th)
1979                 {
1980                         echo "<option selected value='$th'>$th</option>\n";
1981                 }
1982                 else
1983                 {
1984                         echo "<option value='$th'>$th</option>\n";
1985                 }
1986         }
1987         echo "</select></td></tr>\n";
1988 }
1989
1990 function pagesizes_list_row($label, $name, $value)
1991 {
1992         global $pagesizes;
1993
1994         default_focus($name);
1995         echo "<tr><td>$label</td>\n";
1996         echo "<td><select name='$name'>";
1997
1998         if ($value == null)
1999                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2000         foreach ($pagesizes as $pz)
2001         {
2002
2003                 if ($value==$pz)
2004                 {
2005                         echo "<option selected value='$pz'>$pz</option>\n";
2006                 }
2007                 else
2008                 {
2009                         echo "<option value='$pz'>$pz</option>\n";
2010                 }
2011         }
2012         echo "</select></td></tr>\n";
2013 }
2014
2015 function security_headings_list_row($label, $name, $value)
2016 {
2017         global $security_headings;
2018
2019         default_focus($name);
2020         echo "<tr><td>$label</td>\n";
2021         echo "<td><select name='$name'>";
2022
2023         if ($value == null)
2024                 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
2025         $counter=0;
2026         foreach ($security_headings as $sh)
2027         {
2028
2029                 if ($value==$counter)
2030                 {
2031                         echo "<option selected value='$counter'>$sh</option>\n";
2032                 }
2033                 else
2034                 {
2035                         echo "<option value='$counter'>$sh</option>\n";
2036                 }
2037                 $counter++;
2038         }
2039         echo "</select></td></tr>\n";
2040 }
2041
2042 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
2043 {
2044         global $systypes_array;
2045
2046         default_focus($name);
2047         if ($label != null)
2048                 echo "<td>$label</td>\n";
2049     echo "<td><select name='$name'";
2050     if ($submit_on_change)
2051         echo " onchange='this.form.submit();'>";
2052     else
2053         echo ">";
2054         if ($value == null)
2055                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2056     foreach ($systypes_array as $key=>$type)
2057     {
2058
2059                 if ($value==$key)
2060                 {
2061                         echo "<option selected value='$key'>".$type['name']."</option>\n";
2062                 }
2063                 else
2064                 {
2065                         echo "<option value='$key'>".$type['name']."</option>\n";
2066                 }
2067     }
2068     echo "</select></td>\n";
2069 }
2070
2071 function systypes_list_row($label, $name, $value, $submit_on_change=false)
2072 {
2073         echo "<tr>\n";
2074         systypes_list_cells($label, $name, $value, $submit_on_change);
2075         echo "</tr>\n";
2076 }
2077
2078 function cust_allocations_list_cells($label, $name, $selected)
2079 {
2080         global $all_items;
2081         default_focus($name);
2082         if ($label != null)
2083                 label_cell($label);
2084         if ($selected == null)
2085                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2086         echo "<td><select name='$name'>";
2087         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
2088         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
2089         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
2090         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
2091         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
2092         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Delivery Notes"). "</option>\n";
2093         echo "</select></td>\n";
2094 }
2095
2096 function supp_allocations_list_cells($name, $selected)
2097 {
2098         global $all_items;
2099
2100         default_focus($name);
2101         if ($selected == null)
2102                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2103         echo "<td><select name='$name'>";
2104         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
2105         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Invoices"). "</option>\n";
2106         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
2107         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
2108         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
2109         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Overdue Credit Notes"). "</option>\n";
2110         echo "</select></td>\n";
2111 }
2112
2113 function policy_list_cells($label, $name, $selected)
2114 {
2115         default_focus($name);
2116         if ($selected == null)
2117         {
2118                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2119                 if ($selected == "")
2120                         $_POST[$name] = $selected;
2121         }
2122         if ($label != null)
2123                 label_cell($label);
2124         echo "<td><select name='$name'>";
2125         echo "<option " . ($selected == ''?" selected ":"") . " value=''>" . _("Automatically put balance on back order"). "</option>\n";
2126         echo "<option " . ($selected == 'CAN'?" selected ":"") . " value='CAN'>" . _("Cancel any quantites not delivered"). "</option>\n";
2127         echo "</select></td>\n";
2128 }
2129
2130 function policy_list_row($label, $name, $selected)
2131 {
2132         echo "<tr>\n";
2133         policy_list_cells($label, $name, $selected);
2134         echo "</tr>\n";
2135 }
2136
2137 function credit_type_list_cells($label, $name, $selected, $submit_on_change=false)
2138 {
2139         default_focus($name);
2140         if ($selected == null)
2141         {
2142                 $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]);
2143                 if ($selected == "Return")
2144                         $_POST[$name] = $selected;
2145         }
2146         if ($label != null)
2147                 label_cell($label);
2148     echo "<td><select name='$name'";
2149     if ($submit_on_change)
2150         echo " onchange='this.form.submit();'>";
2151     else
2152         echo ">";
2153         echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
2154         echo "<option " . ($selected == 'WriteOff'?" selected ":"") . " value='WriteOff'>" . _("Items Written Off"). "</option>\n";
2155         echo "</select></td>\n";
2156 }
2157
2158 function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
2159 {
2160         echo "<tr>\n";
2161         credit_type_list_cells($label, $name, $selected, $submit_on_change);
2162         echo "</tr>\n";
2163 }
2164
2165 function number_list($name, $selected, $from, $to, $firstlabel="")
2166 {
2167         default_focus($name);
2168         if ($selected == null)
2169         {
2170                 $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]);
2171                 if ($selected == $from)
2172                         $_POST[$name] = $selected;
2173         }
2174         echo "<select name='$name'>";
2175         for ($i = $from; $i <= $to; $i++)
2176     {
2177                 if ($i == 0 && $firstlabel != "")
2178                         $label = $firstlabel;
2179                 else
2180                         $label = $i;
2181                 if ($selected == $i)
2182                 {
2183                         echo "<option selected value='$i'>$label</option>\n";
2184                 }
2185                 else
2186                 {
2187                         echo "<option value='$i'>$label</option>\n";
2188                 }
2189     }
2190         echo "</select>\n";
2191 }
2192
2193 function number_list_cells($label, $name, $selected, $from, $to)
2194 {
2195         if ($label != null)
2196                 label_cell($label);
2197         echo "<td>\n";
2198         number_list($name, $selected, $from, $to);
2199         echo "</td>\n";
2200 }
2201
2202 function number_list_row($label, $name, $selected, $from, $to)
2203 {
2204         echo "<tr>\n";
2205         number_list_cells($label, $name, $selected, $from, $to);
2206         echo "</tr>\n";
2207 }
2208 ?>