<?php 
include('views/_header.tpl.php'); 
if (isset($_GET['saved'])) {
	//$msg = htmlentities(strip_tags($_GET['msg']));
	$saved = "Saved Successfully!";
}
?>
<style>
	#mmen { display:none; }
	.spacer { padding-top:57px; }
	.form .row-item .val { margin-bottom:10px; }
	.form .row-item .lbl { min-width:70px; margin-top:5px; }
	.form .txt { font-weight:300; }
	.btn { padding: 15px 25px; font-size:15px;  font-weight:300; margin-right:10px; }
	.saved  {
		background:#cd1000; margin-top:2px; color:#fff; text-align:center; padding:10px; font-size:15px;
	}
	.saved a, .saved a:active, .saved a:visited { background:#fff;  color:#28d52d; border-radius:50px; padding:3px 10px; font-weight:800; }
	.saved a:hover { color:#fff;  background:#28d52d; }

	.rounded { border-radius: 50px; -moz-border-radius: 50px; -webkit-border-radius: 50px; padding-left:20px; padding-right:20px; }	
</style>

<?php
	if (isset($saved)) {
		echo "<div class='saved' />$saved &nbsp;&nbsp;&nbsp; <a href='/admin/?table&edit={$table['id']}'>Ok</a></div>";
	}
?>

 <div class="home-feature-category" style="background:none; border:none;">
        <div class="container_12 clearfix">
        <div class="grid_8 marked-category">

        <h1 style="margin-bottom:0px;"><a href="/admin/tables">&laquo; Back</a> | <?php
        
        if ($table) {
            echo "Edit";
        } else {
            echo "Add";
            $def = "/static/uploads/placeholder.jpg";
        }
        
        ?> Table/Station</h1>

        <form method="post" class="form form-profile" enctype="multipart/form-data" style="padding:25px 0px 0px;">
            <div class="row-item clearfix" style="padding-bottom:10px; font-size:17px; color:#000; font-weight:300; line-height:25px;">
            
                When a Customer scans this QR Code it&rsquo;ll load their Table or Station Number so when they submit orders via
                your website or app, your crew will know where they&rsquo;re sitting.
                This Table/Station # is <span style="font-weight:600;"><?= $table['tableno'] ?></span>
                <br /><br />
                <?php 
                    require_once '3rdparty/phpqrcode/qrlib.php';
                    
                    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'tables'.DIRECTORY_SEPARATOR;
                    $PNG_WEB_DIR = '3rdparty/phpqrcode/tables/';
                    $fname = 'table-' . $table['tableno'] . '.png';
                    $filename2 = __DIR__ . '/../../3rdparty/phpqrcode/tables/' . $fname;
                    $filename = $PNG_TEMP_DIR.$fname;
                    
//                    $qr_string = array(
//                        'type' => 'table',
//                        'tableno' => $table['tableno']
//                    );
                    
//                    $qrString = json_encode($qr_string);
					// we might not need this
					if (!empty($_SERVER['SERVER_NAME'])) {
						$site_root = $_SERVER['SERVER_NAME'];
					} else {
						$site_root = $_SERVER['HTTP_HOST'];
					}
		            $url = 'https://' . $site_root . '/shop?tbl='.$table['tableno'];
					//echo "URL: " . $url;
		            
//					$qrs = "Open '".$url."' in Safari";
//					echo "URL: " . $qrs;
		            //$qr_string = array(
		            //    'website' => 'https://preorder.sqdash.co/'.$page['slug'],
		            //);
		            //echo "<br />"; 
		            //$qrString = json_encode($qr_string);
		            //$qrString = "Open 'https://preorder.sqdash.co/shopp?tbl=".$table['tableno']."' in Safari";
					$qrString = "Open '".$url."' in Safari";
		            //echo $qrString;                  
                    
                    QRcode::png($qrString, $filename2);
                
                    echo '<img src="/'.$PNG_WEB_DIR.basename($filename).'" style="max-width:200px;" />';  
               ?>
                <br /><br />
                Path to QR Code Image File:<br />
                <input class="txt" type="text" name="qrcode_img" value="<?= $table['qrcode_img'] ?>" 
                style="max-width:600px; margin-top:7px; margin-bottom:7px;" readonly>
                <br />
                <div style="font-size:14px; line-height:22px;">                	
	                Note: You can&rsquo;t edit this image path. It&rsquo;s generated automatically and only meant for 
	                copy/paste (to help you easily share, print or post your Table/Station QR Codes).            
                </div>
                                 
                 <br />
                     
                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">ID:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="id" value="<?= $table['id'] ?>">
                    <p class="rs description-input"></p>
                </div>

                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Table #:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="tableno" value="<?= $table['tableno'] ?>">
                    <p class="rs description-input"></p>
                </div>
                      
                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Type:</label>
                <div class="val" style="margin-left:0px;">
			       <select name="type" id="" class="txt" type="number" style="background:#fff;" <!--name="projectid"-->>
			           <option value="">Select Type</option>
			           <option value="Table" <?php if($table['type'] == 'Table') echo "selected"; ?>>Table</option>
			           <option value="Station" <?php if($table['type'] == 'Station') echo "selected"; ?>>Station</option>     
			       </select>                 
                    <p class="rs description-input"></p>
                </div>
                
                <br />
                Admin System Link (for this Table/Station): <?= $table['link'] ?> 
                
            </div>
            <br />
            <input type="submit" style="font-weight:300" class="btn btn-blue" /> 
            <input type="button" value="Cancel" class="btn btn-blue" onclick="location = '/admin/tables'" />
        </form>

        </div>
    </div>
</div>

<?php include('views/_footer.tpl.php'); ?>