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

class Twitterclone_Form_Admin_Settings_Global extends Engine_Form {

  public function init() {

    $settings = Engine_Api::_()->getApi('settings', 'core');
    $view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;
    $fileLink = $view->baseUrl() . '/admin/files/';

		$supportTicket = '<a href="https://socialengine.com/store/clientarea.php?action=products&module=licensing" target="_blank">click here</a>';
		$descriptionLicense = sprintf('Enter your license key that is provided to you when you purchased this plugin. If you do not know your license key, please %s. (Key Format: SEPHP-XXXXXXXXXXXXXXXX)',$supportTicket);

		$this->addElement('Text', 'twitterclone_licensekey', array(
			'label' => 'License Key',
			'description' => $descriptionLicense,
			'required' => true,
			'allowEmpty' => false,
			'validators' => array(
				array('NotEmpty', true),
			),
			'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('twitterclone.licensekey'),
		));
		$this->getElement('twitterclone_licensekey')->getDecorator('Description')->setOptions(array('placement' => 'PREPEND', 'escape' => false));

		if (engine_in_array($_SERVER['SERVER_NAME'], ['localhost', '127.0.0.1'])) {
			$this->addElement('Text', 'domain_name', array(
				'label' => 'Domain Name',
				'required' => true,
				'allowEmpty' => false,
				'validators' => array(
					array('NotEmpty', true),
				),
				'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('domain.name'),
			));
		}

		if (Engine_Api::_()->getApi('settings', 'core')->getSetting('twitterclone.pluginactivated')) {

			// Get available files
			$logoOptions = array('' => 'Text-only (No logo)');
			$files = Engine_Api::_()->getDbTable('files', 'core')->getFiles(array('fetchAll' => 1, 'extension' => array('gif', 'jpg', 'jpeg', 'png', 'webp')));
			foreach( $files as $file ) {
				$logoOptions[$file->storage_path] = $file->name;
			}

			$this->addElement('Radio', 'twitterclone_changelanding', array(
				'label' => 'Set Landing Page of X Clone Theme',
				'description' => 'Do you want to set the Landing Page from this theme and replace the current Landing page with one of the landing page design from this theme? (If you choose Yes and save changes, then later you can manually make changes in the Landing page from Layout Editor. Back up page of your current landing page will get created with the name "Backup - Landing Page".)',
				'onclick' => 'confirmChangeLandingPage(this.value)',
				'multiOptions' => array(
					'1' => 'Yes, set the Landing Page',
					'0' => 'No',
				),
				'value' => Engine_Api::_()->getDbTable('settings', 'core')->getDbSettings('twitterclone.changelanding') ? Engine_Api::_()->getDbTable('settings', 'core')->getDbSettings('twitterclone.changelanding'): 0,
			));

			if (!$settings->getSetting('twitterclone.changememberhome', 0)) {
				$this->addElement('Radio', 'twitterclone_changememberhome', array(
					'label' => 'Set Member Home Page',
					'description' => 'Do you want to set the Member Home Page from this theme and replace the current Member Home page with one of the member home page design from this theme? (If you choose Yes and save changes, then later you can manually make changes in the Member Home page from Layout Editor. Back up page of your current member home page will get created with the name "Backup - Member Home Page".)',
					'onclick' => 'confirmChangeMemberHomePage(this.value)',
					'multiOptions' => array(
						'1' => 'Yes',
						'0' => 'No',
					),
					'value' => $settings->getSetting('twitterclone.changememberhome', 0),
				));
			}
			
			if (!$settings->getSetting('twitterclone.changememberprofile', 0)) {
				$this->addElement('Radio', 'twitterclone_changememberprofile', array(
					'label' => 'Set Member Profile Page',
					'description' => 'Do you want to set the Member Profile Page from this theme and replace the current Member Profile page with one of the member profile page design from this theme? (If you choose Yes and save changes, then later you can manually make changes in the Member Profile page from Layout Editor. Back up page of your current member profile page will get created with the name "Backup - Member Profile Page".)',
					'onclick' => 'confirmChangeMemberProfilePage(this.value)',
					'multiOptions' => array(
						'1' => 'Yes',
						'0' => 'No',
					),
					'value' => $settings->getSetting('twitterclone.changememberprofile', 0),
				));
			}

			$this->addElement('MultiCheckbox', 'twitterclone_headerloggedinoptions', array(
				'label' => 'Header Options for Logged in Members',
				'description' => 'Choose from the below options to be available in the header to logged in members on your website.',
				'multiOptions' => array(
						'search' => 'Search',
						'miniMenu' => 'Mini Menu',
						'mainMenu' =>'Main Menu',
						'logo' =>'Logo',
				),
				'value' => unserialize($settings->getSetting('twitterclone.headerloggedinoptions', 'a:4:{i:0;s:6:"search";i:1;s:8:"miniMenu";i:2;s:8:"mainMenu";i:3;s:4:"logo";}')),
			));

			$this->addElement('MultiCheckbox', 'twitterclone_headernonloggedinoptions', array(
				'label' => 'Header Options for Non-Logged in Members',
				'description' => 'Choose from the below options to be available in the header to non-logged in members on your website.',
				'multiOptions' => array(
						'search' => 'Search',
						'miniMenu' => 'Mini Menu',
						'mainMenu' =>'Main Menu',
						'logo' =>'Logo',
				),
				'value' => unserialize($settings->getSetting('twitterclone.headernonloggedinoptions', 'a:4:{i:0;s:6:"search";i:1;s:8:"miniMenu";i:2;s:8:"mainMenu";i:3;s:4:"logo";}')),
			));

			$description = $this->getTranslator()->translate('Choose from below the logo to be displayed in the header of your website. [Note: You can add a new logo from the "File & Media Manager" section from here: <a href="%1$s" target="_blank">File & Media Manager</a>.]');
			$description = vsprintf($description, array($fileLink));
				
			$this->addElement('Select', 'twitterclone_logo', array(
				'label' => 'Logo In Header',
				'description' => $description,
				'multiOptions' => $logoOptions,
				'value'=>$settings->getSetting("twitterclone_logo",'')
			));
			$this->twitterclone_logo->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false));
			
