public function onDispatchChanges(iUmiEventPoint $oEvent) {
			$sTemplate = "default";

			try {
				list($sTemplateSubject, $sTemplateMessage) = def_module::loadTemplatesForMail("forum/mails/".$sTemplate, "mail_subject", "mail_message");
			} catch (publicException $e) {
				return false;
			}

			$iTopicId = $oEvent->getParam("topic_id");
			$iMessageId = $oEvent->getParam("message_id");
			$message = umiHierarchy::getInstance()->getElement($iMessageId);

			$sel = new selector('objects');
			$sel->types('object-type')->name("users", "user");
			$sel->where('subscribed_pages')->equals($iTopicId);
			
			if (!$sel->length()) return false;

			$hierarchy = umiHierarchy::getInstance();

			$block_arr = Array();

			$sTemplateSubject = def_module::parseTemplateForMail($sTemplateSubject, $block_arr, $iMessageId);
			
			$sFromEmail = regedit::getInstance()->getVal("//settings/email_from");
			$sFromFio = regedit::getInstance()->getVal("//settings/fio_from");

			$oMail = new umiMail();
			$oMail->setFrom($sFromEmail, $sFromFio);
			$oMail->setSubject($sTemplateSubject);

			foreach($sel->result() as $oUser) {
				$oMailUser = clone $oMail;
				$sUserMail = $oUser->getValue('e-mail');
				$block_arr['h1'] = $message->getValue('h1');
				$block_arr['message'] = $message->getValue('message');

				$hierarchy->forceAbsolutePath(true);
				$block_arr['unsubscribe_link'] = $hierarchy->getPathById($iTopicId) . "?unsubscribe=" . base64_encode($iUserId);
				$sTemplateMessageUser = def_module::parseTemplateForMail($sTemplateMessage, $block_arr, $iMessageId);
				$oMailUser->setContent($sTemplateMessageUser);
				$hierarchy->forceAbsolutePath(false);

				if (umiMail::checkEmail($sUserMail)) {
					$sUserFio = $oUser->getValue('lname') . " ". $oUser->getValue('fname') . " " . $oUser->getValue('father_name');
					$oMailUser->addRecipient($sUserMail, $sUserFio);
					$oMailUser->commit();
					$oMailUser->send();
				}
				else continue;
			}
			return true;
		}
 public function confirmUserAnswer($oElement)
 {
     $bConfirmUserAnswer = (bool) regedit::getInstance()->getVal("//modules/faq/confirm_user_answer");
     if (!$bConfirmUserAnswer) {
         return true;
     }
     if ($oElement instanceof umiHierarchyElement && $oElement->getIsActive()) {
         $iAuthorId = $oElement->getValue("author_id");
         $author_name = "";
         $author_email = "";
         $oAuthor = umiObjectsCollection::getInstance()->getObject($iAuthorId);
         if ($oAuthor instanceof umiObject) {
             $author_user = null;
             if ($oAuthor->getValue("is_registrated")) {
                 $user_id = $oAuthor->getValue("user_id");
                 $author_user = umiObjectsCollection::getInstance()->getObject($user_id);
             }
             if ($author_user instanceof umiObject) {
                 // author user
                 $author_name = $author_user->getValue("lname") . " " . $author_user->getValue("fname");
                 $author_email = $author_user->getValue("e-mail");
             } else {
                 // author guest
                 $author_name = $oAuthor->getValue("nickname");
                 $author_email = $oAuthor->getValue("email");
             }
         }
         if (umiMail::checkEmail($author_email)) {
             list($sMailSubject, $sMailBody) = def_module::loadTemplatesForMail("faq/default", "answer_mail_subj", "answer_mail");
             $block_arr = array();
             $block_arr['domain'] = $sDomain = $_SERVER['HTTP_HOST'];
             $block_arr['element_id'] = $iElementId = $oElement->getId();
             $block_arr['author_id'] = $oElement->getValue("author_id");
             $bOldFHStatus = umiHierarchy::getInstance()->forceAbsolutePath(true);
             $block_arr['question_link'] = umiHierarchy::getInstance()->getPathById($iElementId);
             umiHierarchy::getInstance()->forceAbsolutePath($bOldFHStatus);
             $block_arr['ticket'] = $iElementId;
             $sSubject = def_module::parseTemplateForMail($sMailSubject, $block_arr, $iElementId);
             $sBody = def_module::parseTemplateForMail($sMailBody, $block_arr, $iElementId);
             $from = regedit::getInstance()->getVal("//settings/fio_from");
             $from_email = regedit::getInstance()->getVal("//settings/email_from");
             $oMail = new umiMail();
             $oMail->addRecipient($author_email);
             $oMail->setFrom($from_email, $from);
             $oMail->setSubject($sSubject);
             $oMail->setContent($sBody);
             $oMail->commit();
         }
     }
     return true;
 }
 public function onCommentAdd(iUmiEventPoint $oEventPoint)
 {
     $regedit = regedit::getInstance();
     if (!$regedit->getVal("//modules/blogs20/notifications/on_comment_add")) {
         return;
     }
     $template = ($tmp = $oEventPoint->getParam('template')) ? $tmp : 'default';
     $commentId = $oEventPoint->getParam('id');
     $hierarchy = umiHierarchy::getInstance();
     $collection = umiObjectsCollection::getInstance();
     $parentId = $hierarchy->getElement($commentId, true)->getRel();
     $element = $hierarchy->getElement($parentId);
     $postHtypeId = umiHierarchyTypesCollection::getInstance()->getTypeByName('blogs20', 'post')->getId();
     $post = $element;
     if ($post instanceof umiHierarchyElement == false) {
         return false;
     }
     while ($post->getTypeId() != $postHtypeId) {
         $post = $hierarchy->getElement($post->getRel(), true);
     }
     if ($element->getTypeId() == $postHtypeId) {
         $parentOwner = $collection->getObject($element->getObject()->getOwnerId());
         if (!$parentOwner instanceof umiObject) {
             return false;
         }
         $email = $parentOwner->getValue('e-mail');
         $nick = $parentOwner->getValue('login');
         $fname = $parentOwner->getValue('fname');
         $lname = $parentOwner->getValue('lname');
         $patr = $parentOwner->getValue('father_name');
         $name = strlen($fname) ? $fname . ' ' . $patr . ' ' . $lname : $nick;
         list($tplSubject, $tplBody) = def_module::loadTemplatesForMail('blogs20/mail/' . $template, 'comment_for_post_subj', 'comment_for_post_body');
     } else {
         $parentOwner = $collection->getObject($element->getValue('author_id'));
         if ($parentOwner->getValue('is_registrated')) {
             $user = $collection->getObject($parentOwner->getValue('user_id'));
             $email = $user->getValue('e-mail');
             $nick = $user->getValue('login');
             $fname = $user->getValue('fname');
             $lname = $user->getValue('lname');
             $patr = $user->getValue('father_name');
             $name = strlen($fname) ? $fname . ' ' . $patr . ' ' . $lname : $nick;
         } else {
             $email = $parentOwner->getValue('email');
             $name = $parentOwner->getValue('nickname');
         }
         list($tplSubject, $tplBody) = def_module::loadTemplatesForMail('blogs20/mail/' . $template, 'comment_for_comment_subj', 'comment_for_comment_body');
     }
     $aParams = array();
     $aParams['name'] = $name;
     $aParams['link'] = 'http://' . cmsController::getInstance()->getCurrentDomain()->getHost() . $hierarchy->getPathById($post->getId()) . '#comment_' . $commentId;
     $subject = def_module::parseTemplateForMail($tplSubject, $aParams);
     $body = def_module::parseTemplateForMail($tplBody, $aParams);
     $fromEmail = $regedit->getVal("//settings/email_from");
     $fromName = $regedit->getVal("//settings/fio_from");
     $oMail = new umiMail();
     $oMail->addRecipient($email, $name);
     $oMail->setFrom($fromEmail, $fromName);
     $oMail->setSubject($subject);
     $oMail->setContent($body);
     $oMail->commit();
     $oMail->send();
 }
 private function parseContent()
 {
     $v9a0364b9e99bb480dd25e1f0284c8555 = $this->content;
     if (mainConfiguration::getInstance()->get('system', 'use-old-templater') && is_null(getRequest('scheme')) === false) {
         unset($_REQUEST['scheme']);
     }
     try {
         list($vb6b2481e9a1cb5fbe264662343183d95) = def_module::loadTemplatesForMail("mail/" . $this->template, "body");
     } catch (publicException $ve1671797c52e15f763380b45e841ec32) {
         $vb6b2481e9a1cb5fbe264662343183d95 = "%header%\n%content%";
     }
     $vfca1bff8ad8b3a8585abfb0ad523ba42 = array();
     $vfca1bff8ad8b3a8585abfb0ad523ba42['header'] = $this->subject;
     $vfca1bff8ad8b3a8585abfb0ad523ba42['content'] = $this->content;
     $vb01a74494194b212fcf94b6a6364e046 = def_module::parseTemplateForMail($vb6b2481e9a1cb5fbe264662343183d95, $vfca1bff8ad8b3a8585abfb0ad523ba42);
     $v52d3a7c11fa6e88478f6437456cc19af = array();
     $vb391d9fc0580b82c8487c853e5415c19 = array();
     if (preg_match_all('#<\\w+[^>]+\\s((?i)src|background|href(?-i))\\s*=\\s*(["\']?)?([\\w\\?=\\.\\-_:\\/]+.(jpeg|jpg|gif|png|bmp))\\2#i', $vb01a74494194b212fcf94b6a6364e046, $v020aae5ccf424487d5c7cecc391f9521)) {
         $v52d3a7c11fa6e88478f6437456cc19af = isset($v020aae5ccf424487d5c7cecc391f9521[3]) ? $v020aae5ccf424487d5c7cecc391f9521[3] : array();
     }
     if (preg_match_all('#(?i)url(?-i)\\(\\s*(["\']?)([\\w\\.\\-_:\\/]+.(jpeg|jpg|gif|png|bmp))\\1\\s*\\)#', $vb01a74494194b212fcf94b6a6364e046, $v020aae5ccf424487d5c7cecc391f9521)) {
         $vb391d9fc0580b82c8487c853e5415c19 = isset($v020aae5ccf424487d5c7cecc391f9521[2]) ? $v020aae5ccf424487d5c7cecc391f9521[2] : array();
     }
     $v34c033f0f84cdc7d18f8302893c97eeb = array_unique(array_merge($v52d3a7c11fa6e88478f6437456cc19af, $vb391d9fc0580b82c8487c853e5415c19));
     foreach ($v34c033f0f84cdc7d18f8302893c97eeb as $v28b569d3f9a3e63f94ca6fad969475f9) {
         $this->addHTMLImage($v28b569d3f9a3e63f94ca6fad969475f9);
     }
     $v61adcb2cd3bec191f3057b6c9bef9158 = cmsController::getInstance()->getCurrentDomain()->getHost();
     $vb01a74494194b212fcf94b6a6364e046 = preg_replace('#(href)\\s*=\\s*(["\']?)?(/([^\\s"\']+))#i', '$1=$2http://' . $v61adcb2cd3bec191f3057b6c9bef9158 . '$3', $vb01a74494194b212fcf94b6a6364e046);
     return $vb01a74494194b212fcf94b6a6364e046;
 }
 public function restore($activate_code = false, $template = "default")
 {
     static $result = array();
     if (isset($result[$template])) {
         return $result[$template];
     }
     list($template_restore_failed_block, $template_restore_ok_block, $template_mail_password, $template_mail_password_subject) = def_module::loadTemplatesForMail("users/forget/" . $template, "restore_failed_block", "restore_ok_block", "mail_password", "mail_password_subject");
     if (!$activate_code) {
         $activate_code = (string) getRequest('param0');
         $activate_code = trim($activate_code);
     }
     $object_type_id = umiObjectTypesCollection::getInstance()->getBaseType("users", "user");
     $object_type = umiObjectTypesCollection::getInstance()->getType($object_type_id);
     $activate_code_field_id = $object_type->getFieldId("activate_code");
     $sel = new selector('objects');
     $sel->types('object-type')->name('users', 'user');
     $sel->where('activate_code')->equals($activate_code);
     $sel->limit(0, 1);
     if ($sel->first) {
         $object = $sel->first;
         $user_id = $object->id;
     } else {
         $object = false;
         $user_id = false;
     }
     $block_arr = array();
     if ($user_id && $activate_code) {
         $password = self::getRandomPassword();
         $login = $object->getValue("login");
         $email = $object->getValue("e-mail");
         $fio = $object->getValue("lname") . " " . $object->getValue("fname") . " " . $object->getValue("father_name");
         $object->setValue("password", md5($password));
         $object->setValue("activate_code", "");
         $object->commit();
         $email_from = regedit::getInstance()->getVal("//settings/email_from");
         $fio_from = regedit::getInstance()->getVal("//settings/fio_from");
         $mail_arr = array();
         $mail_arr['domain'] = $domain = $_SERVER['HTTP_HOST'];
         $mail_arr['password'] = $password;
         $mail_arr['login'] = $login;
         $mail_subject = def_module::parseTemplateForMail($template_mail_password_subject, $mail_arr, false, $user_id);
         $mail_content = def_module::parseTemplateForMail($template_mail_password, $mail_arr, false, $user_id);
         $someMail = new umiMail();
         $someMail->addRecipient($email, $fio);
         $someMail->setFrom($email_from, $fio_from);
         $someMail->setSubject($mail_subject);
         $someMail->setContent($mail_content);
         $someMail->commit();
         $someMail->send();
         $block_arr['attribute:status'] = "success";
         $block_arr['login'] = $login;
         $block_arr['password'] = $password;
         return $result[$template] = def_module::parseTemplate($template_restore_ok_block, $block_arr, false, $user_id);
     } else {
         $block_arr['attribute:status'] = "fail";
         return $result[$template] = def_module::parseTemplate($template_restore_failed_block, $block_arr);
     }
 }
    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();
    }
