<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.9 www.exoops.info 2006/05
//v1.8 www.exoops.info 2006/03 
// $Id: misc.php,v 1.7 2003/05/22 16:39:47 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include_once("./mainfile.php");
if ( $action == "showpopups" ) {
	xoops_header(false);
	$closebutton = 1;
switch ( $type ) {
case "images":
	include_once("./include/image_manager.php");
	break;
case "smilies":
	echo "
	<script type='text/javascript'>
	<!--
	function doSmilie(addSmilie) {
	var currentMessage = window.opener.xoopsGetElementById(\"".$target."\").value;
	window.opener.xoopsGetElementById(\"".$target."\").value=currentMessage+addSmilie;
	return;
	}
	//-->
	</script>
	</head><body>
	<table width='100%'><tr>
	<td colspan='3'><big><b>"._SMILIES."</b></big><br />"._CLICKASMILIE."</td>
	</tr><tr class='bg2'>
	<td><b>"._CODE."</b></td>
	<td><b>"._EMOTION."</b></td>
	<td><b>"._IMAGE."</b></td>
	</tr>";
	if ( $getsmiles = $db->query("SELECT code, emotion, smile_url FROM ".$db->prefix("smiles")) ) {
		$rcolor = 'bg1';
		while ( $smile = $db->fetchArray($getsmiles) ) {
			echo "<tr class='$rcolor'><td>".$smile['code']."</td><td>".$smile['emotion']."</td><td><a href='javascript: justReturn()' onclick='doSmilie(\" ".$smile['code']." \");'><img src='".formatURL(XOOPS_URL."/images/smilies/", $smile['smile_url'])."' alt='' /></a></td></tr>";
			if ( $rcolor == 'bg1' ) {
				$rcolor = 'bg2';
				} else {
					$rcolor = 'bg1';
				}
			}
			} else {
				echo "Could not retrieve data from the database.";
			}
			echo "</table>";
	break;
case "avatars":
	if ( $xoopsUser && $xoopsUser->isAdmin() && !empty($_FILES['image']['name']) ) {
		include_once(XOOPS_ROOT_PATH."/class/upload.class.php");
		$upload = new Upload();
		$upload->setUploadPath(XOOPS_ROOT_PATH . "/images/avatar/$subdir");
		$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
		$upload->setMaxImageSize($bcoosConfig['avatar_width'], $bcoosConfig['avatar_height']);
		$upload->setMaxFileSize($bcoosConfig['avatar_maxsize']);
		$upload->setDestinationFileName('image');
		$result = $upload->doUpload();
		if ($result) {
			?>
			<script type='text/javascript'>
			window.opener.location.reload();
			</script>
			<?php
			
		} else {
			$errors = $upload->getUploadErrors();
			$errorstring = "";
			$errorstring .= "<strong>::Errors occured::</strong><br />\n";
			while(list($filename,$values) = each($errors)) {
				$errorstring .= "File: " . $filename . "<br />";
				$count = count($values);
				for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
				
			}
			redirect_header("edituser.php", 3, $errorstring);
			exit();
		}
	} elseif ( $_GET["delete"] && $xoopsUser && $xoopsUser->isAdmin() && preg_match("'[a-z0-9_/-]+\.(gif|jpg|png)$'i", $_GET["delete"]) ) {
			if ( @file_exists(XOOPS_ROOT_PATH . "/images/avatar/" . $_GET["delete"]) ) {
				unlink(XOOPS_ROOT_PATH . "/images/avatar/" . $_GET["delete"]);
				?>
				<script type='text/javascript'>
					window.opener.location.reload();
				</script>
				<?php
			}
		}
	?>
	<script type='text/javascript'>
	<!--
	function myimage_onclick(counter) {
	xselect = window.opener.xoopsGetElementById("user_avatar");
	ximage  = window.opener.xoopsGetElementById("avatar");
	xselect.options[counter].selected = true;
	ximage.src='<?php echo XOOPS_URL;?>/images/avatar/' + xselect.options[counter].value;
	window.close();
	}
	//-->
	</script>
	</head><body>
	<h4><?php echo _AVAVATARS;?></h4>
	<?php
	include_once(XOOPS_ROOT_PATH."/class/xoopslists.php");
	if ( !isset($subdir) ) {
		$subdir = "";
	}
	$lists       = new XoopsLists;
	$avatarslist = $lists->getAvatarsList($subdir);
	$counter     = isset($start) ? intval($start) : 0;
	foreach ($avatarslist as $avatar) {
		echo "<span><a href='javascript:void();'><img src='images/avatar/".$avatar."' alt='"._SELECT.": ".$avatar."' onclick='myimage_onclick($counter)' hspace='5' vspace='5' border='0' /></a>";
		if ($xoopsUser && $xoopsUser->isAdmin() && ($avatar != "blank.gif")) {
			echo "<a href='"._REQUEST_URI."&delete=$avatar'><img src='".XOOPS_URL."/images/x.gif' border='0' alt='"._DELETE.": ".$avatar."'></a>";
		}
		echo "</span>";
		$counter++;
	}
	if ($xoopsUser && $xoopsUser->isAdmin()) {
		?>
		<div align="center">
		<form name="upload" enctype="multipart/form-data" method="post" action="<?php echo _REQUEST_URI;?>">
		<input type="file" name="image" id="image" />
		<input type="submit" class="button" name="submit" value="<?php echo _UPLOADAVATAR;?>">
		</td></form></div>
		<?php
	}
	break;
case "friend":
	if ( !isset($op) || $op == "sendform" ) {
		if ( $xoopsUser ) {
			$yname = $xoopsUser->getVar("uname");
			$ymail = $xoopsUser->getVar("email");
			$fname = "";
			$fmail = "";
			} else {
				break;
			}
		printCheckForm();
		echo "
		</head><body>
		<table width='100%' border='0' cellspacing='1' cellpadding='0'><tr class='bg2'><td valign='top'>
		<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg3'><td valign='top'>
		<h4>"._RECOMMENDSITE."</h4>
		<form action='".XOOPS_URL."/misc.php' method='post' id='friend' onsubmit='return checkForm();'>
		<table width='100%'><tr><td>
		<input type='hidden' name='op' value='sendsite' />
		<input type='hidden' name='action' value='showpopups' />
		<input type='hidden' name='type' value='friend' />
		"._YOURNAMEC."</td><td><input type='text' class='text' name='yname' value='$yname' id='yname' /></td></tr>
		<tr><td>"._YOUREMAILC."</td><td>".$ymail."</td></tr>
		<tr><td>"._FRIENDNAMEC."</td><td><input type='text' class='text' name='fname' value='$fname' id='fname' /></td></tr>
		<tr><td>"._FRIENDEMAILC."</td><td><input type='text' class='text' name='fmail' value='$fmail' id='fmail' /></td></tr>
		<tr><td align='center' colspan='2'><br /><br /><input type='submit' class='button' value='"._SEND."' />&nbsp;<input value='"._CLOSE."' type='button' class='button' onclick='javascript:window.close();' /></td></tr>
		</table></form>";
		$closebutton = 0;
		echo "</td></tr></table></td></tr></table>";
		} elseif ( $op == "sendsite" ) {
			if ( $xoopsUser ) {
				$ymail = $xoopsUser->getVar("email");
				} else {
					break;
				}
			if ( !isset($yname) || $yname == "" || !isset($fname) || $fname == ""  || !$fmail ) {
				redirect_header(XOOPS_URL."/misc.php?action=showpopups&amp;type=friend&amp;op=sendform",2,_NEEDINFO);
				exit();
				}
			if ( !checkEmail($fmail) ) {
				$errormessage = _INVALIDEMAIL1."<br />"._INVALIDEMAIL2."";
				redirect_header(XOOPS_URL."/misc.php?action=showpopups&amp;type=friend&amp;op=sendform",2,$errormessage);
				exit();
				}
			$xoopsMailer =& getMailer();
			$xoopsMailer->setTemplate("tellfriend.tpl");
			$xoopsMailer->assign("SITENAME", $bcoosConfig['title']);
			$xoopsMailer->assign("ADMINMAIL", $bcoosConfig['adminmail']);
			$xoopsMailer->assign("SITEURL", XOOPS_URL."/");
			$xoopsMailer->assign("YOUR_NAME", $yname);
			$xoopsMailer->assign("FRIEND_NAME", $fname);
			$xoopsMailer->setToEmails($fmail);
			$xoopsMailer->setFromEmail($xoopsUser->getVar("email"));
			$xoopsMailer->setFromName($yname);
			$xoopsMailer->setSubject(sprintf(_INTSITE, $bcoosConfig['title']));
			echo "
			<table width='100%' border='0' cellspacing='1' cellpadding='0'><tr class='bg2'><td valign='top'>
			<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg3'><td valign='top'>";
			if ( !$xoopsMailer->send() ) {
				echo $xoopsMailer->getErrors();
				} else {
					echo "<h5>"._REFERENCESENT."</h5>";
				}
			echo "</td></tr></table></td></tr></table>";
			}
	break;
}
if ($closebutton) {
	echo "<div align='center'><input value='"._CLOSE."' type='button' class='button' onclick='javascript:window.close();' /></div><br />";
}
xoops_footer(0);
}
function printCheckForm() {
?>
<script type='text/javascript'>
<!--
function checkForm() {
if ( xoopsGetElementById("yname").value == "" ) {
	alert( "<?php echo _ENTERYNAME;?>" );
	xoopsGetElementById("yname").focus();
	return false;
	} else if ( xoopsGetElementById("fname").value == "" ) {
		alert( "<?php echo _ENTERFNAME;?>" );
		xoopsGetElementById("fname").focus();
		return false;
	} else if ( xoopsGetElementById("fmail").value =="") {
		alert( "<?php echo _ENTERFMAIL;?>" );
		xoopsGetElementById("fmail").focus();
		return false;
	} else {
		return true;
	}
}
//--->
</script>
<?php
}
?>
