Просмотр файла top/inc/add.php

Размер файла: 5.37Kb
<?php
 $sid = 0;
 $fod=getcwd();
 $fold=$fod."/inc/members";
 chdir($fold);
 $fo=opendir($fold);
 while ($read=readdir($fo))
 { 
   if(($read != ".") && ($read != "..")) 
   { 
	 $note[]=$read; 
	 $fnt = file("$read");
	 $fnt[0];
	 $notes[] = $fnt[0];
	 $record = explode("¤", trim($fnt[0]));
	 if ($record[4]>$sid) $sid = $record[4];
	 rsort($note);
   } 
 }
 chdir("../../");
 closedir($fo);
 $sid++;
 $count_notes = count($notes);
 $record = explode("¤", trim($notes[$count_notes-1]));
 $error='do_form';
 if (isset($_POST['name']))  {
 $name = htmlspecialchars(substr(trim($_POST['name']), 0, 45)); 
 if (isset($_POST['email'])) $email = htmlspecialchars(substr(trim($_POST['email']), 0, 80));
 if (isset($_POST['site_url'])) $site_url = htmlspecialchars(substr(trim($_POST['site_url']), 0, 80));
 if (isset($_POST['pwd'])) $pwd = htmlspecialchars(substr(trim($_POST['pwd']), 0, 20));
 if (isset($_POST['banner'])) $banner = htmlspecialchars(substr(trim($_POST['banner']), 0, 100)); else $banner="";
 if (isset($_POST['descr'])) $descr = htmlspecialchars(substr(trim($_POST['descr']), 0, 255)); else $descr = "";
 if (moderate) $site_url = "*".$site_url;
 $site_is = false;
 for ($j=0;$j<$count_notes;$j++) {
     $record = explode("¤", trim($notes[$j]));
	 if (strpos(trim($record[0]),$site_url)>-1) {
		 $site_is=true;
		 $site_id=$record[4];
	 }
 }
 if (!$site_is) {
	 save_note($sid, $site_url."¤".$banner."¤".$name."¤".$email."¤".$sid."¤".$descr."¤".$pwd);
	 $IO_data = "./inc/data/io_".$sid.".dat";
     $io = "0¤0";
	 $fopt = fopen ($IO_data, "w"); 
	 chmod($IO_data, 0733);
	 if ($fopt) $result = fwrite($fopt, $io);
     fclose($fopt);
 }
   else { ?>
   <br><br><center><span style="FONT-SIZE: 18px;COLOR: #FFF000; FONT-FAMILY: 'Courier new',Verdana;"><b>Сайт <?php echo $site_url ?><br>уже зарегистрирован<br>ID сайта : <font color=white><?php echo $site_id; ?></span><br><br><form action="index.php"><input type="hidden" name="sid" value="<?php echo $site_id; ?>"><input type="hidden" name="action" value="getcode"><input type="submit" class=sb2 value="Получить код"></form><br><br><br>  
<?php  }
if (!$site_is) include "./inc/code.php";
}
else print_form();
function print_form() {?>
<script language="javascript">
 function checkform (f1) {
  if (f1.email.value=="") {alert("Введите ваш email !");return false;} 
   else if (f1.email.value.search('@')<0) {alert("Введите корректный email !");return false;} 
    else if ((f1.site_url.value=="") || (f1.site_url.value=="http://")) {alert("URL сайта не задано !");return false;}
     else if (f1.pwd.value=="") {alert("Введите пароль для редактирования информации");return false;}
      else if (f1.name.value=="") {alert("Название сайта не задано !");return false;}
        else {
		   if (f1.banner.value=="http://") f1.banner.value=''; 
           return true;
		}
}
</script>
<p>&nbsp;</p><p>&nbsp;</p>
<center>
<h4><b>Пожалуйста заполните следующую форму:</b></h4>
<FORM METHOD="POST" name="f1" onsubmit="return checkform(this);">
<table align=center cellspacing =0 border=0>
 <tr>
  <TD>
   <DIV class=blue>
    <div class=headblue>
	 <table cellspacing =0 border=0 background="<?php echo top_bg1; ?>" bgcolor="<?php echo top_bg; ?>">
      <TR>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4><b>&nbsp;Ваш Email </TD>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4>&nbsp;<font color=red>*<INPUT class=sb TYPE="text" style="width:260px;"  NAME="email" maxlength=80 value="" onfocus="this.value='';">&nbsp;</TD>
	  </TR>
	  <TR>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4><b>&nbsp;URL сайта</TD>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4>&nbsp;<font color=red>*<INPUT class=sb TYPE="text" style="width:260px;"  NAME="site_url" maxlength=80 value="http://">&nbsp;</TD>
	  </TR>
	  <TR>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4><b>&nbsp;URL баннера</TD>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4>&nbsp;&nbsp;&nbsp;<INPUT class=sb TYPE="text" style="width:260px;"  NAME="banner" maxlength=100 value="http://">&nbsp;</TD>
	  </TR>
	  <TR>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4><b>&nbsp;Пароль</TD>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4>&nbsp;<font color=red>*<INPUT class=sb TYPE="password" style="width:260px;"  NAME="pwd" maxlength=20 value="">&nbsp;</TD>
	  </TR>
	  <TR>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4><b>&nbsp;Название сайта</TD>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4>&nbsp;<font color=red>*<INPUT class=sb TYPE="text" style="width:260px;"  NAME="name" maxlength=45 value="">&nbsp;</TD>
	  </TR>
	  <TR>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4><b>&nbsp;Описание сайта</TD>
	   <TD height=22 background="<?php echo top_bg2; ?>" class=d4>&nbsp;&nbsp;&nbsp;<input class=sb style="width:260px;"  NAME="descr" maxlength=256 value=""></input>&nbsp;</TD>
	  </TR>
    </div>
   </div>
  </td>
 </tr>
</TABLE>
<p align=center><input class=sb2 type=submit value="Зарегистрироваться в рейтинге" style="cursor:hand;Width:260px;height:22px"></p></form></td>
 </tr>
</table>
<?php 
 }
function save_note($n, $data_str) 
{
  $fopt = fopen("./inc/members/sid".$n.".db", 'w');
  if ($fopt) 
  { 
	  $result = fwrite($fopt, $data_str); 
	  fclose($fopt);	
  }
} 
?>
</HTML>