loadByUserEmailInArray($usr_gmail); //getting the skin require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.system.php"); $sysConf = new \System(); $responseSysConfig = $sysConf->getSystemConfiguration( PATH_CONFIG . 'env.ini' ); $response['enviroment'] = $responseSysConfig['default_skin']; return $response; } /** * Get Application data by appUid * * @param string $app_uid Unique id of the app * @param string $index * * return row app_cache_view * */ public function getDraftApp($app_uid, $index=1) { $c = new \Criteria( 'workflow' ); $c->clearSelectColumns(); $c->addSelectColumn( \AppCacheViewPeer::APP_NUMBER ); $c->addSelectColumn( \AppCacheViewPeer::APP_STATUS ); $c->addSelectColumn( \AppCacheViewPeer::DEL_INDEX ); $c->addSelectColumn( \AppCacheViewPeer::APP_DEL_PREVIOUS_USER ); $c->addSelectColumn( \AppCacheViewPeer::DEL_DELEGATE_DATE ); $c->addSelectColumn( \AppCacheViewPeer::USR_UID ); $c->addSelectColumn( \AppCacheViewPeer::PRO_UID ); $c->addSelectColumn( \AppCacheViewPeer::APP_PRO_TITLE ); $c->addSelectColumn( \AppCacheViewPeer::APP_TAS_TITLE ); $c->addSelectColumn( \AppCacheViewPeer::DEL_THREAD_STATUS ); $c->addSelectColumn( \AppCacheViewPeer::TAS_UID ); $c->addSelectColumn( \AppCacheViewPeer::DEL_LAST_INDEX ); $c->addSelectColumn( \AppCacheViewPeer::APP_UID ); $c->add( \AppCacheViewPeer::APP_UID, $app_uid ); $c->add( \AppCacheViewPeer::DEL_INDEX, $index ); $rs = \AppCacheViewPeer::doSelectRS( $c ); $rs->setFetchmode( \ResultSet::FETCHMODE_ASSOC ); $rows = Array (); while ($rs->next()) { $rows[] = $rs->getRow(); } return $rows; } public function gmailsForRouting($sUsrUid, $sTasUid, $sAppUid, $delIndex, $isSubprocess) { $taskProxy = new \Task(); $taskData = $taskProxy-> load($sTasUid); //guard condition, message events do not need to send emails if ($taskData['TAS_TYPE'] === 'START-MESSAGE-EVENT') { return; } if($sUsrUid === "") { $targetEmails = $this->targetEmailsForUnassigned($sTasUid, $sAppUid); if ($targetEmails['to'] !== "" && $targetEmails['to'] !== null ) { $this->sendGmail($sAppUid, $targetEmails['to'].','.$targetEmails['cc'], $delIndex, $isSubprocess, true, null, null); } } else { $userObject = new \Users(); $userData = $userObject->loadDetails($sUsrUid); if ($userData !== null) { $this->sendGmail($sAppUid, $userData['USR_EMAIL'], $delIndex, $isSubprocess, false, null, null); } } } public function gmailsIfSelfServiceValueBased($app_uid, $index, $arrayTask, $arrayData) { require_once(PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Application.php"); $resultMail = ""; foreach ($arrayTask as $aTask) { //just self service tasks are processed in this function if ($aTask ["TAS_ASSIGN_TYPE"] !== "SELF_SERVICE") { continue; } $appData = $this->getDraftApp($app_uid, $index); if (count($appData) === 0) { return "appUid not found"; } if (!isset ($aTask ["USR_UID"])) { $aTask ["USR_UID"] = ""; } $application = $appData[0]; $labelID = "PMUASS"; $isSelfServiceValueBased = false; if ($aTask["TAS_ASSIGN_TYPE"] === "SELF_SERVICE") { $task = \TaskPeer::retrieveByPK($aTask["TAS_UID"]); if (trim($task->getTasGroupVariable()) != '') { $isSelfServiceValueBased = true; } } if ($isSelfServiceValueBased) { $mailToAddresses = ''; $mailCcAddresses = ''; $criteria = new \Criteria ("workflow"); $criteria->addSelectColumn(\AppAssignSelfServiceValuePeer::GRP_UID); $criteria->add(\AppAssignSelfServiceValuePeer::APP_UID, $app_uid); $criteria->add(\AppAssignSelfServiceValuePeer::DEL_INDEX, $aTask["DEL_INDEX"]); $rsCriteria = \AppAssignSelfServiceValuePeer::doSelectRs($criteria); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); while ($rsCriteria->next()) { $row = $rsCriteria->getRow(); } $targetIds = unserialize($row ['GRP_UID']); $usersToSend = $this->getSelfServiceValueBasedUsers($targetIds); foreach($usersToSend as $record) { $toAux = (($record['USR_FIRSTNAME'] != '' || $record['USR_LASTNAME'] != '') ? $record['USR_FIRSTNAME'] . ' ' . $record['USR_LASTNAME'] . ' ' : '') . '<' . $record['USR_EMAIL'] . '>'; if ($mailToAddresses == '') { $mailToAddresses = $toAux; } else { $mailCcAddresses .= (($mailCcAddresses != '')? ',' : '') . $toAux; } } $resultMail = $this->sendEmailWithApplicationData($application, $labelID, $mailToAddresses, $mailCcAddresses); } } return $resultMail; } /** * Send email using appUid and mail * * @param string $app_uid Unique id of the app * @param string $mail * * return uid * */ public function sendGmail($app_uid, $mailToAddresses, $index, $isSubprocess = false, $isSelfService = false, $arrayTask = null, $arrayData = null) { //getting the default email server $defaultEmail = $this->emailAccount(); if ($defaultEmail === null) { error_log(G::LoadTranslation('ID_EMAIL_ENGINE_IS_NOT_ENABLED')); return false; } $mailCcAddresses = ""; $appData = $this->getDraftApp($app_uid, $index); if (count($appData) === 0) { return; } $application = $appData[0]; $this->sendEmailWithApplicationData($application, $this->getEmailType($index, $isSubprocess, $isSelfService), $mailToAddresses, $mailCcAddresses); } /** * Get if the license has the feature * * return uid * */ public function hasGmailFeature() { require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.licensedFeatures.php"); $licensedFeatures = new \PMLicensedFeatures(); if (!$licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) { return false; }else { return true; } } /** * Get the default 'email from account' that is used to send emails in the server email in PM * * return uid * */ public function emailAccount() { $emailServer = new \EmailServer(); $response = $emailServer->loadDefaultAccount(); return $response['MESS_ACCOUNT']; } /** * Business Model to delete all the labels of an acount * * @param string $mail * * return uid * */ public function deleteLabels($mail) { require_once(PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.labelsGmail.php"); $oLabels = new \labelsGmail(); $response = $oLabels->deletePMGmailLabels($mail); return $response; } public function modifyMailToPauseCase($appUid, $appDelIndex) { require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.labelsGmail.php"); $oLabels = new \labelsGmail(); $oResponse = $oLabels->setLabelsToPauseCase($appUid, $appDelIndex); } public function modifyMailToUnpauseCase($appUid, $appDelIndex) { require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.labelsGmail.php"); $oLabels = new \labelsGmail(); $oResponse = $oLabels->setLabelsToUnpauseCase($appUid, $appDelIndex); } private function getEmailType($index, $isSubprocess, $isSelfService) { $retval = ""; if ($isSelfService) { $retval = "PMUASS"; } else { $retval = ($index === 1 && !$isSubprocess) ? "PMDRFT" : "PMIBX"; } if ($retval === "") { throw new Exception('Is not possible to determine the email type'); } return $retval; } private function createMailTemplateFile() { $pathTemplate = PATH_DATA_SITE . "mailTemplates" . PATH_SEP . "pmGmail.html"; if (!file_exists($pathTemplate)) { $file = @fopen($pathTemplate, "w"); fwrite($file, '