public function send_ajax() { // Check captcha to know we should do anything if (isset($_REQUEST['captcha'])) { $_SESSION['user_captcha'] = md5((int) $_REQUEST['captcha']); } if (!umiCaptcha::checkCaptcha()) { return $this->errorNewMessageCustom("%errors_wrong_captcha%", array('captcha')); } //------------------------------------------------------------------- // Get necessary data $oTypes = umiObjectTypesCollection::getInstance(); $iBaseTypeId = $oTypes->getBaseType("webforms", "form"); $iFormTypeId = getRequest('system_form_id'); $sSenderIP = getServer('REMOTE_ADDR'); $iTime = new umiDate(time()); $aAddresses = getRequest('system_email_to'); if (!is_array($aAddresses)) { $aAddresses = array($aAddresses); } $aRecipients = array(); foreach ($aAddresses as $address) { if ($address) { $sEmailTo = $this->guessAddressValue($address); $sAddress = $this->guessAddressName($address); $aRecipients[] = array('email' => $sEmailTo, 'name' => $sAddress); } } if (!$oTypes->isExists($iFormTypeId) || $oTypes->getParentClassId($iFormTypeId) != $iBaseTypeId) { return $this->errorNewMessageCustom("%wrong_form_type%"); } // if (($ef = $this->checkRequiredFieldsCustom($iFormTypeId)) !== true) { return $this->errorNewMessageCustom(getLabel('error-required_list') . $this->assembleErrorFields($ef), $this->assembleErrorFieldsArray($ef)); } //------------------------------------------------------------------- // Saving message and preparing it for sending $_REQUEST['data']['new']['sender_ip'] = $sSenderIP; // Hack for saving files-only-forms $oObjectsCollection = umiObjectsCollection::getInstance(); $iObjectId = $oObjectsCollection->addObject($sAddress, $iFormTypeId); $oObjectsCollection->getObject($iObjectId)->setOwnerId(permissionsCollection::getInstance()->getUserId()); cmsController::getInstance()->getModule('data')->saveEditedObject($iObjectId, true); $oObject = $oObjectsCollection->getObject($iObjectId); $oObject->setValue('destination_address', $sEmailTo); $oObject->setValue('sender_ip', $sSenderIP); $oObject->setValue('sending_time', $iTime); $aMessage = $this->formatMessage($iObjectId, true); //-------------------------------------------------------------------- // Make an e-mail $oMail = new umiMail(); //-------------------------------------------------------------------- // Determine file fields $aFTypes = array('file', 'img_file', 'swf_file'); $aFields = $oTypes->getType($oObject->getTypeId())->getAllFields(); foreach ($aFields as $oField) { $oType = $oField->getFieldType(); if (in_array($oType->getDataType(), $aFTypes)) { $oFile = $oObject->getValue($oField->getName()); if ($oFile instanceof umiFile) { $oMail->attachFile($oFile); } /*else { return $this->errorNewMessageCustom("%errors_wrong_file_type%"); }*/ } } $recpCount = 0; foreach ($aRecipients as $recipient) { foreach (explode(',', $recipient['email']) as $sAddress) { if (strlen(trim($sAddress))) { $oMail->addRecipient(trim($sAddress), $recipient['name']); $recpCount++; } } } if (!$recpCount) { return $this->errorNewMessageCustom(getLabel('error-no_recipients')); } $oMail->setFrom($aMessage['from_email_template'], $aMessage['from_template']); $oMail->setSubject($aMessage['subject_template']); $oMail->setContent($aMessage['master_template']); $oMail->commit(); $oMail->send(); //-------------------------------------------------------------------- // Send autoreply if should if (strlen($aMessage['autoreply_template'])) { $oMailReply = new umiMail(); $oMailReply->addRecipient($aMessage['from_email_template'], $aMessage['from_template']); $oMailReply->setFrom($aMessage['autoreply_from_email_template'], $aMessage['autoreply_from_template']); $oMailReply->setSubject($aMessage['autoreply_subject_template']); $oMailReply->setContent($aMessage['autoreply_template']); $oMailReply->commit(); $oMailReply->send(); } //-------------------------------------------------------------------- // Process events $oEventPoint = new umiEventPoint("webforms_post"); $oEventPoint->setMode("after"); $oEventPoint->setParam("email", $aMessage['from_email_template']); $oEventPoint->setParam("message_id", $iObjectId); $oEventPoint->setParam("form_id", $iFormTypeId); $oEventPoint->setParam("fio", $aMessage['from_template']); $this->setEventPoint($oEventPoint); //-------------------------------------------------------------------- return array('plain:result' => json_encode(array('success' => $this->posted($iFormTypeId)))); }
public function release_send() { $buffer = outputBuffer::current('HTTPOutputBuffer'); $buffer->charset('utf-8'); $buffer->contentType('text/xml'); $buffer->push('<?xml version="1.0" encoding="utf-8"?>'); $iDispId = (int) getRequest('param0'); $iReleaseId = $this->getNewReleaseInstanceId($iDispId); $arrPostData = getRequest("data_values"); $objectsColl = umiObjectsCollection::getinstance(); $controller = cmsController::getInstance(); $oDispatch = $objectsColl->getObject($iDispId); $oRelease = $objectsColl->getObject($iReleaseId); if (!$oDispatch instanceof umiObject || !$oRelease instanceof umiObject) { $buffer->push("<error>Не указан идентификатор рассылки</error>"); $buffer->end(); } if ($oRelease->getValue('status')) { $buffer->push("<error>Этот выпуск уже был отправлен</error>"); $buffer->end(); } $arrRecipients = array(); if (!getSession('umi_send_list_' . $iReleaseId)) { $sel = new selector('objects'); $sel->types("object-type")->name("dispatches", "subscriber"); $sel->where("subscriber_dispatches")->equals($iDispId); $sel->option('return')->value('id'); $sel->group("name"); foreach ($sel->result() as $recipient) { $arrRecipients[] = $recipient['id']; } $_SESSION['umi_send_list_' . $iReleaseId] = $arrRecipients; $_SESSION['umi_send_list_' . $iReleaseId . '_count'] = count($arrRecipients); } else { $arrRecipients = getSession('umi_send_list_' . $iReleaseId); } $delay = getSession('umi_send_list_' . $iReleaseId . '_delay'); $iTotal = (int) getSession('umi_send_list_' . $iReleaseId . '_count'); if ($delay and time() < $delay) { $iSended = $iTotal - count($arrRecipients); $sResult = <<<END <release dispatch="{$iDispId}"> \t<total>{$iTotal}</total> \t<sended>{$iSended}</sended> </release> END; $buffer->push($sResult); $buffer->end(); } $sHost = $controller->getCurrentDomain()->getHost(); $oMailer = new umiMail(); $arrMailBlocks = array(); $arrMailBlocks['header'] = $oDispatch->getName(); $arrMailBlocks['messages'] = ""; list($sReleaseFrm, $sMessageFrm) = def_module::loadTemplatesForMail("dispatches/release", "release_body", "release_message"); $sel = new selector('objects'); $sel->types("object-type")->name("dispatches", "message"); $sel->where("release_reference")->equals($iReleaseId); if ($sel->length()) { foreach ($sel->result() as $oNextMsg) { if ($oNextMsg instanceof umiObject) { $arrMsgBlocks = array(); $arrMsgBlocks['body'] = $oNextMsg->getValue('body'); $arrMsgBlocks['header'] = $oNextMsg->getValue('header'); $arrMailBlocks['messages'] .= def_module::parseTemplateForMail($sMessageFrm, $arrMsgBlocks, false, $oNextMsg->getId()); $oNextAttach = $oNextMsg->getValue('attach_file'); if ($oNextAttach instanceof umiFile && !$oNextAttach->getIsBroken()) { $oMailer->attachFile($oNextAttach); } } } } else { unset($_SESSION[$iDispId . '_new_templater']); $buffer->push("<error>В выпуске нет сообщений</error>"); $buffer->end(); } $oMailer->setFrom(regedit::getInstance()->getVal("//settings/email_from"), regedit::getInstance()->getVal("//settings/fio_from")); $oMailer->setSubject($arrMailBlocks['header']); $delay = 0; $max_messages = (int) mainConfiguration::getinstance()->get('modules', 'dispatches.max_messages_in_hour'); if ($max_messages && $iTotal >= $max_messages) { $delay = floor(3600 / $max_messages); } $aSended = array(); $iPacketSize = 5; //TODO: add to settings foreach ($arrRecipients as $recipient_id) { --$iPacketSize; $oNextMailer = clone $oMailer; $oNextSbs = new umiSubscriber($recipient_id); $sRecipientName = $oNextSbs->getValue('lname') . " " . $oNextSbs->getValue('fname') . " " . $oNextSbs->getValue('father_name'); $mail = $oNextSbs->getValue('email'); if (!strlen($mail)) { $mail = $oNextSbs->getName(); } $arrMailBlocks['unsubscribe_link'] = "http://" . $sHost . "/dispatches/unsubscribe/" . $oNextSbs->getId() . '/?email=' . $mail; $sMailBody = def_module::parseTemplateForMail($sReleaseFrm, $arrMailBlocks, false, $oNextSbs->getId()); $oNextMailer->setContent($sMailBody); $oNextMailer->addRecipient($mail, $sRecipientName); if (!(defined('CURRENT_VERSION_LINE') && CURRENT_VERSION_LINE == 'demo')) { $oNextMailer->commit(); $oNextMailer->send(); } $aSended[] = $recipient_id; //Unload temporary objects unset($oNextMailer); if ($iPacketSize === 0) { break; } if ($delay) { $_SESSION['umi_send_list_' . $iReleaseId . '_delay'] = $delay + time(); $_SESSION['umi_send_list_' . $iReleaseId] = array_diff($arrRecipients, $aSended); $iTotal = (int) getSession('umi_send_list_' . $iReleaseId . '_count'); $iSended = $iTotal - (count($arrRecipients) - count($aSended)); $sResult = <<<END <release dispatch="{$iDispId}"> \t<total>{$iTotal}</total> \t<sended>{$iSended}</sended> </release> END; $buffer->push($sResult); $buffer->end(); } } umiMail::clearFilesCache(); $_SESSION['umi_send_list_' . $iReleaseId] = array_diff($arrRecipients, $aSended); if (!count(getSession('umi_send_list_' . $iReleaseId))) { $oRelease->setValue('status', true); $oDate = new umiDate(time()); $oRelease->setValue('date', $oDate); $oRelease->setName($oDate->getFormattedDate('d-m-Y H:i')); $oRelease->commit(); $oDispatch->setValue('disp_last_release', $oDate); $oDispatch->commit(); } $iTotal = (int) getSession('umi_send_list_' . $iReleaseId . '_count'); $iSended = $iTotal - (count($arrRecipients) - count($aSended)); usleep(500000); $sResult = <<<END <release dispatch="{$iDispId}"> \t<total>{$iTotal}</total> \t<sended>{$iSended}</sended> </release> END; unset($_SESSION[$iDispId . '_new_templater']); $buffer->push($sResult); $buffer->end(); }
public function post() { if (defined('CURRENT_VERSION_LINE') && CURRENT_VERSION_LINE == 'demo') { $url = getRequest('ref_onsuccess'); if (!$url) { $url = $this->pre_lang . "/webforms/posted/"; } $this->redirect($url); } global $_FILES; $iOldErrorReportingLevel = error_reporting(~E_ALL & ~E_STRICT); $res = ""; $email_to = getRequest('email_to'); $message = getRequest('message'); $data = getRequest('data'); $domain = getRequest('domain'); $subject = cmsController::getInstance()->getCurrentDomain()->getHost(); $referer_url = $_SERVER['HTTP_REFERER']; $this->errorRegisterFailPage($referer_url); // check captcha if (isset($_REQUEST['captcha'])) { $_SESSION['user_captcha'] = md5((int) $_REQUEST['captcha']); } if (!umiCaptcha::checkCaptcha()) { $this->errorNewMessage("%errors_wrong_captcha%"); $this->errorPanic(); } $sRecipientName = "administrator"; if (is_numeric($email_to)) { $to = $this->guessAddressValue($email_to); if (intval($to) != $email_to) { $sRecipientName = $this->guessAddressName($email_to); } else { $oTCollection = umiObjectTypesCollection::getInstance(); $iTypeId = $oTCollection->getBaseType('webforms', 'address'); $oType = $oTCollection->getType($iTypeId); $iFieldId = $oType->getFieldId('insert_id'); $oSelection = new umiSelection(); $oSelection->addObjectType($iTypeId); $oSelection->addPropertyFilterEqual($iFieldId, $email_to); $aIDs = umiSelectionsParser::runSelection($oSelection); if (count($aIDs)) { $oObject = umiObjectsCollection::getInstance()->getObject($aIDs[0]); $to = $oObject->getValue('address_list'); $sRecipientName = $oObject->getValue('address_description'); } else { if (!defined("DB_DRIVER") || DB_DRIVER != "xml") { $sql = "SELECT email, descr FROM cms_webforms WHERE id={$email_to}"; $result = l_mysql_query($sql); list($to, $sRecipientName) = mysql_fetch_row($result); } else { $this->redirect($this->pre_lang . "/webforms/posted/?template=error_no_recipient"); } } } } else { $this->checkAddressExistence($email_to); $to = $email_to; } if (!$data['email_from'] && isset($data['email'])) { $data['email_from'] = $data['email']; } $someMail = new umiMail(); $arrMails = explode(",", $to); $arrMails = array_map("trim", $arrMails); foreach ($arrMails as $sEmail) { $someMail->addRecipient($sEmail, $sRecipientName); } $from = $data['fname'] . " " . $data['lname']; $someMail->setFrom($data['email_from'], $from); $mess = ""; if (is_array($data)) { if (isset($data['subject'])) { $subject = $data['subject']; } if (isset($data['fio'])) { $from = $data['fio']; } if ($data['fname'] || $data['lname'] || $data['mname']) { $from = $data['lname'] . " " . $data['fname'] . " " . $data['mname']; } if ($data['fio_frm']) { $from = $data['fio_frm']; } if ($email_from = $data['email_from']) { $email_from = $data['email_from']; } $mess = <<<END <table border="0" width="100%"> END; if (is_array($_FILES['data']['name'])) { $data = array_merge($data, $_FILES['data']['name']); } $uploadDir = CURRENT_WORKING_DIR . "/sys-temp/uploads"; if (!is_dir($uploadDir)) { mkdir($uploadDir); } $max_size = getBytesFromString(mainConfiguration::getInstance()->get('system', 'quota-files-and-images')); if ($max_size != 0) { $summary_size = getBusyDiskSize(array('/images', '/files', '/sys-temp/uploads')); } foreach ($data as $field => $cont) { if ($filename = $_FILES['data']['name'][$field]) { if ($max_size == 0 || $summary_size + $_FILES['data']['size'][$field] <= $max_size) { $file = umiFile::upload('data', $field, $uploadDir); if (!$file) { $this->errorNewMessage("%errors_wrong_file_type%"); $this->errorPanic(); } $someMail->attachFile($file); $summary_size += $_FILES['data']['size'][$field]; } else { $cont = def_module::parseTPLMacroses("%not_enough_space_for_load_file%"); } } if (!is_array($cont)) { $cont = str_replace("%", "%", $cont); } if (!$cont) { $cont = "—"; } if (is_array($cont)) { foreach ($cont as $i => $v) { $cont[$i] = str_replace("%", "%", $v); } $cont = implode(", ", $cont); } $label = $_REQUEST['labels'][$field] ? $_REQUEST['labels'][$field] : "%" . $field . "%"; $mess .= <<<END \t<tr> \t\t<td width="30%"> \t\t\t{$label}: \t\t</td> \t\t<td> \t\t\t{$cont} \t\t</td> \t</tr> END; } $mess .= <<<END </table> <hr /> END; } if ($from) { $user_fio_from = $from; } $message = str_replace("%", "%", $message); $mess .= nl2br($message); if (!$from) { $from = regedit::getInstance()->getVal("//settings/fio_from"); } if (!$from_email) { $from_email = regedit::getInstance()->getVal("//settings/email_from"); } $from = $from . "<" . $from_email . ">"; $someMail->setSubject($subject); $someMail->setContent($mess); $someMail->commit(); $someMail->send(); if ($template = (string) $_REQUEST['template']) { //Sending auto-reply list($template_mail, $template_mail_subject) = def_module::loadTemplatesForMail("webforms/" . $template, "webforms_reply_mail", "webforms_reply_mail_subject"); $template_mail = def_module::parseTemplateForMail($template_mail, $arr); $template_mail_subject = def_module::parseTemplateForMail($template_mail, $arr); $check_param = false; if (!is_array($template_mail)) { if ((bool) strlen($template_mail)) { $check_param = true; } } if ($check_param) { $email_from = regedit::getInstance()->getVal("//settings/email_from"); $fio_from = regedit::getInstance()->getVal("//settings/fio_from"); $replyMail = new umiMail(); $replyMail->addRecipient($data['email_from'], $from); $replyMail->setFrom($email_from, $fio_from); $replyMail->setSubject($template_mail_subject); $replyMail->setContent($template_mail); $replyMail->commit(); $replyMail->send(); } } $oEventPoint = new umiEventPoint("webforms_post"); $oEventPoint->setMode("after"); $oEventPoint->setParam("email", $data['email_from']); $oEventPoint->setParam("fio", $user_fio_from); $this->setEventPoint($oEventPoint); $url = getRequest('ref_onsuccess'); if (!$url) { $url = $this->pre_lang . "/webforms/posted/"; } if ($template) { $url .= (strpos($url, '?') === false ? '?' : '&') . "template=" . $template; } error_reporting($iOldErrorReportingLevel); $this->redirect($url); }