<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
$admin_start_sql="select * from genaralsettings where set_id=23";
$admin_start_res=mysql_query($admin_start_sql);
$admin_start_row=mysql_fetch_array($admin_start_res);

$admin_end_sql="select * from genaralsettings where set_id=24";
$admin_end_res=mysql_query($admin_end_sql);
$admin_end_row=mysql_fetch_array($admin_end_res);

$userid=$_SESSION[userid];
$producttitle=$_POST[txttitle];
$itemdes=stripslashes( $_POST['htmlcontent'] );
$dur=$_POST[cbodur];
$category_id=$_SESSION[categoryid];
$cat_sql="select * from downcats where category_id=$category_id";
$res=mysql_query($cat_sql);
$row=mysql_fetch_array($res);
$tablename=$row[tablename];
$file_path=$row[file_path];

$_SESSION[producttitle]=$producttitle;
$_SESSION[itemdes]=$itemdes;
?>
<html>
<head>
<title>Sell Your Item:Ship & Tax Detail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<? require 'include/header.php';?>
<table width="758" border="0" cellpadding="0" cellspacing="0" align="center" class="table_border">
  <tr>
    <td valign="top">
	<? 
	$tilte="The Best Marketplace";
	?>
	</td>
  </tr>
  
  <?
  
$flag=$_POST[flag];
$sub_cat=$_POST[cbosubcat];
if($flag==1)
{
  if($tablename)
  {
  $tab_sql="select * from $tablename";
  $tab_res=mysql_query($tab_sql);
  $i =2;
  while ($i < mysql_num_fields($tab_res))
  {
    $tab_col = mysql_fetch_field($tab_res, $i);
    if (!$tab_col) 
	{
        echo "No information available<br/>\n";
    }
	else
	{
	  $dummy="$".$tab_col->name;
      $dummy=$_POST[$tab_col->name];
	    $_SESSION[$tab_col->name]=$_POST[$tab_col->name];		
		if(empty($_SESSION[$tab_col->name]))
        {
         $err_dummy="Please Enter this Information";
	     $err_flag=1;
        }
		else
		{
		 $var_type=$tab_col->type;
		 if($var_type=="int" or $var_type=="tinyint")
		  {
		   if(!is_numeric($_SESSION[$tab_col->name]))
	        {
		    $err_flag=1;
	        }
		  }
		}
	   }
	$i++;
} // while
} //
if(!empty($sub_cat))  // check the user select the subcategory or not 
  $_SESSION[categoryid]=$sub_cat; 
if(empty($producttitle))
{
 $err_title="Please Enter this Information";
	 $err_flag=1;
}

if(strlen($itemdes)==0)
{  
 $err_des="Please Enter this Information";
	 $err_flag=1;
}
else
{
$err_flag=0;
}


$ad_img1=$_FILES['img1']['name'];
if(!empty($ad_img1))
{
  $type1=$_FILES['img1']['type'];
 if($type1=="image/pjpeg" || $type1=="image/gif" || $type1=="image/jpeg" || $type1=="image/bmp")
 {
  srand();
  $rad1=substr(md5(rand(0,1000)),0,5); 
  $img=urlencode($ad_img1);
  $imgname="$username"."$rad1"."$img";
  $uploaddir="../images/$imgname";
  move_uploaded_file($_FILES['img1']['tmp_name'],$uploaddir);
  chmod ("$uploaddir",0755);
  $_SESSION[img1]=$_FILES['img1']['name'];
  $_SESSION[image]=$imgname;
  
 }
}

 function addDay($date,$interval) 
  { 
  if (!isset($date)) 
  $date = date("Y-m-d"); 
  $elts = explode("-", $date); 
  $inter=$interval*24*3600; 
  $dcour=mktime(1,0,0,$elts[1],$elts[2],$elts[0]); 
  $dres=$dcour+$inter; 
  $date1=date("Y-m-d",$dres);
  $sec=date("G:i:s");
  $ret_date="$date1"." "."$sec";
  return $ret_date; 
}

 if($err_flag!=1)
 {
 
 $bid_starting_date=date("y-m-d");
 if($admin_end_row['set_value']=='no')
 {
 $end_date="select * from genaralsettings where set_id=26";
 $end_res=mysql_query($end_date);
 $end_row=mysql_fetch_array($end_res);
 $dur=$end_row[set_value];
 }
  $expire_date = addDay($bid_starting_date,$dur);  
  $sql="insert into auction_details(user_id,producttitle,detailed_descrip,selling_method,duration,bid_starting_date,picture1,expire_date,category_id,status)";
 $sql.="values('1','$producttitle','$itemdes','ads','$dur','$bid_starting_date','$_SESSION[image]','$expire_date','$_SESSION[categoryid]','Active')"; 
  
  $res=mysql_query($sql);
   if($res)
   {
   $productid=mysql_insert_id(); 
   $_SESSION[image]=" ";
   $_SESSION[img1]=" ";
   }
  
  if($tablename)
  {
  $tab_sql="select * from $tablename";
  $tab_res=mysql_query($tab_sql);
  $i =2;
  $up_cat="update $tablename set ";
  $in_sql="insert into $tablename(productid,";
  $in_sql_value="values(' $productid ', ";
while ($i < mysql_num_fields($tab_res))
{
      $tab_col = mysql_fetch_field($tab_res, $i);
   	  $dummy=$tab_col->name;
	  
      $table_sql="select * from $tablename where productid=$productid";
	  $table_res=mysql_query($table_sql);
      $var_value=$table_row[$tab_col->name];
	  if(mysql_num_rows($table_res)==0)
	  {
	    $in_sql.="$tab_col->name ,";
     	$in_sql_value.="'$_SESSION[$dummy]',";
	    // $table_row=mysql_fetch_array($table_res);
	  }
	  else
	  {	   
	  $up_cat.=$tab_col->name.'='."'".$_SESSION[$tab_col->name] ."'".", ";
	  }
	 // $_SESSION[$tab_col->name]=$table_row[$tab_col->name];
	  $i++;
} // while
if(mysql_num_rows($table_res) > 0)
{
$up_cat=rtrim($up_cat,", ");
$up_cat.=" where productid=".$productid;
$in_res=mysql_query($up_cat);
}
else
{
$in_sql=rtrim($in_sql,", "); 
$in_sql_value=rtrim($in_sql_value,", "); 
 $in_sql.=")".$in_sql_value.")";

 $in_res=mysql_query($in_sql);
}
 $up_cat;
} // if($tablename)
  
  
  
  if($in_res)
  $sucess=1;
  else
  $fail=1;
  

  $sucess=1;
  
  
  
  }
}
?>
  <link href="cssfiles/css.css" rel="stylesheet" type="text/css">

