<?php session_start();?>
<?php
include ('dbf.php');
if($_POST[ins])
{
   $valu=split(",",$_POST[ins]);
   $row=mysql_query("select * from `matn` where id='{$valu[0]}'");
   $cd=mysql_num_rows($row);
   if($cd=='0')
	$suq=mysql_query("insert into  matn (id,name,paje,user,city)
	VALUES ('{$valu[0]}','{$valu[1]}','{$valu[2]}','{$_SESSION[user]}','{$_SESSION[city]}')");
   if($suq)
      echo 'success';
   else
	 echo'<span class="blacktext"> متن اين كتاب قبلا ثبت شده است </span>';
}
if (isset($_POST['del']))
 {
  mysql_query("delete from matn where (ip={$_POST['id']})");
}
if (isset($_POST['edit'])) {
   $valu=split(",",$_POST['edit']);
	mysql_query("update matn set name='{$valu[0]}'
	where  (ip='{$_POST['id']}')");
	$_SESSION[selpage]="textpage.php";
    include ('login.php');
}
///////upload matn ketab
if(isset($_POST[upload]))
{
    if(is_uploaded_file($_FILES['up_book']['tmp_name'])){
	    $fmat=$_FILES['up_book']['name'];
    	$address=$fmat;
    	$idb="";
    	if(($_POST['booko']!="") && ($_POST['bookid']==""))
    		$idb=$_POST['booko'];
    	elseif(($_POST['booko']=="") && ($_POST['bookid']!=""))
    		$idb=$_POST['bookid'];
    	elseif(($_POST['booko']!="") && ($_POST['bookid']!=""))
    		$idb=$_POST['bookid'];
 	$p=mysql_query("select * from `ketab` where id='{$idb}'");
	$pf=mysql_fetch_assoc($p);
	$o=mysql_query("select * from matn where (up_book='{$address}' or up_book <>'') and id='{$pf[id]}' ");
	$of=mysql_fetch_assoc($o);
	if(($of=="") && ($idb!="")){
	copy($_FILES['up_book']['tmp_name'],"books/$fmat");
	mysql_query("insert into `matn`(id,up_book,user,city) values('{$pf[id]}','{$address}','{$_SESSION[user]}','{$pf[city]}') ");
	}
	}
  $_SESSION[m]='1';
  $_SESSION[selpage]="textpage.php";
  include ('login.php');
  echo"<script>window.location='msg.php?msgs=sabt'</script>";

}
?>