fieldname__validate function
Archived from the Xataface Users forum.
ststoddard — Mon Nov 05, 2007 4:16 pm
Hello, a question regarding the validate function. I attempted the following per the documentation:
- Code: Select all
function location_code__validate(&$record,$value,$params) { $app =& Dataface_application::getInstance(); $auth =& Dataface_AuthenticationTool::getInstance(); if ( $value == 'test' ) { $params['message'] = "no!"; return false; } }
As a test after failed attempts using a more complex validation condition. Basically, the message doesn’t come through. I get the form back with the field highlighted and the message saying “Permission Denied”.
Am I doing something wrong?
FYI Steve – I had to re-register with the user forum as it wouldn’t accept my old username.
shannah — Mon Nov 05, 2007 4:36 pm
Try passing $params by reference:
- Code: Select all
function location_code__validate(&$record,$value,&$params) { ...
inmisia — Tue Nov 06, 2007 2:36 am
HI,
I have same problems with:
- Code: Select all
function Valore__validate( &$record, $value, &$params){ if ( $value>10 or $value<0 ){ $params['message'] = "Valore non valido."; return false; } else { return true; }
and pass &$params by reference.
I get this error:
Fatal error: [pear_error: message=”Valore non valido.” code=211 mode= level=notice prefix=”” info=”On line 77 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 1447 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function permissionDenied(Valore non valido.)
shannah — Tue Nov 06, 2007 6:14 am
Yes.. this appears to be a bug. In Dataface/QuickForm.php around line 1447, you will find some code:
- Code: Select all
if ( !$this->_record->validate($fieldname, $value, $params) ){ return Dataface_Error::permissionDenied($params['message']); }
Comment this out or remove it… that should fix the issue.
inmisia — Tue Nov 06, 2007 6:24 am
Hi,
I have Comment it, but now there isn’t error message when field is not valid
shannah — Tue Nov 06, 2007 8:26 am
OK.. I have reviewed the source and run tests on it and it appears to be working fine for me with version 0.7.1.
Please undo the changes that I suggested earlier. That code is a good failsafe.
Which leads me to ask: which version of Dataface are you running?
inmisia — Tue Nov 06, 2007 8:58 am
Hi,
I’m using version 0.7.1. too, I get this error:
Fatal error: [pear_error: message=”Valore non valido.” code=211 mode= level=notice prefix=”” info=”On line 77 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 1447 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function permissionDenied(Valore non valido.)
On line 1320 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function pushField(Valore)
On line 2016 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function push()
On line of file in function save(array(28,1,15,2007-11-13,Save,2,array(2),,edit,0,analisi,0,30,browse,Record successfully saved.
,)
On line 1608 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\lib\HTML\QuickForm.php in function call_user_func(array(Dataface_QuickForm Object,save),array(28,1,15,2007-11-13,Save,2,array(2),,edit,0,analisi,0,30,browse,Record successfully saved.
,)
On line in E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php on line 2046
shannah — Tue Nov 06, 2007 10:37 am
Do you get this error when adding a new record, editing an existing record, or both?
inmisia — Wed Nov 07, 2007 4:04 am
HI,
I get this error in both case, I’m using XAMPP per Windows Version 1.5.1
with:Apache/2.2.0 (Win32),PHP/5.1.1
I have another question about validate, is posible view a value of another fields? Example with $record->val(‘IDtipoAnalisi’), but I have view a value from form.
shannah — Wed Nov 07, 2007 3:13 pm
I can’t seem to reproduce this behavior.
Stephen, can you confirm that you are still having problems with this one?
-Steve
inmisia — Fri Nov 09, 2007 4:39 am
Hi, and about second question? Is it possible validate a field using
a value from other form field?
shannah — Sat Nov 10, 2007 10:03 am
Absolutely.
The first parameter to your validate method &$record is a Dataface_Record object of the current record.
You can get the value of any field using $record->val(‘fieldname’)
inmisia — Mon Nov 12, 2007 12:34 am
Hi, I need to validate a field using e value on form, not in table.
Ex if validate run on insert, $record->val(‘fieldname’) is void.
shannah — Mon Nov 12, 2007 5:46 am
Oh.. yes. For this you should just use the values in the $_POST array.
e.g.
- Code: Select all
if ($_POST['fieldname'] == 'somevalue'){ // do something ... } else { // do somethine else }
inmisia — Tue Nov 13, 2007 2:53 am
Hi, was come back!!
I try with XAMPP Version 1.6.4 for Windows XP Professional service pack 2
( * Apache HTTPD 2.2.6 + Openssl 0.9.8e
* MySQL 5.0.45
* PHP 5.2.4
* PHP 4.4.7
* phpMyAdmin 2.11.1
* Zend Optimizer 3.3.0 )
and I get same error:
Fatal error: [pear_error: message=”Valore non valido. range:” code=211 mode= level=notice prefix=”” info=”On line 77 of file C:\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 1447 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function permissionDenied(Valore non valido. range:)
On line 1320 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function pushField(Valore)
On line 2016 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function push()
On line of file in function save(array(28,1,45,2007-11-05,Save,3,array(3),,edit,0,analisi,0,30,browse,-action=edit&-cursor=0&-table=a)
On line 1608 of file C:\xampp\htdocs\dataface\lib\HTML\QuickForm.php in function call_user_func(array(Dataface_QuickForm Object,save),array(28,1,45,2007-11-05,Save,3,array(3),,edit,0,analisi,0,30,browse,-action=edit&-cursor=0&-table=a)
On line 103 of file C:\xampp\htdocs\dataface\actions\edit.php in function process(array(Dataface_QuickForm Object,save))
On l in C:\xampp\htdocs\dataface\Dataface\QuickForm.php on line 2046
What OS are you using? Linux? Next I will try with OpenSuse 10.3
inmisia — Fri Nov 09, 2007 4:39 am
Hi, and about second question? Is it possible validate a field using
a value from other form field?
shannah — Sat Nov 10, 2007 10:03 am
Absolutely.
The first parameter to your validate method &$record is a Dataface_Record object of the current record.
You can get the value of any field using $record->val(‘fieldname’)
inmisia — Mon Nov 12, 2007 12:34 am
Hi, I need to validate a field using e value on form, not in table.
Ex if validate run on insert, $record->val(‘fieldname’) is void.
shannah — Mon Nov 12, 2007 5:46 am
Oh.. yes. For this you should just use the values in the $_POST array.
e.g.
- Code: Select all
if ($_POST['fieldname'] == 'somevalue'){ // do something ... } else { // do somethine else }
inmisia — Tue Nov 13, 2007 2:53 am
Hi, was come back!!
I try with XAMPP Version 1.6.4 for Windows XP Professional service pack 2
( * Apache HTTPD 2.2.6 + Openssl 0.9.8e
* MySQL 5.0.45
* PHP 5.2.4
* PHP 4.4.7
* phpMyAdmin 2.11.1
* Zend Optimizer 3.3.0 )
and I get same error:
Fatal error: [pear_error: message=”Valore non valido. range:” code=211 mode= level=notice prefix=”” info=”On line 77 of file C:\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 1447 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function permissionDenied(Valore non valido. range:)
On line 1320 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function pushField(Valore)
On line 2016 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function push()
On line of file in function save(array(28,1,45,2007-11-05,Save,3,array(3),,edit,0,analisi,0,30,browse,-action=edit&-cursor=0&-table=a)
On line 1608 of file C:\xampp\htdocs\dataface\lib\HTML\QuickForm.php in function call_user_func(array(Dataface_QuickForm Object,save),array(28,1,45,2007-11-05,Save,3,array(3),,edit,0,analisi,0,30,browse,-action=edit&-cursor=0&-table=a)
On line 103 of file C:\xampp\htdocs\dataface\actions\edit.php in function process(array(Dataface_QuickForm Object,save))
On l in C:\xampp\htdocs\dataface\Dataface\QuickForm.php on line 2046
What OS are you using? Linux? Next I will try with OpenSuse 10.3
shannah — Tue Nov 13, 2007 5:24 am
This is bizarre. You shouldn’t have to try different installs… it should just work. (i.e. I have it running and tested on Linux, OS X, Windows XP/Apache, Windows XP/XAMPP, and Solaris).
Any chance you can give me access to the source so that I can do some debugging?
inmisia — Tue Nov 13, 2007 6:01 am
Of course! I can send source with export of database to your email
steve_hannah@sfu.ca if you wont.
inmisia — Tue Nov 13, 2007 7:14 am
file:analisi.php
val(‘IDtipoAnalisi’);
$app =& Dataface_Application::getInstance();
$res = mysql_query($sql, $app->db()) or
die (“Errore in tables_analisi on query:”.$sql.” code”. mysql_error());
$riga = mysql_fetch_array($res, MYSQL_NUM);
eval(“$ret=$riga[0];”);
mysql_free_result($res);
*/
if ($value > 40 or $value <100>val(‘IDtipoAnalisi’);
$app =& Dataface_Application::getInstance();
$res = mysql_query($sql, $app->db()) or
die (“Errore in tables_analisi on query:”.$sql.” code”. mysql_error());
$riga = mysql_fetch_array($res, MYSQL_NUM);
$value=$record->value(“Valore”);
eval(“$ret=$riga[0];”);
if($ret)
{
return “”.$record->value(“Valore”).””;
}
else
{
return $record->value(“Valore”).”#”;
}
}
}
?>
CREATE TABLE analisi (
IDAnalisi bigint(20) NOT NULL auto_increment,
IDAnagrafica bigint(20) default NULL,
IDtipoAnalisi bigint(20) default NULL,
Valore decimal(10,0) default NULL,
Data date default NULL,
PRIMARY KEY (IDAnalisi)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
SET SQL_MODE=@OLD_SQL_MODE;
shannah — Tue Nov 13, 2007 1:02 pm
[quote=”inmisia”]Of course! I can send source with export of database to your email
steve_hannah@sfu.ca if you wont.
shannah — Thu Nov 15, 2007 9:51 am
Thanks for sending your code. I have nailed down the issue. You need to change the validate() method in lib/HTML/QuickForm.php
The method starts out like:
- Code: Select all
- `if (count($this->_rules) == 0 && count($this->_formRules) == 0 &&
$this->isSubmitted()) {
return true;
} elseif (!$this->isSubmitted()) {
return false;
}….`
Change it to:
- Code: Select all
if (count($this->_rules) == 0 && count($this->_formRules) == 0 && $this->isSubmitted()) { return (count($this->_errors) == 0); } elseif (!$this->isSubmitted()) { return false; } ....
Best regards
Steve
inmisia — Fri Nov 16, 2007 12:27 am
HI! Thanks It wotks!!
Great Job!
fantomasdm — Tue Jul 01, 2008 6:27 am
Hi! I have a fucntion
- Code: Select all
function Codice__validate( &$record, $value, &$params) { if ( substr ($value,0,2) !='BM' ) { $params['message'] = $this->local('biomolecolareCodeError'); Dataface_Error::permissionDenied($this->local('biomolecolareCodeError')); return false; } else { return true; } }
for validate field Codice, but if I add in config.ini language section my error message is no more visible, instread i get classic “permission denied”
without language session I get right message.
Thank for help, sorry for my English..
shannah — Wed Jul 02, 2008 9:40 am
What does your local() method look like?
fantomasdm — Thu Jul 03, 2008 12:24 am
base class is:
- Code: Select all
- `class local_class {
var $lg;
private $ar;
function local_class()
{
$app =& Dataface_Application::getInstance();
if ( $app->_conf[‘lang’] ==”it” || $app->_conf[‘lang’] ==”en” )
$this->lg = $app->_conf[‘lang’];
else
$this->lg = “it”;
$this->loadArray();
}
private function loadArray()
{
$this->ar= array();
$this->ar[‘it’]= array();
$this->ar[‘en’]= array();
$this->ar[‘it’][‘cryptModeOn’]=”Il sistema sta girando in modo Criptato”;
$this->ar[‘it’][‘cryptModeOff’]=”Il sistema sta girando in modo tutto visibile”;
$this->ar[‘it’][‘getPwdCrypt’]=”Inserire la Password di Criptazione:”;
$this->ar[‘it’][‘pwdCryptErr’]=”Occore prima inserire la chiave di criptazione”;
$this->ar[‘it’][‘reportAlreadyClose’]=”Il referto è giàstato chiuso!!”;
$this->ar[‘it’][‘reportClose’]=”Il referto è stato chiuso, non saràpiù possibile modificarlo salvo autorizzazione!!”;
$this->ar[‘it’][‘autopsiaCodeError’]=”Il codice delle autopsie deve iniziare per A!”;
$this->ar[‘it’][‘istochimicaCodeError’]=”Il codice delle autopsie deve iniziare per IC”;
$this->ar[‘it’][‘biomolecolareCodeError’]=”Il codice delle autopsie deve iniziare per BM”;
$this->ar[‘it’][‘citologiaCodeError’]=”Il codice delle autopsie deve iniziare per C”;
$this->ar[‘it’][‘imistochimicaCodeError’]=”Il codice delle autopsie deve iniziare per IM”;
$this->ar[‘it’][‘istologiaCodeError’]=”Il codice delle autopsie deve iniziare per I”;$this->ar[‘en’][‘cryptModeOn’]=”The system is running in crypt mode on”;
$this->ar[‘en’][‘cryptModeOff’]=”The system is running in crypt mode off”;
$this->ar[‘en’][‘getPwdCrypt’]=”Insert key for encrypt data:”;
$this->ar[‘en’][‘pwdCryptErr’]=”Need to insert key for encrypt data”;
$this->ar[‘en’][‘reportAlreadyClose’]=”Report has been already closed!!”;
$this->ar[‘en’][‘reportClose’]=”The report was closed, you can not change it unless authorized”;
$this->ar[‘en’][‘autopsiaCodeError’]=”The code of autopsies must begin for A”;
$this->ar[‘en’][‘istochimicaCodeError’]=”The code of autopsies must begin for IC”;
$this->ar[‘en’][‘biomolecolareCodeError’]=”The code of autopsies must begin for BM”;
$this->ar[‘en’][‘citologiaCodeError’]=”The code of autopsies must begin for C”;
$this->ar[‘en’][‘imistochimicaCodeError’]=”The code of autopsies must begin for IM”;
$this->ar[‘en’][‘istologiaCodeError’]=”The code of autopsies must begin for I”;
}
function local($str)
{
if ($this->ar[$this->lg][$str]==””)
return “Localization not found!!”;
else
return $this->ar[$this->lg][$str];
}
}`
first derivate:
- Code: Select all
- `include_once(“local.php”);
class table_class extends local_class {var $td;
var $iv;
function table_class(){
$this->td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, ‘’, MCRYPT_MODE_ECB, ‘’);
$this->iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($this->td), MCRYPT_RAND);
parent::__construct();
}function __destruct() {
mcrypt_module_close($this->td);
}function gdecrypt($input)
{
if( isset($_SESSION[“PWDCRYPT”]) and $input!=”” )
{
$key=$_SESSION[“PWDCRYPT”];
mcrypt_generic_init($this->td, $key, $this->iv);$encrypted_data = mdecrypt_generic ($this->td, $input);
mcrypt_generic_deinit($this->td);
return rtrim( $encrypted_data, ( ( ord(substr( $encrypted_data, strlen( $encrypted_data )-1, 1 )) >= 0 and ord(substr( $encrypted_data, strlen( $encrypted_data )-1, 1 ) ) <= 16 ) ? chr(ord(substr( $encrypted_data, strlen( $encrypted_data )-1, 1 ))): null) );
}
else
{
return $input;
}
}function gcrypt($input)
{
if( !isset($_SESSION[“PWDCRYPT”]) )
{
$form_html = “”.$this->local(‘pwdCryptErr’).””;
df_display(array(‘form’=>$form_html), ‘chiudi.html’);
exit;
}
if ( $input!=”” )
{
$key=$_SESSION[“PWDCRYPT”];
mcrypt_generic_init($this->td, $key, $this->iv);
$val=str_pad($input, (16*(floor(strlen($input) / 16)+(strlen($input) % 16==0?2:1))), chr(16-(strlen($input) % 16)));
$encrypted_data = mcrypt_generic($this->td, $val);
mcrypt_generic_deinit($this->td);
return $encrypted_data;
}
else
return $input;
}}`
second derivate:
include_once “TableClass.php”;
- Code: Select all
- `class baseBrowser extends table_class
{
function baseBrowser(){
parent::__construct();
}
function getTitle(&$record)
{
$sql = “select nome,cognome from anagrafica where idanagrafica=”.$record->val(‘idanagrafica’).” limit 1”;
$res = mysql_query($sql, df_db());
$linea = mysql_fetch_array($res, MYSQL_NUM);
/* Liberazione delle risorse del risultato */
mysql_free_result($res);return $this->gdecrypt($linea[0]).’ ‘.$this->gdecrypt($linea[1]).”:”.$record->val(‘codice’);
}function getPermissions(&$record)
{
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
if ( $query[‘-action’] == ‘new’/* and (!$record || !$record->val(‘registrantid’))*/ )
{
return Dataface_PermissionsTool::ALL();
}if ( !is_null ($record) && $record->val(‘chiuso’) )
return Dataface_PermissionsTool::READ_ONLY();
else
return Dataface_PermissionsTool::getRolePermissions($user->val(‘role’));
}
}`
last derivate that message for validate not works:
- Code: Select all
- `include_once “baseBrowser.php”;
class tables_istologia extends baseBrowser
{
function tables_istologia()
{
parent::__construct();
}function Codice__validate( &$record, $value, &$params)
{
if ( $value{0} !=’I’ )
{
$params[‘message’] = $this->local(‘istologiaCodeError’);
Dataface_Error::permissionDenied($this->local(‘istologiaCodeError’));
echo “find:”.$params[‘message’];
return false;
}
else
{
return true;
}
}}`
last derivate that message for validate works:
- Code: Select all
- `include_once “baseBrowser.php”;
class tables_biomolecolare extends baseBrowser
{
function tables_biomolecolare()
{
parent::__construct();
}function Codice__validate( &$record, $value, &$params)
{
if ( substr ($value,0,2) !=’BM’ )
{
$params[‘message’] = $this->local(‘biomolecolareCodeError’);
Dataface_Error::permissionDenied($this->local(‘biomolecolareCodeError’));
return false;
}
else
{
return true;
}
}}`
another example that validate message don’t work!
- Code: Select all
- `include_once “baseBrowser.php”;
class tables_imistochimica extends baseBrowser
{function tables_imistochimica()
{
parent::__construct();
}function Codice__validate( &$record, $value, &$params)
{
if ( substr ($value,0,2) !=’IM’ )
{
$params[‘message’] = $this->local(‘imistochimicaCodeError’);
Dataface_Error::permissionDenied($this->local(‘imistochimicaCodeError’));
return false;
}
else
{
return true;
}
}}`
fantomasdm — Thu Jul 03, 2008 12:35 am
Find problem!!
When add new relative record return bad error message, classic “permission Denied” but when Edit record return true error message!!
inmisia — Fri Nov 16, 2007 12:27 am
HI! Thanks It wotks!!
Great Job!
fantomasdm — Tue Jul 01, 2008 6:27 am
Hi! I have a fucntion
- Code: Select all
function Codice__validate( &$record, $value, &$params) { if ( substr ($value,0,2) !='BM' ) { $params['message'] = $this->local('biomolecolareCodeError'); Dataface_Error::permissionDenied($this->local('biomolecolareCodeError')); return false; } else { return true; } }
for validate field Codice, but if I add in config.ini language section my error message is no more visible, instread i get classic “permission denied”
without language session I get right message.
Thank for help, sorry for my English..
shannah — Wed Jul 02, 2008 9:40 am
What does your local() method look like?
fantomasdm — Thu Jul 03, 2008 12:24 am
base class is:
- Code: Select all
- `class local_class {
var $lg;
private $ar;
function local_class()
{
$app =& Dataface_Application::getInstance();
if ( $app->_conf[‘lang’] ==”it” || $app->_conf[‘lang’] ==”en” )
$this->lg = $app->_conf[‘lang’];
else
$this->lg = “it”;
$this->loadArray();
}
private function loadArray()
{
$this->ar= array();
$this->ar[‘it’]= array();
$this->ar[‘en’]= array();
$this->ar[‘it’][‘cryptModeOn’]=”Il sistema sta girando in modo Criptato”;
$this->ar[‘it’][‘cryptModeOff’]=”Il sistema sta girando in modo tutto visibile”;
$this->ar[‘it’][‘getPwdCrypt’]=”Inserire la Password di Criptazione:”;
$this->ar[‘it’][‘pwdCryptErr’]=”Occore prima inserire la chiave di criptazione”;
$this->ar[‘it’][‘reportAlreadyClose’]=”Il referto è giàstato chiuso!!”;
$this->ar[‘it’][‘reportClose’]=”Il referto è stato chiuso, non saràpiù possibile modificarlo salvo autorizzazione!!”;
$this->ar[‘it’][‘autopsiaCodeError’]=”Il codice delle autopsie deve iniziare per A!”;
$this->ar[‘it’][‘istochimicaCodeError’]=”Il codice delle autopsie deve iniziare per IC”;
$this->ar[‘it’][‘biomolecolareCodeError’]=”Il codice delle autopsie deve iniziare per BM”;
$this->ar[‘it’][‘citologiaCodeError’]=”Il codice delle autopsie deve iniziare per C”;
$this->ar[‘it’][‘imistochimicaCodeError’]=”Il codice delle autopsie deve iniziare per IM”;
$this->ar[‘it’][‘istologiaCodeError’]=”Il codice delle autopsie deve iniziare per I”;$this->ar[‘en’][‘cryptModeOn’]=”The system is running in crypt mode on”;
$this->ar[‘en’][‘cryptModeOff’]=”The system is running in crypt mode off”;
$this->ar[‘en’][‘getPwdCrypt’]=”Insert key for encrypt data:”;
$this->ar[‘en’][‘pwdCryptErr’]=”Need to insert key for encrypt data”;
$this->ar[‘en’][‘reportAlreadyClose’]=”Report has been already closed!!”;
$this->ar[‘en’][‘reportClose’]=”The report was closed, you can not change it unless authorized”;
$this->ar[‘en’][‘autopsiaCodeError’]=”The code of autopsies must begin for A”;
$this->ar[‘en’][‘istochimicaCodeError’]=”The code of autopsies must begin for IC”;
$this->ar[‘en’][‘biomolecolareCodeError’]=”The code of autopsies must begin for BM”;
$this->ar[‘en’][‘citologiaCodeError’]=”The code of autopsies must begin for C”;
$this->ar[‘en’][‘imistochimicaCodeError’]=”The code of autopsies must begin for IM”;
$this->ar[‘en’][‘istologiaCodeError’]=”The code of autopsies must begin for I”;
}
function local($str)
{
if ($this->ar[$this->lg][$str]==””)
return “Localization not found!!”;
else
return $this->ar[$this->lg][$str];
}
}`
first derivate:
- Code: Select all
- `include_once(“local.php”);
class table_class extends local_class {var $td;
var $iv;
function table_class(){
$this->td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, ‘’, MCRYPT_MODE_ECB, ‘’);
$this->iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($this->td), MCRYPT_RAND);
parent::__construct();
}function __destruct() {
mcrypt_module_close($this->td);
}function gdecrypt($input)
{
if( isset($_SESSION[“PWDCRYPT”]) and $input!=”” )
{
$key=$_SESSION[“PWDCRYPT”];
mcrypt_generic_init($this->td, $key, $this->iv);$encrypted_data = mdecrypt_generic ($this->td, $input);
mcrypt_generic_deinit($this->td);
return rtrim( $encrypted_data, ( ( ord(substr( $encrypted_data, strlen( $encrypted_data )-1, 1 )) >= 0 and ord(substr( $encrypted_data, strlen( $encrypted_data )-1, 1 ) ) <= 16 ) ? chr(ord(substr( $encrypted_data, strlen( $encrypted_data )-1, 1 ))): null) );
}
else
{
return $input;
}
}function gcrypt($input)
{
if( !isset($_SESSION[“PWDCRYPT”]) )
{
$form_html = “”.$this->local(‘pwdCryptErr’).””;
df_display(array(‘form’=>$form_html), ‘chiudi.html’);
exit;
}
if ( $input!=”” )
{
$key=$_SESSION[“PWDCRYPT”];
mcrypt_generic_init($this->td, $key, $this->iv);
$val=str_pad($input, (16*(floor(strlen($input) / 16)+(strlen($input) % 16==0?2:1))), chr(16-(strlen($input) % 16)));
$encrypted_data = mcrypt_generic($this->td, $val);
mcrypt_generic_deinit($this->td);
return $encrypted_data;
}
else
return $input;
}}`
second derivate:
include_once “TableClass.php”;
- Code: Select all
- `class baseBrowser extends table_class
{
function baseBrowser(){
parent::__construct();
}
function getTitle(&$record)
{
$sql = “select nome,cognome from anagrafica where idanagrafica=”.$record->val(‘idanagrafica’).” limit 1”;
$res = mysql_query($sql, df_db());
$linea = mysql_fetch_array($res, MYSQL_NUM);
/* Liberazione delle risorse del risultato */
mysql_free_result($res);return $this->gdecrypt($linea[0]).’ ‘.$this->gdecrypt($linea[1]).”:”.$record->val(‘codice’);
}function getPermissions(&$record)
{
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
if ( $query[‘-action’] == ‘new’/* and (!$record || !$record->val(‘registrantid’))*/ )
{
return Dataface_PermissionsTool::ALL();
}if ( !is_null ($record) && $record->val(‘chiuso’) )
return Dataface_PermissionsTool::READ_ONLY();
else
return Dataface_PermissionsTool::getRolePermissions($user->val(‘role’));
}
}`
last derivate that message for validate not works:
- Code: Select all
- `include_once “baseBrowser.php”;
class tables_istologia extends baseBrowser
{
function tables_istologia()
{
parent::__construct();
}function Codice__validate( &$record, $value, &$params)
{
if ( $value{0} !=’I’ )
{
$params[‘message’] = $this->local(‘istologiaCodeError’);
Dataface_Error::permissionDenied($this->local(‘istologiaCodeError’));
echo “find:”.$params[‘message’];
return false;
}
else
{
return true;
}
}}`
last derivate that message for validate works:
- Code: Select all
- `include_once “baseBrowser.php”;
class tables_biomolecolare extends baseBrowser
{
function tables_biomolecolare()
{
parent::__construct();
}function Codice__validate( &$record, $value, &$params)
{
if ( substr ($value,0,2) !=’BM’ )
{
$params[‘message’] = $this->local(‘biomolecolareCodeError’);
Dataface_Error::permissionDenied($this->local(‘biomolecolareCodeError’));
return false;
}
else
{
return true;
}
}}`
another example that validate message don’t work!
- Code: Select all
- `include_once “baseBrowser.php”;
class tables_imistochimica extends baseBrowser
{function tables_imistochimica()
{
parent::__construct();
}function Codice__validate( &$record, $value, &$params)
{
if ( substr ($value,0,2) !=’IM’ )
{
$params[‘message’] = $this->local(‘imistochimicaCodeError’);
Dataface_Error::permissionDenied($this->local(‘imistochimicaCodeError’));
return false;
}
else
{
return true;
}
}}`
fantomasdm — Thu Jul 03, 2008 12:35 am
Find problem!!
When add new relative record return bad error message, classic “permission Denied” but when Edit record return true error message!!
fantomasdm — Sun Jul 06, 2008 11:52 pm
When add new record, with version dataface-0.7.1 and xataface-1.0-beta-3 I get “Permission Denied” error message with xataface-1.0-beta-2 I get nothing. validete function works but, I can’t see my error message when add, but it’s works good when edit!!
shannah — Mon Jul 07, 2008 10:01 am
I have added this to the issue tracker and have uploaded a patch that should fix this issue:
http://bugs.weblite.ca/view.php?id=220
-Steve
fantomasdm — Mon Jul 07, 2008 11:50 pm
Thanks!! Now It works!!!