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