<?
ob_start();
session_start();
 include("../include/db.inc.php");
 include("../include/pager.php"); 
 include("../include/bit_functions.inc.php");
   $db1=new db;
   $db1->open();
    mysql_query("SET NAMES 'utf8'");
   
   
// for new addition
		if(isset($_POST['Addnew_btn'])){
			$sql_qry=mysql_query("select * from winner_interviews where uid='".$_POST['uid']."' and pid='".$_POST['product_id']."'");
				if(mysql_num_rows($sql_qry)){
					$action=base64_encode("\t'".get_fieldval(id,uname,user,$_POST['uid'])."' user already exists!");
					header("location:winner_interviews.php?action=".$action);
				}
			else{
			
			$winner=mysql_query("insert into winner_interviews set uid='".$_POST['uid']."',pid='".$_POST['product_id']."',value='".$_POST['value']."',ques1='".$_POST['ques1']."',ques2='".$_POST['ques2']."',
			ques3='".$_POST['ques3']."',ans1='".$_POST['ans1']."',ans2='".$_POST['ans2']."',ans3='".$_POST['ans3']."',description='".$_POST['description']."', add_time=now()");
			$action=base64_encode('"'.get_fieldval(id,uname,user,$_POST['uid']).'" user\'s interview has been added');
			header("location:winner_interviews.php?action=".$action);
			
			}
			
		}		

// for edit  
		if(isset($_POST['edit_btn']))
		{	
				
			  $sql_qry1="update winner_interviews set uid='".$_POST['uid']."',pid='".$_POST['product_id']."',value='".$_POST['value']."',description='".$_POST['description']."',ques1='".$_POST['ques1']."',
			  ques2='".$_POST['ques2']."',ques3='".$_POST['ques3']."',ans1='".$_POST['ans1']."',ans2='".$_POST['ans2']."',ans3='".$_POST['ans3']."' where id=".$_GET['edit'];
			  
			  mysql_query($sql_qry1);
			  $action=base64_encode('"'.get_fieldval(id,uname,user,$_POST['uid']).'" user has been edited');
		      header("location:winner_interviews.php?id=".$_GET['id']."&action=".$action);
		}

		
	if($_GET['del']){
		mysql_query("delete from winner_interviews where id=".$_GET['del']);
		header("location:winner_interviews.php");
		
	}
	$sql_qry=mysql_query("select * from winner_interviews  ");
	$tot_found=mysql_num_rows($sql_qry);
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Auctions | Admin Controls</title>
<link href="index.css" rel="stylesheet" type="text/css" />

<script language="javascript">

function populate(catid, form1)
{	
	for(x=form1['product_id'].length; x>=0; x=x-1)
	{
		form1['product_id'][x]=null;
	} 
	
	
		<?php 
		$sql2=mysql_query("SELECT s.uid FROM t123go_product p inner join t123go_product_sold s on p.pid=s.pid");
		while($res1=mysql_fetch_object($sql2))
		{
			$c_id = $res1->uid;
			
		?>
		
		if(catid == '<?php echo $c_id; ?>')
			{
						
				<?php 
					$subsql=mysql_query("SELECT p.pid,pname FROM t123go_product p inner join t123go_product_sold s on p.pid=s.pid WHERE s.uid='$c_id'");
				?>
				form1['product_id'][form1['product_id'].length]=new Option("-- Select --", "0", "", false);
				<?php
				while($subres=mysql_fetch_object($subsql))
					{ 
						$s_id = $subres->pid;
						$s_text = $subres->pname;
				?>
						form1['product_id'][form1['product_id'].length]=new Option("<? echo $s_text; ?>", "<?php echo $s_id; ?>", "", false);
						
			<?php	} ?>
			}
<?php	} ?>

}


function valid()
{
	if(document.editfrm.uid.value==0)
    {
	alert('Please select the user!');
	return false;
    }
	
	if(document.editfrm.product_id.value==0)
    {
	alert('Please select the product!');
	return false;
    }


}


</script>

</head>
<body bgcolor="#ffffff">
<div class="admin_wrapper">
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px">
<div class="maximum">
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse; border-color:#ffffff">
  <tr>
    <td><? //include("header.php");?></td>
  </tr>
</table>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->

<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<div style="margin-top:5px">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%" style="border-collapse:collapse; border-color:#404193">
  <tr height="417">
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->   
    
	<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->    
<td width="81%" bgcolor="#FFFFFF" valign="top">
		
<table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
  <tr> 
    <td width="15" valign="top">&nbsp;</td>
          <td valign="top"><br> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
        <tr> 
          <td width="33" valign="top"><img src="img/03.gif" width="33" height="23"></td>
                <td background="img/bg01.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="42%"><strong>WINNER INTERVIEWS LIST</strong> </td>
                      <td width="32%">&nbsp;</td>
                      <td width="26%" align="right">
					  <a href="winner_interviews.php?new=1" class="link5">Add New</a>
					  </td>
                    </tr>
                  </table></td>
          <td width="35"><img src="img/04.gif" width="35" height="23"></td>
        </tr>
      </table>
      <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
        <tr> 
          <td width="22" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13"></td>
          <td valign="top" align="center">		  		  		             
	 <? if($_GET['error_action']){ print "<font color='red'><strong>".base64_decode($_GET['error_action'])."</strong></font>";}else if($_GET['action']){ print "<strong>".base64_decode($_GET['action'])."</strong>";}
		
		if($tot_found){
	 ?>
<br>

                    <table width="90%" border="1" cellspacing="1" cellpadding="1" style="border-collapse:collapse; border-color:#FED267">
                      <tr bgcolor="#FED267"> 
                        <td width="139" align="center" ><strong><font color="#FFFFFF">User Image</font></strong> 
                        </td>
                        <td width="126"  ><strong><font color="#FFFFFF">User Name</font></strong></td>
                        <td width="276" ><strong><font color="#FFFFFF">Product Name</font></strong></td>
                         <td width="78" align="center"><strong><font color="#FFFFFF">Value</font></strong></td>
                        <td width="57" >&nbsp;</td>
                        <td width="56" height="20" align="center"><strong><font color="#FFFFFF">Delete</font></strong></td>
                      </tr>
                      <? $i=0;
				while($myrow=mysql_fetch_array($sql_qry)){
					if($i%2==0){$col='#E6E4E3';}else{$col='#FFFFFF';}
			?>
                      <tr  onMouseOver="this.style.backgroundColor='#FFECBF'" onMouseOut="this.style.backgroundColor='#ffffff'"> 
                        <td align="center" valign="top">
                          <?=get_user_image_admin(get_fieldval(id,image,user,$myrow['uid']),50,50)?>
                        </td>
                        <td > <? echo get_fieldval(id,uname,user,$myrow['uid']);?> 
                        </td>
                        <td > 
                          <? echo get_fieldval(pid,pname,t123go_product,$myrow['pid']);?> 
                        </td>
                        <td align="center"> 
                          <?=$myrow['value']?>
                        </td>
                        <td align="center" ><a href="winner_interviews.php?edit=<?=$myrow['id']?>" class="link5" title="Click To Edit"> Edit</a></td>
                        <td align="center">                           
                          <table>
                            <tr>
                              <td></td>
                              <td><a href="winner_interviews.php?del=<?=$myrow['id']?>"><img src="../images/category/imgdelete.gif" border="0"></a></td>
                            </tr>
                          </table> </td>
                      </tr>
                      <? $i++;}?>
                    </table>
                      
                   

<? }else{ echo '<br><br><br><br><strong>No record found</strong><br><br><br><br>';} ?>
</td>
          <td width="19" valign="top" background="img/tbl-right04.gif"><img src="img/tbl-right04.gif" width="19" height="9"></td>
        </tr>
      </table>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33"><img src="img/tbl-bot01.gif" width="33" height="12"></td>
                <td  width="709" align="right" background="img/tbl-bg.gif"></td>
                <td width="33"><img src="img/tbl-right05.gif" width="35" height="12"></td>
              </tr>
            </table>
    </td>
    <td width="15" valign="top">&nbsp;</td>
  </tr>
</table>
<br>
      <? 
	if($_GET['action']){ echo '<div align="center"><strong>'.base64_decode($_GET['action']).'</strong></div>';}
	
	
	
	if($_GET['edit']){
		$sql_qry=mysql_query("select * from winner_interviews where id=".$_GET['edit']);
		$myrec=mysql_fetch_array($sql_qry);		
		$id_found=mysql_num_rows($sql_qry);
	}
	
	
	if($_GET['new']==1 || $_GET['edit']!='')
	{
?>
      <TABLE WIDTH="74%" BORDER=0 CELLPADDING=0 CELLSPACING=0 align="center">
        <TR> 
          <TD> <img border='0' src="border_img/circle_01.gif" WIDTH=36 HEIGHT=35 ALT=""></TD>
          <TD height="34" valign="top" > <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="5%" align="center"><strong><font color="#003366"><? if($_GET['edit'])echo "Edit"; else echo "Add";?></font></strong></td>
                <td width="95%" background="border_img/circle_02.gif">&nbsp;</td>
              </tr>
            </table></TD>
          <TD> <img border='0' src="border_img/circle_03.gif" WIDTH=35 HEIGHT=35 ALT=""></TD>
        </TR>
        <TR> 
          <TD width="36" background="border_img/circle_04.gif">&nbsp; </TD>
    <TD align="left" valign="top"> 
      <form action="" method="post" enctype="multipart/form-data" name="editfrm" onSubmit="return valid();" > 
	  
      <table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#003366" > 
          <tr bgcolor="#E6F2FF"> 
            <td width="19%" height="20">User Name</td> 
            <td width="72%">
            <select name="uid" id="uid"  onChange="populate(this.options[this.selectedIndex].value, document.editfrm);">
			<option value="0">-- Select Username --</option>
			<? $user=mysql_query("select u.id,uname from user u inner join t123go_product_sold p on u.id=p.uid");
					while($rec=mysql_fetch_array($user))
					{
				if($myrec['uid']==$rec['id']){
					?>
					<option value="<?=$rec['id'];?>" selected="selected"><?=$rec['uname'];?></option>
				<?	}else{?>
					<option value="<?=$rec['id'];?>" ><?=$rec['uname'];?></option>
					
					<? }
					}?>                    
             </select>       
                    </td> 
          </tr> 
          <tr bgcolor="#E6F2FF">    
            <td height="20">Product Name</td>    
            <td>
            <select name="product_id" id="product_id">
            <option value="0">-- Select Product --</option>
            <?
			if($myrec['pid']!=''){?>
		    <option value="<?=$myrec['pid']?>" selected><? echo get_fieldval(pid,pname,t123go_product,$myrec['pid']);?></option>
			<? }?>
            </select>
           </td>      
          </tr>  
          <tr bgcolor="#E6F2FF">      
            <td height="20">Value</td>   
            <td><input name="value"  class="inputtext" size="40" style="height:20px;"  value="<?=$myrec['value']?>"> 
             </td> 
          </tr> 
		  <tr bgcolor="#E6F2FF">        
           <td height="20">Description</td>   
            <td><textarea name="description" rows="5" cols="500" style="width:500px" ><?=$myrec['description']?></textarea></td>   
          </tr> 
          
		  <tr bgcolor="#E6F2FF">      
            <td height="20">Question 1</td>    
            <td><input name="ques1" type="text" class="inputtext" style="height:20px;" size="80" value="<?=$myrec['ques1']?>"></td>  
          </tr>  
		  <tr bgcolor="#E6F2FF">      
            <td height="20">Answer1</td>    
            <td><textarea name="ans1"  rows="3" cols="500" style="width:500px" ><?=$myrec['ans1']?></textarea></td>   
          </tr> 
		   <tr bgcolor="#E6F2FF">        
            <td height="20">Question 2</td>     
            <td><input name="ques2" type="text" class="inputtext"  style="height:20px;" size="80" value="<?=$myrec['ques2']?>"></td>   
          </tr>
		  <tr bgcolor="#E6F2FF">      
            <td height="20">Answer2</td>    
            <td><textarea name="ans2"    rows="3" cols="500" style="width:500px" ><?=$myrec['ans2']?></textarea></td>   
          </tr> 
		      <tr bgcolor="#E6F2FF">        
            <td height="20">Question 3</td>   
            <td><input name="ques3" type="text" class="inputtext" style="height:20px;" size="80" value="<?=$myrec['ques3']?>"></td >  
          </tr> 
		  <tr bgcolor="#E6F2FF">       
            <td height="25">Answer3</td>      
            <td><textarea name="ans3"   rows="3" cols="500" style="width:500px"><?=$myrec['ans3']?></textarea></td>   
          </tr>  
		  
          
          <? if($_GET['edit']!=''){?>
          
          <tr bgcolor="#E6F2FF">   
            <td height="30">&nbsp;</td>
            <td><input name="edit_btn" type="submit" class="inputsubmit"  value="Update" ></td> 
          </tr>
          <? }
		  else {?>          
           <tr bgcolor="#E6F2FF">  
            <td height="30">&nbsp;</td> 
            <td><input name="Addnew_btn" type="submit" class="inputsubmit"  value="Save" ></td>
          </tr> 
          <? }?>
        </table>
        
      </form></TD>
          <TD width="35" background="border_img/circle_06.gif">&nbsp; </TD>
        </TR>
        <TR> 
          <TD> <img border='0' src="border_img/circle_07.gif" WIDTH=36 HEIGHT=34 ALT=""></TD>
          <TD height="34" background="border_img/circle_08.gif">&nbsp; </TD>
          <TD> <img border='0' src="border_img/circle_09.gif" WIDTH=35 HEIGHT=34 ALT=""></TD>
        </TR>
      </TABLE>
      
  <? }?>    
      

        
  
</table>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center ends:::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
