Ignore:
Timestamp:
06/04/09 10:30:18 (15 years ago)
Author:
alexandrecorreia
Message:

Ticket #505 - Arquivos modificados para a administração de hosts virtuais no servidor Jabber.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jabberit_messenger/inc/class.db_im.inc.php

    r896 r946  
    1414define('PHPGW_API_INC','../phpgwapi/inc'); 
    1515require_once(PHPGW_API_INC . '/class.db.inc.php'); 
     16require_once "class.fileDefine.inc.php"; 
    1617         
    1718class db_im 
     
    2526        private $db_type; 
    2627        private $user_id; 
     28        private $fileD; 
    2729         
    2830        public final function __construct() 
    2931        { 
     32                $this->fileD = new fileDefine(); 
    3033                $this->db_name = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name']; 
    3134                $this->db_host = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host']; 
     
    5154        }        
    5255 
     56        public final function editHostJabber($pItem) 
     57        { 
     58                $hostsJabber = unserialize($this->getHostsJabber()); 
     59                $findHosts      = explode(":", $pItem['item']); 
     60                $return = "";    
     61                 
     62                for( $i = 0 ; $i < count($hostsJabber); $i++ ) 
     63                        if( $hostsJabber[$i]['org'] == $findHosts[0] && $hostsJabber[$i]['jabberName'] == $findHosts[1] ) 
     64                        { 
     65                                $return = "org:" . $hostsJabber[$i]['org'] . ";" . 
     66                                                  "jabberName:" . $hostsJabber[$i]['jabberName'] . ";" .                                                          
     67                                                  "serverLdap:" . $hostsJabber[$i]['serverLdap'] . ";" . 
     68                                                  "contextLdap:" . $hostsJabber[$i]['contextLdap'] . ";" . 
     69                                                  "user:" . $hostsJabber[$i]['user'] . ";" . 
     70                                                  "password:" . $hostsJabber[$i]['password'] ;                                                                                                                                                                                             
     71                        } 
     72 
     73                return trim($return); 
     74        } 
     75         
    5376        public final function getApplicationsEnabled() 
    5477        { 
     
    338361        public final function setHostJabber($pParam) 
    339362        { 
    340                 $organization   = $pParam['organization']; 
    341                 $hostJabber             = $pParam['hostJabber']; 
    342          
     363                $confHostsJabber =  array(); 
     364 
     365                foreach($pParam as $key => $itens) 
     366                        $confHostsJabber[$key] = ( $key === 'org' ) ? strtoupper($itens) : $itens; 
     367 
    343368                if( $this->db ) 
    344369                { 
    345370                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';"; 
    346371                         
    347                         if($this->db->query($query)) 
    348                         { 
    349                          
    350                                 if ( $this->db->query($query) ) 
    351                                 {        
    352                                         while($this->db->next_record()) 
    353                                                 $result[] = $this->db->row(); 
    354                                 } 
    355                                  
    356                                 if( count($result) == 0 ) 
    357                                 { 
    358                                         $confHostJabber = strtoupper($organization).":".$hostJabber; 
    359                                         $return = "<return><confServer ou='".strtoupper($organization)."' serverName='".$hostJabber."'>".$confHostJabber."</confServer></return>"; 
    360                                         $query = "INSERT INTO phpgw_config(config_app,config_name, config_value) VALUES('phpgwapi','map_org_realm_jabberit','".serialize($confHostJabber)."')"; 
    361                                         $_SESSION['debug']['gravar'] = $confHostJabber; 
    362                                         $this->db->query($query);                                        
    363                                 } 
     372                        if( $this->db->query($query) ) 
     373                        { 
     374                                while($this->db->next_record()) 
     375                                        $result[] = $this->db->row();                            
     376                        } 
     377                         
     378                        if( count($result) == 0 ) 
     379                        { 
     380                                $return = "<return><confServer ou='".strtoupper($confHostsJabber['org'])."' serverName='".$confHostsJabber['jabberName']."'>".strtoupper($confHostsJabber['org']).":".$confHostsJabber['jabberName']."</confServer></return>";                           
     381                                $hostsJabber[0] = $confHostsJabber; 
     382                                 
     383                                $this->fileD->ldapExternal($hostsJabber); 
     384                                  
     385                                $query = "INSERT INTO phpgw_config(config_app, config_name, config_value) VALUES('phpgwapi','map_org_realm_jabberit','".serialize($hostsJabber)."')"; 
     386                                $this->db->query($query);                                
     387                        } 
     388                        else 
     389                        { 
     390                                $resultQuery = unserialize($result[0]['config_value']);  
     391                                $foundOrg = false; 
     392                                 
     393                                foreach($resultQuery as $key => $itens) 
     394                                { 
     395                                        $foundString = array_search($confHostsJabber['org'], $itens); 
     396                                        if( $foundString ) 
     397                                        { 
     398                                                $foundOrg = $foundString; 
     399                                                $ky = $key; 
     400                                        } 
     401                                }        
     402 
     403                                if( ! $foundOrg ) 
     404                                        $resultQuery[] = $confHostsJabber;       
    364405                                else 
    365                                 { 
    366                                         $confHostJabber = unserialize($result[0]['config_value']); 
    367                                         $OrgHosts = explode(";", $confHostJabber); 
    368                                         $stringSearch = strtoupper($organization).":".$hostJabber; 
    369                                         $FoundString = array_search($stringSearch, $OrgHosts); 
    370  
    371                                         if( $FoundString === false) 
    372                                                 $confHostJabber .= ";" . $stringSearch; 
    373                                  
    374                                         $items = explode(";", $confHostJabber); 
    375                                         natcasesort($items); 
    376                                                                                          
    377                                         $return = "<return>"; 
    378                                         foreach($items as $tmp) 
    379                                         { 
    380                                                 $aux = explode(":",$tmp); 
    381                                                 $return .= "<confServer ou='".$aux[0]."' serverName='".$aux[1]."'>".$tmp."</confServer>"; 
    382                                         }                                        
    383                                         $return .= "</return>"; 
    384  
    385                                         $query = "UPDATE phpgw_config SET config_value = '".serialize($confHostJabber)."' WHERE config_name = 'map_org_realm_jabberit';"; 
    386                                         $this->db->query($query); 
    387                                 } 
    388                                  
    389                                 return $return; 
    390                         } 
    391                 } 
    392  
     406                                        $resultQuery[$ky] = $confHostsJabber; 
     407 
     408                                $return = "<return>"; 
     409                                 
     410                                foreach( $resultQuery as $itens ) 
     411                                        $return .= "<confServer ou='".$itens['org']."' serverName='".$itens['jabberName']."'>".$itens['org'].":".$itens['jabberName']."</confServer>"; 
     412                                 
     413                                $return .= "</return>"; 
     414                                 
     415                                $this->fileD->ldapExternal($resultQuery); 
     416                                 
     417                                $query = "UPDATE phpgw_config SET config_value = '".serialize($resultQuery)."' WHERE config_name = 'map_org_realm_jabberit';"; 
     418                                $this->db->query($query); 
     419                        } 
     420                        return $return; 
     421                }        
    393422                return false; 
    394423        } 
     
    466495        } 
    467496         
    468         public final function setUseParticipantsExternal($pFlag) 
    469         { 
    470                 $flag = $pFlag['value']; 
    471                 $return = ""; 
    472                  
    473                 if( $this->db ) 
    474                 { 
    475                         $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit';"; 
    476  
    477                         if ( $this->db->query($query) ) 
    478                         {        
    479                                 while($this->db->next_record()) 
    480                                         $result[] = $this->db->row(); 
    481                         } 
    482  
    483                         if(count($result) == 0) 
    484                         { 
    485                                 $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','use_external_participants_jabberit','".$flag."')"; 
    486                                 $this->db->query($query); 
    487                                 return true; 
    488                         } 
    489                         else 
    490                         { 
    491                                 $query = "UPDATE phpgw_config SET config_value = '".$flag."' WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit'"; 
    492                                 $this->db->query($query); 
    493                                 return true; 
    494                         } 
    495                 } 
    496                 return false; 
    497         } 
    498          
    499         public final function setOrganization($pOrganization) 
    500         { 
    501                 $organization = $pOrganization['organization']; 
    502                 $orgConfiguration = ""; 
    503                  
    504                 if( $this->db ) 
    505                 { 
    506                         $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'"; 
    507  
    508                         if ( $this->db->query($query) ) 
    509                         {        
    510                                 while($this->db->next_record()) 
    511                                         $result[] = $this->db->row(); 
    512                  
    513                                 if(count($result) > 0) 
    514                                         $orgConfiguration = $result[0]['config_value']; 
    515                         } 
    516  
    517                         if( trim($orgConfiguration) == "" ) 
    518                         { 
    519                                 $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','conf_organization_jabberit','".$organization."')"; 
    520                                 $this->db->query($query); 
    521                                  
    522                                 return "<return><ou attr='".$organization."'>".$organization."</ou></return>"; 
    523                         } 
    524                         else 
    525                         { 
    526                                 $orgAux = explode(",",$orgConfiguration); 
    527                                  
    528                                 foreach( $orgAux as $tmp ) 
    529                                 { 
    530                                         if(strtolower(trim($tmp)) === strtolower(trim($organization))) 
    531                                                 return false; 
    532                                 } 
    533  
    534                                 $value = $orgConfiguration . "," . $organization; 
    535                                 $query = "UPDATE phpgw_config SET config_value = '".$value."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'"; 
    536                                 $this->db->query($query); 
    537  
    538                                 $return = explode(",",$value); 
    539                                 natcasesort($return); 
    540  
    541                                 $values = "<return>"; 
    542                                  
    543                                 foreach($return as $tmp) 
    544                                         $values .= "<ou attr='" . $tmp . "'>" . $tmp . "</ou>"; 
    545                                          
    546                                 $values .= "</return>"; 
    547                                  
    548                                 return $values;                  
    549                         } 
    550                 } 
    551                 return false;  
    552         } 
    553  
    554497        public final function removeAttributesLdap($pOrg) 
    555498        { 
     
    610553                                { 
    611554                                        $confHostsOrgs = unserialize($result[0]['config_value']); 
    612                                         $confHostsOrgs = explode(";", $confHostsOrgs);                                   
    613                                         $foundValue = array_search($pItem['item'], $confHostsOrgs);                                      
    614          
    615                                         if( $foundValue !== false ) 
    616                                                 array_splice($confHostsOrgs, $foundValue, 1); 
    617                                          
    618                                         if(count($confHostsOrgs) > 0 ) 
     555                                        $hosts = explode(":", $pItem['item']); 
     556                                        $key = ""; 
     557 
     558                                        if( count($confHostsOrgs) > 0 ) 
    619559                                        { 
    620                                                 foreach( $confHostsOrgs as $values ) 
    621                                                         $stringHostsOrgs .= $values . ";"; 
    622          
    623                                                 $stringHostsOrgs = substr($stringHostsOrgs, 0, strlen($stringHostsOrgs) -1 ); 
    624                                                 $query = "UPDATE phpgw_config SET config_value = '".serialize($stringHostsOrgs)."' WHERE config_name = 'map_org_realm_jabberit';"; 
     560                                                for( $i = 0; $i < count($confHostsOrgs); $i++) 
     561                                                        if( $confHostsOrgs[$i]['org'] == $hosts[0] && $confHostsOrgs[$i]['jabberName'] == $hosts[1]) 
     562                                                                $key = $i;       
     563 
     564                                                array_splice($confHostsOrgs, $key, 1); 
     565                                 
     566                                                if(count($confHostsOrgs) > 0) 
     567                                                {                                        
     568                                                        $this->fileD->ldapExternal($confHostsOrgs); 
     569                                                        $query = "UPDATE phpgw_config SET config_value = '".serialize($confHostsOrgs)."' WHERE config_name = 'map_org_realm_jabberit';"; 
     570                                                } 
     571                                                else 
     572                                                { 
     573                                                        $this->fileD->ldapExternal(""); 
     574                                                        $query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';"; 
     575                                                } 
    625576                                        } 
    626577                                        else 
     578                                        {        
     579                                                $this->fileD->ldapExternal("");                                          
    627580                                                $query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';"; 
    628                                          
     581                                        } 
     582 
    629583                                        if( $this->db->query($query) ) 
    630584                                                return "true"; 
     
    692646                return $return; 
    693647        } 
    694          
    695         public final function removeParticipantsExternal($pOrganization) 
    696         { 
    697                  
    698                 $organization = $pOrganization['participants'];  
    699                  
    700                 if( $this->db ) 
    701                 { 
    702                         $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'"; 
    703                                  
    704                         if ( $this->db->query($query) ) 
    705                         {        
    706                                 while( $this->db->next_record() ) 
    707                                         $result[] = $this->db->row(); 
    708                  
    709                                 if( count($result) > 0 ) 
    710                                         $valueDB = $result[0]['config_value']; 
    711                         } 
    712  
    713                         $OrgDB = explode(",", $valueDB); 
    714                         $newValue = "";  
    715  
    716                         foreach($OrgDB as $tmp) 
    717                         { 
    718                                 if( strtolower(trim($tmp)) != strtolower(trim($organization))) 
    719                                         $newValue .= $tmp . ","; 
    720                         } 
    721                          
    722                         $newValue = substr($newValue, 0,(strlen($newValue) -1 )); 
    723                          
    724                         if( trim($newValue) != "") 
    725                                 $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'"; 
    726                         else 
    727                                 $query = "DELETE from phpgw_config where config_name = 'conf_organization_jabberit'"; 
    728                                  
    729                         if( $this->db->query($query)) 
    730                                 return true; 
    731                         else 
    732                                 return false; 
    733                 } 
    734                 return false;    
    735         } 
     648 
    736649} 
    737650?> 
Note: See TracChangeset for help on using the changeset viewer.