<tr><td>
<? 
 if($sucess==1)
{
if($tablename)
  {
  $tab_sql="select * from $tablename";
  $tab_res=mysql_query($tab_sql);
  $i =2;
while ($i < mysql_num_fields($tab_res))
{
    $tab_col = mysql_fetch_field($tab_res, $i);
    if (!$tab_col) 
	{
        echo "";
    }
	else
	{
	  $dummy="$".$tab_col->name;
      $dummy=$_POST[$tab_col->name];
	  $_SESSION[$tab_col->name]="";		
    }
	$i++;
} // while
} // if($tablename)
?>

<tr><td valign="top">
<table cellpadding="5" cellspacing="2" align="center" class="table_topless_border" width="95%">
<tr><td><center><font size="2" color="#FF0000"><b>You have successfully listed your item.</b></font></td></tr>
<!-- <tr><td><b>View your listing:</b>&nbsp;<a href="review.php?productid=<?= $productid ?> "><?= $item_row[producttitle]; ?></a></td></tr> -->

 
</table>
</td></tr>
<tr><td><? require 'include/footer.php'; ?></td></tr>
</table>
<?  
$sucess=0;
exit();
}
?>
<? 
 if($fail==1)
{
?>
<tr><td ><br>
<br>
<br>
<table align="center" class="table_border1_with_bg" cellpadding="15">
<tr class="tdhead">
<td align="center"><font size="2"><b>Oop's!</b></font> </td></tr>
<tr><td><font size="2"><b>Problems In listing your item.Please Try Again Later!</b></font>
 </td></tr>
<!-- <tr><td><b>View your listing:</b>&nbsp;<a href="review.php?productid=<?= $productid ?> "><?= $item_row[producttitle]; ?></a></td></tr> -->
</table><br>
<br>
<br></td></tr>
<!-- <tr align="center"><td align="center"><a href="pay.php">Pay Now</a></td></tr> -->
</table>
</td></tr>
<tr><td><? require 'include/footer.php'; ?></td></tr>
</table>
<?  
exit();
}
?>
 <tr><td>
