GroupAction.class.php

gehe zur Dokumentation dieser Datei
00001 <?php
00002 // ---------------------------------------------------------------------------
00003 // $Id$
00004 // ---------------------------------------------------------------------------
00005 // OpenRat Content Management System
00006 // Copyright (C) 2002-2004 Jan Dankert, cms@jandankert.de
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 // ---------------------------------------------------------------------------
00022 
00023 
00032 class GroupAction extends Action
00033 {
00034      var $group;
00035      var $defaultSubAction = 'edit';
00036 
00037 
00038      function GroupAction()
00039      {
00040           if   ( !$this->userIsAdmin() )
00041                die('you are not an admin');
00042 
00043           if   ( $this->getRequestId() != 0 )
00044           {
00045                $this->group = new Group( $this->getRequestId() );
00046                $this->group->load();
00047                $this->setTemplateVar( 'groupid',$this->group->groupid );
00048           }
00049      }
00050 
00051 
00052 
00053      function delete()
00054      {
00055           if   ( $this->hasRequestVar('confirm') )
00056           {
00057                $this->group->delete();
00058      
00059                $this->addNotice('group',$this->group->name,'DELETED','ok');
00060           }
00061           else
00062           {
00063                $this->addNotice('group',$this->group->name,'NOT_DELETED','ok');
00064           }
00065      }
00066      
00067      
00068      
00069      function remove()
00070      {
00071           $this->setTemplateVars( $this->group->getProperties() );
00072      }
00073      
00074      
00075      
00076      function save()
00077      {
00078           if   ( $this->getRequestVar('name') != '' )
00079           {
00080                $this->group->name = $this->getRequestVar('name');
00081                
00082                $this->group->save();
00083      
00084                $this->addNotice('group',$this->group->name,'SAVED','ok');
00085           }
00086           else
00087           {
00088                $this->addValidationError('name');
00089                $this->callSubAction('edit');
00090           }
00091      }
00092 
00093 
00094      function add()
00095      {
00096      }
00097      
00098      
00099      function addgroup()
00100      {
00101           if   ( $this->getRequestVar('name') != '')
00102           {
00103                $this->group = new Group();
00104                $this->group->name = $this->getRequestVar('name');
00105                $this->group->add();
00106                $this->addNotice('group',$this->group->name,'ADDED','ok');
00107                $this->callSubAction('listing');
00108           }
00109           else
00110           {
00111                $this->addValidationError('name');
00112                $this->callSubAction('add');
00113           }
00114      }
00115 
00116 
00117      function adduser()
00118      {
00119           $this->setTemplateVar('users',$this->group->getOtherUsers());
00120      }
00121 
00122 
00127      function addusertogroup()
00128      {
00129           $userid = $this->getRequestVar('userid');
00130 
00131           if   ( is_array($userid))
00132           {
00133                // Im Request steht eine Liste von User-Ids.
00134                foreach( $userid as $uid )
00135                {
00136                     $this->group->addUser( $uid );
00137                }
00138                $this->addNotice('group',$this->group->name,'USER_ADDED_TO_GROUP',OR_NOTICE_OK,array('count'=>count($userid)));
00139           }
00140           elseif( intval($userid) > 0 )
00141           {
00142                // Nur 1 Benutzer hinzuf�gen.
00143                $this->group->addUser( intval($userid) );
00144                $this->addNotice('group',$this->group->name,'USER_ADDED_TO_GROUP',OK_NOTICE_OK,array('count'=>'1'));
00145           }
00146           else
00147           {
00148                // Es wurde kein Benutzer ausgew�hlt.
00149                $this->addNotice('group',$this->group->name,'NOTHING_DONE',OR_NOTICE_WARN);
00150           }
00151      }
00152 
00153 
00154      
00158      function deluser()
00159      {
00160           $this->group->delUser( intval($this->getRequestVar('userid')) );
00161      
00162           $this->addNotice('group',$this->group->name,'DELETED',OR_NOTICE_OK);
00163      }
00164 
00165 
00166 
00170      function listing()
00171      {
00172           $list = array();
00173 
00174           foreach( Group::getAll() as $id=>$name )
00175           {
00176                $list[$id]         = array();
00177                $list[$id]['url' ] = Html::url('main','group',$id,array(REQ_PARAM_TARGETSUBACTION=>'edit'));
00178                $list[$id]['name'] = $name;
00179           }
00180 
00181           $this->setTemplateVar('el',   $list);
00182      }
00183 
00184 
00185      function edit()
00186      {
00187           $this->setTemplateVars( $this->group->getProperties() );
00188      }
00189 
00190 
00191      
00195      function memberships()
00196      {
00197      }
00198      
00199      
00200      
00205      function users()
00206      {
00207           // Mitgliedschaften ermitteln
00208           //
00209           $userliste = array();
00210           
00211           foreach( $this->group->getUsers() as $userid=>$name )
00212           {
00213                $userliste[$userid] = array('name'       => $name,
00214                                            'delete_url' => Html::url('group','deluser',$this->getRequestId(),array('userid'=>$userid)));
00215           }
00216           $this->setTemplateVar('memberships',$userliste);
00217      }
00218 
00219      
00220      
00221      
00222 
00226      function rights()
00227      {
00228           $rights = $this->group->getAllAcls();
00229 
00230           $projects = array();
00231           
00232           foreach( $rights as $acl )
00233           {
00234                if   ( !isset($projects[$acl->projectid]))
00235                {
00236                     $projects[$acl->projectid] = array();
00237                     $p = new Project($acl->projectid);
00238                     $p->load();
00239                     $projects[$acl->projectid]['projectname'] = $p->name;
00240                     $projects[$acl->projectid]['rights'     ] = array();
00241                }
00242 
00243                $right = array();
00244                
00245                if   ( $acl->languageid > 0 )
00246                {
00247                     $language = new Language($acl->languageid);
00248                     $language->load();
00249                     $right['languagename'] = $language->name;
00250                }
00251                else
00252                {
00253                     $right['languagename'] = lang('ALL_LANGUAGES');
00254                }
00255                
00256                
00257                $o = new Object($acl->objectid);
00258                $o->objectLoad();
00259                $right['objectname'] = $o->name;
00260                $right['objectid'  ] = $o->objectid;
00261                $right['objecttype'] = $o->getType();
00262                
00263                if   ( $acl->groupid > 0 )
00264                {
00265                     $group = new Group($acl->groupid);
00266                     $group->load();
00267                     $right['groupname'] = $group->name;
00268                }
00269                else
00270                {
00271                     // Berechtigung f�r "alle".
00272                }
00273 
00274                $right['bits'] = $acl->getProperties();
00275                
00276                $projects[$acl->projectid]['rights'][] = $right;
00277           }
00278           
00279           $this->setTemplateVar('projects'    ,$projects );
00280           
00281           $this->setTemplateVar('show',Acl::getAvailableRights() );
00282      }
00283      
00284      
00285      
00292      function checkMenu( $menu )
00293      {
00294           switch( $menu )
00295           {
00296                case 'users':
00297                     // Benutzerliste nur anzeigen, wenn welche vorhanden.
00298                     return count($this->group->getUsers()) > 0;
00299                case 'adduser':
00300                     // Benutzer k�nnen nur hinzugef�gt werden, wenn noch nicht alle
00301                     // in der Gruppe sind.
00302                     return count($this->group->getOtherUsers()) > 0;
00303                default:
00304                     return true;
00305           }
00306      }
00307 }

Erzeugt am Thu May 14 00:55:48 2009 für OpenRat von  doxygen 1.5.8