+/*
+ Helper function.
+ Returns true if selector $name is subject to update.
+*/
+function list_updated($name)
+{
+ return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
+}
+//----------------------------------------------------------------------------------------------
+// Universal array combo generator
+// $items is array of options 'value' => 'description'
+// Options is reduced set of combo_selector options and is merged with defaults.
+
+function array_selector($name, $selected_id, $items, $options=null)
+{
+ global $Ajax;
+
+$opts = array( // default options
+ 'spec_option'=>false, // option text or false
+ 'spec_id' => 0, // option id
+ 'select_submit' => false, //submit on select: true/false
+ 'edit_submit' => false, // call editor on F4
+ 'async' => true, // select update via ajax (true) vs _page_body reload
+ 'default' => '', // default value when $_POST is not set
+ // search box parameters
+ 'sel_hint' => null,
+ 'disabled' => false
+);
+// ------ merge options with defaults ----------
+ if($options != null)
+ $opts = array_merge($opts, $options);
+ $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
+ $spec_id = $opts['spec_id'];
+ $spec_option = $opts['spec_option'];
+ $disabled = $opts['disabled'] ? "disabled" : '';
+
+ if ($selected_id == null) {
+ $selected_id = get_post($name, $opts['default']);
+ }
+
+ if (isset($_POST[$select_submit])) {
+ if (!$opts['async'])
+ $Ajax->activate('_page_body');
+ else
+ $Ajax->activate($name);
+ }
+
+ // ------ make selector ----------
+ $selector = $first_opt = '';
+ $first_id = false;
+ $found = false;
+//if($name=='SelectStockFromList') display_error($sql);
+ foreach($items as $value=>$descr) {
+ $sel = '';
+ if ($selected_id == $value) {
+ $sel = 'selected';
+ $found = $value;
+ }
+ if ($first_id === false) {
+ $first_id = $value;
+ $first_opt = $descr;
+ }
+ $selector .= "<option $sel value='$value'>$descr</option>\n";
+ }
+
+ // Prepend special option.
+ if ($spec_option !== false) { // if special option used - add it
+ $first_id = $spec_id;
+ $first_opt = $spec_option;
+ $sel = $found===false ? 'selected' : '';
+ $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
+ . $selector;
+ }
+
+ if ($found === false) {
+ $_POST[$name] = $first_id;
+ }
+
+ $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
+ $selector = "<select $disabled name='$name' class='combo' title='"
+ . $opts['sel_hint']."'$aspect >".$selector."</select>\n";
+
+ $Ajax->addUpdate($name, "_{$name}_sel", $selector);
+
+ $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
+
+ if ($select_submit != false) { // if submit on change is used - add select button
+ global $_select_button;
+ $selector .= sprintf($_select_button, $disabled, user_theme(),
+ (fallback_mode() ? '' : 'display:none;'),
+ $select_submit)."\n";
+ }
+ default_focus($name);
+ echo $selector;
+
+ return $selector;
+}
+//----------------------------------------------------------------------------------------------
+
+function _format_add_curr($row)
+{
+ static $company_currency;
+
+ if ($company_currency == null)
+ {
+ $company_currency = get_company_currency();
+ }
+ return $row[1] . ($row[2] == $company_currency ?
+ '' : (" - " . $row[2]));
+}
+
+function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)