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