<!DOCTYPE html>
    <html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <title>Certificate</title>
        <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
        <link href="css/profile.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
            td {
                padding: 5px;
            }
        </style>
        <!-- <link rel="Shortcut Icon" type="image/x-icon" href="/images/Logo.png" /> -->
        <script>
            certificate = {}
            // certificate.shared = {}
            // certificate.contacts = {}
            // certificate.docs = {}
            certificate.v = {}
        </script>


        <script type="text/javascript" src="jsinclude/jquery-1.11.3.js"></script>
        <script type="text/javascript" src="jsinclude/jquery-ui.min.js"></script>

<!--
        <script type="text/javascript" src="jsinclude/modernizr.min.js"></script>
        <script type="text/javascript" src="jsinclude/jquery.md5.js"></script>
        <script type="text/javascript" src="jsinclude/jquery.cookie.js"></script>
        <script type="text/javascript" src="jsinclude/moment.min.js"></script>
        <script type="text/javascript" src="jsinclude/moment-timezone.js"></script>
-->
<!--         <script>
            if (location.protocol != "https:") {
                location.href = 'https://rephrecruiting.com/profile/';
            }
            if (location.href.indexOf("#") != -1) {
                if (location.href.length > 36) {
                    if ($.cookie("b") === 'n') {
                        history.pushState({}, null, '/profile/');
                    } else {
                        location.href = '#';
                    }
                }
            }

        </script> -->
        <script type="text/javascript" src="js/shared.js"></script>
    </head>

    <body>
            <div id="status"><span></span></div>
                <div id="header">
                    <img src="images/logo.jpg" id="logo" alt="" />
                    <br />
                    <br />
                    <br />

                    
                    <div id="menu" onClick=""></div>

                    <!-- <div id="logout" onclick="< ? echo urlLogout(); ? >">logout</div> -->
                    <div class="title">Gift Certificate Portal</div>
                </div>


                <br />
                <br />
                <br />
                <div id="main">
                    <div id="spreadsheet" style="float: right;" class="button"> <a href="index.php?">Back</a> </div>
                    <center>

                   <?
                        include('_functions.php');
                        if (isset($_GET['delete'])) {
                            deleteCertificate($_GET['id']);
                        }
                        if (isset($_GET['toggle'])) {
                            toggleCertificate($_GET['id'],$_GET['toggle']);
                        }


                        $data = spreadsheet();
                        if (!empty($data)) {
                            if (isset($_GET['manage'])) {
                                echo "<div class='button'><a href='spreadsheet.php?'>View</a></div>";
                            } else {
                                echo "<div class='button'><a href='?manage'>Manage Records</a></div>";
                            }
                    ?>
                    <table border="1">
                      <tr>

                        <?
                        if (isset($_GET['manage'])) {
                            echo"<th>delete</th>";
                        }
                        ?>

                        <th>ordernumber</th>
                        <th>first</th>
                        <th>last</th>
                        <th>email</th>
                        <th>ecard_number</th>
                        <th>value</th>
                        <th>used</th>
                        <?
                        if (isset($_GET['manage'])) {
                            echo"<th>toggle used</th>";
                        }
                        ?>
                      </tr>
                   <?}
                        // var_dump(count($data));
                        // echo count($data);
                        // var_dump(($data));
                        if (!empty($data)) {

                            foreach($data as $key => $item) {
                                if ($item['used']) {
                                    $used = 'NO';
                                } else {
                                    $used = 'YES';
                                }
                                echo "

                                  <tr>

                                    ";

                                    if (isset($_GET['manage'])) {
                                        $guid = "'" . $item['guid'] . "'";
                                        echo"<td><div class='deleterow' onClick=\"certificate.order.deleterow($guid);\"><img src='images/delete.png'></div></td>";
                                    }

                                    echo"

                                    <td>".$item['ordernumber']."</td>
                                    <td>".$item['first']."</td>
                                    <td>".$item['last']."</td>
                                    <td>".$item['email']."</td>
                                    <td>".$item['ecard_number']."</td>
                                    <td>$".$item['dvalue']."</td>
                                    <td>".$used."</td>";

                                    if (isset($_GET['manage'])) {
                                        if ($item['used']) {
                                            $guid = "'" . $item['guid'] . "',0";
                                            echo"<td><div class='togglerow' onClick=\"certificate.order.togglerow($guid);\"><img src='images/toggle_off.png' style='height:23px;width: 50px;'></div></td>";
                                        } else {
                                            $guid = "'" . $item['guid'] . "',1";
                                            echo"<td><div class='togglerow' onClick=\"certificate.order.togglerow($guid);\"><img src='images/toggle_on.png' style='height:23px;width: 50px;'></div></td>";
                                        }
                                    }


                                    echo"

                                  </tr>

                                ";
                            }
                echo"
                </table>
                ";

                        } else {
                            echo 'No Data';
                        }       
                   ?>
                    <div class="" onclick="certificate.order.doThisWhenDone('excel', 800, certificate.order.excel);" style="float: right;padding: 20px;">
                        <img src="images/excel.png" style="width: 100px;">
                        <br /> 
                        Download to Excel
                    </div>
                    </center>
            </div>

    <br />
    <br />
    
    </body>

    </html>