Fixed layout of hyperlink_params_td()
[fa-stable.git] / includes / ui / ui_lists.inc
index 785ab74604515bae2e260e1fe6599615bf692faf..6766415e767ac7a131078802d159e597561812db 100644 (file)
@@ -74,13 +74,16 @@ $opts = array(              // default options
                        : _('Enter description fragment to search or * for all')) :'';
 
        if ($selected_id == null) {
-               $selected_id = get_post($name);
+               $selected_id = get_post($name, null);
        }
        $txt = get_post($search_box);
        $rel = '';
        $limit = '';
 
        if (isset($_POST[$select_submit])) {
+
+               if ($by_id) $txt = $_POST[$name];
+
                if (!$opts['async'])
                        $Ajax->activate('_page_body');
                else
@@ -91,15 +94,17 @@ $opts = array(              // default options
 
        $rel = "rel='$search_box'"; // set relation to list
    if ($opts['search_submit']) {
-       // if selected from list - set focus on next field
        if (isset($_POST[$search_submit])) {
-               $Ajax->activate($name);
+               if (!$opts['async'])
+                       $Ajax->activate('_page_body');
+               else
+                       $Ajax->activate($name);
        }
        if ($txt == '') {
-               if ($spec_option === false)
-               $limit = ' LIMIT 1';
+               if ($spec_option === false && $selected_id==null)
+                 $limit = ' LIMIT 1';
                else
-               $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
+                 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
        }
        else
                if ($txt != '*') {
@@ -121,70 +126,49 @@ $opts = array(            // default options
 
        $sql .= $limit;
        // ------ make selector ----------
-       $selector = '';
-       $first_id = $first_opt = '';
+       $selector = $first_opt = '';
+       $first_id = false;
        $found = false;
-//if($name=='code_id')    display_error($sql);
+//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 (isset($_POST[$search_submit])) {
-                               if (($by_id ? $value : $contact_row[1]) === $txt)
-                               $selected_id = $value;
-                       }
-                       // if no initial selection - set the first item
-                       if ($selected_id === "")        {
-                               $selected_id = $value;
-                       }
-                       if ($selected_id == $value) {
+                       if ($selected_id === $value) {
                                $sel = 'selected';
                                $found = $value;
-                               $_POST[$name] = $selected_id;
                        }
-                       if ($first_opt == false) {
+                       if ($first_id === false) {
                                $first_id = $value;
                                $first_opt = $descr;
-                               continue;
                        }
                        $selector .= "<option $sel value='$value'>$descr</option>\n";
                }
                db_free_result($result);
        }
-       // add first option - selected also if no match for selected_id was found
-       // and no special option defined
-       $sel = $spec_option===false || $found === $first_id ? 'selected' : '';
-       $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
-                       . $selector;
-
        // Prepend special option.
        if ($spec_option !== false) { // if special option used - add it
                $first_id = $spec_id;
                $first_opt = $spec_option;
-               if (isset($_POST[$search_submit])) {
-                       if ($txt == '')
-                               $selected_id = $spec_id;
-               }
                $sel = $found===false ? 'selected' : '';
                $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
                        . $selector;
        }
 
        if ($found === false) {
-       $_POST[$name] = $first_id;
+               $_POST[$name] = $first_id;
        }
 
-
        if ($by_id) {
-       $txt = $_POST[$name];
-       if ($search_box)
-               $Ajax->addUpdate($name, $search_box, $txt);
+               $txt = $_POST[$name];
+               if ($search_box)
+                       $Ajax->addUpdate($name, $search_box, $txt);
        }
 
        $selector = "<select name='$name' class='$class' title='"
-       . $opts['sel_hint']."' $rel>".$selector."</select>\n";
+               . $opts['sel_hint']."' $rel>".$selector."</select>\n";
 
        $Ajax->addUpdate($name, "_{$name}_sel", $selector);
 
@@ -201,7 +185,7 @@ $opts = array(              // default options
        }
 // ------ make combo ----------
 
-$edit_entry = '';
+       $edit_entry = '';
        if ($search_box != false) {
                $edit_entry = "<input type='text' name='$search_box' id='$search_box' size='".
                        $opts['size']."' maxlength='".$opts['max'].
@@ -668,7 +652,7 @@ function stock_costable_items_list($name, $selected_id,
 function stock_purchasable_items_list($name, $selected_id,     $all_option=false,
                $submit_on_change=false, $opts=array())
 {
-
+ 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
@@ -717,7 +701,8 @@ function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
                echo "<td>$label</td>\n";
        echo "<td>";
        if ($enabled)
-               $sel = "<select name='$name' onchange='this.form.submit();'>\n";
+               $sel = "<select name='$name' onchange='JsHttpRequest.request(\"_{$name}_update\", this.form);'>\n";
+               
        else
                $sel =  "<select disabled name='$name'>\n";
        if ($selected_id == null)
@@ -735,8 +720,6 @@ function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
 
 function stock_units_list_row($label, $name, $value, $enabled=true)
 {
-       global $stock_units;
-
        default_focus($name);
        $result = get_all_item_units();
        echo "<tr><td>$label</td>\n";
@@ -771,14 +754,12 @@ function stock_units_list_row($label, $name, $value, $enabled=true)
 
 function tax_types_list($name, $selected_id, $none_option=false, $submit_on_change=false)
 {
-       global $all_items;
-
        $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
 
        return combo_input($name, $selected_id, $sql, 'id', 'name',
        array(
                'spec_option' => $none_option,
-               'spec_id' => $all_items,
+               'spec_id' => 0,
                'select_submit'=> $submit_on_change,
                'async' => false,
        ) );
@@ -809,15 +790,13 @@ function tax_types_list_row($label, $name, $selected_id, $none_option=false,
 function tax_groups_list($name, $selected_id,
        $none_option=false, $submit_on_change=false)
 {
-       global $all_items;
-
        $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
 
        return combo_input($name, $selected_id, $sql, 'id', 'name',
        array(
                'order' => 'id',
                'spec_option' => $none_option,
-               'spec_id' => $all_items,
+               'spec_id' => 0,
                'select_submit'=> $submit_on_change,
                'async' => false,
        ) );
@@ -1013,8 +992,6 @@ function credit_status_list_row($label, $name, $selected_id)
 
 function sales_types_list($name, $selected_id, $submit_on_change=false, $special_option=false)
 {
-       global $all_items;
-
        $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
 
        return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
@@ -1252,7 +1229,7 @@ function gl_account_types_list_row($label, $name, $selected_id, $all_option=fals
 
 //-----------------------------------------------------------------------------------------------
 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
-       $show_group=false, $cells=false)
+       $show_group=false, $cells=false, $all_option=false)
 {
        if ($skip_bank_accounts)
                $sql = "SELECT chart.account_code, chart.account_name, type.name
@@ -1269,6 +1246,8 @@ function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
        combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
        array(
                'format' => '_format_account' .  ($show_group ? '2' : ''),
+               'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
+               'spec_id' => '',
                'order' => 'account_code',
                'search_box' => $cells,
                        'search_submit' => false,
@@ -1290,21 +1269,21 @@ function _format_account2($row)
 }
 
 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
-       $show_group=false, $cells=false)
+       $show_group=false, $cells=false, $all_option=false)
 {
        if ($label != null)
                echo "<td>$label</td>\n";
        echo "<td>";
-       gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells);
+       gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
        echo "</td>\n";
 }
 
 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
-       $show_group=false, $cells=false)
+       $show_group=false, $cells=false, $all_option=false)
 {
        echo "<tr>\n";
        gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
-               $show_group, $cells);
+               $show_group, $cells, $all_option);
        echo "</tr>\n";
 }
 
@@ -1818,7 +1797,7 @@ function credit_type_list_cells($label, $name, $selected, $submit_on_change=fals
                label_cell($label);
        echo "<td><select name='$name'";
        if ($submit_on_change)
-               echo " onchange='this.form.submit();'>";        // FIX ajax
+               echo " onchange='JsHttpRequest.request(\"_{$name}_update\", this.form);'>";
        else
                echo ">";
        echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
@@ -1834,47 +1813,55 @@ function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
        return $str;
 }
 
-function number_list($name, $selected, $from, $to, $firstlabel="")
+function number_list($name, $selected, $from, $to, $no_option=false)
 {
        default_focus($name);
        if ($selected == null)
        {
-               $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]);
-               if ($selected == $from)
-                       $_POST[$name] = $selected;
+               $selected = (!isset($_POST[$name]) ? reserved_words::get_all_numeric() : $_POST[$name]);
        }
        echo "<select name='$name'>";
+       if ($no_option !== false)
+       {
+               $reserved_word = reserved_words::get_all_numeric();
+
+       if ($selected == $reserved_word)
+       {
+            echo "<option selected value='$reserved_word'>$no_option</option>\n";
+       }
+       else
+       {
+            echo "<option value='$reserved_word'>$no_option</option>\n";
+       }
+       }
+
        for ($i = $from; $i <= $to; $i++)
        {
-               if ($i == 0 && $firstlabel != "")
-                       $label = $firstlabel;
-               else
-                       $label = $i;
                if ($selected == $i)
                {
-                       echo "<option selected value='$i'>$label</option>\n";
+                       echo "<option selected value='$i'>$i</option>\n";
                }
                else
                {
-                       echo "<option value='$i'>$label</option>\n";
+                       echo "<option value='$i'>$i</option>\n";
                }
        }
        echo "</select>\n";
 }
 
-function number_list_cells($label, $name, $selected, $from, $to)
+function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
 {
        if ($label != null)
                label_cell($label);
        echo "<td>\n";
-       number_list($name, $selected, $from, $to);
+       number_list($name, $selected, $from, $to, $no_option);
        echo "</td>\n";
 }
 
-function number_list_row($label, $name, $selected, $from, $to)
+function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
 {
        echo "<tr>\n";
-       number_list_cells($label, $name, $selected, $from, $to);
+       number_list_cells($label, $name, $selected, $from, $to, $no_option);
        echo "</tr>\n";
 }
 ?>
\ No newline at end of file