X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_lists.inc;h=6170e79f41496303cda59347fc4fd520a38bb721;hb=cfaa5cec1f5137bcc1599a4306879e3265d1dacd;hp=72d2dd9c261f422a0be830b88780a9c4150ca64e;hpb=c232de82bc5c4e365b84550ee811e4d6bd9631d6;p=fa-stable.git diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 72d2dd9c..6170e79f 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 @@ -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 @@ -77,8 +76,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 +97,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 +141,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 '; @@ -203,11 +212,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); } @@ -255,9 +268,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"; } @@ -271,8 +283,7 @@ $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"; } @@ -328,7 +339,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']) @@ -345,27 +356,24 @@ $opts = array( // default options foreach($items as $value=>$descr) { $sel = ''; if (in_array((string)$value, $selected_id, true)) { - $sel = "selected='selected'"; + $sel = 'selected'; $found = $value; } if ($first_id === false) { $first_id = $value; - $first_opt = "\n"; - } - else { - $selector .= "\n"; + $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; } @@ -374,6 +382,7 @@ $opts = array( // default options $selected_id = array($first_id); } $_POST[$name] = $multi ? $selected_id : $selected_id[0]; + $selector = "