====== dhtml class source code ======
__**Note:**__ It's PHP 4 code.
/**
* php_dhtml
* Copyright (C) 2004 Eric Colinet
* http://wildphp.free.fr
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Default debug mode
*/
if( !defined('DHTML_DEBUG') ) define('DHTML_DEBUG', 0 );
/**
* Static DHTML Member debug - debug on/off
*/
$GLOBALS['dhtml_class_debug']= DHTML_DEBUG;
/**
* Static DHTML Member wnds - the list of all windows
*/
$GLOBALS['dhtml_class_wnds']= array();
/**
* Static DHTML Member return_code - the return code of exit
*/
$GLOBALS['dhtml_class_return_code']= 0;
/**
* Static DHTML Member wnd_messages - Inter-windows messages
*/
$GLOBALS['dhtml_class_wnd_messages']= array();
/**
* dhtml class - a wrapper class for the php_dhtml extension.
*/
class dhtml {
/**
* php_dhtml resource
*/
var $wnd;
/**
* Window id
*/
var $id;
/**
* wether if the window have been closed
* @todo implement it on php_dhtml
*/
var $closed;
/**
* TMP file - used by load_string
* @todo find a way to unlink it automatically (register_shutdown_function for PHP4/_destruct for PHP5)
*/
var $tmp_file;
/**
* Wrappers
*/
function dhtml_create() { return dhtml_create(); }
function dhtml_get_id($wnd) { return dhtml_get_id($wnd); }
function dhtml_set($wnd, $what, $value, $extra) { return dhtml_set($wnd, $what, $value, $extra); }
function dhtml_get($wnd, $what, $value) { return dhtml_get($wnd, $what, $value); }
function dhtml_get_event($wait) { return dhtml_get_event($wait); }
function dhtml_is_closed($wnd) { return dhtml_is_closed($wnd); }
function dhtml($title='', $page= false, $show=true, $size=null) {
$this->wnd= $this->dhtml_create();
$this->id= $this->dhtml_get_id($this->wnd);
$this->Log("Created (".get_class($this).", id: $this->id)");
$this->closed= 0;
$GLOBALS['dhtml_class_wnds'][$this->id]= &$this;
if( $size ) $this->size( $size );
if( $title ) $this->set_title($title);
if( $show ) $this->show();
if( $page ) $this->load_rc($page);
}
/************************
php_dhtml get/set wrappers
************************/
function _set($what, $value='', $extra=null) {
$this->Log("SET '$what'\t'$value'\t'$extra'\n");
$ret= $this->dhtml_set($this->wnd, $what, $value, $extra);
if( !$ret ) $this->Error("set $what failed", '_set');
return $ret;
}
function _get($what, $value='') {
$result= $this->dhtml_get($this->wnd, $what, $value);
$this->Log("GET '$what'\t'$value'\t=> '$result'");
return $result;
}
/********************
Browser Window control
*********************/
function show() {
return $this->_set( 'show');
}
function hide() {
return $this->_set( 'hide');
}
function focus() {
return $this->_set( 'focus');
}
function minimize() {
return $this->_set( 'minimize');
}
function maximize() {
return $this->_set( 'maximize');
}
function restore() {
return $this->_set( 'restore');
}
function size($x, $y=false) {
if( !$y )
return $this->_set( 'size', "$x" ); // ie: $x='640x480'
else
return $this->_set( 'size', "{$x}x{$y}" ); // ie: $x=640 $y=480
}
function move($x, $y) {
return $this->_set( 'move', "{$x}x{$y}" );
}
function close() {
$this->closed= 1;
return $this->_set( 'close');
}
function enable() {
return $this->_set('enable');
}
function disable() {
return $this->_set('disable');
}
function caption($on=true) {
return $this->_set('caption', $on?1:0);
}
function border($on=true) {
return $this->_set('border', $on?1:0);
}
function maximizebox($on=true) {
return $this->_set('maximizebox', $on?1:0);
}
function minimizebox($on=true) {
return $this->_set('minimizebox', $on?1:0);
}
function sysmenu($on=true) {
return $this->_set('sysmenu', $on?1:0);
}
function sizebox($on=true) {
return $this->_set('sizebox', $on?1:0);
}
function dlgframe($on=true) {
return $this->_set('dlgframe', $on?1:0);
}
function appwindow($on=true) {
return $this->_set('appwindow', $on?1:0);
}
function clientedge($on=true) {
return $this->_set('clientedge', $on?1:0);
}
function toolwindow($on=true) {
return $this->_set('toolwindow', $on?1:0);
}
function topmost($on=true) {
return $this->_set('topmost', $on?1:0);
}
function windowedge($on=true) {
return $this->_set('windowedge', $on?1:0);
}
function redraw() {
return $this->_set('redraw');
}
/**
* load_url wrapper - Try to help using it
*/
function load_rc($url) {
$this->Log("Load_rc $url");
/* c: d: file:, http:, mhtml: and others */
if( ereg('^[a-z]+:', $url) ) return $this->load_url( $url );
/* So is it a file system file ? */
if( !file_exists($url) ) return $this->Error("'$url' doesn't exists", 'load_rc');
return $this->load_url(realpath($url));
}
/**
* Load an url - use load_rc instead
* Be sure to specify a full path name when requesting a file - or use load_rc.
*/
function load_url($url) {
return $this->_set( 'url', $url );
}
/**
* Load a default template - you can use the id 'content' to access the body of the default page
*/
function load_default() {
return $this->_set('load_default');
}
/**
* Reload the current url
*/
function reload() {
return $this->_set('reload');
}
/************************************************************
set or retrieve (depending of the number of arguments) an HTML id property
************************************************************/
/**
* get/set a tag's 'inner' HTML code.
* innerHTML: the Code that is between the opening and the ending tags.
* IE then parse the HTML code to display it.
*/
function id_html($id) {
if( func_num_args()>1 ) { $v= func_get_arg(1); return $this->_set( 'id_html', $id, $v ); }
return $this->_get( 'id_html', $id );
}
/**
* get/set a tag's attribute 'value' (ie: )
*/
function id_value($id) {
if( func_num_args()>1 ) { $v= func_get_arg(1); return $this->_set( 'id_value', $id, $v ); }
return $this->_get( 'id_value', $id );
}
/**
* get/set a tag's 'inner' TEXT.
* Mostly the same as id_html but the TEXT is not parsed by IE.
*/
function id_text($id) {
if( func_num_args()>1 ) { $v= func_get_arg(1); return $this->_set( 'id_text', $id, $v ); }
return $this->_get( 'id_text', $id );
}
/**
* get/set a tag's 'outer' HTML. The same as id_html but also include the tag contents.
*/
function id_outer_html($id) {
if( func_num_args()>1 ) { $v= func_get_arg(1); return $this->_set( 'id_outer_html', $id, $v ); }
return $this->_get( 'id_outer_html', $id );
}
/**
* get/set a 'A' tag's attribute 'HREF' (ie: Text).
*/
function id_a_href($id) {
if( func_num_args()>1 ) { $v= func_get_arg(1); return $this->_set( 'id_a_href', $id, $v ); }
return $this->_get( 'id_a_href', $id );
}
/**
* get/set a 'A' tag's attribute 'target' (ie Text).
* Please note that frames and iframes are not supported at this time by php_dhtml (but it should!).
*/
function id_a_target($id) {
if( func_num_args()>1 ) { $v= func_get_arg(1); return $this->_set( 'id_a_target', $id, $v ); }
return $this->_get( 'id_a_target', $id );
}
/**
* get/set a 'IMG' tag's 'SRC' (ie: ).
*/
function id_img_src($id) {
if( func_num_args()>1 ) { $v= func_get_arg(1); return $this->_set( 'id_img_src', $id, $v ); }
return $this->_get( 'id_img_src', $id );
}
/**
* get/set a 'FRAME' or 'IFRAME' tag's 'SRC' attribute (ie: