<?php include 'include/header.php';?>

    <body class="fixed-left">
        
        <!-- Begin page -->
        <div id="wrapper">
        
            <?php include 'include/side_menu.php';

  $button = "submit";
      $btn_name = "Add City Place";
      $path = base_url("assets/images/banner/user_b.png");
      
        $path1 = base_url("assets/images/banner/user_b.png");
      $path2 = base_url("assets/images/banner/user_b.png");
      $path3 = base_url("assets/images/banner/user_b.png");
      $path4 = base_url("assets/images/banner/user_b.png");

      $id = $this->uri->segment(4);
      if($id!=''){
        $fetch = $this->admin_common_model->get_where('country_map_city_places',['id'=>$id]);
        $row = $fetch[0];
        $button = "update";
        $btn_name = "Update City Place";        
        if($row['icon']!=''){
          $path = base_url("uploads/images/".$row['icon']);
        }
    
                $country_map_city_places_images = $this->admin_common_model->get_where('country_map_city_places_images',['place_id'=>$id]);
 if($country_map_city_places_images[0]['image']!=''){
          $path1 = base_url("uploads/images/".$country_map_city_places_images[0]['image']);
        }
        
         if($country_map_city_places_images[1]['image']!=''){
          $path2 = base_url("uploads/images/".$country_map_city_places_images[1]['image']);
        } 
        if($country_map_city_places_images[2]['image']!=''){
          $path3 = base_url("uploads/images/".$country_map_city_places_images[2]['image']);
        }
        
         if($country_map_city_places_images[3]['image']!=''){
          $path4 = base_url("uploads/images/".$country_map_city_places_images[3]['image']);
        }
      }

      
      
      
           // script for get current lat long

            $client  = @$_SERVER['HTTP_CLIENT_IP'];
	    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
	    $remote  = @$_SERVER['REMOTE_ADDR'];
	    $result  = array('country'=>'', 'city'=>'');
	    if(filter_var($client, FILTER_VALIDATE_IP)){
	        $ip = $client;
	    }elseif(filter_var($forward, FILTER_VALIDATE_IP)){
	        $ip = $forward;
	    }else{
	        $ip = $remote;
	    }
	    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));    
	    if($ip_data && $ip_data->geoplugin_countryName != null){
	    	$ip_result['country_name'] = $ip_data->geoplugin_countryName;
	        $ip_result['country'] = $ip_data->geoplugin_countryCode;
	        $ip_result['city'] = $ip_data->geoplugin_city;
	        $ip_result['lat'] = $ip_data->geoplugin_latitude;
	        $ip_result['lon'] = $ip_data->geoplugin_longitude;
	    }else{
	        $ip_result['lat'] = 28.7041;
	        $ip_result['lon'] = 77.1025;
            }
           

?>
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.css" />

<style>
    
    .vodiapicker{
  display: none; 
}

#a{
  padding-left: 0px;
}

#a img, .btn-select img{
  width: 12px;
  
}

#a li{
  list-style: none;
  padding-top: 5px;
  padding-bottom: 5px;
}

#a li:hover{
 background-color: #F4F3F3;
}

#a li img{
  margin: 5px;
}

#a li span, .btn-select li span{
  margin-left: 30px;
}

/* item list */

.b{
  display: none;
  width: 100%;
  max-width: 350px;
  box-shadow: 0 6px 12px rgba(0,0,0,.175);
  border: 1px solid rgba(0,0,0,.15);
  border-radius: 5px;
  
}

.open{
  display: show !important;
}

.btn-select{
  margin-top: 10px;
  width: 100%;
  max-width: 350px;
  height: 34px;
  border-radius: 5px;
  background-color: #fff;
  border: 1px solid #ccc;
 
}
.btn-select li{
  list-style: none;
  float: left;
  padding-bottom: 0px;
}

.btn-select:hover li{
  margin-left: 0px;
}

.btn-select:hover{
  background-color: #F4F3F3;
  border: 1px solid transparent;
  box-shadow: inset 0 0px 0px 1px #ccc;
  
  
}

.btn-select:focus{
   outline:none;
}

.lang-select{
  margin-left: 50px;
}


