Fixes in fields and added protection for not update fields in Webmodel

This commit is contained in:
Antonio de la Rosa 2015-12-29 02:02:06 +01:00
parent 479f449b13
commit f0f8b6c9cd
5 changed files with 40 additions and 54 deletions

View file

@ -55,7 +55,7 @@ class CharField extends PhangoField {
{ {
//Delete Javascript tags and simple quotes. //Delete Javascript tags and simple quotes.
$this->value=Utils::form_text($value); $value=Utils::form_text($value);
if($value=='') if($value=='')
{ {

View file

@ -2,6 +2,7 @@
namespace PhangoApp\PhaModels\CoreFields; namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaUtils\Utils; use PhangoApp\PhaUtils\Utils;
use PhangoApp\PhaTime;
/** /**
* Datefield is a field for save dates in timestamp, this value is a timestamp and you need use form_date or form_time for format DateField * Datefield is a field for save dates in timestamp, this value is a timestamp and you need use form_date or form_time for format DateField
@ -19,10 +20,10 @@ class DateField extends PhangoField {
public $set_default_time=0; public $set_default_time=0;
public $std_error=''; public $std_error='';
function __construct($size=11) function __construct()
{ {
$this->size=$size; $this->size=14;
$this->form='PhangoApp\PhaModels\Forms\DateForm'; $this->form='PhangoApp\PhaModels\Forms\DateForm';
} }
@ -37,7 +38,7 @@ class DateField extends PhangoField {
if($this->set_default_time==0) if($this->set_default_time==0)
{ {
$final_value=mktime(date('H'), date('i'), date('s')); $final_value=PhaTime\DateTime::local_to_gmt(date(PhaTime\DateTime::$sql_format_time));
} }
@ -54,20 +55,12 @@ class DateField extends PhangoField {
if($value[0]>0 && $value[1]>0 && $value[2]>0) if($value[0]>0 && $value[1]>0 && $value[2]>0)
{ {
/*$substr_time=$user_data['format_time']/3600; $new_timestamp=date(PhaTime\DateTime::$sql_format_time, mktime($value[3], $value[4], $value[5], $value[1], $value[0], $value[2]));
$value[3]-=$substr_time;*/ $final_value=PhaTime\DateTime::local_to_gmt( $new_timestamp );
$final_value=mktime ($value[3], $value[4], $value[5], $value[1], $value[0], $value[2] );
} }
/*echo date('H-i-s', $final_value);
//echo $final_value;
die;*/
} }
else if(strpos($value, '-')!==false) else if(strpos($value, '-')!==false)
{ {
@ -82,23 +75,20 @@ class DateField extends PhangoField {
if($final_value===false) if($final_value===false)
{ {
$this->error=true; $this->error=1;
$final_value=mktime(date('H'), date('i'), date('s')); $final_value=PhaTime\DateTime::local_to_gmt(date(PhaTime\DateTime::$sql_format_time));
} }
} }
else
if(gettype($value)=='string' || gettype($value)=='integer') if($final_value===false)
{ {
settype($value, 'integer'); $this->error=1;
$final_value=$value; $final_value=PhaTime\DateTime::local_to_gmt(date(PhaTime\DateTime::$sql_format_time));
} }
$this->value=Utils::form_text($final_value);
return $final_value; return $final_value;
} }
@ -106,7 +96,7 @@ class DateField extends PhangoField {
function get_type_sql() function get_type_sql()
{ {
return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""';
} }
@ -118,23 +108,15 @@ class DateField extends PhangoField {
public function show_formatted($value) public function show_formatted($value)
{ {
return $this->format_date($value); return PhaTime\DateTime::format_date($value);
} }
static public function format_date($value)
{
load_libraries(array('form_date'));
return form_date( $value );
}
function get_parameters_default() function get_parameters_default()
{ {
return array($this->name_component, '', time()); return array($this->name_component, '', date(PhaTime\DateTime::$sql_format_time));
} }

View file

@ -157,7 +157,7 @@ class PhangoField {
public function get_type_sql() public function get_type_sql()
{ {
return 'VARCHAR('.$this->size.') NOT NULL DEFAULT "0"'; return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""';
} }

View file

@ -3,6 +3,8 @@
namespace PhangoApp\PhaModels\Forms; namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaI18n\I18n; use PhangoApp\PhaI18n\I18n;
use PhangoApp\PhaUtils\Utils;
use PhangoApp\PhaTime;
class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm { class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm {
@ -14,9 +16,9 @@ class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm {
$value=$this->default_value; $value=$this->default_value;
settype($value, 'integer'); settype($value, 'string');
if($value==0) if($value=='')
{ {
$day=''; $day='';
@ -30,14 +32,8 @@ class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm {
else else
{ {
//$value+=$user_data['format_time']; list($year, $month, $day, $hour, $minute, $second)=PhaTime\DateTime::format_timedata($value);
$day=date('j', $value);
$month=date('n', $value);
$year=date('Y', $value);
$hour=date('G', $value);
$minute=date('i', $value);
$second=date('s', $value);
} }
//return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">'; //return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">';

View file

@ -394,17 +394,23 @@ class Webmodel {
public $update=0; public $update=0;
/** /**
* Method for set the method used from cache or directly from the database. * Property for set the method used from cache or directly from the database.
*/ */
public $method_fetch_array='nocached_fetch_array'; public $method_fetch_array='nocached_fetch_array';
/** /**
* Method for set the method used from cache or directly from the database. * Property for set the method used from cache or directly from the database.
*/ */
public $method_fetch_row='nocached_fetch_row'; public $method_fetch_row='nocached_fetch_row';
/**
* Property that define the fields to update
*/
public $fields_to_update=array();
//Construct the model //Construct the model
/** /**
@ -1834,7 +1840,7 @@ class Webmodel {
//If is set the variable for this component make checking //If is set the variable for this component make checking
if(isset($post[$key]) && ($field->protected==0 || $safe_query==1)) if(isset($post[$key]) && ($field->protected==0 || $safe_query==1) && in_array($key, $this->fields_to_update))
{ {
$this->components[$key]->update=$this->update; $this->components[$key]->update=$this->update;
@ -2034,6 +2040,8 @@ class Webmodel {
$this->check_enctype+=$this->forms[$component_name]->enctype; $this->check_enctype+=$this->forms[$component_name]->enctype;
$this->fields_to_update[]=$component_name;
$this->components[$component_name]->form_loaded=&$this->forms[$component_name]; $this->components[$component_name]->form_loaded=&$this->forms[$component_name];
$this->components[$component_name]->get_parameters_default(); $this->components[$component_name]->get_parameters_default();