UserAction.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 
00029 class UserAction extends Action
00030 {
00031      var $user;
00032      var $defaultSubAction = 'edit';
00033 
00034 
00035      function UserAction()
00036      {
00037           if   ( !$this->userIsAdmin() )
00038                die('you are not an admin');
00039 
00040           if   ( $this->getRequestId() != 0 )
00041           {
00042                $this->user = new User( $this->getRequestId() );
00043                $this->user->load();
00044                $this->setTemplateVar('userid',$this->user->userid);
00045           }
00046      }
00047 
00048 
00049      function save()
00050      {
00051           if   ( $this->getRequestVar('name') != '' )
00052           {
00053                // Benutzer speichern
00054                $this->user->name     = $this->getRequestVar('name'    );
00055                $this->user->fullname = $this->getRequestVar('fullname');
00056                $this->user->isAdmin  = $this->hasRequestVar('is_admin');
00057                $this->user->ldap_dn  = $this->getRequestVar('ldap_dn' );
00058                $this->user->tel      = $this->getRequestVar('tel'     );
00059                $this->user->desc     = $this->getRequestVar('desc'    );
00060                
00061                global $conf;
00062                if   ( @$conf['security']['user']['show_mail'] )
00063                     $this->user->mail = $this->getRequestVar('mail'    );
00064                     
00065                $this->user->style    = $this->getRequestVar('style'   );
00066      
00067                $this->user->save();
00068                $this->addNotice('user',$this->user->name,'SAVED','ok');
00069           }
00070           else
00071           {
00072                $this->addValidationError('name');
00073                $this->callSubAction('edit');
00074           }
00075      }
00076 
00077 
00078 
00079      function remove()
00080      {
00081           $this->setTemplateVars( $this->user->getProperties() );
00082      }
00083      
00084      
00085      
00086      function delete()
00087      {
00088           if   ( $this->hasRequestVar('confirm') )
00089           {
00090                $this->user->delete();
00091                $this->addNotice('user',$this->user->name,'DELETED','ok');
00092           }
00093           else
00094           {
00095                $this->addValidationError('confirm');
00096                $this->callSubAction('remove');
00097           }
00098      }
00099 
00100 
00101      function add()
00102      {
00103      }
00104      
00105      
00106      
00107      function adduser()
00108      {
00109           if   ( $this->getRequestVar('name') != '' )
00110           {
00111                $this->user = new User();
00112                $this->user->add( $this->getRequestVar('name') );
00113                $this->addNotice('user',$this->user->name,'ADDED','ok');
00114           }
00115           else
00116           {
00117                $this->addValidationError('name');
00118                $this->callSubAction('add');
00119           }
00120      }
00121 
00122 
00123      function addgrouptouser()
00124      {
00125           $this->user->addGroup( $this->getRequestVar('groupid') );
00126      
00127           $this->addNotice('user',$this->user->name,'ADDED','ok');
00128      }
00129 
00130 
00131      function addgroup()
00132      {
00133           // Alle hinzufuegbaren Gruppen ermitteln
00134           $this->setTemplateVar('groups',$this->user->getOtherGroups());
00135      }
00136 
00137 
00138      function delgroup()
00139      {
00140           $this->user->delGroup( $this->getRequestVar('groupid') );
00141 
00142           $this->addNotice('user',$this->user->name,'DELETED','ok');
00143      }
00144 
00145 
00151      function mailPw( $pw )
00152      {
00153           $to   = $this->user->fullname.' <'.$this->user->mail.'>';
00154           $mail = new Mail($to,'USER_MAIL');
00155 
00156           $mail->setVar('username',$this->user->name      );
00157           $mail->setVar('password',$pw                    );
00158           $mail->setVar('name'    ,$this->user->getName() );
00159 
00160           $mail->send();
00161      }
00162 
00163 
00167      function pwchange()
00168      {
00169           global $conf;
00170 
00171           $pw1 = $this->getRequestVar('password1');
00172           $pw2 = $this->getRequestVar('password2');
00173 
00174           // Zufaelliges Kennwort erzeugen
00175           if   ( $this->hasRequestVar('random') && $this->hasRequestVar('email') )
00176           {
00177                $pw1 = $this->user->createPassword();
00178                $pw2 = $pw1;
00179           }
00180 
00181           if ( strlen($pw1)<intval($conf['security']['password']['min_length']) )
00182           {
00183                $this->addValidationError('password1');
00184                $this->callSubAction('pw');
00185           }
00186           elseif    ( $pw1 != $pw2 )
00187           {
00188                $this->addValidationError('password2');
00189                $this->callSubAction('pw');
00190           }
00191           else
00192           {
00193                // Kennwoerter identisch und lang genug
00194                $this->user->setPassword($pw1,!$this->hasRequestVar('timeout') ); // Kennwort setzen
00195                
00196                // E-Mail mit dem neuen Kennwort an Benutzer senden
00197                if   ( $this->hasRequestVar('email') && !empty($this->user->mail) && $conf['mail']['enabled'] )
00198                {
00199                     $this->mailPw( $pw1 );
00200                     $this->addNotice('user',$this->user->name,'MAIL_SENT','ok');
00201                }
00202 
00203                $this->addNotice('user',$this->user->name,'SAVED','ok');
00204           }
00205 
00206      }
00207 
00208 
00209 
00210      function listing()
00211      {
00212           $list = array();
00213 
00214           foreach( User::getAllUsers() as $user )
00215           {
00216                $list[$user->userid]         = $user->getProperties();
00217                $list[$user->userid]['url' ] = Html::url('main','user',$user->userid,
00218                                                         array(REQ_PARAM_TARGETSUBACTION=>'edit') );
00219           }
00220           $this->setTemplateVar('el',$list);
00221      }    
00222           
00223 
00227      function edit()
00228      {
00229           $this->setTemplateVars( $this->user->getProperties() );
00230 
00231           $this->setTemplateVar( 'allstyles',$this->user->getAvailableStyles() );
00232      }
00233 
00234 
00235      function memberships()
00236      {
00237           
00238      }
00239 
00240      
00241      function groups()
00242      {
00243           // Mitgliedschaften
00244 //        $this->setTemplateVar('memberships',$this->user->getGroups());
00245           
00246           $gruppenListe = array();
00247           
00248           $allGroups  = Group::getAll();
00249           $userGroups = $this->user->getGroups();
00250           
00251           foreach( $allGroups as $id=>$name )
00252           {
00253                
00254                $hasGroup = array_key_exists($id,$userGroups);
00255                $varName  = 'group'.$id;
00256                $gruppenListe[$id] = array('name'       =>$name,
00257                                           'id'         =>$id,
00258                                           'var'        =>$varName,
00259                                           'member'     =>$hasGroup
00260                                          );
00261                $this->setTemplateVar($varName,$hasGroup);
00262           }
00263           $this->setTemplateVar('memberships',$gruppenListe);
00264           
00265           global $conf;
00266           if   ($conf['security']['authorize']['type']=='ldap')
00267                $this->addNotice('user',$this->user->name,'GROUPS_MAY_CONFLICT_WITH_LDAP',OR_NOTICE_WARN);
00268      }
00269 
00270 
00271      function savegroups()
00272      {
00273           $allGroups  = Group::getAll();
00274           $userGroups = $this->user->getGroups();
00275           
00276           foreach( $allGroups as $id=>$name )
00277           {
00278                $hasGroup = array_key_exists($id,$userGroups);
00279                
00280                if   ( !$hasGroup && $this->hasRequestVar('group'.$id) )
00281                {
00282                     $this->user->addGroup($id);
00283                     $this->addNotice('group',$name,'ADDED');
00284                }
00285 
00286                if   ( $hasGroup && !$this->hasRequestVar('group'.$id) )
00287                {
00288                     $this->user->delGroup($id);
00289                     $this->addNotice('group',$name,'DELETED');
00290                }
00291           }
00292      }
00293 
00294 
00298      function pw()
00299      {
00300           $this->setTemplateVars( $this->user->getProperties() );
00301      }
00302 
00303 
00307      function rights()
00308      {
00309           $rights = $this->user->getAllAcls();
00310 
00311           $projects = array();
00312           
00313           foreach( $rights as $acl )
00314           {
00315                if   ( !isset($projects[$acl->projectid]))
00316                {
00317                     $projects[$acl->projectid] = array();
00318                     $p = new Project($acl->projectid);
00319                     $p->load();
00320                     $projects[$acl->projectid]['projectname'] = $p->name;
00321                     $projects[$acl->projectid]['rights'     ] = array();
00322                }
00323 
00324                $right = array();
00325                
00326                if   ( $acl->languageid > 0 )
00327                {
00328                     $language = new Language($acl->languageid);
00329                     $language->load();
00330                     $right['languagename'] = $language->name;
00331                }
00332                else
00333                {
00334                     $right['languagename'] = lang('ALL_LANGUAGES');
00335                }
00336                
00337                
00338                $o = new Object($acl->objectid);
00339                $o->objectLoad();
00340                $right['objectname'] = $o->name;
00341                $right['objectid'  ] = $o->objectid;
00342                $right['objecttype'] = $o->getType();
00343                
00344                if   ( $acl->userid > 0 )
00345                {
00346                     $user = new User($acl->userid);
00347                     $user->load();
00348                     $right['username'] = $user->name;
00349                }
00350                elseif    ( $acl->groupid > 0 )
00351                {
00352                     $group = new Group($acl->groupid);
00353                     $group->load();
00354                     $right['groupname'] = $group->name;
00355                }
00356                else
00357                {
00358                     // Berechtigung f�r "alle".
00359                }
00360 
00361 //             $show = array();
00362 //             foreach( $acl->getProperties() as $p=>$set)
00363 //                  $show[$p] = $set;
00364 //                  
00365 //             $right['show'] = $show;
00366                $right['bits'] = $acl->getProperties();
00367                
00368                $projects[$acl->projectid]['rights'][] = $right;
00369           }
00370           
00371           $this->setTemplateVar('projects'    ,$projects );
00372           
00373           $this->setTemplateVar('show',Acl::getAvailableRights() );
00374           
00375           if   ( $this->user->isAdmin )
00376                $this->addNotice('user',$this->user->name,'ADMIN_NEEDS_NO_RIGHTS',OR_NOTICE_WARN);
00377      }
00378      
00379      
00384      function checkMenu( $menu )
00385      {
00386           global $conf;
00387 
00388           switch( $menu )
00389           {
00390                case 'addgroup':
00391                     return count($this->user->getOtherGroups()) > 0;
00392 
00393                case 'groups':
00394                     return count($this->user->getGroups()) > 0;
00395      
00396                case 'pw':
00397                     return     @$conf['security']['auth']['type'] == 'database'
00398                            && !@$conf['security']['auth']['userdn'];
00399           }
00400           
00401           return true;
00402      }
00403      
00404                     
00405 }

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