Added fixed asset related db changes in upgrade class.
[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 "
1657                 .TB_PREF."stock_fa_class c, "
1658                 .TB_PREF."stock_fa_class p 
1659         WHERE c.parent_id=p.fa_class_id";
1660
1661         return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1662                 array('order'=>'c.fa_class_id',
1663                         'spec_option' => $spec_opt,
1664                         'spec_id' => -1,
1665                         'select_submit'=> $submit_on_change,
1666                         'async' => true,
1667                         'search_box' => true,
1668                         'search' => array("c.fa_class_id"),
1669                     'search_submit' => false,
1670                     'spec_option' => '',
1671                     'spec_id' => '',
1672                     'size' => 3,
1673                     'max' => 3,
1674                         'category' => 2,
1675                 ));
1676 }
1677
1678 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1679 {
1680         echo "<tr><td class='label'>$label</td>";
1681         echo "<td>";
1682         echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1683         echo "</td></tr>\n";
1684 }
1685
1686 //-----------------------------------------------------------------------------------------------
1687
1688 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1689 {
1690
1691         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1692
1693         return combo_input($name, $selected_id, $sql, 'id', 'name',
1694                 array(
1695                         'format' => '_format_account',
1696                         'order' => array('class_id', 'id', 'parent'),
1697                         'spec_option' =>$all_option,
1698                         'spec_id' => ALL_TEXT
1699                 ) );
1700 }
1701
1702 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1703 {
1704         if ($label != null)
1705                 echo "<td>$label</td>\n";
1706         echo "<td>";
1707         echo gl_account_types_list($name, $selected_id, $all_option, $all);
1708         echo "</td>\n";
1709 }
1710
1711 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1712 {
1713         echo "<tr><td class='label'>$label</td>";
1714         gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1715                 $all);
1716         echo "</tr>\n";
1717 }
1718
1719 //-----------------------------------------------------------------------------------------------
1720 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1721         $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1722 {
1723         if ($skip_bank_accounts)
1724                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1725                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1726                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1727                         ."ON chart.account_code=acc.account_code
1728                                 WHERE acc.account_code  IS NULL
1729                         AND chart.account_type=type.id";
1730         else
1731                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1732                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1733                         WHERE chart.account_type=type.id";
1734
1735         return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1736                 array(
1737                         'format' => '_format_account',
1738                         'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1739                         'spec_id' => '',
1740                         'type' => 2,
1741                         'order' => array('type.class_id','type.id','account_code'),
1742                         'search_box' => $cells,
1743                         'search_submit' => false,
1744                         'size' => 12,
1745                         'max' => 10,
1746                         'cells' => true,
1747                         'select_submit'=> $submit_on_change,
1748                         'async' => false,
1749                         'category' => 2,
1750                         'show_inactive' => $all
1751                 ) );
1752 }
1753
1754 function _format_account($row)
1755 {
1756         return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1757 }
1758
1759 function gl_all_accounts_list_cells($label, $name, $selected_id=null, 
1760         $skip_bank_accounts=false, $cells=false, $all_option=false, 
1761         $submit_on_change=false, $all=false)
1762 {
1763         if ($label != null)
1764                 echo "<td>$label</td>\n";
1765         echo "<td>";
1766         echo gl_all_accounts_list($name, $selected_id, 
1767                 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1768         echo "</td>\n";
1769 }
1770
1771 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
1772         $skip_bank_accounts=false, $cells=false, $all_option=false)
1773 {
1774         echo "<tr><td class='label'>$label</td>";
1775         gl_all_accounts_list_cells(null, $name, $selected_id, 
1776                 $skip_bank_accounts, $cells, $all_option);
1777         echo "</tr>\n";
1778 }
1779
1780 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1781 {
1782         $items = array();
1783         $items['0'] = strlen($name_no) ? $name_no : _("No");
1784         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1785
1786         return array_selector($name, $selected_id, $items, 
1787                 array( 
1788                         'select_submit'=> $submit_on_change,
1789                         'async' => false ) ); // FIX?
1790 }
1791
1792 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1793 {
1794         if ($label != null)
1795                 echo "<td>$label</td>\n";
1796         echo "<td>";
1797         echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1798         echo "</td>\n";
1799 }
1800
1801 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1802 {
1803         echo "<tr><td class='label'>$label</td>";
1804         yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1805         echo "</tr>\n";
1806 }
1807
1808 //------------------------------------------------------------------------------------------------
1809
1810 function languages_list($name, $selected_id=null, $all_option=false)
1811 {
1812         global $installed_languages;
1813
1814         $items = array();
1815         if ($all_option)
1816                 $items[''] = $all_option;
1817         foreach ($installed_languages as $lang)
1818                         $items[$lang['code']] = $lang['name'];
1819         return array_selector($name, $selected_id, $items);
1820 }
1821
1822 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1823 {
1824         if ($label != null)
1825                 echo "<td>$label</td>\n";
1826         echo "<td>";
1827         echo languages_list($name, $selected_id, $all_option);
1828         echo "</td>\n";
1829 }
1830
1831 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1832 {
1833         echo "<tr><td class='label'>$label</td>";
1834         languages_list_cells(null, $name, $selected_id, $all_option);
1835         echo "</tr>\n";
1836 }
1837
1838 //------------------------------------------------------------------------------------------------
1839
1840 function bank_account_types_list($name, $selected_id=null)
1841 {
1842         global $bank_account_types;
1843
1844         return array_selector($name, $selected_id, $bank_account_types);
1845 }
1846
1847 function bank_account_types_list_cells($label, $name, $selected_id=null)
1848 {
1849         if ($label != null)
1850                 echo "<td>$label</td>\n";
1851         echo "<td>";
1852         echo bank_account_types_list($name, $selected_id);
1853         echo "</td>\n";
1854 }
1855
1856 function bank_account_types_list_row($label, $name, $selected_id=null)
1857 {
1858         echo "<tr><td class='label'>$label</td>";
1859         bank_account_types_list_cells(null, $name, $selected_id);
1860         echo "</tr>\n";
1861 }
1862
1863 //------------------------------------------------------------------------------------------------
1864 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1865 {
1866         global $payment_person_types;
1867
1868         $items = array();
1869         foreach ($payment_person_types as $key=>$type)
1870         {
1871                 if ($key != PT_WORKORDER)
1872                         $items[$key] = $type;
1873         }               
1874         return array_selector($name, $selected_id, $items, 
1875                 array( 'select_submit'=> $submit_on_change ) );
1876 }
1877
1878 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1879 {
1880         if ($label != null)
1881                 echo "<td>$label</td>\n";
1882         echo "<td>";
1883         echo payment_person_types_list($name, $selected_id, $related);
1884         echo "</td>\n";
1885 }
1886
1887 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1888 {
1889         echo "<tr><td class='label'>$label</td>";
1890         payment_person_types_list_cells(null, $name, $selected_id, $related);
1891         echo "</tr>\n";
1892 }
1893
1894 //------------------------------------------------------------------------------------------------
1895
1896 function wo_types_list($name, $selected_id=null)
1897 {
1898         global $wo_types_array;
1899         
1900         return array_selector($name, $selected_id, $wo_types_array, 
1901                 array( 'select_submit'=> true, 'async' => true ) );
1902 }
1903
1904 function wo_types_list_row($label, $name, $selected_id=null)
1905 {
1906         echo "<tr><td class='label'>$label</td><td>\n";
1907         echo wo_types_list($name, $selected_id);
1908         echo "</td></tr>\n";
1909 }
1910
1911 //------------------------------------------------------------------------------------------------
1912
1913 function dateformats_list_row($label, $name, $value=null)
1914 {
1915         global $SysPrefs;
1916
1917         echo "<tr><td class='label'>$label</td>\n<td>";
1918         echo array_selector( $name, $value, $SysPrefs->dateformats );
1919         echo "</td></tr>\n";
1920 }
1921
1922 function dateseps_list_row($label, $name, $value=null)
1923 {
1924         global $SysPrefs;
1925
1926         echo "<tr><td class='label'>$label</td>\n<td>";
1927         echo array_selector( $name, $value, $SysPrefs->dateseps );
1928         echo "</td></tr>\n";
1929 }
1930
1931 function thoseps_list_row($label, $name, $value=null)
1932 {
1933         global $SysPrefs;
1934
1935         echo "<tr><td class='label'>$label</td>\n<td>";
1936         echo array_selector( $name, $value, $SysPrefs->thoseps );
1937         echo "</td></tr>\n";
1938 }
1939
1940 function decseps_list_row($label, $name, $value=null)
1941 {
1942         global $SysPrefs;
1943
1944         echo "<tr><td class='label'>$label</td>\n<td>";
1945         echo array_selector( $name, $value, $SysPrefs->decseps );
1946         echo "</td></tr>\n";
1947 }
1948
1949 function themes_list_row($label, $name, $value=null)
1950 {
1951         global $path_to_root;
1952
1953         $path = $path_to_root.'/themes/';
1954         $themes = array();
1955         $themedir = opendir($path);
1956         while(false !== ($fname = readdir($themedir)))
1957         {
1958                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1959                 {
1960                         $themes[$fname] =  $fname;
1961                 }
1962         }
1963         ksort($themes);
1964
1965         echo "<tr><td class='label'>$label</td>\n<td>";
1966         echo array_selector( $name, $value, $themes );
1967         echo "</td></tr>\n";
1968 }
1969
1970 function pagesizes_list_row($label, $name, $value=null)
1971 {
1972         global $SysPrefs;
1973
1974         $items = array();
1975         foreach ($SysPrefs->pagesizes as $pz)
1976                 $items[$pz] = $pz;
1977
1978         echo "<tr><td class='label'>$label</td>\n<td>";
1979         echo array_selector( $name, $value, $items );
1980         echo "</td></tr>\n";
1981 }
1982
1983 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1984 {
1985         global $systypes_array;
1986
1987         // emove non-voidable transactions if needed
1988         $systypes = array_diff_key($systypes_array, array_flip($exclude));
1989         return array_selector($name, $value, $systypes, 
1990                 array( 
1991                         'spec_option'=> $spec_opt,
1992                         'spec_id' => ALL_NUMERIC,
1993                         'select_submit'=> $submit_on_change,
1994                         'async' => false,
1995                         )
1996         );
1997 }
1998
1999 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2000 {
2001         if ($label != null)
2002                 echo "<td>$label</td>\n";
2003         echo "<td>";
2004         echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2005         echo "</td>\n";
2006 }
2007
2008 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2009 {
2010         echo "<tr><td class='label'>$label</td>";
2011         systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2012         echo "</tr>\n";
2013 }
2014
2015 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2016 {
2017         global $systypes_array;
2018
2019         if ($label != null)
2020                 echo "<td>$label</td>\n";
2021         echo "<td>";
2022
2023         $items = $systypes_array;
2024
2025         // exclude quotes, orders and dimensions
2026         foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2027                         unset($items[$excl]);
2028         
2029         echo array_selector($name, $value, $items, 
2030                 array( 
2031                         'spec_option'=> _("All"),
2032                         'spec_id' => -1,
2033                         'select_submit'=> $submit_on_change,
2034                         'async' => false
2035                         )
2036         );
2037         echo "</td>\n";
2038 }
2039
2040 function cust_allocations_list_cells($label, $name, $selected=null)
2041 {
2042
2043         if ($label != null)
2044                 label_cell($label);
2045         echo "<td>\n";
2046         $allocs = array( 
2047                 ALL_TEXT=>_("All Types"),
2048                 '1'=> _("Sales Invoices"),
2049                 '2'=> _("Overdue Invoices"),
2050                 '3' => _("Payments"),
2051                 '4' => _("Credit Notes"),
2052                 '5' => _("Delivery Notes")
2053         );
2054         echo array_selector($name, $selected, $allocs);
2055         echo "</td>\n";
2056 }
2057
2058 function supp_allocations_list_cell($name, $selected=null)
2059 {
2060
2061         echo "<td>\n";
2062         $allocs = array( 
2063                 ALL_TEXT=>_("All Types"),
2064                 '1'=> _("Invoices"),
2065                 '2'=> _("Overdue Invoices"),
2066                 '3' => _("Payments"),
2067                 '4' => _("Credit Notes"),
2068                 '5' => _("Overdue Credit Notes")
2069         );
2070         echo array_selector($name, $selected, $allocs);
2071         echo "</td>\n";
2072 }
2073
2074 function supp_transactions_list_cell($name, $selected=null)
2075 {
2076
2077         echo "<td>\n";
2078         $allocs = array( 
2079                 ALL_TEXT=>_("All Types"),
2080                 '6'=>_("GRNs"),
2081                 '1'=> _("Invoices"),
2082                 '2'=> _("Overdue Invoices"),
2083                 '3' => _("Payments"),
2084                 '4' => _("Credit Notes"),
2085                 '5' => _("Overdue Credit Notes")
2086         );
2087
2088         echo array_selector($name, $selected, $allocs);
2089         echo "</td>\n";
2090 }
2091
2092 function policy_list_cells($label, $name, $selected=null)
2093 {
2094         if ($label != null)
2095                 label_cell($label);
2096         echo "<td>\n";
2097         echo array_selector($name, $selected, 
2098                                 array( '' => _("Automatically put balance on back order"),
2099                                         'CAN' => _("Cancel any quantites not delivered")) );
2100         echo "</td>\n";
2101 }
2102
2103 function policy_list_row($label, $name, $selected=null)
2104 {
2105         echo "<tr><td class='label'>$label</td>";
2106         policy_list_cells(null, $name, $selected);
2107         echo "</tr>\n";
2108 }
2109
2110 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2111 {
2112         if ($label != null)
2113                 label_cell($label);
2114         echo "<td>\n";
2115         echo array_selector($name, $selected, 
2116                         array( 'Return' => _("Items Returned to Inventory Location"),
2117                                 'WriteOff' => _("Items Written Off")),
2118                         array( 'select_submit'=> $submit_on_change ) );
2119         echo "</td>\n";
2120 }
2121
2122 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2123 {
2124         echo "<tr><td class='label'>$label</td>";
2125         credit_type_list_cells(null, $name, $selected, $submit_on_change);
2126         echo "</tr>\n";
2127 }
2128
2129 function number_list($name, $selected, $from, $to, $no_option=false)
2130 {
2131         $items = array();
2132         for ($i = $from; $i <= $to; $i++)
2133                 $items[$i] = "$i";
2134
2135         return array_selector($name, $selected, $items,
2136                         array(  'spec_option' => $no_option,
2137                                         'spec_id' => ALL_NUMERIC) );
2138 }
2139
2140 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2141 {
2142         if ($label != null)
2143                 label_cell($label);
2144         echo "<td>\n";
2145         echo number_list($name, $selected, $from, $to, $no_option);
2146         echo "</td>\n";
2147 }
2148
2149 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2150 {
2151         echo "<tr><td class='label'>$label</td>";
2152         echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2153         echo "</tr>\n";
2154 }
2155
2156 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2157         $submit_on_change=true)
2158 {
2159         $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2160                 ." GROUP BY profile";
2161         $result = db_query($sql, 'cannot get all profile names');
2162         $profiles = array();
2163         while($myrow=db_fetch($result)) {
2164                 $profiles[$myrow['profile']] = $myrow['profile'];
2165         }
2166
2167         echo "<tr>";
2168         if ($label != null)
2169                 echo "<td class='label'>$label</td>\n";
2170         echo "<td>";
2171
2172         echo array_selector($name, $selected_id, $profiles, 
2173                 array( 'select_submit'=> $submit_on_change,
2174                         'spec_option'=>$spec_opt,
2175                         'spec_id' => ''
2176                  ));
2177
2178         echo "</td></tr>\n";
2179 }
2180
2181 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2182 {
2183         static $printers; // query only once for page display
2184
2185         if (!$printers) {
2186                 $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; 
2187                 $result = db_query($sql, 'cannot get all printers');
2188                 $printers = array();
2189                 while($myrow=db_fetch($result)) {
2190                         $printers[$myrow['id']] = $myrow['name'].'&nbsp;-&nbsp;'.$myrow['description'];
2191                 }
2192         }
2193         return array_selector($name, $selected_id, $printers, 
2194                 array( 'select_submit'=> $submit_on_change,
2195                         'spec_option'=>$spec_opt,
2196                         'spec_id' => ''
2197                  ));
2198 }
2199
2200 //------------------------------------------------------------------------------------------------
2201
2202 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2203 {
2204         $where = false;
2205         $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2206         if ($type != null)
2207                 $sql .= " WHERE type=$type";
2208
2209         return combo_input($name, $selected_id, $sql, 'id', 'description',
2210                 array(
2211                         'spec_id' => '',
2212                         'order' => 'description',
2213                         'select_submit'=> $submit_on_change,
2214                         'async' => false
2215                 ) );
2216
2217 }
2218
2219 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2220 {
2221         if ($label != null)
2222                 echo "<td>$label</td>\n";
2223         echo "<td>";    
2224         echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2225         echo "</td>";
2226 }
2227
2228 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2229 {
2230         echo "<tr><td class='label'>$label</td>";
2231         quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2232         echo "</tr>\n";
2233 }
2234
2235
2236 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2237 {
2238         global $quick_actions;
2239         
2240         echo "<tr><td class='label'>$label</td><td>";
2241         echo array_selector($name, $selected_id, $quick_actions, 
2242                 array( 
2243                         'select_submit'=> $submit_on_change
2244                 ) );
2245         echo "</td></tr>\n";
2246 }
2247
2248 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2249 {
2250         global $quick_entry_types;
2251                 
2252         echo "<tr><td class='label'>$label</td><td>";
2253         echo array_selector($name, $selected_id, $quick_entry_types, 
2254                 array( 
2255                         'select_submit'=> $submit_on_change
2256                         ) );
2257         echo "</td></tr>\n";
2258 }
2259
2260 function record_status_list_row($label, $name) {
2261         return yesno_list_row($label, $name, null,      _('Inactive'), _('Active'));
2262 }
2263
2264 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2265 {
2266         global $class_types;
2267         
2268         echo "<tr><td class='label'>$label</td><td>";
2269         echo array_selector($name, $selected_id, $class_types, 
2270                 array( 
2271                         'select_submit'=> $submit_on_change
2272                 ) );
2273         echo "</td></tr>\n";
2274 }
2275
2276 //------------------------------------------------------------------------------------------------
2277
2278 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2279         $show_inactive = false)
2280 {
2281
2282         $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2283
2284         return combo_input($name, $selected_id, $sql, 'id', 'description',
2285                 array(
2286                         'spec_option'=>$new_item ? _("New role") : false,
2287                         'spec_id' => '',
2288                         'select_submit'=> $submit_on_change,
2289                         'show_inactive' => $show_inactive
2290                 ) );
2291 }
2292
2293 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2294         $show_inactive = false)
2295 {
2296         if ($label != null)
2297                 echo "<td>$label</td>\n";
2298         echo "<td>";
2299         echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2300         echo "</td>\n";
2301 }
2302
2303 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2304         $show_inactive = false)
2305 {
2306         echo "<tr><td class='label'>$label</td>";
2307         security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2308         echo "</tr>\n";
2309 }
2310
2311 function tab_list_row($label, $name, $selected_id=null)
2312 {
2313         global $installed_extensions;
2314         
2315         $tabs = array();
2316         foreach ($_SESSION['App']->applications as $app) {
2317                 $tabs[$app->id] = access_string($app->name, true);
2318         }
2319         echo "<tr>\n";
2320         echo "<td class='label'>$label</td><td>\n";
2321         echo array_selector($name, $selected_id, $tabs);
2322         echo "</td></tr>\n";
2323 }
2324
2325 //-----------------------------------------------------------------------------------------------
2326
2327 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2328 {
2329         // Get tags
2330         global $path_to_root;
2331         include_once($path_to_root . "/admin/db/tags_db.inc");
2332         $results = get_tags($type, $all);
2333
2334         while ($tag = db_fetch($results))
2335                 $tags[$tag['id']] = $tag['name'];
2336         
2337         if (!isset($tags)) {
2338                 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2339                 $spec_opt = false;
2340         }
2341         return array_selector($name, null, $tags,
2342                 array(
2343                         'multi' => $multi,
2344                         'height' => $height,
2345                         'spec_option'=> $spec_opt,
2346                         'spec_id' => -1,
2347                 ) );
2348 }
2349
2350 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2351 {
2352         if ($label != null)
2353                 echo "<td>$label</td>\n";
2354         echo "<td>\n";
2355         echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2356         echo "</td>\n";
2357         
2358 }
2359
2360 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2361 {
2362         echo "<tr><td class='label'>$label</td>";
2363         tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2364         echo "</tr>\n"; 
2365 }
2366
2367 //---------------------------------------------------------------------------------------------
2368 //      List of sets of active extensions 
2369 //
2370 function extset_list($name, $value=null, $submit_on_change=false)
2371 {
2372         global $db_connections;
2373
2374         $items = array();
2375         foreach ($db_connections as $comp)
2376                 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2377         return array_selector( $name, $value, $items,
2378                 array(
2379                         'spec_option'=> _("Available and/or installed"),
2380                         'spec_id' => -1,
2381                         'select_submit'=> $submit_on_change,
2382                         'async' => true
2383                 ));
2384 }
2385
2386 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2387 {
2388
2389         $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2390
2391         $multi = false;
2392         $groups = false;
2393         $where = array();
2394         if (@$filter['class']) {
2395                 $where[] = 'type='.db_escape($filter['class']);
2396         } else
2397                 $groups = 'type';
2398         if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2399         if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2400         if (@$filter['multi']) { // contact category selector for person
2401                 $multi = true;
2402         }
2403
2404         return combo_input($name, $selected_id, $sql, 'id', 'name',
2405                 array(
2406                         'multi' => $multi,
2407                         'height' => $multi ? 5:1,
2408                         'category' => $groups,
2409                         'select_submit'=> $submit_on_change,
2410                         'async' => true,
2411                         'where' => $where
2412                 ));
2413 }
2414
2415 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2416 {
2417         echo "<tr><td class='label'>$label</td><td>";
2418         echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2419         echo "</td></tr>\n";
2420 }
2421
2422 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2423 {
2424         global $pterm_types;
2425         
2426         echo "<tr><td class='label'>$label</td><td>";
2427         echo array_selector($name, $selected_id, $pterm_types, 
2428                 array( 
2429                         'select_submit'=> $submit_on_change
2430                 ) );
2431         echo "</td></tr>\n";
2432 }
2433
2434 function coa_list_row($label, $name, $value=null)
2435 {
2436         global $path_to_root, $installed_extensions;
2437
2438         $path = $path_to_root.'/sql/';
2439         $coas = array();
2440         $sqldir = opendir($path);
2441         while (false !== ($fname = readdir($sqldir)))
2442         {
2443                 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2444                 {
2445                         $ext = array_search_value($fname, $installed_extensions, 'sql');
2446                         if ($ext!=null) {
2447                                 $descr = $ext['name'];
2448                         } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2449                                 $descr = _("Standard new company American COA (4 digit)");
2450                         } elseif ($fname == 'en_US-demo.sql') {
2451                                 $descr = _("Standard American COA (4 digit) with demo data");
2452                         } else
2453                                 $descr = $fname;
2454
2455                         $coas[$fname] =  $descr;
2456                 }
2457         }
2458         ksort($coas);
2459
2460         echo "<tr><td class='label'>$label</td>\n<td>";
2461         echo array_selector( $name, $value, $coas );
2462         echo "</td></tr>\n";
2463 }
2464
2465 function payment_services($name)
2466 {
2467         global $payment_services;
2468
2469         $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2470
2471         return array_selector($name, null, $services, array(
2472                         'spec_option'=> _("No payment Link"),
2473                         'spec_id' => '',
2474                 ));
2475 }
2476
2477 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2478 {
2479         global $tax_algorithms;
2480         
2481         return array_selector($name, $value, $tax_algorithms, 
2482                 array( 
2483                         'select_submit'=> $submit_on_change,
2484                         'async' => true,
2485                         )
2486         );
2487 }
2488
2489 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2490 {
2491         if ($label != null)
2492                 echo "<td>$label</td>\n";
2493         echo "<td>";
2494         echo tax_algorithm_list($name, $value, $submit_on_change);
2495         echo "</td>\n";
2496 }
2497
2498 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2499 {
2500         echo "<tr><td class='label'>$label</td>";
2501         tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2502         echo "</tr>\n";
2503 }
2504
2505 function refline_list($name, $type, $value=null, $spec_option=false)
2506 {
2507         $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2508
2509         $where = array();
2510
2511         if (isset($type))
2512                 $where = array('`trans_type`='.db_escape($type));
2513
2514         return combo_input($name, $value, $sql, 'id', 'prefix',
2515                 array(
2516                         'order'=>array('prefix'),
2517                         'spec_option' => $spec_option,
2518                         'spec_id' => '',
2519                         'type' => 2,
2520                         'where' => $where,
2521                         'select_submit' => true,
2522                         )
2523                 );
2524 }
2525
2526 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2527 {
2528         echo "<tr>";
2529         if ($label != null)
2530                 echo "<td class='label'>$label</td>\n";
2531         echo "<td>";
2532
2533         echo refline_list($name, $type, $selected_id, $spec_option);
2534         echo "</td></tr>\n";
2535 }
2536
2537
2538 //----------------------------------------------------------------------------------------------
2539
2540 function subledger_list($name, $account, $selected_id=null)
2541 {
2542
2543         $type = is_subledger_account($account);
2544         if (!$type)
2545                 return '';
2546
2547         if($type > 0)
2548                 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name 
2549                 FROM "
2550                 .TB_PREF."debtors_master d,"
2551                 .TB_PREF."cust_branch c
2552                 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2553         else
2554                 $sql = "SELECT supplier_id as id, supp_ref as name 
2555                 FROM "
2556                 .TB_PREF."suppliers s
2557                 WHERE s.payable_account=".db_escape($account);
2558
2559         $mode = get_company_pref('no_customer_list');
2560
2561         return combo_input($name, $selected_id, $sql, 'id', 'name',
2562         array(
2563                 'type' => 1,
2564                 'size' => 20,
2565                 'async' => false,
2566         ) );
2567 }
2568
2569 function subledger_list_cells($label, $name, $account, $selected_id=null)
2570 {
2571         if ($label != null)
2572                 echo "<td>$label</td>\n";
2573         echo "<td nowrap>";
2574         echo subledger_list($name, $account, $selected_id);
2575         echo "</td>\n";
2576 }
2577
2578 function subledger_list_row($label, $name, $selected_id=null, $all_option = false, 
2579         $submit_on_change=false, $show_inactive=false, $editkey = false)
2580 {
2581         echo "<tr><td class='label'>$label</td><td nowrap>";
2582         echo subledger_list($name, $account, $selected_id);
2583         echo "</td>\n</tr>\n";
2584 }
2585
2586 function accounts_type_list_row($label, $name, $selected_id=null)
2587 {
2588         echo "<tr>";
2589         if ($label != null)
2590                 echo "<td class='label'>$label</td>\n";
2591         echo "<td>";
2592         $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2593         echo array_selector($name, $selected_id, $sel); 
2594         echo "</td></tr>\n";
2595 }
2596
2597 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2598 {
2599     $where = false;
2600     $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2601
2602     if ($label != null)
2603         echo "<td>$label</td>\n";
2604     echo "<td>";
2605
2606     echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2607         array(
2608             'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2609             'spec_id' => '',
2610             'order' => 'real_name',
2611             'select_submit'=> $submit_on_change,
2612             'async' => false
2613         ) );
2614     echo "</td>";
2615
2616 }
2617
2618 function collations_list_row($label, $name, $selected_id=null)
2619 {
2620         global $supported_collations;
2621
2622         echo "<tr>";
2623         if ($label != null)
2624                 echo "<td class='label'>$label</td>\n";
2625         echo "<td>";
2626
2627         echo array_selector($name, $selected_id, $supported_collations, 
2628                 array('select_submit'=> false) );
2629         echo "</td></tr>\n";
2630 }