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