projects
/
timetracker.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Moved Delete to timesheet_edit.php to have room for paid status column.
[timetracker.git]
/
WEB-INF
/
lib
/
ttTaskHelper.class.php
diff --git
a/WEB-INF/lib/ttTaskHelper.class.php
b/WEB-INF/lib/ttTaskHelper.class.php
index
b4644d5
..
0156740
100644
(file)
--- a/
WEB-INF/lib/ttTaskHelper.class.php
+++ b/
WEB-INF/lib/ttTaskHelper.class.php
@@
-35,9
+35,11
@@
class ttTaskHelper {
global $user;
$mdb2 = getConnection();
global $user;
$mdb2 = getConnection();
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
$sql = "select id, name, description, status from tt_tasks
$sql = "select id, name, description, status from tt_tasks
- where id = $id and group_id = $
user->group
_id and (status = 0 or status = 1)";
+ where id = $id and group_id = $
group_id and org_id = $org
_id and (status = 0 or status = 1)";
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
@@
-53,15
+55,17
@@
class ttTaskHelper {
// getAssignedProjects - returns an array of projects associatied with a task.
static function getAssignedProjects($task_id)
{
// getAssignedProjects - returns an array of projects associatied with a task.
static function getAssignedProjects($task_id)
{
-
global $user;
+ global $user;
$result = array();
$mdb2 = getConnection();
$result = array();
$mdb2 = getConnection();
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
// Do a query with inner join to get assigned projects.
$sql = "select p.id, p.name from tt_projects p
inner join tt_project_task_binds ptb on (ptb.project_id = p.id and ptb.task_id = $task_id)
// Do a query with inner join to get assigned projects.
$sql = "select p.id, p.name from tt_projects p
inner join tt_project_task_binds ptb on (ptb.project_id = p.id and ptb.task_id = $task_id)
- where p.group_id = $
user->group
_id and p.status = 1 order by p.name";
+ where p.group_id = $
group_id and p.org_id = $org
_id and p.status = 1 order by p.name";
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
while ($val = $res->fetchRow()) {
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
while ($val = $res->fetchRow()) {
@@
-133,10
+137,11
@@
class ttTaskHelper {
// insert function inserts a new task into database.
static function insert($fields)
{
// insert function inserts a new task into database.
static function insert($fields)
{
+ global $user;
$mdb2 = getConnection();
$mdb2 = getConnection();
- $group_id =
(int) $fields['group_id']
;
- $org_id =
(int) $fields['org_id']
;
+ $group_id =
$user->getGroup()
;
+ $org_id =
$user->org_id
;
$name = $fields['name'];
$description = $fields['description'];
$projects = $fields['projects'];
$name = $fields['name'];
$description = $fields['description'];
$projects = $fields['projects'];
@@
-149,20
+154,18
@@
class ttTaskHelper {
if (is_a($affected, 'PEAR_Error'))
return false;
if (is_a($affected, 'PEAR_Error'))
return false;
- $sql = "select last_insert_id() as last_insert_id";
- $res = $mdb2->query($sql);
- $val = $res->fetchRow();
- $last_id = $val['last_insert_id'];
-
+ $last_id = $mdb2->lastInsertID('tt_tasks', 'id');
+
if (is_array($projects)) {
foreach ($projects as $p_id) {
// Insert task binds into tt_project_task_binds table.
if (is_array($projects)) {
foreach ($projects as $p_id) {
// Insert task binds into tt_project_task_binds table.
- $sql = "insert into tt_project_task_binds (project_id, task_id) values($p_id, $last_id)";
+ $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)".
+ " values($p_id, $last_id, $group_id, $org_id)";
$affected = $mdb2->exec($sql);
$affected = $mdb2->exec($sql);
-
if (is_a($affected, 'PEAR_Error'))
-
return false;
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
-
// Add task bind to the tasks field of the tt_projects table.
+ // Add task bind to the tasks field of the tt_projects table.
$sql = "select tasks from tt_projects where id = $p_id";
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error'))
$sql = "select tasks from tt_projects where id = $p_id";
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error'))
@@
-171,16
+174,16
@@
class ttTaskHelper {
$val = $res->fetchRow();
$task_ids = $val['tasks'];
if ($task_ids) {
$val = $res->fetchRow();
$task_ids = $val['tasks'];
if ($task_ids) {
-
$task_ids .= ",$last_id";
-
$task_ids = ttTaskHelper::sort($task_ids);
-
} else
-
$task_ids = $last_id;
+ $task_ids .= ",$last_id";
+ $task_ids = ttTaskHelper::sort($task_ids);
+ } else
+ $task_ids = $last_id;
$sql = "update tt_projects set tasks = ".$mdb2->quote($task_ids)." where id = $p_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
return false;
$sql = "update tt_projects set tasks = ".$mdb2->quote($task_ids)." where id = $p_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
return false;
-
}
+ }
}
return $last_id;
}
}
return $last_id;
}
@@
-189,9
+192,10
@@
class ttTaskHelper {
static function update($fields)
{
global $user;
static function update($fields)
{
global $user;
-
$mdb2 = getConnection();
$mdb2 = getConnection();
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
$task_id = (int)$fields['task_id'];
$name = $fields['name'];
$description = $fields['description'];
$task_id = (int)$fields['task_id'];
$name = $fields['name'];
$description = $fields['description'];
@@
-199,7
+203,7
@@
class ttTaskHelper {
$projects = $fields['projects'];
$sql = "update tt_tasks set name = ".$mdb2->quote($name).", description = ".$mdb2->quote($description).
$projects = $fields['projects'];
$sql = "update tt_tasks set name = ".$mdb2->quote($name).", description = ".$mdb2->quote($description).
- ", status = $status where id = $task_id and group_id = $
user->
group_id";
+ ", status = $status where id = $task_id and group_id = $group_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
die($affected->getMessage());
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
die($affected->getMessage());
@@
-211,7
+215,8
@@
class ttTaskHelper {
die($affected->getMessage());
if (count($projects) > 0)
foreach ($projects as $p_id) {
die($affected->getMessage());
if (count($projects) > 0)
foreach ($projects as $p_id) {
- $sql = "insert into tt_project_task_binds (project_id, task_id) values($p_id, $task_id)";
+ $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)".
+ " values($p_id, $task_id, $group_id, $org_id)";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
die($affected->getMessage());
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
die($affected->getMessage());
@@
-221,7
+226,7
@@
class ttTaskHelper {
// We need to either delete or insert task id in all affected projects.
// Get all not deleted projects for group.
// We need to either delete or insert task id in all affected projects.
// Get all not deleted projects for group.
- $sql = "select id, tasks from tt_projects where group_id = $
user->
group_id and status is not NULL";
+ $sql = "select id, tasks from tt_projects where group_id = $group_id and status is not NULL";
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error'))
die($res->getMessage());
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error'))
die($res->getMessage());
@@
-266,17
+271,17
@@
class ttTaskHelper {
// sort function sorts task ids passed as comma-separated list by their name.
static function sort($comma_separated) {
// sort function sorts task ids passed as comma-separated list by their name.
static function sort($comma_separated) {
-
// We can't sort an empty string.
-
if (!$comma_separated)
-
return $comma_separated;
-
+ // We can't sort an empty string.
+ if (!$comma_separated)
+ return $comma_separated;
+
$mdb2 = getConnection();
$mdb2 = getConnection();
-
-
$sql = "select id, name from tt_tasks where id in ($comma_separated)";
+
+ $sql = "select id, name from tt_tasks where id in ($comma_separated)";
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error'))
die ($res->getMessage());
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error'))
die ($res->getMessage());
-
+
$task_arr = array();
while ($val = $res->fetchRow()) {
$task_arr[] = array('id'=>$val['id'],'name'=>$val['name']);
$task_arr = array();
while ($val = $res->fetchRow()) {
$task_arr[] = array('id'=>$val['id'],'name'=>$val['name']);
@@
-286,7
+291,7
@@
class ttTaskHelper {
for($i = 0; $i < count($task_arr); $i++) {
$task_ids[] = $task_arr[$i]['id'];
}
for($i = 0; $i < count($task_arr); $i++) {
$task_ids[] = $task_arr[$i]['id'];
}
-
$result = implode(',', $task_ids);
+ $result = implode(',', $task_ids);
return $result;
}
}
return $result;
}
}