<?php
global $conn;
$error = '';
$succuss = '';

if (isset($_FILES['media_file'])) {
    if(!empty($_FILES['media_file']["tmp_name"])){
        $filename = "";
        $fileInfo = array(
            'file' => $_FILES["media_file"]["tmp_name"],
            'name' => $_FILES['media_file']['name'],
            'size' => $_FILES["media_file"]["size"],
            'type' => $_FILES["media_file"]["type"],
            'types' => 'jpg,png,gif,jpeg'
        );
        $media    = ShareFile($fileInfo,0,false,'stickers');
        if (!empty($media)) {
            $filename = $media['filename'];
        }
        $media_file = Secure($filename);
        $is_pro = (isset($_POST['is_pro']) ? Secure($_POST['is_pro']) : '0');

        $query  = mysqli_query($conn, "INSERT INTO `stickers` (`file`, `is_pro`, `created_at`) VALUES ('".$media_file."', '".$is_pro."','".date('Y-m-d H:i:s')."')");
        if ($query) {
            $succuss = '<i class="fa fa-fw fa-check"></i> ' . __('Sticker added');
        } else {
            $error = '<i class="fa fa-fw fa-exclamation-triangle"></i> ' . __('Error while add sticker');
        }
    }else{
        $error = '<i class="fa fa-fw fa-exclamation-triangle"></i> ' . __('Error while add sticker');
    }
}

?>

<div class="container-fluid">
    <div class="block-header">
        <h2>Stickers > Add New Sticker</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="header">
                    <h2>Add New Sticker </h2>
                </div>
                <div class="body">
                      <?php if (!empty($error)) { ?>
				      <div class="alert alert-danger">
				      	<?php echo $error;?>
				      </div>
				      <?php } ?>
				      <?php if (!empty($succuss)) { ?>
				      <div class="alert alert-success">
				      	<?php echo $succuss;?>
				      </div>
				      <?php } ?>
                    <form class="" enctype="multipart/form-data" action="<?php echo Wo_LoadAdminLinkSettings('add-new-sticker'); ?>" method="POST">
                        <label for="emailValidation">Sticker type
                            <span class="black" data-toggle="popover" data-trigger="hover" data-content="if you choose Premium. Sticker will be visible only for Premium users" data-original-title="" title="">
                                <i class="fa fa-question-circle fa-fw"></i>
                            </span>
                        </label>
                        <div class="form-group">
                            <input type="radio" name="is_pro" id="is_pro-enabled" value="1">
                            <label for="is_pro-enabled">Premium</label>
                            <input type="radio" name="is_pro" id="is_pro-disabled" value="0" checked="">
                            <label for="is_pro-disabled" class="m-l-20">Standard</label>
                        </div>

                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="file" id="media_file" name="media_file" class="form-control">
                                <label class="form-label">Sticker File <small>only: .jpg,.jpeg,.png,.gif allowed</small></label>
                            </div>
                        </div>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Add Sticker</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->