public function init()
 {
     $validate = new Zend_Validate_Callback('userExists');
     $validate->setMessage('Usuario inexistente!');
     $this->addElement('text', 'usuario', array('label' => 'CPF (usuario / somente numeros)*', 'required' => true, 'class' => 'campo-txt', 'validators' => array(new Zend_Validate_Int(), $validate)));
     $this->addElement('submit', 'submit_button', array('label' => 'Enviar', 'class' => 'bt-enviar', 'ignore' => true));
 }
 public function init()
 {
     $this->addElement('text', 'nome', array('label' => 'Nome*', 'required' => true, 'class' => 'campo-txt', 'validators' => array(new Zend_Validate_Alpha(true))));
     $validate = new Zend_Validate_Callback('userExists');
     $validate->setMessage('Usuário já existe!');
     $this->addElement('text', 'usuario', array('label' => 'CPF (usuario / somente numeros)*', 'required' => true, 'class' => 'campo-txt', 'validators' => array(new Zend_Validate_Between(array('min' => 1, 'max' => 99999999999)), $validate)));
     $this->addElement('password', 'senha', array('label' => 'Senha*', 'required' => true, 'class' => 'campo-txt', 'validators' => array(new Zend_Validate_Identical(Zend_Controller_Front::getInstance()->getRequest()->getParam('repita_senha')))));
     $this->addElement('password', 'repita_senha', array('label' => 'Repita a Senha*', 'required' => true, 'class' => 'campo-txt', 'validators' => array(new Zend_Validate_Identical(Zend_Controller_Front::getInstance()->getRequest()->getParam('senha')))));
     $this->addElement('submit', 'submit_button', array('label' => 'Enviar', 'class' => 'bt-enviar', 'ignore' => true));
 }
Exemplo n.º 3
0
 public function validateCompanyId($company_id)
 {
     $validator = new Zend_Validate_Callback('is_numeric');
     if ($validator->isValid((int) $company_id)) {
         return true;
     }
     $msg = Sanmax_MessageStack::getInstance($this->_messagestack_name());
     $msg->addMessage('pf_company_id', $validator->getMessages(), 'common');
     return false;
 }
Exemplo n.º 4
0
 protected function setUp()
 {
     $this->_model = new \Magento\Framework\Validator\Object();
     $fieldOneExactValue = new \Zend_Validate_Identical('field_one_value');
     $fieldOneExactValue->setMessage("'field_one' does not match expected value");
     $fieldOneLength = new \Zend_Validate_StringLength(['min' => 10]);
     $fieldTwoExactValue = new \Zend_Validate_Identical('field_two_value');
     $fieldTwoExactValue->setMessage("'field_two' does not match expected value");
     $fieldTwoLength = new \Zend_Validate_StringLength(['min' => 5]);
     $entityValidity = new \Zend_Validate_Callback([$this, 'isEntityValid']);
     $entityValidity->setMessage('Entity is not valid.');
     $this->_model->addRule($fieldOneLength, 'field_one')->addRule($fieldOneExactValue, 'field_one')->addRule($fieldTwoLength, 'field_two')->addRule($fieldTwoExactValue, 'field_two')->addRule($entityValidity);
 }
