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