2011-03-28 14:21:28 +00:00
< ?
/**************************************************************************/
/*-- Invite tree class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
***************************************************************************/
class INVITE_TREE {
var $UserID = 0 ;
var $Visible = true ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Set things up
2013-04-20 08:01:01 +00:00
function INVITE_TREE ( $UserID , $Options = array ()) {
2011-03-28 14:21:28 +00:00
$this -> UserID = $UserID ;
2013-04-20 08:01:01 +00:00
if ( $Options [ 'visible' ] === false ) {
2011-03-28 14:21:28 +00:00
$this -> Visible = false ;
}
}
2013-02-22 08:00:24 +00:00
2012-11-17 08:00:19 +00:00
function make_tree () {
2011-03-28 14:21:28 +00:00
$UserID = $this -> UserID ;
global $DB ;
?>
< div class = " invitetree pad " >
< ?
2012-11-17 08:00:19 +00:00
$DB -> query ( " SELECT TreePosition, TreeID, TreeLevel FROM invite_tree WHERE UserID= $UserID " );
list ( $TreePosition , $TreeID , $TreeLevel ) = $DB -> next_record ( MYSQLI_NUM , false );
if ( ! $TreeID ) {
return ;
}
2013-05-16 16:15:57 +00:00
$DB -> query ( "
SELECT TreePosition
FROM invite_tree
WHERE TreeID = $TreeID
AND TreeLevel = $TreeLevel
AND TreePosition > $TreePosition
ORDER BY TreePosition ASC
LIMIT 1 " );
2012-11-17 08:00:19 +00:00
if ( $DB -> record_count ()) {
list ( $MaxPosition ) = $DB -> next_record ( MYSQLI_NUM , false );
} else {
$MaxPosition = false ;
}
2013-05-16 16:15:57 +00:00
$TreeQuery = $DB -> query ( "
SELECT
it . UserID ,
Enabled ,
PermissionID ,
Donor ,
Uploaded ,
Downloaded ,
Paranoia ,
TreePosition ,
TreeLevel
2011-03-28 14:21:28 +00:00
FROM invite_tree AS it
2013-05-16 16:15:57 +00:00
JOIN users_main AS um ON um . ID = it . UserID
JOIN users_info AS ui ON ui . UserID = it . UserID
2011-03-28 14:21:28 +00:00
WHERE TreeID = $TreeID
2013-05-16 16:15:57 +00:00
AND TreePosition > $TreePosition " .
( $MaxPosition ? " AND TreePosition< $MaxPosition " : '' ) . "
AND TreeLevel > $TreeLevel
2011-03-28 14:21:28 +00:00
ORDER BY TreePosition " );
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$PreviousTreeLevel = $TreeLevel ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Stats for the summary
$MaxTreeLevel = $TreeLevel ; // The deepest level (this changes)
$OriginalTreeLevel = $TreeLevel ; // The level of the user we're viewing
$BaseTreeLevel = $TreeLevel + 1 ; // The level of users invited by our user
$Count = 0 ;
$Branches = 0 ;
$DisabledCount = 0 ;
$DonorCount = 0 ;
$ParanoidCount = 0 ;
$TotalUpload = 0 ;
$TotalDownload = 0 ;
$TopLevelUpload = 0 ;
$TopLevelDownload = 0 ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$ClassSummary = array ();
global $Classes ;
foreach ( $Classes as $ClassID => $Val ) {
$ClassSummary [ $ClassID ] = 0 ;
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// We store this in an output buffer, so we can show the summary at the top without having to loop through twice
ob_start ();
2013-04-20 08:01:01 +00:00
while ( list ( $ID , $Enabled , $Class , $Donor , $Uploaded , $Downloaded , $Paranoia , $TreePosition , $TreeLevel ) = $DB -> next_record ()) {
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Do stats
$Count ++ ;
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
if ( $TreeLevel > $MaxTreeLevel ) {
2011-03-28 14:21:28 +00:00
$MaxTreeLevel = $TreeLevel ;
}
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
if ( $TreeLevel == $BaseTreeLevel ) {
2011-03-28 14:21:28 +00:00
$Branches ++ ;
$TopLevelUpload += $Uploaded ;
$TopLevelDownload += $Downloaded ;
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$ClassSummary [ $Class ] ++ ;
2013-04-20 08:01:01 +00:00
if ( $Enabled == 2 ) {
2011-03-28 14:21:28 +00:00
$DisabledCount ++ ;
}
2013-04-20 08:01:01 +00:00
if ( $Donor ) {
2011-03-28 14:21:28 +00:00
$DonorCount ++ ;
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Manage tree depth
2013-04-20 08:01:01 +00:00
if ( $TreeLevel > $PreviousTreeLevel ) {
for ( $i = 0 ; $i < $TreeLevel - $PreviousTreeLevel ; $i ++ ) {
2013-05-16 16:15:57 +00:00
echo " <ul class= \" invitetree \" > \n \t <li> " ;
2013-04-20 08:01:01 +00:00
}
} elseif ( $TreeLevel < $PreviousTreeLevel ) {
for ( $i = 0 ; $i < $PreviousTreeLevel - $TreeLevel ; $i ++ ) {
2013-05-16 16:15:57 +00:00
echo " \t </li> \n </ul> " ;
2013-04-20 08:01:01 +00:00
}
2013-05-16 16:15:57 +00:00
echo " \t </li> \n <li> " ;
2012-09-29 08:00:21 +00:00
} else {
2013-05-16 16:15:57 +00:00
echo " \t </li> \n <li> " ;
2011-03-28 14:21:28 +00:00
}
?>
2013-05-16 16:15:57 +00:00
< strong >< ? = Users :: format_username ( $ID , true , true , ( $Enabled != 2 ? false : true ), true ) ?> </strong>
2011-03-28 14:21:28 +00:00
< ?
2013-04-20 08:01:01 +00:00
if ( check_paranoia ( array ( 'uploaded' , 'downloaded' ), $Paranoia , $UserClass )) {
2011-03-28 14:21:28 +00:00
$TotalUpload += $Uploaded ;
$TotalDownload += $Downloaded ;
?>
2012-10-11 08:00:15 +00:00
& nbsp ; Uploaded : < strong >< ? = Format :: get_size ( $Uploaded ) ?> </strong>
& nbsp ; Downloaded : < strong >< ? = Format :: get_size ( $Downloaded ) ?> </strong>
& nbsp ; Ratio : < strong >< ? = Format :: get_ratio_html ( $Uploaded , $Downloaded ) ?> </strong>
2011-03-28 14:21:28 +00:00
< ?
} else {
$ParanoidCount ++ ;
?>
& nbsp ; Paranoia : < strong >< ? = number_format ( $Paranoia ) ?> </strong>
< ?
}
2013-02-22 08:00:24 +00:00
?>
2012-09-29 08:00:21 +00:00
2011-03-28 14:21:28 +00:00
< ? $PreviousTreeLevel = $TreeLevel ;
2011-05-28 08:00:05 +00:00
$DB -> set_query_id ( $TreeQuery );
}
2012-09-29 08:00:21 +00:00
2011-03-28 14:21:28 +00:00
$Tree = ob_get_clean ();
2013-04-20 08:01:01 +00:00
for ( $i = 0 ; $i < $PreviousTreeLevel - $OriginalTreeLevel ; $i ++ ) {
2013-05-16 16:15:57 +00:00
$Tree .= " \t </li> \n </ul> \n " ;
2013-04-20 08:01:01 +00:00
}
2012-09-29 08:00:21 +00:00
2013-04-20 08:01:01 +00:00
if ( $Count ) {
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
?> <p style="font-weight: bold;">
2013-05-16 16:15:57 +00:00
This tree has < ? = number_format ( $Count ) ?> entries, <?=number_format($Branches)?> branches, and a depth of <?=number_format($MaxTreeLevel - $OriginalTreeLevel)?>.
2011-03-28 14:21:28 +00:00
It has
< ?
$ClassStrings = array ();
foreach ( $ClassSummary as $ClassID => $ClassCount ) {
2013-04-20 08:01:01 +00:00
if ( $ClassCount == 0 ) {
continue ;
}
2012-10-11 08:00:15 +00:00
$LastClass = Users :: make_class_string ( $ClassID );
2013-04-20 08:01:01 +00:00
if ( $ClassCount > 1 ) {
if ( $LastClass == 'Torrent Celebrity' ) {
2011-03-28 14:21:28 +00:00
$LastClass = 'Torrent Celebrities' ;
} else {
2013-02-22 08:00:24 +00:00
$LastClass .= 's' ;
2011-03-28 14:21:28 +00:00
}
}
2013-04-20 08:01:01 +00:00
$LastClass = $ClassCount . ' ' . $LastClass . ' (' . number_format (( $ClassCount / $Count ) * 100 ) . '%)' ;
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
$ClassStrings [] = $LastClass ;
2011-03-28 14:21:28 +00:00
}
2013-04-20 08:01:01 +00:00
if ( count ( $ClassStrings ) > 1 ) {
2011-03-28 14:21:28 +00:00
array_pop ( $ClassStrings );
echo implode ( ', ' , $ClassStrings );
echo ' and ' . $LastClass ;
} else {
echo $LastClass ;
}
echo '. ' ;
echo $DisabledCount ;
2013-04-20 08:01:01 +00:00
echo ( $DisabledCount == 1 ) ? ' user is' : ' users are' ;
2011-03-28 14:21:28 +00:00
echo ' disabled (' ;
2013-04-20 08:01:01 +00:00
if ( $DisabledCount == 0 ) {
echo '0%)' ;
} else {
echo number_format (( $DisabledCount / $Count ) * 100 ) . '%)' ;
}
2011-03-28 14:21:28 +00:00
echo ', and ' ;
echo $DonorCount ;
2013-04-20 08:01:01 +00:00
echo ( $DonorCount == 1 ) ? ' user has' : ' users have' ;
2011-03-28 14:21:28 +00:00
echo ' donated (' ;
2013-04-20 08:01:01 +00:00
if ( $DonorCount == 0 ) {
echo '0%)' ;
} else {
echo number_format (( $DonorCount / $Count ) * 100 ) . '%)' ;
}
2011-03-28 14:21:28 +00:00
echo '. </p>' ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
echo '<p style="font-weight: bold;">' ;
2012-10-11 08:00:15 +00:00
echo 'The total amount uploaded by the entire tree was ' . Format :: get_size ( $TotalUpload );
echo '; the total amount downloaded was ' . Format :: get_size ( $TotalDownload );
echo '; and the total ratio is ' . Format :: get_ratio_html ( $TotalUpload , $TotalDownload ) . '. ' ;
2011-03-28 14:21:28 +00:00
echo '</p>' ;
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
echo '<p style="font-weight: bold;">' ;
2012-10-11 08:00:15 +00:00
echo 'The total amount uploaded by direct invitees (the top level) was ' . Format :: get_size ( $TopLevelUpload );
echo '; the total amount downloaded was ' . Format :: get_size ( $TopLevelDownload );
echo '; and the total ratio is ' . Format :: get_ratio_html ( $TopLevelUpload , $TopLevelDownload ) . '. ' ;
2013-05-16 16:15:57 +00:00
2013-04-20 08:01:01 +00:00
echo 'These numbers include the stats of paranoid users and will be factored into the invitation giving script.</p>' ;
2013-05-16 16:15:57 +00:00
2013-04-20 08:01:01 +00:00
if ( $ParanoidCount ) {
2011-03-28 14:21:28 +00:00
echo '<p style="font-weight: bold;">' ;
echo $ParanoidCount ;
2013-04-20 08:01:01 +00:00
echo ( $ParanoidCount == 1 ) ? ' user (' : ' users (' ;
echo number_format (( $ParanoidCount / $Count ) * 100 );
2011-03-28 14:21:28 +00:00
echo '%) ' ;
2013-04-20 08:01:01 +00:00
echo ( $ParanoidCount == 1 ) ? ' is' : ' are' ;
2011-03-28 14:21:28 +00:00
echo ' too paranoid to have their stats shown here, and ' ;
2013-04-20 08:01:01 +00:00
echo ( $ParanoidCount == 1 ) ? ' was' : ' were' ;
2011-03-28 14:21:28 +00:00
echo ' not factored into the stats for the total tree.' ;
echo '</p>' ;
}
}
?>
< br />
< ? = $Tree ?>
</ div >
< ?
}
}
?>