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

class Core_Form_Admin_Mail_Emailtemplate extends Engine_Form {

  public function init() {
		
    $view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;
    $fileLink = $view->baseUrl() . '/admin/files/';

    // 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', 'svg')));
    foreach( $files as $file ) {
      $logoOptions[$file->storage_path] = $file->name;
    }

		$request = Zend_Controller_Front::getInstance()->getRequest();

		$templateId = $request->getParam('template_id', null) ? $request->getParam('template_id', null) : $request->getParam('duplicate', null);
		if($templateId)
		 $template = Engine_Api::_()->getItem('core_emailtemplate', $templateId);
		else
			$template = '';
		
	  /*------------------ Title -----------------------------*/
		$this->addElement('Text', 'title', array(
			'label' => 'Template Title',
			'allowEmpty' => false,
			'required' => true,
    ));

		$this->addElement('Text', 'mail_background_color', array(
			'label' => 'Mail Background Color',
			'description' => 'Select Email background color which you want to show in background of mail template',
			'allowEmpty' => true,
			'required' => false,
			'class' => 'SEcolor',
    ));
    $this->mail_background_color->getDecorator("Description")->setOption("placement", "prepend");  
    
		$this->addElement('Text', 'mail_padding_topbottom', array(
			'label' => 'Mail Padding from Top-Bottom',
			'description' => 'Enter the padding in px',
			'allowEmpty' => true,
			'required' => false,
    ));
    $this->mail_padding_topbottom->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Text', 'mail_padding_rightleft', array(
			'label' => 'Mail Padding from Left-Right',
			'description' => 'Enter the padding in px',
			'allowEmpty' => true,
			'required' => false,
    ));
    $this->mail_padding_rightleft->getDecorator("Description")->setOption("placement", "prepend"); 

    $this->addDisplayGroup(array('mail_background_color', 'mail_padding_topbottom','mail_padding_rightleft'), 'features_content', array('disableLoadDefaultDecorators' => true, 'legend' => 'General'));
    $features_content = $this->getDisplayGroup('features_content');
    $features_content->setDecorators(array('FormElements', 'Fieldset', array('HtmlTag', array('tag' => 'div', 'id' => 'features_content'))));
    
	  /*------------------ Header -----------------------------*/
		$this->addElement('hidden', 'is_active', array(
			'value'=>'0',
    ));

    $description = $this->getTranslator()->translate('Choose from below the logo to be displayed in the email header. [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', 'header_logo', array(
      'label' => 'Logo',
      'description' => $description,
      'multiOptions' => $logoOptions,
			'attribs' => array(
        'class' => 'preview-select-image'
   		),
    ));  
    $this->header_logo->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false));

		$this->addElement('Select', 'header_logo_align', array(
			'label' => 'Logo Alignment',
			'description'=>'Choose Alignment of logo. logo alignment center applicable for "Show Email & Phone" setting Selected as "NO" ',
			'allowEmpty' => true,
			'required' => false,
			'multiOptions'=> array(
				'1'=>'Left',
				'2'=>'Center',
				'3'=>'Right',
			),
			'value'=>'1',
    ));
    $this->header_logo_align->getDecorator("Description")->setOption("placement", "prepend");     
		
		$this->addElement('Select', 'header_emailphone_show', array(
			'label' => 'Show Email & Phone',
			'description'=>'Do you want to show Email and Phone in Header.',
			'allowEmpty' => true,
			'required' => false,
			'onchange' => 'showemail(this.value)',
			'multiOptions'=> array(
				'1'=>'Yes',
				'0'=>'No',
			),
			'value'=>'1',
    ));
    $this->header_emailphone_show->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Select', 'footer_social_icons_type', array(
			'label' => 'Icons Type',
			'description' => 'Choose the type of Icons which you want to show in this template.',
			'multiOptions' => array(
				'0'=>'Dark icon',
				'1'=> 'Light icon',
			),
			'value' => '0',
    ));
    $this->footer_social_icons_type->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Text', 'header_mail', array(
			'label' => 'Email',
			'description'=>'Enter Email Id which you want to show in Email Template\'s header.',
    ));
    $this->header_mail->getDecorator("Description")->setOption("placement", "prepend");     

		$this->addElement('Text', 'header_phone', array(
			'label' => 'Phone Number',
			'description'=>'Enter Phone Number which you want to show in Email Template\'s header.',
    ));
    $this->header_phone->getDecorator("Description")->setOption("placement", "prepend");        

		$this->addElement('Select', 'header_emailphone_align', array(
			'label' => 'Email & Phone Alignment',
			'description'=>'Choose alignment of Email & Phone Number in Header.',
			'allowEmpty' => true,
			'required' => false,
			'multiOptions'=> array(
				'1' => 'Left',
				'2' => 'Right',
			),
			'value'=>'2',
    ));
    $this->header_emailphone_align->getDecorator("Description")->setOption("placement", "prepend");       
		
		$this->addElement('Text', 'header_background_color', array(
			'label' => 'Background Color',
			'description' => 'Choose Background color of Header',
			'class' => 'SEcolor',
    ));
    $this->header_background_color->getDecorator("Description")->setOption("placement", "prepend");       

		$this->addElement('Text', 'font_color_textemailphone', array(
			'label' => 'Font color',
			'description'=>'Choose the text font color for Email and phone \'s.',
			'class' => 'SEcolor',
    ));
    $this->font_color_textemailphone->getDecorator("Description")->setOption("placement", "prepend");   		

		$this->addElement('Text', 'header_border_Width', array(
			'label' => 'Border Width',
			'description' => 'Enter border width in px.',
			'value' => '1',
    ));
    $this->header_border_Width->getDecorator("Description")->setOption("placement", "prepend");     

		$this->addElement('Text', 'header_border_color', array(
			'label' => 'Border Color',
			'class' => 'SEcolor',
			'description'=>'Choose border color.',
    ));
    $this->header_border_color->getDecorator("Description")->setOption("placement", "prepend");     

		$this->addElement('Select', 'header_border_style', array(
			'label' => 'Border Style',
			'description'=>'Choose border style.',
			'multioptions'=>array(
			'none'=>'none',
			'hidden'=>'hidden',
			'dotted'=>'dotted',
			'dashed'=>'dashed',
			'solid'=>'solid',
			'double'=>'double',
			'groove'=>'groove',
			'ridge'=>'ridge',
			'inset'=>'inset',
			'outset'=>'outset',
			'initial'=>'initial',
			'inherit'=>'inherit',
			),
			'value'=>'solid',
    ));
    $this->header_border_style->getDecorator("Description")->setOption("placement", "prepend"); 
    
		$this->addElement('Text', 'header_padding', array(
			'label' => 'Padding',
			'description' => 'Enter Padding in px.',
			'value' => '1',
    ));
    $this->header_padding->getDecorator("Description")->setOption("placement", "prepend"); 
    
		$this->addDisplayGroup(array('header_logo', 'header_logo_align', 'header_emailphone_show','footer_social_icons_type', 'header_mail', 'header_phone', 'header_emailphone_align', 'header_background_color', 'header_background_color', 'font_color_textemailphone', 'header_border_Width', 'header_border_color', 'header_border_style', 'header_padding'), 'column_header', array('disableLoadDefaultDecorators' => true, 'legend' => 'Header'));
    $column_header = $this->getDisplayGroup('column_header');
    $column_header->setDecorators(array('FormElements', 'Fieldset', array('HtmlTag', array('tag' => 'div', 'id' => 'column_header'))));

	  /*------------------ Tagline -----------------------------*/
		$this->addElement('Select', 'tagline_position', array(
			'label' => 'Tagline Position',
			'description'=>'Choose Tagline Position.',
			'allowEmpty' => true,
			'required' => false,
			'multiOptions'=> array(
				'1' => 'Above Header',
				'2' => 'Below Header',
			),
			'value'=>'1',
    ));
    $this->tagline_position->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Text', 'tagline_content', array(
			'label' => 'Tagline Content',
			'description'=>'Enter Content for Tagline.',
			'allowEmpty' => true,
			'required' => false,
    ));
    $this->tagline_content->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Text', 'tagline_font_color', array(
			'label' => 'Tagline Font Color',
			'description'=>'Choose Font color for Tagline.',
			'allowEmpty' => true,
			'required' => false,
			'class' => 'SEcolor',
    ));
    $this->tagline_font_color->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Text', 'tagline_background_color', array(
			'label' => 'Background Color',
			'description' => 'Choose Background color of Tagline',
			'class' => 'SEcolor',
    ));
    $this->tagline_background_color->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Text', 'tagline_border_Width', array(
			'label' => 'Border Width',
			'description' => 'Enter Border width in px.',
			'value' => '1',
    ));
    $this->tagline_border_Width->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Text', 'tagline_border_color', array(
			'label' => 'Border Color',
			'class' => 'SEcolor',
			'description'=>'Choose border color.',
    ));
    $this->tagline_border_color->getDecorator("Description")->setOption("placement", "prepend"); 

		$this->addElement('Select', 'tagline_border_style', array(
			'label' => 'Border Style',
			'description'=>'Choose Border style.',
			'multioptions'=>array(
			'none'=>'none',
			'hidden'=>'hidden',
			'dotted'=>'dotted',
			'dashed'=>'dashed',
			'solid'=>'solid',
			'double'=>'double',
			'groove'=>'groove',
			'ridge'=>'ridge',
			'inset'=>'inset',
			'outset'=>'outset',
			'initial'=>'initial',
			'inherit'=>'inherit',
			),
			'value'=>'solid',
    ));
    $this->tagline_border_style->getDecorator("Description")->setOption("placement", "prepend"); 


		$this->addElement('Select', 'tagline_text_alignment', array(
			'label' => 'Text Alignment',
			'description' => 'Choose Text Alignment.',
			'allowEmpty' => true,
			'required' => false,
			'multiOptions'=> array(
				'1'=>'Left',
				'2'=>'Center',
				'3'=>'Right',
			),
			'value'=>'2',
    ));
    $this->tagline_text_alignment->getDecorator("Description")->setOption("placement", "prepend");
    
		$this->addElement('Text', 'tagline_padding', array(
			'label' => 'Padding',
			'description' => 'Enter Padding in px.',
			'value' => '1',
    ));
    $this->tagline_padding->getDecorator("Description")->setOption("placement", "prepend");

    $this->addDisplayGroup(array('tagline_position', 'tagline_content', 'tagline_font_color','tagline_background_color', 'tagline_border_Width', 'tagline_border_color', 'tagline_border_style', 'tagline_text_alignment', 'tagline_padding'), 'column_tagline', array('disableLoadDefaultDecorators' => true, 'legend' => 'Tagline'));
    $column_tagline = $this->getDisplayGroup('column_tagline');
    $column_tagline->setDecorators(array('FormElements', 'Fieldset', array('HtmlTag', array('tag' => 'div', 'id' => 'column_tagline'))));
		
	  /*------------------ Body -----------------------------*/
		$this->addElement('Text', 'body_background_color', array(
			'label' => 'Background Color',
			'description' => 'Choose Background color of Body',
			'class' => 'SEcolor',
    ));
    $this->body_background_color->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Text', 'body_text_color', array(
			'label' => 'Body Text Color',
			'description' => 'Choose text color of Body',
			'value' => '000000',
			'class' => 'SEcolor',
    ));
    $this->body_text_color->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Text', 'body_border_Width', array(
			'label' => 'Border Width',
			'description' => 'Enter Border width in px.',
			'value' => '1',
    ));
    $this->body_border_Width->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Text', 'body_border_color', array(
			'label' => 'Border Color',
			'class' => 'SEcolor',
			'description'=>'Choose Border color.',
    ));
    $this->body_border_color->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Select', 'body_border_style', array(
			'label' => 'Border Style',
			'description'=>'Choose Border style.',
			'multioptions'=>array(
			'none'=>'none',
			'hidden'=>'hidden',
			'dotted'=>'dotted',
			'dashed'=>'dashed',
			'solid'=>'solid',
			'double'=>'double',
			'groove'=>'groove',
			'ridge'=>'ridge',
			'inset'=>'inset',
			'outset'=>'outset',
			'initial'=>'initial',
			'inherit'=>'inherit',
			),
			'value'=>'solid',
    ));
    $this->body_border_style->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Text', 'body_padding', array(
			'label' => 'Padding',
			'description' => 'Enter Padding in px.',
			'value' => '1',
    ));
    $this->body_padding->getDecorator("Description")->setOption("placement", "prepend");

		$this->addDisplayGroup(array('body_background_color', 'body_text_color', 'body_border_Width','body_border_color', 'body_border_style', 'body_padding'), 'column_body', array('disableLoadDefaultDecorators' => true, 'legend' => 'Body'));
    $column_body = $this->getDisplayGroup('column_body');
    $column_body->setDecorators(array('FormElements', 'Fieldset', array('HtmlTag', array('tag' => 'div', 'id' => 'column_body'))));

  	/*------------------ Footer -----------------------------*/
		$this->addElement('Select', 'footer_social_icons', array(
			'label' => 'Social Icons',
			'description'=>'Do you want to show Social Icons in Footer.',
			'multioptions'=>array(
				'1'=>'Yes',
				'0'=>'No',
			),
			'value' => 1,
    ));
    $this->footer_social_icons->getDecorator("Description")->setOption("placement", "prepend");
    
		$this->addElement('Text', 'footer_background_color', array(
			'label' => 'Background Color',
			'description' => 'Choose Background color of Footer',
			'class' => 'SEcolor',
    ));
    $this->footer_background_color->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Text', 'footer_border_Width', array(
			'label' => 'Border Width',
			'description' => 'Enter Border width in px.',
			'value' => '1',
    ));
    $this->footer_border_Width->getDecorator("Description")->setOption("placement", "prepend");
    
		$this->addElement('Text', 'footer_border_color', array(
			'label' => 'Border Color',
			'class' => 'SEcolor',
			'description'=>'Choose Border color.',
    ));
    $this->footer_border_color->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Select', 'footer_border_style', array(
			'label' => 'Border Style',
			'description'=>'Choose Border style.',
			'multioptions'=>array(
			'none'=>'none',
			'hidden'=>'hidden',
			'dotted'=>'dotted',
			'dashed'=>'dashed',
			'solid'=>'solid',
			'double'=>'double',
			'groove'=>'groove',
			'ridge'=>'ridge',
			'inset'=>'inset',
			'outset'=>'outset',
			'initial'=>'initial',
			'inherit'=>'inherit',
			),
			'value'=>'solid',
    ));
    $this->footer_border_style->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Select', 'footer_text_alignment', array(
			'label' => 'Text Alignment',
			'description' => 'Choose Text Alignment.',
			'allowEmpty' => true,
			'required' => false,
			'multiOptions'=> array(
				'1'=>'Left',
				'2'=>'Center',
				'3'=>'Right',
			),
			'value'=>'2',
    ));
    $this->footer_text_alignment->getDecorator("Description")->setOption("placement", "prepend");

		$this->addElement('Text', 'footer_padding', array(
			'label' => 'Padding',
			'description' => 'Enter Padding in px.',
			'value' => '1',
    ));
     $this->footer_padding->getDecorator("Description")->setOption("placement", "prepend");   

    $this->addDisplayGroup(array('footer_social_icons', 'footer_background_color', 'footer_border_Width','footer_border_color', 'footer_border_style', 'footer_text_alignment', 'footer_padding'), 'column_footer', array('disableLoadDefaultDecorators' => true, 'legend' => 'Footer'));
    $column_footer = $this->getDisplayGroup('column_footer');
    $column_footer->setDecorators(array('FormElements', 'Fieldset', array('HtmlTag', array('tag' => 'div', 'id' => 'column_footer'))));
		
		$this->addElement('Checkbox', 'activate_thistemplate', array(
			'label' => 'Yes, activate this email template for all outgoing emails.(Note: At any time only one template can be activated. Thus, if you activate this template, then the current activated template will be deactivated.',
			'description' => 'Activate This Template for All Emails',
			'value' => '0',
			'allowEmpty' => true,
			'required' => false,
    ));
		$this->addElement('Checkbox', 'test_email_check', array(
			'label' => 'Send me a test email.',
			'description' => 'Test Email',
			'allowEmpty' => true,
			'required' => false,
			'onchange'=>'emailinput(this)',
    ));
		$this->addElement('Text', 'test_email', array(
			'label' => 'Email ID for Testing',
			'allowEmpty' => true,
			'required' => false,
    ));
		// Buttons
		$this->addElement('Button', 'save', array(
				'label' => 'Save',
				'type' => 'submit',
				'ignore' => true,
				'decorators' => array('ViewHelper')
		));
		$this->addElement('Button', 'submit', array(
				'label' => 'Save & Exit',
				'type' => 'submit',
				'ignore' => true,
				'decorators' => array('ViewHelper')
		));
		$this->addElement('Cancel', 'cancel', array(
				'label' => 'Cancel',
				'link' => true,
				'prependText' => ' or ',
				'href' => Zend_Controller_Front::getInstance()->getRouter()->assemble(array('action' => 'manage')),
				'onClick' => 'javascript:parent.Smoothbox.close();',
				'decorators' => array('ViewHelper')
		));
		$this->addDisplayGroup(array('save', 'submit', 'cancel'), 'buttons');
    
  }
}
