<?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";
      $path = base_url("assets/images/banner/user_b.png");
      $path1 = 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',['id'=>$id]);
        $row = $fetch[0];
        $button = "update";
        $btn_name = "Update City";        
        if($row['image']!=''){
          $path = base_url("uploads/images/".$row['image']);
        }if($row['country_icon']!=''){
          $path1 = base_url("uploads/images/".$row['country_icon']);
        }
      }
?>
      
      
      
      

  <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" />



            <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</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</h3></div>
                                    <?php }else{?>
                                    <div class="panel-heading"><h3 class="panel-title">Add City</h3></div>
                                    <?php }?>
                                    <div class="panel-body">
                                        <form role="form">
                                            
                                            
                                 <div class="form-group">
                                                <label>Select Country Name *</label>
                                                 <?php $category = $this->admin_common_model->get_all('country_map');  ?>
                                                  <select name = "country_id" class="form-control" required onchange="getTag(this.value);">
                                                      <option value="">--select--</option>
                                                    <?php foreach($category as $category_name){?>
                                                      <option <?php if($row['country_id'] == $category_name['id']){echo 'selected' ; } ?> value="<?=$category_name['id']?>" ><?=$category_name['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>Select Tag Name (You Can Select Multiple) *</label>
                                                
                                    <div>
                                        <select class="selectpicker form-control selctmbtn" name="tag_id[]"  multiple data-live-search="true">
               
              <?php 
              
              if($row['tag_id']){
                 $tag_id = $row['tag_id'];
              }
              else{
                  $tag_id = '';
              }
              
              $fetchSubCategories = $this->admin_common_model->get_where('tags',['id'=>$tag_id]);
                    $subCategoriesRows = $fetchSubCategories[0];?> 
          <option value="<?php if($row['tag_id']){ echo $row['tag_id'];} ?>"><? if($subCategoriesRows['tag_name']){ echo $subCategoriesRows['tag_name'];}else{ echo 'Select Tag';}?></option>

              </select>
              </div>
                     -->                 
   
                                            
                                            <div class="form-group">
                                                <label>City Name *</label>
                                                <input type="text" class="form-control" name="name" required value="<?=$row['name'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>City Name(in Arabic) *</label>
                                                <input type="text" class="form-control" name="name_ar" required value="<?=$row['name_ar'];?>">
                                            </div>
                                            
                                          
                                              <div class="form-group">
                                                <label>City Plan Price *</label>
                                                <input type="number" class="form-control" name="city_map_price" required value="<?=$row['city_map_price'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>City Plan Month (1 to 12 month)*</label>
                                                <input type="number" class="form-control" name="city_map_month" required value="<?=$row['city_map_month'];?>">
                                            </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 for="exampleInputEmail1">About City *</label>

                                            <textarea class="form-control" required style="width:550px; height:150px;" cols="42" rows="5" name="about_city"><?php
  if($row['about_city']) echo $row['about_city'];
?></textarea>
                                            </div>


 
                                           <div class="form-group">
                                                <label for="exampleInputEmail1">About City Arabic*</label>

                                            <textarea class="form-control" required style="width:550px; height:150px;" cols="42" rows="5" name="about_city_ar"><?php
  if($row['about_city_ar']) echo $row['about_city_ar'];
?></textarea>
                                            </div>
     
                                            
                                              
                                            <div class="form-group">
                                                <label>Currency *</label>
                                                <input type="text" class="form-control" name="currency" required value="<?=$row['currency'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Currency(in Arabic) *</label>
                                                <input type="text" class="form-control" name="currency_ar" required value="<?=$row['currency_ar'];?>">
                                            </div>
                                            
                                            
                                            
                                            
                                              
                                            <div class="form-group">
                                                <label>Clothing *</label>
                                                <input type="text" class="form-control" name="clothing" required value="<?=$row['clothing'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Clothing(in Arabic) *</label>
                                                <input type="text" class="form-control" name="clothing_ar" required value="<?=$row['clothing_ar'];?>">
                                            </div>
                                            
                                            
                                            
                                            <div class="form-group">
                                                <label>Health *</label>
                                                <input type="text" class="form-control" name="health" required value="<?=$row['clothing'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Health(in Arabic) *</label>
                                                <input type="text" class="form-control" name="health_ar" required value="<?=$row['health_ar'];?>">
                                            </div>
                                            
                                            
                                            
                                            
                                            <div class="form-group">
                                                <label>Communications *</label>
                                                <input type="text" class="form-control" name="communications" required value="<?=$row['communications'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Communications(in Arabic) *</label>
                                                <input type="text" class="form-control" name="communications_ar" required value="<?=$row['communications_ar'];?>">
                                            </div>



                                            <div class="form-group">
                                                <label>Offical Language *</label>
                                                <input type="text" class="form-control" name="offical_language" required value="<?=$row['offical_language'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Offical Language(in Arabic) *</label>
                                                <input type="text" class="form-control" name="offical_language_ar" required value="<?=$row['offical_language_ar'];?>">
                                            </div>



                                           <div class="form-group">
                                                <label>Best time to visit *</label>
                                                <input type="text" class="form-control" name="best_time_to_visit" required value="<?=$row['best_time_to_visit'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Best time to visit (in Arabic) *</label>
                                                <input type="text" class="form-control" name="best_time_to_visit_ar" required value="<?=$row['best_time_to_visit_ar'];?>">
                                            </div>
                                            
                                            
                                            
                                             <div class="form-group">
                                                <label>Electrical Socket *</label>
                                                <input type="text" class="form-control" name="electrical_socket" required value="<?=$row['electrical_socket'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Electrical Socket(in Arabic) *</label>
                                                <input type="text" class="form-control" name="electrical_socket_ar" required value="<?=$row['electrical_socket_ar'];?>">
                                            </div>
                                            
                                            
                                              
                                            <div class="form-group">
                                                <label>The Waether *</label>
                                                <input type="text" class="form-control" name="the_waether" required value="<?=$row['the_waether'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>The Waether(in Arabic) *</label>
                                                <input type="text" class="form-control" name="the_waether_ar" required value="<?=$row['the_waether_ar'];?>">
                                            </div>
                                            
                                            
                                            
                                            
                                              <div class="form-group">
                                                <label>Car Police Number *</label>
                                                <input type="text" class="form-control" name="car_police_number" required value="<?=$row['car_police_number'];?>">
                                            </div>
                                            
                                            
                                            
                                              <div class="form-group">
                                                <label>Police Number *</label>
                                                <input type="text" class="form-control" name="police_number" required value="<?=$row['police_number'];?>">
                                            </div>
                                            

                                              </div>

                                              <div class="row clearfix">
                                               <div class="col-md-4">
                                                <div class="image-view">
                                                <img src="<?=$path;?>" name="image" id="image">    
                                                </div>    
                                                </div>
                                                </div>

 <div class="row clearfix">
                                              <div class="form-group col-md-6">
                                                <label>Image</label>

                                               <input type="file" name="image" onchange="readURL(this,'image');" class="form-control">
                                            </div>
                                            

                                            
                                           
                                    </div><!-- panel-body -->
                                    
                                             
                            </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>

   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]);
        }
    }


