Exemple #1
0
 /**
  * Hook for node form, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     $content_type = Zoo::getService('content')->getType($item->type);
     if ($content_type->has_parent_url == 0) {
         $path = new Zend_Form_Element_Text('rewrite_path', array('size' => 65));
         $path->setLabel('URL');
         $form->addElement($path);
         $options = array('legend' => Zoo::_("URL Rewriting"));
         $form->addDisplayGroup(array('rewrite_path'), 'rewrite_path_options', $options);
         if ($item->id > 0) {
             $factory = new Rewrite_Path_Factory();
             $path = $factory->find($item->id)->current();
             if ($path) {
                 $form->populate(array('rewrite_path' => $path->path));
             } else {
                 // Find parent's path
                 if ($item->pid && ($path = $factory->find($item->pid)->current())) {
                     $form->populate(array('rewrite_path' => $path->path . "/" . $item->id));
                 } else {
                     $form->populate(array('rewrite_path' => $item->url()));
                 }
             }
         }
     }
 }
 public function ajouterAction()
 {
     $form = new Zend_Form();
     $form->setMethod('post');
     $form->addElement('text', 'TITRE_E', array('label' => 'Titre de l\'émission : ', 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'THEME', array('label' => 'Theme : ', 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'ANIMATEURS', array('label' => 'Animateur(s) : ', 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'DUREE', array('label' => 'Durée de l\'émission : ', 'required' => true, 'filters' => array('Int')));
     $form->addElement('text', 'PATH_E', array('label' => 'Lien vers le podcast : ', 'required' => false, 'filters' => array('StringTrim')));
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel('Ajouter');
     $form->addElement($submit);
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $dba = Zend_Registry::get('dba');
             $datas = array('THEME' => $formData["THEME"], 'ANIMATEURS' => $formData["ANIMATEURS"], 'DUREE' => $formData["DUREE"], 'TITRE_E' => $formData["TITRE_E"], 'PATH_E' => $formData["PATH_E"]);
             $dba->beginTransaction();
             try {
                 $dba->insert('EMISSION', $datas);
                 $dba->commit();
             } catch (Exception $e) {
                 $dba->rollBack();
                 echo $e->getMessage();
             }
             $this->_helper->redirector('index');
         } else {
             $form->populate($formData);
         }
     }
     $this->view->form = $form;
 }
 /**
  * Create the setting form and populate with the custom setting values
  * 
  * @param integer $groupid
  */
 public static function createForm($groupid)
 {
     $form = new Zend_Form(array('action' => '/admin/settings/index/groupid/' . $groupid, 'method' => 'post'));
     $form->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator');
     $records = Doctrine_Query::create()->from('SettingsParameters s')->where('group_id = ?', $groupid)->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     if (!empty($records)) {
         foreach ($records as $record) {
             // Custom style added to the textareas
             $style = $record['type'] == "textarea" ? array('rows' => 4) : array();
             $form->addElement($record['type'], $record['var'], $style + array('decorators' => array('Bootstrap'), 'filters' => array('StringTrim'), 'label' => $record['name'], 'description' => $record['description'], 'class' => 'form-control obj_' . $record['var']));
             if (!empty($record['config'])) {
                 $config = json_decode($record['config'], true);
                 if (!empty($config['class']) && class_exists($config['class']) && !empty($config['method']) && method_exists($config['class'], $config['method'])) {
                     $class = $config['class'];
                     $method = $config['method'];
                     $data = call_user_func(array($class, $method));
                     if (!empty($data)) {
                         if ($record['type'] == "select") {
                             $form->getElement($record['var'])->setMultiOptions($data);
                         } else {
                             $form->getElement($record['var'])->setValue($data);
                         }
                     }
                 }
             }
         }
     }
     $settings = self::getValues(Settings::find_by_GroupId($groupid));
     $form->populate($settings);
     return $form;
 }
Exemple #4
0
 public function populateFromModel($id)
 {
     $row = $this->_model->find($id)->current();
     if ($row) {
         parent::populate($row->toArray());
     }
 }
 public function editAction()
 {
     $configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
     $userForm = new Zend_Form($configForm->user);
     $userId = $this->getRequest()->getParam('id', null);
     if ($this->getRequest()->isPost()) {
         if ($userForm->isValid($_POST)) {
             try {
                 $values = $userForm->getValues();
                 unset($values['password_repeat']);
                 $userId = $this->userRepository->saveEntity($values);
                 $this->_helper->systemMessages('notice', 'Nutzer erfolgreich gespeichert');
             } catch (\Exception $e) {
                 $log = $this->getInvokeArg('bootstrap')->log;
                 $log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
                 $this->_helper->systemMessages('error', 'Nutzer konnte nicht gespeichert werden');
             }
         }
     } else {
         try {
             $entity = $this->userRepository->fetchEntity($userId);
             $userForm->populate($entity->toArray());
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), 404);
         }
     }
     $userForm->setAction('/admin/user/edit/' . $userId);
     $this->view->form = $userForm;
 }
