File indexing completed on 2024-12-22 05:33:35
0001 <?php 0002 /** 0003 * ocs-webserver 0004 * 0005 * Copyright 2016 by pling GmbH. 0006 * 0007 * This file is part of ocs-webserver. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 **/ 0022 0023 class Default_Form_ButtonCreate extends Zend_Form 0024 { 0025 0026 public function init() 0027 { 0028 $filterStripSlashes = new Zend_Filter_Callback('stripslashes'); 0029 0030 $title = $this->createElement('text', 'title') 0031 ->setRequired(true) 0032 //->addErrorMessage('ProjectAddFormTitleErr') 0033 ->setFilters(array('StringTrim', $filterStripSlashes)) 0034 ->addValidator('StringLength', false, array(6, 60)); 0035 0036 $url = $this->createElement('text', 'link_1', array()) 0037 ->addPrefixPath('Local_Validate', 'Local/Validate', Zend_Form_Element::VALIDATE) 0038 ->setRequired(true) 0039 ->setFilters(array('StringTrim')) 0040 ->addValidator('PartialUrl'); 0041 0042 /** @var Zend_Form_Element_Select $category */ 0043 $category = $this->createElement('Select', 'project_category_id') 0044 ->setRequired(true) 0045 ->addErrorMessage("ProjectAddFormCatErr"); 0046 $prjCatTable = new Default_Model_DbTable_ProjectCategory(); 0047 $categoryList = $prjCatTable->fetchMainCatForSelect(); 0048 $categoryValidator = new Zend_Validate_InArray(array_keys($categoryList)); 0049 $category->addValidator($categoryValidator); 0050 $category->addMultiOptions($categoryList); 0051 0052 $mailExistCheck = new Zend_Validate_Db_NoRecordExists(array('table' => 'member', 'field' => 'mail', 'exclude' => array('field' => 'is_deleted', 'value' => 1))); 0053 $mailExistCheck->setMessage('RegisterFormEmailErrAlreadyRegistered', Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND); 0054 0055 $mailValidCheck = $this->getMailValidator(); 0056 0057 $siblingNotEmptyValidator = new Local_Validate_NotEmptyXor(array('paypal_mail', 'dwolla_id')); 0058 0059 $paypal_mail = $this->createElement('text', 'paypal_mail') 0060 ->setRequired(false) 0061 ->setAllowEmpty(false) 0062 ->addValidator($siblingNotEmptyValidator, true) 0063 ->removeDecorator('HtmlTag'); 0064 0065 $dwolla_id = $this->createElement('text', 'dwolla_id') 0066 ->setRequired(false) 0067 ->setAllowEmpty(false) 0068 ->addValidator($siblingNotEmptyValidator, true) 0069 ->removeDecorator('HtmlTag'); 0070 0071 $userExistCheck = new Zend_Validate_Db_NoRecordExists(array('table' => 'member', 'field' => 'username', 'exclude' => array('field' => 'is_deleted', 'value' => 1))); 0072 $userExistCheck->setMessage('This username already exists.', Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND); 0073 $userEmptyCheck = new Zend_Validate_NotEmpty(); 0074 $userEmptyCheck->setMessage('RegisterFormUsernameErr', Zend_Validate_NotEmpty::IS_EMPTY); 0075 $userNameLength = new Zend_Validate_StringLength(array('min' => 4, 'max' => 35)); 0076 0077 $user_name = $this->createElement('text', 'username') 0078 ->setRequired(true) 0079 ->addValidator($userEmptyCheck) 0080 ->addValidator($userExistCheck) 0081 ->addValidator($userNameLength); 0082 0083 $user_mail = $this->createElement('text', 'mail') 0084 ->setRequired(true) 0085 ->addValidator($mailValidCheck, true) 0086 ->addValidator($mailExistCheck) 0087 ->removeDecorator('HtmlTag'); 0088 0089 $this->addElement($category) 0090 ->addElement($title) 0091 ->addElement($url) 0092 ->addElement($paypal_mail) 0093 ->addElement($dwolla_id) 0094 ->addElement($user_name) 0095 ->addElement($user_mail); 0096 } 0097 0098 /** 0099 * @return Zend_Validate_EmailAddress 0100 * @throws Zend_Validate_Exception 0101 */ 0102 protected function getMailValidator() 0103 { 0104 $mailValidCheck = new Zend_Validate_EmailAddress(); 0105 $mailValidCheck->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID) 0106 ->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID_FORMAT) 0107 ->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID_LOCAL_PART) 0108 ->setMessage("RegisterFormEmailErrWrongHost", Zend_Validate_EmailAddress::INVALID_HOSTNAME) 0109 ->setMessage("RegisterFormEmailErrWrongHost2", Zend_Validate_Hostname::INVALID_HOSTNAME) 0110 ->setMessage("RegisterFormEmailErrHostLocal", Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED) 0111 ->setOptions(array('domain' => TRUE)); 0112 return $mailValidCheck; 0113 } 0114 0115 public function preValidation($data) 0116 { 0117 if (!empty($data['paypal_mail'])) { 0118 $this->paypal_mail->addValidator($this->getMailValidator()); 0119 } 0120 return $this; 0121 } 0122 0123 }