</script>
<?php

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

            $arr_data = $this->input->post();

 $tag_id = $arr_data['tag_id'];
            $arr_data['tag_id'] = implode(",",$tag_id);
 
           if($_FILES['image']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info = pathinfo($_FILES['image']['name']);
               $img = "Category_IMG_" . $n .'.'.$path_info['extension'];
               move_uploaded_file($_FILES['image']['tmp_name'], "uploads/images/" . $img);
               $arr_data['image'] = $img;        
      }
      
      
       //print_r($arr_data);die;
date_default_timezone_set('Asia/Riyadh'); 

$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',$arr_data); 
//echo $this->db->last_query(); die;
             
        
if ($result){
echo 
"<script> swal(
  'Success',
  'Add City Successfully',
  'success'

); 

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

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

</script>";

    }else{

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

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

</script>";

}

}// end if submit


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

$arr_data = $this->input->post();

 $tag_id = $arr_data['tag_id'];
            $arr_data['tag_id'] = implode(",",$tag_id);
 
 if($_FILES['image']['name']!='')
      {
               $n = rand(0, 100000);
               $path_info = pathinfo($_FILES['image']['name']);
               $img = "Category_IMG_" . $n .'.'.$path_info['extension'];
               move_uploaded_file($_FILES['image']['tmp_name'], "uploads/images/" . $img);
               $arr_data['image'] = $img;        
      }
          
           
      
date_default_timezone_set('Asia/Riyadh'); 

$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',$arr_data, $arr_where); 
//echo $this->db->last_query(); die;
             
        
if ($result) {
    
echo 
"<script> swal(
  'Success',
  'Update City Successfully',
  'success'
); 

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

</script>";

    }else{

echo "<script> swal(
  'Error',
  'Error In Updating City',
  '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;
}
.selctmbtn button{
    -webkit-border-radius: 2px;
    -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    background-color: #fafafa;
    border-radius: 2px;
    border: 1px solid #eeeeee;
    box-shadow: none;
    color: rgba(0, 0, 0, 0.6);
    font-size: 14px;
    height: 37px;
}
.selctmbtn button:hover{
    box-shadow:none;
    border:none;
}
     </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 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 getTag(country_id){
 $.ajax({
          url: "<?=base_url('admin/getTag');?>",
          data: {'country_id': country_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> 


