<?php
ob_start();
require("../includes/check_auth_user.php");
require("../includes/dbconnect.php");
include('../includes/function.php');

$formname = 'About us';
$maindb = 'about';
$printfile = "";
$file = 'aboutus.php';
$trandbexist = 0;
$keyfld = "code";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
//mysql_select_db($zdb);
include("../includes/vouchno_generate.php");
include("../includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;
    $para1 = $_POST["para1"];
    $para2 = $_POST["para2"];
    $para3 = $_POST["para3"];
    $image = $_POST["image"];

    $mvouch = $qvouch;

    if ($a == 1) {
        $path = "MyImages/about/";

        #####################IMAGE#####################
        $filename1 = $mvouch . ".jpg";
        $img_file1 = $path . ($filename1);
        $image_ftype = pathinfo($img_file1, PATHINFO_EXTENSION);

        $uploadOk = 1;

        if ($uploadOk == 1) {
            move_uploaded_file($_FILES["image"]["tmp_name"], $img_file1);
        } else {
            browse("Sorry, there was an error uploading your file.");
            header("refresh: 1; $file?mode=last");
        }

        ############################## MAIN  ######################################################
        $getimage = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `code`='$mvouch'")or die(mysqli_error($conn));
        $gimage = mysqli_fetch_array($getimage);

        ############################## MAIN  ######################################################
        if ($gimage == "") {
            mysqli_query($conn,"INSERT INTO `$maindb`(code, `image`, `para1`, `para2`, `para3`)
                                        VALUES($qvouch, '$img_file1', N'$para1',N '$para2', N'$para3')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $qvouch; //1
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch; //1

            mysqli_query($conn,"UPDATE `$maindb` SET `image`='$img_file1', `para1`=N'$para1', `para2`=N'$para2', `para3`=N'$para3'
                               WHERE code = '$mvouch' ") or die(mysqli_error($conn));
            updmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }
    }
}

if ($addflag != 1) {

    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }

    $result = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE $keyfld='1'") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
}

$senable = "";
$cenable = "";


if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}

include("../includes/linkshead.php");
?>
<script src="MyScript/about.js" type="text/javascript"></script>
</head>
<body>
    <form action='' method='POST'  enctype="multipart/form-data">
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-8">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php Echo $formname; ?></h3>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">About Wolfit Bag</label>
                            </div>
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 pad">
                                <textarea class="form-control form textarea" name="para1" cols="50" rows="10"><?php Echo ($addflag != 1) ? $get["para1"] : ""; ?></textarea>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Why Us</label>
                            </div>
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 pad">
                                <textarea class="form-control form textarea" name="para2" cols="50" rows="10"><?php Echo ($addflag != 1) ? $get["para2"] : ""; ?></textarea>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Products And Serives</label>
                            </div>
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 pad">
                                <textarea class="form-control form textarea" name="para3" cols="50" rows="10"><?php Echo ($addflag != 1) ? $get["para3"] : ""; ?></textarea>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Image</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="file" class="btn btn-warning form image" name="image" id="image">
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <img class="view1" src="<?php Echo ($addflag != 1) ? $get['image']."?a=".mt_rand() : "" ?>" style="padding: 10px; border: #E7B315 solid 1px;" alt="Image 1" />
                            </div>
                        </div>
                        <div class="panel-footer">
                            <div style="overflow: auto; ">
                                <table class="table-condensed" style="margin: 0 auto;">
                                    <tr>
                                        <td class=" buttonform tooltip-bottom" id="hadd" style="display: <?
                                        if ($get['code'] == 1 || $addflag == 1) {
                                            Echo "none";
                                        }
                                        ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Add Record" >
                                            <button id='add' type="button" class="btn btn-pad btn-square " style="background-color:#C0CA33; " onclick="window.location.href = '<?= $file . "?mode=true" ?>'" class="btn btn-labeled btn-success ">
                                                <i class="fa fa-plus" style="color:#ffffff"></i>    
                                            </button>
                                        <td class=" buttonform tooltip-bottom" id="hedit" style="display: <? Echo $editdisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Edit Record">
                                            <button id='edit' type="button" style="background-color:#F0AD4E; " class="btn btn-pad btn-square">
                                                <i class="fa fa-pencil" style="color:#ffffff"></i>
                                            </button>
                                        </td>
                                        <td class=" buttonform tooltip-bottom" id="ssubmit" style="display: <? Echo $savedisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Save Record">
                                            <button id='submit' type='submit' name='submit' value='<?php echo ($addflag == 0) ? "Update" : "Save"; ?>' class="btn btn-pad btn-square " style="background-color:#008D4C; ">
                                                <i class="fa fa-check" style="color:#ffffff"></i>
                                            </button>
                                        </td>
                                        <td class=" buttonform tooltip-bottom" id="scancel" style="display: <? Echo $canceldisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Cancel Record">
                                            <button id='cancel' type="button" class="btn btn-pad btn-square " style="background-color:#39CCCC; "  onClick="window.location.href = '<?= $file . "?mode=last" ?>'">
                                                <i class="fa fa-times" style="color:#ffffff"></i>
                                            </button>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <?php include("../includes/linksfoot.php"); ?>
</body>
</html>
