<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}
global $imgurl;
$orders = trim(isset($_GET['orders']) ? $_GET['orders'] : $_POST['orders']);
switch($orders){
	case '0':
		Show_UserGroupID();
		break;
	case '1':
		Show_BoardID();
		break;
	case '2':
	default:
		Show_ToolsInfo();
		break;
}
ShowFoot();

function Show_ToolsInfo(){
	global $lang;
	print <<<EOT
<table  cellpadding="0" cellspacing="0" align="center" class="mainbox tableborder">
	<tr>
		<th height="23">{$lang['tpl.str1']}</th>
	</tr>
	<tr>
		<td height="23" class="tablebody5">{$lang['tpl.str2']}<BR></td>
	</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" align="center" class="mainbox">
EOT;
	$bussInfo =& getBussInfoByUserId($GLOBALS['userid']);
	if( $bussInfo === false ){
		print <<<EOT
	<tr><td class="TableBody1" valign="Top">{$lang['tpl.str3']}</td></tr>
EOT;
	} else{
		$Str = "action=0&touserid={$GLOBALS['userid']}&boardid={$GLOBALS['boardid']}&topicid={$GLOBALS['topicid']}&replyid={$GLOBALS['replyid']}";
		foreach( $bussInfo as $index => $val ){
			if( $val['toolsimg'] != '' ){
				$toolsImg = htmlspecialchars(strtolower($val['toolsimg']));
			} else{
				$toolsImg = 'dv_plus/tools/pic/none.jpg';
			}
			$strTR = '';
			if( $index % 3 === 0 ){
				if( $index === 0 ){
					$strTR = '<tr>';
				} else{
					$strTR = "</tr>\r\n				<tr>";
				}
			}
			$val['toolsname'] = htmlspecialchars($val['toolsname']);
			$val['toolsinfo'] = htmlspecialchars($val['toolsinfo']);
			print <<<EOT
	{$strTR}
		<td class="tableBody1" valign="Top">
			<table border="0" cellpadding="0" cellspacing="0" class="tableborder" width="100%" align="center">
				<tr><th height="20" >{$val['toolsname']}</th></tr>
				<tr>
					<td align="center" Width="50%"><a href="plus_tools_postings.php?toolsid={$val['toolsid']}&{$Str}" ><img src="{$toolsImg}" border="0" Title="{$lang['tpl.str4']}{$val['toolsinfo']}&#13;&#10;{$lang['tpl.str5']}{$val['toolscount']}"></a></td>
				</tr>
				<tr>
					<td><li>{$lang['tpl.str5']}{$val['toolscount']}</td>
				</tr>
			</table>
		</td>
EOT;
		}
	}
	print <<<EOT
</table>
EOT;
}

function ShowFoot(){
	print <<<EOT
<script type="text/JavaScript">
<!--
function putallid(v){
	var putid = '', comma = '';
	var ID = thisForm['id[]'];
	for (var i=0;i<ID.length;i++)  
		{
			if (ID[i].checked==true){
				putid += comma+''+ID[i].value; 
				comma = ',';
			}
		}
	v && (v.value=putid);
	window.close();
	return false;
}
function CheckAll(form)  
  {  
  for (var i=0;i<form.elements.length;i++)  
    {  
    var e = form.elements[i];  
    if (e.name != 'chkall')  
       e.checked = form.chkall.checked;  
    }  
  }
//-->
</script>
EOT;
}

function Show_UserGroupID(){
	global $ToUserID, $lang;
	$id = trim($GLOBALS['id']);
	if( !is_numeric($id) || $id < 0 ){
		showmsg($lang['Error.strings1'],0,'',false);
		exit;
	}
	$tmpRs =& getToolsInfoById($id);
	if( $tmpRs === false ){
		showmsg($lang['Error.strings1'],0,'',false);
		exit;
	}
	$toolsName = iHtmlencode($tmpRs[0]['toolsname']);
	$toolsGroupID = $tmpRs[0]['usergroupid'];
	unset($tmpRs);
	if( $toolsGroupID.'' === '' ){
		$toolsGroupID = '';
	} else{
		$toolsGroupID = ','.trim($toolsGroupID).',';
	}
	$temp = 1;
	if ($GLOBALS['master'] === true && get_cookie('backend_flag') != '') {
		$temp = 0;
	}
	$canUse = false;
	print <<<EOT
<table cellspacing="0" cellpadding="0" align="center"  class="mainbox tableborder">
	<form name=thisForm onsubmit="return putallid(self.opener.PlusTools.usergroupid);return putallid(self.opener.PlusTools.ToolsGroupID);">
	<tr><th colspan="2" height=23>{$toolsName} {$lang['tpl.str6']}</th></tr>
EOT;
	$userGrps =& getUserGrops();
	if( $userGrps === false ){
	} else{
		$userGropID = $GLOBALS['usergroupid'];
		require_once printout('grouppermission');
		foreach( $userGrps as $index => $currUserGrp ){
			if( $userGropID == $currUserGrp['usergroupid'] ){
				$strClassName = 'tablebody2';
				$canUse = true;
			} else{
				$strClassName = 'tablebody1';
			}
			$isSet = sysgroupname($currUserGrp['parentgid']);
			$iffcheck = iffcheck(strpos($toolsGroupID, ",{$currUserGrp['usergroupid']},") !== false, $temp, $currUserGrp['usergroupid']);
			print <<<EOT
	<tr>
		<td width="70%" class="{$strClassName}">{$isSet} {$currUserGrp['title']} &gt;&gt; <font color="gray">{$currUserGrp['usertitle']}</font></td>
		<td class="tablebody2" width="30%" align="center">{$iffcheck}</td>
	</tr>
EOT;
		}
	}
	if( $canUse === true ){
		$strTmp1 = $lang['tpl.str7'];
	} else{
		$strTmp1 = $lang['tpl.str8'];
	}
	if( $temp === 0 ){
		$strTmp2 = $lang['tpl.str9'];
	} else{
		$strTmp2 = $lang['tpl.str10'];
	}
	print <<<EOT
	<tr><td class="tablebody2" colspan="2" align=center><font color="{$_DCACHE['stylecss'][19]}">{$strTmp1}</font></td></tr>
	<tr><td class="tablebody1" colspan="2">{$strTmp2}</td></tr>
	</form>
</table>
EOT;
}

