X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_lists.inc;h=f0c65e08417e3061b0f4fcf1867b0b467c069eb3;hb=2758ae02d6477d7e6df35f19f44fb08e38900f50;hp=6d24ed627e03096acf073a98241a1a5d1c217ba8;hpb=94bf640ca2382815f0fd54ee54adc823a9675123;p=fa-stable.git diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 6d24ed62..f0c65e08 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -13,13 +13,11 @@ include_once($path_to_root . "/includes/banking.inc"); include_once($path_to_root . "/includes/types.inc"); include_once($path_to_root . "/includes/current_user.inc"); -$_search_button = " "; +define('SEARCH_BUTTON', " "); -$_select_button = " "; - -$all_items = ALL_TEXT; +define('SELECT_BUTTON', " "); //---------------------------------------------------------------------------- // Universal sql combo generator @@ -27,9 +25,9 @@ $all_items = ALL_TEXT; // Options are merged with defaults. function combo_input($name, $selected_id, $sql, $valfield, $namefield, - $options=null) + $options=null, $type=null) { -global $Ajax; +global $Ajax, $path_to_root, $SysPrefs ; $opts = array( // default options 'where'=> array(), // additional constraints @@ -46,9 +44,10 @@ $opts = array( // default options 'sel_hint' => null, 'search_box' => false, // name or true/false 'type' => 0, // type of extended selector: - // 0 - with (optional) visible search box, search by id + // 0 - with (optional) visible search box, search by fragment inside id // 1 - with hidden search box, search by option text - // 2 - TODO reverse: box with hidden selector available via enter; this + // 2 - with (optional) visible search box, search by fragment at the start of id + // 3 - TODO reverse: box with hidden selector available via enter; this // would be convenient for optional ad hoc adding of new item 'search_submit' => true, //search submit button: true/false 'size' => 8, // size and max of box tag @@ -61,7 +60,8 @@ $opts = array( // default options 'box_hint' => null, // box/selectors hints; null = std see below 'category' => false, // category column name or false 'show_inactive' => false, // show inactive records. - 'editable' => false // false, or length of editable entry field + 'editable' => false, // false, or length of editable entry field + 'editlink' => false // link to entity entry/edit page (optional) ); // ------ merge options with defaults ---------- if($options != null) @@ -77,8 +77,17 @@ $opts = array( // default options $select_submit = $opts['select_submit']; $spec_id = $opts['spec_id']; $spec_option = $opts['spec_option']; - $by_id = ($opts['type'] == 0); - $class = $by_id ? 'combo':'combo2'; + if ($opts['type'] == 0) { + $by_id = true; + $class = 'combo'; + } elseif($opts['type'] == 1) { + $by_id = false; + $class = 'combo2'; + } else { + $by_id = true; + $class = 'combo3'; + } + $disabled = $opts['disabled'] ? "disabled" : ''; $multi = $opts['multi']; @@ -89,21 +98,20 @@ $opts = array( // default options $opts['sel_hint'] = $by_id || $search_box==false ? '' : _('Press Space tab for search pattern entry'); - if ($opts['box_hint'] === null) // dodaƦ hint dla pustego **** + if ($opts['box_hint'] === null) $opts['box_hint'] = $search_box && $search_submit != false ? ($by_id ? _('Enter code fragment to search or * for all') : _('Enter description fragment to search or * for all')) :''; if ($selected_id == null) { - $selected_id = get_post($name, $opts['default']); + $selected_id = get_post($name, (string)$opts['default']); } if(!is_array($selected_id)) - $selected_id = array($selected_id); // code is generalized for multiple selection support + $selected_id = array((string)$selected_id); // code is generalized for multiple selection support $txt = get_post($search_box); $rel = ''; $limit = ''; - if (isset($_POST['_'.$name.'_update'])) { // select list or search box change if ($by_id) $txt = $_POST[$name]; @@ -134,17 +142,19 @@ $opts = array( // default options if ($spec_option === false && $selected_id == array()) $limit = ' LIMIT 1'; else - $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'"; + $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id)); } else if ($txt != '*') { foreach($opts['search'] as $i=> $s) - $opts['search'][$i] = $s . " LIKE '%{$txt}%'"; + $opts['search'][$i] = $s . " LIKE " + .db_escape(($class=='combo3' ? '' : '%').$txt.'%'); $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')'; } } } + // sql completion if (count($opts['where'])) { $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND '; @@ -170,18 +180,20 @@ $opts = array( // default options $found = false; $lastcat = null; $edit = false; -//if($name=='stock_id') display_notification('
'.print_r($_POST, true).'
'); -//if($name=='curr_default') display_notification($opts['search_submit']); + $pname = false; + if (($type === "customer" || $type === "supplier") && !empty($SysPrefs->prefs['shortname_name_in_list'])) + $pname = true; if($result = db_query($sql)) { while ($contact_row = db_fetch($result)) { $value = $contact_row[0]; $descr = $opts['format']==null ? $contact_row[1] : - call_user_func($opts['format'], $contact_row); + call_user_func($opts['format'], $contact_row, $pname); $sel = ''; if (get_post($search_button) && ($txt == $value)) { $selected_id[] = $value; } - if (in_array($value, $selected_id)) { + + if (in_array((string)$value, $selected_id, true)) { $sel = 'selected'; $found = $value; $edit = $opts['editable'] && $contact_row['editable'] @@ -202,11 +214,15 @@ $opts = array( // default options } $cat = $contact_row[$opts['category']]; if ($opts['category'] !== false && $cat != $lastcat){ + if ($lastcat!==null) + $selector .= ""; $selector .= "\n"; $lastcat = $cat; } $selector .= "\n"; } + if ($lastcat!==null) + $selector .= ""; db_free_result($result); } @@ -214,8 +230,6 @@ $opts = array( // default options if ($spec_option !== false) { // if special option used - add it $first_id = $spec_id; $first_opt = $spec_option; -// } -// if($first_id !== false) { $sel = $found===false ? 'selected' : ''; $optclass = @$contact_row['inactive'] ? "class='inactive'" : ''; $selector = "\n" @@ -228,11 +242,16 @@ $opts = array( // default options $_POST[$name] = $multi ? $selected_id : $selected_id[0]; - $selector = "".$selector."\n"; + else + $selector = "\n"; - if ($by_id && ($search_box != false || $opts['editable']) ) { // on first display show selector list if (isset($_POST[$search_box]) && $opts['editable'] && $edit) { @@ -254,9 +273,8 @@ $opts = array( // default options // if selectable or editable list is used - add select button if ($select_submit != false || $search_button) { - global $_select_button; // button class selects form reload/ajax selector update - $selector .= sprintf($_select_button, $disabled, user_theme(), + $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(), (fallback_mode() ? '' : 'display:none;'), '_'.$name.'_update')."\n"; } @@ -270,18 +288,86 @@ $opts = array( // default options .(!fallback_mode() && !$by_id ? " style=display:none;":'') .">\n"; if ($search_submit != false || $opts['editable']) { - global $_search_button; - $edit_entry .= sprintf($_search_button, $disabled, user_theme(), + $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) { + 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 = ''; + } + } + + if ($opts['editlink']) + $selector .= ' '.$opts['editlink']; + if ($search_box && $opts['cells']) - $str = ($edit_entry!='' ? "$edit_entry" : '')."$selector"; + $str = ($edit_entry!='' ? "$edit_entry" : '')."$selector$img"; else - $str = $edit_entry.$selector; + $str = $edit_entry.$selector.$img; return $str; } @@ -327,7 +413,7 @@ $opts = array( // default options $selected_id = get_post($name, $opts['default']); } if(!is_array($selected_id)) - $selected_id = array($selected_id); // code is generalized for multiple selection support + $selected_id = array((string)$selected_id); // code is generalized for multiple selection support if (isset($_POST[ '_'.$name.'_update'])) { if (!$opts['async']) @@ -340,31 +426,27 @@ $opts = array( // default options $selector = $first_opt = ''; $first_id = false; $found = false; -//if($name=='SelectStockFromList') display_error($sql); - foreach($items as $value=>$descr) { - $sel = ''; - if (in_array((string)$value, $selected_id)) { - $sel = "selected='selected'"; - $found = $value; - } - if ($first_id === false) { - $first_id = $value; - $first_opt = "\n"; - } - else { - $selector .= "\n"; - } + 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 .= "\n"; + } if ($first_id!==false) { $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : ''; - $selector = sprintf($first_opt, $sel).$selector; } // 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='selected'" : ''; + $sel = $found===false ? 'selected' : ''; $selector = "\n" . $selector; } @@ -373,6 +455,7 @@ $opts = array( // default options $selected_id = array($first_id); } $_POST[$name] = $multi ? $selected_id : $selected_id[0]; + $selector = "