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.
$this->value=Utils::form_text($value);
$value=Utils::form_text($value);
if($value=='')
{

View file

@ -2,6 +2,7 @@
namespace PhangoApp\PhaModels\CoreFields;
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
@ -19,10 +20,10 @@ class DateField extends PhangoField {
public $set_default_time=0;
public $std_error='';
function __construct($size=11)
function __construct()
{
$this->size=$size;
$this->size=14;
$this->form='PhangoApp\PhaModels\Forms\DateForm';
}
@ -31,13 +32,13 @@ class DateField extends PhangoField {
function check($value)
{
$final_value=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));
}
@ -53,20 +54,12 @@ class DateField extends PhangoField {
if($value[0]>0 && $value[1]>0 && $value[2]>0)
{
$new_timestamp=date(PhaTime\DateTime::$sql_format_time, mktime($value[3], $value[4], $value[5], $value[1], $value[0], $value[2]));
/*$substr_time=$user_data['format_time']/3600;
$value[3]-=$substr_time;*/
$final_value=mktime ($value[3], $value[4], $value[5], $value[1], $value[0], $value[2] );
$final_value=PhaTime\DateTime::local_to_gmt( $new_timestamp );
}
/*echo date('H-i-s', $final_value);
//echo $final_value;
die;*/
}
else if(strpos($value, '-')!==false)
@ -82,22 +75,19 @@ class DateField extends PhangoField {
if($final_value===false)
{
$this->error=true;
$final_value=mktime(date('H'), date('i'), date('s'));
$this->error=1;
$final_value=PhaTime\DateTime::local_to_gmt(date(PhaTime\DateTime::$sql_format_time));
}
}
else
if(gettype($value)=='string' || gettype($value)=='integer')
{
settype($value, 'integer');
$final_value=$value;
}
$this->value=Utils::form_text($final_value);
if($final_value===false)
{
$this->error=1;
$final_value=PhaTime\DateTime::local_to_gmt(date(PhaTime\DateTime::$sql_format_time));
}
return $final_value;
@ -106,7 +96,7 @@ class DateField extends PhangoField {
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)
{
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()
{
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()
{
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;
use PhangoApp\PhaI18n\I18n;
use PhangoApp\PhaUtils\Utils;
use PhangoApp\PhaTime;
class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm {
@ -14,9 +16,9 @@ class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm {
$value=$this->default_value;
settype($value, 'integer');
settype($value, 'string');
if($value==0)
if($value=='')
{
$day='';
@ -29,15 +31,9 @@ class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm {
}
else
{
list($year, $month, $day, $hour, $minute, $second)=PhaTime\DateTime::format_timedata($value);
//$value+=$user_data['format_time'];
$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).'">';

View file

@ -394,16 +394,22 @@ class Webmodel {
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';
/**
* 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';
/**
* Property that define the fields to update
*/
public $fields_to_update=array();
//Construct the model
@ -1834,7 +1840,7 @@ class Webmodel {
//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;
@ -2034,6 +2040,8 @@ class Webmodel {
$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]->get_parameters_default();