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