global $user;
$mdb2 = getConnection();
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
$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')) {
// getAssignedProjects - returns an array of projects associatied with a task.
static function getAssignedProjects($task_id)
{
- global $user;
+ global $user;
$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)
- 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()) {
// insert function inserts a new task into database.
static function insert($fields)
{
+ global $user;
$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'];
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.
global $user;
$mdb2 = getConnection();
- $group_id = $user->getActiveGroup();
+ $group_id = $user->getGroup();
$org_id = $user->org_id;
$task_id = (int)$fields['task_id'];
$name = $fields['name'];
// 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();
-
- $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());
-
+
$task_arr = array();
while ($val = $res->fetchRow()) {
$task_arr[] = array('id'=>$val['id'],'name'=>$val['name']);
for($i = 0; $i < count($task_arr); $i++) {
$task_ids[] = $task_arr[$i]['id'];
}
- $result = implode(',', $task_ids);
+ $result = implode(',', $task_ids);
return $result;
}
}