<?php
/***************************************************************************
*
* Image.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 Image extends Control
{
var $dnobj = object; // dn string with additional functions
function Image ()
{}
function get_view_panel ($attriberrors = null)
{
$tmpl = new TPLInterface();
$this->dnobj = new dnInterpreter( $this->dn );
if ($this->value[0] != "" )
{
$link = $this->dnobj->get_dn();
$maxheight = $this->attributeoptions["maxheight"];
$maxwidth = $this->attributeoptions["maxwight"];
}
else
{
$link = "nopic";
}
$tmpl->assign(array("DESCRIPTION" => $this->description,
"ATTRIBLABEL" => $this->label,
"DN" => $link,
"ATTRIBNAME" => $this->attribute,
"MAXHEIGHT" => $maxheight,
"MAXWIGHT" => $maxwight,
"SOURCE_TYPE" => "image/jpeg",
"SOURCE_ALT" => $this->dnobj->get_label( $this->dnobj->get_leaf() )
));
return $tmpl->fetch($this->get_template('view'));
}
function get_edit_panel ()
{
$tmpl = new TPLInterface();
$this->dnobj = new dnInterpreter($this->dn);
if ($this->value[0] != "" )
{
$link = $this->dnobj->get_dn();
$maxheight = $this->attributeoptions["maxheight"];
$maxwidth = $this->attributeoptions["maxwight"];
}
else
{
$link = "nopic";
}
$tmpl->assign(array("DESCRIPTION" => $this->description,
"ATTRIBLABEL" => $this->label,
"ATTRIBNAME" => $this->attribute,
"SOURCE_TYPE" => "image/jpeg",
"SOURCE_ALT" => $this->dnobj->get_label($this->dnobj->get_leaf()),
"DN" => $link,
"MAXHEIGHT" => $maxheight,
"MAXWIGHT" => $maxwidth,
"ERRORMESSAGE" => $this->get_error_message()
));
return $tmpl->fetch($this->get_template('edit'));
}
function html2LDAPvalue( $htmlvalue, $mode )
{
$return = array();
if ( $_REQUEST['remove'] ) // user wants to remove the image
{
$return[] = array();
}
elseif ( file_exists( $_FILES[$this->attribute]['tmp_name'] ) ) // new image is to be upload
{
// image maxsize handling
if ($_FILES[$this->attribute]['size'] <= $this->get_max_size() )
{
$file_name = $_FILES[$this->attribute]['tmp_name'];
$file_size = $_FILES[$this->attribute]['size'];
$return[] = $this->convert_image( $file_name, $file_size );
}
else
{
$this->add_error_message(gettext('Image to big.'));
}
}
return $return;
}
function get_max_size()
{
if (!$this->attributeoptions['maxsize'])
{
$this->attributeoptions['maxsize'] = 100000;
}
return $this->attributeoptions['maxsize'];
}
// convert uploaded image
function convert_image( $file_name, $file_size = null )
{
$fp = fopen($file_name, 'r');
$content = fread ($fp, $file_size);
$encodedcontent = $content;
fclose ($fp);
return $encodedcontent;
}
}
?>