Beispiel #7
0
	public function post_question() {

		$iPosted= getRequest('posted');
		if(is_null($tickets = getSession('tickets'))) {
			$tickets = $_SESSION['tickets'] = Array();
		}

		if ($iPosted) {
			$sPosted = getArrayKey($tickets, $iPosted);
			return $sPosted;
		}

		$referer_url = getServer('HTTP_REFERER');
		$this->errorRegisterFailPage($referer_url);

		$parent_element_id = (int) getRequest('param0');
		// input
		$email = htmlspecialchars(getRequest('email'));
		$nick = htmlspecialchars(getRequest('nick'));
		$title = htmlspecialchars(getRequest('title'));
		$question = htmlspecialchars(getRequest('question'));
		$ip = $_SERVER['REMOTE_ADDR'];

		if(!strlen($title)) {
			$this->errorNewMessage("%error_faq_required_title%");
			$this->errorPanic();
		}

		if(!strlen($question)) {
			$this->errorNewMessage("%error_faq_required_question%");
			$this->errorPanic();
		}

		if(!strlen($email)) {
			$users = cmsController::getInstance()->getModule("users");
			if($users instanceof def_module) {
				$user_id = $users->user_id;
				if($user = umiObjectsCollection::getInstance()->getObject($user_id)) {
					$email = $user->getValue('e-mail');
				}
			}
		}

		$referer_url = (string) $_SERVER['HTTP_REFERER'];
		$posttime = time();
		$ip = $_SERVER['REMOTE_ADDR'];

		if (isset($_REQUEST['captcha'])) {
			$_SESSION['user_captcha'] = md5((int) getRequest('captcha'));
		}

		if (!umiCaptcha::checkCaptcha()) {
			$this->errorNewMessage("%errors_wrong_captcha%");
			$this->errorPanic();
		}

		// before add event point
		$oEventPoint = new umiEventPoint("faq_post_question");
		$oEventPoint->setMode("before");
		$oEventPoint->setParam("parent_element_id", $parent_element_id);
		$oEventPoint->setParam("test_captcha", umiCaptcha::checkCaptcha());

		$this->setEventPoint($oEventPoint);

		// check captcha
		if (!umiCaptcha::checkCaptcha() || !$parent_element_id) {
			$this->redirect($referer_url);
		}

		$is_active = 0;

		if($oUsers = cmsController::getInstance()->getModule("users")) {
			if($oUsers->is_auth()) {
				$user_id = cmsController::getInstance()->getModule('users')->user_id;
				$iAuthorId = $oUsers->createAuthorUser($user_id);
				$is_active = $oUsers->isSv($user_id);
			} else {
				$iAuthorId = $oUsers->createAuthorGuest($nick, $email, $ip);
			}
		}

		$object_type_id = umiObjectTypesCollection::getInstance()->getBaseType("faq", "question");
		$hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("faq", "question")->getId();

		$parentElement = umiHierarchy::getInstance()->getElement($parent_element_id);
		$tpl_id		= $parentElement->getTplId();
		$domain_id	= $parentElement->getDomainId();
		$lang_id	= $parentElement->getLangId();

		$element_id = umiHierarchy::getInstance()->addElement($parent_element_id, $hierarchy_type_id, $title, $title, $object_type_id, $domain_id, $lang_id, $tpl_id);

		permissionsCollection::getInstance()->setDefaultPermissions($element_id);

		$element = umiHierarchy::getInstance()->getElement($element_id);

		$element->setIsActive(false);
		$element->setIsVisible(false);

		$element->setValue("question", $question);
		$element->setValue("publish_time", $posttime);

		$element->getObject()->setName($title);
		$element->setValue("h1", $title);

		$element->setValue("author_id", $iAuthorId);
		$element->commit();

		// send mails

		$from = regedit::getInstance()->getVal("//settings/fio_from");
		$from_email = regedit::getInstance()->getVal("//settings/email_from");
		$admin_email = regedit::getInstance()->getVal("//settings/admin_email");

		list(
			$confirm_mail_subj_user, $confirm_mail_user, $confirm_mail_subj_admin, $confirm_mail_admin
		) = def_module::loadTemplatesForMail("faq/default",
			"confirm_mail_subj_user", "confirm_mail_user", "confirm_mail_subj_admin", "confirm_mail_admin"
		);

		// for admin
		$mail_arr = Array();
		$mail_arr['domain'] = $domain = $_SERVER['HTTP_HOST'];
		$mail_arr['question'] = $question;
		$mail_arr['question_link'] = "http://" . $domain . $this->pre_lang. "/admin/faq/edit/" . $element_id . "/";
		$mail_adm_subj = def_module::parseTemplateForMail($confirm_mail_subj_admin, $mail_arr);
		$mail_adm_content = def_module::parseTemplateForMail($confirm_mail_admin, $mail_arr);

		$confirmAdminMail = new umiMail();
		$confirmAdminMail->addRecipient($admin_email);
		$confirmAdminMail->setFrom($email, $nick);
		$confirmAdminMail->setSubject($mail_adm_subj);
		$confirmAdminMail->setContent($mail_adm_content);
		$confirmAdminMail->commit();
		$confirmAdminMail->send();

		// for user
		$user_mail = Array();
		$user_mail['domain'] = $domain = $_SERVER['HTTP_HOST'];
		$user_mail['question'] = $question;
		$user_mail['ticket'] = $element_id;
		$mail_usr_subj = def_module::parseTemplateForMail($confirm_mail_subj_user, $user_mail);
		$mail_usr_content = def_module::parseTemplateForMail($confirm_mail_user, $user_mail);

		$confirmMail = new umiMail();
		$confirmMail->addRecipient($email);
		$confirmMail->setFrom($from_email, $from);
		$confirmMail->setSubject($mail_usr_subj);
		$confirmMail->setContent($mail_usr_content);
		$confirmMail->commit();
		$confirmMail->send();

		// after add event point
		$oEventPoint = new umiEventPoint("faq_post_question");
		$oEventPoint->setMode("after");
		$oEventPoint->setParam("element_id", $element_id);
		$this->setEventPoint($oEventPoint);

		$_SESSION['tickets'][$element_id] = $mail_usr_content;
		$this->redirect($this->pre_lang . '/faq/post_question/?posted=' . $element_id);
	}
		public function onRegisterAdminMail(iUmiEventPoint $oEventPoint) {
			$regedit = regedit::getInstance();
			$template = "default";

			if($oEventPoint->getMode() == "after") {
				list($template_mail, $template_mail_subject) = def_module::loadTemplatesForMail("users/register/".$template, "mail_admin_registrated", "mail_admin_registrated_subject");

				$email_to = $regedit->getVal("//settings/admin_email");
				$email_from = $regedit->getVal("//settings/email_from");
				$fio_from = $regedit->getVal("//settings/fio_from");

				$object_id = $oEventPoint->getParam('user_id');
				$login = $oEventPoint->getParam('login');

				$mail_arr = Array();
				$mail_arr['user_id'] = $object_id;
				if($login) {
					$mail_arr['login'] = $login;
				}
				$mail_subject = def_module::parseTemplateForMail($template_mail_subject, $mail_arr, false, $object_id);
				$mail_content = def_module::parseTemplateForMail($template_mail, $mail_arr, false, $object_id);

				$someMail = new umiMail();
				$someMail->addRecipient($email_to, $fio_from);
				$someMail->setFrom($email_from, $fio_from);
				$someMail->setSubject($mail_subject);
				$someMail->setContent($mail_content);
				$someMail->commit();
				$someMail->send();
			}
		}
 public function sendManagerNotification(order $order)
 {
     $regedit = regedit::getInstance();
     $cmsController = cmsController::getInstance();
     $domains = domainsCollection::getInstance();
     $domainId = $cmsController->getCurrentDomain()->getId();
     $defaultDomainId = $domains->getDefaultDomain()->getId();
     if ($regedit->getVal("//modules/emarket/manager-email/{$domainId}")) {
         $emails = $regedit->getVal("//modules/emarket/manager-email/{$domainId}");
         $fromMail = $regedit->getVal("//modules/emarket/from-email/{$domainId}");
         $fromName = $regedit->getVal("//modules/emarket/from-name/{$domainId}");
     } elseif ($regedit->getVal("//modules/emarket/manager-email/{$defaultDomainId}")) {
         $emails = $regedit->getVal("//modules/emarket/manager-email/{$defaultDomainId}");
         $fromMail = $regedit->getVal("//modules/emarket/from-email/{$defaultDomainId}");
         $fromName = $regedit->getVal("//modules/emarket/from-name/{$defaultDomainId}");
     } else {
         $emails = $regedit->getVal('//modules/emarket/manager-email');
         $fromMail = $regedit->getVal("//modules/emarket/from-email");
         $fromName = $regedit->getVal("//modules/emarket/from-name");
     }
     $letter = new umiMail();
     $recpCount = 0;
     foreach (explode(',', $emails) as $recipient) {
         $recipient = trim($recipient);
         if (strlen($recipient)) {
             $letter->addRecipient($recipient);
             $recpCount++;
         }
     }
     if (!$recpCount) {
         return;
     }
     list($template) = def_module::loadTemplatesForMail("emarket/mail/default", "neworder_notification");
     try {
         $payment = payment::get($order->payment_id);
         $paymentName = $payment->name;
         $paymentStatus = order::getCodeByStatus($order->getPaymentStatus());
     } catch (coreException $e) {
         $paymentName = "";
         $paymentStatus = "";
     }
     $param = array();
     $param["order_id"] = $order->id;
     $param["order_name"] = $order->name;
     $param["order_number"] = $order->number;
     $param["payment_type"] = $paymentName;
     $param["payment_status"] = $paymentStatus;
     $param["price"] = $order->getActualPrice();
     $param["domain"] = cmsController::getInstance()->getCurrentDomain()->getHost();
     $content = def_module::parseTemplateForMail($template, $param);
     $langs = cmsController::getInstance()->langs;
     $letter->setFrom($fromMail, $fromName);
     $letter->setSubject($langs['notification-neworder-subject'] . " (#{$order->number})");
     $letter->setContent($content);
     $letter->commit();
     $letter->send();
 }
 public function cronUnpublishPage($oEvent)
 {
     $object_type = umiObjectTypesCollection::getInstance()->getTypeByGUID('root-pages-type');
     $field_id = $object_type->getFieldId("expiration_date");
     $sel = new umiSelection();
     $sel->addPropertyFilterLess($field_id, time());
     $sel->addPropertyFilterNotEqual($field_id, 0);
     $sel->addActiveFilter(true);
     $sel->forceHierarchyTable(true);
     $result = umiSelectionsParser::runSelection($sel);
     $res = array();
     foreach ($result as $key => $page_id) {
         $ePage = umiHierarchy::getInstance()->getElement($page_id, true);
         $ePage->setIsActive(false);
         $pageObject = $ePage->getObject();
         $pageObject->setValue("publish_status", $this->getPageStatusIdByStatusSid("page_status_unpublish"));
         $pageObject->commit();
         $ePage->commit();
         if (!($publishComments = $ePage->getValue("publish_comments"))) {
             $publishComments = "Отсутствуют.";
         }
         $user_id = $ePage->getObject()->getOwnerId();
         $oUser = umiObjectsCollection::getInstance()->getObject($user_id);
         if ($oUser instanceof umiObject && ($user_email = $oUser->getValue("e-mail"))) {
             //Составляем и посылаем сообщение пользователю
             $mail_message = new umiMail();
             $from = regedit::getInstance()->getVal("//settings/email_from");
             $mail_message->setFrom($from);
             $mail_message->setPriorityLevel("high");
             $mail_message->setSubject(getLabel('label-notification-expired-mail-header'));
             list($body) = def_module::loadTemplatesForMail("mail/expired", "body");
             $block['notify_header'] = getLabel('label-notification-expired-mail-header');
             $block['page_header'] = $ePage->getName();
             $block['publish_comments'] = $publishComments;
             $domain = domainsCollection::getInstance()->getDomain($ePage->getDomainId());
             $page_host = "http://" . $domain->getHost() . umiHierarchy::getInstance()->getPathById($page_id);
             $block['page_link'] = $page_host;
             $mail_html = def_module::parseTemplateForMail($body, $block, $page_id);
             $mail_message->addRecipient($user_email);
             $mail_message->setContent($mail_html);
             $mail_message->commit();
             $mail_message->send();
         }
     }
 }
