<?php 
    $data = array();
    $data['title'] = "Yeni Web Semineri | ".$App->title;
    $data['links'] = [];
    $data['styles'] = ['/admin/public/assets/css/jstable.css'];
    $data['header']['scripts'] = [];
    $data['version'] = $App->version;
    $data['csrf_token'] = $csrf_generator->create();
    $data['sidebar_menu'] = $menu->get(array('position'=>'sidebar'));
    $data['sidebar_active_menu'] = $menu->getActiveMenuItemId(trim($_SERVER['REQUEST_URI']));
    $data['footer']['scripts'] = ['/admin/public/assets/js/pages/webinar.js'];
    $menu_items = $menu->get(array('position'=>'footer'));
    foreach($menu_items as $item){
        if($item['col'] == "1"){
            $data['menu']['footer']["1"][] = $item;
        }
        if($item['col'] == "2"){
            $data['menu']['footer']["2"][] = $item;
        }
        if($item['col'] == "3"){
            $data['menu']['footer']["3"][] = $item;
        }
        if($item['col'] == "4"){
            $data['menu']['footer']["4"][] = $item;
        }
    }

    $data['breadcrumbs'] = array();
    $data['breadcrumbs'][] = array(
        'text' => "Pano",
        'href' => "/admin",
        'index' => 1
    );
    $data['breadcrumbs'][] = array(
        'text' => "Web Seminerleri",
        'href' => "/admin/course/list",
        'index' => 2
    );
    $data['breadcrumbs'][] = array(
        'text' => "Yeni Web Semineri",
        'href' => "#",
        'index' => 3
    );

    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $request = array(
            'topic' => $_POST['topic'],
            'agenda' => $_POST['agenda'],
            'duration' => $_POST['duration'],
            'start_time' => gmdate('Y-m-d\TH:i:s\Z', strtotime($_POST['start_time'])),
            'password' => $_POST['password'],
            'timezone' => $_POST['timezone'],
            'settings' => array(
                'contact_email' => $_POST['contact_email'],
                'approval_type' => isset($_POST['approval_type']) ? 0 : 2,
                'host_video' => isset($_POST['host_video']) ? true : false,
                'panelists_video' => isset($_POST['panelists_video']) ? true : false,
                'question_and_answer' => isset($_POST['question_and_answer']) ? array('enable'=>true, 'answer_questions'=>'all', 'attendees_can_comment'=> true, 'attendees_can_upvote'=> true) : array('enable'=>false),
                'practice_session' => isset($_POST['practice_session']) ? true : false,
                'auto_recording' => isset($_POST['auto_recording']) ? 'cloud' : 'none',
                'email_language' => $_POST['email_language'],
                'global_dial_in_countries' => array($_POST['global_dial_in_countries']),
                'post_webinar_survey' => isset($_POST['survey_url']) && !empty($_POST['survey_url']) ? true : false,
                'survey_url' => $_POST['survey_url']
            )
        );

        $result = $zoomApi->createWebinar($request);

        if(!$result){
            $session->data['messageType'] = "error"; 
            $session->data['messageTitle'] = "Hata!"; 
            $session->data['message'] = "Bir hata oluştu ve webinar vertitabanına kaydedilemedi."; 
            header("Refresh: 0;");
            exit();
        }else{
            $session->data['messageType'] = "success"; 
            $session->data['messageTitle'] = "Başarılı!"; 
            $session->data['message'] = "Webinar başarıyla kaydedildi."; 
            header("Location: /admin/webinar/edit?id=".$result['id']);
            exit();
        }
	}
    $surveys = $survey->getSurveys();
