openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

GroupAction.class.php (6442B)


      1 <?php
      2 
      3 namespace cms\action;
      4 
      5 use cms\model\Acl;
      6 use cms\model\User;
      7 use cms\model\Project;
      8 use cms\model\Group;
      9 use cms\model\BaseObject;
     10 use cms\model\Language;
     11 
     12 use \Html;
     13 // OpenRat Content Management System
     14 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
     15 //
     16 // This program is free software; you can redistribute it and/or
     17 // modify it under the terms of the GNU General Public License
     18 // as published by the Free Software Foundation; either version 2
     19 // of the License, or (at your option) any later version.
     20 //
     21 // This program is distributed in the hope that it will be useful,
     22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 // GNU General Public License for more details.
     25 //
     26 // You should have received a copy of the GNU General Public License
     27 // along with this program; if not, write to the Free Software
     28 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     29 
     30 
     31 /**
     32  * Action-Klasse zum Bearbeiten einer Benutzergruppe.
     33  * 
     34  * @author Jan Dankert
     35  */
     36 
     37 class GroupAction extends BaseAction
     38 {
     39 	public $security = Action::SECURITY_ADMIN;
     40 
     41     /**
     42      * @var Group
     43      */
     44 	private $group;
     45 
     46 
     47 	function __construct()
     48 	{
     49         parent::__construct();
     50 
     51     }
     52 
     53 
     54     public function init()
     55     {
     56         $this->group = new Group( $this->getRequestId() );
     57 		$this->group->load();
     58 		$this->setTemplateVar( 'groupid',$this->group->groupid );
     59 	}
     60 
     61 
     62 
     63 	function removePost()
     64 	{
     65 		if   ( $this->hasRequestVar('confirm') )
     66 		{
     67 			$this->group->delete();
     68 	
     69 			$this->addNotice('group',$this->group->name,'DELETED',OR_NOTICE_OK);
     70 		}
     71 		else
     72 		{
     73 			$this->addNotice('group',$this->group->name,'NOTHING_DONE',OR_NOTICE_WARN);
     74 		}
     75 	}
     76 	
     77 	
     78 	
     79 	function removeView()
     80 	{
     81 		$this->setTemplateVars( $this->group->getProperties() );
     82 	}
     83 	
     84 	
     85 	
     86 	public function propPost()
     87 	{
     88 		if	( ! $this->getRequestVar('name') )
     89 		    throw new \ValidationException('name');
     90 
     91         $this->group->name = $this->getRequestVar('name');
     92         $this->group->save();
     93 
     94         $this->addNotice('group',$this->group->name,'SAVED','ok');
     95 	}
     96 
     97 
     98 	function adduser()
     99 	{
    100 		$this->setTemplateVar('users',$this->group->getOtherUsers());
    101 	}
    102 
    103 
    104 	/**
    105 	 * Benutzer zur Gruppe hinzuf�gen.<br>
    106 	 * Es kann eine Liste oder eine einzelne Person zur Gruppe hinzugef�gt werden.
    107 	 */
    108 	function addusertogroup()
    109 	{
    110 		$userid = $this->getRequestVar('userid');
    111 
    112 		if	( is_array($userid))
    113 		{
    114 			// Im Request steht eine Liste von User-Ids.
    115 			foreach( $userid as $uid )
    116 			{
    117 				$this->group->addUser( $uid );
    118 			}
    119 			$this->addNotice('group',$this->group->name,'USER_ADDED_TO_GROUP',OR_NOTICE_OK,array('count'=>count($userid)));
    120 		}
    121 		elseif( intval($userid) > 0 )
    122 		{
    123 			// Nur 1 Benutzer hinzuf�gen.
    124 			$this->group->addUser( intval($userid) );
    125 			$this->addNotice('group',$this->group->name,'USER_ADDED_TO_GROUP',OK_NOTICE_OK,array('count'=>'1'));
    126 		}
    127 		else
    128 		{
    129 			// Es wurde kein Benutzer ausgew�hlt.
    130 			$this->addNotice('group',$this->group->name,'NOTHING_DONE',OR_NOTICE_WARN);
    131 		}
    132 	}
    133 
    134 
    135 	
    136 	/**
    137 	 * Einen Benutzer aus der Gruppe entfernen.
    138 	 */
    139 	function deluser()
    140 	{
    141 		$this->group->delUser( intval($this->getRequestVar('userid')) );
    142 	
    143 		$this->addNotice('group',$this->group->name,'DELETED',OR_NOTICE_OK);
    144 	}
    145 
    146 
    147 
    148 	/**
    149 	 * Liste aller Gruppen.
    150 	 */
    151 	function listingView()
    152 	{
    153 		$list = array();
    154 
    155 		foreach( Group::getAll() as $id=>$name )
    156 		{
    157 			$list[$id]         = array();
    158 			$list[$id]['name'] = $name;
    159 		}
    160 
    161 		$this->setTemplateVar('el',	$list);
    162 	}
    163 
    164 
    165 	function infoView()
    166 	{
    167 		$this->setTemplateVars( $this->group->getProperties() );
    168 		$this->setTemplateVar( 'users',$this->group->getUsers() );
    169 	}
    170 
    171 
    172 	
    173 	function propView()
    174 	{
    175 		$this->setTemplateVars( $this->group->getProperties() );
    176 	}
    177 
    178 
    179 
    180 
    181 	
    182 	
    183 	/**
    184 	 * Liste aller Benutzer in dieser Gruppe.
    185 	 *
    186 	 */
    187 	function membershipsView()
    188 	{
    189 		// Mitgliedschaften ermitteln
    190 		//
    191 		$userliste = array();
    192 		
    193 		$allUsers = User::listAll();
    194 		
    195 		$actualGroupUsers = $this->group->getUsers();
    196 		
    197 		foreach( $allUsers as $id=>$name )
    198 		{
    199 			$hasUser = array_key_exists($id,$actualGroupUsers);
    200 			$varName  = 'user'.$id;
    201 			$userliste[$id] = array('name'       => $name,
    202 			                        'id'         => $id,
    203 			                        'var'        => $varName,
    204 			                        'member'     => $hasUser
    205 			                        );
    206 			$this->setTemplateVar($varName,$hasUser);
    207 		}
    208 		$this->setTemplateVar('memberships',$userliste);
    209 
    210 		global $conf;
    211 		if	($conf['security']['authorize']['type']=='ldap')
    212 			$this->addNotice('group',$this->group->name,'GROUPS_MAY_CONFLICT_WITH_LDAP',OR_NOTICE_WARN);
    213 	}
    214 	
    215 	
    216 	function membershipsPost()
    217 	{
    218 		$allUsers  = User::listAll();
    219 		$groupUsers = $this->group->getUsers();
    220 		
    221 		foreach( $allUsers as $id=>$name )
    222 		{
    223 			$hasUser = array_key_exists($id,$groupUsers);
    224 			
    225 			if	( !$hasUser && $this->hasRequestVar('user'.$id) )
    226 			{
    227 				$this->group->addUser($id);
    228 				$this->addNotice('user',$name,'ADDED');
    229 			}
    230 
    231 			if	( $hasUser && !$this->hasRequestVar('user'.$id) )
    232 			{
    233 				$this->group->delUser($id);
    234 				$this->addNotice('user',$name,'DELETED');
    235 			}
    236 		}
    237 	}
    238 
    239 	
    240 	
    241 	
    242 
    243 	/**
    244 	 * Anzeigen der Benutzerrechte
    245 	 */
    246 	function rightsView()
    247 	{
    248 		$rights = $this->group->getAllAcls();
    249 
    250 		$projects = array();
    251 		
    252 		foreach( $rights as $acl )
    253 		{
    254 			if	( !isset($projects[$acl->projectid]))
    255 			{
    256 				$projects[$acl->projectid] = array();
    257 				$p = new Project($acl->projectid);
    258 				$p->load();
    259 				$projects[$acl->projectid]['projectname'] = $p->name;
    260 				$projects[$acl->projectid]['rights'     ] = array();
    261 			}
    262 
    263 			$right = array();
    264 			
    265 			if	( $acl->languageid > 0 )
    266 			{
    267 				$language = new Language($acl->languageid);
    268 				$language->load();
    269 				$right['languagename'] = $language->name;
    270 			}
    271 			else
    272 			{
    273 				$right['languagename'] = lang('ALL_LANGUAGES');
    274 			}
    275 			
    276 			
    277 			$o = new BaseObject($acl->objectid);
    278 			$o->objectLoad();
    279 			$right['objectname'] = $o->name;
    280 			$right['objectid'  ] = $o->objectid;
    281 			$right['objecttype'] = $o->getType();
    282 			
    283 			if	( $acl->groupid > 0 )
    284 			{
    285 				$group = new Group($acl->groupid);
    286 				$group->load();
    287 				$right['groupname'] = $group->name;
    288 			}
    289 			else
    290 			{
    291 				// Berechtigung f�r "alle".
    292 			}
    293 
    294 			$right['bits'] = $acl->getProperties();
    295 			
    296 			$projects[$acl->projectid]['rights'][] = $right;
    297 		}
    298 		
    299 		$this->setTemplateVar('projects'    ,$projects );
    300 		
    301 		$this->setTemplateVar('show',Acl::getAvailableRights() );
    302 	}
    303 	
    304 	
    305 	
    306 }