Advertisement
Guest User

Untitled

a guest
Dec 24th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.92 KB | None | 0 0
  1. <?php acf_form_head(); ?>
  2. <?php get_header(); ?>
  3.  
  4. <?php
  5. function my_acf_load_value( $value, $post_id, $field ) { // ORDER BY ASSESSMENT DATE
  6.  
  7. // vars
  8. $order = array();
  9.  
  10. // bail early if no value
  11. if( empty($value) ) {
  12. return $value;
  13. }
  14.  
  15. // populate order
  16. foreach( $value as $i => $row ) {
  17. $order[ $i ] = $row['field_5753d72618569'];
  18. }
  19.  
  20. // multisort
  21. array_multisort( $order, SORT_ASC, $value );
  22.  
  23. // return
  24. return $value;
  25. }
  26.  
  27. add_filter('acf/load_value/name=assessments', 'my_acf_load_value', 10, 3);
  28. ?>
  29.  
  30. <div id="placeholder"></div>
  31.  
  32. <div id="legend"></div>
  33. <div class="wrap">
  34.  
  35. <h1 class="main-header">Booking Matrix</h1>
  36.  
  37. <?php global $bp; //Gobal BuddyPress?>
  38.  
  39. <div id="filtrify" class="filtrify">
  40.  
  41. <?php
  42. global $wpdb, $current_user, $EM_Notices, $EM_Person;
  43.  
  44. $people = array();
  45. $events = EM_Events::get(array('scope'=>'all','order'=>'DESC','orderby'=>'event_end_date,event_end_time'));
  46. $pass = array(2,3,4,5); // Check if assessment passed
  47. //echo '<pre>' . var_export($events, true) . '</pre>';
  48.  
  49. $args = array(
  50. 'role' => 'technician',
  51. 'numberposts' => -1,
  52. 'order' => 'DESC',
  53. 'orderby' => 'meta_value',
  54. 'meta_key' => 'assessment_date',
  55. );
  56.  
  57. $techs = new WP_User_Query( $args );
  58. foreach($techs->results as $tech) :
  59. setup_postdata( $post );
  60. endforeach;
  61.  
  62. foreach($events as $event ) :
  63. setup_postdata( $post );
  64. endforeach;
  65.  
  66. $previous_course_date = "";
  67.  
  68. foreach ( $events as $event ) {
  69. $EM_Bookings = $event->get_bookings();
  70. $current_course_date = $event->event_start_date;
  71. if (($current_course_date != $previous_course_date) && (count($EM_Bookings->bookings) > 0)) { ?>
  72.  
  73. <h5 class="adf-header"><strong><?php echo date("d M Y",strtotime($event->event_start_date)) . " - " . date("d M Y",strtotime($event->event_end_date)); ?></strong>
  74. <?php
  75. $approved = 0;
  76. $pending = 0;
  77. foreach($EM_Bookings->bookings as $book) { // Check if transaction exists
  78. if(($book->previous_status) == 1) {
  79. $approved = $approved + 1;
  80. } elseif(($book->previous_status) != 1) {
  81. $pending = $pending + 1;
  82. };
  83. };
  84. /* echo highlight_string("<?php\n\$book =\n" . var_export($book, true) . ";\n?>") ; */
  85. echo "<span class=\"booking-stats\">";
  86. echo $approved . " <i class=\"fa fa-thumbs-o-up\" aria-hidden=\"true\"></i> | " . $pending . " <i class=\"fa fa-thumbs-o-down\" aria-hidden=\"true\"></i>";
  87. echo "</span>";
  88. ?></h5>
  89.  
  90. <table class="booking-matrix">
  91. <tr class="table-header">
  92. <td>Name</td>
  93. <td>Email</td>
  94. <td>Contact</td>
  95. <td>Status</td>
  96. <td>Notes</td>
  97. <td class="icons"><a href="<?php echo site_url(); ?>/wp-admin/edit.php?post_type=event&page=events-manager-bookings&event_id=<?php echo $event->event_id; ?>&action=manual_booking" target="_blank"><i class="fa fa-plus-square" aria-hidden="true"></i></a> <a href="<?php echo site_url(); ?>/wp-admin/post.php?post=<?php echo $event->post_id; ?>&action=edit" target="_blank"><i class="fa fa-pencil-square" aria-hidden="true"></i></a> <a href="<?php echo site_url(); ?>/wp-admin/edit.php?post_type=event&page=events-manager-bookings&event_id=<?php echo $event->event_id; ?>" target="_blank"><i class="fa fa-eye" aria-hidden="true"></i></a></td>
  98. </tr>
  99.  
  100. <?php
  101. $guest_bookings = get_option('dbem_bookings_registration_disable');
  102. $guest_booking_user = get_option('dbem_bookings_registration_user');
  103.  
  104. foreach( $EM_Bookings as $EM_Booking){
  105. $people[] = $EM_Booking->get_person()->ID;
  106. $person = $EM_Booking->get_person()->ID;
  107. $user_info = get_userdata($person); //Default WP data
  108. $user = 'user_' . $person; // Dispayed User ID
  109. $b_status = $EM_Booking->booking_meta['gateway']; //transaction status
  110. // Current Level
  111. if(get_field('assessments',$user)):
  112. $assessments_repeater = array_reverse(get_field('assessments',$user)); // Assessments Repeater
  113. $ass_latest = end($assessments_repeater); // Last row of repeater
  114. $ass_latest_rating = $ass_latest['ass_rating']; // Rating
  115. $ass_at = $ass_latest['assessed_at']; // Assessed at
  116. $latest_doc_dispatch = $ass_latest['docs_dispatched'];
  117. // $current_level = get_field('current_level',$user); // Current level
  118.  
  119. $current_level = "N/A"; // Check if assessment
  120. $pass = array("2","3","4","5");
  121.  
  122. foreach($assessments_repeater as $ass) {
  123. if (in_array($ass["ass_rating"], $pass)) {
  124. $ass_at = $ass["assessed_at"];
  125. $current_level = $ass_at;
  126. break;
  127. } else {
  128. $current_level = "N/A";
  129. }
  130. }
  131. endif; // Current Level
  132. ?>
  133.  
  134. <?php if(1 == 1): // Check transaction status ?>
  135.  
  136. <tr>
  137. <td><a class="pop details-<?php echo $person ?>"><?php echo $EM_Booking->get_person()->get_name(); ?></a></td>
  138. <td><?php echo $user_info->user_email; ?></td>
  139. <td><?php echo the_field('contact_number', $user); ?></td>
  140. <td><?php if($EM_Booking->previous_status == 1) {
  141. echo "Paid";
  142. } else {
  143. echo "Awaiting Payment";
  144. }; ?></td>
  145. <form id="all-bookings" class="acf-form" action="" method="post">
  146. <?php
  147. add_action( 'wp_print_styles', 'tsm_deregister_admin_styles', 999 );
  148. /**
  149. * Add edit post toggle button
  150. */
  151. add_action( 'loop_start', 'tsm_do_acf_form_edit_toggle', 5 );
  152. /**
  153. * Add the acf_form
  154. * @uses Advanced Custom Fields Pro
  155. */
  156. add_action( 'loop_end', 'tsm_do_acf_form_content' );
  157. /**
  158. * Load existing post title
  159. * @uses Advanced Custom Fields Pro
  160. */
  161. add_filter( 'acf/load_value/key=field_54dfc93e35ec4', 'tsm_load_post_title', 10, 3 );
  162. /**
  163. * Load existing post content
  164. * @uses Advanced Custom Fields Pro
  165. */
  166. add_filter( 'acf/load_value/key=field_54dfc94e35ec5', 'tsm_load_post_content', 10, 3 );
  167. /**
  168. * Load existing email
  169. * @uses Advanced Custom Fields Pro
  170. */
  171. add_filter( 'acf/load_value/key=field_54dfc94e35ec5', 'tsm_load_post_content', 10, 3 );
  172. /**
  173. * Load existing post thumbnail
  174. * @uses Advanced Custom Fields Pro
  175. */
  176. add_filter( 'acf/load_value/key=field_54dfcd4278d63', 'tsm_load_post_thumbnail', 10, 3 );
  177. /**
  178. * Load existing post author
  179. * @uses Advanced Custom Fields Pro
  180. */
  181. add_filter( 'acf/load_value/key=field_55fd4e421dfb6', 'tsm_load_post_author', 10, 3 );
  182. /**
  183. * Update existing post data
  184. * @uses Advanced Custom Fields Pro
  185. */
  186. add_action( 'acf/save_post', 'tsm_update_existing_post_data', 10 );
  187. // acf/update_value/name={$field_name} - filter for a specific field based on it's key
  188.  
  189. ?>
  190.  
  191. <?php
  192. $edit_post = array(
  193. 'id' => 'all-bookings',
  194. 'post_id' => $user, // Get the post ID
  195. 'field_groups' => array(10), // Create post field group ID(s)
  196. 'field_el' => 'td',
  197. 'fields' => array(
  198. 'field_584fe30107cd9', //Notes
  199. ),
  200. 'form' => false,
  201. 'return' => add_query_arg( 'details', 'updated', get_permalink() ),
  202. 'html_before_fields' => '',
  203. 'submit_value' => "Save",
  204. );
  205.  
  206. //load acf_form based on POST TYPES
  207.  
  208. acf_form( $edit_post );
  209. ?>
  210. <td class="acf-form-submit">
  211. <input type="submit" class="acf-button button button-primary button-large" value="Update">
  212. <span class="acf-spinner"></span>
  213. </td>
  214. </tr>
  215.  
  216. </form>
  217.  
  218. <div
  219. data-Assessment-Date="<?php echo date("d F Y",strtotime(get_field('assessment_date', $user)))?>"
  220. <?php if(get_field('assessments',$user)){ ?>
  221. data-Level="Level <?php echo $current_level; ?>"
  222. <?php } ?>
  223. data-Referral-Code="<?php echo "Code:" . do_shortcode('[affiliates_affiliate_id_by_user id="' . $person . '" /]') ?>"
  224. data-Name="<?php echo $EM_Booking->get_person()->get_name() ?>"
  225. >
  226.  
  227. <!-- PopUp container -->
  228. <div class="popup details-container-<?php echo $person;?>">
  229. <h5><?php echo $EM_Booking->get_person()->get_name(); ?></h5>
  230.  
  231. <!-- Profile Picture -->
  232. <div class="pop-inner details-<?php echo $person;?>">
  233. <a href="<?php echo bp_core_get_user_domain( $person );?>profile" target="_blank" class="view-profile-link">
  234. <?php echo bp_core_fetch_avatar ( array( 'item_id' => $person, 'type' => 'full', 'style' => 'margin: 0; border: 1px solid #ccc; padding: 3px; border-radius: 5px padding: 3px; height: 150px' ) ); ?>
  235. </a>
  236. </div>
  237.  
  238. <!-- Personal Details -->
  239. <h6>Personal Details</h6>
  240. <div class="icon phone"><i class="fa fa-phone" aria-hidden="true"></i> <?php echo get_field('contact_number', $user); ?></div>
  241. <div class="icon email"><i class="fa fa-envelope" aria-hidden="true"></i> <?php echo $user_info->user_email; ?></div>
  242.  
  243. <!-- IRATA Details -->
  244. <h6>IRATA Details</h6>
  245. <div class="icon irata-number"><i class="fa fa-user" aria-hidden="true"></i> <?php echo get_field('irata_number', $user); ?></div>
  246. <?php if(get_field('assessments',$user)){ ?>
  247. <div class="icon level"><i class="fa fa-trophy" aria-hidden="true"></i> <?php echo $current_level;?></div>
  248. <?php } ?>
  249.  
  250. <?php if( have_rows('assessments', $user)): ?>
  251.  
  252. <?php while( have_rows('assessments', $user)): the_row();
  253. endwhile;
  254.  
  255. $dates = get_field('assessments', $user);
  256. $latest_date = array_shift($dates);
  257. $date_ass_before = $latest_date['ass_date'];
  258. $date_ass = str_replace('/', '-', $date_ass_before); // strtotime doesn't work with /d/m/y format
  259.  
  260. $now = time();
  261. $exp_date = strtotime('+3 year', strtotime($date_ass));
  262. $exp_date_new = strtotime('-1 day', $exp_date);
  263. $datediff = $exp_date_new - $now;
  264. $remaining = floor($datediff/(60*60*24));
  265. ?>
  266. <div class="icon expiration">
  267. <i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo $remaining . " days left (" . date('d F Y', $exp_date_new) . ")"; ?>
  268. </div>
  269.  
  270. <?php endif;?>
  271.  
  272. <!-- Address -->
  273. <h6>Address:</h6>
  274. <?php
  275. if(get_field('address_line_1', $user)){
  276. echo get_field('address_line_1', $user);
  277. echo "<br/>";
  278. }
  279. if(get_field('address_line_2', $user)){
  280. echo get_field('address_line_2', $user);
  281. echo "<br/>";
  282. }
  283. if(get_field('address_line_3', $user)){
  284. echo get_field('address_line_3', $user);
  285. echo "<br/>";
  286. }
  287. if(get_field('city', $user)){
  288. echo get_field('city', $user);
  289. echo "<br/>";
  290. }
  291. if(get_field('state-province', $user)){
  292. echo get_field('state-province', $user);
  293. echo "<br/>";
  294. }
  295. if(get_field('country', $user)){
  296. echo get_field('country', $user);
  297. echo "<br/>";
  298. }
  299. if(get_field('post_code', $user)){
  300. echo get_field('post_code', $user);
  301. } ?>
  302. </div> <!-- PopUp Container -->
  303.  
  304. </div> <!-- tech -->
  305.  
  306. <?php endif; //booking status check ?>
  307. <?php
  308.  
  309. // }elseif($EM_Booking->booking_status == 1 && $guest_bookings && $EM_Booking->get_person()->ID == $guest_booking_user ){
  310. // echo '<li>'. $EM_Booking->get_person()->get_name() .'</li>';
  311. // }
  312. }
  313. ?>
  314. </table>
  315. <?php
  316. }
  317. }
  318. wp_reset_postdata();
  319. ?>
  320. </div>
  321. </div>
  322.  
  323. <script>
  324. jQuery(document).ready(function(){
  325. jQuery.filtrify("filtrify", "placeholder", {
  326. close : true,
  327. callback : function( query, match, mismatch ) {
  328. if ( !mismatch.length ) {
  329. jQuery("h1").removeClass('filtered').html("Technicians");
  330. jQuery('.tech').removeClass('tech-view');
  331. } else {
  332. jQuery('.tech').addClass('tech-view');
  333. var category, tags, i, tag, legend = "<strong>Currently filtered by:</strong><br/>";
  334. for ( category in query ) {
  335. tags = query[category];
  336. if ( tags.length ) {
  337. legend += "";
  338. for ( i = 0; i < tags.length; i++ ) {
  339. tag = tags[i];
  340. legend += "<br/>" + tag ;
  341. };
  342. legend += "";
  343. };
  344. };
  345. jQuery("h1").addClass('filtered').html( legend );
  346. };
  347. }
  348. });
  349. });
  350. </script>
  351. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement