<?php

include('views/_header.tpl.php');

if (isset($_GET['msg'])) {
    $msg = htmlentities(strip_tags($_GET['msg']));
}

?>

<style>
    #mmen { display:none; }
    div.spacer { padding-top: 45px; }
    .tinybutton { padding:3px 7px; background:#fff; width:65px;  min-width:65px;
        border-radius: 50px; -moz-border-radius: 50px; -webkit-border-radius: 50px; font-size:12px; }
        
     input.txt { font-size:17px; padding:25px; font-weight:300; }
     input[type="button"], input[type="submit"] { font-size:17px; padding:15px 25px; width: 150px; font-weight:300 !important; }
     
	 .form .txt { background: #f0f0f0; border: 0px; }
        
/* ###################################################### */
/* ####### The Switch - the box around the slider ####### */
/* ###################################################### */

.switch {
  position: relative;
  display: inline-block;
  width: 60px !important;
  height: 32px;
}

/* Hide default HTML checkbox */
.switch input {display:none;}

/* The slider */
.sliderr {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.sliderr:before {
  position: absolute;
  content: "";
  height: 28px;
  width: 28px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .sliderr {
  background-color: #98cb54;
}

input:focus + .sliderr {
  box-shadow: 0 0 1px #98cb54;
}

input:checked + .sliderr:before {
  -webkit-transform: translateX(28px);
  -ms-transform: translateX(28px);
  transform: translateX(28px);
}

/* Rounded sliders */
.sliderr.round {
  border-radius: 32px; -moz-border-radius: 32px; -webkit-border-radius: 32px;
}

.sliderr.round:before {
  border-radius: 50%;
  -moz-border-radius: 50%;
  -webkit-border-radius: 50%;
  
}
/* ##################################################### */
/* ##############     The Switch ENDS     ############## */
/* ##################################################### */              

 /* ######################################### */
/* ############     MOBILE      ############# */
/* ########################################## */

/* ################################### */
/* ##   Landscape phones and down   ## */
/* ################################### */

    /* @media screen and (max-device-width:  600px), screen and (max-width: 600px) { */
    @media (max-width: 600px) {
    .home-feature-category { margin-top:20px; }
}       
</style>

 <div class="home-feature-category" style="background:none; border:none; padding-top:0px;">
     <?php if(isset($_GET['msg'])) : ?>
     <div style="background:#cd1000; color:#fff; font-weight:300; height:25px; line-height:25px; margin-top:3px; text-align:center; padding:5px 0;">
         Saved Successfully! <a href="/admin/?square_var&edit=<?= $square_variation['id'] ?>" class="tinybutton">Ok!</a>
     </div>
     <?php endif; ?>

        <div class="container_12 clearfix" style="padding-top:7px;">
            
        <div class="grid_8 marked-category">
      
        <h1 style="margin-bottom:0px;"><?php
        
        if ($square_variation) {
            echo "Edit";
        } else {
            echo "Add";
            $def = "static/system/placeholder.jpg";
        }
        
        ?> Square Variation</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;">         
                <label class="lbl" for="txt_name1" style="text-align:left; width:50px; margin-right:5px;">ID:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="id" value="<?= $square_variation['id'] ?>" readonly>
                    <p class="rs description-input"></p>
                </div>        
            </div>
            <div class="row-item clearfix" style="padding-bottom:10px;">         
                <label class="lbl" for="txt_name1" style="text-align:left; width:50px; margin-right:5px;">Parent:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="parent_name" value="<?= $square_variation['parent_name'] ?>" readonly>
                    <p class="rs description-input"></p>
                </div>        
            </div>            
            <div class="row-item clearfix" style="padding-bottom:10px;">         
                <label class="lbl" for="txt_name1" style="text-align:left; width:50px; margin-right:5px;">SQID:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="square_item_id" value="<?= $square_variation['square_item_id'] ?>" readonly>
                    <p class="rs description-input"></p>
                </div>        
            </div>
               <div class="row-item clearfix" style="padding-bottom:10px;">         
                <label class="lbl" for="txt_name1" style="text-align:left; width:50px; margin-right:5px;">Var ID:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="square_item_variation_id" value="<?= $square_variation['square_item_variation_id'] ?>" readonly>
                    <p class="rs description-input"></p>
                </div>        
            </div>         
            <div class="row-item clearfix" style="padding-bottom:10px;">         
                <label class="lbl" for="txt_name1" style="text-align:left; width:50px; margin-right:5px;">Name:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="name" value="<?= $square_variation['name'] ?>" readonly>
                    <p class="rs description-input"></p>
                </div>        
            </div>        
 
 			<!-- EXTRA FIELD, LIKE FOR DIGITAL DOWNLOADS, ETC -->
            <div class="row-item clearfix" style="padding-bottom:10px;">         
                <label class="lbl" for="txt_name1" style="text-align:left; width:50px; margin-right:5px;">Link:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="extra" value="<?= $square_variation['extra'] ?>">
                    <p class="rs description-input"></p>
                </div>        
            </div>    
            
            <div class="row-item clearfix" style="padding-bottom:10px;">         
                <label class="lbl" for="txt_name1" style="text-align:left; width:50px; margin-right:5px;">@ Loc:</label>
                <div class="val" style="margin-left:0px;">
                    <textarea class="txt" type="text" style="font-size:12px; min-height:40px; height:auto" sreadonly><?= $square_variation['at_locations'] ?></textarea>
                    <input id="" class="txt" type="text" name="at_locations" value="<?= $square_variation['at_locations'] ?>" readonly 
                    style="font-size:12px; display:none;">
                    
                    <p class="rs description-input" style="margin-left:55px !important; color:#000; font-style:normal !important;">
                            <span style="color:#ff0000;">Locations this item/variation is carried at</span>
                            <br /><br />
                            <span style="font-size:18px;"><strong>IN STOCK AT THESE LOCATIONS</strong></span><br />
                            Note: If no locations are checked, that means <span style="color:#ff0000;">the item is carried at ALL locations.</span>   
                            
                            <?php    
                                     
                                    if (strpos($square_variation['at_locations'], 'FJQMA3B3NT0B2') !== false) {
                                        $checked_1 = "checked";
                                    } else {
                                        $checked_1 = "";
                                    }
                                    
                                    if (strpos($square_variation['at_locations'], '5ZXH0WQ6THAH5') !== false) {
                                        $checked_2 = "checked";
                                    } else {
                                        $checked_2 = "";
                                    }       
                                    
                                    if (strpos($square_variation['at_locations'], '247JV58NPBAQ7') !== false) {
                                        $checked_3 = "checked";
                                    } else {
                                        $checked_3 = "";
                                    }    
                                                                                                                              
                             ?>                                      
                            <br /><br />
                            <div style="font-size:17px; margin-left:55px; color:#000;">
							<?php foreach($square_variation['locations'] as $location) { ?>
								
								<input type="checkbox" name="at_locations[]" value="<?= $location['id'] ?>" <?= $checked_1 ?>> In-Stock @
								<strong><?= $location['name'] ?></strong> (<?= $location['id'] ?>)<br />
							<?php } ?>
                                
                <!-- ########### SWITCH FIELD STARTS HERE ########### -->
                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px; margin-top:12px; font-size:15px;">Out of Stock at ALL Locations?</label>
                    <div style="display:inline-block; float:left; width:auto; min-width:150px; height:41px; line-height:41px; background:none; padding-top:9px; margin-top:5px;">
                        <?php 
                            $is_excluded = !empty($square_variation['is_excluded']) ? " checked='checked'" : ""; 
                            $is_exclude = isset($square_variation['is_excluded']) ? 1 : 0;                            
                        ?>
                         <label class='switch'>                           
                           <input class='' id='' data-toggle='toggle' type='checkbox' name="is_excluded"<?= $is_excluded ?> /><span class='sliderr round'></span>
                         </label>                                          
                    </div>                         
                    <div class="clear"></div>         
                                             
                            </div>

                            <!--<br /><br />
                            <span style="color:#ff0000; font-size:17px;">FJQMA3B3NT0B2</span> (Damen) 
                             <br /><br />
                            <span style="color:#ff0000; font-size:17px;">5ZXH0WQ6THAH5</span> (Lincoln)
                             <br /><br />
                            <span style="color:#ff0000; font-size:17px;">247JV58NPBAQ7</span> (Madison)
                            <br /><br />
                            <span style="color:#ff0000; font-size:17px;">9DKTGDCEPCJ4H</span> (Roastery)                                                                                                        
                            <br /><br />
                            <span style="color:#ff0000; font-size:17px;">5YX758DGGCJ4J</span> (Farmer&rsquo;s Market)
                            <br /><br />-->
                          
                    </p>
                </div>        
            </div>      
             
            <br />
            <input type="submit" style="font-weight:300" class="btn btn-black" /> 
            <input type="button" value="Cancel" class="btn btn-black" onclick="location = '/admin/'" />
            <br /><br />
            
        </form>

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

<script type="application/javascript" >
    var barCheckBox = document.getElementById('bar').value;
    var clubCheckBox = document.getElementById('club').value;
    var searchBox = document.getElementById('at_locations').value;
    
    function updateAtLocations() {
        if (barCheckBox.checked) {
            searchBox.value += ' Bars';
        } else if (clubCheckBox.checked) {
            searchBox.value += ' Clubs';
        } else {
            searchBox.value = '';
        }
    }
</script>

<?php

include('views/_footer.tpl.php');

?>