Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

lib/group.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  This program is free software; you can redistribute it and/or
00004  modify it under the terms of the GNU General Public License
00005  as published by the Free Software Foundation; either version 2
00006  of the License, or (at your option) any later version.
00007 
00008  This program is distributed in the hope that it will be useful,
00009  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  GNU General Public License for more details.
00012 
00013  You should have received a copy of the GNU General Public License
00014  along with this program; if not, write to the Free Software
00015  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016  ***************************************************************************/
00017 
00021 class Group
00022 {
00023     var $oDB;   
00024     var $oLog;  
00025     var $aAdmin;
00026     var $aAdminArrays;
00027     var $aRightNames;
00028 
00038     function Group ( &$oDB, &$oLog, &$aAdmin, $aAdminArrays, &$aRightNames )
00039     {
00040         $this->oDB =& $oDB;
00041         $this->oLog =& $oLog;
00042         $this->aAdmin =& $aAdmin;
00043         $this->aAdminArrays = $aAdminArrays;
00044         $this->aRightNames =& $aRightNames;
00045     }
00046 
00052     function get ( $intId = 0 )
00053     {
00054         $this->oDB->query("SELECT * FROM `".$this->oDB->tblUsergroup."` WHERE `usergroup_id`='$intId';");
00055         $aRow = $this->oDB->fetch_assoc();
00056 
00057         if ( $aRow['usergroup_id'] != $intId )
00058         {
00059             // group does not exist
00060             return false;
00061         }
00062 
00063         return $aRow;
00064     }
00065 
00073     function set ( $intId, $strName, $aRights )
00074     {
00075         // extract all rights
00076         $strQuery = '';
00077         foreach ( $this->aAdminArrays AS $intArrayId => $strField )
00078         {
00079             $intTmp = 0; // rights for this field
00080             foreach ( $this->aAdmin[$intArrayId] AS $strRightName => $intBit )
00081             {
00082                 if ( isset ( $aRights[$strRightName] ) )
00083                 {
00084                     $intTmp |= $intBit;
00085                 }
00086             }
00087 
00088             $strQuery .= ',`'.$strField."`='".$intTmp."'";
00089         }
00090         $this->oDB->query("UPDATE `".$this->oDB->tblUsergroup."`
00091                            SET `name`='$strName'".$strQuery.$GLOBALS['strUpdateString']."
00092                            WHERE `usergroup_id`='$intId';");
00093         $this->oLog->write( 'Gruppenupdate: [' . $strName . '] (id=' . $intId . ')', 7 );
00094     }
00095 
00103     function add ( $strName, $aRights )
00104     {
00105         $this->oDB->query("SELECT `usergroup_id` FROM `".$this->oDB->tblUsergroup."` WHERE `name`='$strName';");
00106         $aRow = $this->oDB->fetch_assoc();
00107         if ( $aRow['usergroup_id'] > 0 )
00108         {
00109             // group with this name already exists
00110             return false;
00111         }
00112 
00113         // extract all rights
00114         $strQuery = '';
00115         foreach ( $this->aAdminArrays AS $intArrayId => $strField )
00116         {
00117             $intTmp = 0; // rights for this field
00118             foreach ( $this->aAdmin[$intArrayId] AS $strRightName => $intBit )
00119             {
00120                 if ( isset ( $aRights[$strRightName] ) )
00121                 {
00122                     $intTmp |= $intBit;
00123                 }
00124             }
00125 
00126             $strQuery .= ',`'.$strField."`='".$intTmp."'";
00127         }
00128 
00129         $this->oDB->query("INSERT INTO `".$this->oDB->tblUsergroup."`
00130                            SET `name`='$strName'".$strQuery.$GLOBALS['strUpdateString'].$GLOBALS['strCreatedString'].";");
00131         $this->oLog->write( "Gruppe angelegt: [" . $strName . "]", 7 );
00132         return true;
00133     }
00134 
00139     function getAll()
00140     {
00141         $aReturn = array();
00142 
00143         // in which fields are the rights?
00144         $strFields = ','.implode(',', $this->aAdminArrays);
00145 
00146         // get the groups
00147         $this->oDB->query("SELECT `usergroup_id`, `name`$strFields FROM `".$this->oDB->tblUsergroup."` ORDER BY `name`;");
00148         while ( $aRow = $this->oDB->fetch_assoc() )
00149         {
00150             $aReturn[] = $aRow;
00151         }
00152         return $aReturn;
00153     }
00154 }

Generated on Sun May 8 19:29:45 2005 for PhpMap by  doxygen 1.4.2