* FusionForge roles
*
* Copyright 2004, GForge, LLC
- * Copyright 2009-2010, Roland Mas
+ * Copyright 2009-2011, Roland Mas
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
*/
function create($role_name, $data, $newproject=false) {
if ($this->Group == NULL) {
- if (!forge_check_global_perm ('forge_admin')) {
+ if (!forge_check_global_perm('forge_admin')) {
$this->setPermissionDeniedError();
return false;
}
}
if ($newproject) {
- if (!forge_check_global_perm ('approve_projects')) {
+ if (!forge_check_global_perm('approve_projects')) {
$this->setPermissionDeniedError();
return false;
}
- } elseif (!forge_check_perm ('project_admin', $this->Group->getID())) {
+ } elseif (!forge_check_perm('project_admin', $this->Group->getID())) {
$this->setPermissionDeniedError();
return false;
}
db_begin();
if ($this->Group == NULL) {
- $res = db_query_params('SELECT role_name FROM pfo_role WHERE home_group_id IS NULL AND role_name=$1',
+ $res = db_query_params('SELECT role_name FROM pfo_role WHERE home_group_id IS NULL AND LOWER(role_name)=LOWER($1)',
array (htmlspecialchars($role_name)));
if (db_numrows($res)) {
$this->setError('Cannot create a role with this name (already used)');
return false;
}
} else {
- $res = db_query_params('SELECT role_name FROM pfo_role WHERE home_group_id=$1 AND role_name=$2',
+ $res = db_query_params('SELECT role_name FROM pfo_role WHERE home_group_id=$1 AND LOWER(role_name)=LOWER($2)',
array ($this->Group->getID(), htmlspecialchars($role_name)));
if (db_numrows($res)) {
$this->setError('Cannot create a role with this name (already used)');
$this->setError(_('Cannot remove a non empty role.'));
return false;
}
-
+
+ db_begin();
$res=db_query_params('DELETE FROM pfo_user_role WHERE role_id=$1',
array($this->getID())) ;
- if (!$res || db_affected_rows($res) < 1) {
+ if (!$res) {
$this->setError('delete::name::'.db_error());
db_rollback();
return false;
$res=db_query_params('DELETE FROM role_project_refs WHERE role_id=$1',
array($this->getID()));
- if (!$res || db_affected_rows($res) < 1) {
+ if (!$res) {
$this->setError('delete::name::'.db_error());
db_rollback();
return false;
$res=db_query_params('DELETE FROM pfo_role_setting WHERE role_id=$1',
array($this->getID()));
- if (!$res || db_affected_rows($res) < 1) {
+ if (!$res) {
$this->setError('delete::name::'.db_error());
db_rollback();
return false;
$res=db_query_params('DELETE FROM pfo_role WHERE role_id=$1',
array($this->getID()));
- if (!$res || db_affected_rows($res) < 1) {
+ if (!$res) {
$this->setError('delete::name::'.db_error());
db_rollback();
return false;
}
+ db_commit();
+ return true;
}
/**