Exemple #6
0
 /**
  * Hook for node form - if type is Guestbook Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     if ($item->type == "guestbook_entry") {
         // Add guestbook fields
         $name = new Zend_Form_Element_Text('guestbook_name', array('size' => 35));
         $name->setLabel('Name');
         $name->setRequired(true);
         $email = new Zend_Form_Element_Text('guestbook_email', array('size' => 35));
         $email->setLabel('Email');
         $email->setRequired(true)->addValidator(new Zend_Validate_StringLength(6))->addValidator(new Zend_Validate_EmailAddress());
         $url = new Zend_Form_Element_Text('guestbook_homepage', array('size' => 35));
         $url->setLabel('Homepage');
         $url->setRequired(false)->addValidator(new Zend_Validate_StringLength(4))->addValidator(new Zend_Validate_Hostname());
         $form->addElements(array($name, $email, $url));
         $options = array('legend' => Zoo::_("Guest information"));
         $form->addDisplayGroup(array('guestbook_name', 'guestbook_email', 'guestbook_homepage'), 'guestbook_add', $options);
         if ($item->id > 0) {
             // Fetch guestbook object
             $factory = new Guestbook_Node_Factory();
             $guestbook = $factory->find($item->id)->current();
             if (!$guestbook) {
                 $guestbook = $factory->createRow();
             }
             $values = $guestbook->toArray();
             $populate = array();
             foreach ($values as $key => $value) {
                 $populate['guestbook_' . $key] = $value;
             }
             $form->populate($populate);
         }
     }
 }
 public function populate(array $dados)
 {
     $this->getElement('Cadastrar')->setName('Editar');
     if (isset($dados['preco']) && $dados['preco']) {
         $dados['preco'] = number_format($dados['preco'], 2, ',', '.');
         $dados['preco'] = str_replace('.', '', $dados['preco']);
     }
     return parent::populate($dados);
 }
 private function saveComment(Zend_Form $form, GC\Entity\BlogEntry $blogEntry)
 {
     $comment = new GC\Entity\Comment($form->getValues());
     $comment->blogEntry = $blogEntry;
     $this->_em->persist($comment);
     $this->_em->flush();
     // clear form values
     $form->populate(array('name' => '', 'email' => '', 'content' => ''));
 }
Exemple #9
0
 public function testPopulateProxiesToSetDefaults()
 {
     $this->testCanAddAndRetrieveMultipleElements();
     $values = array('foo' => 'foovalue', 'bar' => 'barvalue', 'baz' => 'bazvalue', 'bat' => 'batvalue');
     $this->form->populate($values);
     $test = $this->form->getValues();
     $elements = $this->form->getElements();
     foreach (array_keys($values) as $name) {
         $this->assertEquals($values[$name], $test[$name]);
     }
 }
 public function indexAction()
 {
     $session = new \Zend_Session_Namespace('twitter', true);
     $oauthConfig = array('callbackUrl' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], 'siteUrl' => 'http://twitter.com/oauth');
     $configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
     $twitterApiForm = new \Zend_Form($configForm->twitterApi);
     if ($this->getRequest()->isPost()) {
         if ($twitterApiForm->isValid($_POST)) {
             try {
                 $this->twitterRepository->saveEntity($twitterApiForm->getValues());
                 $oauthConfig['consumerKey'] = $twitterApiForm->getValue('consumerKey');
                 $oauthConfig['consumerSecret'] = $twitterApiForm->getValue('consumerSecret');
                 $consumer = new \Zend_Oauth_Consumer($oauthConfig);
                 $token = $consumer->getRequestToken();
                 $session->twitterRequestToken = serialize($token);
                 $consumer->redirect();
             } catch (\Exception $e) {
                 $log = $this->getInvokeArg('bootstrap')->log;
                 $log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
                 $this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
             }
         }
     } else {
         try {
             $entity = $this->twitterRepository->fetchEntity();
             if ($entity) {
                 if (isset($session->twitterRequestToken)) {
                     $oauthConfig['consumerKey'] = $entity->consumerKey;
                     $oauthConfig['consumerSecret'] = $entity->consumerSecret;
                     $consumer = new \Zend_Oauth_Consumer($oauthConfig);
                     $token = $consumer->getAccessToken($_GET, unserialize($session->twitterRequestToken));
                     $this->twitterRepository->saveEntity(array('accessToken' => serialize($token)));
                     unset($session->twitterRequestToken);
                     $this->_helper->systemMessages('notice', 'Einstellungen erfolgreich gespeichert');
                 }
                 $twitterApiForm->populate($entity->toArray());
             }
         } catch (\Exception $e) {
             $log = $this->getInvokeArg('bootstrap')->log;
             $log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
             $this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
         }
     }
     $twitterApiForm->setAction('/admin/twitter');
     $this->view->form = $twitterApiForm;
 }
Exemple #11
0
 /**
  * Hook for node form - if type is Estate Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     $title = new Zend_Form_Element_Text('title', array('class' => 'content_title'));
     $title->setLabel('Title');
     $title->setRequired(true)->addValidator(new Zend_Validate_StringLength(2, 255));
     $content = new Zoo_Form_Element_Wysiwyg('content');
     $content->setRequired(false)->setLabel('Content')->setAttrib('cols', 50);
     $form->addElements(array($title, $content));
     $form->addDisplayGroup(array('title', 'content'), 'content_add', array('legend' => Zoo::_('Content')));
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $identity = Zend_Auth::getInstance()->getIdentity();
         $uid = $identity->id;
     } else {
         $uid = 0;
     }
     $filters = Zoo::getService('filter')->getFiltersByUser($uid);
     if ($filters && $filters->count() > 0) {
         foreach ($filters as $filter) {
             $options = array();
             if (!$filter->optional) {
                 $options = array('disabled' => 'disabled', 'value' => 1);
             } elseif ($item->id == 0) {
                 $options['value'] = $filter->default;
             }
             $ele = new Zend_Form_Element_Checkbox("filter_" . $filter->name, $options);
             $ele->setLabel($filter->name);
             $form->addElement($ele);
             $elements[] = "filter_" . $filter->name;
             $userfilters[$filter->id] = $filter;
         }
         $options = array('legend' => Zoo::_("Filters"));
         $form->addDisplayGroup($elements, 'filter_set', $options);
         if ($item->id > 0) {
             // Fetch set filters
             $filters = Zoo::getService('content')->getFilters($item);
             $populate = array();
             foreach ($filters as $filter) {
                 $populate['filter_' . $userfilters[$filter->filter_id]->name] = 1;
             }
             $form->populate($populate);
         }
     }
 }
 public function indexAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $this->_redirect("/accueil");
         //  echo "identity remove";
         // $auth->clearIdentity();
     }
     $this->view->menu = "index";
     $form = new Zend_Form();
     $form->setMethod('post');
     $form->addElement('text', 'LOGIN', array('label' => 'Login : '******'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('password', 'PASSWORD', array('label' => 'Password : '******'required' => true, 'filters' => array('StringTrim')));
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel('Se Connecter')->setAttrib('class', 'valid_button gros-bouton');
     $form->addElement($submit);
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             MyAcl::setCache(Zend_Cache::factory("Core", "File"));
             $acl = MyAcl::getInstance();
             Acl_Db_Table_Row::setAcl($acl);
             $dba = Zend_Registry::get('dba');
             $TMembres = new Application_Model_Membre($dba);
             $membre = $TMembres->createRow();
             $membre->LOGIN = $formData["LOGIN"];
             // ceci pourrait provenir d'un formulaire
             $membre->PASSWORD = $formData["PASSWORD"];
             // ceci pourrait provenir d'un formulaire
             $result = $membre->authenticate();
             // si OK : persistance 30min en session
             if (!$result->isValid()) {
                 echo 'login ou mot de passe incorrect';
             } else {
                 echo "ok";
                 $this->_redirect("/accueil");
             }
         } else {
             $form->populate($formData);
         }
     }
     $this->view->form = $form;
 }
 /**
  * Initiate system installation
  *
  */
 public function indexAction()
 {
     $settingsform = new Zoo_Form_Settings();
     $modulesform = new Zoo_Form_Modules();
     $form = new Zend_Form(array('name' => 'installForm'));
     $form->setSubFormDecorators(array('FormElements', 'Fieldset'));
     $form->addSubForm($settingsform, 'settings');
     $form->addSubForm($modulesform, 'modules');
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($settingsform->isValid($formData)) {
             //                $this->_forward('install');
         }
         $form->populate($formData);
     }
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel('Install');
     $form->addElements(array($submit));
     $this->view->form = $form;
 }
 public function indexAction()
 {
     $configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
     $deliciousApiForm = new \Zend_Form($configForm->deliciousApi);
     if ($this->getRequest()->isPost()) {
         if ($deliciousApiForm->isValid($_POST)) {
             try {
                 $this->deliciousRepository->saveEntity($deliciousApiForm->getValues());
                 $this->_helper->systemMessages('notice', 'Einstellungen erfolgreich gespeichert');
             } catch (\Exception $e) {
                 $log = $this->getInvokeArg('bootstrap')->log;
                 $log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
                 $this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
             }
         }
     } else {
         $entity = $this->deliciousRepository->fetchEntity();
         if ($entity) {
             $deliciousApiForm->populate($entity->toArray());
         }
     }
     $deliciousApiForm->setAction('/admin/delicious');
     $this->view->form = $deliciousApiForm;
 }
 /**
  * Hook for setting the data on the form.
  */
 protected function populateForm()
 {
     $this->_form->populate($this->formData);
 }
Exemple #16
0
 public function populate(array $values)
 {
     $values['temp_name'] = str_replace('_', ' ', $values['name']);
     return parent::populate($values);
 }
