Last active
December 16, 2015 13:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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’s logged billable hours</p> | |
<h1 id='time'></h1> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$company = "companyname"; | |
$key = "yourapikey"; | |
$userid = $_GET['userid']; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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