Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy track #90

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.easy-track.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this branch adds a start-stop timetracker function, which doesn't require you to stay logged in all the time.
76 changes: 76 additions & 0 deletions include/class.timetracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,82 @@

class timetracker {

/**
* Start new timetracking
*/
function openTracking($user, $project = 0, $task =0){
global $conn;
$opentrack = $this->getOpenTrackId($user);
if ($opentrack != 0){
return 'open track existing';
}

$started = time();
$ended=0;
$hours=0;
$comment = 'pending timetrack';

$insStmt = $conn->prepare("INSERT INTO timetracker (user,project,task,comment,started,ended,hours,pstatus) VALUES (?,?,?,?,?,?,?,0)");
$ins = $insStmt->execute(array((int) $user, (int) $project, (int) $task, $comment, $started, $ended, $hours));

if ($ins) {
$insid = $conn->lastInsertId();
$_SESSION['opentrack'] = $insid;
return $insid;
} else {
return false;
}
}

function cancelTracking($tid){
$this->del($tid);
$_SESSION['opentrack']=0;
}

function finishTracking($user, $pid = 0, $tid =0){
global $conn;
$opentrack = $this->getOpenTrackId($user);
if ($opentrack == 0){
return false;
}
$ended = time();

$sel = $conn->prepare("SELECT started,project,task FROM timetracker WHERE ended=0 AND user=?");
$selStmt = $sel->execute(array((int) $user));
$track = array();
$track = $sel->fetch();
if (empty($track)){
return false;
}
$hours = ($ended - $track['started']) / 3600;
if ($pid == 0){
$pid = $task['project'];
}
if ($tid == 0){
$tid = $task['task'];
}

$updStmt = $conn->prepare("UPDATE timetracker SET project=?, task=?, ended=?, hours=? WHERE ID=?");
$upd = $updStmt->execute(array((int)$pid,(int)$tid,(int)$ended,$hours,(int)$opentrack));

if ($upd){
$_SESSION['opentrack'] = 0;
return $opentrack;
}
return false;
}

function getOpenTrackId($user){
global $conn;
$sel = $conn->prepare("SELECT ID FROM timetracker WHERE ended=0 AND user=?");
$selStmt = $sel->execute(array((int) $user));
$track = array();
$track = $sel->fetch();
if (empty($track)){
return 0;
}
return $track['ID'];
}

/**
* Add timetracker entry
Expand Down
4 changes: 4 additions & 0 deletions include/class.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ function login($user, $pass)
$_SESSION["userpermissions"] = $rolesobj->getUserRole($chk["ID"]);

$userid = $_SESSION['userid'];

$tracker = new timetracker();
$_SESSION['opentrack'] = $tracker->getOpenTrackId($userid);

$seid = session_id();
$staylogged = getArrayVal($_POST, 'staylogged');

Expand Down
28 changes: 28 additions & 0 deletions include/js/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,3 +1016,31 @@ if (typeof (Object.Event) != "undefined") {
}
Control.Modal.attachEvents();

function startEasyTracking(){
new Ajax.Request('managetimetracker.php?action=starteasytracking', {
method: 'get',
onSuccess: function(payload) {
if (payload.responseText == 'ok'){
var div=document.getElementById('tracker');
while (div.hasChildNodes()){
div.removeChild(div.lastChild);
}
} else {
alert(payload.responseText);
}
}
});
}

function cancelEasyTracking(){
new Ajax.Request('managetimetracker.php?action=canceleasytracking',{
method: 'get',
onSuccess: function(payload) {
var div=document.getElementById('tracker');
while (div.hasChildNodes()){
div.removeChild(div.lastChild);
}
}
});
}

28 changes: 28 additions & 0 deletions include/js/ajax.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading