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.
64 'editable' => false // false, or length of editable entry field
66 // ------ merge options with defaults ----------
68 $opts = array_merge($opts, $options);
69 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
71 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
72 // select content filtered by search field:
73 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
74 // select set by select content field
75 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
77 $select_submit = $opts['select_submit'];
78 $spec_id = $opts['spec_id'];
79 $spec_option = $opts['spec_option'];
80 $by_id = ($opts['type'] == 0);
81 $class = $by_id ? 'combo':'combo2';
82 $disabled = $opts['disabled'] ? "disabled" : '';
83 $multi = $opts['multi'];
85 if(!count($opts['search'])) {
86 $opts['search'] = array($by_id ? $valfield : $namefield);
88 if ($opts['sel_hint'] === null)
89 $opts['sel_hint'] = $by_id || $search_box==false ?
90 '' : _('Press Space tab for search pattern entry');
92 if ($opts['box_hint'] === null) // dodaƦ hint dla pustego ****
93 $opts['box_hint'] = $search_box && $search_submit != false ?
94 ($by_id ? _('Enter code fragment to search or * for all')
95 : _('Enter description fragment to search or * for all')) :'';
97 if ($selected_id == null) {
98 $selected_id = get_post($name, $opts['default']);
100 if(!is_array($selected_id))
101 $selected_id = array($selected_id); // code is generalized for multiple selection support
103 $txt = get_post($search_box);
107 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
108 if ($by_id) $txt = $_POST[$name];
111 $Ajax->activate('_page_body');
113 $Ajax->activate($name);
115 if (isset($_POST[$search_button])) {
117 $Ajax->activate('_page_body');
119 $Ajax->activate($name);
122 // search related sql modifications
124 $rel = "rel='$search_box'"; // set relation to list
125 if ($opts['search_submit']) {
126 if (isset($_POST[$search_button])) {
127 $selected_id = array(); // ignore selected_id while search
129 $Ajax->activate('_page_body');
131 $Ajax->activate($name);
134 if ($spec_option === false && $selected_id == array())
137 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
142 foreach($opts['search'] as $i=> $s)
143 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
144 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
149 if (count($opts['where'])) {
150 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
151 $where .= '('. implode($opts['where'], ' AND ') . ')';
152 $group_pos = strpos($sql, 'GROUP BY');
154 $group = substr($sql, $group_pos);
155 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
160 if ($opts['order'] != false) {
161 if (!is_array($opts['order']))
162 $opts['order'] = array($opts['order']);
163 $sql .= ' ORDER BY '.implode(',',$opts['order']);
167 // ------ make selector ----------
168 $selector = $first_opt = '';
173 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
174 //if($name=='curr_default') display_notification($opts['search_submit']);
175 if($result = db_query($sql)) {
176 while ($contact_row = db_fetch($result)) {
177 $value = $contact_row[0];
178 $descr = $opts['format']==null ? $contact_row[1] :
179 call_user_func($opts['format'], $contact_row);
181 if (get_post($search_button) && ($txt == $value)) {
182 $selected_id[] = $value;
184 if (in_array($value, $selected_id)) {
187 $edit = $opts['editable'] && $contact_row['editable']
188 && (@$_POST[$search_box] == $value)
191 break; // selected field is editable - abandon list construction
193 // show selected option even if inactive
194 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
197 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
199 if ($first_id === false) {
203 $cat = $contact_row[$opts['category']];
204 if ($opts['category'] !== false && $cat != $lastcat){
205 $selector .= "<optgroup label='".$cat."'>\n";
208 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
210 db_free_result($result);
213 // Prepend special option.
214 if ($spec_option !== false) { // if special option used - add it
215 $first_id = $spec_id;
216 $first_opt = $spec_option;
218 // if($first_id !== false) {
219 $sel = $found===false ? 'selected' : '';
220 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
221 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
225 if ($found===false) {
226 $selected_id = array($first_id);
229 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
231 $selector = "<select ".($multi ? "multiple" : '')
232 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
233 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
234 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
236 if ($by_id && ($search_box != false || $opts['editable']) ) {
237 // on first display show selector list
238 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
239 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
240 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
241 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
242 set_focus($name.'_text'); // prevent lost focus
243 } else if (isset($_POST['_'.$name.'_edit']))
244 set_focus($name); // prevent lost focus
245 if (!$opts['editable'])
247 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
250 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
252 // span for select list/inut field update
253 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
255 // if selectable or editable list is used - add select button
256 if ($select_submit != false || $search_button) {
257 global $_select_button;
258 // button class selects form reload/ajax selector update
259 $selector .= sprintf($_select_button, $disabled, user_theme(),
260 (fallback_mode() ? '' : 'display:none;'),
261 '_'.$name.'_update')."\n";
263 // ------ make combo ----------
265 if ($search_box != false) {
266 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
267 $opts['size']."' maxlength='".$opts['max'].
268 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
269 .$opts['box_hint']."'"
270 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
272 if ($search_submit != false || $opts['editable']) {
273 global $_search_button;
274 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
275 (fallback_mode() ? '' : 'display:none;'),
276 $search_submit ? $search_submit : "_{$name}_button")."\n";
279 default_focus(($search_box && $by_id) ? $search_box : $name);
281 if ($search_box && $opts['cells'])
282 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
284 $str = $edit_entry.$selector;
290 Returns true if selector $name is subject to update.
292 function list_updated($name)
294 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
296 //----------------------------------------------------------------------------------------------
297 // Universal array combo generator
298 // $items is array of options 'value' => 'description'
299 // Options is reduced set of combo_selector options and is merged with defaults.
301 function array_selector($name, $selected_id, $items, $options=null)
305 $opts = array( // default options
306 'spec_option'=>false, // option text or false
307 'spec_id' => 0, // option id
308 'select_submit' => false, //submit on select: true/false
309 'async' => true, // select update via ajax (true) vs _page_body reload
310 'default' => '', // default value when $_POST is not set
311 'multi'=>false, // multiple select
312 // search box parameters
313 'height' => false, // number of lines in select box
317 // ------ merge options with defaults ----------
319 $opts = array_merge($opts, $options);
320 $select_submit = $opts['select_submit'];
321 $spec_id = $opts['spec_id'];
322 $spec_option = $opts['spec_option'];
323 $disabled = $opts['disabled'] ? "disabled" : '';
324 $multi = $opts['multi'];
326 if ($selected_id == null) {
327 $selected_id = get_post($name, $opts['default']);
329 if(!is_array($selected_id))
330 $selected_id = array($selected_id); // code is generalized for multiple selection support
332 if (isset($_POST[ '_'.$name.'_update'])) {
334 $Ajax->activate('_page_body');
336 $Ajax->activate($name);
339 // ------ make selector ----------
340 $selector = $first_opt = '';
343 //if($name=='SelectStockFromList') display_error($sql);
344 foreach($items as $value=>$descr) {
346 if (in_array((string)$value, $selected_id)) {
350 if ($first_id === false) {
354 $selector .= "<option $sel value='$value'>$descr</option>\n";
357 // Prepend special option.
358 if ($spec_option !== false) { // if special option used - add it
359 $first_id = $spec_id;
360 $first_opt = $spec_option;
361 $sel = $found===false ? 'selected' : '';
362 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
366 if ($found===false) {
367 $selected_id = array($first_id);
369 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
370 $selector = "<select ".($multi ? "multiple" : '')
371 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
372 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
373 . $opts['sel_hint']."'>".$selector."</select>\n";
375 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
377 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
379 if ($select_submit != false) { // if submit on change is used - add select button
380 global $_select_button;
381 $selector .= sprintf($_select_button, $disabled, user_theme(),
382 (fallback_mode() ? '' : 'display:none;'),
383 '_'.$name.'_update')."\n";
385 default_focus($name);
389 //----------------------------------------------------------------------------------------------
391 function _format_add_curr($row)
393 static $company_currency;
395 if ($company_currency == null)
397 $company_currency = get_company_currency();
399 return $row[1] . ($row[2] == $company_currency ?
400 '' : (" - " . $row[2]));
403 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
404 $all=false, $editkey = false)
408 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
410 $mode = get_company_pref('no_supplier_list');
413 set_editor('supplier', $name, $editkey);
415 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
417 'format' => '_format_add_curr',
418 'order' => array('supp_ref'),
419 'search_box' => $mode!=0,
421 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
422 'spec_id' => $all_items,
423 'select_submit'=> $submit_on_change,
425 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
426 _('Select supplier'),
427 'show_inactive'=>$all
431 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
432 $submit_on_change=false, $all=false, $editkey = false)
435 echo "<td>$label</td><td>\n";
436 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
441 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
442 $submit_on_change=false, $all=false, $editkey = false)
444 echo "<tr><td>$label</td><td>";
445 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
449 //----------------------------------------------------------------------------------------------
451 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
452 $show_inactive=false, $editkey = false)
456 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
458 $mode = get_company_pref('no_customer_list');
461 set_editor('customer', $name, $editkey);
463 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
465 'format' => '_format_add_curr',
466 'order' => array('debtor_ref'),
467 'search_box' => $mode!=0,
470 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
471 'spec_id' => $all_items,
472 'select_submit'=> $submit_on_change,
474 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
475 _('Select customer'),
476 'show_inactive' => $show_inactive
480 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
481 $submit_on_change=false, $show_inactive=false, $editkey = false)
484 echo "<td>$label</td>\n";
486 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
487 $show_inactive, $editkey);
491 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
492 $submit_on_change=false, $show_inactive=false, $editkey = false)
494 echo "<tr><td>$label</td><td nowrap>";
495 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
496 $show_inactive, $editkey);
497 echo "</td>\n</tr>\n";
500 //------------------------------------------------------------------------------------------------
502 function customer_branches_list($customer_id, $name, $selected_id=null,
503 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
507 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
508 WHERE debtor_no='" . $customer_id . "' ";
511 set_editor('branch', $name, $editkey);
513 $where = $enabled ? array("disable_trans = 0") : array();
514 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
517 'order' => array('branch_ref'),
518 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
519 'spec_id' => $all_items,
520 'select_submit'=> $submit_on_change,
521 'sel_hint' => _('Select customer branch')
524 //------------------------------------------------------------------------------------------------
526 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
527 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
530 echo "<td>$label</td>\n";
532 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
533 $submit_on_change, $editkey);
537 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
538 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
541 customer_branches_list_cells($label, $customer_id, $name, $selected_id,
542 $all_option, $enabled, $submit_on_change, $editkey);
546 //------------------------------------------------------------------------------------------------
548 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
552 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
554 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
556 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
557 'spec_id' => $all_items,
558 'select_submit'=> $submit_on_change
562 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
565 echo "<td>$label</td>\n";
567 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
571 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
574 locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
578 //-----------------------------------------------------------------------------------------------
580 function currencies_list($name, $selected_id=null, $submit_on_change=false)
582 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
584 // default to the company currency
585 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
587 'select_submit'=> $submit_on_change,
588 'default' => get_company_currency(),
593 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
596 echo "<td>$label</td>\n";
598 echo currencies_list($name, $selected_id, $submit_on_change);
602 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
605 currencies_list_cells($label, $name, $selected_id, $submit_on_change);
609 //---------------------------------------------------------------------------------------------------
611 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
614 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
616 // default to the company current fiscal year
618 return combo_input($name, $selected_id, $sql, 'id', '',
621 'default' => get_company_pref('f_year'),
622 'format' => '_format_fiscalyears',
623 'select_submit'=> $submit_on_change,
628 function _format_fiscalyears($row)
630 return sql2date($row[1]) . " - " . sql2date($row[2])
631 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
634 function fiscalyears_list_cells($label, $name, $selected_id=null)
637 echo "<td>$label</td>\n";
639 echo fiscalyears_list($name, $selected_id);
643 function fiscalyears_list_row($label, $name, $selected_id=null)
646 fiscalyears_list_cells($label, $name, $selected_id);
649 //------------------------------------------------------------------------------------
651 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
652 $submit_on_change=false, $showclosed=false, $showtype=1)
654 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
657 'order' => 'reference',
658 'spec_option'=>$no_option ? $showname : false,
660 'select_submit'=> $submit_on_change,
665 $options['where'][] = "closed=0";
667 $options['where'][] = "type_=$showtype";
669 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
672 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
673 $showclosed=false, $showtype=0, $submit_on_change=false)
676 echo "<td>$label</td>\n";
678 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
682 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
683 $showclosed=false, $showtype=0, $submit_on_change=false)
686 dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
687 $showclosed, $showtype, $submit_on_change);
691 //---------------------------------------------------------------------------------------------------
693 function stock_items_list($name, $selected_id=null, $all_option=false,
694 $submit_on_change=false, $opts=array(), $editkey = false)
698 $sql = "SELECT stock_id, s.description, c.description, s.inactive
699 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
702 set_editor('item', $name, $editkey);
704 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
707 'format' => '_format_stock_items',
708 'spec_option' => $all_option===true ? _("All Items") : $all_option,
709 'spec_id' => $all_items,
710 'search_box' => true,
711 'search' => array("stock_id", "c.description","s.description"),
712 'search_submit' => get_company_pref('no_item_list')!=0,
714 'select_submit'=> $submit_on_change,
716 'order' => array('c.description','stock_id')
720 function _format_stock_items($row)
722 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
725 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
726 $submit_on_change=false, $all=false, $editkey = false)
729 echo "<td>$label</td>\n";
730 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
731 array('cells'=>true, 'show_inactive'=>$all), $editkey);
734 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
737 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
741 //---------------------------------------------------------------------------------------------------
743 // Select item via foreign code.
745 function sales_items_list($name, $selected_id=null, $all_option=false,
746 $submit_on_change=false, $type='', $opts=array())
750 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
751 i.inactive, if(count(*)>1, '0', s.editable) as editable
753 ".TB_PREF."stock_master s,
754 ".TB_PREF."item_codes i
756 ".TB_PREF."stock_category c
757 ON i.category_id=c.category_id
758 WHERE i.stock_id=s.stock_id";
761 if ($type == 'local') { // exclude foreign codes
762 $sql .= " AND !i.is_foreign";
763 } elseif ($type == 'kits') { // sales kits
764 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
766 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
767 $sql .= " GROUP BY i.item_code";
769 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
772 'format' => '_format_stock_items',
773 'spec_option' => $all_option===true ? _("All Items") : $all_option,
774 'spec_id' => $all_items,
775 'search_box' => true,
776 'search' => array("i.item_code", "c.description", "i.description"),
777 'search_submit' => get_company_pref('no_item_list')!=0,
779 'select_submit'=> $submit_on_change,
781 'order' => array('c.description','i.item_code'),
787 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
790 echo "<td>$label</td>\n";
791 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
792 '', array('cells'=>true));
795 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
797 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
798 'kits', array('cells'=>false, 'editable' => false));
801 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
805 echo "<td>$label</td>\n";
807 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
808 'local', array('cells'=>false, 'editable' => false));
811 //------------------------------------------------------------------------------------
813 function stock_manufactured_items_list($name, $selected_id=null,
814 $all_option=false, $submit_on_change=false)
816 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
817 array('where'=>array("mb_flag= 'M'")));
820 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
821 $all_option=false, $submit_on_change=false)
824 echo "<td>$label</td>\n";
826 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
830 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
831 $all_option=false, $submit_on_change=false)
834 stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
837 //------------------------------------------------------------------------------------
839 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
840 $all_option=false, $submit_on_change=false, $editkey = false)
842 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
843 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
846 function stock_component_items_list_cells($label, $name, $parent_stock_id,
847 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
850 echo "<td>$label</td>\n";
851 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
852 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
855 //------------------------------------------------------------------------------------
857 function stock_costable_items_list($name, $selected_id=null,
858 $all_option=false, $submit_on_change=false)
860 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
861 array('where'=>array("mb_flag!='D'")));
864 function stock_costable_items_list_cells($label, $name, $selected_id=null,
865 $all_option=false, $submit_on_change=false)
868 echo "<td>$label</td>\n";
869 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
870 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
873 //------------------------------------------------------------------------------------
874 function stock_purchasable_items_list($name, $selected_id=null,
875 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
877 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
878 array('where'=>array("mb_flag!= 'M'"),
879 'show_inactive'=>$all), $editkey);
882 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
883 $all_option=false, $submit_on_change=false, $editkey=false)
886 echo "<td>$label</td>\n";
887 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
888 array('where'=>array("mb_flag!= 'M'"),
889 '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 stock_purchasable_items_list_cells($label, $name, $selected_id=null,
897 $all_option, $submit_on_change, $editkey);
901 //------------------------------------------------------------------------------------
903 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
909 echo "<td>$label</td>\n";
912 echo array_selector($name, $selected_id, $stock_types,
914 'select_submit'=> true,
915 'disabled' => !$enabled) );
919 function stock_units_list_row($label, $name, $value=null, $enabled=true)
921 $result = get_all_item_units();
924 echo "<td>$label</td>\n";
927 while($unit = db_fetch($result))
928 $units[$unit['abbr']] = $unit['name'];
930 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
935 //------------------------------------------------------------------------------------
937 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
939 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
941 return combo_input($name, $selected_id, $sql, 'id', 'name',
943 'spec_option' => $none_option,
944 'spec_id' => ALL_NUMERIC,
945 'select_submit'=> $submit_on_change,
950 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
951 $submit_on_change=false)
954 echo "<td>$label</td>\n";
956 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
960 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
961 $submit_on_change=false)
964 tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
968 //------------------------------------------------------------------------------------
970 function tax_groups_list($name, $selected_id=null,
971 $none_option=false, $submit_on_change=false)
973 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
975 return combo_input($name, $selected_id, $sql, 'id', 'name',
978 'spec_option' => $none_option,
979 'spec_id' => ALL_NUMERIC,
980 'select_submit'=> $submit_on_change,
985 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
988 echo "<td>$label</td>\n";
990 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
994 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
997 tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
1001 //------------------------------------------------------------------------------------
1003 function item_tax_types_list($name, $selected_id=null)
1005 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1006 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1009 function item_tax_types_list_cells($label, $name, $selected_id=null)
1012 echo "<td>$label</td>\n";
1014 echo item_tax_types_list($name, $selected_id);
1018 function item_tax_types_list_row($label, $name, $selected_id=null)
1021 item_tax_types_list_cells($label, $name, $selected_id);
1025 //------------------------------------------------------------------------------------
1027 function shippers_list($name, $selected_id=null)
1029 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1030 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1031 array('order'=>array('shipper_name')));
1034 function shippers_list_cells($label, $name, $selected_id=null)
1037 echo "<td>$label</td>\n";
1039 echo shippers_list($name, $selected_id);
1043 function shippers_list_row($label, $name, $selected_id=null)
1046 shippers_list_cells($label, $name, $selected_id);
1050 //-------------------------------------------------------------------------------------
1052 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1054 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1055 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1056 array('order'=>array('salesman_name'),
1057 'spec_option' => $spec_opt,
1058 'spec_id' => ALL_NUMERIC));
1061 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1064 echo "<td>$label</td>\n";
1066 echo sales_persons_list($name, $selected_id, $spec_opt);
1070 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1073 sales_persons_list_cells($label, $name, $selected_id, $spec_opt);
1077 //------------------------------------------------------------------------------------
1079 function sales_areas_list($name, $selected_id=null)
1081 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1082 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1085 function sales_areas_list_cells($label, $name, $selected_id=null)
1088 echo "<td>$label</td>\n";
1090 echo sales_areas_list($name, $selected_id);
1094 function sales_areas_list_row($label, $name, $selected_id=null)
1097 sales_areas_list_cells($label, $name, $selected_id);
1101 //------------------------------------------------------------------------------------
1103 function sales_groups_list($name, $selected_id=null, $special_option=false)
1105 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1106 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1107 'spec_option' => $special_option===true ? ' ' : $special_option,
1108 'order' => 'description', 'spec_id' => 0,
1112 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1115 echo "<td>$label</td>\n";
1117 echo sales_groups_list($name, $selected_id, $special_option);
1121 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1124 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1128 //------------------------------------------------------------------------------------
1130 function _format_template_items($row)
1132 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1135 function templates_list($name, $selected_id=null, $special_option=false)
1137 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1138 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1139 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1140 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1141 'format' => '_format_template_items',
1142 'spec_option' => $special_option===true ? ' ' : $special_option,
1143 'order' => 'order_no', 'spec_id' => 0,
1147 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1150 echo "<td>$label</td>\n";
1152 echo templates_list($name, $selected_id, $special_option);
1156 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1159 templates_list_cells($label, $name, $selected_id, $special_option);
1163 //------------------------------------------------------------------------------------
1165 function workorders_list($name, $selected_id=null)
1167 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1168 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1171 function workorders_list_cells($label, $name, $selected_id=null)
1174 echo "<td>$label</td>\n";
1176 echo workorders_list($name, $selected_id);
1180 function workorders_list_row($label, $name, $selected_id=null)
1183 workorders_list_cells($label, $name, $selected_id);
1187 //------------------------------------------------------------------------------------
1189 function payment_terms_list($name, $selected_id=null)
1191 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1192 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1195 function payment_terms_list_cells($label, $name, $selected_id=null)
1198 echo "<td>$label</td>\n";
1200 echo payment_terms_list($name, $selected_id);
1204 function payment_terms_list_row($label, $name, $selected_id=null)
1207 payment_terms_list_cells($label, $name, $selected_id);
1211 //------------------------------------------------------------------------------------
1213 function credit_status_list($name, $selected_id=null)
1215 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1216 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1219 function credit_status_list_cells($label, $name, $selected_id=null)
1222 echo "<td>$label</td>\n";
1224 echo credit_status_list($name, $selected_id);
1228 function credit_status_list_row($label, $name, $selected_id=null)
1231 credit_status_list_cells($label, $name, $selected_id);
1235 //-----------------------------------------------------------------------------------------------
1237 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1239 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1241 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1243 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1245 'select_submit'=> $submit_on_change,
1246 // 'async' => false,
1250 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1253 echo "<td>$label</td>\n";
1255 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1259 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1262 sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1266 //-----------------------------------------------------------------------------------------------
1268 function movement_types_list($name, $selected_id=null)
1270 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1271 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1274 function movement_types_list_cells($label, $name, $selected_id=null)
1277 echo "<td>$label</td>\n";
1279 echo movement_types_list($name, $selected_id);
1283 function movement_types_list_row($label, $name, $selected_id=null)
1286 movement_types_list_cells($label, $name, $selected_id);
1290 //-----------------------------------------------------------------------------------------------
1291 function _format_date($row)
1293 return sql2date($row['reconciled']);
1296 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1298 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1299 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1300 GROUP BY reconciled";
1301 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1303 'spec_option' => $special_option,
1304 'format' => '_format_date',
1306 'select_submit'=> $submit_on_change
1310 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1313 echo "<td>$label</td>\n";
1315 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1319 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1322 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1326 //-----------------------------------------------------------------------------------------------
1328 function workcenter_list($name, $selected_id=null, $all_option=false)
1332 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1334 return combo_input($name, $selected_id, $sql, 'id', 'name',
1336 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1337 'spec_id' => $all_items,
1341 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1343 default_focus($name);
1345 echo "<td>$label</td>\n";
1347 echo workcenter_list($name, $selected_id, $all_option);
1351 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1354 workcenter_list_cells($label, $name, $selected_id, $all_option);
1358 //-----------------------------------------------------------------------------------------------
1360 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1362 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1363 FROM ".TB_PREF."bank_accounts";
1365 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1367 'format' => '_format_add_curr',
1368 'select_submit'=> $submit_on_change,
1373 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1376 echo "<td>$label</td>\n";
1378 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1382 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1385 bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1388 //-----------------------------------------------------------------------------------------------
1390 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1392 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1393 FROM ".TB_PREF."bank_accounts
1394 WHERE ".TB_PREF."bank_accounts.account_type=3";
1397 echo "<tr><td>$label</td>\n";
1399 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1401 'format' => '_format_add_curr',
1402 'select_submit'=> $submit_on_change,
1405 echo "</td></tr>\n";
1407 //-----------------------------------------------------------------------------------------------
1409 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1411 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1413 default_focus($name);
1416 echo "<td>$label</td>\n";
1419 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1421 'select_submit'=> $submit_on_change,
1423 'spec_option' =>$spec_option,
1425 'order'=> array('pos_name')
1427 echo "</td></tr>\n";
1430 //-----------------------------------------------------------------------------------------------
1432 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1435 echo "<td>$label</td>\n";
1437 echo yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1440 //-----------------------------------------------------------------------------------------------
1442 function class_list($name, $selected_id=null, $submit_on_change=false)
1444 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1446 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1448 'select_submit'=> $submit_on_change,
1454 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1457 echo "<td>$label</td>\n";
1459 echo class_list($name, $selected_id, $submit_on_change);
1463 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1466 class_list_cells($label, $name, $selected_id, $submit_on_change);
1470 //-----------------------------------------------------------------------------------------------
1471 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1473 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1474 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1475 array('order'=>'category_id',
1476 'spec_option' => $spec_opt,
1478 'select_submit'=> $submit_on_change,
1483 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1486 echo "<td>$label</td>\n";
1488 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1492 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1495 stock_categories_list_cells($label, $name, $selected_id, $spec_opt, $submit_on_change);
1499 //-----------------------------------------------------------------------------------------------
1501 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all_option_numeric=true)
1505 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1507 return combo_input($name, $selected_id, $sql, 'id', 'name',
1510 'spec_option' =>$all_option,
1511 'spec_id' => $all_option_numeric ? 0 : $all_items
1515 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1516 $all_option_numeric=false)
1519 echo "<td>$label</td>\n";
1521 echo gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1525 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1526 $all_option_numeric=false)
1529 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1530 $all_option_numeric);
1534 //-----------------------------------------------------------------------------------------------
1535 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1536 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1538 if ($skip_bank_accounts)
1539 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1540 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1541 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1542 ."ON chart.account_code=acc.account_code
1543 WHERE acc.account_code IS NULL
1544 AND chart.account_type=type.id";
1546 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1547 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1548 WHERE chart.account_type=type.id";
1550 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1552 'format' => '_format_account',
1553 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1555 'order' => array('type.id','account_code'),
1556 'search_box' => $cells,
1557 'search_submit' => false,
1561 'select_submit'=> $submit_on_change,
1564 'show_inactive' => $all
1569 function _format_account($row)
1571 return $row[0] . " " . $row[1];
1574 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1575 $skip_bank_accounts=false, $cells=false, $all_option=false,
1576 $submit_on_change=false, $all=false)
1579 echo "<td>$label</td>\n";
1581 echo gl_all_accounts_list($name, $selected_id,
1582 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1586 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1587 $skip_bank_accounts=false, $cells=false, $all_option=false)
1590 gl_all_accounts_list_cells($label, $name, $selected_id,
1591 $skip_bank_accounts, $cells, $all_option);
1595 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1598 $items['0'] = strlen($name_no) ? $name_no : _("No");
1599 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1601 return array_selector($name, $selected_id, $items,
1603 'select_submit'=> $submit_on_change,
1604 'async' => false ) ); // FIX?
1607 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1610 echo "<td>$label</td>\n";
1612 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1616 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1619 yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1623 //------------------------------------------------------------------------------------------------
1625 function languages_list($name, $selected_id=null)
1627 global $installed_languages;
1630 foreach ($installed_languages as $lang)
1631 $items[$lang['code']] = $lang['name'];
1633 return array_selector($name, $selected_id, $items);
1636 function languages_list_cells($label, $name, $selected_id=null)
1639 echo "<td>$label</td>\n";
1641 echo languages_list($name, $selected_id);
1645 function languages_list_row($label, $name, $selected_id=null)
1648 languages_list_cells($label, $name, $selected_id);
1652 //------------------------------------------------------------------------------------------------
1654 function bank_account_types_list($name, $selected_id=null)
1656 global $bank_account_types;
1658 return array_selector($name, $selected_id, $bank_account_types);
1661 function bank_account_types_list_cells($label, $name, $selected_id=null)
1664 echo "<td>$label</td>\n";
1666 echo bank_account_types_list($name, $selected_id);
1670 function bank_account_types_list_row($label, $name, $selected_id=null)
1673 bank_account_types_list_cells($label, $name, $selected_id);
1677 //------------------------------------------------------------------------------------------------
1678 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1680 global $payment_person_types;
1683 foreach ($payment_person_types as $key=>$type)
1685 if ($key != PT_WORKORDER)
1686 $items[$key] = $type;
1688 return array_selector($name, $selected_id, $items,
1689 array( 'select_submit'=> $submit_on_change ) );
1692 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1695 echo "<td>$label</td>\n";
1697 echo payment_person_types_list($name, $selected_id, $related);
1701 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1704 payment_person_types_list_cells($label, $name, $selected_id, $related);
1708 //------------------------------------------------------------------------------------------------
1710 function wo_types_list($name, $selected_id=null)
1712 global $wo_types_array;
1714 return array_selector($name, $selected_id, $wo_types_array,
1715 array( 'select_submit'=> true, 'async' => true ) );
1718 function wo_types_list_row($label, $name, $selected_id=null)
1720 echo "<tr><td>$label</td><td>\n";
1721 echo wo_types_list($name, $selected_id);
1722 echo "</td></tr>\n";
1725 //------------------------------------------------------------------------------------------------
1727 function dateformats_list_row($label, $name, $value=null)
1729 global $dateformats;
1731 echo "<tr><td>$label</td>\n<td>";
1732 echo array_selector( $name, $value, $dateformats );
1733 echo "</td></tr>\n";
1736 function dateseps_list_row($label, $name, $value=null)
1740 echo "<tr><td>$label</td>\n<td>";
1741 echo array_selector( $name, $value, $dateseps );
1742 echo "</td></tr>\n";
1745 function thoseps_list_row($label, $name, $value=null)
1749 echo "<tr><td>$label</td>\n<td>";
1750 echo array_selector( $name, $value, $thoseps );
1751 echo "</td></tr>\n";
1754 function decseps_list_row($label, $name, $value=null)
1758 echo "<tr><td>$label</td>\n<td>";
1759 echo array_selector( $name, $value, $decseps );
1760 echo "</td></tr>\n";
1763 function themes_list_row($label, $name, $value=null)
1765 global $path_to_root;
1767 $path = $path_to_root.'/themes/';
1769 $themedir = opendir($path);
1770 while(false !== ($fname = readdir($themedir)))
1772 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1774 $themes[$fname] = $fname;
1779 echo "<tr><td>$label</td>\n<td>";
1780 echo array_selector( $name, $value, $themes );
1781 echo "</td></tr>\n";
1784 function pagesizes_list_row($label, $name, $value=null)
1789 foreach ($pagesizes as $pz)
1792 echo "<tr><td>$label</td>\n<td>";
1793 echo array_selector( $name, $value, $items );
1794 echo "</td></tr>\n";
1797 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false)
1799 global $systypes_array;
1801 return array_selector($name, $value, $systypes_array,
1803 'spec_option'=> $spec_opt,
1804 'spec_id' => ALL_NUMERIC,
1805 'select_submit'=> $submit_on_change,
1811 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1814 echo "<td>$label</td>\n";
1816 echo systypes_list($name, $value, false, $submit_on_change);
1820 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1823 systypes_list_cells($label, $name, $value, false, $submit_on_change);
1827 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1829 global $systypes_array;
1832 echo "<td>$label</td>\n";
1835 $items = $systypes_array;
1837 // exclude quotes, orders and dimensions
1838 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1839 ST_SALESQUOTE) as $excl)
1840 unset($items[$excl]);
1842 echo array_selector($name, $value, $items,
1844 'spec_option'=> _("All"),
1846 'select_submit'=> $submit_on_change,
1853 function cust_allocations_list_cells($label, $name, $selected=null)
1861 $all_items=>_("All Types"),
1862 '1'=> _("Sales Invoices"),
1863 '2'=> _("Overdue Invoices"),
1864 '3' => _("Payments"),
1865 '4' => _("Credit Notes"),
1866 '5' => _("Delivery Notes")
1868 echo array_selector($name, $selected, $allocs);
1872 function supp_allocations_list_cell($name, $selected=null)
1878 $all_items=>_("All Types"),
1879 '1'=> _("Invoices"),
1880 '2'=> _("Overdue Invoices"),
1881 '3' => _("Payments"),
1882 '4' => _("Credit Notes"),
1883 '5' => _("Overdue Credit Notes")
1885 echo array_selector($name, $selected, $allocs);
1889 function policy_list_cells($label, $name, $selected=null)
1894 echo array_selector($name, $selected,
1895 array( '' => _("Automatically put balance on back order"),
1896 'CAN' => _("Cancel any quantites not delivered")) );
1900 function policy_list_row($label, $name, $selected=null)
1903 policy_list_cells($label, $name, $selected);
1907 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1912 echo array_selector($name, $selected,
1913 array( 'Return' => _("Items Returned to Inventory Location"),
1914 'WriteOff' => _("Items Written Off")),
1915 array( 'select_submit'=> $submit_on_change ) );
1919 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1922 credit_type_list_cells($label, $name, $selected, $submit_on_change);
1926 function number_list($name, $selected, $from, $to, $no_option=false)
1929 for ($i = $from; $i <= $to; $i++)
1932 return array_selector($name, $selected, $items,
1933 array( 'spec_option' => $no_option,
1934 'spec_id' => ALL_NUMERIC) );
1937 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1942 echo number_list($name, $selected, $from, $to, $no_option);
1946 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1949 echo number_list_cells($label, $name, $selected, $from, $to, $no_option);
1953 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1954 $submit_on_change=true)
1956 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1957 ." GROUP BY profile";
1958 $result = db_query($sql, 'cannot get all profile names');
1959 $profiles = array();
1960 while($myrow=db_fetch($result)) {
1961 $profiles[$myrow['profile']] = $myrow['profile'];
1966 echo "<td>$label</td>\n";
1969 echo array_selector($name, $selected_id, $profiles,
1970 array( 'select_submit'=> $submit_on_change,
1971 'spec_option'=>$spec_opt,
1975 echo "</td></tr>\n";
1978 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1980 static $printers; // query only once for page display
1983 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
1984 $result = db_query($sql, 'cannot get all printers');
1985 $printers = array();
1986 while($myrow=db_fetch($result)) {
1987 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
1990 return array_selector($name, $selected_id, $printers,
1991 array( 'select_submit'=> $submit_on_change,
1992 'spec_option'=>$spec_opt,
1997 //------------------------------------------------------------------------------------------------
1999 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2002 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2004 $sql .= " WHERE type=$type";
2006 return combo_input($name, $selected_id, $sql, 'id', 'description',
2009 'order' => 'description',
2010 'select_submit'=> $submit_on_change,
2016 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2018 echo "<td>$label</td><td>\n";
2019 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2023 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2026 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2031 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2033 global $quick_actions;
2035 echo "<tr><td>$label</td><td>";
2036 echo array_selector($name, $selected_id, $quick_actions,
2038 'select_submit'=> $submit_on_change
2040 echo "</td></tr>\n";
2043 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2045 global $quick_entry_types;
2047 echo "<tr><td>$label</td><td>";
2048 echo array_selector($name, $selected_id, $quick_entry_types,
2050 'select_submit'=> $submit_on_change
2052 echo "</td></tr>\n";
2055 function record_status_list_row($label, $name) {
2056 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2059 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2061 global $class_types;
2063 echo "<tr><td>$label</td><td>";
2064 echo array_selector($name, $selected_id, $class_types,
2066 'select_submit'=> $submit_on_change
2068 echo "</td></tr>\n";
2071 //------------------------------------------------------------------------------------------------
2073 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2074 $show_inactive = false)
2078 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2080 return combo_input($name, $selected_id, $sql, 'id', 'description',
2082 'spec_option'=>$new_item ? _("New role") : false,
2084 'select_submit'=> $submit_on_change,
2085 'show_inactive' => $show_inactive
2089 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2090 $show_inactive = false)
2093 echo "<td>$label</td>\n";
2095 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2099 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2100 $show_inactive = false)
2103 security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2107 function tab_list_row($label, $name, $selected_id=null, $all = false)
2109 global $installed_extensions;
2112 foreach ($_SESSION['App']->applications as $app) {
2113 $tabs[$app->id] = access_string($app->name, true);
2115 if ($all) { // add also not active ext. modules
2116 foreach ($installed_extensions as $ext) {
2117 if ($ext['type'] == 'module' && !$ext['active'])
2118 $tabs[$ext['tab']] = access_string($ext['title'], true);
2122 echo "<td>$label</td><td>\n";
2123 echo array_selector($name, $selected_id, $tabs);
2124 echo "</td></tr>\n";
2127 //-----------------------------------------------------------------------------------------------
2129 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2132 global $path_to_root;
2133 include_once($path_to_root . "/admin/db/tags_db.inc");
2134 $results = get_tags($type, $all);
2136 while ($tag = db_fetch($results))
2137 $tags[$tag['id']] = $tag['name'];
2139 if (!isset($tags)) {
2140 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2143 return array_selector($name, null, $tags,
2146 'height' => $height,
2147 'spec_option'=> $spec_opt,
2152 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2155 echo "<td>$label</td>\n";
2157 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2162 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2165 tag_list_cells($label, $name, $height, $type, $mult, $all, $spec_opt);
2169 //---------------------------------------------------------------------------------------------
2170 // List of sets of active extensions
2172 function extset_list($name, $value=null, $submit_on_change=false)
2174 global $db_connections;
2177 foreach ($db_connections as $comp)
2178 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2179 return array_selector( $name, $value, $items,
2181 'spec_option'=> _("Available and/or installed"),
2183 'select_submit'=> $submit_on_change,