<?php

//メンテナンスロック
if(maint_lock >= MAS_FLAG){
	dell_session(cookie_name,'','1');#セッション破棄
	error("現在メンテナンス中です");
}

//共通任意のplugin
require_once(plug_dir."plug-delete.php");
require_once(plug_dir."plug-page.php");
require_once(plug_dir."plug-write.php");
require_once(plug_dir."plug-schedule.php");


#---------------------------------------------#
#                            初期設定
#---------------------------------------------#

$CG=array("class='hide'");

//コンテンツチェック
$CONT_OTC=CheckACT();

//実行モジュール
$PRINT="";
$SPLUG="cont";if(QSS) $SPLUG=QSS;
// debug-s kyoh for お店から速報の投稿回数の調整
//$course = 'couse_PC_p';
$course = 'couse_MO_p';
$query = "SELECT $course FROM client_shop_t WHERE id_p = " . ID;
$result = loadsqldata($query,"","");
$SOKUHO_MAXCNT = '';
if($result) {
    // オプションの場合
    if ($result[0][$course] == 4) { $SOKUHO_MAXCNT = 6; }
}
// debug-e kyoh for お店から速報の投稿回数の調整
if(!file_exists(adm_dir."adm-".$SPLUG.".php")) error("不明な処理です");
require_once(adm_dir."adm-".$SPLUG.".php");

//表示
$PRINT_TAB=tab_menu($TAB_MENU,$TAB_LINK,$TAB_PLUG,$TAB_COM);
$MAIN_PRINT=$PRINT;

//JAVAチェック
$header_print.="<noscript><META HTTP-EQUIV=Refresh CONTENT='0; URL=?login=1'></noscript>";

//アラート表示
require_once(adm_dir."plug-alert-set.php");
$ALERT_FLAG=alert_disp();


#---------------------------------------------#
#                 	       メイン画面
#---------------------------------------------#

$PRINT=header_disp($header_print,$header_body);

//上
$name=$DATA[0]['area_p'].$DATA[0]['genre_p'].$DATA[0]['name'];
$PRINT.="<div id='bodys'>";
$PRINT.="<div class='title-bar'>".str_replace(",","/",$name)."</div>";
//$PRINT.="<div class='logout'><a href='?'>サイト管理トップ</a>｜<a href='?ss=manual' target=_blank>ヘルプ</a>｜<a href='?login=1'>ログアウト</a></div>";
//$PRINT.="<div class='logout'><a href='?'>サイト管理トップ</a>｜<a href='?login=1'>ログアウト</a></div>";
// PC SP切り替え追加
$PRINT.="<div class='logout'><a href='?'>サイト管理トップ</a>｜<a href='?terminal=sp'>スマホ表示</a>｜<a href='?login=1'>ログアウト</a></div>";
$PRINT.="</div>";

//loding
$PRINT.="<div id='loading' style='display:none' align='center'><img src='".log_full."admin/images/"."loading_l.gif'><br>処理実行中...<br>完了するまでこのままお待ち下さい</div>\n";
$PRINT.="<div id='wrap'>";

//左
$PRINT.="<div id='lefts'>";
$PRINT.="<div class='corner-left'></div>";
$PRINT.="<div class='corner-right'></div>";
$PRINT.="<div class='sub-cont'>";
$PRINT.="<h1>風俗サイト管理システム<br>".preg_replace("/([0-9]{1,4})([0-9]{1,2})([0-9]{1,2})/","\$1年\$2月\$3日",TODAY)."(".$WEEKDAY[date("w", TimeStamp(TODAYS))].")</h1>";

$PRINT.="<h3><a href='?' >トップページ</a></h3>";
$PRINT.="<ul class='departments'>";
foreach($SCRIPT_FLAG[2] as $key => $val){
	if(!in_array($key,$CONT_OTC)) continue;
	$PRINT.="<li><a href='?ss=".$key."'>".$val[0].$ALERT_FLAG[$key]."</a></li>";
}
$PRINT.="</ul>";

