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