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