<?php  
if($_SESSION['role']!=1){ 
exit("You dont have permisiion to access this page ");}
?>
 <div>
    <ul class="breadcrumb">
        <li>
            <a href="index.php">Home</a>
        </li>
         <li>
            <a href="index.php?page=LandingPage"><?php  
			 //echo(landing(post($connect,$_REQUEST['Lid']),$connect)['landingPage_name']); ?></a>
            
        </li>
        <li>
            <a href="index.php?page=LandingPageAffilates&Lid=<?php  echo(post($connect,$_REQUEST['Lid'])); ?>"> Add af</a>
        </li>
    </ul>
</div>

<div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2><i class=" glyphicon glyphicon-th-list"></i> Landing Page af</h2>

                    <div class="box-icon">
                        <a href="#" class="btn btn-setting btn-round btn-default"><i
                                class="glyphicon glyphicon-cog"></i></a>
                        <a href="#" class="btn btn-minimize btn-round btn-default"><i
                                class="glyphicon glyphicon-chevron-up"></i></a>
                        <a href="#" class="btn btn-close btn-round btn-default"><i
                                class="glyphicon glyphicon-remove"></i></a>
                    </div>
                </div>
                <div class="box-content">
                
                <br />

                
              
                 
                  <?php  
				 if($_REQUEST['opt']==do_up){
					if($_REQUEST['affiliates_id']==0
 
	){
		
		echo("<div style='color:red'> Please Fill All Parameters </div>");
		}else{
 

 $affiliates_query="update  
  
affiliates_landing
set affiliates_landing_landingId='".post($connect,$_REQUEST['Lid'])."'
,affiliates_landing_affID='".post($connect,$_REQUEST['affiliates_id'])."'
 
 
 where affiliates_landing_id='".post($connect,$_REQUEST['id'])."'
 
 
 ";
 
 
 
 $situation=mysqli_query($connect,$affiliates_query);
 if($situation){ echo("<div>af Added SucessFully</div>");}
}}
				 ?>
                 
                 
                
                 
                 
                 
                 
                 <?php  
				 if($_REQUEST['opt']==up){
					 
					 $affiliates_q="select * from affiliates where affiliates_id=".post($connect,$_REQUEST['id']);
					$affiliates_res=mysqli_query($connect,$affiliates_q);
					if($affiliates_res){
						$affiliates_row=mysqli_fetch_assoc($affiliates_res);
					
					 }
				 ?>
                 
                         
                   
                  <fieldset>
<legend>Update  service</legend>      
                   
                 
                 
                 <form method="post"  class="login_form" >
<input type="hidden" name="opt" value="do_up" />
<input type="hidden" name="id" value="<?php echo($affiliates_row['affiliates_id']); ?>" />
<input type="hidden" name="Lid" value="<?php  echo(post($connect,$_REQUEST['Lid'])); ?>" />


<div class="form-group">
<div class="row ">
<div class="col-md-5">af Name </div>
<div class="col-md-4"> 

<select name="affiliates_id" id="affiliates_id" class="form-control" data-rel="chosen">
<option value="0">Select af</option>
<?php $selaffiliatesr=mysqli_query($connect,"select * from affiliates");


while($rowProv=mysqli_fetch_array($selaffiliatesr)){
	?>
	<option value="<?php echo($rowProv['affiliates_id']); ?>" <?php if($_REQUEST['id']==$rowProv['affiliates_id']){?> selected<?php } ?>><?php echo($rowProv['affiliates_name']); ?></option>
	<?php
	
	}
 ?>
</select>

</div>
</div>
</div>



 

<div class="form-group">
<div class="row ">

<div class="col-md-12"><input type="submit" name="update_affiliates" value="update affiliates" class="action-button"  style="width:120px"/></div>
</div>
</div>

</form>
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
              


                       <br>
<br>
<br>
<br>






<br>
<br>   
                 
                 
                 
                 
              </fieldset>   
                 
                 
                 
                  <?php  
				 	}
				 ?>
                 
                 
                 
                
                 <!-----      end update affiliates       -->
                 
                
               <!-----       add affiliates       -->
                
                <?php 
				
			if($_REQUEST['opt']==do_add)
{
	
	if($_REQUEST['affiliates_id']==0
 
	){
		
		echo("<div style='color:red'> Please Fill All Parameters </div>");
		}else{
 

 $affiliates_query="insert into affiliates_landing
set affiliates_landing_landingId='".post($connect,$_REQUEST['Lid'])."'
,affiliates_landing_affID='".post($connect,$_REQUEST['affiliates_id'])."'
,affiliates_landing_CodeID='".generateRandom(7)."'
 ";
 
 
 
 $situation=mysqli_query($connect,$affiliates_query);
 if($situation){ echo("<div>affiliates Added SucessFully</div>");}
}}
			
			
			
				 ?>
                
                
                
                   <?php 
				   if($_REQUEST['opt']==add)
				   { 
				   ?>
                   
                   
                   
                   
                   
                   
                  <fieldset>
<legend>Add New service</legend>      
                   
                   
                   
                   
                   
                   
                   
                       <form method="post"  class="login_form" >
<input type="hidden" name="opt" value="do_add" />
<input type="hidden" name="Lid" value="<?php  echo(post($connect,$_REQUEST['Lid'])); ?>" />
<div class="form-group">
<div class="row ">
<div class="col-md-5">af Name </div>
<div class="col-md-4">
<select name="affiliates_id" id="affiliates_id" class="form-control" data-rel="chosen">
<option value="0">Select af</option>
<?php $selaffiliatesr=mysqli_query($connect,"select * from affiliates");


while($rowProv=mysqli_fetch_array($selaffiliatesr)){
	?>
	<option value="<?php echo($rowProv['affiliates_id']); ?>" <?php if($_REQUEST['affiliates_id']==$rowProv['affiliates_id']){?> selected<?php } ?>><?php echo($rowProv['affiliates_name']); ?></option>
	<?php
	
	}
 ?>
</select>
</div>
</div>
</div>


 

<div class="form-group">
<div class="row ">

<div class="col-md-12"><input type="submit" name="Add_affiliates" value="Add affiliates" class="action-button"  style="width:120px"/></div>
</div>
</div>

</form>







    </fieldset>












                       <br>
<br>
<br>
<br>






<br>
<br>

 <!-----      end  add affiliates       -->
                       
                       <?php } ?>
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                      
                  <fieldset>
