Added fixed assets module
[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 define('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 define('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 //----------------------------------------------------------------------------
23 //      Universal sql combo generator
24 //      $sql must return selector values and selector texts in columns 0 & 1
25 //      Options are merged with defaults.
26
27 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
28         $options=null)
29 {
30 global $Ajax;
31
32 $opts = array(          // default options
33         'where'=> array(),              // additional constraints
34         'order' => $namefield,  // list sort order
35                 // special option parameters
36         'spec_option'=>false,   // option text or false
37         'spec_id' => 0,         // option id
38                 // submit on select parameters
39         'default' => '', // default value when $_POST is not set
40         'multi' => false,       // multiple select
41         'select_submit' => false, //submit on select: true/false
42         'async' => true,        // select update via ajax (true) vs _page_body reload
43                 // search box parameters
44         'sel_hint' => null,
45         'search_box' => false,  // name or true/false
46         'type' => 0,    // type of extended selector:
47                 // 0 - with (optional) visible search box, search by fragment inside id
48                 // 1 - with hidden search box, search by option text
49                 // 2 - with (optional) visible search box, search by fragment at the start of id
50                 // 3 - TODO reverse: box with hidden selector available via enter; this
51                 // would be convenient for optional ad hoc adding of new item
52         'search_submit' => true, //search submit button: true/false
53         'size' => 8,    // size and max of box tag
54         'max' => 50,
55         'height' => false,      // number of lines in select box
56         'cells' => false,       // combo displayed as 2 <td></td> cells
57         'search' => array(), // sql field names to search
58         'format' => null,        // format functions for regular options
59         'disabled' => false,
60         'box_hint' => null, // box/selectors hints; null = std see below
61         'category' => false, // category column name or false
62         'show_inactive' => false, // show inactive records. 
63         'editable' => false, // false, or length of editable entry field
64         'editlink' => false     // link to entity entry/edit page (optional)
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         if ($opts['type'] == 0) {
81                 $by_id = true;
82                 $class = 'combo';
83         } elseif($opts['type'] == 1) {
84                 $by_id = false;
85                 $class = 'combo2';
86         } else {
87                 $by_id = true;
88                 $class = 'combo3';
89         }
90
91         $disabled = $opts['disabled'] ? "disabled" : '';
92         $multi = $opts['multi'];
93         
94         if(!count($opts['search'])) {
95                 $opts['search'] = array($by_id ? $valfield : $namefield);
96         }
97         if ($opts['sel_hint'] === null) 
98                 $opts['sel_hint'] = $by_id || $search_box==false ?
99                         '' : _('Press Space tab for search pattern entry');
100
101         if ($opts['box_hint'] === null)
102                 $opts['box_hint'] = $search_box && $search_submit != false ?
103                         ($by_id ? _('Enter code fragment to search or * for all')
104                         : _('Enter description fragment to search or * for all')) :'';
105
106         if ($selected_id == null) {
107                 $selected_id = get_post($name, (string)$opts['default']);
108         }
109         if(!is_array($selected_id))
110                 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
111
112         $txt = get_post($search_box);
113         $rel = '';
114         $limit = '';
115         if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
116                 if ($by_id) $txt = $_POST[$name];
117
118                 if (!$opts['async'])
119                         $Ajax->activate('_page_body');
120                 else
121                         $Ajax->activate($name);
122         }
123         if (isset($_POST[$search_button])) {
124                 if (!$opts['async'])
125                         $Ajax->activate('_page_body');
126                 else
127                         $Ajax->activate($name);
128         }
129         if ($search_box) {
130                 // search related sql modifications
131
132                 $rel = "rel='$search_box'"; // set relation to list
133                 if ($opts['search_submit']) {
134                         if (isset($_POST[$search_button])) {
135                                 $selected_id = array(); // ignore selected_id while search
136                                 if (!$opts['async'])
137                                         $Ajax->activate('_page_body');
138                                 else
139                                         $Ajax->activate($name);
140                         }
141                         if ($txt == '') {
142                                 if ($spec_option === false && $selected_id == array())
143                                         $limit = ' LIMIT 1';
144                                 else
145                                         $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
146                         }
147                         else
148                                 if ($txt != '*') {
149
150                                         foreach($opts['search'] as $i=> $s)
151                                                 $opts['search'][$i] = $s . " LIKE "
152                                                         .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
153                                         $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
154                                 }
155                 }
156         }
157
158         // sql completion
159         if (count($opts['where'])) {
160                 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
161                 $where .= '('. implode($opts['where'], ' AND ') . ')';
162                 $group_pos = strpos($sql, 'GROUP BY');
163                 if ($group_pos) {
164                         $group = substr($sql, $group_pos);
165                         $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
166                 } else {
167                         $sql .= $where;
168                 }
169         }
170         if ($opts['order'] != false) {
171                 if (!is_array($opts['order']))
172                         $opts['order'] = array($opts['order']);
173                 $sql .= ' ORDER BY '.implode(',',$opts['order']);
174         }
175
176         $sql .= $limit;
177         // ------ make selector ----------
178         $selector = $first_opt = '';
179         $first_id = false;
180         $found = false;
181         $lastcat = null;
182         $edit = false;
183         if($result = db_query($sql)) {
184                 while ($contact_row = db_fetch($result)) {
185                         $value = $contact_row[0];
186                         $descr = $opts['format']==null ?  $contact_row[1] :
187                                 call_user_func($opts['format'], $contact_row);
188                         $sel = '';
189                         if (get_post($search_button) && ($txt == $value)) {
190                                 $selected_id[] = $value;
191                         }
192
193                         if (in_array((string)$value, $selected_id, true)) {
194                                 $sel = 'selected';
195                                 $found = $value;
196                                 $edit = $opts['editable'] && $contact_row['editable'] 
197                                         && (@$_POST[$search_box] == $value)
198                                         ? $contact_row[1] : false; // get non-formatted description
199                                 if ($edit)
200                                         break;  // selected field is editable - abandon list construction
201                         }
202                         // show selected option even if inactive 
203                         if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
204                                 continue;
205                         } else 
206                                 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
207
208                         if ($first_id === false) {
209                                 $first_id = $value;
210                                 $first_opt = $descr;
211                         }
212                         $cat = $contact_row[$opts['category']];
213                         if ($opts['category'] !== false && $cat != $lastcat){
214                                 if ($lastcat!==null)
215                                         $selector .= "</optgroup>";
216                                 $selector .= "<optgroup label='".$cat."'>\n";
217                                 $lastcat = $cat;
218                         }
219                         $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
220                 }
221                 if ($lastcat!==null)
222                         $selector .= "</optgroup>";
223                 db_free_result($result);
224         }
225
226         // Prepend special option.
227         if ($spec_option !== false) { // if special option used - add it
228                 $first_id = $spec_id;
229                 $first_opt = $spec_option;
230                 $sel = $found===false ? 'selected' : '';
231                 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
232                 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
233                         . $selector;
234         }
235
236         if ($found===false) {
237                 $selected_id = array($first_id);
238         }
239         
240         $_POST[$name] = $multi ? $selected_id : $selected_id[0];
241
242         $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
243                 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
244                 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
245                 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
246
247         if ($by_id && ($search_box != false || $opts['editable']) ) {
248                 // on first display show selector list
249                 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
250                         $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
251                         ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
252                                 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
253                                 set_focus($name.'_text'); // prevent lost focus
254                 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
255                         set_focus($name); // prevent lost focus
256                 if (!$opts['editable'])
257                         $txt = $found;
258                 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
259         }
260
261         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
262
263         // span for select list/input field update
264         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
265
266          // if selectable or editable list is used - add select button
267         if ($select_submit != false || $search_button) {
268         // button class selects form reload/ajax selector update
269                 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
270                         (fallback_mode() ? '' : 'display:none;'),
271                          '_'.$name.'_update')."\n";
272         }
273 // ------ make combo ----------
274         $edit_entry = '';
275         if ($search_box != false) {
276                 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
277                         $opts['size']."' maxlength='".$opts['max'].
278                         "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
279                         .$opts['box_hint']."'"
280                         .(!fallback_mode() && !$by_id ? " style=display:none;":'')
281                         .">\n";
282                 if ($search_submit != false || $opts['editable']) {
283                         $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
284                                 (fallback_mode() ? '' : 'display:none;'),
285                                 $search_submit ? $search_submit : "_{$name}_button")."\n";
286                 }
287         }
288         default_focus(($search_box && $by_id) ? $search_box : $name);
289
290         if ($opts['editlink'])
291                 $selector .= ' '.$opts['editlink'];
292
293         if ($search_box && $opts['cells'])
294                 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
295         else
296                 $str = $edit_entry.$selector;
297         return $str;
298 }
299
300 /*
301         Helper function.
302         Returns true if selector $name is subject to update.
303 */
304 function list_updated($name)
305 {
306         return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
307 }
308 //----------------------------------------------------------------------------------------------
309 //      Universal array combo generator
310 //      $items is array of options 'value' => 'description'
311 //      Options is reduced set of combo_selector options and is merged with defaults.
312
313 function array_selector($name, $selected_id, $items, $options=null)
314 {
315         global $Ajax;
316
317 $opts = array(          // default options
318         'spec_option'=>false,   // option text or false
319         'spec_id' => 0,         // option id
320         'select_submit' => false, //submit on select: true/false
321         'async' => true,        // select update via ajax (true) vs _page_body reload
322         'default' => '', // default value when $_POST is not set
323         'multi'=>false, // multiple select
324                 // search box parameters
325         'height' => false,      // number of lines in select box
326         'sel_hint' => null,
327         'disabled' => false
328 );
329 // ------ merge options with defaults ----------
330         if($options != null)
331                 $opts = array_merge($opts, $options);
332         $select_submit =  $opts['select_submit'];
333         $spec_id = $opts['spec_id'];
334         $spec_option = $opts['spec_option'];
335         $disabled = $opts['disabled'] ? "disabled" : '';
336         $multi = $opts['multi'];
337
338         if ($selected_id == null) {
339                 $selected_id = get_post($name, $opts['default']);
340         }
341         if(!is_array($selected_id))
342                 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
343
344         if (isset($_POST[ '_'.$name.'_update'])) {
345                 if (!$opts['async'])
346                         $Ajax->activate('_page_body');
347                 else
348                         $Ajax->activate($name);
349         }
350
351         // ------ make selector ----------
352         $selector = $first_opt = '';
353         $first_id = false;
354         $found = false;
355         foreach($items as $value=>$descr) {
356                 $sel = '';
357                 if (in_array((string)$value, $selected_id, true)) {
358                         $sel = 'selected';
359                         $found = $value;
360                 }
361                 if ($first_id === false) {
362                         $first_id = $value;
363                         $first_opt = $descr;
364                 }
365                 $selector .= "<option $sel value='$value'>$descr</option>\n";
366         }
367
368         if ($first_id!==false) {
369                 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
370         }
371         // Prepend special option.
372         if ($spec_option !== false) { // if special option used - add it
373                 $first_id = $spec_id;
374                 $first_opt = $spec_option;
375                 $sel = $found===false ? 'selected' : '';
376                 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
377                         . $selector;
378         }
379
380         if ($found===false) {
381                 $selected_id = array($first_id);
382         }
383         $_POST[$name] = $multi ? $selected_id : $selected_id[0];
384
385         $selector = "<select autocomplete='off' ".($multi  ? "multiple" : '')
386                 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
387                 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
388                 . $opts['sel_hint']."'>".$selector."</select>\n";
389
390         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
391
392         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
393
394         if ($select_submit != false) { // if submit on change is used - add select button
395                 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
396                         (fallback_mode() ? '' : 'display:none;'),
397                          '_'.$name.'_update')."\n";
398         }
399         default_focus($name);
400
401         return $selector;
402 }
403 //----------------------------------------------------------------------------------------------
404 function array_selector_row($label, $name, $selected_id, $items, $options=null)
405 {
406         echo "<tr><td class='label'>$label</td>\n<td>";
407         echo array_selector($name, $selected_id, $items, $options);
408         echo "</td></tr>\n";
409 }
410
411 //----------------------------------------------------------------------------------------------
412 function _format_add_curr($row)
413 {
414         static $company_currency;
415
416         if ($company_currency == null)
417         {
418                 $company_currency = get_company_currency();
419         }
420         return $row[1] . ($row[2] == $company_currency ?
421                 '' : ("&nbsp;-&nbsp;" . $row[2]));
422 }
423
424 function add_edit_combo($type)
425 {
426         global $path_to_root, $popup_editors, $SysPrefs;
427
428         if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
429                 return "";
430         // Derive theme path
431         $theme_path = $path_to_root . '/themes/' . user_theme();
432
433         $key = $popup_editors[$type][1];
434         $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
435         $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
436         return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>"; 
437 }
438
439 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
440         $all=false, $editkey = false)
441 {
442
443         $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
444
445         $mode = get_company_pref('no_supplier_list');
446
447         if ($editkey)
448                 set_editor('supplier', $name, $editkey);
449
450         $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
451         array(
452                 'format' => '_format_add_curr',
453             'order' => array('supp_ref'),
454                 'search_box' => $mode!=0,
455                 'type' => 1,
456         'search' => array("supp_ref","supp_name","gst_no"),        
457                 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
458                 'spec_id' => ALL_TEXT,
459                 'select_submit'=> $submit_on_change,
460                 'async' => false,
461                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
462                 _('Select supplier'),
463                 'show_inactive'=>$all,
464                 'editlink' => $editkey ? add_edit_combo('supplier') : false
465                 ));
466         return $ret;
467 }
468
469 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, 
470         $submit_on_change=false, $all=false, $editkey = false)
471 {
472         if ($label != null)
473                 echo "<td>$label</td><td>\n";
474                 echo supplier_list($name, $selected_id, $all_option, $submit_on_change, 
475                 $all, $editkey);
476                 echo "</td>\n";
477 }
478
479 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, 
480         $submit_on_change=false, $all=false, $editkey = false)
481 {
482         echo "<tr><td class='label'>$label</td><td>";
483         echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
484                 $all, $editkey);
485         echo "</td></tr>\n";
486 }
487 //----------------------------------------------------------------------------------------------
488
489 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, 
490         $show_inactive=false, $editkey = false)
491 {
492
493         $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
494
495         $mode = get_company_pref('no_customer_list');
496
497         if ($editkey)
498                 set_editor('customer', $name, $editkey);
499
500         $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
501         array(
502             'format' => '_format_add_curr',
503             'order' => array('debtor_ref'),
504                 'search_box' => $mode!=0,
505                 'type' => 1,
506                 'size' => 20,
507         'search' => array("debtor_ref","name","tax_id"),        
508                 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
509                 'spec_id' => ALL_TEXT,
510                 'select_submit'=> $submit_on_change,
511                 'async' => false,
512                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
513                 _('Select customer'),
514                 'show_inactive' => $show_inactive,
515                 'editlink' => $editkey ? add_edit_combo('customer') : false
516         ) );
517         return $ret;
518 }
519
520 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, 
521         $submit_on_change=false, $show_inactive=false, $editkey = false)
522 {
523         if ($label != null)
524                 echo "<td>$label</td>\n";
525         echo "<td nowrap>";
526         echo customer_list($name, $selected_id, $all_option, $submit_on_change,
527                 $show_inactive, $editkey);
528         echo "</td>\n";
529 }
530
531 function customer_list_row($label, $name, $selected_id=null, $all_option = false, 
532         $submit_on_change=false, $show_inactive=false, $editkey = false)
533 {
534
535         echo "<tr><td class='label'>$label</td><td nowrap>";
536         echo customer_list($name, $selected_id, $all_option, $submit_on_change,
537                 $show_inactive, $editkey);
538         echo "</td>\n</tr>\n";
539 }
540
541 //------------------------------------------------------------------------------------------------
542
543 function customer_branches_list($customer_id, $name, $selected_id=null,
544         $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
545 {
546
547         $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
548                 WHERE debtor_no=" . db_escape($customer_id)." ";
549
550         if ($editkey)
551                 set_editor('branch', $name, $editkey);
552
553         $where = $enabled ? array("inactive = 0") : array();
554         $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
555         array(
556                 'where' => $where,
557                 'order' => array('branch_ref'),
558                 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
559                 'spec_id' => ALL_TEXT,
560                 'select_submit'=> $submit_on_change,
561                 'sel_hint' => _('Select customer branch'),
562                 'editlink' => $editkey ? add_edit_combo('branch') : false
563         ) );
564         return $ret;
565 }
566 //------------------------------------------------------------------------------------------------
567
568 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, 
569         $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
570 {
571         if ($label != null)
572                 echo "<td>$label</td>\n";
573         echo "<td>";
574         echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, 
575                 $submit_on_change, $editkey);
576         echo "</td>\n";
577 }
578
579 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null, 
580         $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
581 {
582         echo "<tr><td class='label'>$label</td>";
583         customer_branches_list_cells(null, $customer_id, $name, $selected_id, 
584                 $all_option, $enabled, $submit_on_change, $editkey);
585         echo "</tr>";
586 }
587
588 //------------------------------------------------------------------------------------------------
589
590 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
591 {
592
593         $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
594
595         return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
596                 array(
597                         'spec_option' => $all_option === true ? _("All Locations") : $all_option,
598                         'spec_id' => ALL_TEXT,
599                         'select_submit'=> $submit_on_change
600                 ) );
601 }
602
603 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
604 {
605         if ($label != null)
606                 echo "<td>$label</td>\n";
607         echo "<td>";
608         echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
609         echo "</td>\n";
610 }
611
612 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
613 {
614         echo "<tr><td class='label'>$label</td>";
615         locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
616         echo "</tr>\n";
617 }
618
619 //-----------------------------------------------------------------------------------------------
620
621 function currencies_list($name, $selected_id=null, $submit_on_change=false)
622 {
623         $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
624
625         // default to the company currency
626         return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
627                 array(
628                         'select_submit'=> $submit_on_change,
629                         'default' => get_company_currency(),
630                         'async' => false                
631                 ) );
632 }
633
634 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
635 {
636         if ($label != null)
637                 echo "<td>$label</td>\n";
638         echo "<td>";
639         echo currencies_list($name, $selected_id, $submit_on_change);
640         echo "</td>\n";
641 }
642
643 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
644 {
645         echo "<tr><td class='label'>$label</td>";
646         currencies_list_cells(null, $name, $selected_id, $submit_on_change);
647         echo "</tr>\n";
648 }
649
650 //---------------------------------------------------------------------------------------------------
651
652 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
653 {
654
655         $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
656
657         // default to the company current fiscal year
658
659         return combo_input($name, $selected_id, $sql, 'id', '',
660                 array(
661                         'order' => 'begin',
662                         'default' => get_company_pref('f_year'),
663                         'format' => '_format_fiscalyears',
664                         'select_submit'=> $submit_on_change,
665                         'async' => false
666                 ) );
667 }
668
669 function _format_fiscalyears($row)
670 {
671         return sql2date($row[1]) . "&nbsp;-&nbsp;" . sql2date($row[2])
672         . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active'));
673 }
674
675 function fiscalyears_list_cells($label, $name, $selected_id=null)
676 {
677         if ($label != null)
678                 echo "<td>$label</td>\n";
679         echo "<td>";
680         echo fiscalyears_list($name, $selected_id);
681         echo "</td>\n";
682 }
683
684 function fiscalyears_list_row($label, $name, $selected_id=null)
685 {
686         echo "<tr><td class='label'>$label</td>";
687         fiscalyears_list_cells(null, $name, $selected_id);
688         echo "</tr>\n";
689 }
690 //------------------------------------------------------------------------------------
691
692 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
693         $submit_on_change=false, $showclosed=false, $showtype=1)
694 {
695         $sql = "SELECT id, CONCAT(reference,'  ',name) as ref FROM ".TB_PREF."dimensions";
696
697         $options = array(
698                 'order' => 'reference',
699                 'spec_option'=>$no_option ? $showname : false,
700                 'spec_id' => 0,
701                 'select_submit'=> $submit_on_change,
702                 'async' => false,
703         );
704
705         if (!$showclosed)
706                 $options['where'][] = "closed=0";
707         if($showtype)
708                 $options['where'][] = "type_=".db_escape($showtype);
709
710         return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
711 }
712
713 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
714         $showclosed=false, $showtype=0, $submit_on_change=false)
715 {
716         if ($label != null)
717                 echo "<td>$label</td>\n";
718         echo "<td>";
719         echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
720         echo "</td>\n";
721 }
722
723 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
724         $showclosed=false, $showtype=0, $submit_on_change=false)
725 {
726         echo "<tr><td class='label'>$label</td>";
727         dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
728                 $showclosed, $showtype, $submit_on_change);
729         echo "</tr>\n";
730 }
731
732 //---------------------------------------------------------------------------------------------------
733
734 function stock_items_list($name, $selected_id=null, $all_option=false, 
735         $submit_on_change=false, $opts=array(), $editkey = false)
736 {
737
738         $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
739                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
740
741         if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
742                 $sql .= " AND mb_flag='F'";
743         else
744                 $sql .= " AND mb_flag!='F'";
745
746         if ($editkey)
747                 set_editor('item', $name, $editkey);
748
749         $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
750                 array_merge(
751                   array(
752                         'format' => '_format_stock_items',
753                         'spec_option' => $all_option===true ?  _("All Items") : $all_option,
754                         'spec_id' => ALL_TEXT,
755                         'search_box' => true,
756                         'search' => array("stock_id", "c.description","s.description"),
757                         'search_submit' => get_company_pref('no_item_list')!=0,
758                         'size'=>10,
759                         'select_submit'=> $submit_on_change,
760                         'category' => 2,
761                         'order' => array('c.description','stock_id'),
762                         'editlink' => $editkey ? add_edit_combo('item') : false,
763                         'editable' => false,
764                         'max' => 255
765                   ), $opts) );
766         return $ret;
767 }
768
769 function _format_stock_items($row)
770 {
771         return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "") . $row[1];
772 }
773
774 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, 
775         $submit_on_change=false, $all=false, $editkey = false, $opts= array())
776 {
777         if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
778                 $editor_item = 'fa_item';
779         else
780                 $editor_item = 'item';
781
782 //      if ($editkey) ??
783 //              set_editor($editor_item, $name, $editkey);
784
785         if ($label != null)
786                 echo "<td>$label</td>\n";
787
788 // ??
789 //  $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
790 //
791 //      echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
792
793         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
794                 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
795
796 }
797 /*
798 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
799 {
800         echo "<tr>\n";
801         stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
802         echo "</tr>\n";
803 }
804 */
805 //---------------------------------------------------------------------------------------------------
806 //
807 // Select item via foreign code.
808 //
809 function sales_items_list($name, $selected_id=null, $all_option=false, 
810         $submit_on_change=false, $type='', $opts=array())
811 {
812         // all sales codes
813         $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
814                          i.inactive, if(count(*)>1, '0', s.editable) as editable
815                         FROM
816                         ".TB_PREF."stock_master s,
817                         ".TB_PREF."item_codes i
818                         LEFT JOIN
819                         ".TB_PREF."stock_category c
820                         ON i.category_id=c.category_id
821                         WHERE i.stock_id=s.stock_id
822       AND mb_flag != 'F'";
823
824         
825         if ($type == 'local')   { // exclude foreign codes
826                 $sql .= " AND !i.is_foreign"; 
827         } elseif ($type == 'kits') { // sales kits
828                 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
829         }
830         $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
831         $sql .= " GROUP BY i.item_code";
832
833         return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
834                 array_merge(
835                   array(
836                         'format' => '_format_stock_items',
837                         'spec_option' => $all_option===true ?  _("All Items") : $all_option,
838                         'spec_id' => ALL_TEXT,
839                         'search_box' => true,
840                         'search' => array("i.item_code", "c.description", "i.description"),
841                         'search_submit' => get_company_pref('no_item_list')!=0,
842                         'size'=>15,
843                         'select_submit'=> $submit_on_change,
844                         'category' => 2,
845                         'order' => array('c.description','i.item_code'),
846                         'editable' => 30,
847                         'max' => 255
848                   ), $opts) );
849 }
850
851 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
852 {
853         if ($editkey)
854                 set_editor('item', $name, $editkey);
855
856         if ($label != null)
857                 echo "<td>$label</td>\n";
858         echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
859                 '', array('cells'=>true));
860 }
861
862 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
863 {
864         return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
865                 'kits', array('cells'=>false, 'editable' => false));
866 }
867
868 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
869 {
870         echo "<tr>";
871         if ($label != null)
872                 echo "<td class='label'>$label</td>\n";
873         echo "<td>";
874         echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
875                 'local', array('cells'=>false, 'editable' => false));
876         echo "</td></tr>";
877 }
878 //------------------------------------------------------------------------------------
879
880 function stock_manufactured_items_list($name, $selected_id=null,
881         $all_option=false, $submit_on_change=false)
882 {
883         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
884                 array('where'=>array("mb_flag= 'M'")));
885 }
886
887 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
888                                 $all_option=false, $submit_on_change=false)
889 {
890         if ($label != null)
891                 echo "<td>$label</td>\n";
892         echo "<td>";
893         echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
894         echo "</td>\n";
895 }
896
897 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
898                 $all_option=false, $submit_on_change=false)
899 {
900         echo "<tr><td class='label'>$label</td>";
901         stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
902         echo "</tr>\n";
903 }
904 //------------------------------------------------------------------------------------
905
906 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
907         $all_option=false, $submit_on_change=false, $editkey = false)
908 {
909         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
910                 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
911 }
912
913 function stock_component_items_list_cells($label, $name, $parent_stock_id, 
914         $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
915 {
916         if ($label != null)
917                 echo "<td>$label</td>\n";
918         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
919                 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
920                 $editkey);
921 }
922 //------------------------------------------------------------------------------------
923
924 function stock_costable_items_list($name, $selected_id=null,
925         $all_option=false, $submit_on_change=false)
926 {
927         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
928                 array('where'=>array("mb_flag!='D'")));
929 }
930
931 function stock_costable_items_list_cells($label, $name, $selected_id=null, 
932         $all_option=false, $submit_on_change=false)
933 {
934         if ($label != null)
935                 echo "<td>$label</td>\n";
936         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
937                 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
938 }
939
940 //------------------------------------------------------------------------------------
941 function stock_purchasable_items_list($name, $selected_id=null, 
942         $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
943 {
944         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
945                 array('where'=>array("NOT no_purchase"), 
946                         'show_inactive'=>$all), $editkey);
947 }
948 //
949 //      This helper is used in PO/GRN/PI entry and supports editable descriptions.
950 //
951 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
952                         $all_option=false, $submit_on_change=false, $editkey=false)
953 {
954         if ($label != null)
955                 echo "<td>$label</td>\n";
956         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
957                 array('where'=>array("NOT no_purchase"), 
958                          'editable' => 30,
959                          'cells'=>true), $editkey);
960 }
961
962 //------------------------------------------------------------------------------------
963
964 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
965 {
966         global $stock_types;
967
968         echo "<tr>";
969         if ($label != null)
970                 echo "<td class='label'>$label</td>\n";
971         echo "<td>";
972
973         echo array_selector($name, $selected_id, $stock_types, 
974                 array( 
975                         'select_submit'=> true, 
976                         'disabled' => !$enabled) );
977         echo "</td></tr>\n";
978 }
979
980 function stock_units_list_row($label, $name, $value=null, $enabled=true)
981 {
982         $result = get_all_item_units();
983         echo "<tr>";
984         if ($label != null)
985                 echo "<td class='label'>$label</td>\n";
986         echo "<td>";
987
988         while($unit = db_fetch($result))
989                 $units[$unit['abbr']] = $unit['name'];
990
991         echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
992
993         echo "</td></tr>\n";
994 }
995
996 //------------------------------------------------------------------------------------
997
998 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
999         $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1000 {
1001         // Check if a fixed asset has been bought.
1002         $where_opts[] = "stock_id NOT IN
1003         ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1004
1005         // exclude items currently on the order.
1006         foreach($exclude_items as $item) {
1007         $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1008         }
1009         $where_opts[] = "mb_flag='F'";
1010
1011         echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey, 
1012     array('fixed_asset' => true, 'where' => $where_opts));
1013 }
1014
1015 function stock_disposable_fa_list($name, $selected_id=null,
1016         $all_option=false, $submit_on_change=false)
1017 {
1018         // Check if a fixed asset has been bought....
1019         $where_opts[] = "stock_id IN
1020         ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1021         // ...but has not been disposed or sold already.
1022         $where_opts[] = "stock_id NOT IN
1023                 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1024
1025         $where_opts[] = "mb_flag='F'";
1026
1027         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1028     array('fixed_asset' => true, 'where' => $where_opts));
1029 }
1030
1031 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1032         $all_option=false, $submit_on_change=false, $exclude_items = array())
1033 {
1034         // Check if a fixed asset has been bought....
1035         $where_opts[] = "stock_id IN
1036         ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1037         // ...but has not been disposed or sold already.
1038         $where_opts[] = "stock_id NOT IN
1039         ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1040
1041         $where_opts[] = "mb_flag='F'";
1042
1043         foreach($exclude_items as $item) {
1044         $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1045         }
1046
1047         if ($label != null)
1048                 echo "<td>$label</td>\n";
1049         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, 
1050     array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1051 }
1052
1053 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1054         $all_option=false, $submit_on_change=false)
1055 {
1056
1057         // Check if a fixed asset has been bought....
1058         $where_opts[] = "stock_id IN
1059         ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1060         // ...but has not been disposed or sold already.
1061         $where_opts[] = "stock_id NOT IN
1062         ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1063
1064         $year = get_current_fiscalyear();
1065         $y = date('Y', strtotime($year['end']));
1066
1067         // check if current fiscal year
1068         $where_opts[] = "depreciation_date < '".$y."-12-01'";
1069         $where_opts[] = "depreciation_date >= '".($y-1)."-12-01'";
1070
1071         $where_opts[] = "material_cost > 0";
1072         $where_opts[] = "mb_flag='F'";
1073
1074         if ($label != null)
1075                 echo "<td>$label</td>\n";
1076         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1077                  array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1078 }
1079
1080 //------------------------------------------------------------------------------------
1081
1082 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1083 {
1084         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1085
1086         return combo_input($name, $selected_id, $sql, 'id', 'name',
1087                 array(
1088                         'spec_option' => $none_option,
1089                         'spec_id' => ALL_NUMERIC,
1090                         'select_submit'=> $submit_on_change,
1091                         'async' => false,
1092                 ) );
1093 }
1094
1095 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1096         $submit_on_change=false)
1097 {
1098         if ($label != null)
1099                 echo "<td>$label</td>\n";
1100         echo "<td>";
1101         echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1102         echo "</td>\n";
1103 }
1104
1105 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1106         $submit_on_change=false)
1107 {
1108         echo "<tr><td class='label'>$label</td>";
1109         tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1110         echo "</tr>\n";
1111 }
1112
1113 //------------------------------------------------------------------------------------
1114
1115 function tax_groups_list($name, $selected_id=null,
1116         $none_option=false, $submit_on_change=false)
1117 {
1118         $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1119
1120         return combo_input($name, $selected_id, $sql, 'id', 'name',
1121                 array(
1122                         'order' => 'id',
1123                         'spec_option' => $none_option,
1124                         'spec_id' => ALL_NUMERIC,
1125                         'select_submit'=> $submit_on_change,
1126                         'async' => false,
1127                 ) );
1128 }
1129
1130 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1131 {
1132         if ($label != null)
1133                 echo "<td>$label</td>\n";
1134         echo "<td>";
1135         echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1136         echo "</td>\n";
1137 }
1138
1139 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1140 {
1141         echo "<tr><td class='label'>$label</td>";
1142         tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1143         echo "</tr>\n";
1144 }
1145
1146 //------------------------------------------------------------------------------------
1147
1148 function item_tax_types_list($name, $selected_id=null)
1149 {
1150         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1151         return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1152 }
1153
1154 function item_tax_types_list_cells($label, $name, $selected_id=null)
1155 {
1156         if ($label != null)
1157                 echo "<td>$label</td>\n";
1158         echo "<td>";
1159         echo item_tax_types_list($name, $selected_id);
1160         echo "</td>\n";
1161 }
1162
1163 function item_tax_types_list_row($label, $name, $selected_id=null)
1164 {
1165         echo "<tr><td class='label'>$label</td>";
1166         item_tax_types_list_cells(null, $name, $selected_id);
1167         echo "</tr>\n";
1168 }
1169
1170 //------------------------------------------------------------------------------------
1171
1172 function shippers_list($name, $selected_id=null)
1173 {
1174         $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1175         return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', 
1176                 array('order'=>array('shipper_name')));
1177 }
1178
1179 function shippers_list_cells($label, $name, $selected_id=null)
1180 {
1181         if ($label != null)
1182                 echo "<td>$label</td>\n";
1183         echo "<td>";
1184         echo shippers_list($name, $selected_id);
1185         echo "</td>\n";
1186 }
1187
1188 function shippers_list_row($label, $name, $selected_id=null)
1189 {
1190         echo "<tr><td class='label'>$label</td>";
1191         shippers_list_cells(null, $name, $selected_id);
1192         echo "</tr>\n";
1193 }
1194
1195 //-------------------------------------------------------------------------------------
1196
1197 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1198 {
1199         $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1200         return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', 
1201                 array('order'=>array('salesman_name'),
1202                         'spec_option' => $spec_opt,
1203                         'spec_id' => ALL_NUMERIC));
1204 }
1205
1206 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1207 {
1208         if ($label != null)
1209                 echo "<td>$label</td>\n";
1210         echo "<td>\n";
1211         echo sales_persons_list($name, $selected_id, $spec_opt);
1212         echo "</td>\n";
1213 }
1214
1215 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1216 {
1217         echo "<tr><td class='label'>$label</td>";
1218         sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1219         echo "</tr>\n";
1220 }
1221
1222 //------------------------------------------------------------------------------------
1223
1224 function sales_areas_list($name, $selected_id=null)
1225 {
1226         $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1227         return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1228 }
1229
1230 function sales_areas_list_cells($label, $name, $selected_id=null)
1231 {
1232         if ($label != null)
1233                 echo "<td>$label</td>\n";
1234         echo "<td>";
1235         echo sales_areas_list($name, $selected_id);
1236         echo "</td>\n";
1237 }
1238
1239 function sales_areas_list_row($label, $name, $selected_id=null)
1240 {
1241         echo "<tr><td class='label'>$label</td>";
1242         sales_areas_list_cells(null, $name, $selected_id);
1243         echo "</tr>\n";
1244 }
1245
1246 //------------------------------------------------------------------------------------
1247
1248 function sales_groups_list($name, $selected_id=null, $special_option=false)
1249 {
1250         $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1251         return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1252                 'spec_option' => $special_option===true ? ' ' : $special_option,
1253                 'order' => 'description', 'spec_id' => 0,
1254         ));
1255 }
1256
1257 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1258 {
1259         if ($label != null)
1260                 echo "<td>$label</td>\n";
1261         echo "<td>";
1262         echo sales_groups_list($name, $selected_id, $special_option);
1263         echo "</td>\n";
1264 }
1265
1266 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1267 {
1268         echo "<tr><td class='label'>$label</td>";
1269         sales_groups_list_cells(null, $name, $selected_id, $special_option);
1270         echo "</tr>\n";
1271 }
1272
1273 //------------------------------------------------------------------------------------
1274
1275 function _format_template_items($row)
1276 {
1277         return ($row[0] . "&nbsp;- &nbsp;" . _("Amount") . "&nbsp;".$row[1]);
1278 }
1279
1280 function templates_list($name, $selected_id=null, $special_option=false)
1281 {
1282         $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1283                 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1284                 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1285         return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1286                 'format' => '_format_template_items',
1287                 'spec_option' => $special_option===true ? ' ' : $special_option,
1288                 'order' => 'order_no', 'spec_id' => 0,
1289         ));
1290 }
1291
1292 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1293 {
1294         if ($label != null)
1295                 echo "<td>$label</td>\n";
1296         echo "<td>";
1297         echo templates_list($name, $selected_id, $special_option);
1298         echo "</td>\n";
1299 }
1300
1301 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1302 {
1303         echo "<tr><td class='label'>$label</td>";
1304         templates_list_cells(null, $name, $selected_id, $special_option);
1305         echo "</tr>\n";
1306 }
1307
1308 //------------------------------------------------------------------------------------
1309
1310 function workorders_list($name, $selected_id=null)
1311 {
1312         $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1313         return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1314 }
1315
1316 function workorders_list_cells($label, $name, $selected_id=null)
1317 {
1318         if ($label != null)
1319                 echo "<td>$label</td>\n";
1320         echo "<td>";
1321         echo workorders_list($name, $selected_id);
1322         echo "</td>\n";
1323 }
1324
1325 function workorders_list_row($label, $name, $selected_id=null)
1326 {
1327         echo "<tr><td class='label'>$label</td>";
1328         workorders_list_cells(null, $name, $selected_id);
1329         echo "</tr>\n";
1330 }
1331
1332 //------------------------------------------------------------------------------------
1333
1334 function payment_terms_list($name, $selected_id=null)
1335 {
1336         $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1337         return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1338 }
1339
1340 function payment_terms_list_cells($label, $name, $selected_id=null)
1341 {
1342         if ($label != null)
1343                 echo "<td>$label</td>\n";
1344         echo "<td>";
1345         echo payment_terms_list($name, $selected_id);
1346         echo "</td>\n";
1347 }
1348
1349 function payment_terms_list_row($label, $name, $selected_id=null)
1350 {
1351         echo "<tr><td class='label'>$label</td>";
1352         payment_terms_list_cells(null, $name, $selected_id);
1353         echo "</tr>\n";
1354 }
1355
1356 //------------------------------------------------------------------------------------
1357
1358 function credit_status_list($name, $selected_id=null)
1359 {
1360         $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1361         return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1362 }
1363
1364 function credit_status_list_cells($label, $name, $selected_id=null)
1365 {
1366         if ($label != null)
1367                 echo "<td>$label</td>\n";
1368         echo "<td>";
1369         echo credit_status_list($name, $selected_id);
1370         echo "</td>\n";
1371 }
1372
1373 function credit_status_list_row($label, $name, $selected_id=null)
1374 {
1375         echo "<tr><td class='label'>$label</td>";
1376         credit_status_list_cells(null, $name, $selected_id);
1377         echo "</tr>\n";
1378 }
1379
1380 //-----------------------------------------------------------------------------------------------
1381
1382 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1383 {
1384         $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1385
1386         return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1387         array(
1388                 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1389                 'spec_id' => 0,
1390                 'select_submit'=> $submit_on_change,
1391         ) );
1392 }
1393
1394 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1395 {
1396         if ($label != null)
1397                 echo "<td>$label</td>\n";
1398         echo "<td>";
1399         echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1400         echo "</td>\n";
1401 }
1402
1403 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1404 {
1405         echo "<tr><td class='label'>$label</td>";
1406         sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1407         echo "</tr>\n";
1408 }
1409
1410 //-----------------------------------------------------------------------------------------------
1411
1412 function _format_date($row)
1413 {
1414         return sql2date($row['reconciled']);
1415 }
1416
1417 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1418 {
1419         $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1420                 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1421                 GROUP BY reconciled";
1422         return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1423                 array(
1424                         'spec_option' => $special_option,
1425                         'format' => '_format_date',
1426                         'spec_id' => '',
1427                         'select_submit'=> $submit_on_change
1428                 ) );
1429 }
1430
1431 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1432 {
1433         if ($label != null)
1434                 echo "<td>$label</td>\n";
1435         echo "<td>";
1436         echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1437         echo "</td>\n";
1438 }
1439 /*
1440 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1441 {
1442         echo "<tr>\n";
1443         bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1444         echo "</tr>\n";
1445 }
1446 */
1447 //-----------------------------------------------------------------------------------------------
1448
1449 function workcenter_list($name, $selected_id=null, $all_option=false)
1450 {
1451
1452         $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1453
1454         return combo_input($name, $selected_id, $sql, 'id', 'name',
1455                 array(
1456                         'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1457                         'spec_id' => ALL_TEXT,
1458                 ) );
1459 }
1460
1461 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1462 {
1463         default_focus($name);
1464         if ($label != null)
1465                 echo "<td>$label</td>\n";
1466         echo "<td>";
1467         echo workcenter_list($name, $selected_id, $all_option);
1468         echo "</td>\n";
1469 }
1470
1471 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1472 {
1473         echo "<tr><td class='label'>$label</td>";
1474         workcenter_list_cells(null, $name, $selected_id, $all_option);
1475         echo "</tr>\n";
1476 }
1477
1478 //-----------------------------------------------------------------------------------------------
1479
1480 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1481 {
1482         $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1483                 FROM ".TB_PREF."bank_accounts";
1484
1485         return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1486                 array(
1487                         'format' => '_format_add_curr',
1488                         'select_submit'=> $submit_on_change,
1489                         'spec_option' => $spec_option,
1490                         'spec_id' => '',
1491                         'async' => false
1492                 ) );
1493 }
1494
1495 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1496 {
1497         if ($label != null)
1498                 echo "<td>$label</td>\n";
1499         echo "<td>";
1500         echo bank_accounts_list($name, $selected_id, $submit_on_change);
1501         echo "</td>\n";
1502 }
1503
1504 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1505 {
1506         echo "<tr><td class='label'>$label</td>";
1507         bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1508         echo "</tr>\n";
1509 }
1510 //-----------------------------------------------------------------------------------------------
1511
1512 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1513 {
1514
1515         $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1516                 FROM ".TB_PREF."bank_accounts
1517                 WHERE account_type=".BT_CASH;
1518
1519         if ($label != null)
1520                 echo "<tr><td class='label'>$label</td>\n";
1521         echo "<td>";
1522         echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1523                 array(
1524                         'spec_option' => $all_option,
1525                         'spec_id' => ALL_TEXT,
1526                         'format' => '_format_add_curr',
1527                         'select_submit'=> $submit_on_change,
1528                         'async' => true
1529                 ) );
1530         echo "</td></tr>\n";
1531 }
1532 //-----------------------------------------------------------------------------------------------
1533
1534 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1535 {
1536         $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1537
1538         default_focus($name);
1539         echo '<tr>';
1540         if ($label != null)
1541                 echo "<td class='label'>$label</td>\n";
1542         echo "<td>";
1543
1544         echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1545                 array(
1546                         'select_submit'=> $submit_on_change,
1547                         'async' => true,
1548                         'spec_option' =>$spec_option,
1549                         'spec_id' => -1,
1550                         'order'=> array('pos_name')
1551                 ) );
1552         echo "</td></tr>\n";
1553
1554 }
1555 //-----------------------------------------------------------------------------------------------
1556 // Payment type selector for current user.
1557 //
1558 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1559 {
1560         $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1561
1562         if ($category == PM_CASH) // only cash
1563                         $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1564         elseif ($category == PM_CREDIT) // only delayed payments
1565                         $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1566         elseif (!$prepayments)
1567                         $sql .= " WHERE days_before_due>=0";
1568
1569         return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1570                 array(
1571                         'select_submit'=> $submit_on_change,
1572                         'async' => true
1573                 ) );
1574
1575 }
1576
1577 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1578 {
1579         if ($label != null)
1580                 echo "<td class='label'>$label</td>\n";
1581         echo "<td>";
1582
1583         echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1584
1585         echo "</td>\n";
1586 }
1587 //-----------------------------------------------------------------------------------------------
1588
1589 function class_list($name, $selected_id=null, $submit_on_change=false)
1590 {
1591         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1592
1593         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1594                 array(
1595                         'select_submit'=> $submit_on_change,
1596                         'async' => false
1597                 ) );
1598
1599 }
1600
1601 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1602 {
1603         if ($label != null)
1604                 echo "<td>$label</td>\n";
1605         echo "<td>";
1606         echo class_list($name, $selected_id, $submit_on_change);
1607         echo "</td>\n";
1608 }
1609
1610 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1611 {
1612         echo "<tr><td class='label'>$label</td>";
1613         class_list_cells(null, $name, $selected_id, $submit_on_change);
1614         echo "</tr>\n";
1615 }
1616
1617 //-----------------------------------------------------------------------------------------------
1618 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1619 {
1620         $where_opts = array();
1621         if ($fixed_asset)
1622                 $where_opts[0] = "dflt_mb_flag='F'";
1623         else
1624                 $where_opts[0] = "dflt_mb_flag!='F'";
1625
1626         $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1627         return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1628                 array('order'=>'category_id',
1629                         'spec_option' => $spec_opt,
1630                         'spec_id' => -1,
1631                         'select_submit'=> $submit_on_change,
1632                         'async' => true,
1633                         'where' => $where_opts,
1634                 ));
1635 }
1636
1637 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1638 {
1639         if ($label != null)
1640                 echo "<td>$label</td>\n";
1641         echo "<td>";
1642         echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1643         echo "</td>\n";
1644 }
1645
1646 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1647 {
1648         echo "<tr><td class='label'>$label</td>";
1649         stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1650         echo "</tr>\n";
1651 }
1652
1653 //-----------------------------------------------------------------------------------------------
1654 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1655 {
1656         $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description), c.inactive FROM ".TB_PREF."stock_fa_class c, ".TB_PREF."stock_fa_class p WHERE c.parent_id=p.fa_class_id";
1657
1658         return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1659                 array('order'=>'c.fa_class_id',
1660                         'spec_option' => $spec_opt,
1661                         'spec_id' => -1,
1662                         'select_submit'=> $submit_on_change,
1663                         'async' => true,
1664                         'search_box' => true,
1665                         'search' => array("c.fa_class_id"),
1666                     'search_submit' => false,
1667                     'spec_option' => '',
1668                     'spec_id' => '',
1669                     'size' => 3,
1670                     'max' => 3,
1671                         'category' => 2,
1672                 ));
1673 }
1674
1675 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1676 {
1677         echo "<tr><td class='label'>$label</td>";
1678         echo "<td>";
1679         echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1680         echo "</td></tr>\n";
1681 }
1682
1683 //-----------------------------------------------------------------------------------------------
1684
1685 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1686 {
1687
1688         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1689
1690         return combo_input($name, $selected_id, $sql, 'id', 'name',
1691                 array(
1692                         'format' => '_format_account',
1693                         'order' => array('class_id', 'id', 'parent'),
1694                         'spec_option' =>$all_option,
1695                         'spec_id' => ALL_TEXT
1696                 ) );
1697 }
1698
1699 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1700 {
1701         if ($label != null)
1702                 echo "<td>$label</td>\n";
1703         echo "<td>";
1704         echo gl_account_types_list($name, $selected_id, $all_option, $all);
1705         echo "</td>\n";
1706 }
1707
1708 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1709 {
1710         echo "<tr><td class='label'>$label</td>";
1711         gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1712                 $all);
1713         echo "</tr>\n";
1714 }
1715
1716 //-----------------------------------------------------------------------------------------------
1717 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1718         $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1719 {
1720         if ($skip_bank_accounts)
1721                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1722                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1723                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1724                         ."ON chart.account_code=acc.account_code
1725                                 WHERE acc.account_code  IS NULL
1726                         AND chart.account_type=type.id";
1727         else
1728                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1729                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1730                         WHERE chart.account_type=type.id";
1731
1732         return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1733                 array(
1734                         'format' => '_format_account',
1735                         'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1736                         'spec_id' => '',
1737                         'type' => 2,
1738                         'order' => array('type.class_id','type.id','account_code'),
1739                         'search_box' => $cells,
1740                         'search_submit' => false,
1741                         'size' => 12,
1742                         'max' => 10,
1743                         'cells' => true,
1744                         'select_submit'=> $submit_on_change,
1745                         'async' => false,
1746                         'category' => 2,
1747                         'show_inactive' => $all
1748                 ) );
1749 }
1750
1751 function _format_account($row)
1752 {
1753         return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1754 }
1755
1756 function gl_all_accounts_list_cells($label, $name, $selected_id=null, 
1757         $skip_bank_accounts=false, $cells=false, $all_option=false, 
1758         $submit_on_change=false, $all=false)
1759 {
1760         if ($label != null)
1761                 echo "<td>$label</td>\n";
1762         echo "<td>";
1763         echo gl_all_accounts_list($name, $selected_id, 
1764                 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1765         echo "</td>\n";
1766 }
1767
1768 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
1769         $skip_bank_accounts=false, $cells=false, $all_option=false)
1770 {
1771         echo "<tr><td class='label'>$label</td>";
1772         gl_all_accounts_list_cells(null, $name, $selected_id, 
1773                 $skip_bank_accounts, $cells, $all_option);
1774         echo "</tr>\n";
1775 }
1776
1777 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1778 {
1779         $items = array();
1780         $items['0'] = strlen($name_no) ? $name_no : _("No");
1781         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1782
1783         return array_selector($name, $selected_id, $items, 
1784                 array( 
1785                         'select_submit'=> $submit_on_change,
1786                         'async' => false ) ); // FIX?
1787 }
1788
1789 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1790 {
1791         if ($label != null)
1792                 echo "<td>$label</td>\n";
1793         echo "<td>";
1794         echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1795         echo "</td>\n";
1796 }
1797
1798 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1799 {
1800         echo "<tr><td class='label'>$label</td>";
1801         yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1802         echo "</tr>\n";
1803 }
1804
1805 //------------------------------------------------------------------------------------------------
1806
1807 function languages_list($name, $selected_id=null, $all_option=false)
1808 {
1809         global $installed_languages;
1810
1811         $items = array();
1812         if ($all_option)
1813                 $items[''] = $all_option;
1814         foreach ($installed_languages as $lang)
1815                         $items[$lang['code']] = $lang['name'];
1816         return array_selector($name, $selected_id, $items);
1817 }
1818
1819 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1820 {
1821         if ($label != null)
1822                 echo "<td>$label</td>\n";
1823         echo "<td>";
1824         echo languages_list($name, $selected_id, $all_option);
1825         echo "</td>\n";
1826 }
1827
1828 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1829 {
1830         echo "<tr><td class='label'>$label</td>";
1831         languages_list_cells(null, $name, $selected_id, $all_option);
1832         echo "</tr>\n";
1833 }
1834
1835 //------------------------------------------------------------------------------------------------
1836
1837 function bank_account_types_list($name, $selected_id=null)
1838 {
1839         global $bank_account_types;
1840
1841         return array_selector($name, $selected_id, $bank_account_types);
1842 }
1843
1844 function bank_account_types_list_cells($label, $name, $selected_id=null)
1845 {
1846         if ($label != null)
1847                 echo "<td>$label</td>\n";
1848         echo "<td>";
1849         echo bank_account_types_list($name, $selected_id);
1850         echo "</td>\n";
1851 }
1852
1853 function bank_account_types_list_row($label, $name, $selected_id=null)
1854 {
1855         echo "<tr><td class='label'>$label</td>";
1856         bank_account_types_list_cells(null, $name, $selected_id);
1857         echo "</tr>\n";
1858 }
1859
1860 //------------------------------------------------------------------------------------------------
1861 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1862 {
1863         global $payment_person_types;
1864
1865         $items = array();
1866         foreach ($payment_person_types as $key=>$type)
1867         {
1868                 if ($key != PT_WORKORDER)
1869                         $items[$key] = $type;
1870         }               
1871         return array_selector($name, $selected_id, $items, 
1872                 array( 'select_submit'=> $submit_on_change ) );
1873 }
1874
1875 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1876 {
1877         if ($label != null)
1878                 echo "<td>$label</td>\n";
1879         echo "<td>";
1880         echo payment_person_types_list($name, $selected_id, $related);
1881         echo "</td>\n";
1882 }
1883
1884 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1885 {
1886         echo "<tr><td class='label'>$label</td>";
1887         payment_person_types_list_cells(null, $name, $selected_id, $related);
1888         echo "</tr>\n";
1889 }
1890
1891 //------------------------------------------------------------------------------------------------
1892
1893 function wo_types_list($name, $selected_id=null)
1894 {
1895         global $wo_types_array;
1896         
1897         return array_selector($name, $selected_id, $wo_types_array, 
1898                 array( 'select_submit'=> true, 'async' => true ) );
1899 }
1900
1901 function wo_types_list_row($label, $name, $selected_id=null)
1902 {
1903         echo "<tr><td class='label'>$label</td><td>\n";
1904         echo wo_types_list($name, $selected_id);
1905         echo "</td></tr>\n";
1906 }
1907
1908 //------------------------------------------------------------------------------------------------
1909
1910 function dateformats_list_row($label, $name, $value=null)
1911 {
1912         global $SysPrefs;
1913
1914         echo "<tr><td class='label'>$label</td>\n<td>";
1915         echo array_selector( $name, $value, $SysPrefs->dateformats );
1916         echo "</td></tr>\n";
1917 }
1918
1919 function dateseps_list_row($label, $name, $value=null)
1920 {
1921         global $SysPrefs;
1922
1923         echo "<tr><td class='label'>$label</td>\n<td>";
1924         echo array_selector( $name, $value, $SysPrefs->dateseps );
1925         echo "</td></tr>\n";
1926 }
1927
1928 function thoseps_list_row($label, $name, $value=null)
1929 {
1930         global $SysPrefs;
1931
1932         echo "<tr><td class='label'>$label</td>\n<td>";
1933         echo array_selector( $name, $value, $SysPrefs->thoseps );
1934         echo "</td></tr>\n";
1935 }
1936
1937 function decseps_list_row($label, $name, $value=null)
1938 {
1939         global $SysPrefs;
1940
1941         echo "<tr><td class='label'>$label</td>\n<td>";
1942         echo array_selector( $name, $value, $SysPrefs->decseps );
1943         echo "</td></tr>\n";
1944 }
1945
1946 function themes_list_row($label, $name, $value=null)
1947 {
1948         global $path_to_root;
1949
1950         $path = $path_to_root.'/themes/';
1951         $themes = array();
1952         $themedir = opendir($path);
1953         while(false !== ($fname = readdir($themedir)))
1954         {
1955                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1956                 {
1957                         $themes[$fname] =  $fname;
1958                 }
1959         }
1960         ksort($themes);
1961
1962         echo "<tr><td class='label'>$label</td>\n<td>";
1963         echo array_selector( $name, $value, $themes );
1964         echo "</td></tr>\n";
1965 }
1966
1967 function pagesizes_list_row($label, $name, $value=null)
1968 {
1969         global $SysPrefs;
1970
1971         $items = array();
1972         foreach ($SysPrefs->pagesizes as $pz)
1973                 $items[$pz] = $pz;
1974
1975         echo "<tr><td class='label'>$label</td>\n<td>";
1976         echo array_selector( $name, $value, $items );
1977         echo "</td></tr>\n";
1978 }
1979
1980 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1981 {
1982         global $systypes_array;
1983
1984         // emove non-voidable transactions if needed
1985         $systypes = array_diff_key($systypes_array, array_flip($exclude));
1986         return array_selector($name, $value, $systypes, 
1987                 array( 
1988                         'spec_option'=> $spec_opt,
1989                         'spec_id' => ALL_NUMERIC,
1990                         'select_submit'=> $submit_on_change,
1991                         'async' => false,
1992                         )
1993         );
1994 }
1995
1996 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1997 {
1998         if ($label != null)
1999                 echo "<td>$label</td>\n";
2000         echo "<td>";
2001         echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2002         echo "</td>\n";
2003 }
2004
2005 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2006 {
2007         echo "<tr><td class='label'>$label</td>";
2008         systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2009         echo "</tr>\n";
2010 }
2011
2012 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2013 {
2014         global $systypes_array;
2015
2016         if ($label != null)
2017                 echo "<td>$label</td>\n";
2018         echo "<td>";
2019
2020         $items = $systypes_array;
2021
2022         // exclude quotes, orders and dimensions
2023         foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2024                         unset($items[$excl]);
2025         
2026         echo array_selector($name, $value, $items, 
2027                 array( 
2028                         'spec_option'=> _("All"),
2029                         'spec_id' => -1,
2030                         'select_submit'=> $submit_on_change,
2031                         'async' => false
2032                         )
2033         );
2034         echo "</td>\n";
2035 }
2036
2037 function cust_allocations_list_cells($label, $name, $selected=null)
2038 {
2039
2040         if ($label != null)
2041                 label_cell($label);
2042         echo "<td>\n";
2043         $allocs = array( 
2044                 ALL_TEXT=>_("All Types"),
2045                 '1'=> _("Sales Invoices"),
2046                 '2'=> _("Overdue Invoices"),
2047                 '3' => _("Payments"),
2048                 '4' => _("Credit Notes"),
2049                 '5' => _("Delivery Notes")
2050         );
2051         echo array_selector($name, $selected, $allocs);
2052         echo "</td>\n";
2053 }
2054
2055 function supp_allocations_list_cell($name, $selected=null)
2056 {
2057
2058         echo "<td>\n";
2059         $allocs = array( 
2060                 ALL_TEXT=>_("All Types"),
2061                 '1'=> _("Invoices"),
2062                 '2'=> _("Overdue Invoices"),
2063                 '3' => _("Payments"),
2064                 '4' => _("Credit Notes"),
2065                 '5' => _("Overdue Credit Notes")
2066         );
2067         echo array_selector($name, $selected, $allocs);
2068         echo "</td>\n";
2069 }
2070
2071 function supp_transactions_list_cell($name, $selected=null)
2072 {
2073
2074         echo "<td>\n";
2075         $allocs = array( 
2076                 ALL_TEXT=>_("All Types"),
2077                 '6'=>_("GRNs"),
2078                 '1'=> _("Invoices"),
2079                 '2'=> _("Overdue Invoices"),
2080                 '3' => _("Payments"),
2081                 '4' => _("Credit Notes"),
2082                 '5' => _("Overdue Credit Notes")
2083         );
2084
2085         echo array_selector($name, $selected, $allocs);
2086         echo "</td>\n";
2087 }
2088
2089 function policy_list_cells($label, $name, $selected=null)
2090 {
2091         if ($label != null)
2092                 label_cell($label);
2093         echo "<td>\n";
2094         echo array_selector($name, $selected, 
2095                                 array( '' => _("Automatically put balance on back order"),
2096                                         'CAN' => _("Cancel any quantites not delivered")) );
2097         echo "</td>\n";
2098 }
2099
2100 function policy_list_row($label, $name, $selected=null)
2101 {
2102         echo "<tr><td class='label'>$label</td>";
2103         policy_list_cells(null, $name, $selected);
2104         echo "</tr>\n";
2105 }
2106
2107 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2108 {
2109         if ($label != null)
2110                 label_cell($label);
2111         echo "<td>\n";
2112         echo array_selector($name, $selected, 
2113                         array( 'Return' => _("Items Returned to Inventory Location"),
2114                                 'WriteOff' => _("Items Written Off")),
2115                         array( 'select_submit'=> $submit_on_change ) );
2116         echo "</td>\n";
2117 }
2118
2119 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2120 {
2121         echo "<tr><td class='label'>$label</td>";
2122         credit_type_list_cells(null, $name, $selected, $submit_on_change);
2123         echo "</tr>\n";
2124 }
2125
2126 function number_list($name, $selected, $from, $to, $no_option=false)
2127 {
2128         $items = array();
2129         for ($i = $from; $i <= $to; $i++)
2130                 $items[$i] = "$i";
2131
2132         return array_selector($name, $selected, $items,
2133                         array(  'spec_option' => $no_option,
2134                                         'spec_id' => ALL_NUMERIC) );
2135 }
2136
2137 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2138 {
2139         if ($label != null)
2140                 label_cell($label);
2141         echo "<td>\n";
2142         echo number_list($name, $selected, $from, $to, $no_option);
2143         echo "</td>\n";
2144 }
2145
2146 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2147 {
2148         echo "<tr><td class='label'>$label</td>";
2149         echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2150         echo "</tr>\n";
2151 }
2152
2153 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2154         $submit_on_change=true)
2155 {
2156         $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2157                 ." GROUP BY profile";
2158         $result = db_query($sql, 'cannot get all profile names');
2159         $profiles = array();
2160         while($myrow=db_fetch($result)) {
2161                 $profiles[$myrow['profile']] = $myrow['profile'];
2162         }
2163
2164         echo "<tr>";
2165         if ($label != null)
2166                 echo "<td class='label'>$label</td>\n";
2167         echo "<td>";
2168
2169         echo array_selector($name, $selected_id, $profiles, 
2170                 array( 'select_submit'=> $submit_on_change,
2171                         'spec_option'=>$spec_opt,
2172                         'spec_id' => ''
2173                  ));
2174
2175         echo "</td></tr>\n";
2176 }
2177
2178 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2179 {
2180         static $printers; // query only once for page display
2181
2182         if (!$printers) {
2183                 $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; 
2184                 $result = db_query($sql, 'cannot get all printers');
2185                 $printers = array();
2186                 while($myrow=db_fetch($result)) {
2187                         $printers[$myrow['id']] = $myrow['name'].'&nbsp;-&nbsp;'.$myrow['description'];
2188                 }
2189         }
2190         return array_selector($name, $selected_id, $printers, 
2191                 array( 'select_submit'=> $submit_on_change,
2192                         'spec_option'=>$spec_opt,
2193                         'spec_id' => ''
2194                  ));
2195 }
2196
2197 //------------------------------------------------------------------------------------------------
2198
2199 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2200 {
2201         $where = false;
2202         $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2203         if ($type != null)
2204                 $sql .= " WHERE type=$type";
2205
2206         return combo_input($name, $selected_id, $sql, 'id', 'description',
2207                 array(
2208                         'spec_id' => '',
2209                         'order' => 'description',
2210                         'select_submit'=> $submit_on_change,
2211                         'async' => false
2212                 ) );
2213
2214 }
2215
2216 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2217 {
2218         if ($label != null)
2219                 echo "<td>$label</td>\n";
2220         echo "<td>";    
2221         echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2222         echo "</td>";
2223 }
2224
2225 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2226 {
2227         echo "<tr><td class='label'>$label</td>";
2228         quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2229         echo "</tr>\n";
2230 }
2231
2232
2233 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2234 {
2235         global $quick_actions;
2236         
2237         echo "<tr><td class='label'>$label</td><td>";
2238         echo array_selector($name, $selected_id, $quick_actions, 
2239                 array( 
2240                         'select_submit'=> $submit_on_change
2241                 ) );
2242         echo "</td></tr>\n";
2243 }
2244
2245 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2246 {
2247         global $quick_entry_types;
2248                 
2249         echo "<tr><td class='label'>$label</td><td>";
2250         echo array_selector($name, $selected_id, $quick_entry_types, 
2251                 array( 
2252                         'select_submit'=> $submit_on_change
2253                         ) );
2254         echo "</td></tr>\n";
2255 }
2256
2257 function record_status_list_row($label, $name) {
2258         return yesno_list_row($label, $name, null,      _('Inactive'), _('Active'));
2259 }
2260
2261 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2262 {
2263         global $class_types;
2264         
2265         echo "<tr><td class='label'>$label</td><td>";
2266         echo array_selector($name, $selected_id, $class_types, 
2267                 array( 
2268                         'select_submit'=> $submit_on_change
2269                 ) );
2270         echo "</td></tr>\n";
2271 }
2272
2273 //------------------------------------------------------------------------------------------------
2274
2275 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2276         $show_inactive = false)
2277 {
2278
2279         $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2280
2281         return combo_input($name, $selected_id, $sql, 'id', 'description',
2282                 array(
2283                         'spec_option'=>$new_item ? _("New role") : false,
2284                         'spec_id' => '',
2285                         'select_submit'=> $submit_on_change,
2286                         'show_inactive' => $show_inactive
2287                 ) );
2288 }
2289
2290 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2291         $show_inactive = false)
2292 {
2293         if ($label != null)
2294                 echo "<td>$label</td>\n";
2295         echo "<td>";
2296         echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2297         echo "</td>\n";
2298 }
2299
2300 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2301         $show_inactive = false)
2302 {
2303         echo "<tr><td class='label'>$label</td>";
2304         security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2305         echo "</tr>\n";
2306 }
2307
2308 function tab_list_row($label, $name, $selected_id=null)
2309 {
2310         global $installed_extensions;
2311         
2312         $tabs = array();
2313         foreach ($_SESSION['App']->applications as $app) {
2314                 $tabs[$app->id] = access_string($app->name, true);
2315         }
2316         echo "<tr>\n";
2317         echo "<td class='label'>$label</td><td>\n";
2318         echo array_selector($name, $selected_id, $tabs);
2319         echo "</td></tr>\n";
2320 }
2321
2322 //-----------------------------------------------------------------------------------------------
2323
2324 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2325 {
2326         // Get tags
2327         global $path_to_root;
2328         include_once($path_to_root . "/admin/db/tags_db.inc");
2329         $results = get_tags($type, $all);
2330
2331         while ($tag = db_fetch($results))
2332                 $tags[$tag['id']] = $tag['name'];
2333         
2334         if (!isset($tags)) {
2335                 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2336                 $spec_opt = false;
2337         }
2338         return array_selector($name, null, $tags,
2339                 array(
2340                         'multi' => $multi,
2341                         'height' => $height,
2342                         'spec_option'=> $spec_opt,
2343                         'spec_id' => -1,
2344                 ) );
2345 }
2346
2347 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2348 {
2349         if ($label != null)
2350                 echo "<td>$label</td>\n";
2351         echo "<td>\n";
2352         echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2353         echo "</td>\n";
2354         
2355 }
2356
2357 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2358 {
2359         echo "<tr><td class='label'>$label</td>";
2360         tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2361         echo "</tr>\n"; 
2362 }
2363
2364 //---------------------------------------------------------------------------------------------
2365 //      List of sets of active extensions 
2366 //
2367 function extset_list($name, $value=null, $submit_on_change=false)
2368 {
2369         global $db_connections;
2370
2371         $items = array();
2372         foreach ($db_connections as $comp)
2373                 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2374         return array_selector( $name, $value, $items,
2375                 array(
2376                         'spec_option'=> _("Available and/or installed"),
2377                         'spec_id' => -1,
2378                         'select_submit'=> $submit_on_change,
2379                         'async' => true
2380                 ));
2381 }
2382
2383 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2384 {
2385
2386         $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2387
2388         $multi = false;
2389         $groups = false;
2390         $where = array();
2391         if (@$filter['class']) {
2392                 $where[] = 'type='.db_escape($filter['class']);
2393         } else
2394                 $groups = 'type';
2395         if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2396         if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2397         if (@$filter['multi']) { // contact category selector for person
2398                 $multi = true;
2399         }
2400
2401         return combo_input($name, $selected_id, $sql, 'id', 'name',
2402                 array(
2403                         'multi' => $multi,
2404                         'height' => $multi ? 5:1,
2405                         'category' => $groups,
2406                         'select_submit'=> $submit_on_change,
2407                         'async' => true,
2408                         'where' => $where
2409                 ));
2410 }
2411
2412 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2413 {
2414         echo "<tr><td class='label'>$label</td><td>";
2415         echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2416         echo "</td></tr>\n";
2417 }
2418
2419 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2420 {
2421         global $pterm_types;
2422         
2423         echo "<tr><td class='label'>$label</td><td>";
2424         echo array_selector($name, $selected_id, $pterm_types, 
2425                 array( 
2426                         'select_submit'=> $submit_on_change
2427                 ) );
2428         echo "</td></tr>\n";
2429 }
2430
2431 function coa_list_row($label, $name, $value=null)
2432 {
2433         global $path_to_root, $installed_extensions;
2434
2435         $path = $path_to_root.'/sql/';
2436         $coas = array();
2437         $sqldir = opendir($path);
2438         while (false !== ($fname = readdir($sqldir)))
2439         {
2440                 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2441                 {
2442                         $ext = array_search_value($fname, $installed_extensions, 'sql');
2443                         if ($ext!=null) {
2444                                 $descr = $ext['name'];
2445                         } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2446                                 $descr = _("Standard new company American COA (4 digit)");
2447                         } elseif ($fname == 'en_US-demo.sql') {
2448                                 $descr = _("Standard American COA (4 digit) with demo data");
2449                         } else
2450                                 $descr = $fname;
2451
2452                         $coas[$fname] =  $descr;
2453                 }
2454         }
2455         ksort($coas);
2456
2457         echo "<tr><td class='label'>$label</td>\n<td>";
2458         echo array_selector( $name, $value, $coas );
2459         echo "</td></tr>\n";
2460 }
2461
2462 function payment_services($name)
2463 {
2464         global $payment_services;
2465
2466         $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2467
2468         return array_selector($name, null, $services, array(
2469                         'spec_option'=> _("No payment Link"),
2470                         'spec_id' => '',
2471                 ));
2472 }
2473
2474 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2475 {
2476         global $tax_algorithms;
2477         
2478         return array_selector($name, $value, $tax_algorithms, 
2479                 array( 
2480                         'select_submit'=> $submit_on_change,
2481                         'async' => true,
2482                         )
2483         );
2484 }
2485
2486 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2487 {
2488         if ($label != null)
2489                 echo "<td>$label</td>\n";
2490         echo "<td>";
2491         echo tax_algorithm_list($name, $value, $submit_on_change);
2492         echo "</td>\n";
2493 }
2494
2495 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2496 {
2497         echo "<tr><td class='label'>$label</td>";
2498         tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2499         echo "</tr>\n";
2500 }
2501
2502 function refline_list($name, $type, $value=null, $spec_option=false)
2503 {
2504         $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2505
2506         $where = array();
2507
2508         if (isset($type))
2509                 $where = array('`trans_type`='.db_escape($type));
2510
2511         return combo_input($name, $value, $sql, 'id', 'prefix',
2512                 array(
2513                         'order'=>array('prefix'),
2514                         'spec_option' => $spec_option,
2515                         'spec_id' => '',
2516                         'type' => 2,
2517                         'where' => $where,
2518                         'select_submit' => true,
2519                         )
2520                 );
2521 }
2522
2523 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2524 {
2525         echo "<tr>";
2526         if ($label != null)
2527                 echo "<td class='label'>$label</td>\n";
2528         echo "<td>";
2529
2530         echo refline_list($name, $type, $selected_id, $spec_option);
2531         echo "</td></tr>\n";
2532 }
2533
2534
2535 //----------------------------------------------------------------------------------------------
2536
2537 function subledger_list($name, $account, $selected_id=null)
2538 {
2539
2540         $type = is_subledger_account($account);
2541         if (!$type)
2542                 return '';
2543
2544         if($type > 0)
2545                 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name 
2546                 FROM "
2547                 .TB_PREF."debtors_master d,"
2548                 .TB_PREF."cust_branch c
2549                 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2550         else
2551                 $sql = "SELECT supplier_id as id, supp_ref as name 
2552                 FROM "
2553                 .TB_PREF."suppliers s
2554                 WHERE s.payable_account=".db_escape($account);
2555
2556         $mode = get_company_pref('no_customer_list');
2557
2558         return combo_input($name, $selected_id, $sql, 'id', 'name',
2559         array(
2560                 'type' => 1,
2561                 'size' => 20,
2562                 'async' => false,
2563         ) );
2564 }
2565
2566 function subledger_list_cells($label, $name, $account, $selected_id=null)
2567 {
2568         if ($label != null)
2569                 echo "<td>$label</td>\n";
2570         echo "<td nowrap>";
2571         echo subledger_list($name, $account, $selected_id);
2572         echo "</td>\n";
2573 }
2574
2575 function subledger_list_row($label, $name, $selected_id=null, $all_option = false, 
2576         $submit_on_change=false, $show_inactive=false, $editkey = false)
2577 {
2578         echo "<tr><td class='label'>$label</td><td nowrap>";
2579         echo subledger_list($name, $account, $selected_id);
2580         echo "</td>\n</tr>\n";
2581 }
2582
2583 function accounts_type_list_row($label, $name, $selected_id=null)
2584 {
2585         echo "<tr>";
2586         if ($label != null)
2587                 echo "<td class='label'>$label</td>\n";
2588         echo "<td>";
2589         $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2590         echo array_selector($name, $selected_id, $sel); 
2591         echo "</td></tr>\n";
2592 }
2593
2594 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2595 {
2596     $where = false;
2597     $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2598
2599     if ($label != null)
2600         echo "<td>$label</td>\n";
2601     echo "<td>";
2602
2603     echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2604         array(
2605             'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2606             'spec_id' => '',
2607             'order' => 'real_name',
2608             'select_submit'=> $submit_on_change,
2609             'async' => false
2610         ) );
2611     echo "</td>";
2612
2613 }
2614
2615 function collations_list_row($label, $name, $selected_id=null)
2616 {
2617         global $supported_collations;
2618
2619         echo "<tr>";
2620         if ($label != null)
2621                 echo "<td class='label'>$label</td>\n";
2622         echo "<td>";
2623
2624         echo array_selector($name, $selected_id, $supported_collations, 
2625                 array('select_submit'=> false) );
2626         echo "</td></tr>\n";
2627 }