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