0)
{
$grouplimit++;
$adders--;
}
for ($counter = 0; $counter < $linecount; $counter++)
{
if ( $membercounter == 0 )
{
$return[$groupcounter] = array();
}
$return[$groupcounter][$membercounter]
= $linearray[$counter];
$membercounter++;
if ( $membercounter == $grouplimit )
{
if ( $sortresult )
{
sort ( $return[$groupcounter] );
}
$groupcounter++;
$membercounter = 0;
$grouplimit = $basegroup;
if ($adders > 0)
{
$grouplimit++;
$adders--;
}
}
}
}
return $return;
}
else
{
return array();
}
}
function groups2string ( $groups,
$groupseparator = "\n", $memberseparator = "\t" )
{
$return = '';
if ( count( $groups ) > 0 )
{
foreach ( $groups as $group )
{
if ( count($group) > 0 )
{
foreach ( $group as $member )
{
$return .= $member . $memberseparator;
}
$return = substr( $return, 0, -1 );
}
$return .= $groupseparator;
}
$return = substr( $return, 0, -1 );
}
return $return;
}
function string2groups ( $string,
$groupseparator = "\n", $memberseparator = "\t" )
{
$return = array();
$groups = explode ( $groupseparator, $string );
foreach ( $groups as $groupstring )
{
$return[] = explode ( $memberseparator, $groupstring );
}
return $return;
}
function puzzleunique ( $groups )
{
$subgroupsize = 0;
$unique = true;
foreach ( $groups as $group ) {
if ( $subgroupsize )
{
if ( count ( $group ) != $subgroupsize )
{
$unique = false;
}
}
else
{
$subgroupsize = count( $group );
}
}
return $unique;
}
function number( $number, $mode )
{
switch ( $mode )
{
case 1:
return ( chr ( $number + 65 ) );
break;
default:
return ($number + 1);
}
}
function echogroups ( $grouptitle, $groups, $mode = 0, $drawone=false,
$divclass='group', $ulclass='group', $tabs = 1 )
{
$counter = 0;
foreach ( $groups as $group )
{
echo ( str_repeat ( "\t", $tabs )
. '
' . "\n");
$tabs++;
echo(str_repeat ( "\t", $tabs )
. '
' . $grouptitle . number($counter, $mode) . '
' . "\n");
echo(str_repeat ( "\t", $tabs )
. '
' . "\n");
$tabs++;
$membercounter = 0;
$theone = 0;
if ( $drawone !== false )
{
if ( is_array($drawone) )
{
$theone = $drawone[ $counter ];
}
else
{
$theone = rand(1, count($group));
}
}
foreach ( $group as $member )
{
$membercounter++;
echo(str_repeat ( "\t", $tabs ) );
if ($theone == $membercounter)
{
echo( '' );
}
echo( '- ' );
echo( trim ( $member ) );
echo( '
' );
if ($theone == $membercounter)
{
echo( '' );
}
echo( "\n" );
}
$tabs--;
echo(str_repeat ( "\t", $tabs ) . '
' . "\n");
$tabs--;
echo (str_repeat ( "\t", $tabs ) . '
' . "\n");
$counter++;
}
}
function grouppuzzler ( $groups, $sizeaim, $signmode = 1, $sm2arr = 0 )
{
$groupcounter = 0;
$membercounter = 0;
$orgin = 0;
$return = array();
foreach ( $groups as $group )
{
foreach ( $group as $member )
{
if ( ! ($membercounter % $sizeaim) )
{
$groupcounter=0;
}
switch ( $signmode )
{
case 1:
$return [$groupcounter][] = '[' . ($orgin+1) . '] ' . $member;
break;
case 2:
if ( in_array($member, $sm2arr) )
{
$return [$groupcounter][]
= '' . $member . '';
}
else
{
$return [$groupcounter][] = $member;
}
break;
default:
$return [$groupcounter][] = $member;
}
$groupcounter++;
$membercounter++;
}
$orgin++;
}
return $return;
}
function isgivendata( $lines, $title, $grouptitle )
{
// if lines start with title or group title,
// then it appears to be given data
return
( substr($lines, 0, strlen($title)) == $title ) ||
( substr($lines, 0, strlen($grouptitle)) == $grouptitle );
}
function extractgivendatagroups( $lines, $title, $grouptitle, $downloadme )
{
$group = array();
// remove title, if lines start with it
if ( substr($lines, 0, strlen($title)) == $title )
{
$lines = substr( $lines, strlen($title), strlen($lines) - strlen($title) );
$lines = trim( $lines );
}
// remove $downloadme, ist lines end with it
if (
substr(
$lines,
strlen($lines) - strlen($downloadme),
strlen($downloadme)
) == $downloadme
)
{
$lines = substr( $lines, 0, strlen($lines) - strlen($downloadme) );
$lines = trim( $lines );
}
// now split the array along the group title
$parts = explode($grouptitle, $lines);
$counter = 1;
foreach ($parts as $part)
{
if ( $part )
{
if ( substr($part, 0, strlen($counter)) == $counter )
{
$part = substr($part, strlen($counter),
strlen($part)-strlen($counter));
}
$counter++;
$part = trim ($part);
$members = explode("\n", $part);
$group[] = $members;
}
}
return $group;
}
// Setting default values and deal with superglobals...
$state = 0;
if (@$_POST['state'])
{
$state = $_POST['state'];
}
$sizeaim = 0;
$lines = '';
if (@$_POST['lines'])
{
$lines = $_POST['lines'];
$lines = htmlentities($lines);
if ($state == 1 || $state == 4)
{
setcookie('gruppenmixer', base64_encode(trim($lines)),
time() + 365*24*3600);
}
if (@$_POST['clearcookie']) {
setcookie('gruppenmixer', "", time() - 1);
$cleared = true;
}
}
else
{
if (@$_POST['clearcookie']) {
setcookie('gruppenmixer', "", time() - 1);
$lines = $linesdefault;
$cleared = true;
}
else
{
if (@$_COOKIE['gruppenmixer'])
{
$lines = base64_decode($_COOKIE['gruppenmixer']);
}
else
{
$lines = $linesdefault;
}
}
}
if (@$_POST['parts'])
{
$partsaim = $_POST['parts'];
}
if (!$lines) {
$state = 0;
}
else if ( $state == 5 )
{
if ( @$_POST['circle'] )
{
$circle = $_POST['circle'];
if ( count( $circle ) == @$circle[ count( $circle ) - 1 ] )
{
$state = 1;
if ( @$_POST['mustdecode'] )
{
$lines = base64_decode ( $lines );
}
}
}
else
{
$state = 1;
if ( @$_POST['mustdecode'] )
{
$lines = base64_decode ( $lines );
}
}
}
// Now start output,
// but the main state switch will still be coming
// and also some state-dependent processing
// will be scattered around there...
?>