Bug in tax_types_list (spec_id)
[fa-stable.git] / includes / ui / ui_lists.inc
1 <?php
2
3 include_once($path_to_root . "/includes/banking.inc");
4 include_once($path_to_root . "/includes/reserved.inc");
5 include_once($path_to_root . "/includes/types.inc");
6 include_once($path_to_root . "/includes/current_user.inc");
7
8 $_search_button = "<input type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
9         ."%s/images/locate.png) no-repeat;%s' name='%s' value=' ' title='"._("Set filter")."'> ";
10
11 $_select_button = "<input type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
12         ."%s/images/button_ok.png) no-repeat;%s' name='%s' value=' ' title='"._("Select")."'> ";
13
14 $all_items = reserved_words::get_all();
15
16 //----------------------------------------------------------------------------
17 //      Universal combo generator
18 //      $sql must return selector values and selector texts in columns 0 & 1
19 //      Options are merged with defaults.
20
21 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
22         $options=null)
23 {
24 global $Ajax;
25
26 $opts = array(          // default options
27         'where'=> array(),              // additional constraints
28         'order' => $namefield,  // list sort order
29                 // special option parameters
30         'spec_option'=>false,   // option text or false
31         'spec_id' => 0,         // option id
32                 // submit on select parameters
33         'select_submit' => false, //submit on select: true/false
34         'async' => true,        // select update via ajax (true) vs _page_body reload
35                 // search box parameters
36         'sel_hint' => null,
37         'search_box' => false,  // name or true/false
38         'type' => 0,    // type of extended selector:
39                 // 0 - with (optional) visible search box, search by id
40                 // 1 - with hidden search box, search by option text
41                 // 2 - TODO reverse: box with hidden selector available via enter; this
42                 // would be convenient for optional ad hoc adding of new item
43         'search_submit' => true, //search submit button: true/false
44         'size' => 8,    // size and max of box tag
45         'max' => 50,
46         'cells' => false,       // combo displayed as 2 <td></td> cells
47         'search' => array(), // sql field names to search
48         'format' => null,        // format functions for regular options
49         'disabled' => false, // FIX todo
50         'box_hint' => null // box/selectors hints; null = std see below
51 );
52 // ------ merge options with defaults ----------
53         $opts = array_merge($opts, $options);
54         if (!is_array($opts['where']))  $opts['where'] = array($opts['where']);
55
56         $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
57         $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
58         $select_submit =  $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
59         $spec_id = $opts['spec_id'];
60         $spec_option = $opts['spec_option'];
61         $by_id = ($opts['type'] == 0);
62         $class = $by_id ? 'combo':'combo2';
63
64         if(!count($opts['search'])) {
65                 $opts['search'] = array($by_id ? $valfield : $namefield);
66         }
67         if ($opts['sel_hint'] === null)
68                 $opts['sel_hint'] = $by_id || $search_box==false ?
69                 '' : _('Press Space tab for search pattern entry');
70
71         if ($opts['box_hint'] === null)
72                 $opts['box_hint'] = $search_box ?
73                         ($by_id ? _('Enter code fragment to search or * for all')
74                         : _('Enter description fragment to search or * for all')) :'';
75
76         if ($selected_id == null) {
77                 $selected_id = get_post($name, null);
78         }
79         $txt = get_post($search_box);
80         $rel = '';
81         $limit = '';
82
83         if (isset($_POST[$select_submit])) {
84                 if (!$opts['async'])
85                         $Ajax->activate('_page_body');
86                 else
87                         $Ajax->activate($name);
88         }
89         if ($search_box) {
90                 // search related sql modifications
91
92         $rel = "rel='$search_box'"; // set relation to list
93    if ($opts['search_submit']) {
94         // if selected from list - set focus on next field
95         if (isset($_POST[$search_submit])) {
96                 $Ajax->activate($name);
97         }
98         if ($txt == '') {
99                 if ($spec_option === false)
100                 $limit = ' LIMIT 1';
101                 else
102                 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
103         }
104         else
105                 if ($txt != '*') {
106
107                 foreach($opts['search'] as $i=> $s)
108                         $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
109                 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
110                 }
111         }
112    }
113         // sql completion
114         if (count($opts['where'])) {
115                 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
116                 $sql .= '('. implode($opts['where'], ' AND ') . ')';
117         }
118         if ($opts['order'] != false) {
119                 $sql .= ' ORDER BY '.$opts['order'];
120         }
121
122         $sql .= $limit;
123         // ------ make selector ----------
124         $selector = $first_opt = '';
125         $first_id = false;
126         $found = false;
127 //if($name=='code_id')    display_error($sql);
128         if($result = db_query($sql)) {
129                 while ($contact_row = db_fetch($result)) {
130                         $value = $contact_row[0];
131                         $descr = $opts['format']==null ?  $contact_row[1] :
132                         call_user_func($opts['format'], $contact_row);
133                         $sel = '';
134                         if ($selected_id === $value) {
135                                 $sel = 'selected';
136                                 $found = $value;
137                         }
138                         if ($first_id === false) {
139                                 $first_id = $value;
140                                 $first_opt = $descr;
141                         }
142                         $selector .= "<option $sel value='$value'>$descr</option>\n";
143                 }
144                 db_free_result($result);
145         }
146         // Prepend special option.
147         if ($spec_option !== false) { // if special option used - add it
148                 $first_id = $spec_id;
149                 $first_opt = $spec_option;
150                 $sel = $found===false ? 'selected' : '';
151                 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
152                         . $selector;
153         }
154
155         if ($found === false) {
156                 $_POST[$name] = $first_id;
157         }
158
159         if ($by_id) {
160                 $txt = $_POST[$name];
161                 if ($search_box)
162                         $Ajax->addUpdate($name, $search_box, $txt);
163         }
164
165         $selector = "<select name='$name' class='$class' title='"
166                 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
167
168         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
169
170         // because of bug which M$ cannot fix since IE 5.0
171         // we must embed whole selector in span tags to enable proper ajax update
172         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
173
174         if ($select_submit != false) { // if submit on change is used - add select button
175                 global $_select_button;
176         // button class selects form reload/ajax selector update
177                 $selector .= sprintf($_select_button, user_theme(),
178                         (in_ajax() ? 'display:none;':''),
179                         $select_submit)."\n";
180         }
181 // ------ make combo ----------
182
183         $edit_entry = '';
184         if ($search_box != false) {
185                 $edit_entry = "<input type='text' name='$search_box' id='$search_box' size='".
186                         $opts['size']."' maxlength='".$opts['max'].
187                         "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
188                         .$opts['box_hint']."'"
189                         .(in_ajax() && !$by_id ? " style=display:none;":'')
190                         .">\n";
191                 if ($search_submit != false) {
192                         global $_search_button;
193                         $edit_entry .= sprintf($_search_button, user_theme(),
194                                 (in_ajax() ? 'display:none;':''),
195                                 $search_submit)."\n";
196                 }
197         }
198         default_focus($name);
199         $str = $selector;
200         if ($search_box && $opts['cells'])
201                 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
202         else
203                 echo $edit_entry.$selector;
204
205         return $str;
206 }
207
208 function supplier_list($name, $selected_id, $spec_option=false, $submit_on_change=false)
209 {
210         global $all_items;
211
212         $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
213
214         $mode = get_company_pref('no_supplier_list');
215
216         return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
217         array(
218                 'format' => '_format_add_curr',
219                 'search_box' => $mode!=0,
220                 'type' => 1,
221                 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
222                 'spec_id' => $all_items,
223                 'select_submit'=> $submit_on_change,
224                 'async' => false,
225                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
226                 _('Select supplier')
227                 ));
228 }
229
230 function _format_add_curr($row)
231 {
232 static $company_currency;
233
234 if ($company_currency == null)
235 {
236         $company_currency = get_company_currency();
237 }
238 return $row[1] . ($row[2] == $company_currency ?
239         '' : ("&nbsp;-&nbsp;" . $row[2]));
240 }
241
242 function supplier_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
243 {
244         if ($label != null)
245                 echo "<td>$label</td><td>\n";
246         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
247                 echo "</td>\n";
248         return $str;
249 }
250
251 function supplier_list_row($label, $name, $selected_id, $all_option = false, $submit_on_change=false)
252 {
253 echo "<tr><td>$label</td><td>";
254         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
255 echo "</td></tr>\n";
256 return $str;
257 }
258 //----------------------------------------------------------------------------------------------
259
260 function customer_list($name, $selected_id, $spec_option=false, $submit_on_change=false)
261 {
262         global $all_items;
263
264         $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
265
266         $mode = get_company_pref('no_customer_list');
267
268 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
269         array(
270             'format' => '_format_add_curr',
271                 'search_box' => $mode!=0,
272                 'type' => 1,
273                 'size' => 20,
274                 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
275                 'spec_id' => $all_items,
276                 'select_submit'=> $submit_on_change,
277                 'async' => false,
278                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
279                 _('Select customer')
280         ) );
281 }
282
283 function customer_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
284 {
285         if ($label != null)
286                 echo "<td>$label</td>\n";
287         echo "<td nowrap>";
288         $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
289         echo "</td>\n";
290         return $str;
291 }
292
293 function customer_list_row($label, $name, $selected_id, $all_option = false, $submit_on_change=false)
294 {
295 echo "<tr><td>$label</td><td nowrap>";
296 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
297 echo "</td>\n</tr>\n";
298 return $str;
299 }
300
301 //------------------------------------------------------------------------------------------------
302
303 function customer_branches_list($customer_id, $name, $selected_id,
304         $spec_option = true, $enabled=true, $submit_on_change=false)
305 {
306         global $all_items;
307
308         $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
309                 WHERE debtor_no='" . $customer_id . "' ";
310
311         $where = $enabled ? array("disable_trans = 0") : array();
312 return  combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
313         array(
314                 'where' => $where,
315                 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
316                 'spec_id' => $all_items,
317                 'select_submit'=> $submit_on_change,
318                 'sel_hint' => _('Select customer branch')
319 //                'async' => false
320         ) );
321 }
322 //------------------------------------------------------------------------------------------------
323
324 function customer_branches_list_cells($label,$customer_id, $name, $selected_id, $all_option = true, $enabled=true, $submit_on_change=false)
325 {
326         if ($label != null)
327                 echo "<td>$label</td>\n";
328         echo "<td>";
329         $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
330         echo "</td>\n";
331         return $ret;
332 }
333
334 function customer_branches_list_row($label,$customer_id, $name, $selected_id, $all_option = true, $enabled=true, $submit_on_change=false)
335 {
336         echo "<tr>";
337         $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
338         echo "</tr>";
339         return $ret;
340 }
341
342 //------------------------------------------------------------------------------------------------
343
344 function locations_list($name, $selected_id, $all_option=false, $submit_on_change=false)
345 {
346         global $all_items;
347
348         $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
349
350 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
351         array(
352                 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
353                 'spec_id' => $all_items,
354                 'select_submit'=> $submit_on_change,
355                 'async' => false
356         ) );
357 }
358
359 function locations_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
360 {
361         if ($label != null)
362                 echo "<td>$label</td>\n";
363         echo "<td>";
364         $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
365         echo "</td>\n";
366         return $str;
367 }
368
369 function locations_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
370 {
371         echo "<tr>";
372         $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
373         echo "</tr>\n";
374         return $str;
375 }
376
377 //-----------------------------------------------------------------------------------------------
378
379 function currencies_list($name, $selected_id, $submit_on_change=false)
380 {
381         $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
382
383 // default to the company currency
384         if ($selected_id == "")
385         {
386                         $selected_id = get_company_currency();
387                         $_POST[$name] = $selected_id;
388         }
389
390 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
391         array(
392                 'select_submit'=> $submit_on_change,
393                 'async' => false
394         ) );
395 }
396
397 function currencies_list_cells($label, $name, $selected_id)
398 {
399         if ($label != null)
400                 echo "<td>$label</td>\n";
401         echo "<td>";
402         $str = currencies_list($name, $selected_id);
403         echo "</td>\n";
404         return $str;
405 }
406
407 function currencies_list_row($label, $name, $selected_id)
408 {
409         echo "<tr>\n";
410         $str = currencies_list_cells($label, $name, $selected_id);
411         echo "</tr>\n";
412         return $str;
413 }
414
415 //---------------------------------------------------------------------------------------------------
416
417 function fiscalyears_list($name, $selected_id, $submit_on_change=false)
418 {
419
420         $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
421
422 // default to the company current fiscal year
423         if ($selected_id == "")
424         {
425                         $selected_id = get_company_pref('f_year');
426                         $_POST[$name] = $selected_id;
427         }
428
429 return combo_input($name, $selected_id, $sql, 'id', '',
430         array(
431                 'order' => 'begin',
432                 'format' => '_format_fiscalyears',
433                 'select_submit'=> $submit_on_change,
434                 'async' => false
435         ) );
436 }
437
438 function _format_fiscalyears($row)
439 {
440         return sql2date($row[1]) . "&nbsp;-&nbsp;" . sql2date($row[2])
441         . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
442 }
443
444 function fiscalyears_list_cells($label, $name, $selected_id)
445 {
446         if ($label != null)
447                 echo "<td>$label</td>\n";
448         echo "<td>";
449         $str = fiscalyears_list($name, $selected_id);
450         echo "</td>\n";
451         return $str;
452 }
453
454 function fiscalyears_list_row($label, $name, $selected_id)
455 {
456         echo "<tr>\n";
457         $str = fiscalyears_list_cells($label, $name, $selected_id);
458         echo "</tr>\n";
459         return $str;
460 }
461 //------------------------------------------------------------------------------------
462
463 function dimensions_list($name, $selected_id, $no_option=false, $showname=' ',
464         $submit_on_change=false, $showclosed=false, $showtype=1)
465 {
466 $sql = "SELECT id, CONCAT(reference,'  ',name) as ref FROM ".TB_PREF."dimensions";
467
468 $options = array(
469         'order' => 'reference',
470         'spec_option'=>$no_option ? $showname : false,
471         'spec_id' => 0,
472         'select_submit'=> $submit_on_change,
473         'async' => false,
474         );
475
476         if ($showclosed)
477         $options['where'][] = "closed=0";
478         if($showtype)
479         $options['where'][] = "type_=$showtype";
480
481         return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
482 }
483
484 function dimensions_list_cells($label, $name, $selected_id, $no_option=false, $showname=null,
485         $showclosed=false, $showtype=0)
486 {
487         if ($label != null)
488                 echo "<td>$label</td>\n";
489         echo "<td>";
490         $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
491         echo "</td>\n";
492         return $str;
493 }
494
495 function dimensions_list_row($label, $name, $selected_id, $no_option=false, $showname=null,
496         $showclosed=false, $showtype=0)
497 {
498         echo "<tr>\n";
499         $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
500                 $showclosed, $showtype);
501         echo "</tr>\n";
502         return $str;
503 }
504
505 //---------------------------------------------------------------------------------------------------
506
507 function stock_items_list($name, $selected_id, $all_option=false, $submit_on_change=false, $opts=array())
508 {
509         global $all_items;
510
511         $sql = "SELECT stock_id, s.description, c.description
512                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
513
514         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
515         array_merge(
516           array(
517                 'format' => '_format_stock_items',
518                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
519                 'spec_id' => $all_items,
520                 'search_box' => true,
521                 'search' => array("stock_id", "c.description","s.description"),
522                 'search_submit' => get_company_pref('no_item_list')!=0,
523                 'size'=>10,
524                 'select_submit'=> $submit_on_change
525           ), $opts) );
526 }
527
528 function _format_stock_items($row)
529 {
530         return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "")
531                 . $row[2] . "&nbsp;-&nbsp;" . $row[1];
532 }
533
534 function stock_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
535 {
536         if ($label != null)
537                 echo "<td>$label</td>\n";
538         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
539         array('cells'=>true));
540         return $str;
541 }
542 /*
543 function stock_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
544 {
545         echo "<tr>\n";
546         $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
547         echo "</tr>\n";
548         return $str;
549 }
550 */
551 //------------------------------------------------------------------------------------
552
553 function base_stock_items_list($where, $name, $selected_id,
554         $all_option=false, $submit_on_change=false)
555 {
556         global $all_items;
557
558         $sql = "SELECT stock_id, s.description, c.description
559                 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
560                 s.category_id=c.category_id";
561
562         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
563         array(
564                 'format' => '_format_stock_items',
565                 'spec_option' => $all_option==true ?  _("All Items") : $all_option,
566                 'spec_id' => $all_items,
567                 'select_submit'=> $submit_on_change,
568                 'where' => $where
569         ) );
570 }
571 //------------------------------------------------------------------------------------
572
573 function stock_bom_items_list($name, $selected_id, $all_option=false, $submit_on_change=false)
574 {
575
576         return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
577                 $name, $selected_id, $all_option, $submit_on_change);
578 }
579 /*
580 function stock_bom_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
581 {
582         if ($label != null)
583                 echo "<td>$label</td>\n";
584         echo "<td>";
585         $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
586         echo "</td>\n";
587         return $str;
588 }
589
590 function stock_bom_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
591 {
592         echo "<tr>\n";
593         $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
594         echo "</tr>\n";
595         return $str;
596 }
597 */
598 //------------------------------------------------------------------------------------
599
600 function stock_manufactured_items_list($name, $selected_id,
601         $all_option=false, $submit_on_change=false)
602 {
603         return base_stock_items_list("s.mb_flag='M'",
604                 $name, $selected_id, $all_option, $submit_on_change);
605 }
606
607 function stock_manufactured_items_list_cells($label, $name, $selected_id,
608                                 $all_option=false, $submit_on_change=false)
609 {
610         if ($label != null)
611                 echo "<td>$label</td>\n";
612         echo "<td>";
613         $str = stock_manufactured_items_list($name, $selected_id, $all_option,
614                                 $submit_on_change);
615         echo "</td>\n";
616         return $str;
617 }
618
619 function stock_manufactured_items_list_row($label, $name, $selected_id,
620                 $all_option=false, $submit_on_change=false)
621 {
622         echo "<tr>\n";
623         $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
624                         $all_option, $submit_on_change);
625         echo "</tr>\n";
626         return $str;
627 }
628 //------------------------------------------------------------------------------------
629
630 function stock_component_items_list($name, $parent_stock_id, $selected_id,
631         $all_option=false, $submit_on_change=false)
632 {
633         return base_stock_items_list("stock_id != '$parent_stock_id'", $name, $selected_id,
634                 $all_option, $submit_on_change);
635 }
636 //------------------------------------------------------------------------------------
637
638 function stock_costable_items_list($name, $selected_id,
639         $all_option=false, $submit_on_change=false)
640 {
641         return base_stock_items_list("mb_flag!='D'", $name, $selected_id,
642                 $all_option, $submit_on_change);
643 }
644
645 //------------------------------------------------------------------------------------
646
647 function stock_purchasable_items_list($name, $selected_id,      $all_option=false,
648                 $submit_on_change=false, $opts=array())
649 {
650  global $all_items;
651         $sql = "SELECT stock_id, s.description, c.description
652                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c
653                         WHERE s.category_id=c.category_id
654                                 AND mb_flag !='M' ";
655         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
656           array_merge( array(
657                 'format' => '_format_stock_items',
658                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
659                 'spec_id' => $all_items,
660                 'search_box' => true,
661                 'search' => array("stock_id", "c.description","s.description"),
662                 'search_submit' => get_company_pref('no_item_list')!=0,
663                 'size'=>10,
664                 'select_submit'=> $submit_on_change
665           ), $opts) );
666
667 }
668
669 function stock_purchasable_items_list_cells($label, $name, $selected_id,
670                         $all_option=false, $submit_on_change=false)
671 {
672         if ($label != null)
673                 echo "<td>$label</td>\n";
674         $ret = stock_purchasable_items_list($name, $selected_id, $all_option,
675                 $submit_on_change, array('cells'=>true) );
676         return $ret;
677 }
678
679 function stock_purchasable_items_list_row($label, $name, $selected_id,
680                         $all_option=false, $submit_on_change=false)
681 {
682         echo "<tr>\n";
683         $ret = stock_purchasable_items_list_cells($label, $name, $selected_id,
684                 $all_option, $submit_on_change);
685         echo "</tr>\n";
686         return $ret;
687 }
688
689 //------------------------------------------------------------------------------------
690
691 function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
692 {
693         default_focus($name);
694         echo "<tr>";
695         if ($label != NULL)
696                 echo "<td>$label</td>\n";
697         echo "<td>";
698         if ($enabled)
699                 $sel = "<select name='$name' onchange='this.form.submit();'>\n";
700         else
701                 $sel =  "<select disabled name='$name'>\n";
702         if ($selected_id == null)
703                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
704         if ($selected_id == "")
705                 $_POST[$name] = $selected_id = "B";
706         $sel .= "<option " . ($selected_id == 'M'?" selected ":"") . " value='M'>" . _("Manufactured"). "</option>\n";
707         $sel .= "<option " . ($selected_id == 'B'?" selected ":"") . " value='B'>" . _("Purchased"). "</option>\n";
708         $sel .= "<option " . ($selected_id == 'D'?" selected ":"") . " value='D'>" . _("Service"). "</option>\n";
709         $sel .= "</select>";
710         echo $sel;
711         echo "</td></tr>\n";
712         return $sel;
713 }
714
715 function stock_units_list_row($label, $name, $value, $enabled=true)
716 {
717         global $stock_units;
718
719         default_focus($name);
720         $result = get_all_item_units();
721         echo "<tr><td>$label</td>\n";
722         if ($enabled)
723                 echo "<td><select name='$name'>";
724         else
725                 echo "<td><select disabled name='$name'>";
726
727         if ($value == null)
728                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
729
730         while($unit = db_fetch($result))
731         {
732                 if ($value == "")
733                 {
734                         $_POST[$name] = $unit['abbr'];
735                 }
736                 $descr = $unit['name'];
737                 if ($value==$unit['abbr'])
738                 {
739                         echo "<option selected value='".$unit['abbr']."'>$descr</option>\n";
740                 }
741                 else
742                 {
743                         echo "<option value='".$unit['abbr']."'>$descr</option>\n";
744                 }
745         }
746         echo "</select></td></tr>\n";
747 }
748
749 //------------------------------------------------------------------------------------
750
751 function tax_types_list($name, $selected_id, $none_option=false, $submit_on_change=false)
752 {
753         global $all_items;
754
755         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
756
757         return combo_input($name, $selected_id, $sql, 'id', 'name',
758         array(
759                 'spec_option' => $none_option,
760                 'spec_id' => 0,
761                 'select_submit'=> $submit_on_change,
762                 'async' => false,
763         ) );
764 }
765
766 function tax_types_list_cells($label, $name, $selected_id, $none_option=false,
767         $submit_on_change=false)
768 {
769         if ($label != null)
770                 echo "<td>$label</td>\n";
771         echo "<td>";
772         $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
773         echo "</td>\n";
774         return $str;
775 }
776
777 function tax_types_list_row($label, $name, $selected_id, $none_option=false,
778         $submit_on_change=false)
779 {
780         echo "<tr>\n";
781         $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
782         echo "</tr>\n";
783         return $str;
784 }
785
786 //------------------------------------------------------------------------------------
787
788 function tax_groups_list($name, $selected_id,
789         $none_option=false, $submit_on_change=false)
790 {
791         global $all_items;
792
793         $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
794
795         return combo_input($name, $selected_id, $sql, 'id', 'name',
796         array(
797                 'order' => 'id',
798                 'spec_option' => $none_option,
799                 'spec_id' => 0,
800                 'select_submit'=> $submit_on_change,
801                 'async' => false,
802         ) );
803 }
804
805 function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
806 {
807         if ($label != null)
808                 echo "<td>$label</td>\n";
809         echo "<td>";
810         $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
811         echo "</td>\n";
812         return $str;
813 }
814
815 function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
816 {
817         echo "<tr>\n";
818         $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
819         echo "</tr>\n";
820         return $str;
821 }
822
823 //------------------------------------------------------------------------------------
824
825 function item_tax_types_list($name, $selected_id)
826 {
827         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
828         combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
829 }
830
831 function item_tax_types_list_cells($label, $name, $selected_id)
832 {
833         if ($label != null)
834                 echo "<td>$label</td>\n";
835         echo "<td>";
836         item_tax_types_list($name, $selected_id);
837         echo "</td>\n";
838 }
839
840 function item_tax_types_list_row($label, $name, $selected_id)
841 {
842         echo "<tr>\n";
843         item_tax_types_list_cells($label, $name, $selected_id);
844         echo "</tr>\n";
845 }
846
847 //------------------------------------------------------------------------------------
848
849 function shippers_list($name, $selected_id)
850 {
851         $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
852         combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
853 }
854
855 function shippers_list_cells($label, $name, $selected_id)
856 {
857         if ($label != null)
858                 echo "<td>$label</td>\n";
859         echo "<td>";
860         shippers_list($name, $selected_id);
861         echo "</td>\n";
862 }
863
864 function shippers_list_row($label, $name, $selected_id)
865 {
866         echo "<tr>\n";
867         shippers_list_cells($label, $name, $selected_id);
868         echo "</tr>\n";
869 }
870
871 //-------------------------------------------------------------------------------------
872
873 function sales_persons_list($name, $selected_id)
874 {
875         $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
876         combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
877 }
878
879 function sales_persons_list_cells($label, $name, $selected_id)
880 {
881         if ($label != null)
882                 echo "<td>$label</td>\n";
883         echo "<td>\n";
884         sales_persons_list($name, $selected_id);
885         echo "</td>\n";
886 }
887
888 function sales_persons_list_row($label, $name, $selected_id, $submit_on_change=false)
889 {
890         echo "<tr>\n";
891         sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
892         echo "</tr>\n";
893 }
894
895 //------------------------------------------------------------------------------------
896
897 function sales_areas_list($name, $selected_id)
898 {
899         $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
900         combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
901 }
902
903 function sales_areas_list_cells($label, $name, $selected_id)
904 {
905         if ($label != null)
906                 echo "<td>$label</td>\n";
907         echo "<td>";
908         sales_areas_list($name, $selected_id);
909         echo "</td>\n";
910 }
911
912 function sales_areas_list_row($label, $name, $selected_id)
913 {
914         echo "<tr>\n";
915         sales_areas_list_cells($label, $name, $selected_id);
916         echo "</tr>\n";
917 }
918
919 //------------------------------------------------------------------------------------
920
921 function workorders_list($name, $selected_id)
922 {
923         $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
924         combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
925 }
926
927 function workorders_list_cells($label, $name, $selected_id)
928 {
929         if ($label != null)
930                 echo "<td>$label</td>\n";
931         echo "<td>";
932         workorders_list($name, $selected_id);
933         echo "</td>\n";
934 }
935
936 function workorders_list_row($label, $name, $selected_id)
937 {
938         echo "<tr>\n";
939         workorders_list_cells($label, $name, $selected_id);
940         echo "</tr>\n";
941 }
942
943 //------------------------------------------------------------------------------------
944
945 function payment_terms_list($name, $selected_id)
946 {
947         $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
948         combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
949 }
950
951 function payment_terms_list_cells($label, $name, $selected_id)
952 {
953         if ($label != null)
954                 echo "<td>$label</td>\n";
955         echo "<td>";
956         payment_terms_list($name, $selected_id);
957         echo "</td>\n";
958 }
959
960 function payment_terms_list_row($label, $name, $selected_id)
961 {
962         echo "<tr>\n";
963         payment_terms_list_cells($label, $name, $selected_id);
964         echo "</tr>\n";
965 }
966
967 //------------------------------------------------------------------------------------
968
969 function credit_status_list($name, $selected_id)
970 {
971         $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
972         combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
973 }
974
975 function credit_status_list_cells($label, $name, $selected_id)
976 {
977         if ($label != null)
978                 echo "<td>$label</td>\n";
979         echo "<td>";
980         credit_status_list($name, $selected_id);
981         echo "</td>\n";
982 }
983
984 function credit_status_list_row($label, $name, $selected_id)
985 {
986         echo "<tr>\n";
987         credit_status_list_cells($label, $name, $selected_id);
988         echo "</tr>\n";
989 }
990
991 //-----------------------------------------------------------------------------------------------
992
993 function sales_types_list($name, $selected_id, $submit_on_change=false, $special_option=false)
994 {
995         global $all_items;
996
997         $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
998
999         return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1000         array(
1001                 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1002                 'spec_id' => 0,
1003                 'select_submit'=> $submit_on_change,
1004         //        'async' => false,
1005         ) );
1006 }
1007
1008 function sales_types_list_cells($label, $name, $selected_id, $submit_on_change=false, $special_option=false)
1009 {
1010         if ($label != null)
1011                 echo "<td>$label</td>\n";
1012         echo "<td>";
1013         $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1014         echo "</td>\n";
1015         return $str;
1016 }
1017
1018 function sales_types_list_row($label, $name, $selected_id, $submit_on_change=false, $special_option=false)
1019 {
1020         echo "<tr>\n";
1021         $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1022         echo "</tr>\n";
1023         return $str;
1024 }
1025
1026 //-----------------------------------------------------------------------------------------------
1027
1028 function movement_types_list($name, $selected_id)
1029 {
1030         $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1031         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1032 }
1033
1034 function movement_types_list_cells($label, $name, $selected_id)
1035 {
1036         if ($label != null)
1037                 echo "<td>$label</td>\n";
1038         echo "<td>";
1039         movement_types_list($name, $selected_id);
1040         echo "</td>\n";
1041 }
1042
1043 function movement_types_list_row($label, $name, $selected_id)
1044 {
1045         echo "<tr>\n";
1046         movement_types_list_cells($label, $name, $selected_id);
1047         echo "</tr>\n";
1048 }
1049
1050 //-----------------------------------------------------------------------------------------------
1051
1052 function bank_trans_types_list($name, $selected_id)
1053 {
1054         $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1055         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1056 }
1057
1058 function bank_trans_types_list_cells($label, $name, $selected_id)
1059 {
1060         if ($label != null)
1061                 echo "<td>$label</td>\n";
1062         echo "<td>";
1063         bank_trans_types_list($name, $selected_id);
1064         echo "</td>\n";
1065 }
1066
1067 function bank_trans_types_list_row($label, $name, $selected_id)
1068 {
1069         echo "<tr>\n";
1070         bank_trans_types_list_cells($label, $name, $selected_id);
1071         echo "</tr>\n";
1072 }
1073
1074 //-----------------------------------------------------------------------------------------------
1075
1076 function workcenter_list($name, $selected_id, $all_option=false)
1077 {
1078         global $all_items;
1079
1080         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1081
1082         return combo_input($name, $selected_id, $sql, 'id', 'name',
1083         array(
1084                 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1085                 'spec_id' => $all_items,
1086         ) );
1087 }
1088
1089 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1090 {
1091         default_focus($name);
1092         if ($label != null)
1093                 echo "<td>$label</td>\n";
1094         echo "<td>";
1095         workcenter_list($name, $selected_id, $all_option);
1096         echo "</td>\n";
1097 }
1098
1099 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1100 {
1101         echo "<tr>\n";
1102         workcenter_list_cells($label, $name, $selected_id, $all_option);
1103         echo "</tr>\n";
1104 }
1105
1106 //-----------------------------------------------------------------------------------------------
1107
1108 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1109 {
1110         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1111                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1112                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1113
1114         return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1115         array(
1116                 'format' => '_format_add_curr',
1117                 'select_submit'=> $submit_on_change,
1118                 'async' => false
1119         ) );
1120 }
1121
1122 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1123 {
1124         if ($label != null)
1125                 echo "<td>$label</td>\n";
1126         echo "<td>";
1127         $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1128         echo "</td>\n";
1129         return $str;
1130 }
1131
1132 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1133 {
1134         echo "<tr>\n";
1135         $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1136         echo "</tr>\n";
1137         return $str;
1138 }
1139
1140 //-----------------------------------------------------------------------------------------------
1141
1142 function class_list($name, $selected_id, $submit_on_change=false)
1143 {
1144         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1145
1146         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1147         array(
1148                 'select_submit'=> $submit_on_change,
1149                 'async' => false
1150         ) );
1151
1152 }
1153
1154 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1155 {
1156         if ($label != null)
1157                 echo "<td>$label</td>\n";
1158         echo "<td>";
1159         $str = class_list($name, $selected_id, $submit_on_change);
1160         echo "</td>\n";
1161         return $str;
1162 }
1163
1164 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1165 {
1166         echo "<tr>\n";
1167         $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1168         echo "</tr>\n";
1169         return $str;
1170 }
1171
1172 //-----------------------------------------------------------------------------------------------
1173
1174 function stock_categories_list($name, $selected_id)
1175 {
1176         $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1177         combo_input($name, $selected_id, $sql, 'category_id', 'description',
1178         array('order'=>'category_id'));
1179 }
1180
1181 function stock_categories_list_cells($label, $name, $selected_id)
1182 {
1183         if ($label != null)
1184                 echo "<td>$label</td>\n";
1185         echo "<td>";
1186         stock_categories_list($name, $selected_id);
1187         echo "</td>\n";
1188 }
1189
1190 function stock_categories_list_row($label, $name, $selected_id)
1191 {
1192         echo "<tr>\n";
1193         stock_categories_list_cells($label, $name, $selected_id);
1194         echo "</tr>\n";
1195 }
1196
1197 //-----------------------------------------------------------------------------------------------
1198
1199 function gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric)
1200 {
1201         global $all_items;
1202
1203         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1204
1205         combo_input($name, $selected_id, $sql, 'id', 'name',
1206         array(
1207                 'order' => 'id',
1208                 'spec_option' =>$all_option,
1209                 'spec_id' => $all_option_numeric ? 0 : $all_items
1210         ) );
1211 }
1212
1213 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false,
1214         $all_option_numeric=false)
1215 {
1216         if ($label != null)
1217                 echo "<td>$label</td>\n";
1218         echo "<td>";
1219         gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1220         echo "</td>\n";
1221 }
1222
1223 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false,
1224         $all_option_numeric=false)
1225 {
1226         echo "<tr>\n";
1227         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1228                 $all_option_numeric);
1229         echo "</tr>\n";
1230 }
1231
1232 //-----------------------------------------------------------------------------------------------
1233 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
1234         $show_group=false, $cells=false, $all_option=false)
1235 {
1236         if ($skip_bank_accounts)
1237                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1238                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1239                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1240                         ."ON chart.account_code=acc.account_code
1241                                 WHERE acc.account_code IS NULL
1242                         AND chart.account_type=type.id";
1243         else
1244                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1245                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1246                         WHERE chart.account_type=type.id";
1247
1248         combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1249         array(
1250                 'format' => '_format_account' .  ($show_group ? '2' : ''),
1251                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1252                 'spec_id' => '',
1253                 'order' => 'account_code',
1254                 'search_box' => $cells,
1255                         'search_submit' => false,
1256                         'size' => 12,
1257                         'max' => 10,
1258                         'cells' => true
1259         ) );
1260
1261 }
1262
1263 function _format_account($row)
1264 {
1265                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1266 }
1267
1268 function _format_account2($row)
1269 {
1270                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1271 }
1272
1273 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1274         $show_group=false, $cells=false, $all_option=false)
1275 {
1276         if ($label != null)
1277                 echo "<td>$label</td>\n";
1278         echo "<td>";
1279         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1280         echo "</td>\n";
1281 }
1282
1283 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1284         $show_group=false, $cells=false, $all_option=false)
1285 {
1286         echo "<tr>\n";
1287         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1288                 $show_group, $cells, $all_option);
1289         echo "</tr>\n";
1290 }
1291
1292 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1293 {
1294         default_focus($name);
1295         if ($submit_on_change == true)
1296                 echo "<select name='$name' onchange='this.form.submit();'>"; // FIX ajax
1297         else
1298                 echo "<select name='$name'>";
1299
1300         if (strlen($name_yes) == 0)
1301         {
1302                 unset($name_yes);
1303         }
1304         if (strlen($name_no) == 0)
1305         {
1306                 unset($name_no);
1307         }
1308
1309         if ($selected_id == null)
1310                 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1311         if ($selected_id == 0)
1312                 echo "<option value=1>";
1313         else
1314                 echo "<option selected value=1>";
1315         if (!isset($name_yes))
1316                 echo _("Yes") . "</option>\n";
1317         else
1318                 echo $name_yes . "</option>\n";
1319         if ($selected_id == 0)
1320                 echo "<option selected value=0>";
1321         else
1322                 echo "<option value=0>";
1323         if (!isset($name_no))
1324                 echo _("No") . "</option>\n";
1325         else
1326                 echo $name_no . "</option>\n";
1327         echo "</select>";
1328 }
1329
1330 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1331 {
1332         if ($label != null)
1333                 echo "<td>$label</td>\n";
1334         echo "<td>";
1335         $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1336         echo "</td>\n";
1337         return $str;
1338 }
1339
1340 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1341 {
1342         echo "<tr>\n";
1343         $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1344         echo "</tr>\n";
1345         return $str;
1346 }
1347
1348 //------------------------------------------------------------------------------------------------
1349
1350 function languages_list($name, $selected_id)
1351 {
1352         global $installed_languages;
1353
1354         default_focus($name);
1355         echo "<select name='$name'>";
1356
1357         if ($selected_id == null)
1358                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1359         foreach ($installed_languages as $lang)
1360         {
1361                 echo "<option ";
1362                 if ($selected_id == $lang['code'])
1363                         echo "selected ";
1364                 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1365         }
1366 }
1367
1368 function languages_list_cells($label, $name, $selected_id)
1369 {
1370         if ($label != null)
1371                 echo "<td>$label</td>\n";
1372         echo "<td>";
1373         languages_list($name, $selected_id);
1374         echo "</td>\n";
1375 }
1376
1377 function languages_list_row($label, $name, $selected_id)
1378 {
1379         echo "<tr>\n";
1380         languages_list_cells($label, $name, $selected_id);
1381         echo "</tr>\n";
1382 }
1383
1384 //------------------------------------------------------------------------------------------------
1385
1386 function bank_account_types_list($name, $selected_id)
1387 {
1388         $bank_account_types = bank_account_types::get_all();
1389
1390         default_focus($name);
1391         echo "<select name='$name'>";
1392
1393         if ($selected_id == null)
1394                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1395         foreach ($bank_account_types as $type)
1396         {
1397                 echo "<option ";
1398                 if ($selected_id == "" || $selected_id == $type['id'])
1399                         echo "selected ";
1400                 echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1401         }
1402 }
1403
1404 function bank_account_types_list_cells($label, $name, $selected_id)
1405 {
1406         if ($label != null)
1407                 echo "<td>$label</td>\n";
1408         echo "<td>";
1409         bank_account_types_list($name, $selected_id);
1410         echo "</td>\n";
1411 }
1412
1413 function bank_account_types_list_row($label, $name, $selected_id)
1414 {
1415         echo "<tr>\n";
1416         bank_account_types_list_cells($label, $name, $selected_id);
1417         echo "</tr>\n";
1418 }
1419
1420 //------------------------------------------------------------------------------------------------
1421
1422 function payment_person_types_list($name, $selected_id, $related=null)
1423 {
1424         $types = payment_person_types::get_all();
1425
1426         default_focus($name);
1427         echo "<select name='$name'";
1428         if ($related)   // FIX ajax
1429                 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1430         echo ">";
1431
1432         if ($selected_id == null)
1433                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1434         foreach ($types as $type)
1435         {
1436                 if (payment_person_types::has_items($type['id']))
1437                 {
1438                         if ($selected_id == "")
1439                                 $_POST[$name] = $selected_id = $type['id'];
1440                         echo "<option ";
1441                         if ($selected_id == $type['id'])
1442                                 echo "selected ";
1443                         echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1444                 }
1445         }
1446 }
1447
1448 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1449 {
1450         if ($label != null)
1451                 echo "<td>$label</td>\n";
1452         echo "<td>";
1453         $str = payment_person_types_list($name, $selected_id, $related);
1454         echo "</td>\n";
1455         return $str;
1456 }
1457
1458 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1459 {
1460         echo "<tr>\n";
1461         $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1462         echo "</tr>\n";
1463         return $str;
1464 }
1465
1466 //------------------------------------------------------------------------------------------------
1467
1468 function wo_types_list($name, $selected_id)
1469 {
1470         $types = wo_types::get_all();
1471
1472         default_focus($name);   // FIX ajax
1473         echo "<select name='$name' onchange='this.form.submit();'>";
1474
1475         if ($selected_id == null)
1476                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1477         foreach ($types as $type)
1478         {
1479                 echo "<option ";
1480                 if ($selected_id == $type['id'])
1481                         echo "selected ";
1482                 echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1483         }
1484         echo "</select>";
1485 }
1486
1487 function wo_types_list_row($label, $name, $selected_id)
1488 {
1489         echo "<tr><td>$label</td><td>\n";
1490         $str = wo_types_list($name, $selected_id);
1491         echo "</td></tr>\n";
1492         return $str;
1493 }
1494
1495 //------------------------------------------------------------------------------------------------
1496
1497 function dateformats_list_row($label, $name, $value)
1498 {
1499         global $dateformats;
1500
1501         default_focus($name);
1502         echo "<tr><td>$label</td>\n";
1503         echo "<td><select name='$name'>";
1504
1505         if ($value == null)
1506                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1507         $counter = 0;
1508         foreach ($dateformats as $df)
1509         {
1510
1511                 if ($value==$counter)
1512                 {
1513                         echo "<option selected value='$counter'>$df</option>\n";
1514                 }
1515                 else
1516                 {
1517                         echo "<option value='$counter'>$df</option>\n";
1518                 }
1519                 $counter++;
1520         }
1521         echo "</select></td></tr>\n";
1522 }
1523
1524 function dateseps_list_row($label, $name, $value)
1525 {
1526         global $dateseps;
1527
1528         default_focus($name);
1529         echo "<tr><td>$label</td>\n";
1530         echo "<td><select name='$name'>";
1531
1532         if ($value == null)
1533                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1534         $counter = 0;
1535         foreach ($dateseps as $ds)
1536         {
1537
1538                 if ($value==$counter)
1539                 {
1540                         echo "<option selected value='$counter'>$ds</option>\n";
1541                 }
1542                 else
1543                 {
1544                         echo "<option value='$counter'>$ds</option>\n";
1545                 }
1546                 $counter++;
1547         }
1548         echo "</select></td></tr>\n";
1549 }
1550
1551 function thoseps_list_row($label, $name, $value)
1552 {
1553         global $thoseps;
1554
1555         default_focus($name);
1556         echo "<tr><td>$label</td>\n";
1557         echo "<td><select name='$name'>";
1558
1559         if ($value == null)
1560                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1561         $counter = 0;
1562         foreach ($thoseps as $ts)
1563         {
1564
1565                 if ($value==$counter)
1566                 {
1567                         echo "<option selected value='$counter'>$ts</option>\n";
1568                 }
1569                 else
1570                 {
1571                         echo "<option value='$counter'>$ts</option>\n";
1572                 }
1573                 $counter++;
1574         }
1575         echo "</select></td></tr>\n";
1576 }
1577
1578 function decseps_list_row($label, $name, $value)
1579 {
1580         global $decseps;
1581
1582         default_focus($name);
1583         echo "<tr><td>$label</td>\n";
1584         echo "<td><select name='$name'>";
1585
1586         if ($value == null)
1587                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1588         $counter = 0;
1589         foreach ($decseps as $ds)
1590         {
1591
1592                 if ($value==$counter)
1593                 {
1594                         echo "<option selected value='$counter'>$ds</option>\n";
1595                 }
1596                 else
1597                 {
1598                         echo "<option value='$counter'>$ds</option>\n";
1599                 }
1600                 $counter++;
1601         }
1602         echo "</select></td></tr>\n";
1603 }
1604
1605 function themes_list_row($label, $name, $value)
1606 {
1607         global $path_to_root;
1608
1609         default_focus($name);
1610         $path = $path_to_root.'/themes/';
1611         $themes = array();
1612         $themedir = opendir($path);
1613         while(false !== ($fname = readdir($themedir)))
1614         {
1615                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1616                 {
1617                         $themes[] =  $fname;
1618                 }
1619         }
1620         sort($themes);
1621         echo "<tr><td>$label</td>\n";
1622         echo "<td><select name='$name'>";
1623
1624         if ($value == null)
1625                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1626         foreach ($themes as $th)
1627         {
1628
1629                 if ($value==$th)
1630                 {
1631                         echo "<option selected value='$th'>$th</option>\n";
1632                 }
1633                 else
1634                 {
1635                         echo "<option value='$th'>$th</option>\n";
1636                 }
1637         }
1638         echo "</select></td></tr>\n";
1639 }
1640
1641 function pagesizes_list_row($label, $name, $value)
1642 {
1643         global $pagesizes;
1644
1645         default_focus($name);
1646         echo "<tr><td>$label</td>\n";
1647         echo "<td><select name='$name'>";
1648
1649         if ($value == null)
1650                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1651         foreach ($pagesizes as $pz)
1652         {
1653
1654                 if ($value==$pz)
1655                 {
1656                         echo "<option selected value='$pz'>$pz</option>\n";
1657                 }
1658                 else
1659                 {
1660                         echo "<option value='$pz'>$pz</option>\n";
1661                 }
1662         }
1663         echo "</select></td></tr>\n";
1664 }
1665
1666 function security_headings_list_row($label, $name, $value)
1667 {
1668         global $security_headings;
1669
1670         default_focus($name);
1671         echo "<tr><td>$label</td>\n";
1672         echo "<td><select name='$name'>";
1673
1674         if ($value == null)
1675                 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
1676         $counter=0;
1677         foreach ($security_headings as $sh)
1678         {
1679
1680                 if ($value==$counter)
1681                 {
1682                         echo "<option selected value='$counter'>$sh</option>\n";
1683                 }
1684                 else
1685                 {
1686                         echo "<option value='$counter'>$sh</option>\n";
1687                 }
1688                 $counter++;
1689         }
1690         echo "</select></td></tr>\n";
1691 }
1692
1693 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
1694 {
1695         global $systypes_array;
1696
1697         default_focus($name);
1698         if ($label != null)
1699                 echo "<td>$label</td>\n";
1700         echo "<td><select name='$name'";
1701         if ($submit_on_change)
1702                 echo " onchange='this.form.submit();'>";        // FIX ajax
1703         else
1704                 echo ">";
1705         if ($value == null)
1706                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1707         foreach ($systypes_array as $key=>$type)
1708         {
1709
1710                 if ($value==$key)
1711                 {
1712                         echo "<option selected value='$key'>".$type['name']."</option>\n";
1713                 }
1714                 else
1715                 {
1716                         echo "<option value='$key'>".$type['name']."</option>\n";
1717                 }
1718         }
1719         echo "</select></td>\n";
1720 }
1721
1722 function systypes_list_row($label, $name, $value, $submit_on_change=false)
1723 {
1724         echo "<tr>\n";
1725         $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1726         echo "</tr>\n";
1727         return $str;
1728 }
1729
1730 function cust_allocations_list_cells($label, $name, $selected)
1731 {
1732         global $all_items;
1733         default_focus($name);
1734         if ($label != null)
1735                 label_cell($label);
1736         if ($selected == null)
1737                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1738         echo "<td><select name='$name'>";
1739         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
1740         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
1741         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1742         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1743         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1744         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Delivery Notes"). "</option>\n";
1745         echo "</select></td>\n";
1746 }
1747
1748 function supp_allocations_list_cells($name, $selected)
1749 {
1750         global $all_items;
1751
1752         default_focus($name);
1753         if ($selected == null)
1754                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1755         echo "<td><select name='$name'>";
1756         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
1757         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Invoices"). "</option>\n";
1758         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1759         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1760         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1761         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Overdue Credit Notes"). "</option>\n";
1762         echo "</select></td>\n";
1763 }
1764
1765 function policy_list_cells($label, $name, $selected)
1766 {
1767         default_focus($name);
1768         if ($selected == null)
1769         {
1770                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1771                 if ($selected == "")
1772                         $_POST[$name] = $selected;
1773         }
1774         if ($label != null)
1775                 label_cell($label);
1776         echo "<td><select name='$name'>";
1777         echo "<option " . ($selected == ''?" selected ":"") . " value=''>" . _("Automatically put balance on back order"). "</option>\n";
1778         echo "<option " . ($selected == 'CAN'?" selected ":"") . " value='CAN'>" . _("Cancel any quantites not delivered"). "</option>\n";
1779         echo "</select></td>\n";
1780 }
1781
1782 function policy_list_row($label, $name, $selected)
1783 {
1784         echo "<tr>\n";
1785         policy_list_cells($label, $name, $selected);
1786         echo "</tr>\n";
1787 }
1788
1789 function credit_type_list_cells($label, $name, $selected, $submit_on_change=false)
1790 {
1791         default_focus($name);
1792         if ($selected == null)
1793         {
1794                 $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]);
1795                 if ($selected == "Return")
1796                         $_POST[$name] = $selected;
1797         }
1798         if ($label != null)
1799                 label_cell($label);
1800         echo "<td><select name='$name'";
1801         if ($submit_on_change)
1802                 echo " onchange='this.form.submit();'>";        // FIX ajax
1803         else
1804                 echo ">";
1805         echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
1806         echo "<option " . ($selected == 'WriteOff'?" selected ":"") . " value='WriteOff'>" . _("Items Written Off"). "</option>\n";
1807         echo "</select></td>\n";
1808 }
1809
1810 function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
1811 {
1812         echo "<tr>\n";
1813         $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1814         echo "</tr>\n";
1815         return $str;
1816 }
1817
1818 function number_list($name, $selected, $from, $to, $firstlabel="")
1819 {
1820         default_focus($name);
1821         if ($selected == null)
1822         {
1823                 $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]);
1824                 if ($selected == $from)
1825                         $_POST[$name] = $selected;
1826         }
1827         echo "<select name='$name'>";
1828         for ($i = $from; $i <= $to; $i++)
1829         {
1830                 if ($i == 0 && $firstlabel != "")
1831                         $label = $firstlabel;
1832                 else
1833                         $label = $i;
1834                 if ($selected == $i)
1835                 {
1836                         echo "<option selected value='$i'>$label</option>\n";
1837                 }
1838                 else
1839                 {
1840                         echo "<option value='$i'>$label</option>\n";
1841                 }
1842         }
1843         echo "</select>\n";
1844 }
1845
1846 function number_list_cells($label, $name, $selected, $from, $to)
1847 {
1848         if ($label != null)
1849                 label_cell($label);
1850         echo "<td>\n";
1851         number_list($name, $selected, $from, $to);
1852         echo "</td>\n";
1853 }
1854
1855 function number_list_row($label, $name, $selected, $from, $to)
1856 {
1857         echo "<tr>\n";
1858         number_list_cells($label, $name, $selected, $from, $to);
1859         echo "</tr>\n";
1860 }
1861 ?>