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

function form()
{

  $c1 = $_POST['c1'];
  $new_text = $_POST['new_text'];
  $name = $_POST['name'];

  $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_link" 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_text">$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/linkGroup"; 
    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,$new_text,LOCK_EX);
  header("Refresh: 2; URL=AYANASU_control.php?cname=creating_linkr&name=$name");
  }

}
?>
