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