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