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

require_once '../check_edit_page.php';


class edit extends database
{
    
    
    public function Getdata($id)
    {
        $where['cl_id']= $id;
        return $this->fetchRow('tb_product_category', $where);
    }
    
    public function getAllBanners($id, $lang, $screen)
    {
        return $this->fetchAll('tb_product_category_banners', ['cl_language' => $lang, 'cl_category_id' => $id, 'cl_screen' => $screen]);
    }

   
}

$obj = new edit();

$data = $obj->Getdata($id);
$bannersEnglish = $obj->getAllBanners($id, 'en', 'Desktop');
$bannersEstonina = $obj->getAllBanners($id, 'ee', 'Desktop');
$bannersLithuanian = $obj->getAllBanners($id, 'lt', 'Desktop');
$bannersLatvian = $obj->getAllBanners($id, 'lv', 'Desktop');

$bannersEnglishMobile = $obj->getAllBanners($id, 'en', 'Mobile');
$bannersEstoninaMobile = $obj->getAllBanners($id, 'ee', 'Mobile');
$bannersLithuanianMobile = $obj->getAllBanners($id, 'lt', 'Mobile');
$bannersLatvianMobile = $obj->getAllBanners($id, 'lv', 'Mobile');

$templateType = 'edit';
include '../header.php';
?>
 <link href="<?php echo MAIN_DOMAIN ?>/dropzone/dist/dropzone.css" rel="stylesheet" />
 <script src="<?php echo MAIN_DOMAIN ?>//dropzone/dist/dropzone.js"></script>
               <!-- 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">Edit Product Category  - <?php echo $data['cl_name'] ?></h2>
                                    
                                </div>
                                
                              
                            </div>
                        </div>
                        
                        <div class="row m-t-25 m-row">
                    
                            <div class="col-lg-10">
                                <div class="card">
                                    <ul class="nav nav-tabs">
                                        <li class="nav-item">
                                          <a class="nav-link" href="edit.php?id=<?php echo $id ?>">Main</a>
                                        </li>
                                        <li class="nav-item">
                                          <a class="nav-link active" href="banners.php?id=<?php echo $id ?>">Banners</a>
                                        </li>
                                        <li class="nav-item">
                                            <a class="nav-link" href="top_rated.php?id=<?php echo $id ?>">Top Rated</a>
                                          </li>
                                          <li class="nav-item">
    <a class="nav-link" href="banners2.php?id=<?php echo $id ?>">Banners 2</a>
  </li>

  <li class="nav-item">
                                            <a class="nav-link" href="brands.php?id=<?php echo $id ?>">Brands</a>
                                          </li>
                                          <li class="nav-item">
    <a class="nav-link" href="custom_text.php?id=<?php echo $id ?>">Custom Texts</a>
  </li>
                                      </ul>
                                   
                                    <div class="card-body card-block">
                                        <div method="post"  enctype="multipart/form-data" class="form" cluster-url="../ajax/product_category/edit_ajax?id=<?php echo $id;?>" cluster-redirect="list">
                                            <div class="col-12">
                                                <div class="row">
                                                    <div class="col-12 new_design_container">
                                                        <div class="row">
                                                            <div class="col-12">
                                                                <label for="Name" class=" form-control-label">Banners (English) - Desktop</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=en&id=<?php echo $id ?>"
                                                                    class="dropzone"
                                                                    id="banner-english"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersEnglish))
                                                                    {
                                                                        foreach($bannersEnglish AS $banner)
                                                                        {
                                                                            ?>
                                                                    <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                        <td>
                                                                           <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                        </td>
                                                                        <td>
                                                                            <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                           
                                                                        </td>
                                                                        <td>
                                                                            <button type="button" class="btn btn-delete btn-danger" 
                                                                                    cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>">
                                                                                Delete
                                                                            </button>
                                                                            <div class="error-input"></div>    
                                                                        </td>
                                                                    </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>

                                                            </div>
                                                            <div class="col-12 mt-3">
                                                                <label for="Name" class=" form-control-label">Banners (English) - Mobile</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=en&id=<?php echo $id ?>&screen=Mobile"
                                                                    class="dropzone"
                                                                    id="banner-english-mobile"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersEnglishMobile))
                                                                    {
                                                                        foreach($bannersEnglishMobile AS $banner)
                                                                        {
                                                                            ?>
                                                                    <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                        <td>
                                                                           <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                        </td>
                                                                        <td>
                                                                            <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                            
                                                                        </td>
                                                                        <td>
                                                                            <button type="button" class="btn btn-delete btn-danger" 
                                                                                    cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>">
                                                                                Delete
                                                                            </button>
                                                                            <div class="error-input"></div>    
                                                                        </td>
                                                                    </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>

                                                            </div>
                                                            
                                                            <div class="col-12 mt-3">
                                                                <label for="Name" class=" form-control-label">Banners (Latvian) - Desktop</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=lv&id=<?php echo $id ?>"
                                                                    class="dropzone"
                                                                    id="banner-latvian"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersLatvian))
                                                                    {
                                                                        foreach($bannersLatvian AS $banner)
                                                                        {
                                                                            ?>
                                                                            <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                                <td>
                                                                                   <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                                </td>
                                                                                <td>
                                                                                    <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                                    
                                                                                </td>
                                                                                <td>
                                                                                    <button type="button" class="btn btn-delete btn-danger"
                                                                                            cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>"
                                                                                            >
                                                                                        Delete
                                                                                    </button>
                                                                                    <div class="error-input"></div>    
                                                                                </td>
                                                                            </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>
                                                            </div>
                                                            <div class="col-12 mt-3">
                                                                <label for="Name" class=" form-control-label">Banners (Latvian) - Mobile</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=lv&id=<?php echo $id ?>&screen=Mobile"
                                                                    class="dropzone"
                                                                    id="banner-latvian-mobile"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersLatvianMobile))
                                                                    {
                                                                        foreach($bannersLatvianMobile AS $banner)
                                                                        {
                                                                            ?>
                                                                            <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                                <td>
                                                                                   <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                                </td>
                                                                                <td>
                                                                                    <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                                   
                                                                                </td>
                                                                                <td>
                                                                                    <button type="button" class="btn btn-delete btn-danger"
                                                                                            cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>"
                                                                                            >
                                                                                        Delete
                                                                                    </button>
                                                                                    <div class="error-input"></div>    
                                                                                </td>
                                                                            </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>
                                                            </div>
                                                            
                                                            
                                                            <div class="col-12 mt-3">
                                                                <label for="Name" class=" form-control-label">Banners (Lithuanian) - Desktop</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=lt&id=<?php echo $id ?>"
                                                                    class="dropzone"
                                                                    id="banner-lithuanian"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersLithuanian))
                                                                    {
                                                                        foreach($bannersLithuanian AS $banner)
                                                                        {
                                                                            ?>
                                                                            <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                                <td>
                                                                                   <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                                </td>
                                                                                <td>
                                                                                    <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                                    
                                                                                </td>
                                                                                <td>
                                                                                    <button type="button" class="btn btn-delete btn-danger"
                                                                                            cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>"
                                                                                            >
                                                                                        Delete
                                                                                    </button>
                                                                                    <div class="error-input"></div>    
                                                                                </td>
                                                                            </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>
                                                            </div>
                                                            <div class="col-12 mt-3">
                                                                <label for="Name" class=" form-control-label">Banners (Lithuanian) - Mobile</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=lt&id=<?php echo $id ?>&screen=Mobile"
                                                                    class="dropzone"
                                                                    id="banner-lithuanian-mobile"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersLithuanianMobile))
                                                                    {
                                                                        foreach($bannersLithuanianMobile AS $banner)
                                                                        {
                                                                            ?>
                                                                            <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                                <td>
                                                                                   <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                                </td>
                                                                                <td>
                                                                                    <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                                   
                                                                                </td>
                                                                                <td>
                                                                                    <button type="button" class="btn btn-delete btn-danger"
                                                                                            cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>"
                                                                                            >
                                                                                        Delete
                                                                                    </button>
                                                                                    <div class="error-input"></div>    
                                                                                </td>
                                                                            </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>
                                                            </div>
                                                            <div class="col-12 mt-3">
                                                                <label for="Name" class=" form-control-label">Banners (Estonian) - Desktop</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=ee&id=<?php echo $id ?>"
                                                                    class="dropzone"
                                                                    id="banner-estonian"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersEstonina))
                                                                    {
                                                                        foreach($bannersEstonina AS $banner)
                                                                        {
                                                                            ?>
                                                                    <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                        <td>
                                                                           <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                        </td>
                                                                        <td>
                                                                            <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                            
                                                                        </td>
                                                                        <td>
                                                                            <button type="button" class="btn btn-delete btn-danger"
                                                                                    cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>">
                                                                                Delete
                                                                            </button>
                                                                            <div class="error-input"></div>    
                                                                        </td>
                                                                    </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>
                                                            </div>
                                                            <div class="col-12 mt-3">
                                                                <label for="Name" class=" form-control-label">Banners (Estonian) - Mobile</label>
                                                                <div action="/ajax/product_category/banner_upload?lang=ee&id=<?php echo $id ?>&screen=Mobile"
                                                                    class="dropzone"
                                                                    id="banner-estonian-mobile"></div>

                                                                <table class="table table-striped">
                                                                    <?php
                                                                    if(!empty($bannersEstoninaMobile))
                                                                    {
                                                                        foreach($bannersEstoninaMobile AS $banner)
                                                                        {
                                                                            ?>
                                                                    <tr cluster-id="<?php echo htmlspecialchars($banner['cl_id']) ?>">
                                                                        <td>
                                                                           <img style="max-width: 150px;max-height : 150px;width:auto;height : auto;" src="<?php echo MAIN_DOMAIN ?>/uploads/product_category/<?php echo $banner['cl_image'] ?>" />
                                                                        </td>
                                                                        <td>
                                                                            <input type="text" class="form-control banner_link" value="<?php echo htmlspecialchars($banner['cl_link']) ?>"/>
                                                                            
                                                                        </td>
                                                                        <td>
                                                                            <button type="button" class="btn btn-delete btn-danger"
                                                                                    cluster-href="../ajax/product_category/delete_banner_image_ajax?id=<?php  echo htmlspecialchars($banner['cl_id']); ?>">
                                                                                Delete
                                                                            </button>
                                                                            <div class="error-input"></div>    
                                                                        </td>
                                                                    </tr>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    ?>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                       </div>
                                   </div>
                                </div>
                            </div>
                          
                        </div>
                        
                        <script>
  // Note that the name "myDropzone" is the camelized
  // id of the form.
  Dropzone.options.bannerEmglish = {
    // Configuration options go here
  };
  
  Dropzone.options.bannerEmglishMobile = {
    // Configuration options go here
  };
  
  Dropzone.options.bannerLithuanian = {
    // Configuration options go here
  };
  
  Dropzone.options.bannerLithuanianMobile = {
    // Configuration options go here
  };
  
  Dropzone.options.bannerEstonian = {
    // Configuration options go here
  };
  
  Dropzone.options.bannerEstonianMobile = {
    // Configuration options go here
  };
  
  
  
  $(document).on('blur', '.banner_link', function(){
      var parent = $(this).parents('tr').first();
      var id = $(parent).attr('cluster-id');
       $(parent).find('.error-input').html('<div class="alert alert-warning col-xs-12">Updating....</div>').show();
       
      $.post('/ajax/product_category/banner_link_update?id=' + id, {link: $(this).val()}, function(res){
          $(parent).find('.error-input').html('<div class="alert alert-success col-12">' + res.message + '</div>').show();
      }, 'json').fail(function(xhr){
          var res = xhr.responseJSON;
          if (typeof res === 'undefined') {
                $(parent).find('.error-input').html('<div class="alert alert-danger col-xs-12">Something went wrong</div>').show();
                return;
          }
          
          $(parent).find('.error-input').html('<div class="alert alert-danger col-12">' + res.error_text + '</div>').show();
      }, 'json');
  })
</script>
                        
                   <?php
				   include '../footer.php';
				  