[382] | 1 | <?php |
---|
[417] | 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 | \***************************************************************************/ |
---|
[382] | 12 | |
---|
| 13 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
| 14 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
| 15 | require_once(PHPGW_API_INC . '/class.db.inc.php'); |
---|
| 16 | |
---|
| 17 | class db_im |
---|
| 18 | { |
---|
| 19 | private $db; |
---|
| 20 | private $db_name; |
---|
| 21 | private $db_host; |
---|
| 22 | private $db_port; |
---|
| 23 | private $db_user; |
---|
| 24 | private $db_pass; |
---|
| 25 | private $db_type; |
---|
| 26 | private $user_id; |
---|
| 27 | |
---|
| 28 | public final function __construct() |
---|
| 29 | { |
---|
| 30 | $this->db_name = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name']; |
---|
| 31 | $this->db_host = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host']; |
---|
| 32 | $this->db_port = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_port']; |
---|
| 33 | $this->db_user = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_user']; |
---|
| 34 | $this->db_pass = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_pass']; |
---|
| 35 | $this->db_type = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_type']; |
---|
| 36 | $this->user_id = $_SESSION['phpgw_info']['jabberit_messenger']['user_id']; |
---|
[519] | 37 | $this->connectDB(); |
---|
[382] | 38 | } |
---|
| 39 | |
---|
[417] | 40 | private final function connectDB() |
---|
[382] | 41 | { |
---|
| 42 | $this->db = new db(); |
---|
[519] | 43 | $this->db_name = ( !$this->db_name ) ? $_SESSION['phpgwinfo']['db_name'] : $this->db_name; |
---|
| 44 | $this->db_host = ( !$this->db_host ) ? $_SESSION['phpgwinfo']['db_host'] : $this->db_host; |
---|
| 45 | $this->db_port = ( !$this->db_port ) ? $_SESSION['phpgwinfo']['db_port'] : $this->db_port; |
---|
| 46 | $this->db_user = ( !$this->db_user ) ? $_SESSION['phpgwinfo']['db_user'] : $this->db_user; |
---|
| 47 | $this->db_pass = ( !$this->db_pass ) ? $_SESSION['phpgwinfo']['db_pass'] : $this->db_pass; |
---|
| 48 | $this->db_type = ( !$this->db_type ) ? $_SESSION['phpgwinfo']['db_type'] : $this->db_type; |
---|
| 49 | |
---|
[382] | 50 | $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type); |
---|
[417] | 51 | } |
---|
| 52 | |
---|
| 53 | public final function getApplicationsEnabled() |
---|
| 54 | { |
---|
[519] | 55 | |
---|
[417] | 56 | $this->db->query("SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"); |
---|
| 57 | if($this->db->num_rows()) |
---|
| 58 | { |
---|
| 59 | $tmp = ""; |
---|
| 60 | while($this->db->next_record()) |
---|
| 61 | { |
---|
| 62 | $tmp[]= $this->db->row(); |
---|
| 63 | } |
---|
| 64 | return $tmp[0]['config_value']; |
---|
| 65 | } |
---|
| 66 | return false; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | public final function getApplicationsList() |
---|
| 70 | { |
---|
| 71 | $this->db->query("SELECT * FROM phpgw_applications WHERE app_enabled = '1' order by app_name"); |
---|
| 72 | if($this->db->num_rows()) |
---|
| 73 | { |
---|
| 74 | while ($this->db->next_record()) |
---|
| 75 | { |
---|
| 76 | $app = $this->db->f('app_name'); |
---|
| 77 | $title = @$GLOBALS['phpgw_info']['apps'][$app]['title']; |
---|
| 78 | if (empty($title)) |
---|
| 79 | { |
---|
| 80 | $title = lang($app) == $app.'*' ? $app : lang($app); |
---|
| 81 | } |
---|
| 82 | $apps[$app] = array( |
---|
| 83 | 'title' => $title, |
---|
| 84 | 'name' => $app, |
---|
| 85 | 'status' => $this->db->f('app_enabled') |
---|
| 86 | ); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | return $apps; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | public final function get_accounts_acl() |
---|
| 93 | { |
---|
[382] | 94 | $query = "select acl_account from phpgw_acl where acl_location in (select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger') "; |
---|
| 95 | $query .= "union select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger'"; |
---|
| 96 | |
---|
| 97 | if( $this->db->query($query) ) |
---|
| 98 | { |
---|
| 99 | $users = array(); |
---|
| 100 | $new_users = array(); |
---|
| 101 | while($this->db->next_record()) |
---|
| 102 | $users[] = $this->db->row(); |
---|
| 103 | |
---|
| 104 | if(is_array($users)) |
---|
| 105 | foreach($users as $tmp) |
---|
| 106 | $new_users[] = $tmp['acl_account']; |
---|
| 107 | |
---|
| 108 | return $new_users; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | return false; |
---|
| 112 | } |
---|
| 113 | |
---|
[417] | 114 | public final function getPreferences() |
---|
[382] | 115 | { |
---|
[417] | 116 | $result = array(); |
---|
| 117 | $query = "select * from phpgw_preferences where preference_owner = '".$this->user_id."' and preference_app = 'jabberit_messenger'"; |
---|
| 118 | |
---|
| 119 | if ( $this->db->query($query) ) |
---|
| 120 | { |
---|
| 121 | while($this->db->next_record()) |
---|
| 122 | $result[] = $this->db->row(); |
---|
| 123 | |
---|
| 124 | if(count($result) > 0) |
---|
| 125 | return unserialize($result[0]['preference_value']); |
---|
| 126 | } |
---|
| 127 | |
---|
[622] | 128 | return "openWindowJabberit:true;openWindowJabberitPopUp:false"; |
---|
| 129 | |
---|
[417] | 130 | } |
---|
| 131 | |
---|
| 132 | public final function setPreferences($pParam) |
---|
| 133 | { |
---|
[563] | 134 | $preferences = $preferences1 = $pParam['preferences1']; |
---|
| 135 | |
---|
| 136 | if(isset($pParam['preferences2'])) |
---|
| 137 | { |
---|
| 138 | $preferences2 = $pParam['preferences2']; |
---|
| 139 | $preferences .= ";". $preferences2; |
---|
| 140 | } |
---|
| 141 | |
---|
[417] | 142 | $user_id = $this->user_id; |
---|
| 143 | |
---|
| 144 | $query = "insert into phpgw_preferences values('".$user_id."','jabberit_messenger','".serialize($preferences)."')"; |
---|
| 145 | |
---|
| 146 | if($this->db->query($query)) |
---|
| 147 | { |
---|
| 148 | return "true"; |
---|
| 149 | } |
---|
[382] | 150 | else |
---|
[417] | 151 | { |
---|
| 152 | $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='jabberit_messenger' and preference_owner='".$user_id."'"; |
---|
| 153 | |
---|
| 154 | if($this->db->query($query)) |
---|
| 155 | return "true"; |
---|
| 156 | else |
---|
| 157 | return "false"; |
---|
| 158 | } |
---|
[382] | 159 | } |
---|
[417] | 160 | |
---|
| 161 | public final function setApplications($pApplications) |
---|
| 162 | { |
---|
| 163 | $apps = serialize($pApplications); |
---|
| 164 | |
---|
| 165 | if( $this->db ) |
---|
| 166 | { |
---|
| 167 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"; |
---|
| 168 | |
---|
| 169 | $this->db->query($query); |
---|
| 170 | |
---|
| 171 | if(!$this->db->next_record()) |
---|
| 172 | { |
---|
| 173 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')"; |
---|
| 174 | $this->db->query($query); |
---|
| 175 | return true; |
---|
| 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
| 179 | $query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'"; |
---|
| 180 | $this->db->query($query); |
---|
| 181 | return true; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | return false; |
---|
| 185 | } |
---|
[519] | 186 | |
---|
| 187 | public final function setAttributesLdap($pAttributes) |
---|
| 188 | { |
---|
| 189 | $values = $pAttributes['conf']; |
---|
| 190 | $attributesOrg = ""; |
---|
| 191 | |
---|
| 192 | if( $this->db ) |
---|
| 193 | { |
---|
| 194 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 195 | |
---|
| 196 | if ( $this->db->query($query) ) |
---|
| 197 | { |
---|
| 198 | while($this->db->next_record()) |
---|
| 199 | $result[] = $this->db->row(); |
---|
| 200 | |
---|
| 201 | if(count($result) > 0) |
---|
| 202 | $attributesOrg = $result[0]['config_value']; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | if( trim($attributesOrg) == "" ) |
---|
| 206 | { |
---|
| 207 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','attributes_org_ldap_jabberit','".$values."')"; |
---|
| 208 | $this->db->query($query); |
---|
| 209 | |
---|
| 210 | $attr = explode(";", $values); |
---|
| 211 | $values = "<return><ou attr='".$attr[1]."'>".$attr[0]."</ou></return>"; |
---|
| 212 | return $values; |
---|
| 213 | } |
---|
| 214 | else |
---|
| 215 | { |
---|
| 216 | $org = explode(",", $attributesOrg); |
---|
| 217 | $newValue = explode(";", $values); |
---|
| 218 | |
---|
| 219 | foreach( $org as $tmp ) |
---|
| 220 | { |
---|
| 221 | $attr = explode(";",$tmp); |
---|
| 222 | if( strtolower(trim($attr[0])) == strtolower(trim($newValue[0])) ) |
---|
| 223 | return false; |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | $values = $values . "," . $attributesOrg; |
---|
| 227 | $query = "UPDATE phpgw_config SET config_value = '".$values."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 228 | $this->db->query($query); |
---|
| 229 | |
---|
| 230 | $return = explode(",",$values); |
---|
| 231 | natcasesort($return); |
---|
| 232 | |
---|
| 233 | $values = "<return>"; |
---|
| 234 | |
---|
| 235 | foreach($return as $tmp) |
---|
| 236 | { |
---|
| 237 | $attr = explode(";", $tmp); |
---|
| 238 | $values .= "<ou attr='" . $attr[1] . "'>" . $attr[0] . "</ou>"; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | $values .= "</return>"; |
---|
| 242 | |
---|
| 243 | return $values; |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | return false; |
---|
| 247 | } |
---|
[563] | 248 | |
---|
| 249 | public final function setGroupsLocked($pGroups) |
---|
| 250 | { |
---|
| 251 | $groups = ""; |
---|
| 252 | |
---|
| 253 | if( is_array($pGroups) ) |
---|
| 254 | { |
---|
| 255 | foreach($pGroups as $tmp) |
---|
| 256 | if(trim($tmp) != "") |
---|
| 257 | $groups .= $tmp . ";"; |
---|
| 258 | |
---|
| 259 | $groups = substr($groups, 0, strlen($groups) - 1 ); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | if( $this->db ) |
---|
| 263 | { |
---|
| 264 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 265 | |
---|
| 266 | if($this->db->query($query)) |
---|
| 267 | { |
---|
| 268 | |
---|
| 269 | if ( $this->db->query($query) ) |
---|
| 270 | { |
---|
| 271 | while($this->db->next_record()) |
---|
| 272 | $result[] = $this->db->row(); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | if( count($result) == 0 ) |
---|
| 276 | { |
---|
| 277 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_locked_jabberit','".$groups."');"; |
---|
| 278 | $this->db->query($query); |
---|
| 279 | return true; |
---|
| 280 | } |
---|
| 281 | else |
---|
| 282 | { |
---|
| 283 | $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; |
---|
| 284 | $this->db->query($query); |
---|
| 285 | return true; |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | return false; |
---|
| 291 | } |
---|
[519] | 292 | |
---|
[563] | 293 | public final function setUseParticipantsExternal($pFlag) |
---|
| 294 | { |
---|
| 295 | $flag = $pFlag['value']; |
---|
| 296 | $return = ""; |
---|
| 297 | |
---|
| 298 | if( $this->db ) |
---|
| 299 | { |
---|
| 300 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit';"; |
---|
| 301 | |
---|
| 302 | if ( $this->db->query($query) ) |
---|
| 303 | { |
---|
| 304 | while($this->db->next_record()) |
---|
| 305 | $result[] = $this->db->row(); |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | if(count($result) == 0) |
---|
| 309 | { |
---|
| 310 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','use_external_participants_jabberit','".$flag."')"; |
---|
| 311 | $this->db->query($query); |
---|
| 312 | return true; |
---|
| 313 | } |
---|
| 314 | else |
---|
| 315 | { |
---|
| 316 | $query = "UPDATE phpgw_config SET config_value = '".$flag."' WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit'"; |
---|
| 317 | $this->db->query($query); |
---|
| 318 | return true; |
---|
| 319 | } |
---|
| 320 | } |
---|
| 321 | return false; |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | public final function setOrganization($pOrganization) |
---|
| 325 | { |
---|
| 326 | $organization = $pOrganization['organization']; |
---|
| 327 | $orgConfiguration = ""; |
---|
| 328 | |
---|
| 329 | if( $this->db ) |
---|
| 330 | { |
---|
| 331 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'"; |
---|
| 332 | |
---|
| 333 | if ( $this->db->query($query) ) |
---|
| 334 | { |
---|
| 335 | while($this->db->next_record()) |
---|
| 336 | $result[] = $this->db->row(); |
---|
| 337 | |
---|
| 338 | if(count($result) > 0) |
---|
| 339 | $orgConfiguration = $result[0]['config_value']; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | if( trim($orgConfiguration) == "" ) |
---|
| 343 | { |
---|
| 344 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','conf_organization_jabberit','".$organization."')"; |
---|
| 345 | $this->db->query($query); |
---|
| 346 | |
---|
| 347 | return "<return><ou attr='".$organization."'>".$organization."</ou></return>"; |
---|
| 348 | } |
---|
| 349 | else |
---|
| 350 | { |
---|
| 351 | $orgAux = explode(",",$orgConfiguration); |
---|
| 352 | |
---|
| 353 | foreach( $orgAux as $tmp ) |
---|
| 354 | { |
---|
| 355 | if(strtolower(trim($tmp)) === strtolower(trim($organization))) |
---|
| 356 | return false; |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | $value = $orgConfiguration . "," . $organization; |
---|
| 360 | $query = "UPDATE phpgw_config SET config_value = '".$value."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'"; |
---|
| 361 | $this->db->query($query); |
---|
| 362 | |
---|
| 363 | $return = explode(",",$value); |
---|
| 364 | natcasesort($return); |
---|
| 365 | |
---|
| 366 | $values = "<return>"; |
---|
| 367 | |
---|
| 368 | foreach($return as $tmp) |
---|
| 369 | $values .= "<ou attr='" . $tmp . "'>" . $tmp . "</ou>"; |
---|
| 370 | |
---|
| 371 | $values .= "</return>"; |
---|
| 372 | |
---|
| 373 | return $values; |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | return false; |
---|
| 377 | } |
---|
| 378 | |
---|
[519] | 379 | public final function removeAttributesLdap($pOrg) |
---|
| 380 | { |
---|
| 381 | $organization = $pOrg['org']; |
---|
| 382 | |
---|
| 383 | if( $this->db ) |
---|
| 384 | { |
---|
| 385 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 386 | |
---|
| 387 | if ( $this->db->query($query) ) |
---|
| 388 | { |
---|
| 389 | while( $this->db->next_record() ) |
---|
| 390 | $result[] = $this->db->row(); |
---|
| 391 | |
---|
| 392 | if( count($result) > 0 ) |
---|
| 393 | $attributesOrg = $result[0]['config_value']; |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | $attributesOrg = explode(",", $attributesOrg); |
---|
| 397 | $newValue = ""; |
---|
| 398 | foreach($attributesOrg as $tmp) |
---|
| 399 | { |
---|
| 400 | $attr = explode(";",$tmp); |
---|
| 401 | |
---|
| 402 | if( strtolower(trim($attr[0])) != strtolower(trim($organization))) |
---|
| 403 | { |
---|
| 404 | $newValue .= $attr[0] . ";" . $attr[1] . ","; |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | $newValue = substr($newValue, 0,(strlen($newValue) -1 )); |
---|
| 409 | |
---|
| 410 | if( trim($newValue) != "") |
---|
| 411 | $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 412 | else |
---|
| 413 | $query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'"; |
---|
| 414 | |
---|
| 415 | if( $this->db->query($query)) |
---|
| 416 | return true; |
---|
| 417 | else |
---|
| 418 | return false; |
---|
| 419 | } |
---|
| 420 | return false; |
---|
| 421 | } |
---|
[563] | 422 | |
---|
| 423 | public final function removeParticipantsExternal($pOrganization) |
---|
| 424 | { |
---|
| 425 | |
---|
| 426 | $organization = $pOrganization['participants']; |
---|
| 427 | |
---|
| 428 | if( $this->db ) |
---|
| 429 | { |
---|
| 430 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'"; |
---|
| 431 | |
---|
| 432 | if ( $this->db->query($query) ) |
---|
| 433 | { |
---|
| 434 | while( $this->db->next_record() ) |
---|
| 435 | $result[] = $this->db->row(); |
---|
| 436 | |
---|
| 437 | if( count($result) > 0 ) |
---|
| 438 | $valueDB = $result[0]['config_value']; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | $OrgDB = explode(",", $valueDB); |
---|
| 442 | $newValue = ""; |
---|
| 443 | |
---|
| 444 | foreach($OrgDB as $tmp) |
---|
| 445 | { |
---|
| 446 | if( strtolower(trim($tmp)) != strtolower(trim($organization))) |
---|
| 447 | $newValue .= $tmp . ","; |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | $newValue = substr($newValue, 0,(strlen($newValue) -1 )); |
---|
| 451 | |
---|
| 452 | if( trim($newValue) != "") |
---|
| 453 | $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'"; |
---|
| 454 | else |
---|
| 455 | $query = "DELETE from phpgw_config where config_name = 'conf_organization_jabberit'"; |
---|
| 456 | |
---|
| 457 | if( $this->db->query($query)) |
---|
| 458 | return true; |
---|
| 459 | else |
---|
| 460 | return false; |
---|
| 461 | } |
---|
| 462 | return false; |
---|
| 463 | } |
---|
[382] | 464 | } |
---|
[417] | 465 | ?> |
---|