Location: PHPKode > projects > phpCAMALEO > skinMNGR.php
<?php
/***************************************************************************
 *	skinMNGR.php
 *
 *	begin		: August 2006
 *	version		: 21 October 2006
 *	copyright	: (C) 2006 grandolini.net
 *
 *	phpCAMALEO skin manager
 *
 ***************************************************************************/
ini_set('max_execution_time',0);
session_start(); $_SESSION[id]=session_id();
$_SESSION[sitelanguage]='';
#
if(!file_exists('private/Host.inc'))
{
	header('Location: install/Setup.php');
	die;
	#-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
}
#
if(isset($_GET[installcomplete]))
{
	#---| installation completed |---#
	#
	if($_SESSION[setupCAMALEO]=='*OK*')
	{
		unset($_SESSION[setupCAMALEO]);
		header('Location: skinMNGR.php');
		die;
		#-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
	}
}
#
if(isset($_GET[admin])) { $_SESSION[skinMNGRadmin]='on'; }
#
$skin='phpCAMALEO';
#
include('Session.php');
#
$_SESSION[misc][skin]='phpCAMALEO';
$_SESSION[skinf]=$_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/phpCAMALEO/';
check_path($_SESSION[skinf],'Layout.php');
#
include($_SESSION[skinf].'def/'.$_SESSION[sitelanguage].'/common_defs.php');
include($_SESSION[skinf].'def/'.$_SESSION[sitelanguage].'/skinMNGR_defs.php');
$PageNr='skinMNGR';
include_once($_SESSION[skinf].'head.php');
#
if($_POST[exp_all]!='')			{ $exp_all='checked'; }
if($_POST[cdefsk_exp_dir]!='')	{ $cdefsk_exp_dir='checked'; }
if($_POST[remove_exp_dir]!='')	{ $remove_exp_dir='checked'; }
if(!isset($_POST[exp_zip]) || $_POST[exp_zip]=='')
								{ $exp_zip_no='checked'; }
