Advertisement
MrViSiOn

Untitled

Dec 10th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Checklist
  4.  */
  5. get_header();
  6. ?>
  7. <script>
  8.   var URI = "<?php echo get_template_directory_uri(); ?>/";
  9.     jQuery(document).ready(function($) {
  10.         $('.checklist-listing input').change(function(event) {
  11.             var data = {};
  12.             data[$(this).attr("name")] = $(this).is(':checked');
  13.             $.ajax({
  14.                 url: URI+"checklist-ajax.php",
  15.                 type: 'POST',
  16.                 data: data,
  17.             })
  18.             .done(function( data, textStatus, jqXHR ) {
  19.             });
  20.         });
  21.     });
  22. </script>
  23. <div style="width: 100%;">
  24. <?php
  25.         //Cargar checklist del usuario
  26.         $user_ID = get_current_user_id();
  27.         $checklist = unserialize(get_user_meta($user_ID, "checklist", true));
  28.  
  29.         $esNuevo = false;
  30.         if(!$checklist){
  31.             $checklist = array();
  32.             $esNuevo = true;
  33.         }
  34.         // Define the query y obtener todos los items
  35.     $args = array(
  36.         'post_type' => 'checklist'
  37.     );
  38.     $query = new WP_Query( $args );
  39.  
  40.     $checklistArray = array();
  41.  
  42.     if($query->have_posts()):
  43. ?>
  44.         <ul class="">
  45. <?php
  46.         while ( $query->have_posts() ) : $query->the_post(); ?>
  47.             <?php
  48.                 if(array_key_exists("checklist-".get_the_ID(), $checklist)){
  49.                     $checklistArray["checklist-".get_the_ID()] = $checklist["checklist-".get_the_ID()];
  50.                 }else{
  51.                     $checklistArray["checklist-".get_the_ID()] = false;
  52.                 }
  53.             ?>
  54.           <li class="checklist-listing" id="post-<?php the_ID(); ?>">
  55.             <input type="checkbox" name="checklist-<?php the_ID(); ?>" id="checklist-id-<?php the_ID(); ?>" <?php echo (strlen($checklistArray["checklist-".get_the_ID()])>0) ? "checked='checked'" : ""; ?>> <label for="checklist-id-<?php the_ID(); ?>"><?php the_title(); ?></label>
  56.           </li>
  57. <?php endwhile; ?>
  58.         </ul>
  59. <?php endif; ?>
  60. <?php if($esNuevo) add_user_meta( $user_ID, "checklist", serialize($checklistArray)); ?>
  61. </div>
  62. <?php
  63. get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement