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