<?php defined('ABSPATH') or die("No script kiddies please!"); 
global $wpdb;
$pages = $this->get_all_page_lists();
$posts = $this->get_all_post_lists();
$categories = $this->get_categories();
$args = array('public' => true, '_builtin' => false);
$output = 'objects';
$operator = 'and';
$post_types = get_post_types($args, $output, $operator);

$all_post_types = array();
foreach ($post_types as $post_type) {
  $all_post_types[] = $post_type->name;
}
if (isset($page_specific_display) && is_array($page_specific_display)) {
  $show_pages_list_array = $page_specific_display;
} else {
  $show_pages_list_array = '';
}
?>
<div class="egpr_floating_review_settings egpr_manager_wrapper">
  <div class="hide_configuration">
    <p class="description"><?php _e('Choose default review from above reviews lists to display as floating review on specified below position on all pages, only on homepage or on specific pages. '. 'You can even changed assigned review name from its specific edit page.', 'everest-google-places-reviews'); ?></p>
  </div>
  <table>
    <tbody>
      <tr>
        <td class="egpr-name">
          <label for="enable_floating_review">
            <h4><?php _e('Enable Floating Review','everest-google-places-reviews');?></h4>
          </label>
        </td>
        <td class="egpr-value">
          <label class="egpr-switch">
           <input type="checkbox" name="egp_reviews[floating_review][enable_floating_review]" value="1" id="enable_floating_review" class="enable_floating_review-field" <?php
           if ( isset($enable_floating_review) ) {
            checked($enable_floating_review, true);
          }
          ?>/>
          <div class="egpr-slider round"></div>
        </label>
        <div class="egpr-tooltip-description">
          <div class="egpr-description">
           <?php _e('Please check to enable the floating review options for specific review.', 'everest-google-places-reviews'); ?>
         </div>
       </div>
     </td>
   </tr> 
   <tr>
    <td class="egpr-name">
      <label for="default_review"><?php _e('Default Review','everest-google-places-reviews');?></label>
    </td>
    <td class="egpr-value">
     <?php 
     global $egpr_wpdb;
     $review_posts = $egpr_wpdb->get_all_reviews('egprreviews');
                    //$this->displayArr($posts);
     ?>
     <select name="egp_reviews[floating_review][default_review]" data-settings='{"cutOff": 4}' class="dropdown" id="default_review">
       <option value="" class="label">-Choose Default Review Name-</option>
       <?php if(isset($review_posts) && !empty($review_posts)):
       foreach($review_posts as $key => $value){
         ?>
         <option value="<?php echo esc_attr($value['ID']);?>" <?php if($default_review == $value['ID']) echo "selected='selected'";?>><?php echo esc_attr($value['post_title']);?></option>
         <?php 
       }
       endif;
       ?>
     </select>
   </td>
 </tr> 
 <tr>
  <td class="egpr-name">
    <label for="floating_review_layout"><?php _e('Template Layout','everest-google-places-reviews');?></label>
  </td>
  <td class="egpr-value">
   <select name="egp_reviews[floating_review][layout]" id="floating_review_layout">
     <option value="template1" <?php selected( $layout, 'template1' ); ?>>Template1</option>                       
     <option value="template2" <?php selected( $layout, 'template2' ); ?>>Template2</option>
     <option value="template3" <?php selected( $layout, 'template3' ); ?>>Template3</option>
     <option value="template4" <?php selected( $layout, 'template4' ); ?>>Template4</option>
     <option value="template5" <?php selected( $layout, 'template5' ); ?>>Template5</option>
   </select>
   <p class="description"><?php _e('Choose any template layout among 5 for floating review.', 'everest-google-places-reviews'); ?></p>
   <div class="floating_review_preview">
    <div id="floating_template1" class="review_preview <?php if ($layout == 'template1') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
      <div class="egpr-fleft"> <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-1.png' ?>"/></div>
    </div>
    <div id="floating_template2" class="review_preview <?php if ($layout == 'template2') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
      <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-2.png' ?>"/>
    </div> <div id="floating_template3" class="review_preview <?php if ($layout == 'template3') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
    <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-3.png' ?>"/>
  </div> <div id="floating_template4" class="review_preview <?php if ($layout == 'template4') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
  <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-4.png' ?>"/>
</div> 
<div id="floating_template5" class="review_preview <?php if ($layout == 'template5') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
 <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-5.png' ?>"/>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<table>
  <tbody>
    <tr class="position">
      <td class="egpr-name">
        <label for="egpr_freview_placement"><?php _e('Review Position','everest-google-places-reviews');?></label>
      </td>
      <td class="egpr-value">
       <select name="egp_reviews[floating_review][placement]" id="egpr_freview_placement" class="dropdown" tabindex="5" data-settings='{"cutOff":5}'>
         <option value="top-left" <?php selected( $placement, 'top-left' ); ?>>Top Left</option>
         <option value="left" <?php selected($placement, 'left' ); ?>>Middle Left</option> 
         <option value="bottom-left" <?php selected($placement, 'bottom-left' ); ?>>Bottom Left</option>
         <option value="top-right" <?php selected( $placement, 'top-right' ); ?>>Top Right</option>
         <option value="right" <?php selected( $placement, 'right' ); ?>>Middle Right</option>
         <option value="bottom-right" <?php selected( $placement, 'bottom-right' ); ?>>Bottom Right</option>
       </select>
       <p class="description"><?php _e('Choose where to display floating review.', 'everest-google-places-reviews'); ?></p>
     </td>
   </tr>
   <tr class="display_pages">
    <td class="egpr-name">
      <label for="egpr_freview_display"><?php _e('Show Floating Review On','everest-google-places-reviews');?></label>
    </td>
    <td class="egpr-value">
     <select name="egp_reviews[floating_review][show_floating_review_on]" id="egpr_freview_display" class="dropdown" data-settings='{"cutOff": 12}'>
       <option value="all_pages" <?php selected( $display, 'all_pages' ); ?>><?php _e('Show On All Pages', 'everest-google-places-reviews'); ?></option>
       <option value="all_posts" <?php selected( $display, 'all_posts' ); ?>><?php _e('Show On All Posts', 'everest-google-places-reviews'); ?></option>
       <option value="only_on_home_page" <?php selected($display, 'only_on_home_page' ); ?>><?php _e('Home Page Only', 'everest-google-places-reviews'); ?></option> 
       <option value="specific_pages" <?php selected($display, 'specific_pages' ); ?>><?php _e('Show On Specific', 'everest-google-places-reviews'); ?></option>
     </select>
     <p class="description"><?php _e('Choose where to display floating review.', 'everest-google-places-reviews'); ?></p>
   </td>
 </tr>
