[6779] | 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 db_im |
---|
| 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 getGroupsBlocked() |
---|
| 116 | { |
---|
| 117 | $return = ""; |
---|
| 118 | |
---|
| 119 | if( $this->db ) |
---|
| 120 | { |
---|
| 121 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 122 | |
---|
| 123 | if($this->db->query($query)) |
---|
| 124 | { |
---|
| 125 | |
---|
| 126 | if ( $this->db->query($query) ) |
---|
| 127 | { |
---|
| 128 | while($this->db->next_record()) |
---|
| 129 | $result[] = $this->db->row(); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | if( count($result) > 0 ) |
---|
| 133 | $return = $result[0]['config_value']; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | return $return; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | public final function getGroupsJmessenger() |
---|
| 141 | { |
---|
| 142 | $return = ""; |
---|
| 143 | |
---|
| 144 | if( $this->db ) |
---|
| 145 | { |
---|
| 146 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_jmessenger_jabberit';"; |
---|
| 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 | return $return; |
---|
| 159 | |
---|
| 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 setAddGroupsJmessenger($pData) |
---|
| 317 | { |
---|
| 318 | $pData = ( $pData ) ? serialize($pData) : ""; |
---|
| 319 | |
---|
| 320 | if( $this->db ) |
---|
| 321 | { |
---|
| 322 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_jmessenger_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 | $query = "INSERT INTO phpgw_config( config_app, config_name, config_value ) VALUES('phpgwapi', 'groups_jmessenger_jabberit', '".$pData."');"; |
---|
| 332 | else |
---|
| 333 | $query = "UPDATE phpgw_config SET config_value = '".$pData."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_jmessenger_jabberit';"; |
---|
| 334 | |
---|
| 335 | if ( $this->db->query($query) ) |
---|
| 336 | return true; |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | return false; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | public final function setAddGroupsSearch($pData) |
---|
| 343 | { |
---|
| 344 | if( $pData) |
---|
| 345 | { |
---|
| 346 | if( $this->db ) |
---|
| 347 | { |
---|
| 348 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';"; |
---|
| 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 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_search_jabberit','".serialize($pData)."');"; |
---|
| 359 | $this->db->query($query); |
---|
| 360 | return true; |
---|
| 361 | } |
---|
| 362 | else |
---|
| 363 | { |
---|
| 364 | $keyLdap = array_keys($pData); |
---|
| 365 | $resultQuery = unserialize($result[0]['config_value']); |
---|
| 366 | |
---|
| 367 | if( is_array(unserialize($pData[$keyLdap[0]])) ) |
---|
| 368 | $resultQuery[$keyLdap[0]] = $pData[$keyLdap[0]]; |
---|
| 369 | else |
---|
| 370 | unset($resultQuery[$keyLdap[0]]); |
---|
| 371 | |
---|
| 372 | if( count($resultQuery)) |
---|
| 373 | $query = "UPDATE phpgw_config SET config_value = '".serialize($resultQuery)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';"; |
---|
| 374 | else |
---|
| 375 | $query = "DELETE FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_search_jabberit';"; |
---|
| 376 | |
---|
| 377 | $this->db->query($query); |
---|
| 378 | return true; |
---|
| 379 | } |
---|
| 380 | } |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | public final function setGroupsLocked($pGroups) |
---|
| 385 | { |
---|
| 386 | $groups = ""; |
---|
| 387 | |
---|
| 388 | if( is_array($pGroups) ) |
---|
| 389 | { |
---|
| 390 | foreach($pGroups as $tmp) |
---|
| 391 | if(trim($tmp) != "") |
---|
| 392 | $groups .= $tmp . ";"; |
---|
| 393 | |
---|
| 394 | $groups = substr($groups, 0, strlen($groups) - 1 ); |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | if( $this->db ) |
---|
| 398 | { |
---|
| 399 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 400 | |
---|
| 401 | if($this->db->query($query)) |
---|
| 402 | { |
---|
| 403 | |
---|
| 404 | if ( $this->db->query($query) ) |
---|
| 405 | { |
---|
| 406 | while($this->db->next_record()) |
---|
| 407 | $result[] = $this->db->row(); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | if( count($result) == 0 ) |
---|
| 411 | { |
---|
| 412 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_locked_jabberit','".$groups."');"; |
---|
| 413 | $this->db->query($query); |
---|
| 414 | return true; |
---|
| 415 | } |
---|
| 416 | else |
---|
| 417 | { |
---|
| 418 | $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 419 | $this->db->query($query); |
---|
| 420 | return true; |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | return false; |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | public final function setHostJabber($pParam) |
---|
| 429 | { |
---|
| 430 | $confHostsJabber = array(); |
---|
| 431 | |
---|
| 432 | foreach($pParam as $key => $itens) |
---|
| 433 | $confHostsJabber[$key] = ( $key === 'org' ) ? strtoupper($itens) : $itens; |
---|
| 434 | |
---|
| 435 | if( $this->db ) |
---|
| 436 | { |
---|
| 437 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';"; |
---|
| 438 | |
---|
| 439 | if( $this->db->query($query) ) |
---|
| 440 | { |
---|
| 441 | while($this->db->next_record()) |
---|
| 442 | $result[] = $this->db->row(); |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | if( count($result) == 0 ) |
---|
| 446 | { |
---|
| 447 | $return = "<return><confServer ou='".strtoupper($confHostsJabber['org'])."' serverName='".$confHostsJabber['jabberName']."'>".strtoupper($confHostsJabber['org']).":".$confHostsJabber['jabberName']."</confServer></return>"; |
---|
| 448 | $hostsJabber[0] = $confHostsJabber; |
---|
| 449 | |
---|
| 450 | $this->fileD->ldapExternal($hostsJabber); |
---|
| 451 | |
---|
| 452 | $query = "INSERT INTO phpgw_config(config_app, config_name, config_value) VALUES('phpgwapi','map_org_realm_jabberit','".serialize($hostsJabber)."')"; |
---|
| 453 | $this->db->query($query); |
---|
| 454 | } |
---|
| 455 | else |
---|
| 456 | { |
---|
| 457 | $resultQuery = unserialize($result[0]['config_value']); |
---|
| 458 | $foundOrg = false; |
---|
| 459 | |
---|
| 460 | foreach($resultQuery as $key => $itens) |
---|
| 461 | { |
---|
| 462 | $foundString = array_search($confHostsJabber['org'], $itens); |
---|
| 463 | if( $foundString ) |
---|
| 464 | { |
---|
| 465 | $foundOrg = $foundString; |
---|
| 466 | $ky = $key; |
---|
| 467 | } |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | if( ! $foundOrg ) |
---|
| 471 | $resultQuery[] = $confHostsJabber; |
---|
| 472 | else |
---|
| 473 | $resultQuery[$ky] = $confHostsJabber; |
---|
| 474 | |
---|
| 475 | $return = "<return>"; |
---|
| 476 | |
---|
| 477 | foreach( $resultQuery as $itens ) |
---|
| 478 | $return .= "<confServer ou='".$itens['org']."' serverName='".$itens['jabberName']."'>".$itens['org'].":".$itens['jabberName']."</confServer>"; |
---|
| 479 | |
---|
| 480 | $return .= "</return>"; |
---|
| 481 | |
---|
| 482 | $this->fileD->ldapExternal($resultQuery); |
---|
| 483 | |
---|
| 484 | $query = "UPDATE phpgw_config SET config_value = '".serialize($resultQuery)."' WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 485 | $this->db->query($query); |
---|
| 486 | } |
---|
| 487 | return $return; |
---|
| 488 | } |
---|
| 489 | return false; |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | public final function setOuGroupsLocked($pGroup) |
---|
| 493 | { |
---|
| 494 | |
---|
| 495 | function strallpos($haystack, $needle, $offset = 0) |
---|
| 496 | { |
---|
| 497 | $result = array(); |
---|
| 498 | for($i = $offset; $i< strlen($haystack); $i++ ) |
---|
| 499 | { |
---|
| 500 | $pos = strpos($haystack,$needle,$i); |
---|
| 501 | if($pos !== FALSE) |
---|
| 502 | { |
---|
| 503 | $offset = $pos; |
---|
| 504 | if($offset >= $i) |
---|
| 505 | $result[] = $i = $offset; |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | return $result; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | $group = $pGroup['group']; |
---|
| 513 | $gidnumber = $pGroup['gidnumber']; |
---|
| 514 | $organization = strtoupper(trim($pGroup['ou'])); |
---|
| 515 | |
---|
| 516 | $posAll = strallpos($organization, "OU=" ); |
---|
| 517 | $orgs = array(); |
---|
| 518 | |
---|
| 519 | for( $i = 0 ; $i < count($posAll); $i++ ) |
---|
| 520 | { |
---|
| 521 | $pos = strpos($organization, ","); |
---|
| 522 | $tmpString = substr($organization, $posAll[$i] + 3); |
---|
| 523 | $orgs[] = substr($tmpString, 0, strpos($tmpString, ",")); |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | $organization = implode("/", array_reverse($orgs)); |
---|
| 527 | |
---|
| 528 | if( $this->db ) |
---|
| 529 | { |
---|
| 530 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 531 | |
---|
| 532 | if($this->db->query($query)) |
---|
| 533 | { |
---|
| 534 | |
---|
| 535 | if ( $this->db->query($query) ) |
---|
| 536 | { |
---|
| 537 | while($this->db->next_record()) |
---|
| 538 | $result[] = $this->db->row(); |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | $groupsLocked = explode(";",$result[0]['config_value']); |
---|
| 542 | |
---|
| 543 | foreach( $groupsLocked as $tmp ) |
---|
| 544 | { |
---|
| 545 | $aux = explode(":", $tmp); |
---|
| 546 | if(($group.":".$gidnumber) == ($aux[0].":".$aux[1])) |
---|
| 547 | { |
---|
| 548 | if( $aux[2] ) |
---|
| 549 | { |
---|
| 550 | $ou_groups = explode(",",$aux[2]); |
---|
| 551 | natcasesort($ou_groups); |
---|
| 552 | $key = array_search($organization, $ou_groups); |
---|
| 553 | |
---|
| 554 | if( $key === false ) |
---|
| 555 | array_push($ou_groups, $organization); |
---|
| 556 | |
---|
| 557 | $groups .= $group.":".$gidnumber.":"; |
---|
| 558 | |
---|
| 559 | $return = "<return>"; |
---|
| 560 | |
---|
| 561 | foreach($ou_groups as $tmp) |
---|
| 562 | { |
---|
| 563 | $return .= "<ou attr='".$tmp."'>".$tmp."</ou>"; |
---|
| 564 | $groups .= $tmp .","; |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | $return .= "</return>"; |
---|
| 568 | |
---|
| 569 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 570 | $groups .= ";"; |
---|
| 571 | } |
---|
| 572 | else |
---|
| 573 | { |
---|
| 574 | $groups .= $group.":".$gidnumber.":".$organization.";"; |
---|
| 575 | $return = "<return><ou attr='".$organization."'>".$organization."</ou></return>"; |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | else |
---|
| 579 | $groups .= $tmp . ";" ; |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 583 | |
---|
| 584 | $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 585 | $this->db->query($query); |
---|
| 586 | |
---|
| 587 | return $return; |
---|
| 588 | } |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | return false; |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | public final function removeAttributesLdap($pOrg) |
---|
| 595 | { |
---|
| 596 | $organization = $pOrg['org']; |
---|
| 597 | |
---|
| 598 | if( $this->db ) |
---|
| 599 | { |
---|
| 600 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 601 | |
---|
| 602 | if ( $this->db->query($query) ) |
---|
| 603 | { |
---|
| 604 | while( $this->db->next_record() ) |
---|
| 605 | $result[] = $this->db->row(); |
---|
| 606 | |
---|
| 607 | if( count($result) > 0 ) |
---|
| 608 | $attributesOrg = $result[0]['config_value']; |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | $attributesOrg = explode(",", $attributesOrg); |
---|
| 612 | $newValue = ""; |
---|
| 613 | foreach($attributesOrg as $tmp) |
---|
| 614 | { |
---|
| 615 | $attr = explode(";",$tmp); |
---|
| 616 | |
---|
| 617 | if( strtolower(trim($attr[0])) != strtolower(trim($organization))) |
---|
| 618 | { |
---|
| 619 | $newValue .= $attr[0] . ";" . $attr[1] . ","; |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | $newValue = substr($newValue, 0,(strlen($newValue) -1 )); |
---|
| 624 | |
---|
| 625 | if( trim($newValue) != "") |
---|
| 626 | $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 627 | else |
---|
| 628 | $query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 629 | |
---|
| 630 | if( $this->db->query($query)) |
---|
| 631 | return true; |
---|
| 632 | else |
---|
| 633 | return false; |
---|
| 634 | } |
---|
| 635 | return false; |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | public final function removeHostsJabber($pItem) |
---|
| 639 | { |
---|
| 640 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'map_org_realm_jabberit';"; |
---|
| 641 | |
---|
| 642 | if( $this->db ) |
---|
| 643 | { |
---|
| 644 | if($this->db->query($query)) |
---|
| 645 | { |
---|
| 646 | while($this->db->next_record()) |
---|
| 647 | $result[] = $this->db->row(); |
---|
| 648 | |
---|
| 649 | if( count($result) > 0 ) |
---|
| 650 | { |
---|
| 651 | $confHostsOrgs = unserialize($result[0]['config_value']); |
---|
| 652 | $hosts = explode(":", $pItem['item']); |
---|
| 653 | $key = ""; |
---|
| 654 | |
---|
| 655 | if( count($confHostsOrgs) > 0 ) |
---|
| 656 | { |
---|
| 657 | for( $i = 0; $i < count($confHostsOrgs); $i++) |
---|
| 658 | if( $confHostsOrgs[$i]['org'] == $hosts[0] && $confHostsOrgs[$i]['jabberName'] == $hosts[1]) |
---|
| 659 | $key = $i; |
---|
| 660 | |
---|
| 661 | array_splice($confHostsOrgs, $key, 1); |
---|
| 662 | |
---|
| 663 | if(count($confHostsOrgs) > 0) |
---|
| 664 | { |
---|
| 665 | $this->fileD->ldapExternal($confHostsOrgs); |
---|
| 666 | $query = "UPDATE phpgw_config SET config_value = '".serialize($confHostsOrgs)."' WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 667 | } |
---|
| 668 | else |
---|
| 669 | { |
---|
| 670 | $this->fileD->ldapExternal(""); |
---|
| 671 | $query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | else |
---|
| 675 | { |
---|
| 676 | $this->fileD->ldapExternal(""); |
---|
| 677 | $query = "DELETE FROM phpgw_config WHERE config_name = 'map_org_realm_jabberit';"; |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | if( $this->db->query($query) ) |
---|
| 681 | return "true"; |
---|
| 682 | } |
---|
| 683 | } |
---|
| 684 | } |
---|
| 685 | return "false"; |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | public final function removeOuGroupsLocked($pGroup) |
---|
| 689 | { |
---|
| 690 | $group = $pGroup['group']; |
---|
| 691 | $gidnumber = $pGroup['gidnumber']; |
---|
| 692 | $organization = strtoupper($pGroup['ou']); |
---|
| 693 | $return = false; |
---|
| 694 | |
---|
| 695 | if( $this->db ) |
---|
| 696 | { |
---|
| 697 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 698 | |
---|
| 699 | if($this->db->query($query)) |
---|
| 700 | { |
---|
| 701 | |
---|
| 702 | if ( $this->db->query($query) ) |
---|
| 703 | { |
---|
| 704 | while($this->db->next_record()) |
---|
| 705 | $result[] = $this->db->row(); |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | $groupsLocked = explode(";",$result[0]['config_value']); |
---|
| 709 | |
---|
| 710 | foreach( $groupsLocked as $tmp ) |
---|
| 711 | { |
---|
| 712 | $aux = explode(":",$tmp); |
---|
| 713 | |
---|
| 714 | if(($group.":".$gidnumber) == ($aux[0].":".$aux[1])) |
---|
| 715 | { |
---|
| 716 | $ous = explode(",", $aux[2]); |
---|
| 717 | $key = array_search($organization, $ous); |
---|
| 718 | |
---|
| 719 | if( $key !== false ) |
---|
| 720 | unset($ous[$key]); |
---|
| 721 | |
---|
| 722 | $groups .= $group.":".$gidnumber.":"; |
---|
| 723 | |
---|
| 724 | foreach($ous as $ouTmp) |
---|
| 725 | $groups .= $ouTmp .","; |
---|
| 726 | |
---|
| 727 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 728 | $groups .= ";"; |
---|
| 729 | } |
---|
| 730 | else |
---|
| 731 | $groups .= $tmp . ";" ; |
---|
| 732 | } |
---|
| 733 | |
---|
| 734 | $groups = substr($groups,0,strlen($groups)-1); |
---|
| 735 | |
---|
| 736 | $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 737 | |
---|
| 738 | if( $this->db->query($query)) |
---|
| 739 | $return = true; |
---|
| 740 | } |
---|
| 741 | } |
---|
| 742 | |
---|
| 743 | return $return; |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | } |
---|
| 747 | ?> |
---|