[2411] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * Expresso - Expresso Messenger * |
---|
| 4 | * - Alexandre Correia / Rodrigo Souza * |
---|
| 5 | * - JETI - http://jeti-im.org/ * |
---|
| 6 | * ------------------------------------------------------------------------- * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 8 | * under the terms of the GNU General Public License as published by the * |
---|
| 9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 10 | * option) any later version. * |
---|
| 11 | \***************************************************************************/ |
---|
| 12 | |
---|
| 13 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
| 14 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
| 15 | require_once(PHPGW_API_INC . '/class.db.inc.php'); |
---|
| 16 | //require_once "class.fileDefine.inc.php"; |
---|
| 17 | |
---|
| 18 | class DataBaseIM |
---|
| 19 | { |
---|
| 20 | private $db; |
---|
| 21 | private $db_name; |
---|
| 22 | private $db_host; |
---|
| 23 | private $db_port; |
---|
| 24 | private $db_user; |
---|
| 25 | private $db_pass; |
---|
| 26 | private $db_type; |
---|
| 27 | private $user_id; |
---|
| 28 | private $fileD; |
---|
| 29 | |
---|
| 30 | public final function __construct() |
---|
| 31 | { |
---|
| 32 | //$this->fileD = new fileDefine(); |
---|
| 33 | $this->db_name = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name']; |
---|
| 34 | $this->db_host = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host']; |
---|
| 35 | $this->db_port = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_port']; |
---|
| 36 | $this->db_user = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_user']; |
---|
| 37 | $this->db_pass = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_pass']; |
---|
| 38 | $this->db_type = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_type']; |
---|
| 39 | $this->user_id = $_SESSION['phpgw_info']['jabberit_messenger']['user_id']; |
---|
| 40 | $this->connectDB(); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | private final function connectDB() |
---|
| 44 | { |
---|
| 45 | $this->db = new db(); |
---|
| 46 | $this->db_name = ( !$this->db_name ) ? $_SESSION['phpgwinfo']['db_name'] : $this->db_name; |
---|
| 47 | $this->db_host = ( !$this->db_host ) ? $_SESSION['phpgwinfo']['db_host'] : $this->db_host; |
---|
| 48 | $this->db_port = ( !$this->db_port ) ? $_SESSION['phpgwinfo']['db_port'] : $this->db_port; |
---|
| 49 | $this->db_user = ( !$this->db_user ) ? $_SESSION['phpgwinfo']['db_user'] : $this->db_user; |
---|
| 50 | $this->db_pass = ( !$this->db_pass ) ? $_SESSION['phpgwinfo']['db_pass'] : $this->db_pass; |
---|
| 51 | $this->db_type = ( !$this->db_type ) ? $_SESSION['phpgwinfo']['db_type'] : $this->db_type; |
---|
| 52 | |
---|
| 53 | $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type); |
---|
| 54 | } |
---|
| 55 | |
---|
| 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 | |
---|
| 76 | public final function getApplicationsEnabled() |
---|
| 77 | { |
---|
| 78 | |
---|
| 79 | $this->db->query("SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"); |
---|
| 80 | if($this->db->num_rows()) |
---|
| 81 | { |
---|
| 82 | $tmp = ""; |
---|
| 83 | while($this->db->next_record()) |
---|
| 84 | { |
---|
| 85 | $tmp[]= $this->db->row(); |
---|
| 86 | } |
---|
| 87 | return $tmp[0]['config_value']; |
---|
| 88 | } |
---|
| 89 | return false; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | public final function getApplicationsList() |
---|
| 93 | { |
---|
| 94 | $this->db->query("SELECT * FROM phpgw_applications WHERE app_enabled = '1' order by app_name"); |
---|
| 95 | if($this->db->num_rows()) |
---|
| 96 | { |
---|
| 97 | while ($this->db->next_record()) |
---|
| 98 | { |
---|
| 99 | $app = $this->db->f('app_name'); |
---|
| 100 | $title = @$GLOBALS['phpgw_info']['apps'][$app]['title']; |
---|
| 101 | if (empty($title)) |
---|
| 102 | { |
---|
| 103 | $title = lang($app) == $app.'*' ? $app : lang($app); |
---|
| 104 | } |
---|
| 105 | $apps[$app] = array( |
---|
| 106 | 'title' => $title, |
---|
| 107 | 'name' => $app, |
---|
| 108 | 'status' => $this->db->f('app_enabled') |
---|
| 109 | ); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | return $apps; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | public final function get_accounts_acl() |
---|
| 116 | { |
---|
| 117 | $query = "SELECT acl_account FROM phpgw_acl WHERE acl_location IN (SELECT CAST(acl_account AS varchar) FROM phpgw_acl WHERE acl_appname = 'jabberit_messenger') "; |
---|
| 118 | $query .= "UNION SELECT acl_account FROM phpgw_acl WHERE acl_appname = 'jabberit_messenger'"; |
---|
| 119 | |
---|
| 120 | if( $this->db->query($query) ) |
---|
| 121 | { |
---|
| 122 | $users = array(); |
---|
| 123 | $new_users = array(); |
---|
| 124 | while($this->db->next_record()) |
---|
| 125 | $users[] = $this->db->row(); |
---|
| 126 | |
---|
| 127 | if(is_array($users)) |
---|
| 128 | foreach($users as $tmp) |
---|
| 129 | $new_users[] = $tmp['acl_account']; |
---|
| 130 | |
---|
| 131 | return $new_users; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | return false; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | public final function getGroupsBlocked() |
---|
| 138 | { |
---|
| 139 | $return = ""; |
---|
| 140 | |
---|
| 141 | if( $this->db ) |
---|
| 142 | { |
---|
| 143 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 144 | |
---|
| 145 | if($this->db->query($query)) |
---|
| 146 | { |
---|
| 147 | |
---|
| 148 | if ( $this->db->query($query) ) |
---|
| 149 | { |
---|
| 150 | while($this->db->next_record()) |
---|
| 151 | $result[] = $this->db->row(); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | if( count($result) > 0 ) |
---|
| 155 | $return = $result[0]['config_value']; |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | return $return; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | public final function getGroupsSearch() |
---|
| 163 | { |
---|
| 164 | $return = ""; |
---|
| 165 | |
---|
| 166 | if( $this->db ) |
---|
| 167 | { |
---|
| 168 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';"; |
---|
| 169 | |
---|
| 170 | if($this->db->query($query)) |
---|
| 171 | { |
---|
| 172 | while($this->db->next_record()) |
---|
| 173 | $result[] = $this->db->row(); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | if( count($result) > 0 ) |
---|
| 177 | $return = $result[0]['config_value']; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | return $return; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | public final function getHostsJabber() |
---|
| 184 | { |
---|
| 185 | $return = ""; |
---|
| 186 | |
---|
| 187 | if( $this->db ) |
---|
| 188 | { |
---|
| 189 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';"; |
---|
| 190 | |
---|
| 191 | if($this->db->query($query)) |
---|
| 192 | { |
---|
| 193 | while($this->db->next_record()) |
---|
| 194 | $result[] = $this->db->row(); |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | if( count($result) > 0 ) |
---|
| 198 | $return = $result[0]['config_value']; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | return $return; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | public final function getPreferences() |
---|
| 205 | { |
---|
| 206 | $result = array(); |
---|
| 207 | $query = "SELECT * FROM phpgw_preferences WHERE preference_owner = '".$this->user_id."' AND preference_app = 'jabberit_messenger'"; |
---|
| 208 | |
---|
| 209 | if ( $this->db->query($query) ) |
---|
| 210 | { |
---|
| 211 | while($this->db->next_record()) |
---|
| 212 | $result[] = $this->db->row(); |
---|
| 213 | |
---|
| 214 | if( count($result) > 0 ) |
---|
| 215 | { |
---|
| 216 | $_return = unserialize($result[0]['preference_value']); |
---|
| 217 | |
---|
| 218 | if( is_array($_return) ) |
---|
| 219 | return $_return['preferences']; |
---|
| 220 | else |
---|
| 221 | return $_return; |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | return "openWindowJabberit:true;openWindowJabberitPopUp:false;flagAwayIM:5"; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | public final function setApplications($pApplications) |
---|
| 229 | { |
---|
| 230 | $apps = serialize($pApplications); |
---|
| 231 | |
---|
| 232 | if( $this->db ) |
---|
| 233 | { |
---|
| 234 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"; |
---|
| 235 | |
---|
| 236 | $this->db->query($query); |
---|
| 237 | |
---|
| 238 | if(!$this->db->next_record()) |
---|
| 239 | { |
---|
| 240 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')"; |
---|
| 241 | $this->db->query($query); |
---|
| 242 | return true; |
---|
| 243 | } |
---|
| 244 | else |
---|
| 245 | { |
---|
| 246 | $query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'"; |
---|
| 247 | $this->db->query($query); |
---|
| 248 | return true; |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | return false; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | public final function setAttributesLdap($pAttributes) |
---|
| 255 | { |
---|
| 256 | $values = $pAttributes['conf']; |
---|
| 257 | $attributesOrg = ""; |
---|
| 258 | |
---|
| 259 | if( $this->db ) |
---|
| 260 | { |
---|
| 261 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 262 | |
---|
| 263 | if ( $this->db->query($query) ) |
---|
| 264 | { |
---|
| 265 | while($this->db->next_record()) |
---|
| 266 | $result[] = $this->db->row(); |
---|
| 267 | |
---|
| 268 | if(count($result) > 0) |
---|
| 269 | $attributesOrg = $result[0]['config_value']; |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | if( trim($attributesOrg) == "" ) |
---|
| 273 | { |
---|
| 274 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','attributes_org_ldap_jabberit','".$values."')"; |
---|
| 275 | $this->db->query($query); |
---|
| 276 | |
---|
| 277 | $attr = explode(";", $values); |
---|
| 278 | $values = "<return><ou attr='".$attr[1]."'>".$attr[0]."</ou></return>"; |
---|
| 279 | return $values; |
---|
| 280 | } |
---|
| 281 | else |
---|
| 282 | { |
---|
| 283 | $org = explode(",", $attributesOrg); |
---|
| 284 | $newValue = explode(";", $values); |
---|
| 285 | |
---|
| 286 | foreach( $org as $tmp ) |
---|
| 287 | { |
---|
| 288 | $attr = explode(";",$tmp); |
---|
| 289 | if( strtolower(trim($attr[0])) == strtolower(trim($newValue[0])) ) |
---|
| 290 | return false; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | $values = $values . "," . $attributesOrg; |
---|
| 294 | $query = "UPDATE phpgw_config SET config_value = '".$values."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 295 | $this->db->query($query); |
---|
| 296 | |
---|
| 297 | $return = explode(",",$values); |
---|
| 298 | natcasesort($return); |
---|
| 299 | |
---|
| 300 | $values = "<return>"; |
---|
| 301 | |
---|
| 302 | foreach($return as $tmp) |
---|
| 303 | { |
---|
| 304 | $attr = explode(";", $tmp); |
---|
| 305 | $values .= "<ou attr='" . $attr[1] . "'>" . $attr[0] . "</ou>"; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | $values .= "</return>"; |
---|
| 309 | |
---|
| 310 | return $values; |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | return false; |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | public final function setAddGroupsSearch($pData) |
---|
| 317 | { |
---|
| 318 | if( $pData) |
---|
| 319 | { |
---|
| 320 | if( $this->db ) |
---|
| 321 | { |
---|
| 322 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';"; |
---|
| 323 | |
---|
| 324 | if( $this->db->query($query) ) |
---|
| 325 | { |
---|
| 326 | while( $this->db->next_record()) |
---|
| 327 | $result[] = $this->db->row(); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | if( count($result) == 0 ) |
---|
| 331 | { |
---|
| 332 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_search_jabberit','".serialize($pData)."');"; |
---|
| 333 | $this->db->query($query); |
---|
| 334 | return true; |
---|
| 335 | } |
---|
| 336 | else |
---|
| 337 | { |
---|
| 338 | $keyLdap = array_keys($pData); |
---|
| 339 | $resultQuery = unserialize($result[0]['config_value']); |
---|
| 340 | |
---|
| 341 | if( is_array(unserialize($pData[$keyLdap[0]])) ) |
---|
| 342 | $resultQuery[$keyLdap[0]] = $pData[$keyLdap[0]]; |
---|
| 343 | else |
---|
| 344 | unset($resultQuery[$keyLdap[0]]); |
---|
| 345 | |
---|
| 346 | if( count($resultQuery)) |
---|
| 347 | $query = "UPDATE phpgw_config SET config_value = '".serialize($resultQuery)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';"; |
---|
| 348 | else |
---|
| 349 | $query = "DELETE FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';"; |
---|
| 350 | |
---|
| 351 | $this->db->query($query); |
---|
| 352 | return true; |
---|
| 353 | } |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | public final function setGroupsLocked($pGroups) |
---|
| 359 | { |
---|
| 360 | $groups = ""; |
---|
| 361 | |
---|
| 362 | if( is_array($pGroups) ) |
---|
| 363 | { |
---|
| 364 | foreach($pGroups as $tmp) |
---|
| 365 | if(trim($tmp) != "") |
---|
| 366 | $groups .= $tmp . ";"; |
---|
| 367 | |
---|
| 368 | $groups = substr($groups, 0, strlen($groups) - 1 ); |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | if( $this->db ) |
---|
| 372 | { |
---|
| 373 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 374 | |
---|
| 375 | if($this->db->query($query)) |
---|
| 376 | { |
---|
| 377 | |
---|
| 378 | if ( $this->db->query($query) ) |
---|
| 379 | { |
---|
| 380 | while($this->db->next_record()) |
---|
| 381 | $result[] = $this->db->row(); |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | if( count($result) == 0 ) |
---|
| 385 | { |
---|
| 386 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_locked_jabberit','".$groups."');"; |
---|
| 387 | $this->db->query($query); |
---|
| 388 | return true; |
---|
| 389 | } |
---|
| 390 | else |
---|
| 391 | { |
---|
| 392 | $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 393 | $this->db->query($query); |
---|
| 394 | return true; |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | return false; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | public final function setHostJabber($pParam) |
---|
| 403 | { |
---|
| 404 | $confHostsJabber = array(); |
---|
| 405 | |
---|
| 406 | foreach($pParam as $key => $itens) |
---|
| 407 | $confHostsJabber[$key] = ( $key === 'org' ) ? strtoupper($itens) : $itens; |
---|
| 408 | |
---|
| 409 | if( $this->db ) |
---|
| 410 | { |
---|
| 411 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';"; |
---|
| 412 | |
---|
| 413 | if( $this->db->query($query) ) |
---|
| 414 | { |
---|
| 415 | while($this->db->next_record()) |
---|
| 416 | $result[] = $this->db->row(); |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | if( count($result) == 0 ) |
---|
| 420 | { |
---|
| 421 | $return = "<return><confServer ou='".strtoupper($confHostsJabber['org'])."' serverName='".$confHostsJabber['jabberName']."'>".strtoupper($confHostsJabber['org']).":".$confHostsJabber['jabberName']."</confServer></return>"; |
---|
| 422 | $hostsJabber[0] = $confHostsJabber; |
---|
| 423 | |
---|
| 424 | $this->fileD->ldapExternal($hostsJabber); |
---|
| 425 | |
---|
| 426 | $query = "INSERT INTO phpgw_config(config_app, config_name, config_value) VALUES('phpgwapi','map_org_realm_jabberit','".serialize($hostsJabber)."')"; |
---|
| 427 | $this->db->query($query); |
---|
| 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
| 431 | $resultQuery = unserialize($result[0]['config_value']); |
---|
| 432 | $foundOrg = false; |
---|
| 433 | |
---|
| 434 | foreach($resultQuery as $key => $itens) |
---|
| 435 | { |
---|
| 436 | $foundString = array_search($confHostsJabber['org'], $itens); |
---|
| 437 | if( $foundString ) |
---|
| 438 | { |
---|
| 439 | $foundOrg = $foundString; |
---|
| 440 | $ky = $key; |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | if( ! $foundOrg ) |
---|
| 445 | $resultQuery[] = $confHostsJabber; |
---|
| 446 | else |
---|
| 447 | $resultQuery[$ky] = $confHostsJabber; |
---|
| 448 | |
---|
| 449 | $return = "<return>"; |
---|
| 450 | |
---|
| 451 | foreach( $resultQuery as $itens ) |
---|
| 452 | $return .= "<confServer ou='".$itens['org']."' serverName='".$itens['jabberName']."'>".$itens['org'].":".$itens['jabberName']."</confServer>"; |
---|
| 453 | |
---|
| 454 | $return .= "</return>"; |
---|
| 455 | |
---|
| 456 | $this->fileD->ldapExternal($resultQuery); |
---|
| 457 | |
---|
| 458 | $query = "UPDATE phpgw_config SET config_value = '".serialize($resultQuery)."' WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 459 | $this->db->query($query); |
---|
| 460 | } |
---|
| 461 | return $return; |
---|
| 462 | } |
---|
| 463 | return false; |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | public final function setOuGroupsLocked($pGroup) |
---|
| 467 | { |
---|
| 468 | |
---|
| 469 | function strallpos($haystack, $needle, $offset = 0) |
---|
| 470 | { |
---|
| 471 | $result = array(); |
---|
| 472 | for($i = $offset; $i< strlen($haystack); $i++ ) |
---|
| 473 | { |
---|
| 474 | $pos = strpos($haystack,$needle,$i); |
---|
| 475 | if($pos !== FALSE) |
---|
| 476 | { |
---|
| 477 | $offset = $pos; |
---|
| 478 | if($offset >= $i) |
---|
| 479 | $result[] = $i = $offset; |
---|
| 480 | } |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | return $result; |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | $group = $pGroup['group']; |
---|
| 487 | $gidnumber = $pGroup['gidnumber']; |
---|
| 488 | $organization = strtoupper(trim($pGroup['ou'])); |
---|
| 489 | |
---|
| 490 | $posAll = strallpos($organization, "OU=" ); |
---|
| 491 | $orgs = array(); |
---|
| 492 | |
---|
| 493 | for( $i = 0 ; $i < count($posAll); $i++ ) |
---|
| 494 | { |
---|
| 495 | $pos = strpos($organization, ","); |
---|
| 496 | $tmpString = substr($organization, $posAll[$i] + 3); |
---|
| 497 | $orgs[] = substr($tmpString, 0, strpos($tmpString, ",")); |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | $organization = implode("/", array_reverse($orgs)); |
---|
| 501 | |
---|
| 502 | if( $this->db ) |
---|
| 503 | { |
---|
| 504 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 505 | |
---|
| 506 | if($this->db->query($query)) |
---|
| 507 | { |
---|
| 508 | |
---|
| 509 | if ( $this->db->query($query) ) |
---|
| 510 | { |
---|
| 511 | while($this->db->next_record()) |
---|
| 512 | $result[] = $this->db->row(); |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | $groupsLocked = explode(";",$result[0]['config_value']); |
---|
| 516 | |
---|
| 517 | foreach( $groupsLocked as $tmp ) |
---|
| 518 | { |
---|
| 519 | $aux = explode(":", $tmp); |
---|
| 520 | if(($group.":".$gidnumber) == ($aux[0].":".$aux[1])) |
---|
| 521 | { |
---|
| 522 | if( $aux[2] ) |
---|
| 523 | { |
---|
| 524 | $ou_groups = explode(",",$aux[2]); |
---|
| 525 | natcasesort($ou_groups); |
---|
| 526 | $key = array_search($organization, $ou_groups); |
---|
| 527 | |
---|
| 528 | if( $key === false ) |
---|
| 529 | array_push($ou_groups, $organization); |
---|
| 530 | |
---|
| 531 | $groups .= $group.":".$gidnumber.":"; |
---|
| 532 | |
---|
| 533 | $return = "<return>"; |
---|
| 534 | |
---|
| 535 | foreach($ou_groups as $tmp) |
---|
| 536 | { |
---|
| 537 | $return .= "<ou attr='".$tmp."'>".$tmp."</ou>"; |
---|
| 538 | $groups .= $tmp .","; |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | $return .= "</return>"; |
---|
| 542 | |
---|
| 543 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 544 | $groups .= ";"; |
---|
| 545 | } |
---|
| 546 | else |
---|
| 547 | { |
---|
| 548 | $groups .= $group.":".$gidnumber.":".$organization.";"; |
---|
| 549 | $return = "<return><ou attr='".$organization."'>".$organization."</ou></return>"; |
---|
| 550 | } |
---|
| 551 | } |
---|
| 552 | else |
---|
| 553 | $groups .= $tmp . ";" ; |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 557 | |
---|
| 558 | $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 559 | $this->db->query($query); |
---|
| 560 | |
---|
| 561 | return $return; |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | return false; |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | public final function removeAttributesLdap($pOrg) |
---|
| 569 | { |
---|
| 570 | $organization = $pOrg['org']; |
---|
| 571 | |
---|
| 572 | if( $this->db ) |
---|
| 573 | { |
---|
| 574 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 575 | |
---|
| 576 | if ( $this->db->query($query) ) |
---|
| 577 | { |
---|
| 578 | while( $this->db->next_record() ) |
---|
| 579 | $result[] = $this->db->row(); |
---|
| 580 | |
---|
| 581 | if( count($result) > 0 ) |
---|
| 582 | $attributesOrg = $result[0]['config_value']; |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | $attributesOrg = explode(",", $attributesOrg); |
---|
| 586 | $newValue = ""; |
---|
| 587 | foreach($attributesOrg as $tmp) |
---|
| 588 | { |
---|
| 589 | $attr = explode(";",$tmp); |
---|
| 590 | |
---|
| 591 | if( strtolower(trim($attr[0])) != strtolower(trim($organization))) |
---|
| 592 | { |
---|
| 593 | $newValue .= $attr[0] . ";" . $attr[1] . ","; |
---|
| 594 | } |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | $newValue = substr($newValue, 0,(strlen($newValue) -1 )); |
---|
| 598 | |
---|
| 599 | if( trim($newValue) != "") |
---|
| 600 | $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 601 | else |
---|
| 602 | $query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 603 | |
---|
| 604 | if( $this->db->query($query)) |
---|
| 605 | return true; |
---|
| 606 | else |
---|
| 607 | return false; |
---|
| 608 | } |
---|
| 609 | return false; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | public final function removeHostsJabber($pItem) |
---|
| 613 | { |
---|
| 614 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';"; |
---|
| 615 | |
---|
| 616 | if( $this->db ) |
---|
| 617 | { |
---|
| 618 | if($this->db->query($query)) |
---|
| 619 | { |
---|
| 620 | while($this->db->next_record()) |
---|
| 621 | $result[] = $this->db->row(); |
---|
| 622 | |
---|
| 623 | if( count($result) > 0 ) |
---|
| 624 | { |
---|
| 625 | $confHostsOrgs = unserialize($result[0]['config_value']); |
---|
| 626 | $hosts = explode(":", $pItem['item']); |
---|
| 627 | $key = ""; |
---|
| 628 | |
---|
| 629 | if( count($confHostsOrgs) > 0 ) |
---|
| 630 | { |
---|
| 631 | for( $i = 0; $i < count($confHostsOrgs); $i++) |
---|
| 632 | if( $confHostsOrgs[$i]['org'] == $hosts[0] && $confHostsOrgs[$i]['jabberName'] == $hosts[1]) |
---|
| 633 | $key = $i; |
---|
| 634 | |
---|
| 635 | array_splice($confHostsOrgs, $key, 1); |
---|
| 636 | |
---|
| 637 | if(count($confHostsOrgs) > 0) |
---|
| 638 | { |
---|
| 639 | $this->fileD->ldapExternal($confHostsOrgs); |
---|
| 640 | $query = "UPDATE phpgw_config SET config_value = '".serialize($confHostsOrgs)."' WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 641 | } |
---|
| 642 | else |
---|
| 643 | { |
---|
| 644 | $this->fileD->ldapExternal(""); |
---|
| 645 | $query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 646 | } |
---|
| 647 | } |
---|
| 648 | else |
---|
| 649 | { |
---|
| 650 | $this->fileD->ldapExternal(""); |
---|
| 651 | $query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | if( $this->db->query($query) ) |
---|
| 655 | return "true"; |
---|
| 656 | } |
---|
| 657 | } |
---|
| 658 | } |
---|
| 659 | return "false"; |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | public final function removeOuGroupsLocked($pGroup) |
---|
| 663 | { |
---|
| 664 | $group = $pGroup['group']; |
---|
| 665 | $gidnumber = $pGroup['gidnumber']; |
---|
| 666 | $organization = strtoupper($pGroup['ou']); |
---|
| 667 | $return = false; |
---|
| 668 | |
---|
| 669 | if( $this->db ) |
---|
| 670 | { |
---|
| 671 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 672 | |
---|
| 673 | if($this->db->query($query)) |
---|
| 674 | { |
---|
| 675 | |
---|
| 676 | if ( $this->db->query($query) ) |
---|
| 677 | { |
---|
| 678 | while($this->db->next_record()) |
---|
| 679 | $result[] = $this->db->row(); |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | $groupsLocked = explode(";",$result[0]['config_value']); |
---|
| 683 | |
---|
| 684 | foreach( $groupsLocked as $tmp ) |
---|
| 685 | { |
---|
| 686 | $aux = explode(":",$tmp); |
---|
| 687 | |
---|
| 688 | if(($group.":".$gidnumber) == ($aux[0].":".$aux[1])) |
---|
| 689 | { |
---|
| 690 | $ous = explode(",", $aux[2]); |
---|
| 691 | $key = array_search($organization, $ous); |
---|
| 692 | |
---|
| 693 | if( $key !== false ) |
---|
| 694 | unset($ous[$key]); |
---|
| 695 | |
---|
| 696 | $groups .= $group.":".$gidnumber.":"; |
---|
| 697 | |
---|
| 698 | foreach($ous as $ouTmp) |
---|
| 699 | $groups .= $ouTmp .","; |
---|
| 700 | |
---|
| 701 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 702 | $groups .= ";"; |
---|
| 703 | } |
---|
| 704 | else |
---|
| 705 | $groups .= $tmp . ";" ; |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 709 | |
---|
| 710 | $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 711 | |
---|
| 712 | if( $this->db->query($query)) |
---|
| 713 | $return = true; |
---|
| 714 | } |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | return $return; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | } |
---|
| 721 | ?> |
---|