Missed files
This commit is contained in:
294
workflow/engine/classes/DashletOpenVsCompleted.php
Normal file
294
workflow/engine/classes/DashletOpenVsCompleted.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DashletOpenVsCompleted implements DashletInterface
|
||||
{
|
||||
|
||||
const version = '1.0';
|
||||
|
||||
private $value;
|
||||
private $open;
|
||||
private $completed;
|
||||
private $centerLabel;
|
||||
private $redFrom;
|
||||
private $redTo;
|
||||
private $yellowFrom;
|
||||
private $yellowTo;
|
||||
private $greenFrom;
|
||||
private $greenTo;
|
||||
|
||||
public static function getAdditionalFields ($className)
|
||||
{
|
||||
$additionalFields = array ();
|
||||
|
||||
$contextTimeStore = new stdclass();
|
||||
$contextTimeStore->xtype = 'arraystore';
|
||||
$contextTimeStore->fields = array ('id','value'
|
||||
);
|
||||
$contextTimeStore->data = array (array ('TODAY', G::LoadTranslation('ID_TODAY')
|
||||
),array ('YESTERDAY', G::LoadTranslation('ID_YESTERDAY')
|
||||
),array ('THIS_WEEK', G::LoadTranslation('ID_THIS_WEEK')
|
||||
),array ('PREVIOUS_WEEK', G::LoadTranslation('ID_PREVIOUS_WEEK')
|
||||
),array ('THIS_MONTH', G::LoadTranslation('ID_THIS_MONTH')
|
||||
),array ('PREVIOUS_MONTH', G::LoadTranslation('ID_PREVIOUS_MONTH')
|
||||
),array ('THIS_YEAR', G::LoadTranslation('ID_THIS_YEAR')
|
||||
),array ('PREVIOUS_YEAR', G::LoadTranslation('ID_PREVIOUS_YEAR')
|
||||
)
|
||||
);
|
||||
|
||||
$contextTime = new stdclass();
|
||||
$contextTime->xtype = 'combo';
|
||||
$contextTime->name = 'DAS_INS_CONTEXT_TIME';
|
||||
$contextTime->fieldLabel = G::LoadTranslation( 'ID_PERIOD' );
|
||||
$contextTime->editable = false;
|
||||
$contextTime->width = 320;
|
||||
$contextTime->store = $contextTimeStore;
|
||||
$contextTime->mode = 'local';
|
||||
$contextTime->triggerAction = 'all';
|
||||
$contextTime->valueField = 'id';
|
||||
$contextTime->displayField = 'value';
|
||||
$contextTime->value = 'TODAY';
|
||||
$additionalFields[] = $contextTime;
|
||||
|
||||
$redFrom = new stdclass();
|
||||
$redFrom->xtype = 'numberfield';
|
||||
$redFrom->name = 'DAS_RED_FROM';
|
||||
$redFrom->fieldLabel = G::LoadTranslation( 'ID_RED_STARTS_IN' );
|
||||
$redFrom->width = 50;
|
||||
$redFrom->maxLength = 3;
|
||||
$redFrom->maxValue = 100;
|
||||
$redFrom->minValue = 0;
|
||||
$redFrom->allowBlank = false;
|
||||
$redFrom->value = 0;
|
||||
$additionalFields[] = $redFrom;
|
||||
|
||||
$redTo = new stdclass();
|
||||
$redTo->xtype = 'numberfield';
|
||||
$redTo->name = 'DAS_RED_TO';
|
||||
$redTo->fieldLabel = G::LoadTranslation( 'ID_RED_ENDS_IN' );
|
||||
$redTo->width = 50;
|
||||
$redTo->maxLength = 3;
|
||||
$redTo->maxValue = 100;
|
||||
$redTo->minValue = 0;
|
||||
$redTo->allowBlank = false;
|
||||
$redTo->value = 30;
|
||||
$additionalFields[] = $redTo;
|
||||
|
||||
$yellowFrom = new stdclass();
|
||||
$yellowFrom->xtype = 'numberfield';
|
||||
$yellowFrom->name = 'DAS_YELLOW_FROM';
|
||||
$yellowFrom->fieldLabel = G::LoadTranslation( 'ID_YELLOW_STARTS_IN' );
|
||||
$yellowFrom->width = 50;
|
||||
$yellowFrom->maxLength = 3;
|
||||
$yellowFrom->maxValue = 100;
|
||||
$yellowFrom->minValue = 0;
|
||||
$yellowFrom->allowBlank = false;
|
||||
$yellowFrom->value = 30;
|
||||
$additionalFields[] = $yellowFrom;
|
||||
|
||||
$yellowTo = new stdclass();
|
||||
$yellowTo->xtype = 'numberfield';
|
||||
$yellowTo->name = 'DAS_YELLOW_TO';
|
||||
$yellowTo->fieldLabel = G::LoadTranslation( 'ID_YELLOW_ENDS_IN' );
|
||||
$yellowTo->width = 50;
|
||||
$yellowTo->maxLength = 3;
|
||||
$yellowTo->maxValue = 100;
|
||||
$yellowTo->minValue = 0;
|
||||
$yellowTo->allowBlank = false;
|
||||
$yellowTo->value = 50;
|
||||
$additionalFields[] = $yellowTo;
|
||||
|
||||
$greenFrom = new stdclass();
|
||||
$greenFrom->xtype = 'numberfield';
|
||||
$greenFrom->name = 'DAS_GREEN_FROM';
|
||||
$greenFrom->fieldLabel = G::LoadTranslation( 'ID_GREEN_STARTS_IN' );
|
||||
$greenFrom->width = 50;
|
||||
$greenFrom->maxLength = 3;
|
||||
$greenFrom->maxValue = 100;
|
||||
$greenFrom->minValue = 0;
|
||||
$greenFrom->allowBlank = false;
|
||||
$greenFrom->value = 50;
|
||||
$additionalFields[] = $greenFrom;
|
||||
|
||||
$greenTo = new stdclass();
|
||||
$greenTo->xtype = 'numberfield';
|
||||
$greenTo->name = 'DAS_GREEN_TO';
|
||||
$greenTo->fieldLabel = G::LoadTranslation( 'ID_GREEN_ENDS_IN' );
|
||||
$greenTo->width = 50;
|
||||
$greenTo->maxLength = 3;
|
||||
$greenTo->maxValue = 100;
|
||||
$greenTo->minValue = 0;
|
||||
$greenTo->allowBlank = false;
|
||||
$greenTo->value = 100;
|
||||
$additionalFields[] = $greenTo;
|
||||
|
||||
return $additionalFields;
|
||||
}
|
||||
|
||||
public static function getXTemplate ($className)
|
||||
{
|
||||
return "<img src='{page}?w={width}&r={random}&DAS_INS_UID={id}'>";
|
||||
}
|
||||
|
||||
public function setup ($config)
|
||||
{
|
||||
$this->redFrom = isset( $config['DAS_RED_FROM'] ) ? (int) $config['DAS_RED_FROM'] : 0;
|
||||
$this->redTo = isset( $config['DAS_RED_TO'] ) ? (int) $config['DAS_RED_TO'] : 30;
|
||||
$this->yellowFrom = isset( $config['DAS_YELLOW_FROM'] ) ? (int) $config['DAS_YELLOW_FROM'] : 30;
|
||||
$this->yellowTo = isset( $config['DAS_YELLOW_TO'] ) ? (int) $config['DAS_YELLOW_TO'] : 50;
|
||||
$this->greenFrom = isset( $config['DAS_GREEN_FROM'] ) ? (int) $config['DAS_GREEN_FROM'] : 50;
|
||||
$this->greenTo = isset( $config['DAS_GREEN_TO'] ) ? (int) $config['DAS_GREEN_TO'] : 100;
|
||||
|
||||
$thisYear = date( 'Y' );
|
||||
$lastYear = $thisYear - 1;
|
||||
$thisMonth = date( 'M' );
|
||||
$lastMonth = date( 'M', strtotime( "31 days ago" ) );
|
||||
|
||||
$todayIni = date( 'Y-m-d H:i:s', strtotime( "today 00:00:00" ) );
|
||||
$todayEnd = date( 'Y-m-d H:i:s', strtotime( "today 23:59:59" ) );
|
||||
$yesterdayIni = date( 'Y-m-d H:i:s', strtotime( "yesterday 00:00:00" ) );
|
||||
$yesterdayEnd = date( 'Y-m-d H:i:s', strtotime( "yesterday 23:59:59" ) );
|
||||
$thisWeekIni = date( 'Y-m-d H:i:s', strtotime( "monday 00:00:00" ) );
|
||||
$thisWeekEnd = date( 'Y-m-d H:i:s', strtotime( "sunday 23:59:59" ) );
|
||||
$previousWeekIni = date( 'Y-m-d H:i:s', strtotime( "last monday 00:00:00" ) );
|
||||
$previousWeekEnd = date( 'Y-m-d H:i:s', strtotime( "last sunday 23:59:59" ) );
|
||||
|
||||
$thisMonthIni = date( 'Y-m-d H:i:s', strtotime( "$thisMonth 1st 00:00:00" ) );
|
||||
$thisMonthEnd = date( 'Y-m-d H:i:s', strtotime( "$thisMonth last day 23:59:59" ) );
|
||||
|
||||
$previousMonthIni = date( 'Y-m-d H:i:s', strtotime( "$lastMonth 1st 00:00:00" ) );
|
||||
$previousMonthEnd = date( 'Y-m-d H:i:s', strtotime( "$lastMonth last day 23:59:59" ) );
|
||||
|
||||
$thisYearIni = date( 'Y-m-d H:i:s', strtotime( "jan $thisYear 00:00:00" ) );
|
||||
$thisYearEnd = date( 'Y-m-d H:i:s', strtotime( "Dec 31 $thisYear 23:59:59" ) );
|
||||
$previousYearIni = date( 'Y-m-d H:i:s', strtotime( "jan $lastYear 00:00:00" ) );
|
||||
$previousYearEnd = date( 'Y-m-d H:i:s', strtotime( "Dec 31 $lastYear 23:59:59" ) );
|
||||
|
||||
if (! isset( $config['DAS_INS_CONTEXT_TIME'] )) {
|
||||
$config['DAS_INS_CONTEXT_TIME'] = 'TODAY';
|
||||
}
|
||||
|
||||
switch ($config['DAS_INS_CONTEXT_TIME']) {
|
||||
case 'TODAY':
|
||||
$dateIni = $todayIni;
|
||||
$dateEnd = $todayEnd;
|
||||
break;
|
||||
case 'YESTERDAY':
|
||||
$dateIni = $yesterdayIni;
|
||||
$dateEnd = $yesterdayEnd;
|
||||
break;
|
||||
case 'THIS_WEEK':
|
||||
$dateIni = $thisWeekIni;
|
||||
$dateEnd = $thisWeekEnd;
|
||||
break;
|
||||
case 'PREVIOUS_WEEK':
|
||||
$dateIni = $previousWeekIni;
|
||||
$dateEnd = $previousWeekEnd;
|
||||
break;
|
||||
case 'THIS_MONTH':
|
||||
$dateIni = $todayIni;
|
||||
$dateEnd = $todayEnd;
|
||||
break;
|
||||
case 'PREVIOUS_MONTH':
|
||||
$dateIni = $todayIni;
|
||||
$dateEnd = $todayEnd;
|
||||
break;
|
||||
case 'THIS_QUARTER':
|
||||
$dateIni = $todayIni;
|
||||
$dateEnd = $todayEnd;
|
||||
break;
|
||||
case 'PREVIOUS_QUARTER':
|
||||
$dateIni = $todayIni;
|
||||
$dateEnd = $todayEnd;
|
||||
break;
|
||||
case 'THIS_YEAR':
|
||||
$dateIni = $thisYearIni;
|
||||
$dateEnd = $thisYearEnd;
|
||||
break;
|
||||
case 'PREVIOUS_YEAR':
|
||||
$dateIni = $previousYearIni;
|
||||
$dateEnd = $previousYearEnd;
|
||||
break;
|
||||
}
|
||||
|
||||
$con = Propel::getConnection( "workflow" );
|
||||
$stmt = $con->createStatement();
|
||||
$sql = "select count(*) as CANT from APPLICATION where APP_STATUS in ( 'DRAFT', 'TO_DO' ) ";
|
||||
$sql .= "and APP_CREATE_DATE > '$dateIni' and APP_CREATE_DATE <= '$dateEnd' ";
|
||||
$rs = $stmt->executeQuery( $sql, ResultSet::FETCHMODE_ASSOC );
|
||||
$rs->next();
|
||||
$row = $rs->getRow();
|
||||
$casesTodo = $row['CANT'];
|
||||
|
||||
$stmt = $con->createStatement();
|
||||
$sql = "select count(*) as CANT from APPLICATION where APP_STATUS = 'COMPLETED' ";
|
||||
$sql .= "and APP_CREATE_DATE > '$dateIni' and APP_CREATE_DATE <= '$dateEnd' ";
|
||||
$rs = $stmt->executeQuery( $sql, ResultSet::FETCHMODE_ASSOC );
|
||||
$rs->next();
|
||||
$row = $rs->getRow();
|
||||
$casesCompleted = $row['CANT'];
|
||||
if ($casesCompleted + $casesTodo != 0) {
|
||||
$this->value = $casesCompleted / ($casesCompleted + $casesTodo) * 100;
|
||||
} else {
|
||||
$this->value = 0;
|
||||
}
|
||||
$this->open = $casesCompleted;
|
||||
$this->completed = $casesCompleted + $casesTodo;
|
||||
switch ($config['DAS_INS_CONTEXT_TIME']) {
|
||||
case 'TODAY':
|
||||
$this->centerLabel = G::LoadTranslation('ID_TODAY');
|
||||
break;
|
||||
case 'YESTERDAY':
|
||||
$this->centerLabel = G::LoadTranslation('ID_YESTERDAY');
|
||||
break;
|
||||
case 'THIS_WEEK':
|
||||
$this->centerLabel = G::LoadTranslation('ID_THIS_WEEK');
|
||||
break;
|
||||
case 'PREVIOUS_WEEK':
|
||||
$this->centerLabel = G::LoadTranslation('ID_PREVIOUS_WEEK');
|
||||
break;
|
||||
case 'THIS_MONTH':
|
||||
$this->centerLabel = G::LoadTranslation('ID_THIS_MONTH');
|
||||
break;
|
||||
case 'PREVIOUS_MONTH':
|
||||
$this->centerLabel = G::LoadTranslation('ID_PREVIOUS_MONTH');
|
||||
break;
|
||||
case 'THIS_QUARTER':
|
||||
$this->centerLabel = G::LoadTranslation('ID_THIS_QUARTER');
|
||||
break;
|
||||
case 'PREVIOUS_QUARTER':
|
||||
$this->centerLabel = G::LoadTranslation('ID_PREVIOUS_QUARTER');
|
||||
break;
|
||||
case 'THIS_YEAR':
|
||||
$this->centerLabel = G::LoadTranslation('ID_THIS_YEAR');
|
||||
break;
|
||||
case 'PREVIOUS_YEAR':
|
||||
$this->centerLabel = G::LoadTranslation('ID_PREVIOUS_YEAR');
|
||||
break;
|
||||
default:
|
||||
$this->centerLabel = '';
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function render ($width = 300)
|
||||
{
|
||||
$g = new pmGauge();
|
||||
$g->w = $width;
|
||||
$g->value = $this->value;
|
||||
|
||||
$g->redFrom = $this->redFrom;
|
||||
$g->redTo = $this->redTo;
|
||||
$g->yellowFrom = $this->yellowFrom;
|
||||
$g->yellowTo = $this->yellowTo;
|
||||
$g->greenFrom = $this->greenFrom;
|
||||
$g->greenTo = $this->greenTo;
|
||||
|
||||
$g->centerLabel = $this->centerLabel;
|
||||
$g->open = $this->open;
|
||||
$g->completed = $this->completed;
|
||||
$g->render();
|
||||
}
|
||||
|
||||
}
|
||||
402
workflow/engine/classes/PmDashlet.php
Normal file
402
workflow/engine/classes/PmDashlet.php
Normal file
File diff suppressed because it is too large
Load Diff
268
workflow/engine/classes/PmDrive.php
Normal file
268
workflow/engine/classes/PmDrive.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?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(static::DRIVE);
|
||||
$this->setScope(static::DRIVE_FILE);
|
||||
$this->setScope(static::DRIVE_READONLY);
|
||||
$this->setScope(static::DRIVE_METADATA);
|
||||
$this->setScope(static::DRIVE_METADATA_READONLY);
|
||||
$this->setScope(static::DRIVE_APPDATA);
|
||||
|
||||
$service = $this->serviceDrive();
|
||||
|
||||
try {
|
||||
$rows = array();
|
||||
$parameters['q'] = "'" . $fileId . "' in parents and trashed = false";
|
||||
$parents = $service->files->listFiles($parameters);
|
||||
|
||||
foreach ($parents->getItems() as $parent) {
|
||||
$rows = $parent;
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(static::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);
|
||||
} catch (Exception $e) {
|
||||
$createdFolder = null;
|
||||
error_log ( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $createdFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->setScope(static::DRIVE_FILE);
|
||||
|
||||
$service = $this->serviceDrive();
|
||||
|
||||
$file = new Google_Service_Drive_DriveFile();
|
||||
$file->setMimeType($mime);
|
||||
$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'
|
||||
)
|
||||
);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $createdFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->setScope(static::DRIVE);
|
||||
$this->setScope(static::DRIVE_APPDATA);
|
||||
$this->setScope(static::DRIVE_APPS_READONLY);
|
||||
$this->setScope(static::DRIVE_FILE);
|
||||
$this->setScope(static::DRIVE_METADATA);
|
||||
$this->setScope(static::DRIVE_METADATA_READONLY);
|
||||
$this->setScope(static::DRIVE_READONLY);
|
||||
$service = $this->serviceDrive();
|
||||
$response = null;
|
||||
|
||||
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) {
|
||||
$response = $httpRequest->getResponseBody();
|
||||
} else {
|
||||
error_log(G::LoadTranslation("ID_MSG_AJAX_FAILURE"));
|
||||
}
|
||||
} else {
|
||||
error_log(G::LoadTranslation("ID_PMDRIVE_NO_CONTENT_IN_FILE"));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(static::DRIVE);
|
||||
$this->setScope(static::DRIVE_FILE);
|
||||
|
||||
$service = $this->serviceDrive();
|
||||
$permission = null;
|
||||
|
||||
$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
|
||||
)
|
||||
);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log(G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $permission;
|
||||
}
|
||||
}
|
||||
245
workflow/engine/classes/PmGoogleApi.php
Normal file
245
workflow/engine/classes/PmGoogleApi.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?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.php
|
||||
*
|
||||
*/class PmGoogleApi
|
||||
{
|
||||
const DRIVE = 'https://www.googleapis.com/auth/drive';
|
||||
const DRIVE_FILE = 'https://www.googleapis.com/auth/drive.file';
|
||||
const DRIVE_APPS_READONLY = 'https://www.googleapis.com/auth/drive.apps.readonly';
|
||||
const DRIVE_READONLY = 'https://www.googleapis.com/auth/drive.readonly';
|
||||
const DRIVE_METADATA = 'https://www.googleapis.com/auth/drive.metadata';
|
||||
const DRIVE_METADATA_READONLY = 'https://www.googleapis.com/auth/drive.metadata.readonly';
|
||||
const DRIVE_APPDATA = 'https://www.googleapis.com/auth/drive.appdata';
|
||||
const DRIVE_PHOTOS_READONLY = 'https://www.googleapis.com/auth/drive.photos.readonly';
|
||||
const GMAIL_MODIFY = 'https://www.googleapis.com/auth/gmail.modify';
|
||||
|
||||
private $scope = array();
|
||||
private $serviceAccountEmail;
|
||||
private $serviceAccountCertificate;
|
||||
private $user;
|
||||
private $serviceGmailStatus = false;
|
||||
private $serviceDriveStatus = false;
|
||||
private $configuration;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$licensedFeatures = &PMLicensedFeatures::getSingleton();
|
||||
if (!($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09') || $licensedFeatures->verifyfeature('AhKNjBEVXZlWUFpWE8wVTREQ0FObmo0aTdhVzhvalFic1M='))) {
|
||||
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 getConfigGmail()
|
||||
{
|
||||
$this->configuration = new Configurations();
|
||||
$this->configuration->loadConfig($gmail, 'GOOGLE_API_SETTINGS', '');
|
||||
}
|
||||
|
||||
public function setConfigGmail ($id, $value)
|
||||
{
|
||||
$this->configuration->aConfig[$id] = $value;
|
||||
$this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', '');
|
||||
}
|
||||
|
||||
public function setServiceAccountEmail($serviceAccountEmail)
|
||||
{
|
||||
$this->setConfigGmail('serviceAccountEmail', $serviceAccountEmail);
|
||||
$this->serviceAccountEmail = $serviceAccountEmail;
|
||||
}
|
||||
|
||||
public function getServiceAccountEmail()
|
||||
{
|
||||
return $this->serviceAccountEmail;
|
||||
}
|
||||
|
||||
public function setServiceAccountCertificate ($serviceAccountCertificate)
|
||||
{
|
||||
$this->setConfigGmail('serviceAccountCertificate', $serviceAccountCertificate);
|
||||
$this->serviceAccountCertificate = $serviceAccountCertificate;
|
||||
}
|
||||
|
||||
public function getServiceAccountCertificate()
|
||||
{
|
||||
return $this->serviceAccountCertificate;
|
||||
}
|
||||
|
||||
public function setServiceGmailStatus($status)
|
||||
{
|
||||
$licensedFeatures = &PMLicensedFeatures::getSingleton();
|
||||
if (!$licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
|
||||
$status = false;
|
||||
}
|
||||
$this->setConfigGmail('serviceGmailStatus', $status);
|
||||
$this->serviceGmailStatus = $status;
|
||||
}
|
||||
|
||||
public function getServiceGmailStatus()
|
||||
{
|
||||
return $this->serviceGmailStatus;
|
||||
}
|
||||
|
||||
public function setServiceDriveStatus($status)
|
||||
{
|
||||
$licensedFeatures = &PMLicensedFeatures::getSingleton();
|
||||
if (!$licensedFeatures->verifyfeature('AhKNjBEVXZlWUFpWE8wVTREQ0FObmo0aTdhVzhvalFic1M=')) {
|
||||
$status = false;
|
||||
}
|
||||
$this->setConfigGmail('serviceDriveStatus', $status);
|
||||
$this->serviceDriveStatus = $status;
|
||||
}
|
||||
|
||||
public function getServiceDriveStatus()
|
||||
{
|
||||
return $this->serviceDriveStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* load configuration gmail service account
|
||||
*
|
||||
*/
|
||||
public function loadSettings()
|
||||
{
|
||||
$this->getConfigGmail();
|
||||
|
||||
$serviceAccountCertificate = empty($this->configuration->aConfig['serviceAccountCertificate']) ? '' : $this->configuration->aConfig['serviceAccountCertificate'];
|
||||
$serviceAccountEmail = empty($this->configuration->aConfig['serviceAccountEmail']) ? '' : $this->configuration->aConfig['serviceAccountEmail'];
|
||||
$serviceGmailStatus = empty($this->configuration->aConfig['serviceGmailStatus']) ? false : $this->configuration->aConfig['serviceGmailStatus'];
|
||||
$serviceDriveStatus = empty($this->configuration->aConfig['serviceDriveStatus']) ? false : $this->configuration->aConfig['serviceDriveStatus'];
|
||||
|
||||
$this->scope = array();
|
||||
|
||||
$this->serviceAccountEmail = $serviceAccountEmail;
|
||||
$this->serviceAccountCertificate = $serviceAccountCertificate;
|
||||
$this->serviceGmailStatus = $serviceGmailStatus;
|
||||
$this->serviceDriveStatus = $serviceDriveStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* New service client - Authentication google Api
|
||||
*
|
||||
* @return Google_Service_Client $service API service instance.
|
||||
*/
|
||||
public function serviceClient()
|
||||
{
|
||||
$client = null;
|
||||
if (file_exists(PATH_DATA_SITE . $this->serviceAccountCertificate)) {
|
||||
$key = file_get_contents(PATH_DATA_SITE . $this->serviceAccountCertificate);
|
||||
} else {
|
||||
throw new Exception(G::LoadTranslation('ID_GOOGLE_CERTIFICATE_ERROR'));
|
||||
}
|
||||
|
||||
$data = json_decode($key);
|
||||
$assertionCredentials = new Google_Auth_AssertionCredentials(
|
||||
$this->serviceAccountEmail,
|
||||
$this->scope,
|
||||
$data->private_key
|
||||
);
|
||||
|
||||
$assertionCredentials->sub = $this->user;
|
||||
|
||||
$client = new Google_Client();
|
||||
$client->setApplicationName("PMDrive");
|
||||
$client->setAssertionCredentials($assertionCredentials);
|
||||
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* New service client - Authentication google Api
|
||||
*
|
||||
* @param $credentials
|
||||
* @throws \Exception
|
||||
* @return \StdClass response.
|
||||
*/
|
||||
public function testService($credentials)
|
||||
{
|
||||
|
||||
$scope = array(
|
||||
static::DRIVE,
|
||||
static::DRIVE_FILE,
|
||||
static::DRIVE_READONLY,
|
||||
static::DRIVE_METADATA,
|
||||
static::DRIVE_METADATA_READONLY,
|
||||
static::DRIVE_APPDATA,
|
||||
static::DRIVE_PHOTOS_READONLY
|
||||
);
|
||||
|
||||
if (file_exists($credentials->pathServiceAccountCertificate)) {
|
||||
$key = file_get_contents($credentials->pathServiceAccountCertificate);
|
||||
} else {
|
||||
throw new Exception(G::LoadTranslation('ID_GOOGLE_CERTIFICATE_ERROR'));
|
||||
}
|
||||
$data = json_decode($key);
|
||||
$assertionCredentials = new Google_Auth_AssertionCredentials(
|
||||
$credentials->emailServiceAccount,
|
||||
$scope,
|
||||
$data->private_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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user