</style>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css" />


      <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.5.6/tinymce.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.5.6/jquery.tinymce.min.js"></script>

    

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&key=AIzaSyAGxLMNvIuc8XpG21cOF3VkxbK1EkTpuzQ"></script>

<link rel="stylesheet" href="css/intlTelInput.css">
    
    
    
            <div class="content-page">
                <!-- Start content -->
                <div class="content">
                    <div class="container">

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="pull-left page-title">Welcome</h4>
                                <ol class="breadcrumb pull-right">
  <li><a href="<?=base_url('admin/view_page/dashboard');?>"><?php $fetch_app_name = $this->admin_common_model->get_where('admin',['id'=>'1']);
                                echo $fetch_app_name[0]['app_name']; ?></a></li>    
                                <li class="active">Add City Place</li>
                                </ol>
                            </div>
                        </div>

                        <!-- Start Widget -->
                
<div class="row">
<form method="POST" action="" enctype="multipart/form-data">
          <input type="hidden"  class="form-control" name="id" value="<?=$row['id'];?>">

                            <!-- Basic example -->
                            <div class="col-md-12">
                                <div class="panel panel-default">
 <?php if($row['id']){?>
                                    <div class="panel-heading"><h3 class="panel-title">Update City Place</h3></div>
                                    <?php }else{?>
                                    <div class="panel-heading"><h3 class="panel-title">Add City Place</h3></div>
                                    <?php }?>
                                                                       <div class="panel-body">
                                        <form role="form">
                                            
                                            
                                      
          
          
                                    <div class="form-group">
                                                <label>Country Name  *</label>
               <select class="form-control" name="country_id" onchange="getSubCategory(this.value);"> 
                                 <option value="">--select--</option>

              <?php 
               $category = $this->admin_common_model->get_all('country_map');
               
              foreach($category as $arr){ ?>
<!--                 <option value="<?=$arr['id'];?>"> <?=$arr['name'];?> </option>
-->                 
                 <option <?php if($row['country_id'] == $arr['id']){echo 'selected' ; } ?> value="<?=$arr['id']?>" ><?=$arr['name'];?></option>

              <?php } ?>
              </select>
                                            </div>
          
 <div class="form-group">
 <label>City Name *</label>
  <select class="form-control" name="city_id" onchange="getTag1(this.value);"> 
  
                                  

              <?php 
              
              if($row['city_id']){
                 $city_id = $row['city_id'];
              }
              else{
                  $city_id = '';
              }
              
              $fetchSubCategories = $this->admin_common_model->get_where('country_map_city',['id'=>$city_id]);
                    $subCategoriesRows = $fetchSubCategories[0];?> 
          <option value="<?php if($row['city_id']){ echo $row['city_id'];} ?>"><? if($subCategoriesRows['name']){ echo $subCategoriesRows['name'];}else{ echo 'Select City';}?></option>
       
              </select>
              </div>
                                            
                                            
                                         
    
  <!--
           <div class="form-group">
                                       
               <select id="chkveg" multiple="multiple" class="form-control"   name="tag_id[]" required> 
               

              <?php 
              
            
              $tags = $this->admin_common_model->get_all('tags',['type'=>'USER']); 
             
              foreach($tags as $tags_name){ ?>
                  <option  <?php if($row['tag_id'] == $category_name['id']){echo 'selected' ; } ?> value="<?=$category_name['id']?>" ><?=$category_name['tag_name'];?></option>
                 
              <?php } ?>
              </select>       
                                                
                                </div>
                                         -->
                                     
                                    
                                              
                          <!--          <div class="form-group">
                         <label>Select Tag Name (You Can Select Multiple) *</label>
               <select  id="chkveg" multiple="multiple" class="form-control" name="tag_id[]" > 
                                 <option value="">--select--</option>

              <?php 
               $category = $this->admin_common_model->get_all('tags');
               
              foreach($category as $arr){ ?>
                              
                 <option <?php if($row['tag_id'] == $arr['id']){echo 'selected' ; } ?> value="<?=$arr['id']?>" ><?=$arr['tag_name'];?></option>

              <?php } ?>
              </select>
                                            </div>     --> 
                                              
                                          
                                          
                                          
                                              <div class="form-group">
                                                <label>Select Tag Name (You Can Select Multiple) *</label>
                                                
                                    <div id="multipleData">
                                        <select  class="selectpicker form-control selctmbtn" name="tag_id[]"  multiple data-live-search="true">
                                            <?php 
               $category = $this->admin_common_model->get_all('tags');
               
              foreach($category as $arr){ ?>
<!--                 <option value="<?=$arr['id'];?>"> <?=$arr['tag_name'];?> </option>
-->                 
                 <option <?php if($row['tag_id'] == $arr['id']){echo 'selected' ; } ?> value="<?=$arr['id']?>" ><?=$arr['tag_name'];?></option>

              <?php } ?>

