7835f33905bbef4d64bd11b4bb774cae71af5e1f
[fa-stable.git] / includes / ui / ui_lists.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/banking.inc");
13 include_once($path_to_root . "/includes/types.inc");
14 include_once($path_to_root . "/includes/current_user.inc");
15
16 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
17         ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
18
19 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
20         ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
21
22 $all_items = ALL_TEXT;
23
24 //----------------------------------------------------------------------------
25 //      Universal sql combo generator
26 //      $sql must return selector values and selector texts in columns 0 & 1
27 //      Options are merged with defaults.
28
29 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
30         $options=null)
31 {
32 global $Ajax;
33
34 $opts = array(          // default options
35         'where'=> array(),              // additional constraints
36         'order' => $namefield,  // list sort order
37                 // special option parameters
38         'spec_option'=>false,   // option text or false
39         'spec_id' => 0,         // option id
40                 // submit on select parameters
41         'default' => '', // default value when $_POST is not set
42         'select_submit' => false, //submit on select: true/false
43         'async' => true,        // select update via ajax (true) vs _page_body reload
44                 // search box parameters
45         'sel_hint' => null,
46         'search_box' => false,  // name or true/false
47         'type' => 0,    // type of extended selector:
48                 // 0 - with (optional) visible search box, search by id
49                 // 1 - with hidden search box, search by option text
50                 // 2 - TODO reverse: box with hidden selector available via enter; this
51                 // would be convenient for optional ad hoc adding of new item
52         'search_submit' => true, //search submit button: true/false
53         'size' => 8,    // size and max of box tag
54         'max' => 50,
55         'height' => false,      // number of lines in select box
56         'cells' => false,       // combo displayed as 2 <td></td> cells
57         'search' => array(), // sql field names to search
58         'format' => null,        // format functions for regular options
59         'disabled' => false,
60         'box_hint' => null, // box/selectors hints; null = std see below
61         'category' => false, // category column name or false
62         'show_inactive' => false // show inactive records. 
63 );
64 // ------ merge options with defaults ----------
65         if($options != null)
66                 $opts = array_merge($opts, $options);
67         if (!is_array($opts['where']))  $opts['where'] = array($opts['where']);
68
69         $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
70         $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
71         $select_submit =  $opts['select_submit'];
72         $spec_id = $opts['spec_id'];
73         $spec_option = $opts['spec_option'];
74         $by_id = ($opts['type'] == 0);
75         $class = $by_id ? 'combo':'combo2';
76         $disabled = $opts['disabled'] ? "disabled" : '';
77
78         if(!count($opts['search'])) {
79                 $opts['search'] = array($by_id ? $valfield : $namefield);
80         }
81         if ($opts['sel_hint'] === null) 
82                 $opts['sel_hint'] = $by_id || $search_box==false ?
83                         '' : _('Press Space tab for search pattern entry');
84
85         if ($opts['box_hint'] === null)
86                 $opts['box_hint'] = $search_box && $search_submit != false ?
87                         ($by_id ? _('Enter code fragment to search or * for all')
88                         : _('Enter description fragment to search or * for all')) :'';
89
90         if ($selected_id == null) {
91                 $selected_id = get_post($name, $opts['default']);
92         }
93         $txt = get_post($search_box);
94         $rel = '';
95         $limit = '';
96
97         if (isset($_POST['_'.$name.'_update'])) {
98                 if ($by_id) $txt = $_POST[$name];
99
100                 if (!$opts['async'])
101                         $Ajax->activate('_page_body');
102                 else
103                         $Ajax->activate($name);
104         }
105         if ($search_box) {
106                 // search related sql modifications
107
108         $rel = "rel='$search_box'"; // set relation to list
109    if ($opts['search_submit']) {
110         if (isset($_POST[$search_submit])) {
111                 $selected_id = ''; // ignore selected_id while search
112                 if (!$opts['async'])
113                         $Ajax->activate('_page_body');
114                 else
115                         $Ajax->activate($name);
116         }
117         if ($txt == '') {
118                 if ($spec_option === false && $selected_id==null)
119                   $limit = ' LIMIT 1';
120                 else
121                   $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
122         }
123         else
124                 if ($txt != '*') {
125
126                 foreach($opts['search'] as $i=> $s)
127                         $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
128                 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
129                 }
130         }
131    }
132         // sql completion
133         if (count($opts['where'])) {
134                 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
135                 $where .= '('. implode($opts['where'], ' AND ') . ')';
136                 $group_pos = strpos($sql, 'GROUP BY');
137                 if ($group_pos) {
138                         $group = substr($sql, $group_pos);
139                         $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
140                 } else {
141                         $sql .= $where;
142                 }
143         }
144         if ($opts['order'] != false) {
145                 if (!is_array($opts['order']))
146                         $opts['order'] = array($opts['order']);
147                 $sql .= ' ORDER BY '.implode(',',$opts['order']);
148         }
149
150         $sql .= $limit;
151         // ------ make selector ----------
152         $selector = $first_opt = '';
153         $first_id = false;
154         $found = false;
155         $lastcat = null;
156 //if($name=='stock_id') display_error($sql);
157         if($result = db_query($sql)) {
158                 while ($contact_row = db_fetch($result)) {
159                         $value = $contact_row[0];
160                         $descr = $opts['format']==null ?  $contact_row[1] :
161                         call_user_func($opts['format'], $contact_row);
162                         $sel = '';
163                         if (get_post($search_submit) && ($txt === $value)) {
164                                 $selected_id = $value;
165                         }
166                         if      ((string)($selected_id) === $value) {
167                                 $sel = 'selected';
168                                 $found = $value;
169                         }
170                         // show selected option even if inactive 
171                         if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
172                                 continue;
173                         } else 
174                                 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
175
176                         if ($first_id === false) {
177                                 $first_id = $value;
178                                 $first_opt = $descr;
179                         }
180                         $cat = $contact_row[$opts['category']];
181                         if ($opts['category'] !== false && $cat != $lastcat){
182                                 $selector .= "<optgroup label='".$cat."'>\n";
183                                 $lastcat = $cat;
184                         }
185                         $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
186                 }
187                 db_free_result($result);
188         }
189
190         // Prepend special option.
191         if ($spec_option !== false) { // if special option used - add it
192                 $first_id = $spec_id;
193                 $first_opt = $spec_option;
194 //      }
195 //      if($first_id !== false) {
196                 $sel = $found===false ? 'selected' : '';
197                 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
198                 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
199                         . $selector;
200         }
201
202         if ($found === false) {
203                 $selected_id = $first_id;
204         }
205         $_POST[$name] = $selected_id;
206
207         if ($by_id && $search_box != false) {
208                 $txt = $found;
209                 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
210         }
211         $selector = "<select ".(strpos($name,'[]')!==false ? "multiple" : '')
212                 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
213                 . "$disabled name='$name' class='$class' title='"
214                 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
215
216         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
217
218         // because of bug which M$ cannot fix since IE 5.0
219         // we must embed whole selector in span tags to enable proper ajax update
220         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
221
222         if ($select_submit != false) { // if submit on change is used - add select button
223                 global $_select_button;
224         // button class selects form reload/ajax selector update
225                 $selector .= sprintf($_select_button, $disabled, user_theme(),
226                         (fallback_mode() ? '' : 'display:none;'),
227                          '_'.$name.'_update')."\n";
228         }
229 // ------ make combo ----------
230
231         $edit_entry = '';
232         if ($search_box != false) {
233                 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
234                         $opts['size']."' maxlength='".$opts['max'].
235                         "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
236                         .$opts['box_hint']."'"
237                         .(!fallback_mode() && !$by_id ? " style=display:none;":'')
238                         .">\n";
239                 if ($search_submit != false) {
240                         global $_search_button;
241                         $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
242                                 (fallback_mode() ? '' : 'display:none;'),
243                                 $search_submit)."\n";
244                 }
245         }
246         default_focus(($search_box && $by_id) ? $search_box : $name);
247         $str = $selector;
248         if ($search_box && $opts['cells'])
249                 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
250         else
251                 echo $edit_entry.$selector;
252
253         return $str;
254 }
255
256 /*
257         Helper function.
258         Returns true if selector $name is subject to update.
259 */
260 function list_updated($name)
261 {
262         return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
263 }
264 //----------------------------------------------------------------------------------------------
265 //      Universal array combo generator
266 //      $items is array of options 'value' => 'description'
267 //      Options is reduced set of combo_selector options and is merged with defaults.
268
269 function array_selector($name, $selected_id, $items, $options=null)
270 {
271         global $Ajax;
272
273 $opts = array(          // default options
274         'spec_option'=>false,   // option text or false
275         'spec_id' => 0,         // option id
276         'select_submit' => false, //submit on select: true/false
277         'async' => true,        // select update via ajax (true) vs _page_body reload
278         'default' => '', // default value when $_POST is not set
279                 // search box parameters
280         'height' => false,      // number of lines in select box
281         'sel_hint' => null,
282         'disabled' => false
283 );
284 // ------ merge options with defaults ----------
285         if($options != null)
286                 $opts = array_merge($opts, $options);
287         $select_submit =  $opts['select_submit'];
288         $spec_id = $opts['spec_id'];
289         $spec_option = $opts['spec_option'];
290         $disabled = $opts['disabled'] ? "disabled" : '';
291
292         if ($selected_id == null) {
293                 $selected_id = get_post($name, $opts['default']);
294         }
295
296         if (isset($_POST[ '_'.$name.'_update'])) {
297                 if (!$opts['async'])
298                         $Ajax->activate('_page_body');
299                 else
300                         $Ajax->activate($name);
301         }
302
303         // ------ make selector ----------
304         $selector = $first_opt = '';
305         $first_id = false;
306         $found = false;
307 //if($name=='SelectStockFromList') display_error($sql);
308                 foreach($items as $value=>$descr) {
309                         $sel = '';
310                         if ((string)$selected_id === (string)$value) {
311                                 $sel = 'selected';
312                                 $found = $value;
313                         }
314                         if ($first_id === false) {
315                                 $first_id = $value;
316                                 $first_opt = $descr;
317                         }
318                         $selector .= "<option $sel value='$value'>$descr</option>\n";
319                 }
320
321         // Prepend special option.
322         if ($spec_option !== false) { // if special option used - add it
323                 $first_id = $spec_id;
324                 $first_opt = $spec_option;
325                 $sel = $found===false ? 'selected' : '';
326                 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
327                         . $selector;
328         }
329
330         if ($found === false) {
331                 $selected_id = $first_id;
332         }
333         $_POST[$name] = $selected_id;
334
335         $selector = "<select ".(strpos($name,'[]')!==false ? "multiple" : '')
336                 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
337                 . "$disabled name='$name' class='combo' title='"
338                 . $opts['sel_hint']."'>".$selector."</select>\n";
339
340         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
341
342         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
343
344         if ($select_submit != false) { // if submit on change is used - add select button
345                 global $_select_button;
346                 $selector .= sprintf($_select_button, $disabled, user_theme(),
347                         (fallback_mode() ? '' : 'display:none;'),
348                          '_'.$name.'_update')."\n";
349         }
350         default_focus($name);
351         echo $selector;
352
353         return $selector;
354 }
355 //----------------------------------------------------------------------------------------------
356
357 function _format_add_curr($row)
358 {
359         static $company_currency;
360
361         if ($company_currency == null)
362         {
363                 $company_currency = get_company_currency();
364         }
365         return $row[1] . ($row[2] == $company_currency ?
366                 '' : ("&nbsp;-&nbsp;" . $row[2]));
367 }
368
369 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
370         $all=false, $editkey = false)
371 {
372         global $all_items;
373
374         $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
375
376         $mode = get_company_pref('no_supplier_list');
377
378         if ($editkey)
379                 set_editor('supplier', $name, $editkey);
380                 
381         return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
382         array(
383                 'format' => '_format_add_curr',
384             'order' => array('supp_ref'),
385                 'search_box' => $mode!=0,
386                 'type' => 1,
387                 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
388                 'spec_id' => $all_items,
389                 'select_submit'=> $submit_on_change,
390                 'async' => false,
391                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
392                 _('Select supplier'),
393                 'show_inactive'=>$all
394                 ));
395 }
396
397 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, 
398         $submit_on_change=false, $all=false, $editkey = false)
399 {
400         if ($label != null)
401                 echo "<td>$label</td><td>\n";
402         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change, 
403                 $all, $editkey);
404                 echo "</td>\n";
405         return $str;
406 }
407
408 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, 
409         $submit_on_change=false, $all=false, $editkey = false)
410 {
411 echo "<tr><td>$label</td><td>";
412         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change,
413                 $all, $editkey);
414 echo "</td></tr>\n";
415 return $str;
416 }
417 //----------------------------------------------------------------------------------------------
418
419 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, 
420         $show_inactive=false, $editkey = false)
421 {
422         global $all_items;
423
424         $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
425
426         $mode = get_company_pref('no_customer_list');
427
428         if ($editkey)
429                 set_editor('customer', $name, $editkey);
430
431 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
432         array(
433             'format' => '_format_add_curr',
434             'order' => array('debtor_ref'),
435                 'search_box' => $mode!=0,
436                 'type' => 1,
437                 'size' => 20,
438                 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
439                 'spec_id' => $all_items,
440                 'select_submit'=> $submit_on_change,
441                 'async' => false,
442                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
443                 _('Select customer'),
444                 'show_inactive' => $show_inactive
445         ) );
446 }
447
448 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, 
449         $submit_on_change=false, $show_inactive=false, $editkey = false)
450 {
451         if ($label != null)
452                 echo "<td>$label</td>\n";
453         echo "<td nowrap>";
454         $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
455                 $show_inactive, $editkey);
456         echo "</td>\n";
457         return $str;
458 }
459
460 function customer_list_row($label, $name, $selected_id=null, $all_option = false, 
461         $submit_on_change=false, $show_inactive=false, $editkey = false)
462 {
463         echo "<tr><td>$label</td><td nowrap>";
464         $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
465                 $show_inactive, $editkey);
466         echo "</td>\n</tr>\n";
467         return $str;
468 }
469
470 //------------------------------------------------------------------------------------------------
471
472 function customer_branches_list($customer_id, $name, $selected_id=null,
473         $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
474 {
475         global $all_items;
476
477         $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
478                 WHERE debtor_no='" . $customer_id . "' ";
479
480         if ($editkey)
481                 set_editor('branch', $name, $editkey);
482
483         $where = $enabled ? array("disable_trans = 0") : array();
484 return  combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
485         array(
486                 'where' => $where,
487                 'order' => array('branch_ref'),
488                 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
489                 'spec_id' => $all_items,
490                 'select_submit'=> $submit_on_change,
491                 'sel_hint' => _('Select customer branch')
492         ) );
493 }
494 //------------------------------------------------------------------------------------------------
495
496 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, 
497         $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
498 {
499         if ($label != null)
500                 echo "<td>$label</td>\n";
501         echo "<td>";
502         $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, 
503                 $submit_on_change, $editkey);
504         echo "</td>\n";
505         return $ret;
506 }
507
508 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null, 
509         $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
510 {
511         echo "<tr>";
512         $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, 
513                 $all_option, $enabled, $submit_on_change, $editkey);
514         echo "</tr>";
515         return $ret;
516 }
517
518 //------------------------------------------------------------------------------------------------
519
520 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
521 {
522         global $all_items;
523
524         $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
525
526 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
527         array(
528                 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
529                 'spec_id' => $all_items,
530                 'select_submit'=> $submit_on_change
531         ) );
532 }
533
534 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
535 {
536         if ($label != null)
537                 echo "<td>$label</td>\n";
538         echo "<td>";
539         $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
540         echo "</td>\n";
541         return $str;
542 }
543
544 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
545 {
546         echo "<tr>";
547         $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
548         echo "</tr>\n";
549         return $str;
550 }
551
552 //-----------------------------------------------------------------------------------------------
553
554 function currencies_list($name, $selected_id=null, $submit_on_change=false)
555 {
556         $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
557
558 // default to the company currency
559
560 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
561         array(
562                 'select_submit'=> $submit_on_change,
563                 'default' => get_company_currency(),
564                 'async' => false                
565         ) );
566 }
567
568 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
569 {
570         if ($label != null)
571                 echo "<td>$label</td>\n";
572         echo "<td>";
573         $str = currencies_list($name, $selected_id, $submit_on_change);
574         echo "</td>\n";
575         return $str;
576 }
577
578 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
579 {
580         echo "<tr>\n";
581         $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
582         echo "</tr>\n";
583         return $str;
584 }
585
586 //---------------------------------------------------------------------------------------------------
587
588 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
589 {
590
591         $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
592
593 // default to the company current fiscal year
594
595 return combo_input($name, $selected_id, $sql, 'id', '',
596         array(
597                 'order' => 'begin',
598                 'default' => get_company_pref('f_year'),
599                 'format' => '_format_fiscalyears',
600                 'select_submit'=> $submit_on_change,
601                 'async' => false
602         ) );
603 }
604
605 function _format_fiscalyears($row)
606 {
607         return sql2date($row[1]) . "&nbsp;-&nbsp;" . sql2date($row[2])
608         . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
609 }
610
611 function fiscalyears_list_cells($label, $name, $selected_id=null)
612 {
613         if ($label != null)
614                 echo "<td>$label</td>\n";
615         echo "<td>";
616         $str = fiscalyears_list($name, $selected_id);
617         echo "</td>\n";
618         return $str;
619 }
620
621 function fiscalyears_list_row($label, $name, $selected_id=null)
622 {
623         echo "<tr>\n";
624         $str = fiscalyears_list_cells($label, $name, $selected_id);
625         echo "</tr>\n";
626         return $str;
627 }
628 //------------------------------------------------------------------------------------
629
630 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
631         $submit_on_change=false, $showclosed=false, $showtype=1)
632 {
633 $sql = "SELECT id, CONCAT(reference,'  ',name) as ref FROM ".TB_PREF."dimensions";
634
635 $options = array(
636         'order' => 'reference',
637         'spec_option'=>$no_option ? $showname : false,
638         'spec_id' => 0,
639         'select_submit'=> $submit_on_change,
640         'async' => false,
641         );
642
643         if (!$showclosed)
644                 $options['where'][] = "closed=0";
645         if($showtype)
646                 $options['where'][] = "type_=$showtype";
647
648         return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
649 }
650
651 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
652         $showclosed=false, $showtype=0, $submit_on_change=false)
653 {
654         if ($label != null)
655                 echo "<td>$label</td>\n";
656         echo "<td>";
657         $str = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
658         echo "</td>\n";
659         return $str;
660 }
661
662 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
663         $showclosed=false, $showtype=0, $submit_on_change=false)
664 {
665         echo "<tr>\n";
666         $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
667                 $showclosed, $showtype, $submit_on_change);
668         echo "</tr>\n";
669         return $str;
670 }
671
672 //---------------------------------------------------------------------------------------------------
673
674 function stock_items_list($name, $selected_id=null, $all_option=false, 
675         $submit_on_change=false, $opts=array(), $editkey = false)
676 {
677         global $all_items;
678
679         $sql = "SELECT stock_id, s.description, c.description, s.inactive
680                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
681
682         if ($editkey)
683                 set_editor('item', $name, $editkey);
684
685         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
686         array_merge(
687           array(
688                 'format' => '_format_stock_items',
689                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
690                 'spec_id' => $all_items,
691                 'search_box' => true,
692                 'search' => array("stock_id", "c.description","s.description"),
693                 'search_submit' => get_company_pref('no_item_list')!=0,
694                 'size'=>10,
695                 'select_submit'=> $submit_on_change,
696                 'category' => 2,
697                 'order' => array('c.description','stock_id')
698           ), $opts) );
699 }
700
701 function _format_stock_items($row)
702 {
703         return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "") . $row[1];
704 }
705
706 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, 
707         $submit_on_change=false, $all=false, $editkey = false)
708 {
709         if ($label != null)
710                 echo "<td>$label</td>\n";
711         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
712                 array('cells'=>true, 'show_inactive'=>$all), $editkey);
713         return $str;
714 }
715 /*
716 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
717 {
718         echo "<tr>\n";
719         $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
720         echo "</tr>\n";
721         return $str;
722 }
723 */
724 //---------------------------------------------------------------------------------------------------
725 //
726 // Select item via foreign code.
727 //
728 function sales_items_list($name, $selected_id=null, $all_option=false, 
729         $submit_on_change=false, $type='', $opts=array())
730 {
731         global $all_items;
732         // all sales codes
733         $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
734                          i.inactive
735                         FROM
736                         ".TB_PREF."stock_master s,
737                         ".TB_PREF."item_codes i
738                         LEFT JOIN
739                         ".TB_PREF."stock_category c
740                         ON i.category_id=c.category_id
741                         WHERE i.stock_id=s.stock_id";
742
743         
744         if ($type == 'local')   { // exclude foreign codes
745                 $sql .= " AND !i.is_foreign"; 
746         } elseif ($type == 'kits') { // sales kits
747                 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
748         }
749         $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
750         $sql .= " GROUP BY i.item_code";
751
752         return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
753         array_merge(
754           array(
755                 'format' => '_format_stock_items',
756                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
757                 'spec_id' => $all_items,
758                 'search_box' => true,
759                 'search' => array("i.item_code", "i.description"),
760                 'search_submit' => get_company_pref('no_item_list')!=0,
761                 'size'=>15,
762                 'select_submit'=> $submit_on_change,
763                 'category' => 2,
764                 'order' => array('c.description','i.item_code')
765           ), $opts) );
766 }
767
768 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
769 {
770         if ($label != null)
771                 echo "<td>$label</td>\n";
772         $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
773                 '', array('cells'=>true));
774         return $str;
775 }
776
777 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
778 {
779         $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
780                 'kits', array('cells'=>false));
781         return $str;
782 }
783
784 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
785 {
786         echo "<tr>";
787         if ($label != null)
788                 echo "<td>$label</td>\n";
789         echo "<td>";
790         $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
791                 'local', array('cells'=>false));
792         echo "</td></tr>";
793         return $str;
794 }
795 //------------------------------------------------------------------------------------
796
797 function stock_manufactured_items_list($name, $selected_id=null,
798         $all_option=false, $submit_on_change=false)
799 {
800         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
801                 array('where'=>array("mb_flag= 'M'")));
802         return $str;            
803 }
804
805 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
806                                 $all_option=false, $submit_on_change=false)
807 {
808         if ($label != null)
809                 echo "<td>$label</td>\n";
810         echo "<td>";
811         $str = stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
812         echo "</td>\n";
813         return $str;
814 }
815
816 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
817                 $all_option=false, $submit_on_change=false)
818 {
819         echo "<tr>\n";
820         $str = stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
821         echo "</tr>\n";
822         return $str;
823 }
824 //------------------------------------------------------------------------------------
825
826 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
827         $all_option=false, $submit_on_change=false, $editkey = false)
828 {
829         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
830                 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
831         return $str;
832 }
833
834 function stock_component_items_list_cells($label, $name, $parent_stock_id, 
835         $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
836 {
837         if ($label != null)
838                 echo "<td>$label</td>\n";
839         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
840                 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
841                 $editkey);
842         return $str;
843 }
844 //------------------------------------------------------------------------------------
845
846 function stock_costable_items_list($name, $selected_id=null,
847         $all_option=false, $submit_on_change=false)
848 {
849         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
850                 array('where'=>array("mb_flag!='D'")));
851         return $str;
852 }
853
854 function stock_costable_items_list_cells($label, $name, $selected_id=null, 
855         $all_option=false, $submit_on_change=false)
856 {
857         if ($label != null)
858                 echo "<td>$label</td>\n";
859         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
860                 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
861         return $str;
862 }
863
864 //------------------------------------------------------------------------------------
865 function stock_purchasable_items_list($name, $selected_id=null, 
866         $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
867 {
868         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
869                 array('where'=>array("mb_flag!= 'M'"), 
870                         'show_inactive'=>$all), $editkey);
871         return $str;
872 }
873
874 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
875                         $all_option=false, $submit_on_change=false, $editkey=false)
876 {
877         if ($label != null)
878                 echo "<td>$label</td>\n";
879         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
880                 array('where'=>array("mb_flag!= 'M'"), 
881                          'cells'=>true), $editkey);
882         return $str;
883 }
884
885 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
886                         $all_option=false, $submit_on_change=false, $editkey=false)
887 {
888         echo "<tr>\n";
889         $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
890                 $all_option, $submit_on_change, $editkey);
891         echo "</tr>\n";
892         return $ret;
893 }
894
895 //------------------------------------------------------------------------------------
896
897 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
898 {
899         global $stock_types;
900
901         echo "<tr>";
902         if ($label != null)
903                 echo "<td>$label</td>\n";
904         echo "<td>";
905
906         array_selector($name, $selected_id, $stock_types, 
907                 array( 
908                         'select_submit'=> true, 
909                         'disabled' => !$enabled) );
910         echo "</td></tr>\n";
911 }
912
913 function stock_units_list_row($label, $name, $value=null, $enabled=true)
914 {
915         $result = get_all_item_units();
916         echo "<tr>";
917         if ($label != null)
918                 echo "<td>$label</td>\n";
919         echo "<td>";
920
921         while($unit = db_fetch($result))
922                 $units[$unit['abbr']] = $unit['name'];
923
924         array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
925
926         echo "</td></tr>\n";
927 }
928
929 //------------------------------------------------------------------------------------
930
931 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
932 {
933         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
934
935         return combo_input($name, $selected_id, $sql, 'id', 'name',
936         array(
937                 'spec_option' => $none_option,
938                 'spec_id' => ALL_NUMERIC,
939                 'select_submit'=> $submit_on_change,
940                 'async' => false,
941         ) );
942 }
943
944 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
945         $submit_on_change=false)
946 {
947         if ($label != null)
948                 echo "<td>$label</td>\n";
949         echo "<td>";
950         $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
951         echo "</td>\n";
952         return $str;
953 }
954
955 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
956         $submit_on_change=false)
957 {
958         echo "<tr>\n";
959         $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
960         echo "</tr>\n";
961         return $str;
962 }
963
964 //------------------------------------------------------------------------------------
965
966 function tax_groups_list($name, $selected_id=null,
967         $none_option=false, $submit_on_change=false)
968 {
969         $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
970
971         return combo_input($name, $selected_id, $sql, 'id', 'name',
972         array(
973                 'order' => 'id',
974                 'spec_option' => $none_option,
975                 'spec_id' => ALL_NUMERIC,
976                 'select_submit'=> $submit_on_change,
977                 'async' => false,
978         ) );
979 }
980
981 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
982 {
983         if ($label != null)
984                 echo "<td>$label</td>\n";
985         echo "<td>";
986         $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
987         echo "</td>\n";
988         return $str;
989 }
990
991 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
992 {
993         echo "<tr>\n";
994         $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
995         echo "</tr>\n";
996         return $str;
997 }
998
999 //------------------------------------------------------------------------------------
1000
1001 function item_tax_types_list($name, $selected_id=null)
1002 {
1003         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1004         combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1005 }
1006
1007 function item_tax_types_list_cells($label, $name, $selected_id=null)
1008 {
1009         if ($label != null)
1010                 echo "<td>$label</td>\n";
1011         echo "<td>";
1012         item_tax_types_list($name, $selected_id);
1013         echo "</td>\n";
1014 }
1015
1016 function item_tax_types_list_row($label, $name, $selected_id=null)
1017 {
1018         echo "<tr>\n";
1019         item_tax_types_list_cells($label, $name, $selected_id);
1020         echo "</tr>\n";
1021 }
1022
1023 //------------------------------------------------------------------------------------
1024
1025 function shippers_list($name, $selected_id=null)
1026 {
1027         $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1028         combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', 
1029                 array('order'=>array('shipper_name')));
1030 }
1031
1032 function shippers_list_cells($label, $name, $selected_id=null)
1033 {
1034         if ($label != null)
1035                 echo "<td>$label</td>\n";
1036         echo "<td>";
1037         shippers_list($name, $selected_id);
1038         echo "</td>\n";
1039 }
1040
1041 function shippers_list_row($label, $name, $selected_id=null)
1042 {
1043         echo "<tr>\n";
1044         shippers_list_cells($label, $name, $selected_id);
1045         echo "</tr>\n";
1046 }
1047
1048 //-------------------------------------------------------------------------------------
1049
1050 function sales_persons_list($name, $selected_id=null)
1051 {
1052         $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1053         combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', 
1054                 array('order'=>array('salesman_name')));
1055 }
1056
1057 function sales_persons_list_cells($label, $name, $selected_id=null)
1058 {
1059         if ($label != null)
1060                 echo "<td>$label</td>\n";
1061         echo "<td>\n";
1062         sales_persons_list($name, $selected_id);
1063         echo "</td>\n";
1064 }
1065
1066 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1067 {
1068         echo "<tr>\n";
1069         sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1070         echo "</tr>\n";
1071 }
1072
1073 //------------------------------------------------------------------------------------
1074
1075 function sales_areas_list($name, $selected_id=null)
1076 {
1077         $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1078         combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1079 }
1080
1081 function sales_areas_list_cells($label, $name, $selected_id=null)
1082 {
1083         if ($label != null)
1084                 echo "<td>$label</td>\n";
1085         echo "<td>";
1086         sales_areas_list($name, $selected_id);
1087         echo "</td>\n";
1088 }
1089
1090 function sales_areas_list_row($label, $name, $selected_id=null)
1091 {
1092         echo "<tr>\n";
1093         sales_areas_list_cells($label, $name, $selected_id);
1094         echo "</tr>\n";
1095 }
1096
1097 //------------------------------------------------------------------------------------
1098
1099 function sales_groups_list($name, $selected_id=null, $special_option=false)
1100 {
1101         $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1102         combo_input($name, $selected_id, $sql, 'id', 'description', array(
1103                 'spec_option' => $special_option===true ? ' ' : $special_option,
1104                 'order' => 'description', 'spec_id' => 0,
1105         ));
1106 }
1107
1108 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1109 {
1110         if ($label != null)
1111                 echo "<td>$label</td>\n";
1112         echo "<td>";
1113         sales_groups_list($name, $selected_id, $special_option);
1114         echo "</td>\n";
1115 }
1116
1117 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1118 {
1119         echo "<tr>\n";
1120         sales_groups_list_cells($label, $name, $selected_id, $special_option);
1121         echo "</tr>\n";
1122 }
1123
1124 //------------------------------------------------------------------------------------
1125
1126 function _format_template_items($row)
1127 {
1128         return ($row[0] . "&nbsp;- &nbsp;" . _("Amount") . "&nbsp;".$row[1]);
1129 }
1130
1131 function templates_list($name, $selected_id=null, $special_option=false)
1132 {
1133         $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1134                 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1135                 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1136         combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1137                 'format' => '_format_template_items',
1138                 'spec_option' => $special_option===true ? ' ' : $special_option,
1139                 'order' => 'order_no', 'spec_id' => 0,
1140         ));
1141 }
1142
1143 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1144 {
1145         if ($label != null)
1146                 echo "<td>$label</td>\n";
1147         echo "<td>";
1148         templates_list($name, $selected_id, $special_option);
1149         echo "</td>\n";
1150 }
1151
1152 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1153 {
1154         echo "<tr>\n";
1155         templates_list_cells($label, $name, $selected_id, $special_option);
1156         echo "</tr>\n";
1157 }
1158
1159 //------------------------------------------------------------------------------------
1160
1161 function workorders_list($name, $selected_id=null)
1162 {
1163         $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1164         combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1165 }
1166
1167 function workorders_list_cells($label, $name, $selected_id=null)
1168 {
1169         if ($label != null)
1170                 echo "<td>$label</td>\n";
1171         echo "<td>";
1172         workorders_list($name, $selected_id);
1173         echo "</td>\n";
1174 }
1175
1176 function workorders_list_row($label, $name, $selected_id=null)
1177 {
1178         echo "<tr>\n";
1179         workorders_list_cells($label, $name, $selected_id);
1180         echo "</tr>\n";
1181 }
1182
1183 //------------------------------------------------------------------------------------
1184
1185 function payment_terms_list($name, $selected_id=null)
1186 {
1187         $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1188         combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1189 }
1190
1191 function payment_terms_list_cells($label, $name, $selected_id=null)
1192 {
1193         if ($label != null)
1194                 echo "<td>$label</td>\n";
1195         echo "<td>";
1196         payment_terms_list($name, $selected_id);
1197         echo "</td>\n";
1198 }
1199
1200 function payment_terms_list_row($label, $name, $selected_id=null)
1201 {
1202         echo "<tr>\n";
1203         payment_terms_list_cells($label, $name, $selected_id);
1204         echo "</tr>\n";
1205 }
1206
1207 //------------------------------------------------------------------------------------
1208
1209 function credit_status_list($name, $selected_id=null)
1210 {
1211         $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1212         combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1213 }
1214
1215 function credit_status_list_cells($label, $name, $selected_id=null)
1216 {
1217         if ($label != null)
1218                 echo "<td>$label</td>\n";
1219         echo "<td>";
1220         credit_status_list($name, $selected_id);
1221         echo "</td>\n";
1222 }
1223
1224 function credit_status_list_row($label, $name, $selected_id=null)
1225 {
1226         echo "<tr>\n";
1227         credit_status_list_cells($label, $name, $selected_id);
1228         echo "</tr>\n";
1229 }
1230
1231 //-----------------------------------------------------------------------------------------------
1232
1233 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1234 {
1235         $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1236
1237         return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1238         array(
1239                 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1240                 'spec_id' => 0,
1241                 'select_submit'=> $submit_on_change,
1242         //        'async' => false,
1243         ) );
1244 }
1245
1246 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1247 {
1248         if ($label != null)
1249                 echo "<td>$label</td>\n";
1250         echo "<td>";
1251         $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1252         echo "</td>\n";
1253         return $str;
1254 }
1255
1256 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1257 {
1258         echo "<tr>\n";
1259         $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1260         echo "</tr>\n";
1261         return $str;
1262 }
1263
1264 //-----------------------------------------------------------------------------------------------
1265
1266 function movement_types_list($name, $selected_id=null)
1267 {
1268         $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1269         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1270 }
1271
1272 function movement_types_list_cells($label, $name, $selected_id=null)
1273 {
1274         if ($label != null)
1275                 echo "<td>$label</td>\n";
1276         echo "<td>";
1277         movement_types_list($name, $selected_id);
1278         echo "</td>\n";
1279 }
1280
1281 function movement_types_list_row($label, $name, $selected_id=null)
1282 {
1283         echo "<tr>\n";
1284         movement_types_list_cells($label, $name, $selected_id);
1285         echo "</tr>\n";
1286 }
1287
1288 //-----------------------------------------------------------------------------------------------
1289 function _format_date($row)
1290 {
1291         return sql2date($row['reconciled']);
1292 }
1293
1294 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1295 {
1296         $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1297                 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1298                 GROUP BY reconciled";
1299         combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1300         array(
1301                 'spec_option' => $special_option,
1302                 'format' => '_format_date',
1303                 'spec_id' => '',
1304                 'select_submit'=> $submit_on_change
1305         ) );
1306 }
1307
1308 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1309 {
1310         if ($label != null)
1311                 echo "<td>$label</td>\n";
1312         echo "<td>";
1313         bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1314         echo "</td>\n";
1315 }
1316 /*
1317 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1318 {
1319         echo "<tr>\n";
1320         bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1321         echo "</tr>\n";
1322 }
1323 */
1324 //-----------------------------------------------------------------------------------------------
1325
1326 function workcenter_list($name, $selected_id=null, $all_option=false)
1327 {
1328         global $all_items;
1329
1330         $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1331
1332         return combo_input($name, $selected_id, $sql, 'id', 'name',
1333         array(
1334                 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1335                 'spec_id' => $all_items,
1336         ) );
1337 }
1338
1339 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1340 {
1341         default_focus($name);
1342         if ($label != null)
1343                 echo "<td>$label</td>\n";
1344         echo "<td>";
1345         workcenter_list($name, $selected_id, $all_option);
1346         echo "</td>\n";
1347 }
1348
1349 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1350 {
1351         echo "<tr>\n";
1352         workcenter_list_cells($label, $name, $selected_id, $all_option);
1353         echo "</tr>\n";
1354 }
1355
1356 //-----------------------------------------------------------------------------------------------
1357
1358 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1359 {
1360         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1361                 FROM ".TB_PREF."bank_accounts";
1362 //              , ".TB_PREF."chart_master
1363 //              WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1364
1365         return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1366         array(
1367                 'format' => '_format_add_curr',
1368                 'select_submit'=> $submit_on_change,
1369                 'async' => false
1370         ) );
1371 }
1372
1373 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1374 {
1375         if ($label != null)
1376                 echo "<td>$label</td>\n";
1377         echo "<td>";
1378         $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1379         echo "</td>\n";
1380         return $str;
1381 }
1382
1383 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1384 {
1385         echo "<tr>\n";
1386         $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1387         echo "</tr>\n";
1388         return $str;
1389 }
1390 //-----------------------------------------------------------------------------------------------
1391
1392 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1393 {
1394         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1395                 FROM ".TB_PREF."bank_accounts
1396                 WHERE ".TB_PREF."bank_accounts.account_type=3";
1397
1398         if ($label != null)
1399                 echo "<tr><td>$label</td>\n";
1400         echo "<td>";
1401         $str = combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1402         array(
1403                 'format' => '_format_add_curr',
1404                 'select_submit'=> $submit_on_change,
1405                 'async' => true
1406         ) );
1407         echo "</td></tr>\n";
1408         return $str;
1409 }
1410 //-----------------------------------------------------------------------------------------------
1411
1412 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1413 {
1414         $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1415
1416         default_focus($name);
1417         echo '<tr>';
1418         if ($label != null)
1419                 echo "<td>$label</td>\n";
1420         echo "<td>";
1421
1422         $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1423         array(
1424                 'select_submit'=> $submit_on_change,
1425                 'async' => true,
1426                 'spec_option' =>$spec_option,
1427                 'spec_id' => -1,
1428                 'order'=> array('pos_name')
1429         ) );
1430         echo "</td></tr>\n";
1431
1432         return $str;    
1433 }
1434 //-----------------------------------------------------------------------------------------------
1435
1436 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1437 {
1438         if ($label != null)
1439                 echo "<td>$label</td>\n";
1440         echo "<td>";
1441         $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1442         echo "</td>\n";
1443         return $str;
1444 }
1445 //-----------------------------------------------------------------------------------------------
1446
1447 function class_list($name, $selected_id=null, $submit_on_change=false)
1448 {
1449         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1450
1451         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1452         array(
1453                 'select_submit'=> $submit_on_change,
1454                 'async' => false
1455         ) );
1456
1457 }
1458
1459 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1460 {
1461         if ($label != null)
1462                 echo "<td>$label</td>\n";
1463         echo "<td>";
1464         $str = class_list($name, $selected_id, $submit_on_change);
1465         echo "</td>\n";
1466         return $str;
1467 }
1468
1469 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1470 {
1471         echo "<tr>\n";
1472         $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1473         echo "</tr>\n";
1474         return $str;
1475 }
1476
1477 //-----------------------------------------------------------------------------------------------
1478
1479 function stock_categories_list($name, $selected_id=null, $submit_on_change=false)
1480 {
1481         $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1482         combo_input($name, $selected_id, $sql, 'category_id', 'description',
1483         array('order'=>'category_id',
1484                 'select_submit'=> $submit_on_change,
1485                 'async' => true
1486         ));
1487 }
1488
1489 function stock_categories_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1490 {
1491         if ($label != null)
1492                 echo "<td>$label</td>\n";
1493         echo "<td>";
1494         stock_categories_list($name, $selected_id, $submit_on_change);
1495         echo "</td>\n";
1496 }
1497
1498 function stock_categories_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1499 {
1500         echo "<tr>\n";
1501         stock_categories_list_cells($label, $name, $selected_id, $submit_on_change);
1502         echo "</tr>\n";
1503 }
1504
1505 //-----------------------------------------------------------------------------------------------
1506
1507 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1508 {
1509         global $all_items;
1510
1511         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1512
1513         combo_input($name, $selected_id, $sql, 'id', 'name',
1514         array(
1515                 'order' => 'id',
1516                 'spec_option' =>$all_option,
1517                 'spec_id' => $all_option_numeric ? 0 : $all_items
1518         ) );
1519 }
1520
1521 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1522         $all_option_numeric=false)
1523 {
1524         if ($label != null)
1525                 echo "<td>$label</td>\n";
1526         echo "<td>";
1527         gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1528         echo "</td>\n";
1529 }
1530
1531 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1532         $all_option_numeric=false)
1533 {
1534         echo "<tr>\n";
1535         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1536                 $all_option_numeric);
1537         echo "</tr>\n";
1538 }
1539
1540 //-----------------------------------------------------------------------------------------------
1541 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1542         $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1543 {
1544         if ($skip_bank_accounts)
1545                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1546                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1547                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1548                         ."ON chart.account_code=acc.account_code
1549                                 WHERE acc.account_code  IS NULL
1550                         AND chart.account_type=type.id";
1551         else
1552                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1553                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1554                         WHERE chart.account_type=type.id";
1555
1556         combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1557         array(
1558                 'format' => '_format_account',
1559                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1560                 'spec_id' => '',
1561                 'order' => array('type.id','account_code'),
1562                 'search_box' => $cells,
1563                         'search_submit' => false,
1564                         'size' => 12,
1565                         'max' => 10,
1566                         'cells' => true,
1567                 'select_submit'=> $submit_on_change,
1568                 'async' => false,
1569                 'category' => 2,
1570                 'show_inactive' => $all
1571         ) );
1572
1573 }
1574
1575 function _format_account($row)
1576 {
1577                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1578 }
1579
1580 function gl_all_accounts_list_cells($label, $name, $selected_id=null, 
1581         $skip_bank_accounts=false, $cells=false, $all_option=false, 
1582         $submit_on_change=false, $all=false)
1583 {
1584         if ($label != null)
1585                 echo "<td>$label</td>\n";
1586         echo "<td>";
1587         gl_all_accounts_list($name, $selected_id, 
1588                 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1589         echo "</td>\n";
1590 }
1591
1592 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
1593         $skip_bank_accounts=false, $cells=false, $all_option=false)
1594 {
1595         echo "<tr>\n";
1596         gl_all_accounts_list_cells($label, $name, $selected_id, 
1597                 $skip_bank_accounts, $cells, $all_option);
1598         echo "</tr>\n";
1599 }
1600
1601 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1602 {
1603         $items = array();
1604         $items['0'] = strlen($name_no) ? $name_no : _("No");
1605         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1606
1607         return array_selector($name, $selected_id, $items, 
1608                 array( 
1609                         'select_submit'=> $submit_on_change,
1610                         'async' => false ) ); // FIX?
1611 }
1612
1613 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1614 {
1615         if ($label != null)
1616                 echo "<td>$label</td>\n";
1617         echo "<td>";
1618         $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1619         echo "</td>\n";
1620         return $str;
1621 }
1622
1623 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1624 {
1625         echo "<tr>\n";
1626         $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1627         echo "</tr>\n";
1628         return $str;
1629 }
1630
1631 //------------------------------------------------------------------------------------------------
1632
1633 function languages_list($name, $selected_id=null)
1634 {
1635         global $installed_languages;
1636
1637         $items = array();
1638         foreach ($installed_languages as $lang)
1639                         $items[$lang['code']] = $lang['name'];
1640         
1641         return array_selector($name, $selected_id, $items );
1642 }
1643
1644 function languages_list_cells($label, $name, $selected_id=null)
1645 {
1646         if ($label != null)
1647                 echo "<td>$label</td>\n";
1648         echo "<td>";
1649         languages_list($name, $selected_id);
1650         echo "</td>\n";
1651 }
1652
1653 function languages_list_row($label, $name, $selected_id=null)
1654 {
1655         echo "<tr>\n";
1656         languages_list_cells($label, $name, $selected_id);
1657         echo "</tr>\n";
1658 }
1659
1660 //------------------------------------------------------------------------------------------------
1661
1662 function bank_account_types_list($name, $selected_id=null)
1663 {
1664         global $bank_account_types;
1665
1666         return array_selector($name, $selected_id, $bank_account_types);
1667 }
1668
1669 function bank_account_types_list_cells($label, $name, $selected_id=null)
1670 {
1671         if ($label != null)
1672                 echo "<td>$label</td>\n";
1673         echo "<td>";
1674         bank_account_types_list($name, $selected_id);
1675         echo "</td>\n";
1676 }
1677
1678 function bank_account_types_list_row($label, $name, $selected_id=null)
1679 {
1680         echo "<tr>\n";
1681         bank_account_types_list_cells($label, $name, $selected_id);
1682         echo "</tr>\n";
1683 }
1684
1685 //------------------------------------------------------------------------------------------------
1686 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1687 {
1688         global $payment_person_types;
1689
1690         $items = array();
1691         foreach ($payment_person_types as $key=>$type)
1692         {
1693                 if ($key != PT_WORKORDER)
1694                         $items[$key] = $type;
1695         }               
1696         return array_selector($name, $selected_id, $items, 
1697                 array( 'select_submit'=> $submit_on_change ) );
1698 }
1699
1700 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1701 {
1702         if ($label != null)
1703                 echo "<td>$label</td>\n";
1704         echo "<td>";
1705         $str = payment_person_types_list($name, $selected_id, $related);
1706         echo "</td>\n";
1707         return $str;
1708 }
1709
1710 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1711 {
1712         echo "<tr>\n";
1713         $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1714         echo "</tr>\n";
1715         return $str;
1716 }
1717
1718 //------------------------------------------------------------------------------------------------
1719
1720 function wo_types_list($name, $selected_id=null)
1721 {
1722         global $wo_types_array;
1723         
1724         return array_selector($name, $selected_id, $wo_types_array, 
1725                 array( 'select_submit'=> true, 'async' => true ) );
1726 }
1727
1728 function wo_types_list_row($label, $name, $selected_id=null)
1729 {
1730         echo "<tr><td>$label</td><td>\n";
1731         $str = wo_types_list($name, $selected_id);
1732         echo "</td></tr>\n";
1733         return $str;
1734 }
1735
1736 //------------------------------------------------------------------------------------------------
1737
1738 function dateformats_list_row($label, $name, $value=null)
1739 {
1740         global $dateformats;
1741
1742         echo "<tr><td>$label</td>\n<td>";
1743         array_selector( $name, $value, $dateformats );
1744         echo "</td></tr>\n";
1745 }
1746
1747 function dateseps_list_row($label, $name, $value=null)
1748 {
1749         global $dateseps;
1750
1751         echo "<tr><td>$label</td>\n<td>";
1752         array_selector( $name, $value, $dateseps );
1753         echo "</td></tr>\n";
1754 }
1755
1756 function thoseps_list_row($label, $name, $value=null)
1757 {
1758         global $thoseps;
1759
1760         echo "<tr><td>$label</td>\n<td>";
1761         array_selector( $name, $value, $thoseps );
1762         echo "</td></tr>\n";
1763 }
1764
1765 function decseps_list_row($label, $name, $value=null)
1766 {
1767         global $decseps;
1768
1769         echo "<tr><td>$label</td>\n<td>";
1770         array_selector( $name, $value, $decseps );
1771         echo "</td></tr>\n";
1772 }
1773
1774 function themes_list_row($label, $name, $value=null)
1775 {
1776         global $path_to_root;
1777
1778         $path = $path_to_root.'/themes/';
1779         $themes = array();
1780         $themedir = opendir($path);
1781         while(false !== ($fname = readdir($themedir)))
1782         {
1783                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1784                 {
1785                         $themes[$fname] =  $fname;
1786                 }
1787         }
1788         ksort($themes);
1789
1790         echo "<tr><td>$label</td>\n<td>";
1791         array_selector( $name, $value, $themes );
1792         echo "</td></tr>\n";
1793 }
1794
1795 function pagesizes_list_row($label, $name, $value=null)
1796 {
1797         global $pagesizes;
1798
1799         $items = array();
1800         foreach ($pagesizes as $pz)
1801                 $items[$pz] = $pz;
1802
1803         echo "<tr><td>$label</td>\n<td>";
1804         array_selector( $name, $value, $items );
1805         echo "</td></tr>\n";
1806 }
1807
1808 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1809 {
1810         global $systypes_array;
1811
1812         if ($label != null)
1813                 echo "<td>$label</td>\n";
1814         echo "<td>";
1815         
1816         $str = array_selector($name, $value, $systypes_array, 
1817                 array( 
1818                         'select_submit'=> $submit_on_change,
1819                         'async' => false
1820                         )
1821         );
1822         echo "</td>\n";
1823         return $str;
1824 }
1825
1826 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1827 {
1828         global $systypes_array;
1829
1830         if ($label != null)
1831                 echo "<td>$label</td>\n";
1832         echo "<td>";
1833
1834         $items = $systypes_array;
1835
1836         // exclude quotes, orders and dimensions
1837         foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION, 
1838                                 ST_SALESQUOTE) as $excl)
1839                         unset($items[$excl]);
1840         
1841         $str = array_selector($name, $value, $items, 
1842                 array( 
1843                         'spec_option'=> _("All"),
1844                         'spec_id' => -1,
1845                         'select_submit'=> $submit_on_change,
1846                         'async' => false
1847                         )
1848         );
1849         echo "</td>\n";
1850         return $str;
1851 }
1852
1853 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1854 {
1855         echo "<tr>\n";
1856         $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1857         echo "</tr>\n";
1858         return $str;
1859 }
1860
1861 function cust_allocations_list_cells($label, $name, $selected=null)
1862 {
1863         global $all_items;
1864
1865         if ($label != null)
1866                 label_cell($label);
1867         echo "<td>\n";
1868         $allocs = array( 
1869                 $all_items=>_("All Types"),
1870                 '1'=> _("Sales Invoices"),
1871                 '2'=> _("Overdue Invoices"),
1872                 '3' => _("Payments"),
1873                 '4' => _("Credit Notes"),
1874                 '5' => _("Delivery Notes")
1875         );
1876         $str = array_selector($name, $selected, $allocs);
1877         echo "</td>\n";
1878         return $str;
1879 }
1880
1881 function supp_allocations_list_cell($name, $selected=null)
1882 {
1883         global $all_items;
1884
1885         echo "<td>\n";
1886         $allocs = array( 
1887                 $all_items=>_("All Types"),
1888                 '1'=> _("Invoices"),
1889                 '2'=> _("Overdue Invoices"),
1890                 '3' => _("Payments"),
1891                 '4' => _("Credit Notes"),
1892                 '5' => _("Overdue Credit Notes")
1893         );
1894         $str = array_selector($name, $selected, $allocs);
1895         echo "</td>\n";
1896         return $str;
1897 }
1898
1899 function policy_list_cells($label, $name, $selected=null)
1900 {
1901         if ($label != null)
1902                 label_cell($label);
1903         echo "<td>\n";
1904         $str = array_selector($name, $selected, 
1905                                 array( '' => _("Automatically put balance on back order"),
1906                                         'CAN' => _("Cancel any quantites not delivered")) );
1907         echo "</td>\n";
1908         return $str;
1909 }
1910
1911 function policy_list_row($label, $name, $selected=null)
1912 {
1913         echo "<tr>\n";
1914         policy_list_cells($label, $name, $selected);
1915         echo "</tr>\n";
1916 }
1917
1918 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1919 {
1920         if ($label != null)
1921                 label_cell($label);
1922         echo "<td>\n";
1923         $str = array_selector($name, $selected, 
1924                                 array( 'Return' => _("Items Returned to Inventory Location"),
1925                                         'WriteOff' => _("Items Written Off")),
1926                                 array( 'select_submit'=> $submit_on_change ) );
1927         echo "</td>\n";
1928         return $str;
1929 }
1930
1931 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1932 {
1933         echo "<tr>\n";
1934         $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1935         echo "</tr>\n";
1936         return $str;
1937 }
1938
1939 function number_list($name, $selected, $from, $to, $no_option=false)
1940 {
1941         $items = array();
1942         for ($i = $from; $i <= $to; $i++)
1943                 $items[$i] = "$i";
1944
1945         return array_selector($name, $selected, $items,
1946                                 array(  'spec_option' => $no_option,
1947                                                 'spec_id' => ALL_NUMERIC) );
1948 }
1949
1950 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1951 {
1952         if ($label != null)
1953                 label_cell($label);
1954         echo "<td>\n";
1955         number_list($name, $selected, $from, $to, $no_option);
1956         echo "</td>\n";
1957 }
1958
1959 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1960 {
1961         echo "<tr>\n";
1962         number_list_cells($label, $name, $selected, $from, $to, $no_option);
1963         echo "</tr>\n";
1964 }
1965
1966 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1967         $submit_on_change=true)
1968 {
1969         $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1970                 ." GROUP BY profile";
1971         $result = db_query($sql, 'cannot get all profile names');
1972         $profiles = array();
1973         while($myrow=db_fetch($result)) {
1974                 $profiles[$myrow['profile']] = $myrow['profile'];
1975         }
1976
1977         echo "<tr>";
1978         if ($label != null)
1979                 echo "<td>$label</td>\n";
1980         echo "<td>";
1981
1982         array_selector($name, $selected_id, $profiles, 
1983                 array( 'select_submit'=> $submit_on_change,
1984                         'spec_option'=>$spec_opt,
1985                         'spec_id' => ''
1986                  ));
1987
1988         echo "</td></tr>\n";
1989 }
1990
1991 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1992 {
1993         static $printers; // query only once for page display
1994
1995         if (!$printers) {
1996                 $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; 
1997                 $result = db_query($sql, 'cannot get all printers');
1998                 $printers = array();
1999                 while($myrow=db_fetch($result)) {
2000                         $printers[$myrow['id']] = $myrow['name'].'&nbsp;-&nbsp;'.$myrow['description'];
2001                 }
2002         }
2003         array_selector($name, $selected_id, $printers, 
2004                 array( 'select_submit'=> $submit_on_change,
2005                         'spec_option'=>$spec_opt,
2006                         'spec_id' => ''
2007                  ));
2008 }
2009
2010 //------------------------------------------------------------------------------------------------
2011
2012 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2013 {
2014         $where = false;
2015         $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2016         if ($type != null)
2017                 $sql .= " WHERE type=$type";
2018
2019         combo_input($name, $selected_id, $sql, 'id', 'description',
2020                 array(
2021                         'spec_id' => '',
2022                         'order' => 'description',
2023                         'select_submit'=> $submit_on_change,
2024                         'async' => false
2025                 ) );
2026
2027 }
2028
2029 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2030 {
2031         echo "<td>$label</td><td>\n";
2032         quick_entries_list($name, $selected_id, $type, $submit_on_change);
2033         echo "</td>";
2034 }
2035
2036 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2037 {
2038         echo "<tr>\n";
2039         quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2040         echo "</tr>\n";
2041 }
2042
2043
2044 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2045 {
2046         global $quick_actions;
2047         
2048         echo "<tr><td>$label</td><td>";
2049         array_selector($name, $selected_id, $quick_actions, 
2050                 array( 
2051                         'select_submit'=> $submit_on_change
2052                 ) );
2053         echo "</td></tr>\n";
2054 }
2055
2056 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2057 {
2058         global $quick_entry_types;
2059                 
2060         echo "<tr><td>$label</td><td>";
2061         array_selector($name, $selected_id, $quick_entry_types, 
2062                 array( 
2063                         'select_submit'=> $submit_on_change
2064                         ) );
2065         echo "</td></tr>\n";
2066 }
2067
2068 function record_status_list_row($label, $name) {
2069         return yesno_list_row($label, $name, null,      _('Inactive'), _('Active'));
2070 }
2071
2072 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2073 {
2074         global $class_types;
2075         
2076         echo "<tr><td>$label</td><td>";
2077         array_selector($name, $selected_id, $class_types, 
2078                 array( 
2079                         'select_submit'=> $submit_on_change
2080                 ) );
2081         echo "</td></tr>\n";
2082 }
2083
2084 //------------------------------------------------------------------------------------------------
2085
2086 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2087         $show_inactive = false)
2088 {
2089         global $all_items;
2090
2091         $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2092
2093 return combo_input($name, $selected_id, $sql, 'id', 'description',
2094         array(
2095                 'spec_option'=>$new_item ? _("New role") : false,
2096                 'spec_id' => '',
2097                 'select_submit'=> $submit_on_change,
2098                 'show_inactive' => $show_inactive
2099         ) );
2100 }
2101
2102 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2103         $show_inactive = false)
2104 {
2105         if ($label != null)
2106                 echo "<td>$label</td>\n";
2107         echo "<td>";
2108         $str = security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2109         echo "</td>\n";
2110         return $str;
2111 }
2112
2113 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2114         $show_inactive = false)
2115 {
2116         echo "<tr>";
2117         $str = security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2118         echo "</tr>\n";
2119         return $str;
2120 }
2121
2122 function tab_list_row($label, $name, $selected_id=null)
2123 {
2124         global $tabs;
2125         echo "<tr>\n";
2126         echo "<td>$label</td><td>\n";
2127
2128         $items = array();
2129
2130         array_selector($name, $selected_id, $tabs);
2131
2132         echo "</td></tr>\n";
2133 }
2134
2135 //---------------------------------------------------------------------------------------------
2136 //      List of sets of active extensions 
2137 //
2138 function extset_list($name, $value=null, $submit_on_change=false)
2139 {
2140         global $db_connections;
2141
2142         $items = array();
2143         foreach ($db_connections as $comp)
2144                 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2145         array_selector( $name, $value, $items,
2146                 array(
2147                         'spec_option'=> _("Installed on system"),
2148                         'spec_id' => -1,
2149                         'select_submit'=> $submit_on_change,
2150                         'async' => true
2151                 ));
2152 }
2153
2154 ?>