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