<?php
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.0 www.exoops.info 2006/05 GPL
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function MimeAdmin() {
global $db, $myts, $xoopsModule;
$url_smiles = XOOPS_URL."/images/smilies";
xoops_cp_header();
OpenTable();
echo "<h4 style='text-align:left;'>"._AM_CURRENT_MIMES."</h4>";
echo "<p style='text-align:left;'>"._AM_MIME_DESC."</p>";
if ($getmimes = $db->query("SELECT id,mime,extension FROM ".$db->prefix("mimes")." ORDER BY mime ASC")) {
	if ($db->getRowsNum($getmimes) > 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_MIME;?></b></td>
		<td align="center"><b><?php echo _AM_EXTENSION;?></b></td>
		<td align="right"><b><?php echo _ACTION;?></b></td>
		</tr>
		<?php
		while ($mimes = $db->fetchArray($getmimes)) {
			?>
			<tr class="bg1">
			<td><?php echo $myts->makeTboxData4Show($mimes['mime']);?></td>
			<td><?php echo $myts->makeTboxData4Show($mimes['extension']);?></td>
			<td align="right"><a href="admin.php?fct=mimes&op=MimeEdit&id=<?php echo $mimes['id'];?>"><?php echo _EDIT;?></a> | <a href="admin.php?fct=mimes&op=MimeDel&id=<?php echo $mimes['id'];?>"><?php echo _DELETE;?></a></td>
			</tr>
			<?php
		}
		echo "</table></td></tr></table>";
	}
	} else {
		echo _AM_CNRFTSD;
	}
?>
<br />
<h4 style="text-align:left;"><?php echo _AM_ADD_NEW_PAIR;?></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_MIME;?></b></td>
<td class="bg1"><input type="text" class="text" name="mime" /></td>
</tr><tr>
<td class="bg3"><b><?php echo _AM_EXTENSION;?></b></td>
<td class="bg1"><input type="text" class="text" name="extension" /></td>
</tr><tr>
<td class="bg3">&nbsp;</td>
<td class="bg1">
<input type="hidden" name="fct" value="mimes" />
<input type="hidden" name="op" value="MimeAdd" />
<input type="submit" class="button" value="<?php echo _ADD;?>" />
</td></tr></table>
</td></tr></table>
</form>
<h4 style="text-align:left;"><?php echo _AM_ADD_NEW_PAIR_FILE;?></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" valign="top"><b><?php echo _AM_ADD_NEW_FILE_SAMPLE;?></b></td>
<td class="bg1">
<?php
include_once(XOOPS_ROOT_PATH."/class/upload.class.php");
$upload = new Upload();
$upload->printFormField("sample");
?>
</td>
</tr><tr>
<td class="bg3">&nbsp;</td>
<td class="bg1">
<input type="hidden" name="fct" value="mimes" />
<input type="hidden" name="op" value="MimeAddSample" />
<input type="submit" class="button" value="<?php echo _ADD;?>" />
</td></tr></table>
</td></tr></table>
</form>
<?php
/*
<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" 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>
*/
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function MimeEdit($id) {
global $db, $myts, $xoopsModule;
xoops_cp_header();
OpenTable();
echo "<h4 style='text-align:left;'>"._AM_EDIT_MIME."</h4>";
if ($getmimes = $db->query("SELECT id,mime,extension FROM ".$db->prefix("mimes")." WHERE id = $id")) {
	if ($mimes = $db->fetchArray($getmimes)) {
		?>
		<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_MIME;?></b></td>
		<td class="bg1"><input type="text" class="text" name="code" value="<?php echo $myts->makeTboxData4Edit($mimes['mime']);?>" /></td>
		</tr><tr>
		<td class="bg3"><b><?php echo _AM_EXTENSION;?></b></td>
		<td class="bg1"><input type="text" class="text" name="emotion" value="<?php echo $myts->makeTboxData4Edit($mimes['extension']);?>" /></td>
		</tr><tr>
		<td class="bg3">
		<input type="hidden" name="id" value="<?php echo $mimes['id'];?>" />
		<input type="hidden" name="op" value="MimeSave" />
		<input type="hidden" name="fct" value="mimes" />
		</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 MimeAdd($mime,$extension) {
global $db, $myts, $_FILES;
$mime      = $myts->makeTboxData4Save($mime);
$extension = $myts->makeTboxData4Save($extension);
if ( !empty($mime) && !empty($extension) ) {
	$db->query("INSERT INTO ".$db->prefix("mimes")." ( `id` , `mime` , `extension` ) VALUES  ( '', '".$mime."', '".$extension."')");
	redirect_header("admin.php?fct=mimes&op=MimeAdmin", 2, _UPDATED);
	} else {
		redirect_header("admin.php?fct=mimes&op=MimeAdmin", 2, _NOTUPDATED);
	}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function MimeAddSample($mime,$extension) {
global $db, $myts, $_FILES;
if ( !empty($_FILES['sample']['name']) ) {
	$mime = $_FILES['sample']['type'];
	$extension = ".".preg_replace("/^.+\.([^.]+)$/sU", "\\1", $_FILES['sample']['name']);
}
if ( !empty($mime) && !empty($extension) ) {
	$db->query("INSERT INTO ".$db->prefix("mimes")." ( `id` , `mime` , `extension` ) VALUES  ( '', '".$mime."', '".$extension."')");
	redirect_header("admin.php?fct=mimes&op=MimeAdmin", 2, _UPDATED);
	} else {
		redirect_header("admin.php?fct=mimes&op=MimeAdmin", 2, _NOTUPDATED);
	}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function MimeSave($id, $mime, $extension) {
global $db, $myts, $_FILES;
$mime = $myts->makeTboxData4Save($mime);
$extension   = $myts->makeTboxData4Save($extension);
if ( !empty($mime) && !empty($extension) ) {
	$db->query("UPDATE ".$db->prefix("mimes")." SET mime='$mime', extension='$extension' WHERE id='$id' ");
	redirect_header("admin.php?fct=mimes&op=MimeAdmin", 2, _UPDATED);
	} else {
		redirect_header("admin.php?fct=mimes&op=MimeAdmin", 2, _NOTUPDATED);
	}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function MimeDel($id, $ok=0) {
global $db, $xoopsModule;
if ($ok==1) {
	$db->query("DELETE FROM ".$db->prefix("mimes")." where id=$id");
	redirect_header("admin.php?fct=mimes&op=MimeAdmin", 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=mimes&op=MimeDel&id=$id&ok=1", _YES);
		echo "</td><td>";
		echo myTextForm("admin.php?fct=mimes&op=MimeAdmin", _NO);
		echo "</td></tr></table><br /><br />";
		CloseTable();
		xoops_cp_footer();
	}
}
//---------------------------------------------------------------------------------------//
} else {
	echo "Access Denied";
}
?>
