<?php
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.8 www.exoops.info 2006/03 
// $Id: smilies.php,v 1.7 2003/03/19 07:04:10 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function SmilesAdmin() {
global $db, $myts, $xoopsModule;
$url_smiles = XOOPS_URL."/images/smilies";
xoops_cp_header();
OpenTable();
echo "<h4 style='text-align:left;'>"._AM_CURRENTSMILE."</h4>";
if ($getsmiles = $db->query("SELECT * FROM ".$db->prefix("smiles"))) {
	if ($db->getRowsNum($getsmiles) > 0) {
		?>
		<table border="0" cellpadding="0" cellspacing="0" align="center" valign="top" width="100%"><tr>
		<td class="bg2">
		<table width="100%" border="0" cellpadding="4" cellspacing="1"><tr class="bg3">
		<td><b><?php echo _AM_CODE;?></b></td>
		<td align="center"><b><?php echo _AM_SMILIE;?></b></td>
		<td align="center"><b><?php echo _AM_EMOTION;?></b></td>
		<td align="right"><b><?php echo _ACTION;?></b></td>
		</tr>
		<?php
		while ($smiles = $db->fetchArray($getsmiles)) {
			?>
			<tr class="bg1">
			<td><?php echo $myts->makeTboxData4Show($smiles['code']);?></td>
			<td align="center"><img src="<?php echo formatURL($url_smiles, $smiles['smile_url']);?>"></td>
			<td align="center"><?php echo $myts->makeTboxData4Show($smiles['emotion']);?></td>
			<td align="right"><a href="admin.php?fct=smilies&op=SmilesEdit&id=<?php echo $smiles['id'];?>"><?php echo _EDIT;?></a> | <a href="admin.php?fct=smilies&op=SmilesDel&id=<?php echo $smiles['id'];?>"><?php echo _DELETE;?></a></td>
			</tr>
			<?php
		}
		echo "</table></td></tr></table>";
	}
	} else {
		echo _AM_CNRFTSD;
	}
