Async update of locations selector
[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         return base_stock_items_list("mb_flag!='D'", $name, $selected_id,
646                 $all_option, $submit_on_change);
647 }
648
649 //------------------------------------------------------------------------------------
650
651 function stock_purchasable_items_list($name, $selected_id,      $all_option=false,
652                 $submit_on_change=false, $opts=array())
653 {
654  global $all_items;
655         $sql = "SELECT stock_id, s.description, c.description
656                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c
657                         WHERE s.category_id=c.category_id
658                                 AND mb_flag !='M' ";
659         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
660           array_merge( array(
661                 'format' => '_format_stock_items',
662                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
663                 'spec_id' => $all_items,
664                 'search_box' => true,
665                 'search' => array("stock_id", "c.description","s.description"),
666                 'search_submit' => get_company_pref('no_item_list')!=0,
667                 'size'=>10,
668                 'select_submit'=> $submit_on_change
669           ), $opts) );
670
671 }
672
673 function stock_purchasable_items_list_cells($label, $name, $selected_id,
674                         $all_option=false, $submit_on_change=false)
675 {
676         if ($label != null)
677                 echo "<td>$label</td>\n";
678         $ret = stock_purchasable_items_list($name, $selected_id, $all_option,
679                 $submit_on_change, array('cells'=>true) );
680         return $ret;
681 }
682
683 function stock_purchasable_items_list_row($label, $name, $selected_id,
684                         $all_option=false, $submit_on_change=false)
685 {
686         echo "<tr>\n";
687         $ret = stock_purchasable_items_list_cells($label, $name, $selected_id,
688                 $all_option, $submit_on_change);
689         echo "</tr>\n";
690         return $ret;
691 }
692
693 //------------------------------------------------------------------------------------
694
695 function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
696 {
697         default_focus($name);
698         echo "<tr>";
699         if ($label != NULL)
700                 echo "<td>$label</td>\n";
701         echo "<td>";
702         if ($enabled)
703                 $sel = "<select name='$name' onchange='JsHttpRequest.request(\"_{$name}_update\", this.form);'>\n";
704                 
705         else
706                 $sel =  "<select disabled name='$name'>\n";
707         if ($selected_id == null)
708                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
709         if ($selected_id == "")
710                 $_POST[$name] = $selected_id = "B";
711         $sel .= "<option " . ($selected_id == 'M'?" selected ":"") . " value='M'>" . _("Manufactured"). "</option>\n";
712         $sel .= "<option " . ($selected_id == 'B'?" selected ":"") . " value='B'>" . _("Purchased"). "</option>\n";
713         $sel .= "<option " . ($selected_id == 'D'?" selected ":"") . " value='D'>" . _("Service"). "</option>\n";
714         $sel .= "</select>";
715         echo $sel;
716         echo "</td></tr>\n";
717         return $sel;
718 }
719
720 function stock_units_list_row($label, $name, $value, $enabled=true)
721 {
722         default_focus($name);
723         $result = get_all_item_units();
724         echo "<tr><td>$label</td>\n";
725         if ($enabled)
726                 echo "<td><select name='$name'>";
727         else
728                 echo "<td><select disabled name='$name'>";
729
730         if ($value == null)
731                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
732
733         while($unit = db_fetch($result))
734         {
735                 if ($value == "")
736                 {
737                         $_POST[$name] = $unit['abbr'];
738                 }
739                 $descr = $unit['name'];
740                 if ($value==$unit['abbr'])
741                 {
742                         echo "<option selected value='".$unit['abbr']."'>$descr</option>\n";
743                 }
744                 else
745                 {
746                         echo "<option value='".$unit['abbr']."'>$descr</option>\n";
747                 }
748         }
749         echo "</select></td></tr>\n";
750 }
751
752 //------------------------------------------------------------------------------------
753
754 function tax_types_list($name, $selected_id, $none_option=false, $submit_on_change=false)
755 {
756         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
757
758         return combo_input($name, $selected_id, $sql, 'id', 'name',
759         array(
760                 'spec_option' => $none_option,
761                 'spec_id' => 0,
762                 'select_submit'=> $submit_on_change,
763                 'async' => false,
764         ) );
765 }
766
767 function tax_types_list_cells($label, $name, $selected_id, $none_option=false,
768         $submit_on_change=false)
769 {
770         if ($label != null)
771                 echo "<td>$label</td>\n";
772         echo "<td>";
773         $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
774         echo "</td>\n";
775         return $str;
776 }
777
778 function tax_types_list_row($label, $name, $selected_id, $none_option=false,
779         $submit_on_change=false)
780 {
781         echo "<tr>\n";
782         $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
783         echo "</tr>\n";
784         return $str;
785 }
786
787 //------------------------------------------------------------------------------------
788
789 function tax_groups_list($name, $selected_id,
790         $none_option=false, $submit_on_change=false)
791 {
792         $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
793
794         return combo_input($name, $selected_id, $sql, 'id', 'name',
795         array(
796                 'order' => 'id',
797                 'spec_option' => $none_option,
798                 'spec_id' => 0,
799                 'select_submit'=> $submit_on_change,
800                 'async' => false,
801         ) );
802 }
803
804 function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
805 {
806         if ($label != null)
807                 echo "<td>$label</td>\n";
808         echo "<td>";
809         $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
810         echo "</td>\n";
811         return $str;
812 }
813
814 function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
815 {
816         echo "<tr>\n";
817         $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
818         echo "</tr>\n";
819         return $str;
820 }
821
822 //------------------------------------------------------------------------------------
823
824 function item_tax_types_list($name, $selected_id)
825 {
826         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
827         combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
828 }
829
830 function item_tax_types_list_cells($label, $name, $selected_id)
831 {
832         if ($label != null)
833                 echo "<td>$label</td>\n";
834         echo "<td>";
835         item_tax_types_list($name, $selected_id);
836         echo "</td>\n";
837 }
838
839 function item_tax_types_list_row($label, $name, $selected_id)
840 {
841         echo "<tr>\n";
842         item_tax_types_list_cells($label, $name, $selected_id);
843         echo "</tr>\n";
844 }
845
846 //------------------------------------------------------------------------------------
847
848 function shippers_list($name, $selected_id)
849 {
850         $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
851         combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
852 }
853
854 function shippers_list_cells($label, $name, $selected_id)
855 {
856         if ($label != null)
857                 echo "<td>$label</td>\n";
858         echo "<td>";
859         shippers_list($name, $selected_id);
860         echo "</td>\n";
861 }
862
863 function shippers_list_row($label, $name, $selected_id)
864 {
865         echo "<tr>\n";
866         shippers_list_cells($label, $name, $selected_id);
867         echo "</tr>\n";
868 }
869
870 //-------------------------------------------------------------------------------------
871
872 function sales_persons_list($name, $selected_id)
873 {
874         $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
875         combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
876 }
877
878 function sales_persons_list_cells($label, $name, $selected_id)
879 {
880         if ($label != null)
881                 echo "<td>$label</td>\n";
882         echo "<td>\n";
883         sales_persons_list($name, $selected_id);
884         echo "</td>\n";
885 }
886
887 function sales_persons_list_row($label, $name, $selected_id, $submit_on_change=false)
888 {
889         echo "<tr>\n";
890         sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
891         echo "</tr>\n";
892 }
893
894 //------------------------------------------------------------------------------------
895
896 function sales_areas_list($name, $selected_id)
897 {
898         $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
899         combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
900 }
901
902 function sales_areas_list_cells($label, $name, $selected_id)
903 {
904         if ($label != null)
905                 echo "<td>$label</td>\n";
906         echo "<td>";
907         sales_areas_list($name, $selected_id);
908         echo "</td>\n";
909 }
910
911 function sales_areas_list_row($label, $name, $selected_id)
912 {
913         echo "<tr>\n";
914         sales_areas_list_cells($label, $name, $selected_id);
915         echo "</tr>\n";
916 }
917
918 //------------------------------------------------------------------------------------
919
920 function workorders_list($name, $selected_id)
921 {
922         $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
923         combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
924 }
925
926 function workorders_list_cells($label, $name, $selected_id)
927 {
928         if ($label != null)
929                 echo "<td>$label</td>\n";
930         echo "<td>";
931         workorders_list($name, $selected_id);
932         echo "</td>\n";
933 }
934
935 function workorders_list_row($label, $name, $selected_id)
936 {
937         echo "<tr>\n";
938         workorders_list_cells($label, $name, $selected_id);
939         echo "</tr>\n";
940 }
941
942 //------------------------------------------------------------------------------------
943
944 function payment_terms_list($name, $selected_id)
945 {
946         $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
947         combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
948 }
949
950 function payment_terms_list_cells($label, $name, $selected_id)
951 {
952         if ($label != null)
953                 echo "<td>$label</td>\n";
954         echo "<td>";
955         payment_terms_list($name, $selected_id);
956         echo "</td>\n";
957 }
958
959 function payment_terms_list_row($label, $name, $selected_id)
960 {
961         echo "<tr>\n";
962         payment_terms_list_cells($label, $name, $selected_id);
963         echo "</tr>\n";
964 }
965
966 //------------------------------------------------------------------------------------
967
968 function credit_status_list($name, $selected_id)
969 {
970         $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
971         combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
972 }
973
974 function credit_status_list_cells($label, $name, $selected_id)
975 {
976         if ($label != null)
977                 echo "<td>$label</td>\n";
978         echo "<td>";
979         credit_status_list($name, $selected_id);
980         echo "</td>\n";
981 }
982
983 function credit_status_list_row($label, $name, $selected_id)
984 {
985         echo "<tr>\n";
986         credit_status_list_cells($label, $name, $selected_id);
987         echo "</tr>\n";
988 }
989
990 //-----------------------------------------------------------------------------------------------
991
992 function sales_types_list($name, $selected_id, $submit_on_change=false, $special_option=false)
993 {
994         $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
995
996         return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
997         array(
998                 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
999                 'spec_id' => 0,
1000                 'select_submit'=> $submit_on_change,
1001         //        'async' => false,
1002         ) );
1003 }
1004
1005 function sales_types_list_cells($label, $name, $selected_id, $submit_on_change=false, $special_option=false)
1006 {
1007         if ($label != null)
1008                 echo "<td>$label</td>\n";
1009         echo "<td>";
1010         $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1011         echo "</td>\n";
1012         return $str;
1013 }
1014
1015 function sales_types_list_row($label, $name, $selected_id, $submit_on_change=false, $special_option=false)
1016 {
1017         echo "<tr>\n";
1018         $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1019         echo "</tr>\n";
1020         return $str;
1021 }
1022
1023 //-----------------------------------------------------------------------------------------------
1024
1025 function movement_types_list($name, $selected_id)
1026 {
1027         $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1028         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1029 }
1030
1031 function movement_types_list_cells($label, $name, $selected_id)
1032 {
1033         if ($label != null)
1034                 echo "<td>$label</td>\n";
1035         echo "<td>";
1036         movement_types_list($name, $selected_id);
1037         echo "</td>\n";
1038 }
1039
1040 function movement_types_list_row($label, $name, $selected_id)
1041 {
1042         echo "<tr>\n";
1043         movement_types_list_cells($label, $name, $selected_id);
1044         echo "</tr>\n";
1045 }
1046
1047 //-----------------------------------------------------------------------------------------------
1048
1049 function bank_trans_types_list($name, $selected_id)
1050 {
1051         $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1052         combo_input($name, $selected_id, $sql, 'id', 'name', array());
1053 }
1054
1055 function bank_trans_types_list_cells($label, $name, $selected_id)
1056 {
1057         if ($label != null)
1058                 echo "<td>$label</td>\n";
1059         echo "<td>";
1060         bank_trans_types_list($name, $selected_id);
1061         echo "</td>\n";
1062 }
1063
1064 function bank_trans_types_list_row($label, $name, $selected_id)
1065 {
1066         echo "<tr>\n";
1067         bank_trans_types_list_cells($label, $name, $selected_id);
1068         echo "</tr>\n";
1069 }
1070
1071 //-----------------------------------------------------------------------------------------------
1072
1073 function workcenter_list($name, $selected_id, $all_option=false)
1074 {
1075         global $all_items;
1076
1077         $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1078
1079         return combo_input($name, $selected_id, $sql, 'id', 'name',
1080         array(
1081                 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1082                 'spec_id' => $all_items,
1083         ) );
1084 }
1085
1086 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1087 {
1088         default_focus($name);
1089         if ($label != null)
1090                 echo "<td>$label</td>\n";
1091         echo "<td>";
1092         workcenter_list($name, $selected_id, $all_option);
1093         echo "</td>\n";
1094 }
1095
1096 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1097 {
1098         echo "<tr>\n";
1099         workcenter_list_cells($label, $name, $selected_id, $all_option);
1100         echo "</tr>\n";
1101 }
1102
1103 //-----------------------------------------------------------------------------------------------
1104
1105 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1106 {
1107         $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1108                 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1109                 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1110
1111         return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1112         array(
1113                 'format' => '_format_add_curr',
1114                 'select_submit'=> $submit_on_change,
1115                 'async' => false
1116         ) );
1117 }
1118
1119 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1120 {
1121         if ($label != null)
1122                 echo "<td>$label</td>\n";
1123         echo "<td>";
1124         $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1125         echo "</td>\n";
1126         return $str;
1127 }
1128
1129 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1130 {
1131         echo "<tr>\n";
1132         $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1133         echo "</tr>\n";
1134         return $str;
1135 }
1136
1137 //-----------------------------------------------------------------------------------------------
1138
1139 function class_list($name, $selected_id, $submit_on_change=false)
1140 {
1141         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1142
1143         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1144         array(
1145                 'select_submit'=> $submit_on_change,
1146                 'async' => false
1147         ) );
1148
1149 }
1150
1151 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1152 {
1153         if ($label != null)
1154                 echo "<td>$label</td>\n";
1155         echo "<td>";
1156         $str = class_list($name, $selected_id, $submit_on_change);
1157         echo "</td>\n";
1158         return $str;
1159 }
1160
1161 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1162 {
1163         echo "<tr>\n";
1164         $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1165         echo "</tr>\n";
1166         return $str;
1167 }
1168
1169 //-----------------------------------------------------------------------------------------------
1170
1171 function stock_categories_list($name, $selected_id)
1172 {
1173         $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1174         combo_input($name, $selected_id, $sql, 'category_id', 'description',
1175         array('order'=>'category_id'));
1176 }
1177
1178 function stock_categories_list_cells($label, $name, $selected_id)
1179 {
1180         if ($label != null)
1181                 echo "<td>$label</td>\n";
1182         echo "<td>";
1183         stock_categories_list($name, $selected_id);
1184         echo "</td>\n";
1185 }
1186
1187 function stock_categories_list_row($label, $name, $selected_id)
1188 {
1189         echo "<tr>\n";
1190         stock_categories_list_cells($label, $name, $selected_id);
1191         echo "</tr>\n";
1192 }
1193
1194 //-----------------------------------------------------------------------------------------------
1195
1196 function gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric)
1197 {
1198         global $all_items;
1199
1200         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1201
1202         combo_input($name, $selected_id, $sql, 'id', 'name',
1203         array(
1204                 'order' => 'id',
1205                 'spec_option' =>$all_option,
1206                 'spec_id' => $all_option_numeric ? 0 : $all_items
1207         ) );
1208 }
1209
1210 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false,
1211         $all_option_numeric=false)
1212 {
1213         if ($label != null)
1214                 echo "<td>$label</td>\n";
1215         echo "<td>";
1216         gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1217         echo "</td>\n";
1218 }
1219
1220 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false,
1221         $all_option_numeric=false)
1222 {
1223         echo "<tr>\n";
1224         gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1225                 $all_option_numeric);
1226         echo "</tr>\n";
1227 }
1228
1229 //-----------------------------------------------------------------------------------------------
1230 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
1231         $show_group=false, $cells=false, $all_option=false)
1232 {
1233         if ($skip_bank_accounts)
1234                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1235                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1236                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1237                         ."ON chart.account_code=acc.account_code
1238                                 WHERE acc.account_code IS NULL
1239                         AND chart.account_type=type.id";
1240         else
1241                 $sql = "SELECT chart.account_code, chart.account_name, type.name
1242                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1243                         WHERE chart.account_type=type.id";
1244
1245         combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1246         array(
1247                 'format' => '_format_account' .  ($show_group ? '2' : ''),
1248                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1249                 'spec_id' => '',
1250                 'order' => 'account_code',
1251                 'search_box' => $cells,
1252                         'search_submit' => false,
1253                         'size' => 12,
1254                         'max' => 10,
1255                         'cells' => true
1256         ) );
1257
1258 }
1259
1260 function _format_account($row)
1261 {
1262                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1263 }
1264
1265 function _format_account2($row)
1266 {
1267                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[2] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1268 }
1269
1270 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1271         $show_group=false, $cells=false, $all_option=false)
1272 {
1273         if ($label != null)
1274                 echo "<td>$label</td>\n";
1275         echo "<td>";
1276         gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1277         echo "</td>\n";
1278 }
1279
1280 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1281         $show_group=false, $cells=false, $all_option=false)
1282 {
1283         echo "<tr>\n";
1284         gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1285                 $show_group, $cells, $all_option);
1286         echo "</tr>\n";
1287 }
1288
1289 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1290 {
1291         default_focus($name);
1292         if ($submit_on_change == true)
1293                 echo "<select name='$name' onchange='this.form.submit();'>"; // FIX ajax
1294         else
1295                 echo "<select name='$name'>";
1296
1297         if (strlen($name_yes) == 0)
1298         {
1299                 unset($name_yes);
1300         }
1301         if (strlen($name_no) == 0)
1302         {
1303                 unset($name_no);
1304         }
1305
1306         if ($selected_id == null)
1307                 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1308         if ($selected_id == 0)
1309                 echo "<option value=1>";
1310         else
1311                 echo "<option selected value=1>";
1312         if (!isset($name_yes))
1313                 echo _("Yes") . "</option>\n";
1314         else
1315                 echo $name_yes . "</option>\n";
1316         if ($selected_id == 0)
1317                 echo "<option selected value=0>";
1318         else
1319                 echo "<option value=0>";
1320         if (!isset($name_no))
1321                 echo _("No") . "</option>\n";
1322         else
1323                 echo $name_no . "</option>\n";
1324         echo "</select>";
1325 }
1326
1327 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1328 {
1329         if ($label != null)
1330                 echo "<td>$label</td>\n";
1331         echo "<td>";
1332         $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1333         echo "</td>\n";
1334         return $str;
1335 }
1336
1337 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1338 {
1339         echo "<tr>\n";
1340         $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1341         echo "</tr>\n";
1342         return $str;
1343 }
1344
1345 //------------------------------------------------------------------------------------------------
1346
1347 function languages_list($name, $selected_id)
1348 {
1349         global $installed_languages;
1350
1351         default_focus($name);
1352         echo "<select name='$name'>";
1353
1354         if ($selected_id == null)
1355                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1356         foreach ($installed_languages as $lang)
1357         {
1358                 echo "<option ";
1359                 if ($selected_id == $lang['code'])
1360                         echo "selected ";
1361                 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1362         }
1363 }
1364
1365 function languages_list_cells($label, $name, $selected_id)
1366 {
1367         if ($label != null)
1368                 echo "<td>$label</td>\n";
1369         echo "<td>";
1370         languages_list($name, $selected_id);
1371         echo "</td>\n";
1372 }
1373
1374 function languages_list_row($label, $name, $selected_id)
1375 {
1376         echo "<tr>\n";
1377         languages_list_cells($label, $name, $selected_id);
1378         echo "</tr>\n";
1379 }
1380
1381 //------------------------------------------------------------------------------------------------
1382
1383 function bank_account_types_list($name, $selected_id)
1384 {
1385         $bank_account_types = bank_account_types::get_all();
1386
1387         default_focus($name);
1388         echo "<select name='$name'>";
1389
1390         if ($selected_id == null)
1391                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1392         foreach ($bank_account_types as $type)
1393         {
1394                 echo "<option ";
1395                 if ($selected_id == "" || $selected_id == $type['id'])
1396                         echo "selected ";
1397                 echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1398         }
1399 }
1400
1401 function bank_account_types_list_cells($label, $name, $selected_id)
1402 {
1403         if ($label != null)
1404                 echo "<td>$label</td>\n";
1405         echo "<td>";
1406         bank_account_types_list($name, $selected_id);
1407         echo "</td>\n";
1408 }
1409
1410 function bank_account_types_list_row($label, $name, $selected_id)
1411 {
1412         echo "<tr>\n";
1413         bank_account_types_list_cells($label, $name, $selected_id);
1414         echo "</tr>\n";
1415 }
1416
1417 //------------------------------------------------------------------------------------------------
1418
1419 function payment_person_types_list($name, $selected_id, $related=null)
1420 {
1421         $types = payment_person_types::get_all();
1422
1423         default_focus($name);
1424         echo "<select name='$name'";
1425         if ($related)   // FIX ajax
1426                 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1427         echo ">";
1428
1429         if ($selected_id == null)
1430                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1431         foreach ($types as $type)
1432         {
1433                 if (payment_person_types::has_items($type['id']))
1434                 {
1435                         if ($selected_id == "")
1436                                 $_POST[$name] = $selected_id = $type['id'];
1437                         echo "<option ";
1438                         if ($selected_id == $type['id'])
1439                                 echo "selected ";
1440                         echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1441                 }
1442         }
1443 }
1444
1445 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1446 {
1447         if ($label != null)
1448                 echo "<td>$label</td>\n";
1449         echo "<td>";
1450         $str = payment_person_types_list($name, $selected_id, $related);
1451         echo "</td>\n";
1452         return $str;
1453 }
1454
1455 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1456 {
1457         echo "<tr>\n";
1458         $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1459         echo "</tr>\n";
1460         return $str;
1461 }
1462
1463 //------------------------------------------------------------------------------------------------
1464
1465 function wo_types_list($name, $selected_id)
1466 {
1467         $types = wo_types::get_all();
1468
1469         default_focus($name);   // FIX ajax
1470         echo "<select name='$name' onchange='this.form.submit();'>";
1471
1472         if ($selected_id == null)
1473                 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1474         foreach ($types as $type)
1475         {
1476                 echo "<option ";
1477                 if ($selected_id == $type['id'])
1478                         echo "selected ";
1479                 echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1480         }
1481         echo "</select>";
1482 }
1483
1484 function wo_types_list_row($label, $name, $selected_id)
1485 {
1486         echo "<tr><td>$label</td><td>\n";
1487         $str = wo_types_list($name, $selected_id);
1488         echo "</td></tr>\n";
1489         return $str;
1490 }
1491
1492 //------------------------------------------------------------------------------------------------
1493
1494 function dateformats_list_row($label, $name, $value)
1495 {
1496         global $dateformats;
1497
1498         default_focus($name);
1499         echo "<tr><td>$label</td>\n";
1500         echo "<td><select name='$name'>";
1501
1502         if ($value == null)
1503                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1504         $counter = 0;
1505         foreach ($dateformats as $df)
1506         {
1507
1508                 if ($value==$counter)
1509                 {
1510                         echo "<option selected value='$counter'>$df</option>\n";
1511                 }
1512                 else
1513                 {
1514                         echo "<option value='$counter'>$df</option>\n";
1515                 }
1516                 $counter++;
1517         }
1518         echo "</select></td></tr>\n";
1519 }
1520
1521 function dateseps_list_row($label, $name, $value)
1522 {
1523         global $dateseps;
1524
1525         default_focus($name);
1526         echo "<tr><td>$label</td>\n";
1527         echo "<td><select name='$name'>";
1528
1529         if ($value == null)
1530                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1531         $counter = 0;
1532         foreach ($dateseps as $ds)
1533         {
1534
1535                 if ($value==$counter)
1536                 {
1537                         echo "<option selected value='$counter'>$ds</option>\n";
1538                 }
1539                 else
1540                 {
1541                         echo "<option value='$counter'>$ds</option>\n";
1542                 }
1543                 $counter++;
1544         }
1545         echo "</select></td></tr>\n";
1546 }
1547
1548 function thoseps_list_row($label, $name, $value)
1549 {
1550         global $thoseps;
1551
1552         default_focus($name);
1553         echo "<tr><td>$label</td>\n";
1554         echo "<td><select name='$name'>";
1555
1556         if ($value == null)
1557                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1558         $counter = 0;
1559         foreach ($thoseps as $ts)
1560         {
1561
1562                 if ($value==$counter)
1563                 {
1564                         echo "<option selected value='$counter'>$ts</option>\n";
1565                 }
1566                 else
1567                 {
1568                         echo "<option value='$counter'>$ts</option>\n";
1569                 }
1570                 $counter++;
1571         }
1572         echo "</select></td></tr>\n";
1573 }
1574
1575 function decseps_list_row($label, $name, $value)
1576 {
1577         global $decseps;
1578
1579         default_focus($name);
1580         echo "<tr><td>$label</td>\n";
1581         echo "<td><select name='$name'>";
1582
1583         if ($value == null)
1584                 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1585         $counter = 0;
1586         foreach ($decseps as $ds)
1587         {
1588
1589                 if ($value==$counter)
1590                 {
1591                         echo "<option selected value='$counter'>$ds</option>\n";
1592                 }
1593                 else
1594                 {
1595                         echo "<option value='$counter'>$ds</option>\n";
1596                 }
1597                 $counter++;
1598         }
1599         echo "</select></td></tr>\n";
1600 }
1601
1602 function themes_list_row($label, $name, $value)
1603 {
1604         global $path_to_root;
1605
1606         default_focus($name);
1607         $path = $path_to_root.'/themes/';
1608         $themes = array();
1609         $themedir = opendir($path);
1610         while(false !== ($fname = readdir($themedir)))
1611         {
1612                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1613                 {
1614                         $themes[] =  $fname;
1615                 }
1616         }
1617         sort($themes);
1618         echo "<tr><td>$label</td>\n";
1619         echo "<td><select name='$name'>";
1620
1621         if ($value == null)
1622                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1623         foreach ($themes as $th)
1624         {
1625
1626                 if ($value==$th)
1627                 {
1628                         echo "<option selected value='$th'>$th</option>\n";
1629                 }
1630                 else
1631                 {
1632                         echo "<option value='$th'>$th</option>\n";
1633                 }
1634         }
1635         echo "</select></td></tr>\n";
1636 }
1637
1638 function pagesizes_list_row($label, $name, $value)
1639 {
1640         global $pagesizes;
1641
1642         default_focus($name);
1643         echo "<tr><td>$label</td>\n";
1644         echo "<td><select name='$name'>";
1645
1646         if ($value == null)
1647                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1648         foreach ($pagesizes as $pz)
1649         {
1650
1651                 if ($value==$pz)
1652                 {
1653                         echo "<option selected value='$pz'>$pz</option>\n";
1654                 }
1655                 else
1656                 {
1657                         echo "<option value='$pz'>$pz</option>\n";
1658                 }
1659         }
1660         echo "</select></td></tr>\n";
1661 }
1662
1663 function security_headings_list_row($label, $name, $value)
1664 {
1665         global $security_headings;
1666
1667         default_focus($name);
1668         echo "<tr><td>$label</td>\n";
1669         echo "<td><select name='$name'>";
1670
1671         if ($value == null)
1672                 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
1673         $counter=0;
1674         foreach ($security_headings as $sh)
1675         {
1676
1677                 if ($value==$counter)
1678                 {
1679                         echo "<option selected value='$counter'>$sh</option>\n";
1680                 }
1681                 else
1682                 {
1683                         echo "<option value='$counter'>$sh</option>\n";
1684                 }
1685                 $counter++;
1686         }
1687         echo "</select></td></tr>\n";
1688 }
1689
1690 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
1691 {
1692         global $systypes_array;
1693
1694         default_focus($name);
1695         if ($label != null)
1696                 echo "<td>$label</td>\n";
1697         echo "<td><select name='$name'";
1698         if ($submit_on_change)
1699                 echo " onchange='this.form.submit();'>";        // FIX ajax
1700         else
1701                 echo ">";
1702         if ($value == null)
1703                 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1704         foreach ($systypes_array as $key=>$type)
1705         {
1706
1707                 if ($value==$key)
1708                 {
1709                         echo "<option selected value='$key'>".$type['name']."</option>\n";
1710                 }
1711                 else
1712                 {
1713                         echo "<option value='$key'>".$type['name']."</option>\n";
1714                 }
1715         }
1716         echo "</select></td>\n";
1717 }
1718
1719 function systypes_list_row($label, $name, $value, $submit_on_change=false)
1720 {
1721         echo "<tr>\n";
1722         $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1723         echo "</tr>\n";
1724         return $str;
1725 }
1726
1727 function cust_allocations_list_cells($label, $name, $selected)
1728 {
1729         global $all_items;
1730         default_focus($name);
1731         if ($label != null)
1732                 label_cell($label);
1733         if ($selected == null)
1734                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1735         echo "<td><select name='$name'>";
1736         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
1737         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
1738         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1739         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1740         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1741         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Delivery Notes"). "</option>\n";
1742         echo "</select></td>\n";
1743 }
1744
1745 function supp_allocations_list_cells($name, $selected)
1746 {
1747         global $all_items;
1748
1749         default_focus($name);
1750         if ($selected == null)
1751                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1752         echo "<td><select name='$name'>";
1753         echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
1754         echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Invoices"). "</option>\n";
1755         echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1756         echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1757         echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1758         echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Overdue Credit Notes"). "</option>\n";
1759         echo "</select></td>\n";
1760 }
1761
1762 function policy_list_cells($label, $name, $selected)
1763 {
1764         default_focus($name);
1765         if ($selected == null)
1766         {
1767                 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1768                 if ($selected == "")
1769                         $_POST[$name] = $selected;
1770         }
1771         if ($label != null)
1772                 label_cell($label);
1773         echo "<td><select name='$name'>";
1774         echo "<option " . ($selected == ''?" selected ":"") . " value=''>" . _("Automatically put balance on back order"). "</option>\n";
1775         echo "<option " . ($selected == 'CAN'?" selected ":"") . " value='CAN'>" . _("Cancel any quantites not delivered"). "</option>\n";
1776         echo "</select></td>\n";
1777 }
1778
1779 function policy_list_row($label, $name, $selected)
1780 {
1781         echo "<tr>\n";
1782         policy_list_cells($label, $name, $selected);
1783         echo "</tr>\n";
1784 }
1785
1786 function credit_type_list_cells($label, $name, $selected, $submit_on_change=false)
1787 {
1788         default_focus($name);
1789         if ($selected == null)
1790         {
1791                 $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]);
1792                 if ($selected == "Return")
1793                         $_POST[$name] = $selected;
1794         }
1795         if ($label != null)
1796                 label_cell($label);
1797         echo "<td><select name='$name'";
1798         if ($submit_on_change)
1799                 echo " onchange='JsHttpRequest.request(\"_{$name}_update\", this.form);'>";
1800         else
1801                 echo ">";
1802         echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
1803         echo "<option " . ($selected == 'WriteOff'?" selected ":"") . " value='WriteOff'>" . _("Items Written Off"). "</option>\n";
1804         echo "</select></td>\n";
1805 }
1806
1807 function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
1808 {
1809         echo "<tr>\n";
1810         $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1811         echo "</tr>\n";
1812         return $str;
1813 }
1814
1815 function number_list($name, $selected, $from, $to, $no_option=false)
1816 {
1817         default_focus($name);
1818         if ($selected == null)
1819         {
1820                 $selected = (!isset($_POST[$name]) ? reserved_words::get_all_numeric() : $_POST[$name]);
1821         }
1822         echo "<select name='$name'>";
1823         if ($no_option !== false)
1824         {
1825                 $reserved_word = reserved_words::get_all_numeric();
1826
1827         if ($selected == $reserved_word)
1828         {
1829              echo "<option selected value='$reserved_word'>$no_option</option>\n";
1830         }
1831         else
1832         {
1833              echo "<option value='$reserved_word'>$no_option</option>\n";
1834         }
1835         }
1836
1837         for ($i = $from; $i <= $to; $i++)
1838         {
1839                 if ($selected == $i)
1840                 {
1841                         echo "<option selected value='$i'>$i</option>\n";
1842                 }
1843                 else
1844                 {
1845                         echo "<option value='$i'>$i</option>\n";
1846                 }
1847         }
1848         echo "</select>\n";
1849 }
1850
1851 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1852 {
1853         if ($label != null)
1854                 label_cell($label);
1855         echo "<td>\n";
1856         number_list($name, $selected, $from, $to, $no_option);
1857         echo "</td>\n";
1858 }
1859
1860 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1861 {
1862         echo "<tr>\n";
1863         number_list_cells($label, $name, $selected, $from, $to, $no_option);
1864         echo "</tr>\n";
1865 }
1866 ?>