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