$temp="";
foreach($SCRIPT_FLAG[1] as $key => $val){
	if(!in_array($key,$CONT_OTC)) continue;
	$temp.="<li><a href='?ss=".$key."'>".$val[0].$ALERT_FLAG[$key]."</a></li>";
}
if($temp) $PRINT.="<h3><a href='?' >コンパニオン管理</a></h3><ul class='departments'>".$temp."</ul>";

$temp="";
foreach($SCRIPT_FLAG[4] as $key => $val){
	if(!in_array($key,$CONT_OTC)) continue;
	$temp.="<li><a href='?ss=".$key."'><img src='".icon_dir."icon_".$key.".gif'>".$val[0].$ALERT_FLAG[$key]."</a></li>";
}
if($temp) $PRINT.="<h3><a href='?' >サービスコンテンツ</a></h3><ul class='departments'>".$temp."</ul>";

$temp="";
foreach($SCRIPT_FLAG[3] as $key => $val){
	if(!in_array($key,$CONT_OTC)) continue;
	$temp.="<li><a href='?ss=".$key."'><img src='".icon_dir."icon_".$key.".gif'>".$val[0].$ALERT_FLAG[$key]."</a></li>";
}
if($temp) $PRINT.="<h3><a href='?' >ご掲載コンテンツ</a></h3><ul class='departments'>".$temp."</ul>";


$PRINT.="</div>";
$PRINT.="</div>";


//真ん中
$PRINT.="<div id='centers'>";
$PRINT.="<div id='tab'>";
$PRINT.=$PRINT_TAB;
$PRINT.="<div id='cont'>";
$PRINT.="<h1>".$CONT_TIT."</h1>";
$PRINT.=$MAIN_PRINT;
$PRINT.="</div>";
$PRINT.="</div>";
$PRINT.="</div>";


//右
$add=data_full.MYHOME."/c/admin.php";
$PRINT.="<div id='rights'>";
$PRINT.="<div class='corner-left'></div>";
$PRINT.="<div class='corner-right'></div>";
$PRINT.="<div class='sub-cont'>";
$PRINT.="<div class='topqr'><img src='".module_name."plugin/qrcode.php?S=3&V=".$add."'></div>";

//CSVコンテンツ
$print_menu="";
if(RFLAG){
	foreach($CONTRACT_FLAG as $key =>$val){
		$contract[$key]=$DATA[0]["couse_".$key."_p"];
		$homepage=car_dir($DATA[0],$key,data_dir);
		$homepage2=car_dir($DATA[0],$key,data_full);
		if(is_dir($homepage) && $contract[$key]) $print_menu.="<li class=h3><a href='".JUMP_PAGE.$homepage2."' target='_blank'>".$CONTRACT_NA[$key]."</a></li>";
	}
}
if(FFLAG!=''){
	$print_menu.="<li class=h3><a href='".JUMP_PAGE."https://".$CONT_FLAG['fan'][1]."i/view.php?ID=".FLOG."' target='_blank'>モバイルファン</a></li>";
}
if($print_menu){
	$PRINT.="<h1>お客様ホームページ</h1>";
	$PRINT.="<ul class='departments'>";
	$PRINT.=$print_menu;
	if(RFLAG) $PRINT.="<li><a href='?ss=analyze'>アクセス状況</a></li>";
	$PRINT.="</ul>";
}

//$PRINT.="<div id='moreadmin'><ul><li><a href='?ss=receipt'>ご掲載情報</a></li></ul></div>";

$print_menu="";
if(RFLAG){
	foreach($SCRIPT_FLAG[0] as $key => $val){
		for($i=0;$i<$SC_MAX[0][$key];$i++){
			list($flag,$contTIT,$temp)=csv_set($key,$i);
			if(!$flag) continue;
			$print_menu.="<li><a href='?ss=".$key;
			if($i) $print_menu.="&ct=".$i;
			$print_menu.="'>".$contTIT."</a></li>";
		}
	}
	if($print_menu){
		$PRINT.="<h1>お客様ページ更新</h1>";
		$PRINT.="<ul class='departments'>";
		$PRINT.=$print_menu;
		$PRINT.="</ul>";
	}
}

