Example #1
0
    public function generate($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $sTypeDocToGener = 'BOTH', $aProperties = array())
    {
        if ($sUID != '' && is_array($aFields) && $sPath != '') {
            $sContent = G::replaceDataGridField($sContent, $aFields);
            G::verifyPath($sPath, true);
            //Start - Create .doc
            $oFile = fopen($sPath . $sFilename . '.doc', 'wb');
            $size = array();
            $size["Letter"] = "216mm  279mm";
            $size["Legal"] = "216mm  357mm";
            $size["Executive"] = "184mm  267mm";
            $size["B5"] = "182mm  257mm";
            $size["Folio"] = "216mm  330mm";
            $size["A0Oversize"] = "882mm  1247mm";
            $size["A0"] = "841mm  1189mm";
            $size["A1"] = "594mm  841mm";
            $size["A2"] = "420mm  594mm";
            $size["A3"] = "297mm  420mm";
            $size["A4"] = "210mm  297mm";
            $size["A5"] = "148mm  210mm";
            $size["A6"] = "105mm  148mm";
            $size["A7"] = "74mm   105mm";
            $size["A8"] = "52mm   74mm";
            $size["A9"] = "37mm   52mm";
            $size["A10"] = "26mm   37mm";
            $size["Screenshot640"] = "640mm  480mm";
            $size["Screenshot800"] = "800mm  600mm";
            $size["Screenshot1024"] = "1024mm 768mm";
            $sizeLandscape["Letter"] = "279mm  216mm";
            $sizeLandscape["Legal"] = "357mm  216mm";
            $sizeLandscape["Executive"] = "267mm  184mm";
            $sizeLandscape["B5"] = "257mm  182mm";
            $sizeLandscape["Folio"] = "330mm  216mm";
            $sizeLandscape["A0Oversize"] = "1247mm 882mm";
            $sizeLandscape["A0"] = "1189mm 841mm";
            $sizeLandscape["A1"] = "841mm  594mm";
            $sizeLandscape["A2"] = "594mm  420mm";
            $sizeLandscape["A3"] = "420mm  297mm";
            $sizeLandscape["A4"] = "297mm  210mm";
            $sizeLandscape["A5"] = "210mm  148mm";
            $sizeLandscape["A6"] = "148mm  105mm";
            $sizeLandscape["A7"] = "105mm  74mm";
            $sizeLandscape["A8"] = "74mm   52mm";
            $sizeLandscape["A9"] = "52mm   37mm";
            $sizeLandscape["A10"] = "37mm   26mm";
            $sizeLandscape["Screenshot640"] = "480mm  640mm";
            $sizeLandscape["Screenshot800"] = "600mm  800mm";
            $sizeLandscape["Screenshot1024"] = "768mm  1024mm";
            if (!isset($aProperties['media'])) {
                $aProperties['media'] = 'Letter';
            }
            if ($sLandscape) {
                $media = $sizeLandscape[$aProperties['media']];
            } else {
                $media = $size[$aProperties['media']];
            }
            $marginLeft = '15';
            if (isset($aProperties['margins']['left'])) {
                $marginLeft = $aProperties['margins']['left'];
            }
            $marginRight = '15';
            if (isset($aProperties['margins']['right'])) {
                $marginRight = $aProperties['margins']['right'];
            }
            $marginTop = '15';
            if (isset($aProperties['margins']['top'])) {
                $marginTop = $aProperties['margins']['top'];
            }
            $marginBottom = '15';
            if (isset($aProperties['margins']['bottom'])) {
                $marginBottom = $aProperties['margins']['bottom'];
            }
            fwrite($oFile, '<html xmlns:v="urn:schemas-microsoft-com:vml"
            xmlns:o="urn:schemas-microsoft-com:office:office"
            xmlns:w="urn:schemas-microsoft-com:office:word"
            xmlns="http://www.w3.org/TR/REC-html40">
            <head>
            <meta http-equiv=Content-Type content="text/html; charset=utf-8">
            <meta name=ProgId content=Word.Document>
            <meta name=Generator content="Microsoft Word 9">
            <meta name=Originator content="Microsoft Word 9">
            <!--[if !mso]>
            <style>
            v\\:* {behavior:url(#default#VML);}
            o\\:* {behavior:url(#default#VML);}
            w\\:* {behavior:url(#default#VML);}
            .shape {behavior:url(#default#VML);}
            </style>
            <![endif]-->
            <!--[if gte mso 9]><xml>
             <w:WordDocument>
              <w:View>Print</w:View>
              <w:DoNotHyphenateCaps/>
              <w:PunctuationKerning/>
              <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing>
              <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing>
             </w:WordDocument>
            </xml><![endif]-->

            <style>
            <!--
            @page WordSection1
             {size:' . $media . ';
             margin-left:' . $marginLeft . 'mm;
             margin-right:' . $marginRight . 'mm;
             margin-bottom:' . $marginBottom . 'mm;
             margin-top:' . $marginTop . 'mm;
             mso-header-margin:35.4pt;
             mso-footer-margin:35.4pt;
             mso-paper-source:0;}
            div.WordSection1
             {page:WordSection1;}
            -->
            </style>
            </head>
            <body>
            <div class=WordSection1>');
            fwrite($oFile, $sContent);
            fwrite($oFile, "\n</div></body></html>\n\n");
            fclose($oFile);
            /* End - Create .doc */
            if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') {
                $oFile = fopen($sPath . $sFilename . '.html', 'wb');
                fwrite($oFile, $sContent);
                fclose($oFile);
                /* Start - Create .pdf */
                if (isset($aProperties['report_generator'])) {
                    switch ($aProperties['report_generator']) {
                        case 'TCPDF':
                            $this->generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
                            break;
                        case 'HTML2PDF':
                        default:
                            $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
                            break;
                    }
                } else {
                    $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
                }
            }
            //end if $sTypeDocToGener
            /* End - Create .pdf */
        } else {
            return PEAR::raiseError(null, G_ERROR_USER_UID, null, null, 'You tried to call to a generate method without send the Output Document UID, fields to use and the file path!', 'G_Error', true);
        }
    }
Example #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() );

        }

    }
Example #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;

        }

    }
Example #4
0
 public function sendNotifications($sCurrentTask, $aTasks, $aFields, $sApplicationUID, $iDelegation, $sFrom = "")
 {
     try {
         $applicationData = $this->loadCase($sApplicationUID);
         $aFields["APP_NUMBER"] = $applicationData["APP_NUMBER"];
         $oConfiguration = new Configuration();
         $sDelimiter = DBAdapter::getStringDelimiter();
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(ConfigurationPeer::CFG_UID, 'Emails');
         $oCriteria->add(ConfigurationPeer::OBJ_UID, '');
         $oCriteria->add(ConfigurationPeer::PRO_UID, '');
         $oCriteria->add(ConfigurationPeer::USR_UID, '');
         $oCriteria->add(ConfigurationPeer::APP_UID, '');
         if (ConfigurationPeer::doCount($oCriteria) == 0) {
             $oConfiguration->create(array('CFG_UID' => 'Emails', 'OBJ_UID' => '', 'CFG_VALUE' => '', 'PRO_UID' => '', 'USR_UID' => '', 'APP_UID' => ''));
             $aConfiguration = array();
         } else {
             $aConfiguration = $oConfiguration->load('Emails', '', '', '', '');
             if ($aConfiguration['CFG_VALUE'] != '') {
                 $aConfiguration = unserialize($aConfiguration["CFG_VALUE"]);
                 $passwd = $aConfiguration["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);
                     }
                 }
                 $aConfiguration["MESS_PASSWORD"] = $passwd;
             } else {
                 $aConfiguration = array();
             }
         }
         if (!isset($aConfiguration['MESS_ENABLED']) || $aConfiguration['MESS_ENABLED'] != '1') {
             return false;
         }
         //Send derivation notification - Start
         $oTask = new Task();
         $aTaskInfo = $oTask->load($sCurrentTask);
         if ($aTaskInfo['TAS_SEND_LAST_EMAIL'] != 'TRUE') {
             return false;
         }
         if ($sFrom == '') {
             $sFrom = '"ProcessMaker"';
         }
         $hasEmailFrom = preg_match('/(.+)@(.+)\\.(.+)/', $sFrom, $match);
         if (!$hasEmailFrom || strpos($sFrom, $aConfiguration['MESS_ACCOUNT']) === false) {
             if ($aConfiguration['MESS_ENGINE'] != 'MAIL' && $aConfiguration['MESS_ACCOUNT'] != '') {
                 $sFrom .= ' <' . $aConfiguration['MESS_ACCOUNT'] . '>';
             } else {
                 if ($aConfiguration['MESS_ENGINE'] == 'MAIL') {
                     $sFrom .= ' <info@' . gethostbyaddr('127.0.0.1') . '>';
                 } else {
                     if ($aConfiguration['MESS_SERVER'] != '') {
                         if ($sAux = @gethostbyaddr($aConfiguration['MESS_SERVER'])) {
                             $sFrom .= ' <info@' . $sAux . '>';
                         } else {
                             $sFrom .= ' <info@' . $aConfiguration['MESS_SERVER'] . '>';
                         }
                     } else {
                         $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);
         } else {
             $sBody = nl2br(G::replaceDataGridField($aTaskInfo["TAS_DEF_MESSAGE"], $aFields));
         }
         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 . "unassignedMessage.html";
                         if (!file_exists($fileTemplate)) {
                             @copy(PATH_TPL . "mails" . PATH_SEP . "unassignedMessage.html", $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();
                 if ($aConfiguration['MESS_RAUTH'] == false || is_string($aConfiguration['MESS_RAUTH']) && $aConfiguration['MESS_RAUTH'] == 'false') {
                     $aConfiguration['MESS_RAUTH'] = 0;
                 } else {
                     $aConfiguration['MESS_RAUTH'] = 1;
                 }
                 $oSpool->setConfig(array("MESS_ENGINE" => $aConfiguration["MESS_ENGINE"], "MESS_SERVER" => $aConfiguration["MESS_SERVER"], "MESS_PORT" => $aConfiguration["MESS_PORT"], "MESS_ACCOUNT" => $aConfiguration["MESS_ACCOUNT"], "MESS_PASSWORD" => $aConfiguration["MESS_PASSWORD"], "SMTPAuth" => $aConfiguration["MESS_RAUTH"] == "1" ? true : false, "SMTPSecure" => isset($aConfiguration["SMTPSecure"]) ? $aConfiguration["SMTPSecure"] : ""));
                 $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"));
                 if ($aConfiguration["MESS_BACKGROUND"] == "" || $aConfiguration["MESS_TRY_SEND_INMEDIATLY"] == "1") {
                     $oSpool->sendMail();
                 }
             }
         }
         //Send derivation notification - End
     } catch (Exception $oException) {
         throw $oException;
     }
 }
Example #5
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
  * @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());
     }
 }
Example #6
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;
     }
 }