2015-11-09 11:01:11 -04:00
|
|
|
<?php
|
2015-12-18 09:57:40 -04:00
|
|
|
session_start();
|
2015-11-11 11:31:25 -04:00
|
|
|
require_once (dirname(__FILE__) . '/../../../gulliver/system/class.bootstrap.php');
|
2016-03-22 10:43:35 -04:00
|
|
|
require_once (dirname(__FILE__) . '/../../../gulliver/system/class.g.php');
|
2015-11-11 11:31:25 -04:00
|
|
|
|
|
|
|
|
$gmailToken = $_GET['gmailToken'];
|
|
|
|
|
$gmail = $_GET['gmail'];
|
|
|
|
|
$pmtoken = $_GET['pmtoken'];
|
|
|
|
|
$pmws = $_GET['pmws'];
|
|
|
|
|
$appUid = $_GET['appUid'];
|
|
|
|
|
$delIndex = $_GET['delIndex'];
|
|
|
|
|
$action = $_GET['action'];
|
|
|
|
|
$proUid = $_GET['proUid'];
|
|
|
|
|
$server = isset($_GET['server']) ? $_GET['server'] : '';
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2015-11-27 11:38:44 -04:00
|
|
|
//We do need the server to continue.
|
2015-12-04 10:42:38 -04:00
|
|
|
if( !isset($_GET['server']) || $server == "" ){
|
|
|
|
|
throw new \Exception(Bootstrap::LoadTranslation( 'ID_GMAIL_NEED_SERVER' ));
|
2015-11-27 11:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
//First check if the feature is enabled in the license.
|
|
|
|
|
$gCurl = curl_init( 'https://' . $server . '/api/1.0/' . $pmws . '/gmailIntegration/verifyGmailfeature/' );
|
|
|
|
|
curl_setopt( $gCurl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $pmtoken ) );
|
|
|
|
|
curl_setopt( $gCurl, CURLOPT_RETURNTRANSFER, true);
|
2015-11-11 11:31:25 -04:00
|
|
|
curl_setopt( $gCurl, CURLOPT_SSL_VERIFYPEER, false);
|
2016-03-08 10:17:03 -04:00
|
|
|
curl_setopt( $gCurl, CURLOPT_CONNECTTIMEOUT, 0);
|
|
|
|
|
curl_setopt($gCurl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
|
2016-03-23 17:35:44 -04:00
|
|
|
if (curl_exec ( $gCurl ) === false) {
|
2016-03-23 19:16:08 -04:00
|
|
|
echo 'Curl error: ' . curl_error ( $gCurl );
|
|
|
|
|
error_log(Bootstrap::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'));
|
|
|
|
|
die ();
|
2016-03-08 10:17:03 -04:00
|
|
|
} else {
|
2016-03-23 17:35:44 -04:00
|
|
|
$gCurl_response = curl_exec ( $gCurl );
|
|
|
|
|
curl_close ( $gCurl );
|
|
|
|
|
$gResp = G::json_decode ( $gCurl_response );
|
|
|
|
|
if ($gResp === false) {
|
|
|
|
|
echo Bootstrap::LoadTranslation ( 'ID_NO_LICENSE_FEATURE_ENABLED' );
|
|
|
|
|
die ();
|
|
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
set_time_limit(60);
|
|
|
|
|
|
|
|
|
|
$curl = curl_init( 'https://' . $server . '/api/1.0/' . $pmws . '/gmailIntegration/userexist/' . $gmail );
|
|
|
|
|
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $pmtoken ) );
|
|
|
|
|
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER,false);
|
2016-03-08 10:17:03 -04:00
|
|
|
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false);
|
2015-11-11 11:31:25 -04:00
|
|
|
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 0);
|
2015-11-09 11:01:11 -04:00
|
|
|
|
|
|
|
|
$curl_response = curl_exec( $curl );
|
|
|
|
|
curl_close($curl);
|
2016-03-11 19:05:40 -04:00
|
|
|
$decodedResp = G::json_decode($curl_response);
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2015-12-04 10:42:38 -04:00
|
|
|
if(!is_object($decodedResp) || property_exists($decodedResp,'error')) {
|
|
|
|
|
die($decodedResp->error->message);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 11:38:44 -04:00
|
|
|
//getting the enviroment
|
|
|
|
|
$enviroment = $decodedResp->enviroment;
|
|
|
|
|
|
|
|
|
|
if(count($decodedResp->user) > 1){
|
2015-11-09 11:01:11 -04:00
|
|
|
echo Bootstrap::LoadTranslation( 'ID_EMAIL_MORE_THAN_ONE_USER' );
|
|
|
|
|
die;
|
2015-11-27 11:38:44 -04:00
|
|
|
} else if(count($decodedResp->user) < 1){
|
2015-12-04 10:42:38 -04:00
|
|
|
echo Bootstrap::LoadTranslation( 'ID_USER_NOT_FOUND' );
|
2015-11-27 11:38:44 -04:00
|
|
|
die;
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//validationg if there is an actual PM session
|
2015-11-27 11:38:44 -04:00
|
|
|
if( !isset($_SESSION['USER_LOGGED']) || $_SESSION['USER_LOGGED'] != $decodedResp->user['0']->USR_UID){
|
2015-11-09 11:01:11 -04:00
|
|
|
$url = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='.$gmailToken;
|
|
|
|
|
|
|
|
|
|
// init curl object
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
// define options
|
2016-03-23 17:35:44 -04:00
|
|
|
$optArray = array(
|
|
|
|
|
CURLOPT_URL => $url,
|
|
|
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
|
|
|
CURLOPT_SSL_VERIFYHOST => false
|
2015-11-09 11:01:11 -04:00
|
|
|
);
|
|
|
|
|
// apply those options
|
|
|
|
|
curl_setopt_array($ch, $optArray);
|
|
|
|
|
// execute request and get response
|
|
|
|
|
$result = curl_exec($ch);
|
2016-03-11 19:05:40 -04:00
|
|
|
$response = (G::json_decode($result));
|
2015-11-09 11:01:11 -04:00
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
|
|
//First validate if this user (mail) corresponds to a PM user
|
|
|
|
|
if(isset($response->email) && ($gmail == $response->email)){
|
|
|
|
|
//If the email corresponds I get the username and with the gmail user_id the session is created.
|
2015-11-27 11:38:44 -04:00
|
|
|
if($decodedResp->user['0']->USR_STATUS == "ACTIVE"){
|
2015-11-09 11:01:11 -04:00
|
|
|
//User Active! lets create the Session
|
2015-12-04 10:42:38 -04:00
|
|
|
@session_destroy();
|
|
|
|
|
session_start();
|
2015-11-11 11:31:25 -04:00
|
|
|
session_regenerate_id();
|
|
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
if (PHP_VERSION < 5.2) {
|
2015-11-27 11:38:44 -04:00
|
|
|
setcookie("workspaceSkin", $enviroment, time() + (24 * 60 * 60), "/sys" . $enviroment, "; HttpOnly");
|
2015-11-09 11:01:11 -04:00
|
|
|
} else {
|
2015-11-27 11:38:44 -04:00
|
|
|
setcookie("workspaceSkin", $enviroment, time() + (24 * 60 * 60), "/sys" . $enviroment, null, false, true);
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 10:42:38 -04:00
|
|
|
$_SESSION = array();
|
|
|
|
|
$_SESSION['__EE_INSTALLATION__'] = 2;
|
|
|
|
|
$_SESSION['__EE_SW_PMLICENSEMANAGER__'] = 1;
|
|
|
|
|
$_SESSION['phpLastFileFound'] = '';
|
|
|
|
|
$_SESSION['USERNAME_PREVIOUS1'] = $decodedResp->user['0']->USR_USERNAME;
|
|
|
|
|
$_SESSION['USERNAME_PREVIOUS2'] = $decodedResp->user['0']->USR_USERNAME;
|
|
|
|
|
$_SESSION['WORKSPACE'] = $pmws;
|
|
|
|
|
$_SESSION['USER_LOGGED'] = $decodedResp->user['0']->USR_UID;
|
|
|
|
|
$_SESSION['USR_USERNAME'] = $decodedResp->user['0']->USR_USERNAME;
|
|
|
|
|
$_SESSION['USR_FULLNAME'] = $decodedResp->user['0']->USR_FIRSTNAME. ' ' .$decodedResp->user['0']->USR_LASTNAME;
|
|
|
|
|
$_SESSION['__sw__'] = 1;
|
2015-11-11 11:31:25 -04:00
|
|
|
//session created
|
2015-11-09 11:01:11 -04:00
|
|
|
} else {
|
|
|
|
|
echo Bootstrap::LoadTranslation( 'ID_USER_NOT_ACTIVE' );
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
echo Bootstrap::LoadTranslation( 'ID_USER_DOES_NOT_CORRESPOND' );
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($action == "draft"){
|
|
|
|
|
//sending the email
|
2016-03-23 17:35:44 -04:00
|
|
|
$curlApp = curl_init( 'https://' . $server . '/api/1.0/' . $pmws . '/gmailIntegration/sendEmail/' . $appUid . '/to/' . $gmail . '/index/' . $delIndex );
|
|
|
|
|
curl_setopt ( $curlApp, CURLOPT_HTTPHEADER, array (
|
|
|
|
|
'Authorization: Bearer ' . $pmtoken
|
|
|
|
|
) );
|
|
|
|
|
curl_setopt ( $curlApp, CURLOPT_CUSTOMREQUEST, "POST" );
|
|
|
|
|
curl_setopt ( $curlApp, CURLOPT_RETURNTRANSFER, true );
|
|
|
|
|
curl_setopt ( $curlApp, CURLOPT_SSL_VERIFYPEER, false );
|
|
|
|
|
curl_setopt ( $curlApp, CURLOPT_SSL_VERIFYHOST, false );
|
|
|
|
|
curl_setopt ( $curlApp, CURLOPT_CONNECTTIMEOUT, 0 );
|
2015-11-09 11:01:11 -04:00
|
|
|
|
|
|
|
|
$curl_response_app = curl_exec( $curlApp );
|
|
|
|
|
curl_close( $curlApp );
|
|
|
|
|
|
2015-11-27 11:38:44 -04:00
|
|
|
$mainUrl = '/sys'. $pmws .'/en/'. $enviroment .'/cases/open?APP_UID='.$appUid.'&DEL_INDEX='.$delIndex.'&action='.$action.'&gmail=1';
|
2015-11-09 11:01:11 -04:00
|
|
|
header( 'location:' . $mainUrl );
|
2015-12-09 17:55:15 -04:00
|
|
|
$_SESSION['APPLICATION'] =$appUid ;
|
|
|
|
|
$_SESSION['INDEX'] = $delIndex;
|
2015-11-09 11:01:11 -04:00
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 11:38:44 -04:00
|
|
|
$_SESSION['server'] = 'https://' . $server . '/sys'. $pmws .'/en/'.$enviroment.'/';
|
2015-11-11 11:31:25 -04:00
|
|
|
$_SESSION['PMCase'] = 'cases/cases_Open?APP_UID='.$appUid.'&DEL_INDEX='.$delIndex.'&action='.$action.'&gmail=1';
|
|
|
|
|
$_SESSION['PMProcessmap'] = 'designer?prj_uid=' . $proUid . '&prj_readonly=true&app_uid=' . $appUid;
|
|
|
|
|
$_SESSION['PMUploadedDocuments'] = 'cases/ajaxListener?action=uploadedDocuments';
|
|
|
|
|
$_SESSION['PMGeneratedDocuments'] = 'cases/casesGenerateDocumentPage_Ajax.php?actionAjax=casesGenerateDocumentPage';
|
2015-11-09 11:01:11 -04:00
|
|
|
|
|
|
|
|
header( 'location:' . 'templateForm.php' );
|
|
|
|
|
|