4 * GForge Group Role Generator
6 * Copyright 2004 GForge, LLC
7 * http://fusionforge.org/
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once dirname(__FILE__).'/../www/env.inc.php';
27 require_once $gfcommon.'include/pre.php';
30 //Required by Role.class.php to update system
31 require_once $gfcommon.'include/System.class.php';
32 // Right now the nss tables don't exist so if sys_account_manager_type=pgsql
33 // This will fail UNIX should be safe
34 //if (!forge_get_config('account_manager_type')) {
35 $sys_account_manager_type='UNIX';
37 require_once $gfcommon.'include/system/'.forge_get_config('account_manager_type').'.class.php';
38 $amt = forge_get_config('account_manager_type') ;
41 require_once $gfcommon.'include/Role.class.php';
44 // Set up this script to run as the site admin
47 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
57 if (db_numrows($res) == 0) {
58 // There are no Admins yet, aborting without failing
63 $id=db_result($res,0,0);
67 // Clear out role settings in case this was run before
70 db_query_params ('UPDATE user_group SET role_id=1',
73 db_query_params ('DELETE FROM role_setting',
76 db_query_params ('DELETE FROM role WHERE role_id>1',
80 $res=db_query_params ('SELECT group_id FROM groups WHERE status != $1',
83 $arr = util_result_column_to_array($res);
85 for ($i=0; $i<count($arr); $i++) {
86 $g = group_get_object($arr[$i]);
93 $todo = array_keys($role->defaults);
94 for ($c=0; $c<count($todo); $c++) {
96 if (!$role->createDefault($todo[$c])) {
97 echo $role->getErrorMessage();
99 echo "Could Not Create Default Roles: ".$arr[$i];
104 $roleid = db_query_params ('SELECT role_id FROM role WHERE group_id=$1 AND role_name=$2',
107 $admin_roleid=db_result($roleid,0,0);
108 $roleid = db_query_params ('SELECT role_id FROM role WHERE group_id=$1 AND role_name=$2',
110 'Junior Developer')) ;
111 $junior_roleid=db_result($roleid,0,0);
113 $rrole = db_query_params ('SELECT user_id,admin_flags FROM user_group WHERE group_id=$1',
115 while ($arrole = db_fetch_array($rrole)) {
117 $role_id= (( trim($arrole['admin_flags']) == 'A' ) ? $admin_roleid : $junior_roleid );
118 $user_id=$arrole['user_id'];
120 $role = new Role($g,$role_id);
121 if (!$role || !is_object($role)) {
122 echo 'Error Getting Role Object';
125 } elseif ($role->isError()) {
126 echo $role->getErrorMessage();
130 if (!$role->setUser($user_id)) {
131 echo $role->getErrorMessage();
143 // c-file-style: "bsd"