<?php
  session_start();
  if(!isset($_SESSION["USERID"])){
  header("Location: ../../login.php");
  exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="ROBOTS" content="NOINDEX">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=yes" />
<title><?php print("$title");?></title>
<link rel="stylesheet" href="../../control/style.css" type="text/css">
<link rel="stylesheet" href="../../control/style_768.css" type="text/css">
<link rel="stylesheet" href="../../foundation-icons/foundation-icons.css" />
</head>
<body>
<?php

  function renamer(){

  $name = $_GET['name'];
  $r_name = $_POST['r_name'];//現在のファイル名、空白時に使用
  $change = $_POST['change'];
  $newname = $_POST['newname'];//新しいファイル名

  if($change =="1" and $newname !== ""){

    if(strpos($r_name,'linkGroup') !== false){
    $re_file = '../'.$r_name.'.inc';
    $new_file = '../linkGroup/'.$newname.'.inc';
    rename($re_file,$new_file);
$test1=1;

    }elseif(strpos($r_name,'html_tag') !== false){
    $re_file = '../'.$r_name.'.inc';
    $new_file = '../html_tag/'.$newname.'.inc';
    rename($re_file,$new_file);
$test1=2;

    }elseif(strpos($r_name,'img_up') !== false){
    $re_file = '../'.$r_name;
    $new_file = '../img_up/'.$newname;
    rename($re_file,$new_file);
$test1=2;

    }elseif(strpos($r_name,'linkGroup') === false and strpos($r_name,'html_tag') === false){
    $re_file1 = '../'.$r_name.'.php';
    $new_file1 = '../'.$newname.'.php';
    rename($re_file1,$new_file1);
    $re_file2 = '../'.$r_name.'.inc';
    $new_file2 = '../'.$newname.'.inc';
    rename($re_file2,$new_file2);
$test1=3;

    }



  $form = <<<EOD
<br><br>
<div id="main_r1">
<h2>変更完了 {$newname}</h2>

{$re_file1}<br>{$new_file1}<br>
{$re_file2}<br>{$new_file2}<br>
{$test1}

<br><br>　コンテンツ名【{$newname}】に変更いたしました。
<br><br>
<div id="border_box">
<a href="#" class="but1" onClick="window.opener.location.reload();window.close(); return false;"><div class="fi-x"> 閉じる CLOSE</div></a>
</div>
<br><br>
</div>
EOD;

  print $form;

  }else{

    if(strpos($name,'img_up') !== false){
    $text1='<font color="red">　※拡張子の入力が必要です。</font>';
    }else{
    $text1='　※拡張子の入力は不要です。';
    }

  $form = <<<EOD
<br><br>
<div id="main_r1">
<h2>ファイル名【{$name}】の変更</h2>
<br>
{$text1}
<br><br>

<form action="./rename.php?name=$r_name" method="post">
<div id="border_box">
<div id="form_box4">　新しいファイル名　<input type="text" name="newname" size="30" class="form_01">
<br><br>
</div>

<input type="hidden" name="r_name" value="{$name}">
<input type="hidden" name="change" value="1">
<a href="#" class="but1" onClick="window.close(); return false;"><div class="fi-x"> 閉じる CLOSE</div></a>
<button class="d_button" type="submit"><div class="fi-page-edit"> 変更 RENAME</div></button>
</form>
</div>
<br><br>

</div>
EOD;

  print $form;
  }

}
renamer();

?>
</body>
</html>
