Advertisement
Evengar

Untitled

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