<?php

include_once("../include/main.inc.php");

check_session('MyCpanel','index.php');

################ Paging Starts From Here ##################

@extract($_REQUEST);

if($parentID=="") {
	$parentID=0;
}

$heading="Manage Enquiry";

$record_type="Enquiry";

$script_name="manage-enquiry.php";

$table_name="tbl_enquiry";

if (isset($_POST['delete'])) {
   if (!empty($_POST['en_id'])) {
       $catid = $_POST['en_id'];
       foreach ($catid as $id) {
           mysqli_query($dbconn, "DELETE FROM $table_name WHERE en_id = '$id'");
       }
       $_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been deleted successfully</div>';
   } else {
       $_SESSION['session_message'] = '<div class="btn btn-danger">No Category selected</div>';
   }
   header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
   exit;
}

########################################################
admin_header("Manage $record_type");
$qry= db_query("select * from $table_name order by en_id desc");	
?>
<div class="content-wrapper">
          <div class="page-header">
            <h3 class="page-title mb-3">
			<?=$heading;?>
            </h3>
          </div>
          <div class="card">
            <div class="card-body">
              <div class="row">
                <div class="col-12">
                  <form action="" method="post">
                    <div class="table-responsive">
                      <table id="order-listing" class="table table-bordered table-hover text-uppercase">
                        <thead>
                          <tr>
                            <th>
                              <div class="form-check mt-0">
                                <label class="form-check-label">
                                  <input type="checkbox" class="form-check-input" name="check_all" id="check_all" value="1" onclick="checkall(this.form)"><i class="input-helper"></i>
                                </label>
                              </div>
                            </th>
                            <th>Sno.</th>
                            <th>Date</th>
                            <th>Name</th>
                            <th>Contact</th>
                            <th>Enquiry For</th>
                            <th>Enquiry Source</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
                        $sl=$start+1;
                        while($arr=mysqli_fetch_array($qry)) {
                          if($arr['en_zcode']!=''){  
                            $mobileNumbers= '+'.$arr[en_zcode].' - '.$arr[en_mobile];
                           }else{ 
                            $mobileNumbers=$arr['en_mobile'];
                         }
                        ?>
                        <tr>
                          <td><input type="checkbox" name="en_id[]" value="<?= $arr['en_id'] ?>"></td>
                          <td><?= $i++ + 1; ?></td>
                          <td>
                            <?= date('d.M.Y', strtotime($arr['en_date'])) ?>
                            <br><?= date('H:ia', strtotime($arr['en_date'])) ?>
                          </td>
                          <td>
                            <p class="ordern"><?= $arr['en_name'] ?></p>
                            <?= empty($arr['en_org_name'])?'':'(Company: '.$arr['en_org_name'].')'; ?>
                          </td>
                          <td>
                            <p class="m-0"><i class="fa fa-phone"></i>  <a href="tel:<?=$mobileNumbers; ?>" class="href"><?=$mobileNumbers; ?></a></p>
                            <?php if ($arr['en_country_name'] != '') { ?>
                            <p class="m-0"><i class="fa fa-map-marker"></i> <?= $arr['en_country_name']?></p>
                            <?php
               } else { ?>
            <?php
               } ?>

                            <?php if ($arr['en_email'] != '') { ?>
                            <p class="m-0"><i class="fa fa-envelope"></i> <a href="mailto:<?= $arr['en_email']?>" class="href"><?= $arr['en_email']?></a></p>
                            <?php
               } else { ?>
            <?php
               } ?>
                            <?php if ($arr['en_country'] != '') { ?>
                            <p class="m-0"><i class="fa fa-map-marker"></i> <?= $arr['en_country']?></p>
                            <?php
               } else { ?>
            <?php
               } ?>


<?php if ($arr['en_quantity'] != '') { ?>
    <p class="m-0">
        <i class="fa fa-cubes"></i> <strong>Quantity:</strong> <?= $arr['en_quantity'] ?>
    </p>
<?php 
} 
  ?>
    

                          </td>


                         
                            
                           
                          </td>
                          <td>
                            <p class="productid-dcs"><?= $arr['enquiry_for']?></p>
                            <p class="productid-dcs"><i class="fa fa-comments"></i>: <?= $arr['en_comment']?></p>
                          </td>
                          <td>
                            <p class="productid-dcs"><b>Url:</b> <?= $arr['en_url'] ?></p>
                            <p class="productid-dcs"><b>IP:</b> <?= $arr['en_ip'] ?></p>
                            <p class="productid-dcs"><b>System:</b> <?= $arr['system_detail'] ?></p>
                          </td>
						</tr>

 <?php  $sl++; }?>
                       
                      </tbody>
                    </table>
                    <div class="btn-grp">
						<button type="submit" name="delete" onclick="return select_chk()" class="btn btn-danger btn-icon-text btn-sm">
							<i class="fas fa-trash-alt mr-1"></i>Delete
                        </button>
                        </div>
                  </div>
                                 </form>
                </div>
              </div>
            </div>
          </div>
        </div>
        <script language="javascript">

checked=false;
function checkall(frm1){
	var aa= frm1;
	if(checked == false){
		checked = true
	}
	else{
		checked = false
	}
	for (var i =0; i < aa.elements.length; i++){
		aa.elements[i].checked = checked;
	}
} 
function select_chk(){
var chks = document.getElementsByName('en_id[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++){
if (chks[i].checked){
  hasChecked = true;
  break;
  }
}
if (hasChecked == false){
alert("Please Select At Least One.");
return false;
}
}
</script>
                  <?php
                  admin_footer();
                  exit;
                  ?>