<?php session_start();?>
<?php
include ('dbf.php');
if(isset($_POST['ffg']) )
{
  if(($_POST['id']!=''))
  {
   $row=mysql_query("select * from `ozv` where (pass='{$_POST['pass']}') and (lname='{$_POST['lname']}')");
   $cd=mysql_num_rows($row);

   $row1=mysql_query("select * from `ozv` where id='{$_POST['id']}'");
   $cd1=mysql_num_rows($row1);

   $q2=mysql_query("select * from login where user ='".$_POST[lname]."' and pass ='".$_POST[pass]."'");
   $cd2=mysql_num_rows($q2);

//echo $_POST['bearthdate'].'wwwwwwwwصصصصصصصصصصصwww<br/>';

   if(($cd=='0') && ($cd1=='0') && ($cd2=='0'))
   {
	$l=mysql_query("select * from `expire`");
	$lf=mysql_fetch_assoc($l);
	$ar=explode('/',$_POST['active1']);
	$aq=$ar[0];
	settype($aq,int);
	$date_e=$lf['exp']+$aq.'/'.$ar[1].'/'.$ar[2];
	if(is_uploaded_file($_FILES['pic']['tmp_name']))
     {
        move_uploaded_file($_FILES['pic']['tmp_name'], "uplowd/".$_FILES['pic']['name']);
        $fileName = $_FILES['pic']['name'];
	    //$test=copy($_FILES['pic']['tmp_name'],"uplowd/".$_FILES['pic']['name']);
	    //$fileName = $_FILES['pic']['name'];
	 }
   mysql_query("insert into  ozv (id,fname,lname,faname,jen,bearthdate,sh_t,code_melli,onvan,pic,date,date_e,address,pass,user,city)
	VALUES ('{$_POST['id']}','{$_POST['fname']}','{$_POST['lname']}','{$_POST['faname']}','{$_POST['jen']}'
	,'{$_POST['bearthdate']}','{$_POST['sh_t']}','{$_POST['code_melli']}','{$_POST['onvan']}','{$fileName}'
	,'{$_POST['active1']}','{$date_e}','{$_POST['address']}','{$_POST['pass']}','{$_SESSION['user']}','{$_SESSION['city']}')");
   $_SESSION[m]='1';
   $_SESSION[selpage]="memberpage1.php";
   echo"<script>window.location='msg.php?msgs=sabt'</script>";
 }
  else
   {
      $_SESSION[m]='1';
      $_SESSION[selpage]="memberpage1.php";
      echo"<script>window.location='msg.php?msgs=nsabt'</script>";
   }
 }
}
elseif (isset($_POST['esla']))
{

		$h1=mysql_query("select * from `expire`");
		$fh1=mysql_fetch_assoc($h1);
		$a=$_POST['date'];
		$ar=explode('/',$a);
		settype($ar[0],int);
		$ar[0]+=$fh1['exp'];
		$date_en=$ar[0].'/'.$ar[1].'/'.$ar[2];
   $row=mysql_query("select * from `ozv` where (pass='{$_POST['pass']}') and (lname='{$_POST['lname']}')");
   $cd=mysql_num_rows($row);
   $row1=mysql_query("select * from `ozv` where id='{$_POST[id]}'")or die(mysql_error());
   $cd1=mysql_num_rows($row1);
   $q2=mysql_query("select * from login where user ='".$_POST[lname]."' and pass ='".$_POST[pass]."'");
   $cd2=mysql_num_rows($q2);
   //echo $_POST[id].'bn'.$cd1;


if(($cd<='1') && ($cd1<='1') && ($cd2=='0') )
   {
	if(is_uploaded_file($_FILES['pic']['tmp_name']))
     {
	    $test=copy($_FILES['pic']['tmp_name'],"uplowd/".$_FILES['pic']['name']);
	    $fileName = $_FILES['pic']['name'];
	 }
	 else
	   $fileName = $_POST['pic1'];
		mysql_query("update ozv set fname='{$_POST['fname']}',lname='{$_POST['lname']}',faname='{$_POST['faname']}'
	,jen='{$_POST['jen']}',bearthdate='{$_POST['bearthdate']}',sh_t='{$_POST['sh_t']}',code_melli='{$_POST['code_melli']}'
	,onvan='{$_POST['onvan']}',date='{$_POST['date']}',date_e='{$date_en}',address='{$_POST['address']}',pass='{$_POST['pass']}',city='{$_SESSION['city']}',user='{$_SESSION['user']}',pic='{$fileName}'
	,id='{$_POST['id']}' where ip={$_POST['ip']}");
   echo"<script>window.location='msg.php?msgs=edit'</script>";
    $_SESSION[selpage]="memberpage.php";
    include ('login.php');
    }
  else
   {
      $_SESSION[selpage]="memberpage.php";
      echo"<script>window.location='msg.php?msgs=nedit'</script>";
   }



}
elseif (isset($_POST['del']))
{
   mysql_query("delete from ozv where ip={$_POST['id']}");
}
elseif(isset($_POST[ins]))
{

   $valu=split(",",$_POST[ins]);
   	mysql_query("delete from `expire` where city='{$_SESSION['city']}' ");
	$suq=mysql_query("insert into `expire`(exp,user,city) values('{$valu[0]}','{$_SESSION['user']}','{$_SESSION['city']}')");
	if($suq)
      echo 'success';

}
elseif(isset($_GET[p]))
{
   include_once('jdf.php');
   $d=jdate('Y/m/d');
   $l=mysql_query("select * from `expire`");
	$lf=mysql_fetch_assoc($l);
	$bb=explode('/',$d);
	$aq=$bb[0];
	settype($aq,int);
	$date_tam=$lf['exp']+$aq.'/'.$bb[1].'/'.$bb[2];
	mysql_query("update `ozv` set date_e='{$date_tam}' where ip='{$_GET[p]}'");
	$_SESSION[selpage]="expire.php";
    include_once ('login.php');

}
elseif($_GET[val]=='id')
{
   $row=mysql_query("select * from `ozv` where (id='{$_GET[id]}')");
   $cd=mysql_num_rows($row);
   if($cd>='1')
   {
    echo '<span class="blacktext">شماره عضويت تكراري است</span>';
   }

}
elseif($_GET[val]=='pass')
{

   $row=mysql_query("select * from `ozv` where (pass='{$_GET[id]}')");
   $cd=mysql_num_rows($row);
   if($cd>='1')
   {
    echo '<span class="blacktext">رمز عبور تكراري است</span>';
   }

}
?>