			$description = $this->getTranslator()->translate('Choose from below the logo to be displayed in contrast mode in the header of your website. [Note: You can add a new logo from the "File & Media Manager" section from here: <a href="%1$s" target="_blank">File & Media Manager</a>.]');
			$description = vsprintf($description, array($fileLink));
			$this->addElement('Select', 'twitterclone_logocontrast', array(
				'label' => 'Logo In Header (Contrast Mode)',
				'description' => $description,
				'multiOptions' => $logoOptions,
				'value' => $settings->getSetting("twitterclone.logocontrast",'')
			)); 
			$this->twitterclone_logocontrast->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false));

			$this->addElement('Text', 'themewidget_radius', array(
				'label' => 'Widget Corner Radius',
				'description' => 'Enter the corner radius of widgets on your website in px.',
				'value' => $settings->getSetting('themewidget.radius', 10),
			));
			
			$this->addElement('Select', 'accessibility_options', array(
				'label' => 'Show Accessibility Options',
				'multiOptions' => array('1'=>'Yes','0'=>'No'),
				'value'=> $settings->getSetting("accessibility_options",1)
			));

			$this->addElement('Select', 'twitterclone_footersidepanel', array(
				'label' => 'Show Footer in Vertical Sidebar',
				'description' => 'Do you want to show footer in vertical sidebar menu with header?',
				'multiOptions' => array(
						1 => 'Yes',
						0 => 'No'
				),
				'value' => $settings->getSetting('twitterclone.footersidepanel',1),
			));
			
			$this->addElement('Button', 'submit', array(
				'label' => 'Save Changes',
				'type' => 'submit',
				'ignore' => true
			));
		} else {
			//Add submit button
			$this->addElement('Button', 'submit', array(
					'label' => 'Activate your theme',
					'type' => 'submit',
					'ignore' => true
			));
		}
  }
}
