Location: PHPKode > projects > LDAPted > ldapted/includes/controls/Control.php
<?php
/***************************************************************************
 *
 *                                  Control.php
 *                              -------------------
 *
 *   begin                : Friday, Jul 5, 2002
 *   copyright            : (C) 2002 The Kabramps Team
 *   email                : hide@address.com,
 *                          hide@address.com
 *
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   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.
 *   (http://www.gnu.org/licenses/gpl.html)
 *
 ***************************************************************************/

class Control
{

	var $dn;
	var $attribute;                    // cn, uid
	var $attributeoptions = array();   // maxsize etc
	var $required = false;             // TODO: a better way to include input validation
	var $value = array();
	var $label;
	var $description;                    // Description in the XML-File
	var $template_view = 'default_view.tpl';
	var $template_edit = 'default_edit.tpl';
	var $jsfiles = array();
	var $errors = array();
  
	function Control ()
	{}

	function init( $dn, $attribute, $config, $lang = 'en')
	{
		$this->dn               = $dn;
		$this->attribute        = $attribute;
		$this->lang             = $lang;
		$this->label            = $config->get_label( $attribute, $lang );
		$this->description      = $config->get_attribute_description( $attribute, $lang);
		$this->attributeoptions = $config->get_attribute_options( $attribute );
		
		if ($this->attributeoptions['template_view'] )
		{
			$this->template_view = $this->attributeoptions['template_view'];
		}
		if ($this->attributeoptions['template_edit'])
		{
			$this->template_edit = $this->attributeoptions['template_edit'];
		}
		if( $this->attributeoptions['required'] )
		{
			$this->required = true;
		}
	}

	function get_view( $mode )
	{
		if( $mode == 'edit' )
		{
			return $this->get_edit_panel();
		}
		else
		{
			return $this->get_view_panel();
		}
	}

  function get_view_panel () {
    die(gettext("Control.php: get_view_panel not overwritten for"." ".$this->attribute));
  }

  function get_edit_panel () {
    return $this->get_view_panel( $attriberros );
  }

	function get_search_panel()
	{
		global $language; // not sure if we need this here
    
		$tmpl = new TPLInterface();
    
		$tmpl->assign(array("MAXLENGTH"  => $this->attributeoptions['maxlenght'],
		                    "SIZE"       => $this->attributeoptions['size'],
		                    "ATTRIBLABEL"=> $this->label,
		                    "ATTRIBNAME" => $this->attribute
		             ));
		return $tmpl->fetch("controls/search.tpl");
	}

  function get_value () {
    return $this->utf8_LDAPencode($this->value);
  }

  function set_value( $value ) { //no good concept with get and set... :-(
    $this->value=$value;
  }
  
  // interprets the given value of the html-formular and returns
  // the corresponding LDAP value
  function html2LDAPvalue ($htmlValue, $mode = '')
  {
    return $this->utf8_LDAPencode(array($htmlValue));
  }
  
  function utf8_LDAPencode ($array) {
    return $array;
  }

  function utf8_LDAPdecode ($array) {
    return $array;
  }

  function get_jsfiles() {
    return $this->jsfiles;
  }

  function get_error_message() {
    $return = '';
    if (is_array($this->errors)) {
      for ($i = 0; $i < count($this->errors); $i++) {
	if ($this->errors[$i] != "") {
	  $return .= $this->errors[$i];
	  if ($i != (count($this->errors)-1))
	    $return .= "\n";
	}
      }
    }
    return $return;
  }
  function add_error_message( $text ) {
    $this->errors[] = $text;
  }

  function add_error_messages( $array ) {
    if (is_array( $this->errors )) {
      $tmp = array_merge($this->errors, $array);
      $this->errors = $tmp;
    } else {
      $this->errors = $array;
    }
  }
  
  function get_template($mode) {
  	$return = "controls/".$this->get_class_name()."/";
  	if ($mode == "edit") {
  	  $return .= $this->template_edit;
  	} else {
  	  $return .= $this->template_view;
  	}
  	return $return;
  }

	// php4 and 5 behave different
	function get_class_name()
	{
		$php_version = phpversion();
		$php_version = $php_version[0];

		if( $php_version == 5 )
		{
			return get_class($this);
		}
		else
		{
			$classname = get_class($this);
			return strtoupper($classname[0]).substr($classname, 1);
		}
	}
	
	function set_attribute( $attribute )
	{
		$this->attribute = $attribute;
	}
	
	function get_attribute()
	{
		return $this->attribute;
	}
}
?>
Return current item: LDAPted