<?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!");
}
// Check module.
$appEngine->forwardInvalidModule( !$appEngine->isGroupEditActive() );
// Parameters.
$selusers = get_request_var('selusers');
$selgroups = get_request_var('selgroups');
if ($selusers == NULL)
$selusers = get_request_var("selected_users");
if ($selgroups == NULL)
$selgroups = get_request_var("selected_groups");
if ($selusers != NULL && count($selusers) > 0 && empty($selusers[0]))
{
$selusers = NULL;
}
if ($selgroups != NULL && count($selgroups) > 0 && empty($selgroups[0]))
{
$selgroups = NULL;
}
// Do it.
if( $selusers == NULL || $selgroups == NULL )
{
$appTemplate->addDefine("WARNING");
$appTemplate->addReplacement("WARNINGMSG",$appTR->tr("You have to select at least one user and one group."));
}
else
{
// Count of: All, Done, Failed
$cntAll = count($selgroups) * count($selusers);
$cntDone = 0;
$cntFailed = 0;
// Iterate all selected users and groups.
for( $i=0; $i<count($selgroups); $i++ )
{
$oG = new \svnadmin\core\entities\Group;
$oG->id = $selgroups[$i];
$oG->name = $selgroups[$i];
for( $j=0; $j<count($selusers); $j++ )
{
$oU = new \svnadmin\core\entities\User;
$oU->id = $selusers[$j];
$oU->name = $selusers[$j];
if( $appEngine->getGroupEditProvider()->assignUserToGroup( $oU, $oG ) )
{
$cntDone++;
}
else
{
$cntFailed++;
}
} //for
} //for
$appEngine->getGroupEditProvider()->save();
// Soo... what happens?
if( $cntDone == $cntAll )
{
// Everything has been made successfully.
$appTemplate->addDefine("INFO");
$appTemplate->addReplacement("INFOMSG",$appTR->tr("Done"));
}
else if( $cntFailed == $cntAll )
{
// Nothing has been done... a full fail! :(
$appTemplate->addDefine("ERROR");
$appTemplate->addReplacement("ERRORMSG",$appTR->tr("An unknown error occured. Check your configuration, please."));
}
else if( $cntFailed > 0 )
{
// Just a few assignments failed.
$appTemplate->addDefine("ERROR");
$appTemplate->addReplacement("ERRORMSG",$appTR->tr("Done"));
}
else
{
$appTemplate->addDefine("ERROR");
$appTemplate->addReplacement("ERRORMSG",$appTR->tr("An unknown error occured. Check your configuration, please."));
}
} //else
?>