X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fui%2Fui_lists.inc;h=bde06e22ade0f6352d9fcb66af3954920e30d8d3;hb=a1e0df1ef259550f26bc150cf912fd518c7344e3;hp=a29dda765317e30b0fa476cd15a35a50a620e728;hpb=9879eeb19e7defd3fe9538c86b1d35122b00a1e0;p=fa-stable.git
diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc
index a29dda76..bde06e22 100644
--- a/includes/ui/ui_lists.inc
+++ b/includes/ui/ui_lists.inc
@@ -1,1237 +1,1197 @@
.
+***********************************************************************/
include_once($path_to_root . "/includes/banking.inc");
+include_once($path_to_root . "/includes/reserved.inc");
+include_once($path_to_root . "/includes/types.inc");
+include_once($path_to_root . "/includes/current_user.inc");
+
+$_search_button = " ";
-define("DEFVAL", "--");
-$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
+ 'category' => false, // category column name or false
+ 'show_inactive' => false // show inactive records.
+);
+// ------ 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);
- }
- else
- $supplier_result = false;
+ }
+ }
+ // sql completion
+ if (count($opts['where'])) {
+ $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) {
+ if (!is_array($opts['order']))
+ $opts['order'] = array($opts['order']);
+ $sql .= ' ORDER BY '.implode(',',$opts['order']);
+ }
- echo " ";
+ $sql .= $limit;
+ // ------ make selector ----------
+ $selector = $first_opt = '';
+ $first_id = false;
+ $found = false;
+ $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 ((string)($selected_id) === $value) {
+ $sel = 'selected';
+ $found = $value;
+ }
+ // show selected option even if inactive
+ if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
+ continue;
+ } else
+ $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
+
+ if ($first_id === false) {
+ $first_id = $value;
+ $first_opt = $descr;
+ }
+ $cat = $contact_row[$opts['category']];
+ if ($opts['category'] !== false && $cat != $lastcat){
+ $selector .= "