<script src="<?php echo base_url();?>ckeditor/ckeditor.js"></script>
<section class="content-header">
   <h1>
      CMS 
   </h1>
   <ol class="breadcrumb">
      <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
      <li><a href="<?php echo base_url('admin/cms');?>">CMS</a></li>
      <li class="active"> Edit</li>
   </ol>
</section>
<section class="content">
   <div class="row">
      <?php echo $this->utility->showMsg();?>
      <div class="col-md-12">
         <div class="loader" style="display:none;"><img src='<?php echo base_url();?>assets/images/loading.gif' alt='loading' /></div>
         <!-- Horizontal Form -->
         <div class="box box-info clearfix">
            <div class="box-header with-border">
               <h3 class="box-title">Edit </h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form id="add_frm" name="add_frm" class="form-horizontal" method="post" action="" enctype="multipart/form-data">
               <div class="box-body">
                  <div class="form-group">
                     <label class="col-sm-2 control-label">Language</label>
                     <div class="col-sm-6">
                        <select name="language" class="form-control">
                           <?php if(!empty($language)){
                              foreach($language as $row){?>
                           <option value="<?php echo $row['id']; ?>" <?php if($cmsDetails && $cmsDetails['language_id']==$row['id']){ echo 'selected'; }?>><?php echo $row['name']; ?></option>
                           <?php } } ?>   
                        </select>
                     </div>
                  </div>
                  <div class="form-group" >

                  <label class="col-sm-2 control-label">Menu Section</label>

                  <div class="col-sm-6">

                    <select name="secton_id" class="form-control">
                      <option value="1" <?php if($cmsDetails && $cmsDetails['section_id']==1){ echo 'selected'; }?>>INSIGHTS</option> 
                      <option value="2" <?php if($cmsDetails && $cmsDetails['section_id']==2){ echo 'selected'; }?>>COMMUNITY</option> 
                      <option value="3" <?php if($cmsDetails && $cmsDetails['section_id']==3){ echo 'selected'; }?>>SHOP</option> 
                      <option value="4" <?php if($cmsDetails && $cmsDetails['section_id']==4){ echo 'selected'; }?>>ABOUT US</option> 
                    </select>
                  </div>

                </div>
                  <div class="form-group">
                     <label class="col-sm-2 control-label">Meta Title</label>
                     <div class="col-sm-6">
                        <input type="text" class="form-control" id="meta_title" name="meta_title" value="<?php if($cmsDetails){ echo $cmsDetails['meta_title']; } ?>" placeholder="Please enter meta title">
                     </div>
                  </div>
                  <div class="form-group">
                     <label class="col-sm-2 control-label">Meta Description</label>
                     <div class="col-sm-6">
                        <textarea class="form-control" id="meta_desc" name="meta_desc" ><?php if($cmsDetails){ echo $cmsDetails['meta_desc']; } ?></textarea>
                     </div>
                  </div>
                
                  <div class="form-group">
                     <label class="col-sm-2 control-label">Title</label>
                     <div class="col-sm-6">
                        <input type="text" class="form-control" id="title" name="title" value="<?php if($cmsDetails){ echo $cmsDetails['title']; } ?>" placeholder="Please enter title">
                     </div>
                  </div>
                  <div class="form-group">

                  <label class="col-sm-2 control-label">Sub Heading</label>

                  <div class="col-sm-6">

                    <input type="text" class="form-control" id="sub_head" name="sub_head" value="<?php if($cmsDetails){ echo $cmsDetails['sub_head']; } ?>" placeholder="Please enter sub heading">

                  </div>

                </div>
                  <div class="form-group">
                     <label class="col-sm-2 control-label">Content</label>
                     <div class="col-sm-10">
                        <textarea name="content" class="form-control"><?php if($cmsDetails){ echo $cmsDetails['content']; } ?></textarea>
                        <script>
                           CKEDITOR.replace( 'content',{
                                    filebrowserBrowseUrl : '/castle/fileman/index.html',
                                    filebrowserImageBrowseUrl : '/castle/fileman/index.html?type=image',
                                    removeDialogTabs: 'link:upload;image:upload'
                            });
                        </script> 
                     </div>
                  </div>
               </div>
               <div class="form-group addpad">
                  <label class="col-sm-2 control-label">Preview Image</label>
                  <div class="col-sm-6">
                     <img src="<?php echo  base_url();?>assets/userfiles/<?php echo $cmsDetails['path'].'/'.$cmsDetails['filename'].'.'.$cmsDetails['extension']; ?>" width="100">
                     <label class="upimg" for="upimg">
                     upload image
                     <input id="upimg" type="file" name="previewImage" value="Upload" class="form-control">
                     </label>
                  </div>
               </div>
               <div class="form-group addpad">
                  <label class="col-sm-2 control-label">Preview Image Alt</label>
                  <div class="col-sm-6">                     
                      <input type="text" class="form-control" id="preview_alt" name="preview_alt" value="<?php if($cmsDetails){ echo $cmsDetails['preview_alt']; } ?>" placeholder="Please enter Preview Image Alt">
                  </div>
               </div> 
               <div class="col-sm-12 backgroundImage">
                  <h4>Add Background Image or Video URL</h4>
                  <p>If want to show image dont fill video else fill video dont upload image</p>
                  <div class="form-group">
                    <label class="col-sm-3 col-md-2 control-label">Page Title</label>
                      <div class="col-sm-9 col-md-7">
                        <input type="text" name="page_title" class="form-control" value="<?php if($cmsDetails){ echo $cmsDetails['page_title']; } ?>">
                      </div>
                  </div> 
                  <div class="form-group">
                     <label class="col-sm-2 control-label">Page Image</label>
                     <div class="col-sm-6">
                        <?php if($cmsDetails['page_image_id']>0) { $file = getFiles($cmsDetails['page_image_id']); ?>
                        <img src="<?php echo  base_url();?>assets/userfiles/<?php echo $file['path'].'/'.$file['filename'].'.'.$file['extension']; ?>" width="100">
                        <?php } ?>
                        <label class="upimg" for="upimg1">
                        upload image  
                        <input type="file" id="upimg1" name="pageImage" value="Upload" class="form-control">
                        </label>  
                     </div>
                  </div>
                  <div class="form-group addpad">
                    <label class="col-sm-2 control-label">Page Image Alt</label>
                    <div class="col-sm-6">                     
                        <input type="text" class="form-control" id="page_alt" name="page_alt" value="<?php if($cmsDetails){ echo $cmsDetails['page_alt']; } ?>" placeholder="Please enter Page Image Alt">
                    </div>
                  </div>

                  <div class="form-group">
                     <label class="col-sm-2 control-label">Page Video Url</label>
                     <div class="col-sm-6">
                        <input type="text" name="pageVideo" value="<?php if($cmsDetails){ echo $cmsDetails['video_url']; } ?>" class="form-control">
                     </div>
                  </div>
               </div>
               <div class="resultContent col-sm-12">
                  <h2>Page Section</h2>
                  <?php if(!empty($cmsSectionDetails)){
                     foreach ($cmsSectionDetails as $value) {
                      if($value['content_title']!=''){
                     ?>
                  <div class="pageContent backgroundImage clearfix">
                     <div class="form-group rmv">
                        <label class="col-sm-3 col-md-2 control-label">Section Title</label>
                        <div class="col-sm-7 col-md-8">
                           <input type="text" name="section_title_<?php echo $value['id']; ?>" value="<?php echo $value['content_title']; ?>" class="form-control">
                        </div>
                        <div class="col-sm-2">                           
                           <span class="remove" data-id="<?php echo $value['id']; ?>" >Delete Section</span>                           
                        </div>
                     </div>
                     <div class="form-group">
                        <label class="col-sm-3 col-md-2 control-label">Section Content</label>
                        <div class="col-sm-7 col-md-8">
                           <textarea name="section_content_<?php echo $value['id']; ?>" class="form-control"><?php echo $value['page_content']; ?></textarea>
                           <script>
                           CKEDITOR.replace( 'section_content_<?php echo $value['id']; ?>',{
                                    filebrowserBrowseUrl : '/castle/fileman/index.html',
                                    filebrowserImageBrowseUrl : '/castle/fileman/index.html?type=image',
                                    removeDialogTabs: 'link:upload;image:upload'
                            });
                        </script>  
                        </div>
                     </div>
                     <div class="col-sm-12 nopad">
                        <h4>Add Background Image or Video URL</h4>
                        <p>If want to show image dont fill video else fill video dont upload image</p>
                        
                           <div class="form-group">
                              <label class="col-sm-4 col-md-2 control-label">Section Image</label>
                              <div class="col-sm-8">
                                 <?php if($value['content_image_id']>0) { $files = getFiles($value['content_image_id']); ?>
                                 <img src="<?php echo  base_url();?>assets/userfiles/<?php echo $files['path'].'/'.$files['filename'].'.'.$files['extension']; ?>" width="100">
                                 <?php } ?>
                                 <label class="upimg" for="upimg_<?php echo $value['id']; ?>">
                                 upload image  
                                 <input type="file" id="upimg_<?php echo $value['id']; ?>" name="section_image_<?php echo $value['id']; ?>" value="Upload" class="form-control">
                                 </label>
                              </div>
                           </div>

                          <div class="form-group addpad">
                            <label class="col-sm-2 control-label">Section Image Alt</label>
                            <div class="col-sm-6">                     
                            <input type="text" class="form-control" name="content_image_alt_<?php echo $value['id']; ?>" value="<?php if($cmsDetails){ echo $value['content_image_alt']; } ?>" placeholder="Please enter Section Image Alt">
                            </div>
                          </div>
                           <div class="form-group">
                              <label class="col-sm-4 col-md-2 control-label">Section Video Url</label>
                              <div class="col-sm-6">
                                 <input type="text" name="section_video_<?php echo $value['id']; ?>" value="<?php echo $value['page_video']; ?>" class="form-control">
                              </div>
                           </div>
                       
                        
                     </div>
                  </div>
                 
                  <?php }          
                     }
                    }
                  ?>

               <div class="total_content col-sm-12">
                   <h2>New Section</h2>   
                  <div class="pageContent backgroundImage clearfix">
                    <div class="form-group rmv">
                      <div class="col-sm-3 addndel pull-right">
                        <span class="add">Add</span> 
                        <span class="removes">Delete</span> 
                      </div>

                      <label class="col-sm-3 col-md-2 control-label">Section Title</label>
                      <div class="col-sm-7 col-md-7">
                        <input type="text" name="section_title[]" value="" class="form-control">
                      </div>
                      
                    </div>
                    <div class="form-group">
                      <label class="col-sm-3 col-md-2 control-label">Section Content</label>
                      <div class="col-sm-9 col-md-7">
                        <textarea name="section_content[]" class="form-control"></textarea>
                        <script>
                           CKEDITOR.replace( 'section_content[]',{
                                    filebrowserBrowseUrl : '/castle/fileman/index.html',
                                    filebrowserImageBrowseUrl : '/castle/fileman/index.html?type=image',
                                    removeDialogTabs: 'link:upload;image:upload'
                            });
                        </script>  
                      </div>
                    </div>
                    <div class="col-sm-12 nopad">
                      <h4>Add Background Image or Video URL</h4>
                      <p>If want to show image dont fill video else fill video dont upload image</p>
                      
                      <div class="form-group">
                        <label class="col-sm-4 col-md-2 control-label">Section Image</label>
                        <div class="col-sm-8">
                          <label class="" for="">
                            Upload Image
                           <input type="file" id="" name="section_image[]" value="Upload" class="form-control">
                          </label>   
                      </div>
                      </div>
                      <div class="form-group">
                        <label class="col-sm-4 col-md-2 control-label">Section Video Url</label>
                        <div class="col-sm-7">
                          <input type="text" name="section_video[]" class="form-control">
                         </div>
                      </div>
                    </div>    
                    </div>
                </div>      
               <div class="resultContents"></div>
         </div>
         <!-- <span class="add"><i class="fa fa-plus" aria-hidden="true"></i></span>  -->
         <!--content-->
         <div class="box-footer">
         <button type="button" onclick="return_back()"class="btn btn-warning  margin-left  " >Cancel</button>
         <input type="submit" class="btn btn-black " value="Update" id="add">
         </div>
         <input type="hidden" name="frmSecurity" value="<?php echo $this->utility->getSecurity();?>"/>
         <!-- /.box-footer -->
         </form>
      </div>
   </div>
   </div>