Exemple #17
0
 /**
  * Populate form
  *
  * Proxies to {@link setDefaults()}
  *
  * @param  array $values
  * @return Zend_Form
  */
 public function populate(array $values)
 {
     Centurion_Signal::factory('pre_populate')->send($this, array($values));
     return parent::populate($values);
 }
 /**
  * Helper function to populate the zend form elements with database data
  *
  * @param Zend_Form $pageForm form definition for this step
  * @param int $stepNum current step number
  *
  * @return void
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     // Check to see if the user is trying to skip ahead in the quote
     $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
     $tooFarAhead = false;
     if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) {
         $tooFarAhead = true;
         $lastCompleted = 1;
     } elseif ($stepNum > 1) {
         // Check to see if any pages previous to the one the user's trying to get to are incomplete
         $tooFarAhead = false;
         for ($i = 1; $i < $stepNum; $i++) {
             if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) {
                 $tooFarAhead = true;
                 $lastCompleted = $i;
                 break;
             }
         }
     }
     if ($tooFarAhead) {
         // Drop user onto page that needs completing
         $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/step' . $lastCompleted);
         return false;
     }
     if ($stepNum > 1) {
         // Before we do ANYTHING we need to check to see if the email address entered matches a customer record
         // we already have - if it does we need to ask them to login before they proceed.
         $customerReferenceNumber = $this->_customerReferenceNumber;
         $customerManager = new Manager_Core_Customer();
         $legacyCustomer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerReferenceNumber);
         $emailAddress = $legacyCustomer->getEmailAddress();
         $customer = $customerManager->getCustomerByEmailAddress($emailAddress);
         if ($customer) {
             // There is already a customer entry for this email address - so we need to see if they are logged in
             // if not we need to force them to login
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             if ($auth->hasIdentity()) {
                 $loggedInEmail = $auth->getStorage()->read()->email_address;
                 if ($loggedInEmail != $customer->getEmailAddress()) {
                     // They are logged in but not who they should be to do this quote
                     $this->_helper->redirector->gotoUrl('/account/login?refer=landlords-insurance&step=' . $stepNum);
                     return false;
                 }
             } else {
                 // TODO: Check that removing the login redirection will not break other processes
                 // They aren't logged in and need to
                 /*$this->_helper->redirector->gotoUrl('/account/login?refer=landlords-insurance&step='. $stepNum);
                 		return false;*/
             }
         }
     }
     $formData = array();
     // If step 1 and not in session (so producing a quick quote) - we need to pre-populate
     // a few bits if the customer is already logged into the site
     if ($stepNum == 1 && !isset($pageSession->CustomerRefNo)) {
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
         if ($auth->hasIdentity()) {
             // Customer is logged in and starting a new quote - so we need to pre-populate the customers details from stored details
             $customerID = $auth->getStorage()->read()->id;
             $customerManager = new Manager_Core_Customer();
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             $formData['title'] = $customer->getTitle();
             $formData['first_name'] = $customer->getFirstName();
             $formData['last_name'] = $customer->getLastName();
             $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
             $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
             $formData['email_address'] = $customer->getEmailAddress();
             $formData['date_of_birth_at'] = $customer->getDateOfBirthAt();
             $pageForm->populate($formData);
         }
     }
     if (isset($this->_quoteID) && $this->_quoteID > 0) {
         $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($this->_quoteID);
         $premiums = $quoteManager->calculatePremiums();
         if ($premiums != '') {
             $this->view->premiums = array('annual' => $premiums['totalGrossAnnualPremium'] + $premiums['totalGrossAnnualIPT'], 'monthly' => $premiums['totalGrossMonthlyPremium'] + $premiums['totalGrossMonthlyIPT']);
             $this->view->premiumsFull = $premiums;
         }
         $fees = $quoteManager->getFees();
         $this->view->fees = $fees;
         switch ($stepNum) {
             case 1:
                 $customerManager = new Manager_Core_Customer();
                 $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteManager->getLegacyCustomerReference());
                 // Populate the customer details
                 $titleOptions = LandlordsInsuranceQuote_Form_Subforms_PersonalDetails::$titles;
                 if (in_array($customer->getTitle(), $titleOptions)) {
                     $formData['title'] = $customer->getTitle();
                 } else {
                     $formData['title'] = "Other";
                     $formData['other_title'] = $customer->getTitle();
                 }
                 $formData['first_name'] = $customer->getFirstName();
                 $formData['last_name'] = $customer->getLastName();
                 $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
                 $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
                 $formData['email_address'] = $customer->getEmailAddress();
                 $dob = $customer->getDateOfBirthAt();
                 if (null != $dob && '0000-00-00' != $dob) {
                     $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($dob);
                 }
                 // Populate the correspondence address details
                 $formData['cor_address_line1'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1);
                 $formData['cor_address_line2'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE2);
                 $formData['cor_address_line3'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE3);
                 $formData['cor_address_postcode'] = $customer->getPostcode();
                 $formData['country'] = $customer->getCountry();
                 // Populate the insured property address details
                 $properties = $quoteManager->getProperties();
                 if (count($properties) > 0) {
                     $formData['ins_address_line1'] = $properties[0]['line_1'];
                     $formData['ins_address_line2'] = $properties[0]['line_2'];
                     $formData['ins_address_line3'] = $properties[0]['town'];
                     $formData['ins_address_postcode'] = $properties[0]['postcode'];
                     $formData['owned_for'] = $properties[0]['ownership_length_id'];
                     $formData['no_claims'] = $properties[0]['no_claims_years_id'];
                     $formData['tenants_type'] = $properties[0]['tenant_type_id'];
                     $formData['have_letting_agent'] = $quoteManager->getAgentSchemeNumber() != Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber()) ? 'yes' : 'no';
                     $formData['through_letting_agent'] = $properties[0]['letting_agent_managed'] ? 'yes' : 'no';
                     // Check to see if this postcode is in a flood risk area - if it is then populate the exclude flood cover data
                     // Populating this will also cause the question to be shown on the front end
                     $landlordsRiskAreas = new Datasource_Insurance_LandlordsPlus_RiskAreas();
                     $riskAreas = $landlordsRiskAreas->getByPostcode($properties[0]['postcode']);
                     if ($riskAreas['floodArea'] == '600') {
                         $formData['exclude_flood_cover'] = $properties[0]['exclude_flood_cover'] ? 'no' : 'yes';
                         // Backwards true/false stuff - I'm sooo sorry :(
                     }
                 }
                 // Populate agent details if one has been chosen
                 $agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
                 $defaultASN = $this->_params->homelet->defaultAgent;
                 if ($formData['have_letting_agent'] == 'yes') {
                     $agents = new Datasource_Core_Agents();
                     $agent = $agents->getAgent($agentSchemeNumber);
                     $formData['letting_agent_name'] = $agent->name;
                     $formData['letting_agent_town'] = $agent->town;
                     $formData['letting_agent_asn'] = $agent->agentSchemeNumber;
                     // Fix for Redmine Ref. #10511:
                     $agentDropdown = $pageForm->subform_lettingagent->letting_agent;
                     $agentDropdown->setMultiOptions(array($agent->agentSchemeNumber => $agent->name . ', ' . $agent->town));
                     $formData['letting_agent'] = $agent->agentSchemeNumber;
                 }
                 // Load the policy start date
                 $startDate = $quoteManager->getStartDate();
                 if ($startDate != '' && $startDate != '0000-00-00') {
                     $formData['policy_start'] = substr($startDate, 8, 2) . '/' . substr($startDate, 5, 2) . '/' . substr($startDate, 0, 4);
                 }
                 // If step1 has been marked complete - we can assume they said yes to the IDD question
                 $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['idd'] = true;
                 }
                 // Data Protection section
                 $customerReferenceNumber = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                 $dpaManager = new Manager_Core_DataProtection();
                 $dpaItems = $dpaManager->getItems($customerReferenceNumber, Model_Core_DataProtection_ItemEntityTypes::INSURANCE);
                 foreach ($dpaItems as $currentItem) {
                     switch ($currentItem->constraintTypeId) {
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_phone_post'] = 0;
                             } else {
                                 $formData['dpa_phone_post'] = 1;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_sms_email'] = 0;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             } else {
                                 $formData['dpa_sms_email'] = 1;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_resale'] = 1;
                             } else {
                                 $formData['dpa_resale'] = 0;
                             }
                             break;
                     }
                 }
             case 2:
                 // If step2 has been marked complete - we can assume they said no to the questions unless
                 // they've been set in the quote manager
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['need_building_insurance'] = 'no';
                     $formData['need_contents_insurance'] = 'no';
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER)) {
                     $formData['need_building_insurance'] = 'yes';
                     $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER);
                     $formData['building_built'] = $productMeta['build_year'];
                     $formData['building_bedrooms'] = $productMeta['bedroom_quantity'];
                     $formData['building_type'] = $productMeta['building_type'];
                     $formData['building_insurance_excess'] = $productMeta['excess'];
                     $formData['building_accidental_damage'] = $productMeta['accidental_damage'];
                     $quote = $quoteManager->getModel();
                     if ((int) $productMeta['rebuild_value'] > 0) {
                         // There's a manually entered rebuild value - need to work out if it is because they
                         // chose £500k+ - or if it's because we don't have a dsi
                         $premiums = $quoteManager->calculatePremiums();
                         if ($premiums['calculatedDSIValue'] > 0) {
                             $formData['override_dsi'] = 1;
                         }
                         $formData['building_value'] = $productMeta['rebuild_value'];
                     }
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER) || $quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::UNFURNISHED_CONTENTS_COVER)) {
                     $formData['need_contents_insurance'] = 'yes';
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) {
                         $formData['property_furnished'] = 'yes';
                         $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER);
                         $formData['contents_amount'] = $productMeta['cover_amount'];
                         $formData['contents_excess'] = $productMeta['excess'];
                         $formData['contents_accidental_damage'] = $productMeta['accidental_damage'];
                     } else {
                         $formData['property_furnished'] = 'no';
                     }
                 }
                 break;
             case 3:
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['need_emergency_assistance'] = 'no';
                     $formData['need_prestige_rent_guarantee'] = 'no';
                     $formData['need_legal_expenses'] = 'no';
                     $formData['need_boiler_heating'] = 'no';
                 }
                 // If we have contents/buildings cover then EAS is already included for free so we can hide the form
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER) || $quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) {
                     // Change the subforms view script to one that just says it's already included for free
                     // yeah yeah.. this aint pretty :(
                     $emergencyAssistanceForm = $pageForm->getSubForm('subform_emergencyassistance');
                     $emergencyAssistanceForm->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/emergency-assistance-free.phtml'))));
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BOILER_HEATING)) {
                         $formData['need_boiler_heating'] = 'yes';
                     }
                 } else {
                     // We can allow stand-alone EAS - so we hide the boiler and heating section
                     // yes... this is waaay too complex... I know :(
                     $pageForm->removeSubForm('subform_boilerheating');
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::EMERGENCY_ASSISTANCE)) {
                         $formData['need_emergency_assistance'] = 'yes';
                     }
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE)) {
                     $formData['need_prestige_rent_guarantee'] = 'yes';
                     $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE);
                     $formData['rent_amount'] = $productMeta['monthly_rent'];
                 } elseif ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::LEGAL_EXPENSES)) {
                     $formData['need_legal_expenses'] = 'yes';
                 }
                 break;
             case 4:
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     // Load underwriting answers from the database as they've already been answered
                     $answersManager = new Manager_Insurance_Answers();
                     $quote = $quoteManager->getModel();
                     $policyNumber = $quote->legacyID;
                     $customerReferenceNumber = $quote->legacyCustomerID;
                     $answers = $answersManager->getUnderwritingAnswers($policyNumber);
                     foreach ($answers as $answer) {
                         switch ($answer->getQuestionNumber()) {
                             case '53':
                                 $formData['declaration1'] = $answer->getAnswer();
                                 break;
                             case '54':
                                 $formData['declaration2'] = $answer->getAnswer();
                                 break;
                             case '55':
                                 $formData['declaration2b'] = $answer->getAnswer();
                                 break;
                             case '56':
                                 $formData['declaration2c'] = $answer->getAnswer();
                                 break;
                             case '57':
                                 $formData['declaration2d'] = $answer->getAnswer();
                                 break;
                             case '58':
                                 $formData['declaration3'] = $answer->getAnswer();
                                 break;
                             case '59':
                                 $formData['declaration4'] = $answer->getAnswer();
                                 break;
                             case '60':
                                 $formData['declaration6'] = $answer->getAnswer();
                                 break;
                             case '61':
                                 $formData['declaration7'] = $answer->getAnswer();
                                 break;
                             case '62':
                                 $formData['declaration8'] = $answer->getAnswer();
                                 break;
                             case '63':
                                 $formData['declaration9'] = $answer->getAnswer();
                                 break;
                             case '64':
                                 $formData['declaration10'] = $answer->getAnswer();
                                 break;
                         }
                     }
                     // Also need to see if they said yes or no to bank interest on the propery…
                     $bankInterestManager = new Manager_Insurance_LegacyBankInterest();
                     $bankInterestArray = $bankInterestManager->getAllInterests($policyNumber, $customerReferenceNumber);
                     $model = array();
                     if (!empty($bankInterestArray)) {
                         $formData['declaration11'] = 'yes';
                     } else {
                         $formData['declaration11'] = 'no';
                     }
                     // They must have agreed to the declaration or they wouldn't have been able to continue
                     $formData['declaration_confirmation'] = 'yes';
                 }
                 break;
             case 5:
                 // Payment Selection section
                 if (isset($pageSession->paymentSelectionDetails) && is_array($pageSession->paymentSelectionDetails)) {
                     $formData = $pageSession->paymentSelectionDetails;
                 }
                 break;
         }
     }
     $pageForm->populate($formData);
     return true;
 }
 /**
  * Make sure PHP is up to snuff, that we can write to the right places, and
  * make the first user.
  */
 public function indexAction()
 {
     $phpCheck = array('PHP Version >= 5.2.3' => version_compare(PHP_VERSION, '5.2.3') >= 0, 'Standard Extension Loaded' => extension_loaded('standard'), 'SOAP Extension Loaded' => extension_loaded('soap'), 'PCRE Extension Loaded' => extension_loaded('pcre'), 'PDO Extension Loaded' => extension_loaded('pdo'), 'PDO SQLite Extension Loaded' => extension_loaded('pdo_sqlite'), 'SPL Extension Loaded' => extension_loaded('spl'), 'Session Extension Loaded' => extension_loaded('session'), 'Ctype Extension Loaded' => extension_loaded('ctype'));
     $systemCheck = array('Languages Directory (' . LANGUAGE_PATH . ') Writable' => is_writable(LANGUAGE_PATH), 'Skins Directory (' . SKIN_PATH . ') Writable' => is_writable(SKIN_PATH), 'Database Directory (' . APPLICATION_PATH . '/../data/db) Writable' => is_writable(APPLICATION_PATH . '/../data/db'), 'Configuration File (' . CONFIG_PATH . '/settings.ini' . ') Writable' => is_writable(CONFIG_PATH . '/settings.ini'));
     /*
      * Show an error if there are any PHP or system errors.
      */
     $hasPhpErrors = false;
     $hasSystemErrors = false;
     foreach ($phpCheck as $check) {
         if (!$check) {
             $hasPhpErrors = true;
             break;
         }
     }
     foreach ($systemCheck as $check) {
         if (!$check) {
             $hasSystemErrors = true;
             break;
         }
     }
     if (!$hasPhpErrors && !$hasSystemErrors) {
         /*
          * Build the add user form.
          */
         $config = Zend_Registry::get('config');
         $skins = Model_Skin::getAllSkins();
         $languages = Model_Language::getAllLanguages();
         /*
          * Turn the skin and language lists into something more Zend_Form
          * friendly.
          */
         foreach ($skins as $skin) {
             $skinList[$skin->name] = $skin->name;
         }
         foreach ($languages as $language) {
             $languageList[$language->name] = $language->name;
         }
         $form = new Zend_Form();
         $form->setMethod('post');
         $username = $form->createElement('text', 'username');
         $username->setLabel(ucfirst($this->view->translate->_('username')));
         $username->setRequired(true);
         $username->addValidator('alnum');
         $apiKey = $form->createElement('text', 'apiKey');
         $apiKey->setLabel(ucfirst($this->view->translate->_('API key')));
         $apiKey->setRequired(true);
         $apiKey->addValidator('alnum');
         $skin = $form->createElement('select', 'skin');
         $skin->setLabel(ucfirst($this->view->translate->_('skin')));
         $skin->addMultiOptions($skinList);
         $skin->setValue($config->defaults->skin);
         $skin->setRequired(true);
         $language = $form->createElement('select', 'language');
         $language->setLabel(ucfirst($this->view->translate->_('language')));
         $language->addMultiOptions($languageList);
         $language->setValue($config->defaults->language);
         $language->setRequired(true);
         $form->addElement($username);
         $form->addElement($apiKey);
         $form->addElement($skin);
         $form->addElement($language);
         $form->addElement('submit', 'submit', array('label' => $this->view->translate->_('Submit')));
         /*
          * Process form submission.
          */
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             if ($form->isValid($formData)) {
                 /*
                  * Try out the username and API key to make sure they
                  * entered a good one.
                  */
                 $account = null;
                 $client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $form->getValue('username'), $form->getValue('apiKey'));
                 try {
                     $account = $client->getObject();
                 } catch (Exception $e) {
                     $this->view->errorMessage = $this->view->translate->_('Please enter a valid username and API key combination.');
                 }
                 /*
                  * Add the user.
                  */
                 if ($account != null) {
                     try {
                         $user = Model_DbTable_User::addUser($form->getValue('username'), $form->getValue('apiKey'), $form->getValue('skin'), $form->getValue('language'), true);
                         $this->_helper->_redirector->goToRouteAndExit(array('controller' => 'index', 'action' => null));
                     } catch (Exception $e) {
                         $this->view->errorMessage = $this->view->translate->_('Unable to add user.') . ' ' . $e->getMessage();
                     }
                 }
             } else {
                 $this->view->errorMessage = $this->view->translate->_('Please completely fill out the configuration form.');
             }
             $form->populate($formData);
         }
         $this->view->form = $form;
     }
     $this->view->pageTitle = 'Installation';
     $this->view->headTitle('Installation');
     $this->view->phpCheck = $phpCheck;
     $this->view->systemCheck = $systemCheck;
     $this->view->hasPhpErrors = $hasPhpErrors;
     $this->view->hasSystemErrors = $hasSystemErrors;
 }
