gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/common/include Group.class, 1.58, 1.59 MailParse


From: tperdue
Subject: [Gforge-commits] gforge/common/include Group.class, 1.58, 1.59 MailParser.class, NONE, 1.1 Role.class, NONE, 1.1 RoleObserver.class, NONE, 1.1 utils.php, 1.32, 1.33 vars.php, 1.3, NONE
Date: Wed, 04 Aug 2004 11:18:38 -0500

Update of /cvsroot/gforge/gforge/common/include
In directory db.perdue.net:/home/tperdue/share/dev.gforge.org/common/include

Modified Files:
        Group.class utils.php 
Added Files:
        MailParser.class Role.class RoleObserver.class 
Removed Files:
        vars.php 
Log Message:
RBAC, DELETION, AND FORUM EMAIL GATEWAY

Index: Group.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/include/Group.class,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- Group.class 2 Aug 2004 20:59:27 -0000       1.58
+++ Group.class 4 Aug 2004 16:18:33 -0000       1.59
@@ -36,11 +36,14 @@
 
 require_once('common/tracker/ArtifactTypes.class');
 require_once('common/forum/Forum.class');
+require_once('common/pm/ProjectGroup.class');
+require_once('common/include/Role.class');
 require_once('common/frs/FRSPackage.class');
 require_once('common/docman/DocumentGroup.class');
 require_once('www/include/BaseLanguage.class');
+
 //the license_id of "Other/proprietary" license
-define('GROUP_LICENSE_OTHER',127);
+define('GROUP_LICENSE_OTHER',126);
 
 $GROUP_OBJ=array();
 
@@ -296,29 +299,20 @@
                }
 
                $id = db_insertid($res, 'groups', 'group_id');
