Added coreforms
This commit is contained in:
parent
cfe9f7217e
commit
40eb84aeab
18 changed files with 519 additions and 17 deletions
|
|
@ -24,7 +24,7 @@ class BooleanField extends PhangoField {
|
|||
{
|
||||
|
||||
$this->size=1;
|
||||
$this->form='SelectForm';
|
||||
$this->form='CoreForms::SelectForm';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class CharField extends PhangoField {
|
|||
{
|
||||
|
||||
$this->size=$size;
|
||||
$this->form='TextForm';
|
||||
$this->form='CoreForms::TextForm';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class DateField extends PhangoField {
|
|||
{
|
||||
|
||||
$this->size=$size;
|
||||
$this->form='DateForm';
|
||||
$this->form='CoreForms::DateForm';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class DoubleField extends PhangoField {
|
|||
{
|
||||
|
||||
$this->size=$size;
|
||||
$this->form='TextForm';
|
||||
$this->form='CoreForms::TextForm';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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='\'';
|
||||
|
|
|
|||
|
|
@ -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="";
|
||||
|
|
|
|||
|
|
@ -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...
|
||||
|
|
|
|||
|
|
@ -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="";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class KeyField extends PhangoField {
|
|||
{
|
||||
|
||||
$this->size=$size;
|
||||
$this->form='TextForm';
|
||||
$this->form='CoreForms::TextForm';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ParentField extends IntegerField{
|
|||
|
||||
$this->parent_model=&$parent_model;
|
||||
$this->size=$size;
|
||||
$this->form='SelectForm';
|
||||
$this->form='CoreForms::SelectForm';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class PasswordField extends CharField {
|
|||
{
|
||||
|
||||
$this->size=$size;
|
||||
$this->form='PasswordForm';
|
||||
$this->form='CoreForms::PasswordForm';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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..
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class TextField extends PhangoField {
|
|||
function __construct($multilang=0)
|
||||
{
|
||||
|
||||
$this->form='TextAreaForm';
|
||||
$this->form='CoreForms::TextAreaForm';
|
||||
$this->multilang=$multilang;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
502
src/CoreForms.php
Normal file
502
src/CoreForms.php
Normal file
|
|
@ -0,0 +1,502 @@
|
|||
<?php
|
||||
/**
|
||||
* Base file include where basic static public and methods for create MVC applications
|
||||
*
|
||||
* This file contains principal static public s and methods for create models, text formatting, forms creation, definition of basic variables, basic ORM that use on 90% of db searchs, etc...
|
||||
*
|
||||
* Functions used for generate forms from models
|
||||
* This static public s are called via $model->form
|
||||
*
|
||||
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
|
||||
* @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 '<input type="text" name="'.$name.'" id="'.$name.'_field_form" class="'.$class.'" value="'.$value.'" />';
|
||||
|
||||
}
|
||||
|
||||
//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 '<input type="password" name="'.$name.'" class="'.$class.'" id="'.$name.'_field_form" value="'.$value.'" />';
|
||||
|
||||
}
|
||||
|
||||
//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='<a href="'.$file_url.'">'.basename($value).'</a> ';
|
||||
|
||||
if($delete_inline==1)
|
||||
{
|
||||
|
||||
$file_exist.=I18n::lang('common', 'delete_file', 'Delete file').' <input type="checkbox" name="delete_'.$name.'" class="'.$class.'" value="1" />';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return '<input type="hidden" name="'.$name.'" value="'.$value.'"/><input type="file" name="'.$name.'" class="'.$class.'" value="" /> '.$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='<a href="'.$image_url.'">'.basename($value).'</a> ';
|
||||
|
||||
if($delete_inline==1)
|
||||
{
|
||||
|
||||
$image_exist.=I18n::lang('common', 'delete_image', 'Delete image').' <input type="checkbox" name="delete_'.$name.'" class="'.$class.'" value="1" />';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return '<input type="hidden" name="'.$name.'" value="'.$value.'"/><input type="file" name="'.$name.'" class="'.$class.'" value="" /> '.$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 '<textarea name="'.$name.'" class="'.$class.'" id="'.$name.'_field_form">'.$value.'</textarea>';
|
||||
|
||||
}
|
||||
|
||||
//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 '<input type="hidden" name="'.$name.'" value="'.$value.'" id="'.$name.'_field_form"/>';
|
||||
|
||||
}
|
||||
|
||||
//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 '<input type="checkbox" name="'.$name.'" value="1" id="'.$name.'_field_form" class="'.$class.'" '.$arr_checked[$value].'/>';
|
||||
|
||||
}
|
||||
|
||||
//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='<select name="'.$name.'" id="'.$name.'_field_form" class="'.$class.'" '.$more_options.'>'."\n";
|
||||
|
||||
list($key, $default)= each($value);
|
||||
|
||||
$arr_selected=array();
|
||||
|
||||
$arr_selected[$default]="selected=\"selected\"";
|
||||
|
||||
//Check if array is safe.
|
||||
|
||||
$z=count($value);
|
||||
|
||||
for($x=1;$x<$z;$x+=2)
|
||||
{
|
||||
|
||||
$val=$value[$x+1];
|
||||
|
||||
settype($val, "string");
|
||||
settype($arr_selected[$val], "string");
|
||||
|
||||
if($val=='optgroup')
|
||||
{
|
||||
$select.='<optgroup label="'.$value[$x].'">';
|
||||
}
|
||||
else
|
||||
if($val=="end_optgroup")
|
||||
{
|
||||
|
||||
$select.='</optgroup>';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$select.= '<option value="'.$val.'" '.$arr_selected[$val].'>'.$value[$x].'</option>'."\n";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$select.='</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='<select name="'.$name.'[]" id="'.$name.'_field_form" class="'.$class.'" '.$more_options.' multiple>'."\n";
|
||||
|
||||
list($key, $arr_values)= each($value);
|
||||
|
||||
$arr_selected=array();
|
||||
|
||||
foreach($arr_values as $default)
|
||||
{
|
||||
|
||||
$arr_selected[$default]="selected";
|
||||
|
||||
}
|
||||
|
||||
//Check if array is safe.
|
||||
|
||||
$z=count($value);
|
||||
|
||||
for($x=1;$x<$z;$x+=2)
|
||||
{
|
||||
|
||||
$val=$value[$x+1];
|
||||
|
||||
settype($val, "string");
|
||||
settype($arr_selected[$val], "string");
|
||||
|
||||
if($val=='optgroup')
|
||||
{
|
||||
$select.='<optgroup label="'.$value[$x].'">';
|
||||
}
|
||||
else
|
||||
if($val=="end_optgroup")
|
||||
{
|
||||
|
||||
$select.='</optgroup>';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$select.= '<option value="'.$val.'" '.$arr_selected[$val].'>'.$value[$x].'</option>'."\n";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$select.='</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='<span id="'.$field.'_field_form" class="'.$class.'">';
|
||||
|
||||
if($set_time<=1)
|
||||
{
|
||||
|
||||
$date.='<input type="text" name="'.$field.'[]" value="'.$day.'" size="2" maxlength="2"/>'."\n";
|
||||
$date.='<input type="text" name="'.$field.'[]" value="'.$month.'" size="2" maxlength="2"/>'."\n";
|
||||
$date.='<input type="text" name="'.$field.'[]" value="'.$year.'" size="4" maxlength="4"/>'."\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.' <input type="text" name="'.$field.'[]" value="'.$hour.'" size="2" maxlength="2" />'."\n";
|
||||
$date.=$minute_txt.' <input type="text" name="'.$field.'[]" value="'.$minute.'" size="2" maxlength="2" />'."\n";
|
||||
$date.=$second_txt.' <input type="text" name="'.$field.'[]" value="'.$second.'" size="2" maxlength="2" />'."\n";
|
||||
|
||||
}
|
||||
|
||||
echo '</span>';
|
||||
|
||||
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].' <input type="radio" name="'.$name.'" value="'.$val.'" '.$arr_selected[$val].' />'."\n";
|
||||
|
||||
}
|
||||
|
||||
return $select;
|
||||
|
||||
}
|
||||
|
||||
//Prepare the value for the select
|
||||
|
||||
static public RadioIntFormSet($post, $value)
|
||||
{
|
||||
|
||||
settype($value, 'integer');
|
||||
|
||||
$post[0]=$value;
|
||||
|
||||
return $post;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue