62a7e22a0fb9168373241b1610fba38ee777e779
[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 (get_post($search_submit ? $search_submit : "_{$name}_button"))
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/input 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, s.editable
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 //      This helper is used in PO/GRN/PI entry and supports editable descriptions.
883 //
884 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
885                         $all_option=false, $submit_on_change=false, $editkey=false)
886 {
887         if ($label != null)
888                 echo "<td>$label</td>\n";
889         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
890                 array('where'=>array("mb_flag!= 'M'"), 
891                          'editable' => 30,
892                          'cells'=>true), $editkey);
893 }
894 /*
895 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
896                         $all_option=false, $submit_on_change=false, $editkey=false)
897 {
898         echo "<tr>\n";
899         stock_purchasable_items_list_cells($label, $name, $selected_id=null,
900                 $all_option, $submit_on_change, $editkey);
901         echo "</tr>\n";
902 }
903 */
904 //------------------------------------------------------------------------------------
905
906 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
907 {
908         global $stock_types;
909
910         echo "<tr>";
911         if ($label != null)
912                 echo "<td>$label</td>\n";
913         echo "<td>";
914
915         echo array_selector($name, $selected_id, $stock_types, 
916                 array( 
917                         'select_submit'=> true, 
918                         'disabled' => !$enabled) );
919         echo "</td></tr>\n";
920 }
921
922 function stock_units_list_row($label, $name, $value=null, $enabled=true)
923 {
924         $result = get_all_item_units();
925         echo "<tr>";
926         if ($label != null)
927                 echo "<td>$label</td>\n";
928         echo "<td>";
929
930         while($unit = db_fetch($result))
931                 $units[$unit['abbr']] = $unit['name'];
932
933         echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
934
935         echo "</td></tr>\n";
936 }
937
938 //------------------------------------------------------------------------------------
939
940 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
941 {
942         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
943
944         return combo_input($name, $selected_id, $sql, 'id', 'name',
945         array(
946                 'spec_option' => $none_option,
947                 'spec_id' => ALL_NUMERIC,
948                 'select_submit'=> $submit_on_change,
949                 'async' => false,
950         ) );
951 }
952
953 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
954         $submit_on_change=false)
955 {
956         if ($label != null)
957                 echo "<td>$label</td>\n";
958         echo "<td>";
959         echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
960         echo "</td>\n";
961 }
962
963 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
964         $submit_on_change=false)
965 {
966         echo "<tr>\n";
967         tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
968         echo "</tr>\n";
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         echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
994         echo "</td>\n";
995 }
996
997 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
998 {
999         echo "<tr>\n";
1000         tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
1001         echo "</tr>\n";
1002 }
1003
1004 //------------------------------------------------------------------------------------
1005
1006 function item_tax_types_list($name, $selected_id=null)
1007 {
1008         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1009         return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1010 }
1011
1012 function item_tax_types_list_cells($label, $name, $selected_id=null)
1013 {
1014         if ($label != null)
1015                 echo "<td>$label</td>\n";
1016         echo "<td>";
1017         echo item_tax_types_list($name, $selected_id);
1018         echo "</td>\n";
1019 }
1020
1021 function item_tax_types_list_row($label, $name, $selected_id=null)
1022 {
1023         echo "<tr>\n";
1024         item_tax_types_list_cells($label, $name, $selected_id);
1025         echo "</tr>\n";
1026 }
1027
1028 //------------------------------------------------------------------------------------
1029
1030 function shippers_list($name, $selected_id=null)
1031 {
1032         $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1033         return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', 
1034                 array('order'=>array('shipper_name')));
1035 }
1036
1037 function shippers_list_cells($label, $name, $selected_id=null)
1038 {
1039         if ($label != null)
1040                 echo "<td>$label</td>\n";
1041         echo "<td>";
1042         echo shippers_list($name, $selected_id);
1043         echo "</td>\n";
1044 }
1045
1046 function shippers_list_row($label, $name, $selected_id=null)
1047 {
1048         echo "<tr>\n";
1049         shippers_list_cells($label, $name, $selected_id);
1050         echo "</tr>\n";
1051 }
1052
1053 //-------------------------------------------------------------------------------------
1054
1055 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1056 {
1057         $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1058         return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', 
1059                 array('order'=>array('salesman_name'),
1060                         'spec_option' => $spec_opt,
1061                         'spec_id' => ALL_NUMERIC));
1062 }
1063
1064 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1065 {
1066         if ($label != null)
1067                 echo "<td>$label</td>\n";
1068         echo "<td>\n";
1069         echo sales_persons_list($name, $selected_id, $spec_opt);
1070         echo "</td>\n";
1071 }
1072
1073 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1074 {
1075         echo "<tr>\n";
1076         sales_persons_list_cells($label, $name, $selected_id, $spec_opt);
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         return 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         echo 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         return 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         echo 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         return 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         echo 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         return 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         echo 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         return 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         echo 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         return 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         echo 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         echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1259         echo "</td>\n";
1260 }
1261
1262 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1263 {
1264         echo "<tr>\n";
1265         sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1266         echo "</tr>\n";
1267 }
1268
1269 //-----------------------------------------------------------------------------------------------
1270
1271 function movement_types_list($name, $selected_id=null)
1272 {
1273         $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1274         return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1275 }
1276
1277 function movement_types_list_cells($label, $name, $selected_id=null)
1278 {
1279         if ($label != null)
1280                 echo "<td>$label</td>\n";
1281         echo "<td>";
1282         echo movement_types_list($name, $selected_id);
1283         echo "</td>\n";
1284 }
1285
1286 function movement_types_list_row($label, $name, $selected_id=null)
1287 {
1288         echo "<tr>\n";
1289         movement_types_list_cells($label, $name, $selected_id);
1290         echo "</tr>\n";
1291 }
1292
1293 //-----------------------------------------------------------------------------------------------
1294 function _format_date($row)
1295 {
1296         return sql2date($row['reconciled']);
1297 }
1298
1299 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1300 {
1301         $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1302                 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1303                 GROUP BY reconciled";
1304         return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1305         array(
1306                 'spec_option' => $special_option,
1307                 'format' => '_format_date',
1308                 'spec_id' => '',
1309                 'select_submit'=> $submit_on_change
1310         ) );
1311 }
1312
1313 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1314 {
1315         if ($label != null)
1316                 echo "<td>$label</td>\n";
1317         echo "<td>";
1318         echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1319         echo "</td>\n";
1320 }
1321 /*
1322 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1323 {
1324         echo "<tr>\n";
1325         bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1326         echo "</tr>\n";
1327 }
1328 */
1329 //-----------------------------------------------------------------------------------------------
1330
1331 function workcenter_list($name, $selected_id=null, $all_option=false)
1332 {
1333         global $all_items;
1334
1335         $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1336
1337         return combo_input($name, $selected_id, $sql, 'id', 'name',
1338         array(
1339                 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1340                 'spec_id' => $all_items,
1341         ) );
1342 }
1343
1344 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1345 {
1346         default_focus($name);
1347         if ($label != null)
1348                 echo "<td>$label</td>\n";
1349         echo "<td>";
1350         echo workcenter_list($name, $selected_id, $all_option);
1351         echo "</td>\n";
1352 }
1353
1354 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1355 {
1356         echo "<tr>\n";
1357         workcenter_list_cells($label, $name, $selected_id, $all_option);
1358         echo "</tr>\n";
1359 }
1360
1361 //-----------------------------------------------------------------------------------------------
1362
1363 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1364 {
1365         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1366                 FROM ".TB_PREF."bank_accounts";
1367
1368         return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1369         array(
1370                 'format' => '_format_add_curr',
1371                 'select_submit'=> $submit_on_change,
1372                 'async' => false
1373         ) );
1374 }
1375
1376 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1377 {
1378         if ($label != null)
1379                 echo "<td>$label</td>\n";
1380         echo "<td>";
1381         echo bank_accounts_list($name, $selected_id, $submit_on_change);
1382         echo "</td>\n";
1383 }
1384
1385 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1386 {
1387         echo "<tr>\n";
1388         bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1389         echo "</tr>\n";
1390 }
1391 //-----------------------------------------------------------------------------------------------
1392
1393 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1394 {
1395         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1396                 FROM ".TB_PREF."bank_accounts
1397                 WHERE ".TB_PREF."bank_accounts.account_type=3";
1398
1399         if ($label != null)
1400                 echo "<tr><td>$label</td>\n";
1401         echo "<td>";
1402         echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1403         array(
1404                 'format' => '_format_add_curr',
1405                 'select_submit'=> $submit_on_change,
1406                 'async' => true
1407         ) );
1408         echo "</td></tr>\n";
1409 }
1410 //-----------------------------------------------------------------------------------------------
1411
1412 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1413 {
1414         $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1415
1416         default_focus($name);
1417         echo '<tr>';
1418         if ($label != null)
1419                 echo "<td>$label</td>\n";
1420         echo "<td>";
1421
1422         echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1423         array(
1424                 'select_submit'=> $submit_on_change,
1425                 'async' => true,
1426                 'spec_option' =>$spec_option,
1427                 'spec_id' => -1,
1428                 'order'=> array('pos_name')
1429         ) );
1430         echo "</td></tr>\n";
1431
1432 }
1433 //-----------------------------------------------------------------------------------------------
1434 // Payment type selector for current user.
1435 //
1436 function sale_payment_list($name, $selected_id=null, $submit_on_change=true)
1437 {
1438         $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1439         $paym = get_sales_point(user_pos());
1440
1441         if (!$paym['cash_sale'] || !$paym['credit_sale']) {
1442                 if ($paym['cash_sale']) // only cash
1443                         $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1444                 else
1445                         $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
1446         }
1447
1448         return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1449         array(
1450                 'select_submit'=> $submit_on_change,
1451                 'async' => true
1452         ) );
1453
1454 }
1455
1456 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=true)
1457 {
1458         if ($label != null)
1459                 echo "<td>$label</td>\n";
1460         echo "<td>";
1461
1462         echo sale_payment_list($name, $selected_id, $submit_on_change);
1463
1464         echo "</td>\n";
1465 }
1466 //-----------------------------------------------------------------------------------------------
1467
1468 function class_list($name, $selected_id=null, $submit_on_change=false)
1469 {
1470         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1471
1472         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1473         array(
1474                 'select_submit'=> $submit_on_change,
1475                 'async' => false
1476         ) );
1477
1478 }
1479
1480 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1481 {
1482         if ($label != null)
1483                 echo "<td>$label</td>\n";
1484         echo "<td>";
1485         echo class_list($name, $selected_id, $submit_on_change);
1486         echo "</td>\n";
1487 }
1488
1489 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1490 {
1491         echo "<tr>\n";
1492         class_list_cells($label, $name, $selected_id, $submit_on_change);
1493         echo "</tr>\n";
1494 }
1495
1496 //-----------------------------------------------------------------------------------------------
1497 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1498 {
1499         $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1500         return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1501         array('order'=>'category_id',
1502                 'spec_option' => $spec_opt,
1503                 'spec_id' => -1,
1504                 'select_submit'=> $submit_on_change,
1505                 'async' => true
1506         ));
1507 }
1508
1509 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1510 {
1511         if ($label != null)
1512                 echo "<td>$label</td>\n";
1513         echo "<td>";
1514         echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1515         echo "</td>\n";
1516 }
1517
1518 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1519 {
1520         echo "<tr>\n";
1521         stock_categories_list_cells($label, $name, $selected_id, $spec_opt, $submit_on_change);
1522         echo "</tr>\n";
1523 }
1524
1525 //-----------------------------------------------------------------------------------------------
1526
1527 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all_option_numeric=true)
1528 {
1529         global $all_items;
1530
1531         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1532
1533         return combo_input($name, $selected_id, $sql, 'id', 'name',
1534         array(
1535                 'order' => 'class_id', 'id',
1536                 'spec_option' =>$all_option,
1537                 'spec_id' => $all_option_numeric ? 0 : $all_items
1538         ) );
1539 }
1540
1541 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1542         $all_option_numeric=false)
1543 {
1544         if ($label != null)
1545                 echo "<td>$label</td>\n";
1546         echo "<td>";
1547         echo gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1548         echo "</td>\n";
1549 }
1550
1551 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1552         $all_option_numeric=false)
1553 {
1554         echo "<tr>\n";
1555         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1556                 $all_option_numeric);
1557         echo "</tr>\n";
1558 }
1559
1560 //-----------------------------------------------------------------------------------------------
1561 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1562         $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1563 {
1564         if ($skip_bank_accounts)
1565                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1566                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1567                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1568                         ."ON chart.account_code=acc.account_code
1569                                 WHERE acc.account_code  IS NULL
1570                         AND chart.account_type=type.id";
1571         else
1572                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1573                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1574                         WHERE chart.account_type=type.id";
1575
1576         return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1577         array(
1578                 'format' => '_format_account',
1579                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1580                 'spec_id' => '',
1581                 'order' => array('type.class_id','type.id','account_code'),
1582                 'search_box' => $cells,
1583                         'search_submit' => false,
1584                         'size' => 12,
1585                         'max' => 10,
1586                         'cells' => true,
1587                 'select_submit'=> $submit_on_change,
1588                 'async' => false,
1589                 'category' => 2,
1590                 'show_inactive' => $all
1591         ) );
1592
1593 }
1594
1595 function _format_account($row)
1596 {
1597                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1598 }
1599
1600 function gl_all_accounts_list_cells($label, $name, $selected_id=null, 
1601         $skip_bank_accounts=false, $cells=false, $all_option=false, 
1602         $submit_on_change=false, $all=false)
1603 {
1604         if ($label != null)
1605                 echo "<td>$label</td>\n";
1606         echo "<td>";
1607         echo gl_all_accounts_list($name, $selected_id, 
1608                 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1609         echo "</td>\n";
1610 }
1611
1612 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
1613         $skip_bank_accounts=false, $cells=false, $all_option=false)
1614 {
1615         echo "<tr>\n";
1616         gl_all_accounts_list_cells($label, $name, $selected_id, 
1617                 $skip_bank_accounts, $cells, $all_option);
1618         echo "</tr>\n";
1619 }
1620
1621 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1622 {
1623         $items = array();
1624         $items['0'] = strlen($name_no) ? $name_no : _("No");
1625         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1626
1627         return array_selector($name, $selected_id, $items, 
1628                 array( 
1629                         'select_submit'=> $submit_on_change,
1630                         'async' => false ) ); // FIX?
1631 }
1632
1633 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1634 {
1635         if ($label != null)
1636                 echo "<td>$label</td>\n";
1637         echo "<td>";
1638         echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1639         echo "</td>\n";
1640 }
1641
1642 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1643 {
1644         echo "<tr>\n";
1645         yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1646         echo "</tr>\n";
1647 }
1648
1649 //------------------------------------------------------------------------------------------------
1650
1651 function languages_list($name, $selected_id=null)
1652 {
1653         global $installed_languages;
1654
1655         $items = array();
1656         foreach ($installed_languages as $lang)
1657                         $items[$lang['code']] = $lang['name'];
1658         
1659         return array_selector($name, $selected_id, $items);
1660 }
1661
1662 function languages_list_cells($label, $name, $selected_id=null)
1663 {
1664         if ($label != null)
1665                 echo "<td>$label</td>\n";
1666         echo "<td>";
1667         echo languages_list($name, $selected_id);
1668         echo "</td>\n";
1669 }
1670
1671 function languages_list_row($label, $name, $selected_id=null)
1672 {
1673         echo "<tr>\n";
1674         languages_list_cells($label, $name, $selected_id);
1675         echo "</tr>\n";
1676 }
1677
1678 //------------------------------------------------------------------------------------------------
1679
1680 function bank_account_types_list($name, $selected_id=null)
1681 {
1682         global $bank_account_types;
1683
1684         return array_selector($name, $selected_id, $bank_account_types);
1685 }
1686
1687 function bank_account_types_list_cells($label, $name, $selected_id=null)
1688 {
1689         if ($label != null)
1690                 echo "<td>$label</td>\n";
1691         echo "<td>";
1692         echo bank_account_types_list($name, $selected_id);
1693         echo "</td>\n";
1694 }
1695
1696 function bank_account_types_list_row($label, $name, $selected_id=null)
1697 {
1698         echo "<tr>\n";
1699         bank_account_types_list_cells($label, $name, $selected_id);
1700         echo "</tr>\n";
1701 }
1702
1703 //------------------------------------------------------------------------------------------------
1704 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1705 {
1706         global $payment_person_types;
1707
1708         $items = array();
1709         foreach ($payment_person_types as $key=>$type)
1710         {
1711                 if ($key != PT_WORKORDER)
1712                         $items[$key] = $type;
1713         }               
1714         return array_selector($name, $selected_id, $items, 
1715                 array( 'select_submit'=> $submit_on_change ) );
1716 }
1717
1718 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1719 {
1720         if ($label != null)
1721                 echo "<td>$label</td>\n";
1722         echo "<td>";
1723         echo payment_person_types_list($name, $selected_id, $related);
1724         echo "</td>\n";
1725 }
1726
1727 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1728 {
1729         echo "<tr>\n";
1730         payment_person_types_list_cells($label, $name, $selected_id, $related);
1731         echo "</tr>\n";
1732 }
1733
1734 //------------------------------------------------------------------------------------------------
1735
1736 function wo_types_list($name, $selected_id=null)
1737 {
1738         global $wo_types_array;
1739         
1740         return array_selector($name, $selected_id, $wo_types_array, 
1741                 array( 'select_submit'=> true, 'async' => true ) );
1742 }
1743
1744 function wo_types_list_row($label, $name, $selected_id=null)
1745 {
1746         echo "<tr><td>$label</td><td>\n";
1747         echo wo_types_list($name, $selected_id);
1748         echo "</td></tr>\n";
1749 }
1750
1751 //------------------------------------------------------------------------------------------------
1752
1753 function dateformats_list_row($label, $name, $value=null)
1754 {
1755         global $dateformats;
1756
1757         echo "<tr><td>$label</td>\n<td>";
1758         echo array_selector( $name, $value, $dateformats );
1759         echo "</td></tr>\n";
1760 }
1761
1762 function dateseps_list_row($label, $name, $value=null)
1763 {
1764         global $dateseps;
1765
1766         echo "<tr><td>$label</td>\n<td>";
1767         echo array_selector( $name, $value, $dateseps );
1768         echo "</td></tr>\n";
1769 }
1770
1771 function thoseps_list_row($label, $name, $value=null)
1772 {
1773         global $thoseps;
1774
1775         echo "<tr><td>$label</td>\n<td>";
1776         echo array_selector( $name, $value, $thoseps );
1777         echo "</td></tr>\n";
1778 }
1779
1780 function decseps_list_row($label, $name, $value=null)
1781 {
1782         global $decseps;
1783
1784         echo "<tr><td>$label</td>\n<td>";
1785         echo array_selector( $name, $value, $decseps );
1786         echo "</td></tr>\n";
1787 }
1788
1789 function themes_list_row($label, $name, $value=null)
1790 {
1791         global $path_to_root;
1792
1793         $path = $path_to_root.'/themes/';
1794         $themes = array();
1795         $themedir = opendir($path);
1796         while(false !== ($fname = readdir($themedir)))
1797         {
1798                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1799                 {
1800                         $themes[$fname] =  $fname;
1801                 }
1802         }
1803         ksort($themes);
1804
1805         echo "<tr><td>$label</td>\n<td>";
1806         echo array_selector( $name, $value, $themes );
1807         echo "</td></tr>\n";
1808 }
1809
1810 function pagesizes_list_row($label, $name, $value=null)
1811 {
1812         global $pagesizes;
1813
1814         $items = array();
1815         foreach ($pagesizes as $pz)
1816                 $items[$pz] = $pz;
1817
1818         echo "<tr><td>$label</td>\n<td>";
1819         echo array_selector( $name, $value, $items );
1820         echo "</td></tr>\n";
1821 }
1822
1823 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false)
1824 {
1825         global $systypes_array;
1826
1827         return array_selector($name, $value, $systypes_array, 
1828                 array( 
1829                         'spec_option'=> $spec_opt,
1830                         'spec_id' => ALL_NUMERIC,
1831                         'select_submit'=> $submit_on_change,
1832                         'async' => false,
1833                         )
1834         );
1835 }
1836
1837 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1838 {
1839         if ($label != null)
1840                 echo "<td>$label</td>\n";
1841         echo "<td>";
1842         echo systypes_list($name, $value, false, $submit_on_change);
1843         echo "</td>\n";
1844 }
1845
1846 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1847 {
1848         echo "<tr>\n";
1849         systypes_list_cells($label, $name, $value, false, $submit_on_change);
1850         echo "</tr>\n";
1851 }
1852
1853 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1854 {
1855         global $systypes_array;
1856
1857         if ($label != null)
1858                 echo "<td>$label</td>\n";
1859         echo "<td>";
1860
1861         $items = $systypes_array;
1862
1863         // exclude quotes, orders and dimensions
1864         foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION, 
1865                                 ST_SALESQUOTE) as $excl)
1866                         unset($items[$excl]);
1867         
1868         echo array_selector($name, $value, $items, 
1869                 array( 
1870                         'spec_option'=> _("All"),
1871                         'spec_id' => -1,
1872                         'select_submit'=> $submit_on_change,
1873                         'async' => false
1874                         )
1875         );
1876         echo "</td>\n";
1877 }
1878
1879 function cust_allocations_list_cells($label, $name, $selected=null)
1880 {
1881         global $all_items;
1882
1883         if ($label != null)
1884                 label_cell($label);
1885         echo "<td>\n";
1886         $allocs = array( 
1887                 $all_items=>_("All Types"),
1888                 '1'=> _("Sales Invoices"),
1889                 '2'=> _("Overdue Invoices"),
1890                 '3' => _("Payments"),
1891                 '4' => _("Credit Notes"),
1892                 '5' => _("Delivery Notes")
1893         );
1894         echo array_selector($name, $selected, $allocs);
1895         echo "</td>\n";
1896 }
1897
1898 function supp_allocations_list_cell($name, $selected=null)
1899 {
1900         global $all_items;
1901
1902         echo "<td>\n";
1903         $allocs = array( 
1904                 $all_items=>_("All Types"),
1905                 '1'=> _("Invoices"),
1906                 '2'=> _("Overdue Invoices"),
1907                 '3' => _("Payments"),
1908                 '4' => _("Credit Notes"),
1909                 '5' => _("Overdue Credit Notes")
1910         );
1911         echo array_selector($name, $selected, $allocs);
1912         echo "</td>\n";
1913 }
1914
1915 function policy_list_cells($label, $name, $selected=null)
1916 {
1917         if ($label != null)
1918                 label_cell($label);
1919         echo "<td>\n";
1920         echo array_selector($name, $selected, 
1921                                 array( '' => _("Automatically put balance on back order"),
1922                                         'CAN' => _("Cancel any quantites not delivered")) );
1923         echo "</td>\n";
1924 }
1925
1926 function policy_list_row($label, $name, $selected=null)
1927 {
1928         echo "<tr>\n";
1929         policy_list_cells($label, $name, $selected);
1930         echo "</tr>\n";
1931 }
1932
1933 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1934 {
1935         if ($label != null)
1936                 label_cell($label);
1937         echo "<td>\n";
1938         echo array_selector($name, $selected, 
1939                                 array( 'Return' => _("Items Returned to Inventory Location"),
1940                                         'WriteOff' => _("Items Written Off")),
1941                                 array( 'select_submit'=> $submit_on_change ) );
1942         echo "</td>\n";
1943 }
1944
1945 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1946 {
1947         echo "<tr>\n";
1948         credit_type_list_cells($label, $name, $selected, $submit_on_change);
1949         echo "</tr>\n";
1950 }
1951
1952 function number_list($name, $selected, $from, $to, $no_option=false)
1953 {
1954         $items = array();
1955         for ($i = $from; $i <= $to; $i++)
1956                 $items[$i] = "$i";
1957
1958         return array_selector($name, $selected, $items,
1959                                 array(  'spec_option' => $no_option,
1960                                                 'spec_id' => ALL_NUMERIC) );
1961 }
1962
1963 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1964 {
1965         if ($label != null)
1966                 label_cell($label);
1967         echo "<td>\n";
1968         echo number_list($name, $selected, $from, $to, $no_option);
1969         echo "</td>\n";
1970 }
1971
1972 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1973 {
1974         echo "<tr>\n";
1975         echo number_list_cells($label, $name, $selected, $from, $to, $no_option);
1976         echo "</tr>\n";
1977 }
1978
1979 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1980         $submit_on_change=true)
1981 {
1982         $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1983                 ." GROUP BY profile";
1984         $result = db_query($sql, 'cannot get all profile names');
1985         $profiles = array();
1986         while($myrow=db_fetch($result)) {
1987                 $profiles[$myrow['profile']] = $myrow['profile'];
1988         }
1989
1990         echo "<tr>";
1991         if ($label != null)
1992                 echo "<td>$label</td>\n";
1993         echo "<td>";
1994
1995         echo array_selector($name, $selected_id, $profiles, 
1996                 array( 'select_submit'=> $submit_on_change,
1997                         'spec_option'=>$spec_opt,
1998                         'spec_id' => ''
1999                  ));
2000
2001         echo "</td></tr>\n";
2002 }
2003
2004 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2005 {
2006         static $printers; // query only once for page display
2007
2008         if (!$printers) {
2009                 $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; 
2010                 $result = db_query($sql, 'cannot get all printers');
2011                 $printers = array();
2012                 while($myrow=db_fetch($result)) {
2013                         $printers[$myrow['id']] = $myrow['name'].'&nbsp;-&nbsp;'.$myrow['description'];
2014                 }
2015         }
2016         return array_selector($name, $selected_id, $printers, 
2017                 array( 'select_submit'=> $submit_on_change,
2018                         'spec_option'=>$spec_opt,
2019                         'spec_id' => ''
2020                  ));
2021 }
2022
2023 //------------------------------------------------------------------------------------------------
2024
2025 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2026 {
2027         $where = false;
2028         $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2029         if ($type != null)
2030                 $sql .= " WHERE type=$type";
2031
2032         return combo_input($name, $selected_id, $sql, 'id', 'description',
2033                 array(
2034                         'spec_id' => '',
2035                         'order' => 'description',
2036                         'select_submit'=> $submit_on_change,
2037                         'async' => false
2038                 ) );
2039
2040 }
2041
2042 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2043 {
2044         echo "<td>$label</td><td>\n";
2045         echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2046         echo "</td>";
2047 }
2048
2049 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2050 {
2051         echo "<tr>\n";
2052         quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2053         echo "</tr>\n";
2054 }
2055
2056
2057 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2058 {
2059         global $quick_actions;
2060         
2061         echo "<tr><td>$label</td><td>";
2062         echo array_selector($name, $selected_id, $quick_actions, 
2063                 array( 
2064                         'select_submit'=> $submit_on_change
2065                 ) );
2066         echo "</td></tr>\n";
2067 }
2068
2069 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2070 {
2071         global $quick_entry_types;
2072                 
2073         echo "<tr><td>$label</td><td>";
2074         echo array_selector($name, $selected_id, $quick_entry_types, 
2075                 array( 
2076                         'select_submit'=> $submit_on_change
2077                         ) );
2078         echo "</td></tr>\n";
2079 }
2080
2081 function record_status_list_row($label, $name) {
2082         return yesno_list_row($label, $name, null,      _('Inactive'), _('Active'));
2083 }
2084
2085 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2086 {
2087         global $class_types;
2088         
2089         echo "<tr><td>$label</td><td>";
2090         echo array_selector($name, $selected_id, $class_types, 
2091                 array( 
2092                         'select_submit'=> $submit_on_change
2093                 ) );
2094         echo "</td></tr>\n";
2095 }
2096
2097 //------------------------------------------------------------------------------------------------
2098
2099 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2100         $show_inactive = false)
2101 {
2102         global $all_items;
2103
2104         $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2105
2106 return combo_input($name, $selected_id, $sql, 'id', 'description',
2107         array(
2108                 'spec_option'=>$new_item ? _("New role") : false,
2109                 'spec_id' => '',
2110                 'select_submit'=> $submit_on_change,
2111                 'show_inactive' => $show_inactive
2112         ) );
2113 }
2114
2115 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2116         $show_inactive = false)
2117 {
2118         if ($label != null)
2119                 echo "<td>$label</td>\n";
2120         echo "<td>";
2121         echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2122         echo "</td>\n";
2123 }
2124
2125 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2126         $show_inactive = false)
2127 {
2128         echo "<tr>";
2129         security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2130         echo "</tr>\n";
2131 }
2132
2133 function tab_list_row($label, $name, $selected_id=null, $all = false)
2134 {
2135         global $installed_extensions;
2136         
2137         $tabs = array();
2138         foreach ($_SESSION['App']->applications as $app) {
2139                 $tabs[$app->id] = access_string($app->name, true);
2140         }
2141         if ($all) {     // add also not active ext. modules
2142                 foreach ($installed_extensions as $ext) {
2143                         if ($ext['type'] == 'module' && !$ext['active'])
2144                                 $tabs[$ext['tab']] = access_string($ext['title'], true);
2145                 }
2146         }
2147         echo "<tr>\n";
2148         echo "<td>$label</td><td>\n";
2149         echo array_selector($name, $selected_id, $tabs);
2150         echo "</td></tr>\n";
2151 }
2152
2153 //-----------------------------------------------------------------------------------------------
2154
2155 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2156 {
2157         // Get tags
2158         global $path_to_root;
2159         include_once($path_to_root . "/admin/db/tags_db.inc");
2160         $results = get_tags($type, $all);
2161
2162         while ($tag = db_fetch($results))
2163                 $tags[$tag['id']] = $tag['name'];
2164         
2165         if (!isset($tags)) {
2166                 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2167                 $spec_opt = false;
2168         }
2169         return array_selector($name, null, $tags,
2170                 array(
2171                         'multi' => $multi,
2172                         'height' => $height,
2173                         'spec_option'=> $spec_opt,
2174                         'spec_id' => -1,
2175                 ) );
2176 }
2177
2178 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2179 {
2180         if ($label != null)
2181                 echo "<td>$label</td>\n";
2182         echo "<td>\n";
2183         echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2184         echo "</td>\n";
2185         
2186 }
2187
2188 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2189 {
2190         echo "<tr>\n";
2191         tag_list_cells($label, $name, $height, $type, $mult, $all, $spec_opt);
2192         echo "</tr>\n"; 
2193 }
2194
2195 //---------------------------------------------------------------------------------------------
2196 //      List of sets of active extensions 
2197 //
2198 function extset_list($name, $value=null, $submit_on_change=false)
2199 {
2200         global $db_connections;
2201
2202         $items = array();
2203         foreach ($db_connections as $comp)
2204                 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2205         return array_selector( $name, $value, $items,
2206                 array(
2207                         'spec_option'=> _("Available and/or installed"),
2208                         'spec_id' => -1,
2209                         'select_submit'=> $submit_on_change,
2210                         'async' => true
2211                 ));
2212 }
2213
2214 ?>