Merged changes form main trunk (2.2.8, 2.2.9)
[fa-stable.git] / includes / ui / ui_lists.inc
index e4f14c1ad83dd14c1e821c3958f42e518dd9905a..0ddf0c34f6dad80ce61af1721c539cf6cfe73697 100644 (file)
@@ -89,21 +89,20 @@ $opts = array(              // default options
                $opts['sel_hint'] = $by_id || $search_box==false ?
                        '' : _('Press Space tab for search pattern entry');
 
-       if ($opts['box_hint'] === null)  // dodaƦ hint dla pustego ****
+       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 = get_post($name, $opts['default']);
+               $selected_id = get_post($name, (string)$opts['default']);
        }
        if(!is_array($selected_id))
-               $selected_id = array($selected_id); // code is generalized for multiple selection support
+               $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
 
        $txt = get_post($search_box);
        $rel = '';
        $limit = '';
-
        if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
                if ($by_id) $txt = $_POST[$name];
 
@@ -145,6 +144,7 @@ $opts = array(              // default options
                                }
                }
        }
+
        // sql completion
        if (count($opts['where'])) {
                $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
@@ -181,12 +181,13 @@ $opts = array(            // default options
                        if (get_post($search_button) && ($txt == $value)) {
                                $selected_id[] = $value;
                        }
-                       if (in_array($value, $selected_id)) {
+
+                       if (in_array((string)$value, $selected_id, true)) {
                                $sel = 'selected';
                                $found = $value;
                                $edit = $opts['editable'] && $contact_row['editable'] 
                                        && (@$_POST[$search_box] == $value)
-                                       ? $descr : false;
+                                       ? $contact_row[1] : false; // get non-formatted description
                                if ($edit)
                                        break;  // selected field is editable - abandon list construction
                        }
@@ -228,7 +229,7 @@ $opts = array(              // default options
        
        $_POST[$name] = $multi ? $selected_id : $selected_id[0];
 
-       $selector = "<select ".($multi ? "multiple" : '')
+       $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
                . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
                . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
                . $opts['sel_hint']."' $rel>".$selector."</select>\n";
@@ -240,7 +241,7 @@ $opts = array(              // default options
                        ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
                                $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
                                set_focus($name.'_text'); // prevent lost focus
-               } else if (isset($_POST['_'.$name.'_edit']))
+               } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
                        set_focus($name); // prevent lost focus
                if (!$opts['editable'])
                        $txt = $found;
@@ -327,7 +328,7 @@ $opts = array(              // default options
                $selected_id = get_post($name, $opts['default']);
        }
        if(!is_array($selected_id))
-               $selected_id = array($selected_id); // code is generalized for multiple selection support
+               $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
 
        if (isset($_POST[ '_'.$name.'_update'])) {
                if (!$opts['async'])
@@ -343,7 +344,7 @@ $opts = array(              // default options
 //if($name=='SelectStockFromList') display_error($sql);
                foreach($items as $value=>$descr) {
                        $sel = '';
-                       if (in_array((string)$value, $selected_id)) {
+                       if (in_array((string)$value, $selected_id, true)) {
                                $sel = 'selected';
                                $found = $value;
                        }
@@ -354,6 +355,10 @@ $opts = array(             // default options
                        $selector .= "<option $sel value='$value'>$descr</option>\n";
                }
 
+       if ($first_id!==false) {
+               $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
+               $selector = sprintf($first_opt, $sel).$selector;
+       }
        // Prepend special option.
        if ($spec_option !== false) { // if special option used - add it
                $first_id = $spec_id;
@@ -367,7 +372,8 @@ $opts = array(              // default options
                $selected_id = array($first_id);
        }
        $_POST[$name] = $multi ? $selected_id : $selected_id[0];
-       $selector = "<select ".($multi  ? "multiple" : '')
+
+       $selector = "<select autocomplete='off' ".($multi  ? "multiple" : '')
                . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
                . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
                . $opts['sel_hint']."'>".$selector."</select>\n";
@@ -441,7 +447,7 @@ function supplier_list_cells($label, $name, $selected_id=null, $all_option=false
 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, 
        $submit_on_change=false, $all=false, $editkey = false)
 {
-       echo "<tr><td>$label</td><td>";
+       echo "<tr><td class='label'>$label</td><td>";
        echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
                $all, $editkey);
        echo "</td></tr>\n";
@@ -491,7 +497,7 @@ 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, $show_inactive=false, $editkey = false)
 {
-       echo "<tr><td>$label</td><td nowrap>";
+       echo "<tr><td class='label'>$label</td><td nowrap>";
        echo customer_list($name, $selected_id, $all_option, $submit_on_change,
                $show_inactive, $editkey);
        echo "</td>\n</tr>\n";
@@ -537,8 +543,8 @@ function customer_branches_list_cells($label,$customer_id, $name, $selected_id=n
 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null, 
        $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
 {
-       echo "<tr>";
-       customer_branches_list_cells($label, $customer_id, $name, $selected_id, 
+       echo "<tr><td class='label'>$label</td>";
+       customer_branches_list_cells(null, $customer_id, $name, $selected_id, 
                $all_option, $enabled, $submit_on_change, $editkey);
        echo "</tr>";
 }
@@ -570,8 +576,8 @@ function locations_list_cells($label, $name, $selected_id=null, $all_option=fals
 
 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
 {
-       echo "<tr>";
-       locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -601,8 +607,8 @@ function currencies_list_cells($label, $name, $selected_id=null, $submit_on_chan
 
 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       currencies_list_cells($label, $name, $selected_id, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       currencies_list_cells(null, $name, $selected_id, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -642,8 +648,8 @@ function fiscalyears_list_cells($label, $name, $selected_id=null)
 
 function fiscalyears_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       fiscalyears_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       fiscalyears_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 //------------------------------------------------------------------------------------
@@ -682,8 +688,8 @@ function dimensions_list_cells($label, $name, $selected_id=null, $no_option=fals
 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
        $showclosed=false, $showtype=0, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
+       echo "<tr><td class='label'>$label</td>";
+       dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
                $showclosed, $showtype, $submit_on_change);
        echo "</tr>\n";
 }
@@ -695,7 +701,7 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
 {
        global $all_items;
 
-       $sql = "SELECT stock_id, s.description, c.description, s.inactive
+       $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
                        FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
 
        if ($editkey)
@@ -802,7 +808,7 @@ function sales_local_items_list_row($label, $name, $selected_id=null, $all_optio
 {
        echo "<tr>";
        if ($label != null)
-               echo "<td>$label</td>\n";
+               echo "<td class='label'>$label</td>\n";
        echo "<td>";
        echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
                'local', array('cells'=>false, 'editable' => false));
@@ -830,8 +836,8 @@ function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
                $all_option=false, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
        echo "</tr>\n";
 }
 //------------------------------------------------------------------------------------
@@ -878,7 +884,9 @@ function stock_purchasable_items_list($name, $selected_id=null,
                array('where'=>array("mb_flag!= 'M'"), 
                        'show_inactive'=>$all), $editkey);
 }
-
+//
+//     This helper is used in PO/GRN/PI entry and supports editable descriptions.
+//
 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
                        $all_option=false, $submit_on_change=false, $editkey=false)
 {
@@ -886,18 +894,19 @@ function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
                echo "<td>$label</td>\n";
        echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
                array('where'=>array("mb_flag!= 'M'"), 
+                        'editable' => 30,
                         'cells'=>true), $editkey);
 }
-
+/*
 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
                        $all_option=false, $submit_on_change=false, $editkey=false)
 {
-       echo "<tr>\n";
-       stock_purchasable_items_list_cells($label, $name, $selected_id=null,
+       echo "<tr><td class='label'>$label</td>";
+       stock_purchasable_items_list_cells(null, $name, $selected_id=null,
                $all_option, $submit_on_change, $editkey);
        echo "</tr>\n";
 }
-
+*/
 //------------------------------------------------------------------------------------
 
 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
@@ -906,7 +915,7 @@ function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=tr
 
        echo "<tr>";
        if ($label != null)
-               echo "<td>$label</td>\n";
+               echo "<td class='label'>$label</td>\n";
        echo "<td>";
 
        echo array_selector($name, $selected_id, $stock_types, 
@@ -921,7 +930,7 @@ function stock_units_list_row($label, $name, $value=null, $enabled=true)
        $result = get_all_item_units();
        echo "<tr>";
        if ($label != null)
-               echo "<td>$label</td>\n";
+               echo "<td class='label'>$label</td>\n";
        echo "<td>";
 
        while($unit = db_fetch($result))
@@ -960,8 +969,8 @@ function tax_types_list_cells($label, $name, $selected_id=null, $none_option=fal
 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
        $submit_on_change=false)
 {
-       echo "<tr>\n";
-       tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -993,8 +1002,8 @@ function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=fa
 
 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -1017,8 +1026,8 @@ function item_tax_types_list_cells($label, $name, $selected_id=null)
 
 function item_tax_types_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       item_tax_types_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       item_tax_types_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1042,8 +1051,8 @@ function shippers_list_cells($label, $name, $selected_id=null)
 
 function shippers_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       shippers_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       shippers_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1069,8 +1078,8 @@ function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=fa
 
 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
 {
-       echo "<tr>\n";
-       sales_persons_list_cells($label, $name, $selected_id, $spec_opt);
+       echo "<tr><td class='label'>$label</td>";
+       sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
        echo "</tr>\n";
 }
 
@@ -1093,8 +1102,8 @@ function sales_areas_list_cells($label, $name, $selected_id=null)
 
 function sales_areas_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       sales_areas_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       sales_areas_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1120,8 +1129,8 @@ function sales_groups_list_cells($label, $name, $selected_id=null, $special_opti
 
 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
 {
-       echo "<tr>\n";
-       sales_groups_list_cells($label, $name, $selected_id, $special_option);
+       echo "<tr><td class='label'>$label</td>";
+       sales_groups_list_cells(null, $name, $selected_id, $special_option);
        echo "</tr>\n";
 }
 
@@ -1155,8 +1164,8 @@ function templates_list_cells($label, $name, $selected_id=null, $special_option=
 
 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
 {
-       echo "<tr>\n";
-       templates_list_cells($label, $name, $selected_id, $special_option);
+       echo "<tr><td class='label'>$label</td>";
+       templates_list_cells(null, $name, $selected_id, $special_option);
        echo "</tr>\n";
 }
 
@@ -1179,8 +1188,8 @@ function workorders_list_cells($label, $name, $selected_id=null)
 
 function workorders_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       workorders_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       workorders_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1203,8 +1212,8 @@ function payment_terms_list_cells($label, $name, $selected_id=null)
 
 function payment_terms_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       payment_terms_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       payment_terms_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1227,8 +1236,8 @@ function credit_status_list_cells($label, $name, $selected_id=null)
 
 function credit_status_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       credit_status_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       credit_status_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1258,8 +1267,8 @@ function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_cha
 
 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
 {
-       echo "<tr>\n";
-       sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
+       echo "<tr><td class='label'>$label</td>";
+       sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
        echo "</tr>\n";
 }
 
@@ -1282,8 +1291,8 @@ function movement_types_list_cells($label, $name, $selected_id=null)
 
 function movement_types_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       movement_types_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       movement_types_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1350,8 +1359,8 @@ function workcenter_list_cells($label, $name, $selected_id=null, $all_option=fal
 
 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
 {
-       echo "<tr>\n";
-       workcenter_list_cells($label, $name, $selected_id, $all_option);
+       echo "<tr><td class='label'>$label</td>";
+       workcenter_list_cells(null, $name, $selected_id, $all_option);
        echo "</tr>\n";
 }
 
@@ -1381,8 +1390,8 @@ function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_c
 
 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
        echo "</tr>\n";
 }
 //-----------------------------------------------------------------------------------------------
@@ -1394,7 +1403,7 @@ function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_cha
                WHERE ".TB_PREF."bank_accounts.account_type=3";
 
        if ($label != null)
-               echo "<tr><td>$label</td>\n";
+               echo "<tr><td class='label'>$label</td>\n";
        echo "<td>";
        echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
        array(
@@ -1413,7 +1422,7 @@ function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $sub
        default_focus($name);
        echo '<tr>';
        if ($label != null)
-               echo "<td>$label</td>\n";
+               echo "<td class='label'>$label</td>\n";
        echo "<td>";
 
        echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
@@ -1453,7 +1462,7 @@ function sale_payment_list($name, $selected_id=null, $submit_on_change=true)
 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=true)
 {
        if ($label != null)
-               echo "<td>$label</td>\n";
+               echo "<td class='label'>$label</td>\n";
        echo "<td>";
 
        echo sale_payment_list($name, $selected_id, $submit_on_change);
@@ -1485,8 +1494,8 @@ function class_list_cells($label, $name, $selected_id=null, $submit_on_change=fa
 
 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       class_list_cells($label, $name, $selected_id, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       class_list_cells(null, $name, $selected_id, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -1514,14 +1523,14 @@ function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt
 
 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       stock_categories_list_cells($label, $name, $selected_id, $spec_opt, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
        echo "</tr>\n";
 }
 
 //-----------------------------------------------------------------------------------------------
 
-function gl_account_types_list($name, $selected_id=null, $all_option=false, $all_option_numeric=true)
+function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
 {
        global $all_items;
 
@@ -1529,28 +1538,26 @@ function gl_account_types_list($name, $selected_id=null, $all_option=false, $all
 
        return combo_input($name, $selected_id, $sql, 'id', 'name',
        array(
-               'order' => 'id',
+               'order' => array('class_id', 'id', 'parent'),
                'spec_option' =>$all_option,
-               'spec_id' => $all_option_numeric ? 0 : $all_items
+               'spec_id' => $all_items
        ) );
 }
 
-function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
-       $all_option_numeric=false)
+function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
 {
        if ($label != null)
                echo "<td>$label</td>\n";
        echo "<td>";
-       echo gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
+       echo gl_account_types_list($name, $selected_id, $all_option, $all);
        echo "</td>\n";
 }
 
-function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
-       $all_option_numeric=false)
+function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,        $all=false)
 {
-       echo "<tr>\n";
-       gl_account_types_list_cells($label, $name, $selected_id, $all_option,
-               $all_option_numeric);
+       echo "<tr><td class='label'>$label</td>";
+       gl_account_types_list_cells(null, $name, $selected_id, $all_option,
+               $all);
        echo "</tr>\n";
 }
 
@@ -1575,7 +1582,7 @@ function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=fals
                'format' => '_format_account',
                'spec_option' => $all_option===true ?  _("Use Item Sales Accounts") : $all_option,
                'spec_id' => '',
-               'order' => array('type.id','account_code'),
+               'order' => array('type.class_id','type.id','account_code'),
                'search_box' => $cells,
                        'search_submit' => false,
                        'size' => 12,
@@ -1609,8 +1616,8 @@ function gl_all_accounts_list_cells($label, $name, $selected_id=null,
 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
        $skip_bank_accounts=false, $cells=false, $all_option=false)
 {
-       echo "<tr>\n";
-       gl_all_accounts_list_cells($label, $name, $selected_id, 
+       echo "<tr><td class='label'>$label</td>";
+       gl_all_accounts_list_cells(null, $name, $selected_id, 
                $skip_bank_accounts, $cells, $all_option);
        echo "</tr>\n";
 }
@@ -1638,37 +1645,38 @@ function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_
 
 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
 {
-       echo "<tr>\n";
-       yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
        echo "</tr>\n";
 }
 
 //------------------------------------------------------------------------------------------------
 
-function languages_list($name, $selected_id=null)
+function languages_list($name, $selected_id=null, $all_option=false)
 {
        global $installed_languages;
 
        $items = array();
+       if ($all_option)
+               $items[''] = $all_option;
        foreach ($installed_languages as $lang)
                        $items[$lang['code']] = $lang['name'];
-       
        return array_selector($name, $selected_id, $items);
 }
 
-function languages_list_cells($label, $name, $selected_id=null)
+function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
 {
        if ($label != null)
                echo "<td>$label</td>\n";
        echo "<td>";
-       echo languages_list($name, $selected_id);
+       echo languages_list($name, $selected_id, $all_option);
        echo "</td>\n";
 }
 
-function languages_list_row($label, $name, $selected_id=null)
+function languages_list_row($label, $name, $selected_id=null, $all_option=false)
 {
-       echo "<tr>\n";
-       languages_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       languages_list_cells(null, $name, $selected_id, $all_option);
        echo "</tr>\n";
 }
 
@@ -1692,8 +1700,8 @@ function bank_account_types_list_cells($label, $name, $selected_id=null)
 
 function bank_account_types_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr>\n";
-       bank_account_types_list_cells($label, $name, $selected_id);
+       echo "<tr><td class='label'>$label</td>";
+       bank_account_types_list_cells(null, $name, $selected_id);
        echo "</tr>\n";
 }
 
@@ -1723,8 +1731,8 @@ function payment_person_types_list_cells($label, $name, $selected_id=null, $rela
 
 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
 {
-       echo "<tr>\n";
-       payment_person_types_list_cells($label, $name, $selected_id, $related);
+       echo "<tr><td class='label'>$label</td>";
+       payment_person_types_list_cells(null, $name, $selected_id, $related);
        echo "</tr>\n";
 }
 
@@ -1740,7 +1748,7 @@ function wo_types_list($name, $selected_id=null)
 
 function wo_types_list_row($label, $name, $selected_id=null)
 {
-       echo "<tr><td>$label</td><td>\n";
+       echo "<tr><td class='label'>$label</td><td>\n";
        echo wo_types_list($name, $selected_id);
        echo "</td></tr>\n";
 }
@@ -1751,7 +1759,7 @@ function dateformats_list_row($label, $name, $value=null)
 {
        global $dateformats;
 
-       echo "<tr><td>$label</td>\n<td>";
+       echo "<tr><td class='label'>$label</td>\n<td>";
        echo array_selector( $name, $value, $dateformats );
        echo "</td></tr>\n";
 }
@@ -1760,7 +1768,7 @@ function dateseps_list_row($label, $name, $value=null)
 {
        global $dateseps;
 
-       echo "<tr><td>$label</td>\n<td>";
+       echo "<tr><td class='label'>$label</td>\n<td>";
        echo array_selector( $name, $value, $dateseps );
        echo "</td></tr>\n";
 }
@@ -1769,7 +1777,7 @@ function thoseps_list_row($label, $name, $value=null)
 {
        global $thoseps;
 
-       echo "<tr><td>$label</td>\n<td>";
+       echo "<tr><td class='label'>$label</td>\n<td>";
        echo array_selector( $name, $value, $thoseps );
        echo "</td></tr>\n";
 }
@@ -1778,7 +1786,7 @@ function decseps_list_row($label, $name, $value=null)
 {
        global $decseps;
 
-       echo "<tr><td>$label</td>\n<td>";
+       echo "<tr><td class='label'>$label</td>\n<td>";
        echo array_selector( $name, $value, $decseps );
        echo "</td></tr>\n";
 }
@@ -1799,7 +1807,7 @@ function themes_list_row($label, $name, $value=null)
        }
        ksort($themes);
 
-       echo "<tr><td>$label</td>\n<td>";
+       echo "<tr><td class='label'>$label</td>\n<td>";
        echo array_selector( $name, $value, $themes );
        echo "</td></tr>\n";
 }
@@ -1812,7 +1820,7 @@ function pagesizes_list_row($label, $name, $value=null)
        foreach ($pagesizes as $pz)
                $items[$pz] = $pz;
 
-       echo "<tr><td>$label</td>\n<td>";
+       echo "<tr><td class='label'>$label</td>\n<td>";
        echo array_selector( $name, $value, $items );
        echo "</td></tr>\n";
 }
@@ -1842,8 +1850,8 @@ function systypes_list_cells($label, $name, $value=null, $submit_on_change=false
 
 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       systypes_list_cells($label, $name, $value, false, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       systypes_list_cells(null, $name, $value, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -1922,8 +1930,8 @@ function policy_list_cells($label, $name, $selected=null)
 
 function policy_list_row($label, $name, $selected=null)
 {
-       echo "<tr>\n";
-       policy_list_cells($label, $name, $selected);
+       echo "<tr><td class='label'>$label</td>";
+       policy_list_cells(null, $name, $selected);
        echo "</tr>\n";
 }
 
@@ -1941,8 +1949,8 @@ function credit_type_list_cells($label, $name, $selected=null, $submit_on_change
 
 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       credit_type_list_cells($label, $name, $selected, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       credit_type_list_cells(null, $name, $selected, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -1968,8 +1976,8 @@ function number_list_cells($label, $name, $selected, $from, $to, $no_option=fals
 
 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
 {
-       echo "<tr>\n";
-       echo number_list_cells($label, $name, $selected, $from, $to, $no_option);
+       echo "<tr><td class='label'>$label</td>";
+       echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
        echo "</tr>\n";
 }
 
@@ -1986,7 +1994,7 @@ function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=fal
 
        echo "<tr>";
        if ($label != null)
-               echo "<td>$label</td>\n";
+               echo "<td class='label'>$label</td>\n";
        echo "<td>";
 
        echo array_selector($name, $selected_id, $profiles, 
@@ -2038,15 +2046,17 @@ function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_cha
 
 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
 {
-       echo "<td>$label</td><td>\n";
+       if ($label != null)
+               echo "<td>$label</td>\n";
+       echo "<td>";    
        echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
        echo "</td>";
 }
 
 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
 {
-       echo "<tr>\n";
-       quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
+       echo "<tr><td class='label'>$label</td>";
+       quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -2055,7 +2065,7 @@ function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_cha
 {
        global $quick_actions;
        
-       echo "<tr><td>$label</td><td>";
+       echo "<tr><td class='label'>$label</td><td>";
        echo array_selector($name, $selected_id, $quick_actions, 
                array( 
                        'select_submit'=> $submit_on_change
@@ -2067,7 +2077,7 @@ function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on
 {
        global $quick_entry_types;
                
-       echo "<tr><td>$label</td><td>";
+       echo "<tr><td class='label'>$label</td><td>";
        echo array_selector($name, $selected_id, $quick_entry_types, 
                array( 
                        'select_submit'=> $submit_on_change
@@ -2083,7 +2093,7 @@ function class_types_list_row($label, $name, $selected_id=null, $submit_on_chang
 {
        global $class_types;
        
-       echo "<tr><td>$label</td><td>";
+       echo "<tr><td class='label'>$label</td><td>";
        echo array_selector($name, $selected_id, $class_types, 
                array( 
                        'select_submit'=> $submit_on_change
@@ -2122,8 +2132,8 @@ function security_roles_list_cells($label, $name, $selected_id=null, $new_item=f
 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
        $show_inactive = false)
 {
-       echo "<tr>";
-       security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
+       echo "<tr><td class='label'>$label</td>";
+       security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
        echo "</tr>\n";
 }
 
@@ -2142,7 +2152,7 @@ function tab_list_row($label, $name, $selected_id=null, $all = false)
                }
        }
        echo "<tr>\n";
-       echo "<td>$label</td><td>\n";
+       echo "<td class='label'>$label</td><td>\n";
        echo array_selector($name, $selected_id, $tabs);
        echo "</td></tr>\n";
 }
@@ -2184,8 +2194,8 @@ function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false,
 
 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
 {
-       echo "<tr>\n";
-       tag_list_cells($label, $name, $height, $type, $mult, $all, $spec_opt);
+       echo "<tr><td class='label'>$label</td>";
+       tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
        echo "</tr>\n"; 
 }
 
@@ -2208,4 +2218,40 @@ function extset_list($name, $value=null, $submit_on_change=false)
                ));
 }
 
+function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
+{
+
+       $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
+
+       $multi = false;
+       $groups = false;
+       $where = array();
+       if (@$filter['class']) {
+               $where[] = 'type='.db_escape($filter['class']);
+       } else
+               $groups = 'type';
+       if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
+       if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
+       if (@$filter['multi']) { // contact category selector for person
+               $multi = true;
+       }
+
+       return combo_input($name, $selected_id, $sql, 'id', 'name',
+               array(
+                       'multi' => $multi,
+                       'height' => $multi ? 5:1,
+                       'category' => $groups,
+                       'select_submit'=> $submit_on_change,
+                       'async' => true,
+                       'where' => $where
+               ));
+}
+
+function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
+{
+       echo "<tr><td class='label'>$label</td><td>";
+       echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
+       echo "</td></tr>\n";
+}
+
 ?>
\ No newline at end of file