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

class Acppro_Form_Admin_Settings_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.');

    $this->addElement('Radio', 'acppro_smtp', array(
      'label' => 'Allow Admins to configure "Send through SMTP" Setting',
      'description' => 'Do you want to allow admins to configure the "Send through SMTP" setting from the Settings >> Mail Settings? If you choose No, then this setting will not show to admin member level and can be configured from super admin member level only.',
      'multiOptions' => array(
        1 => 'Yes',
        0 => 'No',
      ),
      'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('acppro.smtp', 1),
    ));

    // Element: max
    $this->addElement('Text', 'acppro_maxusers', array(
      'label' => 'Active User Count ?',
      'description' => 'Enter the active user count. The field must contain an integer between 1 and 999, or 0 for unlimited.',
      'validators' => array(
        array('Int', true),
        new Engine_Validate_AtLeast(0),
      ),
      'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('acppro.maxusers', 0),
    ));

    // Get available files
    $logoOptions = array('' => '');
    $files = Engine_Api::_()->getDbTable('files', 'core')->getFiles(array('fetchAll' => 1, 'extension' => array('gif', 'jpg', 'jpeg', 'png', 'webp', 'svg')));
    foreach ($files as $file) {
      $logoOptions[$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 logo to be displayed in the admin 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', 'acppro_admin_logo', array(
      'label' => 'Logo In Admin Header',
      'description' => $description,
      'multiOptions' => $logoOptions,
      'value' => $settings->getSetting("acppro_admin_logo", ''),
			'attribs' => array(
        'class' => 'preview-select-image'
   		),
    ));
    $this->acppro_admin_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 the admin 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', 'acppro_admin_logo', array(
      'label' => 'Logo In Admin Header',
      'description' => $description,
      'multiOptions' => $logoOptions,
      'value' => $settings->getSetting("acppro_admin_logo", ''),
			'attribs' => array(
        'class' => 'preview-select-image'
   		),
    ));
    $this->acppro_admin_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 admin 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', 'acppro_admin_logocontrast', array(
      'label' => 'Logo In Admin Header (Contrast Mode)',
      'description' => $description,
      'multiOptions' => $logoOptions,
      'value' => $settings->getSetting("acppro_admin_logocontrast", ''),
			'attribs' => array(
        'class' => 'preview-select-image'
   		),
    ));
    $this->acppro_admin_logocontrast->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false));

    $this->addElement('Radio', 'acppro_showlicense', array(
      'label' => 'Allow Admins to show license key in admin settings?',
      'description' => 'Do you want to allow admins to show the license key in the admin settings panel? If you choose No, then the license key will not be visible to admin member level.',
      'multiOptions' => array(
        1 => 'Yes',
        0 => 'No',
      ),
      'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('acppro.showlicense', 0),
    ));

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