<?php
/**
* Form control creating an hidden field for an object derived from IcmsPersistableObject
*
* @copyright	The ImpressCMS Project http://www.impresscms.org/
* @license		http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @package		IcmsPersistableObject
* @since		1.1
* @author		marcan <marcan@impresscms.org>
* @version		$Id: icmsformimageelement.php 1889 2008-04-30 15:54:09Z malanciault $
*/

if (!defined('ICMS_ROOT_PATH')) die("ImpressCMS root path not defined");

class IcmsFormImageElement extends XoopsFormElementTray {
    function IcmsFormImageElement($object, $key) {
    	$var = $object->vars[$key];
        $object_imageurl = $object->getImageDir();
        $this->XoopsFormElementTray( $var['form_caption'], ' ' );


        $objectArray['image'] = str_replace('{XOOPS_URL}', XOOPS_URL, $objectArray['image']);


        if($object->getVar($key) != '' && (substr($object->getVar($key), 0, 4) == 'http' || substr($object->getVar($key), 0, 11) == '{XOOPS_URL}')){
        	$this->addElement( new XoopsFormLabel( '', "<img src='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key)) . "' alt='' /><br/><br/>" ) );
        }elseif($object->getVar($key) != ''){
        	$this->addElement( new XoopsFormLabel( '', "<img src='" . $object_imageurl . $object->getVar($key) . "' alt='' /><br/><br/>" ) );
       	}

        include_once ICMS_ROOT_PATH."/class/icmsform/elements/icmsformfileuploadelement.php";
        $this->addElement(new IcmsFormFileUploadElement($object, $key));

		$this->addElement(new XoopsFormLabel( '<div style="height: 10px; padding-top: 8px; font-size: 80%;">'._CO_ICMS_URL_FILE_DSC.'</div>', ''));
		include_once ICMS_ROOT_PATH."/class/icmsform/elements/icmsformtextelement.php";
        include_once ICMS_ROOT_PATH."/class/icmsform/elements/icmsformcheckelement.php";

        $this->addElement(new XoopsFormLabel( '', '<br />' . _CO_ICMS_URL_FILE));
        $this->addElement(new IcmsFormTextElement($object, 'url_'.$key));
        $this->addElement(new XoopsFormLabel( '', '<br /><br />'));
        $delete_check = new IcmsFormCheckElement('', 'delete_'.$key);
        $delete_check->addOption(1, '<span style="color:red;">'._CO_ICMS_DELETE.'</span>');
        $this->addElement($delete_check);
    }
}
?>