From a30676de2fafd59cabd4d1415a3ce15f88457b4c Mon Sep 17 00:00:00 2001 From: absurdo Date: Thu, 7 Dec 2023 01:47:47 +0100 Subject: [PATCH] Added simple forms --- LICENSE | 340 +++++++++++++++++++++++ README.md | 2 + composer.json | 20 ++ src/CoreForms.php | 502 +++++++++++++++++++++++++++++++++ src/Forms/BaseForm.php | 112 ++++++++ src/Forms/DateForm.php | 105 +++++++ src/Forms/DateTimeForm.php | 12 + src/Forms/FileForm.php | 36 +++ src/Forms/HiddenForm.php | 24 ++ src/Forms/IpForm.php | 31 +++ src/Forms/MoneyForm.php | 44 +++ src/Forms/NoForm.php | 17 ++ src/Forms/PasswordForm.php | 31 +++ src/Forms/SelectForm.php | 61 ++++ src/Forms/TextAreaForm.php | 19 ++ src/ModelForm.php | 552 +++++++++++++++++++++++++++++++++++++ 16 files changed, 1908 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 src/CoreForms.php create mode 100644 src/Forms/BaseForm.php create mode 100644 src/Forms/DateForm.php create mode 100644 src/Forms/DateTimeForm.php create mode 100644 src/Forms/FileForm.php create mode 100644 src/Forms/HiddenForm.php create mode 100644 src/Forms/IpForm.php create mode 100644 src/Forms/MoneyForm.php create mode 100644 src/Forms/NoForm.php create mode 100644 src/Forms/PasswordForm.php create mode 100644 src/Forms/SelectForm.php create mode 100644 src/Forms/TextAreaForm.php create mode 100644 src/ModelForm.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d6a9326 --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..7ffed3c --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# phamodels +PhaModels is a simple component for create a lightweight ORM for MySQL. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..36cdc8e --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "phangoapp/phaforms", + "description": "A simple class for create models", + "require-dev": { + "phpunit/phpunit": "~4.8@dev" + }, + "license": "GPL", + "authors": [ + { + "name": "Antonio de la Rosa", + "email": "webmaster@web-t-sys.com" + } + ], + "minimum-stability": "dev", + "autoload": { + "psr-4": { + "PhangoApp\\PhaForms\\": "src" + } + } +} diff --git a/src/CoreForms.php b/src/CoreForms.php new file mode 100644 index 0000000..e1feeb9 --- /dev/null +++ b/src/CoreForms.php @@ -0,0 +1,502 @@ +form +* +* @author Antonio de la Rosa +* @file +* @package CoreForms +* +*/ + +namespace PhangoApp\PhaForms; + +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 function TextForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare a value for input text + + static public function TextFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + return $value; + + } + + //Create a input password + + static public function PasswordForm($name="", $class='', $value='') + { + + $value = Utils::replace_quote_text( $value ); + + return ''; + + } + + //Prepare a value for input password + + static public function PasswordFormSet($post, $value) + { + + $value = ''; //Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input file + + static public function 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.=_('Delete file').' '; + + } + + } + + return ' '.$file_exist; + + } + + //Prepare a value for input password + + static public function FileFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + + //Create a special form for a image + + static public function 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.=_('Delete image').' '; + + } + + } + + return ' '.$image_exist; + + } + + //Prepare a value for input password + + static public function ImageFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a textarea + + static public function TextAreaForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare the value for the textarea + + static public function TextAreaFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input hidden + + static public function HiddenForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare the value for a input hidden + + static public function HiddenFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input checkbox + + static public function CheckBoxForm($name="", $class='', $value='') + { + + $arr_checked[$value]=''; + + $arr_checked[0]=''; + $arr_checked[1]='checked'; + + return ''; + + } + + //Prepare the value for the checkbox + + static public function CheckBoxFormSet($post, $value) + { + + settype($value, 'integer'); + + return $value; + + } + + //Create a select + + static public function SelectForm($name="", $class='', $value='', $more_options='') + { + + $select=''."\n"; + + return $select; + + } + + //Prepare the value for the select + + static public function SelectFormSet($post, $value) + { + + $value = preg_replace('/<(.*?)\/(.*?)option(.*?)>/', '', $value); + + $post[0]=$value; + + return $post; + + } + + //Crate a multiple select + + static public function SelectManyForm($name="", $class='', $value='', $more_options='' ) + { + + $select=''."\n"; + + return $select; + + } + + //Prepare the value for the multiple select + + static public function 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 function 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=_('Hour'); + $minute_txt=_('Minute'); + $second_txt=_('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 function 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 function 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 function RadioIntFormSet($post, $value) + { + + settype($value, 'integer'); + + $post[0]=$value; + + return $post; + + } + +} + +?> diff --git a/src/Forms/BaseForm.php b/src/Forms/BaseForm.php new file mode 100644 index 0000000..d563814 --- /dev/null +++ b/src/Forms/BaseForm.php @@ -0,0 +1,112 @@ +label=$name; + $this->name=$name; + $this->default_value=$value; + $this->css=''; + $this->type='text'; + $this->required=0; + $this->comment_form=''; + $this->txt_error = _('Error in field'); + $this->extra_param=''; + } + + public function form() + { + + return 'extra_param.' placeholder="'.$this->placeholder.'"> '.$this->comment_form; + + } + + public function set_parameters(array $parameters) + { + + foreach($parameters as $property => $value) + { + + $this->$property=$value; + + } + + } + + /** + * Static method where is registered the js necessary for a field + */ + + static public function js() + { + + } + + /** + * Static method where is registered the css necessary for a field + */ + + static public function css() + { + + } + + /** + * Static method where is registered other headers for the form. + */ + + static public function header() + { + + } + + /** + * Method for escape value for html input + */ + + public function setform($value) + { + + return trim(htmlspecialchars($value)); + + } +} + +?> diff --git a/src/Forms/DateForm.php b/src/Forms/DateForm.php new file mode 100644 index 0000000..534269e --- /dev/null +++ b/src/Forms/DateForm.php @@ -0,0 +1,105 @@ +default_value; + + if(gettype($value)=='array') + { + + //$t=new DateField(''); + + //$value=$t->check($value); + + } + + settype($value, 'string'); + + if($value=='') + { + + $day=''; + $month=''; + $year=''; + $hour=''; + $minute=''; + $second=''; + + } + else + { + + /*if($this->utc) + { + + $value=PhaTime\DateTime::gmt_to_local($value); + + }*/ + + list($year, $month, $day, $hour, $minute, $second)=date_parse($value); + + } + + //return ''; + + $date=''; + + $date.=''."\n"; + $date.=''."\n"; + $date.=''."\n   "; + + if($this->set_time==1) + { + $hour_txt=I18n::lang('common', 'hour', 'Hour'); + $minute_txt=I18n::lang('common', 'minute', 'Minute'); + $second_txt=I18n::lang('common', 'second', 'Second'); + + if($this->see_title==0) + { + + $hour_txt=''; + $minute_txt=''; + $second_txt=''; + + } + + $date.=$hour_txt.' '."\n"; + $date.=$minute_txt.' '."\n"; + $date.=$second_txt.' '."\n"; + + } + + + echo ''; + + return $date; + + } + + public function setform($value) { + + $d = DateTime::createFromFormat($this->format, $value); + + if($d && $d->format($this->format) === $value) { + + return $value; + + } + + return ''; + + } + +} + +?> diff --git a/src/Forms/DateTimeForm.php b/src/Forms/DateTimeForm.php new file mode 100644 index 0000000..a75f4d5 --- /dev/null +++ b/src/Forms/DateTimeForm.php @@ -0,0 +1,12 @@ + diff --git a/src/Forms/FileForm.php b/src/Forms/FileForm.php new file mode 100644 index 0000000..8c4e2af --- /dev/null +++ b/src/Forms/FileForm.php @@ -0,0 +1,36 @@ +type='file'; + $this->enctype=1; + $this->file_url=''; + + } + + public function form() + { + + return ' '.Utils::form_text($this->default_value).''; + + } + +} + + diff --git a/src/Forms/HiddenForm.php b/src/Forms/HiddenForm.php new file mode 100644 index 0000000..61dd2a0 --- /dev/null +++ b/src/Forms/HiddenForm.php @@ -0,0 +1,24 @@ +type='hidden'; + + } + + +} + +?> diff --git a/src/Forms/IpForm.php b/src/Forms/IpForm.php new file mode 100644 index 0000000..c6ed290 --- /dev/null +++ b/src/Forms/IpForm.php @@ -0,0 +1,31 @@ +std_error=_('IP not valid'); + + return ""; + + } + + } + + +} + +?> diff --git a/src/Forms/MoneyForm.php b/src/Forms/MoneyForm.php new file mode 100644 index 0000000..1a5db64 --- /dev/null +++ b/src/Forms/MoneyForm.php @@ -0,0 +1,44 @@ +comment_form='€'; + + } + + public function setform($value) + { + + settype($value, 'double'); + + return number_format($value, 2, ',', '.'); + + } + + public function form() + { + + $value=$this->default_value; + + return 'extra_param.'> '.$this->comment_form; + + } + + +} + +?> diff --git a/src/Forms/NoForm.php b/src/Forms/NoForm.php new file mode 100644 index 0000000..132baf2 --- /dev/null +++ b/src/Forms/NoForm.php @@ -0,0 +1,17 @@ +default_value); + + } +} + +?> diff --git a/src/Forms/PasswordForm.php b/src/Forms/PasswordForm.php new file mode 100644 index 0000000..96d3f35 --- /dev/null +++ b/src/Forms/PasswordForm.php @@ -0,0 +1,31 @@ +field=new PasswordField(); + + } + + public function form() + { + + return ''; + + } + +} + +?> diff --git a/src/Forms/SelectForm.php b/src/Forms/SelectForm.php new file mode 100644 index 0000000..cd325d8 --- /dev/null +++ b/src/Forms/SelectForm.php @@ -0,0 +1,61 @@ +arr_select=$arr_select; + + } + + public function form() + { + + //return ''; + $arr_selected[$this->default_value]=' selected'; + + ob_start(); + + ?> + + diff --git a/src/Forms/TextAreaForm.php b/src/Forms/TextAreaForm.php new file mode 100644 index 0000000..8dba1a5 --- /dev/null +++ b/src/Forms/TextAreaForm.php @@ -0,0 +1,19 @@ + + + diff --git a/src/ModelForm.php b/src/ModelForm.php new file mode 100644 index 0000000..92f9ab1 --- /dev/null +++ b/src/ModelForm.php @@ -0,0 +1,552 @@ +std_error + * + */ + + public $txt_error; + + /** + * Internal string used for identify fields when name fields protection is used. + * + */ + + public $html_field_name=''; + + /** + * Boolean that defined if this ModelForm is required in the form or not. If is required, set to true or to 1. + * + */ + + public $required=0; + + /** + * Internal boolean that control if the field was filled correctly or not. + * + */ + + public $error_flag=0; + + /** + * Array for save the fields for external checkings. + */ + + static public $arr_form_public=array(); + + /** + * Boolean property that set DEBUG mode + */ + + static public $debug=1; + + /** + * Constructor for create a new ModelForm. ModelForm are used for create forms easily. + * + * @param string $name_form The name of the form where is inserted this form element + * @param string $name_field The name of this ModelForm + * @param string $form String with the name of the function for show the form. For example 'TextForm'. + * @param string $label Text that is used on html form for identify the field. + * @param PhangoField $type PhangoField instance, you need this if you want check the value of the ModelForm. + * @param boolean $required Internal boolean that control if the field was filled correctly or not. + * @param array $parameters Set first set of parameters for $this->form. This element cover the third argument of a Form function. + * + */ + + function __construct($name_form, $name_field, $form, $label, $type, $required=0, $parameters='') + { + + $this->name_form = $name_form; + $this->name = $name_field; + $this->form = $form; + $this->type = $type; + $this->label = $label; + $this->std_error = ''; + $this->txt_error = _('Error in field'); + $this->required = $required; + + $this->html_field_name=$name_field; + + /*switch(ModelForm::$debug) + {*/ + + /*default: + + $prefix_uniqid=Utils::generate_random_password(); + + if(!isset($_SESSION['fields_check'][$name_field])) + { + $this->html_field_name=uniqid($prefix_uniqid); + + $_SESSION['fields_check'][$name_field]=$this->html_field_name; + $_SESSION['fields_check'][$this->html_field_name]=$name_field; + + } + else + { + + $this->html_field_name=$_SESSION['fields_check'][$name_field]; + + } + + break; + + case 1:*/ + + $this->html_field_name=$name_field; + + + //break; + //} + + //$this->html_field_name=$name_field; slugify($this->label, $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); + + ModelForm::$arr_form_public[$this->html_field_name]=$name_field; + + $this->parameters = array($this->html_field_name, $class='', $parameters); + + } + + public function change_label_html($new_label) + { + + $this->html_field_name=slugify($new_label, $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); + + $this->parameters[0]=$this->html_field_name; + + } + + public function return_name_form() + { + + return $this->html_field_name; + + } + + + /** + * + * Method for set default value in the form. + * + * @param mixed $value The value passed to the form + * @param string $form_type_set Parameter don't used for now. + * + */ + + public function set_param_value_form($value, $form_type_set='') + { + + $func_setvalue=$this->form.'Set'; + + //$this->parameters[2]=$func_setvalue($this->parameters[2], $value, $form_type_set); + $this->parameters[2]=call_user_func_array($func_setvalue, array($this->parameters[2], $value, $form_type_set)); + + } + + + /** + * + * Method for set third argument of a form function. Third argument can be mixed type. + * + * @param mixed $parameters Third argument for the chose form function + * + */ + + public function set_parameter_value($parameters) + { + + $this->parameters[2]=$parameters; + + } + + /** + * + * Method for set all arguments for a form function except name. + * + * @param mixed $parameters Third argument for the chose form function + * + */ + + public function set_parameters_form($parameters=array()) + { + + $z=1; + + foreach($parameters as $parameter) + { + + $this->parameters[$z]=$parameter; + + $z++; + + } + + } + + public function set_parameter($key, $value) + { + + $this->parameters[$key]=$value; + + } + + /** + * + * @warning + * + * Method for set all arguments of a form function. DONT USE IF YOU DON'T KNOW WHAT ARE YOU DOING + * + * @param array $parameters An array with arguments for the form function used for this ModelForm + * + */ + + public function set_all_parameters_form($parameters) + { + + $this->parameters=$parameters; + + } + + /** + * + * Static method for check an array of ModelForm instances. + * + * With this method you can check if the values of an array called $post (tipically $_POST) are valid for the corresponding values of an array $arr_form, consisting of ModelForm items. + * + * @param array $arr_form Array consisting of ModelForm items, used for check the values. The array need keys with the name of the ModelForm instance. + * @param array $post Array consisting of values. The array need that the keys was the same of $arr_form. + * + */ + + static public function check_form($arr_form, $post) + { + + $error=0; + + $num_form=0; + + foreach($post as $key_form => $value_form) + { + + //settype($post[$key_form], 'string'); + + if(isset($arr_form[$key_form])) + { + + $form=$arr_form[$key_form]; + + $post[$key_form]=$form->setform($post[$key_form]); + + //If isset how false the error field..., then error. + + if($post[$key_form]=='' && $form->required==1) + { + + if($form->std_error=='') + { + $form->std_error=_('Field is required'); + + } + + $form->error_flag=1; + + if($form->required==1) + { + + $error++; + + } + + } + + } + + $num_form++; + + } + + if($error==0 && $num_form>0) + { + + return [$arr_form, $post]; + + } + + return [$arr_form, false]; + + } + + /** + * + * Fill a ModelForm array with default values. + * + * With this method you can set an array consisting of ModelForm items with the values from $post. + * + * @param array $post is an array with the values to be inserted on $arr_form. The keys must have the same name that keys from $arr_form + * @param array $arr_form is an array of ModelForms. The key of each item is the name of the ModelForm item. + * @param array $show_error An option for choose if in the form is showed + */ + + static public function set_values_form($arr_form, $post, $show_error=1) + { + + //Foreach to $post values + + if(gettype($post)=='array') + { + foreach($post as $name_field => $value) + { + + //If exists a ModelForm into $arr_form with the same name to $name_field check if have a $component field how "type" and set error if exists + + if(isset($arr_form[$name_field])) + { + + if($show_error==1) + { + /* + if($arr_form[$name_field]->std_error!='') + { + + $arr_form[$name_field]->std_error=$arr_form[$name_field]->txt_error; + + + } + else + if($arr_form[$name_field]->std_error=='') + { + + $arr_form[$name_field]->std_error=$arr_form[$name_field]->field->std_error; + + }*/ + + if($arr_form[$name_field]->std_error=='') + { + + $arr_form[$name_field]->std_error=_('Field is required'); + + } + /*else + { + + + + }*/ + + } + + //Set value for ModelForm to $value + + $arr_form[$name_field]->default_value=$value; + + + } + else + { + + unset($post[$name_field]); + + } + + } + + } + + return $arr_form; + } + + /*static public function pass_errors_to_form($model) + { + + foreach(array_keys($model->components) as $key) + { + + if(isset($model->forms[$key])) + { + + + $model->forms[$key]->field->std_error=$model->components[$key]->std_error; + + } + + } + + return $model; + + } + + static public function pass_errors_to_array($model) + { + + $error=[]; + + foreach($model->components as $component) + { + + $error[$component->name_component]=$component->std_error; + + } + + return $error; + + }*/ + + static public function show_form($arr_form, $post, $pass_values=false, $check_values=false, $keys_form=[]) + { + + if($pass_values) + { + + $arr_form=ModelForm::set_values_form($arr_form, $post, $show_error=1); + + } + + if(count($keys_form)==0) + { + + $keys_form=array_keys($arr_form); + + } + + //return View::load_view([$arr_form, $keys_form], 'forms/modelform'); + ob_start(); + + $arr_required[0]=''; + $arr_required[1]='*'; + + $fields=array_keys($arr_form); + + + ?> + +
+ form; + + switch($func_form) + { + + default: + + $label_class=$arr_form[$field]->label_class; + + ?> + +

+ + parameters); + + ?> +

+ parameters)."\n"; + + break; + + }*/ + $label_class=$arr_form[$field]->label_class; + ?> +

+ + form(); + + ?> +

+ +
+ +