<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.2 www.bcoos.net 2006-08 GPL
// $Id: blocksadmin.php,v 1.15 2003/07/13 20:47:19 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
// ------------------------------------------------------------------------- //
// check if the user is authorised
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function list_blocks() {
global $xoopsUser;
OpenTable();
echo "
<h4 style='text-align:left;'>"._AM_BADMIN."</h4>
<form action='admin.php' name='blockadmin' id='blockadmin' method='post' style='position:relative;z-index:3'>
<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 valign='middle' class='bg3'>
<td width='20%'><b>"._AM_BLKDESC."</b></td>
<td width='20%'><b>"._TITLE."</b></td>
<td width='20%'><b>"._MD_AM_MDAD."</b></td>
<td><b>"._AM_SIDE."</b></td>
<td align='center'><b>"._AM_WEIGHT."</b></td>
<td align='center'><b>"._AM_VISIBLE."</b></td>
<td align='right'><b>"._ACTION."</b></td></tr>
<tr><td colspan='7' class='bg1'>&nbsp;</td></tr>
<tr><td colspan='7' class='bg3'><b>"._AM_LSIDEBADMIN."</b></td></tr>";
$arr =& XoopsBlock::getAllBlocks("object", XOOPS_SIDEBLOCK_LEFT, NULL, "side ASC, visible DESC, weight ASC");
foreach ( $arr as $ele ) {
	show_block($ele);
}
echo "<tr><td colspan='7' class='bg3'><b>"._AM_CENTERBADMIN."</b></td></tr>";
$arr =& XoopsBlock::getAllBlocks("object", XOOPS_CENTERBLOCK_ALL, NULL, "visible DESC, weight ASC, side ASC");
foreach($arr as $ele) {
	show_block($ele);
}
echo "<tr><td colspan='7' class='bg3'><b>"._AM_RSIDEBADMIN."</b></td></tr>";
$arr =& XoopsBlock::getAllBlocks("object", XOOPS_SIDEBLOCK_RIGHT, NULL, "side ASC, visible DESC, weight ASC");
foreach ( $arr as $ele ) {
	show_block($ele);
}
echo "
</table></td></tr></table><br />
<input type='hidden' name='fct' value='blocksadmin' />
<input type='hidden' name='op' value='order' />
<input type='submit' class='button' name='submit' value='"._SUBMIT."' />
</form>
<h4 style='text-align:left;'>" ._AM_ADDBLOCK."</h4>
<form action='admin.php?fct=blocksadmin' method='post'>
<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 align='left' valign='top'><td class='bg3' width='30%'>
<b>"._AM_BLKTYPE."</b>
</td><td class='bg1'>
<select class='select' name='bside'>
<option value='0'>" ._AM_SBLEFT."</option>
<option value='1'>" ._AM_SBRIGHT."</option>
<option value='3'>" ._AM_CBLEFT."</option>
<option value='5'>" ._AM_CBCENTER."</option>
<option value='4'>" ._AM_CBRIGHT."</option>
</select>
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>"._AM_WEIGHT."</b>
</td><td class='bg1'>
<input type='text' class='text' name='bweight' size='2' maxlength='2' />
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>" ._AM_VISIBLE."</b>
</td><td class='bg1'>
<select class='select' name='bvisible'>
<option value='0'>" ._NO."</option>
<option value='1' selected='selected'>" ._YES."</option>
</select>
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>" ._TITLE."</b>
</td><td class='bg1'>
<input type='text' class='text' name='btitle' size='60' maxlength='60' />
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>" ._AM_CONTENT."</b><br /><br /><span style='font-size:large;font-weight:bold;'>"._AM_USEFULTAGS."</span><br /><span style='font-size:large;font-weight:normal;'>".sprintf(_AM_BLOCKTAG1, "{X_SITEURL}", XOOPS_URL."/")."</span>
</td><td class='bg1'>
<textarea class='textarea' name='bcontent' cols='60' rows='10'></textarea>
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>" ._AM_CTYPE."</b>
</td><td class='bg1'>
<select class='select' name='bctype'>
<option value='H'>" ._AM_HTML."</option>
<option value='P'>" ._AM_PHP."</option>
<option value='S'>" ._AM_AFWSMILE."</option>
<option value='T' selected='selected'>" ._AM_AFNOSMILE."</option>
</select>
</td></tr>
<tr align='left' valign='top'><td class='bg3'>&nbsp;</td>
<td class='bg1'>
<input type='hidden' name='op' value='save' />
<input type='submit' class='button' value='" ._SUBMIT."' />
</td></tr></table></td></tr></table>
</form>";
CloseTable();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function show_block($ele) {
global$bcoosConfig;
$sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = "";
if ( $ele->getVar("visible") == 1 ) {
	$sel1 = " selected='selected'";
	} else {
		$sel0 = " selected='selected'";
	}
if ( $ele->getVar("side") == XOOPS_SIDEBLOCK_LEFT){
	$ssel0 = " selected='selected'";
	} elseif ( $ele->getVar("side") == XOOPS_SIDEBLOCK_RIGHT ) {
		$ssel1 = " selected='selected'";
	} elseif ( $ele->getVar("side") == XOOPS_CENTERBLOCK_LEFT ) {
		$ssel2 = " selected='selected'";
	} elseif ( $ele->getVar("side") == XOOPS_CENTERBLOCK_RIGHT ) {
		$ssel4 = " selected='selected'";
	} elseif ( $ele->getVar("side") == XOOPS_CENTERBLOCK_CENTER ) {
		$ssel3 = " selected='selected'";
	}
if ( $ele->getVar("title") == "" ) {
	$title = "&nbsp;";
	} else {
		$title = $ele->getVar("title");
	}
echo "
<tr valign='top' class='bg1'>
<td>".$ele->getVar("name")."</td>
<td>".$title."</td>
<td>".$ele->getVar("dirname")."</td>
<td>
<select class='select' name='side[]'>
<option value='".XOOPS_SIDEBLOCK_LEFT."'$ssel0>"._AM_SBLEFT."</option>
<option value='".XOOPS_SIDEBLOCK_RIGHT."'$ssel1>"._AM_SBRIGHT."</option>
<option value='".XOOPS_CENTERBLOCK_LEFT."'$ssel2>"._AM_CBLEFT."</option>
<option value='".XOOPS_CENTERBLOCK_CENTER."'$ssel3>"._AM_CBCENTER."</option>
<option value='".XOOPS_CENTERBLOCK_RIGHT."'$ssel4>"._AM_CBRIGHT."</option>
</select></td>
<td align='center'><input type='text' class='text' name='weight[]' value='".$ele->getVar("weight")."' size='5' maxlength='5' /></td>
<td align='center'>
<select class='select' name='visible[]'>
<option value='0'$sel0>"._NO."</option>
<option value='1'$sel1>"._YES."</option>
</select></td>
<td align='right'>
<a href='admin.php?fct=blocksadmin&amp;op=edit&amp;bid=".$ele->getVar("bid")."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."edit.gif' alt='"._EDIT."' border='0' /></a>";
if ( $ele->isCustom() ) {
	echo "&nbsp;<a href='admin.php?fct=blocksadmin&amp;op=delete&amp;bid=".$ele->getVar("bid")."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."delete.gif' alt='"._DELETE."' border='0' /></a>";
}
echo "
<input type='hidden' name='oldside[]' value='".$ele->getVar("side")."' />
<input type='hidden' name='oldweight[]' value='".$ele->getVar("weight")."' />
<input type='hidden' name='oldvisible[]' value='".$ele->getVar("visible")."' />
<input type='hidden' name='bid[]' value='".$ele->getVar("bid")."' />
</td></tr>";
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype) {
$myblock = new XoopsBlock();
$myblock->setVar("side", $bside);
$myblock->setVar("weight", $bweight);
//$myblock->setVar("position", $bposition);
$myblock->setVar("visible", $bvisible);
$myblock->setVar("weight", $bweight);
$myblock->setVar("title", $btitle);
$myblock->setVar("content", $bcontent);
$myblock->setVar("c_type", $bctype);
$myblock->setVar("type", "C");
switch ($bctype) {
case "H":
	$name = _AM_CUSTOMHTML;
	break;
case "P":
	$name = _AM_CUSTOMPHP;
	break;
case "S":
	$name = _AM_CUSTOMSMILE;
	break;
default:
	$name = _AM_CUSTOMNOSMILE;
	break;
	}
$myblock->setVar("name", $name);
if ( !$myblock->store() ) {
	xoops_cp_header();
	$myblock->getErrors();
	xoops_cp_footer();
	exit();
	}
redirect_header("admin.php?fct=blocksadmin", 1, _UPDATED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function edit_block($bid, $op='') {
$myblock = new XoopsBlock($bid);
if ($op == 'preview') {
	global $myts, $_POST;
	$btitle   = $myts->oopsStripSlashesGPC($_POST['btitle']);
	$bcontent = $myts->oopsStripSlashesGPC($_POST['bcontent']);
	$myblock->setVar("side"    , $_POST['bside']);
	$myblock->setVar("weight"  , $_POST['bweight']);
	$myblock->setVar("position", $_POST['bposition']);
	$myblock->setVar("visible" , $_POST['bvisible']);
	$myblock->setVar("weight"  , $_POST['bweight']);
	$myblock->setVar("c_type"  , $_POST['bctype']);
	$myblock->setVar("title"   , $btitle);
	$myblock->setVar("content" , $bcontent);
	if ( isset($_POST['options']) && (count($_POST['options']) > 0) ) {
		$options = implode("|", $_POST['options']);
		$myblock->setVar("options", $options);
		}
	}
OpenTable();
echo "
<a href='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin'>"._EDIT."</a>: " ._AM_EDITBLOCK."
<form action='admin.php?fct=blocksadmin' method='post'>
<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 align='left' valign='top'><td class='bg3' width='30%'>
<b>"._NAME."</b></td><td class='bg1'>".$myblock->getVar("name")."</td></tr>
<tr align='left' valign='top'><td class='bg3'>
<b>"._AM_BLKTYPE."</b></td>
<td class='bg1'>
<select class='select' name='bside'>
<option value='0'";
if ( $myblock->getVar("side") == 0 ) echo " selected='selected'";
echo ">" ._AM_SBLEFT."</option>
<option value='1'";
if ( $myblock->getVar("side") == 1 ) echo " selected='selected'";
echo ">" ._AM_SBRIGHT."</option>
<option value='3'";
if ( $myblock->getVar("side") == 3 ) echo " selected='selected'";
echo ">" ._AM_CBLEFT."</option>
<option value='5'";
if ( $myblock->getVar("side") == 5 ) echo " selected='selected'";
echo ">" ._AM_CBCENTER."</option>
<option value='4'";
if ( $myblock->getVar("side") == 4 ) echo " selected='selected'";
echo ">" ._AM_CBRIGHT."</option>
</select>
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>"._AM_WEIGHT."</b>
</td><td class='bg1'>
<input type='text' class='text' name='bweight' size='2' maxlength='2' value='";
echo $myblock->getVar("weight");
echo "' />
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>"._AM_VISIBLE."</b></td><td class='bg1'>
<select class='select' name='bvisible'>
<option value='0'";
if ( $myblock->getVar("visible") == 0 ) echo " selected='selected'";
echo ">" ._NO."</option>
<option value='1'";
if ( $myblock->getVar("visible") == 1 ) echo " selected='selected'";
echo ">" ._YES."</option>";
echo "</select>
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>" ._TITLE."</b></td><td class='bg1'>
<input type='text' class='text' name='btitle' size='60' maxlength='60' value='";
echo $myblock->getVar("title", "E");
echo "' />
</td></tr><tr align='left' valign='top'><td class='bg3'>
<b>"._AM_CONTENT."</b><br /><br /><span style='font-size:large;font-weight:bold;'>"._AM_USEFULTAGS."</span><br /><span style='font-size:large;font-weight:normal;'>".sprintf(_AM_BLOCKTAG1, "{X_SITEURL}", XOOPS_URL."/")."</span></td><td class='bg1'>
<textarea class='textarea' name='bcontent' cols='60' rows='10'>";
echo $myblock->getContent("E");
echo "</textarea>
</td></tr>";
if ( !$myblock->isCustom() ) {
	echo "<tr align='left' valign='top'><td class='bg3'>
	<b>" ._AM_POSCONTT."</b></td><td class='bg1'>
	<select class='select' name='bposition'>
	<option value='0'";
	if ( $myblock->getVar("position") == 0) echo " selected='selected'";
	echo ">" ._AM_ABOVEORG."</option>
	<option value='1'";
	if ( $myblock->getVar("position") == 1) echo " selected='selected'";
	echo ">" ._AM_AFTERORG."</option>
	</select>
	</td></tr>";
}
echo "<tr align='left' valign='top'><td class='bg3'>
<b>" ._AM_CTYPE."</b></td><td class='bg1'>
<select class='select' name='bctype'>
<option value='H'";
if ( $myblock->getVar("c_type") == "H") echo " selected='selected'";
echo ">" ._AM_HTML."</option>
<option value='P'";
if ( $myblock->getVar("c_type") == "P") echo " selected='selected'";
echo ">" ._AM_PHP."</option>
<option value='S'";
if ( $myblock->getVar("c_type") == "S") echo " selected='selected'";
echo ">" ._AM_AFWSMILE."</option>
<option value='T'";
if ( $myblock->getVar("c_type") == "T") echo " selected='selected'";
echo ">" ._AM_AFNOSMILE."</option>
</select>
</td></tr>";
$edit_form = $myblock->getOptions();
if ( $edit_form != false ) {
	echo "<tr align='left' valign='top'><td class='bg3'><b>"._AM_OPTIONS."</b></td><td class='bg1'>";
	echo $edit_form;
	echo "</td></tr>";
	}
echo "
<tr align='left' valign='top'><td class='bg3'>&nbsp;</td>
<td class='bg1'>
<select class='select' name='op'>
<option value='preview' selected>"._PREVIEW."</option>
<option value='update'>"._SAVE."</option>
</select>
<input type='hidden' name='bid' value='".$myblock->getVar("bid")."' />
<input type='submit' class='button' value='"._UPDATE."' />&nbsp;
<input type='button' class='button' onclick='location=\"admin.php?fct=blocksadmin\"' value='" ._CANCEL."' />
</td></tr></table></td></tr></table>
</form>";
CloseTable();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function update_block($bid, $bside, $bweight, $bposition, $bvisible, $btitle, $bcontent, $bctype, $options="") {
$myblock = new XoopsBlock($bid);
$myblock->setVar("side", $bside);
$myblock->setVar("weight", $bweight);
$myblock->setVar("position", $bposition);
$myblock->setVar("visible", $bvisible);
$myblock->setVar("weight", $bweight);
$myblock->setVar("title", $btitle);
$myblock->setVar("content", $bcontent);
if ( isset($options) && (count($options) > 0) ) {
	$options = implode("|", $options);
	$myblock->setVar("options", $options);
	}
$myblock->setVar("c_type", $bctype);
if ( $myblock->getVar("type") == "C" ) {
	switch ($bctype) {
		case "H":
			$name = _AM_CUSTOMHTML;
			break;
		case "P":
			$name = _AM_CUSTOMPHP;
			break;
		case "S":
			$name = _AM_CUSTOMSMILE;
			break;
		default:
			$name = _AM_CUSTOMNOSMILE;
			break;
	}
	$myblock->setVar("name", $name);
}
$myblock->store();
redirect_header("admin.php?fct=blocksadmin&op=edit&bid=$bid", 1, _UPDATED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function delete_block($bid) {
$myblock = new XoopsBlock($bid);
if ( $myblock->getVar("type") == "S" ) {
	$message = _AM_SYSTEMCANT;
	redirect_header("admin.php?fct=blocksadmin", 4, $message);
	exit();
	} elseif ($myblock->getVar("type") == "M") {
		$message = _AM_MODULECANT;
		redirect_header("admin.php?fct=blocksadmin", 4, $message);
		exit();
		} else {
			echo "<h4 style='text-align:left;'>".sprintf(_AM_RUSUREDEL, $myblock->getVar("title"))."</h4>";
			echo "<table><tr><td>";
			echo myTextForm("admin.php?fct=blocksadmin&op=delete_ok&bid=".$myblock->getVar("bid") , _YES);
			echo "</td><td>";
			echo myTextForm("admin.php?fct=blocksadmin" , _NO);
			echo "</td></tr></table>";
		}
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function delete_block_ok($bid) {
$myblock = new XoopsBlock($bid);
$myblock->delete();
redirect_header("admin.php?fct=blocksadmin", 1, _UPDATED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function order_block($bid, $weight, $visible, $side) {
$myblock = new XoopsBlock($bid);
$myblock->setVar("weight", $weight);
$myblock->setVar("visible", $visible);
$myblock->setVar("side", $side);
$myblock->store();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function preview_cblock($bid, $btitle, $bcontent, $bctype, $bposition, $options) {
global $myts;
$btitle   = $myts->oopsStripSlashesGPC($btitle);
$bcontent = $myts->oopsStripSlashesGPC($bcontent);
$myblock = new XoopsBlock($bid);
$myblock->setVar("title"   , $btitle);
$myblock->setVar("content" , $bcontent);
$myblock->setVar("c_type"  , $bctype);
$myblock->setVar("position", $bposition);
if ( isset($options) && (count($options) > 0) ) {
	$options = implode("|", $options);
	$myblock->setVar("options", $options);
	}
$block = $myblock->buildBlock($myblock);
?>
<h4><?php echo _AM_BPREVIEW;?></h4>
<table align="center" cellpadding="3" cellspacing="3" border="0"><tr>
<td class="bg2"><?php echo $block['title'];?></td>
</tr><tr>
<td class="bg1"><?php echo $block['content'];?></td>
</tr></table><br />
<?php
}
// ----------------------------------------------------------------------------------------//
	} else {
		echo "Access Denied";
	}
?>
