<?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: LanguageModel.php, v 1.0  2013/03/14 14:14:14
class LanguageModel extends Model {
    //FETCHING ALL LANGUAGES
    public function listLanguages($order = NULL, $status = NULL, $start = NULL, $limit = NULL) {
        //$resSelectLanguages	= $this->ObjCache->get('languages.'.$status);
        //if(!$resSelectLanguages){
        $append = '';
        if ($status)
            $append = " AND languageStatus='" . $status . "' ";
        if ($order)
            $append .= " ORDER BY
										" . $order;
        else
            $append .= "
				ORDER BY 
					languageID ASC";
        if ($start && $limit)
            $append .= "LIMIT " . $start . "," . $limit . "";
        $sql                = "
				SELECT 
					* 
				FROM 
					" . DB_PREFIX . "languages
				WHERE 
					languageStatus != 'Delete'" . $append . "";
        $resSelectLanguages = $this->ObjDatabase->readValues($sql);
        //$this->ObjCache->set('languagesActive', $resSelectLanguages, false, 3600);	
        //}
        return $resSelectLanguages;
    }
	public function listAllLanguages($params = array()) {
		extract($params);
        $append = '';
        if ($status)
            $append = " AND languageStatus='" . $status . "' ";
        if ($order)
            $append .= " ORDER BY
										" . $order;
        else
            $append .= "
				ORDER BY 
					languageID ASC";
        if ($start && $limit)
            $append .= "LIMIT " . $start . "," . $limit . "";
        $sql                = "
				SELECT 
					lang.* ,
					lang_images.brandLanguageLogo
				FROM 
					" . DB_PREFIX . "languages lang
				LEFT JOIN " . DB_PREFIX . "brands brands
					ON (brands.brandKey = '" . $brandKey . "' 
				) 
				LEFT JOIN " . DB_PREFIX . "language_brand_images lang_images
					ON (lang.languageID = lang_images.languageID
					AND brands.brandID = lang_images.brandID
				) 
				";
		 $sql .= "			
				WHERE 
					languageStatus != 'Delete'" . $append . "";
        $resSelectLanguages = $this->ObjDatabase->readValues($sql);
        return $resSelectLanguages;
    }
    //DELETING THE DETAILS  OF A LANGUAGE
    public function changeLanguageStatus($languageID, $status = NULL) {
        if (!$status)
            $status = 'Delete';
        $resLanguageDetails = $this->getLanguageDetails($languageID);
        $languagefilePath   = $resLanguageDetails['LanguageLCIDstring'] . '.xml';
        $sql                = "
		UPDATE 
			" . DB_PREFIX . "languages 
		SET 
			`languageStatus` = '" . $status . "'  
		WHERE 
			languageID = '" . (int)$languageID . "'";
        $resUpdateLanguage  = $this->ObjDatabase->setQuery($sql);
        unlink(__CORE_PUBLIC_MANAGE_PATH . "/languages/" . $languagefilePath);
		if(__AFFILIATE_MODULE){
        unlink(__CORE_PUBLIC_AFFILIATE_PATH . "/languages/" . $languagefilePath);
		}
        unlink(__CORE_PUBLIC_BUSINESS_PATH . "/languages/" . $languagefilePath);
        unlink(__CORE_PUBLIC_COMMON_FRONTEND_PATH . "/languages/" . $languagefilePath);
        $this->recursivelyRmDir(__CORE_PUBLIC_FRONTEND_CACHE_PATH . "/" . $languageID . "/");
        if ($this->isDefaultLanguage($languageID) && $status != "Active")
            $this->changeDefaultLanguage(1);
        return $resUpdateLanguage;
    }
    private function recursivelyRmDir($dir) {
        foreach (glob($dir . '/*') as $file) {
            if (is_dir($file))
                $this->recursivelyRmDir($file);
            else
                unlink($file);
        }
        rmdir($dir);
    }
    //SETTING A LANGUAGE AS DEFAULT
    public function changeDefaultLanguage($languageID) {
        $languageID = $this->escape($languageID);
        //Update languageDefault field of all langs to 'No' & selected to 'Yes' 
        $sql        = "
		UPDATE
			" . DB_PREFIX . "languages
		SET 
			languageDefault = 
				CASE WHEN 
					languageID='" . (int)$languageID . "' 
						THEN 'Yes'
					ELSE 'No'
				END";
        $this->ObjDatabase->setQuery($sql);
        $ObjSettings = new SettingsModel();
        $ObjSettings->writeSettingsToXMLFile();
    }
    //GET DEFAULT LANGUAGE ID
    public function getDefaultLanguageID() {
        $sql               = "
		SELECT 
			languageID 
		FROM 
			`" . DB_PREFIX . "languages` 
		WHERE 
			`languageDefault` = 'Yes' 
			AND `languageStatus` != 'Delete'";
        $resSelectLanguage = $this->ObjDatabase->readValueSlave($sql);
        return $resSelectLanguage['languageID'];
    }
    //GET CONTENT LANGUAGE ID
    public function getContentlanguageID($defaultLangID = '', $languageList = '') {
        $ObjFilter         = new Filter();
        $ObjSession        = $ObjFilter->getSessionInstance();
        $ObjCookie         = $ObjFilter->getCookieInstance();
        $contentLanguageID = $ObjSession->getSession($this->getSection() . '_ContentLanguageID');
        $contentLanguageID = $contentLanguageID > 0 ? $contentLanguageID : $ObjCookie->getCookie($this->getSection() . '_CurrentLanguageID');
        //If current Content Language is inactive, set default as Content Language
        if ($languageList && $contentLanguageID > 0 && !in_array($contentLanguageID, $languageList['All'])) {
            //Set Default Language as Content Language
            $contentLanguageID = $languageList['Default'];
        }
        if ($defaultLangID == '' && $contentLanguageID < 1) {
            $defaultLangID = $this->getDefaultLanguageID();
        }
        $contentLanguageID = $contentLanguageID > 0 ? $contentLanguageID : $defaultLangID;
        return $contentLanguageID;
    }
    //Get language by LCID
    public function getLanguageByLCID($languageLCIDstring) {
        $sql = "
		SELECT 
			languageID,
			languageDefault,
			languageCode,
			LanguageLCIDstring 
	    FROM 
			" . DB_PREFIX . "languages 
		WHERE 
			LanguageLCIDstring = '" . $this->escape($languageLCIDstring) . "'
			AND languageStatus = 'Active'
		LIMIT 1";
        return $this->ObjDatabase->readValue($sql);
    }
    //TO SET CONTENT LANGUAGE ID
    public function setContentLanguageID($languageID) {
        $ObjFilter  = new Filter();
        $ObjSession = $ObjFilter->getSessionInstance();
        $ObjSession->setSession($this->getSection() . '_ContentLanguageID', $languageID);
        $result = $this->getContentLCID($languageID);
        $ObjSession->setSession($this->getSection() . '_ContentLCID', $result);
        return $ObjSession->getSession($this->getSection() . '_ContentLanguageID');
    }
    public function getContentLCID($languageID) {
        if(is_array($languageID)) {
            $languageID = !empty($languageID[0])?$languageID[0]:1;
        }
        $sql = "
		SELECT 			
			LanguageLCIDstring 
	    FROM 
			" . DB_PREFIX . "languages 
		WHERE 
			languageID = '" . (int)$languageID . "'
			AND languageStatus = 'Active'";
        return $this->ObjDatabase->getField($sql);
    }
    //TO GET CURRENT LANGUAGE KEY
    public function getLanguageKey() {
        $sql = "
		SELECT 
			languageKey 
		FROM 
			`" . DB_PREFIX . "languages` 
		WHERE 
			`languageDefault` = 'Yes' 
			AND `languageStatus` != 'Delete'";
        return $this->ObjDatabase->readValue($sql);
    }
    //FETCHING A PARTICLUAR LANGUAGE BY LANGUAGE ID
    public function getLanguageDetails($languageID,$brandID="") {
        $sql = "
		SELECT 
			* 
		FROM 
			`" . DB_PREFIX . "languages` 
		WHERE 
			`languageID` =" . (int)$languageID . "
		LIMIT 1";
        $result =  $this->ObjDatabase->readValue($sql);
		if (isset($brandID) && $brandID > 0) {
			$sql = " SELECT brandLanguageLogo	 FROM " . DB_PREFIX . "language_brand_images  WHERE 
                     languageID	 = '" . (int)$languageID	 . "' AND brandID = '" . (int)$brandID . "'";
            $brandLanguageLogo = $this->ObjDatabase->getField($sql);
			$result['languageLogo'] = $brandLanguageLogo;
		}
		return  $result;
    }
    //CHECKING WHETHER A LANGUAGE WITH SAME CODE EXISTS
    public function isLanguageCodeExixts($LanguageLCIDstring, $languageID = NULL) {
        $append = '';
        if ($languageID)
            $append = "AND `languageID` != '" . (int)$languageID . "'";
        $sql    = "
		SELECT 
			* 
		FROM 
			`" . DB_PREFIX . "languages` 
		WHERE 
			`LanguageLCIDstring` = '" . $this->escape($LanguageLCIDstring) . "' 
			AND `languageStatus` != 'Delete' " . $append . "";
        $result = $this->ObjDatabase->numberOfRecords($sql);
        if ($result != 0)
            return true;
        else
            return false;
    }
    //CHECKING IS DEFAULT LANGUAGE
    public function isDefaultLanguage($languageID) {
        $sql               = "
		SELECT 
			* 
		FROM 
			`" . DB_PREFIX . "languages` 
		WHERE 
			`languageID` = '" . (int)$languageID . "' 
			AND `languageStatus`!='Delete'  
			AND `languageDefault` = 'Yes'";
        $resSelectLanguage = $this->ObjDatabase->numberOfRecords($sql);
        if ($resSelectLanguage)
            return true;
        else
            return false;
    }
    //EDITING OR ADDING A NEW LANGUAGE
    public function saveLanguageDetails($POST, $languageID = NULL) {
        $name                     = $this->escape($POST['languageName']);
        $languageDirection        = $this->escape($POST['languageDirection']);
        $code                     = $this->escape($POST['languageCode']);
        $LCIDString               = $this->escape($POST['LanguageLCIDstring']);
        $locale                   = $this->escape($POST['languageLocale']);
        $status                   = $this->escape($POST['languageStatus']);
        $image                    = $_POST['languageImage'];
        $languageLogo             = $_POST['languageLogo'];		
        $brandID             	  = $this->escape($_POST['brandID']);		
        $languageFileExt          = strtolower(end(explode(".", $_FILES["languageFile"]['name'])));
        $languageFileExtFrontEnd  = strtolower(end(explode(".", $_FILES["languageFileFrontEnd"]['name'])));
        $languageFileExtBusiness  = strtolower(end(explode(".", $_FILES["languageFileBusiness"]['name'])));
        $languageFileExtAffiliate = strtolower(end(explode(".", $_FILES["languageFileAffiliate"]['name'])));
        $languageFileExtMobileapp = strtolower(end(explode(".", $_FILES["languageFileMobileApp"]['name'])));
        if ($languageID) {
            $resSelectlanguage    = $this->getLanguageDetails($languageID);
            $oldLCIDstr           = stripslashes($resSelectlanguage['LanguageLCIDstring']);
            //$image 					=	$resSelectlanguage['languageImage'];
            $oldFileName          = __CORE_PUBLIC_MANAGE_PATH . "/languages/" . $oldLCIDstr . ".xml";
            //$this->ObjCache->delete(preg_replace("/[^A-Za-z0-9]/", "", $oldFileName));
            $oldFileNameFrontEnd  = __CORE_PUBLIC_COMMON_FRONTEND_PATH . "/languages/" . $oldLCIDstr . ".xml";
            //$this->ObjCache->delete(preg_replace("/[^A-Za-z0-9]/", "", $oldFileNameFrontEnd));
            $oldFileNameBusiness  = __CORE_PUBLIC_BUSINESS_PATH . "/languages/" . $oldLCIDstr . ".xml";
            //$this->ObjCache->delete(preg_replace("/[^A-Za-z0-9]/", "", $oldFileNameBusiness));
            $oldFileNameAffiliate = __CORE_PUBLIC_AFFILIATE_PATH . "/languages/" . $oldLCIDstr . ".xml";
            $oldFileNameMobileapp = __CORE_PUBLIC_PATH . "/" . __DIR_PUBLIC_CORE . "/mobileapp/standard/languages/" . $oldLCIDstr . ".xml";
            //$this->ObjCache->delete(preg_replace("/[^A-Za-z0-9]/", "", $oldFileNameAffiliate));
            if (file_exists($oldFileName) && $languageFileExt == "") {
                rename($oldFileName, __CORE_PUBLIC_MANAGE_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
            }
            if (file_exists($oldFileNameFrontEnd) && $languageFileExtFrontEnd == "") {
                rename($oldFileNameFrontEnd, __CORE_PUBLIC_COMMON_FRONTEND_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
            }
            if (file_exists($oldFileNameBusiness) && $languageFileExtBusiness == "") {
                rename($oldFileNameBusiness, __CORE_PUBLIC_BUSINESS_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
            }
            if (file_exists($oldFileNameAffiliate) && $languageFileExtAffiliate == "") {
                rename($oldFileNameAffiliate, __CORE_PUBLIC_AFFILIATE_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
            }
            if (file_exists($oldFileNameMobileapp) && $languageFileExtMobileapp == "") {
                rename($oldFileNameMobileapp, __CORE_PUBLIC_PATH . "/" . __DIR_PUBLIC_CORE . "/mobileapp/standard/languages/" . $POST['LanguageLCIDstring'] . ".xml");
        }
        }
        if ($languageFileExtFrontEnd == 'xml') {
            copy($_FILES["languageFileFrontEnd"]['tmp_name'], __CORE_PUBLIC_COMMON_FRONTEND_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
            if ($languageID) {
                //reset frontend language listing cache variable
                $objCache = new Cache(CACHE_DRIVER);
                $objCache->delete('f_lng_xml_' . $languageID);
            }
        }
        if ($languageFileExt == 'xml') {
            copy($_FILES["languageFile"]['tmp_name'], __CORE_PUBLIC_MANAGE_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
        }
        if ($languageFileExtBusiness == 'xml') {
            copy($_FILES["languageFileBusiness"]['tmp_name'], __CORE_PUBLIC_BUSINESS_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
        }
        if ($languageFileExtAffiliate == 'xml') {
            copy($_FILES["languageFileAffiliate"]['tmp_name'], __CORE_PUBLIC_AFFILIATE_PATH . "/languages/" . $POST['LanguageLCIDstring'] . ".xml");
        }
        if ($languageFileExtMobileapp == 'xml') {
            copy($_FILES["languageFileMobileApp"]['tmp_name'], __CORE_PUBLIC_PATH . "/" . __DIR_PUBLIC_CORE . "/mobileapp/standard/languages/" . $POST['LanguageLCIDstring'] . ".xml");
        }
		//if (!empty($POST["HiddenImageUrl"]) && !empty($POST["languageImage_temp"]) && !empty($image)) {
        if ( !empty($POST["languageImage_temp"]) && !empty($image)) {
            $ObjImage = new ImageModel();
            $ObjImage->resizeImage(__ROOT_PATH . '/' . $_POST["languageImage_temp"], '', 16, 11);
            $ObjImage->copy_file($_POST["languageImage_temp"], '/' . __UPLOADS_FOLDER . 'languages/' . $image);
            @unlink($_POST["languageImage_temp"]);
        }
		 if (!empty($POST["languageLogo_temp"]) && !empty($languageLogo)) {
            $ObjImage = new ImageModel();
           // $ObjImage->resizeImage(__ROOT_PATH . '/' . $_POST["languageImage_temp"], '', 16, 11);
            //$ObjImage->copy_file($_POST["languageLogo_temp"], '/' . __UPLOADS_FOLDER . 'languages/logo/' . $languageLogo);
			
			$languageLogo = $brandID.'__'.$LCIDString.'__'.$languageLogo;
			$ObjImage->copy_file($_POST["languageLogo_temp"], '/' . __UPLOADS_FOLDER . 'languages/logo/' . $languageLogo);
            @unlink($_POST["languageLogo_temp"]);
        }
        if (empty($languageID)) {
            $sql               = "
			INSERT INTO 
				`" . DB_PREFIX . "languages` (
					`languageName`, 
					`languageCode`, 
					`LanguageLCIDstring`,
					`languageLocale`, 
					`languageDirection`, 
					`languageImage`,
					`languageStatus`,
					`languageLogo`
					
				) VALUES (
					'" . $name . "', 
					'" . $code . "', 
					'" . $LCIDString . "',
					'" . $locale . "', 
					'" . $languageDirection . "', 
					'" . $image . "',
					'" . $status . "',
					'" . $languageLogo . "'
				)";
            $resInsertLanguage = $this->ObjDatabase->setQuery($sql);			
			$currentLanguageID = $this->ObjDatabase->getInsertId();
            $defaultLanguageID = $this->getLanguageID();
            $this->makeCacheDirectoryForLanguage($currentLanguageID);
            $this->syncCountriesAndStateLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncBusTypeAndProductTypeLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncemailtemplateLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncProductCategoryLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncBusinessLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncActiveProductLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncUrlLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncDeliveryZones($defaultLanguageID, $currentLanguageID);
            $this->syncStaticBlocks($defaultLanguageID, $currentLanguageID);
            $this->syncBanners($defaultLanguageID, $currentLanguageID);
            $this->syncNewsletterTemplates($defaultLanguageID, $currentLanguageID);
            $this->syncMenuLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncWidgetLanguages($defaultLanguageID, $currentLanguageID);
            $this->syncForms($defaultLanguageID, $currentLanguageID);
            $this->syncUserGroups($defaultLanguageID, $currentLanguageID);
            $this->syncBrands($defaultLanguageID, $currentLanguageID);
			if (!empty($POST["languageLogo_temp"]) && !empty($languageLogo)) {
				$sql               = "
				INSERT INTO 
					`" . DB_PREFIX . "language_brand_images` (
						`languageID`,
						`brandID`,
						`brandLanguageLogo`
						
					) VALUES (
						'" . $currentLanguageID . "', 
						'" . $brandID . "',
						'" . $languageLogo . "'
					)";
				$this->ObjDatabase->setQuery($sql);
		  }
        } else {
            $sql               = "
			UPDATE 
				`" . DB_PREFIX . "languages` 
			SET 
				`languageName` = '" . $name . "', 
				`languageCode` = '" . $code . "', 
				`languageDirection`='" . $languageDirection . "',
				`LanguageLCIDstring`='" . $LCIDString . "',
				`languageLocale` = '" . $locale . "', 
				`languageImage` = '" . $image . "',
				`languageStatus` = '" . $status . "',
				`languageLogo` = '" . $languageLogo . "' 
			WHERE 
				`languageID` = '" . $languageID . "'";
            $resUpdateLanguage = $this->ObjDatabase->setQuery($sql);
            if ($status == "Inactive" && $this->isDefaultLanguage($languageID)) {
                $this->changeLanguageStatus(1, "Active");
                $this->changeDefaultLanguage(1);
            }
			if (!empty($POST["languageLogo_temp"]) && !empty($languageLogo)) {
				$sql = "SELECT id FROM " . DB_PREFIX . "language_brand_images  WHERE languageID	 = '" . $languageID	 . "' 
						AND brandID = '" . $brandID . "'";
            $id = $this->ObjDatabase->getField($sql);
			if($id>0){
				$sql               = "
					UPDATE 
						`" . DB_PREFIX . "language_brand_images` 
					SET  
						`brandLanguageLogo` = '" . $languageLogo . "' 
					WHERE 
						`languageID` = '" . $languageID . "' AND brandID = '" . $brandID . "'";
				$this->ObjDatabase->setQuery($sql);
			} else {
				$sql               = "
				INSERT INTO 
					`" . DB_PREFIX . "language_brand_images` (
						`languageID`,
						`brandID`,
						`brandLanguageLogo`
						
					) VALUES (
						'" . $languageID . "', 
						'" . $brandID . "',
						'" . $languageLogo . "'
					)";
				$this->ObjDatabase->setQuery($sql);
				
			}
		  }
        }
	
    }
    //Function to create directory for each languageID
    private function makeCacheDirectoryForLanguage($languageID) {
        if (!file_exists(__CORE_PUBLIC_FRONTEND_CACHE_PATH . "/" . $languageID . "/"))
            mkdir(__CORE_PUBLIC_FRONTEND_CACHE_PATH . "/" . $languageID . "/");
        chmod(__CORE_PUBLIC_FRONTEND_CACHE_PATH . "/" . $languageID . "/", 0777);
    }
    // these function is used in settings model also
    public function updateDefaultLanguage($languageLCIDstring) {
        $sql       = "
		UPDATE 
			`" . DB_PREFIX . "languages` 
		SET 
			`languageDefault` = 'No'";
        $RowResult = $this->ObjDatabase->setQuery($sql);
        $sql       = "
		UPDATE 
			`" . DB_PREFIX . "languages` 
		SET 
			`languageDefault` = 'Yes' 
		WHERE 
			`LanguageLCIDstring` ='" . $languageLCIDstring . "' 
			AND `languageStatus` = 'Active'";
        $RowResult = $this->ObjDatabase->setQuery($sql);
    }
    public function syncMenuLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "INSERT INTO " . DB_PREFIX . "menu_details(
				  menuID, 
				  languageID, 
				  menuName, 
				  MenuDesc
				) 
				SELECT 
				  menu.menuID, 
				  '" . (int)$currentLanguageID . "' AS languageID, 
				  menDet.menuName, 
				  menDet.MenuDesc 
				FROM 
				  " . DB_PREFIX . "menu menu 
				  LEFT JOIN " . DB_PREFIX . "menu_details menDet 
				  ON menu.menuID = menDet.menuID 
				WHERE 
				  menDet.languageID = '" . (int)$defaultLanguageID . "' 
				  AND menu.status != 'Deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    //Synchronize countries and states
    public function syncCountriesAndStateLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "country_details (
				countryID,
				countryName,
				languageID
			) 
             SELECT 
			 	countryID,
				countryName,
				'" . (int)$currentLanguageID . "' AS languageID 
             FROM 
			 	" . DB_PREFIX . "country_details 
			WHERE 
				languageID = '" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "state_details(
				stateID,
				languageID,
				stateName
			)
             SELECT 
			 	staDet.stateID,
				'" . (int)$currentLanguageID . "' AS languageID,
				staDet.stateName 
            FROM 
				" . DB_PREFIX . "state_details staDet
			LEFT JOIN 
				" . DB_PREFIX . "states sta ON staDet.stateID =sta.stateID
			WHERE 
				staDet.languageID = '" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
    }
    public function syncemailtemplateLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "email_template_details(
				emailTempID,
				languageID,
				emailSubject,
				emailHtml,
				emailText
			)
            SELECT 
				emailTempID,
				'" . (int)$currentLanguageID . "' AS languageID,
				emailSubject,
				emailHtml,
				emailText 
            FROM 
				" . DB_PREFIX . "email_template_details 
			WHERE 
				languageID = '" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "email_template_sectons(
				sectionName,
				sectionUniqueString,
				languageID,
				sectionContent
			)
            SELECT 
				sectionName,
				sectionUniqueString,
				'" . (int)$currentLanguageID . "' AS languageID,
				sectionContent
            FROM 
				" . DB_PREFIX . "email_template_sectons 
			WHERE 
				languageID = '" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
    }
    /********* Synchronise BusinessType And Product Type **********/
    public function syncBusTypeAndProductTypeLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "business_type_details(
				businessTypeID,
				businessTypeName,
				languageID,
				businessTypeDescription
			) 
            SELECT 
				busTypDet.businessTypeID,
				busTypDet.businessTypeName,
				'" . (int)$currentLanguageID . "' AS languageID,
				busTypDet.businessTypeDescription 
			FROM 
			 	" . DB_PREFIX . "business_types busTyp
			LEFT JOIN 
				" . DB_PREFIX . "business_type_details busTypDet ON busTypDet.businessTypeId=busTyp.businessTypeId
			WHERE 
				busTypDet.languageID='" . (int)$defaultLanguageID . "' 
				AND busTyp.businessTypeStatus<>'Delete'";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "product_type_details(
				productTypeID,
				languageID,
				productTypeName,
				productTypeDescription
			)
            SELECT 
				productTypDet.productTypeID,
				'" . (int)$currentLanguageID . "' AS languageID,
				productTypDet.productTypeName,
				productTypDet.productTypeDescription 
			FROM 
				" . DB_PREFIX . "product_types productTyp
			LEFT JOIN 
				" . DB_PREFIX . "product_type_details productTypDet ON productTypDet.productTypeID=productTyp.productTypeID
			WHERE 
				productTypDet.languageID='" . (int)$defaultLanguageID . "' 
				AND productTyp.productTypeStatus<>'Deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    public function syncUrlLanguages($defaultLanguageID, $currentLanguageID) {
        //for product & categories
        $sqlCcmmon = "INSERT INTO 
			" . DB_PREFIX . "url_rewrite(
				objectID,
				parentID,
				type,
				idPath,
                                requestPath,
                                targetPath,
                                languageID,
                                redirectOption,
                                isSystem,
                                description
			) 
                        SELECT 
				url.objectID,
				url.parentID,
				url.type,
				url.idPath,
                                url.requestPath,
                                url.targetPath,
                                '" . (int)$currentLanguageID . "' AS languageID,
                                '' AS redirectOption,
                                url.isSystem,
                                description
				
			FROM 
				" . DB_PREFIX . "url_rewrite url
			
			WHERE languageID='" . (int)$defaultLanguageID . "'  AND  isSystem=1 ";
        $sql       = $sqlCcmmon . "	AND (type='catalog' OR type='product' OR type='blogCategory' )    ";
        $this->ObjDatabase->setQuery($sql);
        //sync page
        $sql     = "SELECT contentID FROM " . DB_PREFIX . "content_pages
				WHERE 
				  languages='0'";
        $results = $this->ObjDatabase->readValues($sql, MYSQLI_ASSOC);
        foreach ($results as $result) {
            $sql = $sqlCcmmon . "	AND type='page' AND objectID='" . (int)$result['contentID'] . "'  ";
            $this->ObjDatabase->setQuery($sql);
        }
        //sync menu
        $sql     = "SELECT menuItemID FROM " . DB_PREFIX . "menu_item
				WHERE 
				  availableLang='0'";
        $results = $this->ObjDatabase->readValues($sql, MYSQLI_ASSOC);
        foreach ($results as $result) {
            $sql = $sqlCcmmon . " AND type='menu' AND objectID='" . (int)$result['menuItemID'] . "'  ";
            $this->ObjDatabase->setQuery($sql);
        }
        
    }
    /********* Synchronise Business **********/
    public function syncBusinessLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "business_details(
				businessID,
				businessName,
				languageID,
				businessProfile
			) 
            SELECT 
				busDet.businessID,
				busDet.businessName,
				'" . (int)$currentLanguageID . "' AS languageID,
				busDet.businessProfile 
			FROM 
				" . DB_PREFIX . "business_details busDet
			LEFT JOIN 
				" . DB_PREFIX . "business bus ON busDet.businessID=bus.businessID 
			WHERE 
				busDet.languageID='" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "business_location_details(
				businessLocID,
				languageID,
				locName,
				locAddress1,
				locAddress2,
				locCity,
				locProvince
			)
            SELECT 
				busLocDet.businessLocID,'" . (int)$currentLanguageID . "' AS languageID,
				busLocDet.locName,
				busLocDet.locAddress1,
				busLocDet.locAddress2,
				busLocDet.locCity,
				busLocDet.locProvince
			FROM 
				" . DB_PREFIX . "business_locations busLoc
			LEFT JOIN 
				" . DB_PREFIX . "business_location_details busLocDet ON busLoc.businessLocID=busLocDet.businessLocID
			WHERE 
				busLocDet.languageID='" . (int)$defaultLanguageID . "' 
				AND busLoc.locStatus<>'Deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    /********* Synchronise Product Categories **********/
    public function syncProductCategoryLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "product_category_details(
				productCategoryID,
				languageID,
				productCategoryName,
				productCategoryDescription,
				productCategoryMetaTitle,
				productCategoryMetaKeywords,
				productCategoryMetaDescription
			) 
            SELECT 
				productCatDet.productCategoryID,
				'" . (int)$currentLanguageID . "' AS languageID,
				productCatDet.productCategoryName,
				productCatDet.productCategoryDescription,
				productCategoryMetaTitle,
				productCategoryMetaKeywords,
				productCategoryMetaDescription 
          	FROM 
				" . DB_PREFIX . "product_categories productCat
			LEFT JOIN 
				" . DB_PREFIX . "product_category_details productCatDet ON productCat.productCategoryID=productCatDet.productCategoryID 
			WHERE 
				productCatDet.languageID='" . (int)$defaultLanguageID . "' 
				AND productCat.productCategoryStatus!='Delete'";
        $this->ObjDatabase->setQuery($sql);
    }
    /********* Synchronise Upcoming / Current Products **********/
    /********* Synchronise Product Categories **********/
    public function syncUserGroups($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "user_group_details(
				`languageID`, `userGroupID`, `userGroupName`
			) 
            SELECT 
				'" . (int)$currentLanguageID . "' AS languageID,
				usrGroDet.`userGroupID`, 
				`userGroupName`
          	FROM 
				" . DB_PREFIX . "user_group usrGro
			LEFT JOIN 
				" . DB_PREFIX . "user_group_details usrGroDet ON usrGro.userGroupID=usrGroDet.userGroupID 
			WHERE 
				usrGroDet.languageID='" . (int)$defaultLanguageID . "' 
				AND usrGro.userGroupStatus!='Deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    /********* Synchronise Upcoming / Current Products **********/
    /********* Synchronise Product Categories **********/
    public function syncBrands($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "brand_details(
				`brandID`, 
				`languageID`, 
				`brandName`, 
				`brandDescription`, 
				`metaTitle`, 
				`metaDescription`, 
				`searchKeywords`
			) 
            SELECT 
				brandDet.`brandID`, 
				'" . (int)$currentLanguageID . "' AS languageID,
				`brandName`, 
				`brandDescription`, 
				`metaTitle`, 
				`metaDescription`, 
				`searchKeywords`
          	FROM 
				" . DB_PREFIX . "brands brand
			LEFT JOIN 
				" . DB_PREFIX . "brand_details brandDet ON brand.brandID=brandDet.brandID 
			WHERE 
				brandDet.languageID='" . (int)$defaultLanguageID . "' 
				AND brand.status!='D'";
        $this->ObjDatabase->setQuery($sql);
    }
    /********* Synchronise Upcoming / Current Products **********/
    public function syncActiveProductLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "product_details(
				languageID,
				productID,
				productTitle,				
				productFinePrint,
				productHighlights,
				productDescription,								
				productMetaTitle,
				productMetaDescription,
				productMetaKeywords,
				searchTags
			) 
            SELECT 
				'" . (int)$currentLanguageID . "' AS languageID,
				productID,
				productTitle,
				productFinePrint,
				productHighlights,
				productDescription,							
				productMetaTitle,
				productMetaDescription,
				productMetaKeywords,
				searchTags
             FROM 
			 	" . DB_PREFIX . "product_details 
			WHERE 
				languageID ='" . (int)$defaultLanguageID . "' 
				AND productID IN (
								SELECT 
									product.productID 
								FROM 
									" . DB_PREFIX . "products product								 
								WHERE 
									product.productStatus != 'Deleted'
								GROUP BY product.productID
								)";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "product_option_details(
				productOptionID,
				languageID,
				productOptionName
				) 
            SELECT 
				productOptDet.productOptionID,
				'" . (int)$currentLanguageID . "' AS languageID,
				productOptDet.productOptionName
            FROM 
				" . DB_PREFIX . "product_options productOpt 
			LEFT JOIN 
				" . DB_PREFIX . "product_option_details productOptDet 
				ON productOpt.productOptionID=productOptDet.productOptionID
			WHERE 
				productOptDet.languageID ='" . (int)$defaultLanguageID . "' 
				AND productOpt.productOptionStatus<>'Delete' 
				AND productOpt.productID IN (
					SELECT 
						product.productID 
					FROM 
						" . DB_PREFIX . "products product					 
					WHERE 
						product.productStatus  != 'Deleted'
					GROUP BY product.productID
				)";
        $this->ObjDatabase->setQuery($sql);
        //Custom Option Details
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "product_custom_option_details(
				customOptionID,
				languageID,
				customOptionName,
				validationMessage,
				helpText
				)
		SELECT 
				customOptDet.customOptionID,
				'" . (int)$currentLanguageID . "' AS languageID,
				customOptDet.customOptionName,
				customOptDet.validationMessage,
				customOptDet.helpText
		FROM 
				" . DB_PREFIX . "product_custom_option_details customOptDet
			WHERE 
				customOptDet.languageID ='" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        //variant Details
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "product_custom_option_variant_details(
				customOptionVariantID,
				languageID,
				value
				)
		SELECT 
				customOptionVariantID,
				'" . (int)$currentLanguageID . "' AS languageID,
				value
		FROM 
				" . DB_PREFIX . "product_custom_option_variant_details 
			WHERE 
				languageID ='" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        //Attribute Details
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "attribute_details(
				attributeID,
				languageID,
				attrName
				) 
			SELECT 
				attrDet.attributeID,
				'" . (int)$currentLanguageID . "' AS languageID,
				attrDet.attrName
			FROM 
				
				" . DB_PREFIX . "attribute_details attrDet
			WHERE 
				attrDet.languageID ='" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        //Attribute Option Details
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "attribute_option_details(
				attrOptionID,
				languageID,
				attrOptName
				) 
			SELECT 
				attrOptionID,
				'" . (int)$currentLanguageID . "' AS languageID,
				attrOptName
			FROM 
				
				" . DB_PREFIX . "attribute_option_details
			WHERE 
				languageID ='" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        //Attribute Group Details
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "attribute_group_details(
				attributeGroupID,
				languageID,
				name
				) 
			SELECT 
				attributeGroupID,
				'" . (int)$currentLanguageID . "' AS languageID,
				name
			FROM 
				
				" . DB_PREFIX . "attribute_group_details
			WHERE 
				languageID ='" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        //Attribute Value Details
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "product_attribute_value_details(
				attrValueID,
				languageID,
				attrDetValue
				)
		SELECT 
				attrValDet.attrValueID,
				'" . (int)$currentLanguageID . "' AS languageID,
				attrDetValue
		FROM 
				" . DB_PREFIX . "product_attribute_value_details attrValDet 
			LEFT JOIN 
				" . DB_PREFIX . "product_attribute_values attrVal 
				ON attrVal.attrValueID=attrValDet.attrValueID
			WHERE 
				attrValDet.languageID ='" . (int)$defaultLanguageID . "' 				
				AND attrVal.productID IN (
					SELECT 
						product.productID 
					FROM 
						" . DB_PREFIX . "products product					 
					WHERE

						product.productStatus != 'Deleted')";
        $this->ObjDatabase->setQuery($sql);
    }
    public function currentLanguageLCIDstring() {
        $ObjFilter         = new Filter();
        $ObjCookie         = $ObjFilter->getCookieInstance();
        $currentLanguageID = $ObjCookie->getCookie($this->getSection() . '_CurrentLanguageID');
        if ($currentLanguageID > 0) {
            return $this->getLanguageLCIDstring($currentLanguageID);
        } else {
            $sql = "
					SELECT 
						LanguageLCIDstring 
					FROM 
						" . DB_PREFIX . "languages 
					WHERE 
						languageDefault = 'Yes' 
						AND languageStatus != 'Delete'";
            return $this->ObjDatabase->getField($sql);
        }
    }
    // function to update User,Business language preference
    public function resetThisLanguagePreferences($inactiveLanguageID, $defaultLanguageID) {
        $sql             = "
		UPDATE 
			" . DB_PREFIX . "users 
		SET 
			userDefaultLanguage=" . (int)$defaultLanguageID . " 
		WHERE 
			userDefaultLanguage='" . (int)$inactiveLanguageID . "'";
        $resUserLanguage = $this->ObjDatabase->setQuery($sql);
        $sql             = "
		UPDATE 
			" . DB_PREFIX . "business 
		SET 
			businessDefaultLanguageID=" .(int)$defaultLanguageID . " 
		WHERE 
			businessDefaultLanguageID='" . (int)$inactiveLanguageID . "'";
        $resBizLanguage  = $this->ObjDatabase->setQuery($sql);
    }
    public function getSettingsValue($settingsGroupId, $settingsKey) {
        $sql              = "
		SELECT 
			settingsValue 
		FROM 
			" . DB_PREFIX . "settings 
		WHERE 
			settingsGroupID='" . $settingsGroupId . "' 
			AND settingsKey='" . $settingsKey . "'";
        $resSettingsValue = $this->ObjDatabase->readValue($sql);
        return $resSettingsValue['settingsValue'];
    }
    public function loadLanguageXMLtoArray($file,$theme_language=array()) {

        $xmlArray = array();
        foreach (simplexml_load_file($file) as $key => $node) {
            $nodeArray = (array) $node;
            //$xmlArray[$key]	= ($nodeArray['@attributes']['custom']) ? $nodeArray['@attributes']['custom'] : $nodeArray['@attributes']['default'];
            if (isset($nodeArray['@attributes']['custom']))
                $xmlArray[$key] = $nodeArray['@attributes']['custom'];
            else if (isset($nodeArray['@attributes']['default']))
                $xmlArray[$key] = $nodeArray['@attributes']['default'];
        }
        if(!empty($theme_language)){
			foreach(simplexml_load_file($theme_language) as $key => $node)
			{
				$nodeArray		= (array)$node;
				if(isset($nodeArray['@attributes']['custom']))
					$xmlArray[$key]	= $nodeArray['@attributes']['custom'];
				else if(isset($nodeArray['@attributes']['default']))
					$xmlArray[$key]	= $nodeArray['@attributes']['default'];				
			}		
		}
        return $xmlArray;
    }
    //GET LANGUAGE ID
    public function getLanguageID() {
        $sql               = "
			SELECT 
				languageID 
			FROM 
				`" . DB_PREFIX . "languages` 
			WHERE 
				`languageDefault` = 'Yes' 
				AND `languageStatus` != 'Delete'";
        $resSelectLanguage = $this->ObjDatabase->readValue($sql);
        return $resSelectLanguage['languageID'];
    }
    //GET LanguageLCIDstring
    public function getLanguageLCIDstring($languageID) {
        if(is_array($languageID)) {
            $languageID = !empty($languageID[0])?$languageID[0]:1;
        }
        $sql = "
		SELECT 
			LanguageLCIDstring 
		FROM 
			" . DB_PREFIX . "languages 
		WHERE 
			languageID =" . (int)$languageID . "
		LIMIT 1";
        return $this->ObjDatabase->getFieldSlave($sql);
    }
    public function syncDeliveryZones($defaultLanguageID, $currentLanguageID) {
        $sql = "INSERT INTO " . DB_PREFIX . "deliveryzone_details(
			  deliveryZoneID, 
			  languageID, 
			  deliveryZoneName,
			  deliveryZoneDescription
			) 
			SELECT 
			  delzon.deliveryZoneID, 
			  '" . (int)$currentLanguageID . "' AS languageID, 
			  delzonDet.deliveryZoneName,
			  delzonDet.deliveryZoneDescription
			FROM 
			  " . DB_PREFIX . "deliveryzones delzon
			LEFT  JOIN " . DB_PREFIX . "deliveryzone_details delzonDet 
			  ON delzonDet.deliveryZoneID = delzon.deliveryZoneID
			WHERE 
				delzonDet.languageID = '" . (int)$defaultLanguageID . "' 
			  AND delzon.deliveryZoneStatus != 'Deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    public function syncStaticBlocks($defaultLanguageID, $currentLanguageID) {
        $sql = "INSERT INTO " . DB_PREFIX . "static_blocks_details(
			  blockID, 
			  languageID, 
			  blockTitle,
			  blockContent
			) 
			SELECT 
			  staBlo.blockID, 
			  '" . (int)$currentLanguageID . "' AS languageID, 
			  staBloDet.blockTitle,
			  staBloDet.blockContent
			FROM 
			  " . DB_PREFIX . "static_blocks AS staBlo
			LEFT  JOIN " . DB_PREFIX . "static_blocks_details AS staBloDet
			  ON staBlo.blockID = staBloDet.blockID 
			WHERE 
				staBloDet.languageID = '" . (int)$defaultLanguageID . "' 
			  AND staBlo.status != 'Deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    public function syncBanners($defaultLanguageID, $currentLanguageID) {
        $sql = "INSERT INTO " . DB_PREFIX . "banner_details(
			  bannerID, 
			  languageID, 
			  bannerTitle,
			  bannerContent
			) 
			SELECT 
			  ban.bannerID, 
			  '" . (int)$currentLanguageID . "' AS languageID, 
			  banDet.bannerTitle,
			  banDet.bannerContent
			FROM 
			  " . DB_PREFIX . "banner AS ban
			LEFT  JOIN " . DB_PREFIX . "banner_details	AS	banDet
			  ON banDet.bannerID	=	ban.bannerID
			WHERE 
				banDet.languageID = '" . (int)$defaultLanguageID . "' 
			  AND ban.bannerStatus != 'Deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    public function get_language_from_lcid($LCIDString) {
        $sql               = " SELECT 
						languageID 
					FROM 
						" . DB_PREFIX . "languages 
					WHERE 
						LanguageLCIDstring ='" . $LCIDString . "'
						AND `languageStatus` = 'Active'
					LIMIT 1";
        $resSelectLanguage = $this->ObjDatabase->readValue($sql);
        return isset($resSelectLanguage['languageID']) ? $resSelectLanguage['languageID'] : 0;
    }
    public function setLanguageFromURL($LCIDString) {
        $sql               = "
		SELECT 
			languageID,LanguageLCIDstring 
		FROM 
			" . DB_PREFIX . "languages 
		WHERE 
			LanguageLCIDstring ='" . $this->escape($LCIDString) . "'
                            AND `languageStatus` != 'Delete'
		LIMIT 1";
        $resSelectLanguage = $this->ObjDatabase->readValueSlave($sql);
        $ObjFilter         = new Filter();
        $ObjCookie         = $ObjFilter->getCookieInstance();
        if ($resSelectLanguage) {
            $ObjCookie->setCookie($this->getSection() . '_CurrentLanguageID', $resSelectLanguage['languageID']);
            $ObjCookie->setCookie($this->getSection() . '_LanguageLCIDstring', $resSelectLanguage['LanguageLCIDstring']);
            return $resSelectLanguage['languageID'];
        }
        return false;
    }
    public function syncNewsletterTemplates($defaultLanguageID, $currentLanguageID) {
        $sql = "INSERT INTO " . DB_PREFIX . "newsletter_template_details(
			  nlTemplateID, 
			  languageID, 
			  nlTemplateName,
			  nlTemplateContent
			) 
			SELECT 
			  newTem.nlTemplateID, 
			  '" . (int)$currentLanguageID . "' AS languageID, 
			  newTemDet.nlTemplateName,
			  newTemDet.nlTemplateContent
			FROM 
			  " . DB_PREFIX . "newsletter_templates AS newTem
			LEFT  JOIN " . DB_PREFIX . "newsletter_template_details	AS	newTemDet
			  ON newTem.nlTemplateID	=	newTemDet.nlTemplateID
			WHERE 
				newTemDet.languageID = '" . (int)$defaultLanguageID . "' 
				AND newTem.nltStatus != 'deleted'";
        $this->ObjDatabase->setQuery($sql);
    }
    public function syncForms($defaultLanguageID, $currentLanguageID) {
        $sql = "
			INSERT INTO " . DB_PREFIX . "form_entity_details
				(
				formID,
				languageID,
				formName,
				formDesc,
				submitButtonValue,
				afterFormSubmissionAction,
				disableFormMessage,
				agreementText,
				adminEmailSubject,
				adminEmailContent,
				userEmailSubject,
				userEmailContent
				)
			(
				SELECT
					formID,
					'" . (int)$currentLanguageID . "',
					formName,
					formDesc,
					submitButtonValue,
					afterFormSubmissionAction,
					disableFormMessage,
					agreementText,
					adminEmailSubject,
					adminEmailContent,
					userEmailSubject,
					userEmailContent
				FROM
					" . DB_PREFIX . "form_entity_details
				WHERE
					languageID = '" . (int)$defaultLanguageID . "' 
			)
		";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
			INSERT INTO " . DB_PREFIX . "form_element_details
				(
				formElementID,
				languageID,
				formElementLabel,
				formElementDesc,
				formElementSubText,
				formElementPlaceHolder,
				formElementValue,
				formValidationMessage
				)
			(
				SELECT
					formElementID,
					'" . (int)$currentLanguageID . "',
					formElementLabel,
					formElementDesc,
					formElementSubText,
					formElementPlaceHolder,
					formElementValue,
					formValidationMessage
				FROM
					" . DB_PREFIX . "form_element_details
				WHERE
					languageID = '" . (int)$defaultLanguageID . "' 
			)
		";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
			INSERT INTO " . DB_PREFIX . "form_options_details
				(
				formElementOptionID,
				languageID,
				optionDesc
				)
			(
				SELECT
					formElementOptionID,
					'" . (int)$currentLanguageID . "',
					optionDesc
				FROM
					" . DB_PREFIX . "form_options_details
				WHERE
					languageID = '" . (int)$defaultLanguageID . "' 
			)
		";
        $this->ObjDatabase->setQuery($sql);
    }
    /********* Synchronise Business **********/
    public function syncWidgetLanguages($defaultLanguageID, $currentLanguageID) {
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "widget_details(
				widgetID,
				widgetTitle,
				languageID,
				widgetDescription
					
			) 
            SELECT 
				widDet.widgetID,
				widDet.widgetTitle,
				'" . (int)$currentLanguageID . "' AS languageID,
				widDet.widgetDescription
				
			FROM 
				" . DB_PREFIX . "widget_details widDet
			LEFT JOIN 
				" . DB_PREFIX . "widgets wid ON widDet.widgetID=wid.widgetID 
			WHERE wid.status!='D' AND
				widDet.languageID='" . (int)$defaultLanguageID . "'";
        $this->ObjDatabase->setQuery($sql);
        $sql = "
		INSERT INTO 
			" . DB_PREFIX . "widget_tab_details(
				widgetTabID,
				languageID,
				tabTitle,
				viewMoreLabel
			)
            SELECT 
				widtabDet.widgetTabID,'" . (int)$currentLanguageID . "' AS languageID,
				widtabDet.tabTitle,
				widtabDet.viewMoreLabel
			FROM 
				" . DB_PREFIX . "widget_tab widtab
			LEFT JOIN 
				" . DB_PREFIX . "widget_tab_details widtabDet ON widtab.widgetTabID=widtabDet.widgetTabID
			WHERE 
				widtabDet.languageID='" . (int)$defaultLanguageID . "' 
				AND widtab.status<>'D'";
        $this->ObjDatabase->setQuery($sql);
    }
    
} 
