<?php session_start();?>
<?php
include ('dbf.php');
if(isset($_POST['ffg']))
{
  if($_POST['id']!='')
  {
   $row=mysql_query("select * from `ketab` where id='{$_POST['id']}'");
   $cd=mysql_num_rows($row);
   if($cd=='0')
   {
    if(is_uploaded_file($_FILES['pic']['tmp_name']))
     {
	    $test=copy($_FILES['pic']['tmp_name'],"books/".$_FILES['pic']['name']);
	    $fileName = $_FILES['pic']['name'];
	 }
	mysql_query("insert into  ketab (id,name,writer,motarjem,topic,nasher,dio_ip,pic,price,price1,tou,m1,m2,kh_k,user,city)
	VALUES ('{$_POST['id']}','{$_POST['name']}','{$_POST['writer']}','{$_POST['motarjem']}'
	,'{$_POST['topic']}','{$_POST['nasher']}','{$_POST['dio']}','{$fileName}','{$_POST['price']}','{$_POST['price1']}','{$_POST['tou']}','{$_POST['m1']}','{$_POST['m2']}','{$_POST['kh_k']}','{$_SESSION['user']}','{$_SESSION['city']}')");
    $_SESSION[m]='1';
    $_SESSION[selpage]="bookpage1.php";
	echo"<script>window.location='msg.php?msgs=sabt'</script>";

   }
   else
   {
      $_SESSION[m]='1';
      $_SESSION[selpage]="bookpage1.php";
      echo"<script>window.location='msg.php?msgs=nsabt'</script>";
   }
  }

  //



}
if (isset($_POST['del'])&& ($_SESSION[tbl]=='ketab') )
{
	mysql_query("delete from ketab where ip={$_POST['id']}");
}
if (isset($_POST['esla']))
{

    if(is_uploaded_file($_FILES['pic']['tmp_name']))
     {
	    $test=copy($_FILES['pic']['tmp_name'],"books/".$_FILES['pic']['name']);
	    $fileName = $_FILES['pic']['name'];
	 }
	 else
	   $fileName = $_POST['pic1'];
	mysql_query("update `ketab` set name='{$_POST['name']}',writer='{$_POST['writer']}'
	,motarjem='{$_POST['motarjem']}',topic='{$_POST['topic']}',tou='{$_POST['tou']}'
	,nasher='{$_POST['nasher']}',dio_ip='{$_POST['dio_ip']}',pic='{$fileName}'
	,price='{$_POST['price']}',price1='{$_POST['price1']}',m1='{$_POST['m1']}'
	,m2='{$_POST['m2']}',kh_k='{$_POST[kh_k]}',city='{$_SESSION['city']}' where ip={$_POST['ip']}");
    echo"<script>window.location='msg.php?msgs=edit'</script>";
	$_SESSION[selpage]="bookpage.php";
    include ('login.php');
}
if($_POST[ins])
{
   $valu=split(",",$_POST[ins]);
   include_once('jdf.php');
   $date=jdate('Y/m/d');
   $suq=mysql_query("insert into `darkhast`(date,name_b,name_ozv,id_ozv,writer,s_nashr,nasher,city) values('{$date}','{$valu[0]}','{$valu[1]}','{$_SESSION[id]}','{$valu[2]}','{$valu[3]}','{$valu[4]}','{$_SESSION[city]}') ");
   if($suq)
      echo 'success';
}
if($_GET[val]=='id')
{
   $row=mysql_query("select * from `ketab` where (id='{$_GET[id]}')");
   $cd=mysql_num_rows($row);
   if($cd=='1')
   {
    echo '<span class="blacktext">شماره ثبت کتاب تکراری است</span>';
   }

}
if ((isset($_POST['del'])) && ($_SESSION[tbl]=='darkhast') )
{
  mysql_query("delete from `darkhast` where id={$_POST['id']}");

}


?>