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

	public function init()
	{
		$action = Zend_Controller_Front::getInstance()->getRequest()->getParams();
		if ($action['action'] == 'edit-location') {
			$this->setTitle('Edit Location')->setDescription('Choose the location.');
		} else {
			$this->setTitle('Add Location')->setDescription('Choose the location.');
			$this->setAttrib('name', 'user_add_location')->setAttrib('class', 'ignore_ajax_form');
		}

		if ($action['action'] == 'edit-location') {
			$this->addElement('Text', 'user_edit_location', array(
				'label' => 'Location',
				'required' => true,
				'allowEmpty' => false,
				'filters' => array(
					new Engine_Filter_Censor(),
					new Engine_Filter_HtmlSpecialChars(),
				),
			));
			$this->addElement(
				'Text',
				'user_lat',
				array(
					'label' => 'Latitude',
					'filters' => array(
						new Engine_Filter_Censor(),
						new Engine_Filter_HtmlSpecialChars(),
					)
				)
			);
			$this->addElement(
				'Text',
				'user_lng',
				array(
					'label' => 'Longitude',
					'filters' => array(
						new Engine_Filter_Censor(),
						new Engine_Filter_HtmlSpecialChars(),
					)
				)
			);
			$this->addElement(
				'Text',
				'user_zip',
				array(
					'label' => 'Zipcode',
					'filters' => array(
						new Engine_Filter_Censor(),
						new Engine_Filter_HtmlSpecialChars(),
					)
				)
			);
			$this->addElement(
				'Text',
				'user_city',
				array(
					'label' => 'City',
					'filters' => array(
						new Engine_Filter_Censor(),
						new Engine_Filter_HtmlSpecialChars(),
					)
				)
			);
			$this->addElement(
				'Text',
				'user_state',
				array(
					'label' => 'State',
					'filters' => array(
						new Engine_Filter_Censor(),
						new Engine_Filter_HtmlSpecialChars(),
					)
				)
			);
			$this->addElement(
				'Text',
				'user_country',
				array(
					'label' => 'Country',
					'filters' => array(
						new Engine_Filter_Censor(),
						new Engine_Filter_HtmlSpecialChars(),
					)
				)
			);

			$this->addDisplayGroup(array(
				'user_edit_location',
				'user_lat',
				'user_lng',
				'user_zip',
				'user_city',
				'user_state',
				'shortURL',
				'user_country',
			), 'input_fields', array(
				'decorators' => array(
					'FormElements',
					'DivDivDivWrapper'
				),
			));
			$this->addElement('Dummy', 'map-canvas-div', array(
				'content' => '<div id="locationSesEdit" style="height:260px;"></div>'
			));
		} else {
			$this->addElement('Text', 'user_location', array(
				'label' => 'Location',
				'filters' => array(
					new Engine_Filter_Censor(),
					new Engine_Filter_HtmlSpecialChars(),
				),
				'required' => true,
				'allowEmpty' => false,
			));
			$this->addElement('Hidden', 'user_lat', array(
				'order' => 9995,
			));
			$this->addElement('Hidden', 'user_lng', array(
				'order' => 9996,
			));
			$this->addElement('Hidden', 'user_zip', array(
				'order' => 9997,
			));
			$this->addElement('Hidden', 'user_city', array(
				'order' => 9998,
			));
			$this->addElement('Hidden', 'user_state', array(
				'order' => 9999,
			));
			$this->addElement('Hidden', 'user_country', array(
				'order' => 10000,
			));
		}
		$sunmitText = 'Save Location';
		if ($action['action'] == 'add-location') {
			$sunmitText = 'Add Location';
		}

		$this->addElement('Button', 'submit', array(
      'label' => $sunmitText,
      'type' => 'submit',
      'ignore' => true,
      'decorators' => array('ViewHelper')
    ));
		if ($action['action'] != 'edit-location') {
			$this->addElement('Cancel', 'cancel', array(
				'label' => 'Cancel',
				'link' => true,
				'prependText' => ' or ',
				'href' => '',
				'onclick' => 'javascript:ajaxsmoothboxclose();',
				'decorators' => array(
					'ViewHelper'
				)
			));
			$this->addDisplayGroup(array('submit', 'cancel'), 'buttons');
		}
	}
}
