<?php
#ini_set('display_errors',1);
#error_reporting(E_ALL);
class Tasks extends Base {
function updateTask($tid,$pid,$name,$task_index,$status,$start){
$query="UPDATE `timesheet`.`tasks` SET `task_name` = '$name',`project_id` = '$pid',`task_index` = '$task_index',`status` = '$status',`start` = '$start' WHERE `tasks`.`id` =$tid";
parent::dbQuery($query);
}
function addTask($pid,$name,$task_index,$status,$start){
$query="INSERT INTO `timesheet`.`tasks` (`project_id`,`task_name`,`task_index`,`status`,`start`) VALUES ('$pid','$name','$task_index','$status','$start')";
#return $query;
parent::dbQuery($query);
}
function makeIndex($pid){
$query="SELECT proj_index from projects WHERE `id`='$pid'";
$project_index = parent::dbQueryRow($query);
$query="SELECT count(id) from tasks where project_id='$pid'";
$step = parent::dbQueryRow($query);
$step++;
return $project_index.'_'.$step;
}
function getTaskUsers($tid){
$query="select u.real_name,t.user_id from users_tasks as t,users as u where t.user_id=u.id and t.task_id='$tid' and t.status = 'Y'";
return parent::dbQuery($query);
}
function getTaskParent($tid){
$query="select project_id from tasks where id=$tid";
return parent::dbQueryRow($query);
}
function getTaskName($tid){
$query="select task_name from tasks where id=$tid";
return parent::dbQueryRow($query);
}
#summ of hours in project for user
function getTskUsrSummMonth($tid,$uid,$year,$month){
$query = "select sum(ts.hours),t.id,t.task_name from tasks as t,tasksteps as ts where t.id =ts.task_id and ts.user_id=$uid and ts.task_id =$tid and year(ts.date)=$year and month(ts.date)=$month;";
foreach(parent::dbQuery($query) as $num=>$key) {
$answer[$key['id']] = array('task_name'=>$key['task_name'],'summ'=>$key['sum(ts.hours)']);
}
return $answer;
}
function getTskUsrSummYear($tid,$uid,$year){
$query = "select sum(hours) from tasksteps where task_id =$tid and user_id=$uid and year(date)=$year";
# foreach(parent::dbQuery($query) as $num=>$key) {
# $answer[$key['id']] = array('task_name'=>$key['task_name'],'summ'=>$key['sum(ts.hours)']);
# }
#return $answer;
return parent::dbQueryRow($query);
}
function getTaskVars($tid){
$query="select id,project_id,task_name,task_index,status from tasks where id=$tid";
foreach(parent::dbQuery($query) as $num=>$key) {
$answer[$key['id']] = array('task_name'=>$key['task_name'],'task_id'=>$key['_id'],'task_index'=>$key['task_index'],'status'=>$key['status']);
}
return $answer;
}
function getProjUsers($proj_index,$year){
for ($mnth=1;$mnth<13;$mnth++){
$query = "SELECT DISTINCT user_id FROM `timesteps` WHERE YEAR(date) = $year AND MONTH(date) = '$mnth' AND `project_id` = $proj_index";
foreach (parent::dbQuery($query) as $key=>$value){
$users[$value['user_id']][$mnth] = $mnth;
}
}
return $users;
}
function getTaskUserByYear($pid,$uid,$year){
$query="SELECT DISTINCT user_id,task_id,month(date) FROM `tasksteps` WHERE YEAR(date) = $year AND `task_id` =any(select id from tasks where project_id=$pid) and user_id=$uid and hours!='0' and hours!=''";
foreach (parent::dbQuery($query) as $key=>$value){
if(isset($value['month(date)'])){
$users[$value['user_id']][$value['task_id']][$value['month(date)']] = 'Y';
}
}
#parent::dbQueryAssoc($query);
return $users;
}
function getTaskMonthSumm($tid,$year,$month){
$query = "SELECT sum(hours) FROM `tasksteps` WHERE YEAR(date) = '$year' AND MONTH(date) = '$month' AND `task_id` = '$tid' ";
return parent::dbQueryRow($query);
#return $query;
}
}
?>