<?php include_once('includes/header.php'); ?>
<script src="assets/plugins/ckeditor/ckeditor.js"></script>

<?php 

    if (isset($_POST['submit'])) {

        $radio_image = time().'_'.$_FILES['radio_image']['name'];
        $radio_image_tmp = $_FILES['radio_image']['tmp_name'];
        $file_path = 'upload/'.$radio_image;
        copy($radio_image_tmp, $file_path);

        $data = array(
            'category_id'   => clean($_POST['category_id']),         
            'radio_name'    => clean($_POST['radio_name']),
            'radio_image'   => $radio_image,
            'radio_url'     => clean($_POST['radio_url']),
            'radio_description' => $_POST['radio_description'],
            'featured'      => clean('0'),
            'type'          => clean($_POST['type'])
        );

        $qry = insert('tbl_radio', $data);                                    
        
        $_SESSION['msg'] = 'Radio added successfully...';
        header( "Location:radio-add.php");
        exit;

    }

    $sql_category = "SELECT * FROM tbl_category";
    $category_result = mysqli_query($connect, $sql_category);

?>

<section class="content">

	<ol class="breadcrumb">
		<li><a href="dashboard.php">Dashboard</a></li>
		<li><a href="radio.php">Manage Radio</a></li>
		<li class="active">Add Radio</a></li>
	</ol>

	<div class="container-fluid">

		<div class="row clearfix">
			<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">

				<form id="form_validation" method="post" enctype="multipart/form-data">
					<div class="card corner-radius">
						<div class="header">
							<h2>ADD RADIO</h2>
						</div>
						<div class="body">

							<?php if(isset($_SESSION['msg'])) { ?>
							<div class='alert alert-info alert-dismissible corner-radius' role='alert'>
								<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span>&nbsp;&nbsp;</button>
								<?php echo $_SESSION['msg']; ?>
							</div>
							<?php unset($_SESSION['msg']); } ?>                            

                            <div class="row clearfix">

                                <div class="col-sm-6">

                                    <div class="form-group">
                                        <div class="font-12">Radio Name</div>
                                        <div class="form-line">
                                            <input type="text" class="form-control" name="radio_name" id="radio_name" placeholder="Radio Name" required>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="font-12">Category</div>
                                        <select class="form-control show-tick" name="category_id" id="category_id">
                                            <?php while ($data = mysqli_fetch_array ($category_result)) { ?>
                                            <option value="<?php echo $data['cid'];?>"><?php echo $data['category_name'];?></option>
                                            <?php } ?>
                                        </select>
                                    </div>

                                    <div class="form-group">
                                        <div class="font-12">Type</div>
                                        <select class="form-control show-tick" name="type" id="type">
                                            <option value="radio">Radio</option>
                                            <option value="mp3">MP3</option>
                                        </select>
                                    </div> 

                                    <div class="form-group">
                                        <div class="font-12">Radio URL</div>
                                        <div class="form-line">
                                            <input type="text" class="form-control" name="radio_url" id="radio_url" placeholder="ex : http://live.radiorodja.com/ or http://202.147.199.100:8000/" required/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="font-12 ex1">Image ( JPG, JPEG, PNG or GIF )</div>
                                        <input type="file" name="radio_image" id="radio_image" class="dropify-image" data-max-file-size="3M" data-allowed-file-extensions="jpg jpeg png gif" required/>
                                    </div>

                                </div>

                                <div class="col-sm-6">
                                    <div class="font-12">Description *</div>
                                    <div class="form-group" style="margin-top: 6px;">
                                        <textarea class="form-control" name="radio_description" id="radio_description" class="form-control" cols="60" rows="10" required></textarea>
                                        <?php if ($ENABLE_RTL_MODE == 'true') { ?>
                                        <script>                             
                                            CKEDITOR.replace( 'radio_description' );
                                            CKEDITOR.config.contentsLangDirection = 'rtl';
                                            CKEDITOR.config.height = 338;
                                        </script>
                                        <?php } else { ?>
                                        <script>                             
                                            CKEDITOR.replace( 'radio_description' );
                                            CKEDITOR.config.height = 338;
                                        </script>
                                        <?php } ?>
                                    </div>
                                </div>

                                <div class="form-group col-sm-12">
                                    <button type="submit" name="<?php if (validateResourceAccess($inputToken)) { echo 'submit'; } else { echo 'validate'; } ?>" class="button button-rounded waves-effect waves-float pull-right">SUBMIT</button>
                                </div>

                            </div>

						</div>
					</div>
				</form>

			</div>
		</div>

	</div>

</section>

<?php include_once('includes/footer.php'); ?>