X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fui%2Fui_lists.inc;h=0ce2546a3e8c469c5618a39654aeb67ffe6b1249;hb=654b2cb832f5ad2313cfbbd98832681fae05943a;hp=a29dda765317e30b0fa476cd15a35a50a620e728;hpb=9879eeb19e7defd3fe9538c86b1d35122b00a1e0;p=fa-stable.git
diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc
index a29dda76..0ce2546a 100644
--- a/includes/ui/ui_lists.inc
+++ b/includes/ui/ui_lists.inc
@@ -1,1141 +1,928 @@
";
-//$search_button = " ";
+$_search_button = " ";
+
+$_select_button = " ";
$all_items = reserved_words::get_all();
-// TDB for all list functions : if there is no data, display a link to the releveant
-// page to add an item, eg. for locations, if no locations, link to Add Location
+//----------------------------------------------------------------------------
+// Universal sql combo generator
+// $sql must return selector values and selector texts in columns 0 & 1
+// Options are merged with defaults.
+
+function combo_input($name, $selected_id, $sql, $valfield, $namefield,
+ $options=null)
+{
+global $Ajax;
+
+$opts = array( // default options
+ 'where'=> array(), // additional constraints
+ 'order' => $namefield, // list sort order
+ // special option parameters
+ 'spec_option'=>false, // option text or false
+ 'spec_id' => 0, // option id
+ // submit on select parameters
+ 'default' => '', // default value when $_POST is not set
+ '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
+ // search box parameters
+ '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
+ // 1 - with hidden search box, search by option text
+ // 2 - 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
+ 'max' => 50,
+ 'cells' => false, // combo displayed as 2
cells
+ '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
+);
+// ------ merge options with defaults ----------
+ if($options != null)
+ $opts = array_merge($opts, $options);
+ if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
+
+ $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
+ $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
+ $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
+ $spec_id = $opts['spec_id'];
+ $spec_option = $opts['spec_option'];
+ $by_id = ($opts['type'] == 0);
+ $class = $by_id ? 'combo':'combo2';
+ $disabled = $opts['disabled'] ? "disabled" : '';
+
+ if(!count($opts['search'])) {
+ $opts['search'] = array($by_id ? $valfield : $namefield);
+ }
+ if ($opts['sel_hint'] === null)
+ $opts['sel_hint'] = $by_id || $search_box==false ?
+ '' : _('Press Space tab for search pattern entry');
-function supplier_list($name, $selected_id, $all_option=false, $submit_on_change=false)
-{
- global $no_supplier_list, $all_items;
+ 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 = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]);
+ if ($selected_id == null) {
+ $selected_id = get_post($name, $opts['default']);
+ }
+ $txt = get_post($search_box);
+ $rel = '';
+ $limit = '';
- if ($no_supplier_list)
- {
- global $search_button;
- $edit_name = $name."_edit";
- $edit_button = $name."_button";
+ if (isset($_POST[$select_submit])) {
+ if ($by_id) $txt = $_POST[$name];
- $val = (isset($_POST[$edit_name]) && $_POST[$edit_name] != "" ? $_POST[$edit_name] : "");
- if (isset($_POST[$edit_button]))
- {
- $selected_id = $_POST[$name] = "";
- }
+ if (!$opts['async'])
+ $Ajax->activate('_page_body');
+ else
+ $Ajax->activate($name);
+ }
+ if ($search_box) {
+ // search related sql modifications
+
+ $rel = "rel='$search_box'"; // set relation to list
+ if ($opts['search_submit']) {
+ if (isset($_POST[$search_submit])) {
+ $selected_id = ''; // ignore selected_id while search
+ if (!$opts['async'])
+ $Ajax->activate('_page_body');
+ else
+ $Ajax->activate($name);
+ }
+ if ($txt == '') {
+ if ($spec_option === false && $selected_id==null)
+ $limit = ' LIMIT 1';
+ else
+ $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
+ }
+ else
+ if ($txt != '*') {
- if ($selected_id != "")
- {
- $val = DEFVAL;
- $supplier_sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers WHERE supplier_id=$selected_id";
- $supplier_result = db_query($supplier_sql);
+ foreach($opts['search'] as $i=> $s)
+ $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
+ $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
}
- else
- {
- if ($val != "" && $val != DEFVAL)
- {
- $supplier_sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers WHERE supp_name LIKE '%{$val}%' ORDER BY supp_name";
- $supplier_result = db_query($supplier_sql);
+ }
+ }
+ // sql completion
+ if (count($opts['where'])) {
+ $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
+ $sql .= '('. implode($opts['where'], ' AND ') . ')';
+ }
+ if ($opts['order'] != false) {
+ $sql .= ' ORDER BY '.$opts['order'];
+ }
+
+ $sql .= $limit;
+ // ------ make selector ----------
+ $selector = $first_opt = '';
+ $first_id = false;
+ $found = false;
+//if($name=='SelectStockFromList') 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;
+ }
+ if ((string)($selected_id) === $value) {
+ $sel = 'selected';
+ $found = $value;
+ }
+ if ($first_id === false) {
+ $first_id = $value;
+ $first_opt = $descr;
}
- else
- $supplier_result = false;
+ $selector .= "\n";
}
+ db_free_result($result);
+ }
- echo " ";
-
- echo sprintf($search_button, $edit_button);
+ // 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 = "\n"
+ . $selector;
}
- else
- {
- $supplier_sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ORDER BY supp_name";
- $supplier_result = db_query($supplier_sql);
+
+ if ($found === false) {
+ $selected_id = $first_id;
}
+ $_POST[$name] = $selected_id;
- if ($submit_on_change==true)
- echo "