//require_once 'classes/model/AppDocument.php'; $oAppDocument = new AppDocument(); $oAppDocument->remove($_POST['DOC']); $oCase = new Cases(); $oCase->getAllGeneratedDocumentsCriteria($_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['TASK'], $_SESSION['USER_LOGGED']); break; /* @Author Erik Amaru Ortiz <*****@*****.**> */ /* @Author Erik Amaru Ortiz <*****@*****.**> */ case 'resendMessage': //require_once 'classes/model/Configuration.php'; G::LoadClass('spool'); $oCase = new Cases(); $data = $oCase->getHistoryMessagesTrackerView($_POST['APP_UID'], $_POST['APP_MSG_UID']); //print_r($data); G::LoadClass("system"); $aSetup = System::getEmailConfiguration(); $passwd = $aSetup['MESS_PASSWORD']; $passwdDec = G::decrypt($passwd, 'EMAILENCRYPT'); $auxPass = explode('hash:', $passwdDec); if (count($auxPass) > 1) { if (count($auxPass) == 2) { $passwd = $auxPass[1]; } else { array_shift($auxPass); $passwd = implode('', $auxPass); } } $aSetup['MESS_PASSWORD'] = $passwd; if ($aSetup['MESS_RAUTH'] == false || is_string($aSetup['MESS_RAUTH']) && $aSetup['MESS_RAUTH'] == 'false') { $aSetup['MESS_RAUTH'] = 0; } else {
public function sendNotifications($sCurrentTask, $aTasks, $aFields, $sApplicationUID, $iDelegation, $sFrom = "") { try { $applicationData = $this->loadCase($sApplicationUID); $aFields["APP_NUMBER"] = $applicationData["APP_NUMBER"]; if (!class_exists('System')) { G::LoadClass('system'); } $aConfiguration = System::getEmailConfiguration(); $msgError = ""; if (!isset($aConfiguration['MESS_ENABLED']) || $aConfiguration['MESS_ENABLED'] != '1') { $msgError = "The default configuration wasn't defined"; $aConfiguration['MESS_ENGINE'] = ''; } //Send derivation notification - Start $oTask = new Task(); $aTaskInfo = $oTask->load($sCurrentTask); if ($aTaskInfo['TAS_SEND_LAST_EMAIL'] != 'TRUE') { return false; } $sFrom = G::buildFrom($aConfiguration, $sFrom); if (isset($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE']) && $aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'] != '') { $sSubject = G::replaceDataField($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'], $aFields); } else { $sSubject = G::LoadTranslation('ID_MESSAGE_SUBJECT_DERIVATION'); } //erik: new behaviour for messages G::loadClass('configuration'); $oConf = new Configurations; $oConf->loadConfig($x, 'TAS_EXTRA_PROPERTIES', $aTaskInfo['TAS_UID'], '', ''); $conf = $oConf->aConfig; $pathEmail = PATH_DATA_SITE . "mailTemplates" . PATH_SEP . $aTaskInfo["PRO_UID"] . PATH_SEP; $swtplDefault = 0; $sBody = null; if (isset($conf["TAS_DEF_MESSAGE_TYPE"]) && isset($conf["TAS_DEF_MESSAGE_TEMPLATE"]) && $conf["TAS_DEF_MESSAGE_TYPE"] == "template" && $conf["TAS_DEF_MESSAGE_TEMPLATE"] != "" ) { if ($conf["TAS_DEF_MESSAGE_TEMPLATE"] == "alert_message.html") { $swtplDefault = 1; } $fileTemplate = $pathEmail . $conf["TAS_DEF_MESSAGE_TEMPLATE"]; if (!file_exists($fileTemplate)) { throw (new Exception("Template file \"$fileTemplate\" does not exist.")); } $sBody = G::replaceDataGridField(file_get_contents($fileTemplate), $aFields, false); } else { $sBody = nl2br(G::replaceDataGridField($aTaskInfo["TAS_DEF_MESSAGE"], $aFields, false)); } G::LoadClass("tasks"); G::LoadClass("groups"); G::LoadClass("spool"); $task = new Tasks(); $group = new Groups(); $oUser = new Users(); foreach ($aTasks as $aTask) { $sTo = null; $sCc = null; switch ($aTask["TAS_ASSIGN_TYPE"]) { case "SELF_SERVICE": if ($swtplDefault == 1) { G::verifyPath($pathEmail, true); //Create if it does not exist $fileTemplate = $pathEmail . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'); if ((!file_exists($fileTemplate)) && file_exists(PATH_TPL . "mails" . PATH_SEP . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'))) { @copy(PATH_TPL . "mails" . PATH_SEP . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'), $fileTemplate); } $sBody = G::replaceDataField(file_get_contents($fileTemplate), $aFields); } if (isset($aTask["TAS_UID"]) && !empty($aTask["TAS_UID"])) { $arrayTaskUser = array(); $arrayAux1 = $task->getGroupsOfTask($aTask["TAS_UID"], 1); foreach ($arrayAux1 as $arrayGroup) { $arrayAux2 = $group->getUsersOfGroup($arrayGroup["GRP_UID"]); foreach ($arrayAux2 as $arrayUser) { $arrayTaskUser[] = $arrayUser["USR_UID"]; } } $arrayAux1 = $task->getUsersOfTask($aTask["TAS_UID"], 1); foreach ($arrayAux1 as $arrayUser) { $arrayTaskUser[] = $arrayUser["USR_UID"]; } $criteria = new Criteria("workflow"); $criteria->addSelectColumn(UsersPeer::USR_UID); $criteria->addSelectColumn(UsersPeer::USR_USERNAME); $criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME); $criteria->addSelectColumn(UsersPeer::USR_LASTNAME); $criteria->addSelectColumn(UsersPeer::USR_EMAIL); $criteria->add(UsersPeer::USR_UID, $arrayTaskUser, Criteria::IN); $rsCriteria = UsersPeer::doSelectRs($criteria); $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC); $to = null; $cc = null; $sw = 1; while ($rsCriteria->next()) { $row = $rsCriteria->getRow(); $toAux = ( (($row["USR_FIRSTNAME"] != "") || ($row["USR_LASTNAME"] != "")) ? $row["USR_FIRSTNAME"] . " " . $row["USR_LASTNAME"] . " " : "" ) . "<" . $row["USR_EMAIL"] . ">"; if ($sw == 1) { $to = $toAux; $sw = 0; } else { $cc = $cc . (($cc != null) ? "," : null) . $toAux; } } $sTo = $to; $sCc = $cc; } break; default: if (isset($aTask["USR_UID"]) && !empty($aTask["USR_UID"])) { $aUser = $oUser->load($aTask["USR_UID"]); $sTo = ( (($aUser["USR_FIRSTNAME"] != "") || ($aUser["USR_LASTNAME"] != "")) ? $aUser["USR_FIRSTNAME"] . " " . $aUser["USR_LASTNAME"] . " " : "" ) . "<" . $aUser["USR_EMAIL"] . ">"; } break; } if ($sTo != null) { $oSpool = new spoolRun(); $oSpool->setConfig($aConfiguration); $oSpool->create(array( "msg_uid" => "", "app_uid" => $sApplicationUID, "del_index" => $iDelegation, "app_msg_type" => "DERIVATION", "app_msg_subject" => $sSubject, "app_msg_from" => $sFrom, "app_msg_to" => $sTo, "app_msg_body" => $sBody, "app_msg_cc" => $sCc, "app_msg_bcc" => "", "app_msg_attach" => "", "app_msg_template" => "", "app_msg_status" => "pending", "app_msg_error" => $msgError )); if ($msgError == '') { if (($aConfiguration["MESS_BACKGROUND"] == "") || ($aConfiguration["MESS_TRY_SEND_INMEDIATLY"] == "1") ) { $oSpool->sendMail(); } } } } //Send derivation notification - End } catch (Exception $oException) { throw $oException; } }
/** * send message * * @param string $caseId * @param string $sFrom * @param string $sTo * @param string $sCc * @param string $sBcc * @param string $sSubject * @param string $sTemplate * @param $appFields = null * @param $aAttachment = null * @param boolean $showMessage = true * @param int $delIndex = 0 * @param $config = array * @return $result will return an object */ public function sendMessage( $caseId, $sFrom, $sTo, $sCc, $sBcc, $sSubject, $sTemplate, $appFields = null, $aAttachment = null, $showMessage = true, $delIndex = 0, $config = array() ) { try { if (!class_exists('System')) { G::LoadClass('system'); } /*----------------------------------********---------------------------------*/ $aSetup = System::getEmailConfiguration(); /*----------------------------------********---------------------------------*/ $msgError = ""; if(sizeof($aSetup) == 0){ $msgError = "The default configuration wasn't defined"; } $oSpool = new spoolRun(); $oSpool->setConfig($aSetup); $oCase = new Cases(); $oldFields = $oCase->loadCase( $caseId ); $pathEmail = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $oldFields['PRO_UID'] . PATH_SEP; $fileTemplate = $pathEmail . $sTemplate; G::mk_dir( $pathEmail, 0777, true ); if (! file_exists( $fileTemplate )) { $data['FILE_TEMPLATE'] = $fileTemplate; $result = new wsResponse( 28, G::LoadTranslation( 'ID_TEMPLATE_FILE_NOT_EXIST', SYS_LANG, $data ) ); return $result; } if ($appFields == null) { $Fields = $oldFields['APP_DATA']; } else { $Fields = array_merge( $oldFields['APP_DATA'], $appFields ); } $sBody = G::replaceDataGridField(file_get_contents($fileTemplate), $Fields, false); $sFrom = G::buildFrom($aSetup, $sFrom); $showMessage = ($showMessage) ? 1 : 0 ; $messageArray = array( "msg_uid" => "", "app_uid" => $caseId, "del_index" => $delIndex, "app_msg_type" => "TRIGGER", "app_msg_subject" => $sSubject, "app_msg_from" => $sFrom, "app_msg_to" => $sTo, "app_msg_body" => $sBody, "app_msg_cc" => $sCc, "app_msg_bcc" => $sBcc, "app_msg_attach" => $aAttachment, "app_msg_template" => "", "app_msg_status" => "pending", "app_msg_show_message" => $showMessage, "app_msg_error" => $msgError, "contentTypeIsHtml" => (preg_match("/^.+\.html?$/i", $fileTemplate))? true : false ); $oSpool->create( $messageArray ); $oSpool->sendMail(); if ($oSpool->status == 'sent') { $result = new wsResponse( 0, G::loadTranslation( 'ID_MESSAGE_SENT' ) . ": " . $sTo ); } else { $result = new wsResponse( 29, $oSpool->status . ' ' . $oSpool->error . print_r( $aSetup, 1 ) ); } return $result; } catch (Exception $e) { return new wsResponse( 100, $e->getMessage() ); } }
/** * Upgrade this workspace database to the latest system schema * * @param bool $checkOnly only check if the upgrade is needed if true * @return array bool upgradeSchema for more information */ public function upgradeDatabase ($onedb = false, $checkOnly = false) { G::LoadClass("patch"); $this->initPropel( true ); p11835::$dbAdapter = $this->dbAdapter; p11835::isApplicable(); $systemSchema = System::getSystemSchema($this->dbAdapter); $systemSchemaRbac = System::getSystemSchemaRbac($this->dbAdapter);// get the Rbac Schema $this->upgradeSchema( $systemSchema ); $this->upgradeSchema( $systemSchemaRbac, false, true, $onedb ); // perform Upgrade to Rbac $this->upgradeData(); //There records in table "EMAIL_SERVER" $criteria = new Criteria("workflow"); $criteria->addSelectColumn(EmailServerPeer::MESS_UID); $criteria->setOffset(0); $criteria->setLimit(1); $rsCriteria = EmailServerPeer::doSelectRS($criteria); if (!$rsCriteria->next()) { //Insert the first record $arrayData = array(); $emailSever = new \ProcessMaker\BusinessModel\EmailServer(); $emailConfiguration = System::getEmailConfiguration(); if (!empty($emailConfiguration)) { $arrayData["MESS_ENGINE"] = $emailConfiguration["MESS_ENGINE"]; switch ($emailConfiguration["MESS_ENGINE"]) { case "PHPMAILER": $arrayData["MESS_SERVER"] = $emailConfiguration["MESS_SERVER"]; $arrayData["MESS_PORT"] = (int)($emailConfiguration["MESS_PORT"]); $arrayData["MESS_RAUTH"] = (is_numeric($emailConfiguration["MESS_RAUTH"]))? (int)($emailConfiguration["MESS_RAUTH"]) : (($emailConfiguration["MESS_RAUTH"] . "" == "true")? 1 : 0); $arrayData["MESS_ACCOUNT"] = $emailConfiguration["MESS_ACCOUNT"]; $arrayData["MESS_PASSWORD"] = $emailConfiguration["MESS_PASSWORD"]; $arrayData["MESS_FROM_MAIL"] = (isset($emailConfiguration["MESS_FROM_MAIL"]))? $emailConfiguration["MESS_FROM_MAIL"] : ""; $arrayData["MESS_FROM_NAME"] = (isset($emailConfiguration["MESS_FROM_NAME"]))? $emailConfiguration["MESS_FROM_NAME"] : ""; $arrayData["SMTPSECURE"] = $emailConfiguration["SMTPSecure"]; $arrayData["MESS_TRY_SEND_INMEDIATLY"] = (isset($emailConfiguration["MESS_TRY_SEND_INMEDIATLY"]) && ($emailConfiguration["MESS_TRY_SEND_INMEDIATLY"] . "" == "true" || $emailConfiguration["MESS_TRY_SEND_INMEDIATLY"] . "" == "1"))? 1 : 0; $arrayData["MAIL_TO"] = isset($emailConfiguration["MAIL_TO"]) ? $emailConfiguration["MAIL_TO"] : ''; $arrayData["MESS_DEFAULT"] = (isset($emailConfiguration["MESS_ENABLED"]) && $emailConfiguration["MESS_ENABLED"] . "" == "1")? 1 : 0; break; case "MAIL": $arrayData["MESS_SERVER"] = ""; $arrayData["MESS_FROM_MAIL"] = (isset($emailConfiguration["MESS_FROM_MAIL"]))? $emailConfiguration["MESS_FROM_MAIL"] : ""; $arrayData["MESS_FROM_NAME"] = (isset($emailConfiguration["MESS_FROM_NAME"]))? $emailConfiguration["MESS_FROM_NAME"] : ""; $arrayData["MESS_TRY_SEND_INMEDIATLY"] = (isset($emailConfiguration["MESS_TRY_SEND_INMEDIATLY"]) && ($emailConfiguration["MESS_TRY_SEND_INMEDIATLY"] . "" == "true" || $emailConfiguration["MESS_TRY_SEND_INMEDIATLY"] . "" == "1"))? 1 : 0; $arrayData["MESS_ACCOUNT"] = ""; $arrayData["MESS_PASSWORD"] = ""; $arrayData["MAIL_TO"] = (isset($emailConfiguration["MAIL_TO"]))? $emailConfiguration["MAIL_TO"] : ""; $arrayData["MESS_DEFAULT"] = (isset($emailConfiguration["MESS_ENABLED"]) && $emailConfiguration["MESS_ENABLED"] . "" == "1")? 1 : 0; break; } $arrayData = $emailSever->create($arrayData); } else { /*----------------------------------********---------------------------------*/ $arrayData["MESS_ENGINE"] = "MAIL"; $arrayData["MESS_SERVER"] = ""; $arrayData["MESS_ACCOUNT"] = ""; $arrayData["MESS_PASSWORD"] = ""; $arrayData["MAIL_TO"] = ""; $arrayData["MESS_DEFAULT"] = 1; $arrayData = $emailSever->create2($arrayData); /*----------------------------------********---------------------------------*/ } } p11835::execute(); return true; }
/** * try resend the emails from spool * * @param string $dateResend * @return none or exception */ public function resendEmails ($dateResend = null, $cron = 0) { if (!class_exists('System')) { G::LoadClass('system'); } $aConfiguration = System::getEmailConfiguration(); if (!isset($aConfiguration["MESS_ENABLED"])) { $aConfiguration["MESS_ENABLED"] = '0'; } if ($aConfiguration["MESS_ENABLED"] == "1") { require_once ("classes/model/AppMessage.php"); $this->setConfig($aConfiguration); $criteria = new Criteria( "workflow" ); $criteria->add( AppMessagePeer::APP_MSG_STATUS, "sent", Criteria::NOT_EQUAL ); if ($dateResend != null) { $criteria->add( AppMessagePeer::APP_MSG_DATE, $dateResend, Criteria::GREATER_EQUAL ); } $rsCriteria = AppMessagePeer::doSelectRS( $criteria ); $rsCriteria->setFetchmode( ResultSet::FETCHMODE_ASSOC ); while ($rsCriteria->next()) { if ($cron == 1) { $arrayCron = unserialize( trim( @file_get_contents( PATH_DATA . "cron" ) ) ); $arrayCron["processcTimeStart"] = time(); @file_put_contents( PATH_DATA . "cron", serialize( $arrayCron ) ); } $row = $rsCriteria->getRow(); try { $sFrom = G::buildFrom($aConfiguration, $row["APP_MSG_FROM"]); $this->setData( $row["APP_MSG_UID"], $row["APP_MSG_SUBJECT"], $sFrom, $row["APP_MSG_TO"], $row["APP_MSG_BODY"], date( "Y-m-d H:i:s" ), $row["APP_MSG_CC"], $row["APP_MSG_BCC"], $row["APP_MSG_TEMPLATE"], $row["APP_MSG_ATTACH"] ); $this->sendMail(); } catch (Exception $e) { $strAux = "Spool::resendEmails(): Using " . $aConfiguration["MESS_ENGINE"] . " for APP_MGS_UID=" . $row["APP_MSG_UID"] . " -> With message: " . $e->getMessage(); if ($e->getCode() == $this->ExceptionCode["WARNING"]) { array_push( $this->aWarnings, $strAux ); continue; } else { throw $e; } } } } }
function getEmailConfiguration() { G::loadClass('system'); return System::getEmailConfiguration(); }
/** * send message * * @param string $caseId * @param string $sFrom * @param string $sTo * @param string $sCc * @param string $sBcc * @param string $sSubject * @param string $sTemplate * @param $appFields = null * @param $aAttachment = null * @param boolean $showMessage = true * @param int $delIndex = 0 * @return $result will return an object */ public function sendMessage($caseId, $sFrom, $sTo, $sCc, $sBcc, $sSubject, $sTemplate, $appFields = null, $aAttachment = null, $showMessage = true, $delIndex = 0) { try { G::LoadClass("system"); $aSetup = System::getEmailConfiguration(); $passwd = $aSetup['MESS_PASSWORD']; $passwdDec = G::decrypt($passwd, 'EMAILENCRYPT'); $auxPass = explode('hash:', $passwdDec); if (count($auxPass) > 1) { if (count($auxPass) == 2) { $passwd = $auxPass[1]; } else { array_shift($auxPass); $passwd = implode('', $auxPass); } } $aSetup['MESS_PASSWORD'] = $passwd; if ($aSetup['MESS_RAUTH'] == false || is_string($aSetup['MESS_RAUTH']) && $aSetup['MESS_RAUTH'] == 'false') { $aSetup['MESS_RAUTH'] = 0; } else { $aSetup['MESS_RAUTH'] = 1; } $oSpool = new spoolRun(); $oSpool->setConfig(array('MESS_ENGINE' => $aSetup['MESS_ENGINE'], 'MESS_SERVER' => $aSetup['MESS_SERVER'], 'MESS_PORT' => $aSetup['MESS_PORT'], 'MESS_ACCOUNT' => $aSetup['MESS_ACCOUNT'], 'MESS_PASSWORD' => $aSetup['MESS_PASSWORD'], 'SMTPSecure' => $aSetup['SMTPSecure'], 'SMTPAuth' => $aSetup['MESS_RAUTH'])); $oCase = new Cases(); $oldFields = $oCase->loadCase($caseId); $pathEmail = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $oldFields['PRO_UID'] . PATH_SEP; $fileTemplate = $pathEmail . $sTemplate; G::mk_dir($pathEmail, 0777, true); if (!file_exists($fileTemplate)) { $data['FILE_TEMPLATE'] = $fileTemplate; $result = new wsResponse(28, G::LoadTranslation('ID_TEMPLATE_FILE_NOT_EXIST', SYS_LANG, $data)); return $result; } if ($appFields == null) { $Fields = $oldFields['APP_DATA']; } else { $Fields = array_merge($oldFields['APP_DATA'], $appFields); } $sBody = G::replaceDataGridField(file_get_contents($fileTemplate), $Fields); $hasEmailFrom = preg_match('/(.+)@(.+)\\.(.+)/', $sFrom, $match); if (!$hasEmailFrom || strpos($sFrom, $aSetup['MESS_ACCOUNT']) === false) { $sFrom = '"' . stripslashes($sFrom) . '" <' . $aSetup['MESS_ACCOUNT'] . ">"; } $showMessage = $showMessage ? 1 : 0; $messageArray = array("msg_uid" => "", "app_uid" => $caseId, "del_index" => $delIndex, "app_msg_type" => "TRIGGER", "app_msg_subject" => $sSubject, "app_msg_from" => $sFrom, "app_msg_to" => $sTo, "app_msg_body" => $sBody, "app_msg_cc" => $sCc, "app_msg_bcc" => $sBcc, "app_msg_attach" => $aAttachment, "app_msg_template" => "", "app_msg_status" => "pending", "app_msg_show_message" => $showMessage, "contentTypeIsHtml" => preg_match("/^.+\\.html?\$/i", $fileTemplate) ? true : false); $oSpool->create($messageArray); $oSpool->sendMail(); if ($oSpool->status == 'sent') { $result = new wsResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $sTo); } else { $result = new wsResponse(29, $oSpool->status . ' ' . $oSpool->error . print_r($aSetup, 1)); } return $result; } catch (Exception $e) { return new wsResponse(100, $e->getMessage()); } }
public function sendNoteNotification($appUid, $usrUid, $noteContent, $noteRecipients, $sFrom = "") { try { if (!class_exists('System')) { G::LoadClass('system'); } $aConfiguration = System::getEmailConfiguration(); if (!isset($aConfiguration['MESS_ENABLED']) || $aConfiguration['MESS_ENABLED'] != '1') { return false; } $oUser = new Users(); $aUser = $oUser->load($usrUid); $authorName = ($aUser['USR_FIRSTNAME'] != '' || $aUser['USR_LASTNAME'] != '' ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>'; G::LoadClass('case'); $oCase = new Cases(); $aFields = $oCase->loadCase($appUid); $configNoteNotification['subject'] = G::LoadTranslation('ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION') . " @#APP_TITLE "; $configNoteNotification['body'] = G::LoadTranslation('ID_CASE') . ": @#APP_TITLE<br />" . G::LoadTranslation('ID_AUTHOR') . ": {$authorName}<br /><br />{$noteContent}"; $sFrom = G::buildFrom($aConfiguration, $sFrom); $sSubject = G::replaceDataField($configNoteNotification['subject'], $aFields); $sBody = nl2br(G::replaceDataField($configNoteNotification['body'], $aFields)); G::LoadClass('spool'); $oUser = new Users(); $recipientsArray = explode(",", $noteRecipients); foreach ($recipientsArray as $recipientUid) { $aUser = $oUser->load($recipientUid); $sTo = ($aUser['USR_FIRSTNAME'] != '' || $aUser['USR_LASTNAME'] != '' ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>'; $oSpool = new spoolRun(); $oSpool->setConfig($aConfiguration); $oSpool->create(array('msg_uid' => '', 'app_uid' => $appUid, 'del_index' => 0, 'app_msg_type' => 'DERIVATION', 'app_msg_subject' => $sSubject, 'app_msg_from' => $sFrom, 'app_msg_to' => $sTo, 'app_msg_body' => $sBody, 'app_msg_cc' => '', 'app_msg_bcc' => '', 'app_msg_attach' => '', 'app_msg_template' => '', 'app_msg_status' => 'pending')); if ($aConfiguration['MESS_BACKGROUND'] == '' || $aConfiguration['MESS_TRY_SEND_INMEDIATLY'] == '1') { $oSpool->sendMail(); } } //Send derivation notification - End } catch (Exception $oException) { throw $oException; } }
/** * send message * @param string $caseId * @param string $sFrom * @param string $sTo * @param string $sCc * @param string $sBcc * @param string $sSubject * @param string $sTemplate * @param $appFields = null * @return $result will return an object */ public function sendMessage($caseId, $sFrom, $sTo, $sCc, $sBcc, $sSubject, $sTemplate, $appFields = null, $aAttachment = null) { try { G::loadClass('system'); $aSetup = System::getEmailConfiguration(); $passwd = $aSetup['MESS_PASSWORD']; $passwdDec = G::decrypt($passwd, 'EMAILENCRYPT'); if (strpos($passwdDec, 'hash:') !== false) { list($hash, $pass) = explode(":", $passwdDec); $arrayFrom['MESS_PASSWORD'] = $pass; } $oSpool = new spoolRun(); $oSpool->setConfig(array('MESS_ENGINE' => $aSetup['MESS_ENGINE'], 'MESS_SERVER' => $aSetup['MESS_SERVER'], 'MESS_PORT' => $aSetup['MESS_PORT'], 'MESS_ACCOUNT' => $aSetup['MESS_ACCOUNT'], 'MESS_PASSWORD' => $aSetup['MESS_PASSWORD'], 'SMTPAuth' => $aSetup['MESS_RAUTH'])); $oCase = new Cases(); $oldFields = $oCase->loadCase($caseId); $pathEmail = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $oldFields['PRO_UID'] . PATH_SEP; $fileTemplate = $pathEmail . $sTemplate; G::mk_dir($pathEmail, 0777, true); if (!file_exists($fileTemplate)) { $data['FILE_TEMPLATE'] = $fileTemplate; $result = new wsResponse(28, G::LoadTranslation('ID_TEMPLATE_FILE_NOT_EXIST', SYS_LANG, $data)); return $result; } if ($appFields == null) { $Fields = $oldFields['APP_DATA']; } else { $Fields = array_merge($oldFields['APP_DATA'], $appFields); } $templateContents = file_get_contents($fileTemplate); //$sContent = G::unhtmlentities($sContent); $iAux = 0; $iOcurrences = preg_match_all('/\\@(?:([\\>])([a-zA-Z\\_]\\w*)|([a-zA-Z\\_][\\w\\-\\>\\:]*)\\(((?:[^\\\\\\)]*(?:[\\\\][\\w\\W])?)*)\\))((?:\\s*\\[[\'"]?\\w+[\'"]?\\])+)?/', $templateContents, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); if ($iOcurrences) { for ($i = 0; $i < $iOcurrences; $i++) { preg_match_all('/@>' . $aMatch[2][$i][0] . '([\\w\\W]*)' . '@<' . $aMatch[2][$i][0] . '/', $templateContents, $aMatch2, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $sGridName = $aMatch[2][$i][0]; $sStringToRepeat = $aMatch2[1][0][0]; if (isset($Fields[$sGridName])) { if (is_array($Fields[$sGridName])) { $sAux = ''; foreach ($Fields[$sGridName] as $aRow) { $sAux .= G::replaceDataField($sStringToRepeat, $aRow); } } } $templateContents = str_replace('@>' . $sGridName . $sStringToRepeat . '@<' . $sGridName, $sAux, $templateContents); } } $sBody = G::replaceDataField($templateContents, $Fields); $hasEmailFrom = preg_match('/(.+)@(.+)\\.(.+)/', $sFrom, $match); if (!$hasEmailFrom) { $sFrom = $aSetup['MESS_ACCOUNT']; } $messageArray = array('msg_uid' => '', 'app_uid' => $caseId, 'del_index' => 0, 'app_msg_type' => 'TRIGGER', 'app_msg_subject' => $sSubject, 'app_msg_from' => $sFrom, 'app_msg_to' => $sTo, 'app_msg_body' => $sBody, 'app_msg_cc' => $sCc, 'app_msg_bcc' => $sBcc, 'app_msg_attach' => $aAttachment, 'app_msg_template' => '', 'app_msg_status' => 'pending'); $oSpool->create($messageArray); $oSpool->sendMail(); if ($oSpool->status == 'sent') { $result = new wsResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $sTo); } else { $result = new wsResponse(29, $oSpool->status . ' ' . $oSpool->error . print_r($aSetup, 1)); } return $result; } catch (Exception $e) { return new wsResponse(100, $e->getMessage()); } }
public function sendNotifications($taskUid, $arrayTask, $arrayData, $applicationUid, $delIndex, $from = '') { try { $arrayApplicationData = $this->loadCase($applicationUid); $arrayData['APP_NUMBER'] = $arrayApplicationData['APP_NUMBER']; if (!class_exists('System')) { G::LoadClass('system'); } $aConfiguration = System::getEmailConfiguration(); $msgError = ""; if (!isset($aConfiguration['MESS_ENABLED']) || $aConfiguration['MESS_ENABLED'] != '1') { $msgError = "The default configuration wasn't defined"; $aConfiguration['MESS_ENGINE'] = ''; } //Send derivation notification - Start $oTask = new Task(); $aTaskInfo = $oTask->load($taskUid); if ($aTaskInfo['TAS_SEND_LAST_EMAIL'] != 'TRUE') { return false; } $from = G::buildFrom($aConfiguration, $from); if (isset($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE']) && $aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'] != '') { $sSubject = G::replaceDataField($aTaskInfo['TAS_DEF_SUBJECT_MESSAGE'], $arrayData); } else { $sSubject = G::LoadTranslation('ID_MESSAGE_SUBJECT_DERIVATION'); } //erik: new behaviour for messages G::loadClass('configuration'); $oConf = new Configurations(); $oConf->loadConfig($x, 'TAS_EXTRA_PROPERTIES', $aTaskInfo['TAS_UID'], '', ''); $conf = $oConf->aConfig; $pathEmail = PATH_DATA_SITE . "mailTemplates" . PATH_SEP . $aTaskInfo["PRO_UID"] . PATH_SEP; $swtplDefault = 0; $sBody = null; if (isset($conf["TAS_DEF_MESSAGE_TYPE"]) && isset($conf["TAS_DEF_MESSAGE_TEMPLATE"]) && $conf["TAS_DEF_MESSAGE_TYPE"] == "template" && $conf["TAS_DEF_MESSAGE_TEMPLATE"] != "") { if ($conf["TAS_DEF_MESSAGE_TEMPLATE"] == "alert_message.html") { $swtplDefault = 1; } $fileTemplate = $pathEmail . $conf["TAS_DEF_MESSAGE_TEMPLATE"]; if (!file_exists($fileTemplate)) { $tempale = PATH_CORE . "templates" . PATH_SEP . "mails" . PATH_SEP . "alert_message.html"; $copied = @copy($tempale, $fileTemplate); if ($copied) { $dataTemplate = array("prf_filename" => $conf["TAS_DEF_MESSAGE_TEMPLATE"], "prf_path" => $fileTemplate, "pro_uid" => $aTaskInfo["PRO_UID"], "usr_uid" => "00000000000000000000000000000001", "prf_uid" => G::generateUniqueID(), "prf_type" => "file", "prf_create_date" => date("Y-m-d H:i:s")); $filesManager = new ProcessMaker\BusinessModel\FilesManager(); $filesManager->addProcessFilesManagerInDb($dataTemplate); } else { throw new Exception("Template file \"{$fileTemplate}\" does not exist."); } } $sBody = file_get_contents($fileTemplate); } else { $sBody = nl2br($aTaskInfo['TAS_DEF_MESSAGE']); } G::LoadClass("tasks"); G::LoadClass("groups"); G::LoadClass("spool"); $task = new Tasks(); $group = new Groups(); $oUser = new Users(); foreach ($arrayTask as $aTask) { $sTo = null; $sCc = null; if (isset($aTask['DEL_INDEX'])) { $arrayData2 = $arrayData; $appDelegation = AppDelegationPeer::retrieveByPK($applicationUid, $aTask['DEL_INDEX']); if (!is_null($appDelegation)) { $arrayData2['TAS_TITLE'] = Content::load('TAS_TITLE', '', $appDelegation->getTasUid(), SYS_LANG); $arrayData2['DEL_TASK_DUE_DATE'] = $appDelegation->getDelTaskDueDate(); } } else { $arrayData2 = $arrayData; } if (isset($aTask['USR_UID']) && !empty($aTask['USR_UID'])) { $user = new \ProcessMaker\BusinessModel\User(); $arrayUserData = $user->getUser($aTask['USR_UID'], true); $arrayData2 = \ProcessMaker\Util\DateTime::convertUtcToTimeZone($arrayData2, trim($arrayUserData['USR_TIME_ZONE']) != '' ? trim($arrayUserData['USR_TIME_ZONE']) : \ProcessMaker\Util\System::getTimeZone()); } else { $arrayData2 = \ProcessMaker\Util\DateTime::convertUtcToTimeZone($arrayData2); } $sBody2 = G::replaceDataGridField($sBody, $arrayData2, false); switch ($aTask["TAS_ASSIGN_TYPE"]) { case "SELF_SERVICE": if ($swtplDefault == 1) { G::verifyPath($pathEmail, true); //Create if it does not exist $fileTemplate = $pathEmail . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'); if (!file_exists($fileTemplate) && file_exists(PATH_TPL . "mails" . PATH_SEP . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'))) { @copy(PATH_TPL . "mails" . PATH_SEP . G::LoadTranslation('ID_UNASSIGNED_MESSAGE'), $fileTemplate); } $sBody2 = G::replaceDataField(file_get_contents($fileTemplate), $arrayData2); } if (isset($aTask["TAS_UID"]) && !empty($aTask["TAS_UID"])) { $arrayTaskUser = array(); $arrayAux1 = $task->getGroupsOfTask($aTask["TAS_UID"], 1); foreach ($arrayAux1 as $arrayGroup) { $arrayAux2 = $group->getUsersOfGroup($arrayGroup["GRP_UID"]); foreach ($arrayAux2 as $arrayUser) { $arrayTaskUser[] = $arrayUser["USR_UID"]; } } $arrayAux1 = $task->getUsersOfTask($aTask["TAS_UID"], 1); foreach ($arrayAux1 as $arrayUser) { $arrayTaskUser[] = $arrayUser["USR_UID"]; } $criteria = new Criteria("workflow"); $criteria->addSelectColumn(UsersPeer::USR_UID); $criteria->addSelectColumn(UsersPeer::USR_USERNAME); $criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME); $criteria->addSelectColumn(UsersPeer::USR_LASTNAME); $criteria->addSelectColumn(UsersPeer::USR_EMAIL); $criteria->add(UsersPeer::USR_UID, $arrayTaskUser, Criteria::IN); $rsCriteria = UsersPeer::doSelectRs($criteria); $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC); $to = null; $cc = null; $sw = 1; while ($rsCriteria->next()) { $row = $rsCriteria->getRow(); $toAux = ($row["USR_FIRSTNAME"] != "" || $row["USR_LASTNAME"] != "" ? $row["USR_FIRSTNAME"] . " " . $row["USR_LASTNAME"] . " " : "") . "<" . $row["USR_EMAIL"] . ">"; if ($sw == 1) { $to = $toAux; $sw = 0; } else { $cc = $cc . ($cc != null ? "," : null) . $toAux; } } $sTo = $to; $sCc = $cc; } break; case "MULTIPLE_INSTANCE": $to = null; $cc = null; $sw = 1; $oDerivation = new Derivation(); $userFields = $oDerivation->getUsersFullNameFromArray($oDerivation->getAllUsersFromAnyTask($aTask["TAS_UID"])); if (isset($userFields)) { foreach ($userFields as $row) { $toAux = ($row["USR_FIRSTNAME"] != "" || $row["USR_LASTNAME"] != "" ? $row["USR_FIRSTNAME"] . " " . $row["USR_LASTNAME"] . " " : "") . "<" . $row["USR_EMAIL"] . ">"; if ($sw == 1) { $to = $toAux; $sw = 0; } else { $cc = $cc . ($cc != null ? "," : null) . $toAux; } } $sTo = $to; $sCc = $cc; } break; case "MULTIPLE_INSTANCE_VALUE_BASED": $aTaskNext = $oTask->load($aTask["TAS_UID"]); if (isset($aTaskNext["TAS_ASSIGN_VARIABLE"]) && !empty($aTaskNext["TAS_ASSIGN_VARIABLE"])) { $to = null; $cc = null; $sw = 1; $nextTaskAssignVariable = trim($aTaskNext["TAS_ASSIGN_VARIABLE"], " @#"); $arrayUsers = $arrayData[$nextTaskAssignVariable]; $oDerivation = new Derivation(); $userFields = $oDerivation->getUsersFullNameFromArray($arrayUsers); foreach ($userFields as $row) { $toAux = ($row["USR_FIRSTNAME"] != "" || $row["USR_LASTNAME"] != "" ? $row["USR_FIRSTNAME"] . " " . $row["USR_LASTNAME"] . " " : "") . "<" . $row["USR_EMAIL"] . ">"; if ($sw == 1) { $to = $toAux; $sw = 0; } else { $cc = $cc . ($cc != null ? "," : null) . $toAux; } } $sTo = $to; $sCc = $cc; } break; default: if (isset($aTask["USR_UID"]) && !empty($aTask["USR_UID"])) { $aUser = $oUser->load($aTask["USR_UID"]); $sTo = ($aUser["USR_FIRSTNAME"] != "" || $aUser["USR_LASTNAME"] != "" ? $aUser["USR_FIRSTNAME"] . " " . $aUser["USR_LASTNAME"] . " " : "") . "<" . $aUser["USR_EMAIL"] . ">"; } break; } if ($sTo != null) { $oSpool = new spoolRun(); $oSpool->setConfig($aConfiguration); $oSpool->create(array("msg_uid" => "", 'app_uid' => $applicationUid, 'del_index' => $delIndex, "app_msg_type" => "DERIVATION", "app_msg_subject" => $sSubject, 'app_msg_from' => $from, "app_msg_to" => $sTo, 'app_msg_body' => $sBody2, "app_msg_cc" => $sCc, "app_msg_bcc" => "", "app_msg_attach" => "", "app_msg_template" => "", "app_msg_status" => "pending", "app_msg_error" => $msgError)); if ($msgError == '') { if ($aConfiguration["MESS_BACKGROUND"] == "" || $aConfiguration["MESS_TRY_SEND_INMEDIATLY"] == "1") { $oSpool->sendMail(); } } } } //Send derivation notification - End } catch (Exception $oException) { throw $oException; } }