</select>


                                    </div>
                                                

                                            </div>      
                                            
                                           <div class="form-group">
                                                <label>Place Name *</label>
                                                <input type="text" class="form-control" name="place_name" required value="<?=$row['place_name'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Place Name(in Arabic) *</label>
                                                <input type="text" class="form-control" name="place_name_ar" required value="<?=$row['place_name_ar'];?>">
                                            </div>
                                            
                                                <div class="form-group">
                                                <label>Google Map Link*</label>
                                                <input type="text" class="form-control" name="google_map_link" required value="<?=$row['google_map_link'];?>">
                                            </div>
                                            
                                             
                                       <!--       
                                           <div class="form-group">
                                                <label>Tag *</label>
                                                <input type="text" class="form-control" name="tag" required value="<?=$row['tag'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Tag(in Arabic) *</label>
                                                <input type="text" class="form-control" name="tag_ar" required value="<?=$row['tag_ar'];?>">
                                            </div>
                                            -->
                                              
                                               <div class="form-group">
                                             <label>Find the Location</label>
                                             <input id="searchInput" class="input-controls" type="text" placeholder="Enter a location">
                                             <div class="map" id="map" style="width: 100%; height: 300px;"></div>               
                                             </div>


                                             <div class="row clearfix">
                                             	 <div class="form-group form_area">
                                             <label>Address</label>
                                             <input class="form-control" name="address"  id="location" placeholder="Address here" required value=<?=$row['address'];?>>
                                              <br>
                                            

                                                <div class="col-sm-4">
                                                <input type="text"  class="form-control" name="lat" id="lat" value="<?=$row['lat'];?>" placeholder="Latitude here">
                                              </div>
                                              <div class="col-sm-4">
                                               <input type="text"  class="form-control" name="lon" id="lng" value="<?=$row['lon'];?>" placeholder="Longitude here">
                                              </div>
                                           
                                           </div>
                                             </div>
         
         
                                             
                                        
                                           
                                            
                                           <div class="form-group">
                                                <label for="exampleInputEmail1">Description *</label>

                                            <textarea class="form-control" required style="width:550px; height:150px;" cols="42" rows="5" name="description"><?php
  if($row['description']){ echo $row['description'];}else{ echo 'NA';};
?></textarea>
                                            </div>
                                            
                                            
                                               
                                           <div class="form-group">
                                                <label for="exampleInputEmail1">Description Arabic *</label>

                                            <textarea class="form-control" required style="width:550px; height:150px;" cols="42" rows="5" name="description_ar"><?php
  if($row['description_ar']){ echo $row['description_ar'];}else{echo 'NA';};
?></textarea>
                                            </div>
                                          
                                           
                                                <div class="form-group">
                                                <label>Promo code and discount</label>
                                                <input style="background-color: #f5d992;/* border-color: red; */border: revert;solid #000000;" type="text" class="form-control" name="promo_code_and_discount" value="<?=$row['promo_code_and_discount'];?>">
                                            </div>
                                            
                                            
                                             <div class="form-group">
                                                <label>Start Date</label>
                                                <input type="date" class="form-control" name="start_date"  value="<?=$row['start_date'];?>">
                                            </div>
                                            

                                            <div class="form-group">
                                                <label>End Date</label>
                                                <input type="date" class="form-control" name="end_date"  value="<?=$row['end_date'];?>">
                                            </div>
                                            
                                            
                                            
                                            
