3 include_once($path_to_root . "/includes/banking.inc");
4 include_once($path_to_root . "/includes/reserved.inc");
5 include_once($path_to_root . "/includes/types.inc");
6 include_once($path_to_root . "/includes/current_user.inc");
8 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
9 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
11 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
12 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
14 $all_items = reserved_words::get_all();
16 //----------------------------------------------------------------------------
17 // Universal sql combo generator
18 // $sql must return selector values and selector texts in columns 0 & 1
19 // Options are merged with defaults.
21 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
26 $opts = array( // default options
27 'where'=> array(), // additional constraints
28 'order' => $namefield, // list sort order
29 // special option parameters
30 'spec_option'=>false, // option text or false
31 'spec_id' => 0, // option id
32 // submit on select parameters
33 'default' => '', // default value when $_POST is not set
34 'select_submit' => false, //submit on select: true/false
35 'edit_submit' => false, // call editor on F4
36 'async' => true, // select update via ajax (true) vs _page_body reload
37 // search box parameters
39 'search_box' => false, // name or true/false
40 'type' => 0, // type of extended selector:
41 // 0 - with (optional) visible search box, search by id
42 // 1 - with hidden search box, search by option text
43 // 2 - TODO reverse: box with hidden selector available via enter; this
44 // would be convenient for optional ad hoc adding of new item
45 'search_submit' => true, //search submit button: true/false
46 'size' => 8, // size and max of box tag
48 'cells' => false, // combo displayed as 2 <td></td> cells
49 'search' => array(), // sql field names to search
50 'format' => null, // format functions for regular options
52 'box_hint' => null // box/selectors hints; null = std see below
54 // ------ merge options with defaults ----------
56 $opts = array_merge($opts, $options);
57 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
59 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
60 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
61 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
62 $spec_id = $opts['spec_id'];
63 $spec_option = $opts['spec_option'];
64 $by_id = ($opts['type'] == 0);
65 $class = $by_id ? 'combo':'combo2';
66 $disabled = $opts['disabled'] ? "disabled" : '';
68 if(!count($opts['search'])) {
69 $opts['search'] = array($by_id ? $valfield : $namefield);
71 if ($opts['sel_hint'] === null)
72 $opts['sel_hint'] = $by_id || $search_box==false ?
73 '' : _('Press Space tab for search pattern entry');
75 if ($opts['box_hint'] === null)
76 $opts['box_hint'] = $search_box && $search_submit != false ?
77 ($by_id ? _('Enter code fragment to search or * for all')
78 : _('Enter description fragment to search or * for all')) :'';
80 if ($selected_id == null) {
81 $selected_id = get_post($name, $opts['default']);
83 $txt = get_post($search_box);
87 if (isset($_POST[$select_submit])) {
88 if ($by_id) $txt = $_POST[$name];
91 $Ajax->activate('_page_body');
93 $Ajax->activate($name);
96 // search related sql modifications
98 $rel = "rel='$search_box'"; // set relation to list
99 if ($opts['search_submit']) {
100 if (isset($_POST[$search_submit])) {
101 $selected_id = ''; // ignore selected_id while search
103 $Ajax->activate('_page_body');
105 $Ajax->activate($name);
108 if ($spec_option === false && $selected_id==null)
111 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
116 foreach($opts['search'] as $i=> $s)
117 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
118 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
123 if (count($opts['where'])) {
124 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
125 $sql .= '('. implode($opts['where'], ' AND ') . ')';
127 if ($opts['order'] != false) {
128 $sql .= ' ORDER BY '.$opts['order'];
132 // ------ make selector ----------
133 $selector = $first_opt = '';
136 //if($name=='contact_sel') display_error($sql);
137 if($result = db_query($sql)) {
138 while ($contact_row = db_fetch($result)) {
139 $value = $contact_row[0];
140 $descr = $opts['format']==null ? $contact_row[1] :
141 call_user_func($opts['format'], $contact_row);
143 if (get_post($search_submit) && ($txt === $value)) {
144 $selected_id = $value;
146 if ((string)($selected_id) === $value) {
150 if ($first_id === false) {
154 $selector .= "<option $sel value='$value'>$descr</option>\n";
156 db_free_result($result);
159 // Prepend special option.
160 if ($spec_option !== false) { // if special option used - add it
161 $first_id = $spec_id;
162 $first_opt = $spec_option;
163 $sel = $found===false ? 'selected' : '';
164 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
168 if ($found === false) {
169 $selected_id = $first_id;
171 $_POST[$name] = $selected_id;
173 if ($by_id && $search_box != false) {
175 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
177 $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
178 $selector = "<select $disabled name='$name' class='$class' title='"
179 . $opts['sel_hint']."'$aspect $rel>".$selector."</select>\n";
181 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
183 // because of bug which M$ cannot fix since IE 5.0
184 // we must embed whole selector in span tags to enable proper ajax update
185 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
187 if ($select_submit != false) { // if submit on change is used - add select button
188 global $_select_button;
189 // button class selects form reload/ajax selector update
190 $selector .= sprintf($_select_button, $disabled, user_theme(),
191 (in_ajax() ? 'display:none;':''),
192 $select_submit)."\n";
194 // ------ make combo ----------
197 if ($search_box != false) {
198 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
199 $opts['size']."' maxlength='".$opts['max'].
200 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
201 .$opts['box_hint']."'"
202 .(in_ajax() && !$by_id ? " style=display:none;":'')
204 if ($search_submit != false) {
205 global $_search_button;
206 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
207 (in_ajax() ? 'display:none;':''),
208 $search_submit)."\n";
211 default_focus($name);
213 if ($search_box && $opts['cells'])
214 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
216 echo $edit_entry.$selector;
223 Returns true if selector $name is subject to update.
225 function list_updated($name)
227 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
229 //----------------------------------------------------------------------------------------------
230 // Universal array combo generator
231 // $items is array of options 'value' => 'description'
232 // Options is reduced set of combo_selector options and is merged with defaults.
234 function array_selector($name, $selected_id, $items, $options=null)
238 $opts = array( // default options
239 'spec_option'=>false, // option text or false
240 'spec_id' => 0, // option id
241 'select_submit' => false, //submit on select: true/false
242 'edit_submit' => false, // call editor on F4
243 'async' => true, // select update via ajax (true) vs _page_body reload
244 'default' => '', // default value when $_POST is not set
245 // search box parameters
249 // ------ merge options with defaults ----------
251 $opts = array_merge($opts, $options);
252 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
253 $spec_id = $opts['spec_id'];
254 $spec_option = $opts['spec_option'];
255 $disabled = $opts['disabled'] ? "disabled" : '';
257 if ($selected_id == null) {
258 $selected_id = get_post($name, $opts['default']);
261 if (isset($_POST[$select_submit])) {
263 $Ajax->activate('_page_body');
265 $Ajax->activate($name);
268 // ------ make selector ----------
269 $selector = $first_opt = '';
272 //if($name=='SelectStockFromList') display_error($sql);
273 foreach($items as $value=>$descr) {
275 if ($selected_id == $value) {
279 if ($first_id === false) {
283 $selector .= "<option $sel value='$value'>$descr</option>\n";
286 // Prepend special option.
287 if ($spec_option !== false) { // if special option used - add it
288 $first_id = $spec_id;
289 $first_opt = $spec_option;
290 $sel = $found===false ? 'selected' : '';
291 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
295 if ($found === false) {
296 $_POST[$name] = $first_id;
299 $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
300 $selector = "<select $disabled name='$name' class='combo' title='"
301 . $opts['sel_hint']."'$aspect >".$selector."</select>\n";
303 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
305 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
307 if ($select_submit != false) { // if submit on change is used - add select button
308 global $_select_button;
309 $selector .= sprintf($_select_button, $disabled, user_theme(),
310 (in_ajax() ? 'display:none;':''),
311 $select_submit)."\n";
313 default_focus($name);
318 //----------------------------------------------------------------------------------------------
320 function _format_add_curr($row)
322 static $company_currency;
324 if ($company_currency == null)
326 $company_currency = get_company_currency();
328 return $row[1] . ($row[2] == $company_currency ?
329 '' : (" - " . $row[2]));
332 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
336 $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
338 $mode = get_company_pref('no_supplier_list');
340 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
342 'format' => '_format_add_curr',
343 'search_box' => $mode!=0,
344 'edit_submit' => true,
346 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
347 'spec_id' => $all_items,
348 'select_submit'=> $submit_on_change,
350 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
355 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
358 echo "<td>$label</td><td>\n";
359 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
364 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
366 echo "<tr><td>$label</td><td>";
367 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
371 //----------------------------------------------------------------------------------------------
373 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
377 $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
379 $mode = get_company_pref('no_customer_list');
381 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
383 'format' => '_format_add_curr',
384 'search_box' => $mode!=0,
387 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
388 'spec_id' => $all_items,
389 'select_submit'=> $submit_on_change,
390 'edit_submit' => true, // call editor on F4
392 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F4 - entry new customer') :
397 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
400 echo "<td>$label</td>\n";
402 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
407 function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
409 echo "<tr><td>$label</td><td nowrap>";
410 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
411 echo "</td>\n</tr>\n";
415 //------------------------------------------------------------------------------------------------
417 function customer_branches_list($customer_id, $name, $selected_id=null,
418 $spec_option = true, $enabled=true, $submit_on_change=false)
422 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
423 WHERE debtor_no='" . $customer_id . "' ";
425 $where = $enabled ? array("disable_trans = 0") : array();
426 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
429 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
430 'spec_id' => $all_items,
431 'select_submit'=> $submit_on_change,
432 'sel_hint' => _('Select customer branch')
435 //------------------------------------------------------------------------------------------------
437 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
440 echo "<td>$label</td>\n";
442 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
447 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
450 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
455 //------------------------------------------------------------------------------------------------
457 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
461 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
463 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
465 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
466 'spec_id' => $all_items,
467 'select_submit'=> $submit_on_change
471 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
474 echo "<td>$label</td>\n";
476 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
481 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
484 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
489 //-----------------------------------------------------------------------------------------------
491 function currencies_list($name, $selected_id=null, $submit_on_change=false)
493 $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
495 // default to the company currency
497 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
499 'select_submit'=> $submit_on_change,
500 'default' => get_company_currency(),
505 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
508 echo "<td>$label</td>\n";
510 $str = currencies_list($name, $selected_id, $submit_on_change);
515 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
518 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
523 //---------------------------------------------------------------------------------------------------
525 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
528 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
530 // default to the company current fiscal year
532 return combo_input($name, $selected_id, $sql, 'id', '',
535 'default' => get_company_pref('f_year'),
536 'format' => '_format_fiscalyears',
537 'select_submit'=> $submit_on_change,
542 function _format_fiscalyears($row)
544 return sql2date($row[1]) . " - " . sql2date($row[2])
545 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
548 function fiscalyears_list_cells($label, $name, $selected_id=null)
551 echo "<td>$label</td>\n";
553 $str = fiscalyears_list($name, $selected_id);
558 function fiscalyears_list_row($label, $name, $selected_id=null)
561 $str = fiscalyears_list_cells($label, $name, $selected_id);
565 //------------------------------------------------------------------------------------
567 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
568 $submit_on_change=false, $showclosed=false, $showtype=1)
570 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
573 'order' => 'reference',
574 'spec_option'=>$no_option ? $showname : false,
576 'select_submit'=> $submit_on_change,
581 $options['where'][] = "closed=0";
583 $options['where'][] = "type_=$showtype";
585 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
588 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
589 $showclosed=false, $showtype=0)
592 echo "<td>$label</td>\n";
594 $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
599 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
600 $showclosed=false, $showtype=0)
603 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
604 $showclosed, $showtype);
609 //---------------------------------------------------------------------------------------------------
611 function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array())
615 $sql = "SELECT stock_id, s.description, c.description
616 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
618 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
621 'format' => '_format_stock_items',
622 'spec_option' => $all_option===true ? _("All Items") : $all_option,
623 'spec_id' => $all_items,
624 'search_box' => true,
625 'search' => array("stock_id", "c.description","s.description"),
626 'search_submit' => get_company_pref('no_item_list')!=0,
628 'select_submit'=> $submit_on_change
632 function _format_stock_items($row)
634 return (user_show_codes() ? ($row[0] . " - ") : "")
635 . $row[2] . " - " . $row[1];
638 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
641 echo "<td>$label</td>\n";
642 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
643 array('cells'=>true));
647 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
650 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
655 //------------------------------------------------------------------------------------
657 function base_stock_items_list($where, $name, $selected_id=null,
658 $all_option=false, $submit_on_change=false)
662 $sql = "SELECT stock_id, s.description, c.description
663 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
664 s.category_id=c.category_id";
666 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
668 'format' => '_format_stock_items',
669 'spec_option' => $all_option==true ? _("All Items") : $all_option,
670 'spec_id' => $all_items,
671 'select_submit'=> $submit_on_change,
675 //------------------------------------------------------------------------------------
677 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
680 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
681 $name, $selected_id, $all_option, $submit_on_change);
684 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
687 echo "<td>$label</td>\n";
689 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
694 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
697 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
702 //------------------------------------------------------------------------------------
704 function stock_manufactured_items_list($name, $selected_id=null,
705 $all_option=false, $submit_on_change=false)
707 return base_stock_items_list("s.mb_flag='M'",
708 $name, $selected_id, $all_option, $submit_on_change);
711 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
712 $all_option=false, $submit_on_change=false)
715 echo "<td>$label</td>\n";
717 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
723 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
724 $all_option=false, $submit_on_change=false)
727 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
728 $all_option, $submit_on_change);
732 //------------------------------------------------------------------------------------
734 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
735 $all_option=false, $submit_on_change=false)
737 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
738 array('where'=>array("stock_id != '$parent_stock_id'")));
742 function stock_component_items_list_cells($label, $name, $parent_stock_id,
743 $selected_id=null, $all_option=false, $submit_on_change=false)
746 echo "<td>$label</td>\n";
747 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
748 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
751 //------------------------------------------------------------------------------------
753 function stock_costable_items_list($name, $selected_id=null,
754 $all_option=false, $submit_on_change=false)
756 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
757 array('where'=>array("mb_flag!='D'")));
761 function stock_costable_items_list_cells($label, $name, $selected_id=null,
762 $all_option=false, $submit_on_change=false)
765 echo "<td>$label</td>\n";
766 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
767 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
771 //------------------------------------------------------------------------------------
772 function stock_purchasable_items_list($name, $selected_id=null,
773 $all_option=false, $submit_on_change=false)
775 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
776 array('where'=>array("mb_flag!= 'M'"),
777 'edit_submit' => true));
781 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
782 $all_option=false, $submit_on_change=false)
785 echo "<td>$label</td>\n";
786 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
787 array('where'=>array("mb_flag!= 'M'"),
788 'edit_submit' => true,
793 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
794 $all_option=false, $submit_on_change=false)
797 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
798 $all_option, $submit_on_change);
803 //------------------------------------------------------------------------------------
805 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
808 'M' => _("Manufactured"),
809 'B' => _("Purchased"),
815 echo "<td>$label</td>\n";
818 array_selector($name, $selected_id, $types,
820 'select_submit'=> true,
821 'disabled' => !$enabled) );
825 function stock_units_list_row($label, $name, $value=null, $enabled=true)
827 $result = get_all_item_units();
830 echo "<td>$label</td>\n";
833 while($unit = db_fetch($result))
834 $units[$unit['abbr']] = $unit['name'];
836 array_selector($name, $value, $units,
838 'select_submit'=> true,
839 'disabled' => !$enabled) );
844 //------------------------------------------------------------------------------------
846 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
848 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
850 return combo_input($name, $selected_id, $sql, 'id', 'name',
852 'spec_option' => $none_option,
853 'spec_id' => reserved_words::get_all_numeric(),
854 'select_submit'=> $submit_on_change,
859 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
860 $submit_on_change=false)
863 echo "<td>$label</td>\n";
865 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
870 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
871 $submit_on_change=false)
874 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
879 //------------------------------------------------------------------------------------
881 function tax_groups_list($name, $selected_id=null,
882 $none_option=false, $submit_on_change=false)
884 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
886 return combo_input($name, $selected_id, $sql, 'id', 'name',
889 'spec_option' => $none_option,
891 'select_submit'=> $submit_on_change,
896 function tax_groups_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
899 echo "<td>$label</td>\n";
901 $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
906 function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
909 $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
914 //------------------------------------------------------------------------------------
916 function item_tax_types_list($name, $selected_id=null)
918 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
919 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
922 function item_tax_types_list_cells($label, $name, $selected_id=null)
925 echo "<td>$label</td>\n";
927 item_tax_types_list($name, $selected_id);
931 function item_tax_types_list_row($label, $name, $selected_id=null)
934 item_tax_types_list_cells($label, $name, $selected_id);
938 //------------------------------------------------------------------------------------
940 function shippers_list($name, $selected_id=null)
942 $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
943 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
946 function shippers_list_cells($label, $name, $selected_id=null)
949 echo "<td>$label</td>\n";
951 shippers_list($name, $selected_id);
955 function shippers_list_row($label, $name, $selected_id=null)
958 shippers_list_cells($label, $name, $selected_id);
962 //-------------------------------------------------------------------------------------
964 function sales_persons_list($name, $selected_id=null)
966 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
967 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
970 function sales_persons_list_cells($label, $name, $selected_id=null)
973 echo "<td>$label</td>\n";
975 sales_persons_list($name, $selected_id);
979 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
982 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
986 //------------------------------------------------------------------------------------
988 function sales_areas_list($name, $selected_id=null)
990 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
991 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
994 function sales_areas_list_cells($label, $name, $selected_id=null)
997 echo "<td>$label</td>\n";
999 sales_areas_list($name, $selected_id);
1003 function sales_areas_list_row($label, $name, $selected_id=null)
1006 sales_areas_list_cells($label, $name, $selected_id);
1010 //------------------------------------------------------------------------------------
1012 function workorders_list($name, $selected_id=null)
1014 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1015 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1018 function workorders_list_cells($label, $name, $selected_id=null)
1021 echo "<td>$label</td>\n";
1023 workorders_list($name, $selected_id);
1027 function workorders_list_row($label, $name, $selected_id=null)
1030 workorders_list_cells($label, $name, $selected_id);
1034 //------------------------------------------------------------------------------------
1036 function payment_terms_list($name, $selected_id=null)
1038 $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
1039 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1042 function payment_terms_list_cells($label, $name, $selected_id=null)
1045 echo "<td>$label</td>\n";
1047 payment_terms_list($name, $selected_id);
1051 function payment_terms_list_row($label, $name, $selected_id=null)
1054 payment_terms_list_cells($label, $name, $selected_id);
1058 //------------------------------------------------------------------------------------
1060 function credit_status_list($name, $selected_id=null)
1062 $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
1063 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1066 function credit_status_list_cells($label, $name, $selected_id=null)
1069 echo "<td>$label</td>\n";
1071 credit_status_list($name, $selected_id);
1075 function credit_status_list_row($label, $name, $selected_id=null)
1078 credit_status_list_cells($label, $name, $selected_id);
1082 //-----------------------------------------------------------------------------------------------
1084 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1086 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
1088 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1090 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1092 'select_submit'=> $submit_on_change,
1093 // 'async' => false,
1097 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1100 echo "<td>$label</td>\n";
1102 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1107 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1110 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1115 //-----------------------------------------------------------------------------------------------
1117 function movement_types_list($name, $selected_id=null)
1119 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1120 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1123 function movement_types_list_cells($label, $name, $selected_id=null)
1126 echo "<td>$label</td>\n";
1128 movement_types_list($name, $selected_id);
1132 function movement_types_list_row($label, $name, $selected_id=null)
1135 movement_types_list_cells($label, $name, $selected_id);
1139 //-----------------------------------------------------------------------------------------------
1141 function bank_trans_types_list($name, $selected_id=null)
1143 $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1144 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1147 function bank_trans_types_list_cells($label, $name, $selected_id=null)
1150 echo "<td>$label</td>\n";
1152 bank_trans_types_list($name, $selected_id);
1156 function bank_trans_types_list_row($label, $name, $selected_id=null)
1159 bank_trans_types_list_cells($label, $name, $selected_id);
1163 //-----------------------------------------------------------------------------------------------
1165 function workcenter_list($name, $selected_id=null, $all_option=false)
1169 $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1171 return combo_input($name, $selected_id, $sql, 'id', 'name',
1173 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1174 'spec_id' => $all_items,
1178 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1180 default_focus($name);
1182 echo "<td>$label</td>\n";
1184 workcenter_list($name, $selected_id, $all_option);
1188 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1191 workcenter_list_cells($label, $name, $selected_id, $all_option);
1195 //-----------------------------------------------------------------------------------------------
1197 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1199 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1200 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1201 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1203 return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1205 'format' => '_format_add_curr',
1206 'select_submit'=> $submit_on_change,
1211 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1214 echo "<td>$label</td>\n";
1216 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1221 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1224 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1229 //-----------------------------------------------------------------------------------------------
1231 function class_list($name, $selected_id=null, $submit_on_change=false)
1233 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1235 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1237 'select_submit'=> $submit_on_change,
1243 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1246 echo "<td>$label</td>\n";
1248 $str = class_list($name, $selected_id, $submit_on_change);
1253 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1256 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1261 //-----------------------------------------------------------------------------------------------
1263 function stock_categories_list($name, $selected_id=null)
1265 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1266 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1267 array('order'=>'category_id'));
1270 function stock_categories_list_cells($label, $name, $selected_id=null)
1273 echo "<td>$label</td>\n";
1275 stock_categories_list($name, $selected_id);
1279 function stock_categories_list_row($label, $name, $selected_id=null)
1282 stock_categories_list_cells($label, $name, $selected_id);
1286 //-----------------------------------------------------------------------------------------------
1288 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1292 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1294 combo_input($name, $selected_id, $sql, 'id', 'name',
1297 'spec_option' =>$all_option,
1298 'spec_id' => $all_option_numeric ? 0 : $all_items
1302 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1303 $all_option_numeric=false)
1306 echo "<td>$label</td>\n";
1308 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1312 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1313 $all_option_numeric=false)
1316 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1317 $all_option_numeric);
1321 //-----------------------------------------------------------------------------------------------
1322 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1323 $show_group=false, $cells=false, $all_option=false, $submit_on_change=false)
1325 if ($skip_bank_accounts)
1326 $sql = "SELECT chart.account_code, chart.account_name, type.name
1327 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1328 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1329 ."ON chart.account_code=acc.account_code
1330 WHERE acc.account_code IS NULL
1331 AND chart.account_type=type.id";
1333 $sql = "SELECT chart.account_code, chart.account_name, type.name
1334 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1335 WHERE chart.account_type=type.id";
1337 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1339 'format' => '_format_account' . ($show_group ? '2' : ''),
1340 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1342 'order' => 'account_code',
1343 'search_box' => $cells,
1344 'search_submit' => false,
1348 'select_submit'=> $submit_on_change,
1354 function _format_account($row)
1356 return $row[0] . " " . $row[1];
1359 function _format_account2($row)
1361 return $row[0] . " " . $row[2] . " " . $row[1];
1364 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1365 $show_group=false, $cells=false, $all_option=false)
1368 echo "<td>$label</td>\n";
1370 gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1374 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1375 $show_group=false, $cells=false, $all_option=false)
1378 gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1379 $show_group, $cells, $all_option);
1383 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1386 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1387 $items['0'] = strlen($name_no) ? $name_no : _("No");
1389 return array_selector($name, $selected_id, $items,
1391 'select_submit'=> $submit_on_change,
1392 'async' => false ) ); // FIX?
1395 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1398 echo "<td>$label</td>\n";
1400 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1405 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1408 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1413 //------------------------------------------------------------------------------------------------
1415 function languages_list($name, $selected_id=null)
1417 global $installed_languages;
1420 foreach ($installed_languages as $lang)
1421 $items[$lang['code']] = $lang['name'];
1423 return array_selector($name, $selected_id, $items );
1426 function languages_list_cells($label, $name, $selected_id=null)
1429 echo "<td>$label</td>\n";
1431 languages_list($name, $selected_id);
1435 function languages_list_row($label, $name, $selected_id=null)
1438 languages_list_cells($label, $name, $selected_id);
1442 //------------------------------------------------------------------------------------------------
1444 function bank_account_types_list($name, $selected_id=null)
1446 $types = bank_account_types::get_all();
1449 foreach ($types as $type)
1451 $items[$type['id']] = $type['name'];
1454 return array_selector($name, $selected_id, $items );
1457 function bank_account_types_list_cells($label, $name, $selected_id=null)
1460 echo "<td>$label</td>\n";
1462 bank_account_types_list($name, $selected_id);
1466 function bank_account_types_list_row($label, $name, $selected_id=null)
1469 bank_account_types_list_cells($label, $name, $selected_id);
1473 //------------------------------------------------------------------------------------------------
1474 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1476 $types = payment_person_types::get_all();
1479 foreach ($types as $type)
1481 if (payment_person_types::has_items($type['id']))
1483 $items[$type['id']] = $type['name'];
1487 return array_selector($name, $selected_id, $items,
1488 array( 'select_submit'=> $submit_on_change ) );
1491 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1494 echo "<td>$label</td>\n";
1496 $str = payment_person_types_list($name, $selected_id, $related);
1501 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1504 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1509 //------------------------------------------------------------------------------------------------
1511 function wo_types_list($name, $selected_id=null)
1513 $types = wo_types::get_all();
1516 foreach ($types as $type)
1517 $items[$type['id']] = $type['name'];
1519 return array_selector($name, $selected_id, $items,
1520 array( 'select_submit'=> true, 'async' => true ) );
1523 function wo_types_list_row($label, $name, $selected_id=null)
1525 echo "<tr><td>$label</td><td>\n";
1526 $str = wo_types_list($name, $selected_id);
1527 echo "</td></tr>\n";
1531 //------------------------------------------------------------------------------------------------
1533 function dateformats_list_row($label, $name, $value=null)
1535 global $dateformats;
1537 echo "<tr><td>$label</td>\n<td>";
1538 array_selector( $name, $value, $dateformats );
1539 echo "</td></tr>\n";
1542 function dateseps_list_row($label, $name, $value=null)
1546 echo "<tr><td>$label</td>\n<td>";
1547 array_selector( $name, $value, $dateseps );
1548 echo "</td></tr>\n";
1551 function thoseps_list_row($label, $name, $value=null)
1555 echo "<tr><td>$label</td>\n<td>";
1556 array_selector( $name, $value, $thoseps );
1557 echo "</td></tr>\n";
1560 function decseps_list_row($label, $name, $value=null)
1564 echo "<tr><td>$label</td>\n<td>";
1565 array_selector( $name, $value, $decseps );
1566 echo "</td></tr>\n";
1569 function themes_list_row($label, $name, $value=null)
1571 global $path_to_root;
1573 $path = $path_to_root.'/themes/';
1575 $themedir = opendir($path);
1576 while(false !== ($fname = readdir($themedir)))
1578 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1580 $themes[$fname] = $fname;
1585 echo "<tr><td>$label</td>\n<td>";
1586 array_selector( $name, $value, $themes );
1587 echo "</td></tr>\n";
1590 function pagesizes_list_row($label, $name, $value=null)
1595 foreach ($pagesizes as $pz)
1598 echo "<tr><td>$label</td>\n<td>";
1599 array_selector( $name, $value, $items );
1600 echo "</td></tr>\n";
1603 function security_headings_list_row($label, $name, $value=null)
1605 global $security_headings;
1607 echo "<tr><td>$label</td>\n<td>";
1608 array_selector( $name, $value, $security_headings );
1609 echo "</td></tr>\n";
1612 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1614 global $systypes_array;
1617 echo "<td>$label</td>\n";
1621 foreach ($systypes_array as $key=>$type)
1622 $items[$key] = $type['name'];
1624 $str = array_selector($name, $value, $items,
1626 'select_submit'=> $submit_on_change,
1634 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1637 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1642 function cust_allocations_list_cells($label, $name, $selected=null)
1650 $all_items=>_("All Types"),
1651 '1'=> _("Sales Invoices"),
1652 '2'=> _("Overdue Invoices"),
1653 '3' => _("Payments"),
1654 '4' => _("Credit Notes"),
1655 '5' => _("Delivery Notes")
1657 $str = array_selector($name, $selected, $allocs);
1662 function supp_allocations_list_cell($name, $selected=null)
1668 $all_items=>_("All Types"),
1669 '1'=> _("Invoices"),
1670 '2'=> _("Overdue Invoices"),
1671 '3' => _("Payments"),
1672 '4' => _("Credit Notes"),
1673 '5' => _("Overdue Credit Notes")
1675 $str = array_selector($name, $selected, $allocs);
1680 function policy_list_cells($label, $name, $selected=null)
1685 $str = array_selector($name, $selected,
1686 array( '' => _("Automatically put balance on back order"),
1687 'CAN' => _("Cancel any quantites not delivered")) );
1692 function policy_list_row($label, $name, $selected=null)
1695 policy_list_cells($label, $name, $selected);
1699 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1704 $str = array_selector($name, $selected,
1705 array( 'Return' => _("Items Returned to Inventory Location"),
1706 'WriteOff' => _("Items Written Off")),
1707 array( 'select_submit'=> $submit_on_change ) );
1712 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1715 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1720 function number_list($name, $selected, $from, $to, $no_option=false)
1723 for ($i = $from; $i <= $to; $i++)
1726 return array_selector($name, $selected, $items,
1727 array( 'spec_option' => $no_option,
1728 'spec_id' => reserved_words::get_all_numeric()) );
1731 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1736 number_list($name, $selected, $from, $to, $no_option);
1740 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1743 number_list_cells($label, $name, $selected, $from, $to, $no_option);
1747 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1748 $submit_on_change=true)
1750 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1751 ." GROUP BY profile";
1752 $result = db_query($sql, 'cannot get all profile names');
1753 $profiles = array();
1754 while($myrow=db_fetch($result)) {
1755 $profiles[$myrow['profile']] = $myrow['profile'];
1760 echo "<td>$label</td>\n";
1763 array_selector($name, $selected_id, $profiles,
1764 array( 'select_submit'=> $submit_on_change,
1765 'spec_option'=>$spec_opt,
1769 echo "</td></tr>\n";
1772 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1774 static $printers; // query only once for page display
1777 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
1778 $result = db_query($sql, 'cannot get all printers');
1779 $printers = array();
1780 while($myrow=db_fetch($result)) {
1781 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
1784 array_selector($name, $selected_id, $printers,
1785 array( 'select_submit'=> $submit_on_change,
1786 'spec_option'=>$spec_opt,