X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttAdmin.class.php;h=ef55ae50b15aadb136528a116e7bcb9157637685;hb=3fe430d82ad416d1766b9f0cd558e2e1f26900a9;hp=ed1b280c3d9ff3612bc17c33bdd05462455c3dd8;hpb=82113b6a111dc3f716c71fb8fb55b11845cbd697;p=timetracker.git diff --git a/WEB-INF/lib/ttAdmin.class.php b/WEB-INF/lib/ttAdmin.class.php index ed1b280c..ef55ae50 100644 --- a/WEB-INF/lib/ttAdmin.class.php +++ b/WEB-INF/lib/ttAdmin.class.php @@ -41,13 +41,23 @@ class ttAdmin { // getSubgroups rerurns an array of subgroups for a group. function getSubgroups($group_id) { - return array(); // TODO: not yet implemented. + $mdb2 = getConnection(); + + $subgroups = array(); + $sql = "select id from tt_groups where parent_id = $group_id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $subgroups[] = $val; + } + } + return $subgroups; } // getUsers obtains user ids in a group. function getUsers($group_id) { $mdb2 = getConnection(); - $sql = "select id from tt_users where team_id = $group_id"; + $sql = "select id from tt_users where group_id = $group_id"; $res = $mdb2->query($sql); $users = array(); if (!is_a($res, 'PEAR_Error')) { @@ -85,7 +95,7 @@ class ttAdmin { // The markTasksDeleted deletes task binds and marks the tasks as deleted for a group. function markTasksDeleted($group_id) { $mdb2 = getConnection(); - $sql = "select id from tt_tasks where team_id = $group_id"; + $sql = "select id from tt_tasks where group_id = $group_id"; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error')) return false; @@ -120,7 +130,7 @@ class ttAdmin { // Now that we are done with subgroups, handle this group. $users = $this->getUsers($group_id); - // Iterate through team users and mark them as deleted. + // Iterate through group users and mark them as deleted. foreach ($users as $one_user) { if (!$this->markUserDeleted($one_user['id'])) return false; @@ -132,32 +142,32 @@ class ttAdmin { $mdb2 = getConnection(); // Mark roles deleted. - $sql = "update tt_roles set status = NULL where team_id = $group_id"; + $sql = "update tt_roles set status = NULL where group_id = $group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; // Mark projects deleted. - $sql = "update tt_projects set status = NULL where team_id = $group_id"; + $sql = "update tt_projects set status = NULL where group_id = $group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; // Mark clients deleted. - $sql = "update tt_clients set status = NULL where team_id = $group_id"; + $sql = "update tt_clients set status = NULL where group_id = $group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; // Mark invoices deleted. - $sql = "update tt_invoices set status = NULL where team_id = $group_id"; + $sql = "update tt_invoices set status = NULL where group_id = $group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; // Mark custom fields deleted. - $sql = "update tt_custom_fields set status = NULL where team_id = $group_id"; + $sql = "update tt_custom_fields set status = NULL where group_id = $group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; // Mark notifications deleted. - $sql = "update tt_cron set status = NULL where team_id = $group_id"; + $sql = "update tt_cron set status = NULL where group_id = $group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -166,9 +176,9 @@ class ttAdmin { // // 1) Users may mark some of them deleted during their work. // If we mark all of them deleted here, we can't recover nicely - // as we'll lose track of what was deleted by user. + // as we'll lose track of what was accidentally deleted by user. // - // 2) DB maintenance script (Clean up DB from inactive teams) should + // 2) DB maintenance script (Clean up DB from inactive groups) should // get rid of these items permanently eventually. // Mark group deleted. @@ -189,7 +199,7 @@ class ttAdmin { $result = true; if (!ttValidString($fields['group_name'], true)) { - $this->err->add($i18n->get('error.field'), $i18n->get('label.team_name')); + $this->err->add($i18n->get('error.field'), $i18n->get('label.group_name')); $result = false; } if (!ttValidString($fields['user_name'])) { @@ -232,7 +242,7 @@ class ttAdmin { } // updateGroup validates user input and updates the group with new information. - function updateGroup($team_id, $fields) { + function updateGroup($group_id, $fields) { if (!$this->validateGroupInfo($fields)) return false; // Can't continue as user input is invalid. global $user; @@ -242,7 +252,7 @@ class ttAdmin { if ($fields['old_group_name'] != $fields['new_group_name']) { $name_part = 'name = '.$mdb2->quote($fields['new_group_name']); $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id); - $sql = 'update tt_groups set '.$name_part.$modified_part.' where id = '.$team_id; + $sql = 'update tt_groups set '.$name_part.$modified_part.' where id = '.$group_id; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; } @@ -332,4 +342,24 @@ class ttAdmin { return true; } + + // getGroupDetails obtains group name and its top manager details. + function getGroupDetails($group_id) { + $result = array(); + $mdb2 = getConnection(); + + $sql = "select g.name as group_name, u.id as manager_id, u.name as manager_name, u.login as manager_login, u.email as manager_email". + " from tt_groups g". + " inner join tt_users u on (u.group_id = g.id)". + " inner join tt_roles r on (r.id = u.role_id and r.rank = 512)". + " where g.id = $group_id"; + + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + return $val; + } + + return false; + } }