/shortcodes.php

https://bitbucket.org/nfredricks/wp-employee-time · PHP · 55 lines · 50 code · 5 blank · 0 comment · 4 complexity · da9ccfcd28eeeee0e2aaa3b6d663b121 MD5 · raw file

  1. <?php
  2. function timesheet_table($atts){
  3. global $wpdb;
  4. $table_name = $wpdb->prefix."employee_time";
  5. extract( shortcode_atts( array('offset' => '0', 'id' => get_current_user_id()), $atts));
  6. $total_hours = 0;
  7. $raw_hours = 0;
  8. if($offset == '0'){
  9. $title = "Current Week";
  10. }
  11. elseif($offset == '1'){
  12. $title = ucfirst(convert_number_to_words($offset))." Week Ago";
  13. }
  14. else{
  15. $title = ucfirst(convert_number_to_words($offset))." Weeks Ago";
  16. }
  17. $offset = "-".$offset;
  18. $week = get_week($offset);
  19. ?>
  20. <table class="time_sheet_table">
  21. <thead>
  22. <tr>
  23. <th colspan=2><?php echo $title; ?></th>
  24. </tr>
  25. <tr>
  26. <th>Day</th>
  27. <th>Hours</th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <?php
  32. for($i=0; $i<7; $i++){
  33. echo "<tr>";
  34. list($year, $month, $day) = explode("-", $week[$i]);
  35. $day = date('l, M d',mktime('0','0','0',$month,$day,$year));
  36. $hours = time_for_day($week[$i], $id, $wpdb, $table_name);
  37. echo "<td>".$day."</td>";
  38. echo "<td>".$hours['rounded']." (actual: ".$hours['raw'].")</td>";
  39. echo "</tr>";
  40. $total_hours += $hours['rounded'];
  41. $raw_hours += $hours['raw'];
  42. }
  43. echo "<tr><td colspan=2><h4>Total Hours: ".$total_hours." (actual: ".$raw_hours.")</h4></td></tr>";
  44. ?>
  45. </tbody>
  46. </table>
  47. <?php
  48. }
  49. add_shortcode( 'show-timesheet', 'timesheet_table' );
  50. ?>