<?php

/**
 * @author Pratik Dev <webmaster.pratik@gmail.com>
 */
require_once __DIR__ . '/../header.php';

$pathc = '';
if ($parentid = Input('cid')) {
    $pathc = '<li class="breadcrumb-item"><a href="../category/index.php">Home</a></li>';
    $db->where('id', $parentid);
    $category = $db->getOne(TABLE_CAT);
    $title = $category['name'];

    $parentids = array_filter(explode('/', $category['folder']));
    array_shift($parentids);

    if ($parentids) {
        $breadcrumbs = $db->where('id', $parentids, 'IN')->orderBy('id', 'ASC', $parentids)->get(TABLE_CAT);
        foreach ($breadcrumbs as $bread) {
            if ($bread['totalitem'] > 0 && $bread['subcate'] == 0)
                $pathc .= '<li class="breadcrumb-item"><a href="../files/index.php?cid=' . $bread['id'] . '">' . $bread['name'] . '</a></li>';
            else {
                $pathc .= '<li class="breadcrumb-item"><a href="../category/index.php?parentid=' . $bread['id'] . '">' . $bread['name'] . '</a></li>';
            }
        }
    }
?>
    <div class="container-fluid">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <?php echo $pathc; ?>
            </ol>
        </nav>
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <div class="d-flex justify-content-between">
                    <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-upload" aria-hidden="true"></i> Upload File</h6>
                </div>
            </div>
            <div class="card-body">
                <div class="alert alert-success alertDialog" style="display: none;" role="alert">
                </div>
                <div id="progressbar" class="progress mb-2" style="height: 25px;display:none">
                    <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="5" aria-valuemin="0" aria-valuemax="100" style="width: 5%">5%</div>
                </div>
                <form id="uploadform" action="createAction.php" method="post" enctype="multipart/form-data">
                    <div class="form-row">
                        <div class="from-group col-md-4">
                            <label for="File">File:</label>
                            <select name="filefrom" class="form-control" id="filefrom">
                                <option value="LOCAL">LOCAL</option>
                                <option value="EXTERNAL_LINK">URL</option>
                            </select>
                        </div>
                        <div id="file_display" class="form-group col-md-6">
                            <label for="file">File</label>
                            <div class="custom-file">
                                <label for="file" class="custom-file-label">Choose File</label>
                                <input type="file" class="custom-file-input" id="file" name="file" />
                            </div>
                        </div>
                        <div id="url_display" style="display: none;" class="form-group col-md-6">
                            <label for="File">URL:</label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="url" id="url" placeholder="Enter Valid URL">
                                <div class="input-group-append">
                                    <button type="button" data-toggle="modal" data-target="#importmodal" id="youtubeimport" type="button" class="btn btn-info">Import Youtube</button>
                                </div>
                            </div>
                        </div>
                        <div class="form-group col-md-6">
                            <label for="File">Name:</label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="filename" id="filename" placeholder="Title of File">
                            </div>
                        </div>
                        <div class="form-group col-md-6">
                            <label for="File">Slug:</label>
                            <div class="input-group">
                                <input type="text" class="form-control" value="" name="slug" id="slug">
                            </div>
                        </div>
                        <div class="from-group col-md-4">
                            <label for="File">Thumb:</label>
                            <select name="thumbfrom" class="form-control" id="thumbfrom">
                                <option value="LOCAL">LOCAL</option>
                                <option value="EXTERNAL_LINK">URL</option>
                            </select>
                        </div>

                        <div id="thumb_file_display" class="form-group col-md-6">
                            <label for="thumb">Thumb File:</label>
                            <div class="custom-file">
                                <label for="thumb" class="custom-file-label">Choose File</label>
                                <input type="file" name="thumb" class="custom-file-input" id="thumbfile" />
                            </div>
                        </div>
                        <div id="thumb_url_display" style="display: none;" class="form-group col-md-6">
                            <label for="File">Thumb URL:</label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="thumb_url" id="thumb_url" placeholder="Enter Valid URL">
                            </div>
                        </div>
                        <div class="col-md-3 text-center">
                            Watermark Postion:
                            <div>
                                <input type="radio" name="w_pos" value="top-left" checked>
                                <input type="radio" name="w_pos" value="top">
                                <input type="radio" name="w_pos" value="top-right"><br>
                                <input type="radio" name="w_pos" value="left">
                                <input type="radio" name="w_pos" value="center">
                                <input type="radio" name="w_pos" value="right"><br>
                                <input type="radio" name="w_pos" value="bottom-left">
                                <input type="radio" name="w_pos" value="bottom">
                                <input type="radio" name="w_pos" value="bottom-right"><br>
                            </div>
                        </div>

                        <div class="form-group col-md-4">
                            <label for="des">Artist:</label>
                            <input type="text" class="form-control tagsinput" name="artist" id="fileartist" placeholder="">
                        </div>
                        <div class="form-group col-md-4">
                            <label for="des">Release Date:</label>
                            <input type="date" class="form-control" name="release_date" id="release_date">
                        </div>
                        <div class="form-group col-md-12">
                            <label for="des">Description:</label>
                            <textarea name="description" id="description" class="form-control htmleditor"></textarea>
                        </div>
                        <div class="col-md-8 form-group">
                            <label for="name">Title</label>
                            <input type="text" name="meta_title" id="meta_title" class="form-control">
                        </div>

                        <div class="col-md-12 form-group">
                            <label for="meta_keyw">Keywords</label>
                            <input type="text" name="meta_keyw" id="meta_keyw" class="form-control">
                        </div>
                        <div class="col-md-12 form-group">
                            <label for="meta_des">Description</label>
                            <input type="text" name="meta_des" id="meta_des" class="form-control">
                        </div>
                        <div class="form-group col-md-2">
                            <label for="">Order:</label>
                            <input type="text" name="pos" id="pos" value="0" placeholder="" class="form-control">
                        </div>
                        <div class="form-group col-md-3 align-self-end">
                            <label for="appname">New Badge <small>(Added Home)</small></label>
                            <input type="checkbox" class="form-control" data-toggle="switch" name="new_tag" value="1" checked />
                        </div>
                        <div class="form-group col-md-3 align-self-end">
                            <label for="appname">Trend:</label>
                            <input type="checkbox" class="form-control" data-toggle="switch" name="trend" value="1" />
                        </div>
                        <div class="form-group col-md-3 align-self-end">
                            <label for="status">Status:</label>
                            <input type="checkbox" class="form-control" data-toggle="switch" name="status" value="1" checked />
                        </div>
                    </div>
                    <div class="row justify-content-end">
                        <button type="submit" id="submit" class="btn btn-primary" name="submit" value="submit">Submit</button>
                    </div>
                </form>
            </div>

        </div>
    </div>

    <div class="modal fade" id="importmodal" tabindex="-1" role="dialog" aria-labelledby="importmodal" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Import Mp3 from Youtube Video</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="input-group">
                        <input type="text" class="form-control" id="youtube_query" placeholder="Enter Youtube URL">
                        <div class="input-group-append"><button type="button" class="btn btn-primary" id="movieSearch"><i class="fa fa-search" aria-hidden="true"></i></button></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

<?php } else {
    echo '<div class="alert">Category ID Missing << <a href="../index.php"> Home</a></div> 
';
}
?>
<?php
require_once __DIR__ . '/../footer.php';
?>