X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/79a38d5d7579d6ba89efdc1b077b87a2e324cbd3..ee3957cfc30d8ba3ed92ac99f3e5b784df1a9c58:/WEB-INF/lib/ttGroupHelper.class.php diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 6ddffaa8..41c03114 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -59,4 +59,45 @@ class ttGroupHelper { } return false; } + + // The getSubgroupByName obtain an immediate subgroup by name if one exists. + static function getSubgroupByName($name) { + global $user; + + $mdb2 = getConnection(); + $parent_id = $user->getActiveGroup(); + $org_id = $user->org_id; + + $sql = "select id from tt_groups where parent_id = $parent_id and org_id = $org_id". + " and name = ".$mdb2->quote($name)." and status is not null"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + if ($val && $val['id']) + return $val; + } + return false; + } + + // The insertSubgroup inserts a new subgroup in database. + static function insertSubgroup($fields) { + global $user; + + $mdb2 = getConnection(); + $parent_id = $user->getActiveGroup(); + $org_id = $user->org_id; + + // TODO: inherit all attributes from the parent group, if not supplied. + $name = $fields['name']; + $description = $fields['description']; + + $created = 'now()'; + $created_ip = $mdb2->quote($_SERVER['REMOTE_ADDR']); + + $sql = "insert into tt_groups (parent_id, org_id, name, description, created, created_ip)". + " values($parent_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($description).", $created, $created_ip)"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + // TODO: design subgroup roles carefully. Perhaps roles are not to be touched in subgroups at all. + } }