Changeset View
Changeset View
Standalone View
Standalone View
core/units/forms/forms/forms_eh.php
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Line(s) | |||||
* Enter description here... | * Enter description here... | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnFormSubmit($event) | protected function OnFormSubmit($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$fields = explode(',',$this->Application->GetVar('fields')); | $fields = explode(',',$this->Application->GetVar('fields')); | ||||
$required_fields = explode(',', $this->Application->GetVar('required_fields')); | $required_fields = explode(',', $this->Application->GetVar('required_fields')); | ||||
$fields_params = $this->Application->GetVar('fields_params'); | $fields_params = $this->Application->GetVar('fields_params'); | ||||
$virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields'); | $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields'); | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Validates POP3 settings (performs test connect) | * Validates POP3 settings (performs test connect) | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function _validatePopSettings($event) | function _validatePopSettings($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$modes = Array ('Reply', 'Bounce'); | $modes = Array ('Reply', 'Bounce'); | ||||
$fields = Array ('Server', 'Port', 'Username', 'Password'); | $fields = Array ('Server', 'Port', 'Username', 'Password'); | ||||
$changed_fields = array_keys( $object->GetChangedFields() ); | $changed_fields = array_keys( $object->GetChangedFields() ); | ||||
foreach ($modes as $mode) { | foreach ($modes as $mode) { | ||||
$set = true; | $set = true; | ||||
$changed = false; | $changed = false; | ||||
Show All 14 Lines | |||||
if ($set && $changed) { | if ($set && $changed) { | ||||
// fields are set and at least on of them is changed | // fields are set and at least on of them is changed | ||||
$connection_info = Array (); | $connection_info = Array (); | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
$connection_info[ strtolower($field) ] = $object->GetDBField($mode . $field); | $connection_info[ strtolower($field) ] = $object->GetDBField($mode . $field); | ||||
} | } | ||||
/** @var POP3Helper $pop3_helper */ | |||||
$pop3_helper = $this->Application->makeClass('POP3Helper', Array ($connection_info, 10)); | $pop3_helper = $this->Application->makeClass('POP3Helper', Array ($connection_info, 10)); | ||||
Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $pop3_helper POP3Helper */ | |||||
switch ( $pop3_helper->initMailbox(true) ) { | switch ( $pop3_helper->initMailbox(true) ) { | ||||
case 'socket': | case 'socket': | ||||
$object->SetError($mode . 'Server', 'connection_failed'); | $object->SetError($mode . 'Server', 'connection_failed'); | ||||
break; | break; | ||||
case 'login': | case 'login': | ||||
$object->SetError($mode . 'Username', 'login_failed'); | $object->SetError($mode . 'Username', 'login_failed'); | ||||
Show All 10 Lines | |||||
/** | /** | ||||
* Makes email communication fields required, when form uses email communication | * Makes email communication fields required, when form uses email communication | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function _setRequired($event) | function _setRequired($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$required = $object->GetDBField('EnableEmailCommunication'); | $required = $object->GetDBField('EnableEmailCommunication'); | ||||
$fields = Array ( | $fields = Array ( | ||||
'ReplyFromName', 'ReplyFromEmail', 'ReplyServer', 'ReplyPort', 'ReplyUsername', 'ReplyPassword', | 'ReplyFromName', 'ReplyFromEmail', 'ReplyServer', 'ReplyPort', 'ReplyUsername', 'ReplyPassword', | ||||
); | ); | ||||
if ($required && $object->GetDBField('BounceEmail')) { | if ($required && $object->GetDBField('BounceEmail')) { | ||||
$bounce_fields = Array ('BounceEmail', 'BounceServer', 'BouncePort', 'BounceUsername', 'BouncePassword'); | $bounce_fields = Array ('BounceEmail', 'BounceServer', 'BouncePort', 'BounceUsername', 'BouncePassword'); | ||||
$fields = array_merge($fields, $bounce_fields); | $fields = array_merge($fields, $bounce_fields); | ||||
} | } | ||||
$object->setRequired($fields, $required); | $object->setRequired($fields, $required); | ||||
} | } | ||||
/** | /** | ||||
* Don't use security image, when form requires login | * Don't use security image, when form requires login | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function _disableSecurityImage($event) | function _disableSecurityImage($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ($object->GetDBField('RequireLogin')) { | if ($object->GetDBField('RequireLogin')) { | ||||
$object->SetDBField('UseSecurityImage', 0); | $object->SetDBField('UseSecurityImage', 0); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Queries pop3 server about new incoming mail | * Queries pop3 server about new incoming mail | ||||
Show All 28 Lines | |||||
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); | $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); | ||||
$table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); | $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); | ||||
$sql = 'SELECT * | $sql = 'SELECT * | ||||
FROM ' . $table_name . ' | FROM ' . $table_name . ' | ||||
WHERE EnableEmailCommunication = 1'; | WHERE EnableEmailCommunication = 1'; | ||||
$forms = $this->Conn->Query($sql, $id_field); | $forms = $this->Conn->Query($sql, $id_field); | ||||
/** @var MailboxHelper $mailbox_helper */ | |||||
$mailbox_helper = $this->Application->recallObject('MailboxHelper'); | $mailbox_helper = $this->Application->recallObject('MailboxHelper'); | ||||
/* @var $mailbox_helper MailboxHelper */ | |||||
$field_prefix = $bounce_mode ? 'Bounce' : 'Reply'; | $field_prefix = $bounce_mode ? 'Bounce' : 'Reply'; | ||||
foreach ($forms as $form_id => $form_info) { | foreach ($forms as $form_id => $form_info) { | ||||
$recipient_email = $bounce_mode ? $form_info['BounceEmail'] : $form_info['ReplyFromEmail']; | $recipient_email = $bounce_mode ? $form_info['BounceEmail'] : $form_info['ReplyFromEmail']; | ||||
if (!$recipient_email) { | if (!$recipient_email) { | ||||
continue; | continue; | ||||
Show All 14 Lines | |||||
'form_info' => $form_info, | 'form_info' => $form_info, | ||||
) | ) | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
function isValidRecipient($params) | function isValidRecipient($params) | ||||
{ | { | ||||
/** @var MailboxHelper $mailbox_helper */ | |||||
$mailbox_helper = $this->Application->recallObject('MailboxHelper'); | $mailbox_helper = $this->Application->recallObject('MailboxHelper'); | ||||
/* @var $mailbox_helper MailboxHelper */ | |||||
$recipients = $mailbox_helper->getRecipients(); | $recipients = $mailbox_helper->getRecipients(); | ||||
$recipient_email = $params['recipient_email']; | $recipient_email = $params['recipient_email']; | ||||
$emails_found = preg_match_all('/((' . REGEX_EMAIL_USER . ')(@' . REGEX_EMAIL_DOMAIN . '))/i', $recipients, $all_emails); | $emails_found = preg_match_all('/((' . REGEX_EMAIL_USER . ')(@' . REGEX_EMAIL_DOMAIN . '))/i', $recipients, $all_emails); | ||||
if (is_array($all_emails)) { | if (is_array($all_emails)) { | ||||
for ($i = 0; $i < $emails_found; $i++) { | for ($i = 0; $i < $emails_found; $i++) { | ||||
Show All 15 Lines | |||||
return false; | return false; | ||||
} | } | ||||
function processEmail($params, &$fields_hash) | function processEmail($params, &$fields_hash) | ||||
{ | { | ||||
if ($params['bounce_mode']) { | if ($params['bounce_mode']) { | ||||
// mark original message as bounced | // mark original message as bounced | ||||
/** @var MailboxHelper $mailbox_helper */ | |||||
$mailbox_helper = $this->Application->recallObject('MailboxHelper'); | $mailbox_helper = $this->Application->recallObject('MailboxHelper'); | ||||
/* @var $mailbox_helper MailboxHelper */ | |||||
if (!array_key_exists('attachments', $mailbox_helper->parsedMessage)) { | if (!array_key_exists('attachments', $mailbox_helper->parsedMessage)) { | ||||
// for now only parse bounces based on attachments, skip other bounce types | // for now only parse bounces based on attachments, skip other bounce types | ||||
return false; | return false; | ||||
} | } | ||||
for ($i = 0; $i < count($mailbox_helper->parsedMessage['attachments']); $i++) { | for ($i = 0; $i < count($mailbox_helper->parsedMessage['attachments']); $i++) { | ||||
$attachment =& $mailbox_helper->parsedMessage['attachments'][$i]; | $attachment =& $mailbox_helper->parsedMessage['attachments'][$i]; | ||||
switch ($attachment['headers']['content-type']) { | switch ($attachment['headers']['content-type']) { | ||||
case 'message/delivery-status': | case 'message/delivery-status': | ||||
// save as BounceInfo | // save as BounceInfo | ||||
Inline comments must end in full-stops, exclamation marks, or question marks Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
/** @var MimeDecodeHelper $mime_decode_helper */ | |||||
$mime_decode_helper = $this->Application->recallObject('MimeDecodeHelper'); | $mime_decode_helper = $this->Application->recallObject('MimeDecodeHelper'); | ||||
/* @var $mime_decode_helper MimeDecodeHelper */ | |||||
$charset = $mailbox_helper->parsedMessage[ $fields_hash['MessageType'] ][0]['charset']; | $charset = $mailbox_helper->parsedMessage[ $fields_hash['MessageType'] ][0]['charset']; | ||||
$fields_hash['Message'] = $mime_decode_helper->convertEncoding($charset, $attachment['data']); | $fields_hash['Message'] = $mime_decode_helper->convertEncoding($charset, $attachment['data']); | ||||
break; | break; | ||||
case 'message/rfc822': | case 'message/rfc822': | ||||
// undelivered message | // undelivered message | ||||
$fields_hash['Subject'] = $attachment['filename2'] ? $attachment['filename2'] : $attachment['filename']; | $fields_hash['Subject'] = $attachment['filename2'] ? $attachment['filename2'] : $attachment['filename']; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
$submission_fields[ 'fld_' . $form_fields[$role]['FormFieldId'] ] = $fields_hash[$email_field]; | $submission_fields[ 'fld_' . $form_fields[$role]['FormFieldId'] ] = $fields_hash[$email_field]; | ||||
} | } | ||||
} | } | ||||
if ($submission_fields) { | if ($submission_fields) { | ||||
// remove object, because it's linked to single form upon creation forever | // remove object, because it's linked to single form upon creation forever | ||||
$this->Application->removeObject('formsubs.-item'); | $this->Application->removeObject('formsubs.-item'); | ||||
/** @var kDBItem $form_submission */ | |||||
$form_submission = $this->Application->recallObject('formsubs.-item', null, Array ('skip_autoload' => true)); | $form_submission = $this->Application->recallObject('formsubs.-item', null, Array ('skip_autoload' => true)); | ||||
Line exceeds 120 characters; contains 129 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 129 characters | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $form_submission kDBItem */ | |||||
// in case that other non-role mapped fields are required | // in case that other non-role mapped fields are required | ||||
$form_submission->IgnoreValidation = true; | $form_submission->IgnoreValidation = true; | ||||
$form_submission->SetDBFieldsFromHash($submission_fields); | $form_submission->SetDBFieldsFromHash($submission_fields); | ||||
$form_submission->SetDBField('FormId', $form_id); | $form_submission->SetDBField('FormId', $form_id); | ||||
$form_submission->SetDBField('MessageId', $fields_hash['MessageId']); | $form_submission->SetDBField('MessageId', $fields_hash['MessageId']); | ||||
$form_submission->SetDBField('SubmissionTime_date', adodb_mktime()); | $form_submission->SetDBField('SubmissionTime_date', adodb_mktime()); | ||||
$form_submission->SetDBField('SubmissionTime_time', adodb_mktime()); | $form_submission->SetDBField('SubmissionTime_time', adodb_mktime()); | ||||
Show All 10 Lines | |||||
WHERE MessageId = ' . $this->Conn->qstr($fields_hash['MessageId']); | WHERE MessageId = ' . $this->Conn->qstr($fields_hash['MessageId']); | ||||
$found = $this->Conn->GetOne($sql); | $found = $this->Conn->GetOne($sql); | ||||
if ($found) { | if ($found) { | ||||
// don't process same message twice | // don't process same message twice | ||||
return false; | return false; | ||||
} | } | ||||
/** @var kDBItem $reply_to */ | |||||
$reply_to = $this->Application->recallObject('submission-log.-reply-to', null, Array ('skip_autoload' => true)); | $reply_to = $this->Application->recallObject('submission-log.-reply-to', null, Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $reply_to kDBItem */ | |||||
$reply_to->Load($regs[2], 'VerifyCode'); | $reply_to->Load($regs[2], 'VerifyCode'); | ||||
if (!$reply_to->isLoaded()) { | if (!$reply_to->isLoaded()) { | ||||
// fake verification code OR feedback, containing submission log was deleted | // fake verification code OR feedback, containing submission log was deleted | ||||
return false; | return false; | ||||
} | } | ||||
if ($params['bounce_mode']) { | if ($params['bounce_mode']) { | ||||
// mark original message as bounced | // mark original message as bounced | ||||
$reply_to->SetDBField('BounceInfo', $fields_hash['Message']); | $reply_to->SetDBField('BounceInfo', $fields_hash['Message']); | ||||
$reply_to->SetDBField('BounceDate_date', TIMENOW); | $reply_to->SetDBField('BounceDate_date', TIMENOW); | ||||
$reply_to->SetDBField('BounceDate_time', TIMENOW); | $reply_to->SetDBField('BounceDate_time', TIMENOW); | ||||
$reply_to->SetDBField('SentStatus', SUBMISSION_LOG_BOUNCE); | $reply_to->SetDBField('SentStatus', SUBMISSION_LOG_BOUNCE); | ||||
$reply_to->Update(); | $reply_to->Update(); | ||||
return true; | return true; | ||||
} | } | ||||
/** @var kDBItem $reply */ | |||||
$reply = $this->Application->recallObject('submission-log.-reply', null, Array ('skip_autoload' => true)); | $reply = $this->Application->recallObject('submission-log.-reply', null, Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $reply kDBItem */ | |||||
$reply->SetDBFieldsFromHash($fields_hash); | $reply->SetDBFieldsFromHash($fields_hash); | ||||
$reply->SetDBField('ReplyTo', $reply_to->GetID()); | $reply->SetDBField('ReplyTo', $reply_to->GetID()); | ||||
$reply->SetDBField('FormSubmissionId', $reply_to->GetDBField('FormSubmissionId')); | $reply->SetDBField('FormSubmissionId', $reply_to->GetDBField('FormSubmissionId')); | ||||
$reply->SetDBField('ToEmail', $params['recipient_email']); | $reply->SetDBField('ToEmail', $params['recipient_email']); | ||||
$reply->SetDBField('Subject', $regs[1]); // save subject without verification code | $reply->SetDBField('Subject', $regs[1]); // save subject without verification code | ||||
$reply->SetDBField('SentStatus', SUBMISSION_LOG_SENT); | $reply->SetDBField('SentStatus', SUBMISSION_LOG_SENT); | ||||
return $reply->Create(); | return $reply->Create(); | ||||
} | } | ||||
} | } |
PHP keywords must be lowercase; expected "array" but found "Array"