<?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 Country Map";
      $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',['id'=>$id]);
        $row = $fetch[0];
        $button = "update";
        $btn_name = "Update Country Map";        
        if($row['image']!=''){
          $path = base_url("uploads/images/".$row['image']);
        }if($row['country_icon']!=''){
          $path1 = base_url("uploads/images/".$row['country_icon']);
        }
      }
?>
      
            <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 Country Map</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 Country Map</h3></div>
                                    <?php }else{?>
                                    <div class="panel-heading"><h3 class="panel-title">Add Country Map</h3></div>
                                    <?php }?>
                                    <div class="panel-body">
                                        <form role="form">
                                            <div class="form-group">
                                                <label>Country Name *</label>
                                                <input type="text" class="form-control" name="name" required value="<?=$row['name'];?>">
                                            </div>
                                         
                                              <div class="form-group">
                                                <label>Country Name(in Arabic) *</label>
                                                <input type="text" class="form-control" name="name_ar" required value="<?=$row['name_ar'];?>">
                                            </div>
                                            
                                            <!--<div class="form-group">
                                                <label>Price *</label>
                                                <input type="number" class="form-control" name="price" required value="<?=$row['price'];?>">
                                            </div>
                                            -->       
                                             <!--   <div class="form-group">
                                                <label>Status *</label>
                                               <select class="form-control" name="status" required>
                                               <option value="">--select--</option>
                                              <option value="Active" <?php if($row['status']=='Active'){ echo 'selected'; } ?>>Active</option>
                                               <option value="Deactive" <?php if($row['status']=='Deactive'){ echo 'selected'; } ?>>Deactive</option>
                                               </select>
                                            </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 class="row clearfix">
                                               <div class="col-md-4">
                                                <div class="image-view">
                                                <img src="<?=$path1;?>" name="country_icon" id="country_icon">    
                                                </div>    
                                                </div>
                                                </div>

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

                                               <input type="file" name="country_icon" onchange="readURL(this,'country_icon');" class="form-control">
                                            </div>
                                             </div>
                                            
                                </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>

   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();

           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;        
      }
      
         if($_FILES['country_icon']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info = pathinfo($_FILES['country_icon']['name']);
               $img = "country_icon_IMG_" . $n .'.'.$path_info['extension'];
               move_uploaded_file($_FILES['country_icon']['tmp_name'], "uploads/images/" . $img);
               $arr_data['country_icon'] = $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',$arr_data); 
//echo $this->db->last_query(); die;
             
        
if ($result){
echo 
"<script> swal(
  'Success',
  'Add Country Map Successfully',
  'success'

); 

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

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

</script>";

    }else{

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

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

</script>";

}

}// end if submit


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

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

 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;        
      }
          
             if($_FILES['country_icon']['name']!=''){
      
               $n = rand(0, 100000);
               $path_info = pathinfo($_FILES['country_icon']['name']);

               $img = "country_icon_IMG_" . $n .'.'.$path_info['extension'];
               move_uploaded_file($_FILES['country_icon']['tmp_name'], "uploads/images/" . $img);
               $arr_data['country_icon'] = $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',$arr_data, $arr_where); 
//echo $this->db->last_query(); die;
             
        
if ($result) {
    
echo 
"<script> swal(
  'Success',
  'Update Country Map Successfully',
  'success'
); 

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

</script>";

    }else{

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

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

</script>";

}// end if result




}


?>

