2011-03-28 14:21:28 +00:00
< ?
/************************************************************************
||------------|| User email history page ||---------------------------||
This page lists previous email addresses a user has used on the site . It
gets called if $_GET [ 'action' ] == 'email' .
It also requires $_GET [ 'userid' ] in order to get the data for the correct
user .
************************************************************************/
$UserID = $_GET [ 'userid' ];
if ( ! is_number ( $UserID )) { error ( 404 ); }
2012-03-28 08:00:20 +00:00
$DB -> query ( " SELECT ui.JoinDate, p.Level AS Class FROM users_main AS um JOIN users_info AS ui ON um.ID=ui.UserID JOIN permissions AS p ON p.ID=um.PermissionID WHERE um.ID = $UserID " );
list ( $Joined , $Class ) = $DB -> next_record ();
2011-06-23 08:00:06 +00:00
if ( ! check_perms ( 'users_view_email' , $Class )) {
error ( 403 );
}
$UsersOnly = $_GET [ 'usersonly' ];
2011-03-28 14:21:28 +00:00
2012-03-29 08:00:19 +00:00
$DB -> query ( " SELECT Username FROM users_main WHERE ID = " . $UserID );
list ( $Username ) = $DB -> next_record ();
2012-10-11 08:00:15 +00:00
View :: show_header ( " Email history for $Username " );
2011-03-28 14:21:28 +00:00
// Get current email (and matches)
$DB -> query ( "
2013-02-12 08:00:08 +00:00
SELECT
2011-03-28 14:21:28 +00:00
m . Email ,
'".sqltime()."' AS Time ,
m . IP ,
GROUP_CONCAT ( h . UserID SEPARATOR '|' ) AS UserIDs ,
GROUP_CONCAT ( h . Time SEPARATOR '|' ) AS UserSetTimes ,
GROUP_CONCAT ( h . IP SEPARATOR '|' ) AS UserIPs ,
GROUP_CONCAT ( m2 . Username SEPARATOR '|' ) AS Usernames ,
2013-02-07 08:00:47 +00:00
GROUP_CONCAT ( m2 . Enabled SEPARATOR '|' ) AS UsersEnabled ,
2011-03-28 14:21:28 +00:00
GROUP_CONCAT ( i . Donor SEPARATOR '|' ) AS UsersDonor ,
GROUP_CONCAT ( i . Warned SEPARATOR '|' ) AS UsersWarned
FROM users_main AS m
LEFT JOIN users_history_emails AS h ON h . Email = m . Email AND h . UserID <> m . ID
LEFT JOIN users_main AS m2 ON m2 . ID = h . UserID
LEFT JOIN users_info AS i ON i . UserID = h . UserID
WHERE m . ID = '$UserID' "
);
$CurrentEmail = array_shift ( $DB -> to_array ());
// Get historic emails (and matches)
$DB -> query ( "
2013-02-12 08:00:08 +00:00
SELECT
h2 . Email ,
2011-03-28 14:21:28 +00:00
h2 . Time ,
h2 . IP ,
h3 . UserID AS UserIDs ,
h3 . Time AS UserSetTimes ,
h3 . IP AS UserIPs ,
m3 . Username AS Usernames ,
2013-02-07 08:00:47 +00:00
m3 . Enabled AS UsersEnabled ,
2011-03-28 14:21:28 +00:00
i2 . Donor AS UsersDonor ,
i2 . Warned AS UsersWarned
FROM users_history_emails AS h2
LEFT JOIN users_history_emails AS h3 ON h3 . Email = h2 . Email AND h3 . UserID <> h2 . UserID
LEFT JOIN users_main AS m3 ON m3 . ID = h3 . UserID
LEFT JOIN users_info AS i2 ON i2 . UserID = h3 . UserID
WHERE h2 . UserID = '$UserID'
ORDER BY Time DESC "
);
$History = $DB -> to_array ();
// Current email
$Current [ 'Email' ] = $CurrentEmail [ 'Email' ];
$Current [ 'StartTime' ] = $History [ 0 ][ 'Time' ];
$Current [ 'CurrentIP' ] = $CurrentEmail [ 'IP' ];
2011-08-12 21:42:06 +00:00
$Current [ 'IP' ] = $History [( count ( $History ) - 1 )][ 'IP' ];
2011-03-28 14:21:28 +00:00
// Matches for current email
if ( $CurrentEmail [ 'Usernames' ] != '' ) {
$UserIDs = explode ( '|' , $CurrentEmail [ 'UserIDs' ]);
$Usernames = explode ( '|' , $CurrentEmail [ 'Usernames' ]);
$UsersEnabled = explode ( '|' , $CurrentEmail [ 'UsersEnabled' ]);
$UsersDonor = explode ( '|' , $CurrentEmail [ 'UsersDonor' ]);
$UsersWarned = explode ( '|' , $CurrentEmail [ 'UsersWarned' ]);
$UserSetTimes = explode ( '|' , $CurrentEmail [ 'UserSetTimes' ]);
$UserIPs = explode ( '|' , $CurrentEmail [ 'UserIPs' ]);
foreach ( $UserIDs as $Key => $Val ) {
2012-10-11 08:00:15 +00:00
$CurrentMatches [ $Key ][ 'Username' ] = ' » ' . Users :: format_username ( $Val , true , true , true );
2011-03-28 14:21:28 +00:00
$CurrentMatches [ $Key ][ 'IP' ] = $UserIPs [ $Key ];
$CurrentMatches [ $Key ][ 'EndTime' ] = $UserSetTimes [ $Key ];
}
}
// Email history records
if ( count ( $History ) == 1 ) {
$Invite [ 'Email' ] = $History [ 0 ][ 'Email' ];
$Invite [ 'EndTime' ] = $Joined ;
$Invite [ 'AccountAge' ] = date ( time () + time () - strtotime ( $Joined )); // Same as EndTime but without ' ago'
$Invite [ 'IP' ] = $History [ 0 ][ 'IP' ];
if ( $Current [ 'StartTime' ] == '0000-00-00 00:00:00' ) { $Current [ 'StartTime' ] = $Joined ; }
} else {
foreach ( $History as $Key => $Val ) {
if ( $History [ $Key + 1 ][ 'Time' ] == '0000-00-00 00:00:00' && $Val [ 'Time' ] != '0000-00-00 00:00:00' ) {
// Invited email
$Invite [ 'Email' ] = $Val [ 'Email' ];
$Invite [ 'EndTime' ] = $Joined ;
$Invite [ 'AccountAge' ] = date ( time () + time () - strtotime ( $Joined )); // Same as EndTime but without ' ago'
$Invite [ 'IP' ] = $Val [ 'IP' ];
} elseif ( $History [ $Key - 1 ][ 'Email' ] != $Val [ 'Email' ] && $Val [ 'Time' ] != '0000-00-00 00:00:00' ) {
// Old email
$i = 1 ;
while ( $Val [ 'Email' ] == $History [ $Key + $i ][ 'Email' ]) {
$i ++ ;
}
$Old [ $Key ][ 'StartTime' ] = ( isset ( $History [ $Key + $i ]) && $History [ $Key + $i ][ 'Time' ] != '0000-00-00 00:00:00' ) ? $History [ $Key + $i ][ 'Time' ] : $Joined ;
$Old [ $Key ][ 'EndTime' ] = $Val [ 'Time' ];
$Old [ $Key ][ 'IP' ] = $Val [ 'IP' ];
$Old [ $Key ][ 'ElapsedTime' ] = date ( time () + strtotime ( $Old [ $Key ][ 'EndTime' ]) - strtotime ( $Old [ $Key ][ 'StartTime' ]));
2013-02-07 08:00:47 +00:00
$Old [ $Key ][ 'Email' ] = $Val [ 'Email' ];
2011-03-28 14:21:28 +00:00
} else {
// Shouldn't have to be here but I'll leave it anyway
$Other [ $Key ][ 'StartTime' ] = ( isset ( $History [ $Key + $i ])) ? $History [ $Key + $i ][ 'Time' ] : $Joined ;
$Other [ $Key ][ 'EndTime' ] = $Val [ 'Time' ];
$Other [ $Key ][ 'IP' ] = $Val [ 'IP' ];
$Other [ $Key ][ 'ElapsedTime' ] = date ( time () + strtotime ( $Other [ $Key ][ 'EndTime' ]) - strtotime ( $Other [ $Key ][ 'StartTime' ]));
2013-02-07 08:00:47 +00:00
$Other [ $Key ][ 'Email' ] = $Val [ 'Email' ];
2011-03-28 14:21:28 +00:00
}
if ( $Val [ 'Usernames' ] != '' ) {
// Match with old email
$OldMatches [ $Key ][ 'Email' ] = $Val [ 'Email' ];
2012-10-11 08:00:15 +00:00
$OldMatches [ $Key ][ 'Username' ] = ' » ' . Users :: format_username ( $Val [ 'UserIDs' ], true , true , true );
2011-03-28 14:21:28 +00:00
$OldMatches [ $Key ][ 'EndTime' ] = $Val [ 'UserSetTimes' ];
$OldMatches [ $Key ][ 'IP' ] = $Val [ 'UserIPs' ];
}
}
}
// Clean up arrays
if ( $Old ) {
$Old = array_reverse ( array_reverse ( $Old ));
$LastOld = count ( $Old ) - 1 ;
if ( $Old [ $LastOld ][ 'StartTime' ] != $Invite [ 'EndTime' ]) {
// Make sure the timeline is intact (invite email was used as email for the account in the beginning)
$Old [ $LastOld + 1 ][ 'Email' ] = $Invite [ 'Email' ];
$Old [ $LastOld + 1 ][ 'StartTime' ] = $Invite [ 'EndTime' ];
$Old [ $LastOld + 1 ][ 'EndTime' ] = $Old [ $LastOld ][ 'StartTime' ];
$Old [ $LastOld + 1 ][ 'ElapsedTime' ] = date ( time () + strtotime ( $Old [ $LastOld + 1 ][ 'EndTime' ] ) - strtotime ( $Old [ $LastOld + 1 ][ 'StartTime' ]));
$Old [ $LastOld + 1 ][ 'IP' ] = $Invite [ 'IP' ];
}
}
// Start page with current email
?>
< div class = " thin " >
2012-08-19 08:00:19 +00:00
< div class = " header " >
< h2 > Email history for < a href = " user.php?id=<?= $UserID ?> " >< ? = $Username ?> </a></h2>
2013-02-12 08:00:08 +00:00
< div class = " linkbox center " >
< a href = " userhistory.php?action=email&userid=<?= $UserID ?> " class = " brackets " > Old email history </ a >
2012-08-19 08:00:19 +00:00
</ div >
2011-03-28 14:21:28 +00:00
</ div >
< br />
< table width = " 100% " >
< tr class = " colhead " >
< td > Current email </ td >
< td > Start </ td >
< td > End </ td >
2013-02-09 08:01:01 +00:00
< td > Current IP < a href = " userhistory.php?action=ips&userid=<?= $UserID ?> " class = " brackets " > H </ a ></ td >
2011-03-28 14:21:28 +00:00
< td > Set from IP </ td >
</ tr >
< tr class = " rowa " >
< td >< ? = display_str ( $Current [ 'Email' ]) ?> </td>
< td >< ? = time_diff ( $Current [ 'StartTime' ]) ?> </td>
< td ></ td >
< td >
2013-02-09 08:01:01 +00:00
< ? = display_str ( $Current [ 'CurrentIP' ]) ?> (<?=Tools::get_country_code_by_ajax($Current['CurrentIP'])?>) <a href="user.php?action=search&ip_history=on&ip=<?=display_str($Current['CurrentIP'])?>" class="brackets" title="Search">S</a> <a href="http://whatismyipaddress.com/ip/<?=display_str($Current['CurrentIP'])?>" class="brackets" title="Search WIMIA.com">WI</a><br />
2012-10-11 08:00:15 +00:00
< ? = Tools :: get_host_by_ajax ( $Current [ 'CurrentIP' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
< td >
2013-02-09 08:01:01 +00:00
< ? = display_str ( $Current [ 'IP' ]) ?> (<?=Tools::get_country_code_by_ajax($Current['IP'])?>) <a href="user.php?action=search&ip_history=on&ip=<?=display_str($Current['IP'])?>" class="brackets" title="Search">S</a> <a href="http://whatismyipaddress.com/ip/<?=display_str($Current['IP'])?>" class="brackets" title="Search WIMIA.com">WI</a><br />
2012-10-11 08:00:15 +00:00
< ? = Tools :: get_host_by_ajax ( $Current [ 'IP' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
</ tr >
< ?
if ( $CurrentMatches ) {
// Match on the current email
2013-02-12 08:00:08 +00:00
foreach ( $CurrentMatches as $Match ) {
2011-03-28 14:21:28 +00:00
?>
< tr class = " rowb " >
< td >< ? = $Match [ 'Username' ] ?> </td>
< td ></ td >
< td >< ? = time_diff ( $Match [ 'EndTime' ]) ?> </td>
< td ></ td >
< td >
2013-02-09 08:01:01 +00:00
< ? = display_str ( $Match [ 'IP' ]) ?> (<?=Tools::get_country_code_by_ajax($Match['IP'])?>) <a href="user.php?action=search&ip_history=on&ip=<?=display_str($Match['IP'])?>" class="brackets" title="Search">S</a> <a href="http://whatismyipaddress.com/ip/<?=display_str($Match['IP'])?>" class="brackets" title="Search WIMIA.com">WI</a><br />
2012-10-11 08:00:15 +00:00
< ? = Tools :: get_host_by_ajax ( $Match [ 'IP' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
2013-02-12 08:00:08 +00:00
</ tr >
< ?
2011-03-28 14:21:28 +00:00
}
}
// Old emails
if ( $Old ) {
?>
< tr class = " colhead " >
< td > Old emails </ td >
< td > Start </ td >
< td > End </ td >
< td > Elapsed </ td >
< td > Set from IP </ td >
</ tr >
< ?
$j = 0 ;
// Old email
2013-02-12 08:00:08 +00:00
foreach ( $Old as $Record ) {
2011-03-28 14:21:28 +00:00
++ $j ;
// Matches on old email
ob_start ();
$i = 0 ;
foreach ( $OldMatches as $Match ) {
if ( $Match [ 'Email' ] == $Record [ 'Email' ]) {
++ $i ;
// Email matches
?>
< tr class = " rowb hidden " id = " matches_<?= $j ?> " >
< td >< ? = $Match [ 'Username' ] ?> </td>
< td ></ td >
< td >< ? = time_diff ( $Match [ 'EndTime' ]) ?> </td>
< td ></ td >
< td >
2013-02-09 08:01:01 +00:00
< ? = display_str ( $Match [ 'IP' ]) ?> (<?=Tools::get_country_code_by_ajax($Match['IP'])?>) <a href="user.php?action=search&ip_history=on&ip=<?=display_str($Match['IP'])?>" class="brackets" title="Search">S</a> <a href="http://whatismyipaddress.com/ip/<?=display_str($Match['IP'])?>" class="brackets" title="Search WIMIA.com">WI</a><br />
2012-10-11 08:00:15 +00:00
< ? = Tools :: get_host_by_ajax ( $Match [ 'IP' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
2013-02-12 08:00:08 +00:00
</ tr >
< ?
2011-03-28 14:21:28 +00:00
}
}
// Save matches to variable
$MatchCount = $i ;
$Matches = ob_get_contents ();
ob_end_clean ();
?>
< tr class = " rowa " >
2012-09-09 08:00:26 +00:00
< td >< ? = display_str ( $Record [ 'Email' ]) ?> <?=(($MatchCount > 0) ? ' <a href="#" onclick="$(\'#matches_'.$j.'\').toggle();return false;">('.$MatchCount.')</a>' : '')?></td>
2011-03-28 14:21:28 +00:00
< td >< ? = time_diff ( $Record [ 'StartTime' ]) ?> </td>
< td >< ? = time_diff ( $Record [ 'EndTime' ]) ?> </td>
< td >< ? = time_diff ( $Record [ 'ElapsedTime' ]) ?> </td>
< td >
2013-02-09 08:01:01 +00:00
< ? = display_str ( $Record [ 'IP' ]) ?> (<?=Tools::get_country_code_by_ajax($Record['IP'])?>) <a href="user.php?action=search&ip_history=on&ip=<?=display_str($Record['IP'])?>" class="brackets" title="Search">S</a> <a href="http://whatismyipaddress.com/ip/<?=display_str($Record['IP'])?>" class="brackets" title="Search WIMIA.com">WI</a><br />
2012-10-11 08:00:15 +00:00
< ? = Tools :: get_host_by_ajax ( $Record [ 'IP' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
2013-02-12 08:00:08 +00:00
</ tr >
< ?
2011-03-28 14:21:28 +00:00
if ( $MatchCount > 0 ) {
2013-02-12 08:00:08 +00:00
if ( isset ( $Matches )) {
2011-03-28 14:21:28 +00:00
echo $Matches ;
unset ( $Matches );
unset ( $MatchCount );
}
}
}
}
// Invite email (always there)
?>
< tr class = " colhead " >
< td > Invite email </ td >
< td > Start </ td >
< td > End </ td >
< td > Age of account </ td >
< td > Signup IP </ td >
</ tr >
< ?
// Matches on invite email
if ( $OldMatches ) {
$i = 0 ;
ob_start ();
foreach ( $OldMatches as $Match ) {
if ( $Match [ 'Email' ] == $Invite [ 'Email' ]) {
++ $i ;
// Match email is the same as the invite email
?>
< tr class = " rowb hidden " id = " matches_invite " >
< td >< ? = $Match [ 'Username' ] ?> </td>
< td ></ td >
< td >< ? = time_diff ( $Match [ 'EndTime' ]) ?> </td>
< td ></ td >
< td >
2013-02-09 08:01:01 +00:00
< ? = display_str ( $Match [ 'IP' ]) ?> (<?=Tools::get_country_code_by_ajax($Match['IP'])?>) <a href="user.php?action=search&ip_history=on&ip=<?=display_str($Match['IP'])?>" class="brackets" title="Search">S</a> <a href="http://whatismyipaddress.com/ip/<?=display_str($Match['IP'])?>" class="brackets" title="Search WIMIA.com">WI</a><br />
2012-10-11 08:00:15 +00:00
< ? = Tools :: get_host_by_ajax ( $Match [ 'IP' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
2013-02-12 08:00:08 +00:00
</ tr >
2011-03-28 14:21:28 +00:00
< ?
}
}
$MatchCount = $i ;
$Matches = ob_get_contents ();
ob_end_clean ();
}
?>
< tr class = " rowa " >
2012-09-09 08:00:26 +00:00
< td >< ? = display_str ( $Invite [ 'Email' ]) ?> <?=(($MatchCount > 0) ? ' <a href="#" onclick="$(\'#matches_invite\').toggle();return false;">('.$MatchCount.')</a>' : '')?></td>
2011-03-28 14:21:28 +00:00
< td > Never </ td >
< td >< ? = time_diff ( $Invite [ 'EndTime' ]) ?> </td>
< td >< ? = time_diff ( $Invite [ 'AccountAge' ]) ?> </td>
< td >
2013-02-09 08:01:01 +00:00
< ? = display_str ( $Invite [ 'IP' ]) ?> (<?=Tools::get_country_code_by_ajax($Invite['IP'])?>) <a href="user.php?action=search&ip_history=on&ip=<?=display_str($Invite['IP'])?>" class="brackets" title="Search">S</a> <a href="http://whatismyipaddress.com/ip/<?=display_str($Invite['IP'])?>" class="brackets" title="Search WIMIA.com">WI</a><br />
2012-10-11 08:00:15 +00:00
< ? = Tools :: get_host_by_ajax ( $Invite [ 'IP' ]) ?>
2011-03-28 14:21:28 +00:00
</ td >
</ tr >
< ?
if ( $Matches ) {
echo $Matches ;
}
2013-02-12 08:00:08 +00:00
?>
2011-03-28 14:21:28 +00:00
</ table >
</ div >
2012-10-11 08:00:15 +00:00
< ? View :: show_footer (); ?>