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

class Gdpr_Form_Admin_Global extends Engine_Form
{

  public function init()
  {

    $settings = Engine_Api::_()->getApi('settings', 'core');
    $this->setTitle('Global Settings')
      ->setDescription('These settings affect all members in your community.');

		$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', 'gdpr_licensekey', array(
			'label' => 'License Key',
			'description' => $descriptionLicense,
			'required' => true,
			'allowEmpty' => false,
			'validators' => array(
				array('NotEmpty', true),
			),
			'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('gdpr.licensekey'),
		));
		$this->getElement('gdpr_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('gdpr.pluginactivated')) {

			$this->addElement('MultiCheckbox', 'gdpr_content', array(
				'label' => 'Consents',
				'description' => 'Choose from below which all consents do you want to enable on your website? The selected consents will be visible to the users of your website in “Privacy Center” widget. You can monitor the requests for each consent in their respective sections of this plugin.',
				'multiOptions' => array('cookie' => 'Cookies & Privacy Policy Consent', 'dataProtection' => 'Contact Data Protection Officer', 'privacySettings' => 'Privacy Settings', 'requestArchive' => 'Request Archive', 'unsubscribe' => 'Unsubscribe', 'forgotMe' => 'Forget Me'),
				'value' => $settings->getSetting('gdpr_content', array('cookie', 'dataProtection', 'privacySettings', 'requestArchive', 'unsubscribe', 'forgotMe')),
			));

			$this->addElement('Select', 'gdpr_popup', array(
				'label' => 'Display Privacy Policy in Popup',
				'description' => 'Do you want to display the Privacy Policy of your website in popup until user has given consent?',
				'multiOptions' => array('1' => 'Yes', '0' => 'No'),
				'value' => $settings->getSetting('gdpr_popup', '0'),
				'onchange' => "hideShow(this.value);",
			));

			$this->addElement('Select', 'gdpr_madatory_popup', array(
				'label' => 'Make Privacy Policy Consent Mandatory',
				'description' => 'Do you want to make it mandatory for users to Agree to the Privacy policies before using your website? If you choose Yes, then until the users Agree the privacy policy, they will not be able to view and use the website as the popup will not close.',
				'multiOptions' => array('1' => 'Yes', '0' => 'No'),
				'value' => $settings->getSetting('gdpr_madatory_popup', '0'),
			));

			$this->addElement('Textarea', 'consent_bypass_cookie', array(
				'label' => 'Necessary Allowed Cookies',
				'description' => 'This box contains cookies which will be saved as necessary allowed cookies into the browsers of your users even if they have not provided any consent for the same. You can remove and add new cookies as per your requirements in this box.',
				'value' => $settings->getSetting('consent_bypass_cookie', 'en4_maint_code,user_consent,user_consent_date,PHPSESSID,en4_locale,en4_language,user_popup_consent'),
			));

			// Add submit button
			$this->addElement('Button', 'submit', array(
				'label' => 'Save Changes',
				'type' => 'submit',
				'ignore' => true
			));
		} else {
			//Add submit button
			$this->addElement('Button', 'submit', array(
					'label' => 'Activate your plugin',
					'type' => 'submit',
					'ignore' => true
			));
		}
  }
}
