<?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' ) ;

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

$ans = '';
$oddeven = "odd";
if($mcount) {
	while ($myrow = icms::$xoopsDB->fetchArray($result)) {
		if($oddeven == "odd")
			$oddeven = "even";
		else
			$oddeven = "odd";
		$ans .= "<tr class='" . $oddeven . "'>";
		$ans .= "<td>" . $myrow['ID']. "</td>";
		$ans .= "<td><a class='single' href='" . XOOPS_URL . $myrow['imgfile']. "' title='" . $myrow['name'] . "'><img src='" . XOOPS_URL . $myrow['imgfile']. "' style='width:300px;height:auto;'></a></td>";
		$ans .= "<td>" . $myrow['msg1']. "</td>";
		$ans .= "<td>" . $myrow['msg2']. "</td>";
		$ans .= "<td><input type='button' class='chenshu' myid='" . $myrow['ID']. "' value='編集'> &nbsp; <input type='button' class='csakujo' myid='" . $myrow['ID']. "' value='削除'></td>";
	}
} else {
		$ans .= "<tr class='" . $oddeven . "'>";
		$ans .= "<td colspan='5'>No data</td>";
}

$mytable = "<table>";
$mytable .= "<tr class='head'>";
$mytable .= "<th>ID</th>";
$mytable .= "<th>イメージ</th>";
$mytable .= "<th>Msg1</th>";
$mytable .= "<th>Msg2</th>";
$mytable .= "<th>処理</th>";
$mytable .= "</tr>";
$mytable .= $ans;
$mytable .= "</table>";


$myscript = '
<script>
	$(function(){
		$(".chenshu").on("click",function(){
				var myid=$(this).attr("myid");
				var gourl="henshu.php?id="+myid;
				window.location.href=gourl;
		})
		$(".csakujo").on("click",function(){
			var myid=$(this).attr("myid");
			var myans = confirm("本当に削除しますか？");
			if(myans == true){
				var gourl="sakujo.php?id="+myid;
				window.location.href=gourl;
			}
		})
    $(".single").colorbox({
    	maxWidth:"90%",
    	maxHeight:"90%",
    	opacity: 0.7
  	});


	})
</script>';

echo $mytable;
echo $myscript;


icms_cp_footer();
