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

class Poke_Form_Admin_Manageactions_Add extends Engine_Form {

  public function init() {

    $manageactionId = Zend_Controller_Front::getInstance()->getRequest()->getParam('manageaction_id', null);
    $manageActions = Engine_Api::_()->getItem('poke_manageaction', $manageactionId);

    $this->setTitle('Add New Action')
      ->setDescription('Below, you can add new Action to send Poke, Slap, Wink, Heart, Cake, Beer, Coffee, etc.');

    $this->addElement('Text', 'name', array(
        'label' => 'Action Name',
        'description' => 'Enter the name of the action.',
        'allowEmpty' => FALSE,
        'validators' => array(
            array('NotEmpty', true),
        )
    ));
    
    $files = Engine_Api::_()->getDbTable('files', 'core')->getFilesAssoc();
    $view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;
    $fileLink = $view->baseUrl() . '/admin/files/';
    if(engine_count($files) > 1) {
      $description = $this->getTranslator()->translate('Choose from below the action icon to send Poke, Slap, Wink, Heart, Cake, Beer, Coffee, etc of your website. [Note: You can add a action icon from the "File & Media Manager" section from here: <a href="%1$s" target="_blank">File & Media Manager.</a> Recommended Size: 16px*16px]');
      $description = vsprintf($description, array($fileLink));
        
      $this->addElement('Select', 'icon', array(
        'label' => 'Action Icon',
        'description' => $description,
        'escape' => false,
        'multiOptions' => $files,
      ));
      $this->icon->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false));
    } else {
      $description = $this->getTranslator()->translate('There are currently no images in the <a href="%1$s" target="_blank"> File & Media Manager </a> section of your site. Please begin by uploading an image to get started.');
      $description = vsprintf($description, array($fileLink));
      $description = "<div class='tip'><span>" . $description . "</span></div>";
      $this->addElement('Dummy', 'icon', array(
        'label' => "Action Icon",
        'description' => $description,
      ));
      $this->icon->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::PREPEND, 'escape' => false));
    }

    $this->addElement('Checkbox', 'enabled', array(
        'description' => 'Enable Action',
        'label' => 'Yes, enable this action.',
        'value' => 1,
    ));

    $this->addElement('Button', 'execute', array(
        'label' => 'Save Changes',
        'type' => 'submit',
        'ignore' => true,
        'decorators' => array('ViewHelper'),
    ));

    $this->addElement('Cancel', 'cancel', array(
        'label' => 'Cancel',
        'prependText' => ' or ',
        'ignore' => true,
        'link' => true,
        'href' => Zend_Controller_Front::getInstance()->getRouter()->assemble(array('action' => 'index')),
        'decorators' => array('ViewHelper'),
    ));
  }
}