<!--                                              <div class="form-group">
                                                <label>Mobile *</label>
                                                <input type="text" class="form-control" name="mobile" required value="<?=$row['mobile'];?>">
                                            </div>
                                             <div class="form-group">
                                                <label>Email *</label>
                                                <input type="text" class="form-control" name="email" required value="<?=$row['email'];?>">
                                            </div>
                                             <div class="form-group">
                                                <label>Site URL *</label>
                                                <input type="text" class="form-control" name="site_url" required value="<?=$row['site_url'];?>">
                                            </div>-->
                                    
                                            
                                              <div class="form-group">
                                                <label>Video Link (in english) </label>
                                                <input type="text" class="form-control" name="video_link_en"  value="<?=$row['video_link_en'];?>">
                                            </div>
                                            
                                              <div class="form-group">
                                                <label>Video Link (in arabic) </label>
                                                <input type="text" class="form-control" name="video_link_ar"  value="<?=$row['video_link_ar'];?>">
                                            </div>
                                            
                                            
                                         <!--  <div class="form-group">
                                                <label>Icon background color Code*</label>
                                                <input type="text" class="form-control" name="icon_background_color" required value="<?=$row['icon_background_color'];?>">
                                            </div>-->
                                            
                                 
                                            
                                 <!--   <div class="form-group" >
                                                <label>Select Map Icon (icon size 62*62 px)  *</label>
               <select class="form-control" name="icon" > 
                                 <option value="">Select Map Icon </option>

              <?php 
               $map_icon = $this->admin_common_model->get_all('map_icon');
               
              foreach($map_icon as $arr_map){
                 // $path = base_url("uploads/images/".$arr_map['icon']);
      if ($arr_map['icon'] == ''){
                          $img_url = base_url('uploads/images/user.jpg');
                        }else{
                          $img_url = base_url('uploads/images/'.$arr_map['icon']);
                        }
                        
                        
              ?>
               

                 <option <?php if($row['icon'] == $arr_map['id']){echo 'selected' ; } ?> value="<?=$arr_map['icon']?>" style="background-image:url(<?=$img_url;?>);">  <?=$arr_map['icon'];?>     </option>

              <?php } ?>
              </select>
                                            </div>-->
                               
                               
                               
                                  
                                           <!--   <div class="form-group">
                                                <label>Select Map Icon *</label>
                                                
                                    <div id="multipleData">
                                        <select  class="selectpicker form-control selctmbtn" name="icon"  data-live-search="true">
                                            <?php 
               $category = $this->admin_common_model->get_all('map_icon');
               
              foreach($category as $arr){
                if ($arr['icon'] == ''){
                          $img_url = base_url('uploads/images/user.jpg');
                        }else{
                          $img_url = base_url('uploads/images/'.$arr['icon']);
                        }
                        
              
              ?>
               
                 <option <?php if($row['icon'] == $arr['id']){echo 'selected' ; } ?>  value="<?=$arr['id']?>" >  <?=$img_url;?> </option>

              <?php } ?>

</select>


                                    </div>
                                                

                                            </div> -->  
                                            
                                            
                                            
                                   <!--    <div class="row clearfix">
                                               <div class="col-md-4">
                                                <div class="image-view">
                                                <img style="height: 100px;width: 100px;" alt="SVG Image" src="<?=$path;?>" name="icon" id="icon">    
                                                </div>    
                                                </div>
                                                </div>

                                          <div class="row clearfix">
                                              <div class="form-group col-md-6">
                                                <label>Select Map Icon (icon size 65*65 px)</label>

                                               <input type="file" accept="image/png, image/gif, image/svg+xml, image/jpeg, image/svg " name="icon" onchange="readURL(this,'icon');" class="form-control">
                                            </div>
                                            -->
                                            
                                            
                                                    
                                          <div class="form-group">
                                               <label> Select Map Icon *</label>
                                             <select  name="icon" id="id_select2_example" style="width: 100px;">
                                                 
                                                <?php   $map_icon = $this->admin_common_model->get_all('map_icon');
               
              foreach($map_icon as $arr_map){
                 // $path = base_url("uploads/images/".$arr_map['icon']);
      if ($arr_map['icon'] == ''){
                          $img_url = base_url('uploads/images/user.jpg');
                        }else{
                          $img_url = base_url('uploads/images/'.$arr_map['icon']);
                        }
                         ?>
                        
        <option value="<?=$arr_map['icon']?>" data-img_src="<?=$img_url;?>"></option>
        
        <?php } ?>
       </select>
     </div>
     <div class="form-check">
      <input class="form-check-input" type="checkbox"  name="show_only_icon" value="1" <?=($row['show_only_icon'] == 1 ? 'checked':'') ?> id="flexCheckIndeterminate">
      <label class="form-check-label" for="flexCheckIndeterminate">
        Show Internal Icons
      </label>
    </div>
    
     
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.js"></script>
<script type="text/javascript">
    function custom_template(obj){
            var data = $(obj.element).data();
            var text = $(obj.element).text();
            if(data && data['img_src']){
                img_src = data['img_src'];
                template = $("<div><img src=\"" + img_src + "\" style=\"width:50px;height:50px;\"/></div>");
                return template;
            }
        }
    var options = {
        'templateSelection': custom_template,
        'templateResult': custom_template,
    }
    $('#id_select2_example').select2(options);
    $('.select2-container--default .select2-selection--single').css({'height': '50px'});

