<? include_once("../includes/main.inc.php");

$page_id = $_REQUEST['page_id'];

if(is_post_back()) {

if($page_id!='') 
    {
         $chkbox = $_POST['chkbox'];
         $chkNew = ""; 
         foreach($chkbox as $chkNew1) 
         { 
         $chkNew .= $chkNew1 . ","; 
         }   
    	$sql = "update `tbl_related_link` set link_name='$chkNew', link_status='$link_status' where id = $page_id ";
    	db_query($sql);
    	set_session_msg("Services updated successfully.");	
        } 
        else
        {
         $pid = $_POST['country_id'];
         $chkbox = $_POST['chkbox'];
         $chkNew = "/"; 
         foreach($chkbox as $chkNew1) 
         { 
         $chkNew .= $chkNew1 . "/"; 
         }    
	    $sql = "insert into `tbl_related_link` set link_name='$chkNew', country_id='$pid', link_status='$link_status'";
	    db_query($sql);
	    set_session_msg("Link added successfully.");
	 }
	    header("Location: links.php?start=$start");
        exit;
  }

  
    if($page_id!='') {
	$sql = "select * from `tbl_related_link` where id = '$page_id'";
	$result = db_query($sql);
	if ($line_raw = mysql_fetch_array($result)) {
		@extract($line_raw);
	}
}
?>
<link href="styles.css" rel="stylesheet" type="text/css">

<? include("top.inc.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="pageHead"><div id="txtPageHead">
       Add/Edit Related Links Name</div></td>
  </tr>
</table>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<table width="90%" align="left">
<tr><td>
<form method="post" action="" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return validate(this);">
<table width="50%" align="center" border=0 cellpadding="0"  cellspacing="0" class="text">
<tr>
<td  colspan="2"height="30"  align="right"><a href="links.php?start=<?=$start?>" class="redcolor"><strong>Back To Links List</strong></a></td>
</tr>    
<tr><td height="15"><div align="center"><span class="msg"><?=display_sess_msg();?></span></div><br /></td></tr>  


<tr><td>&nbsp;</td></tr>

<?php  $pcqry = mysql_query("select * from `tbl_country` where parent_childs !='0' ");	?>
<tr>
<td class="lables"><b>Services Name</b></td>
<td class="feildstxt"><select name="country_id" id="country_id">
<option value="0">Selected Service Name</option>
<?php while($parentData = mysql_fetch_assoc($pcqry)){ ?>  
<option value="<?php echo $parentData['country_id']; ?>" <?php if($parentData['country_id']==$parent_childs){ echo 'selected="selected"'; } ?>><?php echo $parentData['country_name']; ?></option>      
<?php } ?>    
</select></td>
</tr>
<tr><td> </td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td colspan="2"><b style="margin-left:120">Selected Related Link Name in Checkbox</b></td><td></td></tr>
<tr>
<td class="lables" colspan="2"><hr/></td>
</tr>
<tr>
<td class="lables"> 
<?php 
$pcqry1 = mysql_query("select * from `tbl_country` where parent_childs !='0' limit 0,70 ");
while($parentDatan = mysql_fetch_assoc($pcqry1)){ ?>  
<input type="checkbox" name="chkbox[]" value="<?php echo $parentDatan['country_name']; ?>"><label><?php echo $parentDatan['country_name']; ?></label><br/>
<?php } ?> 
</td>
<td class="feildstxt">
<?php 
$pcqry1 = mysql_query("select * from `tbl_country` where parent_childs !='0' limit 70,150 ");
while($parentDatan = mysql_fetch_assoc($pcqry1)){ ?>  
<input type="checkbox" name="chkbox[]" value="<?php echo $parentDatan['country_name']; ?>" id="<?php echo $parentDatan['county_id']; ?>" ><label><?php echo $parentDatan['country_name']; ?></label><br/>
<?php } ?>    
</td>
</tr>
<tr>
<td class="lables" colspan="2"><hr/></td>
</tr>
<tr><td>&nbsp;</td></tr>


<tr>
<td class="lables"><b>Status</b></td>
<td class="feildstxt"><select name="link_status" id="link_status">
<option value="1" <?php if($link_status=='1'){ echo 'selected="selected"'; } ?>>Active</option>
<option value="0" <?php if($link_status=='0'){ echo 'selected="selected"'; } ?>>InActive</option>          
</select></td>
</tr>
<tr><td>&nbsp;</td></tr>

<tr>
<td class="lables" colspan="2"><hr/></td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left" class="lables">&nbsp;</td>
<td align="left" class="feildstxt"><input class="button" type="submit" name="submit" value="Save"></td>
</tr>
<tr><td height="25">&nbsp;</td></tr>
</table>
</form>
</td></tr></table> 
<? include("bottom.inc.php");?>