Skip to content
Code-Schnipsel Gruppen Projekte
contact.php 3,16 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    
    /**
     * This file contains package_quiqqer_bricks_ajax_contact
     */
    
    /**
     * Returns the Brick data
     *
     * @param {String|Integer} $brickId - Brick-ID
     *
     * @return array
     */
    QUI::$Ajax->registerFunction(
        'package_quiqqer_bricks_ajax_contact',
    
        function ($brickId, $project, $siteId, $message, $name, $email, $privacyPolicyAccepted) {
    
            // check if email correct
            if (!QUI\Utils\Security\Orthos::checkMailSyntax($email)) {
                throw new QUI\Exception(
                    QUI::getLocale()->get(
    
                        'quiqqer/bricks',
                        'brick.control.simpleContact.error.wrongEmail'
    
            $BrickManager          = QUI\Bricks\Manager::init();
            $Project               = QUI::getProjectManager()->decode($project);
            $Site                  = $Project->get((int)$siteId);
            $privacyPolicyCheckbox = boolval($Site->getAttribute('quiqqer.settings.sitetypes.contact.showPrivacyPolicyCheckbox'));
    
            if ($privacyPolicyCheckbox && !(int)$privacyPolicyAccepted) {
                throw new QUI\Exception(
                    QUI::getLocale()->get(
                        'quiqqer/bricks',
                        'brick.control.simpleContact.error.privacyPolicyRequired'
                    )
                );
            }
    
            if ($Site->getAttribute('type') === 'quiqqer/sitetypes:types/contact') {
                // Contact form (site)
                $receiver = $Site->getAttribute('quiqqer.settings.sitetypes.contact.email');
            } else {
                // Contact form (brick)
                $Brick    = $BrickManager->getBrickByID($brickId);
                $receiver = $Brick->getSetting('mailTo');
            }
    
            // fallback: admin email
            if (!QUI\Utils\Security\Orthos::checkMailSyntax($receiver)) {
    
                $receiver = (QUI::conf('mail', 'admin_mail'));
            }
    
    
            $Mailer = QUI::getMailManager()->getMailer();
    
    
            $Mailer->setSubject($Site->getAttribute('title').' '.$Site->getUrlRewritten());
    
                <span style=\"font-weight: bold;\">From:</span> {$name}<br />
                <span style=\"font-weight: bold;\">E-mail:</span> {$email}<br />
    
            ";
    
            if ($privacyPolicyCheckbox) {
                $body .= '<span style="font-weight: bold;">'
                         .QUI::getLocale()->get(
    
    Patrick Müller's avatar
    Patrick Müller committed
                             'quiqqer/bricks',
                             'brick.control.simpleContact.mail.privacyPolicy_accepted'
                         ).'</span><br/>';
    
            }
    
            $body .= "<span style=\"font-weight: bold;\">Message:</span><br /><br />
                <div style=\"white-space: pre-line;\">{$_POST['message']}
                </div>";
    
            $Mailer->setBody($body);
    
    Michael's avatar
    Michael committed
                $Mailer->send();
    
    michael.daniel's avatar
    michael.daniel committed
                QUI\System\Log::writeException($Exception);
    
                    QUI::getLocale()->get('quiqqer/bricks', 'brick.control.simpleContact.error.serverError')
    
        ['brickId', 'project', 'siteId', 'message', 'name', 'email', 'privacyPolicyAccepted'],