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