diff --git a/src/CoreFields/BooleanField.php b/src/CoreFields/BooleanField.php index 2a8b55d..8d35258 100644 --- a/src/CoreFields/BooleanField.php +++ b/src/CoreFields/BooleanField.php @@ -24,7 +24,7 @@ class BooleanField extends PhangoField { { $this->size=1; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; } diff --git a/src/CoreFields/CharField.php b/src/CoreFields/CharField.php index 0ad64b5..5a080be 100644 --- a/src/CoreFields/CharField.php +++ b/src/CoreFields/CharField.php @@ -31,7 +31,7 @@ class CharField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; } diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php index e48391d..764e205 100644 --- a/src/CoreFields/ChoiceField.php +++ b/src/CoreFields/ChoiceField.php @@ -29,7 +29,7 @@ class ChoiceField extends PhangoField { { $this->size=$size; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; $this->type=$type; $this->arr_values=$arr_values; $this->default_value=$default_value; diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php index 08b2964..0c33474 100644 --- a/src/CoreFields/DateField.php +++ b/src/CoreFields/DateField.php @@ -23,7 +23,7 @@ class DateField extends PhangoField { { $this->size=$size; - $this->form='DateForm'; + $this->form='CoreForms::DateForm'; } diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index 9feeec3..35f54d6 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -22,7 +22,7 @@ class DoubleField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; } diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index 4ff1c3a..cb4ff27 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -12,7 +12,7 @@ class EmailField extends PhangoField { public $size=200; public $value=""; public $label=""; - public $form="TextForm"; + public $form="CoreForms::TextForm"; public $class=""; public $required=0; public $quot_open='\''; diff --git a/src/CoreFields/FileField.php b/src/CoreFields/FileField.php index 670e434..b4fc13e 100644 --- a/src/CoreFields/FileField.php +++ b/src/CoreFields/FileField.php @@ -12,7 +12,7 @@ class FileField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="FileForm"; + public $form="CoreForms::FileForm"; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 2661d3d..a1806af 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -29,7 +29,7 @@ class ForeignKeyField extends IntegerField{ { $this->size=$size; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; $this->related_model=&$related_model; $this->container_model=$this->related_model->name; //Fields obtained from related_model if you make a query... diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index a08f8be..e7b0a70 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -15,7 +15,7 @@ class ImageField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="ImageForm"; + public $form="CoreForms::ImageForm"; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/IntegerField.php b/src/CoreFields/IntegerField.php index cb1d5fb..ef750e0 100644 --- a/src/CoreFields/IntegerField.php +++ b/src/CoreFields/IntegerField.php @@ -22,7 +22,7 @@ class IntegerField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; $this->only_positive=$only_positive; $this->min_num=$min_num; $this->max_num=$max_num; diff --git a/src/CoreFields/KeyField.php b/src/CoreFields/KeyField.php index a23ed84..4b0a11c 100644 --- a/src/CoreFields/KeyField.php +++ b/src/CoreFields/KeyField.php @@ -26,7 +26,7 @@ class KeyField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; } diff --git a/src/CoreFields/ParentField.php b/src/CoreFields/ParentField.php index c5a664b..815e741 100644 --- a/src/CoreFields/ParentField.php +++ b/src/CoreFields/ParentField.php @@ -17,7 +17,7 @@ class ParentField extends IntegerField{ $this->parent_model=&$parent_model; $this->size=$size; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; } diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index 09f203e..5219a33 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -18,7 +18,7 @@ class PasswordField extends CharField { { $this->size=$size; - $this->form='PasswordForm'; + $this->form='CoreForms::PasswordForm'; } diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index ae277f7..13b8c09 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -87,7 +87,7 @@ class PhangoField { * Form define the function for use in forms... */ - public $form=""; + public $form="CoreForms::TextForm"; /** * Array for create initial parameters for form.. diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index d618813..a2d7eb2 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -33,7 +33,7 @@ class PrimaryField extends PhangoField { * By default, the form used for this field is HiddenForm. */ - public $form="HiddenForm"; + public $form="CoreForms::HiddenForm"; /** * Check function that convert the value on a PrimaryField value. diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index 28dd8ff..23d4edf 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -22,7 +22,7 @@ class TextField extends PhangoField { function __construct($multilang=0) { - $this->form='TextAreaForm'; + $this->form='CoreForms::TextAreaForm'; $this->multilang=$multilang; } diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php index 526c296..9ca4f02 100644 --- a/src/CoreFields/TextHTMLField.php +++ b/src/CoreFields/TextHTMLField.php @@ -25,7 +25,7 @@ class TextHTMLField extends PhangoField { function __construct($multilang=0) { - $this->form='TextAreaForm'; + $this->form='CoreForms::TextAreaForm'; $this->multilang=$multilang; $this->set_safe_html_tags(); diff --git a/src/CoreForms.php b/src/CoreForms.php new file mode 100644 index 0000000..7062013 --- /dev/null +++ b/src/CoreForms.php @@ -0,0 +1,502 @@ +form +* +* @author Antonio de la Rosa +* @file +* @package CoreForms +* +*/ + +namespace PhangoApp\PhaModels; + +use PhangoApp\PhaUtils\Utils; + +class CoreForms { + + /* Function form used for text fields on a form. Show a text html input. + * + * + * @param string $name Name of this text field for use in forms + * @param string $class Css class used in the text field + * @param string $value Initial value for the form + */ + + static public TextForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare a value for input text + + static public TextFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + return $value; + + } + + //Create a input password + + static public PasswordForm($name="", $class='', $value='') + { + + $value = Utils::replace_quote_text( $value ); + + return ''; + + } + + //Prepare a value for input password + + static public PasswordFormSet($post, $value) + { + + $value = ''; //Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input file + + static public FileForm($name="", $class='', $value='', $delete_inline=0, $path_file='') + { + + + + $file_url=$path_file.'/'.$value; + + $file_exist=''; + + if($value!='') + { + + $file_exist=''.basename($value).' '; + + if($delete_inline==1) + { + + $file_exist.=I18n::lang('common', 'delete_file', 'Delete file').' '; + + } + + } + + return ' '.$file_exist; + + } + + //Prepare a value for input password + + static public FileFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + + //Create a special form for a image + + static public ImageForm($name="", $class='', $value='', $delete_inline=0, $path_image='') + { + + $image_url=$path_image.'/'.$value; + + $image_exist=''; + + if($value!='') + { + + $image_exist=''.basename($value).' '; + + if($delete_inline==1) + { + + $image_exist.=I18n::lang('common', 'delete_image', 'Delete image').' '; + + } + + } + + return ' '.$image_exist; + + } + + //Prepare a value for input password + + static public ImageFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a textarea + + static public TextAreaForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare the value for the textarea + + static public TextAreaFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input hidden + + static public HiddenForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare the value for a input hidden + + static public HiddenFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input checkbox + + static public CheckBoxForm($name="", $class='', $value='') + { + + $arr_checked[$value]=''; + + $arr_checked[0]=''; + $arr_checked[1]='checked'; + + return ''; + + } + + //Prepare the value for the checkbox + + static public CheckBoxFormSet($post, $value) + { + + settype($value, 'integer'); + + return $value; + + } + + //Create a select + + static public SelectForm($name="", $class='', $value='', $more_options='') + { + + $select=''."\n"; + + return $select; + + } + + //Prepare the value for the select + + static public SelectFormSet($post, $value) + { + + $value = preg_replace('/<(.*?)\/(.*?)option(.*?)>/', '', $value); + + $post[0]=$value; + + return $post; + + } + + //Crate a multiple select + + static public SelectManyForm($name="", $class='', $value='', $more_options='' ) + { + + $select=''."\n"; + + return $select; + + } + + //Prepare the value for the multiple select + + static public SelectManyFormSet($post, $value) + { + + if(gettype($value)!='array') + { + + $arr_value=unserialize($value); + } + else + { + + $arr_value=$value; + + } + //$value = preg_replace('/<(.*?)\/(.*?)option(.*?)>/', '', $value); + + $post[0]=$arr_value; + + return $post; + + } + + //A special form for dates in format day/month/year + + static public DateForm($field, $class='', $value='', $set_time=1, $see_title=1) + { + + if($value==0) + { + + $day=''; + $month=''; + $year=''; + $hour=''; + $minute=''; + $second=''; + + } + else + { + + //$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); + } + + $date=''; + + if($set_time<=1) + { + + $date.=''."\n"; + $date.=''."\n"; + $date.=''."\n   "; + + } + + if($set_time>0) + { + + $hour_txt=I18n::lang('common', 'hour', 'Hour'); + $minute_txt=I18n::lang('common', 'minute', 'Minute'); + $second_txt=I18n::lang('common', 'second', 'Second'); + + if($see_title==0) + { + + $hour_txt=''; + $minute_txt=''; + $second_txt=''; + + } + + $date.=$hour_txt.' '."\n"; + $date.=$minute_txt.' '."\n"; + $date.=$second_txt.' '."\n"; + + } + + echo ''; + + return $date; + + } + + //Prepare value form dateform + + static public DateFormSet($post, $value) + { + + if(gettype($value)=='array') + { + foreach($value as $key => $val) + { + + settype($value[$key], 'integer'); + + } + + settype($value[3], 'integer'); + settype($value[4], 'integer'); + settype($value[5], 'integer'); + + $final_value=mktime ($value[3], $value[4], $value[5], $value[1], $value[0], $value[2] ); + + } + else + { + + settype($value, 'integer'); + + $final_value=$value; + + } + + + return $final_value; + + } + + static public RadioIntForm($name="", $class='', $value=array(), $more_options='') + { + $select=''; + + list($key, $default)= each($value); + + $arr_selected=array(); + + $arr_selected[$default]="checked"; + + //Check if array is safe. + + $z=count($value); + + for($x=1;$x<$z;$x+=2) + { + + $val=$value[$x+1]; + + settype($arr_selected[$val], "string"); + + $select.= $value[$x].' '."\n"; + + } + + return $select; + + } + + //Prepare the value for the select + + static public RadioIntFormSet($post, $value) + { + + settype($value, 'integer'); + + $post[0]=$value; + + return $post; + + } + +} + +?> \ No newline at end of file