<?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,'gifts');
        if (!empty($media)) {
            $filename = $media['filename'];
        }

        $name = Secure($_POST['gift_name']);
        $media_file = Secure($filename);

        $query  = mysqli_query($conn, "INSERT INTO `gifts` (`name`, `media_file`, `time`) VALUES ('".$name."','".$media_file."','".time()."')");
        if ($query) {
            $succuss = '<i class="fa fa-fw fa-check"></i> ' . __('Gift added');
        } else {
            $error = '<i class="fa fa-fw fa-exclamation-triangle"></i> ' . __('Error while add gift');
        }
    }else{
        $error = '<i class="fa fa-fw fa-exclamation-triangle"></i> ' . __('Error while add gift');
    }
}

?>

<div class="container-fluid">
    <div class="block-header">
        <h2>Gifts > Add New Gift</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="header">
                    <h2>Add New Gift </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-gift'); ?>" method="POST">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="gift_name" name="gift_name" class="form-control">
                                <label class="form-label">Gift Name</label>
                            </div>
                        </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">Gift 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 Gift</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->