<?

     $user_id=$_SESSION[userid];

	 $cansave=$_POST[cansave];

    $myquery="select * from shopfronts where user_id='$user_id'";

	$mytab=mysql_query($myquery);



	if($cansave!=1)

	{

	$row=mysql_fetch_array($mytab);

	$shop_name=$row[shop_name];

	$itemdes=$row[description];

    $aboutpage_type=$row[status];

	$logo1=$row[logo];

	}

	if($cansave==1)

	{

 $shop_name=$_POST[shop_name];

 $itemdes=stripslashes( $_POST[htmlcontent] );

if(empty($itemdes))

$itemdes=$_SESSION[itemdes];

else

$_SESSION[itemdes]=$itemdes;



  $aboutpage_type=$_POST[aboutpage_type];

  if($_FILES['logo']['name'])

  $logo1=$_FILES['logo']['name'];

  else

  {

  $row=mysql_fetch_array($mytab);

  $logo1=$row[logo];

  }	   

                     $uploaddir= getcwd(); 

 					 $updir=explode('/',$uploaddir);

					 $count=count($updir)-1;

					 for($i=0;$i<$count;$i++)

					 {

         			 $up_dir.=$updir[$i]."/";

					 }

$uploaddir=rtrim($up_dir,"/");

if(!empty($logo1))

{

 $type1=$_FILES['logo']['type'];

 if($type1=="image/pjpeg" || $type1=="image/gif" || $type1=="image/jpeg" || $type1=="image/bmp")

 {

  

  $logo1=urlencode($logo1);

  $logo1="$user_id"."$logo1";

  $uploaddir="shopuploads/$logo1";

  move_uploaded_file($_FILES['logo']['tmp_name'],$uploaddir);

  chmod ("$uploaddir",0755); 

  

 }

 }

     $count=mysql_num_rows($mytab);

   	  if($count==0)

	  {

      $query="insert into shopfronts (user_id,logo,description,shop_name,status)values('$user_id','$logo1','$itemdes','$shop_name','$aboutpage_type')";

      mysql_query($query);

      }

	 else

	 {

	 if(empty($logo1))

	 $query="update shopfronts set description ='$itemdes',shop_name='$shop_name',status='$aboutpage_type' where user_id='$user_id'";

	 else

	 $query="update shopfronts set logo='$logo1', description ='$itemdes',shop_name='$shop_name',status='$aboutpage_type' where user_id='$user_id'";

	 mysql_query($query);

  	}

	} //  if($cansave==1)

?>