<?php
session_start();
if (isset($_SESSION['_session']['user']) &&  (time() - $_SESSION['_session']['LAST_ACTIVITY']  < $_SESSION['_session']['koha'])) {
  $_SESSION['_session']['LAST_ACTIVITY']  = time();

  if ($_SESSION['_session']['roli'] == 1 || $_SESSION['_session']['roli'] == 2) {
    require 'header.php';
?>
    <div class="content-wrapper">
      <div class="content-header">
        <div class="container" style="padding-top: 20px;">
          <div class="card">
            <div class="col-12 row">
              <div class="col-md-2 col-6">
                <div class="d-flex flex-wrap" id="icons-container">
                  <a href="" data-toggle="modal" data-target="#ConfigPDFService" onclick="servisiget()">
                    <div class="card icon-card cursor-pointer text-center mb-4 mx-2">
                      <div class="card-body">
                        <!-- <i class="bx bxl-adobe mb-2"></i> -->
                        <i class="material-icons dp48">edit</i>
                        <p class="icon-name text-capitalize text-truncate mb-0">Konfiguro PDF </p>
                        <p>Servisi</p>

                      </div>
                    </div>
                  </a>
                </div>
              </div>
              <div class="col-md-2 col-6">
                <div class="d-flex flex-wrap" id="icons-container">
                  <a href="" data-toggle="modal" data-target="#ConfigPDFPorosi" onclick="porosiget()">
                    <div class="card icon-card cursor-pointer text-center mb-4 mx-2">
                      <div class="card-body">
                        <!-- <i class="bx bxl-adobe mb-2"></i> -->
                        <i class="material-icons dp48">edit</i>
                        <p class="icon-name text-capitalize text-truncate mb-0">Konfiguro PDF </p>
                        <p>Porosie</p>
                      </div>
                    </div>
                  </a>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="modal fade" id="ConfigPDFService">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title"> Konfigurimet për PDF të Servisimit</h4>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">

            <div class="input-group mb-12 row" style="margin-left: 1px;">
              <div class="col-sm-4 col-md-4 col-12" style="border: 1px solid black;">
                <div class="row">
                  <div class="col-md-12 col-12" style="height: 50px;">
                    <input type='file' class="form-control" onchange="bg_img(this);" />
                  </div>
                  <img id="bg_image" src="../../../images/Atommed.png" alt="Fotja për header të dokumentit" style="width:100%; height: 60px;" required />
                </div>
              </div>
              <div class="col-sm-4 col-md-4 col-12" style="border: 1px solid black;">
                <div class="row">
                  <div class="col-md-12 col-sm-12 col-12" style="height: 50px;">
                    <!-- <label for="TitullService"> Titulli i PDF </label> -->
                    <input type="text" class="form-control" placeholder="Titulli: 'RAPORT SERVISIMI' " id="TitullService" name="TitullService" value="" required />

                  </div>
                  <div class="col-md-12 col-sm-12 col-12" style="border-top: 1px solid black;height: 60px;">
                    <!-- <label for="VersDoc"> Versioni i dokumentit </label> -->
                    <input type="text" class="form-control" placeholder="versioni: 'ver.1.0' " id="VersDoc" name="VersDoc" value="" required />
                  </div>
                </div>
              </div>

              <div class="col-sm-4 col-md-4 col-12" style="border: 1px solid black;">
                <div class="row">
                  <div class="col-md-12 col-sm-12 col-12" style="height: 50px;">
                    <!-- <label> Dokumenti </label> -->
                    <input type="text" class="form-control" placeholder=" 'FO-810-2' " id="TipService" name="TipService" value="" required />
                  </div>
                  <div class="col-md-12 col-sm-12 col-12" style="border-top: 1px solid black;height: 60px;">
                    <label> Numri i faqeve </label>
                    <input type="checkbox" id="nrfaqev" />
                  </div>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <div class="col-6">
                <p style="color: red; font-weight:500" id="mszh"> </p>
              </div>
              <div class="col-6">
                <button type="button" id="btnRuajPDFService" class="btn btn-success" style="float: right;"><i class=""></i> Ruaj</button>
              </div>

            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="modal fade" id="ConfigPDFPorosi">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title"> Konfigurimet për PDF të Porosisë</h4>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">

            <div class="input-group mb-12 row" style="margin-left: 1px;">
              <div class="col-sm-4 col-md-4 col-12" style="border: 1px solid black;">
                <div class="row">
                  <div class="col-md-12 col-12" style="height: 50px;">
                    <input type='file' class="form-control" onchange="bg_imgoth(this);" />
                  </div>
                  <img id="bg_imageoth" src="../../../images/Atommed.png" alt="Fotja për header të dokumentit" style="width:100%; height: 60px;" required />
                </div>
              </div>
              <div class="col-sm-4 col-md-4 col-12" style="border: 1px solid black;">
                <div class="row">
                  <div class="col-md-12 col-sm-12 col-12" style="height: 50px;">
                    <!-- <label for="TitullPorosi"> Titulli i PDF </label> -->
                    <input type="text" class="form-control" placeholder="Titulli: 'RAPORT POROSIE' " id="TitullPorosi" name="TitullPorosi" value="" required />

                  </div>
                  <div class="col-md-12 col-sm-12 col-12" style="border-top: 1px solid black;height: 60px;">
                    <!-- <label for="VersDoc"> Versioni i dokumentit </label> -->
                    <input type="text" class="form-control" placeholder="versioni: 'ver.1.0' " id="VersDocporosi" name="VersDocporosi" value="" required />
                  </div>
                </div>
              </div>

              <div class="col-sm-4 col-md-4 col-12" style="border: 1px solid black;">
                <div class="row">
                  <div class="col-md-12 col-sm-12 col-12" style="height: 50px;">
                    <!-- <label> Dokumenti </label> -->
                    <input type="text" class="form-control" placeholder=" 'FO-810-2' " id="TipPorosi" name="TipPorosi" value="" required />
                  </div>
                  <div class="col-md-12 col-sm-12 col-12" style="border-top: 1px solid black;height: 60px;">
                    <label> Numri i faqeve </label>
                    <input type="checkbox" id="nrfaqevp" />
                  </div>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" id="btnRuajPDFPorosi" class="btn btn-success" style="float: right;"><i class=""></i> Ruaj</button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <script>
      function servisiget() {
        $.ajax({
          type: 'GET',
          url: url + "/getservicepdf",
          headers: {
            'api_token': token
          },

          success: function(data, status) {
            if (data.code == 200) {
              vl = data.data[0];
              if (vl.foto != '') {
                bg_imgg = vl.foto;
                $('#bg_image').attr('src', vl.foto);
              }
              $('#TitullService').val(vl.Titulli);
              $('#VersDoc').val(vl.Versioni);
              $('#TipService').val(vl.Kodi);
              vl.NrFaqev == 1 ? $('#nrfaqev').attr('checked', true) : $('#nrfaqev').attr('checked', false)

            }

          },
        });


      }

      function porosiget() {
        $.ajax({
          type: 'GET',
          url: url + "/getporosipdf",
          headers: {
            'api_token': token
          },

          success: function(data, status) {
            if (data.code == 200) {
              vl = data.data[0];
              if (vl.foto != '') {
                bg_imggoth= vl.foto;
                $('#bg_imageoth').attr('src', vl.foto);
              }
              $('#TitullPorosi').val(vl.Titulli);
              $('#VersDocporosi').val(vl.Versioni);
              $('#TipPorosi').val(vl.Kodi);
              vl.NrFaqev == 1 ? $('#nrfaqevp').attr('checked', true) : $('#nrfaqevp').attr('checked', false)

            }


          },
        });


      }

      $("#btnRuajPDFService").click(function(e) {
        e.preventDefault();
        data = {
          foto: bg_imgg,
          titulli: $('#TitullService').val(),
          versioni: $('#VersDoc').val(),
          kodi: $('#TipService').val(),
          nrfaqev: $('#nrfaqev').is(":checked") ? 1 : 0,
        }
        console.log(data);
        $.ajax({
          type: 'POST',
          url: url + "/servicepdf",
          headers: {
            'api_token': token
          },
          data: data,
          success: function(data, status) {
            toastr.success('Konfigurimi është bërë me sukses');

          },
        });
      });
      $("#btnRuajPDFPorosi").click(function(e) {
        e.preventDefault();
        data = {
          foto: bg_imggoth,
          titulli: $('#TitullPorosi').val(),
          versioni: $('#VersDocporosi').val(),
          kodi: $('#TipPorosi').val(),
          nrfaqev: $('#nrfaqevp').is(":checked") ? 1 : 0,
        }
        console.log(data);
        $.ajax({
          type: 'POST',
          url: url + "/porosipdf",
          headers: {
            'api_token': token
          },
          data: data,
          success: function(data, status) {
            toastr.success('Konfigurimi është bërë me sukses');

          },
        });
      });
      bg_imgg = '';

      function bg_img(input) {
        if (input.files && input.files[0]) {
          var edit = new FileReader();

          edit.onload = function(e) {
            $('#bg_image')
              .attr('src', e.target.result)
            bg_imgg = e.target.result;
          };


          edit.readAsDataURL(input.files[0]);
        }
      }
      bg_imggoth = '';

      function bg_imgoth(input) {
        if (input.files && input.files[0]) {
          var edit = new FileReader();

          edit.onload = function(e) {
            $('#bg_imageoth')
              .attr('src', e.target.result)
            bg_imggoth = e.target.result;
          };


          edit.readAsDataURL(input.files[0]);
        }
      }
    </script>

<?php require 'footer.php';
  }
} else {
  header("location:../logout.php");
}
?>