Beispiel #11
0
    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("%", "&#37;", $cont);
                }
                if (!$cont) {
                    $cont = "&mdash;";
                }
                if (is_array($cont)) {
                    foreach ($cont as $i => $v) {
                        $cont[$i] = str_replace("%", "&#37;", $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("%", "&#37;", $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);
    }
Beispiel #12
0
 protected function sendNotification()
 {
     $daysLeft = regedit::getInstance()->getVal("//modules/banners/days-before-notification");
     $daysLeft = $daysLeft * 24 * 3600;
     $viewsLeft = regedit::getInstance()->getVal("//modules/banners/clicks-before-notification");
     $items = array();
     $sel = new selector('objects');
     $sel->types('object-type')->name('banners', 'banner');
     foreach ($sel->result() as $banner) {
         $tillDate = toTimeStamp($banner->getValue('show_till_date'));
         $viewsCount = $banner->getValue('views_count');
         $maxViews = $banner->getValue('max_views');
         $days = false;
         $views = false;
         if ((int) $tillDate && time() + $daysLeft >= $tillDate) {
             $days = true;
         }
         if ((int) $maxViews && $viewsCount + $viewsLeft >= $maxViews) {
             $views = true;
         }
         if ($days || $views) {
             $bannerId = $banner->id;
             $bannerName = $banner->getName();
             $domain = domainsCollection::getInstance()->getDefaultDomain();
             $link = "http://" . $domain->getHost() . '/admin/banners/edit/' . $bannerId;
             list($templateLine) = def_module::loadTemplatesForMail("mail/banner_notification", "item");
             $itemArr['link'] = $link;
             $itemArr['bannerName'] = $bannerName;
             if ($days) {
                 $itemArr['tillDate'] = ' - срок показа истекает ' . $banner->getValue('show_till_date')->getFormattedDate() . '.';
             } elseif ($views) {
                 $itemArr['tillDate'] = ' - оставшееся количество показов: ' . ($maxViews - $viewsCount) . '.';
             } else {
                 $itemArr['tillDate'] = '';
             }
             $items[] = def_module::parseTemplateForMail($templateLine, $itemArr, false, $bannerId);
         }
     }
     if (count($items)) {
         $blockArr = array();
         list($subject, $template) = def_module::loadTemplatesForMail("mail/banner_notification", "subject", "body");
         $mailMessage = new umiMail();
         $from = regedit::getInstance()->getVal("//settings/email_from");
         $mailMessage->setFrom($from);
         $emailTo = regedit::getInstance()->getVal("//settings/admin_email");
         $mailMessage->addRecipient($emailTo);
         $mailMessage->setPriorityLevel("high");
         $subject = def_module::parseTemplateForMail($subject, $blockArr);
         $mailMessage->setSubject($subject);
         $blockArr['header'] = $subject;
         $blockArr['+items'] = $items;
         $content = def_module::parseTemplateForMail($template, $blockArr);
         $mailMessage->setContent($content);
         $mailMessage->commit();
         $mailMessage->send();
         regedit::getInstance()->setVal("//modules/banners/last-check-date", time());
     }
 }
Beispiel #13
0
 public function subscribe_do()
 {
     $sResult = "";
     // input
     $sSbsMail = trim(getRequest('sbs_mail'));
     $sSbsLName = getRequest('sbs_lname');
     $sSbsFName = getRequest('sbs_fname');
     $iSbsGender = (int) getRequest('sbs_gender');
     $sSbsFatherName = getRequest('sbs_father_name');
     $arrSbsDispatches = getRequest('subscriber_dispatches');
     if (is_array($arrSbsDispatches)) {
         $arrSbsDispatches = array_map('intval', $arrSbsDispatches);
     } else {
         $arrSbsDispatches = array();
     }
     $controller = cmsController::getInstance();
     $templater = $controller->getCurrentTemplater();
     $oSubscriber = null;
     // check user registred
     $this->is_auth = false;
     if ($oMdlUsers = $controller->getModule("users")) {
         if ($oMdlUsers->is_auth()) {
             $iUserId = (int) $oMdlUsers->user_id;
             $this->is_auth = true;
             $this->user_id = $iUserId;
             if ($oUserObj = umiObjectsCollection::getInstance()->getObject($iUserId)) {
                 $sSbsMail = $oUserObj->getValue("e-mail");
                 $sSbsLName = $oUserObj->getValue("lname");
                 $sSbsFName = $oUserObj->getValue("fname");
                 $sSbsFatherName = $oUserObj->getValue("father_name");
                 $iSbsGender = $oUserObj->getValue("gender");
             }
             $oSubscriber = self::getSubscriberByUserId($iUserId);
         } elseif (umiMail::checkEmail($sSbsMail)) {
             $oSubscriber = self::getSubscriberByMail($sSbsMail);
             $arrSbsDispatches = self::getAllDispatches();
         } else {
             $sResult = "%subscribe_incorrect_email%";
             return !def_module::isXSLTResultMode() ? $sResult : array("result" => $sResult);
         }
         if (!$oSubscriber instanceof umiObject && !empty($sSbsMail)) {
             $oSubscriber = self::getSubscriberByMail($sSbsMail);
         }
     } elseif (!umiMail::checkEmail($sSbsMail)) {
         $sResult = "%subscribe_incorrect_email%";
         return !def_module::isXSLTResultMode() ? $sResult : array("result" => $sResult);
     }
     if ($oSubscriber instanceof umiObject) {
         $iSbsObjId = $oSubscriber->getId();
         if (!$this->is_auth) {
             list($template_block) = def_module::loadTemplates("dispatches/default", "subscribe_guest_alredy_subscribed");
             $block_arr = array();
             $block_arr['unsubscribe_link'] = $this->pre_lang . "/dispatches/unsubscribe/" . $oSubscriber->getId() . "/?email=" . $oSubscriber->name;
             return def_module::parseTemplate($template_block, $block_arr);
         }
     } else {
         // create sbs
         $iSbsHierarchyTypeId = umiHierarchyTypesCollection::getInstance()->getTypeByName("dispatches", "subscriber")->getId();
         $iSbsTypeId = umiObjectTypesCollection::getInstance()->getTypeByHierarchyTypeId($iSbsHierarchyTypeId);
         $iSbsObjId = umiObjectsCollection::getInstance()->addObject($sSbsMail, $iSbsTypeId);
     }
     if (count($arrSbsDispatches)) {
         $from = regedit::getInstance()->getVal("//settings/fio_from");
         $from_email = regedit::getInstance()->getVal("//settings/email_from");
         list($template_mail, $template_mail_subject) = def_module::loadTemplatesForMail("dispatches/default", "subscribe_confirm", "subscribe_confirm_subject");
         $mail_arr = array();
         $mail_arr['domain'] = $domain = $_SERVER['HTTP_HOST'];
         $mail_arr['unsubscribe_link'] = "http://" . $domain . $this->pre_lang . "/dispatches/unsubscribe/" . $iSbsObjId . "/?email=" . $sSbsMail;
         $mail_subject = def_module::parseTemplateForMail($template_mail_subject, $mail_arr);
         $mail_content = def_module::parseTemplateForMail($template_mail, $mail_arr);
         $confirmMail = new umiMail();
         $confirmMail->addRecipient($sSbsMail);
         $confirmMail->setFrom($from_email, $from);
         $confirmMail->setSubject($mail_subject);
         $confirmMail->setContent($mail_content);
         $confirmMail->commit();
     }
     // try get object
     $oSubscriber = umiObjectsCollection::getInstance()->getObject($iSbsObjId);
     if ($oSubscriber instanceof umiObject) {
         $oSubscriber->setName($sSbsMail);
         $oSubscriber->setValue('lname', $sSbsLName);
         $oSubscriber->setValue('fname', $sSbsFName);
         $oSubscriber->setValue('father_name', $sSbsFatherName);
         $oCurrDate = new umiDate(time());
         $oSubscriber->setValue('subscribe_date', $oCurrDate);
         $oSubscriber->setValue('gender', $iSbsGender);
         if ($this->is_auth) {
             $oSubscriber->setValue('uid', $this->user_id);
             $oSubscriber->setValue('subscriber_dispatches', $arrSbsDispatches);
             $sDispForm = "%subscribe_subscribe_user%:<br /><ul>%rows%</ul>";
             $sDispFormRow = "<li>%disp_name%</li>";
             $sResult = self::parseDispatches($sDispForm, $sDispFormRow, $arrSbsDispatches, true);
         } else {
             // subscriber has all dispatches
             $oSubscriber->setValue('subscriber_dispatches', $arrSbsDispatches);
             $sResult = "%subscribe_subscribe%";
         }
         $oSubscriber->commit();
     }
     return !def_module::isXSLTResultMode() ? $sResult : array("result" => $sResult);
 }