PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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