<?php

include_once '../include/include_class.php';
$musteriInclude = new IncludeClass();
$musteriInclude->musteriSil_controller();
if (isset($_SESSION['admin_id'])) {
    ?>
<!DOCTYPE html>

<html>
    <head>
    <meta charset="UTF-8">
    <title>Müşteri Güncelle</title>
    <?php 
    $bootstrap = new Bootstrap();
    $bootstrap->controller_vb();
    ?>
</head>
<body>
<?php 
    if ($_POST) {
        $header = new Header();
        $header->kokSayfa_header();
        $musteri = new Musteri();
        $musteri->setMusteriId(trim($_POST['musteriId']));
        $musteridao = new MusteriDAO();
        $musteridao->musteriSil($musteri);
    }
}
 function DoktorMusteri(Doktor $doktor)
 {
     $id = $doktor->getDoktorId();
     $musteriList = array();
     try {
         $baglanti = new VeriTabaniBaglanti();
         $conn = $baglanti->pdo_baglanti();
         $sorgu = $conn->query("Select *from musteri where doktor_id={$id} and randevuOnay=1");
         $rows = $sorgu->fetchAll(PDO::FETCH_CLASS);
         foreach ($rows as $row) {
             $musteri = new Musteri();
             $musteri->setAd($row->musteriAd);
             $musteri->setSoyad($row->musteriSoyad);
             $musteri->setRandevuTarihi($row->randevuTarihi);
             $musteri->setSaatId($row->saat_id);
             $musteri->setEmail($row->email);
             $musteri->setTel($row->tel);
             array_push($musteriList, $musteri);
         }
     } catch (Exception $ex) {
         die($ex->getMessage());
     } finally {
         if ($conn != null) {
             $conn = $baglanti->pdo_sonlandir();
         }
     }
     return $musteriList;
 }
 function __construct()
 {
     parent::__construct();
 }
        }
        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Randevuyu Onayla"></td>
            </tr>
        </table>
        </form>
    
    <?php 
        if (isset($_POST['musteriId1'])) {
            //echo  $_POST['musteriId1'];
            $musteri = new Musteri();
            $musteri->setMusteriId($_POST['musteriId1']);
            $musteri->setDoktorId($_POST['doktor']);
            $musteri->setRandevuTarihi($_POST['tarih']);
            $musteri->setSaatId($_POST['saat']);
            $musteri->setMesaj(trim($_POST['mesaj']));
            $musteri->setRandevuOnay(1);
            $musteridao = new MusteriDAO();
            $musteridao->randevuOnayla($musteri);
        }
    }
    $header->footer();
    ?>
</div>
</div>
</body>
 function MusteriDoktorGunGoster($tarih, $id)
 {
     $musteriList = array();
     try {
         $sutunlar = "id,musteriAd,musteriSoyad,email,tel,randevuTarihi,mesaj,saat_id,doktor_id,randevuOnay";
         $baglanti = new VeriTabaniBaglanti();
         $conn = $baglanti->pdo_baglanti();
         $tarihSorgu = $conn->query("select {$sutunlar}  from musteri where randevuTarihi='{$tarih}' and doktor_id={$id} and CURDATE()<=randevuTarihi ");
         $rows = $tarihSorgu->fetchAll(PDO::FETCH_CLASS);
         foreach ($rows as $row) {
             $musteri = new Musteri();
             $musteri->setMusteriId($row->id);
             $musteri->setAd($row->musteriAd);
             $musteri->setSoyad($row->musteriSoyad);
             $musteri->setEmail($row->email);
             $musteri->setTel($row->tel);
             $musteri->setRandevuTarihi($row->randevuTarihi);
             $musteri->setSaatId($row->saat_id);
             $musteri->setMesaj($row->mesaj);
             $musteri->setDoktorId($row->doktor_id);
             array_push($musteriList, $musteri);
         }
     } catch (Exception $ex) {
         die($ex->getMessage());
     } finally {
         if ($conn != null) {
             $conn = $baglanti->pdo_sonlandir();
         }
     }
     return $musteriList;
 }
 function randevuOnayla(Musteri $musteri)
 {
     //echo  $musteri->getMusteriId().' #'.$musteri->getDoktorId().' '.$musteri->getRandevuTarihi().' '.$musteri->getRandevuOnay() ;
     $bilgi = '<p style="color: red;">Bilgiler Günclenmedi</p>';
     try {
         $baglanti = new VeriTabaniBaglanti();
         $conn = $baglanti->pdo_baglanti();
         $guncelle = $conn->prepare("update musteri set randevuTarihi=?, saat_id=?, doktor_id=?, randevuOnay=?, mesaj=? where id=?");
         $sonuc = $guncelle->execute(array($musteri->getRandevuTarihi(), $musteri->getSaatId(), $musteri->getDoktorId(), $musteri->getRandevuOnay(), $musteri->getMesaj(), $musteri->getMusteriId()));
         if ($sonuc) {
             ?>
           <div class="form-signin" style="color: green; background-color: white;">
                  Randevu Onaylandı.
           </div>
         <?php 
             header("refresh:1;url=../musteriekle.php");
         } else {
             echo $bilgi = '<p style="color: red;">Hata Oluştu</p>';
         }
         //echo $sonuc;
     } catch (Exception $ex) {
         echo $bilgi = '<p style="color: red;">Hata Oluştu: ' . $ex->getMessage() . '</p>';
     } finally {
         if ($conn != null) {
             $conn = $baglanti->pdo_sonlandir();
         }
     }
     //return $bilgi;
 }
?>
<!DOCTYPE html>

<html>
    <head>
    <meta charset="UTF-8">
    <title>Doktor Müşteri</title>
    <?php 
$bootstrap = new Bootstrap();
$bootstrap->controller_vb();
?>
</head>
<body>
<?php 
if ($_POST) {
    $header = new Header();
    $header->kokSayfa_header();
    $musteri = new Musteri();
    $musteri->setAd(trim($_POST['ad']));
    $musteri->setSoyad(trim($_POST['soyad']));
    $musteri->setEmail(trim($_POST['email']));
    $musteri->setTel(trim($_POST['tel']));
    $musteri->setRandevuTarihi(trim($_POST['randevuTarihi']));
    $musteri->setSaatId(trim($_POST['saat']));
    $musteri->setMesaj($_POST['mesaj']);
    $musteridao = new MusteriDAO();
    $musteridao->musteriEkle($musteri);
}
?>
</body>
</html>