//モバイルファン
$print_menu="";
if(FFLAG!=''){
	foreach($SCRIPT_FLAG[5] as $key => $val){
		for($i=0;$i<$SC_MAX[5][$key];$i++){
			list($flag,$contTIT,$temp)=csv_set($key,$i);
			if(!$flag) continue;
			$print_menu.="<li><a href='?ss=".$key;
			if($i) $print_menu.="&ct=".$i;
			$print_menu.="'>".$contTIT."</a></li>";
		}
	}
	if($print_menu){
		$PRINT.="<h1>モバイルファン更新</h1>";
		$PRINT.="<ul class='departments'>";
		$PRINT.=$print_menu;
		$PRINT.="</ul>";
	}
}

$PRINT.="<div id='moreadmin'>";
$PRINT.="<ul>";
//$PRINT.="<li><a href='".log_full."admin/manual.pdf' target=_blank>オンラインマニュアル</a></li>";
if(MAS_FLAG=='3') $PRINT.="<li><a href='?ss=script'>コンテンツ設定</a></li>";
$PRINT.="</ul>";
$PRINT.="</div>";

$PRINT.="</div>";
$PRINT.="</div>";


//footer
$PRINT.=footer_disp();


#---------------------------------------------#
#        					タブ表示
#---------------------------------------------#
function  tab_menu($MENU=array(),$LINK=array(),$TAB=array(),$tipcom=array())
{
	global $Q;
	if(!$MENU) return;

	$width=floor(600/sizeof($MENU));
	if($width>120) $width=120;
	$style="width:".$width."px;";

	$PRINT="<div class='tab-cont'>";
	$PRINT.="<ul class='tab-menu'>";
	foreach($MENU as $k => $v){
		if($v=="管理設定" && MAS_FLAG!=3) continue;
		$com="";if($tipcom[$k]) $com="class=tips title='".$tipcom[$k]."'";
		$a=explode("&",$LINK[$k]);
		$ss = ereg_replace("(\?ss\=)([a-z0-9-]+)","\\2",$a[0]);
		if($TAB[$k]){
			$tab=explode(",",$TAB[$k]);
			if($tab[0]) $LINK[$k].="&plug=".$tab[0];
		}else{
			$tab=array();
		};
		if($Q{'ct'} && $LINK[$k]!='?') $LINK[$k].="&ct=".$Q{'ct'};

		if((in_array($Q{'plug'}, $tab) || $Q{'plug'}==$TAB[$k]) && QSS==$ss && $v!='戻る') $PRINT.="<li style='".$style."' $com><a class='active' href='".$LINK[$k]."'><strong>".$v."</strong></a></li>";
		else $PRINT.="<li style='".$style."' $com><a href='".$LINK[$k]."'><strong>".$v."</strong></a></li>";
	}
	$PRINT.="</ul>";
	$PRINT.="</div>";

	return $PRINT;
}

#---------------------------------------------#
#        					契約表示
#---------------------------------------------#
function  prid_disp($value,$tit,$disp='',$tco='',$sma='')
{
	if(!$value) return;
	global $CONT_FLAG;

	$stime=ereg_replace("([0-9]{4})([0-9]{2})([0-9]{2})", "\\2月\\3日 〜 ", $value["start_ct"]);
	if($value["end_ct"]) $etime=ereg_replace("([0-9]{4})([0-9]{2})([0-9]{2})", "\\2月\\3日まで", $value["end_ct"]);
	$vtime=$stime.$etime."ご掲載";if(!$stime) $vtime="調整中";
	if($disp) $disp="- ".$disp;
	//$co="#FFF7CD";
	if($value["start_ct"]>TODAY) $co="#EEEEEE";
	if($tco) $co=$tco;
	$ctp=$CONT_FLAG[$value['ctplug_ct']][0];if(!$CONT_FLAG[$value['ctplug_ct']][0]) $ctp="風俗サイト共通";
	if(!$sma) $small=$ctp." / ";

	$PRINT="<li style='background:$co' class='receipt-cont'>";
	//$PRINT.="<b><font ".CS_TEXT3.">■".$small.$tit." ".$disp."</font></b><br>　ご掲載期間：<font color=red>".$vtime."</font>";
	$PRINT.="<b><font ".CS_TEXT3." color=red>■".$small.$tit." ".$disp."</font></b>";
	$PRINT.="</li>\n";

	return $PRINT;
}

?>
