<?php
session_start();
include_once "../config.php";
require_once '../database1.php';
require_once "../check_admin.php";

class Status extends database
{
   public function index()
    {
		return $this->fetchAll('tb_status');
	}
}


$obj = new Status();
$statuses = $obj->index();

include '../header.php';
?>

<link rel="stylesheet" href="<?php echo DOMAIN ?>/jquery_file_upload/css/style.css">
<link rel="stylesheet" href="<?php echo DOMAIN ?>/jquery_file_upload/css/jquery.fileupload.css">
<input type="hidden" class="file_url_main" value="<?php echo DOMAIN ?>/ajax/upload_status_image" />
            <!-- MAIN CONTENT-->
            <div class="main-content">
                <div class="section__content section__content--p30">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="overview-wrap">
                                    <h2 class="title-1">List Status</h2>
                                    
                                </div>
								<?php if($msg !=''){echo '<span class="col-md-6 alert alert-danger pull-left">'.$msg.'</span>';}?>
                            </div>
                        </div>
                        
                        <div class="row m-t-25 m-row">
					
                            <div class="col-lg-10">
                                <div class="card">
                                    
                                    <div class="card-body card-block">
								        <table class="table table-bordered table-striped">
                                            <?php
                                            if(!empty($statuses))
                                            {
                                                foreach($statuses AS $status)
                                                {
                                            ?>

                                                    <tr class="file_upload_container">
                                                        <th>
                                                            <?php echo htmlspecialchars($status['cl_name']) ?>
                                                        </th>
                                                        <th class="files_area">
                                                            <img src="uploads/<?php echo htmlspecialchars($status['cl_image']) ?>"  style="max-width:100px"/>
                                                        </th>
                                                        <th>
                                                            <a href="edit?id=<?php echo $status['cl_id'] ?>" class="btn btn-success btn-edit">Edit</a>
                                                        </th>
                                                    </tr>
                                                    <?php
                                                }
                                            }
                                            ?>
                                          
                                        </table>
                                    </div>
                                </div>
                            </div>
                          
                        </div>
                        
                    <script>
							$(document).ready(function(){
								$('.active').removeClass('active');
								$('#cat-menu').addClass('active');
							}); 
						</script>      
                       
                            <!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="<?php echo DOMAIN ?>/jquery_file_upload/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="<?php echo DOMAIN ?>/jquery_file_upload/js/jquery.fileupload.js"></script>

<script>
        $(document).ready(function(){
    var url = $('.file_url_main').val();
    $('.fileupload').fileupload({
          url: url,
          dataType: 'json',
          submit: function(e,data){
            var parent = $(this).parents('.file_upload_container').first();
            $(parent).find('.files_area').html('');
            $(parent).find('.error_area').html('<div class="alert alert-warning">Upload in progress</div>');
            $(parent).find('.progress .progress-bar').removeAttr('style');


          },
          done: function (e, data) {
              /*$.each(data.result.files, function (index, file) {
                  console.log(file);
              });*/
             
              var parent = $(this).parents('.file_upload_container').first();
             
              
              $(parent).find('.error_area').html('<div class="alert alert-success">Updated Successfully</div>');
              $(parent).find('.file_url_sub').val(data.result.file);
               $(parent).find('.files_area').html('<img src="' + data.result.link + '" style="max-width:100px" />');
          },
          fail: function (e, data) {
            var parent = $(this).parents('.file_upload_container').first();
            $(parent).find('.error_area').html('<div class="alert alert-danger">' + data.jqXHR.responseJSON.error_text + '</div>');
            $(parent).find('.progress .progress-bar').css(
                  'background-color',
                  'salmon'
              );
          },
          progressall: function (e, data) {
            var parent = $(this).parents('.file_upload_container').first();
              var progress = parseInt(data.loaded / data.total * 100, 10);
               $(parent).find('.progress .progress-bar').css(
                  'width',
                  progress + '%'
              );
          }
      }).prop('disabled', !$.support.fileInput)
          .parent().addClass($.support.fileInput ? undefined : 'disabled');
      });
    </script>
  <?php
  include '../footer.php';
  ?>