X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fui%2Fui_lists.inc;h=86968c9fbe644a6c13336ae6dc7a082fb5902af2;hb=ef2f5f6ff03591f558e3296864bbb8b5cbb1b65d;hp=6653d6a033f51328d081c6b75c88d7e5a99e909a;hpb=7bb664bfb8a14372f289b3184d8a34b66d65cfcd;p=fa-stable.git diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 6653d6a0..86968c9f 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -5,16 +5,16 @@ 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 = " "; +$_search_button = " "; -$_select_button = " "; +$_select_button = " "; $all_items = reserved_words::get_all(); //---------------------------------------------------------------------------- -// Universal combo generator +// Universal sql combo generator // $sql must return selector values and selector texts in columns 0 & 1 // Options are merged with defaults. @@ -30,6 +30,7 @@ $opts = array( // default options '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 @@ -46,11 +47,12 @@ $opts = array( // default options 'cells' => false, // combo displayed as 2 cells 'search' => array(), // sql field names to search 'format' => null, // format functions for regular options - 'disabled' => false, // FIX todo + 'disabled' => false, 'box_hint' => null // box/selectors hints; null = std see below ); // ------ merge options with defaults ---------- - $opts = array_merge($opts, $options); + 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']; @@ -60,21 +62,22 @@ $opts = array( // default options $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'); + '' : _('Press Space tab for search pattern entry'); if ($opts['box_hint'] === null) - $opts['box_hint'] = $search_box ? + $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, null); + $selected_id = get_post($name, $opts['default']); } $txt = get_post($search_box); $rel = ''; @@ -148,6 +151,7 @@ $opts = array( // default options } db_free_result($result); } + // Prepend special option. if ($spec_option !== false) { // if special option used - add it $first_id = $spec_id; @@ -158,16 +162,15 @@ $opts = array( // default options } if ($found === false) { - $_POST[$name] = $first_id; + $selected_id = $first_id; } + $_POST[$name] = $selected_id; - if ($by_id) { + if ($by_id && $search_box != false) { $txt = $_POST[$name]; - if ($search_box) - $Ajax->addUpdate($name, $search_box, $txt); + $Ajax->addUpdate($name, $search_box, $txt); } - - $selector = "\n"; $Ajax->addUpdate($name, "_{$name}_sel", $selector); @@ -179,7 +182,7 @@ $opts = array( // default options if ($select_submit != false) { // if submit on change is used - add select button global $_select_button; // button class selects form reload/ajax selector update - $selector .= sprintf($_select_button, user_theme(), + $selector .= sprintf($_select_button, $disabled, user_theme(), (in_ajax() ? 'display:none;':''), $select_submit)."\n"; } @@ -187,7 +190,7 @@ $opts = array( // default options $edit_entry = ''; if ($search_box != false) { - $edit_entry = "\n"; if ($search_submit != false) { global $_search_button; - $edit_entry .= sprintf($_search_button, user_theme(), + $edit_entry .= sprintf($_search_button, $disabled, user_theme(), (in_ajax() ? 'display:none;':''), $search_submit)."\n"; } @@ -209,6 +212,106 @@ $opts = array( // default options return $str; } +//---------------------------------------------------------------------------------------------- +// Universal array combo generator +// $items is array of options 'value' => 'description' +// Options is reduced set of combo_selector options and is merged with defaults. + +function array_selector($name, $selected_id, $items, $options=null) +{ + global $Ajax; + +$opts = array( // default options + 'spec_option'=>false, // option text or false + 'spec_id' => 0, // option id + 'select_submit' => false, //submit on select: true/false + 'async' => true, // select update via ajax (true) vs _page_body reload + 'default' => '', // default value when $_POST is not set + // search box parameters + 'sel_hint' => null, + 'disabled' => false +); +// ------ merge options with defaults ---------- + if($options != null) + $opts = array_merge($opts, $options); + $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit']; + $spec_id = $opts['spec_id']; + $spec_option = $opts['spec_option']; + $disabled = $opts['disabled'] ? "disabled" : ''; + + if ($selected_id == null) { + $selected_id = get_post($name, $opts['default']); + } + + if (isset($_POST[$select_submit])) { + if (!$opts['async']) + $Ajax->activate('_page_body'); + else + $Ajax->activate($name); + } + + // ------ make selector ---------- + $selector = $first_opt = ''; + $first_id = false; + $found = false; +//if($name=='SelectStockFromList') display_error($sql); + foreach($items as $value=>$descr) { + $sel = ''; + if ($selected_id == $value) { + $sel = 'selected'; + $found = $value; + } + if ($first_id === false) { + $first_id = $value; + $first_opt = $descr; + } + $selector .= "\n"; + } + + // 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; + } + + if ($found === false) { + $_POST[$name] = $first_id; + } + + $selector = "\n"; + + $Ajax->addUpdate($name, "_{$name}_sel", $selector); + + $selector = "".$selector."\n"; + + if ($select_submit != false) { // if submit on change is used - add select button + global $_select_button; + $selector .= sprintf($_select_button, $disabled, user_theme(), + (in_ajax() ? 'display:none;':''), + $select_submit)."\n"; + } + default_focus($name); + echo $selector; + + return $selector; +} +//---------------------------------------------------------------------------------------------- + +function _format_add_curr($row) +{ + static $company_currency; + + if ($company_currency == null) + { + $company_currency = get_company_currency(); + } + return $row[1] . ($row[2] == $company_currency ? + '' : (" - " . $row[2])); +} function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false) { @@ -232,18 +335,6 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_ )); } -function _format_add_curr($row) -{ -static $company_currency; - -if ($company_currency == null) -{ - $company_currency = get_company_currency(); -} -return $row[1] . ($row[2] == $company_currency ? - '' : (" - " . $row[2])); -} - function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) { if ($label != null) @@ -297,10 +388,10 @@ function customer_list_cells($label, $name, $selected_id=null, $all_option=false function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false) { -echo "$label"; -$str = customer_list($name, $selected_id, $all_option, $submit_on_change); -echo "\n\n"; -return $str; + echo "$label"; + $str = customer_list($name, $selected_id, $all_option, $submit_on_change); + echo "\n\n"; + return $str; } //------------------------------------------------------------------------------------------------ @@ -321,7 +412,6 @@ return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name', 'spec_id' => $all_items, 'select_submit'=> $submit_on_change, 'sel_hint' => _('Select customer branch') -// 'async' => false ) ); } //------------------------------------------------------------------------------------------------ @@ -385,33 +475,29 @@ function currencies_list($name, $selected_id=null, $submit_on_change=false) $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies"; // default to the company currency - if ($selected_id == "") - { - $selected_id = get_company_currency(); - $_POST[$name] = $selected_id; - } return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency', array( 'select_submit'=> $submit_on_change, - 'async' => false + 'default' => get_company_currency(), + 'async' => false ) ); } -function currencies_list_cells($label, $name, $selected_id=null) +function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false) { if ($label != null) echo "$label\n"; echo ""; - $str = currencies_list($name, $selected_id); + $str = currencies_list($name, $selected_id, $submit_on_change); echo "\n"; return $str; } -function currencies_list_row($label, $name, $selected_id=null) +function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false) { echo "\n"; - $str = currencies_list_cells($label, $name, $selected_id); + $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change); echo "\n"; return $str; } @@ -424,15 +510,11 @@ function fiscalyears_list($name, $selected_id=null, $submit_on_change=false) $sql = "SELECT * FROM ".TB_PREF."fiscal_year"; // default to the company current fiscal year - if ($selected_id == "") - { - $selected_id = get_company_pref('f_year'); - $_POST[$name] = $selected_id; - } return combo_input($name, $selected_id, $sql, 'id', '', array( 'order' => 'begin', + 'default' => get_company_pref('f_year'), 'format' => '_format_fiscalyears', 'select_submit'=> $submit_on_change, 'async' => false @@ -478,9 +560,9 @@ $options = array( ); if ($showclosed) - $options['where'][] = "closed=0"; + $options['where'][] = "closed=0"; if($showtype) - $options['where'][] = "type_=$showtype"; + $options['where'][] = "type_=$showtype"; return combo_input($name, $selected_id, $sql, 'id', 'ref', $options); } @@ -669,27 +751,12 @@ function stock_costable_items_list_cells($label, $name, $selected_id=null, } //------------------------------------------------------------------------------------ - -function stock_purchasable_items_list($name, $selected_id=null, $all_option=false, - $submit_on_change=false, $opts=array()) +function stock_purchasable_items_list($name, $selected_id=null, + $all_option=false, $submit_on_change=false) { - global $all_items; - $sql = "SELECT stock_id, s.description, c.description - FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c - WHERE s.category_id=c.category_id - AND mb_flag !='M' "; - return combo_input($name, $selected_id, $sql, 'stock_id', 's.description', - array_merge( array( - 'format' => '_format_stock_items', - 'spec_option' => $all_option===true ? _("All Items") : $all_option, - 'spec_id' => $all_items, - 'search_box' => true, - 'search' => array("stock_id", "c.description","s.description"), - 'search_submit' => get_company_pref('no_item_list')!=0, - 'size'=>10, - 'select_submit'=> $submit_on_change - ), $opts) ); - + $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change, + array('where'=>array("mb_flag!= 'M'"))); + return $str; } function stock_purchasable_items_list_cells($label, $name, $selected_id=null, @@ -697,9 +764,9 @@ function stock_purchasable_items_list_cells($label, $name, $selected_id=null, { if ($label != null) echo "$label\n"; - $ret = stock_purchasable_items_list($name, $selected_id, $all_option, - $submit_on_change, array('cells'=>true) ); - return $ret; + $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change, + array('where'=>array("mb_flag!= 'M'"), 'cells'=>true)); + return $str; } function stock_purchasable_items_list_row($label, $name, $selected_id=null, @@ -716,59 +783,41 @@ function stock_purchasable_items_list_row($label, $name, $selected_id=null, function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true) { - default_focus($name); + $types = array( + 'M' => _("Manufactured"), + 'B' => _("Purchased"), + 'D' => _("Service") + ); + echo ""; - if ($label != NULL) + if ($label != null) echo "$label\n"; echo ""; - if ($enabled) - $sel = "\n"; - if ($selected_id == null) - $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]); - if ($selected_id == "") - $_POST[$name] = $selected_id = "B"; - $sel .= "\n"; - $sel .= "\n"; - $sel .= "\n"; - $sel .= ""; - echo $sel; + array_selector($name, $selected_id, $types, + array( + 'select_submit'=> true, + 'disabled' => !$enabled) ); echo "\n"; - return $sel; } function stock_units_list_row($label, $name, $value=null, $enabled=true) { - default_focus($name); $result = get_all_item_units(); - echo "$label\n"; - if ($enabled) - echo ""; - - if ($value == null) - $value = (!isset($_POST[$name]) ? "" : $_POST[$name]); + echo ""; + if ($label != null) + echo "$label\n"; + echo ""; while($unit = db_fetch($result)) - { - if ($value == "") - { - $_POST[$name] = $unit['abbr']; - } - $descr = $unit['name']; - if ($value==$unit['abbr']) - { - echo "\n"; - } - else - { - echo "\n"; - } - } - echo "\n"; + $units[$unit['abbr']] = $unit['name']; + + array_selector($name, $value, $units, + array( + 'select_submit'=> true, + 'disabled' => !$enabled) ); + + echo "\n"; } //------------------------------------------------------------------------------------ @@ -1250,7 +1299,7 @@ function gl_account_types_list_row($label, $name, $selected_id=null, $all_option //----------------------------------------------------------------------------------------------- function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false, - $show_group=false, $cells=false, $all_option=false) + $show_group=false, $cells=false, $all_option=false, $submit_on_change=false) { if ($skip_bank_accounts) $sql = "SELECT chart.account_code, chart.account_name, type.name @@ -1274,7 +1323,9 @@ function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=fals 'search_submit' => false, 'size' => 12, 'max' => 10, - 'cells' => true + 'cells' => true, + 'select_submit'=> $submit_on_change, + 'async' => false ) ); } @@ -1310,40 +1361,14 @@ function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_a function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false) { - default_focus($name); - if ($submit_on_change == true) - echo ""; - - if (strlen($name_yes) == 0) - { - unset($name_yes); - } - if (strlen($name_no) == 0) - { - unset($name_no); - } + $items = array(); + $items['1'] = strlen($name_yes) ? $name_yes : _("Yes"); + $items['0'] = strlen($name_no) ? $name_no : _("No"); - if ($selected_id == null) - $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]); - if ($selected_id == 0) - echo "\n"; - else - echo $name_yes . "\n"; - if ($selected_id == 0) - echo "\n"; - else - echo $name_no . "\n"; - echo ""; + return array_selector($name, $selected_id, $items, + array( + 'select_submit'=> $submit_on_change, + 'async' => false ) ); // FIX? } function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false) @@ -1370,18 +1395,11 @@ function languages_list($name, $selected_id=null) { global $installed_languages; - default_focus($name); - echo ""; + $types = bank_account_types::get_all(); - if ($selected_id == null) - $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]); - foreach ($bank_account_types as $type) + $items = array(); + foreach ($types as $type) { - echo "\n"; + $items[$type['id']] = $type['name']; } + + return array_selector($name, $selected_id, $items ); } function bank_account_types_list_cells($label, $name, $selected_id=null) @@ -1437,31 +1450,21 @@ function bank_account_types_list_row($label, $name, $selected_id=null) } //------------------------------------------------------------------------------------------------ - -function payment_person_types_list($name, $selected_id=null, $related=null) +function payment_person_types_list($name, $selected_id=null, $submit_on_change=false) { $types = payment_person_types::get_all(); - default_focus($name); - echo ""; - - if ($selected_id == null) - $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]); + $items = array(); foreach ($types as $type) - { - echo "\n"; - } - echo ""; + $items[$type['id']] = $type['name']; + + return array_selector($name, $selected_id, $items, + array( 'select_submit'=> true, 'async' => true ) ); } function wo_types_list_row($label, $name, $selected_id=null) @@ -1517,115 +1513,42 @@ function dateformats_list_row($label, $name, $value=null) { global $dateformats; - default_focus($name); - echo "$label\n"; - echo "\n"; + echo "$label\n"; + array_selector( $name, $value, $dateformats ); + echo "\n"; } function dateseps_list_row($label, $name, $value=null) { global $dateseps; - default_focus($name); - echo "$label\n"; - echo "\n"; + echo "$label\n"; + array_selector( $name, $value, $dateseps ); + echo "\n"; } function thoseps_list_row($label, $name, $value=null) { global $thoseps; - default_focus($name); - echo "$label\n"; - echo "\n"; + echo "$label\n"; + array_selector( $name, $value, $thoseps ); + echo "\n"; } function decseps_list_row($label, $name, $value=null) { global $decseps; - default_focus($name); - echo "$label\n"; - echo "\n"; + echo "$label\n"; + array_selector( $name, $value, $decseps ); + echo "\n"; } function themes_list_row($label, $name, $value=null) { global $path_to_root; - default_focus($name); $path = $path_to_root.'/themes/'; $themes = array(); $themedir = opendir($path); @@ -1633,109 +1556,58 @@ function themes_list_row($label, $name, $value=null) { if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname)) { - $themes[] = $fname; + $themes[$fname] = $fname; } } - sort($themes); - echo "$label\n"; - echo "\n"; + echo "$label\n"; + array_selector( $name, $value, $themes ); + echo "\n"; } function pagesizes_list_row($label, $name, $value=null) { global $pagesizes; - default_focus($name); - echo "$label\n"; - echo "\n"; + echo "$label\n"; + array_selector( $name, $value, $items ); + echo "\n"; } function security_headings_list_row($label, $name, $value=null) { global $security_headings; - default_focus($name); - echo "$label\n"; - echo "\n"; + echo "$label\n"; + array_selector( $name, $value, $security_headings ); + echo "\n"; } function systypes_list_cells($label, $name, $value=null, $submit_on_change=false) { global $systypes_array; - default_focus($name); if ($label != null) echo "$label\n"; - echo "\n"; + $items = array(); + foreach ($systypes_array as $key=>$type) + $items[$key] = $type['name']; + + $str = array_selector($name, $value, $items, + array( + 'select_submit'=> $submit_on_change, + 'async' => false + ) + ); + echo "\n"; + return $str; } function systypes_list_row($label, $name, $value=null, $submit_on_change=false) @@ -1749,53 +1621,51 @@ function systypes_list_row($label, $name, $value=null, $submit_on_change=false) function cust_allocations_list_cells($label, $name, $selected=null) { global $all_items; - default_focus($name); + if ($label != null) label_cell($label); - if ($selected == null) - $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]); - echo "\n"; + echo "\n"; + $allocs = array( + $all_items=>_("All Types"), + '1'=> _("Sales Invoices"), + '2'=> _("Overdue Invoices"), + '3' => _("Payments"), + '4' => _("Credit Notes"), + '5' => _("Delivery Notes") + ); + $str = array_selector($name, $selected, $allocs); + echo "\n"; + return $str; } -function supp_allocations_list_cells($name, $selected=null) +function supp_allocations_list_cell($name, $selected=null) { global $all_items; - default_focus($name); - if ($selected == null) - $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]); - echo "\n"; + echo "\n"; + $allocs = array( + $all_items=>_("All Types"), + '1'=> _("Invoices"), + '2'=> _("Overdue Invoices"), + '3' => _("Payments"), + '4' => _("Credit Notes"), + '5' => _("Overdue Credit Notes") + ); + $str = array_selector($name, $selected, $allocs); + echo "\n"; + return $str; } function policy_list_cells($label, $name, $selected=null) { - default_focus($name); - if ($selected == null) - { - $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]); - if ($selected == "") - $_POST[$name] = $selected; - } if ($label != null) label_cell($label); - echo "\n"; + echo "\n"; + $str = array_selector($name, $selected, + array( '' => _("Automatically put balance on back order"), + 'CAN' => _("Cancel any quantites not delivered")) ); + echo "\n"; + return $str; } function policy_list_row($label, $name, $selected=null) @@ -1807,23 +1677,15 @@ function policy_list_row($label, $name, $selected=null) function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false) { - default_focus($name); - if ($selected == null) - { - $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]); - if ($selected == "Return") - $_POST[$name] = $selected; - } if ($label != null) label_cell($label); - echo "\n"; + echo "\n"; + $str = array_selector($name, $selected, + array( 'Return' => _("Items Returned to Inventory Location"), + 'WriteOff' => _("Items Written Off")), + array( 'select_submit'=> $submit_on_change ) ); + echo "\n"; + return $str; } function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false) @@ -1836,38 +1698,13 @@ function credit_type_list_row($label, $name, $selected=null, $submit_on_change=f function number_list($name, $selected, $from, $to, $no_option=false) { - default_focus($name); - if ($selected == null) - { - $selected = (!isset($_POST[$name]) ? reserved_words::get_all_numeric() : $_POST[$name]); - } - echo "\n"; + $items[$i] = "$i"; + + return array_selector($name, $selected, $items, + array( 'spec_option' => $no_option, + 'spec_id' => reserved_words::get_all_numeric()) ); } function number_list_cells($label, $name, $selected, $from, $to, $no_option=false) @@ -1885,4 +1722,5 @@ function number_list_row($label, $name, $selected, $from, $to, $no_option=false) number_list_cells($label, $name, $selected, $from, $to, $no_option); echo "\n"; } + ?> \ No newline at end of file