<?php

  include("./control/session.inc");
  $c1 = $_POST['c1'];

function form()
{

  $r_name = $_GET['name'];

  if(file_exists("./content/{$r_name}.php")) {
  include ("./content/{$r_name}.php");
  $file_name = "./content/{$r_name}.inc";
  $content = file_get_contents( $file_name );
  }else{
  header("Refresh: 1; URL=AYANASU_control.php");
  exit;
  }

  $c1 = $_POST['c1'];

  if($_POST['c1'] =="1"){

  $name = $_POST['name'];
  $meta_dscr = $_POST['meta_dscr'];
  $meta = $_POST['meta'];
  $head = $_POST['head'];
  $title = $_POST['title'];
  $content = $_POST['content'];

//titleタグ エラー処理

    if($_POST['title'] == ""){
    $fmess = "<font color=\"red\">●titleタグの内容です。全角30文字前後が目安です。(入力必須)</font>";
    $check ='2';
    }else{
    $fmess = 'Good!';
    $check ='1';
    }

//書き込み準備

    if($check == "1"){

    $gif_an = <<<EOD
<div id="main_r1">
<h2>コンテンツの保存中です</h2>
<div class="loader"></div>…Creating
</div>
EOD;

  print("$gif_an");

$c_conf = <<<KOEY
<?php
  \$fl_name = '$r_name';
  \$meta_dscr = '$meta_dscr';

  \$meta  = <<<EOD
$meta
EOD;

  \$head  = <<<EOD
$head
EOD;

  \$title = '$title';
?>
KOEY;

$c_text = <<<KOEY
{$content}
KOEY;

    $r_file1 = $r_name.'.php';
    $r_file2 = $r_name.'.inc';
    $r_dir = './content/';

//書き出し処理
    file_put_contents($r_dir.$r_file1,$c_conf,LOCK_EX);
    file_put_contents($r_dir.$r_file2,$c_text,LOCK_EX);

    header("Refresh: 2; URL=AYANASU_control.php?cname=creating_r&name={$r_name}&r=1");
    }else{
    include('./control/form_r.inc'); 
    print $form;
    }

  }elseif($_POST['c1'] ==""){
  $fmess3 = 'titleタグの内容です。全角30文字前後が目安です。';
  include('./control/form_r.inc'); 
  print $form;
  }

}//function form()
?>