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