ca241361091c984b52ba9aab86e01998a43e4fea
[fa-stable.git] / includes / ui / ui_lists.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/banking.inc");
13 include_once($path_to_root . "/includes/types.inc");
14 include_once($path_to_root . "/includes/current_user.inc");
15
16 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
17         ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
18
19 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
20         ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
21
22 $all_items = ALL_TEXT;
23
24 //----------------------------------------------------------------------------
25 //      Universal sql combo generator
26 //      $sql must return selector values and selector texts in columns 0 & 1
27 //      Options are merged with defaults.
28
29 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
30         $options=null)
31 {
32 global $Ajax;
33
34 $opts = array(          // default options
35         'where'=> array(),              // additional constraints
36         'order' => $namefield,  // list sort order
37                 // special option parameters
38         'spec_option'=>false,   // option text or false
39         'spec_id' => 0,         // option id
40                 // submit on select parameters
41         'default' => '', // default value when $_POST is not set
42         'multi' => false,       // multiple select
43         'select_submit' => false, //submit on select: true/false
44         'async' => true,        // select update via ajax (true) vs _page_body reload
45                 // search box parameters
46         'sel_hint' => null,
47         'search_box' => false,  // name or true/false
48         'type' => 0,    // type of extended selector:
49                 // 0 - with (optional) visible search box, search by id
50                 // 1 - with hidden search box, search by option text
51                 // 2 - TODO reverse: box with hidden selector available via enter; this
52                 // would be convenient for optional ad hoc adding of new item
53         'search_submit' => true, //search submit button: true/false
54         'size' => 8,    // size and max of box tag
55         'max' => 50,
56         'height' => false,      // number of lines in select box
57         'cells' => false,       // combo displayed as 2 <td></td> cells
58         'search' => array(), // sql field names to search
59         'format' => null,        // format functions for regular options
60         'disabled' => false,
61         'box_hint' => null, // box/selectors hints; null = std see below
62         'category' => false, // category column name or false
63         'show_inactive' => false, // show inactive records. 
64         'editable' => false // false, or length of editable entry field
65 );
66 // ------ merge options with defaults ----------
67         if($options != null)
68                 $opts = array_merge($opts, $options);
69         if (!is_array($opts['where']))  $opts['where'] = array($opts['where']);
70
71         $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
72         // select content filtered by search field:
73         $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
74         // select set by select content field
75         $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
76
77         $select_submit =  $opts['select_submit'];
78         $spec_id = $opts['spec_id'];
79         $spec_option = $opts['spec_option'];
80         $by_id = ($opts['type'] == 0);
81         $class = $by_id ? 'combo':'combo2';
82         $disabled = $opts['disabled'] ? "disabled" : '';
83         $multi = $opts['multi'];
84         
85         if(!count($opts['search'])) {
86                 $opts['search'] = array($by_id ? $valfield : $namefield);
87         }
88         if ($opts['sel_hint'] === null) 
89                 $opts['sel_hint'] = $by_id || $search_box==false ?
90                         '' : _('Press Space tab for search pattern entry');
91
92         if ($opts['box_hint'] === null)  // dodaƦ hint dla pustego ****
93                 $opts['box_hint'] = $search_box && $search_submit != false ?
94                         ($by_id ? _('Enter code fragment to search or * for all')
95                         : _('Enter description fragment to search or * for all')) :'';
96
97         if ($selected_id == null) {
98                 $selected_id = get_post($name, $opts['default']);
99         }
100         if(!is_array($selected_id))
101                 $selected_id = array($selected_id); // code is generalized for multiple selection support
102
103         $txt = get_post($search_box);
104         $rel = '';
105         $limit = '';
106
107         if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
108                 if ($by_id) $txt = $_POST[$name];
109
110                 if (!$opts['async'])
111                         $Ajax->activate('_page_body');
112                 else
113                         $Ajax->activate($name);
114         }
115         if (isset($_POST[$search_button])) {
116                 if (!$opts['async'])
117                         $Ajax->activate('_page_body');
118                 else
119                         $Ajax->activate($name);
120         }
121         if ($search_box) {
122                 // search related sql modifications
123
124                 $rel = "rel='$search_box'"; // set relation to list
125                 if ($opts['search_submit']) {
126                         if (isset($_POST[$search_button])) {
127                                 $selected_id = array(); // ignore selected_id while search
128                                 if (!$opts['async'])
129                                         $Ajax->activate('_page_body');
130                                 else
131                                         $Ajax->activate($name);
132                         }
133                         if ($txt == '') {
134                                 if ($spec_option === false && $selected_id == array())
135                                         $limit = ' LIMIT 1';
136                                 else
137                                         $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
138                         }
139                         else
140                                 if ($txt != '*') {
141
142                                         foreach($opts['search'] as $i=> $s)
143                                                 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
144                                         $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
145                                 }
146                 }
147         }
148         // sql completion
149         if (count($opts['where'])) {
150                 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
151                 $where .= '('. implode($opts['where'], ' AND ') . ')';
152                 $group_pos = strpos($sql, 'GROUP BY');
153                 if ($group_pos) {
154                         $group = substr($sql, $group_pos);
155                         $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
156                 } else {
157                         $sql .= $where;
158                 }
159         }
160         if ($opts['order'] != false) {
161                 if (!is_array($opts['order']))
162                         $opts['order'] = array($opts['order']);
163                 $sql .= ' ORDER BY '.implode(',',$opts['order']);
164         }
165
166         $sql .= $limit;
167         // ------ make selector ----------
168         $selector = $first_opt = '';
169         $first_id = false;
170         $found = false;
171         $lastcat = null;
172         $edit = false;
173 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
174 //if($name=='curr_default') display_notification($opts['search_submit']);
175         if($result = db_query($sql)) {
176                 while ($contact_row = db_fetch($result)) {
177                         $value = $contact_row[0];
178                         $descr = $opts['format']==null ?  $contact_row[1] :
179                                 call_user_func($opts['format'], $contact_row);
180                         $sel = '';
181                         if (get_post($search_button) && ($txt == $value)) {
182                                 $selected_id[] = $value;
183                         }
184                         if (in_array($value, $selected_id)) {
185                                 $sel = 'selected';
186                                 $found = $value;
187                                 $edit = $opts['editable'] && $contact_row['editable'] 
188                                         && (@$_POST[$search_box] == $value)
189                                         ? $contact_row[1] : false; // get non-formatted description
190                                 if ($edit)
191                                         break;  // selected field is editable - abandon list construction
192                         }
193                         // show selected option even if inactive 
194                         if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
195                                 continue;
196                         } else 
197                                 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
198
199                         if ($first_id === false) {
200                                 $first_id = $value;
201                                 $first_opt = $descr;
202                         }
203                         $cat = $contact_row[$opts['category']];
204                         if ($opts['category'] !== false && $cat != $lastcat){
205                                 $selector .= "<optgroup label='".$cat."'>\n";
206                                 $lastcat = $cat;
207                         }
208                         $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
209                 }
210                 db_free_result($result);
211         }
212
213         // Prepend special option.
214         if ($spec_option !== false) { // if special option used - add it
215                 $first_id = $spec_id;
216                 $first_opt = $spec_option;
217 //      }
218 //      if($first_id !== false) {
219                 $sel = $found===false ? 'selected' : '';
220                 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
221                 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
222                         . $selector;
223         }
224
225         if ($found===false) {
226                 $selected_id = array($first_id);
227         }
228         
229         $_POST[$name] = $multi ? $selected_id : $selected_id[0];
230
231         $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
232                 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
233                 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
234                 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
235
236         if ($by_id && ($search_box != false || $opts['editable']) ) {
237                 // on first display show selector list
238                 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
239                         $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
240                         ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
241                                 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
242                                 set_focus($name.'_text'); // prevent lost focus
243                 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
244                         set_focus($name); // prevent lost focus
245                 if (!$opts['editable'])
246                         $txt = $found;
247                 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
248         }
249
250         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
251
252         // span for select list/input field update
253         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
254
255          // if selectable or editable list is used - add select button
256         if ($select_submit != false || $search_button) {
257                 global $_select_button;
258         // button class selects form reload/ajax selector update
259                 $selector .= sprintf($_select_button, $disabled, user_theme(),
260                         (fallback_mode() ? '' : 'display:none;'),
261                          '_'.$name.'_update')."\n";
262         }
263 // ------ make combo ----------
264         $edit_entry = '';
265         if ($search_box != false) {
266                 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
267                         $opts['size']."' maxlength='".$opts['max'].
268                         "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
269                         .$opts['box_hint']."'"
270                         .(!fallback_mode() && !$by_id ? " style=display:none;":'')
271                         .">\n";
272                 if ($search_submit != false || $opts['editable']) {
273                         global $_search_button;
274                         $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
275                                 (fallback_mode() ? '' : 'display:none;'),
276                                 $search_submit ? $search_submit : "_{$name}_button")."\n";
277                 }
278         }
279         default_focus(($search_box && $by_id) ? $search_box : $name);
280
281         if ($search_box && $opts['cells'])
282                 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
283         else
284                 $str = $edit_entry.$selector;
285         return $str;
286 }
287
288 /*
289         Helper function.
290         Returns true if selector $name is subject to update.
291 */
292 function list_updated($name)
293 {
294         return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
295 }
296 //----------------------------------------------------------------------------------------------
297 //      Universal array combo generator
298 //      $items is array of options 'value' => 'description'
299 //      Options is reduced set of combo_selector options and is merged with defaults.
300
301 function array_selector($name, $selected_id, $items, $options=null)
302 {
303         global $Ajax;
304
305 $opts = array(          // default options
306         'spec_option'=>false,   // option text or false
307         'spec_id' => 0,         // option id
308         'select_submit' => false, //submit on select: true/false
309         'async' => true,        // select update via ajax (true) vs _page_body reload
310         'default' => '', // default value when $_POST is not set
311         'multi'=>false, // multiple select
312                 // search box parameters
313         'height' => false,      // number of lines in select box
314         'sel_hint' => null,
315         'disabled' => false
316 );
317 // ------ merge options with defaults ----------
318         if($options != null)
319                 $opts = array_merge($opts, $options);
320         $select_submit =  $opts['select_submit'];
321         $spec_id = $opts['spec_id'];
322         $spec_option = $opts['spec_option'];
323         $disabled = $opts['disabled'] ? "disabled" : '';
324         $multi = $opts['multi'];
325
326         if ($selected_id == null) {
327                 $selected_id = get_post($name, $opts['default']);
328         }
329         if(!is_array($selected_id))
330                 $selected_id = array($selected_id); // code is generalized for multiple selection support
331
332         if (isset($_POST[ '_'.$name.'_update'])) {
333                 if (!$opts['async'])
334                         $Ajax->activate('_page_body');
335                 else
336                         $Ajax->activate($name);
337         }
338
339         // ------ make selector ----------
340         $selector = $first_opt = '';
341         $first_id = false;
342         $found = false;
343 //if($name=='SelectStockFromList') display_error($sql);
344                 foreach($items as $value=>$descr) {
345                         $sel = '';
346                         if (in_array((string)$value, $selected_id)) {
347                                 $sel = "selected='selected'";
348                                 $found = $value;
349                         }
350                         if ($first_id === false) {
351                                 $first_id = $value;
352                                 $first_opt = "<option %s value='$value'>$descr</option>\n";
353                         } 
354                         else {
355                                 $selector .= "<option $sel value='$value'>$descr</option>\n";
356                         }
357                 }
358
359         if ($first_id!==false) {
360                 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
361                 $selector = sprintf($first_opt, $sel).$selector;
362         }
363         // Prepend special option.
364         if ($spec_option !== false) { // if special option used - add it
365                 $first_id = $spec_id;
366                 $first_opt = $spec_option;
367                 $sel = $found===false ? "selected='selected'" : '';
368                 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
369                         . $selector;
370         }
371
372         if ($found===false) {
373                 $selected_id = array($first_id);
374         }
375         $_POST[$name] = $multi ? $selected_id : $selected_id[0];
376         $selector = "<select autocomplete='off' ".($multi  ? "multiple" : '')
377                 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
378                 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
379                 . $opts['sel_hint']."'>".$selector."</select>\n";
380
381         $Ajax->addUpdate($name, "_{$name}_sel", $selector);
382
383         $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
384
385         if ($select_submit != false) { // if submit on change is used - add select button
386                 global $_select_button;
387                 $selector .= sprintf($_select_button, $disabled, user_theme(),
388                         (fallback_mode() ? '' : 'display:none;'),
389                          '_'.$name.'_update')."\n";
390         }
391         default_focus($name);
392
393         return $selector;
394 }
395 //----------------------------------------------------------------------------------------------
396
397 function _format_add_curr($row)
398 {
399         static $company_currency;
400
401         if ($company_currency == null)
402         {
403                 $company_currency = get_company_currency();
404         }
405         return $row[1] . ($row[2] == $company_currency ?
406                 '' : ("&nbsp;-&nbsp;" . $row[2]));
407 }
408
409 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
410         $all=false, $editkey = false)
411 {
412         global $all_items;
413
414         $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
415
416         $mode = get_company_pref('no_supplier_list');
417
418         if ($editkey)
419                 set_editor('supplier', $name, $editkey);
420                 
421         return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
422         array(
423                 'format' => '_format_add_curr',
424             'order' => array('supp_ref'),
425                 'search_box' => $mode!=0,
426                 'type' => 1,
427                 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
428                 'spec_id' => $all_items,
429                 'select_submit'=> $submit_on_change,
430                 'async' => false,
431                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
432                 _('Select supplier'),
433                 'show_inactive'=>$all
434                 ));
435 }
436
437 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, 
438         $submit_on_change=false, $all=false, $editkey = false)
439 {
440         if ($label != null)
441                 echo "<td>$label</td><td>\n";
442                 echo supplier_list($name, $selected_id, $all_option, $submit_on_change, 
443                 $all, $editkey);
444                 echo "</td>\n";
445 }
446
447 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, 
448         $submit_on_change=false, $all=false, $editkey = false)
449 {
450         echo "<tr><td class='label'>$label</td><td>";
451         echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
452                 $all, $editkey);
453         echo "</td></tr>\n";
454 }
455 //----------------------------------------------------------------------------------------------
456
457 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, 
458         $show_inactive=false, $editkey = false)
459 {
460         global $all_items;
461
462         $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
463
464         $mode = get_company_pref('no_customer_list');
465
466         if ($editkey)
467                 set_editor('customer', $name, $editkey);
468
469         return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
470         array(
471             'format' => '_format_add_curr',
472             'order' => array('debtor_ref'),
473                 'search_box' => $mode!=0,
474                 'type' => 1,
475                 'size' => 20,
476                 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
477                 'spec_id' => $all_items,
478                 'select_submit'=> $submit_on_change,
479                 'async' => false,
480                 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
481                 _('Select customer'),
482                 'show_inactive' => $show_inactive
483         ) );
484 }
485
486 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, 
487         $submit_on_change=false, $show_inactive=false, $editkey = false)
488 {
489         if ($label != null)
490                 echo "<td>$label</td>\n";
491         echo "<td nowrap>";
492         echo customer_list($name, $selected_id, $all_option, $submit_on_change,
493                 $show_inactive, $editkey);
494         echo "</td>\n";
495 }
496
497 function customer_list_row($label, $name, $selected_id=null, $all_option = false, 
498         $submit_on_change=false, $show_inactive=false, $editkey = false)
499 {
500         echo "<tr><td class='label'>$label</td><td nowrap>";
501         echo customer_list($name, $selected_id, $all_option, $submit_on_change,
502                 $show_inactive, $editkey);
503         echo "</td>\n</tr>\n";
504 }
505
506 //------------------------------------------------------------------------------------------------
507
508 function customer_branches_list($customer_id, $name, $selected_id=null,
509         $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
510 {
511         global $all_items;
512
513         $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
514                 WHERE debtor_no='" . $customer_id . "' ";
515
516         if ($editkey)
517                 set_editor('branch', $name, $editkey);
518
519         $where = $enabled ? array("disable_trans = 0") : array();
520         return  combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
521         array(
522                 'where' => $where,
523                 'order' => array('branch_ref'),
524                 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
525                 'spec_id' => $all_items,
526                 'select_submit'=> $submit_on_change,
527                 'sel_hint' => _('Select customer branch')
528         ) );
529 }
530 //------------------------------------------------------------------------------------------------
531
532 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, 
533         $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
534 {
535         if ($label != null)
536                 echo "<td>$label</td>\n";
537         echo "<td>";
538         echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, 
539                 $submit_on_change, $editkey);
540         echo "</td>\n";
541 }
542
543 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null, 
544         $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
545 {
546         echo "<tr><td class='label'>$label</td>";
547         customer_branches_list_cells(null, $customer_id, $name, $selected_id, 
548                 $all_option, $enabled, $submit_on_change, $editkey);
549         echo "</tr>";
550 }
551
552 //------------------------------------------------------------------------------------------------
553
554 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
555 {
556         global $all_items;
557
558         $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
559
560 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
561         array(
562                 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
563                 'spec_id' => $all_items,
564                 'select_submit'=> $submit_on_change
565         ) );
566 }
567
568 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
569 {
570         if ($label != null)
571                 echo "<td>$label</td>\n";
572         echo "<td>";
573         echo locations_list($name, $selected_id, $all_option, $submit_on_change);
574         echo "</td>\n";
575 }
576
577 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
578 {
579         echo "<tr><td class='label'>$label</td>";
580         locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
581         echo "</tr>\n";
582 }
583
584 //-----------------------------------------------------------------------------------------------
585
586 function currencies_list($name, $selected_id=null, $submit_on_change=false)
587 {
588         $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
589
590 // default to the company currency
591 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
592         array(
593                 'select_submit'=> $submit_on_change,
594                 'default' => get_company_currency(),
595                 'async' => false                
596         ) );
597 }
598
599 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
600 {
601         if ($label != null)
602                 echo "<td>$label</td>\n";
603         echo "<td>";
604         echo currencies_list($name, $selected_id, $submit_on_change);
605         echo "</td>\n";
606 }
607
608 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
609 {
610         echo "<tr><td class='label'>$label</td>";
611         currencies_list_cells(null, $name, $selected_id, $submit_on_change);
612         echo "</tr>\n";
613 }
614
615 //---------------------------------------------------------------------------------------------------
616
617 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
618 {
619
620         $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
621
622 // default to the company current fiscal year
623
624 return combo_input($name, $selected_id, $sql, 'id', '',
625         array(
626                 'order' => 'begin',
627                 'default' => get_company_pref('f_year'),
628                 'format' => '_format_fiscalyears',
629                 'select_submit'=> $submit_on_change,
630                 'async' => false
631         ) );
632 }
633
634 function _format_fiscalyears($row)
635 {
636         return sql2date($row[1]) . "&nbsp;-&nbsp;" . sql2date($row[2])
637         . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
638 }
639
640 function fiscalyears_list_cells($label, $name, $selected_id=null)
641 {
642         if ($label != null)
643                 echo "<td>$label</td>\n";
644         echo "<td>";
645         echo fiscalyears_list($name, $selected_id);
646         echo "</td>\n";
647 }
648
649 function fiscalyears_list_row($label, $name, $selected_id=null)
650 {
651         echo "<tr><td class='label'>$label</td>";
652         fiscalyears_list_cells(null, $name, $selected_id);
653         echo "</tr>\n";
654 }
655 //------------------------------------------------------------------------------------
656
657 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
658         $submit_on_change=false, $showclosed=false, $showtype=1)
659 {
660 $sql = "SELECT id, CONCAT(reference,'  ',name) as ref FROM ".TB_PREF."dimensions";
661
662 $options = array(
663         'order' => 'reference',
664         'spec_option'=>$no_option ? $showname : false,
665         'spec_id' => 0,
666         'select_submit'=> $submit_on_change,
667         'async' => false,
668         );
669
670         if (!$showclosed)
671                 $options['where'][] = "closed=0";
672         if($showtype)
673                 $options['where'][] = "type_=$showtype";
674
675         return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
676 }
677
678 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
679         $showclosed=false, $showtype=0, $submit_on_change=false)
680 {
681         if ($label != null)
682                 echo "<td>$label</td>\n";
683         echo "<td>";
684         echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
685         echo "</td>\n";
686 }
687
688 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
689         $showclosed=false, $showtype=0, $submit_on_change=false)
690 {
691         echo "<tr><td class='label'>$label</td>";
692         dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
693                 $showclosed, $showtype, $submit_on_change);
694         echo "</tr>\n";
695 }
696
697 //---------------------------------------------------------------------------------------------------
698
699 function stock_items_list($name, $selected_id=null, $all_option=false, 
700         $submit_on_change=false, $opts=array(), $editkey = false)
701 {
702         global $all_items;
703
704         $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
705                         FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
706
707         if ($editkey)
708                 set_editor('item', $name, $editkey);
709
710         return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
711         array_merge(
712           array(
713                 'format' => '_format_stock_items',
714                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
715                 'spec_id' => $all_items,
716                 'search_box' => true,
717                 'search' => array("stock_id", "c.description","s.description"),
718                 'search_submit' => get_company_pref('no_item_list')!=0,
719                 'size'=>10,
720                 'select_submit'=> $submit_on_change,
721                 'category' => 2,
722                 'order' => array('c.description','stock_id')
723           ), $opts) );
724 }
725
726 function _format_stock_items($row)
727 {
728         return (user_show_codes() ?  ($row[0] . "&nbsp;-&nbsp;") : "") . $row[1];
729 }
730
731 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, 
732         $submit_on_change=false, $all=false, $editkey = false)
733 {
734         if ($label != null)
735                 echo "<td>$label</td>\n";
736         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
737                 array('cells'=>true, 'show_inactive'=>$all), $editkey);
738 }
739 /*
740 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
741 {
742         echo "<tr>\n";
743         stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
744         echo "</tr>\n";
745 }
746 */
747 //---------------------------------------------------------------------------------------------------
748 //
749 // Select item via foreign code.
750 //
751 function sales_items_list($name, $selected_id=null, $all_option=false, 
752         $submit_on_change=false, $type='', $opts=array())
753 {
754         global $all_items;
755         // all sales codes
756         $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
757                          i.inactive, if(count(*)>1, '0', s.editable) as editable
758                         FROM
759                         ".TB_PREF."stock_master s,
760                         ".TB_PREF."item_codes i
761                         LEFT JOIN
762                         ".TB_PREF."stock_category c
763                         ON i.category_id=c.category_id
764                         WHERE i.stock_id=s.stock_id";
765
766         
767         if ($type == 'local')   { // exclude foreign codes
768                 $sql .= " AND !i.is_foreign"; 
769         } elseif ($type == 'kits') { // sales kits
770                 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
771         }
772         $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
773         $sql .= " GROUP BY i.item_code";
774
775         return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
776         array_merge(
777           array(
778                 'format' => '_format_stock_items',
779                 'spec_option' => $all_option===true ?  _("All Items") : $all_option,
780                 'spec_id' => $all_items,
781                 'search_box' => true,
782                 'search' => array("i.item_code", "c.description", "i.description"),
783                 'search_submit' => get_company_pref('no_item_list')!=0,
784                 'size'=>15,
785                 'select_submit'=> $submit_on_change,
786                 'category' => 2,
787                 'order' => array('c.description','i.item_code'),
788                 'editable' => 30,
789                 'max' => 255
790           ), $opts) );
791 }
792
793 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
794 {
795         if ($label != null)
796                 echo "<td>$label</td>\n";
797         echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
798                 '', array('cells'=>true));
799 }
800
801 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
802 {
803         return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
804                 'kits', array('cells'=>false, 'editable' => false));
805 }
806
807 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
808 {
809         echo "<tr>";
810         if ($label != null)
811                 echo "<td class='label'>$label</td>\n";
812         echo "<td>";
813         echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
814                 'local', array('cells'=>false, 'editable' => false));
815         echo "</td></tr>";
816 }
817 //------------------------------------------------------------------------------------
818
819 function stock_manufactured_items_list($name, $selected_id=null,
820         $all_option=false, $submit_on_change=false)
821 {
822         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
823                 array('where'=>array("mb_flag= 'M'")));
824 }
825
826 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
827                                 $all_option=false, $submit_on_change=false)
828 {
829         if ($label != null)
830                 echo "<td>$label</td>\n";
831         echo "<td>";
832         echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
833         echo "</td>\n";
834 }
835
836 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
837                 $all_option=false, $submit_on_change=false)
838 {
839         echo "<tr><td class='label'>$label</td>";
840         stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
841         echo "</tr>\n";
842 }
843 //------------------------------------------------------------------------------------
844
845 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
846         $all_option=false, $submit_on_change=false, $editkey = false)
847 {
848         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
849                 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
850 }
851
852 function stock_component_items_list_cells($label, $name, $parent_stock_id, 
853         $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
854 {
855         if ($label != null)
856                 echo "<td>$label</td>\n";
857         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
858                 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
859                 $editkey);
860 }
861 //------------------------------------------------------------------------------------
862
863 function stock_costable_items_list($name, $selected_id=null,
864         $all_option=false, $submit_on_change=false)
865 {
866         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
867                 array('where'=>array("mb_flag!='D'")));
868 }
869
870 function stock_costable_items_list_cells($label, $name, $selected_id=null, 
871         $all_option=false, $submit_on_change=false)
872 {
873         if ($label != null)
874                 echo "<td>$label</td>\n";
875         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
876                 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
877 }
878
879 //------------------------------------------------------------------------------------
880 function stock_purchasable_items_list($name, $selected_id=null, 
881         $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
882 {
883         return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
884                 array('where'=>array("mb_flag!= 'M'"), 
885                         'show_inactive'=>$all), $editkey);
886 }
887 //
888 //      This helper is used in PO/GRN/PI entry and supports editable descriptions.
889 //
890 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
891                         $all_option=false, $submit_on_change=false, $editkey=false)
892 {
893         if ($label != null)
894                 echo "<td>$label</td>\n";
895         echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
896                 array('where'=>array("mb_flag!= 'M'"), 
897                          'editable' => 30,
898                          'cells'=>true), $editkey);
899 }
900 /*
901 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
902                         $all_option=false, $submit_on_change=false, $editkey=false)
903 {
904         echo "<tr><td class='label'>$label</td>";
905         stock_purchasable_items_list_cells(null, $name, $selected_id=null,
906                 $all_option, $submit_on_change, $editkey);
907         echo "</tr>\n";
908 }
909 */
910 //------------------------------------------------------------------------------------
911
912 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
913 {
914         global $stock_types;
915
916         echo "<tr>";
917         if ($label != null)
918                 echo "<td class='label'>$label</td>\n";
919         echo "<td>";
920
921         echo array_selector($name, $selected_id, $stock_types, 
922                 array( 
923                         'select_submit'=> true, 
924                         'disabled' => !$enabled) );
925         echo "</td></tr>\n";
926 }
927
928 function stock_units_list_row($label, $name, $value=null, $enabled=true)
929 {
930         $result = get_all_item_units();
931         echo "<tr>";
932         if ($label != null)
933                 echo "<td class='label'>$label</td>\n";
934         echo "<td>";
935
936         while($unit = db_fetch($result))
937                 $units[$unit['abbr']] = $unit['name'];
938
939         echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
940
941         echo "</td></tr>\n";
942 }
943
944 //------------------------------------------------------------------------------------
945
946 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
947 {
948         $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
949
950         return combo_input($name, $selected_id, $sql, 'id', 'name',
951         array(
952                 'spec_option' => $none_option,
953                 'spec_id' => ALL_NUMERIC,
954                 'select_submit'=> $submit_on_change,
955                 'async' => false,
956         ) );
957 }
958
959 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
960         $submit_on_change=false)
961 {
962         if ($label != null)
963                 echo "<td>$label</td>\n";
964         echo "<td>";
965         echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
966         echo "</td>\n";
967 }
968
969 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
970         $submit_on_change=false)
971 {
972         echo "<tr><td class='label'>$label</td>";
973         tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
974         echo "</tr>\n";
975 }
976
977 //------------------------------------------------------------------------------------
978
979 function tax_groups_list($name, $selected_id=null,
980         $none_option=false, $submit_on_change=false)
981 {
982         $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
983
984         return combo_input($name, $selected_id, $sql, 'id', 'name',
985         array(
986                 'order' => 'id',
987                 'spec_option' => $none_option,
988                 'spec_id' => ALL_NUMERIC,
989                 'select_submit'=> $submit_on_change,
990                 'async' => false,
991         ) );
992 }
993
994 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
995 {
996         if ($label != null)
997                 echo "<td>$label</td>\n";
998         echo "<td>";
999         echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1000         echo "</td>\n";
1001 }
1002
1003 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1004 {
1005         echo "<tr><td class='label'>$label</td>";
1006         tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1007         echo "</tr>\n";
1008 }
1009
1010 //------------------------------------------------------------------------------------
1011
1012 function item_tax_types_list($name, $selected_id=null)
1013 {
1014         $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1015         return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1016 }
1017
1018 function item_tax_types_list_cells($label, $name, $selected_id=null)
1019 {
1020         if ($label != null)
1021                 echo "<td>$label</td>\n";
1022         echo "<td>";
1023         echo item_tax_types_list($name, $selected_id);
1024         echo "</td>\n";
1025 }
1026
1027 function item_tax_types_list_row($label, $name, $selected_id=null)
1028 {
1029         echo "<tr><td class='label'>$label</td>";
1030         item_tax_types_list_cells(null, $name, $selected_id);
1031         echo "</tr>\n";
1032 }
1033
1034 //------------------------------------------------------------------------------------
1035
1036 function shippers_list($name, $selected_id=null)
1037 {
1038         $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1039         return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', 
1040                 array('order'=>array('shipper_name')));
1041 }
1042
1043 function shippers_list_cells($label, $name, $selected_id=null)
1044 {
1045         if ($label != null)
1046                 echo "<td>$label</td>\n";
1047         echo "<td>";
1048         echo shippers_list($name, $selected_id);
1049         echo "</td>\n";
1050 }
1051
1052 function shippers_list_row($label, $name, $selected_id=null)
1053 {
1054         echo "<tr><td class='label'>$label</td>";
1055         shippers_list_cells(null, $name, $selected_id);
1056         echo "</tr>\n";
1057 }
1058
1059 //-------------------------------------------------------------------------------------
1060
1061 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1062 {
1063         $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1064         return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', 
1065                 array('order'=>array('salesman_name'),
1066                         'spec_option' => $spec_opt,
1067                         'spec_id' => ALL_NUMERIC));
1068 }
1069
1070 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1071 {
1072         if ($label != null)
1073                 echo "<td>$label</td>\n";
1074         echo "<td>\n";
1075         echo sales_persons_list($name, $selected_id, $spec_opt);
1076         echo "</td>\n";
1077 }
1078
1079 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1080 {
1081         echo "<tr><td class='label'>$label</td>";
1082         sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1083         echo "</tr>\n";
1084 }
1085
1086 //------------------------------------------------------------------------------------
1087
1088 function sales_areas_list($name, $selected_id=null)
1089 {
1090         $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1091         return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1092 }
1093
1094 function sales_areas_list_cells($label, $name, $selected_id=null)
1095 {
1096         if ($label != null)
1097                 echo "<td>$label</td>\n";
1098         echo "<td>";
1099         echo sales_areas_list($name, $selected_id);
1100         echo "</td>\n";
1101 }
1102
1103 function sales_areas_list_row($label, $name, $selected_id=null)
1104 {
1105         echo "<tr><td class='label'>$label</td>";
1106         sales_areas_list_cells(null, $name, $selected_id);
1107         echo "</tr>\n";
1108 }
1109
1110 //------------------------------------------------------------------------------------
1111
1112 function sales_groups_list($name, $selected_id=null, $special_option=false)
1113 {
1114         $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1115         return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1116                 'spec_option' => $special_option===true ? ' ' : $special_option,
1117                 'order' => 'description', 'spec_id' => 0,
1118         ));
1119 }
1120
1121 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1122 {
1123         if ($label != null)
1124                 echo "<td>$label</td>\n";
1125         echo "<td>";
1126         echo sales_groups_list($name, $selected_id, $special_option);
1127         echo "</td>\n";
1128 }
1129
1130 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1131 {
1132         echo "<tr><td class='label'>$label</td>";
1133         sales_groups_list_cells(null, $name, $selected_id, $special_option);
1134         echo "</tr>\n";
1135 }
1136
1137 //------------------------------------------------------------------------------------
1138
1139 function _format_template_items($row)
1140 {
1141         return ($row[0] . "&nbsp;- &nbsp;" . _("Amount") . "&nbsp;".$row[1]);
1142 }
1143
1144 function templates_list($name, $selected_id=null, $special_option=false)
1145 {
1146         $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1147                 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1148                 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1149         return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1150                 'format' => '_format_template_items',
1151                 'spec_option' => $special_option===true ? ' ' : $special_option,
1152                 'order' => 'order_no', 'spec_id' => 0,
1153         ));
1154 }
1155
1156 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1157 {
1158         if ($label != null)
1159                 echo "<td>$label</td>\n";
1160         echo "<td>";
1161         echo templates_list($name, $selected_id, $special_option);
1162         echo "</td>\n";
1163 }
1164
1165 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1166 {
1167         echo "<tr><td class='label'>$label</td>";
1168         templates_list_cells(null, $name, $selected_id, $special_option);
1169         echo "</tr>\n";
1170 }
1171
1172 //------------------------------------------------------------------------------------
1173
1174 function workorders_list($name, $selected_id=null)
1175 {
1176         $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1177         return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1178 }
1179
1180 function workorders_list_cells($label, $name, $selected_id=null)
1181 {
1182         if ($label != null)
1183                 echo "<td>$label</td>\n";
1184         echo "<td>";
1185         echo workorders_list($name, $selected_id);
1186         echo "</td>\n";
1187 }
1188
1189 function workorders_list_row($label, $name, $selected_id=null)
1190 {
1191         echo "<tr><td class='label'>$label</td>";
1192         workorders_list_cells(null, $name, $selected_id);
1193         echo "</tr>\n";
1194 }
1195
1196 //------------------------------------------------------------------------------------
1197
1198 function payment_terms_list($name, $selected_id=null)
1199 {
1200         $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1201         return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1202 }
1203
1204 function payment_terms_list_cells($label, $name, $selected_id=null)
1205 {
1206         if ($label != null)
1207                 echo "<td>$label</td>\n";
1208         echo "<td>";
1209         echo payment_terms_list($name, $selected_id);
1210         echo "</td>\n";
1211 }
1212
1213 function payment_terms_list_row($label, $name, $selected_id=null)
1214 {
1215         echo "<tr><td class='label'>$label</td>";
1216         payment_terms_list_cells(null, $name, $selected_id);
1217         echo "</tr>\n";
1218 }
1219
1220 //------------------------------------------------------------------------------------
1221
1222 function credit_status_list($name, $selected_id=null)
1223 {
1224         $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1225         return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1226 }
1227
1228 function credit_status_list_cells($label, $name, $selected_id=null)
1229 {
1230         if ($label != null)
1231                 echo "<td>$label</td>\n";
1232         echo "<td>";
1233         echo credit_status_list($name, $selected_id);
1234         echo "</td>\n";
1235 }
1236
1237 function credit_status_list_row($label, $name, $selected_id=null)
1238 {
1239         echo "<tr><td class='label'>$label</td>";
1240         credit_status_list_cells(null, $name, $selected_id);
1241         echo "</tr>\n";
1242 }
1243
1244 //-----------------------------------------------------------------------------------------------
1245
1246 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1247 {
1248         $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1249
1250         return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1251         array(
1252                 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1253                 'spec_id' => 0,
1254                 'select_submit'=> $submit_on_change,
1255         //        'async' => false,
1256         ) );
1257 }
1258
1259 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1260 {
1261         if ($label != null)
1262                 echo "<td>$label</td>\n";
1263         echo "<td>";
1264         echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1265         echo "</td>\n";
1266 }
1267
1268 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1269 {
1270         echo "<tr><td class='label'>$label</td>";
1271         sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1272         echo "</tr>\n";
1273 }
1274
1275 //-----------------------------------------------------------------------------------------------
1276
1277 function movement_types_list($name, $selected_id=null)
1278 {
1279         $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1280         return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1281 }
1282
1283 function movement_types_list_cells($label, $name, $selected_id=null)
1284 {
1285         if ($label != null)
1286                 echo "<td>$label</td>\n";
1287         echo "<td>";
1288         echo movement_types_list($name, $selected_id);
1289         echo "</td>\n";
1290 }
1291
1292 function movement_types_list_row($label, $name, $selected_id=null)
1293 {
1294         echo "<tr><td class='label'>$label</td>";
1295         movement_types_list_cells(null, $name, $selected_id);
1296         echo "</tr>\n";
1297 }
1298
1299 //-----------------------------------------------------------------------------------------------
1300 function _format_date($row)
1301 {
1302         return sql2date($row['reconciled']);
1303 }
1304
1305 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1306 {
1307         $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1308                 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1309                 GROUP BY reconciled";
1310         return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1311         array(
1312                 'spec_option' => $special_option,
1313                 'format' => '_format_date',
1314                 'spec_id' => '',
1315                 'select_submit'=> $submit_on_change
1316         ) );
1317 }
1318
1319 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1320 {
1321         if ($label != null)
1322                 echo "<td>$label</td>\n";
1323         echo "<td>";
1324         echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1325         echo "</td>\n";
1326 }
1327 /*
1328 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1329 {
1330         echo "<tr>\n";
1331         bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1332         echo "</tr>\n";
1333 }
1334 */
1335 //-----------------------------------------------------------------------------------------------
1336
1337 function workcenter_list($name, $selected_id=null, $all_option=false)
1338 {
1339         global $all_items;
1340
1341         $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1342
1343         return combo_input($name, $selected_id, $sql, 'id', 'name',
1344         array(
1345                 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1346                 'spec_id' => $all_items,
1347         ) );
1348 }
1349
1350 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1351 {
1352         default_focus($name);
1353         if ($label != null)
1354                 echo "<td>$label</td>\n";
1355         echo "<td>";
1356         echo workcenter_list($name, $selected_id, $all_option);
1357         echo "</td>\n";
1358 }
1359
1360 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1361 {
1362         echo "<tr><td class='label'>$label</td>";
1363         workcenter_list_cells(null, $name, $selected_id, $all_option);
1364         echo "</tr>\n";
1365 }
1366
1367 //-----------------------------------------------------------------------------------------------
1368
1369 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1370 {
1371         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1372                 FROM ".TB_PREF."bank_accounts";
1373
1374         return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1375         array(
1376                 'format' => '_format_add_curr',
1377                 'select_submit'=> $submit_on_change,
1378                 'async' => false
1379         ) );
1380 }
1381
1382 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1383 {
1384         if ($label != null)
1385                 echo "<td>$label</td>\n";
1386         echo "<td>";
1387         echo bank_accounts_list($name, $selected_id, $submit_on_change);
1388         echo "</td>\n";
1389 }
1390
1391 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1392 {
1393         echo "<tr><td class='label'>$label</td>";
1394         bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1395         echo "</tr>\n";
1396 }
1397 //-----------------------------------------------------------------------------------------------
1398
1399 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1400 {
1401         $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1402                 FROM ".TB_PREF."bank_accounts
1403                 WHERE ".TB_PREF."bank_accounts.account_type=3";
1404
1405         if ($label != null)
1406                 echo "<tr><td class='label'>$label</td>\n";
1407         echo "<td>";
1408         echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1409         array(
1410                 'format' => '_format_add_curr',
1411                 'select_submit'=> $submit_on_change,
1412                 'async' => true
1413         ) );
1414         echo "</td></tr>\n";
1415 }
1416 //-----------------------------------------------------------------------------------------------
1417
1418 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1419 {
1420         $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1421
1422         default_focus($name);
1423         echo '<tr>';
1424         if ($label != null)
1425                 echo "<td class='label'>$label</td>\n";
1426         echo "<td>";
1427
1428         echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1429         array(
1430                 'select_submit'=> $submit_on_change,
1431                 'async' => true,
1432                 'spec_option' =>$spec_option,
1433                 'spec_id' => -1,
1434                 'order'=> array('pos_name')
1435         ) );
1436         echo "</td></tr>\n";
1437
1438 }
1439 //-----------------------------------------------------------------------------------------------
1440 // Payment type selector for current user.
1441 //
1442 function sale_payment_list($name, $selected_id=null, $submit_on_change=true)
1443 {
1444         $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1445         $paym = get_sales_point(user_pos());
1446
1447         if (!$paym['cash_sale'] || !$paym['credit_sale']) {
1448                 if ($paym['cash_sale']) // only cash
1449                         $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1450                 else
1451                         $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
1452         }
1453
1454         return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1455         array(
1456                 'select_submit'=> $submit_on_change,
1457                 'async' => true
1458         ) );
1459
1460 }
1461
1462 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=true)
1463 {
1464         if ($label != null)
1465                 echo "<td class='label'>$label</td>\n";
1466         echo "<td>";
1467
1468         echo sale_payment_list($name, $selected_id, $submit_on_change);
1469
1470         echo "</td>\n";
1471 }
1472 //-----------------------------------------------------------------------------------------------
1473
1474 function class_list($name, $selected_id=null, $submit_on_change=false)
1475 {
1476         $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1477
1478         return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1479         array(
1480                 'select_submit'=> $submit_on_change,
1481                 'async' => false
1482         ) );
1483
1484 }
1485
1486 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1487 {
1488         if ($label != null)
1489                 echo "<td>$label</td>\n";
1490         echo "<td>";
1491         echo class_list($name, $selected_id, $submit_on_change);
1492         echo "</td>\n";
1493 }
1494
1495 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1496 {
1497         echo "<tr><td class='label'>$label</td>";
1498         class_list_cells(null, $name, $selected_id, $submit_on_change);
1499         echo "</tr>\n";
1500 }
1501
1502 //-----------------------------------------------------------------------------------------------
1503 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1504 {
1505         $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1506         return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1507         array('order'=>'category_id',
1508                 'spec_option' => $spec_opt,
1509                 'spec_id' => -1,
1510                 'select_submit'=> $submit_on_change,
1511                 'async' => true
1512         ));
1513 }
1514
1515 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1516 {
1517         if ($label != null)
1518                 echo "<td>$label</td>\n";
1519         echo "<td>";
1520         echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1521         echo "</td>\n";
1522 }
1523
1524 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1525 {
1526         echo "<tr><td class='label'>$label</td>";
1527         stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1528         echo "</tr>\n";
1529 }
1530
1531 //-----------------------------------------------------------------------------------------------
1532
1533 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1534 {
1535         global $all_items;
1536
1537         $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1538
1539         return combo_input($name, $selected_id, $sql, 'id', 'name',
1540         array(
1541                 'order' => 'class_id', 'id',
1542                 'spec_option' =>$all_option,
1543                 'spec_id' => $all_items
1544         ) );
1545 }
1546
1547 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1548 {
1549         if ($label != null)
1550                 echo "<td>$label</td>\n";
1551         echo "<td>";
1552         echo gl_account_types_list($name, $selected_id, $all_option, $all);
1553         echo "</td>\n";
1554 }
1555
1556 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1557 {
1558         echo "<tr><td class='label'>$label</td>";
1559         gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1560                 $all);
1561         echo "</tr>\n";
1562 }
1563
1564 //-----------------------------------------------------------------------------------------------
1565 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1566         $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1567 {
1568         if ($skip_bank_accounts)
1569                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1570                         FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1571                         ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1572                         ."ON chart.account_code=acc.account_code
1573                                 WHERE acc.account_code  IS NULL
1574                         AND chart.account_type=type.id";
1575         else
1576                 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1577                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1578                         WHERE chart.account_type=type.id";
1579
1580         return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1581         array(
1582                 'format' => '_format_account',
1583                 'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
1584                 'spec_id' => '',
1585                 'order' => array('type.class_id','type.id','account_code'),
1586                 'search_box' => $cells,
1587                         'search_submit' => false,
1588                         'size' => 12,
1589                         'max' => 10,
1590                         'cells' => true,
1591                 'select_submit'=> $submit_on_change,
1592                 'async' => false,
1593                 'category' => 2,
1594                 'show_inactive' => $all
1595         ) );
1596
1597 }
1598
1599 function _format_account($row)
1600 {
1601                 return $row[0] .  "&nbsp;&nbsp;&nbsp;&nbsp;" . $row[1];
1602 }
1603
1604 function gl_all_accounts_list_cells($label, $name, $selected_id=null, 
1605         $skip_bank_accounts=false, $cells=false, $all_option=false, 
1606         $submit_on_change=false, $all=false)
1607 {
1608         if ($label != null)
1609                 echo "<td>$label</td>\n";
1610         echo "<td>";
1611         echo gl_all_accounts_list($name, $selected_id, 
1612                 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1613         echo "</td>\n";
1614 }
1615
1616 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
1617         $skip_bank_accounts=false, $cells=false, $all_option=false)
1618 {
1619         echo "<tr><td class='label'>$label</td>";
1620         gl_all_accounts_list_cells(null, $name, $selected_id, 
1621                 $skip_bank_accounts, $cells, $all_option);
1622         echo "</tr>\n";
1623 }
1624
1625 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1626 {
1627         $items = array();
1628         $items['0'] = strlen($name_no) ? $name_no : _("No");
1629         $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1630
1631         return array_selector($name, $selected_id, $items, 
1632                 array( 
1633                         'select_submit'=> $submit_on_change,
1634                         'async' => false ) ); // FIX?
1635 }
1636
1637 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1638 {
1639         if ($label != null)
1640                 echo "<td>$label</td>\n";
1641         echo "<td>";
1642         echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1643         echo "</td>\n";
1644 }
1645
1646 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1647 {
1648         echo "<tr><td class='label'>$label</td>";
1649         yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1650         echo "</tr>\n";
1651 }
1652
1653 //------------------------------------------------------------------------------------------------
1654
1655 function languages_list($name, $selected_id=null)
1656 {
1657         global $installed_languages;
1658
1659         $items = array();
1660         foreach ($installed_languages as $lang)
1661                         $items[$lang['code']] = $lang['name'];
1662         
1663         return array_selector($name, $selected_id, $items);
1664 }
1665
1666 function languages_list_cells($label, $name, $selected_id=null)
1667 {
1668         if ($label != null)
1669                 echo "<td>$label</td>\n";
1670         echo "<td>";
1671         echo languages_list($name, $selected_id);
1672         echo "</td>\n";
1673 }
1674
1675 function languages_list_row($label, $name, $selected_id=null)
1676 {
1677         echo "<tr><td class='label'>$label</td>";
1678         languages_list_cells(null, $name, $selected_id);
1679         echo "</tr>\n";
1680 }
1681
1682 //------------------------------------------------------------------------------------------------
1683
1684 function bank_account_types_list($name, $selected_id=null)
1685 {
1686         global $bank_account_types;
1687
1688         return array_selector($name, $selected_id, $bank_account_types);
1689 }
1690
1691 function bank_account_types_list_cells($label, $name, $selected_id=null)
1692 {
1693         if ($label != null)
1694                 echo "<td>$label</td>\n";
1695         echo "<td>";
1696         echo bank_account_types_list($name, $selected_id);
1697         echo "</td>\n";
1698 }
1699
1700 function bank_account_types_list_row($label, $name, $selected_id=null)
1701 {
1702         echo "<tr><td class='label'>$label</td>";
1703         bank_account_types_list_cells(null, $name, $selected_id);
1704         echo "</tr>\n";
1705 }
1706
1707 //------------------------------------------------------------------------------------------------
1708 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1709 {
1710         global $payment_person_types;
1711
1712         $items = array();
1713         foreach ($payment_person_types as $key=>$type)
1714         {
1715                 if ($key != PT_WORKORDER)
1716                         $items[$key] = $type;
1717         }               
1718         return array_selector($name, $selected_id, $items, 
1719                 array( 'select_submit'=> $submit_on_change ) );
1720 }
1721
1722 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1723 {
1724         if ($label != null)
1725                 echo "<td>$label</td>\n";
1726         echo "<td>";
1727         echo payment_person_types_list($name, $selected_id, $related);
1728         echo "</td>\n";
1729 }
1730
1731 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1732 {
1733         echo "<tr><td class='label'>$label</td>";
1734         payment_person_types_list_cells(null, $name, $selected_id, $related);
1735         echo "</tr>\n";
1736 }
1737
1738 //------------------------------------------------------------------------------------------------
1739
1740 function wo_types_list($name, $selected_id=null)
1741 {
1742         global $wo_types_array;
1743         
1744         return array_selector($name, $selected_id, $wo_types_array, 
1745                 array( 'select_submit'=> true, 'async' => true ) );
1746 }
1747
1748 function wo_types_list_row($label, $name, $selected_id=null)
1749 {
1750         echo "<tr><td class='label'>$label</td><td>\n";
1751         echo wo_types_list($name, $selected_id);
1752         echo "</td></tr>\n";
1753 }
1754
1755 //------------------------------------------------------------------------------------------------
1756
1757 function dateformats_list_row($label, $name, $value=null)
1758 {
1759         global $dateformats;
1760
1761         echo "<tr><td class='label'>$label</td>\n<td>";
1762         echo array_selector( $name, $value, $dateformats );
1763         echo "</td></tr>\n";
1764 }
1765
1766 function dateseps_list_row($label, $name, $value=null)
1767 {
1768         global $dateseps;
1769
1770         echo "<tr><td class='label'>$label</td>\n<td>";
1771         echo array_selector( $name, $value, $dateseps );
1772         echo "</td></tr>\n";
1773 }
1774
1775 function thoseps_list_row($label, $name, $value=null)
1776 {
1777         global $thoseps;
1778
1779         echo "<tr><td class='label'>$label</td>\n<td>";
1780         echo array_selector( $name, $value, $thoseps );
1781         echo "</td></tr>\n";
1782 }
1783
1784 function decseps_list_row($label, $name, $value=null)
1785 {
1786         global $decseps;
1787
1788         echo "<tr><td class='label'>$label</td>\n<td>";
1789         echo array_selector( $name, $value, $decseps );
1790         echo "</td></tr>\n";
1791 }
1792
1793 function themes_list_row($label, $name, $value=null)
1794 {
1795         global $path_to_root;
1796
1797         $path = $path_to_root.'/themes/';
1798         $themes = array();
1799         $themedir = opendir($path);
1800         while(false !== ($fname = readdir($themedir)))
1801         {
1802                 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1803                 {
1804                         $themes[$fname] =  $fname;
1805                 }
1806         }
1807         ksort($themes);
1808
1809         echo "<tr><td class='label'>$label</td>\n<td>";
1810         echo array_selector( $name, $value, $themes );
1811         echo "</td></tr>\n";
1812 }
1813
1814 function pagesizes_list_row($label, $name, $value=null)
1815 {
1816         global $pagesizes;
1817
1818         $items = array();
1819         foreach ($pagesizes as $pz)
1820                 $items[$pz] = $pz;
1821
1822         echo "<tr><td class='label'>$label</td>\n<td>";
1823         echo array_selector( $name, $value, $items );
1824         echo "</td></tr>\n";
1825 }
1826
1827 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false)
1828 {
1829         global $systypes_array;
1830
1831         return array_selector($name, $value, $systypes_array, 
1832                 array( 
1833                         'spec_option'=> $spec_opt,
1834                         'spec_id' => ALL_NUMERIC,
1835                         'select_submit'=> $submit_on_change,
1836                         'async' => false,
1837                         )
1838         );
1839 }
1840
1841 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1842 {
1843         if ($label != null)
1844                 echo "<td>$label</td>\n";
1845         echo "<td>";
1846         echo systypes_list($name, $value, false, $submit_on_change);
1847         echo "</td>\n";
1848 }
1849
1850 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1851 {
1852         echo "<tr><td class='label'>$label</td>";
1853         systypes_list_cells(null, $name, $value, false, $submit_on_change);
1854         echo "</tr>\n";
1855 }
1856
1857 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1858 {
1859         global $systypes_array;
1860
1861         if ($label != null)
1862                 echo "<td>$label</td>\n";
1863         echo "<td>";
1864
1865         $items = $systypes_array;
1866
1867         // exclude quotes, orders and dimensions
1868         foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION, 
1869                                 ST_SALESQUOTE) as $excl)
1870                         unset($items[$excl]);
1871         
1872         echo array_selector($name, $value, $items, 
1873                 array( 
1874                         'spec_option'=> _("All"),
1875                         'spec_id' => -1,
1876                         'select_submit'=> $submit_on_change,
1877                         'async' => false
1878                         )
1879         );
1880         echo "</td>\n";
1881 }
1882
1883 function cust_allocations_list_cells($label, $name, $selected=null)
1884 {
1885         global $all_items;
1886
1887         if ($label != null)
1888                 label_cell($label);
1889         echo "<td>\n";
1890         $allocs = array( 
1891                 $all_items=>_("All Types"),
1892                 '1'=> _("Sales Invoices"),
1893                 '2'=> _("Overdue Invoices"),
1894                 '3' => _("Payments"),
1895                 '4' => _("Credit Notes"),
1896                 '5' => _("Delivery Notes")
1897         );
1898         echo array_selector($name, $selected, $allocs);
1899         echo "</td>\n";
1900 }
1901
1902 function supp_allocations_list_cell($name, $selected=null)
1903 {
1904         global $all_items;
1905
1906         echo "<td>\n";
1907         $allocs = array( 
1908                 $all_items=>_("All Types"),
1909                 '1'=> _("Invoices"),
1910                 '2'=> _("Overdue Invoices"),
1911                 '3' => _("Payments"),
1912                 '4' => _("Credit Notes"),
1913                 '5' => _("Overdue Credit Notes")
1914         );
1915         echo array_selector($name, $selected, $allocs);
1916         echo "</td>\n";
1917 }
1918
1919 function policy_list_cells($label, $name, $selected=null)
1920 {
1921         if ($label != null)
1922                 label_cell($label);
1923         echo "<td>\n";
1924         echo array_selector($name, $selected, 
1925                                 array( '' => _("Automatically put balance on back order"),
1926                                         'CAN' => _("Cancel any quantites not delivered")) );
1927         echo "</td>\n";
1928 }
1929
1930 function policy_list_row($label, $name, $selected=null)
1931 {
1932         echo "<tr><td class='label'>$label</td>";
1933         policy_list_cells(null, $name, $selected);
1934         echo "</tr>\n";
1935 }
1936
1937 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1938 {
1939         if ($label != null)
1940                 label_cell($label);
1941         echo "<td>\n";
1942         echo array_selector($name, $selected, 
1943                                 array( 'Return' => _("Items Returned to Inventory Location"),
1944                                         'WriteOff' => _("Items Written Off")),
1945                                 array( 'select_submit'=> $submit_on_change ) );
1946         echo "</td>\n";
1947 }
1948
1949 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1950 {
1951         echo "<tr><td class='label'>$label</td>";
1952         credit_type_list_cells(null, $name, $selected, $submit_on_change);
1953         echo "</tr>\n";
1954 }
1955
1956 function number_list($name, $selected, $from, $to, $no_option=false)
1957 {
1958         $items = array();
1959         for ($i = $from; $i <= $to; $i++)
1960                 $items[$i] = "$i";
1961
1962         return array_selector($name, $selected, $items,
1963                                 array(  'spec_option' => $no_option,
1964                                                 'spec_id' => ALL_NUMERIC) );
1965 }
1966
1967 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1968 {
1969         if ($label != null)
1970                 label_cell($label);
1971         echo "<td>\n";
1972         echo number_list($name, $selected, $from, $to, $no_option);
1973         echo "</td>\n";
1974 }
1975
1976 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1977 {
1978         echo "<tr><td class='label'>$label</td>";
1979         echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
1980         echo "</tr>\n";
1981 }
1982
1983 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1984         $submit_on_change=true)
1985 {
1986         $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1987                 ." GROUP BY profile";
1988         $result = db_query($sql, 'cannot get all profile names');
1989         $profiles = array();
1990         while($myrow=db_fetch($result)) {
1991                 $profiles[$myrow['profile']] = $myrow['profile'];
1992         }
1993
1994         echo "<tr>";
1995         if ($label != null)
1996                 echo "<td class='label'>$label</td>\n";
1997         echo "<td>";
1998
1999         echo array_selector($name, $selected_id, $profiles, 
2000                 array( 'select_submit'=> $submit_on_change,
2001                         'spec_option'=>$spec_opt,
2002                         'spec_id' => ''
2003                  ));
2004
2005         echo "</td></tr>\n";
2006 }
2007
2008 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2009 {
2010         static $printers; // query only once for page display
2011
2012         if (!$printers) {
2013                 $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; 
2014                 $result = db_query($sql, 'cannot get all printers');
2015                 $printers = array();
2016                 while($myrow=db_fetch($result)) {
2017                         $printers[$myrow['id']] = $myrow['name'].'&nbsp;-&nbsp;'.$myrow['description'];
2018                 }
2019         }
2020         return array_selector($name, $selected_id, $printers, 
2021                 array( 'select_submit'=> $submit_on_change,
2022                         'spec_option'=>$spec_opt,
2023                         'spec_id' => ''
2024                  ));
2025 }
2026
2027 //------------------------------------------------------------------------------------------------
2028
2029 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2030 {
2031         $where = false;
2032         $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2033         if ($type != null)
2034                 $sql .= " WHERE type=$type";
2035
2036         return combo_input($name, $selected_id, $sql, 'id', 'description',
2037                 array(
2038                         'spec_id' => '',
2039                         'order' => 'description',
2040                         'select_submit'=> $submit_on_change,
2041                         'async' => false
2042                 ) );
2043
2044 }
2045
2046 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2047 {
2048         if ($label != null)
2049                 echo "<td>$label</td>\n";
2050         echo "<td>";    
2051         echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2052         echo "</td>";
2053 }
2054
2055 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2056 {
2057         echo "<tr><td class='label'>$label</td>";
2058         quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2059         echo "</tr>\n";
2060 }
2061
2062
2063 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2064 {
2065         global $quick_actions;
2066         
2067         echo "<tr><td class='label'>$label</td><td>";
2068         echo array_selector($name, $selected_id, $quick_actions, 
2069                 array( 
2070                         'select_submit'=> $submit_on_change
2071                 ) );
2072         echo "</td></tr>\n";
2073 }
2074
2075 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2076 {
2077         global $quick_entry_types;
2078                 
2079         echo "<tr><td class='label'>$label</td><td>";
2080         echo array_selector($name, $selected_id, $quick_entry_types, 
2081                 array( 
2082                         'select_submit'=> $submit_on_change
2083                         ) );
2084         echo "</td></tr>\n";
2085 }
2086
2087 function record_status_list_row($label, $name) {
2088         return yesno_list_row($label, $name, null,      _('Inactive'), _('Active'));
2089 }
2090
2091 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2092 {
2093         global $class_types;
2094         
2095         echo "<tr><td class='label'>$label</td><td>";
2096         echo array_selector($name, $selected_id, $class_types, 
2097                 array( 
2098                         'select_submit'=> $submit_on_change
2099                 ) );
2100         echo "</td></tr>\n";
2101 }
2102
2103 //------------------------------------------------------------------------------------------------
2104
2105 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2106         $show_inactive = false)
2107 {
2108         global $all_items;
2109
2110         $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2111
2112 return combo_input($name, $selected_id, $sql, 'id', 'description',
2113         array(
2114                 'spec_option'=>$new_item ? _("New role") : false,
2115                 'spec_id' => '',
2116                 'select_submit'=> $submit_on_change,
2117                 'show_inactive' => $show_inactive
2118         ) );
2119 }
2120
2121 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2122         $show_inactive = false)
2123 {
2124         if ($label != null)
2125                 echo "<td>$label</td>\n";
2126         echo "<td>";
2127         echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2128         echo "</td>\n";
2129 }
2130
2131 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2132         $show_inactive = false)
2133 {
2134         echo "<tr><td class='label'>$label</td>";
2135         security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2136         echo "</tr>\n";
2137 }
2138
2139 function tab_list_row($label, $name, $selected_id=null, $all = false)
2140 {
2141         global $installed_extensions;
2142         
2143         $tabs = array();
2144         foreach ($_SESSION['App']->applications as $app) {
2145                 $tabs[$app->id] = access_string($app->name, true);
2146         }
2147         if ($all) {     // add also not active ext. modules
2148                 foreach ($installed_extensions as $ext) {
2149                         if ($ext['type'] == 'module' && !$ext['active'])
2150                                 $tabs[$ext['tab']] = access_string($ext['title'], true);
2151                 }
2152         }
2153         echo "<tr>\n";
2154         echo "<td class='label'>$label</td><td>\n";
2155         echo array_selector($name, $selected_id, $tabs);
2156         echo "</td></tr>\n";
2157 }
2158
2159 //-----------------------------------------------------------------------------------------------
2160
2161 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2162 {
2163         // Get tags
2164         global $path_to_root;
2165         include_once($path_to_root . "/admin/db/tags_db.inc");
2166         $results = get_tags($type, $all);
2167
2168         while ($tag = db_fetch($results))
2169                 $tags[$tag['id']] = $tag['name'];
2170         
2171         if (!isset($tags)) {
2172                 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2173                 $spec_opt = false;
2174         }
2175         return array_selector($name, null, $tags,
2176                 array(
2177                         'multi' => $multi,
2178                         'height' => $height,
2179                         'spec_option'=> $spec_opt,
2180                         'spec_id' => -1,
2181                 ) );
2182 }
2183
2184 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2185 {
2186         if ($label != null)
2187                 echo "<td>$label</td>\n";
2188         echo "<td>\n";
2189         echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2190         echo "</td>\n";
2191         
2192 }
2193
2194 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2195 {
2196         echo "<tr><td class='label'>$label</td>";
2197         tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2198         echo "</tr>\n"; 
2199 }
2200
2201 //---------------------------------------------------------------------------------------------
2202 //      List of sets of active extensions 
2203 //
2204 function extset_list($name, $value=null, $submit_on_change=false)
2205 {
2206         global $db_connections;
2207
2208         $items = array();
2209         foreach ($db_connections as $comp)
2210                 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2211         return array_selector( $name, $value, $items,
2212                 array(
2213                         'spec_option'=> _("Available and/or installed"),
2214                         'spec_id' => -1,
2215                         'select_submit'=> $submit_on_change,
2216                         'async' => true
2217                 ));
2218 }
2219
2220 ?>