// 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')) {
// 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;
// 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;
$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;
// If we mark all of them deleted here, we can't recover nicely
// as we'll lose track of what was 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.
global $user;
$modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id);
- $sql = "update tt_teams set status = NULL $modified_part where id = $group_id";
+ $sql = "update tt_groups set status = NULL $modified_part where id = $group_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error')) return false;
$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'])) {
}
// 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;
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_teams 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;
}
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;
+ }
}