/** * Checks todo export form data * * @author Atul Atri * @return bool "true" on Success, "false" otherwise */ private function CheckTodoExportForm() { $_SWIFT = SWIFT::GetInstance(); if (!SWIFT_Session::CheckCSRFHash($_POST['csrfhash'])) { SWIFT::Error($_SWIFT->Language->Get('titlecsrfhash'), $_SWIFT->Language->Get('msgcsrfhash')); return false; } $_pId = $_POST['todoproject']; $_todolistId = $_POST['todolist']; $_todo = trim($_POST['todoitem']); $_date = trim($_POST['duedate']); if (empty($_pId)) { $this->UserInterface->CheckFields('todoproject'); $this->UserInterface->Error($this->Language->Get('basecamp_error_title'), $this->Language->Get('basecamp_empty_todoproject')); return false; } if (empty($_todolistId)) { $this->UserInterface->CheckFields('todlist'); $this->UserInterface->Error($this->Language->Get('basecamp_error_title'), $this->Language->Get('basecamp_empty_todolist')); return false; } if (empty($_todo)) { $this->UserInterface->CheckFields('todoitem'); $this->UserInterface->Error($this->Language->Get('basecamp_error_title'), $this->Language->Get('basecamp_empty_todo')); return false; } if (!empty($_date) && date('m/d/Y', strtotime($_date)) != $_date) { $this->UserInterface->CheckFields('duedate'); $this->UserInterface->Error($this->Language->Get('basecamp_error_title'), $this->Language->Get('basecamp_empty_duedate')); return false; } return true; }
/** * Validate an array of input * * @author Atul Atri * * @param array $_data data to be validated e.g * array( * ['name'] => 'Atul Atri', * ['money'] => 11 * ) * @param array $_filters validators to be applied * e.g. * $_filterArray = array( * ['money'] => array( * array('float' , FILTER_FLAG_ALLOW_OCTAL | FILTER_FLAG_ALLOW_HEX, array(min_range => 1, max_range => 10), 'lang_key_invalid_float') * ), * ['name'] => array('required', 'lang_key_name_can_not_be_empty' * ) * @param bool $_breakOnError break on first error * @param bool $_markFieldInForm mark error field array * * ' * @return mixed true if $_data passed all validations, array of errors if error strings are given or empty array */ public function Validate(array $_data, array $_filters, $_breakOnError = false, $_markFieldInForm = true, $_checkCsrfHash = true) { $_errorArray = array(); $_ValidationFailed = false; if ($_checkCsrfHash && !SWIFT_Session::CheckCSRFHash($_data['csrfhash'])) { return array(SWIFT::GetInstance()->Language->Get('msgcsrfhash')); } foreach ($_data as $_key => $_value) { if (isset($_filters[$_key])) { $_filterArray = $_filters[$_key]; $_isValid = $this->IsValid($_value, $_filterArray); if ($_isValid !== true) { $_ValidationFailed = true; if (is_array($_isValid)) { $_errorArray[$_key] = $_isValid[0]; } if ($_markFieldInForm) { SWIFT::GetInstance()->UserInterface->CheckFields($_key); } if ($_breakOnError) { break; } } } } if ($_ValidationFailed) { return $_errorArray; } return true; }
/** * Checks todo export form data * * @author Atul Atri * @return bool "true" on Success, "false" otherwise */ private function CheckCodeSubmit() { $_SWIFT = SWIFT::GetInstance(); if (!SWIFT_Session::CheckCSRFHash($_POST['csrfhash'])) { SWIFT::Error($_SWIFT->Language->Get('titlecsrfhash'), $_SWIFT->Language->Get('msgcsrfhash')); return false; } if (empty($_POST['basecampcode'])) { return false; } return true; }