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 'multi' => false, // multiple select
43 'select_submit' => false, //submit on select: true/false
44 'async' => true, // select update via ajax (true) vs _page_body reload
45 // search box parameters
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 'height' => false, // number of lines in select box
57 'cells' => false, // combo displayed as 2 <td></td> cells
58 'search' => array(), // sql field names to search
59 'format' => null, // format functions for regular options
61 'box_hint' => null, // box/selectors hints; null = std see below
62 'category' => false, // category column name or false
63 'show_inactive' => false // show inactive records.
65 // ------ merge options with defaults ----------
67 $opts = array_merge($opts, $options);
68 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
70 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
71 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
72 $select_submit = $opts['select_submit'];
73 $spec_id = $opts['spec_id'];
74 $spec_option = $opts['spec_option'];
75 $by_id = ($opts['type'] == 0);
76 $class = $by_id ? 'combo':'combo2';
77 $disabled = $opts['disabled'] ? "disabled" : '';
78 $multi = $opts['multi'];
80 if(!count($opts['search'])) {
81 $opts['search'] = array($by_id ? $valfield : $namefield);
83 if ($opts['sel_hint'] === null)
84 $opts['sel_hint'] = $by_id || $search_box==false ?
85 '' : _('Press Space tab for search pattern entry');
87 if ($opts['box_hint'] === null)
88 $opts['box_hint'] = $search_box && $search_submit != false ?
89 ($by_id ? _('Enter code fragment to search or * for all')
90 : _('Enter description fragment to search or * for all')) :'';
92 if ($selected_id == null) {
93 $selected_id = get_post($name, $opts['default']);
95 if(!is_array($selected_id))
96 $selected_id = array($selected_id); // code is generalized for multiple selection support
98 $txt = get_post($search_box);
102 if (isset($_POST['_'.$name.'_update'])) {
103 if ($by_id) $txt = $_POST[$name];
106 $Ajax->activate('_page_body');
108 $Ajax->activate($name);
111 // search related sql modifications
113 $rel = "rel='$search_box'"; // set relation to list
114 if ($opts['search_submit']) {
115 if (isset($_POST[$search_submit])) {
116 $selected_id = array(); // ignore selected_id while search
118 $Ajax->activate('_page_body');
120 $Ajax->activate($name);
123 if ($spec_option === false && $selected_id == array())
126 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
131 foreach($opts['search'] as $i=> $s)
132 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
133 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
138 if (count($opts['where'])) {
139 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
140 $where .= '('. implode($opts['where'], ' AND ') . ')';
141 $group_pos = strpos($sql, 'GROUP BY');
143 $group = substr($sql, $group_pos);
144 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
149 if ($opts['order'] != false) {
150 if (!is_array($opts['order']))
151 $opts['order'] = array($opts['order']);
152 $sql .= ' ORDER BY '.implode(',',$opts['order']);
156 // ------ make selector ----------
157 $selector = $first_opt = '';
161 //if($name=='stock_id') display_error($sql);
162 if($result = db_query($sql)) {
163 while ($contact_row = db_fetch($result)) {
164 $value = $contact_row[0];
165 $descr = $opts['format']==null ? $contact_row[1] :
166 call_user_func($opts['format'], $contact_row);
168 if (get_post($search_submit) && ($txt === $value)) {
169 $selected_id[] = $value;
171 if (in_array($value, $selected_id)) {
175 // show selected option even if inactive
176 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
179 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
181 if ($first_id === false) {
185 $cat = $contact_row[$opts['category']];
186 if ($opts['category'] !== false && $cat != $lastcat){
187 $selector .= "<optgroup label='".$cat."'>\n";
190 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
192 db_free_result($result);
195 // Prepend special option.
196 if ($spec_option !== false) { // if special option used - add it
197 $first_id = $spec_id;
198 $first_opt = $spec_option;
200 // if($first_id !== false) {
201 $sel = $found===false ? 'selected' : '';
202 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
203 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
207 if ($found===false) {
208 $selected_id = array($first_id);
210 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
212 if ($by_id && $search_box != false) {
214 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
216 $selector = "<select ".($multi ? "multiple" : '')
217 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
218 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
219 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
221 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
223 // because of bug which M$ cannot fix since IE 5.0
224 // we must embed whole selector in span tags to enable proper ajax update
225 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
227 if ($select_submit != false) { // if submit on change is used - add select button
228 global $_select_button;
229 // button class selects form reload/ajax selector update
230 $selector .= sprintf($_select_button, $disabled, user_theme(),
231 (fallback_mode() ? '' : 'display:none;'),
232 '_'.$name.'_update')."\n";
234 // ------ make combo ----------
237 if ($search_box != false) {
238 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
239 $opts['size']."' maxlength='".$opts['max'].
240 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
241 .$opts['box_hint']."'"
242 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
244 if ($search_submit != false) {
245 global $_search_button;
246 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
247 (fallback_mode() ? '' : 'display:none;'),
248 $search_submit)."\n";
251 default_focus(($search_box && $by_id) ? $search_box : $name);
253 if ($search_box && $opts['cells'])
254 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
256 echo $edit_entry.$selector;
262 Returns true if selector $name is subject to update.
264 function list_updated($name)
266 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
268 //----------------------------------------------------------------------------------------------
269 // Universal array combo generator
270 // $items is array of options 'value' => 'description'
271 // Options is reduced set of combo_selector options and is merged with defaults.
273 function array_selector($name, $selected_id, $items, $options=null)
277 $opts = array( // default options
278 'spec_option'=>false, // option text or false
279 'spec_id' => 0, // option id
280 'select_submit' => false, //submit on select: true/false
281 'async' => true, // select update via ajax (true) vs _page_body reload
282 'default' => '', // default value when $_POST is not set
283 'multi'=>false, // multiple select
284 // search box parameters
285 'height' => false, // number of lines in select box
289 // ------ merge options with defaults ----------
291 $opts = array_merge($opts, $options);
292 $select_submit = $opts['select_submit'];
293 $spec_id = $opts['spec_id'];
294 $spec_option = $opts['spec_option'];
295 $disabled = $opts['disabled'] ? "disabled" : '';
296 $multi = $opts['multi'];
298 if ($selected_id == null) {
299 $selected_id = get_post($name, $opts['default']);
301 if(!is_array($selected_id))
302 $selected_id = array($selected_id); // code is generalized for multiple selection support
304 if (isset($_POST[ '_'.$name.'_update'])) {
306 $Ajax->activate('_page_body');
308 $Ajax->activate($name);
311 // ------ make selector ----------
312 $selector = $first_opt = '';
315 //if($name=='SelectStockFromList') display_error($sql);
316 foreach($items as $value=>$descr) {
318 if (in_array((string)$value, $selected_id)) {
322 if ($first_id === false) {
326 $selector .= "<option $sel value='$value'>$descr</option>\n";
329 // Prepend special option.
330 if ($spec_option !== false) { // if special option used - add it
331 $first_id = $spec_id;
332 $first_opt = $spec_option;
333 $sel = $found===false ? 'selected' : '';
334 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
338 if ($found === false) {
339 $selected_id[] = $first_id;
341 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
342 $selector = "<select ".($multi ? "multiple" : '')
343 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
344 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
345 . $opts['sel_hint']."'>".$selector."</select>\n";
347 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
349 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
351 if ($select_submit != false) { // if submit on change is used - add select button
352 global $_select_button;
353 $selector .= sprintf($_select_button, $disabled, user_theme(),
354 (fallback_mode() ? '' : 'display:none;'),
355 '_'.$name.'_update')."\n";
357 default_focus($name);
362 //----------------------------------------------------------------------------------------------
364 function _format_add_curr($row)
366 static $company_currency;
368 if ($company_currency == null)
370 $company_currency = get_company_currency();
372 return $row[1] . ($row[2] == $company_currency ?
373 '' : (" - " . $row[2]));
376 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
377 $all=false, $editkey = false)
381 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
383 $mode = get_company_pref('no_supplier_list');
386 set_editor('supplier', $name, $editkey);
388 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
390 'format' => '_format_add_curr',
391 'order' => array('supp_ref'),
392 'search_box' => $mode!=0,
394 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
395 'spec_id' => $all_items,
396 'select_submit'=> $submit_on_change,
398 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
399 _('Select supplier'),
400 'show_inactive'=>$all
404 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
405 $submit_on_change=false, $all=false, $editkey = false)
408 echo "<td>$label</td><td>\n";
409 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change,
415 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
416 $submit_on_change=false, $all=false, $editkey = false)
418 echo "<tr><td>$label</td><td>";
419 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change,
424 //----------------------------------------------------------------------------------------------
426 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
427 $show_inactive=false, $editkey = false)
431 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
433 $mode = get_company_pref('no_customer_list');
436 set_editor('customer', $name, $editkey);
438 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
440 'format' => '_format_add_curr',
441 'order' => array('debtor_ref'),
442 'search_box' => $mode!=0,
445 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
446 'spec_id' => $all_items,
447 'select_submit'=> $submit_on_change,
449 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
450 _('Select customer'),
451 'show_inactive' => $show_inactive
455 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
456 $submit_on_change=false, $show_inactive=false, $editkey = false)
459 echo "<td>$label</td>\n";
461 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
462 $show_inactive, $editkey);
467 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
468 $submit_on_change=false, $show_inactive=false, $editkey = false)
470 echo "<tr><td>$label</td><td nowrap>";
471 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
472 $show_inactive, $editkey);
473 echo "</td>\n</tr>\n";
477 //------------------------------------------------------------------------------------------------
479 function customer_branches_list($customer_id, $name, $selected_id=null,
480 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
484 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
485 WHERE debtor_no='" . $customer_id . "' ";
488 set_editor('branch', $name, $editkey);
490 $where = $enabled ? array("disable_trans = 0") : array();
491 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
494 'order' => array('branch_ref'),
495 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
496 'spec_id' => $all_items,
497 'select_submit'=> $submit_on_change,
498 'sel_hint' => _('Select customer branch')
501 //------------------------------------------------------------------------------------------------
503 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
504 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
507 echo "<td>$label</td>\n";
509 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
510 $submit_on_change, $editkey);
515 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
516 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
519 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id,
520 $all_option, $enabled, $submit_on_change, $editkey);
525 //------------------------------------------------------------------------------------------------
527 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
531 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
533 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
535 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
536 'spec_id' => $all_items,
537 'select_submit'=> $submit_on_change
541 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
544 echo "<td>$label</td>\n";
546 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
551 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
554 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
559 //-----------------------------------------------------------------------------------------------
561 function currencies_list($name, $selected_id=null, $submit_on_change=false)
563 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
565 // default to the company currency
567 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
569 'select_submit'=> $submit_on_change,
570 'default' => get_company_currency(),
575 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
578 echo "<td>$label</td>\n";
580 $str = currencies_list($name, $selected_id, $submit_on_change);
585 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
588 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
593 //---------------------------------------------------------------------------------------------------
595 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
598 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
600 // default to the company current fiscal year
602 return combo_input($name, $selected_id, $sql, 'id', '',
605 'default' => get_company_pref('f_year'),
606 'format' => '_format_fiscalyears',
607 'select_submit'=> $submit_on_change,
612 function _format_fiscalyears($row)
614 return sql2date($row[1]) . " - " . sql2date($row[2])
615 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
618 function fiscalyears_list_cells($label, $name, $selected_id=null)
621 echo "<td>$label</td>\n";
623 $str = fiscalyears_list($name, $selected_id);
628 function fiscalyears_list_row($label, $name, $selected_id=null)
631 $str = fiscalyears_list_cells($label, $name, $selected_id);
635 //------------------------------------------------------------------------------------
637 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
638 $submit_on_change=false, $showclosed=false, $showtype=1)
640 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
643 'order' => 'reference',
644 'spec_option'=>$no_option ? $showname : false,
646 'select_submit'=> $submit_on_change,
651 $options['where'][] = "closed=0";
653 $options['where'][] = "type_=$showtype";
655 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
658 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
659 $showclosed=false, $showtype=0, $submit_on_change=false)
662 echo "<td>$label</td>\n";
664 $str = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
669 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
670 $showclosed=false, $showtype=0, $submit_on_change=false)
673 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
674 $showclosed, $showtype, $submit_on_change);
679 //---------------------------------------------------------------------------------------------------
681 function stock_items_list($name, $selected_id=null, $all_option=false,
682 $submit_on_change=false, $opts=array(), $editkey = false)
686 $sql = "SELECT stock_id, s.description, c.description, s.inactive
687 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
690 set_editor('item', $name, $editkey);
692 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
695 'format' => '_format_stock_items',
696 'spec_option' => $all_option===true ? _("All Items") : $all_option,
697 'spec_id' => $all_items,
698 'search_box' => true,
699 'search' => array("stock_id", "c.description","s.description"),
700 'search_submit' => get_company_pref('no_item_list')!=0,
702 'select_submit'=> $submit_on_change,
704 'order' => array('c.description','stock_id')
708 function _format_stock_items($row)
710 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
713 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
714 $submit_on_change=false, $all=false, $editkey = false)
717 echo "<td>$label</td>\n";
718 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
719 array('cells'=>true, 'show_inactive'=>$all), $editkey);
723 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
726 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
731 //---------------------------------------------------------------------------------------------------
733 // Select item via foreign code.
735 function sales_items_list($name, $selected_id=null, $all_option=false,
736 $submit_on_change=false, $type='', $opts=array())
740 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
743 ".TB_PREF."stock_master s,
744 ".TB_PREF."item_codes i
746 ".TB_PREF."stock_category c
747 ON i.category_id=c.category_id
748 WHERE i.stock_id=s.stock_id";
751 if ($type == 'local') { // exclude foreign codes
752 $sql .= " AND !i.is_foreign";
753 } elseif ($type == 'kits') { // sales kits
754 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
756 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
757 $sql .= " GROUP BY i.item_code";
759 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
762 'format' => '_format_stock_items',
763 'spec_option' => $all_option===true ? _("All Items") : $all_option,
764 'spec_id' => $all_items,
765 'search_box' => true,
766 'search' => array("i.item_code", "i.description"),
767 'search_submit' => get_company_pref('no_item_list')!=0,
769 'select_submit'=> $submit_on_change,
771 'order' => array('c.description','i.item_code')
775 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
778 echo "<td>$label</td>\n";
779 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
780 '', array('cells'=>true));
784 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
786 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
787 'kits', array('cells'=>false));
791 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
795 echo "<td>$label</td>\n";
797 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
798 'local', array('cells'=>false));
802 //------------------------------------------------------------------------------------
804 function stock_manufactured_items_list($name, $selected_id=null,
805 $all_option=false, $submit_on_change=false)
807 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
808 array('where'=>array("mb_flag= 'M'")));
812 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
813 $all_option=false, $submit_on_change=false)
816 echo "<td>$label</td>\n";
818 $str = stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
823 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
824 $all_option=false, $submit_on_change=false)
827 $str = stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
831 //------------------------------------------------------------------------------------
833 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
834 $all_option=false, $submit_on_change=false, $editkey = false)
836 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
837 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
841 function stock_component_items_list_cells($label, $name, $parent_stock_id,
842 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
845 echo "<td>$label</td>\n";
846 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
847 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
851 //------------------------------------------------------------------------------------
853 function stock_costable_items_list($name, $selected_id=null,
854 $all_option=false, $submit_on_change=false)
856 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
857 array('where'=>array("mb_flag!='D'")));
861 function stock_costable_items_list_cells($label, $name, $selected_id=null,
862 $all_option=false, $submit_on_change=false)
865 echo "<td>$label</td>\n";
866 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
867 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
871 //------------------------------------------------------------------------------------
872 function stock_purchasable_items_list($name, $selected_id=null,
873 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
875 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
876 array('where'=>array("mb_flag!= 'M'"),
877 'show_inactive'=>$all), $editkey);
881 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
882 $all_option=false, $submit_on_change=false, $editkey=false)
885 echo "<td>$label</td>\n";
886 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
887 array('where'=>array("mb_flag!= 'M'"),
888 'cells'=>true), $editkey);
892 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
893 $all_option=false, $submit_on_change=false, $editkey=false)
896 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
897 $all_option, $submit_on_change, $editkey);
902 //------------------------------------------------------------------------------------
904 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
910 echo "<td>$label</td>\n";
913 array_selector($name, $selected_id, $stock_types,
915 'select_submit'=> true,
916 'disabled' => !$enabled) );
920 function stock_units_list_row($label, $name, $value=null, $enabled=true)
922 $result = get_all_item_units();
925 echo "<td>$label</td>\n";
928 while($unit = db_fetch($result))
929 $units[$unit['abbr']] = $unit['name'];
931 array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
936 //------------------------------------------------------------------------------------
938 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
940 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
942 return combo_input($name, $selected_id, $sql, 'id', 'name',
944 'spec_option' => $none_option,
945 'spec_id' => ALL_NUMERIC,
946 'select_submit'=> $submit_on_change,
951 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
952 $submit_on_change=false)
955 echo "<td>$label</td>\n";
957 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
962 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
963 $submit_on_change=false)
966 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
971 //------------------------------------------------------------------------------------
973 function tax_groups_list($name, $selected_id=null,
974 $none_option=false, $submit_on_change=false)
976 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
978 return combo_input($name, $selected_id, $sql, 'id', 'name',
981 'spec_option' => $none_option,
982 'spec_id' => ALL_NUMERIC,
983 'select_submit'=> $submit_on_change,
988 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
991 echo "<td>$label</td>\n";
993 $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
998 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1001 $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
1006 //------------------------------------------------------------------------------------
1008 function item_tax_types_list($name, $selected_id=null)
1010 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1011 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1014 function item_tax_types_list_cells($label, $name, $selected_id=null)
1017 echo "<td>$label</td>\n";
1019 item_tax_types_list($name, $selected_id);
1023 function item_tax_types_list_row($label, $name, $selected_id=null)
1026 item_tax_types_list_cells($label, $name, $selected_id);
1030 //------------------------------------------------------------------------------------
1032 function shippers_list($name, $selected_id=null)
1034 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1035 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1036 array('order'=>array('shipper_name')));
1039 function shippers_list_cells($label, $name, $selected_id=null)
1042 echo "<td>$label</td>\n";
1044 shippers_list($name, $selected_id);
1048 function shippers_list_row($label, $name, $selected_id=null)
1051 shippers_list_cells($label, $name, $selected_id);
1055 //-------------------------------------------------------------------------------------
1057 function sales_persons_list($name, $selected_id=null)
1059 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1060 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1061 array('order'=>array('salesman_name')));
1064 function sales_persons_list_cells($label, $name, $selected_id=null)
1067 echo "<td>$label</td>\n";
1069 sales_persons_list($name, $selected_id);
1073 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1076 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1080 //------------------------------------------------------------------------------------
1082 function sales_areas_list($name, $selected_id=null)
1084 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1085 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1088 function sales_areas_list_cells($label, $name, $selected_id=null)
1091 echo "<td>$label</td>\n";
1093 sales_areas_list($name, $selected_id);
1097 function sales_areas_list_row($label, $name, $selected_id=null)
1100 sales_areas_list_cells($label, $name, $selected_id);
1104 //------------------------------------------------------------------------------------
1106 function sales_groups_list($name, $selected_id=null, $special_option=false)
1108 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1109 combo_input($name, $selected_id, $sql, 'id', 'description', array(
1110 'spec_option' => $special_option===true ? ' ' : $special_option,
1111 'order' => 'description', 'spec_id' => 0,
1115 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1118 echo "<td>$label</td>\n";
1120 sales_groups_list($name, $selected_id, $special_option);
1124 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1127 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1131 //------------------------------------------------------------------------------------
1133 function _format_template_items($row)
1135 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1138 function templates_list($name, $selected_id=null, $special_option=false)
1140 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1141 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1142 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1143 combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1144 'format' => '_format_template_items',
1145 'spec_option' => $special_option===true ? ' ' : $special_option,
1146 'order' => 'order_no', 'spec_id' => 0,
1150 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1153 echo "<td>$label</td>\n";
1155 templates_list($name, $selected_id, $special_option);
1159 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1162 templates_list_cells($label, $name, $selected_id, $special_option);
1166 //------------------------------------------------------------------------------------
1168 function workorders_list($name, $selected_id=null)
1170 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1171 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1174 function workorders_list_cells($label, $name, $selected_id=null)
1177 echo "<td>$label</td>\n";
1179 workorders_list($name, $selected_id);
1183 function workorders_list_row($label, $name, $selected_id=null)
1186 workorders_list_cells($label, $name, $selected_id);
1190 //------------------------------------------------------------------------------------
1192 function payment_terms_list($name, $selected_id=null)
1194 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1195 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1198 function payment_terms_list_cells($label, $name, $selected_id=null)
1201 echo "<td>$label</td>\n";
1203 payment_terms_list($name, $selected_id);
1207 function payment_terms_list_row($label, $name, $selected_id=null)
1210 payment_terms_list_cells($label, $name, $selected_id);
1214 //------------------------------------------------------------------------------------
1216 function credit_status_list($name, $selected_id=null)
1218 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1219 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1222 function credit_status_list_cells($label, $name, $selected_id=null)
1225 echo "<td>$label</td>\n";
1227 credit_status_list($name, $selected_id);
1231 function credit_status_list_row($label, $name, $selected_id=null)
1234 credit_status_list_cells($label, $name, $selected_id);
1238 //-----------------------------------------------------------------------------------------------
1240 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1242 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1244 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1246 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1248 'select_submit'=> $submit_on_change,
1249 // 'async' => false,
1253 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1256 echo "<td>$label</td>\n";
1258 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1263 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1266 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1271 //-----------------------------------------------------------------------------------------------
1273 function movement_types_list($name, $selected_id=null)
1275 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1276 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1279 function movement_types_list_cells($label, $name, $selected_id=null)
1282 echo "<td>$label</td>\n";
1284 movement_types_list($name, $selected_id);
1288 function movement_types_list_row($label, $name, $selected_id=null)
1291 movement_types_list_cells($label, $name, $selected_id);
1295 //-----------------------------------------------------------------------------------------------
1296 function _format_date($row)
1298 return sql2date($row['reconciled']);
1301 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1303 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1304 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1305 GROUP BY reconciled";
1306 combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1308 'spec_option' => $special_option,
1309 'format' => '_format_date',
1311 'select_submit'=> $submit_on_change
1315 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1318 echo "<td>$label</td>\n";
1320 bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1324 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1327 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1331 //-----------------------------------------------------------------------------------------------
1333 function workcenter_list($name, $selected_id=null, $all_option=false)
1337 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1339 return combo_input($name, $selected_id, $sql, 'id', 'name',
1341 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1342 'spec_id' => $all_items,
1346 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1348 default_focus($name);
1350 echo "<td>$label</td>\n";
1352 workcenter_list($name, $selected_id, $all_option);
1356 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1359 workcenter_list_cells($label, $name, $selected_id, $all_option);
1363 //-----------------------------------------------------------------------------------------------
1365 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1367 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1368 FROM ".TB_PREF."bank_accounts";
1369 // , ".TB_PREF."chart_master
1370 // WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1372 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1374 'format' => '_format_add_curr',
1375 'select_submit'=> $submit_on_change,
1380 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1383 echo "<td>$label</td>\n";
1385 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1390 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1393 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1397 //-----------------------------------------------------------------------------------------------
1399 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1401 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1402 FROM ".TB_PREF."bank_accounts
1403 WHERE ".TB_PREF."bank_accounts.account_type=3";
1406 echo "<tr><td>$label</td>\n";
1408 $str = combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1410 'format' => '_format_add_curr',
1411 'select_submit'=> $submit_on_change,
1414 echo "</td></tr>\n";
1417 //-----------------------------------------------------------------------------------------------
1419 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1421 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1423 default_focus($name);
1426 echo "<td>$label</td>\n";
1429 $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1431 'select_submit'=> $submit_on_change,
1433 'spec_option' =>$spec_option,
1435 'order'=> array('pos_name')
1437 echo "</td></tr>\n";
1441 //-----------------------------------------------------------------------------------------------
1443 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1446 echo "<td>$label</td>\n";
1448 $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1452 //-----------------------------------------------------------------------------------------------
1454 function class_list($name, $selected_id=null, $submit_on_change=false)
1456 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1458 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1460 'select_submit'=> $submit_on_change,
1466 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1469 echo "<td>$label</td>\n";
1471 $str = class_list($name, $selected_id, $submit_on_change);
1476 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1479 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1484 //-----------------------------------------------------------------------------------------------
1486 function stock_categories_list($name, $selected_id=null, $submit_on_change=false)
1488 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1489 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1490 array('order'=>'category_id',
1491 'select_submit'=> $submit_on_change,
1496 function stock_categories_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1499 echo "<td>$label</td>\n";
1501 stock_categories_list($name, $selected_id, $submit_on_change);
1505 function stock_categories_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1508 stock_categories_list_cells($label, $name, $selected_id, $submit_on_change);
1512 //-----------------------------------------------------------------------------------------------
1514 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1518 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1520 combo_input($name, $selected_id, $sql, 'id', 'name',
1523 'spec_option' =>$all_option,
1524 'spec_id' => $all_option_numeric ? 0 : $all_items
1528 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1529 $all_option_numeric=false)
1532 echo "<td>$label</td>\n";
1534 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1538 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1539 $all_option_numeric=false)
1542 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1543 $all_option_numeric);
1547 //-----------------------------------------------------------------------------------------------
1548 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1549 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1551 if ($skip_bank_accounts)
1552 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1553 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1554 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1555 ."ON chart.account_code=acc.account_code
1556 WHERE acc.account_code IS NULL
1557 AND chart.account_type=type.id";
1559 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1560 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1561 WHERE chart.account_type=type.id";
1563 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1565 'format' => '_format_account',
1566 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1568 'order' => array('type.id','account_code'),
1569 'search_box' => $cells,
1570 'search_submit' => false,
1574 'select_submit'=> $submit_on_change,
1577 'show_inactive' => $all
1582 function _format_account($row)
1584 return $row[0] . " " . $row[1];
1587 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1588 $skip_bank_accounts=false, $cells=false, $all_option=false,
1589 $submit_on_change=false, $all=false)
1592 echo "<td>$label</td>\n";
1594 gl_all_accounts_list($name, $selected_id,
1595 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1599 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1600 $skip_bank_accounts=false, $cells=false, $all_option=false)
1603 gl_all_accounts_list_cells($label, $name, $selected_id,
1604 $skip_bank_accounts, $cells, $all_option);
1608 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1611 $items['0'] = strlen($name_no) ? $name_no : _("No");
1612 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1614 return array_selector($name, $selected_id, $items,
1616 'select_submit'=> $submit_on_change,
1617 'async' => false ) ); // FIX?
1620 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1623 echo "<td>$label</td>\n";
1625 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1630 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1633 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1638 //------------------------------------------------------------------------------------------------
1640 function languages_list($name, $selected_id=null)
1642 global $installed_languages;
1645 foreach ($installed_languages as $lang)
1646 $items[$lang['code']] = $lang['name'];
1648 return array_selector($name, $selected_id, $items);
1651 function languages_list_cells($label, $name, $selected_id=null)
1654 echo "<td>$label</td>\n";
1656 languages_list($name, $selected_id);
1660 function languages_list_row($label, $name, $selected_id=null)
1663 languages_list_cells($label, $name, $selected_id);
1667 //------------------------------------------------------------------------------------------------
1669 function bank_account_types_list($name, $selected_id=null)
1671 global $bank_account_types;
1673 return array_selector($name, $selected_id, $bank_account_types);
1676 function bank_account_types_list_cells($label, $name, $selected_id=null)
1679 echo "<td>$label</td>\n";
1681 bank_account_types_list($name, $selected_id);
1685 function bank_account_types_list_row($label, $name, $selected_id=null)
1688 bank_account_types_list_cells($label, $name, $selected_id);
1692 //------------------------------------------------------------------------------------------------
1693 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1695 global $payment_person_types;
1698 foreach ($payment_person_types as $key=>$type)
1700 if ($key != PT_WORKORDER)
1701 $items[$key] = $type;
1703 return array_selector($name, $selected_id, $items,
1704 array( 'select_submit'=> $submit_on_change ) );
1707 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1710 echo "<td>$label</td>\n";
1712 $str = payment_person_types_list($name, $selected_id, $related);
1717 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1720 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1725 //------------------------------------------------------------------------------------------------
1727 function wo_types_list($name, $selected_id=null)
1729 global $wo_types_array;
1731 return array_selector($name, $selected_id, $wo_types_array,
1732 array( 'select_submit'=> true, 'async' => true ) );
1735 function wo_types_list_row($label, $name, $selected_id=null)
1737 echo "<tr><td>$label</td><td>\n";
1738 $str = wo_types_list($name, $selected_id);
1739 echo "</td></tr>\n";
1743 //------------------------------------------------------------------------------------------------
1745 function dateformats_list_row($label, $name, $value=null)
1747 global $dateformats;
1749 echo "<tr><td>$label</td>\n<td>";
1750 array_selector( $name, $value, $dateformats );
1751 echo "</td></tr>\n";
1754 function dateseps_list_row($label, $name, $value=null)
1758 echo "<tr><td>$label</td>\n<td>";
1759 array_selector( $name, $value, $dateseps );
1760 echo "</td></tr>\n";
1763 function thoseps_list_row($label, $name, $value=null)
1767 echo "<tr><td>$label</td>\n<td>";
1768 array_selector( $name, $value, $thoseps );
1769 echo "</td></tr>\n";
1772 function decseps_list_row($label, $name, $value=null)
1776 echo "<tr><td>$label</td>\n<td>";
1777 array_selector( $name, $value, $decseps );
1778 echo "</td></tr>\n";
1781 function themes_list_row($label, $name, $value=null)
1783 global $path_to_root;
1785 $path = $path_to_root.'/themes/';
1787 $themedir = opendir($path);
1788 while(false !== ($fname = readdir($themedir)))
1790 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1792 $themes[$fname] = $fname;
1797 echo "<tr><td>$label</td>\n<td>";
1798 array_selector( $name, $value, $themes );
1799 echo "</td></tr>\n";
1802 function pagesizes_list_row($label, $name, $value=null)
1807 foreach ($pagesizes as $pz)
1810 echo "<tr><td>$label</td>\n<td>";
1811 array_selector( $name, $value, $items );
1812 echo "</td></tr>\n";
1815 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1817 global $systypes_array;
1820 echo "<td>$label</td>\n";
1823 $str = array_selector($name, $value, $systypes_array,
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";
1841 $items = $systypes_array;
1843 // exclude quotes, orders and dimensions
1844 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1845 ST_SALESQUOTE) as $excl)
1846 unset($items[$excl]);
1848 $str = array_selector($name, $value, $items,
1850 'spec_option'=> _("All"),
1852 'select_submit'=> $submit_on_change,
1860 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1863 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1868 function cust_allocations_list_cells($label, $name, $selected=null)
1876 $all_items=>_("All Types"),
1877 '1'=> _("Sales Invoices"),
1878 '2'=> _("Overdue Invoices"),
1879 '3' => _("Payments"),
1880 '4' => _("Credit Notes"),
1881 '5' => _("Delivery Notes")
1883 $str = array_selector($name, $selected, $allocs);
1888 function supp_allocations_list_cell($name, $selected=null)
1894 $all_items=>_("All Types"),
1895 '1'=> _("Invoices"),
1896 '2'=> _("Overdue Invoices"),
1897 '3' => _("Payments"),
1898 '4' => _("Credit Notes"),
1899 '5' => _("Overdue Credit Notes")
1901 $str = array_selector($name, $selected, $allocs);
1906 function policy_list_cells($label, $name, $selected=null)
1911 $str = array_selector($name, $selected,
1912 array( '' => _("Automatically put balance on back order"),
1913 'CAN' => _("Cancel any quantites not delivered")) );
1918 function policy_list_row($label, $name, $selected=null)
1921 policy_list_cells($label, $name, $selected);
1925 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1930 $str = array_selector($name, $selected,
1931 array( 'Return' => _("Items Returned to Inventory Location"),
1932 'WriteOff' => _("Items Written Off")),
1933 array( 'select_submit'=> $submit_on_change ) );
1938 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1941 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1946 function number_list($name, $selected, $from, $to, $no_option=false)
1949 for ($i = $from; $i <= $to; $i++)
1952 return array_selector($name, $selected, $items,
1953 array( 'spec_option' => $no_option,
1954 'spec_id' => ALL_NUMERIC) );
1957 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1962 number_list($name, $selected, $from, $to, $no_option);
1966 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1969 number_list_cells($label, $name, $selected, $from, $to, $no_option);
1973 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1974 $submit_on_change=true)
1976 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1977 ." GROUP BY profile";
1978 $result = db_query($sql, 'cannot get all profile names');
1979 $profiles = array();
1980 while($myrow=db_fetch($result)) {
1981 $profiles[$myrow['profile']] = $myrow['profile'];
1986 echo "<td>$label</td>\n";
1989 array_selector($name, $selected_id, $profiles,
1990 array( 'select_submit'=> $submit_on_change,
1991 'spec_option'=>$spec_opt,
1995 echo "</td></tr>\n";
1998 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2000 static $printers; // query only once for page display
2003 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2004 $result = db_query($sql, 'cannot get all printers');
2005 $printers = array();
2006 while($myrow=db_fetch($result)) {
2007 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2010 array_selector($name, $selected_id, $printers,
2011 array( 'select_submit'=> $submit_on_change,
2012 'spec_option'=>$spec_opt,
2017 //------------------------------------------------------------------------------------------------
2019 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2022 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2024 $sql .= " WHERE type=$type";
2026 combo_input($name, $selected_id, $sql, 'id', 'description',
2029 'order' => 'description',
2030 'select_submit'=> $submit_on_change,
2036 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2038 echo "<td>$label</td><td>\n";
2039 quick_entries_list($name, $selected_id, $type, $submit_on_change);
2043 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2046 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2051 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2053 global $quick_actions;
2055 echo "<tr><td>$label</td><td>";
2056 array_selector($name, $selected_id, $quick_actions,
2058 'select_submit'=> $submit_on_change
2060 echo "</td></tr>\n";
2063 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2065 global $quick_entry_types;
2067 echo "<tr><td>$label</td><td>";
2068 array_selector($name, $selected_id, $quick_entry_types,
2070 'select_submit'=> $submit_on_change
2072 echo "</td></tr>\n";
2075 function record_status_list_row($label, $name) {
2076 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2079 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2081 global $class_types;
2083 echo "<tr><td>$label</td><td>";
2084 array_selector($name, $selected_id, $class_types,
2086 'select_submit'=> $submit_on_change
2088 echo "</td></tr>\n";
2091 //------------------------------------------------------------------------------------------------
2093 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2094 $show_inactive = false)
2098 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2100 return combo_input($name, $selected_id, $sql, 'id', 'description',
2102 'spec_option'=>$new_item ? _("New role") : false,
2104 'select_submit'=> $submit_on_change,
2105 'show_inactive' => $show_inactive
2109 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2110 $show_inactive = false)
2113 echo "<td>$label</td>\n";
2115 $str = security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2120 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2121 $show_inactive = false)
2124 $str = security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2129 function tab_list_row($label, $name, $selected_id=null)
2133 echo "<td>$label</td><td>\n";
2137 array_selector($name, $selected_id, $tabs);
2139 echo "</td></tr>\n";
2142 //-----------------------------------------------------------------------------------------------
2144 function tag_list($name, $height, $type, $multi=false, $all=false)
2147 global $path_to_root;
2148 include_once($path_to_root . "/admin/db/tags_db.inc");
2149 $results = get_tags($type,$all);
2151 while ($tag = db_fetch($results))
2152 $tags[$tag['id']] = $tag['name'];
2154 if (!isset($tags)) {
2155 $tags[''] = _("No ".($all?"":"active ")."tags defined.");
2157 return array_selector($name, null, $tags,
2160 'height' => $height,
2164 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false)
2167 echo "<td>$label</td>\n";
2169 tag_list($name, $height, $type, $mult, $all);
2174 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false)
2177 tag_list_cells($label, $name, $height, $type, $mult, $all);
2181 //---------------------------------------------------------------------------------------------
2182 // List of sets of active extensions
2184 function extset_list($name, $value=null, $submit_on_change=false)
2186 global $db_connections;
2189 foreach ($db_connections as $comp)
2190 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2191 array_selector( $name, $value, $items,
2193 'spec_option'=> _("Installed on system"),
2195 'select_submit'=> $submit_on_change,