Your IP : 18.216.91.156


Current Path : /data/web/virtuals/51568/virtual/www/www/plany.bak/
Upload File :
Current File : /data/web/virtuals/51568/virtual/www/www/plany.bak/planyPlany.php

<?php
  if (file_exists('funkce/DbConnect.php')){
     require_once('funkce/DbConnect.php');
  }
  if (file_exists('../../funkce/DbConnect.php')){
     require_once('../../funkce/DbConnect.php');
  }
  if (!IsSet($idRok)){
      if (IsSet($_POST["idRok"])){$idRok = $_POST["idRok"];}
  }
?>


<hr>
<div class="h4">Plány</div>
<div class="row my-2">

  <div class="col">
    <button class="btn btn-info rounded-0" id="plNovyBtn">Nový
    </button>
  </div>
  <div class="col text-right">  
    <button class="btn btn-success rounded-0" id="plTiskBtn">Tisk
    </button>
  </div>
</div>
<div id="plLzeEdit" class="row mb-2">
  <div class="col">
    <button id="btnPlEdit" class="btn btn-outline-info rounded-0">Editovat</button>
  </div>
  <div class="col text-right">
    <button id="btnPlDel" class="btn btn-outline-danger rounded-0">Smazat</button>
  </div>
</div>

<div id="plany" class="table-scroll-container-40 mb-3 table-scroll" style="min-width: 220px; max-width: 220px;">
  <div id="containerNovyPlan"></div>
  <div id="containerSmazatPlan" class="d-none">
    <div class="alert alert-danger rounded-0">
      <div class="h5">Mazání</div>
      <p>Chystáš se smazat plán. Texty (a týdny), které jsou přiřazeny k plánu, zůstanou zachovány.</p>
      <p>Chceš pokračovat? </p>
      <div class="row mt-2">
        <div class="col">
          <button id="btnDelAno" class="btn btn-danger btn-sm  rounded-0">Ano</button>
        </div>
        <div class="col text-right">
          <button class="btn btn-success btn-sm rounded-0" id="btnDelNe">Ne</button>
        </div>
      </div>
    </div>
  </div>
  <?php

  $sql = "SELECT pp.id, MIN(pt.zacatek) as zacatek, MAX(pt.zacatek) as konec from pl_plany pp join pl_tydny pt on pt.idplan = pp.id "
       ."where pp.idrok = $idRok GROUP by pp.id order by zacatek desc";        
  $result = mysqli_query($conn, $sql);
  if ($row =  mysqli_fetch_object($result)) {
  $pocet = 0;
  if ($row->id > 0) { ?>
  <table class="table table-striped table-bordered table-sm ">
    <?php   do {
          $pocet++;
          $checked = false;
          if($pocet == 1) {$checked = true;  $idPlan = $row->id;}  
          $checkedS = ($checked) ? "checked" : "";         
                    ?>
    <tr <?php echo ($checked) ?  "id='aktualni'" : ""; ?>>
      <td>
        <div class="custom-control custom-radio ml-1 pr-0">
          <input type="radio" class="custom-control-input" id="rgPlanZobr<?php echo $row->id; ?>" name="rgPlanZobr"
            <?php echo $checkedS; ?>>
          <label class="custom-control-label" for="rgPlanZobr<?php echo $row->id; ?>">
            <?php echo date('d.m.', strtotime($row->zacatek));?> -
            <?php echo date('d.m.Y', strtotime("+6 day", strtotime($row->konec)));?>
          </label>
        </div>
      </td>
    </tr>
    <?php  } while ($row =  mysqli_fetch_object($result)); ?>
  </table>
  <?php ;}
  }
  ?>
</div>


<script src="www/plany/funkce.js"></script>
<script>
  $(document).ready(function () {

    $("#btnPlDel").on("click", function () {
      $("#containerSmazatPlan").removeClass("d-none");
      $("#containerNovyPlan").addClass("d-none");
    })

    $("#btnDelNe").on("click", function () {
      $("#containerSmazatPlan").addClass("d-none");
    })

    $("#btnDelAno").on("click", function () {
      $("#containerSmazatPlan").addClass("d-none");
      var idPlan = rgKod("rgPlanZobr");
      $.ajax({
        url: "www/plany/planyPlanySmaz.php",
        type: 'POST',
        data: {
          'idPlan': idPlan,
        },
        success: function (result) {
          $.ajax({
            url: "www/plany/planyPlany.php",
            type: 'POST',
            data: {
              'idRok': '<?php echo $idRok; ?>',
            },
            success: function (result) {
              $("#idListPlans").html(result);
              $.ajax({
                url: "www/plany/planyNahled.php",
                type: 'POST',
                data: {
                  'idPlan': 0,
                  'idRok': '<?php echo $idRok; ?>',
                },
                success: function (result) {
                  $("#main").html(result);

                }
              })
            }
          })

        }
      })
    })

    $("#plNovyBtn").on('click', function () {
      $("#containerSmazatPlan").addClass("d-none");
      $("#containerNovyPlan").removeClass("d-none");
      $.ajax({
        url: "www/plany/planyPlanyNovy.php",
        type: 'POST',
        data: {
          'idRok': '<?php echo $idRok; ?>',
          'akce': 'n'
        },
        success: function (result) {
          $("#containerNovyPlan").html(result);
        }

      })
    })

    $("#btnPlEdit").on('click', function () {
      $("#containerSmazatPlan").addClass("d-none");
      $("#containerNovyPlan").removeClass("d-none");
      var idPlan = rgKod("rgPlanZobr");
      $.ajax({
        url: "www/plany/planyPlanyNovy.php",
        type: 'POST',
        data: {
          'idRok': '<?php echo $idRok; ?>',
          'idPlan': idPlan,
          'akce': 'e'
        },
        success: function (result) {
          $("#containerNovyPlan").html(result);
          idPlan = result;

        }

      })
    })

    $('[id^="rgPlanZobr"]').on('click', function () {
      $("#containerNovyPlan").addClass("d-none");
      $("#containerSmazatPlan").addClass("d-none");
      let idPlan = rgKod("rgPlanZobr");

      $.ajax({
        url: "www/plany/planyNahled.php",
        type: 'POST',
        data: {
          'idPlan': idPlan
        },
        success: function (result) {
          $("#main").html(result);
          $.ajax({
            url: "www/plany/planyJeAktualni.php",
            type: 'POST',
            data: {
              'idPlan': idPlan
            },
            success: function (result) {
              result = result.trim();
              if (result == idPlan) {
                $("#plLzeEdit").removeClass("d-none")
              } else {
                $("#plLzeEdit").addClass("d-none");
              }
            }
          })
        }
      })

    })

    $('#plTiskBtn').on('click', function (event) {
      $("#containerNovyPlan").addClass("d-none");
      $("#containerSmazatPlan").addClass("d-none");
      let idPlan = rgKod("rgPlanZobr");
      event.preventDefault();
      event.stopPropagation();
      let targetAttr = 'tisk';
      let linkHref = 'www/plany/planyTisk.php?idPlan=' + idPlan;
      window.open(linkHref, targetAttr);
    });


  })
</script>