+               if (!$id) {
+                       $this->setError('ERROR: Could not get group id: 
'.db_error());
+                       db_rollback();
+                       return false;
+               }
 
                //
                // Now, make the user an admin
                //
-               $res = db_query("
-                       INSERT INTO user_group (
-                               user_id,
-                               group_id,
-                               admin_flags,
-                               cvs_flags,
-                               artifact_flags,
-                               forum_flags
-                       )
-                       VALUES (
-                               ".$user->getID().",
-                               '$id',
-                               'A',
-                               1,
-                               2,
-                               2
-                       )
-               ");
+               $sql="INSERT INTO user_group ( user_id, group_id, admin_flags,
+                       cvs_flags, artifact_flags, forum_flags, role_id)
+                       VALUES ( ".$user->getID().", '$id', 'A', 1, 2, 2, 1)";
 
+               $res=db_query($sql);
                if (!$res || db_affected_rows($res) < 1) {
                        $this->setError('ERROR: Could not add admin to newly 
created group: '.db_error());
                        db_rollback();
@@ -601,14 +595,11 @@
                global $Language,$SYS;
 
                $perm =& $this->getPermission($user);
-
                if (!$perm || !is_object($perm)) {
-                       
$this->setError($Language->getText('general','permnotget'));
+                       $this->setPermissionDeniedError();
                        return false;
-               }
-
-               if (!$perm->isSuperUser()) {
-                       
$this->setError($Language->getText('general','permdenied'));
+               } elseif (!$perm->isSuperUser()) {
+                       $this->setPermissionDeniedError();
                        return false;
                }
 
@@ -631,11 +622,9 @@
 
                db_begin();
 
-               $res = db_query("
-                       UPDATE groups
+               $res = db_query("UPDATE groups
                        SET status='$status'
-                       WHERE group_id='". $this->getID()."'
-               ");
+                       WHERE group_id='". $this->getID()."'");
 
                if (!$res || db_affected_rows($res) < 1) {
                        $this->setError('ERROR: DB: Could not change group 
status: '.db_error());
@@ -671,25 +660,6 @@
 
                }
 
-               // Make sure that active group have default trackers
-               if ($status=='A') {
-                       $ats = new ArtifactTypes($this);
-                       if (!$ats || !is_object($ats)) {
-                               $this->setError('Error creating ArtifactTypes 
object');
-                               db_rollback();
-                               return false;
-                       } else if ($ats->isError()) {
-                               $this->setError($ats->getErrorMessage());
-                               db_rollback();
-                               return false;
-                       }
-                       if (!$ats->createTrackers()) {
-                               $this->setError($ats->getErrorMessage());
-                               db_rollback();
-                               return false;
-                       }
-               }
-
                db_commit();
 
                // Log the audit trail
@@ -861,7 +831,7 @@
         *  @return     string  The custom license.
         */
        function getLicenseOther() {
-               if ($this->getLicense() == 'other') {
+               if ($this->getLicense() == GROUP_LICENSE_OTHER) {
                        return $this->data_array['license_other'];
                } else {
                        return '';
@@ -883,14 +853,14 @@
         *
         */
        function getGroupAdmins() {
-                   // this function gets all group admins in order to send 
Jabber and mail messages
-                   $q = "SELECT user_id FROM user_group WHERE admin_flags = 
'A' AND group_id = ".$this->getID();
-                   //echo($q."<br/>");
-                   $res = db_query($q);
-                   $users = array();
-                   for($i=0;$i<db_numrows($res);$i++)
+               // this function gets all group admins in order to send Jabber 
and mail messages
+               $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' 
AND group_id = ".$this->getID();
+               $res = db_query($q);
+               $users = array();
+               for($i=0;$i<db_numrows($res);$i++) {
                        array_push($users,db_result($res,$i,'user_id'));
-                   return implode(",",$users);
+               }
+               return implode(",",$users);
        }
                
        /**
@@ -900,13 +870,12 @@
         *
         */
        function getMemberRole($user_id) {
-                   $q = "SELECT member_role FROM user_group WHERE user_id = 
$user_id AND group_id = ".$this->getID();
-                   $res = db_query($q);
-                   if(db_numrows($res))
-                   {
+               $q = "SELECT member_role FROM user_group WHERE user_id = 
$user_id AND group_id = ".$this->getID();
+               $res = db_query($q);
+               if(db_numrows($res)) {
                        return db_result($res,0,'member_role');
-                   }
-                   return 0;
+               }
+               return 0;
        }
                
        /*
@@ -1170,8 +1139,8 @@
                        return $res ;
                } else {
                        $sql="DELETE FROM group_plugin
-                                                         WHERE group_id = ". 
$this->getID() . "
-                                                               AND plugin_id = 
". $plugin_id ;
+                               WHERE group_id = ". $this->getID() . "
+                               AND plugin_id = ". $plugin_id ;
                        $res=db_query($sql);
                        return $res ;
                }
@@ -1238,20 +1207,20 @@
        /**
         *      addUser - controls adding a user to a group.
         *  
-        *  @param      string  Unix name of the user to add.
+        *  @param      string  Unix name of the user to add OR integer user_id.
+        *      @param  int     The role_id this user should have.
         *      @return boolean success.
         *      @access public.
         */
-       function addUser($user_unix_name) {
+       function addUser($user_unix_name,$role_id) {
                global $Language,$SYS;
                /*
                        Admins can add users to groups
                */
 
                $perm =& $this->getPermission( session_get_user() );
-
                if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
-                       $this->setError('You Are Not An Admin For This Group');
+                       $this->setPermissionDeniedError();
                        return false;
                }
 
@@ -1260,8 +1229,11 @@
                /*
                        get user id for this user's unix_name
                */
-               $res_newuser = db_query("SELECT * FROM users WHERE user_name='" 
. strtolower($user_unix_name) . "'");
-
+               if (eregi('[^0-9]',$user_unix_name)) {
+                       $res_newuser = db_query("SELECT * FROM users WHERE 
user_name='". strtolower($user_unix_name) ."'");
+               } else {
+                       $res_newuser = db_query("SELECT * FROM users WHERE 
user_id='". intval($user_unix_name) ."'");
+               }
                if (db_numrows($res_newuser) > 0) {
                        //
                        //      make sure user is active
@@ -1275,13 +1247,14 @@
                        //
                        //      user was found - set new user_id var
                        //
-                       $form_newuid = db_result($res_newuser,0,'user_id');
+                       $user_id = db_result($res_newuser,0,'user_id');
 
                        //
                        //      if not already a member, add them
                        //
-                       $res_member = db_query("SELECT user_id FROM user_group 
".
-                               "WHERE user_id='$form_newuid' AND group_id='". 
$this->getID() ."'");
+                       $res_member = db_query("SELECT user_id 
+                               FROM user_group 
+                               WHERE user_id='$user_id' AND group_id='". 
$this->getID() ."'");
 
                        if (db_numrows($res_member) < 1) {
                                //
@@ -1290,26 +1263,28 @@
                                //      if no unix account, give them a unix_uid
                                //
                                if ( !db_result($res_newuser,0,'unix_uid') ) {
-                                       
$user=&user_get_object($form_newuid,$res_newuser);
+                                       
$user=&user_get_object($user_id,$res_newuser);
                                        if (!$user->setUpUnixUID()) {
                                                $this->setError('ERROR: Cannot 
assign UNIX uid to the user: '.$user->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
-                                       if 
(!$SYS->sys_create_user($form_newuid)) {
+/*                                     if (!$SYS->sys_create_user($user_id)) {
                                                
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
+*/
                                } else {
-                                       //
+/*                                     //
                                        //      User already had unix account
                                        //
-                                       if 
(!$SYS->sys_check_create_user($form_newuid)) {
+                                       if 
(!$SYS->sys_check_create_user($user_id)) {
                                                
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
+*/
                                }
                                //
                                //      Create this user's row in the 
user_group table
@@ -1317,43 +1292,119 @@
                                $res=db_query("INSERT INTO user_group 
                                        
(user_id,group_id,admin_flags,forum_flags,project_flags,
                                        
doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
-                                       VALUES ('$form_newuid','". 
$this->getID() ."','','0','0','0','1','100','0','0')");
+                                       VALUES ('$user_id','". $this->getID() 
."','','0','0','0','1','100','0','0')");
 
                                //verify the insert worked
                                if (!$res || db_affected_rows($res) < 1) {
-                                       $this->setError('ERROR: Could Not Add 
User To Group');
+                                       $this->setError('ERROR: Could Not Add 
User To Group: '.db_error());
                                        db_rollback();
                                        return false;
                                }
-                               //
+/*                             //
                                //      set up their ldap info
                                //
-                               if 
(!$SYS->sys_group_add_user($this->getID(),$form_newuid)) {
-                                       
$this->setError($SYS->getErrorMessage());
+                               if 
(!$SYS->sys_group_add_user($this->getID(),$user_id)) {
+                                       
$this->setError('addUser::ld3::'.$SYS->getErrorMessage());
+                                       db_rollback();
+                                       return false;
+                               }
+*/
+                               //
+                               //      Add to all forums
+                               //
+                               $sql="INSERT INTO forum_perm 
(group_forum_id,user_id,perm_level) 
+                                       SELECT group_forum_id,$user_id,1
+                                       FROM forum_group_list 
+                                       WHERE group_id='".$this->getID()."'";
+                               $res=db_query($sql);
+                               if (!$res) {
+                                       $this->setError('Adding to forums: 
'.db_error());
+                                       db_rollback();
+                                       return false;
+                               }
+                               //
+                               //      Add to all subprojects
+                               //
+                               $sql="INSERT INTO project_perm 
(group_project_id,user_id,perm_level) 
+                                       SELECT group_project_id,$user_id,2
+                                       FROM project_group_list 
+                                       WHERE group_id='".$this->getID()."'";
+                               $res=db_query($sql);
+                               if (!$res) {
+                                       $this->setError('Adding to subprojects: 
'.db_error());
+                                       db_rollback();
+                                       return false;
+                               }
+                               //
+                               //      Add to all trackers
+                               //
+                               $sql="INSERT INTO artifact_perm 
(group_artifact_id,user_id,perm_level) 
+                                       SELECT group_artifact_id,$user_id,2
+                                       FROM artifact_group_list 
+                                       WHERE group_id='".$this->getID()."'";
+                               $res=db_query($sql);
+                               if (!$res) {
+                                       $this->setError('Adding to subprojects: 
'.db_error());
+                                       db_rollback();
+                                       return false;
+                               }
+
+                               $role = new Role($this,$role_id);
+                               if (!$role || !is_object($role)) {
+                                       $this->setError('Error Getting Role 
Object');
+                                       db_rollback();
+                                       return false;
+                               } elseif ($role->isError()) {
+                                       
$this->setError('addUser::roleget::'.$role->getErrorMessage());
+                                       db_rollback();
+                                       return false;
+                               }
+                               if (!$role->setUser($user_id)) {
+                                       
$this->setError('addUser::role::setUser'.$role->getErrorMessage());
                                        db_rollback();
                                        return false;
                                }
 
                        } else {
                                //
-                               //      user was already a member
-                               //      make sure they are set up with a 
unix_uid,
-                               //      LDAP entry and membership
+                               //  user was already a member
+                               //  make sure they are set up with a unix_uid,
+                               //  LDAP entry and membership
                                //
-                               
$user=&user_get_object($form_newuid,$res_newuser);
+                               $user=&user_get_object($user_id,$res_newuser);
                                if (!$user->setUpUnixUID()) {
                                        $this->setError('ERROR: Cannot assign 
UNIX uid to the user: '.$user->getErrorMessage());
                                        db_rollback();
                                        return false;
                                } else {
                                        $user->fetchData($user->getID());
-                                       if 
(!$SYS->sys_check_create_user($form_newuid)) {
+/*                                     if 
(!$SYS->sys_check_create_user($user_id)) {
                                                
$this->setError($SYS->getErrorMessage());
                                                db_rollback();
                                                return false;
                                        }
+                                       if 
(!sf_ldap_group_add_user($this->getID(),$user_id)) {
+                                               
$this->setError('addUser::ld5::'.sf_ldap_get_error_msg());
+                                               db_rollback();
+                                               return false;
+                                       }
+*/
+                                       $role = new Role($this,$role_id);
+                                       if (!$role || !is_object($role)) {
+                                               $this->setError('Error Getting 
Role Object');
+                                               db_rollback();
+                                               return false;
+                                       } elseif ($role->isError()) {
+                                               
$this->setError('addUser::roleget::'.$role->getErrorMessage());
+                                               db_rollback();
+                                               return false;
+                                       }
+                                       if (!$role->setUser($user_id)) {
+                                               
$this->setError('addUser::role::setUser'.$role->getErrorMessage());
+/*
                                                if 
(!$SYS->sys_group_add_user($this->getID(),$form_newuid)) {
                                                
$this->setError($SYS->getErrorMessage());
+*/
                                                db_rollback();
                                                return false;
                                        }
@@ -1365,7 +1416,7 @@
                        //
                        //      user doesn't exist
                        //
-                       $this->setError('ERROR: User does not exist on 
SourceForge');
+                       $this->setError('ERROR: User does not exist');
                        db_rollback();
                        return false;
                }
@@ -1395,23 +1446,17 @@
                        $perm =& $this->getPermission( session_get_user() );
 
                        if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
-                               $this->setError('You Are Not An Admin For This 
Group');
+                               $this->setPermissionDeniedError();
                                return false;
                        }
                }
        
-               $res=db_query("SELECT count(*) FROM user_group WHERE 
group_id='".$this->getID()."' AND user_id='$user_id' AND admin_flags = 'A'");
-               $row_count = db_fetch_array($res);
-               if ($row_count['count'] > 0) {
-                       $this->setError('Cannot remove admin');
-                       return false;
-               }
-
                db_begin();
-               $res=db_query("DELETE FROM user_group ".
-                       "WHERE group_id='".$this->getID()."' AND 
user_id='$user_id' AND admin_flags <> 'A'");
+               $res=db_query("DELETE FROM user_group 
+                       WHERE group_id='".$this->getID()."' 
+                       AND user_id='$user_id'");
                if (!$res || db_affected_rows($res) < 1) {
-                       $this->setError('ERROR: DB: User not removed.');
+                       $this->setError('ERROR: DB: User not 
removed.'.db_error());
                        db_rollback();
                        return false;
                } else {
@@ -1424,13 +1469,31 @@
                                FROM artifact_group_list 
                                WHERE group_id='".$this->getID()."') 
                                AND user_id='$user_id'");
+                       //
+                       //      remove them from subprojects
+                       //
+                       db_query("DELETE FROM project_perm 
+                               WHERE group_project_id 
+                               IN (SELECT group_project_id 
+                               FROM project_group_list 
+                               WHERE group_id='".$this->getID()."') 
+                               AND user_id='$user_id'");
+                       //
+                       //      remove them from forums
+                       //
+                       db_query("DELETE FROM forum_perm 
+                               WHERE group_forum_id 
+                               IN (SELECT group_forum_id 
+                               FROM forum_group_list 
+                               WHERE group_id='".$this->getID()."') 
+                               AND user_id='$user_id'");
 
-                       if 
(!$SYS->sys_group_remove_user($this->getID(),$user_id)) {
+/*                     if 
(!$SYS->sys_group_remove_user($this->getID(),$user_id)) {
                                $this->setError($SYS->getErrorMessage());
                                db_rollback();
                                return false;
                        }
-
+*/
                        //audit trail
                        $this->addHistory('removed user',$user_id);
                }
@@ -1439,92 +1502,35 @@
        }
 
        /**      
-        *  updateUser - controls updating a user's perms in this group.
+        *  updateUser - controls updating a user's role in this group.
         *
         *  @param      int             The ID of the user.
-        *  @param      string  The admin flag for the user.
-        *  @param      int             The forum flag for the user.
-        *  @param      int             The project flag for the user.
-        *  @param      int             The doc flag for the user.
-        *  @param      int             The CVS flag for the user.
-        *  @param      int             The release flag for the user.
-        *      @param  int             The member role for the user.
-        *      @param  int             The artifact flags for the user.
+        *      @param  int             The role_id to set this user to.
         *      @return boolean success.
         */      
-       function 
updateUser($user_id,$admin_flags='',$forum_flags=0,$project_flags=1,$doc_flags=0,$cvs_flags=1,$release_flags=1,$member_role=100,$artifact_flags=0)
 {
+       function updateUser($user_id,$role_id) {
                global $Language,$SYS;
 
-       $perm =& $this->getPermission( session_get_user() );
-
-       if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
-                       $this->setError('You Are Not An Admin For This Group');
+               $perm =& $this->getPermission( session_get_user() );
+               if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
+                       $this->setPermissionDeniedError();
                        return false;
                }
 
-               if (user_getid() == $user_id) {
-                       $admin_flags='A';
-               }
-               $release_flags = ((!$release_flags) ? "0" : $release_flags);
-               $cvs_flags = ((!$cvs_flags) ? "0" : $cvs_flags);
-
-               db_begin();
-               $res = db_query("UPDATE user_group SET
-                       admin_flags='$admin_flags',
-                       forum_flags='$forum_flags',
-                       project_flags='$project_flags', 
-                       doc_flags='$doc_flags', 
-                       cvs_flags='$cvs_flags', 
-                       release_flags='$release_flags', 
-                       artifact_flags='$artifact_flags', 
-                       member_role='$member_role' 
-                       WHERE user_id='$user_id' AND group_id='". 
$this->getID() ."'");
-
-               if (!$res || db_affected_rows($res) < 1) {
-                       $this->setError('ERROR: Could Not Change Member 
Permissions: '.db_error());
-                       db_rollback();
+               $role = new Role($this,$role_id);
+               if (!$role || !is_object($role)) {
+                       $this->setError('Could Not Get Role');
+                       return false;
+               } elseif ($role->isError()) {
+                       $this->setError('Role: '.$role->getErrorMessage());
                        return false;
                }
-
-               //
-               //      If user acquired admin access to CVS,
-               //      one to be given normal shell on CVS machine,
-               //      else - restricted.
-               //
-               if ($cvs_flags>1) {
-                       if 
(!$SYS->sys_user_set_attribute($user_id,"debGforgeCvsShell","/bin/bash")) {
-                               $this->setError($SYS->getErrorMessage());
-                               db_rollback();
-                               return false;
-                       }
-               } else {
-                       if 
(!$SYS->sys_user_set_attribute($user_id,"debGforgeCvsShell","/bin/cvssh")) {
-                               $this->setError($SYS->getErrorMessage());
-                               db_rollback();
-                               return false;
-                       }
-               }
-
-               //
-               //      If user acquired at least commit access to CVS,
-               //      one to be promoted to CVS group, else, demoted.
-               //
-               if ($cvs_flags>0) {
-                       if 
(!$SYS->sys_group_add_user($this->getID(),$user_id,1)) {
-                               $this->setError($SYS->getErrorMessage());
-                               db_rollback();
-                               return false;
-                       }
-               } else {
-                       if 
(!$SYS->sys_group_remove_user($this->getID(),$user_id,1)) {
-                               $this->setError($SYS->getErrorMessage());
-                               db_rollback();
-                               return false;
-                       }
+               if (!$role->setUser($user_id)) {
+                       $this->setError('Role: '.$role->getErrorMessage());
+                       return false;
                }
 
-
-               db_commit();
+               $this->addHistory('updated user',$user_id);
                return true;
        }
 
@@ -1558,12 +1564,9 @@
                        Activate member(s) of the project
                */
 
-               $member_res = db_query("
-                       SELECT users.user_id
-                       FROM users,user_group
-                       WHERE user_group.group_id='".$this->getID()."'
-                       AND users.user_id=user_group.user_id
-               ");
+               $member_res = db_query("SELECT user_id
+                       FROM user_group
+                       WHERE group_id='".$this->getID()."'");
 
                $rows = db_numrows($member_res);
 
@@ -1581,7 +1584,7 @@
                                        return false;
                                }
 
-                               if (!$this->addUser($member->getUnixName())) {
+                               if (!$this->addUser($member->getUnixName(),1)) {
                                        return false;
                                }
                        }
@@ -1614,25 +1617,45 @@
 
                //
                //
+               //      Tracker Integration
+               //
+               //
+               $ats = new ArtifactTypes($this);
+               if (!$ats || !is_object($ats)) {
+                       $this->setError('Error creating ArtifactTypes object');
+                       db_rollback();
+                       return false;
+               } else if ($ats->isError()) {
+                       $this->setError('ATS1 '.$ats->getErrorMessage());
+                       db_rollback();
+                       return false;
+               }
+               if (!$ats->createTrackers()) {
+                       $this->setError('ATS2 '.$ats->getErrorMessage());
+                       db_rollback();
+                       return false;
+               }
+
+               //
+               //
                //      Forum Integration
                //
                //
-               // Step 2: Setup forums for this group
                $f = new Forum($this);
-               if (!$f->create('Open Discussion','General 
Discussion',1,'',1,0)) {
-                       $this->setError($f->getErrorMessage());
+               if (!$f->create('Open-Discussion','General 
Discussion',1,'',1,0)) {
+                       $this->setError('F1 '.$f->getErrorMessage());
                        db_rollback();
                        return false;
                }
                $f = new Forum($this);
                if (!$f->create('Help','Get Public Help',1,'',1,0)) {
-                       $this->setError($f->getErrorMessage());
+                       $this->setError('F2 '.$f->getErrorMessage());
                        db_rollback();
                        return false;
                }
                $f = new Forum($this);
                if (!$f->create('Developers','Project Developer 
Discussion',0,'',1,0)) {
-                       $this->setError($f->getErrorMessage());
+                       $this->setError('F3 '.$f->getErrorMessage());
                        db_rollback();
                        return false;
                }
@@ -1644,7 +1667,7 @@
                //
                $dg = new DocumentGroup($this);
                if (!$dg->create('Uncategorized Submissions')) {
-                       $this->setError($dg->getErrorMessage());
+                       $this->setError('DG1 '.$dg->getErrorMessage());
                        db_rollback();
                        return false;
                }
@@ -1654,14 +1677,46 @@
                //      FRS integration
                //
                //
-               // Step 4: Setup default filerelease package
                $frs = new FRSPackage($this);
                if (!$frs->create($this->getUnixName())) {
-                       $this->setError($frs->getErrorMessage());
+                       $this->setError('FRSP '.$frs->getErrorMessage());
+                       db_rollback();
+                       return false;
+               }
+
+               //
+               //
+               //      PM Integration
+               //
+               //
+               $pg = new ProjectGroup($this);
+               if (!$pg->create('To Do','Things We Have To Do',1)) {
+                       $this->setError('PG1 '.$pg->getErrorMessage());
+                       db_rollback();
+                       return false;
+               }
+               $pg = new ProjectGroup($this);
+               if (!$pg->create('Next Release','Items For Our Next 
Release',1)) {
+                       $this->setError('PG2 '.$pg->getErrorMessage());
                        db_rollback();
                        return false;
                }
 
+               //
+               //
+               //      Set Default Roles
+               //
+               //
+               $role = new Role($this);
+               $todo = array_keys($role->defaults);
+               for ($c=0; $c<count($todo); $c++) {
+                       $role = new Role($this);
+                       if (!$role->createDefault($todo[$c])) {
+                               $this->setError('R'.$c.' 
'.$role->getErrorMessage());
+                               db_rollback();
+                               return false;
+                       }
+               }
                db_commit();
 
                $this->sendApprovalEmail();

--- NEW FILE: MailParser.class ---
<?php
/*
 * Copyright 2004 GForge, LLC
 *
 * @version   $Id: MailParser.class,v 1.1 2004/08/04 16:18:33 tperdue Exp $
 * @author Tim Perdue address@hidden
 *
 * This file is part of GForge.
 *
 * GForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

require_once('common/include/Error.class');

class MailParser extends Error {

        var $max_file_size=2000000;
        var $headers;
        var $body;

        function MailParser($input_file) {
                $this->Error();
                $size = filesize($input_file);
                if ($size > $this->max_file_size) {
                        $this->setError("Error - file too large");
                        return false;
                }
                $fo = fopen($input_file, 'r');
                $input_data = fread($fo, $size);
                fclose($fo);

                $lines=explode("\n",$input_data);
                $linecount=count($lines);
                unset($input_data);

//system("echo \"mp: headers".implode("***\n",$lines)."\n\" >> /tmp/forum.log");
                //
                //      Read the message line-by-line
                //
                for ($i=0; $i<($linecount-1); $i++) {
//system("echo \"mp: line $i of $linecount length: ".strlen($lines[$i])." 
".$lines[$i]."\n\" >> /tmp/forum.log");
                        //
                        //      Still reading headers
                        //
                        if (!$got_headers) {
                                //
                                //      If we hit a blank line, end of headers
                                //
                                if (strlen($lines[$i]) < 2) {
                                        $got_headers=true;
                                        if ($header['Content-Type']) {
                                                if 
(strpos($header['Content-Type'],'text/plain') !== false) {
                                                } else {
                                                        $this->setError('Error 
- only text/plain supported at this time');
                                                        return false;
                                                }
                                        }
//echo "\n\n**".$header['Content-Type']."**\n\n";
                                } else {
                                        //
                                        //      See if line starts with tab, if 
so ignore it for now
                                        //
                                        if (!ereg('^[A-z]',$lines[$i])) {
                                                $header[$lastheader] = 
$header[$lastheader]."\n".$lines[$i];
                                        } else {
                                                $pos = (strpos($lines[$i],':'));
                                                
$header[substr($lines[$i],0,$pos)] = 
trim(substr($lines[$i],$pos+2,(strlen($lines[$i])-$pos-2)));
                                                
$lastheader=substr($lines[$i],0,$pos);
                                        }
                                }
                        } else {
                                $body .= $lines[$i]."\r\n";
                        }


                }
                $this->body =& $body;
                $this->headers =& $header;
                unset ($lines);
//system("echo \"mp: headers".implode("***\n",$header)."\n\" >> 
/tmp/forum.log");
//system("echo \"mp: body".$body."\n\" >> /tmp/forum.log");
                return true;
        }

        function &getBody() {
                return $this->body;
        }

        function &getHeader($header) {
                return $this->headers[$header];
        }

        function getSubject() {
                return $this->getHeader('Subject');
        }

//address@hidden (Tim Perdue)
        function getFromEmail() {
                $mail = $this->getHeader('From');
                if (strpos($mail,'(') !== false) {
                        $email = substr($mail,0,strpos($mail,' '));
                } elseif (strpos($mail,'<') !== false) {
                        $begin=(strpos($mail,'<')+1);
                        $end = strpos($mail,'>');
                        $email = substr($mail,$begin,($end-$begin));
                } else {
                        $email = $mail;
                }
                $email = str_replace('"','',$email);

//echo "***$mail*$begin*$end**".$email."*****";
//system("echo \"mp: email".$email."\n\" >> /tmp/forum.log");
                return trim($email);
        }

        
/*------------------------------------------------------------------------
         *  MIME decoding functions
         
*-----------------------------------------------------------------------*/
        /*
         * Subject and From decode implementation of RFC 2047
         *
         * @param String one or more encoded strings
         * @return String strcat of all texts. Ignore all charsets
         */
        function mime_header_decode_string($string) {

                $decoded_arr = $this->mime_header_decode($string);

                $return_string = $decoded_arr[0]['text'];

                /* Need a space? */
                for ($i=1; $i<count($decoded_arr); $i++) {
                        $return_string.=$decoded_arr[$i]['text'];
                }

                DBG("mime_header: $string -> $return_string \n");

                return $return_string;
        }

        /**
         * Mime header decoding
         *
         * @param String to decode
         * @return Decoded String Array. return['charset'] and retutn['text']
         *
         *# FIXME: Should we use imap_mime_headres_decode? It's too havey to 
install
         *  See 
http://us2.php.net/manual/en/function.imap-mime-header-decode.php
         *
         */
        function mime_header_decode($string) {
                /* We expecting series of encoded-word:
                 * encoded-word = "=?" charset "?" encoding "?" encoded-text 
"?="
                 * See more detail in RFC 2407
                 */
                $count=0;
                $strlen = strlen($string);

                for ($i=0; $i < $strlen; $i++) {
                        /* Start seperation */
                        if (!strcmp($string{$i} . $string{$i+1}, "=?")) {
                                $count++;
                        }

                        /* End seperation */
                        if( !strcmp($string{$i} . $string{$i+1}, "?=")) {
                                $encoded_word_arr[$count].=$string{$i};
                                $encoded_word_arr[$count].=$string{++$i};
                                $count++; /* Null array should be OK */
                                continue;
                        }

                        $encoded_word_arr[$count].=$string{$i};
                }

                for ($i=0; $i<count($encoded_word_arr); $i++) {
                        $return_arr[$i] = 
$this->mime_header_one_word_decode($encoded_word_arr[$i]);
                }

                return $return_arr;
        }

        /**
         * one word decode implementation of RFC 2047
         */
        function mime_header_one_word_decode($string) {
                /* Default charset */
                $charset = "ASCII";

                /* We ecpecting : encoded-word = "=?" charset "?" encoding "?" 
encoded-text "?="
                 * See more detail in RFC 2407
                 */

                /* No encoded-word, return default */
                if (strncmp($string, "=?", 2)) {
                        return array("charset"=>$charset, "text" => $string);
                }

                /*
                 * Expecting [0]='=', [1]=charset, [2]=B|Q, [3]=encoded-text
                 */
                $string_arr = explode('?', $string);

                if (!strcasecmp($string_arr[2], "B") && $string_arr[3]) {
                        $string = base64_decode($string_arr[3]);
                        $charset = $string_arr[1];
                } else if (!strcasecmp($string_arr[2], "Q") && $string_arr[3]) {
                        $string = quoted_printable_decode($string_arr[3]);
                        $charset = $string_arr[1];
                }

                /* Return what we have */
                $ret_arr = array("charset"=>$charset, "text" => $string);
                return $ret_arr;
        }

}

?>

--- NEW FILE: Role.class ---
<?php
/**
 * Role Class
 *
 * Copyright 2004 (c) GForge LLC
 *
 * @version   $Id: Role.class,v 1.1 2004/08/04 16:18:33 tperdue Exp $
 * @author Tim Perdue address@hidden
 * @date 2004-03-16
 *
 * This file is part of GForge.
 *
 * GForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


class Role extends Error {

        var $data_array;
        var $setting_array;
        var $role_vals;
        var $Group;
        var $role_values=array(
        'projectadmin'=>array('0','A'),
        'frs'=>array('0','1'),
        'scm'=>array('-1','0','1'),
        'docman'=>array('0','1'),
        'forumadmin'=>array('0','2'),
        'forum'=>array('-1','0','1','2'),
        'trackeradmin'=>array('0','2'),
        'tracker'=>array('-1','0','1','2','3'),
        'pmadmin'=>array('0','2'),
        'pm'=>array('-1','0','1','2','3'));

        var $defaults=array(
                'Admin'=>array( 'projectadmin'=>'A', 'frs'=>'1', 'scm'=>'1', 
'docman'=>'1', 'forumadmin'=>'2', 'forum'=>'2', 'trackeradmin'=>'2', 
'tracker'=>'3', 'pmadmin'=>'2', 'pm'=>'3' ),
                'Senior Developer'=>array( 'projectadmin'=>'0', 'frs'=>'1', 
'scm'=>'1', 'docman'=>'1', 'forumadmin'=>'2', 'forum'=>'2', 
'trackeradmin'=>'2', 'tracker'=>'2', 'pmadmin'=>'2', 'pm'=>'2' ),
                'Junior Developer'=>array( 'projectadmin'=>'0', 'frs'=>'0', 
'scm'=>'1', 'docman'=>'0', 'forumadmin'=>'0', 'forum'=>'1', 
'trackeradmin'=>'0', 'tracker'=>'1', 'pmadmin'=>'0', 'pm'=>'1' ),
                'Doc Writer'=>array( 'projectadmin'=>'0', 'frs'=>'0', 
'scm'=>'0', 'docman'=>'1', 'forumadmin'=>'0', 'forum'=>'1', 
'trackeradmin'=>'0', 'tracker'=>'0', 'pmadmin'=>'0', 'pm'=>'0' ),
                'Support Tech'=>array( 'projectadmin'=>'0', 'frs'=>'0', 
'scm'=>'0', 'docman'=>'1', 'forumadmin'=>'0', 'forum'=>'1', 
'trackeradmin'=>'0', 'tracker'=>'2', 'pmadmin'=>'0', 'pm'=>'0' )
        );
        
        /**
         *  Role($group,$id) - CONSTRUCTOR.
         *
         *  @param  object       The Group object.
         *  @param  int  The role_id.
         */
        function Role ($Group,$role_id=false) {
                $this->Error();
                if (!$Group || !is_object($Group) || $Group->isError()) {
                        $this->setError('Role::'.$Group->getErrorMessage());
                        return false;
                }
                $this->Group =& $Group;
                if (!$role_id) {
                        //setting up an empty object
                        //probably going to call create()
                        return true;
                }
                return $this->fetchData($role_id);
        }

        /**
         *      getID - get the ID of this role.
         *
         *      @return integer The ID Number.
         */
        function getID() {
                return $this->data_array['role_id'];
        }

        /**
         *      getName - get the name of this role.
         *
         *      @return string  The name of this role.
         */
        function getName() {
                return $this->data_array['role_name'];
        }

        /**
         *      create - create a new role in the database.
         *
         *      @param  string  The name of the role.
         *      @param  array   A multi-dimensional array of data in this 
format: $data['section_name']['ref_id']=$val
         *      @return integer The id on success or false on failure.
         */
        function create($role_name,$data) {
                $perm =& $this->Group->getPermission( session_get_user() );
                if (!$perm || !is_object($perm) || $perm->isError() || 
!$perm->isAdmin()) {
                        $this->setPermissionDeniedError();
                        return false;
                }

                db_begin();
                $sql="INSERT INTO role (group_id,role_name) 
                        VALUES 
('".$this->Group->getID()."','".htmlspecialchars($role_name)."')";
//echo "\n<br>$sql";
                $res=db_query($sql);
                if (!$res) {
                        $this->setError('create::'.db_error());
                        db_rollback();
                        return false;
                }
                $role_id=db_insertid($res,'role','role_id');
                if (!$role_id) {
                        $this->setError('create::db_insertid::'.db_error());
                        db_rollback();
                        return false;
                }

                $arr1 = array_keys($data);
                for ($i=0; $i<count($arr1); $i++) {     
                //      array_values($Report->adjust_days)
                        $arr2 = array_keys($data[$arr1[$i]]);
                        for ($j=0; $j<count($arr2); $j++) {
                                $usection_name=$arr1[$i];
                                $uref_id=$arr2[$j];
                                $uvalue=$data[$arr1[$i]][$arr2[$j]];
                                if (!$uref_id) {
                                        $uref_id=0;
                                }
                                if (!$uvalue) {
                                        $uvalue=0;
                                }
                                $sql="INSERT INTO role_setting 
(role_id,section_name,ref_id,value) 
                                        values ('$role_id','$usection_name', 
'$uref_id','$uvalue')";
//echo "\n<br>$sql";
                                $res=db_query($sql);
                                if (!$res) {
                                        
$this->setError('create::insertsetting::'.db_error());
                                        db_rollback();
                                        return false;
                                }
                        }
                }
                db_commit();
                return $role_id;
        }

        function createDefault($name) {
//echo '<html><body><pre>';
//echo $name;
//print_r($this->defaults);
                $arr =& $this->defaults[$name];
                $keys = array_keys($arr);
                $data = array();

//print_r($keys);
//print_r($arr);
//db_rollback();
//exit;
                for ($i=0; $i<count($keys); $i++) {

                        if ($keys[$i] == 'forum') {
                                $res=db_query("SELECT group_forum_id 
                                        FROM forum_group_list 
                                        WHERE 
group_id='".$this->Group->getID()."'");
                                if (!$res) {
                                        $this->setError('Error: 
Forum'.db_error());
                                        return false;
                                }
                                for ($j=0; $j<db_numrows($res); $j++) {
                                        
$data[$keys[$i]][db_result($res,$j,'group_forum_id')]= $arr[$keys[$i]];
                                }
                        } elseif ($keys[$i] == 'pm') {
                                $res=db_query("SELECT group_project_id 
                                        FROM project_group_list 
                                        WHERE 
group_id='".$this->Group->getID()."'");
                                if (!$res) {
                                        $this->setError('Error: 
TaskMgr'.db_error());
                                        return false;
                                }
                                for ($j=0; $j<db_numrows($res); $j++) {
                                        
$data[$keys[$i]][db_result($res,$j,'group_project_id')]= $arr[$keys[$i]];
                                }
                        } elseif ($keys[$i] == 'tracker') {
                                $res=db_query("SELECT group_artifact_id 
                                        FROM artifact_group_list 
                                        WHERE 
group_id='".$this->Group->getID()."'");
                                if (!$res) {
                                        $this->setError('Error: 
Tracker'.db_error());
                                        return false;
                                }
                                for ($j=0; $j<db_numrows($res); $j++) {
                                        
$data[$keys[$i]][db_result($res,$j,'group_artifact_id')]= $arr[$keys[$i]];
                                }
                        } else {
                                $data[$keys[$i]][0]= $arr[$keys[$i]];
                        }
                }
//print_r($data);
//db_rollback();
//exit;
                return $this->create($name,$data);
        }

        /**
         *  fetchData - May need to refresh database fields.
         *
         *  If an update occurred and you need to access the updated info.
         *
         *  @return boolean success;
         */
        function fetchData($role_id) {
                $res=db_query("SELECT * FROM role WHERE role_id='$role_id'");
                if (!$res || db_numrows($res) < 1) {
                        $this->setError('Role::fetchData()::'.db_error());
                        return false;
                }
                $this->data_array =& db_fetch_array($res);
                $res=db_query("SELECT * FROM role_setting WHERE 
role_id='$role_id'");
                if (!$res) {
                        $this->setError('Role::fetchData()::'.db_error());
                        return false;
                }
                $this->setting_array=array();
                while ($arr =& db_fetch_array($res)) {
                        
$this->setting_array[$arr['section_name']][$arr['ref_id']] = $arr['value'];
                }
                return true;
        }

        /**
         *  &getRoleVals - get all the values and language text strings for 
this section.
         *
         *  @return array       Assoc array of values for this section.
         */
        function &getRoleVals($section) {
                global $Language,$role_vals;

                //
                //      Optimization - save array so it is only built once per 
page view
                //
                if (!isset($role_vals[$section])) {

                        for ($i=0; $i<count($this->role_values[$section]); 
$i++) {
                                //
                                //      Build an associative array of these key 
values + localized description
                                //
                                
$role_vals[$section][$this->role_values[$section][$i]]=$Language->getText('rbac_vals',"$section".$this->role_values[$section][$i]);
                        }
                }
                return $role_vals[$section];
        }

        /**
         *      getVal - get a value out of the array of settings for this role.
         *
         *      @param  string  The name of the role.
         *      @param  integer The ref_id (ex: group_artifact_id, 
group_forum_id) for this item.
         *      @return integer The value of this item.
         */
        function getVal($section,$ref_id) {
                global $role_default_array;
                if (!$ref_id) {
                        $ref_id=0;
                }
                return $this->setting_array[$section][$ref_id];
        }

        /**
         *      update - update a new in the database.
         *
         *      @param  string  The name of the role.
         *      @param  array   A multi-dimensional array of data in this 
format: $data['section_name']['ref_id']=$val
         *      @return boolean True on success or false on failure.
         */
        function update($role_name,$data) {
                //
                //      Cannot update role_id=1
                //
                if ($this->getID() == 1) {
                        $this->setError('Cannot Update Default Role');
                        return false;
                }
                $perm =& $this->Group->getPermission( session_get_user() );
                if (!$perm || !is_object($perm) || $perm->isError() || 
!$perm->isAdmin()) {
                        $this->setPermissionDeniedError();
                        return false;
                }

                db_begin();

                if ($this->getName() != stripslashes($role_name)) {
                        $sql="UPDATE role
                                SET role_name='".htmlspecialchars($role_name)."'
                                WHERE group_id='".$this->Group->getID()."'
                                AND role_id='".$this->getID()."'";
//echo "\n<br>$sql";
                        $res=db_query($sql);
                        if (!$res || db_affected_rows($res) < 1) {
                                $this->setError('update::name::'.db_error());
                                db_rollback();
                                return false;
                        }
                }
////$data['section_name']['ref_id']=$val
                $arr1 = array_keys($data);
                for ($i=0; $i<count($arr1); $i++) {     
                //      array_values($Report->adjust_days)
                        $arr2 = array_keys($data[$arr1[$i]]);
                        for ($j=0; $j<count($arr2); $j++) {
                                $usection_name=$arr1[$i];
                                $uref_id=$arr2[$j];
                                $uvalue=$data[$usection_name][$uref_id];
                                if (!$uref_id) {
                                        $uref_id=0;
                                }
                                if (!$uvalue) {
                                        $uvalue=0;
                                }
                                //
                                //      See if this setting changed. If so, 
then update it
                                //
                                if ($this->getVal($usection_name,$uref_id) != 
$uvalue) {
                                        $sql="UPDATE role_setting 
                                                SET value='$uvalue' 
                                                WHERE 
role_id='".$this->getID()."' 
                                                AND 
section_name='$usection_name'
                                                AND ref_id='$uref_id'";
//echo "\n<br>$sql";
                                        $res=db_query($sql);
                                        if (!$res  || db_affected_rows($res) < 
1) {
                                                $sql="INSERT INTO role_setting 
(role_id,section_name,ref_id,value) 
                                                values 
('".$this->getID()."','$usection_name', '$uref_id','$uvalue')";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::rolesettinginsert::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }
                                        }
                                        if ($usection_name == 'frs') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 'scm') {
                                                $update_usergroup=true;

                                                //iterate all users with this 
role
                                                $res=db_query("SELECT user_id 
                                                        FROM user_group 
                                                        WHERE 
role_id='".$this->getID()."'");
                                                for ($z=0; $z<db_numrows($res); 
$z++) {
                                                /*
                                                        //TODO - this code is 
not active in RBAC - settings must be created first
                                                        //TODO - Shell should 
be separate flag
                                                        //  If user acquired 
admin access to CVS,
                                                        //  one to be given 
normal shell on CVS machine,
                                                        //  else - restricted.
                                                        //
                                                        if ($cvs_flags>1) {
                                                                if 
(!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/bash")) {
                                                                        
$this->setError(sf_ldap_get_error_msg());
                                                                        
db_rollback();
                                                                        return 
false;
                                                                }
                                                        } else {
                                                                if 
(!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/cvssh")) {
                                                                        
$this->setError(sf_ldap_get_error_msg());
                                                                        
db_rollback();
                                                                        return 
false;
                                                                }
                                                        }*/

                                                        //
                                                        //  If user acquired at 
least commit access to CVS,
                                                        //  one to be promoted 
to CVS group, else, demoted.
                                                        //
                                                        if ($uvalue>0) {
        /*                                                      if 
(!sf_ldap_group_add_user($this->Group->getID(),db_result($res,$z,'user_id'),1)) 
{
                                                                        
$this->setError(sf_ldap_get_error_msg());
                                                                        
db_rollback();
                                                                        return 
false;
                                                                }
        */                                              } else {
        /*                                                      if 
(!sf_ldap_group_remove_user($this->Group->getID(),db_result($res,$z,'user_id'),1))
 {
                                                                        
$this->setError(sf_ldap_get_error_msg());
                                                                        
db_rollback();
                                                                        return 
false;
                                                                }
        */                                              }


                                                }
//
//      If we decide to use a "RBAC Group" to define template roles
//      The next 3 items will have to be modified to remap IDs for each project
//

                                        //
                                        //      Forum
                                        //
                                        } elseif ($usection_name == 'forum') {
                                                $sql="UPDATE forum_perm
                                                        SET perm_level='$uvalue'
                                                        WHERE
                                                        
group_forum_id='$uref_id'
                                                        AND EXISTS (SELECT 
user_id FROM
                                                        user_group 
                                                        WHERE 
role_id='".$this->getID()."'
                                                        AND 
user_id=forum_perm.user_id)";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::forum::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }
                                        } elseif ($usection_name == 'pm') {
                                                $sql="UPDATE project_perm
                                                        SET perm_level='$uvalue'
                                                        WHERE
                                                        
group_project_id='$uref_id'
                                                        AND EXISTS (SELECT 
user_id FROM
                                                        user_group 
                                                        WHERE 
role_id='".$this->getID()."'
                                                        AND 
user_id=project_perm.user_id)";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::pm::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }
                                        } elseif ($usection_name == 'tracker') {
                                                $sql="UPDATE artifact_perm
                                                        SET perm_level='$uvalue'
                                                        WHERE
                                                        
group_artifact_id='$uref_id'
                                                        AND EXISTS (SELECT 
user_id FROM
                                                        user_group 
                                                        WHERE 
role_id='".$this->getID()."'
                                                        AND 
user_id=artifact_perm.user_id)";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::tracker::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }

                                        } elseif ($usection_name == 'docman') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 
'forumadmin') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 
'trackeradmin') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 
'projectadmin') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 'pmadmin') {
                                                $update_usergroup=true;
                                        }
                                }
                        }
                }
                if ($update_usergroup) {
                        $sql="UPDATE user_group 
                                SET
                                admin_flags='".$data['projectadmin'][0]."',
                                forum_flags='".$data['forumadmin'][0]."',
                                project_flags='".$data['pmadmin'][0]."',
                                doc_flags='".$data['docman'][0]."',
                                cvs_flags='".$data['scm'][0]."',
                                release_flags='".$data['frs'][0]."',
                                artifact_flags='".$data['trackeradmin'][0]."'
                                WHERE role_id='".$this->getID()."'";
//echo "\n<br>$sql";
                        $res=db_query($sql);
                        if (!$res) {
                                
$this->setError('update::usergroup::'.db_error());
                                db_rollback();
                                return false;
                        }

                }
                db_commit();
                $this->fetchData($this->getID());
                return true;
        }

        function setUser($user_id) {
                $perm =& $this->Group->getPermission( session_get_user() );
                if (!$perm || !is_object($perm) || $perm->isError() || 
!$perm->isAdmin()) {
                        $this->setPermissionDeniedError();
                        return false;
                }

                db_begin();

                //
                //      See if role is actually changing
                //
                $res=db_query("SELECT role_id FROM user_group 
                        WHERE user_id='$user_id' 
                        AND group_id='".$this->Group->getID()."'");
                $old_roleid=db_result($res,0,0);
                if ($this->getID() == $old_roleid) {
                        db_commit();
                        return true;
                }
                //
                //      Get the old role so we can compare new values to old
                //
                $oldrole= new Role($this->Group,$old_roleid);
                if (!$oldrole || !is_object($oldrole) || $oldrole->isError()) {
                        $this->setError($oldrole->getErrorMessage());
                        db_rollback();
                        return false;
                }

                //
                //      Iterate each setting to see if it's changing
                //      If not, no sense updating it
                //
                $arr1 = array_keys($this->setting_array);
                for ($i=0; $i<count($arr1); $i++) {     
                //      array_values($Report->adjust_days)
                        $arr2 = array_keys($this->setting_array[$arr1[$i]]);
                        for ($j=0; $j<count($arr2); $j++) {
                                $usection_name=$arr1[$i];
                                $uref_id=$arr2[$j];
                                
$uvalue=$this->setting_array[$usection_name][$uref_id];
                                if (!$uref_id) {
                                        $uref_id=0;
                                }
                                if (!$uvalue) {
                                        $uvalue=0;
                                }
                                //
                                //      See if this setting changed. If so, 
then update it
                                //
                                if (($this->getVal($usection_name,$uref_id) != 
$oldrole->getVal($usection_name,$uref_id)) || ($old_roleid == 1)) {
                                        if ($usection_name == 'frs') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 'scm') {
                                                $update_usergroup=true;

                /*
                //TODO - this code is not active in RBAC - settings must be 
created first
                //TODO - Shell should be separate flag
                //  If user acquired admin access to CVS,
                //  one to be given normal shell on CVS machine,
                //  else - restricted.
                //
                if ($cvs_flags>1) {
                        if 
(!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/bash")) {
                                $this->setError(sf_ldap_get_error_msg());
                                db_rollback();
                                return false;
                        }
                } else {
                        if 
(!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/cvssh")) {
                                $this->setError(sf_ldap_get_error_msg());
                                db_rollback();
                                return false;
                        }
                }*/

//iterate all users with this role
                                                //
                                                //  If user acquired at least 
commit access to CVS,
                                                //  one to be promoted to CVS 
group, else, demoted.
                                                //
                                                if ($uvalue>0) {
                                        /*              if 
(!sf_ldap_group_add_user($this->Group->getID(),$user_id,1)) {
                                                                
$this->setError(sf_ldap_get_error_msg());
                                                                db_rollback();
                                                                return false;
                                                        }
                                        */      } else {
                                        /*              if 
(!sf_ldap_group_remove_user($this->Group->getID(),$user_id,1)) {
                                                                
$this->setError(sf_ldap_get_error_msg());
                                                                db_rollback();
                                                                return false;
                                                        }
                                        */      }



//
//      If we decide to use a "RBAC Group" to define template roles
//      The next 3 items will have to be modified to remap IDs for each project
//

                                        //
                                        //      Forum
                                        //
                                        } elseif ($usection_name == 'forum') {
                                                $sql="UPDATE forum_perm
                                                        SET perm_level='$uvalue'
                                                        WHERE
                                                        
group_forum_id='$uref_id'
                                                        AND user_id='$user_id'";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::forum::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }
                                        } elseif ($usection_name == 'pm') {
                                                $sql="UPDATE project_perm
                                                        SET perm_level='$uvalue'
                                                        WHERE
                                                        
group_project_id='$uref_id'
                                                        AND user_id='$user_id'";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::pm::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }
                                        } elseif ($usection_name == 'tracker') {
                                                $sql="UPDATE artifact_perm
                                                        SET perm_level='$uvalue'
                                                        WHERE
                                                        
group_artifact_id='$uref_id'
                                                        AND user_id='$user_id'";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::tracker::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }

                                        } elseif ($usection_name == 'docman') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 
'forumadmin') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 
'trackeradmin') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 
'projectadmin') {
                                                $update_usergroup=true;
                                        } elseif ($usection_name == 'pmadmin') {
                                                $update_usergroup=true;
                                        }
                                }
                        }
                }
                if ($update_usergroup) {
                        $sql="UPDATE user_group 
                                SET
                                
admin_flags='".$this->getVal('projectadmin',0)."',
                                forum_flags='".$this->getVal('forumadmin',0)."',
                                project_flags='".$this->getVal('pmadmin',0)."',
                                doc_flags='".$this->getVal('docman',0)."',
                                cvs_flags='".$this->getVal('scm',0)."',
                                release_flags='".$this->getVal('frs',0)."',
                                
artifact_flags='".$this->getVal('trackeradmin',0)."',
                                role_id='".$this->getID()."'
                                WHERE 
                                user_id='".$user_id."'
                                AND group_id='".$this->Group->getID()."'";
//echo "\n<br>$sql";
                        $res=db_query($sql);
                        if (!$res) {
                                
$this->setError('update::usergroup::'.db_error());
                                db_rollback();
                                return false;
                        }

                }
                db_commit();
                return true;

        }

}

?>

--- NEW FILE: RoleObserver.class ---
<?php
/**
 * RoleObserver Class - this class handles the privacy settings
 * for an entire project
 *
 * Copyright 2004 (c) GForge LLC
 *
 * @version   $Id: RoleObserver.class,v 1.1 2004/08/04 16:18:33 tperdue Exp $
 * @author Tim Perdue address@hidden
 * @date 2004-03-16
 *
 * This file is part of GForge.
 *
 * GForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


class RoleObserver extends Error {

        var $setting_array;
        var $role_vals;
        var $Group;
        var $role_values=array(
        'projectpublic'=>array('0','1'),
        'scmpublic'=>array('0','1'),
        'forumpublic'=>array('0','1'),
        'forumanon'=>array('0','1'),
        'trackerpublic'=>array('0','1'),
        'trackeranon'=>array('0','1'),
        'pmpublic'=>array('0','1'),
        'frspackage'=>array('0','1'));

        /**
         *  Role($group,$id) - CONSTRUCTOR.
         *
         *  @param  object       The Group object.
         *  @param  int  The role_id.
         */

        function RoleObserver ($Group) {
                $this->Error();
                if (!$Group || !is_object($Group) || $Group->isError()) {
                        $this->setError('Role::'.$Group->getErrorMessage());
                        return false;
                }
                $this->Group =& $Group;
                return $this->fetchData();
        }

    /**
     *  getID - get the ID of this role.
     *
     *  @return string The ID of the observer.
     */
        function getID() {
                return 'observer';
        }

    /**
     *  getName - get the name of this role.
     *
     *  @return string  The name of this role.
     */
        function getName() {
                return 'Observer';
        }

        /**
         *  fetchData - May need to refresh database fields.
         *
         *  If an update occurred and you need to access the updated info.
         *
         *  @return boolean success;
         */
        function fetchData() {
                $this->setting_array=array();
                //
                //      Forum is_public/allow_anon
                //
                $res=db_query("SELECT group_forum_id,is_public,allow_anonymous 
                        FROM forum_group_list 
                        WHERE group_id='".$this->Group->getID()."'");
                while ($arr =& db_fetch_array($res)) {
                        
$this->setting_array['forumpublic'][$arr['group_forum_id']] = $arr['is_public'];
                        
$this->setting_array['forumanon'][$arr['group_forum_id']] = 
$arr['allow_anonymous'];
                }

                //
                //      Task Manager is_public/allow_anon
                //
                $res=db_query("SELECT group_project_id,is_public
                        FROM project_group_list 
                        WHERE group_id='".$this->Group->getID()."'");
                while ($arr =& db_fetch_array($res)) {
                        
$this->setting_array['pmpublic'][$arr['group_project_id']] = $arr['is_public'];
                }

                //
                //      Tracker is_public/allow_anon
                //
                $res=db_query("SELECT group_artifact_id,is_public,allow_anon
                        FROM artifact_group_list 
                        WHERE group_id='".$this->Group->getID()."'");
                while ($arr =& db_fetch_array($res)) {
                        
$this->setting_array['trackerpublic'][$arr['group_artifact_id']] = 
$arr['is_public'];
                        
$this->setting_array['trackeranon'][$arr['group_artifact_id']] = 
$arr['allow_anon'];
                }

                //
                //      FRS packages can be public/private now
                //
                $res=db_query("SELECT package_id,is_public
                        FROM frs_package
                        WHERE group_id='".$this->Group->getID()."'");
                while ($arr =& db_fetch_array($res)) {
                        $this->setting_array['frspackage'][$arr['package_id']] 
= $arr['is_public'];
                }

                //
                //      AnonCVS
                //
                
$this->setting_array['scmpublic'][0]=$this->Group->enableAnonCVS();
                
$this->setting_array['projectpublic'][0]=$this->Group->isPublic();
//echo '<html><body><pre>'.print_r($this->setting_array).'</pre>';
//exit;
                return true;
        }

        /**
         *  &getRoleVals - get all the values and language text strings for 
this section.
         *
         *  @return array       Assoc array of values for this section.
         */
        function &getRoleVals($section) {
                global $Language,$role_vals;

                //
                //      Optimization - save array so it is only built once per 
page view
                //
                if (!isset($role_vals[$section])) {

                        for ($i=0; $i<count($this->role_values[$section]); 
$i++) {
                                //
                                //      Build an associative array of these key 
values + localized description
                                //
                                
$role_vals[$section][$this->role_values[$section][$i]]=$Language->getText('rbac_vals',"$section".$this->role_values[$section][$i]);
                        }
                }
                return $role_vals[$section];
        }

    /**
     *  getVal - get a value out of the array of settings for this role.
     *
     *  @param  string  The name of the role.
     *  @param  integer The ref_id (ex: group_artifact_id, group_forum_id) for 
this item.
     *  @return integer The value of this item.
     */
        function getVal($section,$ref_id) {
                global $role_default_array;
                if (!$ref_id) {
                        $ref_id=0;
                }
                if (!isset($this->setting_array) && !isset($this->data_array)) {
                        $this->setting_array=$role_default_array;
                }
                return $this->setting_array[$section][$ref_id];
        }

    /**
     *  update - update a new in the database.
     *
     *  @param  array   A multi-dimensional array of data in this format: 
$data['section_name']['
     *  @return boolean True on success or false on failure.
     */
        function update($data) {
                $perm =& $this->Group->getPermission( session_get_user() );
                if (!$perm || !is_object($perm) || $perm->isError() || 
!$perm->isAdmin()) {
                        $this->setPermissionDeniedError();
                        return false;
                }

                db_begin();

////$data['section_name']['ref_id']=$val
                $arr1 = array_keys($data);
                for ($i=0; $i<count($arr1); $i++) {     
                        $arr2 = array_keys($data[$arr1[$i]]);
                        for ($j=0; $j<count($arr2); $j++) {
                                $usection_name=$arr1[$i];
                                $uref_id=$arr2[$j];
                                $uvalue=$data[$usection_name][$uref_id];
                                if (!$uref_id) {
                                        $uref_id=0;
                                }
                                if (!$uvalue) {
                                        $uvalue=0;
                                }
                                //
                                //      See if this setting changed. If so, 
then update it
                                //
                                if ($this->getVal($usection_name,$uref_id) != 
$uvalue) {
                                        if ($usection_name == 'scmpublic' || 
$usection_name == 'projectpublic') {
                                                if (!$data['scmpublic'][0]) {
                                                        $data['scmpublic'][0]=0;
                                                }
                                                if (!$data['projectpublic'][0]) 
{
                                                        
$data['projectpublic'][0]=0;
                                                }
                                                $sql="UPDATE groups
                                                        SET
                                                        
enable_anoncvs='".$data['scmpublic'][0]."',
                                                        
is_public='".$data['projectpublic'][0]."'
                                                        WHERE 
group_id='".$this->Group->getID()."'";
//echo "\n<br>$sql";
                                                        $res=db_query($sql);
                                                        if (!$res) {
                                                                
$this->setError('update::group::'.db_error());
                                                                db_rollback();
                                                                return false;
                                                        }

                                        //
                                        //      Forum
                                        //
                                        } elseif ($usection_name == 
'forumpublic' || $usection_name == 'forumanon') {
                                                //
                                                //      prevent double-updating 
each forum
                                                //
                                                if 
($updated['forum'][$uref_id]) {
                                                        continue;
                                                }
                                                $sql="UPDATE forum_group_list
                                                        SET 
                                                        
is_public='".$data['forumpublic'][$uref_id]."',
                                                        
allow_anonymous='".$data['forumanon'][$uref_id]."'
                                                        WHERE
                                                        
group_forum_id='$uref_id'
                                                        AND 
group_id='".$this->Group->getID()."'";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                $updated['forum'][$uref_id]=1;
                                                if (!$res) {
                                                        
$this->setError('update::forum::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }
                                        } elseif ($usection_name == 'pmpublic') 
{

                                                $sql="UPDATE project_group_list
                                                        SET 
                                                        is_public='$uvalue'
                                                        WHERE
                                                        
group_project_id='$uref_id'
                                                        AND 
group_id='".$this->Group->getID()."'";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::pm::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }

                                        } elseif ($usection_name == 
'frspackage') {

                                                $sql="UPDATE frs_package
                                                        SET 
                                                        is_public='$uvalue'
                                                        WHERE
                                                        package_id='$uref_id'
                                                        AND 
group_id='".$this->Group->getID()."'";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                if (!$res) {
                                                        
$this->setError('update::frspackage::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }

                                        } elseif ($usection_name == 
'trackerpublic' || $usection_name == 'trackeranon') {
                                                //
                                                //      prevent double-updating 
each forum
                                                //
                                                if 
($updated['tracker'][$uref_id]) {
                                                        continue;
                                                }
                                                $sql="UPDATE artifact_group_list
                                                        SET
                                                        
is_public='".$data['trackerpublic'][$uref_id]."',
                                                        
allow_anon='".$data['trackeranon'][$uref_id]."'
                                                        WHERE
                                                        
group_artifact_id='$uref_id'
                                                        AND 
group_id='".$this->Group->getID()."'";
//echo "\n<br>$sql";
                                                $res=db_query($sql);
                                                $updated['tracker'][$uref_id]=1;
                                                if (!$res) {
                                                        
$this->setError('update::tracker::'.db_error());
                                                        db_rollback();
                                                        return false;
                                                }
                                        }
                                }
                        }
                }

                db_commit();
                $this->fetchData();
                return true;
        }

}

?>

Index: utils.php
===================================================================
RCS file: /cvsroot/gforge/gforge/common/include/utils.php,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- utils.php   30 Jun 2004 18:11:51 -0000      1.32
+++ utils.php   4 Aug 2004 16:18:33 -0000       1.33
@@ -84,7 +84,7 @@
  * @param              string  The optional email sender name. Defaults to ''
  *
  */
-function util_send_message($to,$subject,$body,$from='',$BCC='',$sendername='') 
{
+function 
util_send_message($to,$subject,$body,$from='',$BCC='',$sendername='',$extra_headers='')
 {
        global $Language;
        global $sys_sendmail_path;
 
@@ -96,7 +96,13 @@
        }
 
        $charset = $Language->getText('conf','mail_charset');
-       $body = "To: $to".
+       if (!$charset) {
+               $charset = 'ISO-8859-1';
+       }
+       if ($extra_headers) {
+               $body2 = $extra_headers."\n";
+       }
+       $body2 .= "To: $to".
                "\nFrom: ".util_encode_mailaddr($from,$sendername,$charset).
                "\nBCC: $BCC".
                "\nSubject: ".util_encode_mimeheader($subject, $charset).
@@ -108,7 +114,7 @@
                $sys_sendmail_path="/usr/sbin/sendmail";
        }
 
-       exec ("/bin/echo \"". util_prep_string_for_sendmail($body) .
+       exec ("/bin/echo \"". util_prep_string_for_sendmail($body2) .
                  "\" | ".$sys_sendmail_path." -f'$from' -t -i > /dev/null 2>&1 
&");
 }
 
@@ -225,8 +231,9 @@
  *     @param  string  the message body
  *     @param  string  a comma-separated list of email address
  *     @param  string  a comma-separated list of jabber address
+ *     @param  string  From header
  */
-function 
util_handle_message($id_arr,$subject,$body,$extra_emails='',$extra_jabbers='') {
+function 
util_handle_message($id_arr,$subject,$body,$extra_emails='',$extra_jabbers='',$from='')
 {
        $address=array();
 
        if (count($id_arr) < 1) {
@@ -261,7 +268,7 @@
                }
        }
        if ($extra_email1 || $extra_emails) {
-               
util_send_message('',$subject,$body,'',$extra_email1.$extra_emails);
+               
util_send_message('',$subject,$body,$from,$extra_email1.$extra_emails);
        }
        if ($extra_jabber1 || $extra_jabbers) {
                util_send_jabber($extra_jabber1.$extra_jabbers,$subject,$body);

--- vars.php DELETED ---





reply via email to

[Prev in Thread] Current Thread [Next in Thread]