<?php 
include('views/_header.tpl.php'); 
if (isset($_GET['msg'])) {
	$msg = htmlentities(strip_tags($_GET['msg']));
}
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; }	
	.cke_contents {
		max-height: 150px !important;
		height: 150px !important;
	}	
</style>

		<?php
		if (isset($saved)) {
			echo "<div class='saved' />$saved &nbsp;&nbsp;&nbsp; <a href='/admin/?table&edit={$menu['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/menus">&laquo; Back</a> | <?php
        
        if ($menu) {
            echo "Edit";
        } else {
            echo "Add";
			$def = "/static/images/placeholderimgg.jpg";
        }
		// onerror="this.src='/static/images/placeholderimgg.jpg'"
        ?> Menu</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;">
            
               Here is the QR Code that you can share, so people go straight to your PDF Menu
               
                <br /><br />
                <?php 
                    require_once '3rdparty/phpqrcode/qrlib.php';
                    
                    $PNG_TEMP_DIR = dirname(__FILE__,3).DIRECTORY_SEPARATOR.'3rdparty/phpqrcode/menus'.DIRECTORY_SEPARATOR;
                    $PNG_WEB_DIR = '3rdparty/phpqrcode/menus/';
                    $fname = 'WeeklyMenu-' . $menu['order_ref'] . '.png';
                    $filename2 = __DIR__ . '/../../3rdparty/phpqrcode/menus/' . $fname;
                    $filename = $PNG_TEMP_DIR.$fname;
                    
//                    $qr_string = array(
//                        'type' => 'table',
//                        'tableno' => $menu['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 . '/' . $menu['pdf'];
					//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=".$menu['tableno']."' in Safari";
					$qrString = "Open '".$url."' in Safari to view Menu PDF";
		            //echo $qrString;                  
                    
                    QRcode::png($qrString, $filename);
                
                    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="<?= $menu['qrcode_img'] ?>" 
                style="max-width:800px; 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 Menu QR Codes).            
                </div>
                                 
                 <br />
                 
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Date:</label>
				<div class="val" style="margin-left:0px; margin-top:11px">
					<?= $menu['order_at'] ?>
					<!--<p class="rs description-input"></p>-->
				</div>
				<br />                
                     
                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Title:</label>
                <div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="title" value="<?= $menu['title'] ?>">
                    <p class="rs description-input"></p>
                </div>

                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Status:</label>
                <div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="order_status" value="<?= $menu['order_status'] ?>">
                    <p class="rs description-input"></p>
                </div>
                
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Ref:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="order_ref" value="<?= $menu['order_ref'] ?>">
					<p class="rs description-input"></p>
				</div>    
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Inv:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="order_invoice" value="<?= $menu['order_invoice'] ?>">
					<p class="rs description-input"></p>
				</div>
	
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Legend:</label>
				<div class="val" style="margin-left:0px;">
					<textarea class="txt" name="legend" id="ckeditor" class="ckeditor"><?= $menu['legend'] ?></textarea>
					<p class="rs description-input"></p>
				</div>   				
					
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Inv:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="order_invoice" value="<?= $menu['order_invoice'] ?>">
					<p class="rs description-input"></p>
				</div>		
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Notes:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="notes" value="<?= $menu['notes'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Order By:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="order_by" value="<?= $menu['order_by'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Deliv:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="deliv_on" value="<?= $menu['deliv_on'] ?>">
					<p class="rs description-input"></p>
				</div>		
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Period:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="period" value="<?= $menu['period'] ?>">
					<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;">
			           <option value="">Select Type</option>
			           <option value="Table" <?php if($menu['type'] == 'Table') echo "selected"; ?>>Table</option>
			           <option value="Station" <?php if($menu['type'] == 'Station') echo "selected"; ?>>Station</option>     
			       </select>                 
                    <p class="rs description-input"></p>
                </div>-->
                
                <br />
				<a href="/<?= $menu['pdf'] ?>" title="View PDF"><img src="/static/system/pdf_icon.png" 
				style="height:60px;" alt="PDF" /></a> Link for this Menu PDF (will open in a new browser tab).
				<br /><br />
				<b>Menu PDF Path:</b><br />
				https://<?php echo $site_root ?>/<?= $menu['pdf'] ?>
                
            </div>
            <br />
            <input type="submit" style="font-weight:300" class="btn btn-black" />
            <br /><br /> 
            <input type="button" value="Cancel" class="btn btn-black" onclick="location = '/admin/menus'" />
        </form>

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

<script src="/3rdparty/ckeditoradv/ckeditor.js?<?php echo rand() ?>"></script>

<script>
	CKEDITOR.editorConfig = function( config ) {
		config.height = '20vh';
	};

	//	$(function() {
	//		CKEDITOR.config.height = '20vh';
	//	});
	//	$(function() {
	//		CKEDITOR.config.height = '20vh';
	//	});
	//	CKEDITOR.editorConfig = function( config ) {
	//		// Define changes to default configuration here. For example:
	//		// config.language = 'fr';
	//		// config.uiColor = '#AADC6E';
	//		config.height = '20vh';
	//	};
	CKEDITOR.replace( 'ckeditor' ,{
		config.height : '20vh';
	});
</script>

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