Add files pmgmail
This commit is contained in:
@@ -29,7 +29,8 @@
|
|||||||
"underscore/underscore": "1.5.2",
|
"underscore/underscore": "1.5.2",
|
||||||
"colosa/pmUI": "dev-master",
|
"colosa/pmUI": "dev-master",
|
||||||
"colosa/MichelangeloFE": "dev-master",
|
"colosa/MichelangeloFE": "dev-master",
|
||||||
"colosa/pmdynaform": "dev-master"
|
"colosa/pmdynaform": "dev-master",
|
||||||
|
"google/apiclient": "1.1.*"
|
||||||
},
|
},
|
||||||
"require-dev":{
|
"require-dev":{
|
||||||
"guzzle/guzzle":"~3.1.1",
|
"guzzle/guzzle":"~3.1.1",
|
||||||
|
|||||||
269
workflow/engine/classes/class.pmDrive.php
Executable file
269
workflow/engine/classes/class.pmDrive.php
Executable file
@@ -0,0 +1,269 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class.pmDrive.php
|
||||||
|
*
|
||||||
|
* @package workflow.engine.class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class PMDrive extends PMGoogleApi
|
||||||
|
{
|
||||||
|
private $folderIdPMDrive = '';
|
||||||
|
private $folderNamePMDrive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate if exist folder PMDrive
|
||||||
|
*
|
||||||
|
* @param $userUid id user
|
||||||
|
*/
|
||||||
|
private function validateFolderPMDrive($usrUid)
|
||||||
|
{
|
||||||
|
if ($this->folderIdPMDrive != '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = new Users();
|
||||||
|
$dataUser = $user->load($usrUid);
|
||||||
|
|
||||||
|
if (!empty($dataUser['USR_EMAIL'])) {
|
||||||
|
$this->setDriveUser($dataUser['USR_EMAIL']);
|
||||||
|
}
|
||||||
|
$this->folderIdPMDrive = empty($dataUser['USR_PMDRIVE_FOLDER_UID']) ? '' : $dataUser['USR_PMDRIVE_FOLDER_UID'];
|
||||||
|
|
||||||
|
$conf = $this->getConfigGmail();
|
||||||
|
$this->folderNamePMDrive = empty($conf->aConfig['folderNamePMDrive']) ? 'PMDrive (' . SYS_SYS . ')' : $conf->aConfig['folderNamePMDrive'];
|
||||||
|
|
||||||
|
if ($this->folderIdPMDrive == '') {
|
||||||
|
$folderid = $this->createFolder($this->folderNamePMDrive);
|
||||||
|
|
||||||
|
$this->folderIdPMDrive = $folderid->id;
|
||||||
|
$dataUser['USR_PMDRIVE_FOLDER_UID'] = $folderid->id;
|
||||||
|
$user->update($dataUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFolderIdPMDrive($usrUid)
|
||||||
|
{
|
||||||
|
$this->validateFolderPMDrive($usrUid);
|
||||||
|
return $this->folderIdPMDrive;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set account user
|
||||||
|
*
|
||||||
|
* @param $user email user
|
||||||
|
*/
|
||||||
|
public function setFolderNamePMDrive($name)
|
||||||
|
{
|
||||||
|
$conf = $this->getConfigGmail();
|
||||||
|
$conf->aConfig['folderNamePMDrive'] = $name;
|
||||||
|
$conf->saveConfig('GOOGLE_API_SETTINGS', '', '', '');
|
||||||
|
|
||||||
|
$this->folderNamePMDrive = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set account user
|
||||||
|
*
|
||||||
|
* @param $user email user
|
||||||
|
*/
|
||||||
|
public function setDriveUser($user)
|
||||||
|
{
|
||||||
|
$this->setUser($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance google service Drive
|
||||||
|
*
|
||||||
|
* @return Google_Service_Drive $service Drive API service instance.
|
||||||
|
*/
|
||||||
|
private function serviceDrive()
|
||||||
|
{
|
||||||
|
$client = $this->serviceClient();
|
||||||
|
$service = new Google_Service_Drive($client);
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a list of File resources.
|
||||||
|
*
|
||||||
|
* @param string $fileId uid file
|
||||||
|
* @return Array List of Google_Service_Drive_DriveFile resources.
|
||||||
|
*/
|
||||||
|
public function listFolder($fileId)
|
||||||
|
{
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.file');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.readonly');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.metadata.readonly');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.appdata');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.metadata');
|
||||||
|
$service = $this->serviceDrive();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$parameters['q'] = "'" . $fileId . "' in parents and trashed = false";
|
||||||
|
$parents = $service->files->listFiles($parameters);
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
foreach ($parents->getItems() as $parent) {
|
||||||
|
//echo 'File Id: ' . $parent->getId() . '<br>';
|
||||||
|
$rows = $parent;
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a list of File resources.
|
||||||
|
*
|
||||||
|
* @param string $name Title of the file to insert, including the extension.
|
||||||
|
* @param string $parentId Parent folder's ID.
|
||||||
|
* @return Google_Service_Drive_DriveFile The file that was inserted. NULL is returned if an API error occurred.
|
||||||
|
*/
|
||||||
|
public function createFolder($name, $parentId = null)
|
||||||
|
{
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.file');
|
||||||
|
|
||||||
|
$service = $this->serviceDrive();
|
||||||
|
|
||||||
|
$file = new Google_Service_Drive_DriveFile();
|
||||||
|
$file->setMimeType("application/vnd.google-apps.folder");
|
||||||
|
$file->setTitle($name);
|
||||||
|
|
||||||
|
if ($parentId != null) {
|
||||||
|
$parent = new Google_Service_Drive_ParentReference();
|
||||||
|
$parent->setId($parentId);
|
||||||
|
$file->setParents(array($parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$createdFolder = $service->files->insert($file);
|
||||||
|
return $createdFolder;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return "An error occurred: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* upload new file
|
||||||
|
*
|
||||||
|
* @param string $mime MIME type of the file to insert.
|
||||||
|
* @param string $src location of the file to insert.
|
||||||
|
* @param string $name Title of the file to insert, including the extension.
|
||||||
|
* @return Google_Service_Drive_DriveFile The file that was inserted. NULL is returned if an API error occurred.
|
||||||
|
*/
|
||||||
|
public function uploadFile($mime, $src, $name, $parentId = null)
|
||||||
|
{
|
||||||
|
//$this->validateFolderPMDrive();
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.file');
|
||||||
|
|
||||||
|
$service = $this->serviceDrive();
|
||||||
|
|
||||||
|
$file = new Google_Service_Drive_DriveFile();
|
||||||
|
$file->setMimeType("*/*");
|
||||||
|
$file->setTitle($name);
|
||||||
|
|
||||||
|
// Set the parent folder.
|
||||||
|
if ($parentId != null) {
|
||||||
|
$parent = new Google_Service_Drive_ParentReference();
|
||||||
|
$parent->setId($parentId);
|
||||||
|
$file->setParents(array($parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = file_get_contents($src);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$createdFile = $service->files->insert(
|
||||||
|
$file,
|
||||||
|
array(
|
||||||
|
'data' => $data,
|
||||||
|
'mimeType' => $mime,
|
||||||
|
'uploadType' => 'media'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $createdFile;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return "An error occurred: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download a file's content.
|
||||||
|
*
|
||||||
|
* @param string $fileId id file.
|
||||||
|
* @return String The file's content if successful, null otherwise
|
||||||
|
*/
|
||||||
|
public function downloadFile($fileId)
|
||||||
|
{
|
||||||
|
//$this->validateFolderPMDrive();
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.appdata');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.apps.readonly');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.file');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.metadata');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.metadata.readonly');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.readonly');
|
||||||
|
$service = $this->serviceDrive();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$file = $service->files->get($fileId);
|
||||||
|
|
||||||
|
$downloadUrl = $file->getDownloadUrl();
|
||||||
|
if ($downloadUrl) {
|
||||||
|
$request = new Google_Http_Request($downloadUrl, 'GET', null, null);
|
||||||
|
$httpRequest = $service->getClient()->getAuth()->authenticatedRequest($request);
|
||||||
|
if ($httpRequest->getResponseHttpCode() == 200) {
|
||||||
|
return $httpRequest->getResponseBody();
|
||||||
|
} else {
|
||||||
|
// An error occurred.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// The file doesn't have any content stored on Drive.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
print "An error occurred: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a new permission.
|
||||||
|
*
|
||||||
|
* @param String $fileId ID of the file to insert permission for.
|
||||||
|
* @param String $value User or group e-mail address, domain name or NULL for "default" type.
|
||||||
|
* @param String $type The value "user", "group", "domain" or "default".
|
||||||
|
* @param String $role The value "owner", "writer" or "reader".
|
||||||
|
* @return Google_Servie_Drive_Permission The inserted permission. NULL is returned if an API error occurred.
|
||||||
|
*/
|
||||||
|
public function setPermission($fileId, $value, $type = 'user', $role = 'reader', $sendNotification = false)
|
||||||
|
{
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive');
|
||||||
|
$this->setScope('https://www.googleapis.com/auth/drive.file');
|
||||||
|
|
||||||
|
$service = $this->serviceDrive();
|
||||||
|
|
||||||
|
$newPermission = new Google_Service_Drive_Permission();
|
||||||
|
$newPermission->setValue($value);
|
||||||
|
$newPermission->setType($type);
|
||||||
|
$newPermission->setRole($role);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$permission = $service->permissions->insert(
|
||||||
|
$fileId,
|
||||||
|
$newPermission,
|
||||||
|
array(
|
||||||
|
'sendNotificationEmails' => $sendNotification
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $permission;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log('permission error: ' . $e->getMessage());
|
||||||
|
return "An error occurred: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
213
workflow/engine/classes/class.pmGoogleApi.php
Executable file
213
workflow/engine/classes/class.pmGoogleApi.php
Executable file
@@ -0,0 +1,213 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class.pmGoogleApi.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once PATH_TRUNK . 'vendor' . PATH_SEP . 'google' . PATH_SEP . 'apiclient' . PATH_SEP . 'src' . PATH_SEP . 'Google' . PATH_SEP . 'autoload.php';
|
||||||
|
|
||||||
|
class PMGoogleApi
|
||||||
|
{
|
||||||
|
private $scope = array();
|
||||||
|
private $serviceAccountEmail;
|
||||||
|
private $serviceAccountP12;
|
||||||
|
private $statusService;
|
||||||
|
private $domain;
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$licensedFeatures = &PMLicensedFeatures::getSingleton();
|
||||||
|
if (!$licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
|
||||||
|
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
|
||||||
|
G::header('location: ../login/login');
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
$this->loadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setScope($scope)
|
||||||
|
{
|
||||||
|
$this->scope[] = $scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getScope()
|
||||||
|
{
|
||||||
|
return $this->scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUser($user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUser()
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatusService($status)
|
||||||
|
{
|
||||||
|
$conf = $this->getConfigGmail();
|
||||||
|
|
||||||
|
$conf->aConfig['statusService'] = $status;
|
||||||
|
$conf->saveConfig('GOOGLE_API_SETTINGS', '', '', '');
|
||||||
|
|
||||||
|
$this->statusService = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusService()
|
||||||
|
{
|
||||||
|
return $this->statusService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConfigGmail()
|
||||||
|
{
|
||||||
|
$conf = new Configurations();
|
||||||
|
$conf->loadConfig($gmail, 'GOOGLE_API_SETTINGS', '');
|
||||||
|
return $conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setServiceAccountEmail($serviceAccountEmail)
|
||||||
|
{
|
||||||
|
$conf = $this->getConfigGmail();
|
||||||
|
|
||||||
|
$conf->aConfig['serviceAccountEmail'] = $serviceAccountEmail;
|
||||||
|
$conf->saveConfig('GOOGLE_API_SETTINGS', '', '', '');
|
||||||
|
|
||||||
|
$this->serviceAccountEmail = $serviceAccountEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getServiceAccountEmail()
|
||||||
|
{
|
||||||
|
return $this->serviceAccountEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setServiceAccountP12($serviceAccountP12)
|
||||||
|
{
|
||||||
|
$conf = $this->getConfigGmail();
|
||||||
|
|
||||||
|
$conf->aConfig['serviceAccountP12'] = $serviceAccountP12;
|
||||||
|
$conf->saveConfig('GOOGLE_API_SETTINGS', '', '', '');
|
||||||
|
|
||||||
|
$this->serviceAccountP12 = $serviceAccountP12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getserviceAccountP12()
|
||||||
|
{
|
||||||
|
return $this->serviceAccountP12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDomain($domain)
|
||||||
|
{
|
||||||
|
$conf = $this->getConfigGmail();
|
||||||
|
|
||||||
|
$conf->aConfig['domain'] = $domain;
|
||||||
|
$conf->saveConfig('GOOGLE_API_SETTINGS', '', '', '');
|
||||||
|
|
||||||
|
$this->domain = $domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDomain()
|
||||||
|
{
|
||||||
|
return $this->domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load configuration gmail service account
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function loadSettings()
|
||||||
|
{
|
||||||
|
$conf = $this->getConfigGmail();
|
||||||
|
|
||||||
|
$serviceAccountP12 = empty($conf->aConfig['serviceAccountP12']) ? '' : $conf->aConfig['serviceAccountP12'];
|
||||||
|
$serviceAccountEmail = empty($conf->aConfig['serviceAccountEmail']) ? '' : $conf->aConfig['serviceAccountEmail'];
|
||||||
|
$statusService = empty($conf->aConfig['statusService']) ? '' : $conf->aConfig['statusService'];
|
||||||
|
|
||||||
|
$this->scope = array();
|
||||||
|
$this->setServiceAccountEmail($serviceAccountEmail);
|
||||||
|
$this->setServiceAccountP12($serviceAccountP12);
|
||||||
|
$this->setStatusService($statusService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New service client - Authentication google Api
|
||||||
|
*
|
||||||
|
* @return Google_Service_Client $service API service instance.
|
||||||
|
*/
|
||||||
|
public function serviceClient()
|
||||||
|
{
|
||||||
|
$key = file_get_contents(PATH_DATA_SITE . $this->serviceAccountP12);
|
||||||
|
|
||||||
|
$assertionCredentials = new Google_Auth_AssertionCredentials(
|
||||||
|
$this->serviceAccountEmail,
|
||||||
|
$this->scope,
|
||||||
|
$key
|
||||||
|
);
|
||||||
|
$assertionCredentials->sub = $this->user;
|
||||||
|
|
||||||
|
$client = new Google_Client();
|
||||||
|
$client->setApplicationName("PMDrive");
|
||||||
|
$client->setAssertionCredentials($assertionCredentials);
|
||||||
|
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New service client - Authentication google Api
|
||||||
|
*
|
||||||
|
* @return Google_Service_Client $service API service instance.
|
||||||
|
*/
|
||||||
|
public function testService($serviceAccountEmail, $pathServiceAccountP12)
|
||||||
|
{
|
||||||
|
$key = file_get_contents($pathServiceAccountP12);
|
||||||
|
|
||||||
|
$assertionCredentials = new Google_Auth_AssertionCredentials(
|
||||||
|
$serviceAccountEmail,
|
||||||
|
array(
|
||||||
|
'https://www.googleapis.com/auth/drive',
|
||||||
|
'https://www.googleapis.com/auth/drive.file',
|
||||||
|
'https://www.googleapis.com/auth/drive.readonly',
|
||||||
|
'https://www.googleapis.com/auth/drive.metadata.readonly',
|
||||||
|
'https://www.googleapis.com/auth/drive.appdata',
|
||||||
|
'https://www.googleapis.com/auth/drive.metadata',
|
||||||
|
'https://www.googleapis.com/auth/drive.photos.readonly'
|
||||||
|
),
|
||||||
|
$key
|
||||||
|
);
|
||||||
|
$assertionCredentials->sub = $this->user;
|
||||||
|
|
||||||
|
$client = new Google_Client();
|
||||||
|
$client->setApplicationName("PMDrive");
|
||||||
|
$client->setAssertionCredentials($assertionCredentials);
|
||||||
|
|
||||||
|
$service = new Google_Service_Drive($client);
|
||||||
|
|
||||||
|
$result = new StdClass();
|
||||||
|
$result->success = true;
|
||||||
|
|
||||||
|
$result->currentUserName = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR');
|
||||||
|
$result->rootFolderId = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR');
|
||||||
|
$result->quotaType = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR');
|
||||||
|
$result->quotaBytesTotal = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR');
|
||||||
|
$result->quotaBytesUsed = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$about = $service->about->get();
|
||||||
|
|
||||||
|
$result->currentUserName = $about->getName();
|
||||||
|
$result->rootFolderId = $about->getRootFolderId();
|
||||||
|
$result->quotaType = $about->getQuotaType();
|
||||||
|
$result->quotaBytesTotal = $about->getQuotaBytesTotal();
|
||||||
|
$result->quotaBytesUsed = $about->getQuotaBytesUsed();
|
||||||
|
$result->responseGmailTest = G::LoadTranslation('ID_SUCCESSFUL_CONNECTION');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$result->success = false;
|
||||||
|
$result->responseGmailTest = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
115
workflow/engine/controllers/pmGmail.php
Normal file
115
workflow/engine/controllers/pmGmail.php
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pmGmail controller
|
||||||
|
* @inherits Controller
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
|
||||||
|
class pmGmail extends Controller
|
||||||
|
{
|
||||||
|
public function saveConfigPmGmail($httpData)
|
||||||
|
{
|
||||||
|
G::LoadClass( "pmGoogleApi" );
|
||||||
|
$pmGoogle = new PMGoogleApi();
|
||||||
|
$result = new StdClass();
|
||||||
|
$result->success = true;
|
||||||
|
|
||||||
|
if (!empty($httpData->status_pmgmail)) {
|
||||||
|
$httpData->status_pmgmail = $httpData->status_pmgmail == 1 ? true : false;
|
||||||
|
$pmGoogle->setStatusService($httpData->status_pmgmail);
|
||||||
|
$message = G::LoadTranslation('ID_ENABLE_PMGMAIL') . ': ' . ($httpData->status_pmgmail ? G::LoadTranslation('ID_ENABLE') : G::LoadTranslation('ID_DISABLE'));
|
||||||
|
if (!empty($httpData->email_service_account)) {
|
||||||
|
$pmGoogle->setServiceAccountEmail($httpData->email_service_account);
|
||||||
|
$message .= ', ' . G::LoadTranslation('ID_PMG_EMAIL') . ': ' . $httpData->email_service_account;
|
||||||
|
}
|
||||||
|
if (!empty($_FILES)) {
|
||||||
|
if ($_FILES['file_p12']['error'] != 1) {
|
||||||
|
if ($_FILES['file_p12']['tmp_name'] != '') {
|
||||||
|
G::uploadFile($_FILES['file_p12']['tmp_name'], PATH_DATA_SITE, $_FILES['file_p12']['name']);
|
||||||
|
$pmGoogle->setServiceAccountP12($_FILES['file_p12']['name']);
|
||||||
|
$message .= ', ' . G::LoadTranslation('ID_PMG_FILE') . ': ' . $_FILES['file_p12']['name'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result->success = false;
|
||||||
|
$result->fileError = true;
|
||||||
|
print(G::json_encode($result));
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$pmGoogle->setStatusService(false);
|
||||||
|
$message = G::LoadTranslation('ID_ENABLE_PMGMAIL') . ': ' . G::LoadTranslation('ID_DISABLE');
|
||||||
|
}
|
||||||
|
G::auditLog("Update Settings Gmail", $message);
|
||||||
|
|
||||||
|
print(G::json_encode($result));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formPMGmail()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->includeExtJS('admin/pmGmail');
|
||||||
|
if (!empty ($_SESSION['__PMGMAIL_ERROR__'])) {
|
||||||
|
$this->setJSVar('__PMGMAIL_ERROR__', $_SESSION['__PMGMAIL_ERROR__']);
|
||||||
|
unset($_SESSION['__PMGMAIL_ERROR__']);
|
||||||
|
}
|
||||||
|
G::LoadClass( "pmGoogleApi" );
|
||||||
|
$pmGoogle = new PMGoogleApi();
|
||||||
|
$accountEmail = $pmGoogle->getServiceAccountEmail();
|
||||||
|
$fileP12 = $pmGoogle->getServiceAccountP12();
|
||||||
|
$enablePMGmail = $pmGoogle->getStatusService();
|
||||||
|
|
||||||
|
$this->setJSVar('accountEmail', $accountEmail);
|
||||||
|
$this->setJSVar('fileP12', $fileP12);
|
||||||
|
$this->setJSVar('enablePMGmail', $enablePMGmail);
|
||||||
|
|
||||||
|
|
||||||
|
G::RenderPage('publish', 'extJs');
|
||||||
|
} catch (Exception $error) {
|
||||||
|
$_SESSION['__PMGMAIL_ERROR__'] = $error->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConfigPmGmail($httpData)
|
||||||
|
{
|
||||||
|
G::LoadClass( "pmGoogleApi" );
|
||||||
|
$pmGoogle = new PMGoogleApi();
|
||||||
|
|
||||||
|
$emailServiceAccount = empty($httpData->email_service_account) ? $pmGoogle->getServiceAccountEmail() : $httpData->email_service_account;
|
||||||
|
$pathServiceAccountP12 = empty($_FILES['file_p12']['tmp_name']) ? PATH_DATA_SITE . $pmGoogle->getserviceAccountP12() : $_FILES['file_p12']['tmp_name'];
|
||||||
|
|
||||||
|
print(G::json_encode($pmGoogle->testService($emailServiceAccount, $pathServiceAccountP12)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserGmail()
|
||||||
|
{
|
||||||
|
$criteria = new Criteria();
|
||||||
|
$criteria->clearSelectColumns();
|
||||||
|
$criteria->addSelectColumn('COUNT(*) AS NUM_EMAIL');
|
||||||
|
$criteria->addSelectColumn(UsersPeer::USR_UID);
|
||||||
|
$criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME);
|
||||||
|
$criteria->addSelectColumn(UsersPeer::USR_LASTNAME);
|
||||||
|
$criteria->addSelectColumn(UsersPeer::USR_EMAIL);
|
||||||
|
$criteria->addGroupByColumn(UsersPeer::USR_EMAIL);
|
||||||
|
|
||||||
|
$rs = UsersPeer::doSelectRS($criteria);
|
||||||
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
|
$userRepeat = array();
|
||||||
|
while ($rs->next()) {
|
||||||
|
$row = $rs->getRow();
|
||||||
|
if ($row['NUM_EMAIL'] > 1) {
|
||||||
|
$userRepeat[] = array(
|
||||||
|
'USR_UID' => $row['USR_UID'],
|
||||||
|
'FULL_NAME' => $row['USR_FIRSTNAME'] . ' ' . $row['USR_LASTNAME'],
|
||||||
|
'EMAIL' => $row['USR_EMAIL']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print(G::json_encode($userRepeat));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,9 +70,12 @@ if ($RBAC->userCanAccess('PM_SETUP') == 1) {
|
|||||||
$G_TMP_MENU->AddIdRawOption('DASHBOARD', '../dashboard/dashletsList', ucfirst(G::LoadTranslation('ID_DASHBOARD')), '', '', 'settings');
|
$G_TMP_MENU->AddIdRawOption('DASHBOARD', '../dashboard/dashletsList', ucfirst(G::LoadTranslation('ID_DASHBOARD')), '', '', 'settings');
|
||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
|
|
||||||
if ($licensedFeatures->verifyfeature('r19Vm5DK1UrT09MenlLYjZxejlhNUZ1b1NhV0JHWjBsZEJ6dnpJa3dTeWVLVT0=')) {
|
if ($licensedFeatures->verifyfeature('r19Vm5DK1UrT09MenlLYjZxejlhNUZ1b1NhV0JHWjBsZEJ6dnpJa3dTeWVLVT0=')) {
|
||||||
$G_TMP_MENU->AddIdRawOption('STRATEGIC_DASHBOARD', '../strategicDashboard/dashboardList', ucfirst(G::LoadTranslation('ID_STRATEGIC_DASHBOARD')), '', '', 'settings');
|
$G_TMP_MENU->AddIdRawOption('STRATEGIC_DASHBOARD', '../strategicDashboard/dashboardList', ucfirst(G::LoadTranslation('ID_STRATEGIC_DASHBOARD')), '', '', 'settings');
|
||||||
}
|
}
|
||||||
|
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
|
||||||
|
$G_TMP_MENU->AddIdRawOption('PMGMAIL', '../pmGmail/formPMGmail', ucfirst(G::LoadTranslation('ID_PMGMAIL')), '', '', 'settings');
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
|
|
||||||
|
|||||||
315
workflow/engine/templates/admin/pmGmail.js
Normal file
315
workflow/engine/templates/admin/pmGmail.js
Normal file
@@ -0,0 +1,315 @@
|
|||||||
|
var saveButton;
|
||||||
|
var testButton;
|
||||||
|
var storeUsers;
|
||||||
|
Ext.onReady(function(){
|
||||||
|
Ext.QuickTips.init();
|
||||||
|
|
||||||
|
testButton = new Ext.Action({
|
||||||
|
text : _('ID_TEST_CONNECTION'),
|
||||||
|
disabled : !enablePMGmail,
|
||||||
|
handler : testSettings
|
||||||
|
});
|
||||||
|
|
||||||
|
saveButton = new Ext.Action({
|
||||||
|
text : _('ID_SAVE_SETTINGS'),
|
||||||
|
disabled : true,
|
||||||
|
handler : saveSettings
|
||||||
|
});
|
||||||
|
|
||||||
|
var configurationPMGmail = new Ext.form.FieldSet({
|
||||||
|
title: _('ID_PMGMAIL_SETTINGS'),
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
xtype: 'checkbox',
|
||||||
|
id: 'status_pmgmail',
|
||||||
|
name: 'status_pmgmail',
|
||||||
|
boxLabel: _('ID_ENABLE_PMGMAIL'),
|
||||||
|
value: 0,
|
||||||
|
inputValue: 1,
|
||||||
|
uncheckedValue: 0,
|
||||||
|
listeners : {
|
||||||
|
check : function(that, checked) {
|
||||||
|
changeSettings();
|
||||||
|
if (checked) {
|
||||||
|
Ext.getCmp('email_service_account').enable();
|
||||||
|
Ext.getCmp('status_pmgmail').enable();
|
||||||
|
Ext.getCmp('file_p12').enable();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Ext.MessageBox.confirm(
|
||||||
|
_('ID_CONFIRM'),
|
||||||
|
_('ID_PMGMAIL_DISABLE'),
|
||||||
|
function (btn, text) {
|
||||||
|
if (btn == "yes") {
|
||||||
|
Ext.getCmp('email_service_account').disable();
|
||||||
|
Ext.getCmp('file_p12').disable();
|
||||||
|
Ext.getCmp('listUsers').hide();
|
||||||
|
testButton.disable();
|
||||||
|
saveButton.disable();
|
||||||
|
saveSettings();
|
||||||
|
} else {
|
||||||
|
Ext.getCmp('status_pmgmail').enable();
|
||||||
|
Ext.getCmp('email_service_account').enable();
|
||||||
|
Ext.getCmp('file_p12').enable();
|
||||||
|
Ext.getCmp('status_pmgmail').setValue(1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
xtype : 'textfield',
|
||||||
|
id : 'email_service_account',
|
||||||
|
name : 'email_service_account',
|
||||||
|
fieldLabel : _('ID_PMG_EMAIL'),
|
||||||
|
width : 400,
|
||||||
|
allowBlank : false,
|
||||||
|
value : accountEmail,
|
||||||
|
disabled : !enablePMGmail,
|
||||||
|
listeners : {
|
||||||
|
change: function(){
|
||||||
|
changeSettings();
|
||||||
|
},
|
||||||
|
focus : function(tb, e) {
|
||||||
|
Ext.QuickTips.register({
|
||||||
|
target: tb,
|
||||||
|
title: _('ID_PMG_EMAIL'),
|
||||||
|
text: accountEmail
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
xtype : 'fileuploadfield',
|
||||||
|
id : 'file_p12',
|
||||||
|
emptyText : _('ID_PMG_SELECT_FILE'),
|
||||||
|
fieldLabel : _('ID_PMG_FILE'),
|
||||||
|
name : 'file_p12',
|
||||||
|
buttonText : '',
|
||||||
|
width : 400,
|
||||||
|
disabled : !enablePMGmail,
|
||||||
|
buttonCfg : {
|
||||||
|
iconCls : 'upload-icon'
|
||||||
|
},
|
||||||
|
listeners:{
|
||||||
|
change : function(){
|
||||||
|
changeSettings();
|
||||||
|
},
|
||||||
|
afterrender:function(cmp){
|
||||||
|
changeSettings();
|
||||||
|
cmp.fileInput.set({
|
||||||
|
accept:'*/p12'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
regex : /(.)+((\.p12)(\w)?)$/i,
|
||||||
|
regexText : _('ID_PMG_TYPE_ACCEPT')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
xtype : 'label',
|
||||||
|
labelAlign : 'right',
|
||||||
|
fieldLabel : '',
|
||||||
|
text : fileP12,
|
||||||
|
width : 400,
|
||||||
|
style : "padding-left:180px;"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
var testPMGmail = new Ext.form.FieldSet({
|
||||||
|
id : 'testPMGmail',
|
||||||
|
title : _('ID_TEST_CONNECTION'),
|
||||||
|
hidden : true,
|
||||||
|
items : [
|
||||||
|
{
|
||||||
|
id : 'currentUserName',
|
||||||
|
xtype : 'label',
|
||||||
|
labelAlign : 'right',
|
||||||
|
fieldLabel : _('ID_CURRENT_USER'),
|
||||||
|
text : '',
|
||||||
|
width : 400
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id : 'rootFolderId',
|
||||||
|
xtype : 'label',
|
||||||
|
labelAlign : 'right',
|
||||||
|
fieldLabel : _('ID_ROOT_FOLDER'),
|
||||||
|
text : '',
|
||||||
|
width : 400
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id : 'quotaType',
|
||||||
|
xtype : 'label',
|
||||||
|
labelAlign : 'right',
|
||||||
|
fieldLabel : _('ID_QUOTA_TYPE'),
|
||||||
|
text : '',
|
||||||
|
width : 400
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id : 'quotaBytesTotal',
|
||||||
|
xtype : 'label',
|
||||||
|
labelAlign : 'right',
|
||||||
|
fieldLabel : _('ID_QUOTA_TOTAL'),
|
||||||
|
text : '',
|
||||||
|
width : 400
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id : 'quotaBytesUsed',
|
||||||
|
xtype : 'label',
|
||||||
|
labelAlign : 'right',
|
||||||
|
fieldLabel : _('ID_QUOTA_USED'),
|
||||||
|
text : '',
|
||||||
|
width : 400
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id : 'responseGmailTest',
|
||||||
|
xtype : 'label',
|
||||||
|
labelAlign : 'right',
|
||||||
|
labelStyle : 'font-weight:bold;',
|
||||||
|
fieldLabel : _('SERVER_RESPONSE'),
|
||||||
|
text : '',
|
||||||
|
width : 400
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
storeUsers = new Ext.data.JsonStore({
|
||||||
|
url: '../pmGmail/testUserGmail',
|
||||||
|
fields: [
|
||||||
|
'USR_UID',
|
||||||
|
'FULL_NAME',
|
||||||
|
'EMAIL'
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
var listViewUsers = new Ext.list.ListView({
|
||||||
|
store: storeUsers,
|
||||||
|
singleSelect: true,
|
||||||
|
emptyText: _('ID_GRID_PAGE_NO_USERS_MESSAGE'),
|
||||||
|
reserveScrollOffset: true,
|
||||||
|
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
header: _('ID_FULL_NAME'),
|
||||||
|
width:.4,
|
||||||
|
dataIndex: 'FULL_NAME'
|
||||||
|
},{
|
||||||
|
header: _('ID_EMAIL'),
|
||||||
|
width:.4,
|
||||||
|
dataIndex: 'EMAIL'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
var listUsers = new Ext.form.FieldSet({
|
||||||
|
id : 'listUsers',
|
||||||
|
title : _('ID_USERS'),
|
||||||
|
hidden : true,
|
||||||
|
items : [
|
||||||
|
listViewUsers
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
var formPMGmail = new Ext.FormPanel({
|
||||||
|
title : ' ',
|
||||||
|
id :'formPMGmail',
|
||||||
|
labelWidth : 170,
|
||||||
|
labelAlign :'right',
|
||||||
|
autoScroll : true,
|
||||||
|
fileUpload : true,
|
||||||
|
bodyStyle :'padding:5px',
|
||||||
|
waitMsgTarget : true,
|
||||||
|
frame : true,
|
||||||
|
defaults: {
|
||||||
|
allowBlank: false,
|
||||||
|
msgTarget: 'side',
|
||||||
|
align:'center'
|
||||||
|
},
|
||||||
|
items:[ configurationPMGmail, testPMGmail, listUsers ],
|
||||||
|
buttons : [testButton, saveButton]
|
||||||
|
});
|
||||||
|
|
||||||
|
var viewport = new Ext.Viewport({
|
||||||
|
layout: 'fit',
|
||||||
|
autoScroll: false,
|
||||||
|
items: [
|
||||||
|
formPMGmail
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
Ext.getCmp('status_pmgmail').checked = enablePMGmail;
|
||||||
|
Ext.getCmp('status_pmgmail').setValue(enablePMGmail);
|
||||||
|
});
|
||||||
|
|
||||||
|
var testSettings = function ()
|
||||||
|
{
|
||||||
|
storeUsers.reload();
|
||||||
|
Ext.getCmp('testPMGmail').hide();
|
||||||
|
Ext.getCmp('listUsers').hide();
|
||||||
|
Ext.getCmp('currentUserName').setText('');
|
||||||
|
Ext.getCmp('rootFolderId').setText('');
|
||||||
|
Ext.getCmp('quotaType').setText('');
|
||||||
|
Ext.getCmp('quotaBytesTotal').setText('');
|
||||||
|
Ext.getCmp('quotaBytesUsed').setText('');
|
||||||
|
Ext.getCmp('responseGmailTest').setText('');
|
||||||
|
Ext.getCmp('responseGmailTest').container.dom.style.color = 'red';
|
||||||
|
|
||||||
|
Ext.getCmp('formPMGmail').getForm().submit( {
|
||||||
|
url : '../pmGmail/testConfigPmGmail',
|
||||||
|
waitMsg : _('ID_TEST_CONNECTION'),
|
||||||
|
waitTitle : " ",
|
||||||
|
timeout : 36000,
|
||||||
|
success : function(obj, resp) {
|
||||||
|
Ext.getCmp('testPMGmail').show();
|
||||||
|
Ext.getCmp('listUsers').show();
|
||||||
|
var response = Ext.decode(resp.response.responseText);
|
||||||
|
Ext.getCmp('currentUserName').setText(response.currentUserName);
|
||||||
|
Ext.getCmp('rootFolderId').setText(response.rootFolderId);
|
||||||
|
Ext.getCmp('quotaType').setText(response.quotaType);
|
||||||
|
Ext.getCmp('quotaBytesTotal').setText(response.quotaBytesTotal);
|
||||||
|
Ext.getCmp('quotaBytesUsed').setText(response.quotaBytesUsed);
|
||||||
|
Ext.getCmp('responseGmailTest').setText(response.responseGmailTest);
|
||||||
|
|
||||||
|
Ext.getCmp('responseGmailTest').container.dom.style.color = 'green';
|
||||||
|
if (storeUsers.data.length == 0) {
|
||||||
|
saveButton.enable();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
failure: function(obj, resp) {
|
||||||
|
Ext.getCmp('testPMGmail').show();
|
||||||
|
Ext.getCmp('listUsers').hide();
|
||||||
|
saveButton.disable();
|
||||||
|
Ext.getCmp('responseGmailTest').setText(resp.result.responseGmailTest);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var saveSettings = function ()
|
||||||
|
{
|
||||||
|
Ext.getCmp('formPMGmail').getForm().submit( {
|
||||||
|
url : '../pmGmail/saveConfigPmGmail',
|
||||||
|
waitMsg : _('ID_SAVING_PROCESS'),
|
||||||
|
waitTitle : " ",
|
||||||
|
timeout : 36000,
|
||||||
|
success : function(obj, resp) {
|
||||||
|
var response = Ext.decode(resp.response.responseText);
|
||||||
|
parent.PMExt.notify(_('ID_INFO'),_('ID_SAVED_SUCCESSFULLY'));
|
||||||
|
location.href = '../pmGmail/formPMGmail';
|
||||||
|
},
|
||||||
|
failure: function(obj, resp) {
|
||||||
|
PMExt.error( _('ID_ERROR'), resp.result.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var changeSettings = function()
|
||||||
|
{
|
||||||
|
Ext.getCmp('testPMGmail').hide();
|
||||||
|
Ext.getCmp('listUsers').hide();
|
||||||
|
if (Ext.getCmp('status_pmgmail').checked) {
|
||||||
|
testButton.enable();
|
||||||
|
}
|
||||||
|
saveButton.disable();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user