Skip to content
tform.inc.php 72 KiB
Newer Older
<?php

/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**
* Formularbehandlung
*
* Functions to validate, display and save form values
*
*        Database table field definitions
*
*        Datatypes:
*        - INTEGER (Converts data to int automatically)
*        - DOUBLE
*        - CURRENCY (Formats digits in currency notation)
*        - VARCHAR (No format check)
jwarnier's avatar
jwarnier committed
*        - DATE (Date format, converts from and to UNIX timestamps automatically)
*
*        Formtype:
*        - TEXT (Normal text field)
*        - PASSWORD (password field, the content will not be displayed again to the user)
*        - SELECT (Option fiield)
*        - MULTIPLE (Allows selection of multiple values)
*
*        VALUE:
*        - Value or array
*
*        SEPARATOR
*        - separator char used for fileds with multiple values
*
*        Hint: The auto increment (ID) filed of the table has not be be definied separately.
        * Definition of the database table (array)
        * @var tableDef
        */
        var $tableDef;

        /**
        * Private
        * @var action
        */
        var $action;

        /**
        * Table name (String)
        * @var table_name
        */
        var $table_name;

        /**
        * name of the primary field of the database table (string)
        * @var table_index
        */
        var $table_index;

        /**
        * @var errorMessage
        */
        var $errorMessage = '';

        var $dateformat = "d.m.Y";
        var $wordbook;
        var $module;
        var $primary_id;
		var $diffrec = array();

        /**
        * Loading of the table definition
        *
        * @param file: path to the form definition file
        * @return true
        */
        /*
        function loadTableDef($file) {
                global $app,$conf;

                include_once($file);
                $this->tableDef = $table;
                $this->table_name = $table_name;
                $this->table_index = $table_index;
                return true;
        }
        */

    function loadFormDef($file,$module = '') {
                global $app,$conf;

                $this->formDef = $form;

                $this->module = $module;
				$wb = array();
				
				include_once(ISPC_ROOT_PATH.'/lib/lang/'.$_SESSION['s']['language'].'.lng');
                if($module == '') {
					$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng";
					if(!file_exists($lng_file)) $lng_file = "lib/lang/en_".$this->formDef["name"].".lng";
					include($lng_file);
                } else {
					$lng_file = "../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng";
					if(!file_exists($lng_file)) $lng_file = "../$module/lib/lang/en_".$this->formDef["name"].".lng";
					include($lng_file);
                }
					$wb = $app->functions->array_merge($wb_global,$wb);
				}
				if(isset($wb_global)) unset($wb_global);
				
				
				$this->dateformat = $app->lng('conf_format_dateshort');

                return true;
        }


        /**
        * Converts the data in the array to human readable format
        * Datatype conversion e.g. to show the data in lists
        *
        * @param record
        * @return record
        */
        function decode($record,$tab) {
                global $conf, $app;
				if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab does not exist or the tab is empty (TAB: $tab).");
				$table_idx = $this->formDef['db_table_idx'];
				if(isset($record[$table_idx])) $new_record[$table_idx] = $app->functions->intval($record[$table_idx ]);
						foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) {
                                
								//* Apply filter to record value.
								if(isset($field['filters']) && is_array($field['filters'])) {
									$record[$key] = $this->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SHOW');
								}
								
								switch ($field['datatype']) {
                                        $new_record[$key] = $record[$key];
                                        $new_record[$key] = $record[$key];
                                        if($record[$key] > 0) {
                                                $new_record[$key] = date($this->dateformat,$record[$key]);
                                        }
                                break;
								
								case 'DATE':
                                        if($record[$key] != '' && $record[$key] != '0000-00-00') {
												$tmp = explode('-',$record[$key]);
                                                $new_record[$key] = date($this->dateformat,mktime(0, 0, 0, $tmp[1]  , $tmp[2], $tmp[0]));
Loading full blame...