<table width="100%" cellpadding="5" cellspacing="0" align="center" border="0">
<tr height=40>
        <td class="tr_border"><font size="2"><b> Sell Your Item:Enter Your Item 
          Deatils</b></font> </td>
      </tr>
<? if($err_flag==1)
{ 
?>
<tr>
<img src="images/xclabid.gif">
<td><font size=2 color="red">The following must be corrected before continuing:</font></td>
</tr>
<? if($tablename)
		{
		$tab_sql="select * from $tablename";
        $tab_res=mysql_query($tab_sql);
        $i =2; 
 while ($i < mysql_num_fields($tab_res))
{
    $tab_col = mysql_fetch_field($tab_res, $i);
	$dummy=$tab_col->name;
if(empty($_SESSION[$tab_col->name]))
        {
     ?>
	  <tr><td><a href="post_ad.php#<?= $tab_col->name ?>"><?= $tab_col->name ?></a>-Please Enter this Information </td></tr>
	 <?
	    }
		else
		{
		echo $var_type=$tab_col->type;
		if($var_type=="int" or $var_type=="tinyint")
		{
		if(!is_numeric($_SESSION[$tab_col->name]))
	    {
	    ?>
		 <tr><td><a href="post_ad.php#<?= $tab_col->name ?>"><?= $tab_col->name ?></a>-Please Enter this Information </td></tr>
		<?
		}
		}
		}
	$i++;
}
}  ?>




<? if(!empty($err_title))
 {
 ?>
<tr>
<td><a href="post_ad.php#txttitle">Item Title</a> - <?= $err_title; ?></td></tr>
<? 
}
?>
<? if(!empty($err_des))
 {
 ?>
<tr><td><a href="post_ad.php#areades">Item Description</a> - <?= $err_des; ?></td></tr>
<? 
}
?>

<?
}
?>
</td></tr>
<form name="form1" action="post_ad.php" method="post" enctype="multipart/form-data">



<?
echo "test"."$_SESSION[categoryid]";
  if($_SESSION[categoryid])
 {
  $sub_sql="select * from site_categories where category_head_id=$_SESSION[categoryid]";
  $sub_res=mysql_query($sub_sql);
  $sub_tot=mysql_num_rows($sub_res);
 }
if($sub_tot!=0)
{ 
?>
<tr><td><font size=2><b>Sub Category</b></font></td></tr>
<tr><td><select name=cbosubcat><option value="0">Select</option>
<? while($sub_row=mysql_fetch_array($sub_res))
 {
  if(trim($sub_row['category_id'])==trim($sub_cat))
  {
   ?>
  <option value="<?= $sub_row['category_id'] ?>" selected><?= $sub_row['category_name']?></option>
  <? 
  }
  else
    {
	?>
  <option value="<?= $sub_row['category_id'] ?>"><?= $sub_row['category_name']?></option>
  <?
  }
  }
  ?>
  </select>
 </td></tr>
 <? 
 }
 else
 { 
  if($file_path)
  require "$file_path";
 }
 ?>
