<?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/infoWeb.js?v='. OT_VERSION .'"></script>
');

// dataType：dynWeb动态页面，news附加内容，bottom底部栏目，newsWeb单篇页，topic专题，top顶部菜单
$MB->IsSecMenuRight('alertBack',15,$dataType);

switch ($mudi){
	case 'add':
	case 'rev':
		AddOrRev();
		break;

	case 'dynWeb2':	// 单个单篇页
		$dataID = OT::GetInt2( OT::ParaArr('id') );
		JS::HrefEnd('?mudi=rev&dataID='. $dataID .'&isOne=1');
		break;

	case 'dynWeb':
	case 'manage':
		manage();
		break;

	default:
		die('err');
}

$skin->WebBottom();

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





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

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');
	$backURL		= OT::GetStr('backURL');
	$isOne			= OT::GetInt('isOne');
	$dataID			= OT::GetInt2( OT::ParaArr('id') );

	if ($mudi == 'rev'){
		$revexe = $DB->query('select * from '. OT_dbPref .'infoWeb where IW_ID='. $dataID);
			if (! $row = $revexe->fetch()){
				JS::AlertBackEnd('无该记录！');		
			}
		$beforeURL	= GetUrl::CurrDir(1);
		$imgUrl		= $beforeURL . InfoImgDir;
		$IW_theme		= $row['IW_theme'];
		$IW_themeStyle	= $row['IW_themeStyle'];
		$IW_isTitle		= $row['IW_isTitle'];
		$IW_titleAddi	= $row['IW_titleAddi'];
		$IW_mode		= $row['IW_mode'];
		$IW_URL			= $row['IW_URL'];
		$IW_isEncUrl	= $row['IW_isEncUrl'];
		$IW_template	= $row['IW_template'];
		$IW_templateWap	= $row['IW_templateWap'];
		$IW_webKey		= $row['IW_webKey'];
		$IW_webDesc		= $row['IW_webDesc'];
		$IW_content		= $row['IW_content'];
			$IW_content	= str_replace(InfoImgAdminDir, $imgUrl, $IW_content);
		$IW_isWap		= $row['IW_isWap'];
		$IW_contentWap	= $row['IW_contentWap'];
			$IW_contentWap	= str_replace(InfoImgAdminDir, $imgUrl, $IW_contentWap);
		$IW_upImgStr	= $row['IW_upImgStr'];
		$IW_listMode	= $row['IW_listMode'];
			if ($IW_listMode == 0){ $IW_listMode = 2; }
		$IW_pageNum		= $row['IW_pageNum'];
		$IW_rank		= $row['IW_rank'];
		$IW_state		= $row['IW_state'];
		$IW_wapState	= $row['IW_wapState'];
		unset($revexe);

		$mudiCN = '修改';
	}else{
		$IW_theme		= '';
		$IW_themeStyle	= '';
		$IW_isTitle		= 0;
		$IW_titleAddi	= '';
		$IW_mode		= '';
		$IW_URL			= 'http://';
		$IW_isEncUrl	= 0;
		$IW_template	= '';
		$IW_templateWap	= '';
		$IW_webKey		= '';
		$IW_webDesc		= '';
		$IW_content		= '';
		$IW_isWap		= 0;
		$IW_contentWap	= '';
		$IW_upImgStr	= '';
		$IW_listMode	= 2;
		$IW_pageNum		= 15;
		$IW_rank		= intval($DB->GetOne("select max(IW_rank) from ". OT_dbPref ."infoWeb where IW_type='". $dataType ."'"))+10;
		$IW_state		= 1;
		$IW_wapState	= 1;

		$mudiCN = '添加';
	}

	$themeStyle_color	= Str::GetMark($IW_themeStyle,'color:',';');
	$themeStyle_b		= Str::GetMark($IW_themeStyle,'font-weight:',';');

	$skin->TableTop('share_show.gif','',$mudiCN . $dataTypeCN);
		echo('
		<form id="dealForm" name="dealForm" method="post" action="infoWeb_deal.php?mudi='. $mudi .'" onsubmit="return CheckForm()">
		');
		if ($backURL != '' && $isOne == 0){
			echo('<input type="hidden" id="backURL" name="backURL" value="'. $backURL .'" />');
		}else{
			echo('<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" id="backURL" name="backURL" value="\'+ document.location.href +\'" />\')</script>');
		}
		echo('
		<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 .'" />
		<input type="hidden" id="isOne" name="isOne" value="'. $isOne .'" />
		<input type="hidden" id="dataID" name="dataID" value="'. $dataID .'" />
		<table width="99%" align="center" cellpadding="0" cellspacing="0" summary="" class="padd3">
		<tr><td class="tabLeftWidth"></td><td></td></tr>
		<tr>
			<td align="right">标题：</td>
			<td>
			');
				if ($isOne){
					echo($IW_theme .'<input type="hidden" id="theme" name="theme" size="50" value="'. $IW_theme .'" />&ensp;');
				}else{
					echo('<input type="text" id="theme" name="theme" size="50" style="width:480px;'. $IW_themeStyle .'" value="'. $IW_theme .'" />&ensp;');
				}
				if (strpos('|bottom|top|','|'. $dataType .'|') !== false){
					echo(AppBase::InfoWebThemeB($themeStyle_b,$themeStyle_color));
				}
			echo('
			</td>
		</tr>
		');
		if (strpos($dataModeStr,'|URL|') !== false){
			echo('
			<tr>
				<td align="right">模式：</td>
				<td>
					<select id="mode" name="mode" onchange="CheckMode()">
						<option value="web">单篇页</option>
						<option value="url" '. Is::Selected($IW_mode,'url') .'>外部链接(http://)</option>
						<option value="sitemap" '. Is::Selected($IW_mode,'sitemap') .'>网站地图(sitemap.html)</option>
						<option value="message" '. Is::Selected($IW_mode,'message') .'>留言板</option>
						<option value="saveUrl" '. Is::Selected($IW_mode,'saveUrl') .'>*保存到桌面</option>
						<option value="addFavo" '. Is::Selected($IW_mode,'addFavo') .'>*加入收藏</option>
						<option value="setHome" '. Is::Selected($IW_mode,'setHome') .'>*设为首页</option>
					</select>
				</td>
			</tr>
			<tr id="urlBox">
				<td align="right">外部链接：</td>
				<td>
					<input type="text" name="webURL" size="50" style="width:480px;" value="'. $IW_URL .'" />
					'. AppTaobaoke::InfoWebEncUrl($IW_isEncUrl) .'
				</td>
			</tr>
			');
		}
		echo('
		<tbody id="webBox">
		');
		if ($dataType != 'news'){
			echo(AppBase::InfoWebTrBox1($IW_titleAddi,$IW_isTitle));
		}
		echo(AppBase::InfoWebTrBox2($IW_template)
			. AppWap::InfoWebTrBox2($IW_templateWap));
		if ($dataType != 'news'){
			echo('
			<tr>
				<td align="right" valign="top" style="padding-top:6px;">
					关键字：<br />(Keywords)
				</td>
				<td style="padding-bottom:4px;"><textarea id="webKey" name="webKey" rows="5" cols="40" style="width:480px; height:60px;">'. $IW_webKey .'</textarea></td>
			</tr>
			<tr>
				<td align="right" valign="top" style="padding-top:6px;">
					描述：<br />(Description)
				</td>
				<td style="padding-bottom:4px;"><textarea id="webDesc" name="webDesc" rows="5" cols="40" style="width:480px; height:60px;">'. $IW_webDesc .'</textarea><span class="font2_2">星号“*”表示使用网站关键字/描述</span></td>
			</tr>
			');
		}
		if ($dataType == 'topic'){
			echo('
			<tr>
				<td align="right">列表页模式：</td>
				<td align="left">
					<label><input type="radio" name="listMode" value="7" '. Is::Checked($IW_listMode,7) .' />标题</label>&ensp;&ensp;
					<label><input type="radio" name="listMode" value="1" '. Is::Checked($IW_listMode,1) .' />标题+摘要</label>&ensp;&ensp;
					<label><input type="radio" name="listMode" value="2" '. Is::Checked($IW_listMode,2) .' />图+摘要1</label>&ensp;&ensp;
					<label><input type="radio" name="listMode" value="4" '. Is::Checked($IW_listMode,4) .' />图+摘要2</label>&ensp;&ensp;
					<label><input type="radio" name="listMode" value="3" '. Is::Checked($IW_listMode,3) .' />图+标题</label>&ensp;&ensp;
				</td>
			</tr>
			<tr>
				<td align="right">每页数量：</td>
				<td>
					<input type="text" id="pageNum" name="pageNum" size="3" value="'. $IW_pageNum .'" />
				</td>
			</tr>
			');
		}else{
			echo('
			<tr>
				<td align="right" valign="top" style="margin-top:6px;">内容：</td>
				<td>
					<textarea id="content" name="content" cols="40" rows="4" style="width:650px;height:500px;" class="text" onclick=\'LoadEditor("content",0,0,"");\' title="点击开启编辑器模式">'. Str::MoreReplace($IW_content,'textarea') .'</textarea>
					<script language="javascript" type="text/javascript">LoadEditor("content",0,0,"");</script>
					<div style="padding:2px 0;">
					<input type="hidden" id="upImgStr" name="upImgStr" value="'. $IW_upImgStr .'" />
					<input type="button" onclick=\'OT_OpenUpImg("editor","content","","")\' value="上传图片载入编辑器" />
					'. ($dataType == 'news' ? '&ensp;<input type="button" onclick=\'CopyStrToEditor("content")\' value="插入【一键复制框】" />' : '') .'
					</div>
				</td>
			</tr>
			'. AppWap::InfoWebBox1($IW_isWap, $IW_contentWap) .'
			');
		}
		echo('
		</tbody>
		<tr>
			<td align="right">排序：</td>
			<td>
				<input type="text" id="rank" name="rank" size="3" value="'. $IW_rank .'" />
			</td>
		</tr>
		');
		if (strpos('|bottom|top|topic|news|','|'. $dataType .'|') !== false){
			echo('
			<tr>
				<td align="right">电脑版状态：</td>
				<td align="left">
					<label><input type="radio" name="state" value="1" '. Is::Checked($IW_state,1) .' />显示</label>&ensp;&ensp;
					<label><input type="radio" name="state" value="0" '. Is::Checked($IW_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($IW_wapState,1) .' />显示</label>&ensp;&ensp;
					<label><input type="radio" name="wapState" value="0" '. Is::Checked($IW_wapState,0) .' />隐藏</label>&ensp;&ensp;
				</td>
			</tr>
			');
		}else{
			echo('
			<input type="hidden" name="state" value="'. $IW_state .'" />
			<input type="hidden" name="wapState" value="'. $IW_wapState .'" />
			');
		}
		echo('
		</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>
		');

	$skin->TableBottom();
}



// $dataType bottom底部栏目，top顶部菜单，topic专题页，news附加内容
function manage(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$pageCount,$recordCount;

	$dataID		= OT::GetInt2( OT::ParaArr('id') );
	$dataMode	= OT::GetStr('dataMode');
	$dataModeStr= OT::GetStr('dataModeStr');

	echo('
	<div style="padding:6px;">
		<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;&ensp;&ensp;
	</div>

	<form id="listForm" name="listForm" method="post" action="infoWeb_deal.php?mudi=moreDel" onsubmit="return CheckListForm()">
	<script language="javascript" type="text/javascript">document.write (\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'" />\')</script>
	<input type="hidden" name="dataType" value="'. $dataType .'" />
	<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />
	');

	$dataModeCN = '单篇页';
	$skin->TableTop2('share_list.gif','',$dataTypeCN .'列表');
	$skin->TableItemTitle('8%,8%,12%,38%,8%,11%,15%','编号,ID号,模式,名称,排序,电脑/WAP状态,预览&ensp;修改&ensp;删除');

	$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit("select * from ". OT_dbPref ."infoWeb where IW_type='". $dataType ."' order by IW_rank DESC", $pageSize, $page);
	if (! $showRow){
		$skin->TableNoData();
	}else{
		$recordCount=$DB->GetRowCount();
		$pageCount=ceil($recordCount/$pageSize);
		if ($page < 1 || $page > $pageCount){$page=1;}

		echo('
		<tbody class="tabBody padd3">
		');
		$number=1+($page-1)*$pageSize;
		$rowCount = count($showRow);
		for ($i=0; $i<$rowCount; $i++){
			if ($i % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }

			if ($dataType == 'topic'){
				$dataModeCN = '专题页';
				$webURL = '../news/?list_topic-'. $showRow[$i]['IW_ID'] .'.html';
			}else{
				$dataModeCN = ModeCN($showRow[$i]['IW_mode']);
				$webURL = '../news/?web_'. $showRow[$i]['IW_ID'] .'.html?rnd=';
			}
			echo('
			<tr id="data'. $showRow[$i]['IW_ID'] .'" '. $bgcolor .'>
				<td align="center">'. $number .'</td>
				<td align="center">'. $showRow[$i]['IW_ID'] .'</td>
				<td align="center">'. $dataModeCN .'</td>
				<td align="center" style="'. $showRow[$i]['IW_themeStyle'] .'">'. $showRow[$i]['IW_theme'] .'</td>
				<td align="center">'. $showRow[$i]['IW_rank'] .'</td>
				<td align="center">
					'. Adm::SwitchBtn('infoWeb',$showRow[$i]['IW_ID'],$showRow[$i]['IW_state'],'state') .'/
					'. Adm::SwitchBtn('infoWeb',$showRow[$i]['IW_ID'],$showRow[$i]['IW_wapState'],'wapState','userState') .'
				</td>
				<td align="center">
					<img src="images/img_det.gif" style="cursor:pointer" onclick=\'window.open("'. $webURL .'")\' alt="" />&ensp;&ensp;
					<img src="images/img_rev.gif" style="cursor:pointer;" onclick=\'document.location.href="?mudi=rev&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $showRow[$i]['IW_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="infoWeb_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['IW_theme']) .'&dataID='. $showRow[$i]['IW_ID'] .'"}\' alt="" />
				</td>
			</tr>
			');
			$number ++;
		}
		echo('
		</tbody>
		<!-- <tr class="tabColorB padd5">
			<td align="left" colspan="20">
				<input type="button" value="全选" class="tabBottomBtn allSel" onclick="AllSelBox()" />
				<input type="button" value="反选" class="tabBottomBtn revSel" onclick="RevSelBox()" />
				&ensp;
				<input type="submit" value="批量删除" class="tabBottomBtn del" />
			</td>
		</tr> -->
		');
	}
	unset($showRow);

	echo('</form>');

	$skin->TableBottom2($pageCount, $pageSize, $recordCount);

	if ($dataType == 'topic'){
		echo('<div class="font2_2" style="margin:5px;">提醒：新增/编辑栏目-模式['. $dataModeCN .']，可以调用该信息。</div>');
	}
}


function ModeCN($str){
	switch ($str){
		case 'web':			return '单篇页';
		case 'url':			return '外部链接';
		case 'sitemap':		return '网站地图';
		case 'message':		return '留言板';
		case 'saveUrl':		return '保存到桌面';
		case 'addFavo':		return '加入收藏';
		case 'setHome':		return '设为首页';
		default :			return '['. $str .']';
	}
}
?>