+// ------ make combo ----------
+ $edit_entry = '';
+ if ($search_box != false) {
+ $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
+ $opts['size']."' maxlength='".$opts['max'].
+ "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
+ .$opts['box_hint']."'"
+ .(!fallback_mode() && !$by_id ? " style=display:none;":'')
+ .">\n";
+ if ($search_submit != false || $opts['editable']) {
+ $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
+ (fallback_mode() ? '' : 'display:none;'),
+ $search_submit ? $search_submit : "_{$name}_button")."\n";
+ }
+ }
+ default_focus(($search_box && $by_id) ? $search_box : $name);
+
+ $img = "";
+ if ($SysPrefs->use_popup_search && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']))
+ {
+ $img_title = "";
+ $link = "";
+ $id = $name;
+ if ($SysPrefs->use_popup_windows) {
+ if ($type != NULL) {
+ switch (strtolower($type)) {
+ case "stock":
+ $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=all&client_id=" . $id;
+ $img_title = _("Search items");
+ break;
+ case "stock_manufactured":
+ $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=manufactured&client_id=" . $id;
+ $img_title = _("Search items");
+ break;
+ case "stock_purchased":
+ $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=purchasable&client_id=" . $id;
+ $img_title = _("Search items");
+ break;
+ case "stock_sales":
+ $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=sales&client_id=" . $id;
+ $img_title = _("Search items");
+ break;
+ case "stock_costable":
+ $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=costable&client_id=" . $id;
+ $img_title = _("Search items");
+ break;
+ case "component":
+ $parent = $opts['parent'];
+ $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=component&parent=".$parent."&client_id=" . $id;
+ $img_title = _("Search items");
+ break;
+ case "kits":
+ $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=kits&client_id=" . $id;
+ $img_title = _("Search items");
+ break;
+ case "customer":
+ $link = $path_to_root . "/sales/inquiry/customers_list.php?popup=1&client_id=" . $id;
+ $img_title = _("Search customers");
+ break;
+ case "branch":
+ $link = $path_to_root . "/sales/inquiry/customer_branches_list.php?popup=1&client_id=" . $id . "#customer_id";
+ $img_title = _("Search branches");
+ break;
+ case "supplier":
+ $link = $path_to_root . "/purchasing/inquiry/suppliers_list.php?popup=1&client_id=" . $id;
+ $img_title = _("Search suppliers");
+ break;
+ case "account":
+ case "account2":
+ $skip = strtolower($type) == "account" ? false : true;
+ $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&skip=".$skip."&client_id=" . $id;
+ $img_title = _("Search GL accounts");
+ break;
+ }
+ }
+ }
+
+ if ($link !=="") {
+ $theme = user_theme();
+ $img = '<img src="'.$path_to_root.'/themes/'.$theme.'/images/'.ICON_VIEW.
+ '" style="vertical-align:middle;width:12px;height:12px;border:0;" onclick="javascript:lookupWindow("'.
+ $link.'", "");" title="' . $img_title . '" style="cursor:pointer;" />';
+ }
+ }
+
+ if ($opts['editlink'])
+ $selector .= ' '.$opts['editlink'];
+
+ if ($search_box && $opts['cells'])
+ $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td nowrap>$selector$img</td>";
+ else
+ $str = $edit_entry.$selector.$img;
+ return $str;
+}
+
+/*
+ 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
+ 'async' => true, // select update via ajax (true) vs _page_body reload
+ 'default' => '', // default value when $_POST is not set
+ 'multi'=>false, // multiple select
+ // search box parameters
+ 'height' => false, // number of lines in select box
+ 'sel_hint' => null,
+ 'disabled' => false
+);
+// ------ merge options with defaults ----------
+ if($options != null)
+ $opts = array_merge($opts, $options);
+ $select_submit = $opts['select_submit'];
+ $spec_id = $opts['spec_id'];
+ $spec_option = $opts['spec_option'];
+ $disabled = $opts['disabled'] ? "disabled" : '';
+ $multi = $opts['multi'];
+
+ if ($selected_id == null) {
+ $selected_id = get_post($name, $opts['default']);
+ }
+ if(!is_array($selected_id))
+ $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
+
+ if (isset($_POST[ '_'.$name.'_update'])) {
+ if (!$opts['async'])
+ $Ajax->activate('_page_body');
+ else
+ $Ajax->activate($name);
+ }
+
+ // ------ make selector ----------
+ $selector = $first_opt = '';
+ $first_id = false;
+ $found = false;
+ foreach($items as $value=>$descr) {
+ $sel = '';
+ if (in_array((string)$value, $selected_id, true)) {
+ $sel = 'selected';
+ $found = $value;
+ }
+ if ($first_id === false) {
+ $first_id = $value;
+ $first_opt = $descr;
+ }
+ $selector .= "<option $sel value='$value'>$descr</option>\n";
+ }
+
+ if ($first_id!==false) {
+ $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
+ }
+ // 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) {
+ $selected_id = array($first_id);
+ }
+ $_POST[$name] = $multi ? $selected_id : $selected_id[0];
+
+ $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
+ . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
+ . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
+ . $opts['sel_hint']."'>".$selector."</select>\n";