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/reserved.inc");
14 include_once($path_to_root . "/includes/types.inc");
15 include_once($path_to_root . "/includes/current_user.inc");
17 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
18 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
20 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
21 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
23 $all_items = reserved_words::get_all();
25 //----------------------------------------------------------------------------
26 // Universal sql combo generator
27 // $sql must return selector values and selector texts in columns 0 & 1
28 // Options are merged with defaults.
30 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
35 $opts = array( // default options
36 'where'=> array(), // additional constraints
37 'order' => $namefield, // list sort order
38 // special option parameters
39 'spec_option'=>false, // option text or false
40 'spec_id' => 0, // option id
41 // submit on select parameters
42 'default' => '', // default value when $_POST is not set
43 'select_submit' => false, //submit on select: true/false
44 'async' => true, // select update via ajax (true) vs _page_body reload
45 // search box parameters
47 'search_box' => false, // name or true/false
48 'type' => 0, // type of extended selector:
49 // 0 - with (optional) visible search box, search by id
50 // 1 - with hidden search box, search by option text
51 // 2 - TODO reverse: box with hidden selector available via enter; this
52 // would be convenient for optional ad hoc adding of new item
53 'search_submit' => true, //search submit button: true/false
54 'size' => 8, // size and max of box tag
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 $disabled name='$name' class='$class' title='"
212 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
214 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
216 // because of bug which M$ cannot fix since IE 5.0
217 // we must embed whole selector in span tags to enable proper ajax update
218 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
220 if ($select_submit != false) { // if submit on change is used - add select button
221 global $_select_button;
222 // button class selects form reload/ajax selector update
223 $selector .= sprintf($_select_button, $disabled, user_theme(),
224 (fallback_mode() ? '' : 'display:none;'),
225 '_'.$name.'_update')."\n";
227 // ------ make combo ----------
230 if ($search_box != false) {
231 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
232 $opts['size']."' maxlength='".$opts['max'].
233 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
234 .$opts['box_hint']."'"
235 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
237 if ($search_submit != false) {
238 global $_search_button;
239 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
240 (fallback_mode() ? '' : 'display:none;'),
241 $search_submit)."\n";
244 default_focus(($search_box && $by_id) ? $search_box : $name);
246 if ($search_box && $opts['cells'])
247 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
249 echo $edit_entry.$selector;
256 Returns true if selector $name is subject to update.
258 function list_updated($name)
260 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
262 //----------------------------------------------------------------------------------------------
263 // Universal array combo generator
264 // $items is array of options 'value' => 'description'
265 // Options is reduced set of combo_selector options and is merged with defaults.
267 function array_selector($name, $selected_id, $items, $options=null)
271 $opts = array( // default options
272 'spec_option'=>false, // option text or false
273 'spec_id' => 0, // option id
274 'select_submit' => false, //submit on select: true/false
275 'async' => true, // select update via ajax (true) vs _page_body reload
276 'default' => '', // default value when $_POST is not set
277 // search box parameters
281 // ------ merge options with defaults ----------
283 $opts = array_merge($opts, $options);
284 $select_submit = $opts['select_submit'];
285 $spec_id = $opts['spec_id'];
286 $spec_option = $opts['spec_option'];
287 $disabled = $opts['disabled'] ? "disabled" : '';
289 if ($selected_id == null) {
290 $selected_id = get_post($name, $opts['default']);
293 if (isset($_POST[ '_'.$name.'_update'])) {
295 $Ajax->activate('_page_body');
297 $Ajax->activate($name);
300 // ------ make selector ----------
301 $selector = $first_opt = '';
304 //if($name=='SelectStockFromList') display_error($sql);
305 foreach($items as $value=>$descr) {
307 if ((string)$selected_id === (string)$value) {
311 if ($first_id === false) {
315 $selector .= "<option $sel value='$value'>$descr</option>\n";
318 // Prepend special option.
319 if ($spec_option !== false) { // if special option used - add it
320 $first_id = $spec_id;
321 $first_opt = $spec_option;
322 $sel = $found===false ? 'selected' : '';
323 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
327 if ($found === false) {
328 $selected_id = $first_id;
330 $_POST[$name] = $selected_id;
332 $selector = "<select $disabled name='$name' class='combo' title='"
333 . $opts['sel_hint']."'>".$selector."</select>\n";
335 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
337 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
339 if ($select_submit != false) { // if submit on change is used - add select button
340 global $_select_button;
341 $selector .= sprintf($_select_button, $disabled, user_theme(),
342 (fallback_mode() ? '' : 'display:none;'),
343 '_'.$name.'_update')."\n";
345 default_focus($name);
350 //----------------------------------------------------------------------------------------------
352 function _format_add_curr($row)
354 static $company_currency;
356 if ($company_currency == null)
358 $company_currency = get_company_currency();
360 return $row[1] . ($row[2] == $company_currency ?
361 '' : (" - " . $row[2]));
364 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
365 $all=false, $editkey = false)
369 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
371 $mode = get_company_pref('no_supplier_list');
374 set_editor('supplier', $name, $editkey);
376 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
378 'format' => '_format_add_curr',
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 'search_box' => $mode!=0,
431 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
432 'spec_id' => $all_items,
433 'select_submit'=> $submit_on_change,
435 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
436 _('Select customer'),
437 'show_inactive' => $show_inactive
441 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
442 $submit_on_change=false, $show_inactive=false, $editkey = false)
445 echo "<td>$label</td>\n";
447 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
448 $show_inactive, $editkey);
453 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
454 $submit_on_change=false, $show_inactive=false, $editkey = false)
456 echo "<tr><td>$label</td><td nowrap>";
457 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
458 $show_inactive, $editkey);
459 echo "</td>\n</tr>\n";
463 //------------------------------------------------------------------------------------------------
465 function customer_branches_list($customer_id, $name, $selected_id=null,
466 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
470 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
471 WHERE debtor_no='" . $customer_id . "' ";
474 set_editor('branch', $name, $editkey);
476 $where = $enabled ? array("disable_trans = 0") : array();
477 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
480 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
481 'spec_id' => $all_items,
482 'select_submit'=> $submit_on_change,
483 'sel_hint' => _('Select customer branch')
486 //------------------------------------------------------------------------------------------------
488 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
489 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
492 echo "<td>$label</td>\n";
494 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
495 $submit_on_change, $editkey);
500 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
501 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
504 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id,
505 $all_option, $enabled, $submit_on_change, $editkey);
510 //------------------------------------------------------------------------------------------------
512 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
516 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
518 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
520 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
521 'spec_id' => $all_items,
522 'select_submit'=> $submit_on_change
526 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
529 echo "<td>$label</td>\n";
531 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
536 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
539 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
544 //-----------------------------------------------------------------------------------------------
546 function currencies_list($name, $selected_id=null, $submit_on_change=false)
548 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
550 // default to the company currency
552 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
554 'select_submit'=> $submit_on_change,
555 'default' => get_company_currency(),
560 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
563 echo "<td>$label</td>\n";
565 $str = currencies_list($name, $selected_id, $submit_on_change);
570 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
573 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
578 //---------------------------------------------------------------------------------------------------
580 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
583 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
585 // default to the company current fiscal year
587 return combo_input($name, $selected_id, $sql, 'id', '',
590 'default' => get_company_pref('f_year'),
591 'format' => '_format_fiscalyears',
592 'select_submit'=> $submit_on_change,
597 function _format_fiscalyears($row)
599 return sql2date($row[1]) . " - " . sql2date($row[2])
600 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
603 function fiscalyears_list_cells($label, $name, $selected_id=null)
606 echo "<td>$label</td>\n";
608 $str = fiscalyears_list($name, $selected_id);
613 function fiscalyears_list_row($label, $name, $selected_id=null)
616 $str = fiscalyears_list_cells($label, $name, $selected_id);
620 //------------------------------------------------------------------------------------
622 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
623 $submit_on_change=false, $showclosed=false, $showtype=1)
625 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
628 'order' => 'reference',
629 'spec_option'=>$no_option ? $showname : false,
631 'select_submit'=> $submit_on_change,
636 $options['where'][] = "closed=0";
638 $options['where'][] = "type_=$showtype";
640 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
643 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
644 $showclosed=false, $showtype=0, $submit_on_change=false)
647 echo "<td>$label</td>\n";
649 $str = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
654 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
655 $showclosed=false, $showtype=0, $submit_on_change=false)
658 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
659 $showclosed, $showtype, $submit_on_change);
664 //---------------------------------------------------------------------------------------------------
666 function stock_items_list($name, $selected_id=null, $all_option=false,
667 $submit_on_change=false, $opts=array(), $editkey = false)
671 $sql = "SELECT stock_id, s.description, c.description, s.inactive
672 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
675 set_editor('item', $name, $editkey);
677 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
680 'format' => '_format_stock_items',
681 'spec_option' => $all_option===true ? _("All Items") : $all_option,
682 'spec_id' => $all_items,
683 'search_box' => true,
684 'search' => array("stock_id", "c.description","s.description"),
685 'search_submit' => get_company_pref('no_item_list')!=0,
687 'select_submit'=> $submit_on_change,
689 'order' => array('c.description','stock_id')
693 function _format_stock_items($row)
695 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
698 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
699 $submit_on_change=false, $all=false, $editkey = false)
702 echo "<td>$label</td>\n";
703 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
704 array('cells'=>true, 'show_inactive'=>$all), $editkey);
708 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
711 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
716 //---------------------------------------------------------------------------------------------------
718 // Select item via foreign code.
720 function sales_items_list($name, $selected_id=null, $all_option=false,
721 $submit_on_change=false, $type='', $opts=array())
725 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
728 ".TB_PREF."stock_master s,
729 ".TB_PREF."item_codes i
731 ".TB_PREF."stock_category c
732 ON i.category_id=c.category_id
733 WHERE i.stock_id=s.stock_id";
736 if ($type == 'local') { // exclude foreign codes
737 $sql .= " AND !i.is_foreign";
738 } elseif ($type == 'kits') { // sales kits
739 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
741 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
742 $sql .= " GROUP BY i.item_code";
744 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
747 'format' => '_format_stock_items',
748 'spec_option' => $all_option===true ? _("All Items") : $all_option,
749 'spec_id' => $all_items,
750 'search_box' => true,
751 'search' => array("i.item_code", "i.description"),
752 'search_submit' => get_company_pref('no_item_list')!=0,
754 'select_submit'=> $submit_on_change,
756 'order' => array('c.description','i.item_code')
760 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
763 echo "<td>$label</td>\n";
764 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
765 '', array('cells'=>true));
769 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
771 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
772 'kits', array('cells'=>false));
776 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
780 echo "<td>$label</td>\n";
782 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
783 'local', array('cells'=>false));
787 //------------------------------------------------------------------------------------
789 function stock_manufactured_items_list($name, $selected_id=null,
790 $all_option=false, $submit_on_change=false)
792 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
793 array('where'=>array("mb_flag= 'M'")));
797 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
798 $all_option=false, $submit_on_change=false)
801 echo "<td>$label</td>\n";
803 $str = stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
808 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
809 $all_option=false, $submit_on_change=false)
812 $str = stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
816 //------------------------------------------------------------------------------------
818 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
819 $all_option=false, $submit_on_change=false, $editkey = false)
821 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
822 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
826 function stock_component_items_list_cells($label, $name, $parent_stock_id,
827 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
830 echo "<td>$label</td>\n";
831 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
832 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
836 //------------------------------------------------------------------------------------
838 function stock_costable_items_list($name, $selected_id=null,
839 $all_option=false, $submit_on_change=false)
841 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
842 array('where'=>array("mb_flag!='D'")));
846 function stock_costable_items_list_cells($label, $name, $selected_id=null,
847 $all_option=false, $submit_on_change=false)
850 echo "<td>$label</td>\n";
851 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
852 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
856 //------------------------------------------------------------------------------------
857 function stock_purchasable_items_list($name, $selected_id=null,
858 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
860 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
861 array('where'=>array("mb_flag!= 'M'"),
862 'show_inactive'=>$all), $editkey);
866 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
867 $all_option=false, $submit_on_change=false, $editkey=false)
870 echo "<td>$label</td>\n";
871 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
872 array('where'=>array("mb_flag!= 'M'"),
873 'cells'=>true), $editkey);
877 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
878 $all_option=false, $submit_on_change=false, $editkey=false)
881 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
882 $all_option, $submit_on_change, $editkey);
887 //------------------------------------------------------------------------------------
889 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
895 echo "<td>$label</td>\n";
898 array_selector($name, $selected_id, $stock_types,
900 'select_submit'=> true,
901 'disabled' => !$enabled) );
905 function stock_units_list_row($label, $name, $value=null, $enabled=true)
907 $result = get_all_item_units();
910 echo "<td>$label</td>\n";
913 while($unit = db_fetch($result))
914 $units[$unit['abbr']] = $unit['name'];
916 array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
921 //------------------------------------------------------------------------------------
923 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
925 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
927 return combo_input($name, $selected_id, $sql, 'id', 'name',
929 'spec_option' => $none_option,
930 'spec_id' => reserved_words::get_all_numeric(),
931 'select_submit'=> $submit_on_change,
936 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
937 $submit_on_change=false)
940 echo "<td>$label</td>\n";
942 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
947 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
948 $submit_on_change=false)
951 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
956 //------------------------------------------------------------------------------------
958 function tax_groups_list($name, $selected_id=null,
959 $none_option=false, $submit_on_change=false)
961 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
963 return combo_input($name, $selected_id, $sql, 'id', 'name',
966 'spec_option' => $none_option,
967 'spec_id' => reserved_words::get_all_numeric(),
968 'select_submit'=> $submit_on_change,
973 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
976 echo "<td>$label</td>\n";
978 $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
983 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
986 $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
991 //------------------------------------------------------------------------------------
993 function item_tax_types_list($name, $selected_id=null)
995 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
996 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
999 function item_tax_types_list_cells($label, $name, $selected_id=null)
1002 echo "<td>$label</td>\n";
1004 item_tax_types_list($name, $selected_id);
1008 function item_tax_types_list_row($label, $name, $selected_id=null)
1011 item_tax_types_list_cells($label, $name, $selected_id);
1015 //------------------------------------------------------------------------------------
1017 function shippers_list($name, $selected_id=null)
1019 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1020 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
1023 function shippers_list_cells($label, $name, $selected_id=null)
1026 echo "<td>$label</td>\n";
1028 shippers_list($name, $selected_id);
1032 function shippers_list_row($label, $name, $selected_id=null)
1035 shippers_list_cells($label, $name, $selected_id);
1039 //-------------------------------------------------------------------------------------
1041 function sales_persons_list($name, $selected_id=null)
1043 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1044 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
1047 function sales_persons_list_cells($label, $name, $selected_id=null)
1050 echo "<td>$label</td>\n";
1052 sales_persons_list($name, $selected_id);
1056 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1059 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1063 //------------------------------------------------------------------------------------
1065 function sales_areas_list($name, $selected_id=null)
1067 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1068 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1071 function sales_areas_list_cells($label, $name, $selected_id=null)
1074 echo "<td>$label</td>\n";
1076 sales_areas_list($name, $selected_id);
1080 function sales_areas_list_row($label, $name, $selected_id=null)
1083 sales_areas_list_cells($label, $name, $selected_id);
1087 //------------------------------------------------------------------------------------
1089 function sales_groups_list($name, $selected_id=null, $special_option=false)
1091 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1092 combo_input($name, $selected_id, $sql, 'id', 'description', array(
1093 'spec_option' => $special_option===true ? ' ' : $special_option,
1094 'order' => 'description', 'spec_id' => 0,
1098 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1101 echo "<td>$label</td>\n";
1103 sales_groups_list($name, $selected_id, $special_option);
1107 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1110 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1114 //------------------------------------------------------------------------------------
1116 function _format_template_items($row)
1118 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1121 function templates_list($name, $selected_id=null, $special_option=false)
1123 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1124 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1125 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1126 combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1127 'format' => '_format_template_items',
1128 'spec_option' => $special_option===true ? ' ' : $special_option,
1129 'order' => 'order_no', 'spec_id' => 0,
1133 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1136 echo "<td>$label</td>\n";
1138 templates_list($name, $selected_id, $special_option);
1142 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1145 templates_list_cells($label, $name, $selected_id, $special_option);
1149 //------------------------------------------------------------------------------------
1151 function workorders_list($name, $selected_id=null)
1153 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1154 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1157 function workorders_list_cells($label, $name, $selected_id=null)
1160 echo "<td>$label</td>\n";
1162 workorders_list($name, $selected_id);
1166 function workorders_list_row($label, $name, $selected_id=null)
1169 workorders_list_cells($label, $name, $selected_id);
1173 //------------------------------------------------------------------------------------
1175 function payment_terms_list($name, $selected_id=null)
1177 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1178 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1181 function payment_terms_list_cells($label, $name, $selected_id=null)
1184 echo "<td>$label</td>\n";
1186 payment_terms_list($name, $selected_id);
1190 function payment_terms_list_row($label, $name, $selected_id=null)
1193 payment_terms_list_cells($label, $name, $selected_id);
1197 //------------------------------------------------------------------------------------
1199 function credit_status_list($name, $selected_id=null)
1201 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1202 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1205 function credit_status_list_cells($label, $name, $selected_id=null)
1208 echo "<td>$label</td>\n";
1210 credit_status_list($name, $selected_id);
1214 function credit_status_list_row($label, $name, $selected_id=null)
1217 credit_status_list_cells($label, $name, $selected_id);
1221 //-----------------------------------------------------------------------------------------------
1223 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1225 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1227 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1229 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1231 'select_submit'=> $submit_on_change,
1232 // 'async' => false,
1236 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1239 echo "<td>$label</td>\n";
1241 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1246 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1249 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1254 //-----------------------------------------------------------------------------------------------
1256 function movement_types_list($name, $selected_id=null)
1258 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1259 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1262 function movement_types_list_cells($label, $name, $selected_id=null)
1265 echo "<td>$label</td>\n";
1267 movement_types_list($name, $selected_id);
1271 function movement_types_list_row($label, $name, $selected_id=null)
1274 movement_types_list_cells($label, $name, $selected_id);
1278 //-----------------------------------------------------------------------------------------------
1279 function _format_date($row)
1281 return sql2date($row['reconciled']);
1284 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1286 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1287 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1288 GROUP BY reconciled";
1289 combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1291 'spec_option' => $special_option,
1292 'format' => '_format_date',
1294 'select_submit'=> $submit_on_change
1298 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1301 echo "<td>$label</td>\n";
1303 bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1307 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1310 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1314 //-----------------------------------------------------------------------------------------------
1316 function workcenter_list($name, $selected_id=null, $all_option=false)
1320 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1322 return combo_input($name, $selected_id, $sql, 'id', 'name',
1324 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1325 'spec_id' => $all_items,
1329 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1331 default_focus($name);
1333 echo "<td>$label</td>\n";
1335 workcenter_list($name, $selected_id, $all_option);
1339 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1342 workcenter_list_cells($label, $name, $selected_id, $all_option);
1346 //-----------------------------------------------------------------------------------------------
1348 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1350 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1351 FROM ".TB_PREF."bank_accounts";
1352 // , ".TB_PREF."chart_master
1353 // WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1355 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1357 'format' => '_format_add_curr',
1358 'select_submit'=> $submit_on_change,
1363 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1366 echo "<td>$label</td>\n";
1368 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1373 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1376 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1380 //-----------------------------------------------------------------------------------------------
1382 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1384 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1385 FROM ".TB_PREF."bank_accounts
1386 WHERE ".TB_PREF."bank_accounts.account_type=3";
1389 echo "<tr><td>$label</td>\n";
1391 $str = combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1393 'format' => '_format_add_curr',
1394 'select_submit'=> $submit_on_change,
1397 echo "</td></tr>\n";
1400 //-----------------------------------------------------------------------------------------------
1402 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1404 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1406 default_focus($name);
1409 echo "<td>$label</td>\n";
1412 $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1414 'select_submit'=> $submit_on_change,
1416 'spec_option' =>$spec_option,
1419 echo "</td></tr>\n";
1423 //-----------------------------------------------------------------------------------------------
1425 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1428 echo "<td>$label</td>\n";
1430 $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1434 //-----------------------------------------------------------------------------------------------
1436 function class_list($name, $selected_id=null, $submit_on_change=false)
1438 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1440 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1442 'select_submit'=> $submit_on_change,
1448 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1451 echo "<td>$label</td>\n";
1453 $str = class_list($name, $selected_id, $submit_on_change);
1458 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1461 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1466 //-----------------------------------------------------------------------------------------------
1468 function stock_categories_list($name, $selected_id=null, $submit_on_change=false)
1470 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1471 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1472 array('order'=>'category_id',
1473 'select_submit'=> $submit_on_change,
1478 function stock_categories_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1481 echo "<td>$label</td>\n";
1483 stock_categories_list($name, $selected_id, $submit_on_change);
1487 function stock_categories_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1490 stock_categories_list_cells($label, $name, $selected_id, $submit_on_change);
1494 //-----------------------------------------------------------------------------------------------
1496 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1500 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1502 combo_input($name, $selected_id, $sql, 'id', 'name',
1505 'spec_option' =>$all_option,
1506 'spec_id' => $all_option_numeric ? 0 : $all_items
1510 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1511 $all_option_numeric=false)
1514 echo "<td>$label</td>\n";
1516 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1520 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1521 $all_option_numeric=false)
1524 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1525 $all_option_numeric);
1529 //-----------------------------------------------------------------------------------------------
1530 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1531 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1533 if ($skip_bank_accounts)
1534 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1535 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1536 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1537 ."ON chart.account_code=acc.account_code
1538 WHERE acc.account_code IS NULL
1539 AND chart.account_type=type.id";
1541 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1542 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1543 WHERE chart.account_type=type.id";
1545 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1547 'format' => '_format_account',
1548 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1550 'order' => array('type.id','account_code'),
1551 'search_box' => $cells,
1552 'search_submit' => false,
1556 'select_submit'=> $submit_on_change,
1559 'show_inactive' => $all
1564 function _format_account($row)
1566 return $row[0] . " " . $row[1];
1569 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1570 $skip_bank_accounts=false, $cells=false, $all_option=false,
1571 $submit_on_change=false, $all=false)
1574 echo "<td>$label</td>\n";
1576 gl_all_accounts_list($name, $selected_id,
1577 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1581 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1582 $skip_bank_accounts=false, $cells=false, $all_option=false)
1585 gl_all_accounts_list_cells($label, $name, $selected_id,
1586 $skip_bank_accounts, $cells, $all_option);
1590 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1593 $items['0'] = strlen($name_no) ? $name_no : _("No");
1594 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1596 return array_selector($name, $selected_id, $items,
1598 'select_submit'=> $submit_on_change,
1599 'async' => false ) ); // FIX?
1602 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1605 echo "<td>$label</td>\n";
1607 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1612 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1615 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1620 //------------------------------------------------------------------------------------------------
1622 function languages_list($name, $selected_id=null)
1624 global $installed_languages;
1627 foreach ($installed_languages as $lang)
1628 $items[$lang['code']] = $lang['name'];
1630 return array_selector($name, $selected_id, $items );
1633 function languages_list_cells($label, $name, $selected_id=null)
1636 echo "<td>$label</td>\n";
1638 languages_list($name, $selected_id);
1642 function languages_list_row($label, $name, $selected_id=null)
1645 languages_list_cells($label, $name, $selected_id);
1649 //------------------------------------------------------------------------------------------------
1651 function bank_account_types_list($name, $selected_id=null)
1653 $types = bank_account_types::get_all();
1656 foreach ($types as $type)
1658 $items[$type['id']] = $type['name'];
1661 return array_selector($name, $selected_id, $items );
1664 function bank_account_types_list_cells($label, $name, $selected_id=null)
1667 echo "<td>$label</td>\n";
1669 bank_account_types_list($name, $selected_id);
1673 function bank_account_types_list_row($label, $name, $selected_id=null)
1676 bank_account_types_list_cells($label, $name, $selected_id);
1680 //------------------------------------------------------------------------------------------------
1681 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1683 $types = payment_person_types::get_all();
1686 foreach ($types as $type)
1688 if (payment_person_types::has_items($type['id']))
1690 if ($type['id'] != payment_person_types::WorkOrder())
1691 $items[$type['id']] = $type['name'];
1695 return array_selector($name, $selected_id, $items,
1696 array( 'select_submit'=> $submit_on_change ) );
1699 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1702 echo "<td>$label</td>\n";
1704 $str = payment_person_types_list($name, $selected_id, $related);
1709 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1712 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1717 //------------------------------------------------------------------------------------------------
1719 function wo_types_list($name, $selected_id=null)
1721 $types = wo_types::get_all();
1724 foreach ($types as $type)
1725 $items[$type['id']] = $type['name'];
1727 return array_selector($name, $selected_id, $items,
1728 array( 'select_submit'=> true, 'async' => true ) );
1731 function wo_types_list_row($label, $name, $selected_id=null)
1733 echo "<tr><td>$label</td><td>\n";
1734 $str = wo_types_list($name, $selected_id);
1735 echo "</td></tr>\n";
1739 //------------------------------------------------------------------------------------------------
1741 function dateformats_list_row($label, $name, $value=null)
1743 global $dateformats;
1745 echo "<tr><td>$label</td>\n<td>";
1746 array_selector( $name, $value, $dateformats );
1747 echo "</td></tr>\n";
1750 function dateseps_list_row($label, $name, $value=null)
1754 echo "<tr><td>$label</td>\n<td>";
1755 array_selector( $name, $value, $dateseps );
1756 echo "</td></tr>\n";
1759 function thoseps_list_row($label, $name, $value=null)
1763 echo "<tr><td>$label</td>\n<td>";
1764 array_selector( $name, $value, $thoseps );
1765 echo "</td></tr>\n";
1768 function decseps_list_row($label, $name, $value=null)
1772 echo "<tr><td>$label</td>\n<td>";
1773 array_selector( $name, $value, $decseps );
1774 echo "</td></tr>\n";
1777 function themes_list_row($label, $name, $value=null)
1779 global $path_to_root;
1781 $path = $path_to_root.'/themes/';
1783 $themedir = opendir($path);
1784 while(false !== ($fname = readdir($themedir)))
1786 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1788 $themes[$fname] = $fname;
1793 echo "<tr><td>$label</td>\n<td>";
1794 array_selector( $name, $value, $themes );
1795 echo "</td></tr>\n";
1798 function pagesizes_list_row($label, $name, $value=null)
1803 foreach ($pagesizes as $pz)
1806 echo "<tr><td>$label</td>\n<td>";
1807 array_selector( $name, $value, $items );
1808 echo "</td></tr>\n";
1811 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1813 global $systypes_array;
1816 echo "<td>$label</td>\n";
1820 foreach ($systypes_array as $key=>$type)
1821 $items[$key] = $type['name'];
1823 $str = array_selector($name, $value, $items,
1825 'select_submit'=> $submit_on_change,
1833 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1835 global $systypes_array;
1838 echo "<td>$label</td>\n";
1842 foreach ($systypes_array as $key=>$type)
1843 // exclude orders and dimensions
1844 if (!in_array($key, array(18,26,30,40)))
1845 $items[$key] = $type['name'];
1847 $str = array_selector($name, $value, $items,
1849 'spec_option'=> _("All"),
1851 'select_submit'=> $submit_on_change,
1859 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1862 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1867 function cust_allocations_list_cells($label, $name, $selected=null)
1875 $all_items=>_("All Types"),
1876 '1'=> _("Sales Invoices"),
1877 '2'=> _("Overdue Invoices"),
1878 '3' => _("Payments"),
1879 '4' => _("Credit Notes"),
1880 '5' => _("Delivery Notes")
1882 $str = array_selector($name, $selected, $allocs);
1887 function supp_allocations_list_cell($name, $selected=null)
1893 $all_items=>_("All Types"),
1894 '1'=> _("Invoices"),
1895 '2'=> _("Overdue Invoices"),
1896 '3' => _("Payments"),
1897 '4' => _("Credit Notes"),
1898 '5' => _("Overdue Credit Notes")
1900 $str = array_selector($name, $selected, $allocs);
1905 function policy_list_cells($label, $name, $selected=null)
1910 $str = array_selector($name, $selected,
1911 array( '' => _("Automatically put balance on back order"),
1912 'CAN' => _("Cancel any quantites not delivered")) );
1917 function policy_list_row($label, $name, $selected=null)
1920 policy_list_cells($label, $name, $selected);
1924 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1929 $str = array_selector($name, $selected,
1930 array( 'Return' => _("Items Returned to Inventory Location"),
1931 'WriteOff' => _("Items Written Off")),
1932 array( 'select_submit'=> $submit_on_change ) );
1937 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1940 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1945 function number_list($name, $selected, $from, $to, $no_option=false)
1948 for ($i = $from; $i <= $to; $i++)
1951 return array_selector($name, $selected, $items,
1952 array( 'spec_option' => $no_option,
1953 'spec_id' => reserved_words::get_all_numeric()) );
1956 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1961 number_list($name, $selected, $from, $to, $no_option);
1965 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1968 number_list_cells($label, $name, $selected, $from, $to, $no_option);
1972 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1973 $submit_on_change=true)
1975 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1976 ." GROUP BY profile";
1977 $result = db_query($sql, 'cannot get all profile names');
1978 $profiles = array();
1979 while($myrow=db_fetch($result)) {
1980 $profiles[$myrow['profile']] = $myrow['profile'];
1985 echo "<td>$label</td>\n";
1988 array_selector($name, $selected_id, $profiles,
1989 array( 'select_submit'=> $submit_on_change,
1990 'spec_option'=>$spec_opt,
1994 echo "</td></tr>\n";
1997 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1999 static $printers; // query only once for page display
2002 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2003 $result = db_query($sql, 'cannot get all printers');
2004 $printers = array();
2005 while($myrow=db_fetch($result)) {
2006 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2009 array_selector($name, $selected_id, $printers,
2010 array( 'select_submit'=> $submit_on_change,
2011 'spec_option'=>$spec_opt,
2016 //------------------------------------------------------------------------------------------------
2018 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2021 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2023 $sql .= " WHERE type=$type";
2025 combo_input($name, $selected_id, $sql, 'id', 'description',
2028 'order' => 'description',
2029 'select_submit'=> $submit_on_change,
2035 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2037 echo "<td>$label</td><td>\n";
2038 quick_entries_list($name, $selected_id, $type, $submit_on_change);
2042 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2045 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2050 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2052 global $quick_actions;
2054 echo "<tr><td>$label</td><td>";
2055 array_selector($name, $selected_id, $quick_actions,
2057 'select_submit'=> $submit_on_change
2059 echo "</td></tr>\n";
2062 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2064 global $quick_entry_types;
2066 echo "<tr><td>$label</td><td>";
2067 array_selector($name, $selected_id, $quick_entry_types,
2069 'select_submit'=> $submit_on_change
2071 echo "</td></tr>\n";
2074 function record_status_list_row($label, $name) {
2075 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2078 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2080 global $class_types;
2082 echo "<tr><td>$label</td><td>";
2083 array_selector($name, $selected_id, $class_types,
2085 'select_submit'=> $submit_on_change
2087 echo "</td></tr>\n";
2090 //------------------------------------------------------------------------------------------------
2092 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2093 $show_inactive = false)
2097 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2099 return combo_input($name, $selected_id, $sql, 'id', 'description',
2101 'spec_option'=>$new_item ? _("New role") : false,
2103 'select_submit'=> $submit_on_change,
2104 'show_inactive' => $show_inactive
2108 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2109 $show_inactive = false)
2112 echo "<td>$label</td>\n";
2114 $str = security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2119 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2120 $show_inactive = false)
2123 $str = security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2128 function tab_list_row($label, $name, $selected_id=null)
2132 echo "<td>$label</td><td>\n";
2136 array_selector($name, $selected_id, $tabs);
2138 echo "</td></tr>\n";