2015-03-12 18:04:39 -04:00
< ? php
2018-10-19 17:01:49 -04:00
use ProcessMaker\Core\System ;
2017-08-11 11:10:27 -04:00
2017-08-11 11:53:15 -04:00
class ActionsByEmailCoreClass extends PMPlugin
2015-03-12 18:04:39 -04:00
{
public function __construct ()
{
}
public function setup ()
{
2016-07-27 16:37:21 -04:00
2015-03-12 18:04:39 -04:00
}
public function getFieldsForPageSetup ()
{
return array ();
}
public function updateFieldsForPageSetup ()
{
}
2016-11-21 18:01:37 -04:00
/**
2019-02-13 15:53:21 -04:00
* Send Actions By Email .
*
* @ global object $RBAC
* @ param object $data
* @ param array $dataAbe
* @ return type
2016-11-21 18:01:37 -04:00
* @ throws Exception
2019-02-13 15:53:21 -04:00
*
* @ see AppDelegation -> createAppDelegation ()
* @ link https :// wiki . processmaker . com / 3.3 / Actions_by_Email
2016-11-21 18:01:37 -04:00
*/
public function sendActionsByEmail ( $data , $dataAbe )
2015-03-12 18:04:39 -04:00
{
try {
// Validations
2015-06-15 10:17:14 -04:00
try {
if ( ! is_object ( $data )) {
throw new Exception ( 'The parameter $data is null.' );
}
if ( ! isset ( $data -> TAS_UID )) {
throw new Exception ( 'The parameter $data->TAS_UID is null.' );
}
if ( ! isset ( $data -> APP_UID )) {
throw new Exception ( 'The parameter $data->APP_UID is null.' );
}
if ( ! isset ( $data -> DEL_INDEX )) {
throw new Exception ( 'The parameter $data->DEL_INDEX is null.' );
}
if ( ! isset ( $data -> USR_UID )) {
throw new Exception ( 'The parameter $data->USR_UID is null.' );
}
2016-04-26 15:11:02 -04:00
if ( $data -> TAS_UID === '' ) {
2015-06-15 10:17:14 -04:00
throw new Exception ( 'The parameter $data->TAS_UID is empty.' );
}
2016-04-26 15:11:02 -04:00
if ( $data -> APP_UID === '' ) {
2015-06-15 10:17:14 -04:00
throw new Exception ( 'The parameter $data->APP_UID is empty.' );
}
2016-04-26 15:11:02 -04:00
if ( $data -> DEL_INDEX === '' ) {
2015-06-15 10:17:14 -04:00
throw new Exception ( 'The parameter $data->DEL_INDEX is empty.' );
}
2016-04-26 15:11:02 -04:00
if ( $data -> DEL_INDEX === 1 ) {
error_log ( 'The parameter $data->DEL_INDEX is 1, you can not use ActionsByEmail in the initial task' , 0 );
return ;
}
if ( $data -> USR_UID === '' ) {
2015-09-21 13:02:43 -04:00
error_log ( 'The parameter $data->USR_UID is empty, the routed task may be a self-service type, actions by email does not work with self-service task types.' , 0 );
2015-06-15 10:17:14 -04:00
}
} catch ( Exception $e ) {
2016-07-27 16:37:21 -04:00
$token = strtotime ( " now " );
PMException :: registerErrorLog ( $e , $token );
G :: outRes ( G :: LoadTranslation ( " ID_EXCEPTION_LOG_INTERFAZ " , array ( $token )) );
2015-09-21 13:02:43 -04:00
die ;
2015-03-12 18:04:39 -04:00
}
2016-11-21 18:01:37 -04:00
$emailServer = new \ProcessMaker\BusinessModel\EmailServer ();
2017-04-07 18:10:29 -04:00
$emailSetup = ( ! is_null ( \EmailServerPeer :: retrieveByPK ( $dataAbe [ 'ABE_EMAIL_SERVER_UID' ]))) ?
2016-11-21 18:01:37 -04:00
$emailServer -> getEmailServer ( $dataAbe [ 'ABE_EMAIL_SERVER_UID' ], true ) :
$emailServer -> getEmailServerDefault ();
2015-03-12 18:04:39 -04:00
if ( ! empty ( $emailSetup )) {
$cases = new Cases ();
2018-04-04 09:21:59 -04:00
$caseFields = $cases -> loadCase ( $data -> APP_UID , $data -> DEL_INDEX );
$actionEmailTable = new AbeConfiguration ();
$configuration = $actionEmailTable -> getTaskConfiguration ( $caseFields [ 'PRO_UID' ], $data -> TAS_UID );
$caseFields [ 'APP_DATA' ][ 'PRO_ID' ] = $configuration [ 'PRO_ID' ];
$caseFields [ 'APP_DATA' ][ 'TAS_ID' ] = $configuration [ 'TAS_ID' ];
if ( ! empty ( $configuration )) {
2015-03-12 18:04:39 -04:00
$configuration [ 'ABE_EMAIL_FIELD' ] = str_replace ( '@@' , '' , $configuration [ 'ABE_EMAIL_FIELD' ]);
if ( $configuration [ 'ABE_EMAIL_FIELD' ] != '' && isset ( $caseFields [ 'APP_DATA' ][ $configuration [ 'ABE_EMAIL_FIELD' ]])) {
$email = trim ( $caseFields [ 'APP_DATA' ][ $configuration [ 'ABE_EMAIL_FIELD' ]]);
} else {
$userInstance = new Users ();
$userInfo = $userInstance -> getAllInformation ( $data -> USR_UID );
$email = $userInfo [ 'mail' ];
}
if ( $email != '' ) {
2019-07-01 11:49:26 -04:00
$subject = G :: replaceDataField ( $configuration [ 'ABE_SUBJECT_FIELD' ], $caseFields [ 'APP_DATA' ], 'mysql' , false );
2015-04-23 17:40:12 -04:00
if ( $subject == '' ){
$subject = $caseFields [ 'APP_TITLE' ];
}
2015-03-12 18:04:39 -04:00
$abeRequest = array ();
$abeRequest [ 'ABE_REQ_UID' ] = '' ;
$abeRequest [ 'ABE_UID' ] = $configuration [ 'ABE_UID' ];
$abeRequest [ 'APP_UID' ] = $data -> APP_UID ;
$abeRequest [ 'DEL_INDEX' ] = $data -> DEL_INDEX ;
$abeRequest [ 'ABE_REQ_SENT_TO' ] = $email ;
$abeRequest [ 'ABE_REQ_SUBJECT' ] = $subject ;
$abeRequest [ 'ABE_REQ_BODY' ] = '' ;
$abeRequest [ 'ABE_REQ_ANSWERED' ] = 0 ;
$abeRequest [ 'ABE_REQ_STATUS' ] = 'PENDING' ;
try {
$abeRequestsInstance = new AbeRequests ();
$abeRequest [ 'ABE_REQ_UID' ] = $abeRequestsInstance -> createOrUpdate ( $abeRequest );
} catch ( Exception $error ) {
throw $error ;
}
if ( $configuration [ 'ABE_TYPE' ] != '' ) {
// Email
$_SESSION [ 'CURRENT_DYN_UID' ] = $configuration [ 'DYN_UID' ];
$__ABE__ = '' ;
2018-10-19 17:01:49 -04:00
$link = System :: getServerMainPath () . '/services/ActionsByEmail' ;
2015-03-12 18:04:39 -04:00
switch ( $configuration [ 'ABE_TYPE' ]) {
2015-11-23 15:15:57 -04:00
case 'CUSTOM' :
$customGrid = unserialize ( $configuration [ 'ABE_CUSTOM_GRID' ]);
$variableService = new \ProcessMaker\Services\Api\Project\Variable ();
$variables = $variableService -> doGetVariables ( $caseFields [ 'PRO_UID' ]);
$field = new stdClass ();
$field -> label = '' ;
2017-01-10 17:32:11 -04:00
$actionField = str_replace ( array ( '@@' , '@#' , '@=' , '@%' , '@?' , '@$' ), '' , $configuration [ 'ABE_ACTION_FIELD' ]);
2017-02-14 21:24:08 +00:00
2017-08-11 15:49:39 -04:00
$obj = new PmDynaform ( $configuration [ 'DYN_UID' ]);
2015-11-23 15:15:57 -04:00
$configuration [ 'CURRENT_DYNAFORM' ] = $configuration [ 'DYN_UID' ];
$file = $obj -> printPmDynaformAbe ( $configuration );
$__ABE__ .= $file ;
2017-01-12 09:37:54 -04:00
$__ABE__ .= '<div style="width: 100%"></div><strong>' . $field -> label . '</strong><table align="left" border="0"><tr>' ;
2015-11-23 15:15:57 -04:00
$index = 1 ;
2017-01-10 17:32:11 -04:00
$__ABE__ .= '<td><table align="left" cellpadding="2"><tr>' ;
2016-07-11 15:58:34 -04:00
foreach ( $customGrid as $key => $value ) {
2017-01-10 17:32:11 -04:00
$__ABE__ .= '<td align="center"><a style="' . $value [ 'abe_custom_format' ] . '" ' ;
2017-11-24 13:39:33 -04:00
$__ABE__ .= 'href="' . urldecode ( urlencode ( $link )) . '?ACTION=' . G :: encrypt ( 'processABE' , URL_KEY , true ) . '&APP_UID=' ;
$__ABE__ .= G :: encrypt ( $data -> APP_UID , URL_KEY , true ) . '&DEL_INDEX=' . G :: encrypt ( $data -> DEL_INDEX , URL_KEY );
$__ABE__ .= '&FIELD=' . G :: encrypt ( $actionField , URL_KEY , true ) . '&VALUE=' . G :: encrypt ( $value [ 'abe_custom_value' ], URL_KEY , true );
$__ABE__ .= '&ABER=' . G :: encrypt ( $abeRequest [ 'ABE_REQ_UID' ], URL_KEY , true ) . '" target="_blank" >' . $value [ 'abe_custom_label' ];
2015-11-23 15:15:57 -04:00
$__ABE__ .= '</a></td>' . (( $index % 5 == 0 ) ? '</tr><tr>' : ' ' );
$index ++ ;
}
2017-01-12 09:37:54 -04:00
$__ABE__ .= '</tr></table></div>' ;
2015-11-23 15:15:57 -04:00
break ;
2015-03-12 18:04:39 -04:00
case 'LINK' :
2017-11-24 13:39:33 -04:00
$__ABE__ .= '<a href="' . $link . 'DataForm?APP_UID=' . G :: encrypt ( $data -> APP_UID , URL_KEY , true ) . '&DEL_INDEX=' . G :: encrypt ( $data -> DEL_INDEX , URL_KEY , true ) . '&DYN_UID=' . G :: encrypt ( $configuration [ 'DYN_UID' ], URL_KEY , true ) . '&ABER=' . G :: encrypt ( $abeRequest [ 'ABE_REQ_UID' ], URL_KEY , true ) . '" target="_blank">Please complete this form</a>' ;
2015-03-12 18:04:39 -04:00
break ;
// coment
case 'FIELD' :
$variableService = new \ProcessMaker\Services\Api\Project\Variable ();
$variables = $variableService -> doGetVariables ( $caseFields [ 'PRO_UID' ]);
$field = new stdClass ();
$field -> label = 'Test' ;
$field -> type = 'dropdown' ;
$field -> options = array ();
2015-12-04 12:42:49 -04:00
$field -> value = '' ;
2015-11-23 15:15:57 -04:00
$actionField = str_replace ( array ( '@@' , '@#' , '@=' , '@%' , '@?' , '@$' ), '' , $configuration [ 'ABE_ACTION_FIELD' ]);
2015-04-28 12:36:33 -04:00
$dynaform = $configuration [ 'DYN_UID' ];
$variables = G :: json_decode ( $configuration [ 'DYN_CONTENT' ], true );
if ( isset ( $variables [ 'items' ][ 0 ][ 'items' ])){
$fields = $variables [ 'items' ][ 0 ][ 'items' ];
foreach ( $fields as $key => $value ) {
2016-03-15 10:21:53 -04:00
foreach ( $value as $var ){
2015-04-28 12:36:33 -04:00
if ( isset ( $var [ 'variable' ])){
if ( $var [ 'variable' ] == $actionField ) {
$field -> label = $var [ 'label' ];
$field -> type = $var [ 'type' ];
$values = $var [ 'options' ];
foreach ( $values as $val ){
$field -> options [ $val [ 'value' ]] = $val [ 'value' ];
}
}
}
2015-03-12 18:04:39 -04:00
}
}
}
2017-02-14 21:24:08 +00:00
2017-08-11 15:49:39 -04:00
$obj = new PmDynaform ( $configuration [ 'DYN_UID' ]);
2015-04-28 16:21:45 -04:00
$configuration [ 'CURRENT_DYNAFORM' ] = $configuration [ 'DYN_UID' ];
$file = $obj -> printPmDynaformAbe ( $configuration );
$__ABE__ .= $file ;
2015-03-12 18:04:39 -04:00
$__ABE__ .= '<strong>' . $field -> label . '</strong><br /><table align="left" border="0"><tr>' ;
switch ( $field -> type ) {
case 'dropdown' :
2016-03-11 16:18:52 -04:00
case 'radio' :
2015-03-12 18:04:39 -04:00
case 'radiogroup' :
$index = 1 ;
$__ABE__ .= '<br /><td><table align="left" cellpadding="2"><tr>' ;
foreach ( $field -> options as $optValue => $optName ) {
$__ABE__ .= '<td align="center"><a style="text-decoration: none; color: #000; background-color: #E5E5E5; ' ;
$__ABE__ .= 'filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#EFEFEF, endColorstr=#BCBCBC); ' ;
$__ABE__ .= 'background-image: -webkit-gradient(linear, left top, left bottom, from(#EFEFEF), #BCBCBC); ' ;
$__ABE__ .= 'background-image: -webkit-linear-gradient(top, #EFEFEF, #BCBCBC); ' ;
$__ABE__ .= 'background-image: -moz-linear-gradient(top, #EFEFEF, #BCBCBC); background-image: -ms-linear-gradient(top, #EFEFEF, #BCBCBC); ' ;
$__ABE__ .= 'background-image: -o-linear-gradient(top, #EFEFEF, #BCBCBC); border: 1px solid #AAAAAA; ' ;
$__ABE__ .= 'border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); ' ;
$__ABE__ .= 'font-family: Arial,serif; font-size: 9pt; font-weight: 400; line-height: 14px; margin: 2px 0; padding: 2px 7px; ' ;
2017-11-24 13:39:33 -04:00
$__ABE__ .= 'text-decoration: none; text-transform: capitalize;" href="' . urldecode ( urlencode ( $link )) . '?ACTION=' . G :: encrypt ( 'processABE' , URL_KEY , true ) . '&APP_UID=' ;
$__ABE__ .= G :: encrypt ( $data -> APP_UID , URL_KEY , true ) . '&DEL_INDEX=' . G :: encrypt ( $data -> DEL_INDEX , URL_KEY , true );
$__ABE__ .= '&FIELD=' . G :: encrypt ( $actionField , URL_KEY , true ) . '&VALUE=' . G :: encrypt ( $optValue , URL_KEY , true );
$__ABE__ .= '&ABER=' . G :: encrypt ( $abeRequest [ 'ABE_REQ_UID' ], URL_KEY , true ) . '" target="_blank" >' . $optName ;
2015-03-12 18:04:39 -04:00
$__ABE__ .= '</a></td>' . (( $index % 5 == 0 ) ? '</tr><tr>' : ' ' );
$index ++ ;
}
$__ABE__ .= '</tr></table></td>' ;
break ;
case 'yesno' :
2017-11-24 13:39:33 -04:00
$__ABE__ .= '<td align="center"><a href="' . $link . '?ACTION=' . G :: encrypt ( 'processABE' , URL_KEY , true ) . '&APP_UID=' . urlencode ( G :: encrypt ( $data -> APP_UID , URL_KEY , true )) . '&DEL_INDEX=' . urlencode ( G :: encrypt ( $data -> DEL_INDEX , URL_KEY , true )) . '&FIELD=' . urlencode ( G :: encrypt ( $actionField , URL_KEY , true )) . '&VALUE=' . urlencode ( G :: encrypt ( 1 , URL_KEY , true )) . '&ABER=' . urlencode ( G :: encrypt ( $abeRequest [ 'ABE_REQ_UID' ], URL_KEY , true , true )) . '" target="_blank">' . G :: LoadTranslation ( 'ID_YES_VALUE' ) . '</a></td>' ;
$__ABE__ .= '<td align="center"><a href="' . $link . '?ACTION=' . G :: encrypt ( 'processABE' , URL_KEY , true ) . '&APP_UID=' . urlencode ( G :: encrypt ( $data -> APP_UID , URL_KEY , true )) . '&DEL_INDEX=' . urlencode ( G :: encrypt ( $data -> DEL_INDEX , URL_KEY , true )) . '&FIELD=' . urlencode ( G :: encrypt ( $actionField , URL_KEY , true )) . '&VALUE=' . urlencode ( G :: encrypt ( 0 , URL_KEY , true )) . '&ABER=' . urlencode ( G :: encrypt ( $abeRequest [ 'ABE_REQ_UID' ], URL_KEY , true , true )) . '" target="_blank">' . G :: LoadTranslation ( 'ID_NO_VALUE' ) . '</a></td>' ;
2015-03-12 18:04:39 -04:00
break ;
case 'checkbox' :
2017-11-24 13:39:33 -04:00
$__ABE__ .= '<td align="center"><a href="' . $link . '?ACTION=' . G :: encrypt ( 'processABE' , URL_KEY , true ) . '&APP_UID=' . G :: encrypt ( $data -> APP_UID , URL_KEY , true ) . '&DEL_INDEX=' . G :: encrypt ( $data -> DEL_INDEX , URL_KEY , true ) . '&FIELD=' . G :: encrypt ( $actionField , URL_KEY , true ) . '&VALUE=' . G :: encrypt ( $field -> value , URL_KEY , true ) . '&ABER=' . G :: encrypt ( $abeRequest [ 'ABE_REQ_UID' ], URL_KEY , true ) . '" target="_blank">Check</a></td>' ;
$__ABE__ .= '<td align="center"><a href="' . $link . '?ACTION=' . G :: encrypt ( 'processABE' , URL_KEY , true ) . '&APP_UID=' . G :: encrypt ( $data -> APP_UID , URL_KEY , true ) . '&DEL_INDEX=' . G :: encrypt ( $data -> DEL_INDEX , URL_KEY , true ) . '&FIELD=' . G :: encrypt ( $actionField , URL_KEY , true ) . '&VALUE=' . G :: encrypt ( $field -> value , URL_KEY , true ) . '&ABER=' . G :: encrypt ( $abeRequest [ 'ABE_REQ_UID' ], URL_KEY , true ) . '" target="_blank">Uncheck</a></td>' ;
2015-03-12 18:04:39 -04:00
break ;
}
$__ABE__ .= '</tr></table>' ;
break ;
}
$__ABE__ = preg_replace ( '/\<img src=\"\/js\/maborak\/core\/images\/(.+?)\>/' , '' , $__ABE__ );
$__ABE__ = preg_replace ( '/\<input\b[^>]*\/>/' , '' , $__ABE__ );
$__ABE__ = preg_replace ( '/<select\b[^>]*>(.*?)<\/select>/is' , " " , $__ABE__ );
$__ABE__ = preg_replace ( '/align=\"center\"/' , '' , $__ABE__ );
$__ABE__ = preg_replace ( '/class="tableGrid_view" /' , 'class="tableGrid_view" width="100%" ' , $__ABE__ );
$caseFields [ 'APP_DATA' ][ '__ABE__' ] = $__ABE__ ;
$user = new Users ();
2019-02-13 15:53:21 -04:00
$emailFrom = '' ;
2016-08-12 11:29:30 -04:00
if ( ! $configuration [ 'ABE_MAILSERVER_OR_MAILCURRENT' ] && $configuration [ 'ABE_TYPE' ] !== '' ) {
if ( $data -> PREVIOUS_USR_UID !== '' ) {
2016-07-11 15:58:34 -04:00
$userDetails = $user -> loadDetails ( $data -> PREVIOUS_USR_UID );
$emailFrom = ( $userDetails [ " USR_FULLNAME " ] . ' <' . $userDetails [ " USR_EMAIL " ] . '>' );
} else {
global $RBAC ;
2019-02-13 15:53:21 -04:00
if ( $RBAC != null && is_array ( $RBAC -> aUserInfo [ 'USER_INFO' ])) {
$currentUser = $RBAC -> aUserInfo [ 'USER_INFO' ];
$emailFrom = ( $currentUser [ " USR_FIRSTNAME " ] . ' ' . $currentUser [ " USR_LASTNAME " ] . ' <' . $currentUser [ " USR_EMAIL " ] . '>' );
} else {
$usersPeer = UsersPeer :: retrieveByPK ( $data -> USR_UID );
if ( ! empty ( $usersPeer )) {
$emailFrom = ( $usersPeer -> getUsrFirstname () . ' ' . $usersPeer -> getUsrLastname () . ' <' . $usersPeer -> getUsrEmail () . '>' );
}
}
2016-07-11 15:58:34 -04:00
}
2016-08-12 11:29:30 -04:00
} else {
if ( isset ( $emailSetup [ " MESS_FROM_NAME " ]) && isset ( $emailSetup [ " MESS_FROM_MAIL " ])) {
2015-09-21 13:02:43 -04:00
$emailFrom = ( $emailSetup [ " MESS_FROM_NAME " ] . ' <' . $emailSetup [ " MESS_FROM_MAIL " ] . '>' );
2016-08-12 11:29:30 -04:00
} else {
2015-09-21 13:02:43 -04:00
$emailFrom = (( isset ( $emailSetup [ " MESS_FROM_NAME " ])) ? $emailSetup [ " MESS_FROM_NAME " ] : $emailSetup [ " MESS_FROM_MAIL " ]);
}
}
2016-07-11 15:58:34 -04:00
2017-08-11 14:10:44 -04:00
$wsBaseInstance = new WsBase ();
2016-08-12 11:29:30 -04:00
$result = $wsBaseInstance -> sendMessage (
$data -> APP_UID ,
$emailFrom ,
$email ,
'' ,
'' ,
$subject ,
$configuration [ 'ABE_TEMPLATE' ],
$caseFields [ 'APP_DATA' ],
2016-11-21 18:01:37 -04:00
null ,
true ,
2018-04-04 09:21:59 -04:00
$data -> DEL_INDEX ,
2016-11-21 18:01:37 -04:00
$emailSetup ,
2019-03-29 10:00:39 -04:00
0 ,
WsBase :: MESSAGE_TYPE_ACTIONS_BY_EMAIL
2016-11-21 18:01:37 -04:00
);
2015-03-12 18:04:39 -04:00
$abeRequest [ 'ABE_REQ_STATUS' ] = ( $result -> status_code == 0 ? 'SENT' : 'ERROR' );
$body = '' ;
$messageSent = executeQuery ( 'SELECT `APP_MSG_BODY` FROM `APP_MESSAGE` ORDER BY `APP_MSG_SEND_DATE` DESC LIMIT 1' );
if ( ! empty ( $messageSent ) && is_array ( $messageSent )) {
$body = $messageSent [ 1 ][ 'APP_MSG_BODY' ];
}
$abeRequest [ 'ABE_REQ_BODY' ] = $body ;
// Update
try {
$abeRequestsInstance = new AbeRequests ();
$abeRequestsInstance -> createOrUpdate ( $abeRequest );
} catch ( Exception $error ) {
throw $error ;
}
}
}
}
}
} catch ( Exception $error ) {
throw $error ;
}
}
}