Skip to content
tform_base.inc.php 48.2 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)
 *        - 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.
 *
 */
class tform_base {
	/**
	 * Definition of the database table (array)
	 * @var tableDef
	 */
	var $tableDef;

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

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

	/**
	 * Debug Variable
	 * @var debug
	 */
	var $debug = 0;

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

	/**
	 * contains the error messages
	 * @var errorMessage
	 */
	var $errorMessage = '';

	var $dateformat = "d.m.Y";
	var $datetimeformat = 'd.m.Y H:i';
	var $formDef = array();
	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;
		include $file;
		$this->formDef = $form;
		$this->module = $module;
		$wb = array();
		include_once ISPC_ROOT_PATH.'/lib/lang/'.$_SESSION['s']['language'].'.lng';
		if(is_array($wb)) $wb_global = $wb;
		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;
		}
		if(is_array($wb_global)) {
			$wb = $app->functions->array_merge($wb_global, $wb);
		}
		if(isset($wb_global)) unset($wb_global);
		$this->wordbook = $wb;
		$this->dateformat = $app->lng('conf_format_dateshort');
		$this->datetimeformat = $app->lng('conf_format_datetime');
		* Converts the data in the array to human readable format
		* Datatype conversion e.g. to show the data in lists
		*
		* @param record
		* @param tab
		* @param apply_filters
		* @return record
		*/
	protected function _decode($record, $tab = '', $api = false) {
		global $app;
		$new_record = '';
		if($api == false) {
			$table_idx = $this->formDef['db_table_idx'];
			if(isset($record[$table_idx])) $new_record[$table_idx] = $app->functions->intval($record[$table_idx ]);
			$fields = &$this->formDef['tabs'][$tab]['fields'];
		} else {
			$fields = &$this->formDef['fields'];
		}

		if(is_array($record)) {
			foreach($fields as $key => $field) {

				//* Apply filter to record value.
				if($api == false && isset($field['filters']) && is_array($field['filters'])) {
					$record[$key] = $this->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SHOW');
				switch ($field['datatype']) {
				case 'VARCHAR':
					$new_record[$key] = ($api == true ? stripslashes($record[$key]) : $record[$key]);
					break;
				case 'TEXT':
					$new_record[$key] = ($api == true ? stripslashes($record[$key]) : $record[$key]);
					break;
				case 'DATETSTAMP':
					if($record[$key] > 0) {
Loading full blame...