db_name = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name']; $this->db_host = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host']; $this->db_port = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_port']; $this->db_user = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_user']; $this->db_pass = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_pass']; $this->db_type = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_type']; $this->user_id = $_SESSION['phpgw_info']['jabberit_messenger']['user_id']; $this->connectDB(); } private final function connectDB() { $this->db = new db(); $this->db_name = ( !$this->db_name ) ? $_SESSION['phpgwinfo']['db_name'] : $this->db_name; $this->db_host = ( !$this->db_host ) ? $_SESSION['phpgwinfo']['db_host'] : $this->db_host; $this->db_port = ( !$this->db_port ) ? $_SESSION['phpgwinfo']['db_port'] : $this->db_port; $this->db_user = ( !$this->db_user ) ? $_SESSION['phpgwinfo']['db_user'] : $this->db_user; $this->db_pass = ( !$this->db_pass ) ? $_SESSION['phpgwinfo']['db_pass'] : $this->db_pass; $this->db_type = ( !$this->db_type ) ? $_SESSION['phpgwinfo']['db_type'] : $this->db_type; $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type); } public final function getApplicationsEnabled() { $this->db->query("SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"); if($this->db->num_rows()) { $tmp = ""; while($this->db->next_record()) { $tmp[]= $this->db->row(); } return $tmp[0]['config_value']; } return false; } public final function getApplicationsList() { $this->db->query("SELECT * FROM phpgw_applications WHERE app_enabled = '1' order by app_name"); if($this->db->num_rows()) { while ($this->db->next_record()) { $app = $this->db->f('app_name'); $title = @$GLOBALS['phpgw_info']['apps'][$app]['title']; if (empty($title)) { $title = lang($app) == $app.'*' ? $app : lang($app); } $apps[$app] = array( 'title' => $title, 'name' => $app, 'status' => $this->db->f('app_enabled') ); } } return $apps; } public final function get_accounts_acl() { $query = "select acl_account from phpgw_acl where acl_location in (select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger') "; $query .= "union select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger'"; if( $this->db->query($query) ) { $users = array(); $new_users = array(); while($this->db->next_record()) $users[] = $this->db->row(); if(is_array($users)) foreach($users as $tmp) $new_users[] = $tmp['acl_account']; return $new_users; } return false; } public final function getPreferences() { $result = array(); $query = "select * from phpgw_preferences where preference_owner = '".$this->user_id."' and preference_app = 'jabberit_messenger'"; if ( $this->db->query($query) ) { while($this->db->next_record()) $result[] = $this->db->row(); if(count($result) > 0) return unserialize($result[0]['preference_value']); } return "openWindowJabberit:true;openWindowJabberitPopUp:false"; } public final function setPreferences($pParam) { $preferences = $preferences1 = $pParam['preferences1']; if(isset($pParam['preferences2'])) { $preferences2 = $pParam['preferences2']; $preferences .= ";". $preferences2; } $user_id = $this->user_id; $query = "insert into phpgw_preferences values('".$user_id."','jabberit_messenger','".serialize($preferences)."')"; if($this->db->query($query)) { return "true"; } else { $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='jabberit_messenger' and preference_owner='".$user_id."'"; if($this->db->query($query)) return "true"; else return "false"; } } public final function setApplications($pApplications) { $apps = serialize($pApplications); if( $this->db ) { $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"; $this->db->query($query); if(!$this->db->next_record()) { $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')"; $this->db->query($query); return true; } else { $query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'"; $this->db->query($query); return true; } } return false; } public final function setAttributesLdap($pAttributes) { $values = $pAttributes['conf']; $attributesOrg = ""; if( $this->db ) { $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; if ( $this->db->query($query) ) { while($this->db->next_record()) $result[] = $this->db->row(); if(count($result) > 0) $attributesOrg = $result[0]['config_value']; } if( trim($attributesOrg) == "" ) { $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','attributes_org_ldap_jabberit','".$values."')"; $this->db->query($query); $attr = explode(";", $values); $values = "".$attr[0].""; return $values; } else { $org = explode(",", $attributesOrg); $newValue = explode(";", $values); foreach( $org as $tmp ) { $attr = explode(";",$tmp); if( strtolower(trim($attr[0])) == strtolower(trim($newValue[0])) ) return false; } $values = $values . "," . $attributesOrg; $query = "UPDATE phpgw_config SET config_value = '".$values."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; $this->db->query($query); $return = explode(",",$values); natcasesort($return); $values = ""; foreach($return as $tmp) { $attr = explode(";", $tmp); $values .= "" . $attr[0] . ""; } $values .= ""; return $values; } } return false; } public final function setGroupsLocked($pGroups) { $groups = ""; if( is_array($pGroups) ) { foreach($pGroups as $tmp) if(trim($tmp) != "") $groups .= $tmp . ";"; $groups = substr($groups, 0, strlen($groups) - 1 ); } if( $this->db ) { $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; if($this->db->query($query)) { if ( $this->db->query($query) ) { while($this->db->next_record()) $result[] = $this->db->row(); } if( count($result) == 0 ) { $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_locked_jabberit','".$groups."');"; $this->db->query($query); return true; } else { $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';"; $this->db->query($query); return true; } } } return false; } public final function setUseParticipantsExternal($pFlag) { $flag = $pFlag['value']; $return = ""; if( $this->db ) { $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit';"; if ( $this->db->query($query) ) { while($this->db->next_record()) $result[] = $this->db->row(); } if(count($result) == 0) { $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','use_external_participants_jabberit','".$flag."')"; $this->db->query($query); return true; } else { $query = "UPDATE phpgw_config SET config_value = '".$flag."' WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit'"; $this->db->query($query); return true; } } return false; } public final function setOrganization($pOrganization) { $organization = $pOrganization['organization']; $orgConfiguration = ""; if( $this->db ) { $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'"; if ( $this->db->query($query) ) { while($this->db->next_record()) $result[] = $this->db->row(); if(count($result) > 0) $orgConfiguration = $result[0]['config_value']; } if( trim($orgConfiguration) == "" ) { $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','conf_organization_jabberit','".$organization."')"; $this->db->query($query); return "".$organization.""; } else { $orgAux = explode(",",$orgConfiguration); foreach( $orgAux as $tmp ) { if(strtolower(trim($tmp)) === strtolower(trim($organization))) return false; } $value = $orgConfiguration . "," . $organization; $query = "UPDATE phpgw_config SET config_value = '".$value."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'"; $this->db->query($query); $return = explode(",",$value); natcasesort($return); $values = ""; foreach($return as $tmp) $values .= "" . $tmp . ""; $values .= ""; return $values; } } return false; } public final function removeAttributesLdap($pOrg) { $organization = $pOrg['org']; if( $this->db ) { $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; if ( $this->db->query($query) ) { while( $this->db->next_record() ) $result[] = $this->db->row(); if( count($result) > 0 ) $attributesOrg = $result[0]['config_value']; } $attributesOrg = explode(",", $attributesOrg); $newValue = ""; foreach($attributesOrg as $tmp) { $attr = explode(";",$tmp); if( strtolower(trim($attr[0])) != strtolower(trim($organization))) { $newValue .= $attr[0] . ";" . $attr[1] . ","; } } $newValue = substr($newValue, 0,(strlen($newValue) -1 )); if( trim($newValue) != "") $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; else $query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'"; if( $this->db->query($query)) return true; else return false; } return false; } public final function removeParticipantsExternal($pOrganization) { $organization = $pOrganization['participants']; if( $this->db ) { $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'"; if ( $this->db->query($query) ) { while( $this->db->next_record() ) $result[] = $this->db->row(); if( count($result) > 0 ) $valueDB = $result[0]['config_value']; } $OrgDB = explode(",", $valueDB); $newValue = ""; foreach($OrgDB as $tmp) { if( strtolower(trim($tmp)) != strtolower(trim($organization))) $newValue .= $tmp . ","; } $newValue = substr($newValue, 0,(strlen($newValue) -1 )); if( trim($newValue) != "") $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'"; else $query = "DELETE from phpgw_config where config_name = 'conf_organization_jabberit'"; if( $this->db->query($query)) return true; else return false; } return false; } } ?>