X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_lists.inc;h=86968c9fbe644a6c13336ae6dc7a082fb5902af2;hb=0ad69edb5561aac03a5af49286c37b3350307719;hp=f271bb65679041028e16a0378f357eb12dd321e2;hpb=bba815c54136c2c6e3355557c15232f4e206e4ed;p=fa-stable.git
diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc
index f271bb65..86968c9f 100644
--- a/includes/ui/ui_lists.inc
+++ b/includes/ui/ui_lists.inc
@@ -1,1144 +1,904 @@
";
-//$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
+ '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 $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]);
- $no_supplier_list = get_company_pref('no_supplier_list');
- if ($no_supplier_list)
- {
- global $search_button;
- $edit_name = $name."_edit";
- $edit_button = $name."_button";
+ if ($selected_id == null) {
+ $selected_id = get_post($name, $opts['default']);
+ }
+ $txt = get_post($search_box);
+ $rel = '';
+ $limit = '';
- $val = (isset($_POST[$edit_name]) && $_POST[$edit_name] != "" ? $_POST[$edit_name] : "");
- if (isset($_POST[$edit_button]))
- {
- $selected_id = $_POST[$name] = "";
- }
+ if (isset($_POST[$select_submit])) {
- 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);
- }
- 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);
- }
- else
- $supplier_result = false;
- }
-
- echo " ";
+ if ($by_id) $txt = $_POST[$name];
- echo sprintf($search_button, $edit_button);
+ if (!$opts['async'])
+ $Ajax->activate('_page_body');
+ else
+ $Ajax->activate($name);
}
- 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 ($search_box) {
+ // search related sql modifications
+
+ $rel = "rel='$search_box'"; // set relation to list
+ if ($opts['search_submit']) {
+ if (isset($_POST[$search_submit])) {
+ 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)."'";
}
-
- if ($submit_on_change==true)
- echo "