2015-11-09 11:01:11 -04:00
|
|
|
<?php
|
|
|
|
|
namespace ProcessMaker\BusinessModel;
|
|
|
|
|
|
|
|
|
|
use \G;
|
|
|
|
|
/**
|
|
|
|
|
* @copyright Colosa - Bolivia
|
|
|
|
|
*/
|
|
|
|
|
class Pmgmail {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get User by usrGmail
|
|
|
|
|
*
|
|
|
|
|
* @param string $usr_gmail Unique id of User
|
|
|
|
|
*
|
|
|
|
|
* return uid
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function getUserByEmail($usr_gmail)
|
|
|
|
|
{
|
2015-11-27 11:38:44 -04:00
|
|
|
//getting the user data
|
2015-11-09 11:01:11 -04:00
|
|
|
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Users.php");
|
|
|
|
|
$oUsers = new \Users();
|
2015-11-27 11:38:44 -04:00
|
|
|
$response['user'] = $oUsers->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'];
|
2015-11-09 11:01:11 -04:00
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-07 09:34:42 -04:00
|
|
|
* Get Application data by appUid
|
2015-11-09 11:01:11 -04:00
|
|
|
*
|
2015-12-07 09:34:42 -04:00
|
|
|
* @param string $app_uid Unique id of the app
|
2015-11-09 11:01:11 -04:00
|
|
|
* @param string $index
|
|
|
|
|
*
|
2015-12-07 09:34:42 -04:00
|
|
|
* return row app_cache_view
|
2015-11-09 11:01:11 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2015-12-07 09:34:42 -04:00
|
|
|
public function getDraftApp($app_uid, $index=1)
|
2015-11-09 11:01:11 -04:00
|
|
|
{
|
2015-12-07 09:34:42 -04:00
|
|
|
$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->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;
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send email using appUid and mail
|
|
|
|
|
*
|
|
|
|
|
* @param string $app_uid Unique id of the app
|
|
|
|
|
* @param string $mail
|
|
|
|
|
*
|
|
|
|
|
* return uid
|
|
|
|
|
*
|
|
|
|
|
*/
|
2016-03-08 10:17:03 -04:00
|
|
|
public function sendEmail($app_uid, $mailToAddresses, $index, $arrayTask = null, $arrayData = null)
|
2015-11-09 11:01:11 -04:00
|
|
|
{
|
2016-03-23 19:16:08 -04:00
|
|
|
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Application.php");
|
2016-03-15 17:31:34 -04:00
|
|
|
//getting the default email server
|
|
|
|
|
$defaultEmail = $this->emailAccount();
|
|
|
|
|
|
|
|
|
|
if ($defaultEmail === null) {
|
|
|
|
|
error_log(G::LoadTranslation('ID_EMAIL_ENGINE_IS_NOT_ENABLED'));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$mailCcAddresses = "";
|
2015-11-09 11:01:11 -04:00
|
|
|
$oApplication = new \Application();
|
|
|
|
|
$formData = $oApplication->Load($app_uid);
|
|
|
|
|
|
|
|
|
|
$frmData = unserialize($formData['APP_DATA']);
|
|
|
|
|
$dataFormToShowString = "";
|
2016-03-11 19:05:40 -04:00
|
|
|
|
2016-03-15 17:31:34 -04:00
|
|
|
foreach ($frmData as $field => $value) {
|
|
|
|
|
if (($field != 'SYS_LANG') &&
|
2015-11-09 11:01:11 -04:00
|
|
|
($field != 'SYS_SKIN') &&
|
|
|
|
|
($field != 'SYS_SYS') &&
|
|
|
|
|
($field != 'APPLICATION') &&
|
|
|
|
|
($field != 'PROCESS') &&
|
|
|
|
|
($field != 'TASK') &&
|
|
|
|
|
($field != 'INDEX') &&
|
|
|
|
|
($field != 'USER_LOGGED') &&
|
|
|
|
|
($field != 'USR_USERNAME') &&
|
|
|
|
|
($field != 'DYN_CONTENT_HISTORY') &&
|
2016-03-15 17:31:34 -04:00
|
|
|
($field != 'PIN') &&
|
|
|
|
|
(!is_array($value))
|
|
|
|
|
) {
|
2015-11-09 11:01:11 -04:00
|
|
|
$dataFormToShowString .= " " . $field . " " . $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-07 09:34:42 -04:00
|
|
|
$appData = $this->getDraftApp($app_uid, $index);
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2016-03-15 17:31:34 -04:00
|
|
|
foreach ($appData as $application) {
|
2015-11-09 11:01:11 -04:00
|
|
|
$appNumber = $application['APP_NUMBER'];
|
|
|
|
|
$appStatus = $application['APP_STATUS'];
|
|
|
|
|
$index = $application['DEL_INDEX'];
|
2015-12-07 09:34:42 -04:00
|
|
|
$prvUsr = $application['APP_DEL_PREVIOUS_USER'];
|
2015-11-09 11:01:11 -04:00
|
|
|
$delegateDate = $application['DEL_DELEGATE_DATE'];
|
|
|
|
|
$nextUsr = $application['USR_UID'];
|
|
|
|
|
$proUid = $application['PRO_UID'];
|
|
|
|
|
$proName = $application['APP_PRO_TITLE'];
|
|
|
|
|
$tasName = $application['APP_TAS_TITLE'];
|
2015-12-07 09:34:42 -04:00
|
|
|
$threadStatus = $application['DEL_THREAD_STATUS'];
|
2015-11-09 11:01:11 -04:00
|
|
|
$tasUid = $application['TAS_UID'];
|
2015-12-07 09:34:42 -04:00
|
|
|
$lastIndex = $application['DEL_LAST_INDEX'];
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2016-03-15 17:31:34 -04:00
|
|
|
if ($appStatus == "DRAFT") {
|
2015-11-09 11:01:11 -04:00
|
|
|
$labelID = "PMDRFT";
|
|
|
|
|
} else {
|
|
|
|
|
$labelID = "PMIBX";
|
2016-03-23 17:35:44 -04:00
|
|
|
}
|
2016-03-11 19:05:40 -04:00
|
|
|
|
2016-03-23 17:35:44 -04:00
|
|
|
if (( string ) $mailToAddresses === "") {
|
|
|
|
|
if ($arrayTask) {
|
|
|
|
|
$oCases = new \Cases ();
|
2016-03-21 18:15:03 -04:00
|
|
|
|
2016-03-23 17:35:44 -04:00
|
|
|
foreach ( $arrayTask as $aTask ) {
|
|
|
|
|
if (! isset ( $aTask ["USR_UID"] )) {
|
|
|
|
|
$aTask ["USR_UID"] = "";
|
|
|
|
|
}
|
|
|
|
|
$respTo = $oCases->getTo ( $aTask ["TAS_ASSIGN_TYPE"], $aTask ["TAS_UID"], $aTask ["USR_UID"], $arrayData );
|
|
|
|
|
$mailToAddresses = $respTo ['to'];
|
|
|
|
|
$mailCcAddresses = $respTo ['cc'];
|
|
|
|
|
|
|
|
|
|
if ($aTask ["TAS_ASSIGN_TYPE"] === "SELF_SERVICE") {
|
|
|
|
|
$labelID = "PMUASS";
|
|
|
|
|
if (( string ) $mailToAddresses === "") { // Self Service Value Based
|
|
|
|
|
$criteria = new \Criteria ( "workflow" );
|
|
|
|
|
$criteria->addSelectColumn ( \AppAssignSelfServiceValuePeer::GRP_UID );
|
|
|
|
|
$criteria->add ( \AppAssignSelfServiceValuePeer::APP_UID, $app_uid );
|
2016-03-21 18:15:03 -04:00
|
|
|
|
2016-03-23 17:35:44 -04:00
|
|
|
$rsCriteria = \AppAssignSelfServiceValuePeer::doSelectRs ( $criteria );
|
|
|
|
|
$rsCriteria->setFetchmode ( \ResultSet::FETCHMODE_ASSOC );
|
2016-03-21 18:15:03 -04:00
|
|
|
|
2016-03-23 17:35:44 -04:00
|
|
|
while ( $rsCriteria->next () ) {
|
|
|
|
|
$row = $rsCriteria->getRow ();
|
|
|
|
|
}
|
2016-03-23 19:16:08 -04:00
|
|
|
$targetIds = unserialize ( $row ['GRP_UID'] );
|
2016-03-23 17:35:44 -04:00
|
|
|
$oUsers = new \Users ();
|
2016-03-23 19:16:08 -04:00
|
|
|
|
|
|
|
|
if (is_array($targetIds)) {
|
|
|
|
|
foreach ( $targetIds as $user ) {
|
|
|
|
|
$usrData = $oUsers->loadDetails ( $user );
|
2016-03-23 17:35:44 -04:00
|
|
|
$nextMail = $usrData ['USR_EMAIL'];
|
|
|
|
|
$mailToAddresses .= ($mailToAddresses == '') ? $nextMail : ',' . $nextMail;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-03-23 19:16:08 -04:00
|
|
|
$group = new \Groups();
|
|
|
|
|
$users = $group->getUsersOfGroup($targetIds);
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
$nextMail = $user['USR_EMAIL'];
|
|
|
|
|
$mailToAddresses .= ($mailToAddresses == '') ? $nextMail : ',' . $nextMail;
|
|
|
|
|
}
|
2016-03-23 17:35:44 -04:00
|
|
|
}
|
2016-03-23 19:16:08 -04:00
|
|
|
}
|
|
|
|
|
|
2016-03-23 17:35:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$oUsers = new \Users ();
|
2016-03-11 19:05:40 -04:00
|
|
|
|
2016-03-23 17:35:44 -04:00
|
|
|
$usrData = $oUsers->loadDetails ( $nextUsr );
|
|
|
|
|
$mailToAddresses = $usrData ['USR_EMAIL'];
|
|
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//first template
|
|
|
|
|
$pathTemplate = PATH_DATA_SITE . "mailTemplates" . PATH_SEP . "pmGmail.html";
|
2016-03-15 17:31:34 -04:00
|
|
|
if (!file_exists($pathTemplate)) {
|
2015-11-09 11:01:11 -04:00
|
|
|
$file = @fopen($pathTemplate, "w");
|
|
|
|
|
fwrite($file, '<div>');
|
|
|
|
|
fwrite($file, '<span style="display: none !important;">');
|
|
|
|
|
fwrite($file, '-**- Process Name: @#proName<br/>');
|
|
|
|
|
fwrite($file, '-**- Case Number: @#appNumber<br/>');
|
|
|
|
|
fwrite($file, '-**- Case UID: @#caseUid<br/>');
|
|
|
|
|
fwrite($file, '-**- Task Name: @#taskName<br/>');
|
|
|
|
|
fwrite($file, '-**- Index: @#index<br/>');
|
|
|
|
|
fwrite($file, '-**- Action: @#action<br/>');
|
2015-12-07 09:34:42 -04:00
|
|
|
fwrite($file, '-**- Previous User: @#prevUser<br/>');
|
2015-11-09 11:01:11 -04:00
|
|
|
fwrite($file, '-**- Delegate Date: @#delDate<br/>');
|
|
|
|
|
fwrite($file, '-**- Process Id: @#proUid<br/>');
|
|
|
|
|
fwrite($file, '-**- Type: @#type<br/>');
|
|
|
|
|
fwrite($file, '-**- FormFields: @@oform<br/>');
|
|
|
|
|
fwrite($file, '</span>');
|
|
|
|
|
fwrite($file, '</div>');
|
|
|
|
|
fclose($file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$change = array('[', ']', '"');
|
|
|
|
|
$fdata = str_replace($change, ' ', $dataFormToShowString);
|
2016-03-15 17:31:34 -04:00
|
|
|
$aFields = array(
|
|
|
|
|
'proName' => $proName,
|
2015-11-09 11:01:11 -04:00
|
|
|
'appNumber' => $appNumber,
|
|
|
|
|
'caseUid' => $app_uid,
|
|
|
|
|
'taskName' => $tasName,
|
|
|
|
|
'index' => $index,
|
|
|
|
|
'action' => $appStatus,
|
2015-12-07 09:34:42 -04:00
|
|
|
'prevUser' => $prvUsr,
|
2015-11-09 11:01:11 -04:00
|
|
|
'delDate' => $delegateDate,
|
|
|
|
|
'proUid' => $proUid,
|
|
|
|
|
'type' => $labelID,
|
|
|
|
|
'oform' => $fdata
|
|
|
|
|
);
|
|
|
|
|
|
2016-03-15 17:31:34 -04:00
|
|
|
$subject = "[PM] " . $proName . " (" . $index . ") Case: " . $appNumber;
|
2015-12-22 11:26:42 -04:00
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
$ws = new \wsBase();
|
2016-03-08 10:17:03 -04:00
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
$resultMail = $ws->sendMessage(
|
|
|
|
|
$app_uid,
|
2015-12-22 11:26:42 -04:00
|
|
|
$defaultEmail, //From,
|
2016-03-08 10:17:03 -04:00
|
|
|
$mailToAddresses,//$To,
|
|
|
|
|
$mailCcAddresses,//$Cc
|
2015-11-09 11:01:11 -04:00
|
|
|
'',
|
|
|
|
|
$subject,
|
|
|
|
|
'pmGmail.html',//template
|
|
|
|
|
$aFields, //fields
|
|
|
|
|
array(),
|
|
|
|
|
true,
|
|
|
|
|
0,
|
|
|
|
|
array(),
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
return $resultMail;
|
|
|
|
|
}
|
|
|
|
|
return 'The appUid cant be founded';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 11:55:46 -04:00
|
|
|
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);
|
|
|
|
|
}
|
2016-03-22 09:39:38 -04:00
|
|
|
}
|
|
|
|
|
|