Advertisement
Evengar

Untitled

Feb 3rd, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.51 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Tracking
  4.  */
  5. get_header(); ?>
  6. <script type="text/javascript" src="/wp-content/plugins/amazon_tracker/css/responsive-tables.js"></script>
  7.  
  8. <main class="site-main tracking">
  9.  
  10.     <div class="main-content">
  11.  
  12.         <header class="entry-header">
  13.             <h1 class="entry-title">Track your books</h1>
  14.         </header><!-- .entry-header -->
  15.         <!-- check if user is logged in -->
  16.  
  17.         <?php if (is_user_logged_in() ):?>
  18.  
  19.             <?php if (current_user_can('administrator') || current_user_can('premium') || current_user_can('warehouse_admin') ) :?>
  20.             <div class="entry-content">
  21.                 <?php
  22.                 global $trd_amazon_tracker;
  23.                 $user_id = get_current_user_id();
  24.                 //check if admin
  25.                 $is_admin = current_user_can('administrator') || current_user_can('warehouse_admin');
  26.                 $is_premium = current_user_can('premium');
  27.                 //count books
  28.                 $books_count = $trd_amazon_tracker->count_books($is_admin);
  29.                 //set up pagination
  30.                 $nb_elem_per_page = 10;
  31.                 $number_of_pages = intval($books_count/$nb_elem_per_page)+1;
  32.                 //page numbers
  33.                 if (isset($_GET['pn'])) {
  34.                     $page = $_GET['pn'];
  35.                 }
  36.                 else {
  37.                     $page = 1;
  38.                 }
  39.                
  40.                 //update status column
  41.                 if (isset($_GET['submit']) && isset($_GET['book_id']) && isset($_GET['user_status']) ) {
  42.                     $book_id = $_GET['book_id'];
  43.                     $book_status = $_GET['user_status'];
  44.                     $update = $trd_amazon_tracker->update_book_status($book_id, $book_status, $is_admin);
  45.                     if ($update) {
  46.                         echo 'Book status updated!';
  47.                     }
  48.                     else {
  49.                         echo 'Error updating book status';
  50.                     }
  51.                 }
  52.                 //get books    
  53.                 $books = $trd_amazon_tracker->generate_tracked_books_form($page);
  54.                 ?>
  55.  
  56.                 <table class="compat-table sortable tabelsorter responsive" id = "books_table">
  57.                     <thead>
  58.                         <tr class = "compat-table head">
  59.                             <th>Shipping Status</th>
  60.                             <th>Warehouse Status</th>
  61.                             <th>User Status</th>
  62.                             <th>Date</th>
  63.                             <th>Title / ISBN</th>
  64.                             <th>TRN-ID</th>
  65.                             <th>Author</th>
  66.                             <th>Cost, $</th>
  67.                             <th>Trade In, $</th>
  68.                             <th>Profit, $</th>
  69.                             <th>Attachment</th>
  70.                             <th>Actions</th>
  71.                         </tr>
  72.                     </thead>
  73.                     <tbody>
  74.                     <?php foreach ($books as $book) :?>
  75.                     <?php
  76.                     //get tracking registered at aftership and get tracking status
  77.                         $aftership_track_id = $book['tracking_id_aftership'];
  78.                        
  79.                         if (!empty($aftership_track_id)) {
  80.                             $track_status = $trd_amazon_tracker->check_tracking_status($aftership_track_id);
  81.                             $track_status_tag = $track_status['data']['tracking']['tag'];
  82.                         }
  83.                         else {
  84.                             $track_status_tag  = "N/A";
  85.                         }
  86.                         if (empty($book['track_status_manual'])) {
  87.                             $warehouse_status = "N/A";
  88.                         }
  89.                         else {
  90.                             $warehouse_status = $trd_amazon_tracker->status_dict($book['track_status_manual']);
  91.                         }
  92.                     ?>
  93.                    
  94.                         <tr>
  95.                             <td><?php echo $track_status_tag; ?></td>
  96.                             <td><?php echo $warehouse_status; ?></td>
  97.                             <td><?php echo $trd_amazon_tracker->status_dict($book['user_status']); ?></td>
  98.                             <td><?php echo $book['date'];?></td>
  99.                             <td><?php echo $book['book_title'];?>
  100.                                 <span class="isbn"><?php echo $book['isbn10'];?></span>
  101.                                 <span class="isbn"><?php echo $book['isbn13'];?></span>
  102.                             </td>
  103.                             <td><?php echo $book['trn_id'];?></td>
  104.                             <td><?php echo $book['author'];?></td>
  105.                             <td><?php echo $book['book_cost'];?></td>
  106.                             <td><?php echo $book['trd_in_value'];?></td>
  107.                             <td><?php echo floatval($book['trd_in_value']) - floatval($book['book_cost']) ;?> </td>
  108.                             <td><?php if (!empty($book['attachment_url'])):?><a href = "<?php echo $book['attachment_url'];?>">Attachment</a><?php endif;?></td>
  109.                             <!-- Premium user actions-->
  110.                             <?php if ( $is_premium ):?>
  111.                                 <td>
  112.                                     <a class="book_view_btn" href="<?php echo get_permalink($book['ID']);?>">View/Edit</a>
  113.                                     <span class="book_actions">
  114.                                         <a class="book_actions_btn" href= "#">Actions <i class="fa fa-caret-down" aria-hidden="true"></i></a>
  115.                                         <ul class="actions_dropdown">
  116.                                             <li>
  117.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=payment_received">Payment Received</a>
  118.                                             </li>
  119.                                             <li>
  120.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=rejected_by_buyer">Rejected by Buyer</a>
  121.                                             </li>
  122.                                             <li>
  123.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=refunded_by_seller">Refunded By Seller</a>
  124.                                             </li>
  125.                                             <li>
  126.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=donate_or_destroy">Donate or Destroy</a>
  127.                                             </li>
  128.                                             <li>
  129.                                                 <a href="<?php echo get_permalink($book['ID']);?>">Enter Seller Tracking Information</a>
  130.                                             </li>
  131.                                         </ul>
  132.                                     </span>
  133.                                 </td>
  134.                             <!-- if admin -->
  135.                             <?php else:?>
  136.  
  137.                                 <td>
  138.                                     <a class = "book_view_btn" href = "<?php echo get_permalink($book['ID']);?>">View/Edit</a>
  139.                                     <span class="book_actions">
  140.                                         <a class="book_actions_btn" href= "#">Actions <i class="fa fa-caret-down" aria-hidden="true"></i></a>
  141.                                         <ul class="actions_dropdown">
  142.                                             <li>
  143.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=waiting">Waiting</a>
  144.                                             </li>
  145.                                             <li>
  146.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=received">Received</a>
  147.                                             </li>
  148.                                             <li>
  149.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=sent_out">Sent out</a>
  150.                                             </li>
  151.                                             <li>
  152.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=received_with_issues">Received with issues</a>
  153.                                             </li>
  154.                                             <li>
  155.                                                 <a href="?submit=true&book_id=<?php echo $book['ID'];?>&user_status=label_voided">Label voided</a>
  156.                                             </li>                                          
  157.                                             <li>
  158.                                                 <a href="<?php echo get_permalink($book['ID']);?>">Enter Seller Tracking Information</a>
  159.                                             </li>
  160.                                         </ul>
  161.                                     </span>                                
  162.                                 </td>      
  163.                             <?php endif;?>
  164.                         </tr>
  165.                    
  166.                     <?php endforeach;?>
  167.                     </tbody>
  168.                 </table>
  169.             </div><!-- .entry-content -->
  170.  
  171.             <div class = "paginator_wrapper">
  172.  
  173.                 <ul id='paginator'>
  174.                     <?php
  175.                     wp_reset_query();
  176.                     for ($i=1; $i <= $number_of_pages; $i++): ?>
  177.                         <li class = "paginate-links"><a href="<?php echo get_permalink() . '?pn=' . $i; ?>"><?php echo $i;?></a></li>
  178.                     <?php endfor; ?>
  179.                 </ul>
  180.                     <span id ="page_status">Page <span class = "active_page_search"><?php echo $page; ?></span> of <?php echo $number_of_pages; ?></span>
  181.             </div>
  182.  
  183.                 <?php else:?>
  184.                     <div class="entry-content">
  185.                         <p>You have to be logged in as a Premium User to access this page</p>
  186.                     </div> 
  187.                 <?php endif;?>
  188.  
  189.             <?php else: ?>
  190.                 <div class="entry-content">
  191.                     <p>You have to be logged in to access this page</p>
  192.                     <a href = "<?php echo wp_login_url(); ?> ">Log In/Register</a>
  193.                 </div> 
  194.         <?php endif;?>
  195.     </div>
  196. </main>
  197. <script src = "<?php echo get_stylesheet_directory_uri();?>/js/jquery.tablesorter.js"></script>
  198. <script type="text/javascript">
  199.     jQuery("#books_table").tablesorter();
  200. </script>
  201. <script>
  202. (function($) {
  203.     $(function() {
  204.  
  205.         $( '.book_actions_btn' ).on( 'click', function(event) {
  206.             event.preventDefault();
  207.             $(this).parent().find('ul').fadeToggle(100);
  208.             $(this).toggleClass( 'active' );
  209.         });
  210.  
  211.     });
  212. }(jQuery));
  213. </script>
  214. <?php get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement