if (empty($to_name)) {
     $error = true;
     $messageStack->add('friend', ERROR_TO_NAME);
     $smarty->assign('error_to_name', true);
 }
 if (strlen($to_email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
     $error = true;
     $messageStack->add('friend', ERROR_TO_ADDRESS_MIN_LENGTH);
     $smarty->assign('error_to_address', true);
 } elseif (!xos_validate_email($to_email_address)) {
     $error = true;
     $messageStack->add('friend', ERROR_TO_ADDRESS);
     $smarty->assign('error_to_address', true);
 }
 if (!isset($_SESSION['customer_id'])) {
     if (!isset($_POST['process_id']) || $_POST['security_code'] != str_decrypt($_POST['process_id'])) {
         $error = true;
         $messageStack->add('friend', ERROR_SECURITY_CODE);
     }
 }
 if ($error == true) {
     $smarty->assign('error_security_code', true);
 }
 $actionRecorder = new actionRecorder('ar_tell_a_friend', isset($_SESSION['customer_id']) ? $_SESSION['customer_id'] : null, $from_name);
 if (!$actionRecorder->canPerform() && $actionRecorder->check()) {
     $error = true;
     $actionRecorder->record(false);
     $messageStack->add('friend', sprintf(ERROR_ACTION_RECORDER, defined('MODULE_ACTION_RECORDER_TELL_A_FRIEND_EMAIL_MINUTES') ? (int) MODULE_ACTION_RECORDER_TELL_A_FRIEND_EMAIL_MINUTES : 15));
 }
 if ($error == false) {
     //      $lng_code_query = xos_db_query("select code from " . TABLE_LANGUAGES . " where languages_id = '" . (int)$_SESSION['languages_id'] . "'");
//              You should have received a copy of the GNU General Public License
//              along with XOS-Shop.  If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////
require 'includes/application_top.php';
if (!(@(include DIR_FS_SMARTY . 'catalog/templates/' . SELECTED_TPL . '/php/' . FILENAME_NEWSLETTER_SUBSCRIBE) == 'overwrite_all')) {
    if (SEND_EMAILS != 'true' || NEWSLETTER_ENABLED != 'true') {
        xos_redirect(xos_href_link(FILENAME_DEFAULT));
    }
    require DIR_FS_DOCUMENT_ROOT . FILENAME_CAPTCHA;
    require DIR_FS_SMARTY . 'catalog/languages/' . $_SESSION['language'] . '/' . FILENAME_NEWSLETTER_SUBSCRIBE;
    switch ($_GET['action']) {
        case 'process':
            if (isset($_POST['formid']) && $_POST['formid'] == $_SESSION['sessiontoken']) {
                $error = false;
                $scy_code = false;
                if (isset($_POST['process_id']) && $_POST['security_code'] == str_decrypt($_POST['process_id'])) {
                    $scy_code = true;
                }
                $subscriber_email_address = xos_db_prepare_input($_POST['subscriber_email_address']);
                if (isset($_POST['languages'])) {
                    $language_id = xos_db_prepare_input($_POST['languages']);
                } else {
                    $language_id = $_SESSION['languages_id'];
                }
                if (strlen($subscriber_email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
                    $error = true;
                    $messageStack->add('newsletter_subscribe', ENTRY_EMAIL_ADDRESS_ERROR);
                    $smarty->assign('error_email_address', true);
                } elseif (!xos_validate_email($subscriber_email_address)) {
                    $error = true;
                    $messageStack->add('newsletter_subscribe', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);