</script>

                                            
                                       <div class="row clearfix">
                                               <div class="col-md-8">
                                                <div class="image-view">
                                                <img  src="<?=$path1;?>" name="image1" id="image1">    
                                                </div>    
                                                </div>
                                              
                                              <div class="form-group col-md-6">
                                                <label>Place Image 1</label>

                                               <input type="file" name="image1" onchange="readURL(this,'image1');" class="form-control">
                                            </div>
                                                
                                           <div class="col-md-8">
                                                <div class="image-view">
                                                <img  src="<?=$path2;?>" name="image2" id="image2">    
                                                </div>    
                                                </div>
                                              
                                              <div class="form-group col-md-6">
                                                <label>Place Image 2</label>

                                               <input type="file" name="image2" onchange="readURL(this,'image2');" class="form-control">
                                            </div>
                                                
                                                
                                       
                                        </div>
                                        
                                        
                                        
                                           <div class="row clearfix">
                                               <div class="col-md-8">
                                                <div class="image-view">
                                                <img  src="<?=$path3;?>" name="image3" id="image3">    
                                                </div>    
                                                </div>
                                              
                                              <div class="form-group col-md-6">
                                                <label>Place Image 3</label>

                                               <input type="file" name="image3" onchange="readURL(this,'image3');" class="form-control">
                                            </div>
                                                
                                           <div class="col-md-8">
                                                <div class="image-view">
                                                <img  src="<?=$path4;?>" name="image4" id="image4">    
                                                </div>    
                                                </div>
                                              
                                              <div class="form-group col-md-6">
                                                <label>Place Image 4</label>

                                               <input type="file" name="image4" onchange="readURL(this,'image4');" class="form-control">
                                            </div>
                                                
                                                
                                       
                                        </div>
                                        
                                        
                                        
                                    </div><!-- panel-body -->
                                </div> <!-- panel -->
                            </div> <!-- col-->
                            

                        </div> <!-- End row -->

 <button type="submit" name="<?=$button;?>" class="btn btn-purple waves-effect waves-light">Save</button>
                                        </form>
                    </div> <!-- container -->
                               
                </div> <!-- content -->

               
            </div>
          
        </div>
        <!-- END wrapper -->


 <?php include 'include/footer.php';?>
<script>

var langArray = [];
$('.vodiapicker option').each(function(){
  var img = $(this).attr("data-thumbnail");
  var text = this.innerText;
  var value = $(this).val();
  var item = '<li><img src="'+ img +'" alt="" value="'+value+'"/><span>'+ text +'</span></li>';
  langArray.push(item);
})

$('#a').html(langArray);

//Set the button value to the first el of the array
$('.btn-select').html(langArray[0]);
$('.btn-select').attr('value', 'en');

//change button stuff on click
$('#a li').click(function(){
   var img = $(this).find('img').attr("src");
   var value = $(this).find('img').attr('value');
   var text = this.innerText;
   var item = '<li><img src="'+ img +'" alt="" /><span>'+ text +'</span></li>';
  $('.btn-select').html(item);
  $('.btn-select').attr('value', value);
  $(".b").toggle();
  //console.log(value);
});

