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.'); } if ($data->TAS_UID === '') { throw new Exception('The parameter $data->TAS_UID is empty.'); } if ($data->APP_UID === '') { throw new Exception('The parameter $data->APP_UID is empty.'); } if ($data->DEL_INDEX === '') { throw new Exception('The parameter $data->DEL_INDEX is empty.'); } 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 === '') { 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); } } catch(Exception $e) { $token = strtotime("now"); PMException::registerErrorLog($e, $token); G::outRes( G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) ); die; } $emailServer = new \ProcessMaker\BusinessModel\EmailServer(); $emailSetup = (!is_null(\EmailServerPeer::retrieveByPK($dataAbe['ABE_EMAIL_SERVER_UID']))) ? $emailServer->getEmailServer($dataAbe['ABE_EMAIL_SERVER_UID'], true) : $emailServer->getEmailServerDefault(); if (!empty($emailSetup)) { $cases = new Cases(); $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)) { $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 != '') { $subject = G::replaceDataField( $configuration['ABE_SUBJECT_FIELD'], $caseFields['APP_DATA'] ); if($subject == ''){ $subject = $caseFields['APP_TITLE']; } $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__ = ''; $link = System::getServerMainPath() . '/services/ActionsByEmail'; switch ($configuration['ABE_TYPE']) { 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 = ''; $actionField = str_replace(array('@@', '@#', '@=', '@%', '@?', '@$'), '', $configuration['ABE_ACTION_FIELD']); $obj = new PmDynaform($configuration['DYN_UID']); $configuration['CURRENT_DYNAFORM'] = $configuration['DYN_UID']; $file = $obj->printPmDynaformAbe($configuration); $__ABE__ .= $file; $__ABE__ .= '
' . $field->label . ''; $index = 1; $__ABE__ .= '
'; foreach ($customGrid as $key => $value) { $__ABE__ .= '' . (($index % 5 == 0) ? '' : ' '); $index++; } $__ABE__ .= '
' . $value['abe_custom_label']; $__ABE__ .= '
'; break; case 'LINK': $__ABE__ .= 'Please complete this form'; 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(); $field->value = ''; $actionField = str_replace(array('@@','@#','@=','@%','@?','@$'), '', $configuration['ABE_ACTION_FIELD']); $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) { foreach($value as $var){ 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']; } } } } } } $obj = new PmDynaform($configuration['DYN_UID']); $configuration['CURRENT_DYNAFORM'] = $configuration['DYN_UID']; $file = $obj->printPmDynaformAbe($configuration); $__ABE__ .= $file; $__ABE__ .= '' . $field->label . '
'; switch ($field->type) { case 'dropdown': case 'radio': case 'radiogroup': $index = 1; $__ABE__.='
'; break; case 'yesno': $__ABE__ .= ''; $__ABE__ .= ''; break; case 'checkbox': $__ABE__ .= ''; $__ABE__ .= ''; break; } $__ABE__ .= '
'; foreach ($field->options as $optValue => $optName) { $__ABE__ .= '' . (($index % 5 == 0) ? '' : ' '); $index++; } $__ABE__.='
' . $optName; $__ABE__ .= '
' . G::LoadTranslation('ID_YES_VALUE') . '' . G::LoadTranslation('ID_NO_VALUE') . 'CheckUncheck
'; break; } $__ABE__ = preg_replace('/\/', '' , $__ABE__); $__ABE__ = preg_replace('/\]*\/>/', '' , $__ABE__); $__ABE__ = preg_replace('/]*>(.*?)<\/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(); if (!$configuration['ABE_MAILSERVER_OR_MAILCURRENT'] && $configuration['ABE_TYPE'] !== '') { if ($data->PREVIOUS_USR_UID !== '') { $userDetails = $user->loadDetails($data->PREVIOUS_USR_UID); $emailFrom = ($userDetails["USR_FULLNAME"] . ' <' . $userDetails["USR_EMAIL"] . '>'); } else { global $RBAC; $currentUser = $RBAC->aUserInfo['USER_INFO']; $emailFrom = ($currentUser["USR_FIRSTNAME"] . ' ' . $currentUser["USR_LASTNAME"] . ' <' . $currentUser["USR_EMAIL"] . '>'); } } else { if (isset($emailSetup["MESS_FROM_NAME"]) && isset($emailSetup["MESS_FROM_MAIL"])) { $emailFrom = ($emailSetup["MESS_FROM_NAME"] . ' <' . $emailSetup["MESS_FROM_MAIL"] . '>'); } else { $emailFrom = ((isset($emailSetup["MESS_FROM_NAME"])) ? $emailSetup["MESS_FROM_NAME"] : $emailSetup["MESS_FROM_MAIL"]); } } $wsBaseInstance = new WsBase(); $result = $wsBaseInstance->sendMessage( $data->APP_UID, $emailFrom, $email, '', '', $subject, $configuration['ABE_TEMPLATE'], $caseFields['APP_DATA'], null, true, $data->DEL_INDEX, $emailSetup, 0 ); $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; } } }