<?php 

function cp_edit_quiz_cb() {
	if(!isset($_GET['id'])) return_method();
  $post = new post;
  $quiz_meta = $post->get_post_meta($_GET['id']); 
	$all_terms = get_select_options_from_post_q(['type' => 'academic_term'], 'term_name');
	$modes = get_option('mode_of_scoring');
	if(!$modes) {
		echo "Please set mode of scoring first";
		return false;
	}
	if(!_count($modes)) {
		echo "Please set mode of scoring first";
		return false;
	}
	foreach ($modes as $k => $v) {
		$mode = explode(',', $v);
		$mode = trim_array($mode);
		$mode_arr[$mode[0]] = $mode[0];
	}
	?>
	<div class="card" id="add-lesson-container">
        <div class="card-header">
            <span class="badge badge-warning pull"><?php echo get_class_name($quiz_meta['class']) ?></span></br><span class="badge badge-success"><?php echo get_course_name($quiz_meta['course']) ?></span>
        </div>
        <div class="card-body">
        
            <form id="add-lesson-form" method="post" action="contents/plugins/classroom_plus/ajax.php">
                <input type="hidden" name="class" id="class" value="<?php echo $quiz_meta['class']; ?>">
                <input type="hidden" name="course" id="course" value="<?php echo $quiz_meta['course']; ?>">
                <input type="hidden" name="id" id="id" value="<?php echo $quiz_meta['id']; ?>">
                <div class="row">
                    <div class="col-md-6">
                        <?php 
							select(['label' => 'Term/Session', 'id' => 'term', 'required' => 'required'], $all_terms, $quiz_meta['term']);
                         ?>
                    </div>
                    <div class="col-md-6">
                        <?php 
							select(['label' => 'Test type', 'id' => 'test', 'required' => 'required'], $mode_arr, $quiz_meta['test']);
                         ?>
                    </div>
                    <div class="col-sm-6">
                    	<?php 
							checkbox(['label' => 'Solve Online', 'id' => 'solve_online'], $quiz_meta['solve_online']);
                         ?>
                    </div>
                    <div class="col-sm-6">
                    	<?php 
							checkbox(['label' => 'Shuffle Questions', 'id' => 'shuffle_questions'], $quiz_meta['shuffle_questions']);
                         ?>
                    </div>
                    <div class="col-sm-6">
                    	<?php 
							input(['label' => 'Time Allowed<br />(in Minutes)', 'id' => 'time_allowed', 'required' => 'required', 'value' => $quiz_meta['time_allowed'], 'class' => 'form-control numbers-only']);
                         ?>
                    </div>
                    <div class="col-sm-6">
                    	<?php 
							input(['label' => 'Maximum<br />Questions', 'id' => 'max_questions', 'required' => 'required', 'value' => $quiz_meta['max_questions'], 'class' => 'form-control numbers-only']);
                         ?>
                    </div>
                    <?php 
                    	do_action("search_query_filter_date_range_only", ['from' => $quiz_meta['from'], 'to' => $quiz_meta['to'], 'class' => 'col-md-6']);
                     ?>
                    <div class="col-md-12">
                    	<?php 
			                textarea(['label' => 'Instructions', 'id' => 'instructions', 'value' => $quiz_meta['instructions']]);
			                submit_btn('edit_quiz');
			             ?>
                    </div>
            </form>
                
        </div>
    </div>
	<?php
	global $post_meta;
	add_page_javascript('app/assets/js/page-scripts/submit.js');
	add_page_javascript('app/assets/js/page-scripts/koweb.js');
}