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