<?php

include_once('./../../../include/cp_header.php');
define( '_MYMENU_CONSTANT_IN_MODINFO' , '_MI_SLIDER_NAME' ) ;

// branch for altsys
if( defined( 'XOOPS_TRUST_PATH' ) && ! empty( $_GET['lib'] ) ) {
	$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
	$mydirpath = dirname( dirname( __FILE__ ) ) ;

	// common libs (eg. altsys)
	$lib = preg_replace( '/[^a-zA-Z0-9_-]/' , '' , $_GET['lib'] ) ;
	$page = preg_replace( '/[^a-zA-Z0-9_-]/' , '' , @$_GET['page'] ) ;

	if( file_exists( XOOPS_TRUST_PATH.'/libs/'.$lib.'/'.$page.'.php' ) ) {
		include XOOPS_TRUST_PATH.'/libs/'.$lib.'/'.$page.'.php' ;
	} else if( file_exists( XOOPS_TRUST_PATH.'/libs/'.$lib.'/index.php' ) ) {
		include XOOPS_TRUST_PATH.'/libs/'.$lib.'/index.php' ;
	} else {
		die( 'wrong request' ) ;
	}
	exit ;
}

icms_cp_header();
include( './mymenu.php' ) ;

$myid = $_GET['id'];

if(!$myid){
	redirect_header('index.php', 3, "不思議な処理が行われました");
}


$sql = "select * from `" . $xoopsDB->prefix("slider_data") . "` where ID='" . $myid . "'";
$result = icms::$xoopsDB->query($sql);
$mcount = icms::$xoopsDB->getRowsNum($result);

if(!$mcount){
	redirect_header('index.php', 3, "不思議な処理が行われました");
}

$myrow = icms::$xoopsDB->fetchArray($result);
$ans = "<form id='sform' method='post' action='update.php?op=update' enctype='multipart/form-data'>";
$ans .= "<table>";
$ans .= "<tr class='head'><th>項目</th><th>データ</th></tr>";
$ans .= "<tr class='odd'><td>ID</td><td>" . $myrow['ID'] . "</td></tr>";
$ans .= "<tr class='even'><td>題名</td><td><input type='text' name='name' value='" . $myrow['name'] . "'></td></tr>";
$ans .= "<tr class='odd'><td>画像</td><td><input type='checkbox' name='checked' value='1' checked='checked' /><small>現在の画像を使用</small><br />";
$ans .= "<input type='file' name='upfile' id='upfile' accept='image/*' /><br />";
$ans .= "<img class='uploaded thumb' src='" . XOOPS_URL . $myrow['imgfile']. "' style='width:300px;height:auto;'>";
$ans .= "</td>";
$ans .= "<tr class='even'><td>メッセージ1</td><td><input type='text' size='100' name='msg1' value='" . $myrow['msg1'] . "'></td></tr>";
$ans .= "<tr class='odd'><td>メッセージ2</td><td><input type='text' size='100' name='msg2' value='" . $myrow['msg2'] . "'></td></tr>";
$ans .= "<tr class='even'><td>メッセージ2リンク先</td><td><input type='text' size='100' id='msg2_link' name='msg2_link' value='" . $myrow['msg2_link'] . "'><input type='button' id='kakunin' value='リンク先確認'></td></tr>";
$ans .= "<tr class='even'><td>表示開始日</td><td><input type='text' id='start_date' name='start_date' value='" . $myrow['start_date'] . "'></td></tr>";
$ans .= "<tr class='odd'><td>表示終了日</td><td><input type='text' id='end_date' name='end_date' value='" . $myrow['end_date'] . "'></td></tr>";
$ans .= "<tr class='even'><td>&nbsp;</td><td><input type='button' id='koshin' value='更新'>&nbsp;<input type='button' id='goback' value='中止'></td></tr>";
$ans .= "</table><input type='hidden' name='myid' value='" . $myrow['ID'] . "'><input type='hidden' name='mode' value='upd'></form>";


$myscript = '
<script>
	$(function(){

		$("#start_date,#end_date").datepicker({
			regional: "ja",
			dateFormat: "yy-mm-dd",

		});

    $(".single").colorbox({
    	maxWidth:"90%",
    	maxHeight:"90%",
    	opacity: 0.7
  	});

    $("form input:file").uploadThumbs({
	      position : 1,
	      imgbreak : false
	  });

		$(document).on("click","#goback", function(){
			window.location.href="index.php";
		});

		$(document).on("click","#koshin", function(){
			$("#sform").submit();
		});

		$(document).on("click","#kakunin", function(){
			var myurl = $("#msg2_link").val();
			window.open(myurl);
		});



	})
</script>
<style>
form img.thumb {
    margin:0 5px 5px 0;
    max-width:160px;
    vertical-align:bottom;
}
input[type="file"]{
	display: block;
}
</style>';

echo $ans;
echo $myscript;


icms_cp_footer();
