Index: trunk/core/kernel/utility/formatters/multilang_formatter.php =================================================================== diff -u -N -r8605 -r8842 --- trunk/core/kernel/utility/formatters/multilang_formatter.php (.../multilang_formatter.php) (revision 8605) +++ trunk/core/kernel/utility/formatters/multilang_formatter.php (.../multilang_formatter.php) (revision 8842) @@ -113,6 +113,14 @@ return $value; } + /** + * Performs required field check on primary language + * + * @param mixed $value + * @param string $field_name + * @param kDBItem $object + * @return string + */ function Parse($value, $field_name, &$object) { $lang = $this->Application->GetVar('m_lang'); @@ -122,7 +130,7 @@ if (!$this->Application->GetVar('allow_translation') && $lang != $def_lang && getArrayValue($object->Fields, $field_name, 'required')) { $def_lang_field = 'l'.$def_lang.'_'.$master_field; if ( !$object->ValidateRequired($def_lang_field, $object->Fields[$field_name]) ) { - $object->FieldErrors[$master_field]['pseudo'] = 'primary_lang_required'; + $object->SetError($master_field, 'primary_lang_required'); } } Index: trunk/core/kernel/utility/formatters/upload_formatter.php =================================================================== diff -u -N -r8693 -r8842 --- trunk/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 8693) +++ trunk/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 8842) @@ -16,12 +16,12 @@ /** - * Enter description here... + * Processes file uploads from form * * @param mixed $value * @param string $field_name * @param kDBItem $object - * @return unknown + * @return string */ function Parse($value, $field_name, &$object) { @@ -89,19 +89,19 @@ $max_filesize = isset($options['max_size']) ? $options['max_size'] : MAX_UPLOAD_SIZE; if (getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types'])) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_file_format'; + $object->SetError($field_name, 'bad_file_format'); } elseif ($value['size'] > $max_filesize) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_file_size'; + $object->SetError($field_name, 'bad_file_size'); } elseif (!is_writable($this->FullPath)) { - $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file'; + $object->SetError($field_name, 'cant_save_file'); } else { $real_name = $this->ValidateFileName($this->FullPath, $value['name']); $file_name = $this->FullPath.$real_name; if (!move_uploaded_file($value['tmp_name'], $file_name)) { - $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file'; + $object->SetError($field_name, 'cant_save_file'); } else { @chmod($file_name, 0666); @@ -125,17 +125,18 @@ } } else { - $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file'; + $object->SetError($field_name, 'cant_save_file'); } } else { if (getArrayValue($options, 'required')) { - $object->FieldErrors[$field_name]['pseudo'] = 'required'; + $object->SetError($field_name, 'required'); } } - if ((count($value) > 1) && $value['error'] && ($value['error'] != UPLOAD_ERR_NO_FILE) && !$object->FieldErrors[$field_name]['pseudo']) { - $object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file'; + // && !$object->FieldErrors[$field_name]['pseudo'] - already implemented in kDBItem::SetError method + if ((count($value) > 1) && $value['error'] && ($value['error'] != UPLOAD_ERR_NO_FILE)) { + $object->SetError($field_name, 'cant_save_file'); } return $ret; Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -N -r8719 -r8842 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8719) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8842) @@ -172,16 +172,25 @@ * @param string $pseudo * @param string $error_label */ - function SetError($field, $pseudo, $error_label = '') + function SetError($field, $pseudo, $error_label = null, $error_params = null) { $error_field = isset($this->Fields[$field]['error_field']) ? $this->Fields[$field]['error_field'] : $field; + if (isset($this->FieldErrors[$error_field]['pseudo'])) { + // don't set more then one error on field + return ; + } + $this->FieldErrors[$error_field]['pseudo'] = $pseudo; - $error_msg = $error_label ? $this->Application->Phrase($error_label) : ''; - if ($error_label && !getArrayValue($this->ErrorMsgs, $pseudo)) - { - $this->ErrorMsgs[$pseudo] = $error_msg; + if (isset($error_params)) { + // additional params, that helps to determine error sources + $this->FieldErrors[$error_field]['params'] = $error_params; } + + if (isset($error_label) && !isset($this->ErrorMsgs[$pseudo])) { + // label for error (only when not already set) + $this->ErrorMsgs[$pseudo] = (substr($error_label, 1, 1) == '+') ? substr($error_label, 1) : '!'.$error_label.'!'; + } } /** @@ -509,22 +518,18 @@ { $res = true; $val = $this->FieldValues[$field]; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; if ( $val != '' && isset($params['type']) && preg_match("#int|integer|double|float|real|numeric|string#", $params['type']) ) { $res = is_numeric($val); - if($params['type']=='string' || $res) - { + if ($params['type']=='string' || $res) { $f = 'is_'.$params['type']; settype($val, $params['type']); - $res = $f($val) && ($val==$this->FieldValues[$field]); + $res = $f($val) && ($val == $this->FieldValues[$field]); } - if (!$res) - { - $this->FieldErrors[$error_field]['pseudo'] = 'bad_type'; - $this->FieldErrors[$error_field]['params'] = $params['type']; + if (!$res) { + $this->SetError($field, 'bad_type', null, $params['type']); } } return $res; @@ -541,13 +546,14 @@ function ValidateRequired($field, $params) { $res = true; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; - if ( getArrayValue($params,'required') ) - { - $res = ( (string) $this->FieldValues[$field] != ''); + if (isset($params['required']) && $params['required']) { + $res = ((string)$this->FieldValues[$field] != ''); } + $options = $this->GetFieldOptions($field); - if (!$res && getArrayValue($options, 'formatter') != 'kUploadFormatter') $this->FieldErrors[$error_field]['pseudo'] = 'required'; + if (!$res && getArrayValue($options, 'formatter') != 'kUploadFormatter') { + $this->SetError($field, 'required'); + } return $res; } @@ -562,7 +568,6 @@ function ValidateUnique($field, $params) { $res = true; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; $unique_fields = getArrayValue($params,'unique'); if($unique_fields !== false) { @@ -588,7 +593,9 @@ $res = ($res_temp == 0) && ($res_live == 0); - if(!$res) $this->FieldErrors[$error_field]['pseudo'] = 'unique'; + if (!$res) { + $this->SetError($field, 'unique'); + } } return $res; } @@ -605,7 +612,6 @@ { $res = true; $val = $this->FieldValues[$field]; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; if ( isset($params['type']) && preg_match("#int|integer|double|float|real#", $params['type']) && strlen($val) > 0 ) { if ( isset($params['max_value_inc'])) { @@ -626,12 +632,10 @@ } } if (!$res) { - $this->FieldErrors[$error_field]['pseudo'] = 'value_out_of_range'; - if ( !isset($min_val) ) $min_val = '-∞'; if ( !isset($max_val) ) $max_val = '∞'; - $this->FieldErrors[$error_field]['params'] = Array( $min_val, $max_val ); + $this->SetError($field, 'value_out_of_range', null, Array ($min_val, $max_val)); return $res; } if ( isset($params['max_len'])) { @@ -641,8 +645,8 @@ $res = $res && strlen($val) >= $params['min_len']; } if (!$res) { - $this->FieldErrors[$error_field]['pseudo'] = 'length_out_of_range'; - $this->FieldErrors[$error_field]['params'] = Array( getArrayValue($params,'min_len'), getArrayValue($params,'max_len') ); + $error_params = Array (getArrayValue($params, 'min_len'), getArrayValue($params, 'max_len')); + $this->SetError($field, 'length_out_of_range', null, $error_params); return $res; } return $res; @@ -776,7 +780,11 @@ $this->setModifiedFlag(); - $this->raiseEvent('OnAfterItemDelete'); + if ($this->Conn->getAffectedRows() > 0) { + // something was actually deleted + $this->raiseEvent('OnAfterItemDelete'); + } + if ($this->mode != 't') { $this->Application->resetCounters($this->TableName); } Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -N -r8586 -r8842 --- trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 8586) +++ trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 8842) @@ -302,12 +302,12 @@ function ValidateRequired($field, $params) { $res = true; - $error_field = isset($params['error_field']) ? $params['error_field'] : $field; - if ( getArrayValue($params,'required') ) - { + if (getArrayValue($params, 'required')) { $res = ( (string) $this->FieldValues[$field] != ''); } - if (!$res) $this->FieldErrors[$error_field]['pseudo'] = 'required'; + if (!$res) { + $this->SetError($field, 'required'); + } return $res; } Index: trunk/core/units/users/users_event_handler.php =================================================================== diff -u -N -r8796 -r8842 --- trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 8796) +++ trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 8842) @@ -633,13 +633,14 @@ * * @param kEvent $event */ - function OnRecommend(&$event){ - + function OnRecommend(&$event) + { $friend_email = $this->Application->GetVar('friend_email'); $friend_name = $this->Application->GetVar('friend_email'); // used for error reporting only -> rewrite code + theme (by Alex) $object =& $this->Application->recallObject('u', null, Array('skip_autoload' => true)); // TODO: change theme too + /* @var $object UsersItem */ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $friend_email)) { @@ -648,7 +649,7 @@ $send_params['to_name']=$friend_name; $user_id = $this->Application->RecallVar('user_id'); - $email_event = &$this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params); + $email_event =& $this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params); if ($email_event->status == erSUCCESS){ $event->redirect_params = array('opener' => 's', 'pass' => 'all'); @@ -658,14 +659,12 @@ // $event->redirect_params = array('opener' => 's', 'pass' => 'all'); // $event->redirect = $this->Application->GetVar('template_fail'); - $object->ErrorMsgs['send_error'] = $this->Application->Phrase('lu_email_send_error'); - $object->FieldErrors['Email']['pseudo'] = 'send_error'; + $object->SetError('Email', 'send_error', 'lu_email_send_error'); $event->status = erFAIL; } } else { - $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail'); - $object->FieldErrors['Email']['pseudo'] = 'invalid_email'; + $object->SetError('Email', 'invalid_email', 'lu_InvalidEmail'); $event->status = erFAIL; } } @@ -720,8 +719,9 @@ else { // used for error reporting only -> rewrite code + theme (by Alex) $object =& $this->Application->recallObject('u', null, Array('skip_autoload' => true)); // TODO: change theme too - $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail'); - $object->FieldErrors['SubscribeEmail']['pseudo'] = 'invalid_email'; + /* @var $object UsersItem */ + + $object->SetError('SubscribeEmail', 'invalid_email', 'lu_InvalidEmail'); $event->status = erFAIL; } } @@ -819,29 +819,32 @@ function OnForgotPassword(&$event) { - $user_object = &$this->Application->recallObject('u.forgot', null, Array('skip_autoload' => true)); + $user_object =& $this->Application->recallObject('u.forgot', null, Array('skip_autoload' => true)); + /* @var $user_object UsersItem */ // used for error reporting only -> rewrite code + theme (by Alex) $user_current_object =& $this->Application->recallObject('u', null, Array('skip_autoload' => true)); // TODO: change theme too + /* @var $user_current_object UsersItem */ $username = $this->Application->GetVar('username'); $email = $this->Application->GetVar('email'); $found = false; $allow_reset = true; - if( strlen($username) ) - { - if( $user_object->Load(array('Login'=>$username)) ) - $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password")); + if (strlen($username)) { + $user_object->Load($username, 'Login'); + if ($user_object->isLoaded()) { + $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password")); + } } - else if( strlen($email) ) - { - if( $user_object->Load(array('Email'=>$email)) ) - $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password")); + else if(strlen($email)) { + $user_object->Load($email, 'Email'); + if ($user_object->isLoaded()) { + $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password")); + } } - if( $user_object->isLoaded() ) - { + if ($user_object->isLoaded()) { $PwResetConfirm = $user_object->GetDBField('PwResetConfirm'); $PwRequestTime = $user_object->GetDBField('PwRequestTime'); $PassResetTime = $user_object->GetDBField('PassResetTime'); @@ -853,43 +856,34 @@ adodb_mktime() > $PassResetTime + $MinPwResetDelay); } - if($found && $allow_reset) - { + if ($found && $allow_reset) { $this->Application->StoreVar('tmp_user_id', $user_object->GetDBField("PortalUserId")); $this->Application->StoreVar('tmp_email', $user_object->GetDBField("Email")); $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId")); $event->redirect = $this->Application->GetVar('template_success'); } - else - { - if(!strlen($username) && !strlen($email)) - { - $user_current_object->ErrorMsgs['forgotpw_nodata'] = $this->Application->Phrase('lu_ferror_forgotpw_nodata'); - $user_current_object->FieldErrors['Login']['pseudo'] = 'forgotpw_nodata'; - $user_current_object->FieldErrors['Email']['pseudo'] = 'forgotpw_nodata'; + else { + if (!strlen($username) && !strlen($email)) { + $user_current_object->SetError('Login', 'forgotpw_nodata', 'lu_ferror_forgotpw_nodata'); + $user_current_object->SetError('Email', 'forgotpw_nodata', 'lu_ferror_forgotpw_nodata'); } - else - { - if($allow_reset) - { - if( strlen($username) ){ - $user_current_object->ErrorMsgs['unknown_username'] = $this->Application->Phrase('lu_ferror_unknown_username'); - $user_current_object->FieldErrors['Login']['pseudo']='unknown_username'; + else { + if ($allow_reset) { + if (strlen($username)) { + $user_current_object->SetError('Login', 'unknown_username', 'lu_ferror_unknown_username'); } - if( strlen($email) ){ - $user_current_object->ErrorMsgs['unknown_email'] = $this->Application->Phrase('lu_ferror_unknown_email'); - $user_current_object->FieldErrors['Email']['pseudo']='unknown_email'; + if (strlen($email)) { + $user_current_object->SetError('Email', 'unknown_email', 'lu_ferror_unknown_email'); } } - else - { - $user_current_object->ErrorMsgs['reset_denied'] = $this->Application->Phrase('lu_ferror_reset_denied'); - if( strlen($username) ){ - $user_current_object->FieldErrors['Login']['pseudo']='reset_denied'; + else { + if (strlen($username)) { + $user_current_object->SetError('Login', 'reset_denied', 'lu_ferror_reset_denied'); } - if( strlen($email) ){ - $user_current_object->FieldErrors['Email']['pseudo']='reset_denied'; + + if (strlen($email)) { + $user_current_object->SetError('Email', 'reset_denied', 'lu_ferror_reset_denied'); } } } @@ -898,7 +892,6 @@ $event->redirect = false; } } - } /** @@ -929,13 +922,13 @@ // used for error reporting only -> rewrite code + theme (by Alex) $user_current_object =& $this->Application->recallObject('u', null, Array('skip_autoload' => true));// TODO: change theme too + /* @var $user_current_object UsersItem */ if (strlen(trim($passed_key)) == 0) { $event->redirect_params = array('opener' => 's', 'pass' => 'all'); $event->redirect = false; - $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid'); - $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid'; + $user_current_object->SetError('PwResetConfirm', 'code_is_not_valid', 'lu_code_is_not_valid'); } @@ -973,14 +966,12 @@ $user_object->Update(); } else { - $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired'); - $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired'; + $user_current_object->SetError('PwResetConfirm', 'code_expired', 'lu_code_expired'); $event->redirect = false; } } else { - $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid'); - $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid'; + $user_current_object->SetError('PwResetConfirm', 'code_is_not_valid', 'lu_code_is_not_valid'); $event->redirect = false; } Index: trunk/core/kernel/utility/formatters/formatter.php =================================================================== diff -u -N -r7635 -r8842 --- trunk/core/kernel/utility/formatters/formatter.php (.../formatter.php) (revision 7635) +++ trunk/core/kernel/utility/formatters/formatter.php (.../formatter.php) (revision 8842) @@ -87,7 +87,14 @@ return $tc_value; } -//function Parse($value, $options, &$errors) + /** + * Performs basic type validation on form field value + * + * @param mixed $value + * @param string $field_name + * @param kDBItem $object + * @return mixed + */ function Parse($value, $field_name, &$object) { if ($value == '') return NULL; @@ -96,16 +103,15 @@ $tc_value = $this->TypeCast($value,$options); if($tc_value === false) return $value; // for leaving badly formatted date on the form - if( isset($options['type']) ) - { - if( preg_match('#double|float|real|numeric#', $options['type']) ) $tc_value = str_replace(',', '.', $tc_value); + if(isset($options['type'])) { + if (preg_match('#double|float|real|numeric#', $options['type'])) { + $tc_value = str_replace(',', '.', $tc_value); + } } - if( isset($options['regexp']) ) - { - if( !preg_match($options['regexp'], $value) ) - { - $object->FieldErrors[$field_name]['pseudo'] = 'invalid_format'; + if (isset($options['regexp'])) { + if (!preg_match($options['regexp'], $value)) { + $object->SetError($field_name, 'invalid_format'); } } Index: trunk/core/kernel/utility/formatters/left_formatter.php =================================================================== diff -u -N -r5340 -r8842 --- trunk/core/kernel/utility/formatters/left_formatter.php (.../left_formatter.php) (revision 5340) +++ trunk/core/kernel/utility/formatters/left_formatter.php (.../left_formatter.php) (revision 8842) @@ -10,7 +10,6 @@ */ class kLEFTFormatter extends kFormatter { -//function Format($value, $options, &$errors) function Format($value, $field_name, &$object, $format=null) { if ( is_null($value) ) return ''; @@ -29,25 +28,40 @@ return $options['options'][$value]; } -//function Parse($value, $options, &$errors) + /** + * Parse value from form submit + * + * @param mixed $value + * @param string $field_name + * @param kDBItem $object + * @return mixed + */ function Parse($value, $field_name, &$object) { if ($value == '') return NULL; $options = $object->GetFieldOptions($field_name); - if( !array_search($value,$options['options']) ) - { - // required option is not defined in config => query for it - $db =& $this->Application->GetADODBConnection(); - $sql = sprintf($options['left_sql'],$options['left_key_field'],$options['left_title_field'],$value); - $found = $db->GetOne($sql); - if($found !== false) $options['options'][$found] = $value; + $found = isset($options['options']) && array_search($value, $options['options']); + if ($found !== false) { + // requested option found among field options + return $found; } - else - { - $found = array_search($value,$options['options']); + + // requested option is not found in field options -> query for it + $db =& $this->Application->GetADODBConnection(); + $sql = sprintf($options['left_sql'], $options['left_key_field'], $options['left_title_field'], $value); + $found = $db->GetOne($sql); + if ($found !== false) { + // option successfully retrieved from db -> cache it + $options['options'][$found] = $value; } - if($found === false) $found = $options['default']; + + if ($found === false) { + // option not found at all -> return not formatted value & set error + $object->SetError($field_name, 'invalid_option', 'la_error_InvalidOption'); + return $value; + } + return $found; } } \ No newline at end of file Index: trunk/core/kernel/utility/formatters/password_formatter.php =================================================================== diff -u -N -r7635 -r8842 --- trunk/core/kernel/utility/formatters/password_formatter.php (.../password_formatter.php) (revision 7635) +++ trunk/core/kernel/utility/formatters/password_formatter.php (.../password_formatter.php) (revision 8842) @@ -35,6 +35,14 @@ return $value; } + /** + * Performs password & verify password field validation + * + * @param mixed $value + * @param string $field_name + * @param kDBItem $object + * @return string + */ function Parse($value, $field_name, &$object) { $options = $object->GetFieldOptions($field_name); @@ -81,20 +89,16 @@ } $min_length = $this->Application->ConfigValue('Min_Password'); - if( strlen($new_password) >= $min_length ) - { - if($new_password != $verify_password) - { - $object->ErrorMsgs['passwords_do_not_match'] = $this->Application->Phrase('lu_passwords_do_not_match'); - $object->FieldErrors[$password_field]['pseudo'] = 'passwords_do_not_match'; - $object->FieldErrors[$verify_field]['pseudo'] = 'passwords_do_not_match'; + if (strlen($new_password) >= $min_length) { + if ($new_password != $verify_password) { + $object->SetError($password_field, 'passwords_do_not_match', 'lu_passwords_do_not_match'); + $object->SetError($verify_field, 'passwords_do_not_match', 'lu_passwords_do_not_match'); } } - else - { - $object->ErrorMsgs['passwords_min_length'] = sprintf($this->Application->Phrase('lu_passwords_too_short'), $min_length); - $object->FieldErrors[$password_field]['pseudo'] = 'passwords_min_length'; - $object->FieldErrors[$verify_field]['pseudo'] = 'passwords_min_length'; + else { + $error_msg = '+'.sprintf($this->Application->Phrase('lu_passwords_too_short'), $min_length); // + -> not phrase + $object->SetError($password_field, 'passwords_min_length', $error_msg); + $object->SetError($verify_field, 'passwords_min_length', $error_msg); } } if($value == '') return $object->GetDBField($field_name); Index: trunk/core/units/users/users_tag_processor.php =================================================================== diff -u -N -r8757 -r8842 --- trunk/core/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 8757) +++ trunk/core/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 8842) @@ -85,11 +85,10 @@ // used for error reporting only -> rewrite code + theme (by Alex) $user_current_object = &$this->Application->recallObject('u', null, Array('skip_autoload' => true)); // TODO: change theme too + /* @var $user_current_object UsersItem */ if (strlen(trim($passed_key)) == 0) { - - $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid'); - $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid'; + $user_current_object->SetError('PwResetConfirm', 'code_is_not_valid', 'lu_code_is_not_valid'); return false; } @@ -101,15 +100,13 @@ } else { - $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired'); - $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired'; + $user_current_object->SetError('PwResetConfirm', 'code_expired', 'lu_code_expired'); return false; } } else { - $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid'); - $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid'; + $user_current_object->SetError('PwResetConfirm', 'code_is_not_valid', 'lu_code_is_not_valid'); return false; } Index: trunk/core/kernel/utility/formatters/ccdate_formatter.php =================================================================== diff -u -N -r4758 -r8842 --- trunk/core/kernel/utility/formatters/ccdate_formatter.php (.../ccdate_formatter.php) (revision 4758) +++ trunk/core/kernel/utility/formatters/ccdate_formatter.php (.../ccdate_formatter.php) (revision 8842) @@ -37,7 +37,7 @@ * * @param string $value * @param string $field_name - * @param kDBase $object + * @param kDBItem $object * @return string */ function Parse($value, $field_name, &$object) @@ -52,7 +52,9 @@ if( !(int)$month && !(int)$year ) return NULL; $is_valid = ($month >= 1 && $month <= 12) && ($year >= 0 && $year <= 99); - if(!$is_valid) $object->FieldErrors[$field_name]['pseudo'] = 'bad_type'; + if (!$is_valid) { + $object->SetError($field_name, 'bad_type'); + } return $month.'/'.$year; } Index: trunk/core/kernel/utility/formatters/date_formatter.php =================================================================== diff -u -N -r8567 -r8842 --- trunk/core/kernel/utility/formatters/date_formatter.php (.../date_formatter.php) (revision 8567) +++ trunk/core/kernel/utility/formatters/date_formatter.php (.../date_formatter.php) (revision 8842) @@ -257,7 +257,14 @@ return $res; } -//function Parse($value, $options, &$errors) + /** + * Converts formatted date+time to timestamp and validates format + * + * @param mixed $value + * @param string $field_name + * @param kDBItem $object + * @return string + */ function Parse($value, $field_name, &$object) { $options = $object->GetFieldOptions($field_name); @@ -268,10 +275,11 @@ //return strtotime($value); $format = $options['input_format']; - if($dt_separator) $format = trim($format, $dt_separator); + if ($dt_separator) $format = trim($format, $dt_separator); - $object->FieldErrors[$field_name]['params'] = Array( $this->HumanFormat($format), adodb_date($format) ); - $object->FieldErrors[$field_name]['value'] = $value; + $error_field = isset($this->Fields[$field_name]['error_field']) ? $this->Fields[$field_name]['error_field'] : $field_name; + $object->FieldErrors[$error_field]['params'] = Array( $this->HumanFormat($format), adodb_date($format) ); + $object->FieldErrors[$error_field]['value'] = $value; $hour = 0; $minute = 0; @@ -297,7 +305,7 @@ $holders_mask = eregi_replace('[a-zA-Z]{1}', '([a-zA-Z]{1})', $format); if (!ereg($holders_mask, $format, $holders)) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; } @@ -308,7 +316,7 @@ // echo " values_mask : $values_mask
"; if (!preg_match($values_mask, $value, $values)) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; } @@ -362,35 +370,35 @@ //echo "day: $day, month: $month, year: $year, hour: $hour, minute: $minute
"; /*if (!($year >= 1970 && $year <= 2037)) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; }*/ if (!($month >= 1 && $month <= 12)) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; } $months_days = Array ( 1 => 31,2 => 28, 3 => 31, 4 => 30,5 => 31,6 => 30, 7 => 31, 8 => 31,9 => 30,10 => 31,11 => 30,12 => 31); if ($year % 4 == 0) $months_days[2] = 29; if (!($day >=1 && $day <= $months_days[$month])) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; } if (!($hour >=0 && $hour <= 23)) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; } if (!($minute >=0 && $minute <= 59)) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; } if (!($second >=0 && $second <= 59)) { - $object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format'; + $object->SetError($field_name, 'bad_date_format'); return $value; }