<?php include_once 'header.php'; ?>

<?php
global $func;

$cart_info = $session->get('cart_info');

if($_SERVER['REQUEST_METHOD']=='POST' && $func->post('quantity')) {
    if(!$func->post('quantity')['adult'] && !$func->post('quantity')['child']){
        $error->set('Geçerli bir ürün adedi girilmedi!');
        $location->redirect('index');
    }
    $session->set('quantity',$func->post('quantity'));
    getHtml($func->post('quantity'),$cart_info);
}else{
    if(!$session->get('quantity')) {
        $error->set('Geçerli bir ürün adedi girilmedi!');
        $location->redirect('index');
    }else{
        getHtml($session->get('quantity'),$cart_info);
    }
}

?>

<?php

    function getHtml($count,$cart_info){
        //echo '<pre>';print_r($count);die();
        $html = '<section id="cart-page" class="content-section text-center">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <form action="payment.php" method="POST" class="form-horizontal" role="form" id="SaleForm">
                        <div class="row">';
        $x=1;
        foreach ($count as $key=>$item) {
            $kart_type = $key=='adult'?'YETİŞKİN':'ÖĞRENCİ';
            for ($i = 1; $item >= $i; $i++) {
                $html .= '<fieldset>
                                    <div class="col-md-12">
                                        <h5>' . $x . '. Bilet Bilgisi</h5>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>Adınız:</label></div>
                                            <div class="col-sm-8"><input type="text" data-requery="true" data-error="Bir isim girmelisiniz!" name="cart_info[' . $x . '][name]" placeholder="Adı" id="name" required class="form-control" value="' . (isset($cart_info[$x]['name']) ? $cart_info[$x]['name'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>Soyadınız:</label></div>
                                            <div class="col-sm-8"><input type="text" data-requery="true" data-error="Bir soyadı girmelisiniz!" name="cart_info[' . $x . '][lastname]" placeholder="Soyadı" required id="lastname" class="form-control" value="' . (isset($cart_info[$x]['lastname']) ? $cart_info[$x]['lastname'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>TC Kimlik Numarası:</label></div>
                                            <div class="col-sm-8"><input type="text" data-requery="true" data-error="TC Kimlik Numarası girmelisiniz!" name="cart_info[' . $x . '][tc_no]" placeholder="TC Kimlik Numarası" required id="tc_no" class="form-control" value="' . (isset($cart_info[$x]['tc_no']) ? $cart_info[$x]['tc_no'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>Adresiniz:</label></div>
                                            <div class="col-sm-8"><input type="text" data-requery="true" data-error="Bir adres girmelisiniz!" name="cart_info[' . $x . '][addres]" placeholder="Adres " required id="addres" class="form-control" value="' . (isset($cart_info[$x]['addres']) ? $cart_info[$x]['addres'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>Cep Telefonu:</label></div>
                                            <div class="col-sm-8"><input type="tel" data-requery="true" data-error="Bir cep telefonu girmelisiniz!" name="cart_info[' . $x . '][telephone]" placeholder="Telefon No" required id="telephone" class="form-control" value="' . (isset($cart_info[$x]['telephone']) ? $cart_info[$x]['telephone'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>Ev Telefonu:</label></div>
                                            <div class="col-sm-8"><input type="tel" data-requery="true" data-error="Bir ev telefonu girmelisiniz!" name="cart_info[' . $x . '][home_telephone]" placeholder="Ev Telefon No" required id="home_telephone" class="form-control" value="' . (isset($cart_info[$x]['home_telephone']) ? $cart_info[$x]['home_telephone'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>E-Mail Adresiniz:</label></div>
                                            <div class="col-sm-8"><input type="email" name="cart_info[' . $x . '][email]" placeholder="Email" required id="email" class="form-control" value="' . (isset($cart_info[$x]['email']) ? $cart_info[$x]['email'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>Doğum Tarihiniz:</label></div>
                                            <div class="col-sm-8"><input type="text" name="cart_info[' . $x . '][birthdate]" placeholder="20/10/1986" required id="birthdate" class="form-control" value="' . (isset($cart_info[$x]['birthdate']) ? $cart_info[$x]['birthdate'] : '') . '"/></div>
                                        </div>
                                        <div class="form-row mb-3">
                                            <div class="col-sm-4"><label>Kart Tipi:</label></div>
                                            <div class="col-sm-8">'.$kart_type.' <input type="hidden" name="cart_info[' . $x . '][kart_type]" id="kart_type" class="form-control" value="' . $key . '"/></div>
                                        </div>
                                    </div>
                                </fieldset>';
                $x++;
            }
        }
                            $html.='<div class="clearfix"></div>
                                <div class="form-group">
                                <div class="col-sm-12">
                                    <div class="pull-right">
                                        <button type="submit" onclick="return registerValidate(\'#SaleForm\');" class="btn btn-primary" id="qSend">Satın Al</button>
                                    </div>
                                </div>
                            </div>                     
                        </form>
                    </div>
                </div>
            </div>
        </section>';
        echo $html;
    }
?>
<?php include_once 'footer.php'; ?>