Exemplo n.º 5
0
 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('hidden', 'id', array('required' => $this->id ? true : false))->addElement('text', 'tenant', array('label' => _('Tenant'), 'readonly' => true, 'disabled' => true))->addElement('text', 'name', array('label' => _('Name'), 'required' => true))->addElement('text', 'email', array('label' => _('E-mail'), 'required' => true))->addElement('password', 'pw1', array('label' => _('Password'), 'maxlength' => 100, 'size' => 15, 'validators' => array(array('StringLength', false, array(4, 30)), array('identical', false, array('token' => 'pw2')))))->addElement('password', 'pw2', array('label' => _('Password (check)'), 'maxlength' => 100, 'size' => 15, 'validators' => array(array('identical', false, array('token' => 'pw1')))))->addElement('select', 'role', array('label' => _('Role'), 'required' => true))->addElement('radio', 'type', array('label' => _('Usertype'), 'required' => true))->addElement('text', 'apikey', array('label' => _('API Key (required for API users)'), 'required' => false))->addElement('text', 'eppn', array('label' => _('eduPersonPrincipalName (for SAML authentication)'), 'required' => false))->addElement('multiselect', 'defaultSearchProfileIds', array('label' => _('Search Profile Id'), 'required' => false))->addElement('checkbox', 'disableSearchProfileChanging', array('label' => _('Disable changing search profile'), 'required' => false))->addElement('submit', 'submit', array('label' => _('Submit')))->addElement('reset', 'reset', array('label' => _('Reset')))->addElement('submit', 'cancel', array('label' => _('Cancel')))->addElement('submit', 'delete', array('label' => _('Delete'), 'onclick' => 'return confirm(\'' . _('Are you sure you want to delete this user?') . '\');'))->addDisplayGroup(array('submit', 'reset', 'cancel', 'delete'), 'buttons');
         $form->getElement('type')->addMultiOptions(array_combine(OpenSKOS_Db_Table_Users::$types, OpenSKOS_Db_Table_Users::$types))->setSeparator(' ');
         $form->getElement('role')->addMultiOptions(array_combine(OpenSKOS_Db_Table_Users::$roles, OpenSKOS_Db_Table_Users::$roles));
         $searchProfilesModel = new OpenSKOS_Db_Table_SearchProfiles();
         $select = $searchProfilesModel->select();
         if (Zend_Auth::getInstance()->hasIdentity()) {
             $select->where('tenant=?', Zend_Auth::getInstance()->getIdentity()->tenant);
         }
         $searchProfiles = $searchProfilesModel->fetchAll($select);
         $searchProfilesOptions = array();
         foreach ($searchProfiles as $profile) {
             $searchProfilesOptions[$profile->id] = $profile->name;
         }
         $form->getElement('defaultSearchProfileIds')->addMultiOptions($searchProfilesOptions);
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueEmail'));
         $validator->setMessage(_("there is already a user with e-mail address '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('email')->addValidator($validator)->addValidator(new Zend_Validate_EmailAddress());
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueEppn'));
         $validator->setMessage(_("there is already a user with eduPersonPrincipalName '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('eppn')->addValidator($validator);
         $validator = new Zend_Validate_Callback(array($this, 'needApiKey'));
         $validator->setMessage(_("An API Key is required for users that have access to the API"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('type')->addValidator($validator, true);
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueApiKey'));
         $validator->setMessage(_("there is already a user with API key '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('apikey')->addValidator(new Zend_Validate_Alnum())->addValidator($validator)->addValidator(new Zend_Validate_StringLength(array('min' => 6)));
         $userData = $this->toArray();
         $userData['defaultSearchProfileIds'] = explode(', ', $userData['defaultSearchProfileIds']);
         $form->setDefaults($userData);
         if (!$this->id || Zend_Auth::getInstance()->hasIdentity() && Zend_Auth::getInstance()->getIdentity()->id == $this->id) {
             $form->removeElement('delete');
             if (!OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed('editor.users', 'manage')) {
                 // Currently only password edit is allowed.
                 $form->removeElement('name');
                 $form->removeElement('email');
                 $form->removeElement('role');
                 $form->removeElement('type');
                 $form->removeElement('apikey');
                 $form->removeElement('eppn');
                 $form->removeElement('defaultSearchProfileIds');
                 $form->removeElement('disableSearchProfileChanging');
             }
         }
     }
     return $form;
 }
Exemplo n.º 6
0
 public function init()
 {
     $this->setAttrib('id', 'adauga')->setAttrib('enctype', 'multipart/form-data');
     $nameValidator = new Zend_Validate_Callback(array('Gasestema_Form_Obiect_Adauga', 'verifyName'));
     $nameValidator->setMessage('Name has to be unique. Try something more specific.');
     $name = $this->createElement('text', 'name')->setLabel('Name')->addValidator($nameValidator)->setRequired(true)->addFilter('StringTrim');
     $description = $this->createElement('textarea', 'description')->setLabel('Description')->addFilter('StringTrim');
     $tags = $this->createElement('text', 'tags')->setLabel('Tags')->addFilter('StringTrim');
     $locatie = $this->createElement('text', 'locatie')->setLabel('Location')->addFilter('StringTrim');
     $locatieId = $this->createElement('hidden', 'locatie_id')->addFilter('int');
     $submit = $this->createElement('submit', 'submit')->setLabel('Add')->setAttrib('class', 'location-submit')->setDecorators(array('ViewHelper', 'Errors'));
     $this->addElements(array($name, $description, $tags, $locatie, $locatieId, $submit));
     $this->setElementDecorators(array('ViewHelper', 'Errors', array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), array('Label', array('tag' => 'td')), array(array('row' => 'HtmlTag'), array('tag' => 'tr'))), array('name', 'description', 'tags'));
 }
Exemplo n.º 7
0
 public function init()
 {
     $this->addElement('text', 'nome', array('label' => 'Nome*', 'class' => 'campo-txt', 'required' => true));
     $this->addElement('text', 'descricao', array('label' => 'Descrição*', 'class' => 'campo-txt', 'required' => true));
     $this->addElement('file', 'pFoto', array('label' => 'Foto*'));
     $validate = new Zend_Validate_Callback('validaPreco');
     $validate->setMessage('Valor negativo!');
     $this->addElement('text', 'preco', array('label' => 'Preço Em Reais*', 'class' => 'campo-txt', 'required' => true, 'validators' => array($validate)));
     $categoriaModel = new Application_Model_Categoria();
     $categorias = $categoriaModel->fetchAll($categoriaModel->select()->from($categoriaModel->info(Zend_Db_Table_Abstract::NAME))->columns(array('nome_categoria'))->where('excluido = 0'));
     $categoriasArr = array();
     foreach ($categorias as $categoria) {
         $categoriasArr[$categoria['nome_categoria']] = $categoria['nome_categoria'];
     }
     $this->addElement('select', 'categoria', array('label' => 'Categoria: ', 'class' => 'campo-txt', 'multiple' => false, 'multiOptions' => $categoriasArr, 'registerInArrayValidator' => false));
     $this->addElement('checkbox', 'promocao', array('label' => 'Promover Produto?', 'checkedValue' => 1, 'uncheckedValue' => 0));
     $this->addElement('submit', 'submit_button', array('label' => 'Salvar', 'class' => 'bt-enviar', 'ignore' => true));
 }
 public function init()
 {
     $produtoModel = new Application_Model_Produto();
     $produto = $produtoModel->fetchAll($produtoModel->select()->from($produtoModel->info(Zend_Db_Table_Abstract::NAME))->columns(array('id_produto', 'nome'))->where('excluido = 0'));
     $produtoArr = array();
     foreach ($produto as $produto) {
         $produtoArr[$produto['id_produto']] = $produto['nome'];
     }
     $this->addElement('select', 'id_produto', array('label' => 'Produto: ', 'multiple' => false, 'multiOptions' => $produtoArr, 'registerInArrayValidator' => false));
     $this->addElement('checkbox', 'opcional', array('label' => 'Opcional?', 'checkedValue' => 1, 'uncheckedValue' => 0));
     $this->addElement('checkbox', 'adicional', array('label' => 'Adicional?', 'checkedValue' => 1, 'uncheckedValue' => 0));
     $this->addElement('text', 'qtd_padrao', array('label' => 'Quantidade Padrão', 'required' => true));
     $this->addElement('text', 'qtd_max', array('label' => 'Quantidade Máxima', 'required' => true));
     $this->addElement('text', 'qtd_min', array('label' => 'Quantidade Mínima', 'required' => true));
     $validate = new Zend_Validate_Callback('validaPreco');
     $validate->setMessage('Valor negativo!');
     $this->addElement('text', 'valor', array('label' => 'Valor', 'class' => 'campo-txt', 'required' => true, 'validators' => array($validate)));
     $this->addElement('submit', 'submit_button', array('label' => 'Salvar', 'ignore' => true));
 }
Exemplo n.º 9
0
 public function init()
 {
     $produtoModel = new Application_Model_Produto();
     $produtos = $produtoModel->fetchAll($produtoModel->select()->from($produtoModel->info(Zend_Db_Table_Abstract::NAME))->columns(array('id_produto', 'nome'))->where('excluido = 0')->where('not categoria = "Combo"'));
     $produtosArr = array();
     $produtosArr[0] = 'nenhum';
     foreach ($produtos as $produto) {
         $produtosArr[$produto['id_produto']] = $produto['nome'];
     }
     $this->addElement('text', 'nome', array('label' => 'Nome*', 'class' => 'campo-txt', 'required' => true));
     $this->addElement('file', 'pFoto', array('label' => 'Foto'));
     $this->addElement('select', 'id_produto1', array('label' => 'Produto 1: ', 'class' => 'campo-txt', 'multiple' => false, 'multiOptions' => $produtosArr, 'registerInArrayValidator' => false));
     $this->addElement('select', 'id_produto2', array('label' => 'Produto 2: ', 'class' => 'campo-txt', 'multiple' => false, 'multiOptions' => $produtosArr, 'registerInArrayValidator' => false));
     $this->addElement('select', 'id_produto3', array('label' => 'Produto 3: ', 'class' => 'campo-txt', 'multiple' => false, 'multiOptions' => $produtosArr, 'registerInArrayValidator' => false));
     $this->addElement('select', 'id_produto4', array('label' => 'Produto 4: ', 'class' => 'campo-txt', 'multiple' => false, 'multiOptions' => $produtosArr, 'registerInArrayValidator' => false));
     $this->addElement('select', 'id_produto5', array('label' => 'Produto 5: ', 'class' => 'campo-txt', 'multiple' => false, 'multiOptions' => $produtosArr, 'registerInArrayValidator' => false));
     $validate = new Zend_Validate_Callback('validaPreco');
     $validate->setMessage('Valor negativo!');
     $this->addElement('text', 'preco', array('label' => 'Preço*', 'class' => 'campo-txt', 'required' => true, 'validators' => array($validate)));
     $this->addElement('submit', 'submit_button', array('label' => 'Salvar', 'class' => 'bt-enviar', 'ignore' => true));
 }
Exemplo n.º 10
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
  *
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_setValue($value);
     if (!is_string($value)) {
         $this->_error(self::INVALID, $value);
         return false;
     }
     if (!ctype_digit($value)) {
         $this->_error(self::CONTENT, $value);
         return false;
     }
     $length = strlen($value);
     $types = $this->getType();
     $foundp = false;
     $foundl = false;
     foreach ($types as $type) {
         foreach ($this->_cardType[$type] as $prefix) {
             if (substr($value, 0, strlen($prefix)) == $prefix) {
                 $foundp = true;
                 if (in_array($length, $this->_cardLength[$type])) {
                     $foundl = true;
                     break 2;
                 }
             }
         }
     }
     if ($foundp == false) {
         $this->_error(self::PREFIX, $value);
         return false;
     }
     if ($foundl == false) {
         $this->_error(self::LENGTH, $value);
         return false;
     }
     $sum = 0;
     $weight = 2;
     for ($i = $length - 2; $i >= 0; $i--) {
         $digit = $weight * $value[$i];
         $sum += floor($digit / 10) + $digit % 10;
         $weight = $weight % 2 + 1;
     }
     if ((10 - $sum % 10) % 10 != $value[$length - 1]) {
         $this->_error(self::CHECKSUM, $value);
         return false;
     }
     if (!empty($this->_service)) {
         try {
             require_once 'Zend/Validate/Callback.php';
             $callback = new Zend_Validate_Callback($this->_service);
             $callback->setOptions($this->_type);
             if (!$callback->isValid($value)) {
                 $this->_error(self::SERVICE, $value);
                 return false;
             }
         } catch (Zend_Exception $e) {
             $this->_error(self::SERVICEFAILURE, $value);
             return false;
         }
     }
     return true;
 }
Exemplo n.º 11
0
 /**
  * @see Zend_Validate_Interface::isValid()
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_setValue($value);
     $mode = $this->getSeparatorMode();
     if (self::FORMAT_SEPARATOR === $mode) {
         if (!preg_match('/^\\d{3}\\.\\d{3}\\.\\d{3}-\\d{2}$/', $value)) {
             $this->_error(self::INVALID_FORMAT);
             return false;
         }
         $value = $this->_cleanFormat($value);
     } else {
         if (self::FORMAT_AUTO === $mode) {
             if (!preg_match('/^\\d{3}\\.\\d{3}\\.\\d{3}-\\d{2}$/', $value) && !preg_match('/^\\d{11}$/', $value)) {
                 $this->_error(self::INVALID_FORMAT);
                 return false;
             }
             $value = $this->_cleanFormat($value);
         } else {
             if (self::FORMAT_CLEAN === $mode) {
                 if (!preg_match('/^\\d{11}$/', $value)) {
                     $this->_error(self::INVALID_FORMAT);
                     return false;
                 }
             }
         }
     }
     // checksum
     $check = $this->_checkSum($value, 10) && $this->_checkSum($value, 11);
     if (!$check) {
         $this->_error(self::NOT_CPF);
         return false;
     }
     if (null !== $this->_service) {
         require_once 'Zend/Validate/Callback.php';
         $callback = new Zend_Validate_Callback($this->_service);
         $callback->setOptions($this->_separatorMode);
         if (!$callback->isValid($value)) {
             $this->_error(self::SERVICE, $value);
             return false;
         }
     }
     return true;
 }
Exemplo n.º 12
0
 /**
  * Add validation rules to be applied before saving an entity
  *
  * @return \Zend_Validate_Interface $validator
  */
 public function getValidationRulesBeforeSave()
 {
     $userIdentity = new \Zend_Validate_Callback([$this, 'isUserUnique']);
     $userIdentity->setMessage(__('A user with the same user name or email already exists.'), \Zend_Validate_Callback::INVALID_VALUE);
     return $userIdentity;
 }
Exemplo n.º 13
0
 public function testAddingValueOptions()
 {
     $valid = new Zend_Validate_Callback(array('callback' => array($this, 'optionsCallback'), 'options' => 'options'));
     $this->assertEquals(array('options'), $valid->getOptions());
     $this->assertTrue($valid->isValid('test', 'something'));
 }
Exemplo n.º 14
0
 public function isUrl($value)
 {
     $validator = new Zend_Validate_Callback(array('Zend_Uri', 'check'));
     return $validator->isValid($value);
 }
Exemplo n.º 15
0
 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('hidden', 'id', array('required' => $this->id ? true : false))->addElement('text', 'code', array('label' => _('Code'), 'required' => true))->addElement('text', 'dc_title', array('label' => _('Title'), 'required' => true))->addElement('textarea', 'dc_description', array('label' => _('Description'), 'cols' => 80, 'row' => 5))->addElement('text', 'website', array('label' => _('Website')))->addElement('select', 'license', array('label' => _('Standard Licence'), 'style' => 'width: 450px;'))->addElement('text', 'license_name', array('label' => _('Custom Licence (name)')))->addElement('text', 'license_url', array('label' => _('Custom (URL)')))->addElement('checkbox', 'allow_oai', array('label' => _('Allow OpenSKOS OAI Harvesting')))->addElement('select', 'OAI_baseURL', array('label' => _('OAI baseURL'), 'style' => 'width: 450px;'))->addElement('text', 'conceptsBaseUrl', array('label' => _('Concepts base url'), 'style' => 'width: 450px;'))->addElement('submit', 'submit', array('label' => _('Submit')))->addElement('reset', 'reset', array('label' => _('Reset')))->addElement('submit', 'cancel', array('label' => _('Cancel')))->addElement('submit', 'delete', array('label' => _('Delete'), 'onclick' => 'return confirm(\'' . _('Are you sure you want to delete this collection and corresponding Concepts?') . '\');'))->addDisplayGroup(array('submit', 'reset', 'cancel', 'delete'), 'buttons');
         if (!$this->id) {
             $form->removeElement('delete');
         }
         $l = $form->getElement('license')->setOptions(array('onchange' => 'if (this.selectedIndex>0) {this.form.elements[\'license_name\'].value=this.options[this.selectedIndex].text; this.form.elements[\'license_url\'].value=this.options[this.selectedIndex].value; }'));
         $l->addMultiOption('', _('choose a standard license  or type a custom one:'), '');
         foreach (OpenSKOS_Db_Table_Collections::$licences as $key => $value) {
             $l->addMultiOption($value, $key);
         }
         $form->getElement('allow_oai')->setCheckedValue('Y')->setUncheckedValue('N');
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueCode'));
         $validator->setMessage("code '%value%' already exists", Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('code')->addValidator($validator);
         $form->getElement('OAI_baseURL')->addValidator(new OpenSKOS_Validate_Url());
         $form->setDefaults($this->toArray());
         //load OAI sources:
         $oai_providers = array('' => _('Pick a provider (or leave empty)...'));
         $bootstrap = $this->_getBootstrap();
         $instances = $bootstrap->getOption('instances');
         if (null !== $instances) {
             foreach ($instances as $instance) {
                 switch ($instance['type']) {
                     case 'openskos':
                         //fetch Collections:
                         $client = new Zend_Http_Client($instance['url'] . '/api/collections');
                         $response = $client->setParameterGet('allow_oai', 'y')->setParameterGet('format', 'json')->request('GET');
                         if ($response->isError()) {
                             throw new Zend_Exception($response->getMessage(), $response->getCode());
                         }
                         foreach (json_decode($response->getBody())->collections as $collection) {
                             $uri = $instance['url'] . '/oai-pmh/?set=' . $collection->id;
                             $oai_providers[$uri] = $collection->dc_title;
                         }
                         break;
                     case 'external':
                         $uri = rtrim($instance['url'], '?/');
                         if ($instance['set'] || $instance['metadataPrefix']) {
                             $uri .= '?';
                         }
                         if ($instance['set']) {
                             $uri .= '&set=' . $instance['set'];
                         }
                         if ($instance['metadataPrefix']) {
                             $uri .= '&metadataPrefix=' . $instance['metadataPrefix'];
                         }
                         $oai_providers[$uri] = $instance['label'];
                         break;
                     default:
                         throw new Zend_Exception('Unkown OAI instance type: ' . $instance['type']);
                 }
             }
         }
         if (!isset($oai_providers[$this->OAI_baseURL])) {
             $oai_providers[$this->OAI_baseURL] = $this->OAI_baseURL;
         }
         $form->getElement('OAI_baseURL')->setMultiOptions($oai_providers);
     }
     return $form;
 }
Exemplo n.º 16
0
 /**
  * Get old password element
  *
  * @param \Users_Model_User $row
  * @return Zend_Form_Element_Password
  */
 protected function _currentPassword(Users_Model_User $row)
 {
     $callback = new Zend_Validate_Callback(array($row, 'isPassword'));
     $callback->setMessage('Error Current Password');
     $element = new Zend_Form_Element_Password('currentPassword');
     $element->setLabel('Current Password')->addValidator($callback);
     $this->getElement('email')->setDescription('Requires current password');
     $this->getElement('password')->setDescription('Requires current password');
     return $element;
 }