##############################################################
## MOD Title: donor mod
## MOD Author: cr2sh
## : XANDER-CAGE
##
## Installation Level: (Easy)
## Installation Time: ~5 Minutes
##
## Files To Edit:
##	- page_header.tpl
##	- includes/usercp_viewprofile.php
##	- templates/default/usercp_viewprofile.tpl
##
##############################################################

# 
#-----[ SQL QUERY ]---------------------------------
# 
CREATE TABLE `donor_rules` (
`donor_group` INT NOT NULL ,
`donator_group` INT NOT NULL ,
`ratio` FLOAT NOT NULL ,
PRIMARY KEY ( `donor_group` )
);
 INSERT INTO `donor_rules` ( `donor_group` , `donator_group` , `ratio` )
VALUES (
'0', '0', '0.7'
); 
CREATE TABLE `donor` (
`donor_id` INT NOT NULL ,
`donator_id` INT NOT NULL ,
`data` TIMESTAMP NOT NULL ,
`upload` BIGINT NOT NULL ,
INDEX ( `donor_id` )
);

# 
#-----[ OPEN ]---------------------------------
# 
templates/default/page_header.tpl

# 
#-----[ FIND ]---------------------------------
#
<a href="{U_MEMBERLIST}"><b>{L_MEMBERLIST}</b></a>

# 
#-----[ AFTER, ADD / ,  ]---------------------------------
#
<!-- IF LOGGED_IN --><a href="donor.php"><b></b></a><!-- ENDIF -->

# 
#-----[ OPEN ]---------------------------------
# 
includes/usercp_viewprofile.php

# 
#-----[ FIND ]---------------------------------
#
print_page('usercp_viewprofile.tpl'); 

# 
#-----[ BEFORE, ADD /   ]---------------------------------
#

$id=$profiledata['user_id'];
$name=$profiledata['username'];
$gb = 1073741824;
$table = "";
$sql = "SELECT u.username, d.donator_id, d.data, d.upload
	FROM      donor d   
	LEFT JOIN ". BB_USERS     ." u ON(u.user_id  = d.donator_id)
	WHERE d.donor_id  = $id ORDER BY d.data DESC
	"; 
  $result = DB()->sql_query($sql);
  $row = DB()->sql_fetchrow($result);
if (isset($row['upload']))
{
$table = "<table class='forumline forum'>
<col class='row1' width='33.3%'>
<col class='row2' width='33.3%'>
<col class='row3' width='33.3%'>
<tr>
  <th colspan='3'> ,  ".$name."  :</th>
</tr>";
do
  {
$table .= "
  <tr>
    <td align='center'><a href=".PROFILE_URL.$row['donator_id'].">".$row['username']."</td>
    <td align='center'><span style='color:#800000'>".round($row['upload']/$gb,0)." </span></td>
    <td align='center'>".date("d-M-Y  H:i:s",strtotime($row['data']))."</td>
  </tr>
";
  }
while ($row = mysql_fetch_array ($result)); 
$table = $table."</table>";
}
$template->assign_vars(array(
'TABLE'                => $table                     
)); 
$table = '';
$sql = "SELECT u.username, d.donor_id, d.data, d.upload
	FROM      donor d   
	LEFT JOIN ". BB_USERS      ." u ON(u.user_id  = d.donor_id)
	WHERE d.donator_id  = $id ORDER BY d.data DESC
	"; 
	$result = DB()->sql_query($sql);
	$row = DB()->sql_fetchrow($result);
if (isset($row['upload']))
{
$table = "<table class='forumline forum'>
<col class='row1' width='33.3%'>
<col class='row2' width='33.3%'>
<col class='row3' width='33.3%'>
<tr>
  <th colspan='3'> ,  ".$name."  :</th>
</tr>";
do 
	{
$table .= "
  <tr>
    <td align='center'><a href=".PROFILE_URL.$row['donor_id'].">".$row['username']."</td>
    <td align='center'><span style='color:#090'>".round($row['upload']/$gb,0)." </span></td>
    <td align='center'>".date("d-M-Y  H:i:s",strtotime($row['data']))."</td>
  </tr>
";
	}
while ($row = mysql_fetch_array ($result));	
$table.='</table>';
}
$template->assign_vars(array(
'TABLE2'	        			 => $table
));

# 
#-----[ OPEN ]---------------------------------
# 
templates/default/usercp_viewprofile.tpl

# 
#-----[ FIND ]---------------------------------
#
<!--bottom_info--> 

# 
#-----[ BEFORE, ADD /   ]---------------------------------
#
{TABLE} 
{TABLE2} 

#
#-----[ SAVE/CLOSE ALL FILES ]---------------------------------
#
# EoM