</section>
<style type="text/css">
   .loader{
   position: fixed;
   left: 0;
   top: 0;
   right: 0;
   bottom: 0;
   width: 100%;
   height: 100%;
   background-color: rgba(0, 0, 0, 0.60);
   z-index: 9999;
   text-align: center;
   }
   .loader img{
   z-index: 99999;
   margin-top: 10%;
   }
</style>
<script type='text/javascript'>
   $("#add_frm").validate({
     rules: {
       title: {
         required: true,
       },
       content:{
         required:true
       }
     }
   });
</script>
<script type="text/javascript">
   function return_back()
   {
     var back_url='<?php echo base_url()?>admin/cms';
     window.location=back_url;
   }
   $(document).ready(function(){
     $('body').on('click','.add',function(){
        $('.resultContents').append($('.total_content').html());
      })
     $('body').on('click','.removes',function(){
        $(this).parent().parent().parent().remove();
        $(this).parent().parent().parent().prev().remove();
     })
     $('body').on('click','.remove',function(){
        if (!confirm('Are you sure?')) return false;
        //$('.resultContent').children().last().remove();
        $(this).parent().parent().parent().remove();
       var id = $(this).data('id');
       if(id)
       {
          $.ajax({
           url:'<?php echo base_url();?>admin/cms/deleteContentDetails',
           type:'POST',
           data:'id='+id,
           success: function(res){
     
           }
         })
       }
       
     })
   })
</script>

