<?php include_once('../header.php');
if(!check_login()){
	header("Location: " . WEB_URL . "logout.php");
	die();
}
?>
<?php
include_once(ROOT_PATH.'language/'.$lang_code_global.'/lang_tenant_list.php');
$delinfo = 'none';
$addinfo = 'none';
$msg = "";
if(isset($_GET['id']) && $_GET['id'] != '' && $_GET['id'] > 0){
	$result = mysqli_query($link,"SELECT * FROM tbl_tenant where id = '" . $_GET['id'] . "'");
	if($row = mysqli_fetch_array($result)){
		
	}
	$sqlx = "DELETE FROM `tbl_tenant` WHERE id = ".$_GET['id'];
	mysqli_query($link, $sqlx); 
	$delinfo = 'block';
}
if(isset($_GET['m']) && $_GET['m'] == 'add'){
	$addinfo = 'block';
	$msg = $_data['added_renter_successfully'];
}
if(isset($_GET['m']) && $_GET['m'] == 'up'){
	$addinfo = 'block';
	$msg = $_data['update_renter_successfully'];
}
?>
<!-- Content Header (Page header) -->

<section class="content-header">
  <h1><?= $_data['renter_list'];?></h1>
  <ol class="breadcrumb">
    <li><a href="<?= WEB_URL?>dashboard.php"><i class="fa fa-dashboard"></i><?= $_data['home_breadcam'];?></a></li>
    <li class="active"><?= $_data['add_new_renter_information_breadcam'];?></li>
	<li class="active"><?= $_data['renter_list'];?></li>
  </ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Full Width boxes (Stat box) -->
