Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This class provides the actual item that is bought by the user
- */
- class wit_date
- {
- private static $instance;
- /*
- Create the metabox for the insertion and the metabox for the display of the already available dates
- */
- public function __construct()
- {
- $this->insertMetaDate();
- $this->displayDates();
- }
- public static function getInstance()
- {
- if (!self::$instance)
- {
- self::$instance = new wit_date();
- }
- return self::$instance;
- }
- /*
- Removes a specific date item for a route
- */
- public function removeDate( $data )
- {
- check_ajax_referer( 'adsfadsfasdfadsfd', 'security' );
- global $wpdb;
- $sql = "DELETE FROM ". $wpdb->prefix . "witchroute_dates WHERE id=%d";
- $wpdb->query($wpdb->prepare($sql, $data['id']));
- $sql = "SELECT * FROM " . $wpdb->prefix . "witchroute_dates WHERE post_id=%d";
- $dates = $wpdb->get_results( $wpdb->prepare($sql, $data['post_id']) );
- $url = bloginfo('wpurl');
- foreach ($dates as $date)
- {
- $html .= <<<HTML
- <tr>
- <td>$date->start_date</td>
- <td>$date->end_date</td>
- <td>$date->price</td>
- <td>$date->available</td>
- <td>$date->seats</td>
- <td><img src="{$url}/wp-content/plugins/witchroute/images/icons/minus-button.png" alt="Delete" class="witchroute_delete_btn" date-id="$date->id" /></td>
- </tr>
- HTML;
- }
- print $html;
- die();
- }
- /*
- Inserts a new date item to a specific route!
- */
- public function insertDate($data)
- {
- check_ajax_referer( 'asjdnhaspdas[dasudasodasd', 'security' );
- global $wpdb;
- $dataForDb = array('start_date' => $data['start_date'],
- 'end_date' => $data['end_date'],
- 'price' => $data['price'],
- 'seats' => $data['seats'],
- 'available' => $data['seats'],
- 'post_id' => $data['post_id']
- );
- $wpdb->insert( $wpdb->prefix . "witchroute_dates", $dataForDb);
- $sql = "SELECT * FROM " . $wpdb->prefix . "witchroute_dates WHERE post_id=%d";
- $dates = $wpdb->get_results( $wpdb->prepare($sql, $data['post_id']) );
- $url = bloginfo('wpurl');
- foreach ($dates as $date)
- {
- $html .= <<<HTML
- <tr>
- <td>$date->start_date</td>
- <td>$date->end_date</td>
- <td>$date->price</td>
- <td>$date->available</td>
- <td>$date->seats</td>
- <td><img src="{$url}/wp-content/plugins/witchroute/images/icons/minus-button.png" alt="Delete" class="witchroute_delete_btn" date-id="$date->id" /></td>
- </tr>
- HTML;
- }
- print $html;
- die();
- }
- /**
- * Insert the form to insert dates
- **/
- public function insertMetaDate()
- {
- add_action('add_meta_boxes', function() {
- add_meta_box('wit-route-dates-insert', 'Termine zum Buchen', 'show_date_insert_form', 'wit-route');
- });
- function show_date_insert_form($post)
- {
- include('views/date-insert-form.html');
- }
- }
- /**
- * Insert a table that shows all the dates for this route!
- **/
- public function displayDates()
- {
- add_action('add_meta_boxes', function() {
- add_meta_box('wit-route-dates-display', 'Hinterlegte Termine', 'show_date_display_box', 'wit-route');
- });
- function show_date_display_box()
- {
- function getDatesForRoute()
- {
- global $wpdb, $post;
- $sql = "SELECT * FROM " . $wpdb->prefix . "witchroute_dates WHERE post_id=%d";
- return $wpdb->get_results( $wpdb->prepare($sql, $post->ID) );
- }
- $dates = getDatesForRoute();
- include('views/date-display.html');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment