X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttRoleHelper.class.php;h=c324d6805b17f169623c6e895be3a2a9a15d1ff1;hb=109089e858e28200e714a790883c236230b3922f;hp=2751756b7a14ea8facd5da2ad69717ea92226348;hpb=085cb5b327f095bcd55f0764b8ab7b7fb3b6bcfa;p=timetracker.git diff --git a/WEB-INF/lib/ttRoleHelper.class.php b/WEB-INF/lib/ttRoleHelper.class.php index 2751756b..c324d680 100644 --- a/WEB-INF/lib/ttRoleHelper.class.php +++ b/WEB-INF/lib/ttRoleHelper.class.php @@ -37,7 +37,7 @@ class ttRoleHelper { $mdb2 = getConnection(); $sql = "select id, name, description, rank, rights, status from tt_roles - where id = $id and group_id = ".$user->getActiveGroup()." and (status = 0 or status = 1)"; + where id = $id and group_id = ".$user->getGroup()." and (status = 0 or status = 1)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -56,7 +56,7 @@ class ttRoleHelper { $mdb2 = getConnection(); global $user; - $sql = "select id from tt_roles where group_id = ".$user->getActiveGroup(). + $sql = "select id from tt_roles where group_id = ".$user->getGroup(). " and name = ".$mdb2->quote($role_name)." and (status = 1 or status = 0)"; $res = $mdb2->query($sql); @@ -89,7 +89,7 @@ class ttRoleHelper { global $user; $mdb2 = getConnection(); - $sql = "select rights from tt_roles where group_id = ".$user->getActiveGroup()." and id = $role_id"; + $sql = "select rights from tt_roles where group_id = ".$user->getGroup()." and id = $role_id"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -102,13 +102,15 @@ class ttRoleHelper { } // getRoleByRank looks up a role by its rank. - static function getRoleByRank($rank, $group_id) { + static function getRoleByRank($rank) { global $user; $mdb2 = getConnection(); - $rank = (int) $rank; // Cast to int just in case for better security. + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $rank = (int) $rank; // Cast to int just in case. - $sql = "select id from tt_roles where group_id = $group_id and rank = $rank and (status = 1 or status = 0)"; + $sql = "select id from tt_roles where group_id = $group_id and org_id = $org_id and rank = $rank and (status = 1 or status = 0)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -124,6 +126,9 @@ class ttRoleHelper { global $user; $mdb2 = getConnection(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $id = (int)$fields['id']; if (isset($fields['name'])) $name_part = 'name = '.$mdb2->quote($fields['name']); if (isset($fields['rank'])) $rank_part = ', rank = '.(int)$fields['rank']; @@ -131,7 +136,7 @@ class ttRoleHelper { if (isset($fields['status'])) $status_part = ', status = '.(int)$fields['status']; if (isset($fields['rights'])) $rights_part = ', rights = '.$mdb2->quote($fields['rights']); $parts = trim($name_part.$rank_part.$descr_part.$status_part.$rights_part, ','); - $sql = "update tt_roles set $parts where id = $id and group_id = $user->group_id"; + $sql = "update tt_roles set $parts where id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } @@ -141,9 +146,11 @@ class ttRoleHelper { global $user; $mdb2 = getConnection(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; // Mark the task as deleted. - $sql = "update tt_roles set status = NULL where id = $role_id and group_id = $user->group_id"; + $sql = "update tt_roles set status = NULL where id = $role_id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } @@ -151,10 +158,11 @@ class ttRoleHelper { // insert - inserts an entry into tt_roles table. 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']; $rank = (int) $fields['rank']; $description = $fields['description']; @@ -167,10 +175,7 @@ class ttRoleHelper { if (is_a($affected, 'PEAR_Error')) return false; - $sql = "SELECT LAST_INSERT_ID() AS last_id"; - $res = $mdb2->query($sql); - $val = $res->fetchRow(); - $last_id = $val['last_id']; + $last_id = $mdb2->lastInsertID('tt_roles', 'id'); return $last_id; } @@ -313,4 +318,29 @@ class ttRoleHelper { } return false; } + + // copyRolesToGroup copies roles from current on behalf group to another. + static function copyRolesToGroup($group_id) { + global $user; + $mdb2 = getConnection(); + + $org_id = $user->org_id; + $columns = '(group_id, org_id, name, description, rank, rights, status)'; + $roles = ttGroupHelper::getRoles(); // Roles in current on behalf group. + + foreach ($roles as $role) { + $values = "values($group_id, $org_id". + ', '.$mdb2->quote($role['name']). + ', '.$mdb2->quote($role['description']). + ', '.(int)$role['rank']. + ', '.$mdb2->quote($role['rights']). + ', '.$mdb2->quote($role['status']). + ')'; + $sql = "insert into tt_roles $columns $values"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + } + return true; + } }