Changeset 577


Ignore:
Timestamp:
01/07/09 17:14:51 (15 years ago)
Author:
niltonneto
Message:

Resolve #348

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/inc/class.bocategories.inc.php

    r2 r577  
    9696                } 
    9797 
    98                 function get_list() 
     98                function get_list($id_group) 
    9999                { 
    100                         if($this->debug) { echo '<br>querying: "' . $this->query . '"'; } 
    101                         return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,True); 
     100                        if($this->debug) { echo '<br>querying: "' . $this->query . '"'; }                        
     101                        return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,True,'',$id_group); 
    102102                } 
    103103 
  • trunk/admin/inc/class.uicategories.inc.php

    r2 r577  
    6969 
    7070                        $dir = dir(PHPGW_SERVER_ROOT.'/phpgwapi/images'); 
     71 
    7172                        while($file = $dir->read()) 
    7273                        { 
     
    115116                        $this->template->set_var('lang_save',lang('Save')); 
    116117                        $this->template->set_var('lang_search',lang('Search')); 
     118                        $this->template->set_var('lang_group_name',lang('group name')); 
     119                        $this->template->set_var('lang_cat_name',lang('category name')); 
    117120                        $this->template->set_var('lang_sub',lang('Add sub')); 
    118121                        $this->template->set_var('lang_icon',lang('icon')); 
     
    129132                        $this->template->set_var('lang_color',lang('Color')); 
    130133                        $this->template->set_var('lang_icon',lang('Icon')); 
     134                        $this->template->set_var('lang_Loading',lang("Loading")); 
     135                        $this->template->set_var('lang_Searching', lang("search groups"));                               
     136                        $this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));                                                                                                      
     137                        $this->template->set_var('lang_Search_for', lang("Search Groups"));                                                                      
     138                        $this->template->set_var('lang_cat_all', lang("All")); 
     139                        $this->template->set_var('lang_permission', lang("Permission")); 
     140                        $this->template->set_var('lang_Loading',lang("Loading")); 
     141                        $this->template->set_var('lang_Searching', lang("Search Groups")); 
     142                        $this->template->set_var('lang_Owner', lang("Owner (User/Group)")); 
     143                        $this->template->set_var('lang_Add', lang("Add")); 
     144                        $this->template->set_var('lang_Remove', lang("Remove"));                         
     145                        $this->template->set_var('lang_Search_for', lang("Search Groups")); 
     146                        $this->template->set_var('lang_typemoreletters',lang("Type more %1 letters.","X"));                              
    131147                } 
    132148 
     
    148164                                $GLOBALS['phpgw']->redirect_link('/admin/index.php'); 
    149165                        } 
    150  
     166         
     167                         
    151168                        $this->template->set_file(array('cat_list_t' => 'listcats.tpl')); 
    152169                        $this->template->set_block('cat_list_t','cat_list','list'); 
     
    164181                        echo parse_navbar(); 
    165182                        $this->set_langs(); 
     183 
    166184                        $this->template->set_var('query',$this->query); 
     185                         
     186                        // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.  
     187                        if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) { 
     188                                $this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];                                                     
     189                                $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail'])); 
     190                                if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                                
     191                                        $ldap_manager = CreateObject('contactcenter.bo_ldap_manager'); 
     192                                        $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];                                
     193                                        $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; 
     194                                        $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server']; 
     195                                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null; 
     196                                        // Carrega todos scripts necessarios                             
     197                                        $scripts =      "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>". 
     198                                                                "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                         
     199                                                                "<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>"; 
     200                                        // Fim 
     201                                } 
     202                                $this->template->set_var('scripts',$scripts);                    
     203                        } 
     204                        $this->template->set_var('template_set',$this->template_dir); 
    167205 
    168206                        $link_data['menuaction'] = 'admin.uicategories.index'; 
     
    173211                                $start = 0; 
    174212                        } 
    175  
    176                         $cats = $this->bo->get_list(); 
     213                        list($idgroup,$namegroup) = explode('.', @$_POST['group']);                       
     214                        if($this-> query || $namegroup) 
     215                                $result_search = lang("result")." :: ".lang("about")." <b>'".($this-> query ? $this-> query : $namegroup)."'</b> :: "; 
     216                        else 
     217                                $this->template->set_var('type_search_'.($_POST['typesearch'] ? $_POST['typesearch'] : 'a').'_checked', "checked");                                              
     218                        $cats = $this->bo->get_list($idgroup); 
     219 
    177220                        if (!is_array($cats)) $cats = array(); 
    178221 
     
    182225                        $this->template->set_var('right',$right); 
    183226 
    184                         $this->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start)); 
    185  
    186                         $this->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data)); 
    187                         $this->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data)); 
     227                        $this->template->set_var('lang_showing',$result_search.$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start));                       
     228 
     229                        $this->template->set_var('sort_name', !$_POST['typesearch'] ? $this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),$link_data) : lang('Name')); 
     230                        $this->template->set_var('sort_description', !$_POST['typesearch'] ? $this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),$link_data) : lang('Description')); 
    188231 
    189232                        foreach($cats as $cat) 
     
    268311                                } 
    269312                                else 
    270                                 { 
     313                                {                                        
    271314                                        $this->template->set_var('edit',''); 
    272315                                } 
     
    283326 
    284327                                $data = unserialize($cat['data']); 
    285                                 $icon = $data['icon']; 
     328                                $icon = $data['icon'];                           
     329                                $permission = ($cat['owner'] == '-1' ? lang("all"): $cat['owner']); 
     330                                $this->template->set_var('permission', $permission); 
    286331                                $dir_img = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'phpgwapi' . SEP . 'images' . SEP; 
    287                                 $this->template->set_var('icon', "<img src='". $dir_img . $icon  ."'>"); 
     332                                $this->template->set_var('icon', !$icon ? lang("None") : "<img src='". $dir_img . $icon  ."'>"); 
    288333 
    289334                                $this->template->fp('list','cat_list',True); 
     
    303348                        $cat_parent                     = (int)$_POST['cat_parent']; 
    304349                        $cat_name                       = $_POST['cat_name']; 
    305                         $cat_description        = $_POST['cat_description']; 
     350                        $cat_description                = $_POST['cat_description']; 
    306351                        $cat_data                       = $_POST['cat_data']; 
    307352                        $old_parent                     = (int)$_POST['old_parent']; 
     353                        $cat_group                      = $_POST['idgroup']; 
    308354                         
    309355                        if ($new_parent) 
     
    328374                        } 
    329375 
     376                         
    330377                        if ($_POST['save']) 
    331378                        { 
     
    337384                                        'descr'                 => $cat_description, 
    338385                                        'name'                  => $cat_name, 
     386                                        'group'                 => $cat_group, 
    339387                                        'access'                => 'public', 
    340388                                        'data'                  => $data 
     
    360408 
    361409                        $this->set_langs(); 
     410                // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.  
     411                if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) { 
     412                        $this->template_dir = 'calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];                                                     
     413                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail'])); 
     414                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                                
     415                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager'); 
     416                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];                                
     417                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; 
     418                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server']; 
     419                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null; 
     420                                // Carrega todos scripts necessarios                             
     421                                $scripts =      "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>". 
     422                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                         
     423                                                        "<script src='".$this->template_dir."/js/search.js' type='text/javascript'></script>";                           
     424                                // Fim                                                           
     425                                $this->template->set_var('scripts',$scripts); 
     426                                $this->template->set_var('template_set', $this->template_dir); 
     427                        } 
     428                } 
     429                // FIM if. 
    362430 
    363431                        $this->template->set_file(array('form' => 'category_form.tpl')); 
     
    368436                                $cat['data'] = unserialize($cat['data']); 
    369437                        } 
     438                         
    370439                        else 
    371440                        { 
     
    373442                                $cat['parent'] = $_GET['cat_parent']; 
    374443                        } 
     444 
    375445                        // update the old calendar color format, color was added to the description 
    376446                        if (preg_match('/(#[0-9a-fA-F]{6})\n?$/',$cat['description'],$matches)) 
     
    381451 
    382452                        $hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n" . 
    383                                 '<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">' . "\n"; 
     453                                '<input type="hidden" name="old_parent" value="' . $cat['parent'] . '">' . "\n". 
     454                                '<input type="hidden" id="idgroup" name="idgroup" value="' . $cat['id_group'] . '">' . "\n"; 
    384455 
    385456                        $link_data['menuaction']        = 'admin.uicategories.edit'; 
     
    401472                        $this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cat['description'])); 
    402473                        $this->template->set_var('category_list',$this->bo->cats->formatted_list(array('selected' => $cat['parent'],'self' => $this->cat_id))); 
    403  
     474                        $this->template->set_var('category_namegroup',$GLOBALS['phpgw']->strip_html($cat['name_group'])); 
     475                        $this->template->set_var('bt_rem_id_group_visibility',$cat['name_group'] ? "visible" : "hidden"); 
    404476                        if (!is_object($GLOBALS['phpgw']->html)) 
    405477                        { 
     
    407479                        } 
    408480                        $this->template->set_var('color',$GLOBALS['phpgw']->html->inputColor('cat_data[color]',$cat['data']['color'],lang('Click to select a color'))); 
    409  
    410                         $options = '<option value=""'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n"; 
     481                        $options = ''; 
     482                        //$options = '<option value="aanone.gif"'.(!$cat['data']['icon'] ? ' selected="1"':'').'>'.lang('none')."</options>\n"; 
    411483                        foreach ($this->icons as $icon) 
    412484                        { 
     485                                if(!$cat['data']['icon']){ 
     486                                        $cat['data']['icon'] = "aanone.gif"; 
     487                                } 
    413488                                $options .= '<option value="'.$icon.'"'.($icon == $cat['data']['icon'] ? ' selected="1"':'').'>'. 
    414                                         ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon))."</option>\n"; 
     489                                        ucfirst(preg_replace('/\\.(png|gif|jpe?g)$/i','',$icon == 'aanone.gif' ? lang('none') : $icon))."</option>\n"; 
    415490                        } 
    416491                        $this->template->set_var('select_icon', '<select name="cat_data[icon]" onchange="document.images[\'icon\'].src=\''.$this->img_url.'\' + this.value;">'.$options."</select>\n"); 
    417                         $this->template->set_var('icon','<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">'); 
     492                        $this->template->set_var('icon',  '<img id="icon" src="'. $this->img_url.$cat['data']['icon'] .'">'); 
    418493 
    419494                        $already_done = array('icon','color'); 
  • trunk/admin/templates/default/category_form.tpl

    r2 r577  
    1  
    21<!-- BEGIN form --> 
     2<input type="hidden" id="txt_loading" value="{lang_Loading}"> 
     3<input type="hidden" id="txt_searching" value="{lang_Searching}"> 
     4<input type="hidden" id="txt_multipleGroup" value="{lang_Groups}"> 
     5<input type="hidden" id="txt_typemoreletters" value="{lang_typemoreletters}"> 
    36<br> 
    47<center> 
     
    69<table border="0" width="80%" cellspacing="2" cellpadding="2">  
    710<form name="edit_cat" action="{actionurl}" method="POST"> 
     11{hidden_vars} 
    812        <tr class="th"> 
    913                <td colspan="2">{lang_parent}</td> 
     
    1822                <td colspan="2"><textarea name="cat_description" rows="4" cols="50" wrap="virtual">{cat_description}</textarea></td> 
    1923        </tr> 
     24        <tr class="row_on"> 
     25                <td colspan="2">{lang_Search_for}</td> 
     26            <td valign="center" colspan="2"><input type="text" id="search_group" size=30 autocomplete="off" onkeyup="javascript:search_object(this,'cal_span_searching','groupsfound','g')"/> 
     27            &nbsp;<font color="red"><span id="cal_span_searching">&nbsp;</span></font><br/> 
     28            <select id="groupsfound" style="width: 300px" size="4"></select> 
     29            <button type="button" onClick="javascript:add('groupsfound','group');"><img src="{template_set}/images/add.png" style="vertical-align: bottom;"/></button></td> 
     30        </tr> 
     31        <tr class="row_off"> 
     32                <td colspan="2">{lang_Owner}</td> 
     33                <td valign="center" colspan="2"><label id="namegroup" style="font-weight:bold">{category_namegroup}</label> 
     34                <button valign="top" style="visibility:{bt_rem_id_group_visibility}" id="bt_rem_idgroup" type="button" onClick="javascript:remove('group');"><img src="{template_set}/images/delete.png" style="vertical-align: middle;" /></button></td> 
     35        </tr> 
     36 
    2037        <tr class="row_on"> 
    2138                <td colspan="2">{lang_color}</td> 
     
    3249        </tr> 
    3350<!-- END data_row --> 
    34  
    3551        <tr valign="bottom" height="50"> 
    36                 <td> 
    37                         {hidden_vars} 
    38                         <input type="submit" name="save" value="{lang_save}"></form></td> 
    39                 <td> 
    40                         <form method="POST" action="{cancel_url}"> 
    41                         <input type="submit" name="cancel" value="{lang_cancel}"></form></td> 
     52                <td><input type="submit" name="save" value="{lang_save}"></td> 
     53                <td><form method="POST" action="{cancel_url}"><input type="submit" name="cancel" value="{lang_cancel}"></form></td> 
    4254                <td align="right">{delete}</td> 
    4355        </tr> 
    4456</table> 
     57</form> 
    4558</center> 
    4659 
    4760<!-- END form --> 
     61<script language="JavaScript" type="text/javascript"> 
     62function remove(to){ 
     63        document.getElementById("name"+to).innerHTML = ''; 
     64        document.getElementById("id"+to).value = '-1'; 
     65        show_button("id"+to); 
     66}  
     67function show_button(id){ 
     68        document.getElementById("bt_rem_"+id).style.visibility =  
     69                (document.getElementById(id).value != '-1'  ? 'visible' : 'hidden'); 
     70} 
     71function add(from, to){ 
     72        var sel_from = document.getElementById(from); 
     73        for (i = 0 ; i < sel_from.length; i++){ 
     74                if (sel_from[i].selected) { 
     75                        var name = document.getElementById("name"+to); 
     76                        var id = document.getElementById("id"+to); 
     77                        name.innerHTML = sel_from.options[i].text; 
     78                        id.value  = sel_from[i].value; 
     79                        show_button("id"+to); 
     80                        break; 
     81                } 
     82        } 
     83} 
     84</script> 
     85{scripts} 
  • trunk/admin/templates/default/listcats.tpl

    r2 r577  
    1  
    21        <center> 
    3                 <table border="0" cellspacing="2" cellpadding="2"> 
     2                <table border="0" cellspacing="1" cellpadding="2"> 
     3<!-- BEGIN search --> 
    44                        <tr> 
    5                                 <td colspan="5" align="left"> 
     5                                <td colspan="5" align="left" valign="top"><form name="form1" method="post" onSubmit="return on_submit()" action="{action_nurl}">&nbsp;                                   
     6                                        <input type="radio" onclick="javascript:changeElement();" name="typesearch" value="g" {type_search_g_checked}/>{lang_group_name}&nbsp; 
     7                                        <input type="radio" onclick="javascript:changeElement();" name="typesearch" value="c" {type_search_c_checked}/>{lang_cat_name}&nbsp; 
     8                                        <input type="radio" onclick="javascript:changeElement();" name="typesearch" value="a" {type_search_a_checked}/>{lang_cat_all}<br> 
     9                                        <div id="filterByGroup" style="display:none"><br> 
     10                                        {lang_Search_for}&nbsp;<input type="text" id="search_group" size=30 autocomplete="off" onkeyup="javascript:search_object(this,'cal_span_searching','groupsfound','g')"/><br> 
     11                                    &nbsp;<font color="red"><span id="cal_span_searching">&nbsp;</span></font><br/> 
     12                                    <input type="hidden" id="group" name="group"/> 
     13                                    <select id="groupsfound" style="width: 300px" size="4"></select>&nbsp;<input type="submit" value="{lang_search}"> 
     14                                        </div> 
     15                                        <div id="filterByName" style="display:none"><br> 
     16                                        <input id="query" type="text" name="query" value="">&nbsp;<input type="submit" value="{lang_search}"> 
     17                                        </form> 
     18                                </td> 
     19                        </tr> 
     20<!-- END search --> 
     21                 
     22                        <tr> 
     23                                <td colspan="6" align="left"> 
    624                                        <table border="0" width="100%"> 
    725                                                <tr> 
     
    1331                                </td> 
    1432                        </tr> 
    15 <!-- BEGIN search --> 
    16                         <tr> 
    17                                 <td colspan="5" align="right"> 
    18                                         <form method="post" action="{action_nurl}"> 
    19                                         <input type="text" name="query">&nbsp;<input type="submit" name="search" value="{lang_search}"></form></td> 
    20                         </tr> 
    21 <!-- END search --> 
    2233                        <tr class="th"> 
    2334                                <td width="20%">{sort_name}</td> 
    2435                                <td width="32%">{sort_description}</td> 
    25                                 <td>{lang_icon}</td> 
     36                                <td width="1%" align="center">{lang_icon}</td> 
     37                                <td width="8%" align="center">{lang_permission}</td> 
    2638                                <td width="8%" align="center">{lang_sub}</td> 
    2739                                <td width="8%" align="center">{lang_edit}</td> 
     
    3446                                <td>{name}</td> 
    3547                                <td>{descr}</td> 
    36                                 <td>{icon}</td> 
     48                                <td align="center">{icon}</td> 
     49                                <td align="center">{permission}</td> 
    3750                                <td align="center">{add_sub}</a></td> 
    3851                                <td align="center">{edit}</a></td> 
     
    5366                </table> 
    5467        </center> 
     68{scripts} 
     69<input type="hidden" id="txt_loading" value="{lang_Loading}"> 
     70<input type="hidden" id="txt_searching" value="{lang_Searching}"> 
     71<input type="hidden" id="txt_typemoreletters" value="{lang_typemoreletters}"> 
     72<script language="JavaScript" type="text/javascript"> 
     73        function on_submit(){ 
     74                var select_group = document.getElementById("groupsfound"); 
     75                if(document.getElementById("query").value == "" && select_group.value == ""){ 
     76                        return false; 
     77                } 
     78                else if(select_group.options.length == 0) 
     79                        return true;                     
     80                for(j in select_group.options){ 
     81                        if(select_group.selectedIndex == j) 
     82                                document.getElementById("group").value =  select_group.options[j].value+"."+select_group.options[j].text; 
     83                } 
     84                return true;             
     85        } 
     86        function changeElement(){ 
     87                var types =     document.form1.typesearch; 
     88                for(j in types){ 
     89                        if(types[j].checked){ 
     90                                if(types[j].value == 'a'){                               
     91                                        location.href = location.href.toString(); 
     92                                } 
     93                                document.getElementById('filterByGroup').style.display  = (types[j].value == 'g' ? '' : 'none'); 
     94                                document.getElementById('filterByName').style.display   = (types[j].value == 'g' || types[j].value == 'a' ? 'none' : ''); 
     95                        } 
     96                } 
     97        } 
     98</script> 
  • trunk/phpgwapi/inc/class.categories.inc.php

    r2 r577  
    5656                        $this->app_name         = $GLOBALS['phpgw']->db->db_addslashes($app_name); 
    5757                        $this->db                       = $GLOBALS['phpgw']->db; 
    58                         $this->db2                      = $this->db; 
     58                        $this->db2                      = $this->db;                     
    5959                        $this->grants           = $GLOBALS['phpgw']->acl->get_grants($app_name); 
    6060                } 
     
    137137                @param $order order by 
    138138                @param $globals True or False, includes the global egroupware categories or not 
     139                @param $parent_id 
     140                @param $lastmod integer defaults to -1 
     141                @param column string default to '' (All), includes the column returned. 
    139142                @result $cats array 
    140143                */ 
    141144                function return_array($type,$start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '', $lastmod = -1, $column = '') 
    142145                { 
    143                         //casting and addslashes for security 
    144                         $start          = (int)$start; 
    145                         $parent_id      = (int)$parent_id; 
    146                         $query          = $this->db->db_addslashes($query); 
    147                         $sort           = $this->db->db_addslashes($sort); 
    148                         $order          = $this->db->db_addslashes($order); 
    149  
    150                         if ($globals) 
    151                         { 
    152                                 $global_cats = " OR cat_appname='phpgw'"; 
    153                         } 
    154  
    155                         $filter = $this->filter($type); 
    156  
     146                        return $this -> return_sorted_array( $start, $limit, $query, $sort, $order, $globals, $parent_id, NULL, $lastmod, $column); 
     147                } 
     148                /*! 
     149                @function return_sorted_array 
     150                @abstract return an array populated with categories 
     151                @param $type string defaults to 'all' 
     152                @param $start ? 
     153                @param $limit ? 
     154                @param $query string defaults to '' 
     155                @param $sort string sort order, either defaults to 'ASC' 
     156                @param $order order by 
     157                @param $globals True or False, includes the global egroupware categories or not 
     158                @param $parent_id string defaults to '', includes the parent category ID 
     159                @param $group_id integer defaults to NULL, includes the gidNumber 
     160                @param $lastmod integer defaults to -1 
     161                @param column string default to '' (All), includes the column returned. 
     162                @result $cats array 
     163                */                       
     164                function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '',$group_id = NULL,$lastmod = -1, $column = '') 
     165                { 
     166                        //casting and slashes for security 
     167                        $start = (int)$start; 
     168                        $query = $this->db->db_addslashes($query); 
     169                        $sort  = $this->db->db_addslashes($sort); 
     170                        $order = $this->db->db_addslashes($order); 
     171                        $parent_id = (int)$parent_id; 
     172 
     173                        if ($globals && !$group_id) 
     174                        { 
     175                                $global_cats = " cat_appname='phpgw'"; 
     176                        } 
     177                         
    157178                        if (!$sort) 
    158179                        { 
     
    160181                        } 
    161182 
    162                         if (!empty($order) && preg_match('/^[a-zA-Z_(), ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort))) 
     183                        if (!empty($order) && preg_match('/^[a-zA-Z_, ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort))) 
    163184                        { 
    164185                                $ordermethod = " ORDER BY $order $sort"; 
     
    166187                        else 
    167188                        { 
    168                                 $ordermethod = ' ORDER BY cat_main, cat_level, cat_name ASC'; 
    169                         } 
    170  
    171                         if ($this->account_id == '-1') 
    172                         { 
    173                                 $grant_cats = ' cat_owner=-1 '; 
    174                         } 
    175                         else 
    176                         { 
     189                                $ordermethod = ' ORDER BY cat_name ASC'; 
     190                        } 
     191                                                                         
     192                        if($group_id){ 
     193                                $grant_cats .= " cat_owner='".$group_id."' "; 
     194                        } 
     195                        else if ($this->account_id != '-1'){ 
     196                                $grants = $this->grants; 
     197                                $groups = $GLOBALS['phpgw']->accounts->membership(); 
     198                         
    177199                                if (is_array($this->grants)) 
    178200                                { 
    179                                         $grants = $this->grants; 
    180                                         while(list($user) = each($grants)) 
    181                                         { 
    182                                                 $public_user_list[] = $user; 
    183                                         } 
    184                                         reset($public_user_list); 
    185                                         $grant_cats = ' (cat_owner=' . $this->account_id . " OR cat_owner=-1 OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ')) '; 
     201                                         
     202                                        foreach($grants as $idx => $user){                                                                                               
     203                                                $public_user_list[$user] = $user; 
     204                                        } 
     205                                        if(is_array($groups)){ 
     206                                                foreach($groups as $idx => $group) { 
     207                                                        $public_user_list[$group['account_id']] = $group['account_id']; 
     208                                                } 
     209                                        } 
     210                                        @reset($public_user_list); 
     211                                        $grant_cats = " (cat_owner='" . $this->account_id . "' ".(is_array($public_user_list) ? "OR (cat_owner in(" . implode(',',$public_user_list) . ")  AND cat_access='public')" : "").") "; 
     212                                         
    186213                                } 
    187214                                else 
    188215                                { 
    189                                         $grant_cats = ' cat_owner=' . $this->account_id . ' OR cat_owner=-1 '; 
    190                                 } 
    191                         } 
    192  
    193                         if ($parent_id > 0) 
    194                         { 
    195                                 $parent_filter = ' AND cat_parent=' . $parent_id; 
    196                         } 
     216                                        $grant_cats = " cat_owner='" . $this->account_id . "' or cat_owner='-1' "; 
     217                                } 
     218                        } 
     219                         
     220 
     221                        $parent_select = ' AND cat_parent=' . $parent_id; 
    197222 
    198223                        if ($query) 
    199224                        { 
    200                                 $querymethod = " AND (cat_name LIKE '%$query%' OR cat_description LIKE '%$query%') "; 
     225                                $querymethod = " AND (cat_name ILIKE '%$query%' OR cat_description ILIKE '%$query%') "; 
    201226                        } 
    202227 
     
    228253                        } 
    229254 
    230                         $sql = "SELECT $table_column FROM phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ')' 
    231                                 . $parent_filter . $querymethod . $filter; 
    232  
    233                         $this->db2->query($sql,__LINE__,__FILE__); 
    234                         $this->total_records = $this->db2->num_rows(); 
    235  
    236                         if ($limit) 
    237                         { 
    238                                 $this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__); 
    239                         } 
    240                         else 
    241                         { 
    242                                 $this->db->query($sql . $ordermethod,__LINE__,__FILE__); 
    243                         } 
    244  
    245                         while ($this->db->next_record()) 
    246                         { 
    247                                 if ($column) 
    248                                 { 
    249                                         $cats[] = array 
    250                                         ( 
    251                                                 $column => $this->db->f(0) 
    252                                         ); 
    253                                 } 
    254                                 else 
    255                                 { 
    256                                         $cats[] = array 
    257                                         ( 
    258                                                 'id'                    => $this->db->f('cat_id'), 
    259                                                 'owner'                 => $this->db->f('cat_owner'), 
    260                                                 'access'                => $this->db->f('cat_access'), 
    261                                                 'app_name'              => $this->db->f('cat_appname'), 
    262                                                 'main'                  => $this->db->f('cat_main'), 
    263                                                 'level'                 => $this->db->f('cat_level'), 
    264                                                 'parent'                => $this->db->f('cat_parent'), 
    265                                                 'name'                  => $this->db->f('cat_name'), 
    266                                                 'description'   => $this->db->f('cat_description'), 
    267                                                 'data'                  => $this->db->f('cat_data'), 
    268                                                 'last_mod'              => $this->db->f('last_mod') 
    269                                         ); 
    270                                 } 
    271                         } 
    272                         return $cats; 
    273                 } 
    274  
    275                 function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '') 
    276                 { 
    277                         //casting and slashes for security 
    278                         $start = (int)$start; 
    279                         $query = $this->db->db_addslashes($query); 
    280                         $sort  = $this->db->db_addslashes($sort); 
    281                         $order = $this->db->db_addslashes($order); 
    282                         $parent_id = (int)$parent_id; 
    283  
    284                         if ($globals) 
    285                         { 
    286                                 $global_cats = " OR cat_appname='phpgw'"; 
    287                         } 
    288  
    289                         if (!$sort) 
    290                         { 
    291                                 $sort = 'ASC'; 
    292                         } 
    293  
    294                         if (!empty($order) && preg_match('/^[a-zA-Z_, ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/'))) 
    295                         { 
    296                                 $ordermethod = " ORDER BY $order $sort"; 
    297                         } 
    298                         else 
    299                         { 
    300                                 $ordermethod = ' ORDER BY cat_name ASC'; 
    301                         } 
    302  
    303                         if ($this->account_id == '-1') 
    304                         { 
    305                                 $grant_cats = " cat_owner='-1' "; 
    306                         } 
    307                         else 
    308                         { 
    309                                 if (is_array($this->grants)) 
    310                                 { 
    311                                         $grants = $this->grants; 
    312                                         while(list($user) = each($grants)) 
    313                                         { 
    314                                                 $public_user_list[] = $user; 
    315                                         } 
    316                                         reset($public_user_list); 
    317                                         $grant_cats = " (cat_owner='" . $this->account_id . "' OR cat_owner='-1' OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ")) "; 
    318                                 } 
    319                                 else 
    320                                 { 
    321                                         $grant_cats = " cat_owner='" . $this->account_id . "' or cat_owner='-1' "; 
    322                                 } 
    323                         } 
    324  
    325                         $parent_select = ' AND cat_parent=' . $parent_id; 
    326  
    327                         if ($query) 
    328                         { 
    329                                 $querymethod = " AND (cat_name LIKE '%$query%' OR cat_description LIKE '%$query%') "; 
    330                         } 
    331  
    332                         $sql = "SELECT * FROM phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ")" 
    333                                         . $querymethod; 
    334  
     255 
     256                        $sql = "SELECT".$table_column."FROM phpgw_categories WHERE (cat_appname='" . $this->app_name. "' ". 
     257                                        ($grant_cats ? " AND".$grant_cats : "") .($global_cats ? " OR".$global_cats: ""). 
     258                                        ")".$querymethod;                                                
     259                         
    335260                        $this->db2->query($sql . $parent_select,__LINE__,__FILE__); 
    336261                        $total = $this->db2->num_rows(); 
     
    350275                                $cats[$i]['id']          = (int)$this->db->f('cat_id'); 
    351276                                $cats[$i]['owner']       = (int)$this->db->f('cat_owner'); 
     277                                if($cats[$i]['owner'] > 0){ 
     278                                //      Load Name Group. 
     279                                        $group = $this->get_group($cats[$i]['owner']); 
     280                                        $cats[$i]['owner'] = $group['name']; 
     281                                } 
    352282                                $cats[$i]['access']      = $this->db->f('cat_access'); 
    353283                                $cats[$i]['app_name']    = $this->db->f('cat_appname'); 
     
    358288                                $cats[$i]['description'] = $this->db->f('cat_description'); 
    359289                                $cats[$i]['data']        = $this->db->f('cat_data'); 
     290                                         
    360291                                $i++; 
    361292                        } 
     
    365296                        { 
    366297                                $sub_select = ' AND cat_parent=' . $cats[$i]['id'] . ' AND cat_level=' . ($cats[$i]['level']+1); 
    367  
    368                                 /*$this->db2->query($sql . $sub_select,__LINE__,__FILE__); 
    369                                 $total_subs += $this->db2->num_rows(); 
    370  
    371                                 if ($limit) 
    372                                 { 
    373                                         $this->db->limit_query($sql . $sub_select . $ordermethod,$start,__LINE__,__FILE__); 
    374                                 } 
    375                                 else 
    376                                 {*/ 
    377                                         $this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__); 
    378                                         $total += $this->db->num_rows(); 
    379                                 //} 
     298                                $this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__); 
     299                                $total += $this->db->num_rows(); 
    380300 
    381301                                $subcats = array(); 
     
    429349                { 
    430350                        $this->db->query('SELECT * FROM phpgw_categories WHERE cat_id=' . (int)$id,__LINE__,__FILE__); 
    431  
    432351                        if ($this->db->next_record()) 
    433352                        { 
     
    442361                                $cats[0]['description'] = $this->db->f('cat_description'); 
    443362                                $cats[0]['data']        = $this->db->f('cat_data'); 
     363                                if($cats[0]['owner'] > 0){ 
     364                                //      Load Group. 
     365                                        $group = $this->get_group($cats[0]['owner']); 
     366                                        $cats[0]['id_group']    = $group['id']; 
     367                                        $cats[0]['name_group']  = $group['name'];                                        
     368                                }                                
    444369                        } 
    445370                        return $cats; 
     
    459384                        return $this->formated_list($format,$type,$selected,$globals,$site_link); 
    460385                } 
     386                function get_group($id) 
     387                { 
     388                        if (!IsSet($id)) 
     389                                return ""; 
     390                        return array("id" => $id, "name" => $GLOBALS['phpgw']->accounts->id2name($id)); 
     391                } 
     392 
    461393                function formated_list($format,$type='',$selected = '',$globals = False,$site_link = 'site') 
    462394                { 
     
    591523                                $id_val = $values['id'] . ','; 
    592524                        } 
    593  
    594525                        $this->db->query('INSERT INTO phpgw_categories (' . $id_col . 'cat_parent,cat_owner,cat_access,cat_appname,cat_name,cat_description,cat_data,' 
    595                                 . 'cat_main,cat_level, last_mod) VALUES (' . $id_val . (int)$values['parent'] . ',' . $this->account_id . ",'" . $values['access'] 
     526                                . 'cat_main,cat_level, last_mod) VALUES (' . $id_val . (int)$values['parent'] . ',' . ($values['group']!= 0 ? $values['group'] : $this->account_id) . ",'" . $values['access'] 
    596527                                . "','" . $this->app_name . "','" . $values['name'] . "','" . $values['descr'] . "','" . $values['data'] 
    597528                                . "'," . (int)$values['main'] . ',' . (int)$values['level'] . ',' . time() . ')',__LINE__,__FILE__); 
     
    687618                        $values['id']     = (int)$values['id']; 
    688619                        $values['parent'] = (int)$values['parent']; 
    689  
     620                        $values['owner'] = (int)$values['group']; 
     621                        if($values['owner']){ 
     622                                $owner = "cat_owner = ".$values['owner'].","; 
     623                        } 
    690624                        if (isset($values['old_parent']) && (int)$values['old_parent'] != $values['parent']) 
    691625                        { 
     
    710644                        $values['name'] = $this->db->db_addslashes($values['name']); 
    711645 
    712                         $sql = "UPDATE phpgw_categories SET cat_name='" . $values['name'] . "', cat_description='" . $values['descr'] 
     646                        $sql = "UPDATE phpgw_categories SET $owner cat_name='" . $values['name'] . "', cat_description='" . $values['descr'] 
    713647                                . "', cat_data='" . $values['data'] . "', cat_parent=" . $values['parent'] . ", cat_access='" 
    714648                                . $values['access'] . "', cat_main=" . $values['main'] . ', cat_level=' . $values['level'] . ',last_mod=' . time() 
Note: See TracChangeset for help on using the changeset viewer.