<?php
/**
 * Ahead WebSoft Technologies Pvt Ltd.
 * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
 * @license    https://www.socialengine.com/policies
*/

class Pulse_Installer extends Engine_Package_Installer_Module {

  public function onInstall() {
    $db = $this->getDb();
    if($this->_databaseOperationType != 'upgrade') {
    
      //Quick links footer
      $menuitem_id = $db->select()
                      ->from('engine4_core_menuitems', 'id')
                      ->limit(1)
                      ->order('id DESC')
                      ->query()
                      ->fetchColumn();

      $db->query('INSERT IGNORE INTO `engine4_core_menuitems` (`name`, `module`, `label`, `plugin`, `params`, `menu`, `submenu`, `enabled`, `custom`, `order`) VALUES
      ("custom_'.$menuitem_id++.'", "core", "Start Poll", "", \'{"uri":"polls/create","icon":""}\', "pulse_quicklinks_footer", "", 1, 1, 1),
      ("custom_'.$menuitem_id++.'", "core", "Publish Video", "", \'{"uri":"videos/create","icon":""}\', "pulse_quicklinks_footer", "", 1, 1, 2),
      ("custom_'.$menuitem_id++.'", "core", "Join Groups", "", \'{"uri":"groups"}\', "pulse_quicklinks_footer", "", 1, 1, 3),
      ("custom_'.$menuitem_id++.'", "core", "Videos", "", \'{"uri":"videos","icon":"","target":"","enabled":"1"}\', "pulse_quicklinks_footer", "", 0, 1, 4),
      ("custom_'.$menuitem_id++.'", "core", "Music", "", \'{"uri":"music","icon":"","target":"","enabled":"1"}\', "pulse_quicklinks_footer", "", 0, 1, 5);');
      
      //About Us links footer
      $menuitem_id = $db->select()
                      ->from('engine4_core_menuitems', 'id')
                      ->limit(1)
                      ->order('id DESC')
                      ->query()
                      ->fetchColumn();

      $db->query('INSERT IGNORE INTO `engine4_core_menuitems` (`name`, `module`, `label`, `plugin`, `params`, `menu`, `submenu`, `enabled`, `custom`, `order`) VALUES
      ("custom_'.$menuitem_id++.'", "core", "Albums", "", \'{"uri":"albums","icon":""}\', "pulse_aboutlinks_footer", "", 1, 1, 1),
      ("custom_'.$menuitem_id++.'", "core", "Blogs", "", \'{"uri":"blogs","icon":""}\', "pulse_aboutlinks_footer", "", 1, 1, 2),
      ("custom_'.$menuitem_id++.'", "core", "Events", "", \'{"uri":"events"}\', "pulse_aboutlinks_footer", "", 1, 1, 3),
      ("custom_'.$menuitem_id++.'", "core", "Videos", "", \'{"uri":"videos","icon":"","target":"","enabled":"1"}\', "pulse_aboutlinks_footer", "", 0, 1, 4),
      ("custom_'.$menuitem_id++.'", "core", "Music", "", \'{"uri":"music","icon":"","target":"","enabled":"1"}\', "pulse_aboutlinks_footer", "", 0, 1, 5);');

			//Header work
			$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-main";');
			$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-mini";');
			$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-logo";');
			$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.search-mini";');
			$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "charity.header";');
      $parent_content_id = $db->select()
              ->from('engine4_core_content', 'content_id')
              ->where('type = ?', 'container')
              ->where('page_id = ?', '1')
              ->where('name = ?', 'main')
              ->limit(1)
              ->query()
              ->fetchColumn();
			if($parent_content_id) {
				$select = new Zend_Db_Select($db);
	      $select->from('engine4_core_content')
	          ->where('page_id = ?', 1)
	          ->where('type = ?', 'widget')
	          ->where('name = ?', 'pulse.header');
	      $info = $select->query()->fetch();
	      if(empty($info) ) {
					$db->insert('engine4_core_content', array(
							'type' => 'widget',
							'name' => 'pulse.header',
							'page_id' => 1,
							'parent_content_id' => $parent_content_id,
							'order' => 20,
					));
				}
				$select = new Zend_Db_Select($db);
	      $select->from('engine4_core_content')
	          ->where('page_id = ?', 1)
	          ->where('type = ?', 'widget')
	          ->where('name = ?', 'pulse.mobile-menu');
	      $info = $select->query()->fetch();
	      if(empty($info) ) {
					$db->insert('engine4_core_content', array(
							'type' => 'widget',
							'name' => 'pulse.mobile-menu',
							'page_id' => 1,
							'parent_content_id' => $parent_content_id,
							'order' => 25,
					));
				}
			}
      
      //Footer Work
			$db->query('DELETE FROM engine4_core_content WHERE `engine4_core_content`.`page_id` = 2 AND `engine4_core_content`.`name` = "charity.footer";');
			$db->query('DELETE FROM engine4_core_content WHERE `engine4_core_content`.`page_id` = 2 AND `engine4_core_content`.`name` = "inspira.footer";');
			$db->query('DELETE FROM engine4_core_content WHERE `engine4_core_content`.`page_id` = 2 AND `engine4_core_content`.`name` = "core.menu-footer";');
			$db->query('DELETE FROM engine4_core_content WHERE `engine4_core_content`.`page_id` = 2 AND `engine4_core_content`.`name` = "core.menu-social-sites";');
			
			$parent_content_id = $db->select()
						->from('engine4_core_content', 'content_id')
						->where('type = ?', 'container')
						->where('page_id = ?', '2')
						->where('name = ?', 'main')
						->limit(1)
						->query()
						->fetchColumn();
			if($parent_content_id) {
				$select = new Zend_Db_Select($db);
	      $select->from('engine4_core_content')
	          ->where('page_id = ?', 2)
	          ->where('type = ?', 'widget')
	          ->where('name = ?', 'pulse.footer');
	      $info = $select->query()->fetch();
	      if(empty($info) ) {
					$db->insert('engine4_core_content', array(
						'type' => 'widget',
						'name' => 'pulse.footer',
						'page_id' => 2,
						'parent_content_id' => $parent_content_id,
						'order' => 888,
					));
				}
			}

			//Landing Page setup
			$widgetOrder = 1;
			
			$db->insert('engine4_core_content', array(
				'type' => 'container',
				'name' => 'main',
				'page_id' => 3,
				'order' => 1,
			));
			$mainId = $db->lastInsertId();

			$db->insert('engine4_core_content', array(
					'type' => 'container',
					'name' => 'middle',
					'page_id' => 3,
					'parent_content_id' => $mainId,
					'order' => 2,
			));
			$mainMiddleId = $db->lastInsertId();

			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_content')
					->where('page_id = ?', 3)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.landing-page-banner');
			$info = $select->query()->fetch();
			if(empty($info) ) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.landing-page-banner',
					'page_id' => 3,
					'parent_content_id' => $mainMiddleId,
					'order' => $widgetOrder++,
					'params' => '{"title":"Where Connections Thrive!","description":"Join our network for endless opportunities, innovation, and collective growth. We are a one-stop solution where Innovation meets collaboration.","btntext":"Join Us","btntextlink":"signup","dummy1":null,"count1":"100","text1":"Posts","dummy2":null,"count2":"1500","text2":"Members","dummy3":null,"count3":"1000","text3":"Blogs","dummy4":null,"count4":"500","text4":"Forums","photo5":"","nomobile":"0","name":"pulse.landing-page-banner"}',
				));
			}

			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_content')
					->where('page_id = ?', 3)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.landing-page-features');
			$info = $select->query()->fetch();
			if(empty($info) ) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.landing-page-features',
					'page_id' => 3,
					'parent_content_id' => $mainMiddleId,
					'order' => $widgetOrder++,
					'params' => '{"title":"Explore What Makes the Experience Special","dummy1":null,"photo1":"","featuresheading1":"User-Friendly Experience","description1":"Enjoy a straightforward and easy-to-use platform for smooth navigation & responsiveness.","link1":"","dummy2":null,"photo2":"","featuresheading2":"Interactive Feeds","description2":"Get the latest updates and activities from your network through a dynamic content feed, keeping your experience vibrant and ever-evolving.","link2":"","dummy3":null,"photo3":"","featuresheading3":"Mobile Apps","description3":"Stay connected on the go with fast, native iOS and Android apps designed to access anytime, anywhere.","link3":"","nomobile":"0","name":"pulse.landing-page-features"}',
				));
			}
			
			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_content')
					->where('page_id = ?', 3)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.landing-page-counter-section');
			$info = $select->query()->fetch();
			if(empty($info) ) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.landing-page-counter-section',
					'page_id' => 3,
					'parent_content_id' => $mainMiddleId,
					'order' => $widgetOrder++,
					'params' => '{"title":"Explore What Awaits You Inside!","btntext":"Signup","btntextlink":"signup","dummy1":null,"icon1":"fas fa-pager","count1":"100","text1":"Posts","dummy2":null,"icon2":"fas fa-user-friends","count2":"1500","text2":"Members","dummy3":null,"icon3":"fas fa-blog","count3":"1000","text3":"Blogs","dummy4":null,"icon4":"fas fa-table","count4":"500","text4":"Forums","dummy5":null,"icon5":"fas fa-newspaper","count5":"20000","text5":"Classifieds","nomobile":"0","name":"pulse.landing-page-counter-section"}',
				));
			}

			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_content')
					->where('page_id = ?', 3)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.landing-page-service');
			$info = $select->query()->fetch();
			if(empty($info) ) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.landing-page-cta-section',
					'page_id' => 3,
					'parent_content_id' => $mainMiddleId,
					'order' => $widgetOrder++,
					'params' => '{"title":"How Our Community Works?","dummy1":null,"icon1":"fa-solid fa-key","heading1":"Effortless Access","description1":"Embark on your journey with us by signing up and logging in to connect with our vibrant community.","link1":"","dummy2":null,"icon2":"fa-solid fa-clapperboard","heading2":"Share your story","description2":"Dive in and share your updates, stories, live streaming, create groups, organize events, participate in polls, and much more, all within one platform.","link2":"","dummy3":null,"icon3":"fa-solid fa-tower-broadcast","heading3":"Go Live with Your Content","description3":"Start broadcasting your content live with your members and share the recording in the feeds or stories to catch up.","link3":"","dummy4":null,"icon4":"fa-solid fa-coins","heading4":"Monetize Your Community","description4":"Turn engagement into revenue with memberships, Verification subscriptions, ads, and built-in monetization tools.","link4":"","nomobile":"0","name":"pulse.landing-page-cta-section"}',
				));
			}
			
			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_content')
					->where('page_id = ?', 3)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.landing-page-service');
			$info = $select->query()->fetch();
			if(empty($info) ) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.landing-page-service',
					'page_id' => 3,
					'parent_content_id' => $mainMiddleId,
					'order' => $widgetOrder++,
					'params' => '{"title":"Discover Our Features","description":"See what type of features we offer to make launching and managing your SocialEngine community seamless from day one","dummy1":null,"photo1":"","servicesheading1":"Profile Creation","servicesdescription1":"Set up a personalized profile types and member level to showcase your interests and personality ","link1":"","dummy2":null,"photo2":"","servicesheading2":"Messaging","servicesdescription2":"Send instant messages to friends, family & colleagues, encouraging real-time communication","link2":"","dummy3":null,"photo3":"","servicesheading3":"Groups and Communities","servicesdescription3":"Find or create groups by interests. Participate in discussions, events and activities together","link3":"","dummy4":null,"photo4":"","servicesheading4":"Events and Calendar","servicesdescription4":"Stay informed about upcoming events within your network and plan your schedule ahead of time","link4":"","dummy5":null,"photo5":"","servicesheading5":"News And Feed","servicesdescription5":"Receive updates from real-time notifications in a dynamic feed, keeping you connected with the latest activities and content","link5":"","dummy6":null,"photo6":"","servicesheading6":"Classifieds","servicesdescription6":"Buy, sell, or trade goods and services within the community to build a virtual marketplace for members within your community. ","link6":"","nomobile":"0","name":"pulse.landing-page-service"}',
				));
			}
			
			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_content')
					->where('page_id = ?', 3)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.landing-page-blogs');
			$info = $select->query()->fetch();
			if(empty($info) ) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.landing-page-blogs',
					'page_id' => 3,
					'parent_content_id' => $mainMiddleId,
					'order' => $widgetOrder++,
					'params' => '{"title":"Our Latest Blogs","nomobile":"0","name":"pulse.landing-page-blogs"}',
				));
			}
			
			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_content')
					->where('page_id = ?', 3)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.landing-page-app-section');
			$info = $select->query()->fetch();
			if(empty($info) ) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.landing-page-app-section',
					'page_id' => 3,
					'parent_content_id' => $mainMiddleId,
					'order' => $widgetOrder++,
					'params' => '{"title":"Stay Connected Anywhere & Everywhere!","description":"Access your community easily on the go with our simple and user-friendly mobile apps.","androidapplink":"#","iosapplink":"#","apprightimage":"","nomobile":"0","name":"pulse.landing-page-app-section"}',
				));
			}

			//Theme Enable
			$db->query('INSERT IGNORE INTO `engine4_core_themes` (`name`, `title`, `description`, `active`) VALUES
			("pulse", "Pulse", "Pulse", 0);');
			$select = new Zend_Db_Select($db);
			$select->from('engine4_core_themes', 'name')
							->where('active = ?', 1)
							->limit(1);
			$themeActive = $select->query()->fetch();
			if($themeActive) {
				$db->query("UPDATE  `engine4_core_themes` SET  `active` =  '0' WHERE  `engine4_core_themes`.`name` ='".$themeActive['name']."' LIMIT 1");
				$db->query("UPDATE  `engine4_core_modules` SET  `enabled` =  '0' WHERE  `engine4_core_modules`.`name` ='".$themeActive['name']."' LIMIT 1");
				$db->query("UPDATE  `engine4_core_themes` SET  `active` =  '1' WHERE  `engine4_core_themes`.`name` ='pulse' LIMIT 1");
			}
      
      //Start Make extra file for pulse theme custom css
      $themeDirName = APPLICATION_PATH . '/application/themes/pulse';
			@chmod($themeDirName, 0777);
			$fileName = $themeDirName . '/pulse-custom.css';
			$fileexists = @file_exists($fileName);
			if (empty($fileexists)) {
				@chmod($themeDirName, 0777);
				$fh = @fopen($fileName, 'w');
				@fwrite($fh, '/* ADD YOUR CUSTOM CSS HERE */');
				@chmod($fileName, 0777);
				@fclose($fh);
				@chmod($fileName, 0777);
				@chmod($fileName, 0777);
			}
    }

		//Theme Color Default Installation
    $theme = APPLICATION_PATH . '/application/themes/pulse';
    @chmod($theme, 0777);
    $filename = $theme . '/theme-variables.css';
    $fileExists = @file_exists($filename);
    if (empty($fileExists)) {
      @chmod($theme, 0777);
      $fh = @fopen($filename, 'w');
      $constant = ':root {
				--themewidget-radius:1.25rem;
				--pulse-header-background-color:#FFFFFF;
				--pulse-minimenu-links-color:#000000;
				--pulse-minimenu-links-hover-color:#000000;
				--pulse-minimenu-background-color:#FFFFFF;
				--pulse-minimenu-background-hover-color:#F5F5F5;
				--pulse-minimenu-search-background-color:#F5F7FB;
				--pulse-minimenu-search-font-color:#4A536A;
				--pulse-footer-background-color:#FFFFFF;
				--pulse-footer-font-color:#2C2C2C;
				--pulse-footer-links-color:#2C2C2C;
				--pulse-footer-border-color:#FFFFFF;
				--pulse-theme-color:#5E72E4;
				--pulse-body-background-color:#F5F7FB;
				--pulse-font-color:#20242E;
				--pulse-font-color-light:#666666;
				--pulse-links-color:#20242E;
				--pulse-links-hover-color:#1976D2;
				--pulse-headline-color:#2C2C2C;
				--pulse-border-color:#F1F1F1;
				--pulse-box-background-color:#FFFFFF;
				--pulse-box-background-color-alt:#F5F5F5;
				--pulse-input-background-color:#FFFFFF;
				--pulse-input-font-color:#4A536A;
				--pulse-input-border-color:#F1F1F1;
				--pulse-button-background-color:#5E72E4;
				--pulse-button-background-color-hover:#5D66E4;
				--pulse-button-font-color:#FFFFFF;
				--pulse-button-border-color:#5E72E4;
				--pulse-button-font-color-hover:#FFFFFF;
				--pulse-button-border-color-hover:#5D66E4;
				--pulse-secondary-button-background-color:#F5F5F5;
				--pulse-secondary-button-background-color-hover:#D8D8D8;
				--pulse-secondary-button-font-color:#2C2C2C;
				--pulse-secondary-button-font-color-hover:#2C2C2C;
				--pulse-secondary-button-border-color:#F0F0F0;
				--pulse-secondary-button-border-color-hover:#D8D8D8;
				--pulse-comments-background-color:#FDFDFD;
				--pulse-body-fontfamily:"Poppins";
				--pulse-heading-fontfamily:"Poppins";
				--pulse-tab-fontfamily:"Poppins";
				--pulse-body-fontsize:0.875rem;
				--pulse-heading-fontsize:1.0625rem;
				--pulse-tab-fontsize:0.875rem;
      }';
      @fwrite($fh, $constant);
      @chmod($filename, 0777);
      @fclose($fh);
      @chmod($filename, 0777);
      @chmod($filename, 0777);
      
			$db->query('INSERT IGNORE INTO `engine4_core_settings` (`name`, `value`) VALUES
      ("pulse.theme.color", 1);');
    }
		//Theme Color Default Installation
		
    parent::onInstall();
  }
  
  
  public function onDisable() {
  
    $db = $this->getDb();
    
    //Header
    $db->query("DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = 'pulse.header';");
    $parent_content_id = $db->select()
		        ->from('engine4_core_content', 'content_id')
		        ->where('type = ?', 'container')
		        ->where('page_id = ?', '1')
		        ->where('name = ?', 'main')
		        ->limit(1)
		        ->query()
		        ->fetchColumn();
		if($parent_content_id) {
		  $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.menu-mini',
        'page_id' => 1,
        'parent_content_id' => $parent_content_id,
        'order' => 9,
      ));
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.search-mini',
        'page_id' => 1,
        'parent_content_id' => $parent_content_id,
        'order' => 10,
      ));
			$db->insert('engine4_core_content', array(
		      'type' => 'widget',
		      'name' => 'core.menu-logo',
		      'page_id' => 1,
		      'parent_content_id' => $parent_content_id,
		      'order' => 11,
		  ));
		  $db->insert('engine4_core_content', array(
		      'type' => 'widget',
		      'name' => 'core.menu-main',
		      'page_id' => 1,
		      'parent_content_id' => $parent_content_id,
		      'order' => 12,
		  ));
	  }
	  
    //Footer Work
    $db->query('DELETE FROM engine4_core_content WHERE `engine4_core_content`.`page_id` = 2 AND `engine4_core_content`.`name` = "pulse.footer";');
		$db->query('DELETE FROM engine4_core_content WHERE `engine4_core_content`.`page_id` = 2 AND `engine4_core_content`.`name` = "core.menu-footer";');
		$parent_content_id = $db->select()
						->from('engine4_core_content', 'content_id')
						->where('type = ?', 'container')
						->where('page_id = ?', '2')
						->where('name = ?', 'main')
						->limit(1)
						->query()
						->fetchColumn();
		if(!empty($parent_content_id)) {
			$db->insert('engine4_core_content', array(
				'type' => 'widget',
				'name' => 'core.menu-footer',
				'page_id' => 2,
				'parent_content_id' => $parent_content_id,
				'order' => 9,
			));
		}

		
		//Theme Enabled and disabled
		$select = new Zend_Db_Select($db);
		$select->from('engine4_core_themes', 'name')
						->where('active = ?', 1)
						->limit(1);
		$themeActive = $select->query()->fetch();
		if($themeActive) {
			$db->query("UPDATE  `engine4_core_themes` SET  `active` =  '0' WHERE  `engine4_core_themes`.`name` ='".$themeActive['name']."' LIMIT 1");
			$db->query("UPDATE  `engine4_core_modules` SET  `enabled` =  '1' WHERE  `engine4_core_modules`.`name` ='pulse' LIMIT 1");
			$db->query("UPDATE  `engine4_core_themes` SET  `active` =  '1' WHERE  `engine4_core_themes`.`name` ='pulse' LIMIT 1");
		}
		$db->query("UPDATE `engine4_core_settings` SET `value` = '0' WHERE `engine4_core_settings`.`name` = 'pulse.changelanding';");
		
    parent::onDisable();
  }
  
  function onEnable() {
  
    $db = $this->getDb();

		//Header
		$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-main";');
		$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-mini";');
		$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-logo";');
		$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.search-mini";');
		$db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "charity.header";');
    $parent_content_id = $db->select()
		        ->from('engine4_core_content', 'content_id')
		        ->where('type = ?', 'container')
		        ->where('page_id = ?', '1')
		        ->where('name = ?', 'main')
		        ->limit(1)
		        ->query()
		        ->fetchColumn();
		if($parent_content_id) {
			$select = new Zend_Db_Select($db);
			$select_content = $select
					->from('engine4_core_content')
					->where('page_id = ?', 1)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.header')
					->limit(1);
			$content_id = $select_content->query()->fetchObject()->content_id;
			if(empty($content_id)) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.header',
					'page_id' => 1,
					'parent_content_id' => $parent_content_id,
					'order' => 20,
				));
			}
		}

	  //Footer
	  $db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-footer";');
	  $db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "core.menu-social-sites";');
    $db->query('DELETE FROM `engine4_core_content` WHERE `engine4_core_content`.`name` = "charity.footer";');
		$parent_content_id = $db->select()
		        ->from('engine4_core_content', 'content_id')
		        ->where('type = ?', 'container')
		        ->where('page_id = ?', '2')
		        ->where('name = ?', 'main')
		        ->limit(1)
		        ->query()
		        ->fetchColumn();
		if(!empty($parent_content_id)) {
			$select = new Zend_Db_Select($db);
			$select_content = $select
					->from('engine4_core_content')
					->where('page_id = ?', 2)
					->where('type = ?', 'widget')
					->where('name = ?', 'pulse.footer')
					->limit(1);
			$content_id = $select_content->query()->fetchObject()->content_id;
			
			if(empty($content_id)) {
				$db->insert('engine4_core_content', array(
					'type' => 'widget',
					'name' => 'pulse.footer',
					'page_id' => 2,
					'parent_content_id' => $parent_content_id,
					'order' => 9,
				));
			}
	  }
    
    //Theme active
    $select = new Zend_Db_Select($db);
    $select->from('engine4_core_themes', 'name')
            ->where('active = ?', 1)
            ->limit(1);
    $themeActive = $select->query()->fetch();
    if($themeActive) {
			$db->query("UPDATE  `engine4_core_themes` SET  `active` =  '0' WHERE  `engine4_core_themes`.`name` ='".$themeActive['name']."' LIMIT 1");
			$db->query("UPDATE  `engine4_core_modules` SET  `enabled` =  '0' WHERE  `engine4_core_modules`.`name` ='".$themeActive['name']."' LIMIT 1");
	    $db->query("UPDATE  `engine4_core_themes` SET  `active` =  '1' WHERE  `engine4_core_themes`.`name` ='pulse' LIMIT 1");
    }
    $db->query("UPDATE `engine4_core_settings` SET `value` = '0' WHERE `engine4_core_settings`.`name` = 'pulse.changelanding';");

    parent::onEnable();
  }
}