$(".btn-select").click(function(){
        $(".b").toggle();
    });

//check local storage for the lang
var sessionLang = localStorage.getItem('lang');
if (sessionLang){
  //find an item with value of sessionLang
  var langIndex = langArray.indexOf(sessionLang);
  $('.btn-select').html(langArray[langIndex]);
  $('.btn-select').attr('value', sessionLang);
} else {
   var langIndex = langArray.indexOf('ch');
  console.log(langIndex);
  $('.btn-select').html(langArray[langIndex]);
  //$('.btn-select').attr('value', 'en');
}





   function readURL(input,id) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#'+id)
                    .attr('src', e.target.result);
                    
            };

            reader.readAsDataURL(input.files[0]);
        }
    }


function getSubCategory(country_id){
 $.ajax({
          url: "<?=base_url('admin/get_sub_category');?>",
          data: {'country_id': country_id}, // change this to send js object
          type: "POST",
          success: function(result){
            //alert(result);
            $("select[name='city_id']").html(result);
          }
        });
}

</script>


<script>
/* script */
function initialize() {
   var latlng = new google.maps.LatLng(<?=$ip_result['lat'];?>,<?=$ip_result['lon'];?>);
    var map = new google.maps.Map(document.getElementById('map'), {
      center: latlng,
      zoom: 13
    });
    var marker = new google.maps.Marker({
      map: map,
      position: latlng,
      draggable: true,
      anchorPoint: new google.maps.Point(0, -29)
   });
    var input = document.getElementById('searchInput');
    map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
    var geocoder = new google.maps.Geocoder();
    var autocomplete = new google.maps.places.Autocomplete(input);
    autocomplete.bindTo('bounds', map);
    var infowindow = new google.maps.InfoWindow();   
    autocomplete.addListener('place_changed', function() {
        infowindow.close();
        marker.setVisible(false);
        var place = autocomplete.getPlace();
        if (!place.geometry) {
            window.alert("Autocomplete's returned place contains no geometry");
            return;
        }
  
        // If the place has a geometry, then present it on a map.
        if (place.geometry.viewport) {
            map.fitBounds(place.geometry.viewport);
        } else {
            map.setCenter(place.geometry.location);
            map.setZoom(17);
        }
       
        marker.setPosition(place.geometry.location);
        marker.setVisible(true);          
    
        bindDataToForm(place.formatted_address,place.geometry.location.lat(),place.geometry.location.lng());
        infowindow.setContent(place.formatted_address);
        infowindow.open(map, marker);
       
    });
    // this function will work on marker move event into map 
    google.maps.event.addListener(marker, 'dragend', function() {
        geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (results[0]) {        
              bindDataToForm(results[0].formatted_address,marker.getPosition().lat(),marker.getPosition().lng());
              infowindow.setContent(results[0].formatted_address);
              infowindow.open(map, marker);
          }
        }
        });
    });
}
function bindDataToForm(address,lat,lng){
   document.getElementById('location').value = address;
   document.getElementById('lat').value = lat;
   document.getElementById('lng').value = lng;
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

<style type="text/css">
    .input-controls {
      margin-top: 10px;
      border: 1px solid transparent;
      border-radius: 2px 0 0 2px;
      box-sizing: border-box;
      -moz-box-sizing: border-box;
      height: 32px;
      outline: none;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    }
    #searchInput {
      background-color: #fff;
      font-family: Roboto;
      font-size: 15px;
      font-weight: 300;
      margin-left: 12px;
      padding: 0 11px 0 13px;
      text-overflow: ellipsis;
      width: 50%;
    }
    #searchInput:focus {
      border-color: #4d90fe;
    }
</style>


<?php