<div class="row">
  <div class="col-xs-12">
    <div id="me" class="alert alert-danger alert-dismissable" style="display:<?= $delinfo; ?>">
      <button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="fa fa-close"></i></button>
      <h4><i class="icon fa fa-ban"></i><?= $_data['delete_text'];?> !</h4>
      <?= $_data['delete_renter_information'];?> </div>
    <div id="you" class="alert alert-success alert-dismissable" style="display:<?= $addinfo; ?>">
      <button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="fa fa-close"></i></button>
      <h4><i class="icon fa fa-check"></i> <?= $_data['success'];?> !</h4>
      <?= $msg; ?> </div>
    <div align="right" style="margin-bottom:1%;"> <a class="btn btn-success" data-toggle="tooltip" href="<?= WEB_URL; ?>tenant/addtenant.php" data-original-title="<?= $_data['add_new_rent_breadcam'];?>"><i class="fa fa-plus"></i></a> <a class="btn btn-success" data-toggle="tooltip" href="<?= WEB_URL; ?>dashboard.php" data-original-title="<?= $_data['home_breadcam'];?>"><i class="fa fa-dashboard"></i></a> </div>
    <div class="box box-success">
      <div class="box-header">
        <h3 class="box-title"><?= $_data['renter_list'];?></h3>
      </div>
      <!-- /.box-header -->
      <div class="box-body">
        <table class="table sakotable table-bordered table-striped dt-responsive">
          <thead>
            <tr>
              <th><?= $_data['add_new_form_field_text_0'];?></th>
              <th><?= $_data['add_new_form_field_text_1'];?></th>
              <th>Email</th>
              <th>Phone</th>
              <th>Address</th>
              <th>Business Name</th>
              <th>Business Phone</th>
              <th><?= $_data['action_text'];?></th>
            </tr>
          </thead>
          <tbody>
            <?php
				$result = mysqli_query($link,"Select * from tbl_tenant");
				while($row = mysqli_fetch_array($result)){
					$image = WEB_URL . 'img/no_image.jpg';	
					if(file_exists(ROOT_PATH . '/img/upload/' . $row['image']) && $row['image'] != ''){
						$image = WEB_URL . 'img/upload/' . $row['image'];
					}
				
				?>
            <tr>
                <td><img class="photo_img_round" style="width:50px;height:50px;" src="<?= $image;  ?>" /></td>
                <td><?= $row['name']; ?></td>
                <td><?= $row['email']; ?></td>
                <td><?= $row['phone']; ?></td>
                <td><?= $row['address']; ?></td>
                <td><?= $row['business_name']; ?></td>
                <td><?= $row['business_phone']; ?></td>
                <td>
                    <a class="btn btn-primary ams_btn_special" data-toggle="tooltip" href="javascript:;" onClick="$('#assign_<?= $row['id']; ?>').modal('show');" data-original-title="Assign to Unit"><i class="fa fa-clipboard"></i></a>
                    <a class="btn btn-success ams_btn_special" data-toggle="tooltip" href="javascript:;" onClick="$('#nurse_view_<?= $row['id']; ?>').modal('show');" data-original-title="<?= $_data['view_text'];?>"><i class="fa fa-eye"></i></a>
                    <a class="btn btn-warning ams_btn_special" data-toggle="tooltip" href="<?= WEB_URL;?>tenant/updatetenant.php?id=<?= $row['id']; ?>" data-original-title="<?= $_data['edit_text'];?>"><i class="fa fa-pencil"></i></a> 
                    <a class="btn btn-danger ams_btn_special" data-toggle="tooltip" onClick="deleteRent(<?= $row['id']; ?>);" href="javascript:;" data-original-title="<?= $_data['delete_text'];?>"><i class="fa fa-trash-o"></i></a>
                    <div id="nurse_view_<?= $row['id']; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                            <div class="modal-header green_header">
                                <button aria-label="Close" data-dismiss="modal" class="close" type="button"><span aria-hidden="true"><i class="fa fa-close"></i></span></button>
                                <h3 class="modal-title"><?= $_data['rented_details'];?></h3>
                            </div>
                            <div class="modal-body model_view" align="center">&nbsp;
                                <div><img style="width:200px;height:200px;border-radius:200px;" src="<?= $image;  ?>" /></div>
                                <div class="model_title"><?= $row['r_name']; ?></div>
                            </div>
                            <div class="modal-body">
                                <h3 style="text-decoration:underline;"><?= $_data['details_information'];?></h3>
                                <div class="row">
                                <div class="col-xs-6"> <b><?= $_data['add_new_form_field_text_1'];?> :</b> <?= $row['name']; ?><br/>
                                    <b><?= $_data['add_new_form_field_text_2'];?> :</b> <?= $row['email']; ?><br/>
                                    <b>Phone :</b> <?= $row['phone']; ?><br/>
                                    <b>Address :</b> <?= $row['address']; ?><br/>
                                </div>
                                <div class="col-xs-6"> 
                                    <b>Business Name :</b> <?= $row['business_name']; ?><br/>
                                    <b>Business Phone :</b> <?= $row['business_phone']; ?><br/>
                                    <b>Nature of Business :</b> <?= $row['nature_of_business']; ?><br/>
                                </div>
                                </div>
                            </div>
                            </div>
                            <!-- /.modal-content -->
                        </div>
                    </div>
                    <div id="assign_<?= $row['id']; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog" style="width: 40%;">
                            <div class="modal-content">
                            <div class="modal-header green_header">
                                <button aria-label="Close" data-dismiss="modal" class="close" type="button"><span aria-hidden="true"><i class="fa fa-close"></i></span></button>
                                <h3 class="modal-title"><?= $_data['rented_details'];?></h3>
                            </div>
                            <div class="modal-body model_view" align="center">&nbsp;
                                <div><img style="width:200px;height:200px;border-radius:200px;" src="<?= $image;  ?>" /></div>
                                <div class="model_title"><?= $row['r_name']; ?></div>
                            </div>
                            <div class="modal-body">
                                <h3 style="font-weight:600;">Assign To Unit</h3>
                                <form onSubmit="return validateMe();" action="<?= $form_url; ?>" method="post" enctype="multipart/form-data" id="frm_tenant_entry">
                                    <div class="box-body row">
                                        <div class="form-group col-md-6">
                                            <label for="b_name"><span class="errorStar">*</span> <?= $_data['add_new_form_field_text_7'];?> :</label>
                                            <select onchange="getUnit(this.value)" name="b_name" id="b_name" class="form-control">
                                            <option value="">--<?= $_data['select_floor'];?>--</option>
                                            <?php 
                                                    $result_floor = mysqli_query($link,"SELECT * FROM blocks WHERE branch_id = " . (int)$_SESSION['objLogin']['branch_id'] . " order by bid ASC");
                                                    while($row_floor = mysqli_fetch_array($result_floor)){?>
                                            <option <?php if($r_floor_no == $row_floor['bid']){echo 'selected';}?> value="<?= $row_floor['bid'];?>"><?= $row_floor['b_name'];?></option>
                                            <?php } ?>
                                            </select>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label for="ddlUnitNo"><span class="errorStar">*</span> <?= $_data['add_new_form_field_text_8'];?> :</label>
                                            <select name="ddlUnitNo" id="ddlUnitNo" class="form-control">
                                            <option value="">--<?= $_data['select_unit'];?>--</option>
                                            <?php 
                                                    $result_unit = mysqli_query($link,"SELECT * FROM unit_view where b_name = ".(int)$r_floor_no." order by unit_no ASC");
                                                    while($row_unit = mysqli_fetch_array($result_unit)){?>
                                            <option <?php if($r_unit_no == $row_unit['uid']){echo 'selected';}?> value="<?= $row_unit['uid'];?>"><?= $row_unit['unit_no'];?></option>
                                            <?php } ?>
                                            </select>
                                        </div>
                                        <input type="hidden" name="tenant_id" value="<?= $row['id']; ?>" />
                                    </div>
                                    <div class="box-footer">
                                        <div class="form-group pull-right">
                                            <button type="submit" name="button" class="btn btn-success"><i class="fa fa-floppy-o"></i> <?= $button_text; ?></button>
                                        </div>
                                    </div>
                                </form>
                                </div>
                            </div>
                            </div>
                            <!-- /.modal-content -->
                        </div>
                    </div>
                </td>
            </tr>
            <?php } mysqli_close($link);$link = NULL; ?>
          </tbody>
        </table>
      </div>
      <!-- /.box-body -->
    </div>
    <!-- /.box -->
  </div>
  <!-- /.col -->
</div>
<!-- /.row -->
<script type="text/javascript">
  function deleteRent(Id){
    let myFunct = function(){
      window.location = '<?= WEB_URL; ?>tenant/tenantlist.php?id=' + Id;
    }
    sweetConfirmDelete(myFunct);
  }
  
  $( document ).ready(function() {
	setTimeout(function() {
		  $("#me").hide(300);
		  $("#you").hide(300);
	}, 3000);
});
</script>
<style>
    select#b_name, select#ddlUnitNo{
        width:100%;
    }
</style>
<?php include_once('../footer.php'); ?>
