Allowed multiply bank accounts on same gl account, removed bank trans type.
[fa-stable.git] / includes / ui / ui_lists.inc
1 <?php
2
3 include_once($path_to_root . "/includes/banking.inc");
4 include_once($path_to_root . "/includes/reserved.inc");
5 include_once($path_to_root . "/includes/types.inc");
6 include_once($path_to_root . "/includes/current_user.inc");
7
8 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
9         ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
10
11 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
12         ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
13
14 $all_items = reserved_words::get_all();
15
16 //----------------------------------------------------------------------------
17 //      Universal sql combo generator
18 //      $sql must return selector values and selector texts in columns 0 & 1
19 //      Options are merged with defaults.
20
21 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
22         $options=null)
23 {
24 global $Ajax;
25
26 $opts = array(          // default options
27         'where'=> array(),              // additional constraints
28         'order' => $namefield,  // list sort order
29                 // special option parameters
30         'spec_option'=>false,   // option text or false
31         'spec_id' => 0,         // option id
32                 // submit on select parameters
33         'default' => '', // default value when $_POST is not set
34         'select_submit' => false, //submit on select: true/false
35         'edit_submit' => false, // call editor on F4
36         'async' => true,        // select update via ajax (true) vs _page_body reload
37                 // search box parameters
38         'sel_hint' => null,
39         'search_box' => false,  // name or true/false
40         'type' => 0,    // type of extended selector:
41                 // 0 - with (optional) visible search box, search by id
42                 // 1 - with hidden search box, search by option text
43                 // 2 - TODO reverse: box with hidden selector available via enter; this
44                 // would be convenient for optional ad hoc adding of new item
45         'search_submit' => true, //search submit button: true/false
46         'size' => 8,    // size and max of box tag
47         'max' => 50,
48         'cells' => false,       // combo displayed as 2 <td></td> cells
49         'search' => array(), // sql field names to search
50         'format' => null,        // format functions for regular options
51         'disabled' => false,
52         'box_hint' => null // box/selectors hints; null = std see below
53 );
54 // ------ merge options with defaults ----------
55         if($options != null)
56                 $opts = array_merge($opts, $options);
57         if (!is_array($opts['where']))  $opts['where'] = array($opts['where']);
58
59         $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
60         $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
61         $select_submit =  $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
62         $spec_id = $opts['spec_id'];
63         $spec_option = $opts['spec_option'];
64         $by_id = ($opts['type'] == 0);
65         $class = $by_id ? 'combo':'combo2';
66         $disabled = $opts['disabled'] ? "disabled" : '';
67
68         if(!count($opts['search'])) {
69                 $opts['search'] = array($by_id ? $valfield : $namefield);
70         }
71         if ($opts['sel_hint'] === null) 
72                 $opts['sel_hint'] = $by_id || $search_box==false ?
73                         '' : _('Press Space tab for search pattern entry');
74
75         if ($opts['box_hint'] === null)
76                 $opts['box_hint'] = $search_box && $search_submit != false ?
77                         ($by_id ? _('Enter code fragment to search or * for all')
78                         : _('Enter description fragment to search or * for all')) :'';
79
80         if ($selected_id == null) {
81                 $selected_id = get_post($name, $opts['default']);
82         }
83         $txt = get_post($search_box);
84         $rel = '';
85         $limit = '';
86
87         if (isset($_POST[$select_submit])) {
88                 if ($by_id) $txt = $_POST[$name];
89
90                 if (!$opts['async'])
91                         $Ajax->activate('_page_body');
92                 else
93                         $Ajax->activate($name);
94         }
95         if ($search_box) {
96                 // search related sql modifications
97
98         $rel = "rel='$search_box'"; // set relation to list
99    if ($opts['search_submit']) {
100         if (isset($_POST[$search_submit])) {
101                 $selected_id = ''; // ignore selected_id while search
102                 if (!$opts['async'])
103                         $Ajax->activate('_page_body');
104                 else
105                         $Ajax->activate($name);
106         }
107         if ($txt == '') {
108                 if ($spec_option === false && $selected_id==null)
109                   $limit = ' LIMIT 1';
110                 else
111                   $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
112         }
113         else
114                 if ($txt != '*') {
115
116                 foreach($opts['search'] as $i=> $s)
117                         $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
118                 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
119                 }
120         }
121    }
122         // sql completion
123         if (count($opts['where'])) {
124                 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
125                 $sql .= '('. implode($opts['where'], ' AND ') . ')';
126         }
127         if ($opts['order'] != false) {
128                 $sql .= ' ORDER BY '.$opts['order'];
129         }
130
131         $sql .= $limit;
132         // ------ make selector ----------
133         $selector = $first_opt = '';
134         $first_id = false;
135         $found = false;
136 //if($name=='contact_sel') display_error($sql);
137         if($result = db_query($sql)) {
138                 while ($contact_row = db_fetch($result)) {
139                         $value = $contact_row[0];
140                         $descr = $opts['format']==null ?  $contact_row[1] :
141                         call_user_func($opts['format'], $contact_row);
142                         $sel = '';
143                         if (get_post($search_submit) && ($txt === $value)) {
144                                 $selected_id = $value;
145                         }
146                         if      ((string)($selected_id) === $value) {
147                                 $sel = 'selected';
148                                 $found = $value;
149                         }
150                         if ($first_id === false) {
151                                 $first_id = $value;
152                                 $first_opt = $descr;
153                         }
154                         $selector .= "<option $sel value='$value'>$descr</option>\n";
155                 }
156                 db_free_result($result);
157         }
158
159         // Prepend special option.
160         if ($spec_option !== false) { // if special option used - add it
161                 $first_id = $spec_id;
162                 $first_opt = $spec_option;
163                 $sel = $found===false ? 'selected' : '';
164                 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
165                         . $selector;
166         }
167
168         if ($found === false) {
169                 $selected_id = $first_id;
170         }
171         $_POST[$name] = $selected_id;
172
173         if ($by_id && $search_box != false) {
174                 $txt = $found;
175                 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
176         }
177         $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
178         $selector = "<select $disabled name='$name' class='$class' title='"
179                 . $opts['sel_hint']."'$aspect $rel>".$selector."</select>\n";
180
181         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
182
183         // because of bug which M$ cannot fix since IE 5.0
184         // we must embed whole selector in span tags to enable proper ajax update
185         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
186
187         if ($select_submit != false) { // if submit on change is used - add select button
188                 global $_select_button;
189         // button class selects form reload/ajax selector update
190                 $selector .= sprintf($_select_button, $disabled, user_theme(),
191                         (fallback_mode() ? '' : 'display:none;'),
192                         $select_submit)."\n";
193         }
194 // ------ make combo ----------
195
196         $edit_entry = '';
197         if ($search_box != false) {
198                 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
199                         $opts['size']."' maxlength='".$opts['max'].
200                         "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
201                         .$opts['box_hint']."'"
202                         .(!fallback_mode() && !$by_id ? " style=display:none;":'')
203                         .">\n";
204                 if ($search_submit != false) {
205                         global $_search_button;
206                         $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
207                                 (fallback_mode() ? '' : 'display:none;'),
208                                 $search_submit)."\n";
209                 }
210         }
211         default_focus($name);
212         $str = $selector;
213         if ($search_box && $opts['cells'])
214                 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
215         else
216                 echo $edit_entry.$selector;
217
218         return $str;
219 }
220
221 /*
222         Helper function.
223         Returns true if selector $name is subject to update.
224 */
225 function list_updated($name)
226 {
227         return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
228 }
229 //----------------------------------------------------------------------------------------------
230 //      Universal array combo generator
231 //      $items is array of options 'value' => 'description'
232 //      Options is reduced set of combo_selector options and is merged with defaults.
233
234 function array_selector($name, $selected_id, $items, $options=null)
235 {
236         global $Ajax;
237
238 $opts = array(          // default options
239         'spec_option'=>false,   // option text or false
240         'spec_id' => 0,         // option id
241         'select_submit' => false, //submit on select: true/false
242         'edit_submit' => false, // call editor on F4
243         'async' => true,        // select update via ajax (true) vs _page_body reload
244         'default' => '', // default value when $_POST is not set
245                 // search box parameters
246         'sel_hint' => null,
247         'disabled' => false
248 );
249 // ------ merge options with defaults ----------
250         if($options != null)
251                 $opts = array_merge($opts, $options);
252         $select_submit =  $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
253         $spec_id = $opts['spec_id'];
254         $spec_option = $opts['spec_option'];
255         $disabled = $opts['disabled'] ? "disabled" : '';
256
257         if ($selected_id == null) {
258                 $selected_id = get_post($name, $opts['default']);
259         }
260
261         if (isset($_POST[$select_submit])) {
262                 if (!$opts['async'])
263                         $Ajax->activate('_page_body');
264                 else
265                         $Ajax->activate($name);
266         }
267
268         // ------ make selector ----------
269         $selector = $first_opt = '';
270         $first_id = false;
271         $found = false;
272 //if($name=='SelectStockFromList') display_error($sql);
273                 foreach($items as $value=>$descr) {
274                         $sel = '';
275                         if ($selected_id == $value) {
276                                 $sel = 'selected';
277                                 $found = $value;
278                         }
279                         if ($first_id === false) {
280                                 $first_id = $value;
281                                 $first_opt = $descr;
282                         }
283                         $selector .= "<option $sel value='$value'>$descr</option>\n";
284                 }
285
286         // Prepend special option.
287         if ($spec_option !== false) { // if special option used - add it
288                 $first_id = $spec_id;
289                 $first_opt = $spec_option;
290                 $sel = $found===false ? 'selected' : '';
291                 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
292                         . $selector;
293         }
294
295         if ($found === false) {
296                 $_POST[$name] = $first_id;
297         }
298
299         $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
300         $selector = "<select $disabled name='$name' class='combo' title='"
301                 . $opts['sel_hint']."'$aspect >".$selector."</select>\n";
302
303         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
304
305         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
306
307         if ($select_submit != false) { // if submit on change is used - add select button
308                 global $_select_button;
309                 $selector .= sprintf($_select_button, $disabled, user_theme(),
310                         (fallback_mode() ? '' : 'display:none;'),
311                         $select_submit)."\n";
312         }
313         default_focus($name);
314         echo $selector;
315
316         return $selector;
317 }
318 //----------------------------------------------------------------------------------------------
319
320 function _format_add_curr($row)
321 {
322         static $company_currency;
323
324         if ($company_currency == null)
325         {
326                 $company_currency = get_company_currency();
327         }
328         return $row[1] . ($row[2] == $company_currency ?
329                 '' : ("&nbsp;-&nbsp;" . $row[2]));
330 }
331
332 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
333 {
334         global $all_items;
335
336         $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
337
338         $mode = get_company_pref('no_supplier_list');
339
340         return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
341         array(
342                 'format' => '_format_add_curr',
343                 'search_box' => $mode!=0,
344                 'edit_submit' => true, 
345                 'type' => 1,
346                 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
347                 'spec_id' => $all_items,
348                 'select_submit'=> $submit_on_change,
349                 'async' => false,
350                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
351                 _('Select supplier')
352                 ));
353 }
354
355 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
356 {
357         if ($label != null)
358                 echo "<td>$label</td><td>\n";
359         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
360                 echo "</td>\n";
361         return $str;
362 }
363
364 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
365 {
366 echo "<tr><td>$label</td><td>";
367         $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
368 echo "</td></tr>\n";
369 return $str;
370 }
371 //----------------------------------------------------------------------------------------------
372
373 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
374 {
375         global $all_items;
376
377         $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
378
379         $mode = get_company_pref('no_customer_list');
380
381 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
382         array(
383             'format' => '_format_add_curr',
384                 'search_box' => $mode!=0,
385                 'type' => 1,
386                 'size' => 20,
387                 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
388                 'spec_id' => $all_items,
389                 'select_submit'=> $submit_on_change,
390                 'edit_submit' => true, // call editor on F4
391                 'async' => false,
392                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F4 - entry new customer') :
393                 _('Select customer')
394         ) );
395 }
396
397 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
398 {
399         if ($label != null)
400                 echo "<td>$label</td>\n";
401         echo "<td nowrap>";
402         $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
403         echo "</td>\n";
404         return $str;
405 }
406
407 function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
408 {
409         echo "<tr><td>$label</td><td nowrap>";
410         $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
411         echo "</td>\n</tr>\n";
412         return $str;
413 }
414
415 //------------------------------------------------------------------------------------------------
416
417 function customer_branches_list($customer_id, $name, $selected_id=null,
418         $spec_option = true, $enabled=true, $submit_on_change=false)
419 {
420         global $all_items;
421
422         $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
423                 WHERE debtor_no='" . $customer_id . "' ";
424
425         $where = $enabled ? array("disable_trans = 0") : array();
426 return  combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
427         array(
428                 'where' => $where,
429                 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
430                 'spec_id' => $all_items,
431                 'select_submit'=> $submit_on_change,
432                 'sel_hint' => _('Select customer branch')
433         ) );
434 }
435 //------------------------------------------------------------------------------------------------
436
437 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
438 {
439         if ($label != null)
440                 echo "<td>$label</td>\n";
441         echo "<td>";
442         $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
443         echo "</td>\n";
444         return $ret;
445 }
446
447 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
448 {
449         echo "<tr>";
450         $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
451         echo "</tr>";
452         return $ret;
453 }
454
455 //------------------------------------------------------------------------------------------------
456
457 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
458 {
459         global $all_items;
460
461         $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
462
463 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
464         array(
465                 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
466                 'spec_id' => $all_items,
467                 'select_submit'=> $submit_on_change
468         ) );
469 }
470
471 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
472 {
473         if ($label != null)
474                 echo "<td>$label</td>\n";
475         echo "<td>";
476         $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
477         echo "</td>\n";
478         return $str;
479 }
480
481 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
482 {
483         echo "<tr>";
484         $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
485         echo "</tr>\n";
486         return $str;
487 }
488
489 //-----------------------------------------------------------------------------------------------
490
491 function currencies_list($name, $selected_id=null, $submit_on_change=false)
492 {
493         $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
494
495 // default to the company currency
496
497 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
498         array(
499                 'select_submit'=> $submit_on_change,
500                 'default' => get_company_currency(),
501                 'async' => false                
502         ) );
503 }
504
505 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
506 {
507         if ($label != null)
508                 echo "<td>$label</td>\n";
509         echo "<td>";
510         $str = currencies_list($name, $selected_id, $submit_on_change);
511         echo "</td>\n";
512         return $str;
513 }
514
515 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
516 {
517         echo "<tr>\n";
518         $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
519         echo "</tr>\n";
520         return $str;
521 }
522
523 //---------------------------------------------------------------------------------------------------
524
525 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
526 {
527
528         $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
529
530 // default to the company current fiscal year
531
532 return combo_input($name, $selected_id, $sql, 'id', '',
533         array(
534                 'order' => 'begin',
535                 'default' => get_company_pref('f_year'),
536                 'format' => '_format_fiscalyears',
537                 'select_submit'=> $submit_on_change,
538                 'async' => false
539         ) );
540 }
541
542 function _format_fiscalyears($row)
543 {
544         return sql2date($row[1]) . "&nbsp;-&nbsp;" . sql2date($row[2])
545         . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
546 }
547
548 function fiscalyears_list_cells($label, $name, $selected_id=null)
549 {
550         if ($label != null)
551                 echo "<td>$label</td>\n";
552         echo "<td>";
553         $str = fiscalyears_list($name, $selected_id);
554         echo "</td>\n";
555         return $str;
556 }
557
558 function fiscalyears_list_row($label, $name, $selected_id=null)
559 {
560         echo "<tr>\n";
561         $str = fiscalyears_list_cells($label, $name, $selected_id);
562         echo "</tr>\n";
563         return $str;
564 }
565 //------------------------------------------------------------------------------------
566
567 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
568         $submit_on_change=false, $showclosed=false, $showtype=1)
569 {
570 $sql = "SELECT id, CONCAT(reference,'  ',name) as ref FROM ".TB_PREF."dimensions";
571
572 $options = array(
573         'order' => 'reference',
574         'spec_option'=>$no_option ? $showname : false,
575         'spec_id' => 0,
576         'select_submit'=> $submit_on_change,
577         'async' => false,
578         );
579
580         if ($showclosed)
581                 $options['where'][] = "closed=0";
582         if($showtype)
583                 $options['where'][] = "type_=$showtype";
584
585         return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
586 }
587
588 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
589         $showclosed=false, $showtype=0)
590 {
591         if ($label != null)
592                 echo "<td>$label</td>\n";
593         echo "<td>";
594         $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
595         echo "</td>\n";
596         return $str;
597 }
598
599 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
600         $showclosed=false, $showtype=0)
601 {
602         echo "<tr>\n";
603         $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
604                 $showclosed, $showtype);
605         echo "</tr>\n";
606         return $str;
607 }
608
609 //---------------------------------------------------------------------------------------------------
610
611 function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array())
612 {
613         global $all_items;
614
615         $sql = "SELECT stock_id, s.description, c.description
616                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
617
618         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
619         array_merge(
620           array(
621                 'format' => '_format_stock_items',
622                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
623                 'spec_id' => $all_items,
624                 'search_box' => true,
625                 'search' => array("stock_id", "c.description","s.description"),
626                 'search_submit' => get_company_pref('no_item_list')!=0,
627                 'size'=>10,
628                 'select_submit'=> $submit_on_change
629           ), $opts) );
630 }
631
632 function _format_stock_items($row)
633 {
634         return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "")
635                 . $row[2] . "&nbsp;-&nbsp;" . $row[1];
636 }
637
638 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
639 {
640         if ($label != null)
641                 echo "<td>$label</td>\n";
642         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
643                 array('cells'=>true));
644         return $str;
645 }
646 /*
647 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
648 {
649         echo "<tr>\n";
650         $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
651         echo "</tr>\n";
652         return $str;
653 }
654 */
655 //------------------------------------------------------------------------------------
656
657 function base_stock_items_list($where, $name, $selected_id=null,
658         $all_option=false, $submit_on_change=false)
659 {
660         global $all_items;
661
662         $sql = "SELECT stock_id, s.description, c.description
663                 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
664                 s.category_id=c.category_id";
665
666         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
667         array(
668                 'format' => '_format_stock_items',
669                 'spec_option' => $all_option==true ?  _("All Items") : $all_option,
670                 'spec_id' => $all_items,
671                 'select_submit'=> $submit_on_change,
672                 'where' => $where
673         ) );
674 }
675 //------------------------------------------------------------------------------------
676
677 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
678 {
679
680         return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
681                 $name, $selected_id, $all_option, $submit_on_change);
682 }
683 /*
684 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
685 {
686         if ($label != null)
687                 echo "<td>$label</td>\n";
688         echo "<td>";
689         $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
690         echo "</td>\n";
691         return $str;
692 }
693
694 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
695 {
696         echo "<tr>\n";
697         $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
698         echo "</tr>\n";
699         return $str;
700 }
701 */
702 //------------------------------------------------------------------------------------
703
704 function stock_manufactured_items_list($name, $selected_id=null,
705         $all_option=false, $submit_on_change=false)
706 {
707         return base_stock_items_list("s.mb_flag='M'",
708                 $name, $selected_id, $all_option, $submit_on_change);
709 }
710
711 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
712                                 $all_option=false, $submit_on_change=false)
713 {
714         if ($label != null)
715                 echo "<td>$label</td>\n";
716         echo "<td>";
717         $str = stock_manufactured_items_list($name, $selected_id, $all_option,
718                                 $submit_on_change);
719         echo "</td>\n";
720         return $str;
721 }
722
723 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
724                 $all_option=false, $submit_on_change=false)
725 {
726         echo "<tr>\n";
727         $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
728                         $all_option, $submit_on_change);
729         echo "</tr>\n";
730         return $str;
731 }
732 //------------------------------------------------------------------------------------
733
734 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
735         $all_option=false, $submit_on_change=false)
736 {
737         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
738                 array('where'=>array("stock_id != '$parent_stock_id'")));
739         return $str;
740 }
741
742 function stock_component_items_list_cells($label, $name, $parent_stock_id, 
743         $selected_id=null, $all_option=false, $submit_on_change=false)
744 {
745         if ($label != null)
746                 echo "<td>$label</td>\n";
747         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
748                 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
749         return $str;
750 }
751 //------------------------------------------------------------------------------------
752
753 function stock_costable_items_list($name, $selected_id=null,
754         $all_option=false, $submit_on_change=false)
755 {
756         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
757                 array('where'=>array("mb_flag!='D'")));
758         return $str;
759 }
760
761 function stock_costable_items_list_cells($label, $name, $selected_id=null, 
762         $all_option=false, $submit_on_change=false)
763 {
764         if ($label != null)
765                 echo "<td>$label</td>\n";
766         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
767                 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
768         return $str;
769 }
770
771 //------------------------------------------------------------------------------------
772 function stock_purchasable_items_list($name, $selected_id=null, 
773         $all_option=false, $submit_on_change=false)
774 {
775         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
776                 array('where'=>array("mb_flag!= 'M'"), 
777                         'edit_submit' => true));
778         return $str;
779 }
780
781 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
782                         $all_option=false, $submit_on_change=false)
783 {
784         if ($label != null)
785                 echo "<td>$label</td>\n";
786         $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
787                 array('where'=>array("mb_flag!= 'M'"), 
788                          'edit_submit' => true,
789                          'cells'=>true));
790         return $str;
791 }
792
793 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
794                         $all_option=false, $submit_on_change=false)
795 {
796         echo "<tr>\n";
797         $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
798                 $all_option, $submit_on_change);
799         echo "</tr>\n";
800         return $ret;
801 }
802
803 //------------------------------------------------------------------------------------
804
805 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
806 {
807         $types = array(
808                 'M' => _("Manufactured"),
809                 'B' => _("Purchased"),
810                 'D' => _("Service")
811         );
812
813         echo "<tr>";
814         if ($label != null)
815                 echo "<td>$label</td>\n";
816         echo "<td>";
817
818         array_selector($name, $selected_id, $types, 
819                 array( 
820                         'select_submit'=> true, 
821                         'disabled' => !$enabled) );
822         echo "</td></tr>\n";
823 }
824
825 function stock_units_list_row($label, $name, $value=null, $enabled=true)
826 {
827         $result = get_all_item_units();
828         echo "<tr>";
829         if ($label != null)
830                 echo "<td>$label</td>\n";
831         echo "<td>";
832
833         while($unit = db_fetch($result))
834                 $units[$unit['abbr']] = $unit['name'];
835
836         array_selector($name, $value, $units, 
837                 array( 
838                         'select_submit'=> true, 
839                         'disabled' => !$enabled) );
840
841         echo "</td></tr>\n";
842 }
843
844 //------------------------------------------------------------------------------------
845
846 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
847 {
848         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
849
850         return combo_input($name, $selected_id, $sql, 'id', 'name',
851         array(
852                 'spec_option' => $none_option,
853                 'spec_id' => reserved_words::get_all_numeric(),
854                 'select_submit'=> $submit_on_change,
855                 'async' => false,
856         ) );
857 }
858
859 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
860         $submit_on_change=false)
861 {
862         if ($label != null)
863                 echo "<td>$label</td>\n";
864         echo "<td>";
865         $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
866         echo "</td>\n";
867         return $str;
868 }
869
870 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
871         $submit_on_change=false)
872 {
873         echo "<tr>\n";
874         $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
875         echo "</tr>\n";
876         return $str;
877 }
878
879 //------------------------------------------------------------------------------------
880
881 function tax_groups_list($name, $selected_id=null,
882         $none_option=false, $submit_on_change=false)
883 {
884         $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
885
886         return combo_input($name, $selected_id, $sql, 'id', 'name',
887         array(
888                 'order' => 'id',
889                 'spec_option' => $none_option,
890                 'spec_id' => reserved_words::get_all_numeric(),
891                 'select_submit'=> $submit_on_change,
892                 'async' => false,
893         ) );
894 }
895
896 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
897 {
898         if ($label != null)
899                 echo "<td>$label</td>\n";
900         echo "<td>";
901         $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
902         echo "</td>\n";
903         return $str;
904 }
905
906 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
907 {
908         echo "<tr>\n";
909         $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
910         echo "</tr>\n";
911         return $str;
912 }
913
914 //------------------------------------------------------------------------------------
915
916 function item_tax_types_list($name, $selected_id=null)
917 {
918         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
919         combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
920 }
921
922 function item_tax_types_list_cells($label, $name, $selected_id=null)
923 {
924         if ($label != null)
925                 echo "<td>$label</td>\n";
926         echo "<td>";
927         item_tax_types_list($name, $selected_id);
928         echo "</td>\n";
929 }
930
931 function item_tax_types_list_row($label, $name, $selected_id=null)
932 {
933         echo "<tr>\n";
934         item_tax_types_list_cells($label, $name, $selected_id);
935         echo "</tr>\n";
936 }
937
938 //------------------------------------------------------------------------------------
939
940 function shippers_list($name, $selected_id=null)
941 {
942         $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
943         combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
944 }
945
946 function shippers_list_cells($label, $name, $selected_id=null)
947 {
948         if ($label != null)
949                 echo "<td>$label</td>\n";
950         echo "<td>";
951         shippers_list($name, $selected_id);
952         echo "</td>\n";
953 }
954
955 function shippers_list_row($label, $name, $selected_id=null)
956 {
957         echo "<tr>\n";
958         shippers_list_cells($label, $name, $selected_id);
959         echo "</tr>\n";
960 }
961
962 //-------------------------------------------------------------------------------------
963
964 function sales_persons_list($name, $selected_id=null)
965 {
966         $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
967         combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
968 }
969
970 function sales_persons_list_cells($label, $name, $selected_id=null)
971 {
972         if ($label != null)
973                 echo "<td>$label</td>\n";
974         echo "<td>\n";
975         sales_persons_list($name, $selected_id);
976         echo "</td>\n";
977 }
978
979 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
980 {
981         echo "<tr>\n";
982         sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
983         echo "</tr>\n";
984 }
985
986 //------------------------------------------------------------------------------------
987
988 function sales_areas_list($name, $selected_id=null)
989 {
990         $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
991         combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
992 }
993
994 function sales_areas_list_cells($label, $name, $selected_id=null)
995 {
996         if ($label != null)
997                 echo "<td>$label</td>\n";
998         echo "<td>";
999         sales_areas_list($name, $selected_id);
1000         echo "</td>\n";
1001 }
1002
1003 function sales_areas_list_row($label, $name, $selected_id=null)
1004 {
1005         echo "<tr>\n";
1006         sales_areas_list_cells($label, $name, $selected_id);
1007         echo "</tr>\n";
1008 }
1009
1010 //------------------------------------------------------------------------------------
1011
1012 function workorders_list($name, $selected_id=null)
1013 {
1014         $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1015         combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1016 }
1017
1018 function workorders_list_cells($label, $name, $selected_id=null)
1019 {
1020         if ($label != null)
1021                 echo "<td>$label</td>\n";
1022         echo "<td>";
1023         workorders_list($name, $selected_id);
1024         echo "</td>\n";
1025 }
1026
1027 function workorders_list_row($label, $name, $selected_id=null)
1028 {
1029         echo "<tr>\n";
1030         workorders_list_cells($label, $name, $selected_id);
1031         echo "</tr>\n";
1032 }
1033
1034 //------------------------------------------------------------------------------------
1035
1036 function payment_terms_list($name, $selected_id=null)
1037 {
1038         $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
1039         combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1040 }
1041
1042 function payment_terms_list_cells($label, $name, $selected_id=null)
1043 {
1044         if ($label != null)
1045                 echo "<td>$label</td>\n";
1046         echo "<td>";
1047         payment_terms_list($name, $selected_id);
1048         echo "</td>\n";
1049 }
1050
1051 function payment_terms_list_row($label, $name, $selected_id=null)
1052 {
1053         echo "<tr>\n";
1054         payment_terms_list_cells($label, $name, $selected_id);
1055         echo "</tr>\n";
1056 }
1057
1058 //------------------------------------------------------------------------------------
1059
1060 function credit_status_list($name, $selected_id=null)
1061 {
1062         $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
1063         combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1064 }
1065
1066 function credit_status_list_cells($label, $name, $selected_id=null)
1067 {
1068         if ($label != null)
1069                 echo "<td>$label</td>\n";
1070         echo "<td>";
1071         credit_status_list($name, $selected_id);
1072         echo "</td>\n";
1073 }
1074
1075 function credit_status_list_row($label, $name, $selected_id=null)
1076 {
1077         echo "<tr>\n";
1078         credit_status_list_cells($label, $name, $selected_id);
1079         echo "</tr>\n";
1080 }
1081
1082 //-----------------------------------------------------------------------------------------------
1083
1084 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1085 {
1086         $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
1087
1088         return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1089         array(
1090                 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1091                 'spec_id' => 0,
1092                 'select_submit'=> $submit_on_change,
1093         //        'async' => false,
1094         ) );
1095 }
1096
1097 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1098 {
1099         if ($label != null)
1100                 echo "<td>$label</td>\n";
1101         echo "<td>";
1102         $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1103         echo "</td>\n";
1104         return $str;
1105 }
1106
1107 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1108 {
1109         echo "<tr>\n";
1110         $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1111         echo "</tr>\n";
1112         return $str;
1113 }
1114
1115 //-----------------------------------------------------------------------------------------------
1116
1117 function movement_types_list($name, $selected_id=null)
1118 {
1119         $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1120         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1121 }
1122
1123 function movement_types_list_cells($label, $name, $selected_id=null)
1124 {
1125         if ($label != null)
1126                 echo "<td>$label</td>\n";
1127         echo "<td>";
1128         movement_types_list($name, $selected_id);
1129         echo "</td>\n";
1130 }
1131
1132 function movement_types_list_row($label, $name, $selected_id=null)
1133 {
1134         echo "<tr>\n";
1135         movement_types_list_cells($label, $name, $selected_id);
1136         echo "</tr>\n";
1137 }
1138
1139 //-----------------------------------------------------------------------------------------------
1140 /*
1141 function bank_trans_types_list($name, $selected_id=null)
1142 {
1143         $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1144         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1145 }
1146
1147 function bank_trans_types_list_cells($label, $name, $selected_id=null)
1148 {
1149         if ($label != null)
1150                 echo "<td>$label</td>\n";
1151         echo "<td>";
1152         bank_trans_types_list($name, $selected_id);
1153         echo "</td>\n";
1154 }
1155
1156 function bank_trans_types_list_row($label, $name, $selected_id=null)
1157 {
1158         echo "<tr>\n";
1159         bank_trans_types_list_cells($label, $name, $selected_id);
1160         echo "</tr>\n";
1161 }
1162 */
1163 //-----------------------------------------------------------------------------------------------
1164
1165 function workcenter_list($name, $selected_id=null, $all_option=false)
1166 {
1167         global $all_items;
1168
1169         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1170
1171         return combo_input($name, $selected_id, $sql, 'id', 'name',
1172         array(
1173                 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1174                 'spec_id' => $all_items,
1175         ) );
1176 }
1177
1178 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1179 {
1180         default_focus($name);
1181         if ($label != null)
1182                 echo "<td>$label</td>\n";
1183         echo "<td>";
1184         workcenter_list($name, $selected_id, $all_option);
1185         echo "</td>\n";
1186 }
1187
1188 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1189 {
1190         echo "<tr>\n";
1191         workcenter_list_cells($label, $name, $selected_id, $all_option);
1192         echo "</tr>\n";
1193 }
1194
1195 //-----------------------------------------------------------------------------------------------
1196
1197 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1198 {
1199         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code
1200                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1201                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1202
1203         return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1204         array(
1205                 'format' => '_format_add_curr',
1206                 'select_submit'=> $submit_on_change,
1207                 'async' => false
1208         ) );
1209 }
1210
1211 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1212 {
1213         if ($label != null)
1214                 echo "<td>$label</td>\n";
1215         echo "<td>";
1216         $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1217         echo "</td>\n";
1218         return $str;
1219 }
1220
1221 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1222 {
1223         echo "<tr>\n";
1224         $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1225         echo "</tr>\n";
1226         return $str;
1227 }
1228 //-----------------------------------------------------------------------------------------------
1229
1230 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1231 {
1232         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1233                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1234                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code"
1235                 . " AND ".TB_PREF."bank_accounts.account_type=3";
1236
1237         if ($label != null)
1238                 echo "<tr><td>$label</td>\n";
1239         echo "<td>";
1240         $str = combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1241         array(
1242                 'format' => '_format_add_curr',
1243                 'select_submit'=> $submit_on_change,
1244                 'async' => true
1245         ) );
1246         echo "</td></tr>\n";
1247         return $str;
1248 }
1249 //-----------------------------------------------------------------------------------------------
1250
1251 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1252 {
1253         $sql = "SELECT id, pos_name FROM ".TB_PREF."sales_pos";
1254
1255         default_focus($name);
1256         echo '<tr>';
1257         if ($label != null)
1258                 echo "<td>$label</td>\n";
1259         echo "<td>";
1260
1261         $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1262         array(
1263                 'select_submit'=> $submit_on_change,
1264                 'async' => true,
1265                 'spec_option' =>$spec_option,
1266                 'spec_id' => -1,
1267         ) );
1268         echo "</td></tr>\n";
1269
1270         return $str;    
1271 }
1272 //-----------------------------------------------------------------------------------------------
1273
1274 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1275 {
1276         if ($label != null)
1277                 echo "<td>$label</td>\n";
1278         echo "<td>";
1279         $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1280         echo "</td>\n";
1281         return $str;
1282 }
1283 //-----------------------------------------------------------------------------------------------
1284
1285 function class_list($name, $selected_id=null, $submit_on_change=false)
1286 {
1287         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1288
1289         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1290         array(
1291                 'select_submit'=> $submit_on_change,
1292                 'async' => false
1293         ) );
1294
1295 }
1296
1297 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1298 {
1299         if ($label != null)
1300                 echo "<td>$label</td>\n";
1301         echo "<td>";
1302         $str = class_list($name, $selected_id, $submit_on_change);
1303         echo "</td>\n";
1304         return $str;
1305 }
1306
1307 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1308 {
1309         echo "<tr>\n";
1310         $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1311         echo "</tr>\n";
1312         return $str;
1313 }
1314
1315 //-----------------------------------------------------------------------------------------------
1316
1317 function stock_categories_list($name, $selected_id=null)
1318 {
1319         $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1320         combo_input($name, $selected_id, $sql, 'category_id', 'description',
1321         array('order'=>'category_id'));
1322 }
1323
1324 function stock_categories_list_cells($label, $name, $selected_id=null)
1325 {
1326         if ($label != null)
1327                 echo "<td>$label</td>\n";
1328         echo "<td>";
1329         stock_categories_list($name, $selected_id);
1330         echo "</td>\n";
1331 }
1332
1333 function stock_categories_list_row($label, $name, $selected_id=null)
1334 {
1335         echo "<tr>\n";
1336         stock_categories_list_cells($label, $name, $selected_id);
1337         echo "</tr>\n";
1338 }
1339
1340 //-----------------------------------------------------------------------------------------------
1341
1342 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1343 {
1344         global $all_items;
1345
1346         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1347
1348         combo_input($name, $selected_id, $sql, 'id', 'name',
1349         array(
1350                 'order' => 'id',
1351                 'spec_option' =>$all_option,
1352                 'spec_id' => $all_option_numeric ? 0 : $all_items
1353         ) );
1354 }
1355
1356 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1357         $all_option_numeric=false)
1358 {
1359         if ($label != null)
1360                 echo "<td>$label</td>\n";
1361         echo "<td>";
1362         gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1363         echo "</td>\n";
1364 }
1365
1366 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1367         $all_option_numeric=false)
1368 {
1369         echo "<tr>\n";
1370         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1371                 $all_option_numeric);
1372         echo "</tr>\n";
1373 }
1374
1375 //-----------------------------------------------------------------------------------------------
1376 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1377         $show_group=false, $cells=false, $all_option=false, $submit_on_change=false)
1378 {
1379         if ($skip_bank_accounts)
1380                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1381                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1382                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1383                         ."ON chart.account_code=acc.account_code
1384                                 WHERE acc.account_code IS NULL
1385                         AND chart.account_type=type.id";
1386         else
1387                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1388                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1389                         WHERE chart.account_type=type.id";
1390
1391         combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1392         array(
1393                 'format' => '_format_account' .  ($show_group ? '2' : ''),
1394                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1395                 'spec_id' => '',
1396                 'order' => 'account_code',
1397                 'search_box' => $cells,
1398                         'search_submit' => false,
1399                         'size' => 12,
1400                         'max' => 10,
1401                         'cells' => true,
1402                 'select_submit'=> $submit_on_change,
1403                 'async' => false
1404         ) );
1405
1406 }
1407
1408 function _format_account($row)
1409 {
1410                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1411 }
1412
1413 function _format_account2($row)
1414 {
1415                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1416 }
1417
1418 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1419         $show_group=false, $cells=false, $all_option=false)
1420 {
1421         if ($label != null)
1422                 echo "<td>$label</td>\n";
1423         echo "<td>";
1424         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1425         echo "</td>\n";
1426 }
1427
1428 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1429         $show_group=false, $cells=false, $all_option=false)
1430 {
1431         echo "<tr>\n";
1432         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1433                 $show_group, $cells, $all_option);
1434         echo "</tr>\n";
1435 }
1436
1437 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1438 {
1439         $items = array();
1440         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1441         $items['0'] = strlen($name_no) ? $name_no : _("No");
1442
1443         return array_selector($name, $selected_id, $items, 
1444                 array( 
1445                         'select_submit'=> $submit_on_change,
1446                         'async' => false ) ); // FIX?
1447 }
1448
1449 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1450 {
1451         if ($label != null)
1452                 echo "<td>$label</td>\n";
1453         echo "<td>";
1454         $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1455         echo "</td>\n";
1456         return $str;
1457 }
1458
1459 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1460 {
1461         echo "<tr>\n";
1462         $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1463         echo "</tr>\n";
1464         return $str;
1465 }
1466
1467 //------------------------------------------------------------------------------------------------
1468
1469 function languages_list($name, $selected_id=null)
1470 {
1471         global $installed_languages;
1472
1473         $items = array();
1474         foreach ($installed_languages as $lang)
1475                         $items[$lang['code']] = $lang['name'];
1476         
1477         return array_selector($name, $selected_id, $items );
1478 }
1479
1480 function languages_list_cells($label, $name, $selected_id=null)
1481 {
1482         if ($label != null)
1483                 echo "<td>$label</td>\n";
1484         echo "<td>";
1485         languages_list($name, $selected_id);
1486         echo "</td>\n";
1487 }
1488
1489 function languages_list_row($label, $name, $selected_id=null)
1490 {
1491         echo "<tr>\n";
1492         languages_list_cells($label, $name, $selected_id);
1493         echo "</tr>\n";
1494 }
1495
1496 //------------------------------------------------------------------------------------------------
1497
1498 function bank_account_types_list($name, $selected_id=null)
1499 {
1500         $types = bank_account_types::get_all();
1501
1502         $items = array();
1503         foreach ($types as $type)
1504         {
1505                         $items[$type['id']] = $type['name'];
1506         }
1507         
1508         return array_selector($name, $selected_id, $items );
1509 }
1510
1511 function bank_account_types_list_cells($label, $name, $selected_id=null)
1512 {
1513         if ($label != null)
1514                 echo "<td>$label</td>\n";
1515         echo "<td>";
1516         bank_account_types_list($name, $selected_id);
1517         echo "</td>\n";
1518 }
1519
1520 function bank_account_types_list_row($label, $name, $selected_id=null)
1521 {
1522         echo "<tr>\n";
1523         bank_account_types_list_cells($label, $name, $selected_id);
1524         echo "</tr>\n";
1525 }
1526
1527 //------------------------------------------------------------------------------------------------
1528 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1529 {
1530         $types = payment_person_types::get_all();
1531
1532         $items = array();
1533         foreach ($types as $type)
1534         {
1535                 if (payment_person_types::has_items($type['id']))
1536                 {
1537                         $items[$type['id']] = $type['name'];
1538                 }
1539         }
1540         
1541         return array_selector($name, $selected_id, $items, 
1542                 array( 'select_submit'=> $submit_on_change ) );
1543 }
1544
1545 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1546 {
1547         if ($label != null)
1548                 echo "<td>$label</td>\n";
1549         echo "<td>";
1550         $str = payment_person_types_list($name, $selected_id, $related);
1551         echo "</td>\n";
1552         return $str;
1553 }
1554
1555 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1556 {
1557         echo "<tr>\n";
1558         $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1559         echo "</tr>\n";
1560         return $str;
1561 }
1562
1563 //------------------------------------------------------------------------------------------------
1564
1565 function quick_entries_list($name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false)
1566 {
1567         $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
1568         if ($expense)
1569                 $sql .= " WHERE deposit=0";
1570         else
1571                 $sql .= " WHERE deposit=1";
1572         if ($bank_only)
1573                 $sql .= " AND bank_only=1";
1574         else
1575                 $sql .= " AND bank_only=0";
1576         combo_input($name, $selected_id, $sql, 'id', 'description',
1577                 array(
1578                         'spec_id' => '',
1579                         'order' => 'description',
1580                         'select_submit'=> $submit_on_change,
1581                         'async' => false
1582                 ) );
1583
1584 }
1585
1586 function quick_entries_list_row($label, $name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false)
1587 {
1588         echo "<tr><td>$label</td><td>\n";
1589         quick_entries_list($name, $selected_id, $expense, $bank_only, $submit_on_change);
1590         echo "</td></tr>\n";
1591 }
1592
1593
1594 //------------------------------------------------------------------------------------------------
1595
1596 function wo_types_list($name, $selected_id=null)
1597 {
1598         $types = wo_types::get_all();
1599
1600         $items = array();
1601         foreach ($types as $type)
1602                 $items[$type['id']] = $type['name'];
1603         
1604         return array_selector($name, $selected_id, $items, 
1605                 array( 'select_submit'=> true, 'async' => true ) );
1606 }
1607
1608 function wo_types_list_row($label, $name, $selected_id=null)
1609 {
1610         echo "<tr><td>$label</td><td>\n";
1611         $str = wo_types_list($name, $selected_id);
1612         echo "</td></tr>\n";
1613         return $str;
1614 }
1615
1616 //------------------------------------------------------------------------------------------------
1617
1618 function dateformats_list_row($label, $name, $value=null)
1619 {
1620         global $dateformats;
1621
1622         echo "<tr><td>$label</td>\n<td>";
1623         array_selector( $name, $value, $dateformats );
1624         echo "</td></tr>\n";
1625 }
1626
1627 function dateseps_list_row($label, $name, $value=null)
1628 {
1629         global $dateseps;
1630
1631         echo "<tr><td>$label</td>\n<td>";
1632         array_selector( $name, $value, $dateseps );
1633         echo "</td></tr>\n";
1634 }
1635
1636 function thoseps_list_row($label, $name, $value=null)
1637 {
1638         global $thoseps;
1639
1640         echo "<tr><td>$label</td>\n<td>";
1641         array_selector( $name, $value, $thoseps );
1642         echo "</td></tr>\n";
1643 }
1644
1645 function decseps_list_row($label, $name, $value=null)
1646 {
1647         global $decseps;
1648
1649         echo "<tr><td>$label</td>\n<td>";
1650         array_selector( $name, $value, $decseps );
1651         echo "</td></tr>\n";
1652 }
1653
1654 function themes_list_row($label, $name, $value=null)
1655 {
1656         global $path_to_root;
1657
1658         $path = $path_to_root.'/themes/';
1659         $themes = array();
1660         $themedir = opendir($path);
1661         while(false !== ($fname = readdir($themedir)))
1662         {
1663                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1664                 {
1665                         $themes[$fname] =  $fname;
1666                 }
1667         }
1668         ksort($themes);
1669
1670         echo "<tr><td>$label</td>\n<td>";
1671         array_selector( $name, $value, $themes );
1672         echo "</td></tr>\n";
1673 }
1674
1675 function pagesizes_list_row($label, $name, $value=null)
1676 {
1677         global $pagesizes;
1678
1679         $items = array();
1680         foreach ($pagesizes as $pz)
1681                 $items[$pz] = $pz;
1682
1683         echo "<tr><td>$label</td>\n<td>";
1684         array_selector( $name, $value, $items );
1685         echo "</td></tr>\n";
1686 }
1687
1688 function security_headings_list_row($label, $name, $value=null)
1689 {
1690         global $security_headings;
1691
1692         echo "<tr><td>$label</td>\n<td>";
1693         array_selector( $name, $value, $security_headings );
1694         echo "</td></tr>\n";
1695 }
1696
1697 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1698 {
1699         global $systypes_array;
1700
1701         if ($label != null)
1702                 echo "<td>$label</td>\n";
1703         echo "<td>";
1704
1705         $items = array();
1706         foreach ($systypes_array as $key=>$type)
1707                         $items[$key] = $type['name'];
1708         
1709         $str = array_selector($name, $value, $items, 
1710                 array( 
1711                         'select_submit'=> $submit_on_change,
1712                         'async' => false
1713                         )
1714         );
1715         echo "</td>\n";
1716         return $str;
1717 }
1718
1719 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1720 {
1721         echo "<tr>\n";
1722         $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1723         echo "</tr>\n";
1724         return $str;
1725 }
1726
1727 function cust_allocations_list_cells($label, $name, $selected=null)
1728 {
1729         global $all_items;
1730
1731         if ($label != null)
1732                 label_cell($label);
1733         echo "<td>\n";
1734         $allocs = array( 
1735                 $all_items=>_("All Types"),
1736                 '1'=> _("Sales Invoices"),
1737                 '2'=> _("Overdue Invoices"),
1738                 '3' => _("Payments"),
1739                 '4' => _("Credit Notes"),
1740                 '5' => _("Delivery Notes")
1741         );
1742         $str = array_selector($name, $selected, $allocs);
1743         echo "</td>\n";
1744         return $str;
1745 }
1746
1747 function supp_allocations_list_cell($name, $selected=null)
1748 {
1749         global $all_items;
1750
1751         echo "<td>\n";
1752         $allocs = array( 
1753                 $all_items=>_("All Types"),
1754                 '1'=> _("Invoices"),
1755                 '2'=> _("Overdue Invoices"),
1756                 '3' => _("Payments"),
1757                 '4' => _("Credit Notes"),
1758                 '5' => _("Overdue Credit Notes")
1759         );
1760         $str = array_selector($name, $selected, $allocs);
1761         echo "</td>\n";
1762         return $str;
1763 }
1764
1765 function policy_list_cells($label, $name, $selected=null)
1766 {
1767         if ($label != null)
1768                 label_cell($label);
1769         echo "<td>\n";
1770         $str = array_selector($name, $selected, 
1771                                 array( '' => _("Automatically put balance on back order"),
1772                                         'CAN' => _("Cancel any quantites not delivered")) );
1773         echo "</td>\n";
1774         return $str;
1775 }
1776
1777 function policy_list_row($label, $name, $selected=null)
1778 {
1779         echo "<tr>\n";
1780         policy_list_cells($label, $name, $selected);
1781         echo "</tr>\n";
1782 }
1783
1784 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1785 {
1786         if ($label != null)
1787                 label_cell($label);
1788         echo "<td>\n";
1789         $str = array_selector($name, $selected, 
1790                                 array( 'Return' => _("Items Returned to Inventory Location"),
1791                                         'WriteOff' => _("Items Written Off")),
1792                                 array( 'select_submit'=> $submit_on_change ) );
1793         echo "</td>\n";
1794         return $str;
1795 }
1796
1797 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1798 {
1799         echo "<tr>\n";
1800         $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1801         echo "</tr>\n";
1802         return $str;
1803 }
1804
1805 function number_list($name, $selected, $from, $to, $no_option=false)
1806 {
1807         $items = array();
1808         for ($i = $from; $i <= $to; $i++)
1809                 $items[$i] = "$i";
1810
1811         return array_selector($name, $selected, $items,
1812                                 array(  'spec_option' => $no_option,
1813                                                 'spec_id' => reserved_words::get_all_numeric()) );
1814 }
1815
1816 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1817 {
1818         if ($label != null)
1819                 label_cell($label);
1820         echo "<td>\n";
1821         number_list($name, $selected, $from, $to, $no_option);
1822         echo "</td>\n";
1823 }
1824
1825 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1826 {
1827         echo "<tr>\n";
1828         number_list_cells($label, $name, $selected, $from, $to, $no_option);
1829         echo "</tr>\n";
1830 }
1831
1832 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1833         $submit_on_change=true)
1834 {
1835         $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1836                 ." GROUP BY profile";
1837         $result = db_query($sql, 'cannot get all profile names');
1838         $profiles = array();
1839         while($myrow=db_fetch($result)) {
1840                 $profiles[$myrow['profile']] = $myrow['profile'];
1841         }
1842
1843         echo "<tr>";
1844         if ($label != null)
1845                 echo "<td>$label</td>\n";
1846         echo "<td>";
1847
1848         array_selector($name, $selected_id, $profiles, 
1849                 array( 'select_submit'=> $submit_on_change,
1850                         'spec_option'=>$spec_opt,
1851                         'spec_id' => ''
1852                  ));
1853
1854         echo "</td></tr>\n";
1855 }
1856
1857 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1858 {
1859         static $printers; // query only once for page display
1860
1861         if (!$printers) {
1862                 $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; 
1863                 $result = db_query($sql, 'cannot get all printers');
1864                 $printers = array();
1865                 while($myrow=db_fetch($result)) {
1866                         $printers[$myrow['id']] = $myrow['name'].'&nbsp;-&nbsp;'.$myrow['description'];
1867                 }
1868         }
1869         array_selector($name, $selected_id, $printers, 
1870                 array( 'select_submit'=> $submit_on_change,
1871                         'spec_option'=>$spec_opt,
1872                         'spec_id' => ''
1873                  ));
1874 }
1875
1876
1877 ?>