?>
<br /><br />
<h4 style="text-align:left;"><?php echo _AM_ADDSMILE;?></h4>
<form action="admin.php" method="post" enctype="multipart/form-data">
<table border="0" cellpadding="0" cellspacing="0" align="center" valign="top" width="100%"><tr>
<td class="bg2">
<table width="100%" border="0" cellpadding="4" cellspacing="1"><tr>
<td class="bg3"><b><?php echo _AM_SMILECODE;?></b></td>
<td class="bg1"><input type="text" class="text" name="code" /></td>
</tr><tr>
<td class="bg3" valign="top"><b><?php echo _AM_SMILEURL;?></b></td>
<td class="bg1">
<input type="text" class="text" name="smile_url" /> :: <input type="file" class="file" name="image" />
<br /><?php printf(_AM_VALIDUNDER, "images/smilies/");?>
</td>
</tr><tr>
<td class="bg3"><b><?php echo _AM_SMILEEMOTION;?></b></td>
<td class="bg1"><input type="text" class="text" name="emotion" /></td>
</tr><tr>
<td class="bg3">&nbsp;</td>
<td class="bg1">
<input type="hidden" name="fct" value="smilies" />
<input type="hidden" name="op" value="SmilesAdd" />
<input type="submit" class="button" value="<?php echo _ADD;?>" />
</td></tr></table>
</td></tr></table>
</form>
<?php
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function SmilesEdit($id) {
global $db, $myts, $xoopsModule;
xoops_cp_header();
OpenTable();
echo "<h4 style='text-align:left;'>"._AM_EDITSMILE."</h4>";
if ($getsmiles = $db->query("SELECT * FROM ".$db->prefix("smiles")." WHERE id = $id")) {
	if ($smiles = $db->fetchArray($getsmiles)) {
		?>
		<form action="admin.php" method="post" enctype="multipart/form-data">
		<table border="0" cellpadding="0" cellspacing="0" valign="top" width="100%"><tr>
		<td class="bg2">
		<table width="100%" border="0" cellpadding="4" cellspacing="1"><tr>
		<td class="bg3"><b><?php echo _AM_SMILECODE;?></b></td>
		<td class="bg1"><input type="text" class="text" name="code" value="<?php echo $myts->makeTboxData4Edit($smiles['code']);?>" /></td>
		</tr><tr>
		<td class="bg3"><b><?php echo _AM_SMILEURL;?></b></td>
		<td class="bg1">
		<input type="text" class="text" name="smile_url" value="<?php echo $myts->makeTboxData4Edit($smiles['smile_url']);?>" /> :: <input type="file" class="file" name="image" />
		<br /><?php printf(_AM_VALIDUNDER, "images/smilies/");?>
		</td>
		</tr><tr>
		<td class="bg3"><b><?php echo _AM_SMILEEMOTION;?></b></td>
		<td class="bg1"><input type="text" class="text" name="emotion" value="<?php echo $myts->makeTboxData4Edit($smiles['emotion']);?>" /></td>
		</tr><tr>
		<td class="bg3">
		<input type="hidden" name="id" value="<?php echo $smiles['id'];?>" />
		<input type="hidden" name="op" value="SmilesSave" />
		<input type="hidden" name="fct" value="smilies" />
		</td>
		<td class="bg1"><input type="submit" class="button" value="<?php echo _SAVE;?>" /></td>
		</tr></table>
		</td></tr></table>
		</form>
		<?php
	}
	} else {
		echo _AM_CNRFTSD;
	}
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function SmilesAdd($code, $smile_url, $emotion) {
global $db, $myts, $_FILES;
$code      = $myts->makeTboxData4Save($code);
$smile_url = $myts->makeTboxData4Save($smile_url);
$emotion   = $myts->makeTboxData4Save($emotion);
$sql = "SELECT id FROM `".$db->prefix("smiles")."` ORDER BY id DESC LIMIT 1";
$queryid = $db->query($sql) or $eh->show("0013");
	if ($db->getRowsNum($queryid) == 0 ) {
		$newid = 1;
	} else {
		$newid =  $db->result($queryid,0);
		$newid++;
	}
if ( !empty($_FILES['image']['name']) ) {
	include_once(XOOPS_ROOT_PATH."/class/upload.class.php");
	$upload = new Upload();
	$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
	$upload->setUploadPath(XOOPS_ROOT_PATH."/images/smilies");
	$upload->setDestinationFileName('image');
	$upload->setFileName($newid);
	
	$result = $upload->doUpload();
	if ($result) {
		$smile_url = $upload->FileName.".".$upload->getFileExtension();
	}
}
if ( !empty($code) && !empty($smile_url) ) {
	$db->query("INSERT INTO ".$db->prefix("smiles")." SET id=$newid, code='$code', smile_url='$smile_url', emotion='$emotion'");
	redirect_header("admin.php?fct=smilies&op=SmilesAdmin", 2, _UPDATED);
	} else {
		redirect_header("admin.php?fct=smilies&op=SmilesAdmin", 2, _NOTUPDATED);
	}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function SmilesSave($id, $code, $smile_url, $emotion) {
global $db, $myts, $_FILES;
$code      = $myts->makeTboxData4Save($code);
$smile_url = $myts->makeTboxData4Save($smile_url);
$emotion   = $myts->makeTboxData4Save($emotion);
if ( !empty($_FILES['image']['name']) ) {
	include_once(XOOPS_ROOT_PATH."/class/upload.class.php");
	$upload = new Upload();
	$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
	$upload->setUploadPath(XOOPS_ROOT_PATH."/images/smilies/");
	$upload->setDestinationFileName('image');
	$upload->setFileName($id);
	
	$result = $upload->doUpload();
	if ($result) {
		$smile_url = $upload->FileName.".".$upload->getFileExtension();
	}
}
if ( !empty($code) && !empty($smile_url) ) {
	$db->query("UPDATE ".$db->prefix("smiles")." SET code='$code', smile_url='$smile_url', emotion = '$emotion' WHERE id = $id");
	redirect_header("admin.php?fct=smilies&op=SmilesAdmin", 2, _UPDATED);
	} else {
		redirect_header("admin.php?fct=smilies&op=SmilesAdmin", 2, _NOTUPDATED);
	}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function SmilesDel($id, $ok=0) {
global $db, $xoopsModule;
if ($ok==1) {
	if ($result = $db->query("SELECT smile_url FROM ".$db->prefix("smiles")." where id=$id")) {
		list($smile) = $db->fetchRow($result);
		@unlink(XOOPS_ROOT_PATH."/images/smilies/".basename($smile));
	}
	$db->query("DELETE FROM ".$db->prefix("smiles")." where id=$id");
	redirect_header("admin.php?fct=smilies&op=SmilesAdmin", 2, _UPDATED);
	exit();
	} else {
		xoops_cp_header();
		OpenTable();
		echo "
		<br /><font color='#ff0000'><b>"._AM_WAYSYWTDTS."</b>
		<br /><br /></font><table><tr><td>";
		echo myTextForm("admin.php?fct=smilies&op=SmilesDel&id=$id&ok=1", _YES);
		echo "</td><td>";
		echo myTextForm("admin.php?fct=smilies&op=SmileAdmin", _NO);
		echo "</td></tr></table><br /><br />";
		CloseTable();
		xoops_cp_footer();
	}
}
//---------------------------------------------------------------------------------------//
} else {
	echo "Access Denied";
}
?>
