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