Exemple #20
0
 /**
  * @group ZF-3227
  */
 public function testFormsShouldAllowResetting()
 {
     $form = new Zend_Form();
     $foo = new Zend_Form_SubForm(array('name' => 'foo', 'elements' => array('one' => 'text', 'two' => 'text')));
     $form->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat')->addDisplayGroup(array('bar', 'bat'), 'barbat')->addSubForm($foo, 'foo');
     $values = array('bar' => 'Bar Value', 'baz' => 'Baz Value', 'bat' => 'Bat Value', 'foo' => array('one' => 'One Value', 'two' => 'Two Value'));
     $form->populate($values);
     $test = $form->getValues();
     $this->assertEquals($values, $test);
     $form->reset();
     $test = $form->getValues();
     $this->assertNotEquals($values, $test);
     $this->assertEquals(0, array_sum($test));
 }
Exemple #21
0
 /**
  * Get meta action
  *
  * @param  string $data
  * @return Zend_Form
  */
 public function getMetaForm($data)
 {
     $form = new Zend_Form();
     $form->setAction($this->getFrontController()->getBaseUrl() . self::META_ACTION)->setMethod('post');
     $pageId = $form->createElement('hidden', 'page_id');
     $pageId->addFilter('int');
     $pageTitle = $form->createElement('text', 'page_title');
     $pageTitle->setLabel($this->view->getTranslation('Page Title') . ':')->addFilter('stripTags')->setAttrib('class', 'med');
     $filename = $form->createElement('text', 'filename');
     $filename->setLabel($this->view->getTranslation('Filename') . ':')->addFilter('stripTags')->setAttrib('class', 'med');
     $metaDescription = $form->createElement('textarea', 'meta_description');
     $metaDescription->setLabel($this->view->getTranslation('Meta Description') . ':')->addFilter('stripTags')->setAttrib('class', 'med_short');
     $metaKeywords = $form->createElement('textarea', 'keywords');
     $metaKeywords->setLabel($this->view->getTranslation('Meta Keywords') . ':')->addFilter('stripTags')->setAttrib('class', 'med_short');
     $searchTags = $form->createElement('textarea', 'search_tags');
     $searchTags->setLabel($this->view->getTranslation('Search Tags') . ':')->addFilter('stripTags')->setAttrib('class', 'med_short');
     // Add elements to form:
     $form->addElement($pageTitle)->addElement($filename)->addElement($metaDescription)->addElement($metaKeywords)->addElement($searchTags)->addElement('submit', 'update', array('label' => $this->view->getTranslation('Update Meta Data')))->addElement($pageId);
     //set data
     if (is_array($data)) {
         $form->populate($data);
     }
     return $form;
 }
 public function ajouterAction()
 {
     $form = new Zend_Form();
     // On prépare le formulaire à afficher
     $form->setMethod('post');
     $form->addElement('text', 'NOM_M', array('label' => 'Nom : ', 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'PRENOM', array('label' => 'Prénom : ', 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'LOGIN', array('label' => 'Login : '******'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'MAIL', array('label' => 'Votre Adresse e-mail : ', 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'PASSWORD', array('label' => 'Mot de passe : ', 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'ROLE', array('label' => 'Rôle : ', 'required' => false));
     $form->addElement('text', 'DATE_ENTREE', array('label' => "Date d'entrée : ", 'required' => true, 'filters' => array('StringTrim')));
     $form->addElement('text', 'ECOLE', array('label' => 'Ecole : ', 'required' => false));
     $form->addElement('text', 'PROMO', array('label' => 'Promotion : ', 'required' => false));
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel('Ajouter');
     $form->addElement($submit);
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $dba = Zend_Registry::get('dba');
             // On récupère l'instance de la BDD
             $datas = array('PRENOM' => $formData["PRENOM"], 'LOGIN' => $formData["LOGIN"], 'MAIL' => $formData["MAIL"], 'PASSWORD' => md5($formData["PASSWORD"]), 'ROLE' => $formData["ROLE"], 'DATE_ENTREE' => new Zend_Db_Expr('now()'), 'ECOLE' => $formData["ECOLE"], 'PROMO' => $formData["PROMO"], 'NOM_M' => $formData["NOM_M"], 'ACTIVE_M' => true);
             $dba->beginTransaction();
             try {
                 $dba->insert('MEMBRE', $datas);
                 // On prépare le commit
                 $dba->commit();
                 // On tente d'inserer les datas dans la table MEMBRE
             } catch (Exception $e) {
                 $dba->rollBack();
                 // En cas de problèmes avec la base de donnée on annule les changements et on affiche le message d'erreur
                 echo $e->getMessage();
             }
             $this->_helper->redirector('index');
             // Permet de rediriger vers la page index Membre
         } else {
             $form->populate($formData);
             // Si il y a une erreur on pre-remplie les champs déjà renseigner et affiche les éventuelles erreurs
         }
     }
     $this->view->form = $form;
     // On met le formulaire ds la variable form
 }
Exemple #23
0
 /**
  * (non-PHPdoc)
  * @see library/Zend/Zend_Form#populate()
  */
 public function populate(array $values)
 {
     // Call the father's render function.
     return parent::populate($values);
 }
 private function loadForm(Zend_Form $form)
 {
     $id = (int) $this->_getParam('id', 0);
     $blogEntry = $this->loadBlogEntry($id);
     $form->populate($blogEntry->toArray());
     $form->populate(array('existingImage' => $blogEntry->image));
     return $form;
 }
Exemple #25
0
 /**
  * Hook for node form - if type is Filemanager Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     if ($item->type == "gallery_node") {
         $bgcolor = new Zoo_Form_Element_ColorPicker('gallery_bgcolor');
         $bgcolor->setLabel('Background colour');
         $config = Zoo::getConfig('gallery', 'module');
         /*
         $topimage = new Zend_Form_Element_Radio('gallery_topimage');
         $topimage->setLabel('Top image');
         $topimage->setOptions(array('escape' => false));
         $topimages = Zoo::getService('content')->getContent(array('parent' => $config->top_image, 
         														  'nodetype' => 'filemanager_file'));
         $topimage->addMultiOption(0, Zoo::_("None"));
         foreach ($topimages as $image) {
         	$topimage->addMultiOption($image->id, $image->title."<br /><img src='".$image->hooks['filemanager_file']->getUrl(200)."' />");
         }
         */
         $topimage = new Zoo_Form_Element_FileBrowser('gallery_topimage');
         $topimage->setLabel('Top image');
         $bgimage = new Zoo_Form_Element_FileBrowser('gallery_bgimage');
         $bgimage->setLabel('Background image');
         $form->addElements(array($bgcolor, $topimage, $bgimage));
         $options = array('legend' => Zoo::_("Gallery extras"));
         $form->addDisplayGroup(array('gallery_bgcolor', 'gallery_topimage', 'gallery_bgimage'), 'gallery_node', $options);
         if ($item->id > 0) {
             // Fetch extra information
             $top_image = Zoo::getService('link')->getLinkedNodes($item, 'top_image');
             $populate['gallery_topimage'] = count($top_image) > 0 ? $top_image[0]->id : 0;
             $bg_image = Zoo::getService('link')->getLinkedNodes($item, 'bg_image');
             $populate['gallery_bgimage'] = count($bg_image) > 0 ? $bg_image[0]->id : 0;
             $factory = new Gallery_Node_Factory();
             $gnode = false;
             // Fetch estate object
             $gnode = $factory->find($item->id)->current();
             if ($gnode) {
                 $populate['gallery_bgcolor'] = $gnode->bgcolor;
             }
             $form->populate($populate);
         }
     }
 }
 /**
  * @group ZF-2828
  */
 public function testCanPopulateCheckboxOptionsFromPostedData()
 {
     $form = new Zend_Form(array('elements' => array('100_1' => array('MultiCheckbox', array('multiOptions' => array('100_1_1' => 'Agriculture', '100_1_2' => 'Automotive', '100_1_12' => 'Chemical', '100_1_13' => 'Communications'), 'required' => true)))));
     $data = array('100_1' => array('100_1_1', '100_1_2', '100_1_12', '100_1_13'));
     $form->populate($data);
     $html = $form->render($this->getView());
     foreach ($form->getElement('100_1')->getMultiOptions() as $key => $value) {
         if (!preg_match('#(<input[^>]*' . $key . '[^>]*>)#', $html, $m)) {
             $this->fail('Missing input for a given multi option: ' . $html);
         }
         $this->assertContains('checked="checked"', $m[1]);
     }
 }
 private function loadForm(Zend_Form $form)
 {
     $id = (int) $this->_getParam('id', 0);
     $category = $this->loadCategory($id);
     $form->populate($category->toArray());
     return $form;
 }
 /**
  * Helper function to populate the zend form elements with database data
  *
  * @param Zend_Form $pageForm form definition for this step
  * @param int $stepNum current step number
  *
  * @return void
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
     // First of all check that this form should be viewable and the user isn't trying to skip ahead
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     // Check to see if the user is trying to skip ahead in the quote
     $tooFarAhead = false;
     if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) {
         $tooFarAhead = true;
         $lastCompleted = 1;
     } elseif ($stepNum > 1) {
         // Check to see if any pages previous to the one the user's trying to get to are incomplete
         $tooFarAhead = false;
         for ($i = 1; $i < $stepNum; $i++) {
             if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) {
                 $tooFarAhead = true;
                 $lastCompleted = $i;
                 break;
                 break;
             }
         }
     }
     if ($tooFarAhead) {
         // Drop user onto page that needs completing
         $this->_helper->redirector->gotoUrl('/tenants/insurance-quote-b/step' . $lastCompleted);
         return false;
     }
     // Now check to see if they need to login (using an existing email address without being logged in)
     if ($stepNum > 1) {
         // Before we do ANYTHING we need to check to see if the email address entered matches a customer record
         // we already have - if it does we need to ask them to login before they proceed.
         $customerReferenceNumber = $pageSession->CustomerRefNo;
         $customerManager = new Manager_Core_Customer();
         $legacyCustomer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerReferenceNumber);
         $emailAddress = $legacyCustomer->getEmailAddress();
         $customer = $customerManager->getCustomerByEmailAddress($emailAddress);
         if ($customer) {
             // There is already a customer entry for this email address - so we need to see if they are logged in
             // if not we need to force them to login
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             /*if ($auth->hasIdentity()) {
             					$loggedInEmail = $auth->getStorage()->read()->email_address;
             					if ($loggedInEmail != $customer->getEmailAddress()) {
             						// They are logged in but not who they should be to do this quote
             						$this->_helper->redirector->gotoUrl('/account/login?refer=tenants-insurance&step='. $stepNum);
             
             						return false;
             					}
             				} else {
             					// They aren't logged in and need to
             					$this->_helper->redirector->gotoUrl('/account/login?refer=tenants-insurance&step='. $stepNum);
             
             					return false;
             				}*/
         }
     }
     // Echo out some debug info if not in production mode
     Application_Core_Logger::log("Policy Number : " . $this->_policyNumber);
     Application_Core_Logger::log("Customer Ref No : " . $this->_customerReferenceNumber);
     Application_Core_Logger::log("agentSchemeNumber : " . $this->_agentSchemeNumber);
     $formData = array();
     // If step 1 and not in session (so producing a quick quote) - we need to pre-populate
     // a few bits if the customer is already logged into the site
     if ($stepNum == 1 && !isset($pageSession->CustomerRefNo)) {
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
         if ($auth->hasIdentity()) {
             // Customer is logged in and starting a new quote - so we need to pre-populate the customers details from stored details
             $customerID = $auth->getStorage()->read()->id;
             $customerManager = new Manager_Core_Customer();
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             // Get the customer's legacy record too as DoB is only in the old system
             $legacyCustomer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerID);
             $formData['title'] = $customer->getTitle();
             $formData['first_name'] = $customer->getFirstName();
             $formData['last_name'] = $customer->getLastName();
             $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
             $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
             $formData['email_address'] = $customer->getEmailAddress();
             // Fetch DoB from old customer manager
             $formData['date_of_birth_at'] = $legacyCustomer->getDateOfBirth();
             $pageForm->populate($formData);
         }
     }
     // Only populate from DB if we are in session and have a reference number
     if (isset($pageSession->CustomerRefNo)) {
         $customerReferenceNumber = $pageSession->CustomerRefNo;
         $policyNumber = $pageSession->PolicyNumber;
         // Populate $formData with data from model, if available
         switch ($stepNum) {
             case 1:
                 // Personal Details section
                 $customerManager = new Manager_Core_Customer();
                 $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerReferenceNumber);
                 $titleOptions = TenantsInsuranceQuoteB_Form_Subforms_PersonalDetails::$titles;
                 if (in_array($customer->getTitle(), $titleOptions)) {
                     $formData['title'] = $customer->getTitle();
                 } else {
                     $formData['title'] = "Other";
                     $formData['other_title'] = $customer->getTitle();
                 }
                 $formData['first_name'] = $customer->getFirstName();
                 $formData['last_name'] = $customer->getLastName();
                 $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
                 $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
                 $formData['email_address'] = $customer->getEmailAddress();
                 $dob = $customer->getDateOfBirthAt();
                 if (null != $dob && '0000-00-00' != $dob) {
                     $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($dob);
                 }
                 // Data Protection section
                 $dpaManager = new Manager_Core_DataProtection();
                 $dpaItems = $dpaManager->getItems($customerReferenceNumber, Model_Core_DataProtection_ItemEntityTypes::INSURANCE);
                 foreach ($dpaItems as $currentItem) {
                     switch ($currentItem->constraintTypeId) {
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_phone_post'] = 0;
                             } else {
                                 $formData['dpa_phone_post'] = 1;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_sms_email'] = 0;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             } else {
                                 $formData['dpa_sms_email'] = 1;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_resale'] = 1;
                             } else {
                                 $formData['dpa_resale'] = 0;
                             }
                             break;
                     }
                 }
                 // Contents Insurance section
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 // If we've retrieved this quote we need to setup some session variables to match the quote (agent scheme number mostly)
                 $session = new Zend_Session_Namespace('homelet_global');
                 $session->agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
                 $contentsSI = $quoteManager->getCoverAmount(Manager_Insurance_TenantsContentsPlus_Quote::CONTENTS);
                 // TODO: Remove the hard-coded contents insured splits - should be loaded from DB
                 if ($contentsSI == '5000' || $contentsSI == '7500' || $contentsSI == '10000' || $contentsSI == '15000') {
                     $formData['contents_cover_a'] = $contentsSI;
                 } else {
                     $formData['contents_cover_a'] = '15000+';
                     $formData['contents_cover_b'] = $contentsSI;
                 }
                 // Shares section
                 $sharersManager = new Manager_Insurance_TenantsContentsPlus_Sharers();
                 $existingSharers = $sharersManager->getSharers($policyNumber);
                 $formData['policy_sharers'] = 0;
                 if ($existingSharers) {
                     if ($existingSharers->getSharerOccupation(1) != '') {
                         $formData['policy_sharers'] = 1;
                         $formData['policy_sharer1_occupation'] = $existingSharers->getSharerOccupation(1);
                     }
                     if ($existingSharers->getSharerOccupation(2) != '') {
                         $formData['policy_sharers'] = 2;
                         $formData['policy_sharer2_occupation'] = $existingSharers->getSharerOccupation(2);
                     }
                 }
                 for ($i = 1; $i <= $pageForm->maxSharers; $i++) {
                     $formData["policy_sharer{$i}_occupation"] = $existingSharers->getSharerOccupation($i);
                 }
                 // Decide max number of sharers allowed based on contents insured value
                 $contentsAmount = new Zend_Currency(array('value' => $contentsSI, 'precision' => 0));
                 $sharersAllowed = $sharersManager->getNoOfSharersAllowed($contentsAmount);
                 // Push this into Javascript on the page
                 $this->view->headScript()->appendScript("var sharersAllowed = {$sharersAllowed};");
                 // Initial Disclosure Agreement section
                 // As we have a customer reference number they must have saved step 1 at some point which means
                 // they must have agreed to the IDD section
                 $formData['idd'] = 1;
                 break;
             case 2:
                 // Unspecified Possessions section
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 $unspecSI = $quoteManager->getCoverAmount(Manager_Insurance_TenantsContentsPlus_Quote::UNSPECIFIEDPOSSESSIONS);
                 // If step has been completed before we can assume some defaults that we'll over-write later
                 if (isset($pageSession->completed[2]) && $pageSession->completed[2] == true or $quoteManager->getPropertyPostcode() != '') {
                     $formData['away_from_home'] = 'no';
                     $formData['above_x'] = 'no';
                     $formData['bicycle'] = 'no';
                 }
                 // TODO: Re-factor this so that it doesn't use hardcoded pricing breaks anymore
                 if ($unspecSI > 0) {
                     $formData['away_from_home'] = 'yes';
                     $formData['possessions_cover'] = $unspecSI;
                 }
                 //TODO: This should be talking to the quote manager NOT directly to the datasource
                 $possessions = new Datasource_Insurance_Policy_SpecPossessions($pageSession->PolicyNumber);
                 if ($possessions->countPossessions() > 0) {
                     $formData['above_x'] = 'yes';
                 }
                 // Bicycle section
                 //TODO: This should be talking to the quote manager NOT directly to the datasource
                 $bicycle = new Datasource_Insurance_Policy_Cycles($this->_customerReferenceNumber, $this->_policyNumber);
                 if ($bicycle->countBikes() > 0) {
                     $formData['bicycle'] = 'yes';
                 }
                 break;
             case 3:
                 // Insured Address section
                 // Fetch previously stored address
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 $addressArray = $quoteManager->getPropertyAddress();
                 if ($addressArray['postcode'] != '') {
                     if (strpos($addressArray['address1'], ',') !== false) {
                         $formData['ins_house_number_name'] = preg_replace('/,.*$/', '', $addressArray['address1']);
                     } else {
                         $formData['ins_house_number_name'] = preg_replace('/ .*$/', '', $addressArray['address1']);
                     }
                     $formData['ins_postcode'] = $addressArray['postcode'];
                     // Look up address again to populate dropdown
                     $postcodeLookup = new Manager_Core_Postcode();
                     $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['ins_postcode']));
                     $addressList = array('' => '--- please select ---');
                     $filterString = is_numeric($formData['ins_house_number_name']) ? $formData['ins_house_number_name'] . ", " : $formData['ins_house_number_name'];
                     foreach ($addresses as $address) {
                         $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                         if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                             $addressID = $address['id'];
                         }
                     }
                     // Add some validation
                     $ins_address = $pageForm->getSubForm('subform_insuredaddress')->getElement('ins_address');
                     $ins_address->setMultiOptions($addressList);
                     $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                     $ins_address->addValidator($validator, true);
                     // Set the address to selected
                     $ins_address->setValue($addressID);
                     $addressID = null;
                     // Make sure we don't use this again for the correspondance address!
                     // Upsell Message section
                     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
                     $session = new Zend_Session_Namespace('homelet_global');
                     $agentSchemeNumber = $session->agentSchemeNumber;
                 }
                 // Correspondance Address section
                 $customerManager = new Manager_Core_Customer();
                 $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber);
                 $addressLine1 = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1);
                 $addressPostcode = $customer->getPostCode();
                 if ($addressPostcode != '') {
                     if (strpos($addressLine1, ',') !== false) {
                         $formData['cor_house_number_name'] = preg_replace('/,.*$/', '', $addressLine1);
                     } else {
                         $formData['cor_house_number_name'] = preg_replace('/ .*$/', '', $addressLine1);
                     }
                     $formData['cor_postcode'] = $addressPostcode;
                     // TODO: Surely if this postcode and house number matches the previous one
                     // we can just tick the YES box and hide the correspondance address form??
                     $postcodeLookup = new Manager_Core_Postcode();
                     $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['cor_postcode']));
                     $addressList = array('' => '--- please select ---');
                     $filterString = is_numeric($formData['cor_house_number_name']) ? $formData['cor_house_number_name'] . ", " : $formData['cor_house_number_name'];
                     foreach ($addresses as $address) {
                         $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                         if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                             $addressID = $address['id'];
                         }
                     }
                     $cor_address = $pageForm->getSubForm('subform_correspondencedetails')->getElement('cor_address');
                     $cor_address->setMultiOptions($addressList);
                     $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                     $cor_address->addValidator($validator, true);
                     $cor_address->setValue($addressID);
                 }
                 if ($addressPostcode != '' && $addressArray['postcode'] != '') {
                     if ($cor_address->getValue() == $ins_address->getValue()) {
                         $formData['cor_same_address'] = 'yes';
                     } else {
                         $formData['cor_same_address'] = 'no';
                     }
                 }
                 // Letting Agent section
                 // If the agent scheme number is not our default one - load the agent details
                 $params = Zend_Registry::get('params');
                 $agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
                 // How did you hear about us section
                 $marketQuestion = new Manager_Core_ManagementInformation();
                 $formData['how_hear'] = $marketQuestion->getMarketingAnswers($this->_policyNumber);
                 //Campaign code section
                 $webLeadManager = new Manager_Core_WebLead();
                 $webLeadSummary = $webLeadManager->getSummary($this->_webLeadSummaryId);
                 $formData['campaign_code'] = $webLeadSummary->promotionCode;
                 // Start and end date
                 $startDate = $quoteManager->getStartDate();
                 if ($startDate != '' && $startDate != '0000-00-00') {
                     $formData['policy_start'] = substr($startDate, 8, 2) . '/' . substr($startDate, 5, 2) . '/' . substr($startDate, 0, 4);
                 }
                 break;
             case 4:
                 // Important Information section
                 // If this page has previously passed validation, we know what the answers
                 //   given must have been without hitting the DB (as anything else refers)
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum]) {
                     $formData['declaration1'] = 'no';
                     $formData['declaration2'] = 'no';
                     $formData['declaration3'] = 'no';
                     $formData['declaration4'] = 'no';
                     $formData['declaration_confirmation'] = 'yes';
                     // If the step is completed we can also assume they said yes to the declaration agreement
                     $formData['declaration_statement'] = 1;
                 }
                 break;
             case 5:
                 // Not sure if we should really be loading payment methods back in
                 // surely it would be best to just let them choose again
                 break;
             case 'dd':
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 $this->view->payMonthly = strtolower($quoteManager->getPayBy()) == 'monthly';
                 break;
         }
         $pageForm->populate($formData);
         // Populate the quick quote box
         $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
         $premiums = $quoteManager->calculatePremiums();
         $fees = $quoteManager->getFees();
         $this->view->premiums = $premiums;
         $this->view->fees = $fees;
     } else {
         // Not in session but there are some defaults we need to set for step 1
         // TODO: Write the javascript better so we don't need to do fudges like this
         $this->view->headScript()->appendScript("var sharersAllowed = 0;");
     }
     return true;
 }
