diff --git a/module/Restore/src/Restore/Controller/RestoreController.php b/module/Restore/src/Restore/Controller/RestoreController.php index 196852cd..9a631f35 100644 --- a/module/Restore/src/Restore/Controller/RestoreController.php +++ b/module/Restore/src/Restore/Controller/RestoreController.php @@ -28,6 +28,7 @@ use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; use Zend\ViewModel\JsonModel; +use Restore\Model\Restore; use Restore\Form\RestoreForm; class RestoreController extends AbstractActionController @@ -42,17 +43,50 @@ public function indexAction() { if($_SESSION['bareos']['authenticated'] == true) { + $this->getRestoreParams(); + $form = new RestoreForm( $this->restore_params, $this->getJobs("long"), $this->getClients("long"), - $this->getFilesets("long") + null//$this->getFilesets("long") ); - return new ViewModel(array( - 'restore_params' => $this->restore_params, - 'form' => $form - )); + // Set the method attribute for the form + $form->setAttribute('method', 'post'); + + $request = $this->getRequest(); + + if($request->isPost()) { + + $restore = new Restore(); + $form->setInputFilter($restore->getInputFilter()); + $form->setData( $request->getPost() ); + + if($form->isValid()) { + $job = $form->getInputFilter()->getValue('job'); + $client = $form->getInputFilter()->getValue('client'); + $restoreclient = $form->getInputFilter()->getValue('restoreclient'); + $fileset = $form->getInputFilter()->getValue('fileset'); + $before = $form->getInputFilter()->getValue('before'); + $where = $form->getInputFilter()->getValue('where'); + + return $this->redirect()->toRoute('restore', array('action' => 'confirm')); + } + else { + return new ViewModel(array( + 'restore_params' => $this->restore_params, + 'form' => $form + )); + } + + } + else { + return new ViewModel(array( + 'restore_params' => $this->restore_params, + 'form' => $form + )); + } } else { diff --git a/module/Restore/src/Restore/Form/RestoreForm.php b/module/Restore/src/Restore/Form/RestoreForm.php index b1a89e46..045ffc1c 100644 --- a/module/Restore/src/Restore/Form/RestoreForm.php +++ b/module/Restore/src/Restore/Form/RestoreForm.php @@ -172,14 +172,15 @@ public function __construct($restore_params=null, $jobs=null, $clients=null, $fi // Before $this->add(array( - 'name' => 'before-date', + 'name' => 'before', 'type' => 'date', 'options' => array( 'label' => 'Before', + 'format' => 'Y-m-d' ), 'attributes' => array( 'min' => '1970-01-01', - 'max' => $this->today, + 'max' => '2020-01-01', 'step' => '1', ) ) @@ -198,8 +199,8 @@ public function __construct($restore_params=null, $jobs=null, $clients=null, $fi ) ); - // Cross site request forgery - $this->add(new Element\Csrf('security')); + // TODO - Cross site request forgery + //$this->add(new Element\Csrf('security')); // Submit button $this->add(array( @@ -252,6 +253,7 @@ private function getFilesetList() $selectData[$fileset['name']] = $fileset['name']; } } + $selectData = array('fileset-1'=>'fileset-1'); return $selectData; } diff --git a/module/Restore/src/Restore/Model/Restore.php b/module/Restore/src/Restore/Model/Restore.php index ab8d2206..a515ef11 100644 --- a/module/Restore/src/Restore/Model/Restore.php +++ b/module/Restore/src/Restore/Model/Restore.php @@ -3,9 +3,9 @@ /** * * bareos-webui - Bareos Web-Frontend - * + * * @link https://github.com/bareos/bareos-webui for the canonical source repository - * @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/) + * @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/) * * This program is free software: you can redistribute it and/or modify @@ -25,12 +25,112 @@ namespace Restore\Model; -class Restore +use Zend\InputFilter\InputFilter; +use Zend\InputFilter\InputFilterAwareInterface; +use Zend\InputFilter\InputFilterInterface; + +class Restore implements InputFilterAwareInterface { - public function exchangeArray($data) + protected $job; + protected $client; + protected $restoreclient; + protected $fileset; + protected $beforedate; + + protected $inputFilter; + + public function setInputFilter(InputFilterInterface $inputFilter) { - + throw new \Exception("setInputFiler() not used"); } - + + public function getInputFilter() + { + if(!$this->inputFilter) { + + $inputFilter = new InputFilter(); + + $inputFilter->add(array( + 'name' => 'job', + 'required' => false, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + ) + )); + + $inputFilter->add(array( + 'name' => 'client', + 'required' => false, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + ) + )); + + $inputFilter->add(array( + 'name' => 'restoreclient', + 'required' => false, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + ) + )); + + $inputFilter->add(array( + 'name' => 'fileset', + 'required' => false, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + ) + )); + + $inputFilter->add(array( + 'name' => 'before', + 'required' => false, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + ) + )); + + $inputFilter->add(array( + 'name' => 'where', + 'required' => false, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'encoding' => 'UTF-8', + 'min' => 1, + 'max' => 128 + ) + ) + ) + )); + + $this->inputFilter = $inputFilter; + + } + + return $inputFilter; + + } + } diff --git a/module/Restore/view/restore/restore/confirm.phtml b/module/Restore/view/restore/restore/confirm.phtml new file mode 100644 index 00000000..e69de29b diff --git a/module/Restore/view/restore/restore/index.phtml b/module/Restore/view/restore/restore/index.phtml index 75640a1f..b9ebb1c6 100644 --- a/module/Restore/view/restore/restore/index.phtml +++ b/module/Restore/view/restore/restore/index.phtml @@ -55,7 +55,7 @@ $this->headTitle($title); echo $this->formRow($form->get('job')->setAttribute('class', 'form-control')); echo $this->formRow($form->get('client')->setAttribute('class','form-control')); echo $this->formRow($form->get('fileset')->setAttribute('class','form-control')); - echo $this->formRow($form->get('before-date')->setAttribute('class','form-control')); + echo $this->formRow($form->get('before')->setAttribute('class','form-control')); echo $this->formRow($form->get('restoreclient')->setAttribute('class','form-control')); echo $this->formRow($form->get('where')->setAttribute('class','form-control')); break;