?>
<?php include DIR_VIEWS."parts/header.php"; ?>
        <main class="content">
        <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="tab-content" id="tab-content">
                            <div class="tab-pane fade active show" id="generalTab" role="tabpanel">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">Webinar Bilgileri</h5>
                                    </div>
                                    <div class="card-body">
                                        <form action="" method="post">
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label for="topic" class="form-label font-weight-bold">Başlık</label>
                                                </div>
                                                <div class="col-md-9 col-xl-10">
                                                    <input type="text" class="form-control" name="topic" id="topic" placeholder="Topic" value="">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label for="agenda" class="form-label font-weight-bold">Açıklama</label>
                                                </div>
                                                <div class="col-md-9 col-xl-10">
                                                    <textarea class="form-control" name="agenda" id="agenda" rows="6"></textarea>
                                                </div>
                                            </div>
                                            <hr>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label for="duration" class="form-label font-weight-bold">Süre</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <input type="text" class="form-control" name="duration" id="duration" placeholder="Süre" value="">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label for="start_time" class="form-label font-weight-bold">Başlangıç Tarihi</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <input type="datetime-local" class="form-control" name="start_time" id="start_time" value="">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label for="password" class="form-label font-weight-bold">Parola</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <input type="text" class="form-control" name="password" id="password" placeholder="Webinar Passcode" value="<?php echo rand(100000, 999999); ?>">
                                                </div>
                                            </div>
                                            <hr>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label for="contact_email" class="form-label font-weight-bold">İletişim Epostası</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <input type="text" class="form-control" name="contact_email" id="contact_email" placeholder="info@mustelaprofesyonel.com" value="info@mustelaprofesyonel.com">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label for="survey_url" class="form-label font-weight-bold">Anket Adresi</label>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="input-group mb-3">
                                                        <input type="url" class="form-control" name="survey_url" id="survey_url">
                                                        <button class="btn btn-outline-secondary" type="button" data-bs-toggle="modal" data-bs-target="#survey-modal">Seç</button>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label class="form-label font-weight-bold">Kimlik Doğrulama</label>
                                                </div>
                                                <div class="col-md-9 col-xl-10">
                                                    <div class="form-check">
                                                        <input type="checkbox" class="form-check-input" name="approval_type" id="approval_type" checked> <label for="approval_type" class="form-check-label">Panelistlerin katılmak için kimlik doğrulamasını gerektir</label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label class="form-label font-weight-bold">Video</label>
                                                </div>
                                                <div class="col-md-9 col-xl-10">
                                                    <div class="form-check">
                                                        <input type="checkbox" class="form-check-input" name="host_video" id="host_video" checked> <label for="host_video" class="form-check-label">Host</label>
                                                    </div>
                                                    <div class="form-check">
                                                        <input type="checkbox" class="form-check-input" name="panelists_video" id="panelists_video"> <label for="panelists_video" class="form-check-label">Panelistler</label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3 col-xl-2">
                                                    <label class="form-label font-weight-bold">Webinar Ayarları</label>
                                                </div>
                                                <div class="col-md-9 col-xl-10">
                                                    <div class="form-check">
                                                        <input type="checkbox" class="form-check-input" name="question_and_answer" id="question_and_answer" checked> <label for="question_and_answer" class="form-check-label">Soru Cevap</label>
                                                    </div>
                                                    <div class="form-check">
                                                        <input type="checkbox" class="form-check-input" name="practice_session" id="practice_session"> <label for="practice_session" class="form-check-label">Alıştırma Oturumunu Etkinleştir</label>
                                                    </div>
                                                    <div class="form-check">
                                                        <input type="checkbox" class="form-check-input" name="auto_recording" id="auto_recording" checked> <label for="auto_recording" class="form-check-label">Bulut Kaydı</label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-12 text-end">
                                                    <input type="submit" name="update" class="btn btn-primary" value="Kaydet">
                                                </div>
                                            </div>
                                            <input type="hidden" name="timezone" value="Europe/Istanbul">
                                            <input type="hidden" name="email_language" value="tr-TR">
                                            <input type="hidden" name="global_dial_in_countries" value="TR">
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <div class="modal" tabindex="-1" id="survey-modal">
            <div class="modal-dialog modal-dialog-centered">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title fw-bold">Anketler</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body p-0">
                        <table class="table table-striped table-hover table-sortable mb-0" id="survey-table">
                            <thead>
                                <tr>
                                    <th>Başlık</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(count($surveys)>0): ?>
                                    <?php foreach($surveys as $row): ?>
                                        <tr>
                                            <td><?php echo $row['title']; ?></td>
                                            <td><button class="btn btn-primary btn-sm survey-select" data-url="<?php echo $App->url; ?>/anket/<?php echo $row['guid']; ?>">Seç</button></td>
                                        </tr>
                                    <?php endforeach; ?>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Vazgeç</button>
                    </div>
                </div>
            </div>
        </div>
<?php include DIR_VIEWS."parts/footer.php"; ?>