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 'cells' => false, // combo displayed as 2 <td></td> cells
56 'search' => array(), // sql field names to search
57 'format' => null, // format functions for regular options
59 'box_hint' => null, // box/selectors hints; null = std see below
60 'category' => false, // category column name or false
61 'show_inactive' => false // show inactive records.
63 // ------ merge options with defaults ----------
65 $opts = array_merge($opts, $options);
66 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
68 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
69 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
70 $select_submit = $opts['select_submit'];
71 $spec_id = $opts['spec_id'];
72 $spec_option = $opts['spec_option'];
73 $by_id = ($opts['type'] == 0);
74 $class = $by_id ? 'combo':'combo2';
75 $disabled = $opts['disabled'] ? "disabled" : '';
77 if(!count($opts['search'])) {
78 $opts['search'] = array($by_id ? $valfield : $namefield);
80 if ($opts['sel_hint'] === null)
81 $opts['sel_hint'] = $by_id || $search_box==false ?
82 '' : _('Press Space tab for search pattern entry');
84 if ($opts['box_hint'] === null)
85 $opts['box_hint'] = $search_box && $search_submit != false ?
86 ($by_id ? _('Enter code fragment to search or * for all')
87 : _('Enter description fragment to search or * for all')) :'';
89 if ($selected_id == null) {
90 $selected_id = get_post($name, $opts['default']);
92 $txt = get_post($search_box);
96 if (isset($_POST['_'.$name.'_update'])) {
97 if ($by_id) $txt = $_POST[$name];
100 $Ajax->activate('_page_body');
102 $Ajax->activate($name);
105 // search related sql modifications
107 $rel = "rel='$search_box'"; // set relation to list
108 if ($opts['search_submit']) {
109 if (isset($_POST[$search_submit])) {
110 $selected_id = ''; // ignore selected_id while search
112 $Ajax->activate('_page_body');
114 $Ajax->activate($name);
117 if ($spec_option === false && $selected_id==null)
120 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
125 foreach($opts['search'] as $i=> $s)
126 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
127 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
132 if (count($opts['where'])) {
133 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
134 $where .= '('. implode($opts['where'], ' AND ') . ')';
135 $group_pos = strpos($sql, 'GROUP BY');
137 $group = substr($sql, $group_pos);
138 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
143 if ($opts['order'] != false) {
144 if (!is_array($opts['order']))
145 $opts['order'] = array($opts['order']);
146 $sql .= ' ORDER BY '.implode(',',$opts['order']);
150 // ------ make selector ----------
151 $selector = $first_opt = '';
155 //if($name=='stock_id') display_error($sql);
156 if($result = db_query($sql)) {
157 while ($contact_row = db_fetch($result)) {
158 $value = $contact_row[0];
159 $descr = $opts['format']==null ? $contact_row[1] :
160 call_user_func($opts['format'], $contact_row);
162 if (get_post($search_submit) && ($txt === $value)) {
163 $selected_id = $value;
165 if ((string)($selected_id) === $value) {
169 // show selected option even if inactive
170 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
173 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
175 if ($first_id === false) {
179 $cat = $contact_row[$opts['category']];
180 if ($opts['category'] !== false && $cat != $lastcat){
181 $selector .= "<optgroup label='".$cat."'>\n";
184 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
186 db_free_result($result);
189 // Prepend special option.
190 if ($spec_option !== false) { // if special option used - add it
191 $first_id = $spec_id;
192 $first_opt = $spec_option;
194 // if($first_id !== false) {
195 $sel = $found===false ? 'selected' : '';
196 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
197 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
201 if ($found === false) {
202 $selected_id = $first_id;
204 $_POST[$name] = $selected_id;
206 if ($by_id && $search_box != false) {
208 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
210 $selector = "<select $disabled name='$name' class='$class' title='"
211 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
213 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
215 // because of bug which M$ cannot fix since IE 5.0
216 // we must embed whole selector in span tags to enable proper ajax update
217 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
219 if ($select_submit != false) { // if submit on change is used - add select button
220 global $_select_button;
221 // button class selects form reload/ajax selector update
222 $selector .= sprintf($_select_button, $disabled, user_theme(),
223 (fallback_mode() ? '' : 'display:none;'),
224 '_'.$name.'_update')."\n";
226 // ------ make combo ----------
229 if ($search_box != false) {
230 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
231 $opts['size']."' maxlength='".$opts['max'].
232 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
233 .$opts['box_hint']."'"
234 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
236 if ($search_submit != false) {
237 global $_search_button;
238 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
239 (fallback_mode() ? '' : 'display:none;'),
240 $search_submit)."\n";
243 default_focus(($search_box && $by_id) ? $search_box : $name);
245 if ($search_box && $opts['cells'])
246 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
248 echo $edit_entry.$selector;
255 Returns true if selector $name is subject to update.
257 function list_updated($name)
259 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
261 //----------------------------------------------------------------------------------------------
262 // Universal array combo generator
263 // $items is array of options 'value' => 'description'
264 // Options is reduced set of combo_selector options and is merged with defaults.
266 function array_selector($name, $selected_id, $items, $options=null)
270 $opts = array( // default options
271 'spec_option'=>false, // option text or false
272 'spec_id' => 0, // option id
273 'select_submit' => false, //submit on select: true/false
274 'async' => true, // select update via ajax (true) vs _page_body reload
275 'default' => '', // default value when $_POST is not set
276 // search box parameters
280 // ------ merge options with defaults ----------
282 $opts = array_merge($opts, $options);
283 $select_submit = $opts['select_submit'];
284 $spec_id = $opts['spec_id'];
285 $spec_option = $opts['spec_option'];
286 $disabled = $opts['disabled'] ? "disabled" : '';
288 if ($selected_id == null) {
289 $selected_id = get_post($name, $opts['default']);
292 if (isset($_POST[ '_'.$name.'_update'])) {
294 $Ajax->activate('_page_body');
296 $Ajax->activate($name);
299 // ------ make selector ----------
300 $selector = $first_opt = '';
303 //if($name=='SelectStockFromList') display_error($sql);
304 foreach($items as $value=>$descr) {
306 if ((string)$selected_id === (string)$value) {
310 if ($first_id === false) {
314 $selector .= "<option $sel value='$value'>$descr</option>\n";
317 // Prepend special option.
318 if ($spec_option !== false) { // if special option used - add it
319 $first_id = $spec_id;
320 $first_opt = $spec_option;
321 $sel = $found===false ? 'selected' : '';
322 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
326 if ($found === false) {
327 $selected_id = $first_id;
329 $_POST[$name] = $selected_id;
331 $selector = "<select $disabled name='$name' class='combo' title='"
332 . $opts['sel_hint']."'>".$selector."</select>\n";
334 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
336 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
338 if ($select_submit != false) { // if submit on change is used - add select button
339 global $_select_button;
340 $selector .= sprintf($_select_button, $disabled, user_theme(),
341 (fallback_mode() ? '' : 'display:none;'),
342 '_'.$name.'_update')."\n";
344 default_focus($name);
349 //----------------------------------------------------------------------------------------------
351 function _format_add_curr($row)
353 static $company_currency;
355 if ($company_currency == null)
357 $company_currency = get_company_currency();
359 return $row[1] . ($row[2] == $company_currency ?
360 '' : (" - " . $row[2]));
363 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
364 $all=false, $editkey = false)
368 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
370 $mode = get_company_pref('no_supplier_list');
373 set_editor('supplier', $name, $editkey);
375 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
377 'format' => '_format_add_curr',
378 'order' => array('supp_ref'),
379 'search_box' => $mode!=0,
381 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
382 'spec_id' => $all_items,
383 'select_submit'=> $submit_on_change,
385 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
386 _('Select supplier'),
387 'show_inactive'=>$all
391 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
392 $submit_on_change=false, $all=false, $editkey = false)
395 echo "<td>$label</td><td>\n";
396 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change,
402 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
403 $submit_on_change=false, $all=false, $editkey = false)
405 echo "<tr><td>$label</td><td>";
406 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change,
411 //----------------------------------------------------------------------------------------------
413 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
414 $show_inactive=false, $editkey = false)
418 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
420 $mode = get_company_pref('no_customer_list');
423 set_editor('customer', $name, $editkey);
425 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
427 'format' => '_format_add_curr',
428 'order' => array('debtor_ref'),
429 'search_box' => $mode!=0,
432 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
433 'spec_id' => $all_items,
434 'select_submit'=> $submit_on_change,
436 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
437 _('Select customer'),
438 'show_inactive' => $show_inactive
442 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
443 $submit_on_change=false, $show_inactive=false, $editkey = false)
446 echo "<td>$label</td>\n";
448 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
449 $show_inactive, $editkey);
454 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
455 $submit_on_change=false, $show_inactive=false, $editkey = false)
457 echo "<tr><td>$label</td><td nowrap>";
458 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
459 $show_inactive, $editkey);
460 echo "</td>\n</tr>\n";
464 //------------------------------------------------------------------------------------------------
466 function customer_branches_list($customer_id, $name, $selected_id=null,
467 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
471 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
472 WHERE debtor_no='" . $customer_id . "' ";
475 set_editor('branch', $name, $editkey);
477 $where = $enabled ? array("disable_trans = 0") : array();
478 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
481 'order' => array('branch_ref'),
482 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
483 'spec_id' => $all_items,
484 'select_submit'=> $submit_on_change,
485 'sel_hint' => _('Select customer branch')
488 //------------------------------------------------------------------------------------------------
490 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
491 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
494 echo "<td>$label</td>\n";
496 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
497 $submit_on_change, $editkey);
502 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
503 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
506 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id,
507 $all_option, $enabled, $submit_on_change, $editkey);
512 //------------------------------------------------------------------------------------------------
514 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
518 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
520 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
522 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
523 'spec_id' => $all_items,
524 'select_submit'=> $submit_on_change
528 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
531 echo "<td>$label</td>\n";
533 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
538 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
541 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
546 //-----------------------------------------------------------------------------------------------
548 function currencies_list($name, $selected_id=null, $submit_on_change=false)
550 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
552 // default to the company currency
554 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
556 'select_submit'=> $submit_on_change,
557 'default' => get_company_currency(),
562 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
565 echo "<td>$label</td>\n";
567 $str = currencies_list($name, $selected_id, $submit_on_change);
572 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
575 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
580 //---------------------------------------------------------------------------------------------------
582 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
585 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
587 // default to the company current fiscal year
589 return combo_input($name, $selected_id, $sql, 'id', '',
592 'default' => get_company_pref('f_year'),
593 'format' => '_format_fiscalyears',
594 'select_submit'=> $submit_on_change,
599 function _format_fiscalyears($row)
601 return sql2date($row[1]) . " - " . sql2date($row[2])
602 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
605 function fiscalyears_list_cells($label, $name, $selected_id=null)
608 echo "<td>$label</td>\n";
610 $str = fiscalyears_list($name, $selected_id);
615 function fiscalyears_list_row($label, $name, $selected_id=null)
618 $str = fiscalyears_list_cells($label, $name, $selected_id);
622 //------------------------------------------------------------------------------------
624 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
625 $submit_on_change=false, $showclosed=false, $showtype=1)
627 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
630 'order' => 'reference',
631 'spec_option'=>$no_option ? $showname : false,
633 'select_submit'=> $submit_on_change,
638 $options['where'][] = "closed=0";
640 $options['where'][] = "type_=$showtype";
642 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
645 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
646 $showclosed=false, $showtype=0, $submit_on_change=false)
649 echo "<td>$label</td>\n";
651 $str = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
656 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
657 $showclosed=false, $showtype=0, $submit_on_change=false)
660 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
661 $showclosed, $showtype, $submit_on_change);
666 //---------------------------------------------------------------------------------------------------
668 function stock_items_list($name, $selected_id=null, $all_option=false,
669 $submit_on_change=false, $opts=array(), $editkey = false)
673 $sql = "SELECT stock_id, s.description, c.description, s.inactive
674 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
677 set_editor('item', $name, $editkey);
679 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
682 'format' => '_format_stock_items',
683 'spec_option' => $all_option===true ? _("All Items") : $all_option,
684 'spec_id' => $all_items,
685 'search_box' => true,
686 'search' => array("stock_id", "c.description","s.description"),
687 'search_submit' => get_company_pref('no_item_list')!=0,
689 'select_submit'=> $submit_on_change,
691 'order' => array('c.description','stock_id')
695 function _format_stock_items($row)
697 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
700 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
701 $submit_on_change=false, $all=false, $editkey = false)
704 echo "<td>$label</td>\n";
705 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
706 array('cells'=>true, 'show_inactive'=>$all), $editkey);
710 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
713 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
718 //---------------------------------------------------------------------------------------------------
720 // Select item via foreign code.
722 function sales_items_list($name, $selected_id=null, $all_option=false,
723 $submit_on_change=false, $type='', $opts=array())
727 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
730 ".TB_PREF."stock_master s,
731 ".TB_PREF."item_codes i
733 ".TB_PREF."stock_category c
734 ON i.category_id=c.category_id
735 WHERE i.stock_id=s.stock_id";
738 if ($type == 'local') { // exclude foreign codes
739 $sql .= " AND !i.is_foreign";
740 } elseif ($type == 'kits') { // sales kits
741 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
743 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
744 $sql .= " GROUP BY i.item_code";
746 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
749 'format' => '_format_stock_items',
750 'spec_option' => $all_option===true ? _("All Items") : $all_option,
751 'spec_id' => $all_items,
752 'search_box' => true,
753 'search' => array("i.item_code", "i.description"),
754 'search_submit' => get_company_pref('no_item_list')!=0,
756 'select_submit'=> $submit_on_change,
758 'order' => array('c.description','i.item_code')
762 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
765 echo "<td>$label</td>\n";
766 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
767 '', array('cells'=>true));
771 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
773 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
774 'kits', array('cells'=>false));
778 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
782 echo "<td>$label</td>\n";
784 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
785 'local', array('cells'=>false));
789 //------------------------------------------------------------------------------------
791 function stock_manufactured_items_list($name, $selected_id=null,
792 $all_option=false, $submit_on_change=false)
794 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
795 array('where'=>array("mb_flag= 'M'")));
799 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
800 $all_option=false, $submit_on_change=false)
803 echo "<td>$label</td>\n";
805 $str = stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
810 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
811 $all_option=false, $submit_on_change=false)
814 $str = stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
818 //------------------------------------------------------------------------------------
820 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
821 $all_option=false, $submit_on_change=false, $editkey = false)
823 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
824 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
828 function stock_component_items_list_cells($label, $name, $parent_stock_id,
829 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
832 echo "<td>$label</td>\n";
833 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
834 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
838 //------------------------------------------------------------------------------------
840 function stock_costable_items_list($name, $selected_id=null,
841 $all_option=false, $submit_on_change=false)
843 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
844 array('where'=>array("mb_flag!='D'")));
848 function stock_costable_items_list_cells($label, $name, $selected_id=null,
849 $all_option=false, $submit_on_change=false)
852 echo "<td>$label</td>\n";
853 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
854 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
858 //------------------------------------------------------------------------------------
859 function stock_purchasable_items_list($name, $selected_id=null,
860 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
862 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
863 array('where'=>array("mb_flag!= 'M'"),
864 'show_inactive'=>$all), $editkey);
868 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
869 $all_option=false, $submit_on_change=false, $editkey=false)
872 echo "<td>$label</td>\n";
873 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
874 array('where'=>array("mb_flag!= 'M'"),
875 'cells'=>true), $editkey);
879 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
880 $all_option=false, $submit_on_change=false, $editkey=false)
883 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
884 $all_option, $submit_on_change, $editkey);
889 //------------------------------------------------------------------------------------
891 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
897 echo "<td>$label</td>\n";
900 array_selector($name, $selected_id, $stock_types,
902 'select_submit'=> true,
903 'disabled' => !$enabled) );
907 function stock_units_list_row($label, $name, $value=null, $enabled=true)
909 $result = get_all_item_units();
912 echo "<td>$label</td>\n";
915 while($unit = db_fetch($result))
916 $units[$unit['abbr']] = $unit['name'];
918 array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
923 //------------------------------------------------------------------------------------
925 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
927 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
929 return combo_input($name, $selected_id, $sql, 'id', 'name',
931 'spec_option' => $none_option,
932 'spec_id' => ALL_NUMERIC,
933 'select_submit'=> $submit_on_change,
938 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
939 $submit_on_change=false)
942 echo "<td>$label</td>\n";
944 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
949 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
950 $submit_on_change=false)
953 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
958 //------------------------------------------------------------------------------------
960 function tax_groups_list($name, $selected_id=null,
961 $none_option=false, $submit_on_change=false)
963 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
965 return combo_input($name, $selected_id, $sql, 'id', 'name',
968 'spec_option' => $none_option,
969 'spec_id' => ALL_NUMERIC,
970 'select_submit'=> $submit_on_change,
975 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
978 echo "<td>$label</td>\n";
980 $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
985 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
988 $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
993 //------------------------------------------------------------------------------------
995 function item_tax_types_list($name, $selected_id=null)
997 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
998 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1001 function item_tax_types_list_cells($label, $name, $selected_id=null)
1004 echo "<td>$label</td>\n";
1006 item_tax_types_list($name, $selected_id);
1010 function item_tax_types_list_row($label, $name, $selected_id=null)
1013 item_tax_types_list_cells($label, $name, $selected_id);
1017 //------------------------------------------------------------------------------------
1019 function shippers_list($name, $selected_id=null)
1021 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1022 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1023 array('order'=>array('shipper_name')));
1026 function shippers_list_cells($label, $name, $selected_id=null)
1029 echo "<td>$label</td>\n";
1031 shippers_list($name, $selected_id);
1035 function shippers_list_row($label, $name, $selected_id=null)
1038 shippers_list_cells($label, $name, $selected_id);
1042 //-------------------------------------------------------------------------------------
1044 function sales_persons_list($name, $selected_id=null)
1046 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1047 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1048 array('order'=>array('salesman_name')));
1051 function sales_persons_list_cells($label, $name, $selected_id=null)
1054 echo "<td>$label</td>\n";
1056 sales_persons_list($name, $selected_id);
1060 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1063 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1067 //------------------------------------------------------------------------------------
1069 function sales_areas_list($name, $selected_id=null)
1071 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1072 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1075 function sales_areas_list_cells($label, $name, $selected_id=null)
1078 echo "<td>$label</td>\n";
1080 sales_areas_list($name, $selected_id);
1084 function sales_areas_list_row($label, $name, $selected_id=null)
1087 sales_areas_list_cells($label, $name, $selected_id);
1091 //------------------------------------------------------------------------------------
1093 function sales_groups_list($name, $selected_id=null, $special_option=false)
1095 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1096 combo_input($name, $selected_id, $sql, 'id', 'description', array(
1097 'spec_option' => $special_option===true ? ' ' : $special_option,
1098 'order' => 'description', 'spec_id' => 0,
1102 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1105 echo "<td>$label</td>\n";
1107 sales_groups_list($name, $selected_id, $special_option);
1111 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1114 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1118 //------------------------------------------------------------------------------------
1120 function _format_template_items($row)
1122 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1125 function templates_list($name, $selected_id=null, $special_option=false)
1127 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1128 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1129 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1130 combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1131 'format' => '_format_template_items',
1132 'spec_option' => $special_option===true ? ' ' : $special_option,
1133 'order' => 'order_no', 'spec_id' => 0,
1137 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1140 echo "<td>$label</td>\n";
1142 templates_list($name, $selected_id, $special_option);
1146 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1149 templates_list_cells($label, $name, $selected_id, $special_option);
1153 //------------------------------------------------------------------------------------
1155 function workorders_list($name, $selected_id=null)
1157 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1158 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1161 function workorders_list_cells($label, $name, $selected_id=null)
1164 echo "<td>$label</td>\n";
1166 workorders_list($name, $selected_id);
1170 function workorders_list_row($label, $name, $selected_id=null)
1173 workorders_list_cells($label, $name, $selected_id);
1177 //------------------------------------------------------------------------------------
1179 function payment_terms_list($name, $selected_id=null)
1181 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1182 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1185 function payment_terms_list_cells($label, $name, $selected_id=null)
1188 echo "<td>$label</td>\n";
1190 payment_terms_list($name, $selected_id);
1194 function payment_terms_list_row($label, $name, $selected_id=null)
1197 payment_terms_list_cells($label, $name, $selected_id);
1201 //------------------------------------------------------------------------------------
1203 function credit_status_list($name, $selected_id=null)
1205 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1206 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1209 function credit_status_list_cells($label, $name, $selected_id=null)
1212 echo "<td>$label</td>\n";
1214 credit_status_list($name, $selected_id);
1218 function credit_status_list_row($label, $name, $selected_id=null)
1221 credit_status_list_cells($label, $name, $selected_id);
1225 //-----------------------------------------------------------------------------------------------
1227 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1229 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1231 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1233 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1235 'select_submit'=> $submit_on_change,
1236 // 'async' => false,
1240 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1243 echo "<td>$label</td>\n";
1245 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1250 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1253 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1258 //-----------------------------------------------------------------------------------------------
1260 function movement_types_list($name, $selected_id=null)
1262 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1263 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1266 function movement_types_list_cells($label, $name, $selected_id=null)
1269 echo "<td>$label</td>\n";
1271 movement_types_list($name, $selected_id);
1275 function movement_types_list_row($label, $name, $selected_id=null)
1278 movement_types_list_cells($label, $name, $selected_id);
1282 //-----------------------------------------------------------------------------------------------
1283 function _format_date($row)
1285 return sql2date($row['reconciled']);
1288 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1290 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1291 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1292 GROUP BY reconciled";
1293 combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1295 'spec_option' => $special_option,
1296 'format' => '_format_date',
1298 'select_submit'=> $submit_on_change
1302 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1305 echo "<td>$label</td>\n";
1307 bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1311 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1314 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1318 //-----------------------------------------------------------------------------------------------
1320 function workcenter_list($name, $selected_id=null, $all_option=false)
1324 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1326 return combo_input($name, $selected_id, $sql, 'id', 'name',
1328 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1329 'spec_id' => $all_items,
1333 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1335 default_focus($name);
1337 echo "<td>$label</td>\n";
1339 workcenter_list($name, $selected_id, $all_option);
1343 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1346 workcenter_list_cells($label, $name, $selected_id, $all_option);
1350 //-----------------------------------------------------------------------------------------------
1352 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1354 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1355 FROM ".TB_PREF."bank_accounts";
1356 // , ".TB_PREF."chart_master
1357 // WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1359 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1361 'format' => '_format_add_curr',
1362 'select_submit'=> $submit_on_change,
1367 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1370 echo "<td>$label</td>\n";
1372 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1377 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1380 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1384 //-----------------------------------------------------------------------------------------------
1386 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1388 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1389 FROM ".TB_PREF."bank_accounts
1390 WHERE ".TB_PREF."bank_accounts.account_type=3";
1393 echo "<tr><td>$label</td>\n";
1395 $str = combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1397 'format' => '_format_add_curr',
1398 'select_submit'=> $submit_on_change,
1401 echo "</td></tr>\n";
1404 //-----------------------------------------------------------------------------------------------
1406 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1408 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1410 default_focus($name);
1413 echo "<td>$label</td>\n";
1416 $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1418 'select_submit'=> $submit_on_change,
1420 'spec_option' =>$spec_option,
1422 'order'=> array('pos_name')
1424 echo "</td></tr>\n";
1428 //-----------------------------------------------------------------------------------------------
1430 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1433 echo "<td>$label</td>\n";
1435 $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1439 //-----------------------------------------------------------------------------------------------
1441 function class_list($name, $selected_id=null, $submit_on_change=false)
1443 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1445 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1447 'select_submit'=> $submit_on_change,
1453 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1456 echo "<td>$label</td>\n";
1458 $str = class_list($name, $selected_id, $submit_on_change);
1463 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1466 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1471 //-----------------------------------------------------------------------------------------------
1473 function stock_categories_list($name, $selected_id=null, $submit_on_change=false)
1475 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1476 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1477 array('order'=>'category_id',
1478 'select_submit'=> $submit_on_change,
1483 function stock_categories_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1486 echo "<td>$label</td>\n";
1488 stock_categories_list($name, $selected_id, $submit_on_change);
1492 function stock_categories_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1495 stock_categories_list_cells($label, $name, $selected_id, $submit_on_change);
1499 //-----------------------------------------------------------------------------------------------
1501 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1505 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1507 combo_input($name, $selected_id, $sql, 'id', 'name',
1510 'spec_option' =>$all_option,
1511 'spec_id' => $all_option_numeric ? 0 : $all_items
1515 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1516 $all_option_numeric=false)
1519 echo "<td>$label</td>\n";
1521 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1525 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1526 $all_option_numeric=false)
1529 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1530 $all_option_numeric);
1534 //-----------------------------------------------------------------------------------------------
1535 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1536 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1538 if ($skip_bank_accounts)
1539 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1540 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1541 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1542 ."ON chart.account_code=acc.account_code
1543 WHERE acc.account_code IS NULL
1544 AND chart.account_type=type.id";
1546 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1547 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1548 WHERE chart.account_type=type.id";
1550 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1552 'format' => '_format_account',
1553 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1555 'order' => array('type.id','account_code'),
1556 'search_box' => $cells,
1557 'search_submit' => false,
1561 'select_submit'=> $submit_on_change,
1564 'show_inactive' => $all
1569 function _format_account($row)
1571 return $row[0] . " " . $row[1];
1574 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1575 $skip_bank_accounts=false, $cells=false, $all_option=false,
1576 $submit_on_change=false, $all=false)
1579 echo "<td>$label</td>\n";
1581 gl_all_accounts_list($name, $selected_id,
1582 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1586 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1587 $skip_bank_accounts=false, $cells=false, $all_option=false)
1590 gl_all_accounts_list_cells($label, $name, $selected_id,
1591 $skip_bank_accounts, $cells, $all_option);
1595 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1598 $items['0'] = strlen($name_no) ? $name_no : _("No");
1599 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1601 return array_selector($name, $selected_id, $items,
1603 'select_submit'=> $submit_on_change,
1604 'async' => false ) ); // FIX?
1607 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1610 echo "<td>$label</td>\n";
1612 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1617 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1620 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1625 //------------------------------------------------------------------------------------------------
1627 function languages_list($name, $selected_id=null)
1629 global $installed_languages;
1632 foreach ($installed_languages as $lang)
1633 $items[$lang['code']] = $lang['name'];
1635 return array_selector($name, $selected_id, $items );
1638 function languages_list_cells($label, $name, $selected_id=null)
1641 echo "<td>$label</td>\n";
1643 languages_list($name, $selected_id);
1647 function languages_list_row($label, $name, $selected_id=null)
1650 languages_list_cells($label, $name, $selected_id);
1654 //------------------------------------------------------------------------------------------------
1656 function bank_account_types_list($name, $selected_id=null)
1658 global $bank_account_types;
1660 return array_selector($name, $selected_id, $bank_account_types);
1663 function bank_account_types_list_cells($label, $name, $selected_id=null)
1666 echo "<td>$label</td>\n";
1668 bank_account_types_list($name, $selected_id);
1672 function bank_account_types_list_row($label, $name, $selected_id=null)
1675 bank_account_types_list_cells($label, $name, $selected_id);
1679 //------------------------------------------------------------------------------------------------
1680 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1682 global $payment_person_types;
1685 foreach ($payment_person_types as $key=>$type)
1687 if ($key != PT_WORKORDER)
1688 $items[$key] = $type;
1690 return array_selector($name, $selected_id, $items,
1691 array( 'select_submit'=> $submit_on_change ) );
1694 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1697 echo "<td>$label</td>\n";
1699 $str = payment_person_types_list($name, $selected_id, $related);
1704 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1707 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1712 //------------------------------------------------------------------------------------------------
1714 function wo_types_list($name, $selected_id=null)
1716 global $wo_types_array;
1718 return array_selector($name, $selected_id, $wo_types_array,
1719 array( 'select_submit'=> true, 'async' => true ) );
1722 function wo_types_list_row($label, $name, $selected_id=null)
1724 echo "<tr><td>$label</td><td>\n";
1725 $str = wo_types_list($name, $selected_id);
1726 echo "</td></tr>\n";
1730 //------------------------------------------------------------------------------------------------
1732 function dateformats_list_row($label, $name, $value=null)
1734 global $dateformats;
1736 echo "<tr><td>$label</td>\n<td>";
1737 array_selector( $name, $value, $dateformats );
1738 echo "</td></tr>\n";
1741 function dateseps_list_row($label, $name, $value=null)
1745 echo "<tr><td>$label</td>\n<td>";
1746 array_selector( $name, $value, $dateseps );
1747 echo "</td></tr>\n";
1750 function thoseps_list_row($label, $name, $value=null)
1754 echo "<tr><td>$label</td>\n<td>";
1755 array_selector( $name, $value, $thoseps );
1756 echo "</td></tr>\n";
1759 function decseps_list_row($label, $name, $value=null)
1763 echo "<tr><td>$label</td>\n<td>";
1764 array_selector( $name, $value, $decseps );
1765 echo "</td></tr>\n";
1768 function themes_list_row($label, $name, $value=null)
1770 global $path_to_root;
1772 $path = $path_to_root.'/themes/';
1774 $themedir = opendir($path);
1775 while(false !== ($fname = readdir($themedir)))
1777 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1779 $themes[$fname] = $fname;
1784 echo "<tr><td>$label</td>\n<td>";
1785 array_selector( $name, $value, $themes );
1786 echo "</td></tr>\n";
1789 function pagesizes_list_row($label, $name, $value=null)
1794 foreach ($pagesizes as $pz)
1797 echo "<tr><td>$label</td>\n<td>";
1798 array_selector( $name, $value, $items );
1799 echo "</td></tr>\n";
1802 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1804 global $systypes_array;
1807 echo "<td>$label</td>\n";
1810 $str = array_selector($name, $value, $systypes_array,
1812 'select_submit'=> $submit_on_change,
1820 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1822 global $systypes_array;
1825 echo "<td>$label</td>\n";
1828 $items = $systypes_array;
1830 // exclude quotes, orders and dimensions
1831 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1832 ST_SALESQUOTE) as $excl)
1833 unset($items[$excl]);
1835 $str = array_selector($name, $value, $items,
1837 'spec_option'=> _("All"),
1839 'select_submit'=> $submit_on_change,
1847 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1850 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1855 function cust_allocations_list_cells($label, $name, $selected=null)
1863 $all_items=>_("All Types"),
1864 '1'=> _("Sales Invoices"),
1865 '2'=> _("Overdue Invoices"),
1866 '3' => _("Payments"),
1867 '4' => _("Credit Notes"),
1868 '5' => _("Delivery Notes")
1870 $str = array_selector($name, $selected, $allocs);
1875 function supp_allocations_list_cell($name, $selected=null)
1881 $all_items=>_("All Types"),
1882 '1'=> _("Invoices"),
1883 '2'=> _("Overdue Invoices"),
1884 '3' => _("Payments"),
1885 '4' => _("Credit Notes"),
1886 '5' => _("Overdue Credit Notes")
1888 $str = array_selector($name, $selected, $allocs);
1893 function policy_list_cells($label, $name, $selected=null)
1898 $str = array_selector($name, $selected,
1899 array( '' => _("Automatically put balance on back order"),
1900 'CAN' => _("Cancel any quantites not delivered")) );
1905 function policy_list_row($label, $name, $selected=null)
1908 policy_list_cells($label, $name, $selected);
1912 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1917 $str = array_selector($name, $selected,
1918 array( 'Return' => _("Items Returned to Inventory Location"),
1919 'WriteOff' => _("Items Written Off")),
1920 array( 'select_submit'=> $submit_on_change ) );
1925 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1928 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1933 function number_list($name, $selected, $from, $to, $no_option=false)
1936 for ($i = $from; $i <= $to; $i++)
1939 return array_selector($name, $selected, $items,
1940 array( 'spec_option' => $no_option,
1941 'spec_id' => ALL_NUMERIC) );
1944 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1949 number_list($name, $selected, $from, $to, $no_option);
1953 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1956 number_list_cells($label, $name, $selected, $from, $to, $no_option);
1960 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1961 $submit_on_change=true)
1963 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1964 ." GROUP BY profile";
1965 $result = db_query($sql, 'cannot get all profile names');
1966 $profiles = array();
1967 while($myrow=db_fetch($result)) {
1968 $profiles[$myrow['profile']] = $myrow['profile'];
1973 echo "<td>$label</td>\n";
1976 array_selector($name, $selected_id, $profiles,
1977 array( 'select_submit'=> $submit_on_change,
1978 'spec_option'=>$spec_opt,
1982 echo "</td></tr>\n";
1985 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1987 static $printers; // query only once for page display
1990 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
1991 $result = db_query($sql, 'cannot get all printers');
1992 $printers = array();
1993 while($myrow=db_fetch($result)) {
1994 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
1997 array_selector($name, $selected_id, $printers,
1998 array( 'select_submit'=> $submit_on_change,
1999 'spec_option'=>$spec_opt,
2004 //------------------------------------------------------------------------------------------------
2006 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2009 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2011 $sql .= " WHERE type=$type";
2013 combo_input($name, $selected_id, $sql, 'id', 'description',
2016 'order' => 'description',
2017 'select_submit'=> $submit_on_change,
2023 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2025 echo "<td>$label</td><td>\n";
2026 quick_entries_list($name, $selected_id, $type, $submit_on_change);
2030 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2033 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2038 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2040 global $quick_actions;
2042 echo "<tr><td>$label</td><td>";
2043 array_selector($name, $selected_id, $quick_actions,
2045 'select_submit'=> $submit_on_change
2047 echo "</td></tr>\n";
2050 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2052 global $quick_entry_types;
2054 echo "<tr><td>$label</td><td>";
2055 array_selector($name, $selected_id, $quick_entry_types,
2057 'select_submit'=> $submit_on_change
2059 echo "</td></tr>\n";
2062 function record_status_list_row($label, $name) {
2063 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2066 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2068 global $class_types;
2070 echo "<tr><td>$label</td><td>";
2071 array_selector($name, $selected_id, $class_types,
2073 'select_submit'=> $submit_on_change
2075 echo "</td></tr>\n";
2078 //------------------------------------------------------------------------------------------------
2080 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2081 $show_inactive = false)
2085 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2087 return combo_input($name, $selected_id, $sql, 'id', 'description',
2089 'spec_option'=>$new_item ? _("New role") : false,
2091 'select_submit'=> $submit_on_change,
2092 'show_inactive' => $show_inactive
2096 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2097 $show_inactive = false)
2100 echo "<td>$label</td>\n";
2102 $str = security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2107 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2108 $show_inactive = false)
2111 $str = security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2116 function tab_list_row($label, $name, $selected_id=null)
2120 echo "<td>$label</td><td>\n";
2124 array_selector($name, $selected_id, $tabs);
2126 echo "</td></tr>\n";
2129 //---------------------------------------------------------------------------------------------
2130 // List of sets of active extensions
2132 function extset_list($name, $value=null, $submit_on_change=false)
2134 global $db_connections;
2137 foreach ($db_connections as $comp)
2138 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2139 array_selector( $name, $value, $items,
2141 'spec_option'=> _("Installed on system"),
2143 'select_submit'=> $submit_on_change,