Merged changes form main trunk (2.2.8, 2.2.9)
[fa-stable.git] / includes / ui / ui_lists.inc
index ab9a96592452cc0dac5442927f100fb0781901a4..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 ';
@@ -328,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'])
@@ -344,17 +344,15 @@ $opts = array(            // default options
 //if($name=='SelectStockFromList') display_error($sql);
                foreach($items as $value=>$descr) {
                        $sel = '';
-                       if (in_array((string)$value, $selected_id), true) {
-                               $sel = "selected='selected'";
+                       if (in_array((string)$value, $selected_id, true)) {
+                               $sel = 'selected';
                                $found = $value;
                        }
                        if ($first_id === false) {
                                $first_id = $value;
-                               $first_opt = "<option %s value='$value'>$descr</option>\n";
-                       } 
-                       else {
-                               $selector .= "<option $sel value='$value'>$descr</option>\n";
+                               $first_opt = $descr;
                        }
+                       $selector .= "<option $sel value='$value'>$descr</option>\n";
                }
 
        if ($first_id!==false) {
@@ -365,7 +363,7 @@ $opts = array(              // default options
        if ($spec_option !== false) { // if special option used - add it
                $first_id = $spec_id;
                $first_opt = $spec_option;
-               $sel = $found===false ? "selected='selected'" : '';
+               $sel = $found===false ? 'selected' : '';
                $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
                        . $selector;
        }
@@ -374,6 +372,7 @@ $opts = array(              // default options
                $selected_id = array($first_id);
        }
        $_POST[$name] = $multi ? $selected_id : $selected_id[0];
+
        $selector = "<select autocomplete='off' ".($multi  ? "multiple" : '')
                . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
                . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
@@ -1539,7 +1538,7 @@ function gl_account_types_list($name, $selected_id=null, $all_option=false, $all
 
        return combo_input($name, $selected_id, $sql, 'id', 'name',
        array(
-               'order' => 'class_id', 'id',
+               'order' => array('class_id', 'id', 'parent'),
                'spec_option' =>$all_option,
                'spec_id' => $all_items
        ) );
@@ -1653,30 +1652,31 @@ function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no
 
 //------------------------------------------------------------------------------------------------
 
-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><td class='label'>$label</td>";
-       languages_list_cells(null, $name, $selected_id);
+       languages_list_cells(null, $name, $selected_id, $all_option);
        echo "</tr>\n";
 }
 
@@ -1851,7 +1851,7 @@ 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><td class='label'>$label</td>";
-       systypes_list_cells(null, $name, $value, false, $submit_on_change);
+       systypes_list_cells(null, $name, $value, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -2218,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