Skip to content
remoting_lib.inc.php 33.9 KiB
Newer Older
tbrehm's avatar
tbrehm committed
<?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.

--UPDATED 08.2009--
Full SOAP support for ISPConfig 3.1.4 b
Updated by Arkadiusz Roch & Artur Edelman
Copyright (c) Tri-Plex technology

*/

/**
 * 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.
 *
 */

tbrehm's avatar
tbrehm committed

class remoting_lib {



	/**
	 * Definition of the database table (array)
	 * @var tableDef
	 */
	private $tableDef;

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

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

	/**
	 * Debug Variable
	 * @var debug
	 */
	private $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 $formDef = array();
	var $wordbook;
	var $module;
	var $primary_id;
	var $diffrec = array();

	var $sys_username;
	var $sys_userid;
	var $sys_default_group;
	var $sys_groups;
	var $client_id;
	var $dataRecord;


	//* Load the form definition from file.
	function loadFormDef($file) {
		global $app, $conf;

		include $file;

		$this->formDef = $form;
		unset($this->formDef['tabs']);

		//* Copy all fields from all tabs into one form definition
		foreach($form['tabs'] as $tab) {
			foreach($tab['fields'] as $key => $value) {
				$this->formDef['fields'][$key] = $value;
tbrehm's avatar
tbrehm committed
			}
		}
		unset($form);

		$this->dateformat = $app->lng('conf_format_dateshort');

		return true;
	}

	//* Load the user profile
	function loadUserProfile($client_id_param = 0) {
		global $app, $conf;

		$this->client_id = $app->functions->intval($client_id_param);

		if($this->client_id == 0) {
			$this->sys_username         = 'admin';
			$this->sys_userid            = 1;
			$this->sys_default_group     = 1;
			$this->sys_groups            = 1;
			$_SESSION["s"]["user"]["typ"] = 'admin';
		} else {
			//* load system user - try with sysuser and before with userid (workarrond)
			/*
tbrehm's avatar
tbrehm committed
				$user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE sysuser_id = $client_id");
				if(empty($user["userid"])) {
						$user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE userid = $client_id");
						if(empty($user["userid"])) {
								$this->errorMessage .= "No sysuser with the ID $client_id found.";
								return false;
						}

			$user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE client_id = $this->client_id");
			$this->sys_username         = $user['username'];
			$this->sys_userid            = $user['userid'];
			$this->sys_default_group     = $user['default_group'];
			$this->sys_groups             = $user['groups'];
			// $_SESSION["s"]["user"]["typ"] = $user['typ'];
			// we have to force admin priveliges for the remoting API as some function calls might fail otherwise.
			$_SESSION["s"]["user"]["typ"] = 'admin';
		}
tbrehm's avatar
tbrehm committed

		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) {
		$new_record = '';
		if(is_array($record)) {
			foreach($this->formDef['fields'] as $key => $field) {
				switch ($field['datatype']) {
				case 'VARCHAR':
					$new_record[$key] = stripslashes($record[$key]);
					break;

				case 'TEXT':
					$new_record[$key] = stripslashes($record[$key]);
Loading full blame...