*** empty log message ***
[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 $no_supplier_list, $all_items;
17
18         if ($selected_id == null)
19                 $selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]);
20
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 $no_customer_list, $all_items;
131
132         if ($selected_id == null)
133                 $selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]);
134
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, $no_item_list;
610
611         if ($selected_id == null)
612                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
613
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 $no_item_list, $all_items;
902
903         if ($selected_id == null)
904                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
905
906         if ($no_item_list)
907         {
908                 global $search_button;
909                 $edit_name = $name."_edit";
910                 $edit_button = $name."_button";
911
912                 $val = (isset($_POST[$edit_name]) && $_POST[$edit_name] != "" ? $_POST[$edit_name] : "");
913                 if (isset($_POST[$edit_button]))
914                 {
915                         $selected_id = $_POST[$name] = "";
916                 }
917
918                 if ($selected_id != "")
919                 {
920                         $val = DEFVAL;
921                         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
922                                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
923                                 AND mb_flag !='M' AND stock_id='$selected_id'";
924                         $result = db_query($sql);
925                 }
926                 else
927                 {
928                         if ($val != "" && $val != DEFVAL)
929                         {
930                                 $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
931                                         FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE "
932                                         .TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id AND mb_flag !='M' AND
933                                         (stock_id LIKE '%{$val}%' OR ".TB_PREF."stock_category.description LIKE '%{$val}%' OR "
934                                         .TB_PREF."stock_master.description LIKE '%{$val}%')";
935                                 $result = db_query($sql);
936                         }
937                         else
938                                 $result = false;
939                 }
940
941                 echo "<input type='text' name='$edit_name' size='8' maxlength='50' value='$val' onblur='this.form.$edit_button.click();'> ";
942
943                 echo sprintf($search_button, $edit_button);
944         }
945         else
946         {
947                 $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
948                         FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id="
949                         .TB_PREF."stock_category.category_id AND mb_flag !='M'";
950                 $result = db_query($sql);
951         }
952
953         if ($submit_on_change==true)
954                 echo "<select name='$name' onchange='this.form.submit();'>";
955         else if ($extra != "")
956                 echo "<select name='$name' $extra>";
957         else
958                 echo "<select name='$name'>";
959
960         if ($all_option == true)
961         {
962         if ($selected_id == $all_items)
963         {
964              echo "<option selected value='$all_items'>"._("All Items")."</option>\n";
965         }
966         else
967         {
968              echo "<option value='$all_items'>"._("All Items")."</option>\n";
969         }
970                 if ($selected_id == "")
971                 {
972                         $selected_id = $all_items;
973                 }
974         }
975
976         while ($row = db_fetch_row($result))
977         {
978                 if ($selected_id == $row[0])
979                 {
980                         echo "<option selected value='" . $row[0] . "'>";
981                 }
982                 else
983                 {
984                         echo "<option value='" . $row[0] . "'>";
985                 }
986                 echo (user_show_codes()?$row[0] . "&nbsp;-&nbsp;":"") . $row[2] . "&nbsp;-&nbsp;" . $row[1] . "</option>\n";
987
988                 if ($selected_id == "")
989                 {
990                         $selected_id = $row[0];
991                         $_POST[$name] = $selected_id;
992                 }
993         }
994
995         echo "</select>";
996         db_free_result($result);
997 }
998
999 function stock_purchasable_items_list_cells($label, $name, &$selected_id, $all_option=false, $submit_on_change=false, $extra = "")
1000 {
1001         if ($label != null)
1002                 echo "<td>$label</td>\n";
1003         echo "<td>";
1004         stock_purchasable_items_list($name, $selected_id, $all_option, $submit_on_change, $extra);
1005         echo "</td>\n";
1006 }
1007
1008 function stock_purchasable_items_list_row($label, $name, &$selected_id, $all_option=false, $submit_on_change=false)
1009 {
1010         echo "<tr>\n";
1011         stock_purchasable_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
1012         echo "</tr>\n";
1013 }
1014
1015 //------------------------------------------------------------------------------------
1016
1017 function stock_costable_items_list($name, &$selected_id,
1018         $all_option=false, $submit_on_change=false)
1019 {
1020         $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
1021                 FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
1022                 AND mb_flag !='D'";
1023
1024         base_stock_items_list($sql, $name, $selected_id,
1025                 $all_option, _("All Items"), $submit_on_change);
1026 }
1027
1028 //------------------------------------------------------------------------------------
1029
1030 function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
1031 {
1032         echo "<tr>";
1033         if ($label != NULL)
1034                 echo "<td>$label</td>\n";
1035         echo "<td>";
1036         if ($enabled)
1037                 echo "<select name='$name' onchange='this.form.submit();'>\n";
1038         else
1039                 echo "<select disabled name='$name'>\n";
1040         if ($selected_id == null)
1041                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1042         if ($selected_id == "")
1043                 $_POST[$name] = $selected_id = "B";
1044         echo "<option " . ($selected_id == 'M'?" selected ":"") . " value='M'>" . _("Manufactured"). "</option>\n";
1045         echo "<option " . ($selected_id == 'B'?" selected ":"") . " value='B'>" . _("Purchased"). "</option>\n";
1046         echo "<option " . ($selected_id == 'D'?" selected ":"") . " value='D'>" . _("Service"). "</option>\n";
1047         echo "</select></td></tr>\n";
1048 }
1049
1050 function stock_units_list_row($label, $name, $value, $enabled=true)
1051 {
1052         global $stock_units;
1053
1054         echo "<tr><td>$label</td>\n";
1055         if ($enabled)
1056                 echo "<td><select name='$name'>";
1057         else
1058                 echo "<td><select disabled name='$name'>";
1059
1060         if ($value == null)
1061                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1062         foreach ($stock_units as $unit)
1063         {
1064                 if ($value == "")
1065                         $_POST[$name] = $value = $unit;
1066                 if ($value==$unit)
1067                 {
1068                         echo "<option selected value='$unit'>$unit</option>\n";
1069                 }
1070                 else
1071                 {
1072                         echo "<option value='$unit'>$unit</option>\n";
1073                 }
1074         }
1075         echo "</select></td></tr>\n";
1076 }
1077
1078 //------------------------------------------------------------------------------------
1079
1080 function tax_types_list($name, $selected_id,
1081         $none_option=false, $none_option_name=null, $submit_on_change=false)
1082 {
1083         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."tax_types",
1084                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
1085 }
1086
1087 function tax_types_list_cells($label, $name, $selected_id, $none_option=false,
1088         $none_option_name=null, $submit_on_change=false)
1089 {
1090         if ($label != null)
1091                 echo "<td>$label</td>\n";
1092         echo "<td>";
1093         tax_types_list($name, $selected_id, $none_option, $none_option_name, $submit_on_change);
1094         echo "</td>\n";
1095 }
1096
1097 function tax_types_list_row($label, $name, $selected_id, $none_option=false,
1098         $none_option_name=null, $submit_on_change=false)
1099 {
1100         echo "<tr>\n";
1101         tax_types_list_cells($label, $name, $selected_id, $none_option, $none_option_name, $submit_on_change);
1102         echo "</tr>\n";
1103 }
1104
1105 //------------------------------------------------------------------------------------
1106
1107 function tax_groups_list($name, $selected_id,
1108         $none_option=false, $none_option_name=null, $submit_on_change=false)
1109 {
1110         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."tax_groups ORDER BY id",
1111                 $name, $selected_id, $none_option, $none_option_name, true, $submit_on_change);
1112 }
1113
1114 function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
1115 {
1116         if ($label != null)
1117                 echo "<td>$label</td>\n";
1118         echo "<td>";
1119         tax_groups_list($name, $selected_id, false, null, $submit_on_change);
1120         echo "</td>\n";
1121 }
1122
1123 function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
1124 {
1125         echo "<tr>\n";
1126         tax_groups_list_cells($label, $name, $selected_id, false, null, $submit_on_change);
1127         echo "</tr>\n";
1128 }
1129
1130 //------------------------------------------------------------------------------------
1131
1132 function item_tax_types_list($name, $selected_id)
1133 {
1134         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."item_tax_types ORDER BY id",
1135                 $name, $selected_id);
1136 }
1137
1138 function item_tax_types_list_cells($label, $name, $selected_id)
1139 {
1140         if ($label != null)
1141                 echo "<td>$label</td>\n";
1142         echo "<td>";
1143         item_tax_types_list($name, $selected_id);
1144         echo "</td>\n";
1145 }
1146
1147 function item_tax_types_list_row($label, $name, $selected_id)
1148 {
1149         echo "<tr>\n";
1150         item_tax_types_list_cells($label, $name, $selected_id);
1151         echo "</tr>\n";
1152 }
1153
1154 //------------------------------------------------------------------------------------
1155
1156 function shippers_list($name, $selected_id)
1157 {
1158         simple_codeandname_list("SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers",
1159                 $name, $selected_id);
1160 }
1161
1162 function shippers_list_cells($label, $name, $selected_id)
1163 {
1164         if ($label != null)
1165                 echo "<td>$label</td>\n";
1166         echo "<td>";
1167         shippers_list($name, $selected_id);
1168         echo "</td>\n";
1169 }
1170
1171 function shippers_list_row($label, $name, $selected_id)
1172 {
1173         echo "<tr>\n";
1174         shippers_list_cells($label, $name, $selected_id);
1175         echo "</tr>\n";
1176 }
1177
1178 //-------------------------------------------------------------------------------------
1179
1180 function sales_persons_list($name, $selected_id)
1181 {
1182         simple_codeandname_list("SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman",
1183                 $name, $selected_id);
1184 }
1185
1186 function sales_persons_list_cells($label, $name, $selected_id)
1187 {
1188         if ($label != null)
1189                 echo "<td>$label</td>\n";
1190         echo "<td>\n";
1191         sales_persons_list($name, $selected_id);
1192         echo "</td>\n";
1193 }
1194
1195 function sales_persons_list_row($label, $name, $selected_id)
1196 {
1197         echo "<tr>\n";
1198         sales_persons_list_cells($label, $name, $selected_id);
1199         echo "</tr>\n";
1200 }
1201
1202 //------------------------------------------------------------------------------------
1203
1204 function sales_areas_list($name, $selected_id)
1205 {
1206         simple_codeandname_list("SELECT area_code, description FROM ".TB_PREF."areas",
1207                 $name, $selected_id);
1208 }
1209
1210 function sales_areas_list_cells($label, $name, $selected_id)
1211 {
1212         if ($label != null)
1213                 echo "<td>$label</td>\n";
1214         echo "<td>";
1215         sales_areas_list($name, $selected_id);
1216         echo "</td>\n";
1217 }
1218
1219 function sales_areas_list_row($label, $name, $selected_id)
1220 {
1221         echo "<tr>\n";
1222         sales_areas_list_cells($label, $name, $selected_id);
1223         echo "</tr>\n";
1224 }
1225
1226 //------------------------------------------------------------------------------------
1227
1228 function workorders_list($name, $selected_id)
1229 {
1230         simple_codeandname_list("SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0",
1231                 $name, $selected_id);
1232 }
1233
1234 function workorders_list_cells($label, $name, $selected_id)
1235 {
1236         if ($label != null)
1237                 echo "<td>$label</td>\n";
1238         echo "<td>";
1239         workorders_list($name, $selected_id);
1240         echo "</td>\n";
1241 }
1242
1243 function workorders_list_row($label, $name, $selected_id)
1244 {
1245         echo "<tr>\n";
1246         workorders_list_cells($label, $name, $selected_id);
1247         echo "</tr>\n";
1248 }
1249
1250 //------------------------------------------------------------------------------------
1251
1252 function payment_terms_list($name, $selected_id)
1253 {
1254         simple_codeandname_list("SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms",
1255                 $name, $selected_id);
1256 }
1257
1258 function payment_terms_list_cells($label, $name, $selected_id)
1259 {
1260         if ($label != null)
1261                 echo "<td>$label</td>\n";
1262         echo "<td>";
1263         payment_terms_list($name, $selected_id);
1264         echo "</td>\n";
1265 }
1266
1267 function payment_terms_list_row($label, $name, $selected_id)
1268 {
1269         echo "<tr>\n";
1270         payment_terms_list_cells($label, $name, $selected_id);
1271         echo "</tr>\n";
1272 }
1273
1274 //------------------------------------------------------------------------------------
1275
1276 function credit_status_list($name, $selected_id)
1277 {
1278         simple_codeandname_list("SELECT id, reason_description FROM ".TB_PREF."credit_status",
1279                 $name, $selected_id);
1280 }
1281
1282 function credit_status_list_cells($label, $name, $selected_id)
1283 {
1284         if ($label != null)
1285                 echo "<td>$label</td>\n";
1286         echo "<td>";
1287         credit_status_list($name, $selected_id);
1288         echo "</td>\n";
1289 }
1290
1291 function credit_status_list_row($label, $name, $selected_id)
1292 {
1293         echo "<tr>\n";
1294         credit_status_list_cells($label, $name, $selected_id);
1295         echo "</tr>\n";
1296 }
1297
1298 //-----------------------------------------------------------------------------------------------
1299
1300 function sales_types_list($name, $selected_id)
1301 {
1302         simple_codeandname_list("SELECT id, sales_type FROM ".TB_PREF."sales_types",
1303                 $name, $selected_id);
1304 }
1305
1306 function sales_types_list_cells($label, $name, $selected_id)
1307 {
1308         if ($label != null)
1309                 echo "<td>$label</td>\n";
1310         echo "<td>";
1311         sales_types_list($name, $selected_id);
1312         echo "</td>\n";
1313 }
1314
1315 function sales_types_list_row($label, $name, $selected_id)
1316 {
1317         echo "<tr>\n";
1318         sales_types_list_cells($label, $name, $selected_id);
1319         echo "</tr>\n";
1320 }
1321
1322 //-----------------------------------------------------------------------------------------------
1323
1324 function movement_types_list($name, $selected_id)
1325 {
1326         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."movement_types",
1327                 $name, $selected_id);
1328 }
1329
1330 function movement_types_list_cells($label, $name, $selected_id)
1331 {
1332         if ($label != null)
1333                 echo "<td>$label</td>\n";
1334         echo "<td>";
1335         movement_types_list($name, $selected_id);
1336         echo "</td>\n";
1337 }
1338
1339 function movement_types_list_row($label, $name, $selected_id)
1340 {
1341         echo "<tr>\n";
1342         movement_types_list_cells($label, $name, $selected_id);
1343         echo "</tr>\n";
1344 }
1345
1346 //-----------------------------------------------------------------------------------------------
1347
1348 function bank_trans_types_list($name, $selected_id)
1349 {
1350         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."bank_trans_types",
1351                 $name, $selected_id);
1352 }
1353
1354 function bank_trans_types_list_cells($label, $name, $selected_id)
1355 {
1356         if ($label != null)
1357                 echo "<td>$label</td>\n";
1358         echo "<td>";
1359         bank_trans_types_list($name, $selected_id);
1360         echo "</td>\n";
1361 }
1362
1363 function bank_trans_types_list_row($label, $name, $selected_id)
1364 {
1365         echo "<tr>\n";
1366         bank_trans_types_list_cells($label, $name, $selected_id);
1367         echo "</tr>\n";
1368 }
1369
1370 //-----------------------------------------------------------------------------------------------
1371
1372 function workcenter_list($name, $selected_id, $all_option=false)
1373 {
1374         global $all_items;
1375         echo "<select name='$name'>";
1376
1377         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1378         $result = db_query($sql);
1379
1380         if ($selected_id == null)
1381                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1382         if ($all_option == true)
1383         {
1384         if ($selected_id == $all_items)
1385         {
1386              echo "<option selected value='$all_items'>" . _("All Work Centres") . "</option>\n";
1387         }
1388         else
1389         {
1390              echo "<option value='$all_items'>" . _("All Work Centres") . "</option>\n";
1391         }
1392         }
1393
1394         while ($row = db_fetch_row($result))
1395         {
1396                 if ($selected_id == $row[0])
1397                 {
1398                         echo "<option selected value='" . $row[0] . "'>";
1399                 }
1400                 else
1401                 {
1402                         echo "<option value='" . $row[0] . "'>";
1403                 }
1404                 echo $row[1] . "</option>\n";
1405         }
1406
1407         echo "</select>";
1408         db_free_result($result);
1409 }
1410
1411 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1412 {
1413         if ($label != null)
1414                 echo "<td>$label</td>\n";
1415         echo "<td>";
1416         workcenter_list($name, $selected_id, $all_option);
1417         echo "</td>\n";
1418 }
1419
1420 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1421 {
1422         echo "<tr>\n";
1423         workcenter_list_cells($label, $name, $selected_id, $all_option);
1424         echo "</tr>\n";
1425 }
1426
1427 //-----------------------------------------------------------------------------------------------
1428
1429 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1430 {
1431         if ($submit_on_change==true)
1432                 echo "<select name='$name' onchange='this.form.submit();'>";
1433         else
1434                 echo "<select name='$name'>";
1435
1436         $company_currency = get_company_currency();
1437
1438         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1439                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1440                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1441         $result = db_query($sql);
1442
1443         if ($selected_id == null)
1444                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1445         while ($row = db_fetch_row($result))
1446         {
1447                 if ($selected_id == $row[0])
1448                 {
1449                         echo "<option selected value='" . $row[0] . "'>";
1450                 }
1451                 else
1452                 {
1453                         echo "<option value='" . $row[0] . "'>";
1454                 }
1455                 echo $row[1];
1456                 if ($company_currency != $row[2])
1457                         echo "&nbsp;-&nbsp;" . $row[2];
1458                 echo  "</option>\n";
1459                 if ($selected_id == "")
1460                 {
1461                         $selected_id = $row[0];
1462                         $_POST[$name] = $selected_id;
1463                 }
1464         }
1465
1466         echo "</select>";
1467         db_free_result($result);
1468 }
1469
1470 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1471 {
1472         if ($label != null)
1473                 echo "<td>$label</td>\n";
1474         echo "<td>";
1475         bank_accounts_list($name, $selected_id, $submit_on_change);
1476         echo "</td>\n";
1477 }
1478
1479 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1480 {
1481         echo "<tr>\n";
1482         bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1483         echo "</tr>\n";
1484 }
1485
1486 //-----------------------------------------------------------------------------------------------
1487
1488 function class_list($name, $selected_id, $submit_on_change=false)
1489 {
1490         if ($submit_on_change==true)
1491                 echo "<select name='$name' onchange='this.form.submit();'>";
1492         else
1493                 echo "<select name='$name'>";
1494
1495         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1496         $result = db_query($sql);
1497
1498         if ($selected_id == null)
1499                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1500         while ($row = db_fetch_row($result))
1501         {
1502                 if ($selected_id == $row[0])
1503                 {
1504                         echo "<option selected value='" . $row[0] . "'>";
1505                 }
1506                 else
1507                 {
1508                         echo "<option value='" . $row[0] . "'>";
1509                 }
1510                 echo $row[1] . "</option>\n";
1511                 if ($selected_id == "")
1512                 {
1513                         $selected_id = $row[0];
1514                         $_POST[$name] = $selected_id;
1515                 }
1516         }
1517
1518         echo "</select>";
1519         db_free_result($result);
1520 }
1521
1522 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1523 {
1524         if ($label != null)
1525                 echo "<td>$label</td>\n";
1526         echo "<td>";
1527         class_list($name, $selected_id, $submit_on_change);
1528         echo "</td>\n";
1529 }
1530
1531 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1532 {
1533         echo "<tr>\n";
1534         class_list_cells($label, $name, $selected_id, $submit_on_change);
1535         echo "</tr>\n";
1536 }
1537
1538 //-----------------------------------------------------------------------------------------------
1539
1540 function stock_categories_list($name, $selected_id)
1541 {
1542         simple_codeandname_list("SELECT category_id, description FROM ".TB_PREF."stock_category
1543                 ORDER BY category_id", $name, $selected_id);
1544 }
1545
1546 function stock_categories_list_cells($label, $name, $selected_id)
1547 {
1548         if ($label != null)
1549                 echo "<td>$label</td>\n";
1550         echo "<td>";
1551         stock_categories_list($name, $selected_id);
1552         echo "</td>\n";
1553 }
1554
1555 function stock_categories_list_row($label, $name, $selected_id)
1556 {
1557         echo "<tr>\n";
1558         stock_categories_list_cells($label, $name, $selected_id);
1559         echo "</tr>\n";
1560 }
1561
1562 //-----------------------------------------------------------------------------------------------
1563
1564 function gl_account_types_list($name, $selected_id, $all_option, $all_option_name,
1565         $all_option_numeric)
1566 {
1567         simple_codeandname_list("SELECT id, name FROM ".TB_PREF."chart_types ORDER BY id",
1568                 $name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1569 }
1570
1571 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1572         $all_option_numeric=false)
1573 {
1574         if ($label != null)
1575                 echo "<td>$label</td>\n";
1576         echo "<td>";
1577         gl_account_types_list($name, $selected_id, $all_option, $all_option_name, $all_option_numeric);
1578         echo "</td>\n";
1579 }
1580
1581 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false, $all_option_name=null,
1582         $all_option_numeric=false)
1583 {
1584         echo "<tr>\n";
1585         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1586                 $all_option_name, $all_option_numeric);
1587         echo "</tr>\n";
1588 }
1589
1590 //-----------------------------------------------------------------------------------------------
1591
1592 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
1593         $show_group=false, $onchange="")
1594 {
1595         echo "<select name='$name'";
1596         if ($onchange != "")
1597                 echo " onchange='$onchange'";
1598         echo ">";
1599
1600         if ($skip_bank_accounts)
1601                 $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name
1602                         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
1603             WHERE ".TB_PREF."bank_accounts.account_code IS NULL
1604                         AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1605                         ORDER BY account_code;";
1606         else
1607                 $sql = "SELECT account_code, account_name,".TB_PREF."chart_types.name
1608                         FROM ".TB_PREF."chart_master, ".TB_PREF."chart_types
1609                         WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
1610                         ORDER BY account_code";
1611
1612         if ($selected_id == null)
1613                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1614         $result = db_query($sql, "query chart master");
1615
1616         while ($row = db_fetch_row($result))
1617         {
1618                 if ($selected_id == $row[0])
1619                 {
1620                         echo "<option selected value='" . $row[0] . "'>";
1621                 }
1622                 else
1623                 {
1624                         echo "<option value='" . $row[0] . "'>";
1625                 }
1626                 //echo str_pad($row[0],6,'0', STR_PAD_LEFT) .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1627                 if ($show_group)
1628                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1629                 else
1630                         echo $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1] . "</option>\n";
1631
1632                 if ($selected_id == "")
1633                 {
1634                         $selected_id = $row[0];
1635                         $_POST[$name] = $selected_id;
1636                 }
1637         }
1638
1639         echo "</select>";
1640         db_free_result($result);
1641 }
1642
1643 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1644         $show_group=false, $onchange="")
1645 {
1646         if ($label != null)
1647                 echo "<td>$label</td>\n";
1648         echo "<td>";
1649         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $onchange);
1650         echo "</td>\n";
1651 }
1652
1653 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1654         $show_group=false, $onchange="")
1655 {
1656         echo "<tr>\n";
1657         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1658                 $show_group, $onchange);
1659         echo "</tr>\n";
1660 }
1661
1662 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1663 {
1664         if ($submit_on_change == true)
1665                 echo "<select name='$name' onchange='this.form.submit();'>";
1666         else
1667                 echo "<select name='$name'>";
1668
1669         if (strlen($name_yes) == 0)
1670         {
1671                 unset($name_yes);
1672         }
1673         if (strlen($name_no) == 0)
1674         {
1675                 unset($name_no);
1676         }
1677
1678         if ($selected_id == null)
1679                 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1680     if ($selected_id == 0)
1681         echo "<option value=1>";
1682     else
1683         echo "<option selected value=1>";
1684         if (!isset($name_yes))
1685                 echo _("Yes") . "</option>\n";
1686         else
1687                 echo $name_yes . "</option>\n";
1688         if ($selected_id == 0)
1689                 echo "<option selected value=0>";
1690         else
1691         echo "<option value=0>";
1692         if (!isset($name_no))
1693                 echo _("No") . "</option>\n";
1694         else
1695                 echo $name_no . "</option>\n";
1696         echo "</select>";
1697 }
1698
1699 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1700 {
1701         if ($label != null)
1702                 echo "<td>$label</td>\n";
1703         echo "<td>";
1704         yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1705         echo "</td>\n";
1706 }
1707
1708 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1709 {
1710         echo "<tr>\n";
1711         yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1712         echo "</tr>\n";
1713 }
1714
1715 //------------------------------------------------------------------------------------------------
1716
1717 function languages_list($name, &$selected_id)
1718 {
1719         global $installed_languages;
1720
1721         echo "<select name='$name'>";
1722
1723         if ($selected_id == null)
1724                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1725         foreach ($installed_languages as $lang)
1726         {
1727                 echo "<option ";
1728                 if ($selected_id == $lang['code'])
1729                         echo "selected ";
1730                 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1731         }
1732 }
1733
1734 function languages_list_cells($label, $name, $selected_id)
1735 {
1736         if ($label != null)
1737                 echo "<td>$label</td>\n";
1738         echo "<td>";
1739         languages_list($name, $selected_id);
1740         echo "</td>\n";
1741 }
1742
1743 function languages_list_row($label, $name, $selected_id)
1744 {
1745         echo "<tr>\n";
1746         languages_list_cells($label, $name, $selected_id);
1747         echo "</tr>\n";
1748 }
1749
1750 //------------------------------------------------------------------------------------------------
1751
1752 function bank_account_types_list($name, &$selected_id)
1753 {
1754         $bank_account_types = bank_account_types::get_all();
1755
1756         echo "<select name='$name'>";
1757
1758         if ($selected_id == null)
1759                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1760         foreach ($bank_account_types as $type)
1761         {
1762         echo "<option ";
1763         if ($selected_id == "" || $selected_id == $type['id'])
1764                 echo "selected ";
1765         echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1766         }
1767 }
1768
1769 function bank_account_types_list_cells($label, $name, $selected_id)
1770 {
1771         if ($label != null)
1772                 echo "<td>$label</td>\n";
1773         echo "<td>";
1774         bank_account_types_list($name, $selected_id);
1775         echo "</td>\n";
1776 }
1777
1778 function bank_account_types_list_row($label, $name, $selected_id)
1779 {
1780         echo "<tr>\n";
1781         bank_account_types_list_cells($label, $name, $selected_id);
1782         echo "</tr>\n";
1783 }
1784
1785 //------------------------------------------------------------------------------------------------
1786
1787 function payment_person_types_list($name, $selected_id, $related=null)
1788 {
1789         $types = payment_person_types::get_all();
1790
1791         echo "<select name='$name'";
1792         if ($related)
1793                 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1794         echo ">";
1795
1796         if ($selected_id == null)
1797                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1798         foreach ($types as $type)
1799         {
1800                 if (payment_person_types::has_items($type['id']))
1801                 {
1802                         if ($selected_id == "")
1803                                 $_POST[$name] = $selected_id = $type['id'];
1804                     echo "<option ";
1805                 if ($selected_id == $type['id'])
1806                         echo "selected ";
1807                     echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1808                 }
1809         }
1810 }
1811
1812 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1813 {
1814         if ($label != null)
1815                 echo "<td>$label</td>\n";
1816         echo "<td>";
1817         payment_person_types_list($name, $selected_id, $related);
1818         echo "</td>\n";
1819 }
1820
1821 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1822 {
1823         echo "<tr>\n";
1824         payment_person_types_list_cells($label, $name, $selected_id, $related);
1825         echo "</tr>\n";
1826 }
1827
1828 //------------------------------------------------------------------------------------------------
1829
1830 function wo_types_list($name, &$selected_id)
1831 {
1832         $types = wo_types::get_all();
1833
1834         echo "<select name='$name' onchange='this.form.submit();'>";
1835
1836         if ($selected_id == null)
1837                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1838         foreach ($types as $type)
1839         {
1840             echo "<option ";
1841             if ($selected_id == $type['id'])
1842                 echo "selected ";
1843             echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1844         }
1845         echo "</select>";
1846 }
1847
1848 function wo_types_list_row($label, $name, &$selected_id)
1849 {
1850         echo "<tr><td>$label</td><td>\n";
1851         wo_types_list($name, $selected_id);
1852         echo "</td></tr>\n";
1853 }
1854
1855 //------------------------------------------------------------------------------------------------
1856
1857 function dateformats_list_row($label, $name, $value)
1858 {
1859         global $dateformats;
1860
1861         echo "<tr><td>$label</td>\n";
1862         echo "<td><select name='$name'>";
1863
1864         if ($value == null)
1865                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1866         $counter = 0;
1867         foreach ($dateformats as $df)
1868         {
1869
1870                 if ($value==$counter)
1871                 {
1872                         echo "<option selected value='$counter'>$df</option>\n";
1873                 }
1874                 else
1875                 {
1876                         echo "<option value='$counter'>$df</option>\n";
1877                 }
1878                 $counter++;
1879         }
1880         echo "</select></td></tr>\n";
1881 }
1882
1883 function dateseps_list_row($label, $name, $value)
1884 {
1885         global $dateseps;
1886
1887         echo "<tr><td>$label</td>\n";
1888         echo "<td><select name='$name'>";
1889
1890         if ($value == null)
1891                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1892         $counter = 0;
1893         foreach ($dateseps as $ds)
1894         {
1895
1896                 if ($value==$counter)
1897                 {
1898                         echo "<option selected value='$counter'>$ds</option>\n";
1899                 }
1900                 else
1901                 {
1902                         echo "<option value='$counter'>$ds</option>\n";
1903                 }
1904                 $counter++;
1905         }
1906         echo "</select></td></tr>\n";
1907 }
1908
1909 function thoseps_list_row($label, $name, $value)
1910 {
1911         global $thoseps;
1912
1913         echo "<tr><td>$label</td>\n";
1914         echo "<td><select name='$name'>";
1915
1916         if ($value == null)
1917                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1918         $counter = 0;
1919         foreach ($thoseps as $ts)
1920         {
1921
1922                 if ($value==$counter)
1923                 {
1924                         echo "<option selected value='$counter'>$ts</option>\n";
1925                 }
1926                 else
1927                 {
1928                         echo "<option value='$counter'>$ts</option>\n";
1929                 }
1930                 $counter++;
1931         }
1932         echo "</select></td></tr>\n";
1933 }
1934
1935 function decseps_list_row($label, $name, $value)
1936 {
1937         global $decseps;
1938
1939         echo "<tr><td>$label</td>\n";
1940         echo "<td><select name='$name'>";
1941
1942         if ($value == null)
1943                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1944         $counter = 0;
1945         foreach ($decseps as $ds)
1946         {
1947
1948                 if ($value==$counter)
1949                 {
1950                         echo "<option selected value='$counter'>$ds</option>\n";
1951                 }
1952                 else
1953                 {
1954                         echo "<option value='$counter'>$ds</option>\n";
1955                 }
1956                 $counter++;
1957         }
1958         echo "</select></td></tr>\n";
1959 }
1960
1961 function themes_list_row($label, $name, $value)
1962 {
1963         global $themes;
1964
1965         echo "<tr><td>$label</td>\n";
1966         echo "<td><select name='$name'>";
1967
1968         if ($value == null)
1969                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1970         foreach ($themes as $th)
1971         {
1972
1973                 if ($value==$th)
1974                 {
1975                         echo "<option selected value='$th'>$th</option>\n";
1976                 }
1977                 else
1978                 {
1979                         echo "<option value='$th'>$th</option>\n";
1980                 }
1981         }
1982         echo "</select></td></tr>\n";
1983 }
1984
1985 function pagesizes_list_row($label, $name, $value)
1986 {
1987         global $pagesizes;
1988
1989         echo "<tr><td>$label</td>\n";
1990         echo "<td><select name='$name'>";
1991
1992         if ($value == null)
1993                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1994         foreach ($pagesizes as $pz)
1995         {
1996
1997                 if ($value==$pz)
1998                 {
1999                         echo "<option selected value='$pz'>$pz</option>\n";
2000                 }
2001                 else
2002                 {
2003                         echo "<option value='$pz'>$pz</option>\n";
2004                 }
2005         }
2006         echo "</select></td></tr>\n";
2007 }
2008
2009 function security_headings_list_row($label, $name, $value)
2010 {
2011         global $security_headings;
2012
2013         echo "<tr><td>$label</td>\n";
2014         echo "<td><select name='$name'>";
2015
2016         if ($value == null)
2017                 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
2018         $counter=0;
2019         foreach ($security_headings as $sh)
2020         {
2021
2022                 if ($value==$counter)
2023                 {
2024                         echo "<option selected value='$counter'>$sh</option>\n";
2025                 }
2026                 else
2027                 {
2028                         echo "<option value='$counter'>$sh</option>\n";
2029                 }
2030                 $counter++;
2031         }
2032         echo "</select></td></tr>\n";
2033 }
2034
2035 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
2036 {
2037         global $systypes_array;
2038
2039         if ($label != null)
2040                 echo "<td>$label</td>\n";
2041     echo "<td><select name='$name'";
2042     if ($submit_on_change)
2043         echo " onchange='this.form.submit();'>";
2044     else
2045         echo ">";
2046         if ($value == null)
2047                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2048     foreach ($systypes_array as $key=>$type)
2049     {
2050
2051                 if ($value==$key)
2052                 {
2053                         echo "<option selected value='$key'>".$type['name']."</option>\n";
2054                 }
2055                 else
2056                 {
2057                         echo "<option value='$key'>".$type['name']."</option>\n";
2058                 }
2059     }
2060     echo "</select></td>\n";
2061 }
2062
2063 function systypes_list_row($label, $name, $value, $submit_on_change=false)
2064 {
2065         echo "<tr>\n";
2066         systypes_list_cells($label, $name, $value, $submit_on_change);
2067         echo "</tr>\n";
2068 }
2069
2070 function cust_allocations_list_cells($label, $name, $selected)
2071 {
2072         global $all_items;
2073         if ($label != null)
2074                 label_cell($label);
2075         if ($selected == null)
2076                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
2077         echo "<td><select name='$name'>";
2078         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
2079         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
2080         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
2081         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
2082         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit 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 ?>