<?php 

function assign_courses_cb() {
	global $post_meta;
	$post = new post;
	$classes = $post->get_post_by_meta_data(['type' => 'class']);
	$courses = $post->get_post_by_meta_data(['type' => 'course']);
	if(_count($classes) < 1)
		return_method('add-class');
	if(_count($courses) < 1)
		return_method('add-courses');
	$course_mapping = get_option('course_mapping');
	$category_mapping = get_option('category_mapping');
	?>
	<div class="row">
		<div class="col-md-12">
			<div class="card card-primary">
				<div class="card-header">
					<h3 class="card-title">Assign Courses/Subjects to Classes</h3>
				</div>
				<div class="card-body">
					<form id="form" action="contents/plugins/eedu_portal/ajax.php" method="post">
						<?php 
							foreach ($classes as $class_meta) {
								if(_count($category_mapping[$class_meta['id']])) {
									foreach ($category_mapping[$class_meta['id']] as $category_id) {
										select(['label' => $class_meta['class_name'].' '.get_category_name($category_id), 'id' => $class_meta['id'].'-'.$category_id, 'name' => 'courses['.$class_meta['id'].']['.$category_id.'][]', 'multiple' => 'multiple'], get_select_options_from_post($courses, 'course_name', 'id', false), $course_mapping[$class_meta['id']][$category_id]);
									}
								}
							}
							 ?>
						<?php alert(); submit_btn('assign_courses', 'Save Mapping'); ?>
					</form>
				</div>
			</div>
		</div>
	</div>
	<?php
	add_page_javascript('app/assets/js/page-scripts/submit.js');
}