<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：QQ877873666
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//打开用户表，并检测用户是否登录
$MB->Open('','login');

$skin->WebTop();


echo('
<script language="javascript" type="text/javascript" src="js/inc/list.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/inc/trim.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/idcProGroup.js?v='. OT_VERSION .'"></script>
');


switch ($mudi){
	case 'add':
		$MB->IsSecMenuRight('alertBack',9,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$MB->IsSecMenuRight('alertBack',10,$dataType);
		AddOrRev();
		break;

	case 'manage':
		$MB->IsSecMenuRight('alertBack',51,$dataType);
		manage();
		break;

	default:
		die('err');
}

$skin->WebBottom();

$MB->Close();
$DB->Close();





// 新增、修改
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN;

	$mudi2			= OT::GetStr('mudi2');
	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');
	$backURL		= OT::GetStr('backURL');
	$dataID			= OT::GetInt('dataID');

	if ($mudi=='rev'){
		$revexe=$DB->query('select * from '. OT_dbPref .'idcProGroup where IPG_ID='. $dataID);
			if (! $row = $revexe->fetch()){
				JS::AlertBackEnd('无该记录！');		
			}
		$IPG_ID			= $row['IPG_ID'];
		$IPG_typeStr	= $row['IPG_typeStr'];
		$IPG_type1ID	= $row['IPG_type1ID'];
		$IPG_type2ID	= $row['IPG_type2ID'];
		$IPG_type3ID	= $row['IPG_type3ID'];
		$IPG_theme		= $row['IPG_theme'];
		$IPG_themeStyle	= $row['IPG_themeStyle'];
		$IPG_style		= $row['IPG_style'];
		$IPG_tixing		= $row['IPG_tixing'];
		$IPG_note		= $row['IPG_note'];
		$IPG_rank		= $row['IPG_rank'];
		$IPG_state		= $row['IPG_state'];
		$IPG_wapState	= $row['IPG_wapState'];

		$mudiCN='修改';
		$submitCN='修 改';
	}else{
		if ($dataID>0){
			$revexe=$DB->query('select * from '. OT_dbPref .'idcProGroup where IPG_ID='. $dataID);
			if ($row = $revexe->fetch()){
				$IPG_typeStr		= $row['IPG_typeStr'];
				$IPG_type1ID		= $row['IPG_type1ID'];
				$IPG_type2ID		= $row['IPG_type2ID'];
				$IPG_type3ID		= $row['IPG_type3ID'];
				$IPG_themeStyle	= $row['IPG_themeStyle'];
				if ($mudi2 == 'copy'){
					$IPG_theme	= $row['IPG_theme'];
				}else{
					$IPG_theme	= '';
				}
				$IPG_style		= $row['IPG_style'];
				$IPG_tixing		= $row['IPG_tixing'];
				$IPG_note		= $row['IPG_note'];
				$IPG_state		= $row['IPG_state'];
				$IPG_wapState	= $row['IPG_wapState'];
			}
			$dataID = 0;
		}else{
			$IPG_ID			= 0;
			$IPG_typeStr	= '';
			$IPG_type1ID	= 0;
			$IPG_type2ID	= 0;
			$IPG_type3ID	= 0;
			$IPG_theme		= '';
			$IPG_themeStyle	= '';
			$IPG_style		= '';
			$IPG_tixing		= '';
			$IPG_note		= '';
			$IPG_state		= 1;
			$IPG_wapState	= 1;
		}
		$IPG_rank		= intval($DB->GetOne('select max(IPG_rank) from '. OT_dbPref .'idcProGroup'))+10;

		$mudiCN='新增';
		$submitCN='新 增';
	}

	$themeStyle_color	= Str::GetMark($IPG_themeStyle,'color:',';');
	$themeStyle_b		= Str::GetMark($IPG_themeStyle,'font-weight:',';');
	$style_bgcolor		= Str::GetMark($IPG_style,'background-color:',';');

	$moreStr = '';

	if ($mudi=='rev'){
		echo('<div onclick="history.back();" class="font2_1 padd8 pointer">&lt;&lt;&ensp;【返回上级】</div>');
	}

	echo('
	<form id="dealForm" name="dealForm" method="post" action="idcProGroup_deal.php?mudi='. $mudi .'&nohrefStr=close" onsubmit="return CheckForm()">
	<input type="hidden" id="dataID" name="dataID" value="'. $dataID .'" />
	<input type="hidden" id="dataType" name="dataType" value="'. $dataType .'" />
	<input type="hidden" id="dataTypeCN" name="dataTypeCN" value="'. $dataTypeCN .'" />
	<input type="hidden" id="dataMode" name="dataMode" value="'. $dataMode .'" />
	<input type="hidden" id="dataModeStr" name="dataModeStr" value="'. $dataModeStr .'" />
	'. Area::BackUrlInput($backURL) .'

	<table cellpadding="0" cellspacing="0" summary="" class="padd5td">
	<tr><td class="tabLeftWidth"></td><td></td></tr>
	<tr>
		<td align="right">'. Skin::RedSign() .'标题：</td>
		<td align="left">
			<input type="text" id="theme" name="theme" size="50" style="width:380px;'. $IPG_themeStyle .'" value="'. Str::MoreReplace($IPG_theme,'input') .'" />&ensp;
			'. AppBase::InfoThemeB($themeStyle_b,$themeStyle_color,'idcProGroup') .'
		</td>
	</tr>
	<tr>
		<td align="right">'. Skin::RedSign() .'类别：</td>
		<td align="left">
			<select id="typeStr" name="typeStr">
			<option value=""></option>
			');
			$typeNum = 0;
			$typeexe=$DB->query('select IPT_ID,IPT_theme from '. OT_dbPref ."idcProType where IPT_state=1 and IPT_level=1 order by IPT_rank ASC");
			while ($row = $typeexe->fetch()){
				$typeNum ++;
				$type2exe=$DB->query('select IPT_ID,IPT_theme from '. OT_dbPref ."idcProType where IPT_state=1 and IPT_level=2 and IPT_fatID=". $row['IPT_ID'] ." order by IPT_rank ASC");
				// if (! $row2 = $type2exe->fetch()){
					echo('<option value=",'. $row['IPT_ID'] .'," '. Is::InstrSelected($IPG_typeStr,','. $row['IPT_ID'] .',') .'>'. $typeNum .'、'. $row['IPT_theme'] .'</option>');
				// }else{
				//	echo('<optgroup label="'. $typeNum .'、'. $row['IPT_theme'] .'" style="font-weight:normal;"></optgroup>');
					while ($row2 = $type2exe->fetch()){
						echo('<option value=",'. $row['IPT_ID'] .','. $row2['IPT_ID'] .'," '. Is::InstrSelected($IPG_typeStr,','. $row2['IPT_ID'] .',') .'>&ensp;&ensp;&ensp;┣&ensp;'. $row2['IPT_theme'] .'</option>');
					}
				// }
			}
			echo('
			</select>&ensp;
		</td>
	</tr>
	<tr>
		<td align="right">背景色：</td>
		<td align="left">
			<input type="text" id="styleBgcolor" name="styleBgcolor" size="50" style="width:80px;" value="'. $style_bgcolor .'" />'. Skin::ColorBox('input','styleBgcolor','styleBgcolor') .'
		</td>
	</tr>
		<tr>
			<td align="right" valign="top">友情提醒：</td>
			<td>
				<textarea id="tixing" name="tixing" cols="40" rows="4" style="width:510px;height:120px;" class="text" onclick=\'LoadEditor("tixing",510,120,"|miniMenu|");\' title="点击开启编辑器模式">'. Str::MoreReplace($IPG_tixing,'textarea') .'</textarea>
				<input type="hidden" id="upImgStr" name="upImgStr" value="" />
				<div><input type="button" onclick=\'OT_OpenUpImg("editor","tixing","","")\' value="上传图片载入编辑器" /></div>
			</td>
		</tr>
	<tr>
		<td align="right" valign="top" style="padding-top:6px;">备注：</td>
		<td align="left"><textarea id="note" name="note" rows="5" cols="40" style="width:400px; height:60px;">'. $IPG_note .'</textarea></td>
	</tr>
	<tr>
		<td align="right">排序：</td>
		<td align="left">
			<input type="text" id="rank" name="rank" size="50" style="width:30px;" value="'. $IPG_rank .'" />
		</td>
	</tr>
	<tr>
		<td align="right">电脑版状态：</td>
		<td align="left">
			<label><input type="radio" name="state" value="1" '. Is::Checked($IPG_state,1) .' />显示</label>&ensp;&ensp;
			<label><input type="radio" name="state" value="0" '. Is::Checked($IPG_state,0) .' />隐藏</label>&ensp;&ensp;
		</td>
	</tr>
	<tr>
		<td align="right">手机版状态：</td>
		<td align="left">
			<label><input type="radio" name="wapState" value="1" '. Is::Checked($IPG_wapState,1) .' />显示</label>&ensp;&ensp;
			<label><input type="radio" name="wapState" value="0" '. Is::Checked($IPG_wapState,0) .' />隐藏</label>&ensp;&ensp;
		</td>
	</tr>
	</table>

	<table style="height:16px;" cellpadding="0" cellspacing="0" summary=""><tr><td></td></tr></table>

	<center><input type="image" src="'. AdmTpl::ImgSrc('button_'. $mudi) .'" /></center>

	</form>
	');
}



// 管理
function manage(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$pageCount,$recordCount;

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');

	echo('
	<div class="padd5">
		<input type="button" value="新增'. $dataTypeCN .'" onclick=\'document.location.href="?mudi=add&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&backURL="+ encodeURIComponent(document.location.href)\' />&ensp;&ensp;
	</div>
	');

	$skin->TableTop2('share_list.gif','',''. $dataTypeCN .'管理');
	$skin->TableItemTitle('4%,5%,28%,10%,10%,5%,8%,10%','<input type="checkbox" id="selAll" name="selAll" onclick="CheckBoxAll()" />,编号,名称,背景色,备注,排序,电脑/WAP状态,预览　修改　删除');

	$showNum=0;
	$showexe=$DB->query('select * from '. OT_dbPref .'idcProType where IPT_level=1 order by IPT_rank ASC');
	while ($row = $showexe->fetch()){
		echo('
		<tr><td id="adStopStr" colspan="12" class="padd8 pointer" align="center" style="font-weight:bold;background:#e9e7e7;color:blue;padding:5px;">
			→ 【'. $row['IPT_theme'] .'】 ←
		</td></tr>
		');

		$show2exe=$DB->query('select * from '. OT_dbPref .'idcProType where IPT_fatID='. $row['IPT_ID'] .' order by IPT_rank ASC');
		while ($row2 = $show2exe->fetch()){
			if ($showNum % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }
			$showNum ++;

			echo('
			<tbody class="idcProType2 tabBody padd3">
			<tr '. $bgcolor .'>
				<td align="center"></td>
				<td align="center">'. $showNum .'</td>
				<td align="left" style="color:blue;"><span style="'. $row2['IPT_themeStyle'] .'">【'. $row2['IPT_theme'] .'】</span>&ensp;<span id="idcProType'. $row2['IPT_ID'] .'" class="font2_2"></span></td>
				<td align="center"></td>
				<td align="center">'. $row2['IPT_note'] .'</td>
				<td align="center"></td>
				<td align="center"></td>
				<td align="center"></td>
			</tr>
			<tbody>
			');

			$show3exe=$DB->query('select * from '. OT_dbPref .'idcProGroup where IPG_type2ID='. $row2['IPT_ID'] .' order by IPG_rank ASC');
			while ($row3 = $show3exe->fetch()){
				if ($showNum % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }
				$showNum ++;
				echo('
				<tbody class="idcProType2 tabBody padd3">
				<tr id="data'. $row3['IPG_ID'] .'" '. $bgcolor .'>
					<td align="center" class="selCheckbox"><input type="checkbox" name="selDataID[]" value="'. $row3['IPG_ID'] .'" /></td>
					<td align="center">'. $showNum .'</td>
					<td align="left">&ensp;&ensp;┗&ensp;<span style="'. $row3['IPG_themeStyle'] .'">'. $row3['IPG_theme'] .'</span></td>
					<td align="center" style="'. $row3['IPG_style'] .'">'. $row3['IPG_style'] .'</td>
					<td align="center">'. $row3['IPG_note'] .'</td>
					<td align="center">'. $row3['IPG_rank'] .'</td>
					<td align="center">
						'. Adm::SwitchBtn('idcProGroup',$row3['IPG_ID'],$row3['IPG_state'],'state') .'/
						'. Adm::SwitchBtn('idcProGroup',$row3['IPG_ID'],$row3['IPG_wapState'],'wapState','userState') .'
					</td>
					<td align="center">
						<img src="images/img_rev.gif" style="cursor:pointer;" onclick=\'document.location.href="idcProGroup.php?mudi=rev&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $row3['IPG_ID'] .'&backURL="+ encodeURIComponent(document.location.href)\' alt="修改" />&ensp;&ensp;
						<img src="images/img_del.gif" style="cursor:pointer;" onclick=\'if(confirm("确定删除？")==true){DataDeal.location.href="idcProGroup_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($row3['IPG_theme']) .'&dataID='. $row3['IPG_ID'] .'"}\' alt="删除" />
					</td>
				</tr>
				<tbody>
				');

			}
			unset($show3exe);
		}
		unset($show2exe);

	}
	unset($showexe);

	echo('
	<tr class="tabColorB padd5">
		<td align="left" colspan="20">
			<input type="button" value="全选" onclick="AllSelBox()" class="form_button1" />
			<input type="button" value="反选" onclick="RevSelBox()" class="form_button1" />
			<input type="submit" value="提交" class="display" />
		</td>
	</tr>
	</form>
	</table>
	');
}

?>