<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/ //
//$Id: PageController.php, v 1.0 2011/06/14 20:52:11
//
class PageController extends Controller {
    public function __construct() {
        parent::__construct();
        $this->ObjView->assign('statPageName', 'page');
    }
    public function indexAction() {
        $requestPath    = '';
        $viewFile       = '';
        $ObjMenu        = new MenuModel();
        $userSubgroupID = (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID;
        $languageIDs    = $this->ObjView->languageIDs;
        $brandID        = $this->ObjCommon->brandID;
        $mkey           = ($this->getRequestValue('orderID')) ? $this->getRequestValue('orderID') : '';
        if ($mkey) {
            $resMenu = $ObjMenu->getPageMenuItemStatus($mkey, $languageIDs, $userSubgroupID);
            if ($resMenu['menuItemID'] > 0) {                
                $viewFile = $this->ObjCommon->getCMSLayout($resMenu['menuItemID']);                
            }
        }
        $viewFile   = (isset($viewFile) && $viewFile != '') ? $viewFile : $this->ObjCommon->getTemplateFile('contentPage');          
        $contentID  = $this->getRequestValue("id");
        // $this->ObjView->caching =   1;
        /// $this->ObjView->clearCache('Content.tpl');
        //  if($this->ObjView->is_cached($viewFile,'page_'.$contentID,$userSubgroupID)){
        //     $this->ObjView->display($viewFile,'page_'.$contentID,$userSubgroupID); 
        //  } else {
        $objectID   = ($this->getRequestValue('itemID') ? $this->getRequestValue('itemID') : $this->getRequestValue('id'));
        $ObjContent = new ContentModel();
        if (isset($resMenu['menuItemID']) && $resMenu['menuItemID'] > 0) {
            $ObjBanner     = new BannerModel();
            $ObjCustommenu = new CustommenuModel();
            $resContent    = $ObjContent->getContentDetails($languageIDs, $contentID, '', '', 'publish', $userSubgroupID, 'yes', '',$brandID);
            $requestPath   = $this->sefPathByID($resMenu['menuItemID'], 'menu');
            $resBanner     = $ObjBanner->listMenuItemBanners($languageIDs, $resMenu['menuItemID'], "frontend",'',$brandID);
            $this->ObjView->assign('resBanner', $resBanner);
            $resBlocks = $ObjCustommenu->listStaticBlocks($languageIDs, '', '', '', '', '', 'menuItemlist', $resMenu['menuItemID'], 'view', 'Active',$brandID);
            $this->ObjView->assign('resBlocks', $resBlocks);
            $this->ObjView->assign('showBreadCrumb', $resMenu['showBreadCrumb']);
        } else if ($this->getRequestValue('itemID') == '') {
            if (!$contentID) {
                $requestUrlKey = $this->getRequestValue(1);
                $contentID     = $ObjContent->getContentID($requestUrlKey,$brandID);
            }
            $resContent  = $ObjContent->getContentDetails($languageIDs, $contentID, '', '', 'publish', $userSubgroupID, 'yes', '',$brandID);
            $requestPath = $this->sefPathByID($contentID, 'page');
        }
        $enableRemarketing = $this->getSettingValue("seo_settings", "enable_remarketing");
        $enableConversion  = $this->getSettingValue("seo_settings", "enable_conversion_tracking");
        /* Ttracking Codes Listing */
        if ($enableRemarketing || $enableConversion) {
            $ObjSaleTracking = new SaleTrackingModel();
            if (isset($resMenu['menuItemID']) && $resMenu['menuItemID'] > 0) {
                $resSaleTrackDet = $ObjSaleTracking->listTrackingCodesForPage($resMenu['menuItemID'], 'Menu');
            }
            $resCmsSaleTrackDet = $ObjSaleTracking->listTrackingCodesForPage($contentID, 'Cms');
            if (!isset($resSaleTrackDet)) {
                $resSaleTrackDet = $resCmsSaleTrackDet;
            }
            /* Tracking Codes Listing */
            if ($resSaleTrackDet) {
                if ($enableRemarketing) {
                    $remarketingCodeStart = ($resSaleTrackDet['remarketingCodeStart']) ? $resSaleTrackDet['remarketingCodeStart'] : $resCmsSaleTrackDet['remarketingCodeStart'];
                    $this->ObjView->assign('remarketingCodeStart', $remarketingCodeStart);
                    $remarketingCodeEnd = ($resSaleTrackDet['remarketingCodeEnd']) ? $resSaleTrackDet['remarketingCodeEnd'] : $resCmsSaleTrackDet['remarketingCodeEnd'];
                    $this->ObjView->assign('remarketingCodeEnd', $remarketingCodeEnd);
                }
                if ($enableConversion) {
                    $conversionCode = ($resSaleTrackDet['conversionCode']) ? $resSaleTrackDet['conversionCode'] : $resCmsSaleTrackDet['conversionCode'];
                    $this->ObjView->assign('conversionCode', $conversionCode);
                }
            }
        }
        /* Tracking Codes Listing */
        //$resSectionDetails = $ObjContent->getSectionDetails($languageIDs,$resContent['sectionID']);
        if (isset($resContent['content']) && $resContent['content'] != '') {
            /* $contentMetaTitle              = (trim($resContent['contentMetaTitle']) == "") ? $resContent['contentTitle'] : $resContent['contentMetaTitle'];
            $contentMetaDescription        = $resContent['contentMetaDescription'];
            $contentMetaKeywords           = $resContent['contentMetaKeywords'];
            $settingsGlobalMetaTitle       = ($contentMetaTitle) ? $contentMetaTitle : $this->ObjView->_languageXML['lblGlobalMetaTitle'];
            $settingsGlobalMetaDescription = ($contentMetaDescription) ? $contentMetaDescription : $this->ObjView->_languageXML['lblGlobalMetaDesc'];
            $settingsGlobalMetaKeywords    = ($contentMetaKeywords) ? $contentMetaKeywords : $this->ObjView->_languageXML['lblGlobalMetaKeywords'];
            $this->ObjView->assign('commonMetaTitle', $settingsGlobalMetaTitle);
            $this->ObjView->assign('commonMetaDescription', $settingsGlobalMetaDescription);
            $this->ObjView->assign('commonMetaKeywords', $settingsGlobalMetaKeywords); */
            $formIDMatch = explode("[{FORM-", $resContent['content']);
            if (!empty($formIDMatch)) {
                $LCIDStr = $this->ObjCookie->getCookie($this->ObjView->_section . '_LanguageLCIDstring');
                foreach ($formIDMatch as $formCode) {
                    $formCode     = explode("}]", $formCode);
                    $actionReturn = array();
                    if (is_numeric($formCode[0])) {
                        $formID      = $formCode[0];
                        $objForm     = new FormModel();
                        $formID      = ($formID == '') ? $this->getRequestValue('key') : $formID;
                        $languageIDs = $this->ObjView->languageIDs;
                        $languageID  = $languageIDs['Current'];
                        $params      = array(
                            'languageID' => $languageID,
                            'formStatus' => "'publish'",
                            'status' => 'Active',
                            'formID' => $formID,
                            'brandID' => $brandID,
                            'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                        );
                        $resultForm  = $objForm->getForm($params);
                        if (!empty($resultForm)) {
                            $resultElement           = $objForm->getElements($params);
                            $uploadFolder            = __CORE_PUBLIC_PATH . "/uploads/forms/" . $resultForm['globalUploadFolder'];
                            $_POST['formKey']        = $resultForm['formKey'];
                            $_POST['formID']         = $formID;
                            $formDisable             = false;
                            $allowAccess             = false;
                            $resultForm['userGroup'] = isset($resultForm['userGroup']) ? $resultForm['userGroup'] : '';
                            switch ($resultForm['userGroup']) {
                                case '0':
                                    $allowAccess = true;
                                    break;
                                case 'registered':
                                    if ($this->ObjSession->getSession("REGISTERED_USER_ID") > 0) {
                                        $allowAccess = true;
                                    }
                                    break;
                                default:
                                    $allowAccess = true;
                            }
                            if (!$allowAccess) {
                                $this->ObjView->display('NoPage.tpl');
                                exit;
                            }
                            switch ($resultForm['disableForm']) {
                                case 'afterdays':
                                    $disableFormCriteria = $resultForm['disableFormCriteria'];
                                    $formCreatedDate     = $resultForm['formCreatedDate'];
                                    $now                 = date('Y-m-d');
                                    $formCreatedDate     = date('Y-m-d', strtotime("+" . $disableFormCriteria . " day", strtotime($formCreatedDate)));
                                    if ($now > $formCreatedDate) {
                                        $formDisable        = true;
                                        $disableFormMessage = $resultForm['disableFormMessage'];
                                    }
                                    break;
                                case 'aftersubmission':
                                    if ($resultForm['submissions'] >= $resultForm['disableFormCriteria']) {
                                        $formDisable        = true;
                                        $disableFormMessage = $resultForm['disableFormMessage'];
                                    }
                                    break;
                            }
                            $validationEnable = false;
                            $tet              = "1";
                            if (isset($_POST['submitForm'])) {
                                $validationEnable = true;
                                foreach ($resultElement as $element) {
                                    if ($element['validateRule'] != '') {
                                        $validationEnable = $validationEnable && false;
                                    }
                                    if ($element['attributeType'] == 'file') {
                                        $extraAttributes = json_decode($element['extraAttributes']);
                                        if (!empty($extraAttributes->defaults->allowedExtensions)) {
                                            $validationEnable = $validationEnable && false;
                                        }
                                    }
                                }
                            }
                            if (!$formDisable) {
                                $countryList = array();
                                foreach ($resultElement as $key => $element) {
                                    $attributeType     = $element['attributeType'];
                                    $formElementID     = $element['formElementID'];
                                    $extraAttributes   = json_decode($element['extraAttributes']);
                                    $allowUserChoice   = isset($extraAttributes->allowUserChoice) ? $extraAttributes->allowUserChoice : '';
                                    $elementType[$key] = $attributeType;
                                    switch ($attributeType) {
                                        case 'select':
                                        case 'select_multiple':
                                            $resultElement[$key]['options'] = $objForm->getOptions($languageID, $formElementID);
                                            if (isset($allowUserChoice->status) && $allowUserChoice->status == 'Yes') {
                                                array_push($resultElement[$key]['options'], array(
                                                    0 => "-1",
                                                    1 => $this->getLanguageValue("lblOther")
                                                ));
                                            }
                                            break;
                                        case 'radio':
                                        case 'checkbox':
                                            $resultElements = $objForm->getOptions($languageID, $formElementID);
                                            $tempArray      = array();
                                            foreach ($resultElements as $options) {
                                                array_push($tempArray, $options['formElementOptionID'] . "->" . $options['optionDesc']);
                                            }
                                            $resultElement[$key]['options'] = implode("~*", $tempArray);
                                            if (isset($allowUserChoice->status) && $allowUserChoice->status == 'Yes') {
                                                $resultElement[$key]['options'] .= "~*0->" . $this->getLanguageValue("lblOther");
                                            }
                                            break;
                                        case 'country':
                                            $objCountry                     = new CountryModel();
                                            $countryList                    = $objCountry->listCountries($languageIDs);
                                            $resultElement[$key]['options'] = $countryList;
                                            if (isset($allowUserChoice->status) && $allowUserChoice->status == 'Yes') {
                                                array_push($resultElement[$key]['options'], array(
                                                    0 => "0",
                                                    1 => $this->getLanguageValue("lblOther")
                                                ));
                                            }
                                            break;
                                        case 'businesstype':
                                            $ObjBusinessType                = new BusinessTypeModel();
                                            $resultElement[$key]['options'] = "<option value>" . $this->getLanguageValue("lblSelect") . "</option>";
                                            $resultElement[$key]['options'] .= $ObjBusinessType->getBusinessTypeOption($languageIDs, $businessType = "others");
                                        default:
                                            break;
                                    }
                                }
                                $this->ObjView->assign('resultElement', $resultElement);
                                $this->ObjView->assign('formID', $formID);
                                $this->ObjView->assign('elementType', $elementType);
                                $this->ObjView->assign('resultForm', $resultForm);
                            } else {
                                $this->ObjView->assign('formDisable', $formDisable);
                                $this->ObjView->assign('disableFormMessage', $disableFormMessage);
                            }
                            $enable_captcha = $this->getSettingValue('security_settings', 'enable_captcha');
                            if ($this->ObjForm->isValid('oorjitForm_' . $resultForm['formKey'], 'submitForm') || $validationEnable) {
                                $errorExists = 0;
                                if($_POST['oorjitFormSecurityCode']!='' && $_SESSION['captcha_val']!='' && ($_POST['oorjitFormSecurityCode']!=$_SESSION['captcha_val']) && $enable_captcha=='Yes') {
                                    $this->setMessage(trim($this->getLanguageValue("errSecurityCode")), "error", '', 'common_message_form');
                                    $errorExists  =1;
                                } 
                                if($errorExists<=0) {
                                    
                                    $objCache       = new Cache("file");
                                    $globalSettings = $objCache->get('m_form_config');
                                    $formElements   = array();
                                    $formValues     = array();
                                    foreach ($resultElement as $elements) {
                                        if ($elements['attributeType'] != 'html' && $elements['attributeType'] != 'submit') {
                                            $formAttributeName = $elements['attributeType'] . "_" . $elements['formElementID'];
                                            if ($elements['attributeType'] == 'image' || $elements['attributeType'] == 'file') {
                                                if (!is_dir($uploadFolder)) {
                                                    mkdir($uploadFolder, 0777);
                                                }
                                                if ($elements['attributeType'] == 'image' && $_POST[$formAttributeName . "_temp"] != '') {
                                                    $fileName = uniqid('oorjitForm') . "_" . $_POST[$formAttributeName];
                                                    copy($_POST[$formAttributeName . "_temp"], $uploadFolder . "/" . $fileName);
                                                } else if ($elements['attributeType'] == 'file' && $_FILES[$formAttributeName]["tmp_name"] != '') {
                                                    if ($_FILES[$formAttributeName]['name'] != '') {
                                                        $fileName = uniqid('oorjitForm') . "_" . $_FILES[$formAttributeName]['name'];
                                                        copy($_FILES[$formAttributeName]["tmp_name"], $uploadFolder . "/" . $fileName);
                                                    } else {
                                                        $fileName = '';
                                                    }
                                                }
                                                $_POST[$formAttributeName] = ($fileName != '') ? $uploadFolder . "/" . $fileName : '';
                                            } else if ($elements['attributeType'] == 'date') {
                                                $settingsDateFormat        = $this->getSettingValue('site_settings', 'date_format');
                                                $_POST[$formAttributeName] = $this->convertDateForSQL($_POST[$formAttributeName], $settingsDateFormat);
                                            }
                                            array_push($formElements, $formAttributeName);
                                            if (is_array($_POST[$formAttributeName])) {
                                                array_push($formValues, implode(",", $_POST[$formAttributeName]));
                                            } else {
                                                array_push($formValues, $_POST[$formAttributeName]);
                                            }
                                        }
                                    }
                                    $locationDetails = array(); {
                                        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
                                            $ipAddress = $_SERVER['HTTP_CLIENT_IP'];
                                        } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                                            $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
                                        } else {
                                            $ipAddress = $_SERVER['REMOTE_ADDR'];
                                        }
                                        //Usage => new geoip lib
                                        $locationSettings['provider'] = $this->getSettingValue('product_cart_settings', 'location_provider');
                                        if ($locationSettings['provider'] == 'maxmind') {
                                            $locationSettings['apiKey'] = $this->getSettingValue('product_cart_settings', 'maxmind_api_key');
                                        } else {
                                            $locationSettings['apiKey'] = $this->getSettingValue('product_cart_settings', 'ipinfodb_api_key');
                                        }
                                        $locationSettings['apiKey'] = $this->encryptDecrypt("decrypt", $locationSettings['apiKey']);
                                        $ObjGeoip                   = new Geoip($locationSettings);
                                        $locationDetails            = $ObjGeoip->getCity($ipAddress);
                                    }
                                    $userAgent  = $_SERVER['HTTP_USER_AGENT'];
                                    $parameters = array(
                                        "fields" => $formElements,
                                        "values" => $formValues,
                                        "formDetails" => $resultForm,
                                        "elementDetails" => $resultElement,
                                        "locationDetails" => $locationDetails,
                                        "userAgent" => $userAgent,
                                        "ipAddress" => $ipAddress
                                    );
                                    if ($resultForm['codeAction'] != 'none' || $resultForm['codeAction'] != '') {
                                        $ObjFormAction = new FormActionModel();
                                        $codeAction    = explode(",", $resultForm['codeAction']);
                                        if (trim($codeAction[0]) != '' && trim($codeAction[0]) != 'none') {
                                            $actionReturn = $ObjFormAction->$codeAction[0](array(
                                                'objForm' => $objForm,
                                                'languageIDs' => $languageIDs
                                            ));
                                            if ($actionReturn['status'] != 'Success') {
                                                $this->setMessage($actionReturn['Error'], "error", '', 'common_message_form');
                                                $this->setRedirect($LCIDStr . '/' . $requestPath);
                                            }
                                        }
                                    }
                                    if (isset($resultForm['saveToDataBase']) && $resultForm['saveToDataBase'] != 'No') {
                                        $objForm->saveSubmission($languageID, $parameters);
                                    }
                                    $mail_settings                  = $this->getSettingValue('mail_settings');
                                    $mail_settings['smtp_password'] = $this->encryptDecrypt("decrypt", $mail_settings['smtp_password']);
                                    $ObjMail                        = new Mail($mail_settings);
                                    $ObjMail->IsHTML();
                                    $this->sendMail($ObjMail, $languageID, $parameters, 'admin', $globalSettings, $actionReturn);
                                    if (isset($resultForm['sendConfirmMailToSubmitter']) && $resultForm['sendConfirmMailToSubmitter'] == 'Yes') {
                                        preg_match_all("/\{(.+?)\}/", $resultForm['userEmailFields'], $emails);
                                        $emailFields  = $emails[1];
                                        $userEmailIDs = array();
                                        foreach ($emailFields as $emailField) {
                                            array_push($userEmailIDs, $_POST[$emailField]);
                                        }
                                        if (!empty($userEmailIDs)) {
                                            $parameters['userEmail'] = $userEmailIDs;
                                            $this->sendMail($ObjMail, $languageID, $parameters, 'user', $globalSettings, $actionReturn);
                                        }
                                    }
                                    
                                    switch ($resultForm['afterFormSubmission']) {
                                        case 'NoAction':
                                            break;
                                        case 'ShowText':
                                            $this->setMessage($resultForm['afterFormSubmissionAction'], "success", '', 'common_message_form');
                                            $siteUrl                  = rtrim($this->getSettingValue('site_settings', 'global_http_url'), '/');
                                            $redUri                   = str_replace($siteUrl."/".$this->ObjView->_currLanguageLCID."/",'',$_SERVER['SCRIPT_URI']);
                                            $redUri                   = str_replace($siteUrl."/",'',$redUri);
                                            if(empty($redUri)) {
                                                $this->setRedirect();
                                            } else {
                                                $this->setRedirect($redUri);
                                            }                                            
                                            break;
                                        case 'RedirectToUrl':$this->setRedirect($resultForm['afterFormSubmissionAction'],'No');break;
                                        case 'RedirectToMenu':
                                            $this->setRedirect($resultForm['afterFormSubmissionAction']);
                                            break;
                                    }
                                }
                            }                            
                            $this->ObjView->assign('enable_captcha', $enable_captcha);
                            $formPage              = $this->ObjView->fetch('Forminclude.tpl');
                            $resContent['content'] = str_replace("[{FORM-" . $formID . "}]", $formPage, $resContent['content']);
                        } else {
                            $resContent['content'] = str_replace("[{FORM-" . $formID . "}]", '', $resContent['content']);
                        }
                    }
                }
            }
            $resContent['content'] = str_replace('{$httpSiteUrl}', rtrim($this->getSettingValue('site_settings', 'global_http_url'), "/") . "/", $resContent['content']);
            $this->ObjView->assign('resContent', $resContent);
            $this->ObjView->assign('contentArticleAttribs', $resContent['articleAttribs']);
            $this->ObjView->assign('urlKey', $resContent['contentUrlKey']);
            $this->ObjView->assign('pageType', ($this->getRequestValue('orderID')) ? 'menu' : 'page');
            $this->ObjView->assign('requestPath', $requestPath);
            $this->ObjView->assign('menuItemID', ($this->getRequestValue('itemID') ? $this->getRequestValue('itemID') : $contentID));
            if ($resContent['contentKey'] == 'feature-your-business') {
                $this->runAProductAction();
            } else if ($resContent['contentKey'] == 'suggest-a-business') {
                $this->suggestABusinessAction();
            } else if ($resContent['contentKey'] == 'affiliates' && __AFFILIATE_MODULE) {
                $this->affiliateSignupAction();
            }else if ($resContent['contentKey'] == 'suggest-a-seller'){
                
		$this->suggestASellerAction();
            } else {
                
                // $this->ObjView->display($viewFile,'page_'.$contentID,$userSubgroupID); 
                $this->ObjView->display($viewFile);
            }
        } else {
            $this->ObjView->display('NoPage.tpl');
            //$this->setRedirect(".");
        }
        ///}
    }
    public function runAProductAction() {
        //$this->ObjView->caching =   false;
        $ObjCountry     = new CountryModel();
        $ObjContent     = new ContentModel();
        $viewFile       = '';
        // To cache response for 1minute
        $secondsToCache = 60;
        $expiryTime     = gmdate("D, d M Y H:i:s", time() + $secondsToCache) . " GMT";
        header("Expires: $expiryTime");
        header("Pragma: no-cache");
        header("Cache-Control: public,max-age=$secondsToCache");
        // To cache response for 1minute
        $languageIDs = $this->ObjView->languageIDs;
        if ($this->ObjForm->isValid('formRunaproduct', 'submitForms')) {
            $ObjBusinessRequest             = new BusinessRequestModel();
            $ObjEmailtemplate               = new EmailtemplateModel();
            $businessReqID                  = $ObjBusinessRequest->saveForms($_POST, $languageIDs);
            $languageIDsCustom              = $languageIDs;
            $languageIDsCustom['Current']   = $languageIDs['Default'];
            $emailTempDet                   = $ObjEmailtemplate->getEmailTemlateDetails($languageIDsCustom, '', 'business-request-received');
            $resListBusinessRequest         = $ObjBusinessRequest->getBusinessRequestDetails($businessReqID, $languageIDs);
            $mail_settings                  = $this->getSettingValue('mail_settings');
            $mail_settings['smtp_password'] = $this->encryptDecrypt("decrypt", $mail_settings['smtp_password']);
            $ObjMail                        = new Mail($mail_settings);
            $ObjMail->IsHTML();
            $toEmailID   = $this->getSettingValue('site_settings', 'global_notification_email');
            $companyLogo = $this->getSettingValue('company_information', 'company_logo');
            $siteName    = $this->getSettingValue('site_settings', 'site_name');
            $siteUrl     = $this->getSettingValue('site_settings', 'global_http_url');
            $addressMail = $ObjCountry->getFormattedAddress($resListBusinessRequest['businessReqAddress'], $languageIDs);
            $Body        = str_replace('{$emailID}', $_POST['businessReqEmail'], $emailTempDet['emailHtml']);
            $Body        = str_replace('{$typeofbusiness}', $resListBusinessRequest['businessTypeName'] . $_POST['businessTypeOther'], $Body);
            $Body        = str_replace('{$PhoneNumber}', $_POST['businessReqPhone'], $Body);
            $Body        = str_replace('{$name}', $_POST['businessReqFirstName'] . " " . $_POST['businessReqLastName'], $Body);
            $Body        = str_replace('{$address}', $addressMail, $Body);
            $Body        = str_replace('{$businessReqName}', $_POST['businessReqName'], $Body);
            $this->ObjView->assign('emailbody', $Body);
            $this->ObjView->assign('companyLogo', $companyLogo);
            $this->ObjView->assign('siteName', $siteName);
            $this->ObjView->assign('siteUrl', $siteUrl);
            $email_body = $this->ObjCommon->fetch('email_templates/Layout.tpl', $languageIDsCustom);
            $ObjMail->sendMail(array(
                $emailTempDet['emailFromEmail'],
                $emailTempDet['emailFromName']
            ), $toEmailID, $emailTempDet['emailSubject'], $email_body);
            if ($ObjMail->Send()) {
            }
            $emailTempDet = $ObjEmailtemplate->getEmailTemlateDetails($languageIDs, '', 'business-request-thank');
            $ObjMail      = new Mail($mail_settings);
            $ObjMail->IsHTML();
            $Body = str_replace('{$userName}', $_POST['businessReqFirstName'] . " " . $_POST['businessReqLastName'], $emailTempDet['emailHtml']);
            $this->ObjView->assign('emailbody', $Body);
            $this->ObjView->assign('companyLogo', $companyLogo);
            $this->ObjView->assign('siteName', $siteName);
            $this->ObjView->assign('siteUrl', $siteUrl);
            $email_body = $this->ObjCommon->fetch('email_templates/Layout.tpl');
            $ObjMail->sendMail(array(
                $emailTempDet['emailFromEmail'],
                $emailTempDet['emailFromName']
            ), trim($_POST['businessReqEmail']), $emailTempDet['emailSubject'], $email_body);
            if ($ObjMail->Send()) {
            }
            //$this->setRedirect("page/mkey/".$mkey."/");
            $thankPageID = $ObjContent->getContentIDByKey('thank-you-for-your-interest-in-multi-vendor',$this->ObjCommon->brandID);
            $requestPath = $this->sefPathByID($thankPageID);
            $this->setRedirect($this->ObjView->_views_host_share . '/' . $requestPath, "no");
            exit;
        }
        $ObjBusinessType     = new BusinessTypeModel();
        $ObjMenu             = new MenuModel();
        $userSubgroupID      = (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID;
        $mkey                = ($this->getRequestValue('orderID')) ? $this->getRequestValue('orderID') : '';
        $resMenu             = $ObjMenu->getPageMenuItemStatus($mkey, $languageIDs, $userSubgroupID);
        $resListCountry      = $ObjCountry->listCountries($languageIDs, "Yes");
        $enable_captcha      = $this->getSettingValue('security_settings', 'enable_captcha');
        $lblothers           = trim($this->getLanguageValue("lblothers"));
        $defaultOption       = (isset($_POST['businessTypeID']) && $_POST['businessTypeID'] != '') ? $_POST['businessTypeID'] : '';
        $resListBusinessType = $ObjBusinessType->getBusinessTypeOption($languageIDs, $businessType = "others", $defaultOption, $lblothers);
        $this->ObjView->assign('resListCountry', $resListCountry);
        $this->ObjView->assign('enable_captcha', $enable_captcha);
        $this->ObjView->assign('resListBusinessType', $resListBusinessType);
        $_POST['businessRequestSecurityCode'] = '';
        $this->ObjView->assign($_POST['businessRequestSecurityCode']);
        $viewFile = $this->ObjCommon->getCMSLayout($resMenu['menuItemID']);
        $viewFile = ($viewFile != '') ? $viewFile : $this->ObjCommon->getTemplateFile('contentPage');
        $this->ObjView->display($viewFile);
    }
    public function suggestABusinessAction() {
        //  $this->ObjView->caching =   false;
        $viewFile         = '';
        $ObjBusinessType  = new BusinessTypeModel();
        $ObjContent       = new ContentModel();
        $languageIDs      = $this->ObjView->languageIDs;
        //$lblothers           = trim($this->getLanguageValue("lblothers"));
        $defaultOption    = (isset($_POST['businessType']) && $_POST['businessType'] != '') ? $_POST['businessType'] : '';
        $ObjEmailtemplate = new EmailtemplateModel();
        $thankPageID      = $ObjContent->getContentIDByKey('suggest-a-business',$this->ObjCommon->brandID);
        if ($this->ObjForm->isValid('formSuggestYourBusiness', 'submitSuggestYourBusiness')) {
            $languageIDsCustom              = $languageIDs;
            $languageIDsCustom['Current']   = $languageIDs['Default'];
            $resBusinessType                = $ObjBusinessType->getBusinessTypeByID($languageIDsCustom, $_POST['businessType']);
            $mail_settings                  = $this->getSettingValue('mail_settings');
            $mail_settings['smtp_password'] = $this->encryptDecrypt("decrypt", $mail_settings['smtp_password']);
            $emailTempDet                   = $ObjEmailtemplate->getEmailTemlateDetails($languageIDsCustom, '', 'business-suggestion-admin');
            if ($emailTempDet) {
                $ObjMail = new Mail($mail_settings);
                $ObjMail->IsHTML();
                $toEmailID   = $this->getSettingValue('site_settings', 'contact_email');
                $companyLogo = $this->getSettingValue('company_information', 'company_logo');
                $siteName    = $this->getSettingValue('site_settings', 'site_name');
                $siteUrl     = $this->getSettingValue('site_settings', 'global_http_url');
                $Body        = str_replace('{$businessName}', $_POST['businessName'], $emailTempDet['emailHtml']);
                if ($_POST['phone']) {
                    $Body = str_replace('{$phone}', $_POST['phone'], $Body);
                } else {
                    $Body = str_replace('{$phone}', 'Not Specified', $Body);
                }
                if ($_POST['website']) {
                    $Body = str_replace('{$website}', $_POST['website'], $Body);
                } else {
                    $Body = str_replace('{$website}', 'Not Specified', $Body);
                }
                if ($_POST['city']) {
                    $Body = str_replace('{$city}', $_POST['city'], $Body);
                } else {
                    $Body = str_replace('{$city}', 'Not Specified', $Body);
                }
                $Body = str_replace('{$businessType}', $resBusinessType['businessTypeName'], $Body);
                $Body = str_replace('{$comments}', $_POST['comments'], $Body);
                $this->ObjView->assign('emailbody', $Body);
                $this->ObjView->assign('companyLogo', $companyLogo);
                $this->ObjView->assign('siteName', $siteName);
                $this->ObjView->assign('siteUrl', $siteUrl);
                $email_body = $this->ObjCommon->fetch('email_templates/Layout.tpl', $languageIDsCustom);
                $ObjMail->sendMail(array(
                    $emailTempDet['emailFromEmail'],
                    $emailTempDet['emailFromName']
                ), $toEmailID, $emailTempDet['emailSubject'], $email_body);
                if ($ObjMail->Send()) {
                }
            }
            $this->setMessage('language.msgThankYouSuggestion', 'message_success', 'Page', 'message_feature');
            $requestPath = ($_POST['requestPath']) ? $_POST['requestPath'] : $this->sefPathByID($thankPageID);
            $this->setRedirect($this->ObjView->_views_host_share . '/' . $requestPath, "no");
            exit;
        }
        $mkey = ($this->getRequestValue('orderID')) ? $this->getRequestValue('orderID') : '';
        $this->ObjView->assign('resParentBusiness', $ObjBusinessType->getBusinessTypeOption($languageIDs, '', $defaultOption));
        if ($mkey != '') {
            $ObjMenu        = new MenuModel();
            $userSubgroupID = (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID;
            $resMenu        = $ObjMenu->getPageMenuItemStatus($mkey, $languageIDs, $userSubgroupID);
            $viewFile       = $this->ObjCommon->getCMSLayout($resMenu['menuItemID']);
        }
        $viewFile = ($viewFile != '') ? $viewFile : $this->ObjCommon->getTemplateFile('contentPage');
        $this->ObjView->display($viewFile);
    }
    public function affiliateSignupAction() {
        if (!__AFFILIATE_ENABLE) {
            $this->setRedirect("/");
            exit;
        }
        //  $this->ObjView->caching =   false;
        $languageIDs                    = $this->ObjView->languageIDs;
        $mail_settings                  = $this->getSettingValue('mail_settings');
        $mail_settings['smtp_password'] = $this->encryptDecrypt("decrypt", $mail_settings['smtp_password']);
        $viewFile                       = '';
        if ($this->ObjForm->isValid('forms', 'submitForms')) {
            $ObjEmailtemplate                = new EmailtemplateModel();
            $ObjAffiliate                    = new AffiliateModel();
            $_POST['affiliateReqLanguageID'] = $languageIDs['Current'];
            $affiliateReqID                  = $ObjAffiliate->saveAffiliateRequest($_POST);
            $languageIDsCustom               = $languageIDs;
            $languageIDsCustom['Current']    = $languageIDs['Default'];
            $emailTempDet                    = $ObjEmailtemplate->getEmailTemlateDetails($languageIDsCustom, '', 'affiliate-request-received');
            $resListAffiliateRequest         = $ObjAffiliate->getAffiliateRequestDetails($affiliateReqID, $languageIDs, 'Yes');
            $settingsDateFormat              = $this->getSettingValue("site_settings", "date_format");
            $requestDate                     = new DateTime($resListAffiliateRequest['affiliateReqDate']);
            switch ($settingsDateFormat) {
                case '%A, %B %e, %Y':
                    $requestDate = date_format($requestDate, 'l F d, Y');
                    break;
                case '%B %e, %Y':
                    $requestDate = date_format($requestDate, 'F d, Y');
                    break;
                case '%m/%d/%Y':
                    $requestDate = date_format($requestDate, 'm/d/Y');
                    break;
                case '%d/%m/%Y':
                    $requestDate = date_format($requestDate, 'd/m/Y');
                    break;
                case '%d-%m-%Y':
                    $requestDate = date_format($requestDate, 'd-m-Y');
                    break;
                case '%Y-%m-%d':
                    $requestDate = date_format($requestDate, 'Y-m-d');
                    break;
                default:
                    $requestDate = date_format($requestDate, 'M d, Y');
            }
            $ObjMail = new Mail($mail_settings);
            $ObjMail->IsHTML();
            $toEmailID     = $this->getSettingValue('site_settings', 'contact_email');
            $fromEmailName = $emailTempDet['emailFromName'];
            $fromEmailId   = $emailTempDet['emailFromEmail'];
            $Subject       = $emailTempDet['emailSubject'];
            $Body          = $emailTempDet['emailHtml'];
            $companyLogo   = $this->getSettingValue('company_information', 'company_logo');
            $siteName      = $this->getSettingValue('site_settings', 'site_name');
            $siteUrl       = $this->getSettingValue('site_settings', 'global_http_url');
            $Body          = str_replace('{$emailID}', $_POST['affiliateReqEmail'], $Body);
            $Body          = str_replace('{$PhoneNumber}', $_POST['affiliateReqPhone'], $Body);
            $Body          = str_replace('{$City}', (isset($resListAffiliateRequest['cityName']) ? $resListAffiliateRequest['cityName'] : ''), $Body);
            $Body          = str_replace('{$ProvinceState}', $resListAffiliateRequest['stateName'] . $resListAffiliateRequest['affiliateReqProvince'], $Body);
            $Body          = str_replace('{$Country}', $resListAffiliateRequest['countryName'], $Body);
            $Body          = str_replace('{$PostalCodeZip}', $resListAffiliateRequest['affiliateReqZipcode'], $Body);
            $Body          = str_replace('{$name}', $_POST['affiliateReqContactPerson'], $Body);
            $Body          = str_replace('{$address}', $_POST['affiliateReqAddress1'], $Body);
            $Body          = str_replace('{$city}', $_POST['affiliateReqCity'], $Body);
            $Body          = str_replace('{$affiliateReqName}', $_POST['affiliateReqFirstName'] . " " . $_POST['affiliateReqLastName'], $Body);
            $this->ObjView->assign("date", $requestDate);
            $this->ObjView->assign('emailbody', $Body);
            $this->ObjView->assign('companyLogo', $companyLogo);
            $this->ObjView->assign('siteName', $siteName);
            $this->ObjView->assign('siteUrl', $siteUrl);
            $email_body = $this->ObjCommon->fetch('email_templates/Layout.tpl', $languageIDsCustom);
            $ObjMail->sendMail(array(
                $fromEmailId,
                $fromEmailName
            ), $toEmailID, $Subject, $email_body);
            if ($ObjMail->Send()) {
            }
            $emailTempDet = $ObjEmailtemplate->getEmailTemlateDetails($languageIDs, '', 'affiliate-request-thank');
            $ObjMail      = new Mail($mail_settings);
            $ObjMail->IsHTML();
            $Body = str_replace('{$userName}', $_POST['affiliateReqFirstName'] . " " . $_POST['affiliateReqLastName'], $emailTempDet['emailHtml']);
            $this->ObjView->assign('emailbody', $Body);
            $this->ObjView->assign('companyLogo', $companyLogo);
            $this->ObjView->assign('siteName', $siteName);
            $this->ObjView->assign('siteUrl', $siteUrl);
            $email_body = $this->ObjCommon->fetch('email_templates/Layout.tpl');
            $ObjMail->sendMail(array(
                $emailTempDet['emailFromEmail'],
                $emailTempDet['emailFromName']
            ), trim($_POST['affiliateReqEmail']), $emailTempDet['emailSubject'], $email_body);
            if ($ObjMail->Send()) {
            }
            $ObjContent  = new ContentModel();
            $thankPageID = $ObjContent->getContentIDByKey('thank-you-for-your-affiliate-request',$this->ObjCommon->brandID);
            $requestPath = $this->sefPathByID($thankPageID);
            $this->setRedirect($this->ObjView->_views_host_share . '/' . $requestPath, "no");
        }
        $ObjCountry     = new CountryModel();
        $userSubgroupID = (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID;
        $ObjMenu        = new MenuModel();
        $mkey           = ($this->getRequestValue('orderID')) ? $this->getRequestValue('orderID') : '';
        $enable_captcha = $this->getSettingValue('security_settings', 'enable_captcha');
        $this->ObjView->assign('enable_captcha', $enable_captcha);
        $_POST['affiliateRequestSecurityCode'] = '';
        $resMenu                               = $ObjMenu->getPageMenuItemStatus($mkey, $languageIDs, $userSubgroupID);
        $this->ObjView->assign('resListCountry', $ObjCountry->listCountries($languageIDs));
        $viewFile = $this->ObjCommon->getCMSLayout($resMenu['menuItemID']);
        $viewFile = ($viewFile != '') ? $viewFile : $this->ObjCommon->getTemplateFile('contentPage');
        $this->ObjView->display($viewFile);
    }
    public function emailAction() {
        $ObjContent    = new ContentModel();
        $languageIDs   = $this->ObjView->languageIDs;
        $type          = $this->getRequestValue(2);
        $contentID     = 0;
        $requestUrlKey = $this->getRequestValue(4);
        if ($type == 'menu') {
            $menuItemID = $this->getRequestValue(3);
            $shareUrl   = $this->sefPathByID($menuItemID, 'menu');
        } else {
            $contentID = $this->getRequestValue(3);
            $shareUrl  = $this->sefPathByID($contentID, 'page');
        }
        $resContent       = $ObjContent->getContentDetails($languageIDs, $contentID, $requestUrlKey, '', 'publish', '', '', '');
        $siteUrl          = rtrim($this->getSettingValue('site_settings', 'global_http_url'), "/") . "/";
        $cmsTitle         = $resContent['contentTitle'];
        $cmsPageLink      = $this->ObjView->_views_host_share . '/' . $shareUrl;
        $ObjEmailtemplate = new EmailtemplateModel();
        $enable_captcha   = $this->getSettingValue('security_settings', 'enable_captcha');
        if (isset($_POST['sendEmail'])) {
            if ($this->ObjForm->isValid('formReferaFriend', 'sendEmail')) {
                $emailbody  = $ObjEmailtemplate->getEmailTemlateDetails($languageIDs, '', 'cms_page_share');
                $senderName = $_POST['emailFromName'];
                $this->ObjView->assign('fromName', $senderName);
                $this->ObjView->assign('fromEmail', $_POST['emailFrom']);
                $from        = $_POST['emailFromName'] . "<" . $_POST['emailFrom'] . ">";
                $subject     = $emailbody['emailSubject'];
                // sent mail to user
                $companyLogo = $this->getSettingValue('company_information', 'company_logo');
                $this->ObjView->assign('companyLogo', $companyLogo);
                $from        = array(
                    $_POST['emailFrom'],
                    $senderName
                );
                $bodytag     = str_replace('{$referredTo}', '', $emailbody['emailHtml']);
                $bodytag     = str_replace('{$referredBy}', $senderName, $bodytag);
                $bodytag     = str_replace('{$cmsLink}', $cmsPageLink, $bodytag);
                $bodytag     = str_replace('{$cmsHead}', $cmsTitle, $bodytag);
                $bodytag     = str_replace('{$shareBy}', $senderName, $bodytag);
                $bodytag     = str_replace('{$companyLogo}', $companyLogo, $bodytag);
                $mailContent = $this->getLanguageValue('lblHelo') . ',<br><br>' . $this->getLanguageValue('lblApersonal') . $senderName . '<br><br>';
                $mailContent .= str_replace(chr(13), "<br>", stripslashes($_POST['emailContent'])) . '<br><br>' . $bodytag;
                $mailContent = html_entity_decode($mailContent);
                $this->ObjView->assign('emailbody', $mailContent);
                $this->ObjView->assign('siteUrl', $siteUrl);
                $siteName = $this->getSettingValue('site_settings', 'site_name');
                $this->ObjView->assign('siteName', $siteName);
                $this->ObjView->assign('companyLogo', $companyLogo);
                $emailID                        = stripslashes($_POST['recipientEmail']);
                $toemailID                      = explode(",", $emailID);
                $body                           = $this->ObjCommon->fetch("email_templates/Layout.tpl");
                $mail_settings                  = $this->getSettingValue('mail_settings');
                $mail_settings['smtp_password'] = $this->encryptDecrypt("decrypt", $mail_settings['smtp_password']);
                $ObjMail                        = new Mail($mail_settings);
                $ObjMail->IsHTML();
                $send = $ObjMail->sendMail(array(
                    $_POST['emailFrom'],
                    $senderName
                ), $toemailID, $subject, $body);
                if ($ObjMail->Send()) {
                    $this->setMessage("language.msgCmsShare", "message_info");
                    echo '<script type="text/javascript">parent.location.reload();parent.$.fancybox.close(); </script>';
                    exit;
                } else {
                    $this->setMessage("language.errSendingMail", "message_error");
                }
            }
        }
        $this->ObjView->assign('enable_captcha', $enable_captcha);
        $this->ObjView->display('ContentPageEmail.tpl');
        exit;
    }
    public function previewAction() {
        $ObjContent     = new ContentModel();
        $userSubgroupID = (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID;
        $this->ObjView->assign('preview', "yes");
        $languageIDs = $this->ObjView->languageIDs;
        $versionID   = $this->getRequestValue('verid');
        $contentID   = $this->getRequestValue('id');
        if (!$versionID) {
            $resContent = $ObjContent->getContentDetails($languageIDs, $contentID, '', '', '', $userSubgroupID, 'yes');
        } else {
            $resContent = $ObjContent->listContentVersion($languageIDs, $contentID, $versionID);
        }
        if ($resContent['content'] != '') {
            preg_match("/\[{(.+?)\}]/", $resContent['content'], $match);
            if (!empty($match)) {
                $formID       = end(explode("-", $match[1]));
                $objForm      = new FormModel();
                $formID       = ($formID == '') ? $this->getRequestValue('key') : $formID;
                $languageIDs  = $this->ObjView->languageIDs;
                $languageID   = $languageIDs['Current'];
                $actionReturn = array();
                $params       = array(
                    'languageID' => $languageID,
                    'formStatus' => "'publish'",
                    'status' => 'Active',
                    'formID' => $formID,
                    'userGroupID' => (int) $this->ObjCommon->REGISTERED_USER_GROUP_ID
                );
                $resultForm   = $objForm->getForm($params);
                if (empty($resultForm)) {
                    $this->setRedirect("/");
                }
                $resultElement    = $objForm->getElements($params);
                $uploadFolder     = __CORE_PUBLIC_PATH . "/uploads/forms/" . $resultForm['globalUploadFolder'];
                $_POST['formKey'] = $resultForm['formKey'];
                $_POST['formID']  = $formID;
                $formDisable      = false;
                switch ($resultForm['disableForm']) {
                    case 'afterdays':
                        $disableFormCriteria = $resultForm['disableFormCriteria'];
                        $formCreatedDate     = $resultForm['formCreatedDate'];
                        $now                 = date('Y-m-d');
                        $formCreatedDate     = date('Y-m-d', strtotime("+" . $disableFormCriteria . " day", strtotime($formCreatedDate)));
                        if ($now > $formCreatedDate) {
                            $formDisable        = true;
                            $disableFormMessage = $resultForm['disableFormMessage'];
                        }
                        break;
                    case 'aftersubmission':
                        if ($resultForm['submissions'] >= $resultForm['disableFormCriteria']) {
                            $formDisable        = true;
                            $disableFormMessage = $resultForm['disableFormMessage'];
                        }
                        break;
                }
                $validationEnable = false;
                $tet              = "1";
                if (isset($_POST['submitForm'])) {
                    $validationEnable = true;
                    foreach ($resultElement as $element) {
                        if ($element['validateRule'] != '') {
                            $validationEnable = $validationEnable && false;
                        }
                        if ($element['attributeType'] == 'file') {
                            $extraAttributes = json_decode($element['extraAttributes']);
                            if (!empty($extraAttributes->defaults->allowedExtensions)) {
                                $validationEnable = $validationEnable && false;
                            }
                        }
                    }
                }
                if (!$formDisable) {
                    $countryList = array();
                    foreach ($resultElement as $key => $element) {
                        $attributeType     = $element['attributeType'];
                        $formElementID     = $element['formElementID'];
                        $extraAttributes   = json_decode($element['extraAttributes']);
                        $allowUserChoice   = isset($extraAttributes->allowUserChoice) ? $extraAttributes->allowUserChoice : '';
                        $elementType[$key] = $attributeType;
                        switch ($attributeType) {
                            case 'select':
                            case 'select_multiple':
                                $resultElement[$key]['options'] = $objForm->getOptions($languageID, $formElementID);
                                if (isset($allowUserChoice->status) && $allowUserChoice->status == 'Yes') {
                                    array_push($resultElement[$key]['options'], array(
                                        0 => "-1",
                                        1 => $this->getLanguageValue("lblOther")
                                    ));
                                }
                                break;
                            case 'radio':
                            case 'checkbox':
                                $resultElements = $objForm->getOptions($languageID, $formElementID);
                                $tempArray      = array();
                                foreach ($resultElements as $options) {
                                    array_push($tempArray, $options['formElementOptionID'] . "->" . $options['optionDesc']);
                                }
                                $resultElement[$key]['options'] = implode("~*", $tempArray);
                                if (isset($allowUserChoice->status) && $allowUserChoice->status == 'Yes') {
                                    $resultElement[$key]['options'] .= "~*0->" . $this->getLanguageValue("lblOther");
                                }
                                break;
                            case 'country':
                                $objCountry                     = new CountryModel();
                                $countryList                    = $objCountry->listCountries($languageIDs);
                                $resultElement[$key]['options'] = $countryList;
                                if (isset($allowUserChoice->status) && $allowUserChoice->status == 'Yes') {
                                    array_push($resultElement[$key]['options'], array(
                                        0 => "0",
                                        1 => $this->getLanguageValue("lblOther")
                                    ));
                                }
                                break;
                            case 'businesstype':
                                $ObjBusinessType                = new BusinessTypeModel();
                                $resultElement[$key]['options'] = "<option value>" . $this->getLanguageValue("lblSelect") . "</option>";
                                $resultElement[$key]['options'] .= $ObjBusinessType->getBusinessTypeOption($languageIDs, $businessType = "others");
                            default:
                                break;
                        }
                    }
                    $this->ObjView->assign('resultElement', $resultElement);
                    $this->ObjView->assign('formID', $formID);
                    $this->ObjView->assign('elementType', $elementType);
                    $this->ObjView->assign('resultForm', $resultForm);
                } else {
                    $this->ObjView->assign('formDisable', $formDisable);
                    $this->ObjView->assign('disableFormMessage', $disableFormMessage);
                }
                $formPage              = $this->ObjView->fetch('Forminclude.tpl');
                $resContent['content'] = str_replace($match[0], $formPage, $resContent['content']);
            }
            $contentMetaTitle              = $resContent['contentMetaTitle'];
            $contentMetaTitle              = (trim($contentMetaTitle) == "") ? $resContent['contentTitle'] : $contentMetaTitle;
            $contentMetaDescription        = $resContent['contentMetaDescription'];
            $contentMetaKeywords           = $resContent['contentMetaKeywords'];
            $settingsGlobalMetaTitle       = ($contentMetaTitle) ? $contentMetaTitle : $this->ObjView->_languageXML['lblGlobalMetaTitle'];
            $settingsGlobalMetaTitle       = (trim($settingsGlobalMetaTitle) == "") ? $settingsSiteName : $settingsGlobalMetaTitle;
            $settingsGlobalMetaDescription = ($contentMetaDescription) ? $contentMetaDescription : $this->ObjView->_languageXML['lblGlobalMetaDesc'];
            $settingsGlobalMetaKeywords    = ($contentMetaKeywords) ? $contentMetaKeywords : $this->ObjView->_languageXML['lblGlobalMetaKeywords'];
            $this->ObjView->assign('commonMetaTitle', $settingsGlobalMetaTitle);
            $this->ObjView->assign('commonMetaDescription', $settingsGlobalMetaDescription);
            $this->ObjView->assign('commonMetaKeywords', $settingsGlobalMetaKeywords);
            $this->ObjView->assign('resContent', $resContent);
            $requestUrlKey = $resContent['contentUrlKey'];
            $this->ObjView->assign('contentArticleAttribs', $resContent['articleAttribs']);
            $this->ObjView->assign('urlKey', $requestUrlKey);
            $viewFile = $this->ObjCommon->getTemplateFile('contentPage');
            if ($resContent['contentKey'] == 'feature-your-business') {
                $this->runAProductAction();
            } else if ($resContent['contentKey'] == 'suggest-a-business') {
                $this->suggestABusinessAction();
            } else if ($resContent['contentKey'] == 'affiliates' && __AFFILIATE_MODULE) {
                $this->affiliateSignupAction();
            } else {
                $this->ObjView->display($viewFile);
            }
        } else {
            $this->ObjView->display('NoPage.tpl');
            //$this->setRedirect(".");
        }
    }
    private function sendMail($ObjMail, $languageID, $param, $reciever, $globalSettings, $actionReturn = array()) {
        $objForm     = new FormModel();
        $languageIDs = $this->ObjView->languageIDs;
        $languageID  = $languageIDs['Current'];
        $formDetails = $param['formDetails'];
        $fields      = $param['fields'];
        if ($formDetails['emailFromName'] == '') {
            $formDetails['emailFromName'] = $globalSettings['emailFromName'];
        }
        $fromEmailName = $formDetails['emailFromName'];
        $fromEmailId   = $this->getSettingValue('site_settings', 'global_notification_email');
        $companyLogo   = $this->getSettingValue('company_information', 'company_logo');
        $siteName      = $this->getSettingValue('site_settings', 'site_name');
        $siteUrl       = $this->getSettingValue('site_settings', 'global_http_url');
        if ($reciever == 'admin') {
            if ($formDetails['adminEmails'] == '') {
                $formDetails['adminEmails'] = $globalSettings['adminEmails'];
            }
            if ($formDetails['adminEmailSubject'] == '') {
                $formDetails['adminEmailSubject'] = $globalSettings['adminEmailSubject'];
            }
            if ($formDetails['adminEmailContent'] == '') {
                $formDetails['adminEmailContent'] = $globalSettings['adminEmailContent'];
            }
            $toEmailID = explode(",", $formDetails['adminEmails']);
            if (empty($toEmailID)) {
                return true;
            }
            $Subject = $formDetails['adminEmailSubject'];
            $body    = $formDetails['adminEmailContent'];
            if (strrpos($body, '}]') != false) {
                $body = preg_replace("/\-(.+?)\-/", "", $body);
                foreach ($fields as $field) {
                    $elem = explode("_", $field);
                    if (isset($_POST[$field]) && is_array($_POST[$field])) {
                        $elementArray = array();
                        foreach ($_POST[$field] as $fieldID) {
                            $elementArray[] = $objForm->getOptionLabel($fieldID, $elem[1], $languageID, $elem[0]);
                        }
                        $text = implode(",", $elementArray);
                    } else {
                        $text = $objForm->getOptionLabel($_POST[$field], $elem[1], $languageID, $elem[0]);
                    }
                    if ($elem[0] == 'image' && $text!='') {
                        $imageUrl = rtrim($siteUrl, "/") . "/public/" . end(explode("/public/", $text));
                        $text     = "<img src='" . $imageUrl . "' height='100' width='100'/>";
                    } else if ($elem[0] == 'file' && $text!='') {
                        $fileUrl = rtrim($siteUrl, "/")  . "/public/" . end(explode("/public/", $text));
                        $text    = "<a href='" . $fileUrl . "'/>" . $fileUrl . "</a>";
                    }
                    $body = str_replace('[{' . $field . '}]', $text, $body);
                }
                foreach ($actionReturn as $key => $customVar) {
                    $body = str_replace('[{' . $key . '}]', $customVar, $body);
                }
            }
        } else {
            $toEmailID = $param['userEmail'];
            if ($formDetails['userEmailSubject'] == '') {
                $formDetails['userEmailSubject'] = $globalSettings['userEmailSubject'];
            }
            if ($formDetails['userEmailContent'] == '') {
                $formDetails['userEmailContent'] = $globalSettings['userEmailContent'];
            }
            $Subject = $formDetails['userEmailSubject'];
            $body    = $formDetails['userEmailContent'];
            if (strrpos($body, '}]') != false) {
                $body = preg_replace("/\-(.+?)\-/", "", $body);
                foreach ($fields as $field) {
                    $elem = explode("_", $field);
                    $text = $objForm->getOptionLabel($_POST[$field], $elem[1], $languageID, $elem[0]);
                    if ($elem[0] == 'image' && $text!='') {
                        $imageUrl = rtrim($siteUrl, "/") . "/public/" . end(explode("/public/", $text));
                        $text     = "<img src='" . $imageUrl . "' height='100' width='100'/>";
                    } else if ($elem[0] == 'file' && $text!='') {
                        $fileUrl = rtrim($siteUrl, "/") . "/public/" . end(explode("/public/", $text));
                        $text    = "<a href='" . $fileUrl . "'/>" . $fileUrl . "</a>";
                    }
                    $body = str_replace('[{' . $field . '}]', $text, $body);
                }
                foreach ($actionReturn as $key => $customVar) {
                    $body = str_replace('[{' . $key . '}]', $customVar, $body);
                }
            }
        }
        $body = preg_replace("/{\[(.+?)\]}/", "Not Specified", $body);
        $this->ObjView->assign('emailbody', html_entity_decode($body));
        $this->ObjView->assign('companyLogo', $companyLogo);
        $this->ObjView->assign('siteName', $siteName);
        $this->ObjView->assign('siteUrl', $siteUrl);
        $email_body = $this->ObjCommon->fetch('email_templates/Layout.tpl', $languageID);
        $ObjMail->sendMail(array(
            $fromEmailId,
            $fromEmailName
        ), $toEmailID, $Subject, $email_body);
        if ($ObjMail->Send()) {
            $ObjMail->clearAddresses();
        }
    }
    public function isExists($params) {
        $objForm = new FormModel();
        $formKey = $_POST['formKey'];
        $params  = array(
            'formKey' => $formKey,
            'field' => $params['field'],
            'value' => $params['value']
        );
        $res     = $objForm->checkValueExists($params);
        if ($res['exist']) {
            return false;
        } else {
            return true;
        }
    }
    public function sefPathByID($currID, $type = 'page') {
        $languageIDs = $this->ObjView->languageIDs;
        $ObjUrl      = new UrlrewriteModel();
        $idPath      = $type . '/' . $currID . '/';
        $resUrl      = $ObjUrl->getRequestPathByIdPath($languageIDs['Current'], $idPath);
        return $resUrl['requestPath'];
    }
     public function suggestASellerAction()
    {

        $viewFile = '';
        $ObjBusinessType   = new BusinessTypeModel();
        $ObjContent        = new ContentModel();
        $languageIDs       = $this->ObjView->languageIDs;
        //print_r($languageIDs);exit;
        $ObjCountry       	= new CountryModel();
        //$lblothers           = trim($this->getLanguageValue("lblothers"));
        $defaultOption     = (isset($_POST['businessType']) && $_POST['businessType'] != '') ? $_POST['businessType'] : '';		
              
        $ObjEmailtemplate = new EmailtemplateModel();
        //$thankPageID    =   $ObjContent->getContentIDByKey('suggest-a-business');
        if ($this->ObjForm->isValid('formSuggestSeller', 'submitSuggestSeller'))
        {
            
            $languageIDsCustom			  =	$languageIDs;
            $languageIDsCustom['Current'] =	$languageIDs['Default'];
            $resBusinessType = $ObjBusinessType->getBusinessTypeByID($languageIDsCustom, $_POST['businessType']);
            $mail_settings   = $this->getSettingValue('mail_settings');
            $emailTempDet    = $ObjEmailtemplate->getEmailTemlateDetails($languageIDsCustom, '', 'business-suggestion-admin');
           // print_r($emailTempDet);exit;
           // echo $emailTempDet['emailHtml'];exit;
            if($emailTempDet){
                
            $ObjMail         = new Mail($mail_settings);
            $ObjMail->IsHTML();
            $toEmailID     = $this->getSettingValue('site_settings', 'contact_email');
            $companyLogo   = $this->getSettingValue('company_information', 'company_logo');
            $siteName      = $this->getSettingValue('site_settings', 'site_name');
            $siteUrl       = $this->getSettingValue('site_settings', 'global_http_url');
            $Body          = str_replace('{$businessName}', $_POST['businessName'], $emailTempDet['emailHtml']);
			if($_POST['phone'])
			{
                                 $Body          = str_replace('{$phone}', $_POST['phone'], $Body);
			}
			else
			{
				 $Body          = str_replace('{$phone}', 'Not Specified', $Body);
			}
                        if($_POST['website'])
			{
                                $Body          = str_replace('{$website}', $_POST['website'], $Body);
			}
			else
			{
				 $Body          = str_replace('{$website}', 'Not Specified', $Body);
			}
			if($_POST['city'])
			{
                                $Body          = str_replace('{$city}', $_POST['city'], $Body);
			}
			else
			{
				$Body          = str_replace('{$city}', 'Not Specified', $Body);
			}
           $Body          = str_replace('{$businessType}', $resBusinessType['businessTypeName'], $Body);
            $Body          = str_replace('{$comments}', $_POST['comments'], $Body);
            $this->ObjView->assign('emailbody', $Body);
            $this->ObjView->assign('companyLogo', $companyLogo);
            $this->ObjView->assign('siteName', $siteName);
            $this->ObjView->assign('siteUrl', $siteUrl);
            $email_body = $this->ObjCommon->fetch('email_templates/Layout.tpl',$languageIDsCustom);
            $ObjMail->sendMail(array($emailTempDet['emailFromEmail'],$emailTempDet['emailFromName']), $toEmailID, $emailTempDet['emailSubject'], $email_body);
            if ($ObjMail->Send())
            {}
             $emailTempDet  	= $ObjEmailtemplate->getEmailTemlateDetails($languageIDs, '', 'business-request-thank');
		    $ObjMail       	= new Mail($mail_settings);
		    $ObjMail->IsHTML();
		    $this->ObjView->assign('emailbody', $Body);
		    $this->ObjView->assign('companyLogo', $companyLogo);
		    $this->ObjView->assign('siteName', $siteName);
		    $this->ObjView->assign('siteUrl', $siteUrl);
		    $email_body 	= $this->ObjCommon->fetch('email_templates/Layout.tpl');
		    $ObjMail->sendMail(array($emailTempDet['emailFromEmail'],$emailTempDet['emailFromName']), trim($_POST['businessReqEmail']), $emailTempDet['emailSubject'], $email_body);
		    if ($ObjMail->Send())
		    {
		    }
        }
            /*$this->setMessage('language.msgThankYouSuggestion', 'message_success', 'Page', 'message_feature');
                $requestPath = ($_POST['requestPath'])? $_POST['requestPath']:$this->sefPathByID($thankPageID);
               $this->setRedirect($this->ObjView->_views_host_share. '/'.$requestPath,"no");
              exit;*/
                        $thankPageID    =   $ObjContent->getContentIDByKey('thank-you-for-your-interest-in-multi-vendor',$this->ObjCommon->brandID);
                        $requestPath = $this->sefPathByCMS($thankPageID);
                        $this->setRedirect($this->ObjView->_views_host_share. '/'.$requestPath,"no");  
			exit;
        }
        $mkey         = ($this->getRequestValue('orderID'))?$this->getRequestValue('orderID'):''; 
        $this->ObjView->assign('resParentBusiness',$ObjBusinessType->getBusinessTypeOption($languageIDs,'',$defaultOption));
       
        if($mkey!=''){
             $ObjMenu    		  = new MenuModel();
             $userSubgroupID = (int)$this->ObjCommon->REGISTERED_USER_GROUP_ID;
             $resMenu	=	$ObjMenu->getPageMenuItemStatus($mkey,$languageIDs,$userSubgroupID);
             $viewFile=$this->ObjCommon->getCMSLayout($resMenu['menuItemID']);
        }
        $viewFile=($viewFile!='')?$viewFile:$this->ObjCommon->getTemplateFile('contentPage');
        $resListCountry		= $ObjCountry->listCountries($languageIDs, "Yes");
        $this->ObjView->assign('resListCountry', $resListCountry);
        $lblothers          = trim($this->getLanguageValue("lblothers"));
	$defaultOption      = (isset($_POST['businessTypeID']) && $_POST['businessTypeID'] != '') ? $_POST['businessTypeID'] : '';
        $resListBusinessType= $ObjBusinessType->getBusinessTypeOption($languageIDs, $businessType = "others", $defaultOption, $lblothers);
         $this->ObjView->assign('resListBusinessType', $resListBusinessType);
        $this->ObjView->display( $viewFile);
    }
        public function sefPathByCMS($currID)
	{
		$languageIDs       	= $this->ObjView->languageIDs;
		$ObjUrl                 =           new UrlrewriteModel(); 
                $type="page";
              
		$idPath= $type.'/'.$currID.'/';
               // echo $idPath;exit;
		$resUrl = $ObjUrl->getRequestPathByIdPathCMS($languageIDs['Current'],$idPath);
                //print_r($resUrl);exit;
		return $resUrl['requestPath'];
	}
}
