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

function form()
{

  $c1 = $_POST['c1'];
  $name = $_POST['name'];
  $title = $_POST['title'];
  $new_tag = $_POST['new_tag'];
  $c_text = <<<KOEY
<?php
  \$content = <<<EOD
$new_tag
EOD;
?>
KOEY;

  $main1 = <<<EOD
<div id="main_r1">
<h2>よく使うタグのサンプルを登録します</h2>
EOD;

  if($c1 == '1'){$err = '<font color="red">！使用可能な文字列は半角英数と「-」「_」です。</font>';
  }else{$err = '使用可能な文字列は半角英数と「-」「_」です。';
  }

  $form = <<<EOD
<form action="AYANASU_control.php?cname=creating_tag" method="post">
<div id="form_box1">
<div id="form_box2">登録名　※必須</div>
<input size="20" type="text" name="name" value="" class="form_01"> {$err}
</div>
<div id="form_box1">
<div id="form_box2"><div class="fi-page-edit"> HTMLタグの内容</div></div>
<textarea name="new_tag">$html_text</textarea>
</div>
<input type="hidden" name="c1" value="1">
<input type="submit" value="Creating" class="s_button">
</form>
</div>
EOD;

  if($_POST['c1'] =="" or $_POST['name'] =="" or !preg_match( '/^[a-zA-Z0-9-_]+$/',$_POST['name'])){
  print $main1;
  print $form;
  }else{

  $gif_an = <<<EOD
<div id="main_r1">
<h2>よく使うタグの保存中です</h2>
<div class="loader"></div>…Creating
<br>
</div>
EOD;
  print("$gif_an");

    $dire = "./content/html_tag"; 
    if(file_exists($dire)){
    $check='ok';
    }else{
    mkdir($dire, 0755);
    chmod($dire, 0755);
    }

  $l_name = $name.'.inc';
  $file = $dire.'/'.$l_name;
  file_put_contents($file,$c_text,LOCK_EX);
  header("Refresh: 2; URL=./AYANASU_control.php?cname=creating_tagr&oprt=2&name=$name");
  }

}
?>