function Show_BoardID(){
	global $lang;
	$id = trim($GLOBALS['id']);
	if( !is_numeric($id) || $id < 0 ){
		showmsg($lang['Error.strings1'],0,'',false);
		exit;
	}
	$tmpRs =& getToolsInfoById($id);
	if( $tmpRs === false ){
		showmsg($lang['Error.strings1'],0,'',false);
		exit;
	}
	$toolsName = iHtmlencode($tmpRs[0]['toolsname']);
	$toolsBoardID = $tmpRs[0]['boardid'];
	unset($tmpRs);
	if( $toolsBoardID.'' === '' ){
		$toolsBoardID = '';
	} else{
		$toolsBoardID = ','.trim($toolsBoardID).',';
	}
	$temp = 1;
	if( $GLOBALS['master'] === true && get_cookie('backend_flag') != '' ){
		$temp = 0;
	}
	$canUse = false;
	print <<<EOT
<table cellspacing="0" cellpadding="0" align="center"  class="mainbox tableborder">
	<form name="thisForm" onsubmit="return putallid(self.opener.PlusTools.boardid);//return putallid(self.opener.PlusTools.ToolsBoardID)">
	<tr><th colspan="2" height="23">{$toolsName} {$lang['tpl.str11']}</th></tr>
EOT;
	global $_DCACHE,$groupsetting,$imgurl;
	if( empty($_DCACHE['all_forums']) ){
		include_once CACHE_PATH.'board/board_all.php';
	}
	if( is_array($_DCACHE['all_forums']) ){
		$isHidden = $groupsetting[37] == 1 ? true : false;
		foreach( $_DCACHE['all_forums'] as $currBoardID => $currBoardInfo ){
			if( $isHidden === true ){
				if( $currBoardInfo['hidden'] != 0 ){
					continue;
				}
			}
			if( $currBoardInfo['depth'] > 0 ){
				$strSpace = str_repeat('&nbsp;&nbsp;',$currBoardInfo['depth']);
			} else{
				$strSpace = '';
			}
			if( $currBoardInfo['child'] > 0 ){
				$strImg = '<img src="'.$imgurl.'plus.gif">';
			} else{
				$strImg = '<img src="'.$imgurl.'nofollow.gif">';
			}
			$iffcheck = iffcheck(strpos($toolsBoardID, ",{$currBoardID},") !== false, $temp, $currBoardID);
			print <<<EOT
	<tr>
		<td class="tablebody2">{$strSpace}{$strImg}{$currBoardInfo['boardtype']}</td>
		<td class="tablebody1">{$iffcheck}</td>
	</tr>
EOT;
		}
	}
	if( $temp == 0 ){
		$strTemp =$lang['tpl.str12'];
	} else{
		$strTemp =$lang['tpl.str13'];
	}
	print <<<EOT
	<tr><td class="tablebody1" colspan="2">{$strTemp}</td></tr>
	</form>
</table>
EOT;
}

function iffcheck($bln,$itype,$str){
	global $lang;
	if( $itype == 0 ){
		return '<input type="checkbox" class="chkbox" name="id[]" value="'.$str.'" '.($bln===true?' checked ':'').' />';
	} else{
		if( $bln === true ){
			return $lang['tpl.str14'];
		} else{
			return '<font color="'.$GLOBALS['lang']['Dvbbs.mainsetting1'].'">'.$lang['tpl.str15'].'</font>';
		}
	}
}

?>