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