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");
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")."'> ";
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")."'> ";
22 $all_items = ALL_TEXT;
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.
29 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
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 'select_submit' => false, //submit on select: true/false
43 'async' => true, // select update via ajax (true) vs _page_body reload
44 // search box parameters
46 'search_box' => false, // name or true/false
47 'type' => 0, // type of extended selector:
48 // 0 - with (optional) visible search box, search by id
49 // 1 - with hidden search box, search by option text
50 // 2 - TODO reverse: box with hidden selector available via enter; this
51 // would be convenient for optional ad hoc adding of new item
52 'search_submit' => true, //search submit button: true/false
53 'size' => 8, // size and max of box tag
55 'height' => false, // number of lines in select box
56 'cells' => false, // combo displayed as 2 <td></td> cells
57 'search' => array(), // sql field names to search
58 'format' => null, // format functions for regular options
60 'box_hint' => null, // box/selectors hints; null = std see below
61 'category' => false, // category column name or false
62 'show_inactive' => false // show inactive records.
64 // ------ merge options with defaults ----------
66 $opts = array_merge($opts, $options);
67 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
69 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
70 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
71 $select_submit = $opts['select_submit'];
72 $spec_id = $opts['spec_id'];
73 $spec_option = $opts['spec_option'];
74 $by_id = ($opts['type'] == 0);
75 $class = $by_id ? 'combo':'combo2';
76 $disabled = $opts['disabled'] ? "disabled" : '';
78 if(!count($opts['search'])) {
79 $opts['search'] = array($by_id ? $valfield : $namefield);
81 if ($opts['sel_hint'] === null)
82 $opts['sel_hint'] = $by_id || $search_box==false ?
83 '' : _('Press Space tab for search pattern entry');
85 if ($opts['box_hint'] === null)
86 $opts['box_hint'] = $search_box && $search_submit != false ?
87 ($by_id ? _('Enter code fragment to search or * for all')
88 : _('Enter description fragment to search or * for all')) :'';
90 if ($selected_id == null) {
91 $selected_id = get_post($name, $opts['default']);
93 $txt = get_post($search_box);
97 if (isset($_POST['_'.$name.'_update'])) {
98 if ($by_id) $txt = $_POST[$name];
101 $Ajax->activate('_page_body');
103 $Ajax->activate($name);
106 // search related sql modifications
108 $rel = "rel='$search_box'"; // set relation to list
109 if ($opts['search_submit']) {
110 if (isset($_POST[$search_submit])) {
111 $selected_id = ''; // ignore selected_id while search
113 $Ajax->activate('_page_body');
115 $Ajax->activate($name);
118 if ($spec_option === false && $selected_id==null)
121 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
126 foreach($opts['search'] as $i=> $s)
127 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
128 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
133 if (count($opts['where'])) {
134 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
135 $where .= '('. implode($opts['where'], ' AND ') . ')';
136 $group_pos = strpos($sql, 'GROUP BY');
138 $group = substr($sql, $group_pos);
139 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
144 if ($opts['order'] != false) {
145 if (!is_array($opts['order']))
146 $opts['order'] = array($opts['order']);
147 $sql .= ' ORDER BY '.implode(',',$opts['order']);
151 // ------ make selector ----------
152 $selector = $first_opt = '';
156 //if($name=='stock_id') display_error($sql);
157 if($result = db_query($sql)) {
158 while ($contact_row = db_fetch($result)) {
159 $value = $contact_row[0];
160 $descr = $opts['format']==null ? $contact_row[1] :
161 call_user_func($opts['format'], $contact_row);
163 if (get_post($search_submit) && ($txt === $value)) {
164 $selected_id = $value;
166 if ((string)($selected_id) === $value) {
170 // show selected option even if inactive
171 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
174 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
176 if ($first_id === false) {
180 $cat = $contact_row[$opts['category']];
181 if ($opts['category'] !== false && $cat != $lastcat){
182 $selector .= "<optgroup label='".$cat."'>\n";
185 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
187 db_free_result($result);
190 // Prepend special option.
191 if ($spec_option !== false) { // if special option used - add it
192 $first_id = $spec_id;
193 $first_opt = $spec_option;
195 // if($first_id !== false) {
196 $sel = $found===false ? 'selected' : '';
197 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
198 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
202 if ($found === false) {
203 $selected_id = $first_id;
205 $_POST[$name] = $selected_id;
207 if ($by_id && $search_box != false) {
209 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
211 $selector = "<select ".(strpos($name,'[]')!==false ? "multiple" : '')
212 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
213 . "$disabled name='$name' class='$class' title='"
214 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
216 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
218 // because of bug which M$ cannot fix since IE 5.0
219 // we must embed whole selector in span tags to enable proper ajax update
220 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
222 if ($select_submit != false) { // if submit on change is used - add select button
223 global $_select_button;
224 // button class selects form reload/ajax selector update
225 $selector .= sprintf($_select_button, $disabled, user_theme(),
226 (fallback_mode() ? '' : 'display:none;'),
227 '_'.$name.'_update')."\n";
229 // ------ make combo ----------
232 if ($search_box != false) {
233 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
234 $opts['size']."' maxlength='".$opts['max'].
235 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
236 .$opts['box_hint']."'"
237 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
239 if ($search_submit != false) {
240 global $_search_button;
241 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
242 (fallback_mode() ? '' : 'display:none;'),
243 $search_submit)."\n";
246 default_focus(($search_box && $by_id) ? $search_box : $name);
248 if ($search_box && $opts['cells'])
249 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
251 echo $edit_entry.$selector;
258 Returns true if selector $name is subject to update.
260 function list_updated($name)
262 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
264 //----------------------------------------------------------------------------------------------
265 // Universal array combo generator
266 // $items is array of options 'value' => 'description'
267 // Options is reduced set of combo_selector options and is merged with defaults.
269 function array_selector($name, $selected_id, $items, $options=null)
273 $opts = array( // default options
274 'spec_option'=>false, // option text or false
275 'spec_id' => 0, // option id
276 'select_submit' => false, //submit on select: true/false
277 'async' => true, // select update via ajax (true) vs _page_body reload
278 'default' => '', // default value when $_POST is not set
279 // search box parameters
280 'height' => false, // number of lines in select box
284 // ------ merge options with defaults ----------
286 $opts = array_merge($opts, $options);
287 $select_submit = $opts['select_submit'];
288 $spec_id = $opts['spec_id'];
289 $spec_option = $opts['spec_option'];
290 $disabled = $opts['disabled'] ? "disabled" : '';
292 if ($selected_id == null) {
293 $selected_id = get_post($name, $opts['default']);
296 if (isset($_POST[ '_'.$name.'_update'])) {
298 $Ajax->activate('_page_body');
300 $Ajax->activate($name);
303 // ------ make selector ----------
304 $selector = $first_opt = '';
307 //if($name=='SelectStockFromList') display_error($sql);
308 foreach($items as $value=>$descr) {
310 if ((string)$selected_id === (string)$value) {
314 if ($first_id === false) {
318 $selector .= "<option $sel value='$value'>$descr</option>\n";
321 // Prepend special option.
322 if ($spec_option !== false) { // if special option used - add it
323 $first_id = $spec_id;
324 $first_opt = $spec_option;
325 $sel = $found===false ? 'selected' : '';
326 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
330 if ($found === false) {
331 $selected_id = $first_id;
333 $_POST[$name] = $selected_id;
335 $selector = "<select ".(strpos($name,'[]')!==false ? "multiple" : '')
336 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
337 . "$disabled name='$name' class='combo' title='"
338 . $opts['sel_hint']."'>".$selector."</select>\n";
340 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
342 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
344 if ($select_submit != false) { // if submit on change is used - add select button
345 global $_select_button;
346 $selector .= sprintf($_select_button, $disabled, user_theme(),
347 (fallback_mode() ? '' : 'display:none;'),
348 '_'.$name.'_update')."\n";
350 default_focus($name);
355 //----------------------------------------------------------------------------------------------
357 function _format_add_curr($row)
359 static $company_currency;
361 if ($company_currency == null)
363 $company_currency = get_company_currency();
365 return $row[1] . ($row[2] == $company_currency ?
366 '' : (" - " . $row[2]));
369 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
370 $all=false, $editkey = false)
374 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
376 $mode = get_company_pref('no_supplier_list');
379 set_editor('supplier', $name, $editkey);
381 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
383 'format' => '_format_add_curr',
384 'order' => array('supp_ref'),
385 'search_box' => $mode!=0,
387 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
388 'spec_id' => $all_items,
389 'select_submit'=> $submit_on_change,
391 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
392 _('Select supplier'),
393 'show_inactive'=>$all
397 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
398 $submit_on_change=false, $all=false, $editkey = false)
401 echo "<td>$label</td><td>\n";
402 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change,
408 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
409 $submit_on_change=false, $all=false, $editkey = false)
411 echo "<tr><td>$label</td><td>";
412 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change,
417 //----------------------------------------------------------------------------------------------
419 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
420 $show_inactive=false, $editkey = false)
424 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
426 $mode = get_company_pref('no_customer_list');
429 set_editor('customer', $name, $editkey);
431 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
433 'format' => '_format_add_curr',
434 'order' => array('debtor_ref'),
435 'search_box' => $mode!=0,
438 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
439 'spec_id' => $all_items,
440 'select_submit'=> $submit_on_change,
442 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
443 _('Select customer'),
444 'show_inactive' => $show_inactive
448 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
449 $submit_on_change=false, $show_inactive=false, $editkey = false)
452 echo "<td>$label</td>\n";
454 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
455 $show_inactive, $editkey);
460 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
461 $submit_on_change=false, $show_inactive=false, $editkey = false)
463 echo "<tr><td>$label</td><td nowrap>";
464 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
465 $show_inactive, $editkey);
466 echo "</td>\n</tr>\n";
470 //------------------------------------------------------------------------------------------------
472 function customer_branches_list($customer_id, $name, $selected_id=null,
473 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
477 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
478 WHERE debtor_no='" . $customer_id . "' ";
481 set_editor('branch', $name, $editkey);
483 $where = $enabled ? array("disable_trans = 0") : array();
484 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
487 'order' => array('branch_ref'),
488 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
489 'spec_id' => $all_items,
490 'select_submit'=> $submit_on_change,
491 'sel_hint' => _('Select customer branch')
494 //------------------------------------------------------------------------------------------------
496 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
497 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
500 echo "<td>$label</td>\n";
502 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
503 $submit_on_change, $editkey);
508 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
509 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
512 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id,
513 $all_option, $enabled, $submit_on_change, $editkey);
518 //------------------------------------------------------------------------------------------------
520 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
524 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
526 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
528 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
529 'spec_id' => $all_items,
530 'select_submit'=> $submit_on_change
534 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
537 echo "<td>$label</td>\n";
539 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
544 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
547 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
552 //-----------------------------------------------------------------------------------------------
554 function currencies_list($name, $selected_id=null, $submit_on_change=false)
556 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
558 // default to the company currency
560 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
562 'select_submit'=> $submit_on_change,
563 'default' => get_company_currency(),
568 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
571 echo "<td>$label</td>\n";
573 $str = currencies_list($name, $selected_id, $submit_on_change);
578 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
581 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
586 //---------------------------------------------------------------------------------------------------
588 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
591 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
593 // default to the company current fiscal year
595 return combo_input($name, $selected_id, $sql, 'id', '',
598 'default' => get_company_pref('f_year'),
599 'format' => '_format_fiscalyears',
600 'select_submit'=> $submit_on_change,
605 function _format_fiscalyears($row)
607 return sql2date($row[1]) . " - " . sql2date($row[2])
608 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
611 function fiscalyears_list_cells($label, $name, $selected_id=null)
614 echo "<td>$label</td>\n";
616 $str = fiscalyears_list($name, $selected_id);
621 function fiscalyears_list_row($label, $name, $selected_id=null)
624 $str = fiscalyears_list_cells($label, $name, $selected_id);
628 //------------------------------------------------------------------------------------
630 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
631 $submit_on_change=false, $showclosed=false, $showtype=1)
633 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
636 'order' => 'reference',
637 'spec_option'=>$no_option ? $showname : false,
639 'select_submit'=> $submit_on_change,
644 $options['where'][] = "closed=0";
646 $options['where'][] = "type_=$showtype";
648 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
651 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
652 $showclosed=false, $showtype=0, $submit_on_change=false)
655 echo "<td>$label</td>\n";
657 $str = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
662 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
663 $showclosed=false, $showtype=0, $submit_on_change=false)
666 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
667 $showclosed, $showtype, $submit_on_change);
672 //---------------------------------------------------------------------------------------------------
674 function stock_items_list($name, $selected_id=null, $all_option=false,
675 $submit_on_change=false, $opts=array(), $editkey = false)
679 $sql = "SELECT stock_id, s.description, c.description, s.inactive
680 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
683 set_editor('item', $name, $editkey);
685 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
688 'format' => '_format_stock_items',
689 'spec_option' => $all_option===true ? _("All Items") : $all_option,
690 'spec_id' => $all_items,
691 'search_box' => true,
692 'search' => array("stock_id", "c.description","s.description"),
693 'search_submit' => get_company_pref('no_item_list')!=0,
695 'select_submit'=> $submit_on_change,
697 'order' => array('c.description','stock_id')
701 function _format_stock_items($row)
703 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
706 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
707 $submit_on_change=false, $all=false, $editkey = false)
710 echo "<td>$label</td>\n";
711 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
712 array('cells'=>true, 'show_inactive'=>$all), $editkey);
716 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
719 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
724 //---------------------------------------------------------------------------------------------------
726 // Select item via foreign code.
728 function sales_items_list($name, $selected_id=null, $all_option=false,
729 $submit_on_change=false, $type='', $opts=array())
733 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
736 ".TB_PREF."stock_master s,
737 ".TB_PREF."item_codes i
739 ".TB_PREF."stock_category c
740 ON i.category_id=c.category_id
741 WHERE i.stock_id=s.stock_id";
744 if ($type == 'local') { // exclude foreign codes
745 $sql .= " AND !i.is_foreign";
746 } elseif ($type == 'kits') { // sales kits
747 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
749 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
750 $sql .= " GROUP BY i.item_code";
752 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
755 'format' => '_format_stock_items',
756 'spec_option' => $all_option===true ? _("All Items") : $all_option,
757 'spec_id' => $all_items,
758 'search_box' => true,
759 'search' => array("i.item_code", "i.description"),
760 'search_submit' => get_company_pref('no_item_list')!=0,
762 'select_submit'=> $submit_on_change,
764 'order' => array('c.description','i.item_code')
768 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
771 echo "<td>$label</td>\n";
772 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
773 '', array('cells'=>true));
777 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
779 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
780 'kits', array('cells'=>false));
784 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
788 echo "<td>$label</td>\n";
790 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
791 'local', array('cells'=>false));
795 //------------------------------------------------------------------------------------
797 function stock_manufactured_items_list($name, $selected_id=null,
798 $all_option=false, $submit_on_change=false)
800 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
801 array('where'=>array("mb_flag= 'M'")));
805 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
806 $all_option=false, $submit_on_change=false)
809 echo "<td>$label</td>\n";
811 $str = stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
816 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
817 $all_option=false, $submit_on_change=false)
820 $str = stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
824 //------------------------------------------------------------------------------------
826 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
827 $all_option=false, $submit_on_change=false, $editkey = false)
829 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
830 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
834 function stock_component_items_list_cells($label, $name, $parent_stock_id,
835 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
838 echo "<td>$label</td>\n";
839 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
840 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
844 //------------------------------------------------------------------------------------
846 function stock_costable_items_list($name, $selected_id=null,
847 $all_option=false, $submit_on_change=false)
849 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
850 array('where'=>array("mb_flag!='D'")));
854 function stock_costable_items_list_cells($label, $name, $selected_id=null,
855 $all_option=false, $submit_on_change=false)
858 echo "<td>$label</td>\n";
859 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
860 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
864 //------------------------------------------------------------------------------------
865 function stock_purchasable_items_list($name, $selected_id=null,
866 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
868 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
869 array('where'=>array("mb_flag!= 'M'"),
870 'show_inactive'=>$all), $editkey);
874 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
875 $all_option=false, $submit_on_change=false, $editkey=false)
878 echo "<td>$label</td>\n";
879 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
880 array('where'=>array("mb_flag!= 'M'"),
881 'cells'=>true), $editkey);
885 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
886 $all_option=false, $submit_on_change=false, $editkey=false)
889 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
890 $all_option, $submit_on_change, $editkey);
895 //------------------------------------------------------------------------------------
897 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
903 echo "<td>$label</td>\n";
906 array_selector($name, $selected_id, $stock_types,
908 'select_submit'=> true,
909 'disabled' => !$enabled) );
913 function stock_units_list_row($label, $name, $value=null, $enabled=true)
915 $result = get_all_item_units();
918 echo "<td>$label</td>\n";
921 while($unit = db_fetch($result))
922 $units[$unit['abbr']] = $unit['name'];
924 array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
929 //------------------------------------------------------------------------------------
931 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
933 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
935 return combo_input($name, $selected_id, $sql, 'id', 'name',
937 'spec_option' => $none_option,
938 'spec_id' => ALL_NUMERIC,
939 'select_submit'=> $submit_on_change,
944 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
945 $submit_on_change=false)
948 echo "<td>$label</td>\n";
950 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
955 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
956 $submit_on_change=false)
959 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
964 //------------------------------------------------------------------------------------
966 function tax_groups_list($name, $selected_id=null,
967 $none_option=false, $submit_on_change=false)
969 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
971 return combo_input($name, $selected_id, $sql, 'id', 'name',
974 'spec_option' => $none_option,
975 'spec_id' => ALL_NUMERIC,
976 'select_submit'=> $submit_on_change,
981 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
984 echo "<td>$label</td>\n";
986 $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
991 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
994 $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
999 //------------------------------------------------------------------------------------
1001 function item_tax_types_list($name, $selected_id=null)
1003 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1004 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1007 function item_tax_types_list_cells($label, $name, $selected_id=null)
1010 echo "<td>$label</td>\n";
1012 item_tax_types_list($name, $selected_id);
1016 function item_tax_types_list_row($label, $name, $selected_id=null)
1019 item_tax_types_list_cells($label, $name, $selected_id);
1023 //------------------------------------------------------------------------------------
1025 function shippers_list($name, $selected_id=null)
1027 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1028 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1029 array('order'=>array('shipper_name')));
1032 function shippers_list_cells($label, $name, $selected_id=null)
1035 echo "<td>$label</td>\n";
1037 shippers_list($name, $selected_id);
1041 function shippers_list_row($label, $name, $selected_id=null)
1044 shippers_list_cells($label, $name, $selected_id);
1048 //-------------------------------------------------------------------------------------
1050 function sales_persons_list($name, $selected_id=null)
1052 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1053 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1054 array('order'=>array('salesman_name')));
1057 function sales_persons_list_cells($label, $name, $selected_id=null)
1060 echo "<td>$label</td>\n";
1062 sales_persons_list($name, $selected_id);
1066 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1069 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1073 //------------------------------------------------------------------------------------
1075 function sales_areas_list($name, $selected_id=null)
1077 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1078 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1081 function sales_areas_list_cells($label, $name, $selected_id=null)
1084 echo "<td>$label</td>\n";
1086 sales_areas_list($name, $selected_id);
1090 function sales_areas_list_row($label, $name, $selected_id=null)
1093 sales_areas_list_cells($label, $name, $selected_id);
1097 //------------------------------------------------------------------------------------
1099 function sales_groups_list($name, $selected_id=null, $special_option=false)
1101 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1102 combo_input($name, $selected_id, $sql, 'id', 'description', array(
1103 'spec_option' => $special_option===true ? ' ' : $special_option,
1104 'order' => 'description', 'spec_id' => 0,
1108 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1111 echo "<td>$label</td>\n";
1113 sales_groups_list($name, $selected_id, $special_option);
1117 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1120 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1124 //------------------------------------------------------------------------------------
1126 function _format_template_items($row)
1128 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1131 function templates_list($name, $selected_id=null, $special_option=false)
1133 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1134 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1135 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1136 combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1137 'format' => '_format_template_items',
1138 'spec_option' => $special_option===true ? ' ' : $special_option,
1139 'order' => 'order_no', 'spec_id' => 0,
1143 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1146 echo "<td>$label</td>\n";
1148 templates_list($name, $selected_id, $special_option);
1152 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1155 templates_list_cells($label, $name, $selected_id, $special_option);
1159 //------------------------------------------------------------------------------------
1161 function workorders_list($name, $selected_id=null)
1163 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1164 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1167 function workorders_list_cells($label, $name, $selected_id=null)
1170 echo "<td>$label</td>\n";
1172 workorders_list($name, $selected_id);
1176 function workorders_list_row($label, $name, $selected_id=null)
1179 workorders_list_cells($label, $name, $selected_id);
1183 //------------------------------------------------------------------------------------
1185 function payment_terms_list($name, $selected_id=null)
1187 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1188 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1191 function payment_terms_list_cells($label, $name, $selected_id=null)
1194 echo "<td>$label</td>\n";
1196 payment_terms_list($name, $selected_id);
1200 function payment_terms_list_row($label, $name, $selected_id=null)
1203 payment_terms_list_cells($label, $name, $selected_id);
1207 //------------------------------------------------------------------------------------
1209 function credit_status_list($name, $selected_id=null)
1211 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1212 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1215 function credit_status_list_cells($label, $name, $selected_id=null)
1218 echo "<td>$label</td>\n";
1220 credit_status_list($name, $selected_id);
1224 function credit_status_list_row($label, $name, $selected_id=null)
1227 credit_status_list_cells($label, $name, $selected_id);
1231 //-----------------------------------------------------------------------------------------------
1233 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1235 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1237 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1239 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1241 'select_submit'=> $submit_on_change,
1242 // 'async' => false,
1246 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1249 echo "<td>$label</td>\n";
1251 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1256 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1259 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1264 //-----------------------------------------------------------------------------------------------
1266 function movement_types_list($name, $selected_id=null)
1268 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1269 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1272 function movement_types_list_cells($label, $name, $selected_id=null)
1275 echo "<td>$label</td>\n";
1277 movement_types_list($name, $selected_id);
1281 function movement_types_list_row($label, $name, $selected_id=null)
1284 movement_types_list_cells($label, $name, $selected_id);
1288 //-----------------------------------------------------------------------------------------------
1289 function _format_date($row)
1291 return sql2date($row['reconciled']);
1294 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1296 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1297 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1298 GROUP BY reconciled";
1299 combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1301 'spec_option' => $special_option,
1302 'format' => '_format_date',
1304 'select_submit'=> $submit_on_change
1308 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1311 echo "<td>$label</td>\n";
1313 bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1317 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1320 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1324 //-----------------------------------------------------------------------------------------------
1326 function workcenter_list($name, $selected_id=null, $all_option=false)
1330 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1332 return combo_input($name, $selected_id, $sql, 'id', 'name',
1334 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1335 'spec_id' => $all_items,
1339 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1341 default_focus($name);
1343 echo "<td>$label</td>\n";
1345 workcenter_list($name, $selected_id, $all_option);
1349 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1352 workcenter_list_cells($label, $name, $selected_id, $all_option);
1356 //-----------------------------------------------------------------------------------------------
1358 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1360 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1361 FROM ".TB_PREF."bank_accounts";
1362 // , ".TB_PREF."chart_master
1363 // WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1365 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1367 'format' => '_format_add_curr',
1368 'select_submit'=> $submit_on_change,
1373 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1376 echo "<td>$label</td>\n";
1378 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1383 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1386 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1390 //-----------------------------------------------------------------------------------------------
1392 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1394 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1395 FROM ".TB_PREF."bank_accounts
1396 WHERE ".TB_PREF."bank_accounts.account_type=3";
1399 echo "<tr><td>$label</td>\n";
1401 $str = combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1403 'format' => '_format_add_curr',
1404 'select_submit'=> $submit_on_change,
1407 echo "</td></tr>\n";
1410 //-----------------------------------------------------------------------------------------------
1412 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1414 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1416 default_focus($name);
1419 echo "<td>$label</td>\n";
1422 $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1424 'select_submit'=> $submit_on_change,
1426 'spec_option' =>$spec_option,
1428 'order'=> array('pos_name')
1430 echo "</td></tr>\n";
1434 //-----------------------------------------------------------------------------------------------
1436 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1439 echo "<td>$label</td>\n";
1441 $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1445 //-----------------------------------------------------------------------------------------------
1447 function class_list($name, $selected_id=null, $submit_on_change=false)
1449 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1451 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1453 'select_submit'=> $submit_on_change,
1459 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1462 echo "<td>$label</td>\n";
1464 $str = class_list($name, $selected_id, $submit_on_change);
1469 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1472 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1477 //-----------------------------------------------------------------------------------------------
1479 function stock_categories_list($name, $selected_id=null, $submit_on_change=false)
1481 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1482 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1483 array('order'=>'category_id',
1484 'select_submit'=> $submit_on_change,
1489 function stock_categories_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1492 echo "<td>$label</td>\n";
1494 stock_categories_list($name, $selected_id, $submit_on_change);
1498 function stock_categories_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1501 stock_categories_list_cells($label, $name, $selected_id, $submit_on_change);
1505 //-----------------------------------------------------------------------------------------------
1507 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1511 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1513 combo_input($name, $selected_id, $sql, 'id', 'name',
1516 'spec_option' =>$all_option,
1517 'spec_id' => $all_option_numeric ? 0 : $all_items
1521 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1522 $all_option_numeric=false)
1525 echo "<td>$label</td>\n";
1527 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1531 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1532 $all_option_numeric=false)
1535 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1536 $all_option_numeric);
1540 //-----------------------------------------------------------------------------------------------
1541 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1542 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1544 if ($skip_bank_accounts)
1545 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1546 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1547 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1548 ."ON chart.account_code=acc.account_code
1549 WHERE acc.account_code IS NULL
1550 AND chart.account_type=type.id";
1552 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1553 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1554 WHERE chart.account_type=type.id";
1556 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1558 'format' => '_format_account',
1559 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1561 'order' => array('type.id','account_code'),
1562 'search_box' => $cells,
1563 'search_submit' => false,
1567 'select_submit'=> $submit_on_change,
1570 'show_inactive' => $all
1575 function _format_account($row)
1577 return $row[0] . " " . $row[1];
1580 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1581 $skip_bank_accounts=false, $cells=false, $all_option=false,
1582 $submit_on_change=false, $all=false)
1585 echo "<td>$label</td>\n";
1587 gl_all_accounts_list($name, $selected_id,
1588 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1592 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1593 $skip_bank_accounts=false, $cells=false, $all_option=false)
1596 gl_all_accounts_list_cells($label, $name, $selected_id,
1597 $skip_bank_accounts, $cells, $all_option);
1601 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1604 $items['0'] = strlen($name_no) ? $name_no : _("No");
1605 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1607 return array_selector($name, $selected_id, $items,
1609 'select_submit'=> $submit_on_change,
1610 'async' => false ) ); // FIX?
1613 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1616 echo "<td>$label</td>\n";
1618 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1623 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1626 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1631 //------------------------------------------------------------------------------------------------
1633 function languages_list($name, $selected_id=null)
1635 global $installed_languages;
1638 foreach ($installed_languages as $lang)
1639 $items[$lang['code']] = $lang['name'];
1641 return array_selector($name, $selected_id, $items );
1644 function languages_list_cells($label, $name, $selected_id=null)
1647 echo "<td>$label</td>\n";
1649 languages_list($name, $selected_id);
1653 function languages_list_row($label, $name, $selected_id=null)
1656 languages_list_cells($label, $name, $selected_id);
1660 //------------------------------------------------------------------------------------------------
1662 function bank_account_types_list($name, $selected_id=null)
1664 global $bank_account_types;
1666 return array_selector($name, $selected_id, $bank_account_types);
1669 function bank_account_types_list_cells($label, $name, $selected_id=null)
1672 echo "<td>$label</td>\n";
1674 bank_account_types_list($name, $selected_id);
1678 function bank_account_types_list_row($label, $name, $selected_id=null)
1681 bank_account_types_list_cells($label, $name, $selected_id);
1685 //------------------------------------------------------------------------------------------------
1686 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1688 global $payment_person_types;
1691 foreach ($payment_person_types as $key=>$type)
1693 if ($key != PT_WORKORDER)
1694 $items[$key] = $type;
1696 return array_selector($name, $selected_id, $items,
1697 array( 'select_submit'=> $submit_on_change ) );
1700 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1703 echo "<td>$label</td>\n";
1705 $str = payment_person_types_list($name, $selected_id, $related);
1710 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1713 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1718 //------------------------------------------------------------------------------------------------
1720 function wo_types_list($name, $selected_id=null)
1722 global $wo_types_array;
1724 return array_selector($name, $selected_id, $wo_types_array,
1725 array( 'select_submit'=> true, 'async' => true ) );
1728 function wo_types_list_row($label, $name, $selected_id=null)
1730 echo "<tr><td>$label</td><td>\n";
1731 $str = wo_types_list($name, $selected_id);
1732 echo "</td></tr>\n";
1736 //------------------------------------------------------------------------------------------------
1738 function dateformats_list_row($label, $name, $value=null)
1740 global $dateformats;
1742 echo "<tr><td>$label</td>\n<td>";
1743 array_selector( $name, $value, $dateformats );
1744 echo "</td></tr>\n";
1747 function dateseps_list_row($label, $name, $value=null)
1751 echo "<tr><td>$label</td>\n<td>";
1752 array_selector( $name, $value, $dateseps );
1753 echo "</td></tr>\n";
1756 function thoseps_list_row($label, $name, $value=null)
1760 echo "<tr><td>$label</td>\n<td>";
1761 array_selector( $name, $value, $thoseps );
1762 echo "</td></tr>\n";
1765 function decseps_list_row($label, $name, $value=null)
1769 echo "<tr><td>$label</td>\n<td>";
1770 array_selector( $name, $value, $decseps );
1771 echo "</td></tr>\n";
1774 function themes_list_row($label, $name, $value=null)
1776 global $path_to_root;
1778 $path = $path_to_root.'/themes/';
1780 $themedir = opendir($path);
1781 while(false !== ($fname = readdir($themedir)))
1783 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1785 $themes[$fname] = $fname;
1790 echo "<tr><td>$label</td>\n<td>";
1791 array_selector( $name, $value, $themes );
1792 echo "</td></tr>\n";
1795 function pagesizes_list_row($label, $name, $value=null)
1800 foreach ($pagesizes as $pz)
1803 echo "<tr><td>$label</td>\n<td>";
1804 array_selector( $name, $value, $items );
1805 echo "</td></tr>\n";
1808 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1810 global $systypes_array;
1813 echo "<td>$label</td>\n";
1816 $str = array_selector($name, $value, $systypes_array,
1818 'select_submit'=> $submit_on_change,
1826 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1828 global $systypes_array;
1831 echo "<td>$label</td>\n";
1834 $items = $systypes_array;
1836 // exclude quotes, orders and dimensions
1837 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1838 ST_SALESQUOTE) as $excl)
1839 unset($items[$excl]);
1841 $str = array_selector($name, $value, $items,
1843 'spec_option'=> _("All"),
1845 'select_submit'=> $submit_on_change,
1853 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1856 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1861 function cust_allocations_list_cells($label, $name, $selected=null)
1869 $all_items=>_("All Types"),
1870 '1'=> _("Sales Invoices"),
1871 '2'=> _("Overdue Invoices"),
1872 '3' => _("Payments"),
1873 '4' => _("Credit Notes"),
1874 '5' => _("Delivery Notes")
1876 $str = array_selector($name, $selected, $allocs);
1881 function supp_allocations_list_cell($name, $selected=null)
1887 $all_items=>_("All Types"),
1888 '1'=> _("Invoices"),
1889 '2'=> _("Overdue Invoices"),
1890 '3' => _("Payments"),
1891 '4' => _("Credit Notes"),
1892 '5' => _("Overdue Credit Notes")
1894 $str = array_selector($name, $selected, $allocs);
1899 function policy_list_cells($label, $name, $selected=null)
1904 $str = array_selector($name, $selected,
1905 array( '' => _("Automatically put balance on back order"),
1906 'CAN' => _("Cancel any quantites not delivered")) );
1911 function policy_list_row($label, $name, $selected=null)
1914 policy_list_cells($label, $name, $selected);
1918 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1923 $str = array_selector($name, $selected,
1924 array( 'Return' => _("Items Returned to Inventory Location"),
1925 'WriteOff' => _("Items Written Off")),
1926 array( 'select_submit'=> $submit_on_change ) );
1931 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1934 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1939 function number_list($name, $selected, $from, $to, $no_option=false)
1942 for ($i = $from; $i <= $to; $i++)
1945 return array_selector($name, $selected, $items,
1946 array( 'spec_option' => $no_option,
1947 'spec_id' => ALL_NUMERIC) );
1950 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1955 number_list($name, $selected, $from, $to, $no_option);
1959 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1962 number_list_cells($label, $name, $selected, $from, $to, $no_option);
1966 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1967 $submit_on_change=true)
1969 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1970 ." GROUP BY profile";
1971 $result = db_query($sql, 'cannot get all profile names');
1972 $profiles = array();
1973 while($myrow=db_fetch($result)) {
1974 $profiles[$myrow['profile']] = $myrow['profile'];
1979 echo "<td>$label</td>\n";
1982 array_selector($name, $selected_id, $profiles,
1983 array( 'select_submit'=> $submit_on_change,
1984 'spec_option'=>$spec_opt,
1988 echo "</td></tr>\n";
1991 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1993 static $printers; // query only once for page display
1996 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
1997 $result = db_query($sql, 'cannot get all printers');
1998 $printers = array();
1999 while($myrow=db_fetch($result)) {
2000 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2003 array_selector($name, $selected_id, $printers,
2004 array( 'select_submit'=> $submit_on_change,
2005 'spec_option'=>$spec_opt,
2010 //------------------------------------------------------------------------------------------------
2012 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2015 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2017 $sql .= " WHERE type=$type";
2019 combo_input($name, $selected_id, $sql, 'id', 'description',
2022 'order' => 'description',
2023 'select_submit'=> $submit_on_change,
2029 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2031 echo "<td>$label</td><td>\n";
2032 quick_entries_list($name, $selected_id, $type, $submit_on_change);
2036 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2039 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2044 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2046 global $quick_actions;
2048 echo "<tr><td>$label</td><td>";
2049 array_selector($name, $selected_id, $quick_actions,
2051 'select_submit'=> $submit_on_change
2053 echo "</td></tr>\n";
2056 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2058 global $quick_entry_types;
2060 echo "<tr><td>$label</td><td>";
2061 array_selector($name, $selected_id, $quick_entry_types,
2063 'select_submit'=> $submit_on_change
2065 echo "</td></tr>\n";
2068 function record_status_list_row($label, $name) {
2069 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2072 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2074 global $class_types;
2076 echo "<tr><td>$label</td><td>";
2077 array_selector($name, $selected_id, $class_types,
2079 'select_submit'=> $submit_on_change
2081 echo "</td></tr>\n";
2084 //------------------------------------------------------------------------------------------------
2086 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2087 $show_inactive = false)
2091 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2093 return combo_input($name, $selected_id, $sql, 'id', 'description',
2095 'spec_option'=>$new_item ? _("New role") : false,
2097 'select_submit'=> $submit_on_change,
2098 'show_inactive' => $show_inactive
2102 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2103 $show_inactive = false)
2106 echo "<td>$label</td>\n";
2108 $str = security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2113 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2114 $show_inactive = false)
2117 $str = security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2122 function tab_list_row($label, $name, $selected_id=null)
2126 echo "<td>$label</td><td>\n";
2130 array_selector($name, $selected_id, $tabs);
2132 echo "</td></tr>\n";
2135 //---------------------------------------------------------------------------------------------
2136 // List of sets of active extensions
2138 function extset_list($name, $value=null, $submit_on_change=false)
2140 global $db_connections;
2143 foreach ($db_connections as $comp)
2144 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2145 array_selector( $name, $value, $items,
2147 'spec_option'=> _("Installed on system"),
2149 'select_submit'=> $submit_on_change,