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

class Browserpush_Form_Admin_Settings_General extends Engine_Form
{
  public function init()
  {

    $description = $this->getTranslator()->translate('These settings affect all members in your community. <br /><br /> <b>Note:</b> Please do not remove the widgets: "Web & Mobile Push Notifications" & "Prompt Display" in the <a href="admin/content?page=1"> Site Header</a> from Layout Editor of your website.');

    // Decorators
    $this->loadDefaultDecorators();
    $this->getDecorator('Description')->setOption('escape', false);

    $settings = Engine_Api::_()->getApi('settings', 'core');
    $this->setTitle('Global Settings')
      ->setDescription($description);

    $view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;

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

			$this->addElement('Radio', "browserpush_notificationpush", array(
				'label' => 'Enable Browser Notifications',
				'description' => 'Do you want to enable the website browser notification updates to be sent the subscribers of your website?',
				'allowEmpty' => false,
				'required' => true,
				'multiOptions' => array(1 => 'Yes', '0' => 'No'),
				'value' => $settings->getSetting('browserpush.notificationpush', 1),
				'onchange' => 'showHide(this.value);',
			));

			$this->addElement('Select', "browserpush_type", array(
				'label' => 'Subscription Prompt Style',
				'description' => 'Choose from below how you want to prompt your users to subscribe to push notifications on your website? (Note: Users will finally subscribe from browser\'s default pop-up, no matter what prompt style you choose. Other styles are for enhancing visibility of the prompt and encouraging visitors for subscription.)',
				'multiOptions' => array(
					'0' => 'Native Browser Prompt',
					'1' => 'Bell Prompt',
					'2' => 'Basic Popup Prompt',
					'3' => 'Custom HTML Popup Prompt',
				),
				'onchange' => 'showHideOptions(this.value);',
				'value' => $settings->getSetting('browserpush.type', 0),
			));

			$this->addElement('Text', "browserpush_title", array(
				'label' => 'Prompt Title',
				'description' => 'Enter the title for the above chosen prompt style.',
				'value' => $settings->getSetting('browserpush.title', 'Would you like to receive notifications & stay updated always?'),
			));
			$this->addElement('Textarea', "browserpush_descr", array(
				'label' => 'Prompt Description',
				'description' => 'Enter the description for the above chosen prompt style.',
				'value' => $settings->getSetting('browserpush.descr', 'Notifications can be turned off anytime from your browser settings.'),
			));

			$this->addElement('Text', 'browserpush_days', array(
				'label' => 'Browser Prompt Visibility',
				'description' => 'Enter the number of days after which you want the prompt to be visible to users once closed? [Enter "0", if you want it to be visible each time users visit your website.]',
				'value' => $settings->getSetting('browserpush.days', 5),
			));

			$this->addElement('Text', "browserpush_height", array(
				'label' => 'Custom HTML Prompt Height',
				'description' => 'Enter the height of the custom HTML popup prompt.',
				'allowEmpty' => false,
				'required' => true,
				'value' => $settings->getSetting('browserpush.height', '400'),
			));

			$this->addElement('Text', "browserpush_width", array(
				'label' => 'Custom HTML Prompt Width',
				'description' => 'Enter the width of the custom HTML popup prompt.',
				'allowEmpty' => false,
				'required' => true,
				'value' => $settings->getSetting('browserpush.width', '500'),
			));

			//New File System Code
			$logo_options = array('' => '');
			$files = Engine_Api::_()->getDbTable('files', 'core')->getFiles(array('fetchAll' => 1, 'extension' => array('gif', 'jpg', 'jpeg', 'png', 'webp')));
			foreach ($files as $file) {
				$logo_options[$file->storage_path] = $file->name;
			}
			$view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;
			$fileLink = $view->baseUrl() . '/admin/files/';

			$description = $this->getTranslator()->translate('Choose from below the image that you want to show in the above selected Prompt Style. [Note: You can add a new photo 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', 'browserpush_logo', array(
				'label' => 'Choose an Image',
				'description' => $description,
				'multiOptions' => $logo_options,
				'escape' => false,
				'value' => $settings->getSetting('browserpush.logo', ''),
			));
			$this->browserpush_logo->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false));


			$this->addElement('Select', "browserpush_percontainer", array(
				'label' => 'Display Tour Image & Text',
				'description' => 'Do you want to display the tour image & help text to your website visitors? This tour will help them easily locate the native prompt and will also increase the visibility of it thereby increase more visitors for your website.',
				'multiOptions' => array(
					'1' => 'Yes',
					'0' => 'No',
				),
				'onchange' => 'showperHide(this.value);',
				'value' => $settings->getSetting('browserpush.percontainer', 1),
			));

			$web_title = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.site.title', 'My Community');
			$des = 'Always receive notifications to stay updated on new posts & activities on your content and account on ' . $web_title . '.';

			$this->addElement('Text', "browserpush_textpercontai", array(
				'label' => 'Tour Help Text',
				'description' => 'Enter the text for the tour help. You can use this text to let your users know the benefits of subscription in brief.',
				'value' => $settings->getSetting('browserpush.textpercontai', $des),
			));

			// 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
			));
		}
  }
}