Exemple #29
0
 public function translateAction()
 {
     $this->view->page_title .= $this->view->translate('Help us to translate nolotiro.org to your language');
     $request = $this->getRequest();
     $newlangs = array('ca' => 'Català', 'gl' => 'Galego', 'eu' => 'Euskara', 'nl' => 'Nederlands', 'de' => 'Deutsch', 'fr' => 'Français', 'pt' => 'Português', 'it' => 'Italiano');
     $lform = new Zend_Form();
     $lform->setMethod('get');
     $lform->addElement('select', 'lang', array('multiOptions' => $newlangs));
     $elem_newlang = $lform->getElement('lang');
     $elem_newlang->removeDecorator('label')->removeDecorator('HtmlTag')->setAttrib('onchange', 'this.form.submit()');
     $lform->populate($request->getParams());
     $newlang = $elem_newlang->getValue();
     $this->view->langsform = $lform;
     if ($newlang != null) {
         if (isset($newlangs[$newlang])) {
             $this->view->newlangtext = $newlangs[$newlang];
         } else {
             $newlang == null;
         }
     }
     if ($newlang == null) {
         $elem_newlang->clearMultiOptions();
         $elem_newlang->addMultiOption("", "-- " . $this->view->translate("Choose language") . " --");
         $elem_newlang->addMultiOptions($newlangs);
     } else {
         $options = array('scan' => Zend_Translate::LOCALE_FILENAME);
         $translate = new Zend_Translate('csv', NOLOTIRO_PATH . '/application/languages/', 'en', $options);
         $adapter = $translate->getAdapter();
         $es = $adapter->getMessages('es');
         if (strcmp($this->lang, $newlang) != 0) {
             $userlang = $adapter->getMessages($this->lang);
             $adapter->setLocale($this->lang);
         } else {
             $adapter->setLocale("en");
         }
         $en = $adapter->getMessages('en');
         $lang = $adapter->getMessages($newlang);
         $tform = new Zend_Form();
         $tform->setMethod('post');
         $tform->setAttrib('class', 'texts');
         $tform->addElement('captcha', 'safe_captcha', array('label' => 'Please, insert the 4 characters shown:', 'required' => true, 'captcha' => array(' captcha' => 'Image', 'wordLen' => 4, 'height' => 50, 'width' => 160, 'gcfreq' => 50, 'timeout' => 300, 'font' => NOLOTIRO_PATH . '/www/images/antigonimed.ttf', 'imgdir' => NOLOTIRO_PATH . '/www/images/captcha')));
         $tform->setTranslator($adapter);
         $index = 0;
         foreach ($es as $key => $text) {
             if (strpos($key, "safe_") === 0) {
                 continue;
             }
             if (isset($userlang[$key])) {
                 $text = $userlang[$key];
             } elseif (isset($en[$key])) {
                 $text = $en[$key];
             } else {
                 $text = $key;
             }
             $maxlen = strlen($text) * 3;
             $text = preg_replace("/(\\<[^\\>]*\\>)/", " ", $text);
             $text = preg_replace("/(\\'?%[a-zA-Z\\-]*%?\\'?)/", "...", $text);
             if (isset($lang[$key])) {
                 $val = $lang[$key];
                 $maxlen = strlen($val) * 3;
                 $val = preg_replace("/(\\<[^\\>]*\\>)/", " ", $val);
                 $val = preg_replace("/(\\'?%[a-zA-Z\\-]*%?\\'?)/", "...", $val);
             } else {
                 $val = '';
             }
             if ($maxlen < 20) {
                 $maxlen = 20;
             }
             if ($maxlen < 140) {
                 $type = "text";
                 $rows = 1;
             } else {
                 $type = "textarea";
                 $rows = round($maxlen / 50);
             }
             $tform->addElement($type, "text{$index}", array('validators' => array(array('StringLength', false, array(1, $maxlen))), 'required' => false, 'label' => $text, 'value' => $val, 'cols' => 40, 'rows' => $rows));
             $input = $tform->getElement("text{$index}");
             if ($val == '') {
                 $input->getDecorator('Label')->setOption('class', 'empty');
             }
             $valid = $input->getValidator("StringLength")->setEncoding('UTF-8');
             $index++;
         }
         // add the submit button
         $tform->addElement('submit', 'submit_texts', array('label' => 'Send texts', 'class' => 'magenta awesome'));
         $this->view->textsform = $tform;
         $this->view->newlang = $newlang;
         $tform->populate($request->getParams());
         if ($tform->getElement("submit_texts")->getValue() != null) {
             $data = $tform->getValues();
             if ($tform->isValid($data)) {
                 $newdata = false;
                 $index = 0;
                 foreach ($es as $key => $text) {
                     if (strpos($key, "safe_") === 0 || strpos($key, "lang") === 0) {
                         continue;
                     }
                     $mod = false;
                     $val = $data["text{$index}"];
                     $comp = $lang[$key];
                     $comp = preg_replace("/(\\<[^\\>]*\\>)/", " ", $comp);
                     $comp = preg_replace("/(\\'?%[a-zA-Z\\-]*%?\\'?)/", "...", $comp);
                     if ($val != "" && (!isset($lang[$key]) || ($mod = $comp != $val))) {
                         $body .= "\"{$key}\";\"{$val}\"" . ($mod ? ' ***' : "") . "<br>";
                         if ($mod) {
                             $body .= "\"{$key}\";\"{$comp}\"" . ($mod ? ' ***' : "") . "<br>";
                         }
                         $newdata = true;
                     } else {
                         $body .= "<br>";
                     }
                     $index++;
                 }
                 if (!$newdata) {
                     $this->view->error = $this->view->translate('Please, translate at least one text.');
                     return;
                 }
                 $mail = new Zend_Mail('utf-8');
                 $mail->setBodyHtml($body);
                 $auth = Zend_Auth::getInstance();
                 if ($auth->hasIdentity()) {
                     $mail->setFrom($auth->getIdentity()->email, $auth->getIdentity()->username);
                 } else {
                     $mail->setFrom("*****@*****.**");
                 }
                 $mail->addTo('*****@*****.**', 'aLabs');
                 $mail->setSubject("Translation: {$newlang}.csv");
                 $mail->send();
                 $this->_helper->_flashMessenger->addMessage($this->view->translate('Your translation has been sent. Thanks for your help!'));
                 $this->_redirect('/' . $this->lang);
             }
         }
     }
 }
 /**
  * Get publish form
  *
  * @param  string $data
  * @return Zend_Form
  */
 public function getForm($data)
 {
     $form = new Zend_Form();
     $form->setAction($this->baseUrl . self::PUBLISH_ACTION)->setMethod('post');
     $pageId = $form->createElement('hidden', 'page_id');
     $pageId->addFilter('int');
     $publishRadio = $form->createElement('radio', 'publish');
     $publishRadio->setLabel($this->view->getTranslation('Publish or Archive Page') . ':')->setAttrib('class', 'med');
     // Add elements to form:
     $form->addElement($publishRadio)->addElement('submit', 'update', array('label' => $this->view->getTranslation('Publish or Archive')))->addElement($pageId);
     //set data
     if (is_array($data)) {
         $form->populate($data);
     }
     return $form;
 }