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

$formname = 'Contact';
$maindb = 'contact';
$printfile = "contact_fr.php";
$file = 'contact.php';
$trandbexist = 0;
$keyfld = "code";

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

if (isset($_POST["submit"])) {
    $a = 1;
    $name1 = $_POST["name1"];
    $name2 = $_POST["name2"];
    $email1 = $_POST["email1"];
    $email2 = $_POST["email2"];
    $mob1 = $_POST["mob1"];
    $mob2 = $_POST["mob2"];
    $address = $_POST["address"];
    $facebook = $_POST["facebook"];
    $instagram = $_POST["instagram"];
    $twitter = $_POST["twitter"];
    $tel = mysqli_real_escape_string($_POST["tel"]);
    $map = $_POST["map"];

    $mvouch = $qvouch;

    if ($a == 1) {
        ############################## MAIN  ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`code`, `name1`, `name2`, `email1`, `email2`, `mob1`, `mob2`, `address`, `tel`, `map`, `facebook`, `instagram`, `twitter`)
                                        VALUES($qvouch, '$name1', '$name2', '$email1', '$email2', '$mob1', '$mob2', '$addrerss','$tel', '$map', '$facebook', '$instagram', '$twitter')") 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 `name1`='$name1', `name2`='$name2', `email1`='$email1', `email2`='$email2', `mob1`='$mob1',
                                `mob2`='$mob2', `address`='$address', `tel`='$tel', `map`='$map', `facebook`='$facebook',
                                `instagram`='$instagram', `twitter`='$twitter'  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='$getvouch'") 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");
?>
</head>
<body>
    <!--    <div id="preloader" class="col-lg-12 text-center">
            <h3 class="text-center">Loading</h3>
            <div id="status">&nbsp;</div>
        </div>-->
    <form action='' method='POST' enctype="multipart/form-data">
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-10">
                <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>
                            <i class="fa fa-times"></i>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Name1</label>
                            </div>
                            <div class="col-lg-4 pad">
                                <input type="text" class="form-control form focusfield" name="name1" value="<?php Echo ($addflag != 1) ? $get["name1"] : ""; ?>" required>
                            </div>
                            <div class="col-sm-2 text-right pad">
                                <label class="label-control marg">Name2</label>
                            </div>
                            <div class="col-sm-4 pad">
                                <input type="text" class="form-control form focusfield" name="name2" value="<?php Echo ($addflag != 1) ? $get["name2"] : ""; ?>">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">E-mail 1</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="email1" value="<?php Echo ($addflag != 1) ? $get["email1"] : ""; ?>">
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">E-mail 2</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="email2" value="<?php Echo ($addflag != 1) ? $get["email2"] : ""; ?>">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Mobile No. 1</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="mob1" value="<?php Echo ($addflag != 1) ? $get["mob1"] : ""; ?>" required>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Mobile No. 2</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="mob2" value="<?php Echo ($addflag != 1) ? $get["mob2"] : ""; ?>" required>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Address</label>
                            </div>
                            <div class="col-lg-6 col-md-9 col-sm-9 col-xs-9 pad">                           
                                <textarea class="form" rows="4" cols="50" name="address"> <?php Echo ($addflag != 1) ? $get["address"] : ""; ?> </textarea>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Tel nos.</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="tel" value="<?php Echo ($addflag != 1) ? $get["tel"] : ""; ?>">
                            </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">Note :</label>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                                <ol>
                                    <li>Go to Google maps.</li>
                                    <li>Open Your map</li>
                                    <li>Click On Share.</li>
                                    <li>Click On Embed</li>
                                    <li>Click On sizes on left</li>
                                    <li>Select Custom Size</li>
                                    <li>Input Size 600 X 450</li>
                                    <li>Copy The Link</li>
                                    <li>Paste It In The Form</li>
                                </ol>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Map </label>
                            </div>
                            <div class="col-lg-6 col-md-9 col-sm-9 col-xs-9 pad">                           
                                <textarea class="form" rows="4" cols="50" name="map"> <?php Echo ($addflag != 1) ? $get["map"] : ""; ?> </textarea>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Facebook</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="facebook" value="<?php Echo ($addflag != 1) ? $get["facebook"] : ""; ?>">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Instagram</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="instagram" value="<?php Echo ($addflag != 1) ? $get["instagram"] : ""; ?>">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Twitter</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" class="form-control form " name="twiter" value="<?php Echo ($addflag != 1) ? $get["twiter"] : ""; ?>">
                            </div>
                        </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>
    </form>
    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="table table-responsive">
                        <table id="example1" class="table table-striped">
                            <thead>
                                <tr style="background-color: #E7B315;">
                                    <th>Sr</th>
                                    <th>Header</th>
                                    <th>Description</th>
                                    <th>Image</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($addflag != 1) {
                                    $srchresult = mysqli_query($conn, "SELECT * FROM `$maindb`")or die(mysqli_error($conn));
                                    while ($row = mysqli_fetch_array($srchresult)) {
                                        echo "<tr class='clickable-row' data-href='$file?mode=edit&$keyfld=$row[$keyfld]'>";
                                        echo "<td class='numeric'>$row[code]</td>";
                                        echo "<td>$row[header]</td>";
                                        echo "<td>$row[para]</td>";
                                        echo "<td><img src='$row[image]' style='width: 50px;height:50px'></td>";
                                        echo "</tr>";
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("../includes/linksfoot.php"); ?>
</body>
</html>
