<?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_Menu_ItemCreate extends Engine_Form
{
  public function init()
  {
    
    $view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;
    $this
      ->setTitle('Create Menu Item')
      ->setAttrib('class', 'global_form_popup');

    $this->addElement('Text', 'label', array(
      'label' => 'Label',
      'required' => true,
      'allowEmpty' => false,
    ));

		$menuname = Zend_Controller_Front::getInstance()->getRequest()->getParam('menuname', 'core_main');
		
		if(engine_in_array($menuname, array('core_main', 'core_footer', 'user_settings', 'core_helpsupport_mobile'))) {

			if(Engine_Api::_()->getDbtable('modules', 'core')->isModuleEnabled('pulse')) {
				$this->addElement('Textarea', 'description', array(
					'label' => 'Description',
					'required' => false,
					'allowEmpty' => true,
					'maxlength' => '255',
				));
			}

			$this->addElement('File', 'photo', array(
      	'label' => 'Image of this menu item (Note: Currently, this image is supported in the Pulse theme and Mobile Apps only.)',
				'allowEmpty' => true,
				'required' => false,
				'onchange' => 'showReadImage(this,"menu_icon_preview")',
      	'accept'=>"image/*",
			));
			$this->photo->addValidator('Extension', false, 'jpg,png,gif,jpeg,JPG,PNG,GIF,JPEG');

			$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id', null);
			$menuItem = Engine_Api::_()->getItem('core_menuItem', $id);
			if ($id && $menuItem && $menuItem->file_id) {
				$img_path = Engine_Api::_()->storage()->get($menuItem->file_id, '')->getPhotoUrl();
				if (isset($img_path) && !empty($img_path)) {
					$this->addElement('Image', 'menu_icon_preview', array(
							'label' => 'Menu Image Preview',
							'src' => $img_path,
							'width' => 100,
							'height' => 100,
					));

					$this->addElement('Checkbox', 'remove_menu_icon', array(
          	'label' => 'Remove Menu Image'
          ));
				}
			} else {
				$this->addElement('Image', 'menu_icon_preview', array(
						'label' => 'Menu Image Preview',
						'width' => 100,
						'height' => 100,
						'disable' => true
				));
			}
		}

    $this->addElement('Text', 'uri', array(
      'label' => 'URL (Note: If you do not want to give any URL for this, then enter javascript:void(0) below.)',
      'required' => true,
      'allowEmpty' => false,
      'style' => 'width: 300px',
      //'validators' => array(
      //  array('NotEmpty', true),
      //)
    ));

    $iconLabel = sprintf('More info: %s','<a href="https://community.socialengine.com/blogs/597/69/enabling-vertical-menus" target="_blank">See KB article</a>');
    $this->addElement('Text', 'icon', array(
      'label' => 'Icon / Icon Class (Note: Not all menus support icons.) '.$iconLabel,
      'style' => 'width: 500px',
    ));
    $this->getElement('icon')->getDecorator('Label')->setOptions(array('placement' => 'PREPEND', 'escape' => false));

    $this->addElement('Checkbox', 'target', array(
      'label' => 'Open in a new window?',
      'checkedValue' => '_blank',
      'uncheckedValue' => '',
    ));

    $this->addElement('Checkbox', 'enabled', array(
      'label' => 'Enabled?',
      'checkedValue' => '1',
      'uncheckedValue' => '0',
      'value' => '1',
    ));

    // Buttons
    $this->addElement('Button', 'submit', array(
      'label' => 'Create Menu Item',
      'type' => 'submit',
      'ignore' => true,
      'decorators' => array('ViewHelper')
    ));

    $this->addElement('Cancel', 'cancel', array(
      'label' => 'cancel',
      'link' => true,
      'prependText' => ' or ',
      'href' => '',
      'onclick' => 'parent.Smoothbox.close();',
      'decorators' => array(
        'ViewHelper'
      )
    ));
    
    $this->addDisplayGroup(array('submit', 'cancel'), 'buttons');
  }
}