</tbody>
</table>
<div class="clear"></div> 
<div class="egpr-option-select-specific-page"  <?php if ($display == 'specific_pages') { ?>style="display: block;"<?php } else { ?> style="display: none;"<?php } ?>>
  <?php if (count($pages) > 0) { ?>
  <div class="egpr_display"> 
   <h3><?php _e('Pages', 'everest-google-places-reviews') ?></h3>
   <ul class="egpr-cpage-specific-display"> 
    <?php foreach ($pages as $key => $val) { ?>                                                                     
    <li>
      <input type="checkbox" id="page-checkbox-<?php echo $key;?>" class="egpr-display-add-check" name="egp_reviews[floating_review][page_specific_display][]" 
      value="<?php echo $key; ?>" <?php if (!empty($show_pages_list_array) && in_array($key, $show_pages_list_array)) { ?>checked="checked"<?php } ?>/>
      <label class="pages" for="page-checkbox-<?php echo $key;?>"><?php echo $val; ?></label>
    </li>
    <?php
  }
  ?>
</ul>
</div>
<?php } ?>
<?php if (count($posts) > 0) {
  ?>
  <div class="egpr_display"> 
    <h3><?php _e('Posts', 'everest-google-places-reviews') ?></h3>
    <ul class="egpr-cpage-specific-display">
      <?php foreach ($posts as $key => $val) { ?>
      <li>
        <input type="checkbox" id="posts-checkbox-<?php echo $key;?>" class="egpr-display-add-check" 
        name="egp_reviews[floating_review][page_specific_display][]" value="<?php echo $key; ?>" <?php if (!empty($show_pages_list_array) && in_array($key, $show_pages_list_array)) { ?>checked="checked"<?php } ?>/>
        <label class="pages" for="posts-checkbox-<?php echo $key;?>"><?php echo $val; ?></label>
      </li>    
      <?php } ?>
    </ul>
    </div><?php
  } ?>
  <?php 
  if (count($categories) > 0) {?>
  <div class="egpr_display"> 
    <h3><?php _e('Categories', 'everest-google-places-reviews') ?></h3>
    <ul class="egpr-cpage-specific-display">
      
      <?php foreach ($categories as $key => $val) { ?>  
      <li>
        <input type="checkbox" id="category-checkbox<?php echo $key; ?>" class="egpr-display-add-check" 
        name="egp_reviews[floating_review][page_specific_display][category][]" value="<?php echo $key; ?>" <?php if (!empty($show_pages_list_array['category']) && in_array($key, $show_pages_list_array['category'])) { ?>checked="checked"<?php } ?>/>
        <label class="pages" for="category-checkbox<?php echo $key; ?>"><?php echo $val; ?></label>
      </li>
      <?php } ?>
    </ul>
  </div>
  <?php } ?>  
  <?php  if (count($all_post_types) > 0) {  ?>
  <h3><?php _e('Custom Post Types', 'everest-google-places-reviews') ?></h3>
  <?php  foreach ($all_post_types as $postypes => $postype) { 
   $post_type_title = array();
   $args = array('post_type' => $postype, 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC');
   $querys = new WP_Query($args);
   if ($querys->have_posts()): ?>
   <div class="egpr_display"> 
     <label for="post-type-section-<?php echo $postype; ?>">
      <h4 class="post-type-section" id="post-type-section-<?php echo $postype; ?>"><?php echo $postype; ?></h4>
    </label>
    <ul class="egpr-cpage-specific-display"> 
     <?php while ($querys->have_posts()):$querys->the_post();
     $titlee = get_the_title();
     $Posttype_ID = get_the_ID();
     ?>
     <li>
      <input type="checkbox" id="custom-ptype-checkbox-<?php echo $postype; ?>-<?php echo $Posttype_ID; ?>" class="egpr-display-add-check" name="egp_reviews[floating_review][page_specific_display][]" value="<?php echo $Posttype_ID; ?>" <?php
      if (!empty($show_pages_list_array) && in_array($Posttype_ID, $show_pages_list_array)) {
        echo "checked='checked'";
      }
      ?>/>
      <label class="pages" for="custom-ptype-checkbox-<?php echo $postype; ?>-<?php echo $Posttype_ID; ?>"><?php the_title(); ?></label>
    </li>                
  <?php endwhile; ?>
</ul>
</div>
<?php endif; } ?>
<?php } ?>     
</div>
</div>