<? require_once("../includes/main.inc.php");
$headerTitleName = "Industry Served List";

if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {

    if (!empty($_REQUEST['page_id'])) {  // Ensure page_id is set
        // Sanitize and format IDs properly
        $page_ids = array_map('intval', explode(',', $_REQUEST['page_id']));
        $page_id = implode(',', $page_ids);

       
        if (!empty($page_id)) { // Ensure we have valid IDs
            $sql1 = "DELETE FROM `tbl_industry_served` WHERE country_id IN ($page_id)";
            db_query($sql1);
            set_session_msg("Selected Services have been deleted successfully");
        } else {
            set_session_msg("Error: No valid country ID provided.");
        }
    } else {
        set_session_msg("Error: No country ID selected.");
    }

    header("Location: " . $_SERVER['HTTP_REFERER']);
    exit;
}
$start = isset($start) ? intval($start) : 0;
$pagesize = isset($pagesize) ? intval($pagesize) : 100;
$columns = "select `tbl_industry_served`.* ";
$sql = " from `tbl_industry_served` ";
$sql .= " where 1 ";

//$order_by == '' ? $order_by = '`country_id`' : true;

//$order_by2 == '' ? $order_by2 = 'ASC' : true;

$sql_count = "select count(*) ".$sql; 

$sql .= "order by country_id ASC ";

$sql .= "limit $start, $pagesize ";

$sql = $columns.$sql;

$result = db_query($sql);

$reccnt = db_scalar($sql_count);
?><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">
    Manage Industry Served</div></td>
  </tr>
</table>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td id="content">

        <div align="center"><span class="msg"><?=display_sess_msg();?></span></div><br />
        


        <a href="industry_serve_add.php?page_id=&start=0" class="redcolor">Add New Industry</a>  <a style="margin-left:20px;" href="import_state.php" class="redcolor">Import Services Record in excel</a> <a style="margin-left:20px;" href="industry_serve_list.php?action=alldelete" onclick="return confirm('Are you sure?')" class="redcolor">Delete All Industry</a>

      <? if(mysqli_num_rows($result)==0){?>
      
      <div class="msg">Sorry, no records found.</div>
      
      <? } else{ ?>
      <div align="right"> Showing Records: <?= $start+1?> to   <?=($reccnt<$start+$pagesize)?($reccnt-$start):($start+$pagesize)?>    of   <?=$reccnt?> </div>
      <form method="post" name="form1" id="form1" onSubmit="confirm_submit(this)">

        <table width="100%"  border="0" cellpadding="0" cellspacing="1" class="tableList">
          <tr>
          <th  align="center" width="5%">Id</th>
          <th  align="left" width="20%" style="padding-left:10px;">Industry Serviced Name</th>
          <th  align="left" width="20%" style="padding-left:10px;">Parents</th>
          <!--<th  align="left" width="20%" style="padding-left:10px;">Banner Images</th>-->
          <th  align="center" width="8%">Status</th>
          <th align="center" width="8%">Edit</th>
          <th align="center" width="5%">Delete</th>
          </tr>
      <? 
if($start==0){
	$cnt=0;
}
else{
	$cnt=$start;
}
while ($line_raw = mysqli_fetch_array($result)) {
	$cnt++;
$line = ms_display_value($line_raw);
@extract($line);
$css = isset($css) ? (($css == 'trOdd') ? 'trEven' : 'trOdd') : 'trOdd';

?><tr class="<?=$css?>">
<td  valign="top" align="center"><?=stripslashes($country_id)?></td>
<td align="left" valign="middle" style="padding-left:10px;"><?php echo stripslashes($industry_name)?></td>
<td align="left" valign="middle" style="padding-left:10px;">
<?php
if($parent_childs=='0'){  
  echo ' No Parent';
}else{ 
  $parentData = mysqli_fetch_assoc(db_query("select country_name from `tbl_industry_served` where country_id='".$parent_childs."'"));	
  echo $parentData['country_name'];
}
?>
</td>
<?php /*?><td align="left" valign="middle" style="padding-left:10px;">
               <?php $sv_image = $country_banner;
			    if(strlen($country_banner) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image)){
                $imgsrc=UP_FILES_WS_PATH."/banner/thumb/".$sv_image;
                $size=getimagesize(UP_FILES_FS_PATH."/banner/thumb/".$sv_image);
				echo '<img src="'.$imgsrc.'" alt="No Image" width="60" height="60"  />';
                }
				else{  echo 'NO Images'; }
                ?>
</td><?php */?>
<td align="center" valign="middle"><?php if($country_status=='1'){ echo 'Active'; }else{ echo '<span style="color:red;">InActive</span>'; } ?></td>
<td align="center" valign="top"><a href="industry_serve_add.php?page_id=<?=$country_id?>&start=<?=$start?>"><img src="images/icons/edit.png" alt="Edit" width="16" height="16" border="0" /></a></td>

<td align="center" valign="top"><a href="industry_serve_list.php?page_id=<?=$country_id?>&start=<?=$start?>&action=delete" onclick="return stdel_confirm();"><img src="images/icons/trash-20.png" alt="Edit" title="Note - Related <?=$country_name ?? '';?>, All data will be Deleted !" width="16" height="16" border="0" /></a></td>
</tr>
<? }?>        </table>
 </form>
<? }?>
 <? include("paging.inc.php");?>    </td>

  </tr>

</table>
<script>
function stdel_confirm(){  return confirm("Are you sure want to delete?"); }
</script>
<? include("bottom.inc.php");?>