<?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>
        <h3>Add New Sticker</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Stickers</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Add New Sticker</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Add New Sticker</h6>
                      <?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">
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="is_pro" id="is_pro-enabled" value="1">
                                <label class="form-check-label" for="is_pro-enabled">Premium</label>
                            </div>
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="is_pro" id="is_pro-disabled" value="0" checked="">
                                <label class="form-check-label" for="is_pro-disabled" class="m-l-20">Standard</label>
                            </div>
                        </div>
						<div class="form-group form-float">
							  <div class="form-line focused">
								<label class="form-label">Sticker File <small>only: .jpg,.jpeg,.png,.gif allowed</small></label>
								<div class="btn-file d-flex align-items-center">
									<input type="file" id="media_file" accept="image/x-png, image/gif, image/jpeg" name="media_file" class="hidden">
									<div class="mr-2 change-file-ico">
										<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M16.5,6V17.5A4,4 0 0,1 12.5,21.5A4,4 0 0,1 8.5,17.5V5A2.5,2.5 0 0,1 11,2.5A2.5,2.5 0 0,1 13.5,5V15.5A1,1 0 0,1 12.5,16.5A1,1 0 0,1 11.5,15.5V6H10V15.5A2.5,2.5 0 0,0 12.5,18A2.5,2.5 0 0,0 15,15.5V5A4,4 0 0,0 11,1A4,4 0 0,0 7,5V17.5A5.5,5.5 0 0,0 12.5,23A5.5,5.5 0 0,0 18,17.5V6H16.5Z"></path></svg>
									</div>
									<div class="full-width">
										<b id="wowonder-icon-name">Choose Sticker File</b>
									</div>
								</div>
							  </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 -->
<style type="text/css">
	.btn-file { position: relative; overflow: hidden;cursor: pointer;}
	.btn-file input[type=file] { position: absolute; top: 0; right: 0; min-width: 100%; min-height: 100%; font-size: 100px; text-align: right; opacity: 0; outline: none; background: #fff; cursor: inherit; display: block; }
	.change-file-ico {min-width: 36px;}
	.change-file-ico svg {border-radius: 50%;background: rgb(163 53 150 / 15%);color: #a33596;padding: 7px;width: 36px;height: 36px;}
	.full-width {width: 100%;}
	#wowonder-icon-name {font-weight: normal;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;display: block;}
</style>

<script>
	$("#media_file").change(function () {
		var filename = $(this).val().replace(/C:\\fakepath\\/i, '');
		$("#wowonder-icon-name").text(filename);
    });
</script>