if($_POST[exp_zip]=='gz')		{ $exp_zip_gz='checked'; }
if($_POST[exp_zip]=='bz2')		{ $exp_zip_bz2='checked'; }
$exp_zip_type=$_POST[exp_zip];
#
switch($_POST[submit])
{
	#======================
	case 'GO!':
	#======================
		$feedback=check_skin($_POST[opt_skin]);
		if($feedback=='OKIDOKI')
		{
			#	load the required skin
			#
			$skin=$_POST[opt_skin];
			$_SESSION[misc][skin]=$skin;
			$_SESSION[sitelanguage]='';
			$_SESSION[skinMNGRadmin]='off';
  			header('Location: LoadPage.php?page=welcome');
			die;
			#-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
		}
		break;
	#======================
	case SET_DEF_SKIN:
	#======================
		$feedback=check_skin($_POST[opt_skin]);
		if($feedback=='OKIDOKI')
		{
			#	set the required skin as default
			#
			$sth=db_query("SELECT * FROM site_settings WHERE site='*default' AND code='site'");
			if($sth[1]==0)
			{
				$sth=db_query("INSERT INTO site_settings SET site='*default',code='site',value='$_POST[opt_skin]'");
			}
			else
			{
				$sth=db_query("UPDATE site_settings SET value='$_POST[opt_skin]' WHERE site='*default' AND code='site'");
			}
			$feedback=BuildConfirmString(2002).'#@#1';
		}
		else
		{
			$feedback=BuildErrorString(1026).'#@#1';			
		}
		break;
	#======================
	case PERM_TEST_BTN:
	#======================
		$result=test_rights();
		if($result=='OKIDOKI') { $feedback='<img src="img/smile.gif" />&nbsp;'.PERM_TEST_OK; } else { $feedback='<img src="img/warning.gif" />&nbsp;'.PERM_TEST_ERR.'<hr id="line" />'.$result; }
		$feedback.='<hr id="line" />';
		break;
	#======================
	case EXPORT:
	#======================
		$feedback=check_expskin();
		if($feedback=='OKIDOKI')
		{
			$_ROOT=$_SERVER[DOCUMENT_ROOT].'/';
			if(substr($_ROOT,-2,2)=='//') { $_ROOT=substr($_ROOT,0,-1); }
			#
			if($exp_all=='')
			{
				$export_src =$_SESSION[misc][folder].'skins/'.$_POST[opt_skin];
				$basedir	=$_ROOT;
				$export_tgt ='phpCAMALEO_'.$_POST[opt_skin].'.EXP';
			}
			else
			{
				$export_src	=$_SESSION[misc][folder];
				$basedir	=$_ROOT;
				$export_tgt	='phpCAMALEO_'.$_POST[opt_skin].'.EXP.FULL';
				define(EXP_FULL_FLAG,$_POST[opt_skin]);
			}
			if(file_exists($basedir.$export_tgt)) { dirdelete($export_tgt,$basedir); }
			mkdir($basedir.$export_tgt,0777);
			#
			$result=dircopy($export_src,$export_tgt,$basedir);
			#
			if($result=='OKIDOKI')
			{
				?><script type="text/javascript">pop('<?=EXP_DB?>');</script><?php flush(); ob_flush();
				#
				#	export skin db entries in a text file
				#
				$fd=@fopen($_ROOT.$export_tgt.'/MySQL_data.sql','w');
				if(!$fd) { $errlst[$e]=PERM_TEST_FOPEN; $er++; }
				else
				{
					$query='SELECT * FROM site_settings WHERE site=\''.$_POST[opt_skin].'\''; # only selected skin
					#
					if($_POST[exp_all]!='')
					{
						if($_POST[cdefsk_exp_dir]=='')
						{
							#	the selected skin and camaleo
							#
							$query='SELECT * FROM site_settings WHERE LEFT(site,1)!=\'*\' AND (site=\''.$_POST[opt_skin].'\' OR site=\'phpCAMALEO\')';
						}
						else
						{
							#	all skins
							#
							$query='SELECT * FROM site_settings WHERE LEFT(site,1)!=\'*\'';
						}
					}
					$sth=db_query($query.' ORDER BY site ASC, code ASC');
					$t=$sth[1];
					$rows=db_fetch($sth[0],false);
					for($i=0;$i<$t;$i++)
					{
						if($_POST[exp_all]=='' || file_exists($_ROOT.$export_tgt.'/skins/'.$rows[$i][site]))
						{
							#	create mysql record only if is a single skin export or the skin is found in the export directory
							#
							switch($rows[$i][code])
							{
								case '*site':	$value=$rows[$i][value];	break;
								case 'SITE':	$value=$rows[$i][value];	break;
								case 'theme':	$value=$rows[$i][value];	break;
								default:		$value='$$$=default';
							}
							$result=@fwrite($fd,'INSERT IGNORE INTO `site_settings` VALUES (\''.$rows[$i][site].'\', \''.$rows[$i][code].'\', \''.$value.'\');'."\n");
							if($result!=true) { $errlst[$e]=PERM_TEST_FWRITE; $e++; }
						}
					}
					fclose($fd);
				}
				if($exp_zip_type!='no')
				{
					#	compressing exported data
					#
					?><script type="text/javascript">pop('<?=ZIPPING?>');</script><?php flush(); ob_flush();
					chdir($_ROOT);
					if(file_exists($basedir.$export_tgt.'tar.'.$exp_zip_type)) { unlink($basedir.$export_tgt.'tar.'.$exp_zip_type); }
					#
					if($_SERVER[HTTP_HOST]=='kyuxpt')
					{
						#	|===============================|
						#	|								|
						#	| windows server				|
						#	| 								|
						#	|===============================|
						#
						switch($exp_zip_type)
						{
							case 'gz':	passthru('c:\Programmi\tar\bin\bsdtar -czf "'.$export_tgt.'.tar.gz" "'.$export_tgt.'"',$result); break;
							case 'bz2':	passthru('c:\Programmi\tar\bin\bsdtar -cyf "'.$export_tgt.'.tar.bz2" "'.$export_tgt.'"',$result); break;
						}
						# if($result==0) { operation is ok }
					}
					else
					{
						#	|===============================|
						#	|								|
						#	| need help with LINUX servers! |
						#	|								|
						#	|===============================|
					}
					if($remove_exp_dir!='') { dirdelete($export_tgt,$basedir); }
				}
				?><script type="text/javascript">pop('');</script><?php flush(); ob_flush();
				$feedback='<script type="text/javascript">pop(\''.EXPORT_SUCCESS.'\',\''.$_SERVER[PHP_SELF].'\',3);</script>';
			}
			else { $feedback='<img src="img/warning.gif" />&nbsp;'.EXPORT_ERR.'<hr id="line" />'.$result; }
		}
		break;
	#======================
	case CREATE_BTN:
	#======================
		$feedback=check_addskin();
		if($feedback=='OKIDOKI')
		{
			#	copy skin data
			#
			$result=dircopy($_POST[opt_skin],$_POST[newskinid]);
			#
			if($result=='OKIDOKI')
			{
				#	handling database entries for the new skin
				#
				$sth=db_query('SELECT * FROM site_settings WHERE site=\''.$_POST[opt_skin].'\'');
				$t=$sth[1];
				$rows=db_fetch($sth[0],false);
				for($i=0;$i<$t;$i++)
				{
					#	copy settings from the source skin
					#
					$sth=db_query('SELECT * FROM site_settings WHERE site=\''.$_POST[newskinid].'\' AND code=\''.$rows[$i][code].'\'');
					if($sth[1]==0)	{ $sth=db_query('INSERT INTO site_settings SET site=\''.$_POST[newskinid].'\', code=\''.$rows[$i][code].'\', value=\''.$rows[$i][value].'\''); }
					else			{ $sth=db_query('UPDATE site_settings SET value=\''.$rows[$i][value].'\' WHERE site=\''.$_POST[newskinid].'\' AND code=\''.$rows[$i][code].'\''); }
				}
				#	check/generate headers entries for the new skin
				#
				#	*site
				$sth=db_query('SELECT * FROM site_settings WHERE site=\''.$_POST[newskinid].'\' AND code=\'*site\'');
				if($sth[1]==0)	{ $sth=db_query('INSERT INTO site_settings SET site=\''.$_POST[newskinid].'\', code=\'*site\', value=\'phpCAMALEO skin: '.strtoupper($_POST[newskinid]).'\''); }
				else			{ $sth=db_query('UPDATE site_settings SET value=\'phpCAMALEO skin: '.strtoupper($_POST[newskinid]).'\' WHERE site=\''.$_POST[newskinid].'\' AND code=\'*site\''); }
				#
				#	SITE
				$sth=db_query('SELECT * FROM site_settings WHERE site=\''.$_POST[newskinid].'\' AND code=\'SITE\'');
				if($sth[1]==0)	{ $sth=db_query('INSERT INTO site_settings SET site=\''.$_POST[newskinid].'\', code=\'SITE\', value=\''.strtoupper($_POST[newskinid]).' a phpCAMALEO skin\''); }
				else			{ $sth=db_query('UPDATE site_settings SET value=\''.strtoupper($_POST[newskinid]).' a phpCAMALEO skin\' WHERE site=\''.$_POST[newskinid].'\' AND code=\'SITE\''); }
				#
				#	theme
				$sth=db_query('SELECT * FROM site_settings WHERE site=\''.$_POST[newskinid].'\' AND code=\'theme\'');
				if($sth[1]==0)	{ $sth=db_query('INSERT INTO site_settings SET site=\''.$_POST[newskinid].'\', code=\'theme\', value=\''.strtoupper($_POST[newskinid]).' a phpCAMALEO skin\''); }
				else			{ $sth=db_query('UPDATE site_settings SET value=\''.$_POST[newskinid].'\' WHERE site=\''.$_POST[newskinid].'\' AND code=\'theme\''); }
				#
				@unlink($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'tmp/last_update_'.$_POST[newskinid].'.inc'); # remove the last update include
				#
				?><script type="text/javascript">pop('');</script><?php flush(); ob_flush();
				$feedback='<script type="text/javascript">pop(\''.CREATE_SUCCESS.'\',\''.$_SERVER[PHP_SELF].'\',3);</script>';
			}
			else { $feedback='<img src="img/warning.gif" />&nbsp;'.$result; }
		}
		break;
}
if($_POST[submit]==DELETE_BTN || isset($_GET[deleteconfirmed]))
{
	#======================
	#	delete skin
	#======================
	$feedback=check_delskin();
	if($feedback=='OKIDOKI' || (isset($_GET[deleteconfirmed]) && isset($_SESSION[skin2del]) && $_SESSION[skin2del]!=''))
	{
		if(isset($_GET[deleteconfirmed]))
		{
			#	skin data files
			#
			$result=dirdelete($_SESSION[skin2del]);
			#
			if($result=='OKIDOKI')
			{
				#	database entries
				#
				$sth=db_query('DELETE FROM site_settings WHERE site=\''.$_SESSION[skin2del].'\'');
				?><script type="text/javascript">pop('');</script><?php flush(); ob_flush();
				$feedback='<script type="text/javascript">pop(\''.DELETE_SUCCESS.'\',\''.$_SERVER[PHP_SELF].'\',3);</script>';
			}
			else { $feedback='<img src="img/warning.gif" />&nbsp;'.$result; }
			unset($_SESSION[skin2del]);
		}
		else
		{
			$_SESSION[skin2del]=$_POST[newskinid];
			?><script type="text/javascript">if(confirm('<?=CONFIRM_DELETE.strtoupper($_POST[newskinid])?>\n')==true) { window.location="<?=$_SERVER[PHP_SELF]?>?deleteconfirmed"; } else { window.location="<?=$_SERVER[PHP_SELF]?>"; }</script><?php
		}
	}
}
list($feedback_str,$err_i)=explode('#@#',$feedback);
#
$sth=db_query("SELECT * FROM site_settings WHERE site!='*hlp' AND code='*site' ORDER BY value ASC");
$rows=db_fetch($sth[0],false);
#
if($sth[1]==1 && $_SESSION[skinMNGRadmin]!='on')
{
	#	there is only ONE skin installed: load it!
	#	note: phpCAMALEO own skin is NOT taken into account (the db '*site' record is intentionally not included)
	#
	$_SESSION[misc][SITECODE]=$rows[0][site];
	$_SESSION[misc][SITE]=$rows[0][value];
	$_SESSION[misc][skin]=$rows[0][site];
	$_SESSION[sitelanguage]='';
	header('Location: LoadPage.php?page=welcome&skid='.$rows[0][site]);
	die;
	#-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
}
else
{
	$tmp=array();
	$tmp[site]='phpCAMALEO'; $tmp[code]='phpCAMALEO'; $tmp[value]='phpCAMALEO';
	array_push($rows,$tmp);
	$t=$sth[1]+1;
	include($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'contents/skinMNGR.tpl');
}
#
#=========================
function check_skin($skin)
#=========================
{
	unset($_SESSION[misc][SITECODE],$_SESSION[misc][SITE]);
	if(!isset($skin) || $skin=='') { return; }
	$args="SELECT * FROM site_settings WHERE site='$skin'"; if($skin!='phpCAMALEO') { $args.=" AND code='*site'"; }
	$sth=db_query($args);
	if($sth[1]>0)
	{
		$row=db_fetch($sth[0],false);
		$_SESSION[misc][SITECODE]=$row[0][site];
		$_SESSION[misc][SITE]=$row[0][value];
		return('OKIDOKI');
	}
}
#=========================
function check_addskin()
#=========================
{
	if($_POST[opt_skin]=='') { return(BuildErrorString(1026).'#@#1'); }
	if($_POST[newskinid]=='') 	{ return(BuildErrorString(1027).'#@#2'); }
	$sth=db_query("SELECT * FROM site_settings WHERE site='".$_POST[newskinid].'\'');
	if($sth[1]>0)				{ return(BuildErrorString(1028).'#@#2'); }
	if(file_exists($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/'.$_POST[newskinid]))
								{ return(BuildErrorString(1029).'#@#2'); }
	if(strtolower($_POST[opt_skin])=='phpcamaleo') 
								{ return(BuildErrorString(1035).'#@#1'); }
	return('OKIDOKI');
}
#=========================
function check_delskin()
#=========================
{
	if($_POST[newskinid]=='') 	{ return(BuildErrorString(1030).'#@#2'); }
	if($_POST[opt_skin]!=$_POST[newskinid]) { return(BuildErrorString(1031).'#@#2'); }
	$sth=db_query("SELECT * FROM site_settings WHERE site='".$_POST[newskinid].'\'');
	if($sth[1]==0)				{ return(BuildErrorString(1032).'#@#2'); }
	if(!file_exists($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/'.$_POST[newskinid]))
								{ return(BuildErrorString(1033).'#@#2'); }
	return('OKIDOKI');
}
#=========================
function check_expskin()
#=========================
{
	if(!$_POST[opt_skin]) { return(BuildErrorString(1026).'#@#1'); }
	if(strtolower($_POST[opt_skin])=='phpcamaleo') 
								{ return(BuildErrorString(1036).'#@#1'); }
	return('OKIDOKI');
}
#=========================
function test_rights()
#=========================
{
	$_TESTD=$_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/test_permissions_dir_'.date('Y-m-d');
	$_TESTF=$_TESTD.'/test_permissions_file_'.date('Y-m-d').'.txt';
	$errlst=array(); $e=0;
	#
	$result=@mkdir($_TESTD, 0755);	# everything to the owner, read and execute for others
	if($result!=true) { $errlst[$e]=PERM_TEST_MKDIR; $e++; }
	#
	$result=@chmod($_TESTD,0777);	# everything to everyone
	if($result!=true) { $errlst[$e]=PERM_TEST_CHMOD; $e++; }
	#
	$fd=@fopen($_TESTF,'w');
	if(!$fd) { $errlst[$e]=PERM_TEST_FOPEN; $er++; }
	else
	{
		$result=@fwrite($fd,'Written by '.$_SERVER[PHP_SELF].', function: test_rights()');
		if($result!=true) { $errlst[$e]=PERM_TEST_FWRITE; $e++; }
		fclose($fd);
	}
	#
	if($fd)
	{
		$result=unlink($_TESTF);if($result!=true) { $errlst[$e]=PERM_TEST_UNLINK; $e++; }	# delete test file
		$result=rmdir($_TESTD);	if($result!=true) { $errlst[$e]=PERM_TEST_RMDIR; $e++; }	# remove test dir
	}
	if($e==0) { return('OKIDOKI'); }
	#
	#	found at least one error
	#
	$tmp='';
	for($i=0;$i<=$e;$i++) { $tmp.=$errlst[$i].'<br />'; }
	return($tmp);
}
#=========================
function dircopy($source,$target,$basedir='')
#=========================
{
	if($basedir=='') { $_ROOT=$_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/'; } else { $_ROOT=$basedir; }
	if(!file_exists($_ROOT.$target))
	{
		#	create the destination directory
		#
		$result=mkdir($_ROOT.$target, 0755);
		if($result!=true) { $errlst[$e]=CREATE_ERR_DIR.$_ROOT.$target; $e++; }
	}
	$errlst=array(); $e=0;
	#
	if($handle=opendir($_ROOT.$source))
	{
		while(($file=readdir($handle))!==false)
		{
			if(	(is_dir($_ROOT.$source.'/'.$file)===true && $file!='.' && $file!='..' && $file!=EXP_FULL_FLAG.'.EXP.FULL') &&
				(	$_POST[cdefsk_exp_dir]!='' ||
					( 
						$_POST[cdefsk_exp_dir]=='' &&
						(
							 $source!=$_SESSION[misc][folder].'/skins' || 
							($source==$_SESSION[misc][folder].'/skins' && $file==EXP_FULL_FLAG) || 
							($source==$_SESSION[misc][folder].'/skins' && $file=='phpCAMALEO')
						)
					)
				)
			)
			{
				if(	 EXP_FULL_FLAG=='' ||												# if its a normal copy
					(EXP_FULL_FLAG!='' && $source!=$_SESSION[misc][folder].'skins') ||	# its a full skin copy and we are NOT in the /skins dir
					(EXP_FULL_FLAG!='' && $source==$_SESSION[misc][folder].'skins' && $file==EXP_FULL_FLAG)  # its a full skin copy and we ARE in the /skins dir and the skin subdir IS the one we want to export
				)
				{
					if(!file_exists($_ROOT.$target.'/'.$file))
					{
						$result=mkdir($_ROOT.$target.'/'.$file, 0755);
						if($result!=true) { $errlst[$e]=CREATE_ERR_DIR.$file; $e++; }
						else
						{
							dircopy($source.'/'.$file, $target.'/'.$file,$basedir);
						}
					}
				}
			}
			if(is_file($_ROOT.$source.'/'.$file) && $file!='Thumbs.db')
			{
				$result=copy($_ROOT.$source.'/'.$file, $_ROOT.$target.'/'.$file);
				if($result!=true) { $errlst[$e]=CREATE_ERR_COPY.$file; $e++; }
				?><script type="text/javascript">pop('<?=PLS_WAIT?><br /><font id="sml"><?=$_ROOT.'<br />'.$target.'<br />'.$file?></font>');</script><?php flush(); ob_flush();
			}
		}
		closedir($handle);
	}
	if($e==0) { return('OKIDOKI'); }
	#
	#	found at least one error
	#
	$tmp =CREATE_ERR_TITLE.'<hr id="line" />';
	$tmp.=CREATE_ERR_SRC.$_ROOT.$source.'<br />';
	$tmp.=CREATE_ERR_TGT.$_ROOT.$target.'<hr id="line" />';
	for($i=0;$i<=$e;$i++) { $tmp.=$errlst[$i].'<br />'; }
	return($tmp);
}
#=========================
function dirdelete($target,$basedir='')
#=========================
{
	if($basedir=='') { $_ROOT=$_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/'.$target.'/'; } else { $_ROOT=$basedir.$target.'/'; }
	$errlst=array(); $e=0;
	#
	if($handle=opendir($_ROOT))
	{
		while(($file=readdir($handle))!==false)
		{
			if(is_dir($_ROOT.$file)===true && $file!='.' && $file!='..') { dirdelete($target.'/'.$file,$basedir); }
			if(is_file($_ROOT.$file))
			{
				$result=unlink($_ROOT.$file);
				if($result!=true) { $errlst[$e]=DELETE_ERR_UNLINK.$file; $e++; }
				?><script type="text/javascript">pop('<?=PLS_WAIT?><br /><font id="sml"><?=$_ROOT.'<br />'.$file?></font>');</script><?php flush(); ob_flush();
			}
		}
		closedir($handle);
	}
	#
	$result=@rmdir($_ROOT);
	if($result!=true) { $errlst[$e]=DELETE_ERR_RMDIR.$_ROOT; $e++; }
	#
	if($e==0) { return('OKIDOKI'); }
	#
	#	found at least one error
	#
	$tmp =DELETE_ERR_TITLE.'<hr id="line" />';
	$tmp.=DELETE_ERR_TGT.$_ROOT.'<hr id="line" />';
	for($i=0;$i<=$e;$i++) { $tmp.=$errlst[$i].'<br />'; }
	return($tmp);
}
#-------------0.0.1a
#=========================
function dircopy001a($source,$target,$basedir='')
#=========================
{
	if($basedir=='') { $_ROOT=$_SESSION[root].'skins/'; } else { $_ROOT=$basedir; }
	$errlst=array(); $e=0;
	#
	if($handle=opendir($_ROOT.$source))
	{
		while(($file=readdir($handle))!==false)
		{
			if(is_dir($_ROOT.$source.'/'.$file)===true)
			{
				if(EXP_FULL_FLAG=='' || (EXP_FULL_FLAG!='' && $source!=$_SESSION[misc][folder].'/skins') || (EXP_FULL_FLAG!='' && $source==$_SESSION[misc][folder].'/skins' && $file==EXP_FULL_FLAG))
				{
					#	if its a normal copy || its a full skin copy and we are NOT in the /skins dir || its a full skin copy and we ARE in the /skins dir and the skin subdir IS the one we want to export
					#
					if(!file_exists($_ROOT.$target.'/'.$file))
					{
						$result=mkdir($_ROOT.$target.'/'.$file, 0755);	# everything to the owner, read and execute for others
						if($result!=true) { $errlst[$e]=CREATE_ERR_DIR.$file; $e++; }
						dircopy($source.'/'.$file, $target.'/'.$file,$basedir);
					}
				}
			}
			if(is_file($_ROOT.$source.'/'.$file) && $file!='Thumbs.db')
			{
				$result=copy($_ROOT.$source.'/'.$file, $_ROOT.$target.'/'.$file);
				if($result!=true) { $errlst[$e]=CREATE_ERR_COPY.$file; $e++; }
				?><script type="text/javascript">pop('<?=PLS_WAIT?><br /><font id="sml"><?=$_ROOT.'<br />'.$target.'<br />'.$file?></font>');</script><?php flush(); ob_flush();
			}
		}
		closedir($handle);
	}
	if($e==0) { return('OKIDOKI'); }
	#
	#	found at least one error
	#
	$tmp =CREATE_ERR_TITLE.'<hr id="line" />';
	$tmp.=CREATE_ERR_SRC.$_ROOT.$source.'<br />';
	$tmp.=CREATE_ERR_TGT.$_ROOT.$target.'<hr id="line" />';
	for($i=0;$i<=$e;$i++) { $tmp.=$errlst[$i].'<br />'; }
	return($tmp);
}
?>
Return current item: phpCAMALEO