Added remote printing support.
[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                         (in_ajax() ? '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                         .(in_ajax() && !$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                                 (in_ajax() ? '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                         (in_ajax() ? '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' => 0,
891                 'select_submit'=> $submit_on_change,
892                 'async' => false,
893         ) );
894 }
895
896 function tax_groups_list_cells($label, $name, $selected_id=null, $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, false, $submit_on_change);
902         echo "</td>\n";
903         return $str;
904 }
905
906 function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
907 {
908         echo "<tr>\n";
909         $str = tax_groups_list_cells($label, $name, $selected_id, false, $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.account_code, 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, 'account_code', '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
1231 function class_list($name, $selected_id=null, $submit_on_change=false)
1232 {
1233         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1234
1235         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1236         array(
1237                 'select_submit'=> $submit_on_change,
1238                 'async' => false
1239         ) );
1240
1241 }
1242
1243 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1244 {
1245         if ($label != null)
1246                 echo "<td>$label</td>\n";
1247         echo "<td>";
1248         $str = class_list($name, $selected_id, $submit_on_change);
1249         echo "</td>\n";
1250         return $str;
1251 }
1252
1253 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1254 {
1255         echo "<tr>\n";
1256         $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1257         echo "</tr>\n";
1258         return $str;
1259 }
1260
1261 //-----------------------------------------------------------------------------------------------
1262
1263 function stock_categories_list($name, $selected_id=null)
1264 {
1265         $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1266         combo_input($name, $selected_id, $sql, 'category_id', 'description',
1267         array('order'=>'category_id'));
1268 }
1269
1270 function stock_categories_list_cells($label, $name, $selected_id=null)
1271 {
1272         if ($label != null)
1273                 echo "<td>$label</td>\n";
1274         echo "<td>";
1275         stock_categories_list($name, $selected_id);
1276         echo "</td>\n";
1277 }
1278
1279 function stock_categories_list_row($label, $name, $selected_id=null)
1280 {
1281         echo "<tr>\n";
1282         stock_categories_list_cells($label, $name, $selected_id);
1283         echo "</tr>\n";
1284 }
1285
1286 //-----------------------------------------------------------------------------------------------
1287
1288 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1289 {
1290         global $all_items;
1291
1292         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1293
1294         combo_input($name, $selected_id, $sql, 'id', 'name',
1295         array(
1296                 'order' => 'id',
1297                 'spec_option' =>$all_option,
1298                 'spec_id' => $all_option_numeric ? 0 : $all_items
1299         ) );
1300 }
1301
1302 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1303         $all_option_numeric=false)
1304 {
1305         if ($label != null)
1306                 echo "<td>$label</td>\n";
1307         echo "<td>";
1308         gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1309         echo "</td>\n";
1310 }
1311
1312 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1313         $all_option_numeric=false)
1314 {
1315         echo "<tr>\n";
1316         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1317                 $all_option_numeric);
1318         echo "</tr>\n";
1319 }
1320
1321 //-----------------------------------------------------------------------------------------------
1322 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1323         $show_group=false, $cells=false, $all_option=false, $submit_on_change=false)
1324 {
1325         if ($skip_bank_accounts)
1326                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1327                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1328                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1329                         ."ON chart.account_code=acc.account_code
1330                                 WHERE acc.account_code IS NULL
1331                         AND chart.account_type=type.id";
1332         else
1333                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1334                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1335                         WHERE chart.account_type=type.id";
1336
1337         combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1338         array(
1339                 'format' => '_format_account' .  ($show_group ? '2' : ''),
1340                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1341                 'spec_id' => '',
1342                 'order' => 'account_code',
1343                 'search_box' => $cells,
1344                         'search_submit' => false,
1345                         'size' => 12,
1346                         'max' => 10,
1347                         'cells' => true,
1348                 'select_submit'=> $submit_on_change,
1349                 'async' => false
1350         ) );
1351
1352 }
1353
1354 function _format_account($row)
1355 {
1356                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1357 }
1358
1359 function _format_account2($row)
1360 {
1361                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1362 }
1363
1364 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1365         $show_group=false, $cells=false, $all_option=false)
1366 {
1367         if ($label != null)
1368                 echo "<td>$label</td>\n";
1369         echo "<td>";
1370         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1371         echo "</td>\n";
1372 }
1373
1374 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1375         $show_group=false, $cells=false, $all_option=false)
1376 {
1377         echo "<tr>\n";
1378         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1379                 $show_group, $cells, $all_option);
1380         echo "</tr>\n";
1381 }
1382
1383 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1384 {
1385         $items = array();
1386         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1387         $items['0'] = strlen($name_no) ? $name_no : _("No");
1388
1389         return array_selector($name, $selected_id, $items, 
1390                 array( 
1391                         'select_submit'=> $submit_on_change,
1392                         'async' => false ) ); // FIX?
1393 }
1394
1395 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1396 {
1397         if ($label != null)
1398                 echo "<td>$label</td>\n";
1399         echo "<td>";
1400         $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1401         echo "</td>\n";
1402         return $str;
1403 }
1404
1405 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1406 {
1407         echo "<tr>\n";
1408         $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1409         echo "</tr>\n";
1410         return $str;
1411 }
1412
1413 //------------------------------------------------------------------------------------------------
1414
1415 function languages_list($name, $selected_id=null)
1416 {
1417         global $installed_languages;
1418
1419         $items = array();
1420         foreach ($installed_languages as $lang)
1421                         $items[$lang['code']] = $lang['name'];
1422         
1423         return array_selector($name, $selected_id, $items );
1424 }
1425
1426 function languages_list_cells($label, $name, $selected_id=null)
1427 {
1428         if ($label != null)
1429                 echo "<td>$label</td>\n";
1430         echo "<td>";
1431         languages_list($name, $selected_id);
1432         echo "</td>\n";
1433 }
1434
1435 function languages_list_row($label, $name, $selected_id=null)
1436 {
1437         echo "<tr>\n";
1438         languages_list_cells($label, $name, $selected_id);
1439         echo "</tr>\n";
1440 }
1441
1442 //------------------------------------------------------------------------------------------------
1443
1444 function bank_account_types_list($name, $selected_id=null)
1445 {
1446         $types = bank_account_types::get_all();
1447
1448         $items = array();
1449         foreach ($types as $type)
1450         {
1451                         $items[$type['id']] = $type['name'];
1452         }
1453         
1454         return array_selector($name, $selected_id, $items );
1455 }
1456
1457 function bank_account_types_list_cells($label, $name, $selected_id=null)
1458 {
1459         if ($label != null)
1460                 echo "<td>$label</td>\n";
1461         echo "<td>";
1462         bank_account_types_list($name, $selected_id);
1463         echo "</td>\n";
1464 }
1465
1466 function bank_account_types_list_row($label, $name, $selected_id=null)
1467 {
1468         echo "<tr>\n";
1469         bank_account_types_list_cells($label, $name, $selected_id);
1470         echo "</tr>\n";
1471 }
1472
1473 //------------------------------------------------------------------------------------------------
1474 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1475 {
1476         $types = payment_person_types::get_all();
1477
1478         $items = array();
1479         foreach ($types as $type)
1480         {
1481                 if (payment_person_types::has_items($type['id']))
1482                 {
1483                         $items[$type['id']] = $type['name'];
1484                 }
1485         }
1486         
1487         return array_selector($name, $selected_id, $items, 
1488                 array( 'select_submit'=> $submit_on_change ) );
1489 }
1490
1491 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1492 {
1493         if ($label != null)
1494                 echo "<td>$label</td>\n";
1495         echo "<td>";
1496         $str = payment_person_types_list($name, $selected_id, $related);
1497         echo "</td>\n";
1498         return $str;
1499 }
1500
1501 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1502 {
1503         echo "<tr>\n";
1504         $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1505         echo "</tr>\n";
1506         return $str;
1507 }
1508
1509 //------------------------------------------------------------------------------------------------
1510
1511 function wo_types_list($name, $selected_id=null)
1512 {
1513         $types = wo_types::get_all();
1514
1515         $items = array();
1516         foreach ($types as $type)
1517                 $items[$type['id']] = $type['name'];
1518         
1519         return array_selector($name, $selected_id, $items, 
1520                 array( 'select_submit'=> true, 'async' => true ) );
1521 }
1522
1523 function wo_types_list_row($label, $name, $selected_id=null)
1524 {
1525         echo "<tr><td>$label</td><td>\n";
1526         $str = wo_types_list($name, $selected_id);
1527         echo "</td></tr>\n";
1528         return $str;
1529 }
1530
1531 //------------------------------------------------------------------------------------------------
1532
1533 function dateformats_list_row($label, $name, $value=null)
1534 {
1535         global $dateformats;
1536
1537         echo "<tr><td>$label</td>\n<td>";
1538         array_selector( $name, $value, $dateformats );
1539         echo "</td></tr>\n";
1540 }
1541
1542 function dateseps_list_row($label, $name, $value=null)
1543 {
1544         global $dateseps;
1545
1546         echo "<tr><td>$label</td>\n<td>";
1547         array_selector( $name, $value, $dateseps );
1548         echo "</td></tr>\n";
1549 }
1550
1551 function thoseps_list_row($label, $name, $value=null)
1552 {
1553         global $thoseps;
1554
1555         echo "<tr><td>$label</td>\n<td>";
1556         array_selector( $name, $value, $thoseps );
1557         echo "</td></tr>\n";
1558 }
1559
1560 function decseps_list_row($label, $name, $value=null)
1561 {
1562         global $decseps;
1563
1564         echo "<tr><td>$label</td>\n<td>";
1565         array_selector( $name, $value, $decseps );
1566         echo "</td></tr>\n";
1567 }
1568
1569 function themes_list_row($label, $name, $value=null)
1570 {
1571         global $path_to_root;
1572
1573         $path = $path_to_root.'/themes/';
1574         $themes = array();
1575         $themedir = opendir($path);
1576         while(false !== ($fname = readdir($themedir)))
1577         {
1578                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1579                 {
1580                         $themes[$fname] =  $fname;
1581                 }
1582         }
1583         ksort($themes);
1584
1585         echo "<tr><td>$label</td>\n<td>";
1586         array_selector( $name, $value, $themes );
1587         echo "</td></tr>\n";
1588 }
1589
1590 function pagesizes_list_row($label, $name, $value=null)
1591 {
1592         global $pagesizes;
1593
1594         $items = array();
1595         foreach ($pagesizes as $pz)
1596                 $items[$pz] = $pz;
1597
1598         echo "<tr><td>$label</td>\n<td>";
1599         array_selector( $name, $value, $items );
1600         echo "</td></tr>\n";
1601 }
1602
1603 function security_headings_list_row($label, $name, $value=null)
1604 {
1605         global $security_headings;
1606
1607         echo "<tr><td>$label</td>\n<td>";
1608         array_selector( $name, $value, $security_headings );
1609         echo "</td></tr>\n";
1610 }
1611
1612 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1613 {
1614         global $systypes_array;
1615
1616         if ($label != null)
1617                 echo "<td>$label</td>\n";
1618         echo "<td>";
1619
1620         $items = array();
1621         foreach ($systypes_array as $key=>$type)
1622                         $items[$key] = $type['name'];
1623         
1624         $str = array_selector($name, $value, $items, 
1625                 array( 
1626                         'select_submit'=> $submit_on_change,
1627                         'async' => false
1628                         )
1629         );
1630         echo "</td>\n";
1631         return $str;
1632 }
1633
1634 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1635 {
1636         echo "<tr>\n";
1637         $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1638         echo "</tr>\n";
1639         return $str;
1640 }
1641
1642 function cust_allocations_list_cells($label, $name, $selected=null)
1643 {
1644         global $all_items;
1645
1646         if ($label != null)
1647                 label_cell($label);
1648         echo "<td>\n";
1649         $allocs = array( 
1650                 $all_items=>_("All Types"),
1651                 '1'=> _("Sales Invoices"),
1652                 '2'=> _("Overdue Invoices"),
1653                 '3' => _("Payments"),
1654                 '4' => _("Credit Notes"),
1655                 '5' => _("Delivery Notes")
1656         );
1657         $str = array_selector($name, $selected, $allocs);
1658         echo "</td>\n";
1659         return $str;
1660 }
1661
1662 function supp_allocations_list_cell($name, $selected=null)
1663 {
1664         global $all_items;
1665
1666         echo "<td>\n";
1667         $allocs = array( 
1668                 $all_items=>_("All Types"),
1669                 '1'=> _("Invoices"),
1670                 '2'=> _("Overdue Invoices"),
1671                 '3' => _("Payments"),
1672                 '4' => _("Credit Notes"),
1673                 '5' => _("Overdue Credit Notes")
1674         );
1675         $str = array_selector($name, $selected, $allocs);
1676         echo "</td>\n";
1677         return $str;
1678 }
1679
1680 function policy_list_cells($label, $name, $selected=null)
1681 {
1682         if ($label != null)
1683                 label_cell($label);
1684         echo "<td>\n";
1685         $str = array_selector($name, $selected, 
1686                                 array( '' => _("Automatically put balance on back order"),
1687                                         'CAN' => _("Cancel any quantites not delivered")) );
1688         echo "</td>\n";
1689         return $str;
1690 }
1691
1692 function policy_list_row($label, $name, $selected=null)
1693 {
1694         echo "<tr>\n";
1695         policy_list_cells($label, $name, $selected);
1696         echo "</tr>\n";
1697 }
1698
1699 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1700 {
1701         if ($label != null)
1702                 label_cell($label);
1703         echo "<td>\n";
1704         $str = array_selector($name, $selected, 
1705                                 array( 'Return' => _("Items Returned to Inventory Location"),
1706                                         'WriteOff' => _("Items Written Off")),
1707                                 array( 'select_submit'=> $submit_on_change ) );
1708         echo "</td>\n";
1709         return $str;
1710 }
1711
1712 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1713 {
1714         echo "<tr>\n";
1715         $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1716         echo "</tr>\n";
1717         return $str;
1718 }
1719
1720 function number_list($name, $selected, $from, $to, $no_option=false)
1721 {
1722         $items = array();
1723         for ($i = $from; $i <= $to; $i++)
1724                 $items[$i] = "$i";
1725
1726         return array_selector($name, $selected, $items,
1727                                 array(  'spec_option' => $no_option,
1728                                                 'spec_id' => reserved_words::get_all_numeric()) );
1729 }
1730
1731 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1732 {
1733         if ($label != null)
1734                 label_cell($label);
1735         echo "<td>\n";
1736         number_list($name, $selected, $from, $to, $no_option);
1737         echo "</td>\n";
1738 }
1739
1740 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1741 {
1742         echo "<tr>\n";
1743         number_list_cells($label, $name, $selected, $from, $to, $no_option);
1744         echo "</tr>\n";
1745 }
1746
1747 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1748         $submit_on_change=true)
1749 {
1750         $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1751                 ." GROUP BY profile";
1752         $result = db_query($sql, 'cannot get all profile names');
1753         $profiles = array();
1754         while($myrow=db_fetch($result)) {
1755                 $profiles[$myrow['profile']] = $myrow['profile'];
1756         }
1757
1758         echo "<tr>";
1759         if ($label != null)
1760                 echo "<td>$label</td>\n";
1761         echo "<td>";
1762
1763         array_selector($name, $selected_id, $profiles, 
1764                 array( 'select_submit'=> $submit_on_change,
1765                         'spec_option'=>$spec_opt,
1766                         'spec_id' => ''
1767                  ));
1768
1769         echo "</td></tr>\n";
1770 }
1771
1772 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1773 {
1774         static $printers; // query only once for page display
1775
1776         if (!$printers) {
1777                 $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; 
1778                 $result = db_query($sql, 'cannot get all printers');
1779                 $printers = array();
1780                 while($myrow=db_fetch($result)) {
1781                         $printers[$myrow['id']] = $myrow['name'].'&nbsp;-&nbsp;'.$myrow['description'];
1782                 }
1783         }
1784         array_selector($name, $selected_id, $printers, 
1785                 array( 'select_submit'=> $submit_on_change,
1786                         'spec_option'=>$spec_opt,
1787                         'spec_id' => ''
1788                  ));
1789 }
1790
1791
1792 ?>