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