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 = $search_submit ? $search_submit : ($opts['editable'] ? '_'.$name.'_button' : 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);
116 // search related sql modifications
118 $rel = "rel='$search_box'"; // set relation to list
119 if ($opts['search_submit']) {
120 if (isset($_POST[$search_submit])) {
121 $selected_id = array(); // ignore selected_id while search
123 $Ajax->activate('_page_body');
125 $Ajax->activate($name);
128 if ($spec_option === false && $selected_id == array())
131 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
136 foreach($opts['search'] as $i=> $s)
137 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
138 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
143 if (count($opts['where'])) {
144 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
145 $where .= '('. implode($opts['where'], ' AND ') . ')';
146 $group_pos = strpos($sql, 'GROUP BY');
148 $group = substr($sql, $group_pos);
149 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
154 if ($opts['order'] != false) {
155 if (!is_array($opts['order']))
156 $opts['order'] = array($opts['order']);
157 $sql .= ' ORDER BY '.implode(',',$opts['order']);
161 // ------ make selector ----------
162 $selector = $first_opt = '';
167 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
168 //if($name=='stock_id') display_error($search_submit);
169 if($result = db_query($sql)) {
170 while ($contact_row = db_fetch($result)) {
171 $value = $contact_row[0];
172 $descr = $opts['format']==null ? $contact_row[1] :
173 call_user_func($opts['format'], $contact_row);
175 if (get_post($search_button) && ($txt == $value)) {
176 $selected_id[] = $value;
178 if (in_array($value, $selected_id)) {
181 $edit = $opts['editable'] && $contact_row['editable']
182 && ($_POST[$search_box] == $value)
185 break; // selected field is editable - abandon list construction
187 // show selected option even if inactive
188 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
191 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
193 if ($first_id === false) {
197 $cat = $contact_row[$opts['category']];
198 if ($opts['category'] !== false && $cat != $lastcat){
199 $selector .= "<optgroup label='".$cat."'>\n";
202 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
204 db_free_result($result);
207 // Prepend special option.
208 if ($spec_option !== false) { // if special option used - add it
209 $first_id = $spec_id;
210 $first_opt = $spec_option;
212 // if($first_id !== false) {
213 $sel = $found===false ? 'selected' : '';
214 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
215 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
219 if ($found===false) {
220 $selected_id = array($first_id);
223 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
225 $selector = "<select ".($multi ? "multiple" : '')
226 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
227 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
228 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
230 if ($by_id && ($search_box != false || $opts['editable']) ) {
231 // on first display show selector list
232 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
233 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
234 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
235 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
236 // if ($_POST['_focus'] == $name) {
237 set_focus($name.'_text'); // prevent lost focus
239 } else if (isset($_POST[$name.'_text']))
240 set_focus($name); // prevent lost focus
241 if (!$opts['editable'])
243 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
246 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
248 // span for select list/inut field update
249 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
251 // if selectable or editable list is used - add select button
252 if ($select_submit != false || $search_button) {
253 global $_select_button;
254 // button class selects form reload/ajax selector update
255 $selector .= sprintf($_select_button, $disabled, user_theme(),
256 (fallback_mode() ? '' : 'display:none;'),
257 '_'.$name.'_update')."\n";
259 // ------ make combo ----------
261 if ($search_box != false) {
262 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
263 $opts['size']."' maxlength='".$opts['max'].
264 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
265 .$opts['box_hint']."'"
266 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
268 if ($search_submit != false || $opts['editable']) {
269 global $_search_button;
270 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
271 (fallback_mode() ? '' : 'display:none;'),
272 $search_submit ? $search_submit : "_{$name}_button")."\n";
275 default_focus(($search_box && $by_id) ? $search_box : $name);
277 if ($search_box && $opts['cells'])
278 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
280 $str = $edit_entry.$selector;
286 Returns true if selector $name is subject to update.
288 function list_updated($name)
290 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
292 //----------------------------------------------------------------------------------------------
293 // Universal array combo generator
294 // $items is array of options 'value' => 'description'
295 // Options is reduced set of combo_selector options and is merged with defaults.
297 function array_selector($name, $selected_id, $items, $options=null)
301 $opts = array( // default options
302 'spec_option'=>false, // option text or false
303 'spec_id' => 0, // option id
304 'select_submit' => false, //submit on select: true/false
305 'async' => true, // select update via ajax (true) vs _page_body reload
306 'default' => '', // default value when $_POST is not set
307 'multi'=>false, // multiple select
308 // search box parameters
309 'height' => false, // number of lines in select box
313 // ------ merge options with defaults ----------
315 $opts = array_merge($opts, $options);
316 $select_submit = $opts['select_submit'];
317 $spec_id = $opts['spec_id'];
318 $spec_option = $opts['spec_option'];
319 $disabled = $opts['disabled'] ? "disabled" : '';
320 $multi = $opts['multi'];
322 if ($selected_id == null) {
323 $selected_id = get_post($name, $opts['default']);
325 if(!is_array($selected_id))
326 $selected_id = array($selected_id); // code is generalized for multiple selection support
328 if (isset($_POST[ '_'.$name.'_update'])) {
330 $Ajax->activate('_page_body');
332 $Ajax->activate($name);
335 // ------ make selector ----------
336 $selector = $first_opt = '';
339 //if($name=='SelectStockFromList') display_error($sql);
340 foreach($items as $value=>$descr) {
342 if (in_array((string)$value, $selected_id)) {
346 if ($first_id === false) {
350 $selector .= "<option $sel value='$value'>$descr</option>\n";
353 // Prepend special option.
354 if ($spec_option !== false) { // if special option used - add it
355 $first_id = $spec_id;
356 $first_opt = $spec_option;
357 $sel = $found===false ? 'selected' : '';
358 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
362 if ($found===false) {
363 $selected_id = array($first_id);
365 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
366 $selector = "<select ".($multi ? "multiple" : '')
367 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
368 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
369 . $opts['sel_hint']."'>".$selector."</select>\n";
371 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
373 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
375 if ($select_submit != false) { // if submit on change is used - add select button
376 global $_select_button;
377 $selector .= sprintf($_select_button, $disabled, user_theme(),
378 (fallback_mode() ? '' : 'display:none;'),
379 '_'.$name.'_update')."\n";
381 default_focus($name);
385 //----------------------------------------------------------------------------------------------
387 function _format_add_curr($row)
389 static $company_currency;
391 if ($company_currency == null)
393 $company_currency = get_company_currency();
395 return $row[1] . ($row[2] == $company_currency ?
396 '' : (" - " . $row[2]));
399 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
400 $all=false, $editkey = false)
404 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
406 $mode = get_company_pref('no_supplier_list');
409 set_editor('supplier', $name, $editkey);
411 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
413 'format' => '_format_add_curr',
414 'order' => array('supp_ref'),
415 'search_box' => $mode!=0,
417 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
418 'spec_id' => $all_items,
419 'select_submit'=> $submit_on_change,
421 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
422 _('Select supplier'),
423 'show_inactive'=>$all
427 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
428 $submit_on_change=false, $all=false, $editkey = false)
431 echo "<td>$label</td><td>\n";
432 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
437 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
438 $submit_on_change=false, $all=false, $editkey = false)
440 echo "<tr><td>$label</td><td>";
441 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
445 //----------------------------------------------------------------------------------------------
447 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
448 $show_inactive=false, $editkey = false)
452 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
454 $mode = get_company_pref('no_customer_list');
457 set_editor('customer', $name, $editkey);
459 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
461 'format' => '_format_add_curr',
462 'order' => array('debtor_ref'),
463 'search_box' => $mode!=0,
466 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
467 'spec_id' => $all_items,
468 'select_submit'=> $submit_on_change,
470 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
471 _('Select customer'),
472 'show_inactive' => $show_inactive
476 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
477 $submit_on_change=false, $show_inactive=false, $editkey = false)
480 echo "<td>$label</td>\n";
482 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
483 $show_inactive, $editkey);
487 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
488 $submit_on_change=false, $show_inactive=false, $editkey = false)
490 echo "<tr><td>$label</td><td nowrap>";
491 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
492 $show_inactive, $editkey);
493 echo "</td>\n</tr>\n";
496 //------------------------------------------------------------------------------------------------
498 function customer_branches_list($customer_id, $name, $selected_id=null,
499 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
503 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
504 WHERE debtor_no='" . $customer_id . "' ";
507 set_editor('branch', $name, $editkey);
509 $where = $enabled ? array("disable_trans = 0") : array();
510 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
513 'order' => array('branch_ref'),
514 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
515 'spec_id' => $all_items,
516 'select_submit'=> $submit_on_change,
517 'sel_hint' => _('Select customer branch')
520 //------------------------------------------------------------------------------------------------
522 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
523 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
526 echo "<td>$label</td>\n";
528 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
529 $submit_on_change, $editkey);
533 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
534 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
537 customer_branches_list_cells($label, $customer_id, $name, $selected_id,
538 $all_option, $enabled, $submit_on_change, $editkey);
542 //------------------------------------------------------------------------------------------------
544 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
548 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
550 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
552 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
553 'spec_id' => $all_items,
554 'select_submit'=> $submit_on_change
558 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
561 echo "<td>$label</td>\n";
563 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
567 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
570 locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
574 //-----------------------------------------------------------------------------------------------
576 function currencies_list($name, $selected_id=null, $submit_on_change=false)
578 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
580 // default to the company currency
582 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
584 'select_submit'=> $submit_on_change,
585 'default' => get_company_currency(),
590 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
593 echo "<td>$label</td>\n";
595 echo currencies_list($name, $selected_id, $submit_on_change);
599 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
602 currencies_list_cells($label, $name, $selected_id, $submit_on_change);
606 //---------------------------------------------------------------------------------------------------
608 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
611 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
613 // default to the company current fiscal year
615 return combo_input($name, $selected_id, $sql, 'id', '',
618 'default' => get_company_pref('f_year'),
619 'format' => '_format_fiscalyears',
620 'select_submit'=> $submit_on_change,
625 function _format_fiscalyears($row)
627 return sql2date($row[1]) . " - " . sql2date($row[2])
628 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
631 function fiscalyears_list_cells($label, $name, $selected_id=null)
634 echo "<td>$label</td>\n";
636 echo fiscalyears_list($name, $selected_id);
640 function fiscalyears_list_row($label, $name, $selected_id=null)
643 fiscalyears_list_cells($label, $name, $selected_id);
646 //------------------------------------------------------------------------------------
648 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
649 $submit_on_change=false, $showclosed=false, $showtype=1)
651 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
654 'order' => 'reference',
655 'spec_option'=>$no_option ? $showname : false,
657 'select_submit'=> $submit_on_change,
662 $options['where'][] = "closed=0";
664 $options['where'][] = "type_=$showtype";
666 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
669 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
670 $showclosed=false, $showtype=0, $submit_on_change=false)
673 echo "<td>$label</td>\n";
675 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
679 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
680 $showclosed=false, $showtype=0, $submit_on_change=false)
683 dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
684 $showclosed, $showtype, $submit_on_change);
688 //---------------------------------------------------------------------------------------------------
690 function stock_items_list($name, $selected_id=null, $all_option=false,
691 $submit_on_change=false, $opts=array(), $editkey = false)
695 $sql = "SELECT stock_id, s.description, c.description, s.inactive
696 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
699 set_editor('item', $name, $editkey);
701 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
704 'format' => '_format_stock_items',
705 'spec_option' => $all_option===true ? _("All Items") : $all_option,
706 'spec_id' => $all_items,
707 'search_box' => true,
708 'search' => array("stock_id", "c.description","s.description"),
709 'search_submit' => get_company_pref('no_item_list')!=0,
711 'select_submit'=> $submit_on_change,
713 'order' => array('c.description','stock_id')
717 function _format_stock_items($row)
719 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
722 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
723 $submit_on_change=false, $all=false, $editkey = false)
726 echo "<td>$label</td>\n";
727 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
728 array('cells'=>true, 'show_inactive'=>$all), $editkey);
731 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
734 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
738 //---------------------------------------------------------------------------------------------------
740 // Select item via foreign code.
742 function sales_items_list($name, $selected_id=null, $all_option=false,
743 $submit_on_change=false, $type='', $opts=array())
747 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
748 i.inactive, if(count(*)>1, '0', s.editable) as editable
750 ".TB_PREF."stock_master s,
751 ".TB_PREF."item_codes i
753 ".TB_PREF."stock_category c
754 ON i.category_id=c.category_id
755 WHERE i.stock_id=s.stock_id";
758 if ($type == 'local') { // exclude foreign codes
759 $sql .= " AND !i.is_foreign";
760 } elseif ($type == 'kits') { // sales kits
761 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
763 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
764 $sql .= " GROUP BY i.item_code";
766 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
769 'format' => '_format_stock_items',
770 'spec_option' => $all_option===true ? _("All Items") : $all_option,
771 'spec_id' => $all_items,
772 'search_box' => true,
773 'search' => array("i.item_code", "c.description", "i.description"),
774 'search_submit' => get_company_pref('no_item_list')!=0,
776 'select_submit'=> $submit_on_change,
778 'order' => array('c.description','i.item_code'),
784 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
787 echo "<td>$label</td>\n";
788 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
789 '', array('cells'=>true));
792 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
794 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
795 'kits', array('cells'=>false, 'editable' => false));
798 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
802 echo "<td>$label</td>\n";
804 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
805 'local', array('cells'=>false, 'editable' => false));
808 //------------------------------------------------------------------------------------
810 function stock_manufactured_items_list($name, $selected_id=null,
811 $all_option=false, $submit_on_change=false)
813 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
814 array('where'=>array("mb_flag= 'M'")));
817 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
818 $all_option=false, $submit_on_change=false)
821 echo "<td>$label</td>\n";
823 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
827 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
828 $all_option=false, $submit_on_change=false)
831 stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
834 //------------------------------------------------------------------------------------
836 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
837 $all_option=false, $submit_on_change=false, $editkey = false)
839 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
840 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
843 function stock_component_items_list_cells($label, $name, $parent_stock_id,
844 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
847 echo "<td>$label</td>\n";
848 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
849 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
852 //------------------------------------------------------------------------------------
854 function stock_costable_items_list($name, $selected_id=null,
855 $all_option=false, $submit_on_change=false)
857 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
858 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 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
867 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
870 //------------------------------------------------------------------------------------
871 function stock_purchasable_items_list($name, $selected_id=null,
872 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
874 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
875 array('where'=>array("mb_flag!= 'M'"),
876 'show_inactive'=>$all), $editkey);
879 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
880 $all_option=false, $submit_on_change=false, $editkey=false)
883 echo "<td>$label</td>\n";
884 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
885 array('where'=>array("mb_flag!= 'M'"),
886 'cells'=>true), $editkey);
889 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
890 $all_option=false, $submit_on_change=false, $editkey=false)
893 stock_purchasable_items_list_cells($label, $name, $selected_id=null,
894 $all_option, $submit_on_change, $editkey);
898 //------------------------------------------------------------------------------------
900 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
906 echo "<td>$label</td>\n";
909 echo array_selector($name, $selected_id, $stock_types,
911 'select_submit'=> true,
912 'disabled' => !$enabled) );
916 function stock_units_list_row($label, $name, $value=null, $enabled=true)
918 $result = get_all_item_units();
921 echo "<td>$label</td>\n";
924 while($unit = db_fetch($result))
925 $units[$unit['abbr']] = $unit['name'];
927 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
932 //------------------------------------------------------------------------------------
934 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
936 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
938 return combo_input($name, $selected_id, $sql, 'id', 'name',
940 'spec_option' => $none_option,
941 'spec_id' => ALL_NUMERIC,
942 'select_submit'=> $submit_on_change,
947 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
948 $submit_on_change=false)
951 echo "<td>$label</td>\n";
953 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
957 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
958 $submit_on_change=false)
961 tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
965 //------------------------------------------------------------------------------------
967 function tax_groups_list($name, $selected_id=null,
968 $none_option=false, $submit_on_change=false)
970 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
972 return combo_input($name, $selected_id, $sql, 'id', 'name',
975 'spec_option' => $none_option,
976 'spec_id' => ALL_NUMERIC,
977 'select_submit'=> $submit_on_change,
982 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
985 echo "<td>$label</td>\n";
987 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
991 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
994 tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
998 //------------------------------------------------------------------------------------
1000 function item_tax_types_list($name, $selected_id=null)
1002 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1003 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1006 function item_tax_types_list_cells($label, $name, $selected_id=null)
1009 echo "<td>$label</td>\n";
1011 echo item_tax_types_list($name, $selected_id);
1015 function item_tax_types_list_row($label, $name, $selected_id=null)
1018 item_tax_types_list_cells($label, $name, $selected_id);
1022 //------------------------------------------------------------------------------------
1024 function shippers_list($name, $selected_id=null)
1026 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1027 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1028 array('order'=>array('shipper_name')));
1031 function shippers_list_cells($label, $name, $selected_id=null)
1034 echo "<td>$label</td>\n";
1036 echo shippers_list($name, $selected_id);
1040 function shippers_list_row($label, $name, $selected_id=null)
1043 shippers_list_cells($label, $name, $selected_id);
1047 //-------------------------------------------------------------------------------------
1049 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1051 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1052 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1053 array('order'=>array('salesman_name'),
1054 'spec_option' => $spec_opt,
1055 'spec_id' => ALL_NUMERIC));
1058 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1061 echo "<td>$label</td>\n";
1063 echo sales_persons_list($name, $selected_id, $spec_opt);
1067 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1070 sales_persons_list_cells($label, $name, $selected_id, $spec_opt);
1074 //------------------------------------------------------------------------------------
1076 function sales_areas_list($name, $selected_id=null)
1078 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1079 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1082 function sales_areas_list_cells($label, $name, $selected_id=null)
1085 echo "<td>$label</td>\n";
1087 echo sales_areas_list($name, $selected_id);
1091 function sales_areas_list_row($label, $name, $selected_id=null)
1094 sales_areas_list_cells($label, $name, $selected_id);
1098 //------------------------------------------------------------------------------------
1100 function sales_groups_list($name, $selected_id=null, $special_option=false)
1102 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1103 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1104 'spec_option' => $special_option===true ? ' ' : $special_option,
1105 'order' => 'description', 'spec_id' => 0,
1109 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1112 echo "<td>$label</td>\n";
1114 echo sales_groups_list($name, $selected_id, $special_option);
1118 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1121 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1125 //------------------------------------------------------------------------------------
1127 function _format_template_items($row)
1129 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1132 function templates_list($name, $selected_id=null, $special_option=false)
1134 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1135 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1136 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1137 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1138 'format' => '_format_template_items',
1139 'spec_option' => $special_option===true ? ' ' : $special_option,
1140 'order' => 'order_no', 'spec_id' => 0,
1144 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1147 echo "<td>$label</td>\n";
1149 echo templates_list($name, $selected_id, $special_option);
1153 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1156 templates_list_cells($label, $name, $selected_id, $special_option);
1160 //------------------------------------------------------------------------------------
1162 function workorders_list($name, $selected_id=null)
1164 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1165 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1168 function workorders_list_cells($label, $name, $selected_id=null)
1171 echo "<td>$label</td>\n";
1173 echo workorders_list($name, $selected_id);
1177 function workorders_list_row($label, $name, $selected_id=null)
1180 workorders_list_cells($label, $name, $selected_id);
1184 //------------------------------------------------------------------------------------
1186 function payment_terms_list($name, $selected_id=null)
1188 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1189 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1192 function payment_terms_list_cells($label, $name, $selected_id=null)
1195 echo "<td>$label</td>\n";
1197 echo payment_terms_list($name, $selected_id);
1201 function payment_terms_list_row($label, $name, $selected_id=null)
1204 payment_terms_list_cells($label, $name, $selected_id);
1208 //------------------------------------------------------------------------------------
1210 function credit_status_list($name, $selected_id=null)
1212 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1213 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1216 function credit_status_list_cells($label, $name, $selected_id=null)
1219 echo "<td>$label</td>\n";
1221 echo credit_status_list($name, $selected_id);
1225 function credit_status_list_row($label, $name, $selected_id=null)
1228 credit_status_list_cells($label, $name, $selected_id);
1232 //-----------------------------------------------------------------------------------------------
1234 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1236 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1238 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1240 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1242 'select_submit'=> $submit_on_change,
1243 // 'async' => false,
1247 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1250 echo "<td>$label</td>\n";
1252 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1256 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1259 sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1263 //-----------------------------------------------------------------------------------------------
1265 function movement_types_list($name, $selected_id=null)
1267 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1268 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1271 function movement_types_list_cells($label, $name, $selected_id=null)
1274 echo "<td>$label</td>\n";
1276 echo movement_types_list($name, $selected_id);
1280 function movement_types_list_row($label, $name, $selected_id=null)
1283 movement_types_list_cells($label, $name, $selected_id);
1287 //-----------------------------------------------------------------------------------------------
1288 function _format_date($row)
1290 return sql2date($row['reconciled']);
1293 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1295 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1296 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1297 GROUP BY reconciled";
1298 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1300 'spec_option' => $special_option,
1301 'format' => '_format_date',
1303 'select_submit'=> $submit_on_change
1307 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1310 echo "<td>$label</td>\n";
1312 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1316 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1319 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1323 //-----------------------------------------------------------------------------------------------
1325 function workcenter_list($name, $selected_id=null, $all_option=false)
1329 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1331 return combo_input($name, $selected_id, $sql, 'id', 'name',
1333 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1334 'spec_id' => $all_items,
1338 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1340 default_focus($name);
1342 echo "<td>$label</td>\n";
1344 echo workcenter_list($name, $selected_id, $all_option);
1348 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1351 workcenter_list_cells($label, $name, $selected_id, $all_option);
1355 //-----------------------------------------------------------------------------------------------
1357 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1359 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1360 FROM ".TB_PREF."bank_accounts";
1362 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1364 'format' => '_format_add_curr',
1365 'select_submit'=> $submit_on_change,
1370 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1373 echo "<td>$label</td>\n";
1375 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1379 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1382 bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1385 //-----------------------------------------------------------------------------------------------
1387 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1389 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1390 FROM ".TB_PREF."bank_accounts
1391 WHERE ".TB_PREF."bank_accounts.account_type=3";
1394 echo "<tr><td>$label</td>\n";
1396 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1398 'format' => '_format_add_curr',
1399 'select_submit'=> $submit_on_change,
1402 echo "</td></tr>\n";
1404 //-----------------------------------------------------------------------------------------------
1406 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1408 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1410 default_focus($name);
1413 echo "<td>$label</td>\n";
1416 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1418 'select_submit'=> $submit_on_change,
1420 'spec_option' =>$spec_option,
1422 'order'=> array('pos_name')
1424 echo "</td></tr>\n";
1427 //-----------------------------------------------------------------------------------------------
1429 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1432 echo "<td>$label</td>\n";
1434 echo yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1437 //-----------------------------------------------------------------------------------------------
1439 function class_list($name, $selected_id=null, $submit_on_change=false)
1441 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1443 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1445 'select_submit'=> $submit_on_change,
1451 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1454 echo "<td>$label</td>\n";
1456 echo class_list($name, $selected_id, $submit_on_change);
1460 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1463 class_list_cells($label, $name, $selected_id, $submit_on_change);
1467 //-----------------------------------------------------------------------------------------------
1468 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1470 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1471 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1472 array('order'=>'category_id',
1473 'spec_option' => $spec_opt,
1475 'select_submit'=> $submit_on_change,
1480 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1483 echo "<td>$label</td>\n";
1485 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1489 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1492 stock_categories_list_cells($label, $name, $selected_id, $spec_opt, $submit_on_change);
1496 //-----------------------------------------------------------------------------------------------
1498 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all_option_numeric=true)
1502 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1504 return combo_input($name, $selected_id, $sql, 'id', 'name',
1507 'spec_option' =>$all_option,
1508 'spec_id' => $all_option_numeric ? 0 : $all_items
1512 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1513 $all_option_numeric=false)
1516 echo "<td>$label</td>\n";
1518 echo gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1522 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1523 $all_option_numeric=false)
1526 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1527 $all_option_numeric);
1531 //-----------------------------------------------------------------------------------------------
1532 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1533 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1535 if ($skip_bank_accounts)
1536 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1537 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1538 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1539 ."ON chart.account_code=acc.account_code
1540 WHERE acc.account_code IS NULL
1541 AND chart.account_type=type.id";
1543 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1544 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1545 WHERE chart.account_type=type.id";
1547 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1549 'format' => '_format_account',
1550 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1552 'order' => array('type.id','account_code'),
1553 'search_box' => $cells,
1554 'search_submit' => false,
1558 'select_submit'=> $submit_on_change,
1561 'show_inactive' => $all
1566 function _format_account($row)
1568 return $row[0] . " " . $row[1];
1571 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1572 $skip_bank_accounts=false, $cells=false, $all_option=false,
1573 $submit_on_change=false, $all=false)
1576 echo "<td>$label</td>\n";
1578 echo gl_all_accounts_list($name, $selected_id,
1579 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1583 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1584 $skip_bank_accounts=false, $cells=false, $all_option=false)
1587 gl_all_accounts_list_cells($label, $name, $selected_id,
1588 $skip_bank_accounts, $cells, $all_option);
1592 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1595 $items['0'] = strlen($name_no) ? $name_no : _("No");
1596 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1598 return array_selector($name, $selected_id, $items,
1600 'select_submit'=> $submit_on_change,
1601 'async' => false ) ); // FIX?
1604 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1607 echo "<td>$label</td>\n";
1609 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1613 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1616 yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1620 //------------------------------------------------------------------------------------------------
1622 function languages_list($name, $selected_id=null)
1624 global $installed_languages;
1627 foreach ($installed_languages as $lang)
1628 $items[$lang['code']] = $lang['name'];
1630 return array_selector($name, $selected_id, $items);
1633 function languages_list_cells($label, $name, $selected_id=null)
1636 echo "<td>$label</td>\n";
1638 echo languages_list($name, $selected_id);
1642 function languages_list_row($label, $name, $selected_id=null)
1645 languages_list_cells($label, $name, $selected_id);
1649 //------------------------------------------------------------------------------------------------
1651 function bank_account_types_list($name, $selected_id=null)
1653 global $bank_account_types;
1655 return array_selector($name, $selected_id, $bank_account_types);
1658 function bank_account_types_list_cells($label, $name, $selected_id=null)
1661 echo "<td>$label</td>\n";
1663 echo bank_account_types_list($name, $selected_id);
1667 function bank_account_types_list_row($label, $name, $selected_id=null)
1670 bank_account_types_list_cells($label, $name, $selected_id);
1674 //------------------------------------------------------------------------------------------------
1675 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1677 global $payment_person_types;
1680 foreach ($payment_person_types as $key=>$type)
1682 if ($key != PT_WORKORDER)
1683 $items[$key] = $type;
1685 return array_selector($name, $selected_id, $items,
1686 array( 'select_submit'=> $submit_on_change ) );
1689 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1692 echo "<td>$label</td>\n";
1694 echo payment_person_types_list($name, $selected_id, $related);
1698 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1701 payment_person_types_list_cells($label, $name, $selected_id, $related);
1705 //------------------------------------------------------------------------------------------------
1707 function wo_types_list($name, $selected_id=null)
1709 global $wo_types_array;
1711 return array_selector($name, $selected_id, $wo_types_array,
1712 array( 'select_submit'=> true, 'async' => true ) );
1715 function wo_types_list_row($label, $name, $selected_id=null)
1717 echo "<tr><td>$label</td><td>\n";
1718 echo wo_types_list($name, $selected_id);
1719 echo "</td></tr>\n";
1722 //------------------------------------------------------------------------------------------------
1724 function dateformats_list_row($label, $name, $value=null)
1726 global $dateformats;
1728 echo "<tr><td>$label</td>\n<td>";
1729 echo array_selector( $name, $value, $dateformats );
1730 echo "</td></tr>\n";
1733 function dateseps_list_row($label, $name, $value=null)
1737 echo "<tr><td>$label</td>\n<td>";
1738 echo array_selector( $name, $value, $dateseps );
1739 echo "</td></tr>\n";
1742 function thoseps_list_row($label, $name, $value=null)
1746 echo "<tr><td>$label</td>\n<td>";
1747 echo array_selector( $name, $value, $thoseps );
1748 echo "</td></tr>\n";
1751 function decseps_list_row($label, $name, $value=null)
1755 echo "<tr><td>$label</td>\n<td>";
1756 echo array_selector( $name, $value, $decseps );
1757 echo "</td></tr>\n";
1760 function themes_list_row($label, $name, $value=null)
1762 global $path_to_root;
1764 $path = $path_to_root.'/themes/';
1766 $themedir = opendir($path);
1767 while(false !== ($fname = readdir($themedir)))
1769 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1771 $themes[$fname] = $fname;
1776 echo "<tr><td>$label</td>\n<td>";
1777 echo array_selector( $name, $value, $themes );
1778 echo "</td></tr>\n";
1781 function pagesizes_list_row($label, $name, $value=null)
1786 foreach ($pagesizes as $pz)
1789 echo "<tr><td>$label</td>\n<td>";
1790 echo array_selector( $name, $value, $items );
1791 echo "</td></tr>\n";
1794 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false)
1796 global $systypes_array;
1798 return array_selector($name, $value, $systypes_array,
1800 'spec_option'=> $spec_opt,
1801 'spec_id' => ALL_NUMERIC,
1802 'select_submit'=> $submit_on_change,
1808 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1811 echo "<td>$label</td>\n";
1813 echo systypes_list($name, $value, false, $submit_on_change);
1817 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1820 systypes_list_cells($label, $name, $value, false, $submit_on_change);
1824 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1826 global $systypes_array;
1829 echo "<td>$label</td>\n";
1832 $items = $systypes_array;
1834 // exclude quotes, orders and dimensions
1835 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1836 ST_SALESQUOTE) as $excl)
1837 unset($items[$excl]);
1839 echo array_selector($name, $value, $items,
1841 'spec_option'=> _("All"),
1843 'select_submit'=> $submit_on_change,
1850 function cust_allocations_list_cells($label, $name, $selected=null)
1858 $all_items=>_("All Types"),
1859 '1'=> _("Sales Invoices"),
1860 '2'=> _("Overdue Invoices"),
1861 '3' => _("Payments"),
1862 '4' => _("Credit Notes"),
1863 '5' => _("Delivery Notes")
1865 echo array_selector($name, $selected, $allocs);
1869 function supp_allocations_list_cell($name, $selected=null)
1875 $all_items=>_("All Types"),
1876 '1'=> _("Invoices"),
1877 '2'=> _("Overdue Invoices"),
1878 '3' => _("Payments"),
1879 '4' => _("Credit Notes"),
1880 '5' => _("Overdue Credit Notes")
1882 echo array_selector($name, $selected, $allocs);
1886 function policy_list_cells($label, $name, $selected=null)
1891 echo array_selector($name, $selected,
1892 array( '' => _("Automatically put balance on back order"),
1893 'CAN' => _("Cancel any quantites not delivered")) );
1897 function policy_list_row($label, $name, $selected=null)
1900 policy_list_cells($label, $name, $selected);
1904 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1909 echo array_selector($name, $selected,
1910 array( 'Return' => _("Items Returned to Inventory Location"),
1911 'WriteOff' => _("Items Written Off")),
1912 array( 'select_submit'=> $submit_on_change ) );
1916 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1919 credit_type_list_cells($label, $name, $selected, $submit_on_change);
1923 function number_list($name, $selected, $from, $to, $no_option=false)
1926 for ($i = $from; $i <= $to; $i++)
1929 return array_selector($name, $selected, $items,
1930 array( 'spec_option' => $no_option,
1931 'spec_id' => ALL_NUMERIC) );
1934 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1939 echo number_list($name, $selected, $from, $to, $no_option);
1943 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1946 echo number_list_cells($label, $name, $selected, $from, $to, $no_option);
1950 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1951 $submit_on_change=true)
1953 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1954 ." GROUP BY profile";
1955 $result = db_query($sql, 'cannot get all profile names');
1956 $profiles = array();
1957 while($myrow=db_fetch($result)) {
1958 $profiles[$myrow['profile']] = $myrow['profile'];
1963 echo "<td>$label</td>\n";
1966 echo array_selector($name, $selected_id, $profiles,
1967 array( 'select_submit'=> $submit_on_change,
1968 'spec_option'=>$spec_opt,
1972 echo "</td></tr>\n";
1975 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1977 static $printers; // query only once for page display
1980 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
1981 $result = db_query($sql, 'cannot get all printers');
1982 $printers = array();
1983 while($myrow=db_fetch($result)) {
1984 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
1987 return array_selector($name, $selected_id, $printers,
1988 array( 'select_submit'=> $submit_on_change,
1989 'spec_option'=>$spec_opt,
1994 //------------------------------------------------------------------------------------------------
1996 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
1999 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2001 $sql .= " WHERE type=$type";
2003 return combo_input($name, $selected_id, $sql, 'id', 'description',
2006 'order' => 'description',
2007 'select_submit'=> $submit_on_change,
2013 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2015 echo "<td>$label</td><td>\n";
2016 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2020 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2023 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2028 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2030 global $quick_actions;
2032 echo "<tr><td>$label</td><td>";
2033 echo array_selector($name, $selected_id, $quick_actions,
2035 'select_submit'=> $submit_on_change
2037 echo "</td></tr>\n";
2040 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2042 global $quick_entry_types;
2044 echo "<tr><td>$label</td><td>";
2045 echo array_selector($name, $selected_id, $quick_entry_types,
2047 'select_submit'=> $submit_on_change
2049 echo "</td></tr>\n";
2052 function record_status_list_row($label, $name) {
2053 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2056 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2058 global $class_types;
2060 echo "<tr><td>$label</td><td>";
2061 echo array_selector($name, $selected_id, $class_types,
2063 'select_submit'=> $submit_on_change
2065 echo "</td></tr>\n";
2068 //------------------------------------------------------------------------------------------------
2070 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2071 $show_inactive = false)
2075 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2077 return combo_input($name, $selected_id, $sql, 'id', 'description',
2079 'spec_option'=>$new_item ? _("New role") : false,
2081 'select_submit'=> $submit_on_change,
2082 'show_inactive' => $show_inactive
2086 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2087 $show_inactive = false)
2090 echo "<td>$label</td>\n";
2092 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2096 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2097 $show_inactive = false)
2100 security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2104 function tab_list_row($label, $name, $selected_id=null, $all = false)
2106 global $installed_extensions;
2109 foreach ($_SESSION['App']->applications as $app) {
2110 $tabs[$app->id] = access_string($app->name, true);
2112 if ($all) { // add also not active ext. modules
2113 foreach ($installed_extensions as $ext) {
2114 if ($ext['type'] == 'module' && !$ext['active'])
2115 $tabs[$ext['tab']] = access_string($ext['title'], true);
2119 echo "<td>$label</td><td>\n";
2120 echo array_selector($name, $selected_id, $tabs);
2121 echo "</td></tr>\n";
2124 //-----------------------------------------------------------------------------------------------
2126 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2129 global $path_to_root;
2130 include_once($path_to_root . "/admin/db/tags_db.inc");
2131 $results = get_tags($type, $all);
2133 while ($tag = db_fetch($results))
2134 $tags[$tag['id']] = $tag['name'];
2136 if (!isset($tags)) {
2137 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2140 return array_selector($name, null, $tags,
2143 'height' => $height,
2144 'spec_option'=> $spec_opt,
2149 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2152 echo "<td>$label</td>\n";
2154 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2159 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2162 tag_list_cells($label, $name, $height, $type, $mult, $all, $spec_opt);
2166 //---------------------------------------------------------------------------------------------
2167 // List of sets of active extensions
2169 function extset_list($name, $value=null, $submit_on_change=false)
2171 global $db_connections;
2174 foreach ($db_connections as $comp)
2175 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2176 return array_selector( $name, $value, $items,
2178 'spec_option'=> _("Available and/or installed"),
2180 'select_submit'=> $submit_on_change,