<?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="?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>';
            }
        }
    }
} else {
    $pathc .= '<li class="breadcrumb-item"><a href="../index.php">Home</a></li>';
    $pathc .= '<li class="breadcrumb-item"><a href="index.php">Files</a></li>';
    $parentid = "";
    $title = "Files";
}
if (Input('userid')) {
    if ($data = $db->where('id', Input('userid'))->getOne('users')) {
        $title = $data['user_name'] . ' All Uploaded Files';
    }
}

?>
<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"><?php echo $title; ?></h6>
            </div>
        </div>
        <div class="card-body">

            <div class="row">
                <div class="col-md-6">
                    <h6 class="m-0 font-weight-bold">Showing By: <span class="text-danger showingby">All Files</span></h6>
                </div>
                <div class="col-md-6">
                    <div class="row justify-content-end">
                        <div class="dropdown mr-2">
                            <button class="btn btn-dark dropdown-toggle" type="button" id="ActionB" data-toggle="dropdown" aria-expanded="false">
                                Actions
                            </button>
                            <div class="dropdown-menu" aria-labelledby="ActionB">
                                <a class="approveAll dropdown-item" href="#">Approve Selected</a>
                                <a class="restoreAll dropdown-item" href="#">Restore Selected</a>
                                <a class="trashedAll dropdown-item" href="#">Trash Selected</a>
                            </div>
                        </div>
                        <div class="dropdown mr-2">
                            <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-expanded="false">
                                Show
                            </button>
                            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                <a class="showall dropdown-item" href="#">All Files</a>
                                <a class="showpending dropdown-item" href="#">Pending Files</a>
                                <a class="showtrashed dropdown-item" href="#">Trashed Files</a>
                            </div>
                        </div>
                        <?php
                        if ($parentid)
                            if ($category['subcate'] == 0) : ?>
                            <div class="btn-group m-1 m-sm-0" role="group" aria-label="button-group">
                                <a href="../files/create.php?cid=<?php echo $parentid; ?>" class="btn btn-info"><i class="fas fa-upload" aria-hidden="true"></i> Upload File</a>
                                <a href="../files/multi.php?cid=<?php echo $parentid; ?>" class="btn btn-primary ml-1"><i class="fas fa-cloud-upload-alt" aria-hidden="true"></i> Multiple Upload</a>

                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <div class="table-responsive" id="fileTable" data-filter="ALL">
                <table id="datalist" name="files" class="table table-striped table-bordered files" width="100%" cellspacing="0">
                    <thead class="bg-info text-white">
                        <tr>
                            <th>Id</th>
                            <th>Thumb</th>
                            <th>Title</th>
                            <th>User</th>
                            <th>Category/Album</th>
                            <th>Artist</th>
                            <th>Ext</th>
                            <th>Size</th>
                            <th>Download</th>
                            <th>Order</th>
                            <th>ApprovedAt</th>
                            <th>DeletedAt</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modalform" tabindex="-1" role="dialog" aria-labelledby="Modal" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <form id="changetag">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modal-title"></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="form-row">
                        <div class="form-group col-md-6">
                            <label for="">Title</label>
                            <input type="text" name="title" id="title" class="form-control">
                        </div>
                        <div class="form-group col-md-6">
                            <label for="artist">Artist</label>
                            <input type="text" name="artist" id="singer" class="form-control">
                        </div>
                        <div class="form-group col-md-6">
                            <label for="album">Album</label>
                            <input type="text" name="album" id="album" class="form-control">
                        </div>
                        <div class="form-group col-md-6">
                            <label for="year">Year</label>
                            <input type="text" name="year" id="year" class="form-control">
                        </div>

                        <div class="form-group col-md-6">
                            <label for="Phone">Comment</label>
                            <input type="text" name="comment" id="comment" class="form-control">
                        </div>

                        <div class="from-group col-md-6">
                            <label for="File">Album Art (id3v2)::</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">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" accept="image/*" />
                            </div>
                        </div>
                        <div id="thumb_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="thumb_url" id="thumb_url" placeholder="Enter Valid URL">
                            </div>
                        </div>


                    </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" name="id" id="id" />
                    <input type="hidden" name="submit" id="action" />
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <button type="submit" id="submit" class="btn btn-primary">Submit</button>
                </div>
            </div>
        </form>
    </div>
</div>
<?php
require_once __DIR__ . '/../footer.php';
?>