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