<?php

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

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

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

@extract($_REQUEST);

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

$heading="Manage Newsletter";

$record_type="Newsletter";

$script_name="manage-newsletter.php";

$table_name="newsletter_member";

if (isset($_POST['delete'])) {
   if (!empty($_POST['id'])) {
       $catid = $_POST['id'];
       foreach ($catid as $id) {
           mysqli_query($dbconn, "DELETE FROM $table_name WHERE 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 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>Email</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="id[]" value="<?= $arr['id'] ?>"></td>
                          <td><?= $sl++; ?></td>
                          <td>
                            <?= date('d.M.Y', strtotime($arr['join_date'])) ?>
                           
                          </td>
                          <td>
                            <p class="ordern"><?= $arr['email'] ?></p>
                            <?= empty($arr['en_org_name'])?'':'(Company: '.$arr['en_org_name'].')'; ?>
                          </td>
                          <td>
                          
                            <?php if ($arr['email'] != '') { ?>
                            <p class="m-0"><i class="fa fa-envelope"></i> <a href="mailto:<?= $arr['email']?>" class="href"><?= $arr['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-haghtag"></i> <?= $arr['en_quantity']?></p>
                            <?php
               } else { ?>
            <?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['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('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;
                  ?>