<?php
/**
* iF.SVNAdmin
* Copyright (c) 2010 by Manuel Freiholz
* http://www.insanefactory.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.
*/
if( !defined('ACTION_HANDLING') ) {
die("HaHa!");
}
$appEngine->checkUserAuthentication(true, ACL_MOD_ACCESSPATH, ACL_ACTION_ASSIGN);
// Required variables.
$selusers = get_request_var('selected_users');
$selgroups = get_request_var('selected_groups');
$selpaths = get_request_var('selected_accesspaths');
$selperm = get_request_var('permission'); // TODO: There is no check, whether this var is given!
if (count($selusers) == 1 && empty($selusers[0]))
$selusers = NULL;
if (count($selgroups) == 1 && empty($selgroups[0]))
$selgroups = NULL;
if (count($selpaths) == 1 && empty($selpaths[0]))
$selpaths = NULL;
if( $selpaths == NULL || ( $selusers == NULL && $selgroups == NULL ) )
{
$appTemplate->addDefine("WARNING");
$appTemplate->addReplacement("WARNINGMSG", tr("You have to select a user or group and an access-path to perform this action."));
}
else
{
// The number of selected elements.
$selpathsLen = count($selpaths);
$selgroupsLen = 0;
if( $selgroups != NULL ){
$selgroupsLen = count($selgroups);
}
$selusersLen = 0;
if( $selusers != NULL ){
$selusersLen = count($selusers);
}
// Count actions.
$cntAll = ($selpathsLen*$selgroupsLen) + ($selpathsLen*$selusersLen);
$doneList = array(); // List of successfully handled paths.
$noPermList = array(); // List of paths, where the user have no permission.
$failedList = array(); // List of paths, which could not been handled.
// Create permission object.
$oP = new \svnadmin\core\entities\Permission;
$oP->perm = $selperm;
// Iterate all selected_accesspaths.
for( $i=0; $i<$selpathsLen; $i++ )
{
$oAP = new \svnadmin\core\entities\AccessPath;
$oAP->id = $selpaths[$i];
$oAP->path = $selpaths[$i];
// Is the user restricted to some paths? (project-manager)
if ($appEngine->isAuthenticationActive())
{
$currentUsername = $appEngine->getSessionUsername();
if ($appEngine->getAclManager()->isUserAccessPathManager($currentUsername))
{
if (!$appEngine->getAclManager()->isUserAdminOfPath($currentUsername, $oAP->path))
{
$noPermList[] = $oAP->path;
continue;
}
}
}
// Iterate selected_users.
for( $iu=0; $iu<$selusersLen; $iu++ )
{
$oU = new \svnadmin\core\entities\User;
$oU->id = $selusers[$iu];
$oU->name = $selusers[$iu];
$done = $appEngine->getAccessPathEditProvider()->assignUserToAccessPath( $oU, $oAP, $oP );
if ($done)
$doneList[] = $oAP->path;
else
$failedList[] = $oAP->path;
}
// Iterate selected_groups.
for( $ig=0; $ig<$selgroupsLen; $ig++ )
{
$oG = new \svnadmin\core\entities\Group;
$oG->id = $selgroups[$ig];
$oG->name = $selgroups[$ig];
$done = $appEngine->getAccessPathEditProvider()->assignGroupToAccessPath( $oG, $oAP, $oP );
if ($done)
$doneList[] = $oAP->path;
else
$failedList[] = $oAP->path;
}
}
$appEngine->getAccessPathEditProvider()->save();
//////////////////////////////////////////////////////////////////////////////
// Result
//////////////////////////////////////////////////////////////////////////////
if (count($doneList) > 0)
{
$msg = tr("The following Access-Path's has been assigned:");
$msg.= "<br>";
$msg.= "<ul>";
$doneList = array_unique($doneList);
foreach ($doneList as &$valPath)
{
$msg.= "<li>".$valPath."</li>";
}
$msg.= "</ul>";
$appTemplate->addDefine("INFO");
$appTemplate->addReplacement("INFOMSG", $msg);
}
if (count($noPermList) > 0)
{
$msg = tr("You have no permission to assign the following Access-Path's, they have been skipped:");
$msg.= "<br>";
$msg.= "<ul>";
$noPermList = array_unique($noPermList);
foreach ($noPermList as &$valPath)
{
$msg.= "<li>".$valPath."</li>";
}
$msg.= "</ul>";
$appTemplate->addDefine("WARNING");
$appTemplate->addReplacement("WARNINGMSG", $msg);
}
if (count($failedList) > 0)
{
$msg = tr("Due to an unknown error, the following Access-Path's could not been handled:");
$msg.= "<br>";
$msg.= "<ul>";
$failedList = array_unique($failedList);
foreach ($failedList as &$valPath)
{
$msg.= "<li>".$valPath."</li>";
}
$msg.= "</ul>";
$appTemplate->addDefine("ERROR");
$appTemplate->addReplacement("ERRORMSG", $msg);
}
}
?>