@@ -4218,6 +4218,19 @@ class Cases
|
||||
$oListPaused = new ListPaused();
|
||||
$oListPaused->create($data);
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$licensedFeatures = &PMLicensedFeatures::getSingleton();
|
||||
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
|
||||
G::LoadClass( "pmDrive" );
|
||||
$pmDrive = new PMDrive();
|
||||
$enablePMGmail = $pmDrive->getStatusService();
|
||||
if (!empty($enablePMGmail) && $enablePMGmail == 1) {
|
||||
$pmGmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
||||
$pmGmail->modifyMailToPauseCase($aData['APP_UID'], $aData['APP_DEL_INDEX']);
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4314,6 +4327,19 @@ class Cases
|
||||
$oListPaused = new ListPaused();
|
||||
$oListPaused->remove($sApplicationUID, $iDelegation, $aData);
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$licensedFeatures = &PMLicensedFeatures::getSingleton();
|
||||
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
|
||||
G::LoadClass( "pmDrive" );
|
||||
$pmDrive = new PMDrive();
|
||||
$enablePMGmail = $pmDrive->getStatusService();
|
||||
if (!empty($enablePMGmail) && $enablePMGmail == 1) {
|
||||
$pmGmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
||||
$pmGmail->modifyMailToUnpauseCase($aData['APP_UID'], $aData['DEL_INDEX']);
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -7371,5 +7397,6 @@ class Cases
|
||||
}
|
||||
return $processList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class labelsGmail
|
||||
$labels = array_merge($labels, $labelsResponse->getLabels());
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
print 'An error occurred: ' . $e->getMessage();
|
||||
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage();
|
||||
}
|
||||
return $labels;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class labelsGmail
|
||||
try {
|
||||
$message = $service->users_messages->modify($userId, $messageId, $mods);
|
||||
} catch (Exception $e) {
|
||||
print 'An error occurred: ' . $e->getMessage();
|
||||
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +62,116 @@ class labelsGmail
|
||||
$messages = array_merge($messages, $messagesResponse->getMessages());
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
print 'An error occurred: ' . $e->getMessage();
|
||||
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage();
|
||||
}
|
||||
} while ($pageToken);
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
function setLabels($caseId, $index, $actualLastIndex, $unassigned=false){
|
||||
public function setLabelsToPauseCase ($caseId, $index) {
|
||||
require_once PATH_TRUNK . 'vendor' . PATH_SEP . 'google' . PATH_SEP . 'apiclient' . PATH_SEP . 'src' . PATH_SEP . 'Google' . PATH_SEP . 'autoload.php';
|
||||
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.pmGoogleApi.php");
|
||||
|
||||
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
||||
$appData = $Pmgmail->getDraftApp($caseId, $index);
|
||||
|
||||
foreach ($appData as $application){
|
||||
$appNumber = $application['APP_NUMBER'];
|
||||
$index = $application['DEL_INDEX'];
|
||||
$threadUsr = $application['USR_UID'];
|
||||
$proName = $application['APP_PRO_TITLE'];
|
||||
$threadStatus = $application['DEL_THREAD_STATUS'];
|
||||
$appStatus = $application['APP_STATUS'];
|
||||
}
|
||||
|
||||
//Getting the privious User email
|
||||
$oUsers = new \Users();
|
||||
$usrData = $oUsers->loadDetails($threadUsr);
|
||||
$mail = $usrData['USR_EMAIL'];
|
||||
|
||||
//The Subject to search the email
|
||||
$subject = "[PM] " .$proName. " Case: ". $appNumber;
|
||||
|
||||
$pmGoogle = new PMGoogleApi();
|
||||
$pmGoogle->setUser($mail);
|
||||
$pmGoogle->setScope('https://www.googleapis.com/auth/gmail.modify');
|
||||
$client = $pmGoogle->serviceClient();
|
||||
$service = new Google_Service_Gmail($client);
|
||||
$labelsIds = $this->getLabelsIds($service);
|
||||
|
||||
if($appStatus == 'DRAFT'){
|
||||
$labelsToRemove = $labelsIds['Draft'];
|
||||
$labelsToSearch = "*-draft";
|
||||
$labelsToAdd = $labelsIds['Paused'];
|
||||
}
|
||||
|
||||
if($appStatus == 'TO_DO'){
|
||||
$labelsToRemove = $labelsIds['Inbox'];
|
||||
$labelsToSearch = "*-inbox";
|
||||
$labelsToAdd = $labelsIds['Paused'];
|
||||
}
|
||||
|
||||
$q = "subject:('".preg_quote($subject, '-')."') label:('".$labelsToSearch."')";
|
||||
$messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
|
||||
foreach ($messageList as $message) {
|
||||
$messageId = $message->getId();
|
||||
$modifyResult = $this->modifyMessage($service, $mail, $messageId, array($labelsToAdd), array($labelsToRemove));
|
||||
}
|
||||
}
|
||||
|
||||
function setLabelsTounpauseCase ($caseId, $index) {
|
||||
require_once PATH_TRUNK . 'vendor' . PATH_SEP . 'google' . PATH_SEP . 'apiclient' . PATH_SEP . 'src' . PATH_SEP . 'Google' . PATH_SEP . 'autoload.php';
|
||||
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.pmGoogleApi.php");
|
||||
|
||||
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
||||
$appData = $Pmgmail->getDraftApp($caseId, $index);
|
||||
|
||||
foreach ($appData as $application){
|
||||
$appNumber = $application['APP_NUMBER'];
|
||||
$index = $application['DEL_INDEX'];
|
||||
$threadUsr = $application['USR_UID'];
|
||||
$proName = $application['APP_PRO_TITLE'];
|
||||
$threadStatus = $application['DEL_THREAD_STATUS'];
|
||||
$appStatus = $application['APP_STATUS'];
|
||||
}
|
||||
|
||||
//Getting the privious User email
|
||||
$oUsers = new \Users();
|
||||
$usrData = $oUsers->loadDetails($threadUsr);
|
||||
$mail = $usrData['USR_EMAIL'];
|
||||
|
||||
//The Subject to search the email
|
||||
$subject = "[PM] " .$proName. " Case: ". $appNumber;
|
||||
|
||||
$pmGoogle = new PMGoogleApi();
|
||||
$pmGoogle->setUser($mail);
|
||||
$pmGoogle->setScope('https://www.googleapis.com/auth/gmail.modify');
|
||||
$client = $pmGoogle->serviceClient();
|
||||
$service = new Google_Service_Gmail($client);
|
||||
$labelsIds = $this->getLabelsIds($service);
|
||||
|
||||
if($appStatus == 'DRAFT'){
|
||||
$labelsToRemove = $labelsIds['Paused'];
|
||||
$labelsToSearch = "*-paused";
|
||||
$labelsToAdd = $labelsIds['Draft'];
|
||||
}
|
||||
|
||||
if($appStatus == 'TO_DO'){
|
||||
$labelsToRemove = $labelsIds['Paused'];
|
||||
$labelsToSearch = "*-paused";
|
||||
$labelsToAdd = $labelsIds['Inbox'];
|
||||
}
|
||||
|
||||
$q = "subject:('".preg_quote($subject, '-')."') label:('".$labelsToSearch."')";
|
||||
$messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
|
||||
foreach ($messageList as $message) {
|
||||
$messageId = $message->getId();
|
||||
$modifyResult = $this->modifyMessage($service, $mail, $messageId, array($labelsToAdd), array($labelsToRemove));
|
||||
}
|
||||
}
|
||||
|
||||
public function setLabels($caseId, $index, $actualLastIndex, $unassigned=false){
|
||||
//First getting the actual thread data
|
||||
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
||||
$appData = $Pmgmail->getDraftApp($caseId, $index);
|
||||
@@ -80,9 +182,10 @@ class labelsGmail
|
||||
$threadUsr = $application['USR_UID'];
|
||||
$proName = $application['APP_PRO_TITLE'];
|
||||
$threadStatus = $application['DEL_THREAD_STATUS'];
|
||||
$appStatus = $application['APP_STATUS'];
|
||||
}
|
||||
|
||||
if($threadStatus == 'CLOSED' || $unassigned == true){
|
||||
if($threadStatus == 'CLOSED' || $unassigned == true) {
|
||||
//Getting the privious User email
|
||||
$oUsers = new \Users();
|
||||
|
||||
@@ -102,44 +205,20 @@ class labelsGmail
|
||||
$client = $pmGoogle->serviceClient();
|
||||
|
||||
$service = new Google_Service_Gmail($client);
|
||||
|
||||
//getting all the label's ids of the user's mail
|
||||
$listlabels = $this->listLabels($service);
|
||||
|
||||
foreach ($listlabels as $label) {
|
||||
$labId = $label->getId();
|
||||
$labName = $label->getName();
|
||||
switch($labName){
|
||||
case "* Inbox":
|
||||
$idLabInbox = $labId;
|
||||
break;
|
||||
case "* Participated":
|
||||
$idLabParticipated = $labId;
|
||||
break;
|
||||
case "* Unassigned":
|
||||
$idLabUnassigned = $labId;
|
||||
break;
|
||||
case "* Draft":
|
||||
$idLabDraft = $labId;
|
||||
break;
|
||||
case "* Paused":
|
||||
$idLabPaused = $labId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$labelsIds = $this->getLabelsIds($service);
|
||||
|
||||
if($actualLastIndex == 0){
|
||||
$labelsToRemove = $idLabDraft;
|
||||
$labelsToRemove = $labelsIds['Draft'];
|
||||
$labelsToSearch = "*-draft";
|
||||
$labelsToAdd = $idLabParticipated;
|
||||
$labelsToAdd = $labelsIds['Participated'];
|
||||
} else if ( ($actualLastIndex == -1) && ($unassigned == true) ){ //Unassigned
|
||||
$labelsToRemove = $idLabUnassigned;
|
||||
$labelsToRemove = $labelsIds['Unassigned'];
|
||||
$labelsToSearch = "*-unassigned";
|
||||
$labelsToAdd = $idLabInbox;
|
||||
$labelsToAdd = $labelsIds['Inbox'];
|
||||
} else if($actualLastIndex >= 1) {
|
||||
$labelsToRemove = $idLabInbox;
|
||||
$labelsToRemove = $labelsIds['Inbox'];
|
||||
$labelsToSearch = "*-inbox";
|
||||
$labelsToAdd = $idLabParticipated;
|
||||
$labelsToAdd = $labelsIds['Participated'];
|
||||
}
|
||||
|
||||
//Searching the email in the user's mail
|
||||
@@ -169,7 +248,7 @@ class labelsGmail
|
||||
try {
|
||||
$service->users_labels->delete($user, $labelId);
|
||||
} catch (Exception $e) {
|
||||
error_log('An error deleting gmail labels occurred: '.$e->getMessage());
|
||||
error_log(G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,5 +286,32 @@ class labelsGmail
|
||||
return $count . ' labels successfully deleted.';
|
||||
}
|
||||
|
||||
|
||||
private function getLabelsIds($service) {
|
||||
$result = array();
|
||||
$listlabels = $this->listLabels($service);
|
||||
foreach ($listlabels as $label) {
|
||||
$labId = $label->getId();
|
||||
$labName = $label->getName();
|
||||
switch($labName){
|
||||
case "* Inbox":
|
||||
$result['Inbox'] = $labId;
|
||||
break;
|
||||
case "* Participated":
|
||||
$result['Participated'] = $labId;
|
||||
break;
|
||||
case "* Unassigned":
|
||||
$result['Unassigned'] = $labId;
|
||||
break;
|
||||
case "* Draft":
|
||||
$result['Draft'] = $labId;
|
||||
break;
|
||||
case "* Paused":
|
||||
$result['Paused'] = $labId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ class PMDrive extends PMGoogleApi
|
||||
$createdFolder = $service->files->insert($file);
|
||||
} catch (Exception $e) {
|
||||
$createdFolder = null;
|
||||
error_log ( "An error occurred: " . $e->getMessage());
|
||||
error_log ( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $createdFolder;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class PMDrive extends PMGoogleApi
|
||||
);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log( "An error occurred: " . $e->getMessage());
|
||||
error_log( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $createdFile;
|
||||
}
|
||||
@@ -220,13 +220,13 @@ class PMDrive extends PMGoogleApi
|
||||
if ($httpRequest->getResponseHttpCode() == 200) {
|
||||
$response = $httpRequest->getResponseBody();
|
||||
} else {
|
||||
error_log( "An error occurred. ");
|
||||
error_log(G::LoadTranslation("ID_MSG_AJAX_FAILURE"));
|
||||
}
|
||||
} else {
|
||||
error_log( "The file doesn't have any content stored on Drive.");
|
||||
error_log(G::LoadTranslation("ID_PMDRIVE_NO_CONTENT_IN_FILE"));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log( "An error occurred: " . $e->getMessage());
|
||||
error_log( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
@@ -262,7 +262,7 @@ class PMDrive extends PMGoogleApi
|
||||
);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log('permission error: ' . $e->getMessage());
|
||||
error_log(G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
|
||||
}
|
||||
return $permission;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user