<?php
  include("./control/session.inc");

  $cname = 'content_list'; 
  $title = 'AYANASU control top';
  $p = $_GET["p"];

function content_list()
{

//ページャー設定
  $delta = 5;    // 現在から前(後)に表示するＬＩＮＫ数
  $perPage = 5;  // 1ページのデータ表示件数
  $i=0;

//一覧表示HTML

$content1 = <<<EOD
<div id="main_r1">
<h2>コンテンツ一覧</h2>

EOD;
 print("$content1");

//ファイル一覧の取得

 $path='content/';

foreach(glob($path ."*.php") as $file)
{
 $i++;
 include_once $file;
 $array1 = explode("/", $file);
 $list1 = ($array1[count($array1) -1] ); 
 $array2 = explode(".", $list1);

    if(($array2[count($array2) -2] ) == "index"){
    $box1 = 'border_box_index';
    $but4 = '<div id="box_title"><div class="fi-page-copy"><input type="text" class="copy2" readonly="readonly" onClick="this.setSelectionRange(0, this.value.length)" value="'.htmlspecialchars('<a href="index.php">').'リンク文字列'.htmlspecialchars('</a>').'"/></div></div>';
    }else{
    $box1 = 'border_box';
    $but4 = '<div id="box_title"><div class="fi-page-copy"><input type="text" class="copy2" readonly="readonly" onClick="this.setSelectionRange(0, this.value.length)" value="'.htmlspecialchars('<a href="index.php?name=').($array2[count($array2) -2] ).htmlspecialchars('">').'リンク文字列'.htmlspecialchars('</a>').'"/></div></div>';
    }
    $but2 = '<a href="./content/file_operation/rename.php?name='.($array2[count($array2) -2] )."\" onClick=\"window.open"."('./content/file_operation/rename.php?name=".($array2[count($array2) -2] )."','subwin','width=600,height=350,left=500,top=300,menubar=no,toolbar=no,location=no,scrollbars=no'); return false;\" class=\"but1\"><div class=\"fi-page-edit\"> 名前の変更</div></a>";
    $but3 = '<a href="./content/file_operation/delete.php?name='.($array2[count($array2) -2] )."\" onClick=\"window.open"."('./content/file_operation/delete.php?name=".($array2[count($array2) -2] )."','subwin','width=600,height=350,left=500,top=300,menubar=no,toolbar=no,location=no,scrollbars=no'); return false;\" class=\"but1\"><div class=\"fi-trash\"> 削除(確認)</div></a>";
    $list = '<div id="'.$box1.'">'
.'<a href="index.php?name='.($array2[count($array2) -2] ).'" class="but1" target="_blank"><div class="fi-magnifying-glass"> '.($array2[count($array2) -2] ).'</div></a>'.PHP_EOL
.'<a href="?cname=creating_r&name='.($array2[count($array2) -2] ).'" class="but1"><div class="fi-page-edit"> 編集更新</div></a>'.PHP_EOL
.'<a href="?cname=creating_c&name='.($array2[count($array2) -2] ).'" class="but1"><div class="fi-page-copy"> コピー編集</div></a>'.PHP_EOL
.$but2.PHP_EOL
.$but3.PHP_EOL
.'<div id="box_title"><div class="fi-page-copy"><input type="text" class="copy1" readonly="readonly" onClick="this.setSelectionRange(0, this.value.length)" value="'.$title.'"/></div></div>'
.PHP_EOL
.$but4.PHP_EOL
.'</div>'
.PHP_EOL;

//ページング条件分岐

 $num = count(glob($path ."*.inc"));
  if( ($_GET['p'] =="" or $_GET['p'] =="0" or $_GET['p'] =="1") and $i <= $perPage){
 print $list;
 }if($_GET['p'] > "1" and $i >= ($perPage * $_GET['p']-($perPage-1)) and $i <= $perPage * $_GET['p']) {
 print $list;
 }

}

// ページャー設定
  $page_ceil = $num/$perPage;
  $totalPage = ceil($page_ceil);
  $url = "AYANASU_control.php?cname=content_list&p=";
  $page = ($_GET[p]) ? $_GET[p]: 1;
  include("./pager.inc");

  $content2 = "</div>";
  print $content2;

  }

?>

