Guest User

Untitled

a guest
Feb 10th, 2012
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.50 KB | None | 0 0
  1. <?php
  2.     /*
  3.         This class provides the actual item that is bought by the user
  4.     */
  5.     class wit_date
  6.     {
  7.         private static $instance;
  8.  
  9.         /*
  10.             Create the metabox for the insertion and the metabox for the display of the already available dates
  11.         */
  12.         public function __construct()
  13.         {
  14.             $this->insertMetaDate();
  15.             $this->displayDates();         
  16.         }
  17.  
  18.  
  19.         public static function getInstance()
  20.         {
  21.             if (!self::$instance)
  22.             {
  23.                 self::$instance = new wit_date();
  24.             }
  25.  
  26.             return self::$instance;
  27.         }
  28.  
  29.         /*
  30.             Removes a specific date item for a route
  31.         */
  32.         public function removeDate( $data )
  33.         {
  34.             check_ajax_referer( 'adsfadsfasdfadsfd', 'security' );
  35.             global $wpdb;
  36.  
  37.             $sql    =   "DELETE FROM ". $wpdb->prefix . "witchroute_dates WHERE id=%d";
  38.             $wpdb->query($wpdb->prepare($sql, $data['id']));
  39.  
  40.  
  41.             $sql    =   "SELECT * FROM " . $wpdb->prefix . "witchroute_dates WHERE post_id=%d";
  42.             $dates =  $wpdb->get_results( $wpdb->prepare($sql, $data['post_id']) );
  43.  
  44.             $url    =   bloginfo('wpurl');
  45.             foreach ($dates as $date)
  46.             {
  47.                 $html .= <<<HTML
  48. <tr>
  49. <td>$date->start_date</td>
  50. <td>$date->end_date</td>
  51. <td>$date->price</td>
  52. <td>$date->available</td>
  53. <td>$date->seats</td>
  54. <td><img src="{$url}/wp-content/plugins/witchroute/images/icons/minus-button.png" alt="Delete" class="witchroute_delete_btn" date-id="$date->id" /></td>
  55. </tr>
  56. HTML;
  57.  
  58.             }
  59.             print $html;
  60.             die();
  61.         }
  62.  
  63.         /*
  64.             Inserts a new date item to a specific route!
  65.         */
  66.         public function insertDate($data)
  67.         {
  68.             check_ajax_referer( 'asjdnhaspdas[dasudasodasd', 'security' );
  69.  
  70.             global $wpdb;
  71.            
  72.             $dataForDb  = array('start_date'    => $data['start_date'],
  73.                                 'end_date'      => $data['end_date'],
  74.                                 'price'         => $data['price'],
  75.                                 'seats'         => $data['seats'],
  76.                                 'available'     => $data['seats'],
  77.                                 'post_id'       => $data['post_id']
  78.                                 );
  79.                            
  80.             $wpdb->insert( $wpdb->prefix . "witchroute_dates", $dataForDb);
  81.  
  82.             $sql    =   "SELECT * FROM " . $wpdb->prefix . "witchroute_dates WHERE post_id=%d";
  83.  
  84.             $dates =  $wpdb->get_results( $wpdb->prepare($sql, $data['post_id']) );
  85.  
  86.             $url    =   bloginfo('wpurl');
  87.             foreach ($dates as $date)
  88.             {
  89.                 $html .= <<<HTML
  90. <tr>
  91. <td>$date->start_date</td>
  92. <td>$date->end_date</td>
  93. <td>$date->price</td>
  94. <td>$date->available</td>
  95. <td>$date->seats</td>
  96. <td><img src="{$url}/wp-content/plugins/witchroute/images/icons/minus-button.png" alt="Delete" class="witchroute_delete_btn" date-id="$date->id" /></td>
  97. </tr>
  98. HTML;
  99.  
  100.             }
  101.             print $html;
  102.             die();
  103.         }
  104.  
  105.  
  106.         /**
  107.         *   Insert the form to insert dates
  108.         **/
  109.         public function insertMetaDate()
  110.         {
  111.             add_action('add_meta_boxes', function() {
  112.                 add_meta_box('wit-route-dates-insert', 'Termine zum Buchen', 'show_date_insert_form', 'wit-route');
  113.             });
  114.  
  115.  
  116.             function show_date_insert_form($post)
  117.             {
  118.                 include('views/date-insert-form.html');
  119.             }
  120.         }
  121.  
  122.         /**
  123.         *   Insert a table that shows all the dates for this route!
  124.         **/
  125.         public function displayDates()
  126.         {
  127.             add_action('add_meta_boxes', function() {
  128.                 add_meta_box('wit-route-dates-display', 'Hinterlegte Termine', 'show_date_display_box', 'wit-route');
  129.             });
  130.  
  131.  
  132.             function show_date_display_box()
  133.             {
  134.                 function getDatesForRoute()
  135.                 {
  136.                     global $wpdb, $post;
  137.  
  138.                     $sql    =   "SELECT * FROM " . $wpdb->prefix . "witchroute_dates WHERE post_id=%d";
  139.                     return $wpdb->get_results( $wpdb->prepare($sql, $post->ID) );
  140.                 }
  141.  
  142.                 $dates  =   getDatesForRoute();
  143.  
  144.                 include('views/date-display.html');
  145.             }
  146.         }
  147.     }
Advertisement
Add Comment
Please, Sign In to add comment