projects
/
timetracker.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactored ttRoleHelper::getRoleByRank().
[timetracker.git]
/
WEB-INF
/
lib
/
ttRoleHelper.class.php
diff --git
a/WEB-INF/lib/ttRoleHelper.class.php
b/WEB-INF/lib/ttRoleHelper.class.php
index
3537446
..
c324d68
100644
(file)
--- a/
WEB-INF/lib/ttRoleHelper.class.php
+++ b/
WEB-INF/lib/ttRoleHelper.class.php
@@
-102,13
+102,15
@@
class ttRoleHelper {
}
// getRoleByRank looks up a role by its rank.
}
// getRoleByRank looks up a role by its rank.
- static function getRoleByRank($rank
, $group_id
) {
+ static function getRoleByRank($rank) {
global $user;
$mdb2 = getConnection();
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')) {
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
@@
-156,10
+158,11
@@
class ttRoleHelper {
// insert - inserts an entry into tt_roles table.
static function insert($fields)
{
// insert - inserts an entry into tt_roles table.
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'];
$rank = (int) $fields['rank'];
$description = $fields['description'];
$name = $fields['name'];
$rank = (int) $fields['rank'];
$description = $fields['description'];
@@
-172,10
+175,7
@@
class ttRoleHelper {
if (is_a($affected, 'PEAR_Error'))
return false;
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;
}
return $last_id;
}