<tr><td>
<? if(!empty($err_title))
 {?>
 <img src="images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_title ?></font>
 <br>
 <b><font size=2 color=red>Item title</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2 >Item title</font></b>
   <? }
   ?>
 </td></tr>
 
 
 
 
 <tr><td width=250><input type="text" class="bluetext"name="txttitle" class="txtbig" value=<?= $producttitle; ?>>
 </td></tr>
 <tr><td>
<? if(!empty($err_des))
 {
 ?>
 <img src="images/xclabids.gif">&nbsp;
 <font size=2 color=red><?= $err_des; ?></font>
 <br>
 <b><font size=2 color=red>Item Description</font></b>
 <?
  }
  else
  {
   ?>
   <b><font size=2 >Item Description</font></b>
   <? }
   ?>
 </td></tr>

 <tr><td width="100%">
 <?php
include_once("../HTMLEditor/fckeditor.php") ;
?>
<?php
$oFCKeditor = new FCKeditor('htmlcontent') ;
$oFCKeditor->BasePath = '/HTMLEditor/' ;
$oFCKeditor->Value = $itemdes;
$oFCKeditor->Create() ;
?>
 <br>
<font size=2 class="hint_font">Describe your items features, benefits, 
and condition. Be sure to include in your description: Condition (new, used, etc.)</font></td>
</tr>
 <? if($admin_end_row['set_value']=='yes')
 {
 ?>
 <td>
<? if(!empty($err_dur))
 { 
 if($mode!="edit")
 { 
 ?>
 <img src="images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_dur; ?></font>

 <br>
 <b><font size=2 color=red>Duration</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2 >Duration</font></b>
   <? 
   }
   } //  if($mode=='edit')
   } //  if($admin_end_row=='yes')
   ?>
   
 </td>
</tr>



<tr>
<td width=250>
<?  if($admin_end_row['set_value']=='yes')
{
if($mode!="edit")
{
?>
<select name="cbodur">
<option value="0">Select</option>
<? if($dur==30)
{
?>
<option value=30 selected>30 Days</option>
<?
}
else
{
 ?>
 <option value=30>30 Days</option>
 <?
 }
  ?>
  <? if($dur==60)
{
?>
<option value=60 selected>60 Days</option>
<?
}
else
{
 ?>
 <option value=60>60 Days</option>
 <?
 }
  ?>
  <? if($dur==90)
{
?>
<option value=90 selected>90 Days</option>
<?
}
else
{
 ?>
 <option value=90>90 Days</option>
 <?
 }
  ?>
  <? if($dur==120)
{
?>
<option value=120 selected>120 Days</option>
<?
}
else
{
 ?>
 <option value=120>120 Days</option>
 <?
 }
  ?>
</select>
</td>
 <?
 } //if($mode=="edit")
 
 }  // if($admin_end_row=='yes')
 ?></tr>


<tr><td >
<? if(!empty($err_img1))
 {?>
 <img src="images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_img1; ?></font>
 <br>
 <b><font size=2 color=red>Image</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2 >Image</font></b>
   <? 
   }
   ?></td></tr><tr><td>
    <input type="file" name="img1" value="<?= $img1; ?>">
	<? if(!empty($_SESSION[img1]))
	{
	?>
	<img src="images/gallery.png" width=10 height=10>
	<?
	}
	?></td></tr>
	<?
	     $admin_query="select * from genaralsettings where set_id=39";
         $admin_table=mysql_query($admin_query);
         $admin_row=mysql_fetch_array($admin_table);
         $ad_fee=$admin_row['set_value'];
        
		 
         $query="select * from member_details where user_id ='$userid'";
         $tab=mysql_query($query);
         if($row=mysql_fetch_array($tab))
         {
           $mem=$row['member_account'];
          		 }  
   ?>		   
<input type="hidden" name=flag value=1>
<tr align="center"><td><br><input type="submit" class="button"   name=detsub value="Save" class="buttonbig"></td></tr>
</form>
<tr align="center"><td><? require 'include/footer.php'?></td></tr>
</table>