extract($_REQUEST);
// for add holidays
if(isset($submit)){

            $arr_data = $this->input->post();
            $arr_data['show_only_icon'] = $arr_data['show_only_icon'] ?? 0;

 $tag_id = $arr_data['tag_id'];
            $arr_data['tag_id'] = implode(",",$tag_id);
 
 $ans = explode(',',$arr_data['tag_id']);
if($ans){
    $en_tag = '';$ar_tag = '';
 foreach($ans as $row1){ 
                 $emp = $this->admin_common_model->get_where('tags',['id'=>$row1]);
                 
$en_tag = $en_tag.','.$emp[0]['tag_name'];
$ar_tag = $ar_tag.','.$emp[0]['tag_name_ar'];

}
     
 }else{
$en_tag = '';
$ar_tag = '';
}

        $arr_data['tag']  =  $en_tag;       
        $arr_data['tag_ar']  =  $ar_tag;       
               
 
  /* if($_FILES['icon']['name']!=''){
      
       $request_images = $_FILES['icon']['name'];
               $n = rand(0, 100000);
               $img = "icon_IMG_" . $n . $request_images;
               move_uploaded_file($_FILES['icon']['tmp_name'], "uploads/images/" . $img);
               $arr_data['icon'] = $img;        
      } */
      
   
          //print_r($arr_data);die;
date_default_timezone_set('Asia/Calcutta'); 

$arr_data['date_time']=date("Y-m-d H:i:s");

unset($arr_data['submit'],$arr_data['id']);
$result = $this->admin_common_model->insert_data('country_map_city_places',$arr_data); 
//echo $this->db->last_query(); die;
             
        
if ($result) {
    
    
      if($_FILES['image1']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info1 = pathinfo($_FILES['image1']['name']);

               $img = "place_IMG_" . $n .'.'.$path_info1['extension'];
               move_uploaded_file($_FILES['image1']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$result]); 

      } 
      
        if($_FILES['image2']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info2 = pathinfo($_FILES['image2']['name']);
               $img = "place_IMG_" . $n .'.'.$path_info2['extension'];
               move_uploaded_file($_FILES['image2']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$result]); 
      } 
      
          if($_FILES['image3']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info3 = pathinfo($_FILES['image3']['name']);
               $img = "place_IMG_" . $n .'.'.$path_info3['extension'];
               move_uploaded_file($_FILES['image3']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$result]); 
      } 
         if($_FILES['image4']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info4 = pathinfo($_FILES['image']['name']);

               $img = "place_IMG_" . $n .'.'.$path_info4['extension'];
               move_uploaded_file($_FILES['image4']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$result]); 
      } 
   
    
    
    
echo 
"<script> swal(
  'Success',
  'Add Place Successfully',
  'success'

); 

$('.confirm').click(function(){

        window.location='".base_url('admin/view_page/country_map_city_place_list')."';
});

</script>";

    }else{

echo "<script> swal(
  'Error',
  'Error In Add Place',
  'error'
); 

$('.confirm').click(function(){
        window.location='';
});

</script>";

}

}// end if submit


// for update restaurant
if(isset($update)){

$arr_data = $this->input->post();
// echo '<pre>';
// print_r($arr_data);
// echo '</pre>';
// exit;
 $tag_id = $arr_data['tag_id'];
            $arr_data['tag_id'] = implode(",",$tag_id);
 
 /* if($_FILES['icon']['name']!=''){
      
                  $request_images = $_FILES['icon']['name'];
               $n = rand(0, 100000);
               $img = "icon_IMG_" . $n . $request_images;
               move_uploaded_file($_FILES['icon']['tmp_name'], "uploads/images/" . $img);
               $arr_data['icon'] = $img;        
      }   */
      
      
          $icon = $arr_data['icon'];

      if($icon ==''){
          unset($arr_data['icon']);
      }
      
          $arr_data['show_only_icon'] = $arr_data['show_only_icon'] ?? 0;
            $city_id = $arr_data['city_id'];

      if($city_id ==''){
          unset($arr_data['city_id']);
      }
      
            $tag_id = $arr_data['tag_id'];

      if($tag_id ==''){
          unset($arr_data['tag_id']);
      }
      
date_default_timezone_set('Asia/Calcutta'); 

$arr_data['date_time']=date("Y-m-d H:i:s");

$arr_where = ['id'=>$arr_data['id']];
unset($arr_data['update']);
$result = $this->admin_common_model->update_data('country_map_city_places',$arr_data, $arr_where); 
//echo $this->db->last_query(); die;
             
        
if ($result) {
    
    
     $p_id = $this->uri->segment(4);
      if($_FILES['image1']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info1 = pathinfo($_FILES['image1']['name']);
               $img = "place_IMG_" . $n .'.'.$path_info1['extension'];
               move_uploaded_file($_FILES['image1']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$p_id]); 

      } 
      
        if($_FILES['image2']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info2 = pathinfo($_FILES['image2']['name']);
               $img = "place_IMG_" . $n .'.'.$path_info2['extension'];
               move_uploaded_file($_FILES['image2']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$p_id]); 
      } 
      
          if($_FILES['image3']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info3 = pathinfo($_FILES['image3']['name']);
               $img = "place_IMG_" . $n .'.'.$path_info3['extension'];
               move_uploaded_file($_FILES['image3']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$p_id]); 
      } 
         if($_FILES['image4']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info4 = pathinfo($_FILES['image4']['name']);
               $img = "place_IMG_" . $n .'.'.$path_info4['extension'];
               move_uploaded_file($_FILES['image4']['tmp_name'], "uploads/images/" . $img);
               $this->admin_common_model->insert_data('country_map_city_places_images',['image'=>$img,'place_id'=>$p_id]); 
      } 
   
   
