Ejemplo n.º 1
0
 /**
  * Send a test email
  *
  * @param array $arrayData Data
  *
  * return array Return array with result of send test mail
  */
 public function sendTestMail(array $arrayData)
 {
     try {
         \G::LoadClass("system");
         \G::LoadClass("spool");
         $aConfiguration = array("MESS_ENGINE" => $arrayData["MESS_ENGINE"], "MESS_SERVER" => $arrayData["MESS_SERVER"], "MESS_PORT" => (int) $arrayData["MESS_PORT"], "MESS_ACCOUNT" => $arrayData["MESS_ACCOUNT"], "MESS_PASSWORD" => $arrayData["MESS_PASSWORD"], "MESS_FROM_NAME" => $arrayData["FROM_NAME"], "MESS_FROM_MAIL" => $arrayData["FROM_EMAIL"], "MESS_RAUTH" => (int) $arrayData["MESS_RAUTH"], "SMTPSecure" => isset($arrayData["SMTPSecure"]) ? $arrayData["SMTPSecure"] : "none");
         $sFrom = \G::buildFrom($aConfiguration);
         $sSubject = \G::LoadTranslation("ID_MESS_TEST_SUBJECT");
         $msg = \G::LoadTranslation("ID_MESS_TEST_BODY");
         switch ($arrayData["MESS_ENGINE"]) {
             case "MAIL":
                 $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_1");
                 break;
             case "PHPMAILER":
                 $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_2");
                 break;
             case "OPENMAIL":
                 $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_3");
                 break;
         }
         $sBodyPre = new \TemplatePower(PATH_TPL . "admin" . PATH_SEP . "email.tpl");
         $sBodyPre->prepare();
         $sBodyPre->assign("server", $_SERVER["SERVER_NAME"]);
         $sBodyPre->assign("date", date("H:i:s"));
         $sBodyPre->assign("ver", \System::getVersion());
         $sBodyPre->assign("engine", $engine);
         $sBodyPre->assign("msg", $msg);
         $sBody = $sBodyPre->getOutputContent();
         $oSpool = new \spoolRun();
         $oSpool->setConfig($aConfiguration);
         $oSpool->create(array("msg_uid" => "", "app_uid" => "", "del_index" => 0, "app_msg_type" => "TEST", "app_msg_subject" => $sSubject, "app_msg_from" => $sFrom, "app_msg_to" => $arrayData["TO"], "app_msg_body" => $sBody, "app_msg_cc" => "", "app_msg_bcc" => "", "app_msg_attach" => "", "app_msg_template" => "", "app_msg_status" => "pending", "app_msg_attach" => ""));
         $oSpool->sendMail();
         //Return
         $arrayTestMailResult = array();
         if ($oSpool->status == "sent") {
             $arrayTestMailResult["status"] = true;
             $arrayTestMailResult["success"] = true;
             $arrayTestMailResult["msg"] = \G::LoadTranslation("ID_MAIL_TEST_SUCCESS");
         } else {
             $arrayTestMailResult["status"] = false;
             $arrayTestMailResult["success"] = false;
             $arrayTestMailResult["msg"] = $oSpool->error;
         }
         return $arrayTestMailResult;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 2
0
    /**

     * 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() );

        }

    }
Ejemplo n.º 3
0
    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;

        }

    }
Ejemplo n.º 4
0
    /**
     * 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;
                    }
                }
            }
        }
    }
Ejemplo n.º 5
0
 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;
     }
 }
Ejemplo n.º 6
0
$userData = $rbacUser->getByUsername($data['USR_USERNAME']);
if ($userData['USR_EMAIL'] != '' && $userData['USR_EMAIL'] === $data['USR_EMAIL'] && ($userData['USR_AUTH_TYPE'] === '' || $userData['USR_AUTH_TYPE'] == 'MYSQL')) {
    $aSetup = System::getEmailConfiguration();
    if (count($aSetup) == 0 || !isset($aSetup['MESS_ENGINE'])) {
        G::SendTemporalMessage('ID_EMAIL_ENGINE_IS_NOT_ENABLED', "warning");
        G::header('location: forgotPassword');
        die;
    }
    $newPass = G::generate_password();
    $aData['USR_UID'] = $userData['USR_UID'];
    $aData['USR_PASSWORD'] = md5($newPass);
    /* **Save after sending the mail
         $rbacUser->update($aData);
         $user->update($aData);
       */
    $sFrom = G::buildFrom($aSetup, $sFrom);
    $sSubject = G::LoadTranslation('ID_RESET_PASSWORD') . ' - ProcessMaker';
    $msg = '<h3>ProcessMaker Forgot password Service</h3>';
    $msg .= '<p>' . G::LoadTranslation('ID_YOUR_USERMANE_IS') . ' :  <strong>' . $userData['USR_USERNAME'] . '</strong></p>';
    $msg .= '<p>' . G::LoadTranslation('ID_YOUR_PASSWORD_IS') . ' :  <strong>' . $newPass . '</strong></p>';
    switch ($aSetup['MESS_ENGINE']) {
        case 'MAIL':
            $engine = G::LoadTranslation('ID_MESS_ENGINE_TYPE_1');
            break;
        case 'PHPMAILER':
            $engine = G::LoadTranslation('ID_MESS_ENGINE_TYPE_2');
            break;
        case 'OPENMAIL':
            $engine = G::LoadTranslation('ID_MESS_ENGINE_TYPE_3');
            break;
    }
Ejemplo n.º 7
0
 /**
  * for send email configuration
  * @autor Alvaro  <*****@*****.**>
  */
 public function sendTestMail()
 {
     global $G_PUBLISH;
     G::LoadClass("system");
     G::LoadClass('spool');
     $aConfiguration = array('MESS_ENGINE' => $_POST['MESS_ENGINE'], 'MESS_SERVER' => $_POST['MESS_SERVER'], 'MESS_PORT' => $_POST['MESS_PORT'], 'MESS_ACCOUNT' => $_POST['MESS_ACCOUNT'], 'MESS_PASSWORD' => $_POST['MESS_PASSWORD'], 'MESS_FROM_NAME' => $_POST["FROM_NAME"], 'MESS_FROM_MAIL' => $_POST["FROM_EMAIL"], 'MESS_RAUTH' => $_POST['MESS_RAUTH'], 'SMTPSecure' => isset($_POST['SMTPSecure']) ? $_POST['SMTPSecure'] : 'none');
     $sFrom = G::buildFrom($aConfiguration);
     $sSubject = G::LoadTranslation('ID_MESS_TEST_SUBJECT');
     $msg = G::LoadTranslation('ID_MESS_TEST_BODY');
     switch ($_POST['MESS_ENGINE']) {
         case 'MAIL':
             $engine = G::LoadTranslation('ID_MESS_ENGINE_TYPE_1');
             break;
         case 'PHPMAILER':
             $engine = G::LoadTranslation('ID_MESS_ENGINE_TYPE_2');
             break;
         case 'OPENMAIL':
             $engine = G::LoadTranslation('ID_MESS_ENGINE_TYPE_3');
             break;
     }
     $sBodyPre = new TemplatePower(PATH_TPL . 'admin' . PATH_SEP . 'email.tpl');
     $sBodyPre->prepare();
     $sBodyPre->assign('server', $_SERVER['SERVER_NAME']);
     $sBodyPre->assign('date', date('H:i:s'));
     $sBodyPre->assign('ver', System::getVersion());
     $sBodyPre->assign('engine', $engine);
     $sBodyPre->assign('msg', $msg);
     $sBody = $sBodyPre->getOutputContent();
     $oSpool = new spoolRun();
     $oSpool->setConfig($aConfiguration);
     $oSpool->create(array('msg_uid' => '', 'app_uid' => '', 'del_index' => 0, 'app_msg_type' => 'TEST', 'app_msg_subject' => $sSubject, 'app_msg_from' => $sFrom, 'app_msg_to' => $_POST['TO'], 'app_msg_body' => $sBody, 'app_msg_cc' => '', 'app_msg_bcc' => '', 'app_msg_attach' => '', 'app_msg_template' => '', 'app_msg_status' => 'pending', 'app_msg_attach' => ''));
     $oSpool->sendMail();
     $G_PUBLISH = new Publisher();
     $o = new stdclass();
     if ($oSpool->status == 'sent') {
         $o->status = true;
         $o->success = true;
         $o->msg = G::LoadTranslation('ID_MAIL_TEST_SUCCESS');
     } else {
         $o->status = false;
         $o->success = false;
         $o->msg = $oSpool->error;
     }
     return $o;
 }
Ejemplo n.º 8
0
 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;
     }
 }