X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_lists.inc;h=d7e2c964c511b3f16abdfc793ce33ff5c7683c15;hb=714ae79a3a7c96ef27a31a268cc0fef42a43e30d;hp=0ce2546a3e8c469c5618a39654aeb67ffe6b1249;hpb=d4f3d658b9c4767aba1f02bfc8e1581c29d231b1;p=fa-stable.git diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 0ce2546a..d7e2c964 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -1,5 +1,14 @@ . +***********************************************************************/ include_once($path_to_root . "/includes/banking.inc"); include_once($path_to_root . "/includes/reserved.inc"); include_once($path_to_root . "/includes/types.inc"); @@ -49,7 +58,8 @@ $opts = array( // default options 'search' => array(), // sql field names to search 'format' => null, // format functions for regular options 'disabled' => false, - 'box_hint' => null // box/selectors hints; null = std see below + 'box_hint' => null, // box/selectors hints; null = std see below + 'category' => false // category column name or false ); // ------ merge options with defaults ---------- if($options != null) @@ -121,11 +131,20 @@ $opts = array( // default options } // sql completion if (count($opts['where'])) { - $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND '; - $sql .= '('. implode($opts['where'], ' AND ') . ')'; + $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND '; + $where .= '('. implode($opts['where'], ' AND ') . ')'; + $group_pos = strpos($sql, 'GROUP BY'); + if ($group_pos) { + $group = substr($sql, $group_pos); + $sql = substr($sql, 0, $group_pos) . $where.' '.$group; + } else { + $sql .= $where; + } } if ($opts['order'] != false) { - $sql .= ' ORDER BY '.$opts['order']; + if (!is_array($opts['order'])) + $opts['order'] = array($opts['order']); + $sql .= ' ORDER BY '.implode(',',$opts['order']); } $sql .= $limit; @@ -133,16 +152,14 @@ $opts = array( // default options $selector = $first_opt = ''; $first_id = false; $found = false; -//if($name=='SelectStockFromList') display_error($sql); + $lastcat = null; +//if($name=='stock_id') display_error($sql); 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); $sel = ''; - if (get_post($search_submit) && ($txt === $value)) { - $selected_id = $value; - } if (get_post($search_submit) && ($txt === $value)) { $selected_id = $value; } @@ -154,6 +171,11 @@ $opts = array( // default options $first_id = $value; $first_opt = $descr; } + $cat = $contact_row[$opts['category']]; + if ($opts['category'] !== false && $cat != $lastcat){ + $selector .= "\n"; + $lastcat = $cat; + } $selector .= "\n"; } db_free_result($result); @@ -191,7 +213,7 @@ $opts = array( // default options global $_select_button; // button class selects form reload/ajax selector update $selector .= sprintf($_select_button, $disabled, user_theme(), - (in_ajax() ? 'display:none;':''), + (fallback_mode() ? '' : 'display:none;'), $select_submit)."\n"; } // ------ make combo ---------- @@ -202,16 +224,16 @@ $opts = array( // default options $opts['size']."' maxlength='".$opts['max']. "' value='$txt' class='$class' rel='$name' autocomplete='off' title='" .$opts['box_hint']."'" - .(in_ajax() && !$by_id ? " style=display:none;":'') + .(!fallback_mode() && !$by_id ? " style=display:none;":'') .">\n"; if ($search_submit != false) { global $_search_button; $edit_entry .= sprintf($_search_button, $disabled, user_theme(), - (in_ajax() ? 'display:none;':''), + (fallback_mode() ? '' : 'display:none;'), $search_submit)."\n"; } } - default_focus($name); + default_focus(($search_box && $by_id) ? $search_box : $name); $str = $selector; if ($search_box && $opts['cells']) echo ($edit_entry!='' ? "$edit_entry" : '')."$selector"; @@ -275,7 +297,7 @@ $opts = array( // default options //if($name=='SelectStockFromList') display_error($sql); foreach($items as $value=>$descr) { $sel = ''; - if ($selected_id == $value) { + if ((string)$selected_id === (string)$value) { $sel = 'selected'; $found = $value; } @@ -296,8 +318,9 @@ $opts = array( // default options } if ($found === false) { - $_POST[$name] = $first_id; + $selected_id = $first_id; } + $_POST[$name] = $selected_id; $aspect = $opts['edit_submit'] ? " aspect='editable'" : ''; $selector = "