<?PHP
$auth = false;
$authID = 'EAE5972B-83F4-2760-1CCC-96C6F52BAF0D';
if (isset($_COOKIE["guid"])) {
    if ($_COOKIE["guid"] === $authID) {
        $auth = true;
    }
}
if (isset($_POST["username"]) && isset($_POST["password"])) {
    if ($_POST["username"] === 'sales' && $_POST["password"] === '7ab1f81c336ef987a09842fa12638631') {
        $auth = true;
    }
}
// $.md5(md5)
// $.cookie("guid")
// $.cookie("guid", 0, { path: '/projects/certificates', expires: 8000 });
if ($auth) {
    setcookie("guid",$authID,time() + (10 * 365 * 24 * 60 * 60));
?>
<!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;
            }
            .editrecords {
                display: none;
            }

        </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/jquery.cookie.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>
        <script type="text/javascript" src="js/xferAudit.js"></script>
        <script type="text/javascript" src="js/spreadsheet.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"><a href="/certificates/?">eGift Card Portal</a></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('_functions2.php');
                        if (isset($_GET['delete'])) {
                            deleteCertificate($_GET['id']);
                        }
                        if (isset($_GET['toggle'])) {
                            toggleCertificate($_GET['id'],$_GET['toggle']);
                        }


                        $data = spreadsheet2();
                        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>";
                            }
                    ?>

                    <div class='button viewbutton' onclick="$('.managebutton').css('display','inline-block');$(this).css('display','none');$('.editrecords').css('display','none');" style="display: none;">View</div>
                    <div class='button managebutton' onclick="$('.viewbutton').css('display','inline-block');$(this).css('display','none');$('.editrecords').css('display','table-cell');">Manage Records</div>
                    <div id='columns' style="float: left; background-color: gainsboro;">
                        <span id='columntext' class="button" onclick="$('.columnselect').css('display','inline-block');$(this).css('display','none');$('#search').css('display','none');">Columns</span>
                        <div class="columnselect" style="display: none; width: 200px;">
                        <span id='searchclose' onclick="$('.columnselect').css('display','none');$('#columntext').css('display','inline-block');$('#search').css('display','block');" style="float:right;color: crimson;">X</span>
                            <div id="columncheckboxes" class="fieldarea">
                                </br><input type="checkbox" id="week" name="week" checked> <label for="week">week</label>
								</br><input type="checkbox" id="created" name="created" checked> <label for="created">created</label>
								</br><input type="checkbox" id="order" name="order" checked> <label for="order">order</label>
								</br><input type="checkbox" id="first" name="first" checked> <label for="first">first</label>
								</br><input type="checkbox" id="last" name="last" checked> <label for="last">last</label>
								</br><input type="checkbox" id="email" name="email" checked> <label for="email">email</label>
								</br><input type="checkbox" id="ecard" name="ecard" checked> <label for="ecard">ecard</label>
								</br><input type="checkbox" id="value" name="value" checked> <label for="value">value</label>
								</br><input type="checkbox" id="transfer" name="transfer" checked> <label for="transfer">transfer</label>
								</br><input type="checkbox" id="tip" name="tip" checked> <label for="tip">tip</label>
								</br><input type="checkbox" id="emailed" name="emailed" checked> <label for="emailed">emailed</label>
								</br><input type="checkbox" id="gift" name="gift" checked> <label for="gift">gift</label>
								</br><input type="checkbox" id="cardtype" name="cardtype" checked> <label for="cardtype">cardtype</label>
								</br><input type="checkbox" id="modified" name="modified" checked> <label for="modified">modified</label>
								</br><input type="checkbox" id="used" name="used" checked> <label for="used">used</label>
                               

                                <br />
                                <div class="button" onclick="certificate.spreadsheet.showAll();">Show All</div>
                            </div>
                        </div>
                    </div>
                	</br>
                	</br>

                    <div id='search' style="float: left; background-color: gainsboro;">
                        <span id='searchtext' class="button" onclick="$('.searchselect').css('display','inline-block');$(this).css('display','none');$('#columns').css('display','none');document.getSelection().removeAllRanges();">Search</span>
                        <div class="searchselect" style="display: none; width: 200px;">
                        <span id='searchclose' onclick="$('.searchselect').css('display','none');$('#searchtext').css('display','inline-block');$('#columns').css('display','block');document.getSelection().removeAllRanges();" style="float:right;color: crimson;">X</span>
                            <div class="fieldarea">
                                <select id="searchfield">

                                  <option value="week">week</option>
                                  <option value="created">created</option>

                                  <option value="order">order</option>
                                  <option value="first">first</option>
                                  <option value="last">last</option>
                                  <option value="email">email</option>
                                  <option value="ecard">ecard</option>
                                  <option value="value">value</option>
                                  <option value="transfer">transfer</option>

                                  <option value="tip">tip</option>
                                  <option value="emailed">emailed</option>
                                  <option value="gift">gift</option>
                                  <option value="cardtype">cardtype</option>
                                  <option value="modified">modified</option>

                                  <option value="used">used</option>
                                </select>
                                <br />
                                <input type="text" name="searchvalue" id="searchvalue">
                                <br /> <label for="savesearch">Save Search? </label> <input type="checkbox" id="savesearch" name="savesearch" checked> 
                                <br /><div class="button" onclick="certificate.order.search($('#searchfield option:selected').text(),$('#searchvalue').val());">Search</div>
                                <div class="button" onclick="certificate.order.showall();">Show All</div>
                            </div>
                        </div>
                    </div>
                    </br>
                    </br>
                    <div id="loading"><img src="images/gears.gif"></div>
                    <table id="datatable" border="1" style="display: none;">
                      <tr>

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



                        <th class='editrecords'>delete</th>

                        <th class='created'>created</th>

                        <th class='order'>ordernumber</th>
                        <th class='first'>first</th>
                        <th class='last'>last</th>
                        <th class='email'>email</th>
                        <th class='ecard'>ecard_number</th>
                        <th class='value'>value</th>
                        <th class='transfer'>transfer</th>

                        <th class='tip'>tip</th>
                        <th class='emailed'>emailed</th>
                        <th class='gift'>gift</th>
                        <th class='cardtype'>cardtype</th>
                        <th class='modified'>modified</th>

                        <th class='used'>used</th>
                        <th class="editrecords">toggle used</th>
                        <?
                        if (false && isset($_GET['manage'])) {
                            echo"<th>toggle used</th>";
                        }
                        ?>
                      </tr>
                   <?}
                        // var_dump(count($data));
                        // echo count($data);
                        // var_dump(($data));
                        if (!empty($data)) {
                            $i = 0;
                            foreach($data as $key => $item) {
                                $rowID = 'row_' . $i;
                                if ($item['used']) {
                                    $used = 'YES';
                                } else {
                                    $used = 'NO';
                                }
                                echo "

                                  <tr id='$rowID'>

                                    ";

                                    if (false && 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 class='editrecords' ><div class='deleterow' onClick=\"certificate.order.deleterow($guid);\"><img src='images/delete.png'></div></td>";


                                    $xfer = wasTransferred($item['guid']);
                                    if ($xfer) {
                                        $xferClass = 'button';
                                        $xferReseachButton = 'onclick="certificate.xfer.research('.$item['ordernumber'].');" ';
                                        $isXfer = "Yes <span class='button' ".$xferReseachButton.">View History</span>";
                                    } else {
                                        $xferClass = '';
                                        $xferReseachButton = '';
                                        $isXfer = 'No';
                                    }
                                    if ($item['cardtype'] === 1) {
                                    	$cardtype = 'Gold';
                                    } else {
                                    	$cardtype = 'Black';
                                    }

                                    echo"
                                    <td class='created'>".$item['created']."</td>

                                    <td class='order'>".$item['ordernumber']."</td>
                                    <td class='first'>".$item['first']."</td>
                                    <td class='last'>".$item['last']."</td>
                                    <td class='email'>".$item['email']."</td>
                                    <td class='ecard'>".$item['ecard_number']."</td>
                                    <td class='value'>".$item['dvalue']."</td>
                                    <td class='transfer'>".$isXfer." </td>

                                    <td class='tip'>".$item['tip']."</td>
                                    <td class='emailed'>".$item['esend']."</td>
                                    <td class='gift'>".$item['gift']."</td>
                                    <td class='cardtype'>".$cardtype."</td>
                                    <td class='modified'>".$item['modified']."</td>
                                    
                                    <td class='used'>".$used."</td>";



                                    if ($item['used']) {
                                        $guid = "'" . $item['guid'] . "',0";
                                        echo"<td class='editrecords' ><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 class='editrecords' ><div class='togglerow' onClick=\"certificate.order.togglerow($guid);\"><img src='images/toggle_on.png' style='height:23px;width: 50px;'></div></td>";
                                    }



                                    if (false && 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>

                                ";
                                $i++;
                            }
                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 />
    <script type="text/javascript">
        $('tr').each(function() {
            if (typeof $(this).attr('id') === 'undefined') {
                $(this).prepend('<th class="week">week</th>')
            } else {
                $(this).prepend('<td class="week">'+certificate.spreadsheet.woyPrint($(this).find('.created').text())+'</td>')
            }
        });
        certificate.spreadsheet.update();
        certificate.order.restoreSearch();
        $('#loading').css('display','none');
        $('#datatable').css('display','table');
    </script>
    </body>

    </html>
<?
} else {
    @include('login.php');
} 
?>