<legend>Search</legend>
                       
                       
                       <form method="post"  class="login_form"  action="index.php?page=LandingPageAffilates">
<input type="hidden" name="optsearch" value="1" />
<input type="hidden" name="Lid" value="<?php  echo(post($connect,$_REQUEST['Lid'])); ?>" />
 
<div class="form-group">
<div class="row ">
<div class="col-md-5">Name</div>
<div class="col-md-4"><input type="text" name="affiliates_nameSearch" id="affiliates_nameSearch" class="form-control" placeholder="affiliates_name" value="<?php echo($_REQUEST['affiliates_nameSearch']); ?>" /></div>
</div>
</div>

 
  

<div class="form-group">
<div class="row ">

<div class="col-md-12"><input type="submit" name="update_affiliates" value="Search affiliates" class="action-button"  style="width:120px"/></div>
</div>
</div>

</form>
                       
                       
                       
                       
                      
            </fieldset>           
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       <div class="row">
                       <div class="col-md-12">
                         <a href="index.php?page=LandingPageAffilates&opt=add&Lid=<?php  echo(post($connect,$_REQUEST['Lid'])); ?>" ><i class="glyphicon glyphicon-plus icon-white"></i> Add new affiliates</a><br>

                         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                                         
                         
                         
                           <tr>
                             <td>af name </td>
                             <td>price</td>
                             <td>af Code</td>
                             <td>Link</td>
                             <td align="center" valign="middle">update </td>
                           </tr>
                           <?php  
						   
						
			 
			 $query_affiliates="select * from landingpage inner join affiliates_landing
on affiliates_landing_landingId=landingPage_id
inner join affiliates on affiliates_id=affiliates_landing_affID
where  landingPage_id='".post($connect,$_REQUEST['Lid'])."'

" ; 
if($_REQUEST['affiliates_nameSearch']!=''){
	$query_affiliates=$query_affiliates." and affiliates_name like '%".$_REQUEST['affiliates_nameSearch']."%'";
	 
	}
	
	
 
		 
			 $affiliates_res=mysqli_query($connect,$query_affiliates);
			
			 if($affiliates_res){
				 while($row=mysqli_fetch_assoc($affiliates_res))
				 {
				
			  ?>
						
                           <tr>
                             <td><?php echo($row['affiliates_name']); ?></td>
                             <td><?php echo($row['affiliates_landing_price']); ?></td>
                         <td><?php echo($row['affiliates_landing_CodeID']); ?></td>
                             <td><a href="../LandingPage/index.php?L=<?php echo($row['landingPageCode']); ?>&A=<?php echo($row['affiliates_landing_CodeID']); ?>&hash=" target="_blank">Preview</a></td>
                             <td align="center" valign="middle"><a href="index.php?page=LandingPageAffilates&opt=up&id=<?php  echo($row['affiliates_id']); ?>&Lid=<?php  echo(post($connect,$_REQUEST['Lid'])); ?>"  > 
                              <i class="glyphicon glyphicon-edit icon-white"></i> Update</a>
                              
                              <?php //  <i class="glyphicon glyphicon-trash icon-white"></i> Delete
                               ?>
                               
                               </a>
                              </td>
                           </tr>
                           
                           
                           <?php  }}?>
                        
                  </table>
                  <br />


                 
                  </div></div>
                   
                </div>
            </div>
        </div>