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