public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $post = $this->request->getPost();
     $export = $this->loader->getExport();
     $exportTypes = $export->getExportClasses();
     if (isset($post['type'])) {
         $currentType = $post['type'];
     } else {
         reset($exportTypes);
         $currentType = key($exportTypes);
     }
     if (\MUtil_Bootstrap::enabled()) {
         $form = new \Gems_Form(array('id' => 'exportOptionsForm', 'class' => 'form-horizontal'));
     } else {
         $form = new \Gems_Form_TableForm();
     }
     $url = $view->url() . '/step/batch';
     $form->setAction($url);
     $elements = array();
     $elements['type'] = $form->createElement('select', 'type', array('label' => $this->_('Export to'), 'multiOptions' => $exportTypes, 'class' => 'autosubmit'));
     $form->addElements($elements);
     $exportClass = $export->getExport($currentType);
     $exportName = $exportClass->getName();
     $exportFormElements['firstCheck'] = $form->createElement('hidden', $currentType);
     $exportFormElements = $exportClass->getFormElements($form, $data);
     if ($exportFormElements) {
         $form->addElements($exportFormElements);
     }
     if (!isset($post[$currentType])) {
         $post[$exportName] = $exportClass->getDefaultFormValues();
     }
     $element = $form->createElement('submit', 'export_submit', array('label' => $this->_('Export')));
     $form->addElement($element);
     if ($post) {
         $form->populate($post);
     }
     $container = \MUtil_Html::div(array('id' => 'export-form'));
     $container->append($form);
     $form->setAttrib('id', 'autosubmit');
     $form->setAutoSubmit(\MUtil_Html::attrib('href', array('action' => $this->request->getActionName(), 'RouteReset' => true)), 'export-form', true);
     return $container;
 }
 protected function getAutoSearchHref()
 {
     return \MUtil_Html::attrib('href', array('action' => 'autofilter', 'RouteReset' => true));
 }
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $post = $this->request->getPost();
     $currentTrack = null;
     if (isset($post['gto_id_track'])) {
         $currentTrack = $post['gto_id_track'];
     }
     $currentRound = null;
     if (isset($post['gto_round_description'])) {
         $currentRound = $post['gto_round_description'];
     }
     $export = $this->loader->getExport();
     $exportTypes = $export->getExportClasses();
     if (isset($post['type'])) {
         $currentType = $post['type'];
     } else {
         reset($exportTypes);
         $currentType = key($exportTypes);
     }
     $dbLookup = $this->util->getDbLookup();
     $translated = $this->util->getTranslated();
     $noRound = array(self::NoRound => $this->_('No round description'));
     $empty = $translated->getEmptyDropdownArray();
     $tracks = $empty + $this->util->getTrackData()->getAllTracks();
     $rounds = $empty + $noRound + $dbLookup->getRoundsForExport($currentTrack);
     $surveys = $dbLookup->getSurveysForExport($currentTrack, $currentRound, true);
     $organizations = $this->currentUser->getRespondentOrganizations();
     if (\MUtil_Bootstrap::enabled()) {
         $this->form = new \Gems_Form(array('class' => 'form-horizontal'));
     } else {
         $this->form = new \Gems_Form_TableForm();
     }
     $url = \MUtil_Html::attrib('href', array('action' => 'index', 'step' => 'batch'));
     $this->form->setAction($url);
     $elements = array();
     $elements['gto_id_track'] = $this->form->createElement('select', 'gto_id_track', array('label' => $this->_('Track'), 'multiOptions' => $tracks, 'class' => 'autosubmit'));
     if (isset($post['gto_id_track']) && $post['gto_id_track']) {
         $element = $this->form->createElement('checkbox', 'add_track_fields');
         $element->setLabel($this->_('Track fields'));
         $element->setDescription($this->_('Add track fields to export'));
         $elements['add_track_fields'] = $element;
         if (!array_key_exists('add_track_fields', $post)) {
             $post['add_track_fields'] = 1;
         }
     }
     $elements['gto_round_description'] = $this->form->createElement('select', 'gto_round_description', array('label' => $this->_('Round'), 'multiOptions' => $rounds, 'class' => 'autosubmit'));
     $elements['gto_id_survey'] = $this->form->createElement('multiCheckbox', 'gto_id_survey', array('label' => $this->_('Survey'), 'multiOptions' => $surveys));
     $elements['gto_id_survey']->setRequired(true);
     $elements['gto_id_survey']->setSeparator('');
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_survey]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_survey]'));
     }
     $element->setLabel($this->_('Toggle'));
     $elements[] = $element;
     if (count($organizations) > 1) {
         $elements['gto_id_organization'] = $this->form->createElement('multiCheckbox', 'gto_id_organization', array('label' => $this->_('Organizations'), 'multiOptions' => $organizations));
         if (\MUtil_Bootstrap::enabled()) {
             $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_organization]'));
         } else {
             $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_organization]'));
         }
         $element->setLabel($this->_('Toggle'));
         $elements[] = $element;
     }
     $dates = array('gto_start_date' => $this->_('Track start'), 'gto_end_date' => $this->_('Track end'), 'gto_valid_from' => $this->_('Valid from'), 'gto_valid_until' => $this->_('Valid until'));
     // $dates = 'gto_valid_from';
     $periodElements = $this->getPeriodSelectors($dates, 'gto_valid_from');
     $elements += $periodElements;
     $element = $this->form->createElement('textarea', 'ids');
     $element->setLabel($this->_('Respondent id\'s'))->setAttrib('cols', 60)->setAttrib('rows', 4)->setDescription($this->_("Not respondent nr, but respondent id as exported here. Separate multiple id's with , or ;"));
     $elements[] = $element;
     $element = $this->form->createElement('checkbox', 'column_identifiers');
     $element->setLabel($this->_('Column Identifiers'));
     $element->setDescription($this->_('Prefix the column labels with an identifier. (A) Answers, (TF) Trackfields, (D) Description'));
     $elements['column_identifiers'] = $element;
     $element = $this->form->createElement('checkbox', 'show_parent');
     $element->setLabel($this->_('Show parent'));
     $element->setDescription($this->_('Show the parent column even if it doesn\'t have answers'));
     $elements['show_parent'] = $element;
     $element = $this->form->createElement('checkbox', 'prefix_child');
     $element->setLabel($this->_('Prefix child'));
     $element->setDescription($this->_('Prefix the child column labels with parent question label'));
     $elements['prefix_child'] = $element;
     $elements['type'] = $this->form->createElement('select', 'type', array('label' => $this->_('Export to'), 'multiOptions' => $exportTypes, 'class' => 'autosubmit'));
     $this->form->addElements($elements);
     $exportClass = $export->getExport($currentType);
     $exportName = $exportClass->getName();
     $exportFormElements = $exportClass->getFormElements($this->form, $data);
     if ($exportFormElements) {
         $exportFormElements['firstCheck'] = $this->form->createElement('hidden', $currentType);
         $exportFormElements['firstCheck']->setBelongsTo($exportName);
         $this->form->addElements($exportFormElements);
     }
     if (!isset($post[$currentType])) {
         $post[$exportName] = $exportClass->getDefaultFormValues();
     }
     $element = $this->form->createElement('submit', 'export_submit', array('label' => $this->_('Export')));
     $this->form->addElement($element);
     if ($post) {
         $this->form->populate($post);
     }
     $container = \MUtil_Html::div(array('id' => 'export-surveys-form'));
     $container->append($this->form);
     $this->form->setAttrib('id', 'autosubmit');
     $this->form->setAutoSubmit(\MUtil_Html::attrib('href', array('action' => 'index', 'RouteReset' => true)), 'export-surveys-form', true);
     return $container;
 }
 /**
  *
  * @return string Href attribute for type as you go autofilter
  */
 protected function getAutoSearchHref()
 {
     return \MUtil_Html::attrib('href', array('action' => 'autofilter', $this->model->getTextFilter() => null, 'RouteReset' => true));
 }
 /**
  * Handle the form
  *
  * @param type $saveLabel
  * @param type $data
  * @return type
  */
 public function processForm($saveLabel = null, $data = null)
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost() + (array) $data;
     } else {
         //Set the defaults for the form here
         $data = $data + $this->export->getDefaults();
     }
     $form = $this->getForm($data);
     //Make the form 'autosubmit' so it can refresh
     $form->setAttrib('id', 'autosubmit');
     $form->setAutoSubmit(\MUtil_Html::attrib('href', array('action' => 'index', 'RouteReset' => true)), 'mainform');
     if ($data) {
         $form->populate($data);
     }
     return $form;
 }