Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Restore Form Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed May 21, 2015
1 parent a357045 commit 74f720e
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 16 deletions.
44 changes: 39 additions & 5 deletions module/Restore/src/Restore/Controller/RestoreController.php
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions module/Restore/src/Restore/Form/RestoreForm.php
Expand Up @@ -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',
)
)
Expand All @@ -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(
Expand Down Expand Up @@ -252,6 +253,7 @@ private function getFilesetList()
$selectData[$fileset['name']] = $fileset['name'];
}
}
$selectData = array('fileset-1'=>'fileset-1');
return $selectData;
}

Expand Down
112 changes: 106 additions & 6 deletions module/Restore/src/Restore/Model/Restore.php
Expand Up @@ -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
Expand All @@ -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;

}

}
Empty file.
2 changes: 1 addition & 1 deletion module/Restore/view/restore/restore/index.phtml
Expand Up @@ -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;
Expand Down

0 comments on commit 74f720e

Please sign in to comment.