echo 
"<script> swal(
  'Success',
  'Update Place Successfully',
  'success'
); 

$('.confirm').click(function(){
        window.location='".base_url('admin/view_page/country_map_city_place_list')."';
});

</script>";

    }else{

echo "<script> swal(
  'Error',
  'Error In Updating Place',
  'error'
); 

$('.confirm').click(function(){
        window.location='';
});

</script>";

}// end if result




}


?>

  <style>
     .dialog {
    padding-right: 18px;
    float: left;
    position: relative;
}
.close-thik{
   background: #FFF none repeat scroll 0% 0%;
color: #0A0A0A;
font: 14px/100% arial,sans-serif;
position: absolute;
right: 20px;
text-decoration: none;
text-shadow: 0px 1px 0px #FFF;
top: 5px; 
}
.dialog label {
    display: inline-block;
    max-width: 100%;
    margin-bottom: 5px;
    font-weight: 700;
}
.upload_file {
    width: 120px;
    height: 100px;
    border: 1px solid #0070BC;
}
.dialog input{
        visibility: hidden;
    position: absolute;

}
.form-group input[type="checkbox"] {
    display: block;
}
.multiselect.dropdown-toggle.btn.btn-default {
    width: 715px;
    background-color: 
#fff;
box-shadow: none;
border-color:
    #ccc;
}
ul.multiselect-container.dropdown-menu {
    overflow-x: hidden;
    height: 125px;
    overflow-y: scroll;
}
     </style>


<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
        rel="stylesheet" type="text/css" />
    <script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
        type="text/javascript"></script>
<script>
    $(function() {

        $('#chkveg').multiselect({
        
            includeSelectAllOption: true
        
        });
    });
</script> 



<script>

tinymce.init({
    selector: 'textarea',
    height: 200,
    theme: 'modern',
    plugins: [
        'advlist autolink lists link image charmap print preview hr anchor pagebreak',
        'searchreplace wordcount visualblocks visualchars code fullscreen',
        'insertdatetime media nonbreaking save table contextmenu directionality',
        'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc'
    ],
    toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
    toolbar2: 'print preview media | forecolor backcolor emoticons | codesample',
    image_advtab: true
});

// 
// CKEDITOR.replace('editor1', {});
// CKEDITOR.replace('editor2', {});
// CKEDITOR.replace('description', {});
</script>



<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
        rel="stylesheet" type="text/css" />
    <script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
        type="text/javascript"></script>
<script>
    $(function() {

        $('#chkveg').multiselect({
        
            includeSelectAllOption: true
        
        });
    });
</script> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.8.1/css/bootstrap-select.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.8.1/js/bootstrap-select.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<script>
function getTag1(city_id){
 $.ajax({
          url: "<?=base_url('admin/getTag1');?>",
          data: {'city_id': city_id}, // change this to send js object
          type: "POST",
          success: function(result){
        $("#multipleData").html(` <select  class="selectpicker form-control selctmbtn" name="tag_id[]"  multiple data-live-search="true">
                              ${result}      
                </select>`);
                  
                 $('select').selectpicker();
          }
        });
}
</script> 



