Skip to content

Instantly share code, notes, and snippets.

@zastrow
Last active December 16, 2015 13:48
Show Gist options
  • Save zastrow/5443959 to your computer and use it in GitHub Desktop.
Save zastrow/5443959 to your computer and use it in GitHub Desktop.
TeamworkPM Logged billable hours display for Panic's Status Board. Note you'll need to add in your TeamworkPM API information.
<?php include('tw-api.php'); /* Your TeamworkPM API Info */
/* Set ?userid=YOURID to select the person's time to display or uncomment and redecalre below */
/* $userid = YOURID; */
?>
<html>
<head>
<style>
body { color:#fff; font-family: "Roadgeek 2005 Series C"; font-weight:normal; text-align:center; }
h1 { margin:0; font-size:90px; }
p { margin:40px 0 30px; color:rgb(100, 112, 118); text-transform:uppercase }
</style>
<script>
function refresh() {
var req = new XMLHttpRequest();
console.log("Refreshing Time...");
req.onreadystatechange=function() {
if (req.readyState==4 && req.status==200) {
document.getElementById('time').innerText = req.responseText;
}
}
req.open("GET", 'update.php?userid=<?php echo $userid; ?>', true);
req.send(null);
}
function init() {
refresh()
var int=self.setInterval(function(){refresh()},100000);
}
</script>
</head>
<body onload="init()">
<p>Today&rsquo;s logged billable hours</p>
<h1 id='time'></h1>
</body>
</html>
<?php
$company = "companyname";
$key = "yourapikey";
$userid = $_GET['userid'];
?>
<?php
include('tw-api.php'); // Your TeamworkPM API Info
$today = date('Ymd'); // Set to only display today's logged time.
$action = "time_entries.json?fromdate=$today&todate=$today"; // This will only show today's time.
$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "http://". $company .".teamworkpm.net/". $action );
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $channel, CURLOPT_HTTPHEADER,
array( "Authorization: BASIC ". base64_encode( $key .":xxx" )));
$data = json_decode(curl_exec ( $channel ), true);
curl_close ( $channel );
$arr = array();
foreach($data['time-entries'] as $item){
if ($userid == $item['person-id'] && $item['isbillable'] == '1') {
$hrs = $item['hours']*60;
$min = $item['minutes'];
$time = $hrs + $min;
$arr[] = $time;
}
}
$sum = array_sum($arr);
$h = floor($sum / 60);
$m = $sum % 60;
if ($m < 10){
$m = "0" . $m;
}
echo $h . ":" . $m;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment