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