Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
603 righe
24 KiB
603 righe
24 KiB
<? |
|
use \Firebase\JWT\JWT; |
|
use GuzzleHttp\Psr7\Response; |
|
|
|
class goToMtg |
|
{ |
|
private $token; |
|
private $basicAuth; |
|
private $baseAccount; |
|
private $accountAppoggio; |
|
private $hosts; |
|
private $ente; |
|
|
|
public function __construct() |
|
{ |
|
global $config; |
|
$this->basicAuth = base64_encode($config["gotomeeting-CONSUMER"].":".$config["gotomeeting-SECRET"]); |
|
$this->baseAccount = $config["gotomeeting-BASEACCOUNT"]; |
|
$this->accountAppoggio = $config["gotomeeting-ACCOUNTAPPOGGIO"]; |
|
$this->ente = $_SESSION["ente"]->getInfo(); |
|
} |
|
|
|
private function insertToken($token,$codice_ente,$codice_host) { |
|
global $pdo; |
|
$token = json_encode($token); |
|
$result = $pdo->go("INSERT INTO b_gotoMeeting_tokens (response,codice_ente,codice_host) VALUES (:token,:codice_ente,:codice_host)", |
|
[":token"=>$token,":codice_ente"=>$codice_ente,":codice_host"=>$codice_host]); |
|
if ($result->rowCount() > 0) { return true; } |
|
return false; |
|
} |
|
|
|
private function createToken($data,$codice_ente=0,$codice_host=0) { |
|
$curl = curl_init(); |
|
curl_setopt_array($curl, array( |
|
CURLOPT_URL => "https://api.getgo.com/oauth/v2/token", |
|
CURLOPT_RETURNTRANSFER => true, |
|
CURLOPT_ENCODING => "", |
|
CURLOPT_MAXREDIRS => 10, |
|
CURLOPT_TIMEOUT => 0, |
|
CURLOPT_FOLLOWLOCATION => true, |
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
CURLOPT_CUSTOMREQUEST => "POST", |
|
CURLOPT_POSTFIELDS =>$data, |
|
CURLOPT_HTTPHEADER => array( |
|
"Content-Type: application/x-www-form-urlencoded", |
|
"Accept: application/json", |
|
"Authorization: Basic {$this->basicAuth}" |
|
), |
|
)); |
|
$risposta = curl_exec($curl); |
|
curl_close($curl); |
|
if (!empty($risposta)) { |
|
$risposta = json_decode($risposta,true); |
|
if (!empty($risposta["access_token"])) { |
|
$this->token = $risposta; |
|
return $this->insertToken($risposta,$codice_ente,$codice_host); |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function createFirstToken($responseKey,$ente,$codice) { |
|
// PER OTTENERE LA RESPONSE KEY COLLEGARSI A https://api.getgo.com/oauth/v2/authorize?client_id={consumerKey}&response_type=code E COPIARE IL CODE NELLA URL DI RISPOSTA |
|
$data = http_build_query(["grant_type"=>"authorization_code","code"=>$responseKey]); |
|
return $this->createToken($data,$ente,$codice); |
|
} |
|
|
|
public static function getLastToken($codice_ente = 0, $host = 0) { |
|
global $pdo; |
|
$token = $pdo->go("SELECT response FROM b_gotoMeeting_tokens WHERE codice_ente = :codice_ente AND codice_host = :host ORDER BY id DESC LIMIT 0,1", |
|
[":codice_ente"=>$codice_ente,":host"=>$host])->fetch(PDO::FETCH_ASSOC)["response"] ?? false; |
|
if (!empty($token)) { |
|
$token = json_decode($token,TRUE); |
|
return $token; |
|
} |
|
return false; |
|
} |
|
|
|
public function refreshToken($codice_ente = 0, $host = 0) { |
|
$token = self::getLastToken($codice_ente, $host); |
|
if (!empty($token)) { |
|
$data = http_build_query(["grant_type"=>"refresh_token","refresh_token"=>$token["refresh_token"]]); |
|
return $this->createToken($data,$codice_ente,$host); |
|
} |
|
return false; |
|
} |
|
|
|
public function getMeetingDetails($id,$codice_ente,$codice_host) { |
|
if ($codice_ente != 0 && $codice_host != 0) { |
|
if ($this->refreshToken($codice_ente,$codice_host)) { |
|
$curl = curl_init(); |
|
curl_setopt_array($curl, array( |
|
CURLOPT_URL => "https://api.getgo.com/G2M/rest/meetings/{$id}", |
|
CURLOPT_RETURNTRANSFER => true, |
|
CURLOPT_ENCODING => "", |
|
CURLOPT_MAXREDIRS => 10, |
|
CURLOPT_TIMEOUT => 0, |
|
CURLOPT_FOLLOWLOCATION => true, |
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
CURLOPT_CUSTOMREQUEST => "GET", |
|
CURLOPT_HTTPHEADER => array( |
|
"Content-Type: application/json", |
|
"Accept: application/json", |
|
"Authorization: Bearer {$this->token["access_token"]}" |
|
), |
|
)); |
|
$response = curl_exec($curl); |
|
curl_close($curl); |
|
$response = json_decode($response,true); |
|
if (!empty($response[0]["meetingId"])) { |
|
return $response[0]; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function getAttendees($id,$codice_ente,$codice_host) { |
|
if ($codice_ente != 0 && $codice_host != 0) { |
|
if ($this->refreshToken($codice_ente,$codice_host)) { |
|
$curl = curl_init(); |
|
curl_setopt_array($curl, array( |
|
CURLOPT_URL => "https://api.getgo.com/G2M/rest/meetings/{$id}/attendees", |
|
CURLOPT_RETURNTRANSFER => true, |
|
CURLOPT_ENCODING => "", |
|
CURLOPT_MAXREDIRS => 10, |
|
CURLOPT_TIMEOUT => 0, |
|
CURLOPT_FOLLOWLOCATION => true, |
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
CURLOPT_CUSTOMREQUEST => "GET", |
|
CURLOPT_HTTPHEADER => array( |
|
"Content-Type: application/json", |
|
"Accept: application/json", |
|
"Authorization: Bearer {$this->token["access_token"]}" |
|
), |
|
)); |
|
$response = curl_exec($curl); |
|
curl_close($curl); |
|
return json_decode($response,true); |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
|
|
|
|
public function createFirstHostToken($code,$codice_ente,$codice_host) { |
|
$hosts = self::getHosts(false); |
|
foreach($hosts AS $tmp) { |
|
if ($tmp["codice"] == $codice_host) { |
|
$host = json_decode($tmp["other"],true); |
|
break; |
|
} |
|
} |
|
if (!empty($host)) { |
|
$host = $this->editUserEmail($codice_host,$host["email"]); |
|
if (!empty($host)) { |
|
return $this->createFirstToken($code,$codice_ente,$codice_host); |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
private function editUserEmail($codice,$address) { |
|
$hosts = self::getHosts(false); |
|
foreach($hosts AS $tmp) { |
|
if ($tmp["codice"] == $codice) { |
|
$host = json_decode($tmp["other"],true); |
|
break; |
|
} |
|
} |
|
if (!empty($host)) { |
|
|
|
if (empty($this->token)) { $this->refreshToken(); } |
|
$body = [ |
|
"email" => $address, |
|
"firstName" => "Host", |
|
"lastName" => $this->ente["denominazione"] |
|
]; |
|
$curl = curl_init(); |
|
$data = json_encode($body); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/admin/rest/v1/accounts/{$this->baseAccount}/users/{$host["key"]}"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json", |
|
"Accept: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
$risposta = curl_exec($curl); |
|
curl_close($curl); |
|
if (empty($risposta)) { |
|
return $host; |
|
} else { |
|
return $risposta; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function updateEmailAndSend($codice,$address="") { |
|
if (empty($address)) { $address = $this->accountAppoggio; } |
|
$host = $this->editUserEmail($codice,$address); |
|
if (!empty($host)) { |
|
if (!empty($host["key"])) { |
|
$data = json_encode(["subject"=>__("Conferma account"),"text"=>__("Conferma account")]); |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/admin/rest/v1/accounts/{$this->baseAccount}/users/{$host["key"]}/email"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", |
|
"Accept: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
$risposta = curl_exec($curl); |
|
if (empty($risposta)) { |
|
return true; |
|
} else { |
|
return $risposta; |
|
} |
|
} else { |
|
return $host; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function deleteUser($codice) { |
|
$hosts = self::getHosts(false); |
|
foreach($hosts AS $tmp) { |
|
if ($tmp["codice"] == $codice) { |
|
$host = json_decode($tmp["other"],true); |
|
break; |
|
} |
|
} |
|
if (!empty($host)) { |
|
if (empty($this->token)) { $this->refreshToken(0,0); } |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/admin/rest/v1/accounts/{$this->baseAccount}/users/{$host["key"]}"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
$risposta = curl_exec($curl); |
|
curl_close($curl); |
|
if (empty($risposta)) { |
|
global $pdo; |
|
$pdo->go("DELETE FROM b_hosts WHERE codice = :codice AND codice_ente = :ente ",[":codice"=>$codice,":ente"=>$this->ente["codice"]]); |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function getLicense($type="") { |
|
if (empty($type)) { |
|
$type = ($_SESSION["demoEnv"]) ? "GoToMeeting Free" : "GoToMeeting Pro"; |
|
} |
|
if (empty($this->token)) { $this->refreshToken(0,0); } |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/admin/rest/v1/accounts/{$this->baseAccount}/licenses"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
$list = curl_exec($curl); |
|
curl_close($curl); |
|
$list = json_decode($list,true); |
|
if (!empty($list)) { |
|
if (!empty($list["results"])) { |
|
foreach($list["results"] AS $license) { |
|
if ($license["description"] == $type) { |
|
return $license; |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function createUser() { |
|
$license = $this->getLicense(); |
|
if (!empty($license)) { |
|
if (!isset($license["seats"]) || $license["seats"] > $license["userCount"]) { |
|
$body = []; |
|
$body["users"] = [[ |
|
"email" => time()."-".$this->ente["codice"]."@studioamica.it", |
|
"firstName" => "Host", |
|
"lastName" => $this->ente["denominazione"], |
|
"locale" => "it_IT" |
|
]]; |
|
$body["licenseKeys"] = [$license["key"]]; |
|
$body = json_encode($body); |
|
$curl = curl_init(); |
|
global $pdo; |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/admin/rest/v1/accounts/{$this->baseAccount}/users?allOrNothing=false"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $body); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","Authorization: Bearer {$this->token["access_token"]}")); |
|
$risposta = curl_exec($curl); |
|
curl_close($curl); |
|
if (!empty($risposta)) { |
|
$risposta = json_decode($risposta,TRUE); |
|
if (!empty($risposta[0]["key"])) { |
|
$response = json_encode($risposta[0]); |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_hosts"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = ["id"=>$risposta[0]["key"],"codice_ente"=>$this->ente["codice"],"other"=>$response,"provider"=>"gotomeeting"]; |
|
$salva->save(); |
|
return true; |
|
} |
|
} |
|
} else { |
|
return -1; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static function getHosts($onlyID= true) { |
|
if (isset($_SESSION["ente"])) { |
|
global $pdo; |
|
$hosts = $pdo->go("SELECT * FROM b_hosts WHERE provider = 'gotomeeting' AND codice_ente = :ente",[":ente"=>$_SESSION["ente"]->codice]); |
|
if ($hosts->rowCount() > 0) { |
|
$hosts = $hosts->fetchAll(PDO::FETCH_ASSOC); |
|
if ($onlyID) { |
|
$tmp = []; |
|
foreach($hosts AS $host) { |
|
$tmp[] = $host["id"]; |
|
} |
|
$hosts = $tmp; |
|
} |
|
return $hosts; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function getHostFromID($id) { |
|
global $pdo; |
|
$return = $pdo->go("SELECT * FROM b_hosts WHERE id = :id AND provider = 'gotomeeting' AND codice_ente = :ente",[":id"=>$id,":ente"=>$this->ente["codice"]])->fetch(PDO::FETCH_ASSOC); |
|
if (!empty($return)) { |
|
$return["count"] = $this->countHostConference($return["id"]); |
|
return $return; |
|
} |
|
return false; |
|
} |
|
|
|
public function countHostConference($id) { |
|
global $pdo; |
|
$return = $pdo->go("SELECT codice FROM b_conference WHERE host = :id AND provider = 'gotomeeting' AND codice_ente = :ente",[":id"=>$id,":ente"=>$this->ente["codice"]]); |
|
return $return->rowCount(); |
|
} |
|
|
|
public function deleteMeeting($codice_ente,$codice_host,$id) { |
|
if ($this->refreshToken($codice_ente,$codice_host)) { |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/G2M/rest/meetings/{$id}"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
curl_exec($curl); |
|
curl_close($curl); |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public function getMeetingFromDB($sezione,$codice_elemento,$sub_elemento,$contesto,$codice_meeting=false) { |
|
global $pdo; |
|
$bind = [":sezione"=>$sezione,":codice_elemento"=>$codice_elemento,":sub_elemento"=>$sub_elemento,":contesto"=>$contesto,":ente"=>$this->ente["codice"]]; |
|
$sql = "SELECT * FROM b_conference WHERE provider = 'gotomeeting' AND codice_ente = :ente AND sezione = :sezione AND codice_elemento = :codice_elemento AND sub_elemento = :sub_elemento AND contesto = :contesto "; |
|
if (!empty($codice_meeting)) { |
|
$bind[":codice"] = $codice_meeting; |
|
$sql .= " AND codice = :codice"; |
|
} |
|
$sql .= " ORDER BY codice DESC LIMIT 0,1"; |
|
$meetings = $pdo->go($sql,$bind); |
|
if ($meetings->rowCount() > 0) { return $meetings->fetch(PDO::FETCH_ASSOC); } |
|
return false; |
|
} |
|
|
|
public function getRecordings($id,$codice_ente,$codice_host,$startTime,$endTime) { |
|
if ($codice_ente != 0 && $codice_host != 0) { |
|
if ($this->refreshToken($codice_ente,$codice_host)) { |
|
$curl = curl_init(); |
|
curl_setopt_array($curl, array( |
|
CURLOPT_URL => "https://api.getgo.com/G2M/rest/historicalMeetings?" . http_build_query(["startDate"=>$startTime,"endDate"=>$endTime]), |
|
CURLOPT_RETURNTRANSFER => true, |
|
CURLOPT_ENCODING => "", |
|
CURLOPT_MAXREDIRS => 10, |
|
CURLOPT_TIMEOUT => 0, |
|
CURLOPT_FOLLOWLOCATION => true, |
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
CURLOPT_CUSTOMREQUEST => "GET", |
|
CURLOPT_HTTPHEADER => array( |
|
"Content-Type: application/json", |
|
"Accept: application/json", |
|
"Authorization: Bearer {$this->token["access_token"]}" |
|
) |
|
)); |
|
$response = curl_exec($curl); |
|
curl_close($curl); |
|
$response = json_decode($response,true); |
|
if (!empty($response)) { |
|
foreach($response AS $meet) { |
|
if ($meet["meetingId"] == $id) { |
|
if (!empty($meet["recording"])) { return $meet["recording"]; } |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function findInHistorical($id) { |
|
if (empty($this->token)) { $this->refreshToken(); } |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/G2M/rest/upcomingMeetings?startDate"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
$list = curl_exec($curl); |
|
curl_close($curl); |
|
$list = json_decode($list,true); |
|
if (!empty($list)) { |
|
if (!empty($list[0]["meetingId"])) { |
|
return $list; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
|
|
public function listMeeting($codice_ente,$codice_host) { |
|
if ($this->refreshToken($codice_ente,$codice_host)) { |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/G2M/rest/upcomingMeetings"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
$list = curl_exec($curl); |
|
curl_close($curl); |
|
$list = json_decode($list,true); |
|
if (!empty($list)) { |
|
if (!empty($list[0]["meetingId"])) { |
|
return $list; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
private function checkAvailability($host) { |
|
$checkOBj = new goToMtg; |
|
$list = $checkOBj->listMeeting($this->ente["codice"],$host["codice"]); |
|
if (!empty($list)) { |
|
foreach($list AS $meet) { |
|
if ($meet["status"] != "INACTIVE") { return false; } |
|
} |
|
return true; |
|
} else { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public function createMeeting($sezione,$codice_elemento,$sub_elemento,$contesto) { |
|
global $pdo; |
|
$this->refreshToken(0,0); |
|
$body = []; |
|
$body["subject"] = substr("{$sezione} - #{$codice_elemento} - {$contesto}",0,100); |
|
$dt = new DateTime("+5 minute"); |
|
$dt->setTimezone(new DateTimeZone('UTC')); |
|
$body["starttime"] = $dt->format('Y-m-d\TH:i:s.u\Z'); |
|
$dt = new DateTime("+2 hour"); |
|
$dt->setTimezone(new DateTimeZone('UTC')); |
|
$body["endtime"] = $dt->format('Y-m-d\TH:i:s.u\Z'); |
|
$body["passwordrequired"] = false; |
|
$body["conferencecallinfo"] = "Free"; |
|
$body["timezonekey"] = ""; |
|
$body["meetingtype"] = "immediate"; |
|
$body["coorganizerKeys"] = []; |
|
$hosts = $this->getHosts(false); |
|
foreach($hosts AS $tmpHost) { |
|
$count = $this->countHostConference($tmpHost["id"]); |
|
$tmpHost["count"] = $count; |
|
if (!isset($host) || (isset($host) && ($host["count"] > $tmpHost["count"]))) { $host = $tmpHost; } |
|
} |
|
if (!empty($host)) { |
|
$token = $this->refreshToken($this->ente["codice"],$host["codice"]); |
|
if (!empty($token)) { |
|
$curl = curl_init(); |
|
curl_setopt($curl, CURLOPT_URL, "https://api.getgo.com/G2M/rest/meetings"); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body)); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json","Authorization: Bearer {$this->token["access_token"]}")); |
|
$risposta = curl_exec($curl); |
|
curl_close($curl); |
|
$risposta = json_decode($risposta,TRUE); |
|
if (!empty($risposta[0]["meetingid"])) { |
|
$response = json_encode($risposta[0]); |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_conference"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = ["sezione"=>$sezione,"codice_ente"=>$this->ente["codice"],"provider"=>"gotomeeting","codice_elemento"=>$codice_elemento,"sub_elemento"=>$sub_elemento,"contesto"=>$contesto,"host"=>$host["id"],"response"=>$response]; |
|
$salva->save(); |
|
return $risposta[0]; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function getHostURL($codice_conference) { |
|
global $pdo_ente; |
|
$info = $pdo_ente->go("SELECT * FROM b_conference WHERE b_conference.codice = :codice AND codice_ente = :ente",[":codice"=>$codice_conference,":ente"=>$this->ente["codice"]]); |
|
if ($info->rowCount() > 0) { |
|
$ref = $info->fetch(PDO::FETCH_ASSOC); |
|
$host = $this->getHostFromID($ref["host"]); |
|
if ($this->checkAvailability($host)) { |
|
if (!empty($this->refreshToken($this->ente["codice"],$host["codice"]))) { |
|
$response = json_decode($ref["response"],TRUE); |
|
$curl = curl_init(); |
|
curl_setopt_array($curl, array( |
|
CURLOPT_URL => "https://api.getgo.com/G2M/rest/meetings/{$response["meetingid"]}/start", |
|
CURLOPT_RETURNTRANSFER => true, |
|
CURLOPT_ENCODING => "", |
|
CURLOPT_MAXREDIRS => 10, |
|
CURLOPT_TIMEOUT => 0, |
|
CURLOPT_FOLLOWLOCATION => true, |
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
CURLOPT_CUSTOMREQUEST => "GET", |
|
CURLOPT_HTTPHEADER => array( |
|
"Content-Type: application/json", |
|
"Accept: application/json", |
|
"Authorization: Bearer {$this->token["access_token"]}" |
|
), |
|
)); |
|
$response = curl_exec($curl); |
|
curl_close($curl); |
|
$response = json_decode($response,true); |
|
if (!empty($response["hostURL"])) { |
|
return $response["hostURL"]; |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function printLog($id) { |
|
$logs = []; |
|
$bind = []; |
|
$bind[":codice"] = $id; |
|
global $pdo; |
|
$risultato_conference = $pdo->go("SELECT * FROM b_conference WHERE provider = 'gotomeeting' AND codice = :codice ",$bind); |
|
if ($risultato_conference->rowCount() > 0) { |
|
$ip = $pdo->prepare("SELECT ip FROM b_log_accessi WHERE utente_modifica = :utente AND DATE(timestamp) = :date LIMIT 0,1"); |
|
$conference = $risultato_conference->fetch(PDO::FETCH_ASSOC); |
|
$response = json_decode($conference["response"],true); |
|
$host = $this->getHostFromID($conference["host"]); |
|
$info = $this->getAttendees($response["meetingid"],$this->ente["codice"],$host["codice"]); |
|
if (!empty($info)) { |
|
include(__DIR__."/log.php"); |
|
} |
|
} |
|
return $logs; |
|
} |
|
|
|
} |
|
|
|
?>
|