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