Asynchronous customer/supplier/item selection now use popup window.
[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']===true ? '_'.$name.'_update' : $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[$select_submit])) {
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                         $select_submit)."\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']===true ? '_'.$name.'_update' : $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[$select_submit])) {
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                         $select_submit)."\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)
366 {
367         global $all_items;
368
369         $sql = "SELECT supplier_id, supp_name, curr_code, inactive FROM ".TB_PREF."suppliers ";
370
371         $mode = get_company_pref('no_supplier_list');
372
373         return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
374         array(
375                 'format' => '_format_add_curr',
376                 'search_box' => $mode!=0,
377                 'type' => 1,
378                 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
379                 'spec_id' => $all_items,
380                 'select_submit'=> $submit_on_change,
381                 'async' => false,
382                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
383                 _('Select supplier'),
384                 'show_inactive'=>$all
385                 ));
386 }
387
388 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, 
389         $submit_on_change=false, $all=false)
390 {
391         if ($label != null)
392                 echo "<td>$label</td><td>\n";
393         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change, $all);
394                 echo "</td>\n";
395         return $str;
396 }
397
398 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
399 {
400 echo "<tr><td>$label</td><td>";
401         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
402 echo "</td></tr>\n";
403 return $str;
404 }
405 //----------------------------------------------------------------------------------------------
406
407 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, $show_inactive=false)
408 {
409         global $all_items;
410
411         $sql = "SELECT debtor_no, name, curr_code, inactive FROM ".TB_PREF."debtors_master ";
412
413         $mode = get_company_pref('no_customer_list');
414
415 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
416         array(
417             'format' => '_format_add_curr',
418                 'search_box' => $mode!=0,
419                 'type' => 1,
420                 'size' => 20,
421                 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
422                 'spec_id' => $all_items,
423                 'select_submit'=> $submit_on_change,
424                 'async' => false,
425                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
426                 _('Select customer'),
427                 'show_inactive' => $show_inactive
428         ) );
429 }
430
431 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, 
432         $submit_on_change=false, $show_inactive=false)
433 {
434         if ($label != null)
435                 echo "<td>$label</td>\n";
436         echo "<td nowrap>";
437         $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
438                 $show_inactive);
439         echo "</td>\n";
440         return $str;
441 }
442
443 function customer_list_row($label, $name, $selected_id=null, $all_option = false, 
444         $submit_on_change=false, $show_inactive=false)
445 {
446         echo "<tr><td>$label</td><td nowrap>";
447         $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
448                 $show_inactive);
449         echo "</td>\n</tr>\n";
450         return $str;
451 }
452
453 //------------------------------------------------------------------------------------------------
454
455 function customer_branches_list($customer_id, $name, $selected_id=null,
456         $spec_option = true, $enabled=true, $submit_on_change=false)
457 {
458         global $all_items;
459
460         $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
461                 WHERE debtor_no='" . $customer_id . "' ";
462
463         $where = $enabled ? array("disable_trans = 0") : array();
464 return  combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
465         array(
466                 'where' => $where,
467                 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
468                 'spec_id' => $all_items,
469                 'select_submit'=> $submit_on_change,
470                 'sel_hint' => _('Select customer branch')
471         ) );
472 }
473 //------------------------------------------------------------------------------------------------
474
475 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
476 {
477         if ($label != null)
478                 echo "<td>$label</td>\n";
479         echo "<td>";
480         $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
481         echo "</td>\n";
482         return $ret;
483 }
484
485 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
486 {
487         echo "<tr>";
488         $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
489         echo "</tr>";
490         return $ret;
491 }
492
493 //------------------------------------------------------------------------------------------------
494
495 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
496 {
497         global $all_items;
498
499         $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
500
501 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
502         array(
503                 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
504                 'spec_id' => $all_items,
505                 'select_submit'=> $submit_on_change
506         ) );
507 }
508
509 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
510 {
511         if ($label != null)
512                 echo "<td>$label</td>\n";
513         echo "<td>";
514         $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
515         echo "</td>\n";
516         return $str;
517 }
518
519 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
520 {
521         echo "<tr>";
522         $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
523         echo "</tr>\n";
524         return $str;
525 }
526
527 //-----------------------------------------------------------------------------------------------
528
529 function currencies_list($name, $selected_id=null, $submit_on_change=false)
530 {
531         $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
532
533 // default to the company currency
534
535 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
536         array(
537                 'select_submit'=> $submit_on_change,
538                 'default' => get_company_currency(),
539                 'async' => false                
540         ) );
541 }
542
543 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
544 {
545         if ($label != null)
546                 echo "<td>$label</td>\n";
547         echo "<td>";
548         $str = currencies_list($name, $selected_id, $submit_on_change);
549         echo "</td>\n";
550         return $str;
551 }
552
553 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
554 {
555         echo "<tr>\n";
556         $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
557         echo "</tr>\n";
558         return $str;
559 }
560
561 //---------------------------------------------------------------------------------------------------
562
563 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
564 {
565
566         $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
567
568 // default to the company current fiscal year
569
570 return combo_input($name, $selected_id, $sql, 'id', '',
571         array(
572                 'order' => 'begin',
573                 'default' => get_company_pref('f_year'),
574                 'format' => '_format_fiscalyears',
575                 'select_submit'=> $submit_on_change,
576                 'async' => false
577         ) );
578 }
579
580 function _format_fiscalyears($row)
581 {
582         return sql2date($row[1]) . "&nbsp;-&nbsp;" . sql2date($row[2])
583         . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
584 }
585
586 function fiscalyears_list_cells($label, $name, $selected_id=null)
587 {
588         if ($label != null)
589                 echo "<td>$label</td>\n";
590         echo "<td>";
591         $str = fiscalyears_list($name, $selected_id);
592         echo "</td>\n";
593         return $str;
594 }
595
596 function fiscalyears_list_row($label, $name, $selected_id=null)
597 {
598         echo "<tr>\n";
599         $str = fiscalyears_list_cells($label, $name, $selected_id);
600         echo "</tr>\n";
601         return $str;
602 }
603 //------------------------------------------------------------------------------------
604
605 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
606         $submit_on_change=false, $showclosed=false, $showtype=1)
607 {
608 $sql = "SELECT id, CONCAT(reference,'  ',name) as ref FROM ".TB_PREF."dimensions";
609
610 $options = array(
611         'order' => 'reference',
612         'spec_option'=>$no_option ? $showname : false,
613         'spec_id' => 0,
614         'select_submit'=> $submit_on_change,
615         'async' => false,
616         );
617
618         if (!$showclosed)
619                 $options['where'][] = "closed=0";
620         if($showtype)
621                 $options['where'][] = "type_=$showtype";
622
623         return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
624 }
625
626 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
627         $showclosed=false, $showtype=0, $submit_on_change=false)
628 {
629         if ($label != null)
630                 echo "<td>$label</td>\n";
631         echo "<td>";
632         $str = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
633         echo "</td>\n";
634         return $str;
635 }
636
637 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
638         $showclosed=false, $showtype=0, $submit_on_change=false)
639 {
640         echo "<tr>\n";
641         $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
642                 $showclosed, $showtype, $submit_on_change);
643         echo "</tr>\n";
644         return $str;
645 }
646
647 //---------------------------------------------------------------------------------------------------
648
649 function stock_items_list($name, $selected_id=null, $all_option=false, 
650         $submit_on_change=false, $opts=array())
651 {
652         global $all_items;
653
654         $sql = "SELECT stock_id, s.description, c.description, s.inactive
655                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
656
657         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
658         array_merge(
659           array(
660                 'format' => '_format_stock_items',
661                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
662                 'spec_id' => $all_items,
663                 'search_box' => true,
664                 'search' => array("stock_id", "c.description","s.description"),
665                 'search_submit' => get_company_pref('no_item_list')!=0,
666                 'size'=>10,
667                 'select_submit'=> $submit_on_change,
668                 'category' => 2,
669                 'order' => array('c.description','stock_id')
670           ), $opts) );
671 }
672
673 function _format_stock_items($row)
674 {
675         return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "") . $row[1];
676 }
677
678 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, 
679         $submit_on_change=false, $all=false)
680 {
681         if ($label != null)
682                 echo "<td>$label</td>\n";
683         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
684                 array('cells'=>true, 'show_inactive'=>$all));
685         return $str;
686 }
687 /*
688 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
689 {
690         echo "<tr>\n";
691         $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
692         echo "</tr>\n";
693         return $str;
694 }
695 */
696 //---------------------------------------------------------------------------------------------------
697 //
698 // Select item via foreign code.
699 //
700 function sales_items_list($name, $selected_id=null, $all_option=false, 
701         $submit_on_change=false, $type='', $opts=array())
702 {
703         global $all_items;
704         // all sales codes
705         $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
706                          i.inactive
707                         FROM
708                         ".TB_PREF."stock_master s,
709                         ".TB_PREF."item_codes i
710                         LEFT JOIN
711                         ".TB_PREF."stock_category c
712                         ON i.category_id=c.category_id
713                         WHERE i.stock_id=s.stock_id";
714
715         
716         if ($type == 'local')   { // exclude foreign codes
717                 $sql .= " AND !i.is_foreign"; 
718         } elseif ($type == 'kits') { // sales kits
719                 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
720         }
721         $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
722         $sql .= " GROUP BY i.item_code";
723
724         return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
725         array_merge(
726           array(
727                 'format' => '_format_stock_items',
728                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
729                 'spec_id' => $all_items,
730                 'search_box' => true,
731                 'search' => array("i.item_code", "i.description"),
732                 'search_submit' => get_company_pref('no_item_list')!=0,
733                 'size'=>15,
734                 'select_submit'=> $submit_on_change,
735                 'category' => 2,
736                 'order' => array('c.description','i.item_code')
737           ), $opts) );
738 }
739
740 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
741 {
742         if ($label != null)
743                 echo "<td>$label</td>\n";
744         $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
745                 '', array('cells'=>true));
746         return $str;
747 }
748
749 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
750 {
751         $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
752                 'kits', array('cells'=>false));
753         return $str;
754 }
755
756 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
757 {
758         echo "<tr>";
759         if ($label != null)
760                 echo "<td>$label</td>\n";
761         echo "<td>";
762         $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
763                 'local', array('cells'=>false));
764         echo "</td></tr>";
765         return $str;
766 }
767 //------------------------------------------------------------------------------------
768
769 function stock_manufactured_items_list($name, $selected_id=null,
770         $all_option=false, $submit_on_change=false)
771 {
772         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
773                 array('where'=>array("mb_flag= 'M'")));
774         return $str;            
775 }
776
777 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
778                                 $all_option=false, $submit_on_change=false)
779 {
780         if ($label != null)
781                 echo "<td>$label</td>\n";
782         echo "<td>";
783         $str = stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
784         echo "</td>\n";
785         return $str;
786 }
787
788 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
789                 $all_option=false, $submit_on_change=false)
790 {
791         echo "<tr>\n";
792         $str = stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
793         echo "</tr>\n";
794         return $str;
795 }
796 //------------------------------------------------------------------------------------
797
798 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
799         $all_option=false, $submit_on_change=false)
800 {
801         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
802                 array('where'=>array("stock_id != '$parent_stock_id'")));
803         return $str;
804 }
805
806 function stock_component_items_list_cells($label, $name, $parent_stock_id, 
807         $selected_id=null, $all_option=false, $submit_on_change=false)
808 {
809         if ($label != null)
810                 echo "<td>$label</td>\n";
811         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
812                 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
813         return $str;
814 }
815 //------------------------------------------------------------------------------------
816
817 function stock_costable_items_list($name, $selected_id=null,
818         $all_option=false, $submit_on_change=false)
819 {
820         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
821                 array('where'=>array("mb_flag!='D'")));
822         return $str;
823 }
824
825 function stock_costable_items_list_cells($label, $name, $selected_id=null, 
826         $all_option=false, $submit_on_change=false)
827 {
828         if ($label != null)
829                 echo "<td>$label</td>\n";
830         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
831                 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
832         return $str;
833 }
834
835 //------------------------------------------------------------------------------------
836 function stock_purchasable_items_list($name, $selected_id=null, 
837         $all_option=false, $submit_on_change=false, $all=false)
838 {
839         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
840                 array('where'=>array("mb_flag!= 'M'"), 
841                         'show_inactive'=>$all));
842         return $str;
843 }
844
845 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
846                         $all_option=false, $submit_on_change=false, $all=false)
847 {
848         if ($label != null)
849                 echo "<td>$label</td>\n";
850         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
851                 array('where'=>array("mb_flag!= 'M'"), 
852                          'cells'=>true));
853         return $str;
854 }
855
856 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
857                         $all_option=false, $submit_on_change=false)
858 {
859         echo "<tr>\n";
860         $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
861                 $all_option, $submit_on_change);
862         echo "</tr>\n";
863         return $ret;
864 }
865
866 //------------------------------------------------------------------------------------
867
868 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
869 {
870         global $stock_types;
871
872         echo "<tr>";
873         if ($label != null)
874                 echo "<td>$label</td>\n";
875         echo "<td>";
876
877         array_selector($name, $selected_id, $stock_types, 
878                 array( 
879                         'select_submit'=> true, 
880                         'disabled' => !$enabled) );
881         echo "</td></tr>\n";
882 }
883
884 function stock_units_list_row($label, $name, $value=null, $enabled=true)
885 {
886         $result = get_all_item_units();
887         echo "<tr>";
888         if ($label != null)
889                 echo "<td>$label</td>\n";
890         echo "<td>";
891
892         while($unit = db_fetch($result))
893                 $units[$unit['abbr']] = $unit['name'];
894
895         array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
896
897         echo "</td></tr>\n";
898 }
899
900 //------------------------------------------------------------------------------------
901
902 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
903 {
904         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
905
906         return combo_input($name, $selected_id, $sql, 'id', 'name',
907         array(
908                 'spec_option' => $none_option,
909                 'spec_id' => reserved_words::get_all_numeric(),
910                 'select_submit'=> $submit_on_change,
911                 'async' => false,
912         ) );
913 }
914
915 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
916         $submit_on_change=false)
917 {
918         if ($label != null)
919                 echo "<td>$label</td>\n";
920         echo "<td>";
921         $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
922         echo "</td>\n";
923         return $str;
924 }
925
926 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
927         $submit_on_change=false)
928 {
929         echo "<tr>\n";
930         $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
931         echo "</tr>\n";
932         return $str;
933 }
934
935 //------------------------------------------------------------------------------------
936
937 function tax_groups_list($name, $selected_id=null,
938         $none_option=false, $submit_on_change=false)
939 {
940         $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
941
942         return combo_input($name, $selected_id, $sql, 'id', 'name',
943         array(
944                 'order' => 'id',
945                 'spec_option' => $none_option,
946                 'spec_id' => reserved_words::get_all_numeric(),
947                 'select_submit'=> $submit_on_change,
948                 'async' => false,
949         ) );
950 }
951
952 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
953 {
954         if ($label != null)
955                 echo "<td>$label</td>\n";
956         echo "<td>";
957         $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
958         echo "</td>\n";
959         return $str;
960 }
961
962 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
963 {
964         echo "<tr>\n";
965         $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
966         echo "</tr>\n";
967         return $str;
968 }
969
970 //------------------------------------------------------------------------------------
971
972 function item_tax_types_list($name, $selected_id=null)
973 {
974         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
975         combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
976 }
977
978 function item_tax_types_list_cells($label, $name, $selected_id=null)
979 {
980         if ($label != null)
981                 echo "<td>$label</td>\n";
982         echo "<td>";
983         item_tax_types_list($name, $selected_id);
984         echo "</td>\n";
985 }
986
987 function item_tax_types_list_row($label, $name, $selected_id=null)
988 {
989         echo "<tr>\n";
990         item_tax_types_list_cells($label, $name, $selected_id);
991         echo "</tr>\n";
992 }
993
994 //------------------------------------------------------------------------------------
995
996 function shippers_list($name, $selected_id=null)
997 {
998         $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
999         combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
1000 }
1001
1002 function shippers_list_cells($label, $name, $selected_id=null)
1003 {
1004         if ($label != null)
1005                 echo "<td>$label</td>\n";
1006         echo "<td>";
1007         shippers_list($name, $selected_id);
1008         echo "</td>\n";
1009 }
1010
1011 function shippers_list_row($label, $name, $selected_id=null)
1012 {
1013         echo "<tr>\n";
1014         shippers_list_cells($label, $name, $selected_id);
1015         echo "</tr>\n";
1016 }
1017
1018 //-------------------------------------------------------------------------------------
1019
1020 function sales_persons_list($name, $selected_id=null)
1021 {
1022         $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1023         combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
1024 }
1025
1026 function sales_persons_list_cells($label, $name, $selected_id=null)
1027 {
1028         if ($label != null)
1029                 echo "<td>$label</td>\n";
1030         echo "<td>\n";
1031         sales_persons_list($name, $selected_id);
1032         echo "</td>\n";
1033 }
1034
1035 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1036 {
1037         echo "<tr>\n";
1038         sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1039         echo "</tr>\n";
1040 }
1041
1042 //------------------------------------------------------------------------------------
1043
1044 function sales_areas_list($name, $selected_id=null)
1045 {
1046         $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1047         combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1048 }
1049
1050 function sales_areas_list_cells($label, $name, $selected_id=null)
1051 {
1052         if ($label != null)
1053                 echo "<td>$label</td>\n";
1054         echo "<td>";
1055         sales_areas_list($name, $selected_id);
1056         echo "</td>\n";
1057 }
1058
1059 function sales_areas_list_row($label, $name, $selected_id=null)
1060 {
1061         echo "<tr>\n";
1062         sales_areas_list_cells($label, $name, $selected_id);
1063         echo "</tr>\n";
1064 }
1065
1066 //------------------------------------------------------------------------------------
1067
1068 function sales_groups_list($name, $selected_id=null, $special_option=false)
1069 {
1070         $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1071         combo_input($name, $selected_id, $sql, 'id', 'description', array(
1072                 'spec_option' => $special_option===true ? ' ' : $special_option,
1073                 'order' => 'description', 'spec_id' => 0,
1074         ));
1075 }
1076
1077 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1078 {
1079         if ($label != null)
1080                 echo "<td>$label</td>\n";
1081         echo "<td>";
1082         sales_groups_list($name, $selected_id, $special_option);
1083         echo "</td>\n";
1084 }
1085
1086 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1087 {
1088         echo "<tr>\n";
1089         sales_groups_list_cells($label, $name, $selected_id, $special_option);
1090         echo "</tr>\n";
1091 }
1092
1093 //------------------------------------------------------------------------------------
1094
1095 function _format_template_items($row)
1096 {
1097         return ($row[0] . "&nbsp;- &nbsp;" . _("Amount") . "&nbsp;".$row[1]);
1098 }
1099
1100 function templates_list($name, $selected_id=null, $special_option=false)
1101 {
1102         $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1103                 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1104                 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1105         combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1106                 'format' => '_format_template_items',
1107                 'spec_option' => $special_option===true ? ' ' : $special_option,
1108                 'order' => 'order_no', 'spec_id' => 0,
1109         ));
1110 }
1111
1112 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1113 {
1114         if ($label != null)
1115                 echo "<td>$label</td>\n";
1116         echo "<td>";
1117         templates_list($name, $selected_id, $special_option);
1118         echo "</td>\n";
1119 }
1120
1121 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1122 {
1123         echo "<tr>\n";
1124         templates_list_cells($label, $name, $selected_id, $special_option);
1125         echo "</tr>\n";
1126 }
1127
1128 //------------------------------------------------------------------------------------
1129
1130 function workorders_list($name, $selected_id=null)
1131 {
1132         $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1133         combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1134 }
1135
1136 function workorders_list_cells($label, $name, $selected_id=null)
1137 {
1138         if ($label != null)
1139                 echo "<td>$label</td>\n";
1140         echo "<td>";
1141         workorders_list($name, $selected_id);
1142         echo "</td>\n";
1143 }
1144
1145 function workorders_list_row($label, $name, $selected_id=null)
1146 {
1147         echo "<tr>\n";
1148         workorders_list_cells($label, $name, $selected_id);
1149         echo "</tr>\n";
1150 }
1151
1152 //------------------------------------------------------------------------------------
1153
1154 function payment_terms_list($name, $selected_id=null)
1155 {
1156         $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1157         combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1158 }
1159
1160 function payment_terms_list_cells($label, $name, $selected_id=null)
1161 {
1162         if ($label != null)
1163                 echo "<td>$label</td>\n";
1164         echo "<td>";
1165         payment_terms_list($name, $selected_id);
1166         echo "</td>\n";
1167 }
1168
1169 function payment_terms_list_row($label, $name, $selected_id=null)
1170 {
1171         echo "<tr>\n";
1172         payment_terms_list_cells($label, $name, $selected_id);
1173         echo "</tr>\n";
1174 }
1175
1176 //------------------------------------------------------------------------------------
1177
1178 function credit_status_list($name, $selected_id=null)
1179 {
1180         $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1181         combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1182 }
1183
1184 function credit_status_list_cells($label, $name, $selected_id=null)
1185 {
1186         if ($label != null)
1187                 echo "<td>$label</td>\n";
1188         echo "<td>";
1189         credit_status_list($name, $selected_id);
1190         echo "</td>\n";
1191 }
1192
1193 function credit_status_list_row($label, $name, $selected_id=null)
1194 {
1195         echo "<tr>\n";
1196         credit_status_list_cells($label, $name, $selected_id);
1197         echo "</tr>\n";
1198 }
1199
1200 //-----------------------------------------------------------------------------------------------
1201
1202 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1203 {
1204         $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1205
1206         return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1207         array(
1208                 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1209                 'spec_id' => 0,
1210                 'select_submit'=> $submit_on_change,
1211         //        'async' => false,
1212         ) );
1213 }
1214
1215 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1216 {
1217         if ($label != null)
1218                 echo "<td>$label</td>\n";
1219         echo "<td>";
1220         $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1221         echo "</td>\n";
1222         return $str;
1223 }
1224
1225 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1226 {
1227         echo "<tr>\n";
1228         $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1229         echo "</tr>\n";
1230         return $str;
1231 }
1232
1233 //-----------------------------------------------------------------------------------------------
1234
1235 function movement_types_list($name, $selected_id=null)
1236 {
1237         $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1238         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1239 }
1240
1241 function movement_types_list_cells($label, $name, $selected_id=null)
1242 {
1243         if ($label != null)
1244                 echo "<td>$label</td>\n";
1245         echo "<td>";
1246         movement_types_list($name, $selected_id);
1247         echo "</td>\n";
1248 }
1249
1250 function movement_types_list_row($label, $name, $selected_id=null)
1251 {
1252         echo "<tr>\n";
1253         movement_types_list_cells($label, $name, $selected_id);
1254         echo "</tr>\n";
1255 }
1256
1257 //-----------------------------------------------------------------------------------------------
1258 function _format_date($row)
1259 {
1260         return sql2date($row['reconciled']);
1261 }
1262
1263 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1264 {
1265         $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1266                 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1267                 GROUP BY reconciled";
1268         combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1269         array(
1270                 'spec_option' => $special_option,
1271                 'format' => '_format_date',
1272                 'spec_id' => '',
1273                 'select_submit'=> $submit_on_change
1274         ) );
1275 }
1276
1277 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1278 {
1279         if ($label != null)
1280                 echo "<td>$label</td>\n";
1281         echo "<td>";
1282         bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1283         echo "</td>\n";
1284 }
1285 /*
1286 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1287 {
1288         echo "<tr>\n";
1289         bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1290         echo "</tr>\n";
1291 }
1292 */
1293 //-----------------------------------------------------------------------------------------------
1294
1295 function workcenter_list($name, $selected_id=null, $all_option=false)
1296 {
1297         global $all_items;
1298
1299         $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1300
1301         return combo_input($name, $selected_id, $sql, 'id', 'name',
1302         array(
1303                 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1304                 'spec_id' => $all_items,
1305         ) );
1306 }
1307
1308 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1309 {
1310         default_focus($name);
1311         if ($label != null)
1312                 echo "<td>$label</td>\n";
1313         echo "<td>";
1314         workcenter_list($name, $selected_id, $all_option);
1315         echo "</td>\n";
1316 }
1317
1318 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1319 {
1320         echo "<tr>\n";
1321         workcenter_list_cells($label, $name, $selected_id, $all_option);
1322         echo "</tr>\n";
1323 }
1324
1325 //-----------------------------------------------------------------------------------------------
1326
1327 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1328 {
1329         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1330                 FROM ".TB_PREF."bank_accounts";
1331 //              , ".TB_PREF."chart_master
1332 //              WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1333
1334         return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1335         array(
1336                 'format' => '_format_add_curr',
1337                 'select_submit'=> $submit_on_change,
1338                 'async' => false
1339         ) );
1340 }
1341
1342 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1343 {
1344         if ($label != null)
1345                 echo "<td>$label</td>\n";
1346         echo "<td>";
1347         $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1348         echo "</td>\n";
1349         return $str;
1350 }
1351
1352 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1353 {
1354         echo "<tr>\n";
1355         $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1356         echo "</tr>\n";
1357         return $str;
1358 }
1359 //-----------------------------------------------------------------------------------------------
1360
1361 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1362 {
1363         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1364                 FROM ".TB_PREF."bank_accounts
1365                 WHERE ".TB_PREF."bank_accounts.account_type=3";
1366
1367         if ($label != null)
1368                 echo "<tr><td>$label</td>\n";
1369         echo "<td>";
1370         $str = combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1371         array(
1372                 'format' => '_format_add_curr',
1373                 'select_submit'=> $submit_on_change,
1374                 'async' => true
1375         ) );
1376         echo "</td></tr>\n";
1377         return $str;
1378 }
1379 //-----------------------------------------------------------------------------------------------
1380
1381 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1382 {
1383         $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1384
1385         default_focus($name);
1386         echo '<tr>';
1387         if ($label != null)
1388                 echo "<td>$label</td>\n";
1389         echo "<td>";
1390
1391         $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1392         array(
1393                 'select_submit'=> $submit_on_change,
1394                 'async' => true,
1395                 'spec_option' =>$spec_option,
1396                 'spec_id' => -1,
1397         ) );
1398         echo "</td></tr>\n";
1399
1400         return $str;    
1401 }
1402 //-----------------------------------------------------------------------------------------------
1403
1404 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1405 {
1406         if ($label != null)
1407                 echo "<td>$label</td>\n";
1408         echo "<td>";
1409         $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1410         echo "</td>\n";
1411         return $str;
1412 }
1413 //-----------------------------------------------------------------------------------------------
1414
1415 function class_list($name, $selected_id=null, $submit_on_change=false)
1416 {
1417         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1418
1419         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1420         array(
1421                 'select_submit'=> $submit_on_change,
1422                 'async' => false
1423         ) );
1424
1425 }
1426
1427 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1428 {
1429         if ($label != null)
1430                 echo "<td>$label</td>\n";
1431         echo "<td>";
1432         $str = class_list($name, $selected_id, $submit_on_change);
1433         echo "</td>\n";
1434         return $str;
1435 }
1436
1437 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1438 {
1439         echo "<tr>\n";
1440         $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1441         echo "</tr>\n";
1442         return $str;
1443 }
1444
1445 //-----------------------------------------------------------------------------------------------
1446
1447 function stock_categories_list($name, $selected_id=null, $submit_on_change=false)
1448 {
1449         $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1450         combo_input($name, $selected_id, $sql, 'category_id', 'description',
1451         array('order'=>'category_id',
1452                 'select_submit'=> $submit_on_change,
1453                 'async' => true
1454         ));
1455 }
1456
1457 function stock_categories_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1458 {
1459         if ($label != null)
1460                 echo "<td>$label</td>\n";
1461         echo "<td>";
1462         stock_categories_list($name, $selected_id, $submit_on_change);
1463         echo "</td>\n";
1464 }
1465
1466 function stock_categories_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1467 {
1468         echo "<tr>\n";
1469         stock_categories_list_cells($label, $name, $selected_id, $submit_on_change);
1470         echo "</tr>\n";
1471 }
1472
1473 //-----------------------------------------------------------------------------------------------
1474
1475 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1476 {
1477         global $all_items;
1478
1479         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1480
1481         combo_input($name, $selected_id, $sql, 'id', 'name',
1482         array(
1483                 'order' => 'id',
1484                 'spec_option' =>$all_option,
1485                 'spec_id' => $all_option_numeric ? 0 : $all_items
1486         ) );
1487 }
1488
1489 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1490         $all_option_numeric=false)
1491 {
1492         if ($label != null)
1493                 echo "<td>$label</td>\n";
1494         echo "<td>";
1495         gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1496         echo "</td>\n";
1497 }
1498
1499 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1500         $all_option_numeric=false)
1501 {
1502         echo "<tr>\n";
1503         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1504                 $all_option_numeric);
1505         echo "</tr>\n";
1506 }
1507
1508 //-----------------------------------------------------------------------------------------------
1509 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1510         $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1511 {
1512         if ($skip_bank_accounts)
1513                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive
1514                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1515                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1516                         ."ON chart.account_code=acc.account_code
1517                                 WHERE acc.account_code  IS NULL
1518                         AND chart.account_type=type.id";
1519         else
1520                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive
1521                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1522                         WHERE chart.account_type=type.id";
1523
1524         combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1525         array(
1526                 'format' => '_format_account',
1527                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1528                 'spec_id' => '',
1529                 'order' => array('name','account_code'),
1530                 'search_box' => $cells,
1531                         'search_submit' => false,
1532                         'size' => 12,
1533                         'max' => 10,
1534                         'cells' => true,
1535                 'select_submit'=> $submit_on_change,
1536                 'async' => false,
1537                 'category' => 2,
1538                 'show_inactive' => $all
1539         ) );
1540
1541 }
1542
1543 function _format_account($row)
1544 {
1545                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1546 }
1547
1548 function gl_all_accounts_list_cells($label, $name, $selected_id=null, 
1549         $skip_bank_accounts=false, $cells=false, $all_option=false, 
1550         $submit_on_change=false, $all=false)
1551 {
1552         if ($label != null)
1553                 echo "<td>$label</td>\n";
1554         echo "<td>";
1555         gl_all_accounts_list($name, $selected_id, 
1556                 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1557         echo "</td>\n";
1558 }
1559
1560 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
1561         $skip_bank_accounts=false, $cells=false, $all_option=false)
1562 {
1563         echo "<tr>\n";
1564         gl_all_accounts_list_cells($label, $name, $selected_id, 
1565                 $skip_bank_accounts, $cells, $all_option);
1566         echo "</tr>\n";
1567 }
1568
1569 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1570 {
1571         $items = array();
1572         $items['0'] = strlen($name_no) ? $name_no : _("No");
1573         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1574
1575         return array_selector($name, $selected_id, $items, 
1576                 array( 
1577                         'select_submit'=> $submit_on_change,
1578                         'async' => false ) ); // FIX?
1579 }
1580
1581 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1582 {
1583         if ($label != null)
1584                 echo "<td>$label</td>\n";
1585         echo "<td>";
1586         $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1587         echo "</td>\n";
1588         return $str;
1589 }
1590
1591 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1592 {
1593         echo "<tr>\n";
1594         $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1595         echo "</tr>\n";
1596         return $str;
1597 }
1598
1599 //------------------------------------------------------------------------------------------------
1600
1601 function languages_list($name, $selected_id=null)
1602 {
1603         global $installed_languages;
1604
1605         $items = array();
1606         foreach ($installed_languages as $lang)
1607                         $items[$lang['code']] = $lang['name'];
1608         
1609         return array_selector($name, $selected_id, $items );
1610 }
1611
1612 function languages_list_cells($label, $name, $selected_id=null)
1613 {
1614         if ($label != null)
1615                 echo "<td>$label</td>\n";
1616         echo "<td>";
1617         languages_list($name, $selected_id);
1618         echo "</td>\n";
1619 }
1620
1621 function languages_list_row($label, $name, $selected_id=null)
1622 {
1623         echo "<tr>\n";
1624         languages_list_cells($label, $name, $selected_id);
1625         echo "</tr>\n";
1626 }
1627
1628 //------------------------------------------------------------------------------------------------
1629
1630 function bank_account_types_list($name, $selected_id=null)
1631 {
1632         $types = bank_account_types::get_all();
1633
1634         $items = array();
1635         foreach ($types as $type)
1636         {
1637                         $items[$type['id']] = $type['name'];
1638         }
1639         
1640         return array_selector($name, $selected_id, $items );
1641 }
1642
1643 function bank_account_types_list_cells($label, $name, $selected_id=null)
1644 {
1645         if ($label != null)
1646                 echo "<td>$label</td>\n";
1647         echo "<td>";
1648         bank_account_types_list($name, $selected_id);
1649         echo "</td>\n";
1650 }
1651
1652 function bank_account_types_list_row($label, $name, $selected_id=null)
1653 {
1654         echo "<tr>\n";
1655         bank_account_types_list_cells($label, $name, $selected_id);
1656         echo "</tr>\n";
1657 }
1658
1659 //------------------------------------------------------------------------------------------------
1660 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1661 {
1662         $types = payment_person_types::get_all();
1663
1664         $items = array();
1665         foreach ($types as $type)
1666         {
1667                 if (payment_person_types::has_items($type['id']))
1668                 {
1669                         if ($type['id'] != payment_person_types::WorkOrder())
1670                                 $items[$type['id']] = $type['name'];
1671                 }
1672         }
1673         
1674         return array_selector($name, $selected_id, $items, 
1675                 array( 'select_submit'=> $submit_on_change ) );
1676 }
1677
1678 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1679 {
1680         if ($label != null)
1681                 echo "<td>$label</td>\n";
1682         echo "<td>";
1683         $str = payment_person_types_list($name, $selected_id, $related);
1684         echo "</td>\n";
1685         return $str;
1686 }
1687
1688 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1689 {
1690         echo "<tr>\n";
1691         $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1692         echo "</tr>\n";
1693         return $str;
1694 }
1695
1696 //------------------------------------------------------------------------------------------------
1697
1698 function wo_types_list($name, $selected_id=null)
1699 {
1700         $types = wo_types::get_all();
1701
1702         $items = array();
1703         foreach ($types as $type)
1704                 $items[$type['id']] = $type['name'];
1705         
1706         return array_selector($name, $selected_id, $items, 
1707                 array( 'select_submit'=> true, 'async' => true ) );
1708 }
1709
1710 function wo_types_list_row($label, $name, $selected_id=null)
1711 {
1712         echo "<tr><td>$label</td><td>\n";
1713         $str = wo_types_list($name, $selected_id);
1714         echo "</td></tr>\n";
1715         return $str;
1716 }
1717
1718 //------------------------------------------------------------------------------------------------
1719
1720 function dateformats_list_row($label, $name, $value=null)
1721 {
1722         global $dateformats;
1723
1724         echo "<tr><td>$label</td>\n<td>";
1725         array_selector( $name, $value, $dateformats );
1726         echo "</td></tr>\n";
1727 }
1728
1729 function dateseps_list_row($label, $name, $value=null)
1730 {
1731         global $dateseps;
1732
1733         echo "<tr><td>$label</td>\n<td>";
1734         array_selector( $name, $value, $dateseps );
1735         echo "</td></tr>\n";
1736 }
1737
1738 function thoseps_list_row($label, $name, $value=null)
1739 {
1740         global $thoseps;
1741
1742         echo "<tr><td>$label</td>\n<td>";
1743         array_selector( $name, $value, $thoseps );
1744         echo "</td></tr>\n";
1745 }
1746
1747 function decseps_list_row($label, $name, $value=null)
1748 {
1749         global $decseps;
1750
1751         echo "<tr><td>$label</td>\n<td>";
1752         array_selector( $name, $value, $decseps );
1753         echo "</td></tr>\n";
1754 }
1755
1756 function themes_list_row($label, $name, $value=null)
1757 {
1758         global $path_to_root;
1759
1760         $path = $path_to_root.'/themes/';
1761         $themes = array();
1762         $themedir = opendir($path);
1763         while(false !== ($fname = readdir($themedir)))
1764         {
1765                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1766                 {
1767                         $themes[$fname] =  $fname;
1768                 }
1769         }
1770         ksort($themes);
1771
1772         echo "<tr><td>$label</td>\n<td>";
1773         array_selector( $name, $value, $themes );
1774         echo "</td></tr>\n";
1775 }
1776
1777 function pagesizes_list_row($label, $name, $value=null)
1778 {
1779         global $pagesizes;
1780
1781         $items = array();
1782         foreach ($pagesizes as $pz)
1783                 $items[$pz] = $pz;
1784
1785         echo "<tr><td>$label</td>\n<td>";
1786         array_selector( $name, $value, $items );
1787         echo "</td></tr>\n";
1788 }
1789
1790 function security_headings_list_row($label, $name, $value=null)
1791 {
1792         global $security_headings;
1793
1794         echo "<tr><td>$label</td>\n<td>";
1795         array_selector( $name, $value, $security_headings );
1796         echo "</td></tr>\n";
1797 }
1798
1799 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1800 {
1801         global $systypes_array;
1802
1803         if ($label != null)
1804                 echo "<td>$label</td>\n";
1805         echo "<td>";
1806
1807         $items = array();
1808         foreach ($systypes_array as $key=>$type)
1809                         $items[$key] = $type['name'];
1810         
1811         $str = array_selector($name, $value, $items, 
1812                 array( 
1813                         'select_submit'=> $submit_on_change,
1814                         'async' => false
1815                         )
1816         );
1817         echo "</td>\n";
1818         return $str;
1819 }
1820
1821 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1822 {
1823         global $systypes_array;
1824
1825         if ($label != null)
1826                 echo "<td>$label</td>\n";
1827         echo "<td>";
1828
1829         $items = array();
1830         foreach ($systypes_array as $key=>$type)
1831                 // exclude orders and dimensions
1832                 if (!in_array($key, array(18,26,30,40)))
1833                         $items[$key] = $type['name'];
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' => reserved_words::get_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 ?>