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