Ejemplo n.º 1
0
 /**
  * End Point to delete Labels in an uninstalation of the extension
  *
  * @param string $mail {@from path}
  *
  *
  * @url POST /deleteLabels/:mail
  *
  */
 public function doPostDeleteLabels($mail)
 {
     try {
         $Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
         $response = $Pmgmail->deleteLabels($mail);
         return $response;
     } catch (\Exception $e) {
         throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
     }
 }
Ejemplo n.º 2
0
 public function setLabels($caseId, $index, $actualLastIndex, $unassigned = false)
 {
     //First getting the actual thread data
     $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'];
     }
     if ($threadStatus == 'CLOSED' || $unassigned == true) {
         //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;
         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";
         $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 ($actualLastIndex == 0) {
             $labelsToRemove = $labelsIds['Draft'];
             $labelsToSearch = "*-draft";
             $labelsToAdd = $labelsIds['Participated'];
         } else {
             if ($actualLastIndex == -1 && $unassigned == true) {
                 //Unassigned
                 $labelsToRemove = $labelsIds['Unassigned'];
                 $labelsToSearch = "*-unassigned";
                 $labelsToAdd = $labelsIds['Inbox'];
             } else {
                 if ($actualLastIndex >= 1) {
                     $labelsToRemove = $labelsIds['Inbox'];
                     $labelsToSearch = "*-inbox";
                     $labelsToAdd = $labelsIds['Participated'];
                 }
             }
         }
         //Searching the email in the user's mail
         $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));
         }
     }
 }
Ejemplo n.º 3
0
    die;
}
$caseId = $_SESSION['APPLICATION'];
$usrUid = $_SESSION['USER_LOGGED'];
$usrName = $_SESSION['USR_FULLNAME'];
$actualIndex = $_SESSION['INDEX'];
$cont = 0;
use ProcessMaker\Services\Api;
$appDel = new AppDelegation();
$actualThread = $appDel->Load($caseId, $actualIndex);
$actualLastIndex = $actualThread['DEL_PREVIOUS'];
$appDelPrev = $appDel->LoadParallel($caseId);
if ($appDelPrev == array()) {
    $appDelPrev['0'] = $actualThread;
}
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
foreach ($appDelPrev as $app) {
    if ($app['DEL_INDEX'] != $actualIndex && $app['DEL_PREVIOUS'] != $actualLastIndex) {
        //Sending the email to all threads of the case except the actual thread
        $response = $Pmgmail->sendEmail($caseId, "", $app['DEL_INDEX']);
    }
}
require_once PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.labelsGmail.php";
$oLabels = new labelsGmail();
$oResponse = $oLabels->setLabels($caseId, $actualIndex, $actualLastIndex, false);
$enablePMGmail = false;
G::LoadClass("pmDrive");
$pmDrive = new PMDrive();
$enablePMGmail = $pmDrive->getStatusService();
if (key_exists('gmail', $_SESSION) && $_SESSION['gmail'] == 1 && !empty($enablePMGmail) && $enablePMGmail == 1) {
    $_SESSION['gmail'] = 0;