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

group.php

Go to the documentation of this file.
00001 <?php
00009 /***************************************************************************
00010  This program is free software; you can redistribute it and/or
00011  modify it under the terms of the GNU General Public License
00012  as published by the Free Software Foundation; either version 2
00013  of the License, or (at your option) any later version.
00014 
00015  This program is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU General Public License for more details.
00019 
00020  You should have received a copy of the GNU General Public License
00021  along with this program; if not, write to the Free Software
00022  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023  ***************************************************************************/
00024 
00025 require_once ('./general.php');
00026 require_once ('./lib/group.php');
00027 
00028 // get styles
00029 $oStyle->setTemplate ( 'group.html' );
00030 
00031 $oGroup = new Group ( $oMysql, $oLog, $aAdmin, $aAdminArrays, $aRightNames );
00032 
00033 // get variables
00034 if(isset($_POST['action']))     $action = $_POST['action'];
00035 elseif(isset($_GET['action']))  $action = $_GET['action'];
00036 else $action = 'list';
00037 
00038 //-----------------------------------------------------------------------------
00039 if ($action == 'edit' && $oUser->isAdmin ( 'group_edit' ) )
00040 {
00041     if ( !isset ( $_POST['newrights'] ) || !is_array ( $_POST['newrights'] ) )
00042     {
00043         die();
00044     }
00045     $aNew =& $_POST['newrights'];
00046     $aGroups = $oGroup->getAll();
00047     foreach ( $aGroups AS $aData )
00048     {
00049         if ( isset ( $aNew[$aData['usergroup_id']] ) )
00050         {
00051             // there are admin rights for this group
00052             unset ( $aNew[$aData['usergroup_id']]['set'] );
00053             $oGroup->set ( $aData['usergroup_id'], $aData['name'], $aNew[$aData['usergroup_id']] );
00054         }
00055     }
00056     $oStyle->addReplacements ( array ( 'REFRESH_URL' => 'group.php',
00057                                        'REFRESH_MSG' => 'Rechte erfolgreich ge&auml;ndert.' ) );
00058     echo trim ( $oStyle->get_area('Refresh') );
00059     die();
00060 }
00061 //-----------------------------------------------------------------------------
00062 elseif ( $action=='add' && $oUser->isAdmin ( 'group_add' ) )
00063 {
00064     if ( isset ( $_POST['newrights'] ) && is_array ( $_POST['newrights'] ) )
00065     {
00066         // form sent
00067         $strName = $_POST['newrights'][0]['name'];
00068         unset ( $_POST['newrights'][0]['name'] );
00069         $booSuccess = $oGroup->add ( $strName, $_POST['newrights'][0] );
00070         $strMsg = $booSuccess ? 'Gruppe erfolgreich angelegt.' : 'Eine Gruppe mit diesem Namen existiert bereits';
00071         $oStyle->addReplacements ( array ( 'REFRESH_URL' => 'group.php',
00072                                            'REFRESH_MSG' => $strMsg ) );
00073         echo trim ( $oStyle->get_area('Refresh') );
00074         die();
00075     }
00076 
00077     $i = 1;
00078     $strHead = '';
00079     $strInfo = '';
00080     $strNewGroup = '';
00081     foreach ( $aRightNames AS $strRight => $aRightInfo )
00082     {
00083         $strHead .= '<td>'.$aRightInfo[0].'</td>';
00084         $strInfo .= '<tr id="ar_'.$strRight.'"><td>'.$aRightInfo[0].'</td><td>'.$aRightInfo[1].'</td></tr>';
00085         $oStyle->addReplacements ( array ( 'RIGHT' => $strRight, 'CHECKED' => '', 'GROUP_ID' => '0' ) );
00086         $strNewGroup .= $oStyle->get_area('GroupChk');
00087         $i++;
00088     }
00089 
00090     $oStyle->addReplacements ( array ( 'GROUP_HEAD' => $strHead,
00091                                        'GROUP_COLSPAN' => $i,
00092                                        'GROUP_INFO' => $strInfo,
00093                                        'GROUP_NEW' => $strNewGroup ) );
00094 }
00095 //-----------------------------------------------------------------------------
00096 if ( $action == 'list' && $oUser->isAdmin ( 'group_list' ) )
00097 {
00098     $aGroups = $oGroup->getAll();
00099     $i = 0;
00100     $strGroupList = '';
00101     foreach ( $aGroups AS $aData )
00102     {
00103         $oStyle->addReplacements ( array ( 'GROUP_NAME' => $aData['name'],
00104                                            'GROUP_ID' => $aData['usergroup_id'],
00105                                            'GROUP_ROW' => intval(($i++ % 2) == 0)
00106                                          ) );
00107         $strTest = '';
00108         // only rights with a name are displayed
00109         foreach ( $aRightNames AS $strRight => $aRightInfo )
00110         {
00111             $strChecked = '';
00112             foreach ( $aAdminArrays AS $intKey => $strField )
00113             {
00114                 if ( isset ( $aAdmin[$intKey][$strRight] ) && ( ( $aAdmin[$intKey][$strRight] & $aData[$strField] ) > 0 ) )
00115                 {
00116                     $strChecked = ' checked="checked"';
00117                 }
00118             }
00119             $oStyle->addReplacements ( array ( 'RIGHT' => $strRight,
00120                                                'CHECKED' => $strChecked
00121                                          ) );
00122             $strTest .= $oStyle->get_area('GroupChk');
00123         }
00124 
00125         $oStyle->addReplacements ( array ( 'RIGHTS' => $strTest ) );
00126         $strGroupList .= $oStyle->get_area( 'GroupRow' );
00127     }
00128     // build top and bottom
00129     $i = 1; // counter for tds
00130     $strHead = '';
00131     $strInfo = '';
00132     $aInfo = array();
00133     $intNames = ceil( count( $aRightNames ) / 2 );
00134     $intNamesF = floor( count( $aRightNames ) / 2 );
00135     foreach ( $aRightNames AS $strRight => $aRightInfo )
00136     {
00137         $strHead .= '<td>'.$aRightInfo[0].'</td>';
00138         $aInfo[$i] = array( $aRightInfo[0], $strRight, $aRightInfo[1] );
00139         $i++;
00140     }
00141     for( $j=1; $j<=$intNames; ++$j )
00142     {
00143         $strInfo .= '<tr><td>'.$aInfo[$j][0].'</td><td id="ar_'.$aInfo[$j][1].'">'.$aInfo[$j][2].'</td>';
00144         if( isset( $aInfo[$j+$intNamesF] ) )
00145         {
00146             $strInfo .= '<td>'.$aInfo[$j+$intNamesF][0].'</td><td id="ar_'.$aInfo[$j+$intNamesF][1].'">'.$aInfo[$j+$intNamesF][2].'</td></tr>';
00147         }
00148         else
00149         {
00150             $strInfo .= '<td colspan="2"></td></tr>';
00151         }
00152     }
00153 
00154     $oStyle->addReplacements ( array ( 'GROUP_HEAD' => $strHead,
00155                                        'GROUP_COLSPAN' => $i,
00156                                        'GROUP_INFO' => $strInfo,
00157                                        'GROUP_RESULT' => $strGroupList ) );
00158 }
00159 
00160 // get the area
00161 $strTmpl_inhalt = $oStyle->get_area( ucfirst($action) );
00162 output();

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