<?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: AddonModel.php, v 1.0 2013/03/16 20:52:11
//
class AddonModel extends Model {
    //Insert Settings Data
    public function insertSettings($sectionName) {
        if ($sectionName == 'affiliate') {
            $sql = "	ALTER TABLE
								" . DB_PREFIX . "settings
							 CHANGE
								 settingsValidate settingsValidate VARCHAR(500) NOT NULL";
            $this->ObjDatabase->setQuery($sql);
            echo "Unlinking Existing Affiliate Settings Details<br/><br/>";
            $this->unlinkSettings('affiliate');
            echo "Unlinked Existing Affiliate Settings Details<br/><br/>";
            $sql                 = "	SELECT 
								settingsGroupID
							FROM
								" . DB_PREFIX . "settings_group
							WHERE
								settingsGroupKey='affiliate_settings'";
            $resultSet           = $this->ObjDatabase->readValue($sql);
            $affiliateSettingsID = $resultSet['settingsGroupID'];
            if (!$affiliateSettingsID) {
                echo "Inserting Affiliate Settings Group<br/><br/>";
                //Insert Settings Group
                $sql = "	INSERT INTO
									`" . DB_PREFIX . "settings_group`
									 	(
											`settingsGroupLabel` ,
											`settingsGroupDescription` ,
											`settingsGroupKey` ,
											`settingsGroupSortOrder`
										)
								VALUES
										(
											'Affiliate Settings',
											'Control and enable affiliate commission',
											 'affiliate_settings',
											 '12'
										)";
                $this->ObjDatabase->setQuery($sql);
                $affiliateSettingsGroupID = $this->ObjDatabase->getInsertId();
                echo "Inserted Affiliate Settings Group<br/><br/>";
                echo "Inserting Affiliate Settings<br/><br/>";
                //Insert Settings
                $sql = "	INSERT INTO
									" . DB_PREFIX . "settings
										(
											`settingsGroupID`,
											`settingsLabel`,
											`settingsKey`,
											`settingsType`,
											`settingsOptions`,
											`settingsValue`,
											`settingsValidate`,
											`settingsValidateError`,
											`settingsDescription`,
											`settingsSortOrder`,
											`settingsSecure`
										)
								VALUES
										(
											'" . $affiliateSettingsGroupID . "',
											'Enable Affiliate Section',
											'affiliate_enable',
											'checkbox',
											'Yes',
											'Yes',
											'',
											'',
											'',
											1,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Affiliate Cookie Expiry Time (Hrs)',
											'affiliate_cookie_expiry_time',
											'textbox',
											'',
											'100',
											'affiliate_enable->isEqual->Yes~*required~*isWholeNumber',
											'~*Enter affiliate cookie expiry time~*Enter valid affiliate cookie expiry time',
											'',
											2,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Enable Sales Commission<span class=sub-text>Adds commission to the affiliate,
											when cookie is available</span>',
											'affiliate_enable_sales_commission',
											'checkbox',

											'Yes',
											'Yes',
											'',
											'',
											'',
											3,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'First Purchase Commission Type',
											'affiliate_first_purchase_commission_type',
											'select',
											'Percentage~*Value',
											'Value',
											'affiliate_enable_sales_commission->isEqual->Yes~*affiliate_first_purchase_commission_type->required',
											 'Please select Commission Value Type',
											 '',
											 4,
											 'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'First Purchase Commission Value',
											'affiliate_first_purchase_commission_value',
											'textbox',
											'',
											'10',
											'affiliate_enable_sales_commission->isEqual->Yes~*required~*isPrice~*affiliate_first_purchase_commission_type->isEqual->Percentage~*isPercentage',
											'~*Please Enter Commission~*Please Enter a valid Commission ~*~*Please Enter a valid Commission',
											'',
											5,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Additional Referral Purchase Commission Type',
											'affiliate_recurring_purchase_commission_type',
											'select',
											'Percentage~*Value',
											'Percentage',
											'affiliate_enable_sales_commission->isEqual->Yes~*affiliate_recurring_purchase_commission_type->required',
											'Please select Commission Value Type',
											'',
											6,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Additional Referral Purchase Commission Value',
											'affiliate_recurring_purchase_commission_value',
											'textbox',
											'',
											'5',
											'affiliate_enable_sales_commission->isEqual->Yes~*required~*isPrice~*affiliate_recurring_purchase_commission_type->isEqual->Percentage~*isPercentage',
											'~*Please Enter Commission~*Please Enter Valid Commission~*~*Please Enter Valid Commission',
											 '',
											 7,
											 'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Enable Tier Commission<span class=sub-text>Adds affiliate commission for later purchases made by its referral, when cookie is unavailable</span>',
											'affiliate_enable_tier_commission',
											'checkbox',
											'Yes',
											'Yes',
											'',
											'',
											'',
											8,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Tier Commission Level',
											'affiliate_tier_commission_level',
											'textbox',
											'',
											'5',
											'affiliate_enable_tier_commission->isEqual->Yes~*required~*affiliate_tier_commission_level->isWholeNumber',
											'Please Enter Tier Commission Level ~*Please Enter a Valid Tier Commission Level~*Please Enter a Valid Tier Commission Level',
											'',
											9,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Tier Commission Type',
											'affiliate_tier_commission_type',
											'select',\
											'Percentage~*Value',
											'Percentage',
											'affiliate_enable_tier_commission->isEqual->Yes~*affiliate_tier_commission_type->required',
											'Please select Commission Value Type',
											'',
											10,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Tier Commission Value',
											'affiliate_tier_commission_value',
											'textbox',
											'',
											'3',
											'affiliate_enable_tier_commission->isEqual->Yes~*required~*isPrice~*affiliate_tier_commission_type->isEqual->Percentage~*isPercentage',
											'~*Please Enter Commission~*Please Enter Valid Commission~*~*Please Enter Valid Commission',
											'',
											11,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Subscription Commission<span class=sub-text>Adds commission to affiliate for subscription through affiliate referrals</span>',
											 'affiliate_subscription_commission',
											 'checkbox',
											 'Yes',
											 'Yes',
											 '',
											 '',
											 '',
											 12,
											 'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Subscription Commission Amount',
											'affiliate_subscription_commission_amount',
											'textbox',
											'',
											'4',
											'affiliate_subscription_commission->isEqual->Yes~*required~*affiliate_subscription_commission_amount->isPrice',
											'~*Please Enter Subsciption Commission~*Please Enter Valid Subscription Commission',
											'',
											13,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Registration Commission<span class=sub-text>Adds commission to affiliate for user registration through affiliate referrals</span>',
											'affiliate_registeration_commission',
											'checkbox',
											'Yes',
											'Yes',
											'',
											'',
											'',
											14,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Registration Commission Amount',
											'affiliate_registeration_commission_amount',
											'textbox',
											'',
											'6',
											'affiliate_registeration_commission->isEqual->Yes~*required~*affiliate_registeration_commission_amount->isPrice',
											'~*Please Enter Registration Commission Amount~*Please Enter Valid Commission~*Please Enter Valid Commission',
											'',
											15,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Bulk Subscriber Import<span class=sub-text>Provision to import bulk subscriber data and receive commission for each Subscriber confirmation</span>',
											'affiliate_bulk_subscriber_import',
											'checkbox',
											'Yes',
											'Yes',
											'',
											'',
											'',
											16,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Bulk Subscriber Import Commission',
											'affiliate_bulk_subsc_import_commission',
											'textbox',
											'',
											'1',
											'affiliate_bulk_subscriber_import->isEqual->Yes~*required~*affiliate_bulk_subsc_import_commission->isPrice',
											'~*Please Enter Commission~*Please Enter Valid Commission',
											'',
											17,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Bulk User Import<span class=sub-text>Provision to import bulk user data and receive commission for each User confirmation</span>',
											 'affiliate_bulk_user_import',
											 'checkbox',
											 'Yes',
											 'Yes',
											 '',
											 '',
											 '',
											 18,
											 'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Bulk User Import Commission',
											'affiliate_bulk_user_import_commission',
											'textbox',
											'',
											'2',
											'affiliate_bulk_user_import->isEqual->Yes~*required~*affiliate_bulk_user_import_commission->isPrice',
											'~*Please Enter Commission~*Please Enter Valid Commission',
											'',
											19,
											'Yes'
										),
										(
											'" . $affiliateSettingsGroupID . "',
											'Enable Email Verifier',
											'email_verifier_enable',
											'checkbox',
											'Yes',
											'Yes',
											'',
											'',
											'',
											20,
											''
										)";
                $this->ObjDatabase->setQuery($sql);
                echo "Inserted Affiliate Settings<br/><br/>";
                //Set dependancy @ Array Contents -> Index : Parent , Values : Dependancy
                $parentChildDependancy['affiliate_enable']                   = "'affiliate_cookie_expiry_time'";
                $parentChildDependancy['affiliate_enable_sales_commission']  = "'affiliate_first_purchase_commission_type','affiliate_first_purchase_commission_value','affiliate_recurring_purchase_commission_type','affiliate_recurring_purchase_commission_value'";
                $parentChildDependancy['affiliate_enable_tier_commission']   = "'affiliate_tier_commission_level','affiliate_tier_commission_type','affiliate_tier_commission_value'";
                $parentChildDependancy['affiliate_subscription_commission']  = "'affiliate_subscription_commission_amount'";
                $parentChildDependancy['affiliate_registeration_commission'] = "'affiliate_registeration_commission_amount'";
                $parentChildDependancy['affiliate_bulk_subscriber_import']   = "'affiliate_bulk_subsc_import_commission'";
                $parentChildDependancy['affiliate_bulk_user_import']         = "'affiliate_bulk_user_import_commission'";
                foreach ($parentChildDependancy as $parent => $child) {
                    $sql                   = "	SELECT
										CAST
											(
												GROUP_CONCAT(`settingsID`) AS CHAR
											)
										AS
											settingsIDs
									FROM
										" . DB_PREFIX . "settings
									WHERE 
										settingsKey IN (" . $child . ")";
                    $resultSettingsGroupID = $this->ObjDatabase->readValue($sql);
                    $dependantSettingsIDs  = $resultSettingsGroupID['settingsIDs'];
                    $sql                   = "	UPDATE
										" . DB_PREFIX . "settings 
									SET
										settingsFieldType= 'parent',
										settingsDependants='" . $dependantSettingsIDs . "'
									WHERE
										settingsKey = '" . $parent . "'";
                    $resUpdateAffSettings  = $this->ObjDatabase->setQuery($sql);
                    $sql                   = "	UPDATE
										" . DB_PREFIX . "settings
									SET
										 settingsFieldType= 'child'
									WHERE
										settingsKey IN (" . $child . ")";
                    $resUpdateAffSettings1 = $this->ObjDatabase->setQuery($sql);
                }
                echo "Updated Dependency in Affiliate Settings<br/><br/>";
                //Affiliate Related Referral Settings
                echo "Deleting Existing Affiliate Referral Settings<br/><br/>";
                $referralSettingsGroupID = $this->getSettingsGroupID('referral_settings');
                $affReferralSettings     = "'aff_referral_enable','aff_facebook_referral_enable','aff_twitter_referral_enable','aff_googleplus_referral_enable','aff_pinterest_referral_enable'";
                $sql                     = "	DELETE
								FROM
									" . DB_PREFIX . "settings
								WHERE
									settingsKey IN (" . $affReferralSettings . ")";
                $this->ObjDatabase->setQuery($sql);
                echo "Inserting Affiliate related Referral Settings<br/><br/>";
                $sql = "	INSERT INTO
									" . DB_PREFIX . "settings
										(
											`settingsGroupID`,
											`settingsLabel`,
											`settingsKey`,
											`settingsType`,
											`settingsFieldType`,
											`settingsDependants`,
											`settingsOptions`,
											`settingsValue`,
											`settingsValidate`,
											`settingsValidateError`,
											`settingsDescription`,
											`settingsSortOrder`,
											`settingsSecure`
										)
								VALUES
										(
											'" . $referralSettingsGroupID . "',
											'Enable Affiliate Referral System',
											'aff_referral_enable',
											'checkbox',
											'parent',
											'',
											'Yes',
											'Yes',
											'',
											'',
											'',
											8,
											'Yes'
										),
										(
											'" . $referralSettingsGroupID . "',
											'Enable Affiliate Facebook Referral',
											'aff_facebook_referral_enable',
											'checkbox',
											'child',
											'',
											'Yes',
											'Yes',
											'',
											'',
											'',
											9,
											'Yes'
										),
										(
											'" . $referralSettingsGroupID . "',
											'Enable Affiliate Twitter Referral',
											'aff_twitter_referral_enable',
											'checkbox',
											'child',
											'',
											'Yes',
											'Yes',
											'',
											'',
											'',
											10,
											'Yes'
										),
										(
											'" . $referralSettingsGroupID . "',
											'Enable Affiliate Google+ Referral',
											'aff_googleplus_referral_enable',
											'checkbox',
											'child',
											'',
											'Yes',
											'Yes',
											'',
											'',
											'',
											11,
											'Yes'
										),
										(
											'" . $referralSettingsGroupID . "',
											'Enable Affiliate Pinterest Referral',
											'aff_pinterest_referral_enable',
											'checkbox',
											'child',
											'',
											'Yes',
											'Yes',
											'',
											'',
											'',
											12,
											'Yes'
										)";
                $this->ObjDatabase->setQuery($sql);
                $sql                          = "	SELECT
									CAST
										(
											GROUP_CONCAT(`settingsID`) AS CHAR
										)
									AS settingsIDs
								FROM
									" . DB_PREFIX . "settings
								WHERE
									settingsKey IN (" . $affReferralSettings . ")";
                $resultAffReferralSettingsIds = $this->ObjDatabase->readValue($sql);
                $dependantRefSettingsIDs      = $resultAffReferralSettingsIds['settingsIDs'];
                $sql                          = "	UPDATE
									" . DB_PREFIX . "settings
								SET
									settingsDependants='" . $dependantRefSettingsIDs . "'
								WHERE
									settingsKey='aff_referral_enable'";
                $resUpdateAffRefSettings      = $this->ObjDatabase->setQuery($sql);
                echo "Inserted Affiliate related Referral Settings<br/><br/>";
            }
        }
    }
    //Insert Menu
    public function insertMenu($sectionName) {
        if ($sectionName == 'analytics') {
            $sql           = "	SELECT
								adminModuleID
							FROM
								 " . DB_PREFIX . "admin_modules
							WHERE
								adminSectionKey='analytics_index'";
            $resultSet     = $this->ObjDatabase->readValue($sql);
            $adminModuleID = $resultSet['adminModuleID'];
            if (!$adminModuleID) {
                $sql = "	INSERT INTO
									`" . DB_PREFIX . "admin_modules` 
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											0,
											'analytics/',
											NULL,
											'nav07 strict_fixing_right',
											NULL,
											6,
											'All',
											'Active',
											'analytics_index'
										)";
                $this->ObjDatabase->setQuery($sql);
                $lastInsertProductID = $this->ObjDatabase->getInsertId();
                $sql                 = "	INSERT INTO
									`dp_admin_modules`
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/location/',
											NULL,
											NULL,
											NULL,
											999,
											'All',
											'Active',
											'analytics_location'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/browser/',
											NULL,
											NULL,
											NULL,
											999,
											'All',
											'Active',
											analytics_browser'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/agegender/',
											NULL,
											NULL,
											NULL,
											999,
											'All',
											'Active',
											analytics_agegender'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/hourly/',
											NULL,
											NULL,
											NULL,
											999,
											'All',
											'Active',
											'analytics_hourly'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/',
											NULL,
											NULL,
											NULL,
											1,
											'All',
											'Active',
											'analytics_dashboard'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/bounce/',
											NULL,
											NULL,
											NULL,
											999,
											'All',
											'Active',
											'analytics_bounce'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/traffic/',
											NULL,
											NULL,
											NULL,
											999,
											'All',
											'Active',
											'analytics_traffic'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/crawlers/ ',
											NULL,
											NULL,
											NULL,
											999,
											'All',
											'Active',
											'analytics_crawlers'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/browseros/',
											NULL,
											NULL,
											NULL,
											'999',
											'All',
											'Active',
											'analytics_browseros'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/iptrack/',
											NULL,
											NULL,
											NULL,
											'999',
											'All',
											'Active',
											'analytics_iptrack'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/topproduct/',
											NULL,
											NULL,
											NULL,
											'999',
											'All',
											'Active',
											'analytics_topproduct'
										),
										(
											NULL,
											'" . $lastInsertProductID . "',
											'analytics/topengaged/',
											NULL,
											NULL,
											NULL,
											'999',
											'All',
											'Active',
											'analytics_topengaged'
										);";
                $this->ObjDatabase->setQuery($sql);
            }
            if ($lastInsertProductID) {
                $sql = "	INSERT INTO 
									`" . DB_PREFIX . "admin_module_details`
									 	(
											`adminModuleDetailsID`,
											`adminModuleID`,
											`languageID`,
											`adminModuleCaption`,
											`adminModuleBreadcrumbCaption`
										)
								VALUES
										(
											NULL,
											'" . $this->getCorrespondingID('analytics_index') . "',
											1,
											'Analytics',
											'Analytics'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_location') . ",
											1,
											'Location Report',
											'Location Report'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_browser') . ",
											1,
											'Browser Report',
											'Browser Report'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_agegender') . ",
											1,
											'Age Gender Report',
											'Age Gender Report'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_hourly') . ",
											1,
											'Hourly Report',
											'Hourly Report'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_dashboard') . ",
											1,
											'DashBoard',
											'DashBoard'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_bounce') . ",
											1,
											'Bounce Rate',
											'Bounce Rate Report'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_traffic') . ",
											1,
											'Traffic Report',
											'Traffic Report'
										),
										(
											NULL,
											" . $this->getCorrespondingID('analytics_crawlers') . ",
											1,
											'Crawler Management',
											'Crawler Management'
										),
										(
											NULL,
											'" . $this->getCorrespondingID('analytics_browseros') . "',
											'1',
											'Browser Os Detection',
											'Browser Os Detection'
										),
										(
											NULL,
											'" . $this->getCorrespondingID('analytics_iptrack') . "',
											'1',
											'Untracked IP''s',
											'Untracked IP''s'
										),
										(
											NULL,
											'" . $this->getCorrespondingID('analytics_topproduct') . "',
											'1',
											'Top Product List',
											'Top Product List'
										),
										(
											NULL,
											'" . $this->getCorrespondingID('analytics_topengaged') . "',
											'1',
											'Top Engaged Users',
											'Top Engaged Users'
										);";
                $this->ObjDatabase->setQuery($sql);
            }
        } elseif ($sectionName == 'affiliate') {
            echo "Checking Admin Section Key<br/><br/>";
            $this->setAdminSectionKey();
            echo "Unlinking Existing Affiliate Admin Module Details<br/><br/>";
            //Unlink Existing Affiliate Menu
            $this->unlinkAdminModuleDetails($sectionName);
            echo "Unlinked Existing Affiliate Admin Module Details<br/><br/>";
            $sql           = "	SELECT
								adminModuleID
							FROM 
								" . DB_PREFIX . "admin_modules
							WHERE adminSectionKey='affiliate'";
            $resultSet     = $this->ObjDatabase->readValue($sql);
            $adminModuleID = $resultSet['adminModuleID'];
            if (!$adminModuleID) {
                echo "Inserting Affiliate Main Menu<br/><br/>";
                //Insert Main Menu
                $sql = "	INSERT INTO 
									`" . DB_PREFIX . "admin_modules`
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											3,
											'affiliate/',
											NULL,
											NULL,
											'',
											2,
											'All',
											'Active',
											'affiliate'
										)";
                $this->ObjDatabase->setQuery($sql);
                $lastInsertID = $this->ObjDatabase->getInsertId();
                echo "Inserted Main Affiliate Menu<br/><br/>";
                echo "Inserting Affiliate Import Menu<br/><br/>";
                //Insert Import Menu Section in the 1st Level
                $sql = "	INSERT INTO
									`" . DB_PREFIX . "admin_modules`
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											'" . $lastInsertID . "',
											'affiliate/import/',
											NULL,
											NULL,
											NULL,
											5 ,
											'All',
											'Active',
											'affiliate_import'
										)";
                $this->ObjDatabase->setQuery($sql);
                $lastInsertIDForImport = $this->ObjDatabase->getInsertId();
                echo "Inserted Affiliate Import Menu<br/><br/>";
                echo "Inserting Affiliate Report Menu<br/><br/>";
                //Insert Affiliate Menu in Report Section
                $sql = "	INSERT INTO
									`" . DB_PREFIX . "admin_modules`
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											7,
											'report/affiliate/',
											NULL,
											NULL,
											NULL,
											1 ,
											'All',
											'Active',
											'affiliate_reports'
										)";
                $this->ObjDatabase->setQuery($sql);
                echo "Inserted Affiliate Report Menu<br/><br/>";
                echo "Inserting Affiliate Settings Menu<br/><br/>";
                $sql                     = "	SELECT 
									adminModuleID
								FROM 
									" . DB_PREFIX . "admin_modules
								WHERE
									adminModuleURLKey = 'settings/index/'";
                $resultSettingsIndex     = $this->ObjDatabase->readValue($sql);
                $sql                     = "	SELECT
									settingsGroupID
								FROM
									" . DB_PREFIX . "settings_group
								WHERE
									settingsGroupKey = 'affiliate_settings'";
                $resultAffGroupID        = $this->ObjDatabase->readValue($sql);
                $settingsModuleURLString = 'settings/index/id/' . $resultAffGroupID['settingsGroupID'] . '/';
                //Insert Affiliate Menu in Settings Section
                $sql                     = "	INSERT INTO 
									`" . DB_PREFIX . "admin_modules`
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											'" . $resultSettingsIndex['adminModuleID'] . "',
											'" . $settingsModuleURLString . "',
											NULL,
											NULL,
											NULL,
											999 ,
											'All',
											'Active',
											'affiliate_settings'
										)";
                $this->ObjDatabase->setQuery($sql);
                echo "Inserted Affiliate Settings Menu<br/><br/>";
                echo "Inserting Affiliate Main Menu Details<br/><br/>";
                //Insert 1st level Muenu
                $sql = "	INSERT INTO
									`" . DB_PREFIX . "admin_modules`
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											'" . $lastInsertID . "',
											'affiliate/index/',
											NULL,
											NULL,
											NULL,
											1,
											'All',
											'Active',
											'affiliate_index'
										),
										(
											NULL,
											'" . $lastInsertID . "',
											'affiliate/new/',
											NULL,
											NULL,
											NULL,
											2,
											'All',
											'Active',
											'affiliate_new'
										),
										(
											NULL,
											'" . $lastInsertID . "',
											'affiliaterequest/',
											NULL,
											NULL,
											NULL,
											3,
											'All',
											'Active',
											affiliaterequest_index'
										),
										(
											NULL,
										 	'" . $lastInsertID . "',
											'affiliate/paymentnotpaid/',
											NULL,
											NULL,
											NULL,
											4,
											'All',
											'Active',
											'affiliate_paymentnotpaid'
										)";
                $this->ObjDatabase->setQuery($sql);
                echo "Inserted Affiliate Main Menu Details<br/><br/>";
                echo "Inserting Affiliate Import Sub level Menu <br/><br/>";
                //Insert 2nd level Muenu
                $sql = "	INSERT INTO 
									`" . DB_PREFIX . "admin_modules`
										(
											`adminModuleID`,
											`adminModuleParentID`,
											`adminModuleURLKey`,
											`adminModuleURLString`,
											`adminModuleStyleClass`,
											`adminModuleStyleIcon`,
											`adminModuleOrder`,
											`adminModuleType`,
											`adminModuleStatus`,
											`adminSectionKey`
										)
								VALUES
										(
											NULL,
											'" . $lastInsertIDForImport . "',
											'affiliate/importSubscriber/',
											NULL,
											NULL,
											NULL,
											1,
											'All',
											'Active',
											'affiliate_importsubscriber'
										),
										(
											NULL,
											'" . $lastInsertIDForImport . "',
											'affiliate/importuser/',
											NULL,
											NULL,
											NULL,
											2,
											'All',
											'Active',
											'affiliate_importuser'
										),
										(
											NULL,
											'" . $lastInsertIDForImport . "',
											'affiliate/importsubscriberslist/',
											NULL,
											NULL,
											NULL,
											3,
											'All',
											'Active',
											'affiliate_importsubscriberslist'
										),
										(
											NULL,
											'" . $lastInsertIDForImport . "',
											'affiliate/importuserlist/',
											NULL,
											NULL,
											NULL,
											4,
											'All',
											'Active',
											'affiliate_importuserlist'
										)";
                $this->ObjDatabase->setQuery($sql);
                echo "Inserted Affiliate Import Sub level Menu <br/><br/>";
                echo "Inserting Affiliate Menu Details <br/><br/>";
                //Admin Module Details Insertion 
                $sql = "	INSERT INTO 
									`" . DB_PREFIX . "admin_module_details`
										(
											`adminModuleDetailsID`,
											`adminModuleID`,
											`languageID`,
											`adminModuleCaption`,
											`adminModuleBreadcrumbCaption`,
											`adminModuleLabel`
										)
								VALUES
										(
											NULL,
											" . $this->getCorrespondingID('affiliate') . ",
											1,
											'Affiliates',
											'Affiliates',
											'lblAffiliates'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_index') . ",
											1,
											'Affiliates',
											'Affiliates',
											'lblManageAffiliates'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_new') . ",
											1,
											'Add New Affiliate',
											'Add New Affiliate',
											'lblAddNewAffiliate'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliaterequest_index') . ",
											1,
											'Affiliate Request',
											'Affiliate Request',
											'lblManageAffiliateRequest'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_paymentnotpaid') . ",
											1,
											'Affiliate Payments',
											'Affiliate Payments',
											'lblManageAffiliatePayments'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_import') . ",
											1,
											'Import',
											'Import',
											'lblImport'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_importsubscriber') . ",
											1,
											'Import Subscribers',
											'Import Subscribers',
											'lblImportSubscribers'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_importuser') . ",
											1,
											'Import Users',
											'Import Users',
											'lblImportUsers'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_importsubscriberslist') . ",
											1,
											'Imported Subscribers',
											'Imported Subscribers',
											'lblImportedSubscribers'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_importuserlist') . ",
											1,
											'Imported Users',
											'Imported Users',
											'lblImportedUsers'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_reports') . ",
											1,
											'Affiliates',
											'Affiliates',
											'lblAffiliates'
										),
										(
											NULL,
											" . $this->getCorrespondingID('affiliate_settings') . ",
											1,
											'Affiliate Settings',
											'Affiliate Settings',
											'lblAffiliatesSettings'
										)";
                $this->ObjDatabase->setQuery($sql);
                echo "Inserted Affiliate Menu Details <br/><br/>";
            }
        }
    }
    //Insert Email Templates
    public function insertEmailTemplates($sectionName) {
        if ($sectionName == 'affiliate') {
            echo "Unlinking Existing Affiliate Email Templates<br/><br/>";
            $this->unlinkEmailTemplates('affiliate');
            echo "Unlinked Existing Affiliate Email Templates<br/><br/>";
            //Insert Email Template
            echo "Inserting Affiliate Email Template<br/><br/>";
            $sql = "	INSERT INTO
								" . DB_PREFIX . "email_template
									(
										`emailFromName`,
										`emailFromEmail`,
										`emailTemplateName`,
										`emailSendToKey`,
										`emailKey`,
										`editable`
									) 
							VALUES
									(
										'Admin',
										'admin@products.com',
										'New Affiliate Request Received',
										'CONTACT_ADMIN',
										'affiliate-request-received',
										'Yes'
									),
									(
										'Admin',
										'admin@products.com',
										'Affiliate Request Approved',
										'CONTACT_ADMIN',
										'affiliate-request-approved',
										'Yes'
									),
									(
										'Admin',
										'admin@products.com',
										'Thank You For Affiliate Request',
										'CONTACT_ADMIN',
										'affiliate-request-thank',
										'Yes'
									),
									(
										'Admin',
										'admin@products.com',
										'Affiliate Request Declined',
										'CONTACT_ADMIN',
										'affiliate-request-declined',
										'Yes'
									),
									(
										'Admin',
										'admin@products.com',
										'Refer a Friend',
										'GUEST_USER',
										'affiliate-refer-friend',
										'Yes'
									),
									(
										'Admin',
										'admin@products.com',
										'Invitation',
										'INVITE_ADMIN_AFF',
										'affiliate-invite',
										'Yes'
									)";
            $this->ObjDatabase->setQuery($sql);
            echo "Inserted Email Template<br/><br/>";
            //Insert Email Template Details
            echo "Inserting Affiliate Email Template Details<br/><br/>";
            $sql = "	INSERT INTO
								" . DB_PREFIX . "email_template_details
									(
										`emailTempID`,
										`languageID`,
										`emailSubject`,
										`emailHtml`,
										`emailText`
									)
							VALUES
									(
										" . $this->getEmailTemplateID('affiliate-request-received') . ",
										1,
										'New Affiliate Request Received',
										'<h2 style=\"color: #545454; font-family: Helvetica,Arial,sans-serif; font-size: 18px;\">Hi Admin,</h2>
			<p>A new affiliate request has just received. The details of the affiliate are given below:</p>
			<p>Name of the Affiliate : " . '{$affiliateReqName}' . "</p>
			<p>Email id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: " . '{$emailID}' . "</p>
			<p>Phone Number&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: " . '{$PhoneNumber}' . "</p>
			<p>Contact Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: " . '{$name}' . "</p>
			<p>Contact Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: " . '{$address}' . "," . '{$city}' . ", " . '{$ProvinceState}' . ", " . '{$Country}' . ", " . '{$PostalCodeZip}' . "</p>',
										'Hi Admin,

			A new affiliate request has just received. The details of the affiliate are given below:
			
			Name of the Affiliate : " . '{$affiliateReqName}' . "
			
			Email id			  : " . '{$emailID}' . "
			
			Phone Number		  : " . '{$PhoneNumber}' . "
			
			Contact Name		  : " . '{$name}' . "
			
			Contact Address	   : " . '{$address}' . "," . '{$city}' . ", " . '{$ProvinceState}' . ", " . '{$Country}' . ", " . '{$PostalCodeZip}' . "
			
			Thanks,
			" . '{$siteName}' . "'),
			(" . $this->getEmailTemplateID('affiliate-request-approved') . ", 1, 'Affiliate Request Approved', 
			'<h2 style=\"color: #545454; margin: 0px font-family; font-size: 18px;\">Hi " . '{$userName}' . ",</h2>
			<p>{$siteName} team has been added/Updated you as an Affiliate in " . '{$siteName}' . "</p>
			<p>Login details given below:</p>
			<p>UserName : " . '{$affiliateLogin}' . "</p>
			<p>Password : " . '{$affiliatePassword}' . "</p>
			<p style=\"font-family: Helvetica,Arial,sans-serif; color: #545454; margin: 0pt 20px; padding: 15px 0px;\">Access your affiliate area through this <a href=\"{url}\">{url}</a></p>',
			'Hi {$userName},

			{$siteName} team has been added/Updated you as an Affiliate in {$siteName}
			
			Login details given below:
			Access your affiliate area through this {url}
			
			UserName : " . '{$affiliateLogin}' . "
			
			Password : " . '{$affiliatePassword}' . "'),
			(" . $this->getEmailTemplateID('affiliate-request-thank') . ", 1, 'Thank You For Affiliate Request', 
			'<h2 style=\"color: #545454; margin: 0px font-family; font-size: 18px;\">Hi " . '{$userName}' . ",</h2>
			<div id=\"imsgid1\">Thank you for your interest in Daily Product System. Your affiliate details have been submitted successfully. We will get in touch with you  soon.</div>
			<p>&nbsp;</p>
			<p>&nbsp;</p>
			<p style=\"font-family: Helvetica,Arial,sans-serif; color: #545454; margin: 0pt 20px; font-size: 16px; text-align: center; padding: 15px 0px;\">&nbsp;</p>',
			'Thank you for your interest in Daily Product System. Your affiliate details have been submitted successfully. We will get in touch with you soon.'),
			(" . $this->getEmailTemplateID('affiliate-request-declined') . ", 1, 'Affiliate Request Declined', 
			'<h2 style=\"color: #545454; margin: 0px font-family; font-size: 18px;\">Hi " . '{$userName}' . ",</h2>
<p>" . '{$siteName}' . " team has been declined your Affiliate Request due to " . '{$affiliateDeclineReason}' . "</p>',
			'Hi " . '{$userName}' . ",

			" . '{$siteName}' . " team has been declined your Affiliate Request due to " . '{$affiliateDeclineReason}' . "'),
			(" . $this->getEmailTemplateID('affiliate-refer-friend') . ", 1, 'Refer a Friend', 
			'<p><strong>" . '{$referredBy}' . "</strong> invite you to join the daily product system through the referral link</p>
			 <p><a href=\"" . '{$referralLink}' . "\" style=\"color:blue;\">" . '{$referralLink}' . "</a></p>',
			'{$referredBy} invite you to join the daily product system through the referral link

			 " . '{$referralLink}' . "'),
			(" . $this->getEmailTemplateID('affiliate-invite') . ", 1, 'Invitation from daily product', 
			'<h2><span>Hi,</span></h2>
			<p>Oorjit.com invites you to its daily product program,We recieved your reference through Affiliate. Please <a href=" . '{$siteUrl}' . ">Click here to confirm.</a></p>
			<a>
			<p>&nbsp;</p>
			</a>',
			'Hi,

			Oorjit.com invites you to its daily product program,We recieved your reference through Affiliate. " . '{$siteUrl}' . "')";
            $this->ObjDatabase->setQuery($sql);
            echo "Inserted Affiliate Email Template Details<br/><br/>";
        } else if ($sectionName == 'analytics') {
            $sql = "	INSERT INTO
								`" . DB_PREFIX . "email_template`
									(
										`emailFromName`,
										`emailFromEmail`,
										`emailTemplateName`,
										`emailSendToKey`,
										`emailKey`,
										`editable`
									)
							VALUES
									(
										'Admin- Multi Lingual',
										'qamail101@ispg.co',
										'Clean Table Notification',
										'NOTIFICATION_ADMIN',
										'analytics-clean-url-table',
										'Yes'
									),
									(
										'Admin',
										'qamail101@ispg.co',
										'Analytics Cron Notification',
										'NOTIFICATION_ADMIN',
										'analytics-cron-notification',
										'Yes'
									);";
            $this->ObjDatabase->setQuery($sql);
            $sql = "	INSERT INTO 
								`" . DB_PREFIX . "email_template_details` 
									(
										`emailTempID`,
										`languageID`,
										`emailSubject`,
										`emailHtml`,
										`emailText`
									)
							VALUES
									(
										" . $this->getEmailTemplateID('analytics-clean-url-table') . ",
										1,
										'Clean URL Table',
										'<h2 style=\"color: #545454;font-family:Helvetica,Arial,sans-serif;font-size:18px;\">Hi Admin,</h2>\r\n<p>As Our System grewing larger,we recomed you to clear the table that holds URL,for the better performance of the system.Follow the Procedures to clear the URL Table</p>\r\n<p>1)Go To The Menu Settings</p>\r\n<p>2)Reach Cache & Log Cleaning</p>\r\n<p>3)From the many option in that page click on the clear table option. This will clear the table and therby increases the performance of site</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>', 'Hi Admin,\r\nAs Our System grewing larger,we recomed You to Clear the table that holds URL,for better perfomance of the system,.Follow the Procedures to clear the URL Table\r\n1)GO To The Menu \"Settings\"\r\n2)Reach Cache & Log Cleaning\r\n3)From the many option in that page click on the clear table option. This will clear the table and therby increases the performance of site'),
										(" . $this->getEmailTemplateID('analytics-cron-notification') . ", 1, 'Analytics Cron Notification', '<h2 style=\"color: #545454; font-family: Helvetica,Arial,sans-serif; font-size: 18px;\">Hi Admin,</h2>\r\n<p>After running the analytics cron some of IP address are not tracked for the location detection or some of User Agent String not detected the browser and operating system , we recomed You to Update it. Follow the Procedures to update it</p>\r\n<p>1) Go To The Menu Analytics</p>\r\n<p>2) Reach Browser Os Detection and Untracked IP''s</p>', 'Hi Admin,\r\n\r\nAfter running the analytics cron some of IP address are not tracked for the location detection or some of User Agent String not detected the browser and operating system , we recomed You to Update it. Follow the Procedures to update it\r\n\r\n1)Go To The Menu &quot;Analytics&quot;\r\n\r\n2)Reach Browser Os Detection and Untracked IP''s');";
            $this->ObjDatabase->setQuery($sql);
            echo "<br>" . "Fields For Email Templates inserted Sucessfully";
        }
    }
    //Insert Content Pages
    public function insertContentpages($sectionName) {
        if ($sectionName == 'affiliate') {
            echo "Unlinking Existing Content Pages<br/><br/>";
            $this->unlinkContentPages('affiliate');
            echo "Unlinked Existing Content Pages<br/><br/>";
            //Insert Content Pages
            echo "Inserting Affiliate Content Pages<br/><br/>";
            $sql = "	INSERT INTO
								" . DB_PREFIX . "content_pages
									(
										`contentStatus`,
										`contentCreatedDate`,
										`contentIsBasic`,
										`contentIsForSubPages`,
										`contentUrlKey`,
										`contentKey`,
										`sectionID`,
										`sortOrder`
									) 
							VALUES
									(
										'Active',
										 NOW(),
										'Yes',
										'No',
										'Affiliates.html',
										'affiliates',
										1,
										999
									),
									(
										'Active',
										 NOW(),
										'Yes',
										'No',
										'Thank-you-for-your-affiliate-request.html',
										'thank-you-for-your-affiliate-request',
										999,
										999
									),
									(
										'Active',
										 NOW(),
										 'No',
										 'No',
										 'Affiliate-Terms-and-Conditions.html',
										 'affiliate-terms-and-conditions',
										 999,
										 999
									),
									(
										'Active',
										 NOW(),
										 'No',
										 'No',
										 'Affiliate-FAQs.html',
										 'affiliate-faqs',
										 999,
										 999
									)";
            $this->ObjDatabase->setQuery($sql);
            echo "Inserted Affiliate Content Pages<br/><br/>";
            //Insert Content Page Details
            echo "Inserting Affiliate Content Page Details<br/><br/>";
            $sql = "	INSERT INTO
								" . DB_PREFIX . "content_pages_details
									(
										`contentID`,
										`languageID`,
										`contentTitle`,
										`contentMenuName`,
										`contentDescription`,
										`contentMetaTitle`,
										`contentMetaDescription`,
										`contentMetaKeywords`
									) 
							VALUES
									(
										" . $this->getContentID('affiliates') . ",
										1,
										'Affiliates',
										'Affiliates',
										'Affiliate Description',
										'',
										'',
										''
									),
									(
										" . $this->getContentID('thank-you-for-your-affiliate-request') . ",
										1,
										'Thank you for your affiliate request',
										'Thank you for your affiliate request',
										'<p>Thank you for your interest in Affiliate Program. Your details have been submitted successfully. We will get in touch with you soon.</p>',
										'Thank you for your affiliate request',
										'Thank you for your affiliate request',
										'Thank you for your affiliate request'),
			(" . $this->getContentID('affiliate-terms-and-conditions') . ",
										1,
										'Affiliate Terms and Conditions',
										'Affiliate Terms and Conditions',
										'Affiliate Terms and Conditions',
										'Affiliate Terms and Conditions',
										'Affiliate Terms and Conditions',
										'Affiliate Terms and Conditions'),
										(" . $this->getContentID('affiliate-faqs') . ",
										1,
										'Affiliate FAQs',
										'Affiliate FAQs',
										'Affiliate FAQs',
										'',
										'',
										''
									)";
            $this->ObjDatabase->setQuery($sql);
            echo "Inserted Affiliate Content Page Details<br/><br/>";
        }
    }
    // Delete Existing Settings
    public function unlinkSettings($sectionName) {
        if ($sectionName == 'affiliate') {
            $sql      = "	SELECT
									settingsGroupID
								FROM 
									" . DB_PREFIX . "settings_group
								WHERE 
									settingsGroupKey = 'affiliate_settings'";
            $resultID = $this->ObjDatabase->readValues($sql);
            foreach ($resultID as $delteID) {
                $ID  = $delteID['settingsGroupID'];
                $sql = "	DELETE
								FROM
									" . DB_PREFIX . "settings_group
								WHERE
									settingsGroupID='" . $ID . "'";
                $this->ObjDatabase->setQuery($sql);
                $sql = "	DELETE
								FROM
									" . DB_PREFIX . "settings
								WHERE
									settingsGroupID='" . $ID . "'";
                $this->ObjDatabase->setQuery($sql);
            }
            $referralSettingsGroupID = $this->getSettingsGroupID('referral_settings');
            $affReferralSettings     = "'aff_referral_enable','aff_facebook_referral_enable','aff_twitter_referral_enable','aff_googleplus_referral_enable','aff_pinterest_referral_enable'";
            $sql                     = "	DELETE
							FROM
								" . DB_PREFIX . "settings
							WHERE
								settingsKey
								IN (" . $affReferralSettings . ")";
            $this->ObjDatabase->setQuery($sql);
            $sql = "	DELETE
							FROM
								" . DB_PREFIX . "settings
							WHERE
								settingsKey
								IN ('facebook_aff_referral_message')";
            $this->ObjDatabase->setQuery($sql);
            $sql = "	DELETE
							FROM 
								" . DB_PREFIX . "settings
							WHERE
								settingsKey
								IN ('twitter_aff_referral_message')";
            $this->ObjDatabase->setQuery($sql);
            $affGpSettings = "'googleplus_aff_referral_message','googleplus_aff_share_image'";
            $sql           = "	DELETE
							FROM
								" . DB_PREFIX . "settings
							WHERE
								settingsKey
								IN (" . $affGpSettings . ")";
            $this->ObjDatabase->setQuery($sql);
            $affPinitSettings = "'pinterest_aff_referral_message','pinterest_aff_share_image'";
            $sql              = "	DELETE
							FROM
								" . DB_PREFIX . "settings
							WHERE
								settingsKey
								IN (" . $affPinitSettings . ")";
            $this->ObjDatabase->setQuery($sql);
        }
        return true;
    }
    // Delete Existing Admin Modules
    public function unlinkAdminModuleDetails($sectionName) {
        if ($sectionName != '') {
            $sql      = "	SELECT
									adminModuleID
								FROM
									" . DB_PREFIX . "admin_modules
								WHERE
									adminSectionKey
									LIKE '" . $sectionName . "%'";
            $resultID = $this->ObjDatabase->readValues($sql);
            foreach ($resultID as $delteID) {
                $ID  = $delteID['adminModuleID'];
                $sql = "	DELETE
								FROM
									" . DB_PREFIX . "admin_modules
								WHERE
									 adminModuleID='" . $ID . "'";
                $this->ObjDatabase->setQuery($sql);
                $sql = "	DELETE
								FROM
								" . DB_PREFIX . "admin_module_details
								WHERE
									adminModuleID='" . $ID . "'";
                $this->ObjDatabase->setQuery($sql);
            }
        }
        return true;
    }
    // Delete Existing Email Templates
    public function unlinkEmailTemplates($sectionName) {
        $sql      = "	SELECT
								emailTempID
							FROM
								" . DB_PREFIX . "email_template
							WHERE 
								emailKey LIKE '" . $sectionName . "%'";
        $resultID = $this->ObjDatabase->readValues($sql);
        foreach ($resultID as $delteID) {
            $ID  = $delteID['emailTempID'];
            $sql = "	DELETE
							FROM
								" . DB_PREFIX . "email_template
							WHERE 
								emailTempID='" . $ID . "'";
            $this->ObjDatabase->setQuery($sql);
            $sql = "	DELETE
							FROM 
								" . DB_PREFIX . "email_template_details
							WHERE
								emailTempID='" . $ID . "'";
            $this->ObjDatabase->setQuery($sql);
        }
        return true;
    }
    // Delete Existing Content Pages
    public function unlinkContentPages($sectionName) {
        if ($sectionName == 'affiliate') {
            $affBasicPages = "'affiliates','thank-you-for-your-affiliate-request','affiliate-terms-and-conditions','affiliate-faqs'";
            $sql           = "	SELECT
										contentID
									FROM
										" . DB_PREFIX . "content_pages
									WHERE
										contentKey 
										IN (" . $affBasicPages . ")";
            $resultID      = $this->ObjDatabase->readValues($sql);
            foreach ($resultID as $delteID) {
                $ID  = $delteID['contentID'];
                $sql = "	DELETE
									FROM 
										" . DB_PREFIX . "content_pages
									WHERE 
										contentID='" . $ID . "'";
                $this->ObjDatabase->setQuery($sql);
                $sql = "	DELETE 
									FROM 
										" . DB_PREFIX . "content_pages_details
									WHERE contentID='" . $ID . "'";
                $this->ObjDatabase->setQuery($sql);
            }
        }
        return true;
    }
    //Get Corresponding adminModuleID From admin_modules
    public function getCorrespondingID($sectionName) {
        $sql             = "	SELECT
											adminModuleID
										FROM 
											" . DB_PREFIX . "admin_modules
										WHERE
											adminSectionKey='" . $sectionName . "'";
        $resultSet       = $this->ObjDatabase->readValue($sql);
        $correspondingID = $resultSet['adminModuleID'];
        return $correspondingID;
    }
    //Get getEmailTemplateID From email_template
    public function getEmailTemplateID($emailKey) {
        $sql             = "	SELECT
											emailTempID
										FROM
											" . DB_PREFIX . "email_template
										WHERE 
											emailKey = '" . $emailKey . "'";
        $resultSet       = $this->ObjDatabase->readValue($sql);
        $correspondingID = $resultSet['emailTempID'];
        return $correspondingID;
    }
    //Get contentID From content_pages
    public function getContentID($contentKey) {
        $sql             = "	SELECT
											contentID
										FROM
											" . DB_PREFIX . "content_pages
										WHERE
											contentKey = '" . $contentKey . "'";
        $resultSet       = $this->ObjDatabase->readValue($sql);
        $correspondingID = $resultSet['contentID'];
        return $correspondingID;
    }
    //Get Settings groupID
    public function getSettingsGroupID($settingsKey) {
        $sql             = "	SELECT
											settingsGroupID
										FROM
											" . DB_PREFIX . "settings_group
										WHERE
											settingsGroupKey = '" . $settingsKey . "'";
        $resultSet       = $this->ObjDatabase->readValue($sql);
        $correspondingID = $resultSet['settingsGroupID'];
        return $correspondingID;
    }
    //Check for menu key
    public function setAdminSectionKey() {
        $sql       = "	SHOW COLUMNS 
							FROM 
								`" . DB_PREFIX . "admin_modules` 
							LIKE 
								'adminSectionKey'";
        $resultSet = $this->ObjDatabase->readValue($sql);
        if (empty($resultSet)) {
            $sql = "	ALTER TABLE
												" . DB_PREFIX . "admin_modules
											ADD adminSectionKey varchar(255) NOT NULL";
            $this->ObjDatabase->setQuery($sql);
        }
    }
    //Insert Affiliate Tables
    public function insertAffiliateTables() {
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliates`
							(
								`affiliateUserID` int(11) NOT NULL AUTO_INCREMENT,
			  					`affiliateID` varchar(25) DEFAULT NULL,
			  					`affiliateReqID` int(11) NOT NULL DEFAULT '0',
			  					`affiliateUserName` varchar(100) DEFAULT NULL,
			  					`affiliatePassword` varchar(50) DEFAULT NULL,
			  					`affiliateFirstName` varchar(100) DEFAULT NULL,
			  					`affiliateLastName` varchar(100) DEFAULT NULL,
			  					`affiliateContactPerson` varchar(100) DEFAULT NULL,
			  					`affiliateCompanyName` varchar(100) DEFAULT NULL,
			  					`affiliateAddress1` varchar(150) DEFAULT NULL,
			  					`affiliateAddress2` varchar(150) DEFAULT NULL,
			  					`affiliateEmail` varchar(150) DEFAULT NULL,
			  					`affiliatePhone` varchar(50) DEFAULT NULL,
			  					`affiliateFax` varchar(50) DEFAULT NULL,
			  					`affiliateCity` varchar(100) DEFAULT NULL,
			  					`affiliateStateID` int(11) NOT NULL DEFAULT '0',
			  					`affiliateStateProvince` varchar(50) DEFAULT NULL,
			  					`affiliateCountryID` int(11) NOT NULL DEFAULT '0',
			  					`affiliateZipcode` varchar(10) NOT NULL DEFAULT '0',
			  					`affiliateTypeofWebsite` varchar(100) DEFAULT NULL,
			  					`affiliateWebsiteURL` varchar(100) DEFAULT NULL,
			  					`affiliateAccountType` varchar(100) DEFAULT NULL,
			  					`affiliateAccountName` varchar(100) DEFAULT NULL,
			  					`affiliateAccountDetails` varchar(255) DEFAULT NULL,
			  					`affiliateStatus` enum('Active','Inactive','Deleted') NOT NULL DEFAULT 'Active',
			  					`affiliateRegisterDate` datetime NOT NULL,
			  					`affiliateLastAccesed` datetime NOT NULL,
			  					`preferredLanguage` int(15) NOT NULL DEFAULT '1',
			  					PRIMARY KEY (`affiliateUserID`)
							) 
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliates_requests` 
								(
			  						`affiliateReqID` int(11) NOT NULL AUTO_INCREMENT,
			  						`affiliateReqFirstName` varchar(100) DEFAULT NULL,
			  						`affiliateReqLastName` varchar(100) DEFAULT NULL,
			  						`affiliateReqContactPerson` varchar(150) DEFAULT NULL,
			  						`affiliateCompanyName` varchar(150) DEFAULT NULL,
			  						`affiliateReqAddress1` varchar(150) DEFAULT NULL,
			  						`affiliateReqAddress2` varchar(150) DEFAULT NULL,
			  						`affiliateReqEmail` varchar(150) DEFAULT NULL,
			  						`affiliateReqPhone` varchar(20) DEFAULT NULL,
			  						`affiliateReqFax` varchar(20) DEFAULT NULL,
			  						`affiliateReqCity` varchar(100) DEFAULT NULL,
			  						`affiliateReqStateID` int(11) NOT NULL,
			  						`affiliateReqProvince` varchar(50) DEFAULT NULL,
			  						`affiliateReqCountryID` int(11) NOT NULL,
			  						`affiliateReqZipcode` varchar(10) NOT NULL,
			  						`affiliateReqTypeofWebsite` varchar(100) DEFAULT NULL,
			  						`affiliateReqWebsiteURL` varchar(150) DEFAULT NULL,
			  						`affiliateReqComments` varchar(255) DEFAULT NULL,
			  						`affiliateReqStatus` enum('New','Approved','Declined') NOT NULL DEFAULT 'New',
			  						`affiliateReqDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
			  						`affiliateReqUpdatedDate` datetime NOT NULL,
			  						PRIMARY KEY (`affiliateReqID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE 
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_commissions`
								(
			  						`affiliateCommissionID` int(11) NOT NULL AUTO_INCREMENT,
			  						`affVisitorID` int(15) NOT NULL,
			  						`affiliateUserID` int(11) NOT NULL DEFAULT '0',
			  						`actionID` int(11) NOT NULL DEFAULT '0' COMMENT 'For Type:Order-OrderID,Subscription-subscID,Registration-UserID',
			  						`commissionAmount` decimal(6,2) NOT NULL DEFAULT '0.00',
			  						`commissionPercent` decimal(12,2) NOT NULL,
			  						`type` enum('Order','Subscription','Registration','Imported User','Imported Subscriber') NOT NULL DEFAULT 'Order',
									`status` enum('New','Active','Cancelled') NOT NULL DEFAULT 'New',
			  						`createdDate` datetime NOT NULL,
			  						`lastUpdateDate` datetime NOT NULL,
			  						`level` enum('F','N','T') NOT NULL COMMENT 'First,Next,Tier',
			  						PRIMARY KEY (`affiliateCommissionID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE 
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_commission_settings`
								(
			  						`affCommSettingsID` int(11) NOT NULL AUTO_INCREMENT,
			  						`affiliateUserID` int(11) NOT NULL,
			  						`enableSalesCommission` enum('Yes','No') NOT NULL,
			  						`firstPurchaseCommissionType` enum('Percentage','Value') NOT NULL,
			  						`firstPurchaseCommissionValue` decimal(10,2) NOT NULL,
			  						`recurringPurchaseCommissionType` enum('Percentage','Value') NOT NULL,
			  						`recurringPurchaseCommissionValue` decimal(10,2) NOT NULL,
			  						`enableTierCommission` enum('Yes','No') NOT NULL,
			  						`tierCommissionLevel` int(10) NOT NULL,
			  						`tierCommissionType` enum('Percentage','Value') NOT NULL,
			  						`tierCommissionValue` decimal(10,2) NOT NULL,
			  						`subscriptionCommission` enum('Yes','No') NOT NULL,
			  						`subscriptionCommissionAmount` decimal(10,2) NOT NULL,
			  						`registrationCommission` enum('Yes','No') NOT NULL,
			  						`registrationCommissionAmount` decimal(10,2) NOT NULL,
			  						`bulkSubscriberImport` enum('Yes','No') NOT NULL,
			  						`bulkSubscriberImportCommission` decimal(10,2) NOT NULL,
			  						`bulkUserImport` enum('Yes','No') NOT NULL,
			  						`bulkUserImportCommission` decimal(10,2) NOT NULL,
			  						PRIMARY KEY (`affCommSettingsID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_imported_users`
								(
			  						`userID` int(11) NOT NULL AUTO_INCREMENT,
			  						`bulkID` int(11) NOT NULL,
			  						`userEmail` varchar(150) NOT NULL,
			  						`userPassword` varchar(255) NOT NULL,
			  						`userFirstName` varchar(100) NOT NULL,
			  						`userLastName` varchar(100) NOT NULL,
			  						`userPhone` varchar(25) NOT NULL,
			  						`userCity` varchar(100) NOT NULL,
			  						`userAdress1` varchar(255) NOT NULL,
			  						`userAdress2` varchar(255) NOT NULL,
			  						`userZip` varchar(12) NOT NULL,
			  						`userConfirm` enum('Yes','No') NOT NULL DEFAULT 'No',
			  						`confirmDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
			  						PRIMARY KEY (`userID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE 
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_payments`
								(
			  						`affiliatePaymentTransID` int(11) NOT NULL AUTO_INCREMENT,
			  						`affiliateUserID` int(11) NOT NULL DEFAULT '0',
			  						`affiliateTransDate` datetime NOT NULL,
			  						`affiliateTransAmt` decimal(10,2) NOT NULL DEFAULT '0.00',
			  						`affiliateTransType` varchar(50) NOT NULL,
			  						`affiliateTransDescrption` varchar(255) DEFAULT NULL,
			  						`readStatus` enum('Read','Unread') NOT NULL DEFAULT 'Unread',
			  						`transactionDescrForAffiliate` text NOT NULL,
			  						PRIMARY KEY (`affiliatePaymentTransID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_payment_details`
								(
			  						`affiliatePaymentDetailID` int(11) NOT NULL AUTO_INCREMENT,
			  						`affiliatePaymentTransID` int(11) NOT NULL DEFAULT '0',
			  						`affiliateCommissionID` int(11) NOT NULL DEFAULT '0',
			  						`affiliatePaidAmount` decimal(10,2) NOT NULL DEFAULT '0.00',
			  						PRIMARY KEY (`affiliatePaymentDetailID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_performance`
								(
									`affPerformanceID` int(11) NOT NULL AUTO_INCREMENT,
			  						`affVisitorID` int(11) NOT NULL DEFAULT '0',
			  						`affiliateUserID` int(11) NOT NULL DEFAULT '0',
			  						`actionID` int(11) NOT NULL DEFAULT '0' COMMENT 'For Type:Order-OrderID,Subscription-subscID,Registration-UserID',
			  						`type` enum('Order','Subscription','Registration','Imported User','Imported Subscriber') NOT NULL,
			  						`createdDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
			  						PRIMARY KEY (`affPerformanceID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_to_subscribers`
							(
			  					`affSubscID` int(11) NOT NULL AUTO_INCREMENT,
			  					`bulkID` int(11) NOT NULL,
			  					`subscEmailID` varchar(150) NOT NULL,
			  					`contactPhone` varchar(50) NOT NULL,
			  					`confirmStatus` enum('Yes','No') NOT NULL,
			  					`updatedDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
			  					PRIMARY KEY (`affSubscID`)
							)
						ENGINE=MyISAM DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_visits`
								(
			  						`affVisitorID` int(15) NOT NULL AUTO_INCREMENT,
			  						`affiliateUserID` int(15) NOT NULL,
			  						`visitorID` int(15) NOT NULL,
			  						`widgetID` int(15) NOT NULL,
			  						`visitType` enum('Widget','API','Referral','Imported User','Imported Subscriber') NOT NULL,
			  						PRIMARY KEY (`affVisitorID`)
								)
					 	ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_widget_details`
								(
			  						`affiliateWidgetDetailID` int(11) NOT NULL AUTO_INCREMENT,
			  						`widgetName` varchar(100) NOT NULL,
			  						`widgetProductCategories` text NOT NULL,
			  						`widgetCities` text NOT NULL,
			  						`widgetType` enum('Iframe','Flash','JS') NOT NULL,
			  						`affiliateProductSizeID` varchar(50) NOT NULL,
			  						`affiliateUserID` int(11) DEFAULT NULL,
			  						`languageID` int(11) NOT NULL DEFAULT '0',
			  						`affiliateWidgetContentType` enum('Text_Only','Image_Only','Image_with_Text') NOT NULL,
			  						`widgetColors` text NOT NULL,
			  						`affiliateWidgetCreatedDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
			  						`affiliateWidgetOtherProductTypes` varchar(50) NOT NULL,
			  						`widgetScrolling` enum('Horizontal','Vertical') NOT NULL,
			  						`widget_format` enum('Sidebar','Large','Banner') NOT NULL,
			  						`widgetStatus` enum('Active','Inactive','Deleted') NOT NULL DEFAULT 'Active',
			  						PRIMARY KEY (`affiliateWidgetDetailID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "affiliate_widget_size`
								(
			  						`affiliateProductSizeID` int(11) NOT NULL AUTO_INCREMENT,
			  						`affiliateProductWidthPx` int(11) NOT NULL DEFAULT '0',
			  						`affiliateProductHeightPx` int(11) NOT NULL DEFAULT '0',
			  						`widget_format` enum('Sidebar','Large','Banner') NOT NULL,
			  						`widgetScrolling` enum('Horizontal','Vertical') NOT NULL,
			  						PRIMARY KEY (`affiliateProductSizeID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE
							IF NOT EXISTS `" . DB_PREFIX . "aff_bulk_import`
								(
			  						`bulkID` int(11) NOT NULL AUTO_INCREMENT,
					  				`affiliateUserID` int(11) NOT NULL,
					  				`commission` decimal(10,2) NOT NULL,
					  				`addedDate` datetime NOT NULL,
					  				`campaignListID` varchar(100) NOT NULL,
					  				`campaignListName` varchar(50) NOT NULL,
					  				`mailSendStatus` enum('Yes','No') NOT NULL,
			  						`cities` text NOT NULL,
			  						`type` enum('User','Subscriber') NOT NULL,
			  						`mailScheduleDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
			  						`importLog` text NOT NULL,
			  						PRIMARY KEY (`bulkID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	INSERT INTO
							`" . DB_PREFIX . "affiliate_widget_size`
							(
								`affiliateProductSizeID`,
								`affiliateProductWidthPx`,
								`affiliateProductHeightPx`,
								`widget_format`,
								`widgetScrolling`
							) 
						VALUES
							(
								1,
								250,
								250,
								'Large',
								'Horizontal'
							),
							(
								2,
								120,
								400,
								'Sidebar',
								'Vertical'
							),
							(
								3,
								160,
								400,
								'Sidebar',
								'Vertical'
							),
							(
								4,
								300,
								250,
								'Large',
								'Horizontal'
							),
							(
								5,
								336,
								280,
								'Large',
								'Horizontal'
							),
							(
								6,
								728,
								90,
								'Banner',
								'Horizontal'
							);";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	ALTER TABLE
							`" . DB_PREFIX . "subscribers`
						ADD
							`remoteAddress` VARCHAR(100) NOT NULL";
        $this->ObjDatabase->setQuery($sql);
        $sql = "	CREATE TABLE 
							IF NOT EXISTS `" . DB_PREFIX . "visitor_info_log`
								(
			  						`visitorID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Visitor Id',
			  						`entryPage` varchar(765) NOT NULL,
			  						`entryTime` datetime NOT NULL COMMENT 'First Visit Time',
			  						`exitPage` varchar(765) NOT NULL,
			  						`exitTime` datetime NOT NULL,
			  						`userAgent` varchar(765) NOT NULL COMMENT 'User Agent',
			  						`browserName` varchar(765) NOT NULL,
			  						`operatingSystem` varchar(765) NOT NULL,
			  						`httpReferer` varchar(765) NOT NULL COMMENT 'Http Referer',
			  						`remoteAddress` varchar(765) NOT NULL COMMENT 'Remote Address',
			  						`serverAddress` varchar(765) NOT NULL,
			  						`userID` varchar(11) NOT NULL COMMENT 'User ID',
			  						`loginTime` datetime NOT NULL COMMENT 'Login Time',
			  						`logoutTime` datetime NOT NULL COMMENT 'Logout Time',
			  						`userType` varchar(125) NOT NULL COMMENT 'User Type',
			  						`searchKeyWord` varchar(200) NOT NULL,
			  						`searchEngineName` varchar(175) NOT NULL,
			  						`orderPlaced` int(12) NOT NULL,
			  						`orderAmount` decimal(10,2) NOT NULL,
			  						`doneSubscribe` int(12) NOT NULL,
			  						`doneSignUp` int(12) NOT NULL,
			  						`userSex` enum('Not Specified','Male','Female') NOT NULL,
			  						`userAge` varchar(25) NOT NULL,
			  						`pageCount` int(12) NOT NULL,
			  						`city` varchar(765) NOT NULL,
			  						`country` varchar(175) NOT NULL,
			  						`referrerType` varchar(150) NOT NULL,
			  						`referrerDetails` varchar(175) NOT NULL,
			  						`referrerWebSite` varchar(125) NOT NULL,
			  						`widgetID` int(12) NOT NULL,
			  						`isMobileWeb` enum('No','Yes') NOT NULL,
			  						`languageID` int(11) DEFAULT NULL,
			  						PRIMARY KEY (`visitorID`)
								)
						ENGINE=MyISAM  DEFAULT CHARSET=latin1";
        $this->ObjDatabase->setQuery($sql);
    }
    //Function To Check Whethet Analytics Section Installed Or Not In The Given Project
    public function checkAnalyticsExists() {
        $sql           = "	SELECT
									adminModuleID
								FROM
									" . DB_PREFIX . "admin_modules
								WHERE
									adminSectionKey='analytics_index'";
        $resultSet     = $this->ObjDatabase->readValue($sql);
        $adminModuleID = $resultSet['adminModuleID'];
        if ($adminModuleID > 0) {
            return 1;
        } else {
            return 0;
        }
    }
    //FUNCTION TO DROP TABLES  FOR UNISTALLING SECTION NAME
    public function dropTable($moduleName, $isAffiliateEnables) {
        if ($moduleName == 'analytics') {
            if ($isAffiliateEnables == TRUE) {
                $dropTableArray = array(
                    "crone_execution_details",
                    "visitor_count_info",
                    "visitor_url_log
",
                    "search_engine"
                );
            } else {
                $dropTableArray = array(
                    "crone_execution_details",
                    "visitor_count_info",
                    "visitor_info_log",
                    "visitor_url_log
",
                    "search_engine"
                );
            }
        }
        if (count($dropTableArray) > 0) {
            $sql = "DROP TABLE
							IF EXISTS ";
            echo "<br>" . "List Of Deleted Tables Are" . "<br>";
            foreach ($dropTableArray as $tableName) {
                echo $tableName;
                echo "<br>";
                $sql .= DB_PREFIX . $tableName . ",";
            }
            $sqlDropQuery = substr($sql, 0, -1);
            $this->ObjDatabase->setQuery($sql);
        }
    }
    //FUNCTION TO CREATE TABLE ON INSTALLING EACH SECTION	
    public function createTable($moduleName, $isAffiliateEnables) {
        if ($moduleName == 'analytics') {
            $sql = "	CREATE TABLE
								IF NOT EXISTS
									`" . DB_PREFIX . "crone_execution_details`
										(													
  											`croneID` int(12) NOT NULL AUTO_INCREMENT,
  											`executionTime` datetime NOT NULL,
  											`rowsAffected` int(12) NOT NULL,
  											`lastAffectedID` int(12) NOT NULL,
 											PRIMARY KEY (`croneID`)
								 		)
							ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
            $this->ObjDatabase->setQuery($sql);
            $sql = "	CREATE TABLE 
								IF NOT EXISTS `" . DB_PREFIX . "visitor_count_info`
									(
 										`visitorCountID` int(11) NOT NULL AUTO_INCREMENT,
  										`date` date NOT NULL,
 										`newVisitorCount` int(11) NOT NULL,
  										`returningVisitorCount` int(11) NOT NULL,
  										`returningVisitCount` int(11) NOT NULL,
  										`totalVisitCount` int(11) NOT NULL,
  										 PRIMARY KEY (`visitorCountID`)
								 	)
							ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
            $this->ObjDatabase->setQuery($sql);
            if ($isAffiliateEnables != TRUE) {
                $sql = "	CREATE TABLE 
									IF NOT EXISTS `" . DB_PREFIX . "visitor_info_log`
										(
  											`visitorID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Visitor Id',
 											`entryPage` varchar(765) NOT NULL,
  											`entryTime` datetime NOT NULL COMMENT 'First Visit Time',
  											`exitPage` varchar(765) NOT NULL,
 											 `exitTime` datetime NOT NULL,
  											`userAgent` varchar(765) NOT NULL COMMENT 'User Agent',
  											`browserName` varchar(765) NOT NULL,
  											`operatingSystem` varchar(765) NOT NULL,
 											`httpReferer` varchar(765) NOT NULL COMMENT 'Http Referer',
  											`remoteAddress` varchar(765) NOT NULL COMMENT 'Remote Address',
  											`serverAddress` varchar(765) NOT NULL,
  											`userID` varchar(11) NOT NULL COMMENT 'User ID',
  											`loginTime` datetime NOT NULL COMMENT 'Login Time',
  											`logoutTime` datetime NOT NULL COMMENT 'Logout Time',
  											`userType` varchar(125) NOT NULL COMMENT 'User Type',
  											`searchKeyWord` varchar(200) NOT NULL,
  											`searchEngineName` varchar(175) NOT NULL,
  											`orderPlaced` int(12) NOT NULL,
  											`orderAmount` decimal(10,2) NOT NULL,
  											`doneSubscribe` int(12) NOT NULL,
  											`doneSignUp` int(12) NOT NULL,
 											`userSex` enum('Not Specified','Male','Female') NOT NULL,
  											`userAge` varchar(25) NOT NULL,
  											`pageCount` int(12) NOT NULL,
  											`city` varchar(765) NOT NULL,
 											`country` varchar(175) NOT NULL,
  											`referrerType` varchar(150) NOT NULL,
  											`referrerDetails` varchar(175) NOT NULL,
  											`referrerWebSite` varchar(125) NOT NULL,
  											`widgetID` int(12) NOT NULL,
  											`isMobileWeb` enum('No','Yes') NOT NULL,
  											`languageID` int(11) DEFAULT NULL,
  											 PRIMARY KEY (`visitorID`)
										)
								ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
                $this->ObjDatabase->setQuery($sql);
            }
            $sql = "	CREATE TABLE 
								IF NOT EXISTS `" . DB_PREFIX . "visitor_url_log`
									(	
  										`urlID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Url Id',
  										`visitorID` int(11) NOT NULL,
  										`currentUrl` varchar(765) NOT NULL,
 										`refererUrl` varchar(765) NOT NULL,
  										`visitTime` datetime NOT NULL,
 										PRIMARY KEY (`urlID`),
  										KEY `visitorID` (`visitorID`)
									)
							ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
            $this->ObjDatabase->setQuery($sql);
            $sql = "	CREATE TABLE
								IF NOT EXISTS `" . DB_PREFIX . "search_engine`
									(
  										`searchEngineID` int(11) NOT NULL AUTO_INCREMENT,
  										`searchEngineName` varchar(225) NOT NULL,
  										`searchEngineURL` varchar(225) NOT NULL,
  										`searchParameter` varchar(25) NOT NULL,
 										PRIMARY KEY (`searchEngineID`)
									)
							ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
            $this->ObjDatabase->setQuery($sql);
            $sql = "	INSERT INTO `" . DB_PREFIX . "search_engine`
								(
									`searchEngineID`,
									`searchEngineName`,
									`searchEngineURL`,
									`searchParameter`
								)
							VALUES
								(
									1,
									'Google',
									'google',
									'q'
								),
								(
									2,
									'Yahoo !',
									'yahoo',
									'p'
								),
								(
									3,
									'Bing',
									'bing',
									'q'
								),
								(
									4,
									'Ask',
									'ask',
									'q'
								)";
            $this->ObjDatabase->setQuery($sql);
        }
        return true;
    }
    //Check Whether a table exists[Not in use]
    public function checkForATable($table) {
        $tableExists = true;
        $sql         = "SHOW TABLES LIKE '" . DB_PREFIX . $table;
        $resultSet   = $this->ObjDatabase->readValue($sql);
        if (empty($resultSet)) {
            $tableExists = false;
        }
        return $tableExists;
    }
}
// End of Class 


