4 * GForge Group Role Generator
6 * Copyright 2004 GForge, LLC
9 * This file is part of GForge.
11 * GForge 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 * GForge 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
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
26 require_once dirname(__FILE__).'/../www/env.inc.php';
27 require_once $gfwww.'include/squal_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 (!$sys_account_manager_type) {
35 $sys_account_manager_type='UNIX';
37 require_once $gfcommon.'include/system/'.$sys_account_manager_type.'.class.php';
38 $SYS=new $sys_account_manager_type();
40 require_once $gfcommon.'include/Role.class.php';
43 // Set up this script to run as the site admin
46 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
56 if (db_numrows($res) == 0) {
57 // There are no Admins yet, aborting without failing
62 $id=db_result($res,0,0);
66 // Clear out role settings in case this was run before
69 db_query_params ('UPDATE user_group SET role_id=1',
72 db_query_params ('DELETE FROM role_setting',
75 db_query_params ('DELETE FROM role WHERE role_id>1',
79 $res=db_query_params ('SELECT group_id FROM groups WHERE status != $1',
82 $arr = util_result_column_to_array($res);
84 for ($i=0; $i<count($arr); $i++) {
85 $g =& group_get_object($arr[$i]);
92 $todo = array_keys($role->defaults);
93 for ($c=0; $c<count($todo); $c++) {
95 if (!$role->createDefault($todo[$c])) {
96 echo $role->getErrorMessage();
98 echo "Could Not Create Default Roles: ".$arr[$i];
103 $roleid = db_query_params ('SELECT role_id FROM role WHERE group_id=$1 AND role_name=$2',
106 $admin_roleid=db_result($roleid,0,0);
107 $roleid = db_query_params ('SELECT role_id FROM role WHERE group_id=$1 AND role_name=$2',
109 'Junior Developer')) ;
110 $junior_roleid=db_result($roleid,0,0);
112 $rrole = db_query_params ('SELECT user_id,admin_flags FROM user_group WHERE group_id=$1',
114 while ($arrole = db_fetch_array($rrole)) {
116 $role_id= (( trim($arrole['admin_flags']) == 'A' ) ? $admin_roleid : $junior_roleid );
117 $user_id=$arrole['user_id'];
119 $role = new Role($g,$role_id);
120 if (!$role || !is_object($role)) {
121 echo 'Error Getting Role Object';
124 } elseif ($role->isError()) {
125 echo $role->getErrorMessage();
129 if (!$role->setUser($user_id)) {
130 echo $role->getErrorMessage();
142 // c-file-style: "bsd"