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