<?php
require('../fpdf16/fpdf.php');
session_start();
include("conexion.php");



class PDF extends FPDF
{





//Simple table
function BasicTable($header,$data)
{

    //Header
    foreach($header as $col)
        $this->Cell(80,7,$col,1);
    $this->Ln();
    //Data
	
    foreach($data as $row)
    {
        foreach($row as $col)
            $this->Cell(80,6,$col,1);
        $this->Ln();
    }
}

//Simple table
function BasicTable2($header,$data)
{

    //Header
    foreach($header as $col)
        $this->Cell(50,7,$col,1);
    $this->Ln();
    //Data
	
    foreach($data as $row)
    {
        foreach($row as $col)
            $this->Cell(50,6,$col,1);
        $this->Ln();
    }
}


}

$pdf=new PDF();
$data1 = array();
$data = array();
$datauser = array();
$userlogin = $_SESSION['login'];
$query = "SELECT * FROM User WHERE login = '".$userlogin."'";
$answeruser = mysql_query($query);
$rowuser = mysql_fetch_array($answeruser);
	array_push($data1, 'Login: '.$rowuser["login"]);
	array_push($datauser, $data1);
	$data1 = array();
	array_push($data1, 'Name: '.$rowuser["name"]);
	array_push($datauser, $data1);
	$data1 = array();
	array_push($data1, 'Address: '.$rowuser["address"]);
	array_push($datauser, $data1);
	$data1 = array();
	array_push($data1, 'Cash: '.$rowuser["cash"]);
	array_push($datauser, $data1);
	$data1 = array();

$iduser = $rowuser["id"];

$query = "SELECT * FROM Ownership, Stock WHERE user = ".$iduser." AND Stock.id = Ownership.stock";
$answerstocks = mysql_query($query);
while($rowstocks = mysql_fetch_array($answerstocks)){
	array_push($data1, $rowstocks["ticker"]);
	array_push($data1, $rowstocks["volume"]);
	array_push($data1, $rowstocks["price"]);
	array_push($data, $data1);
	$data1 = array();
}



$pdf->SetFont('Arial','',14);
$pdf->AddPage();
//Table of the information of the user
//Column's name
$header=array('Information of the user');
$pdf->BasicTable($header,$datauser);
//blank space
$pdf->Ln(4);

//Table of the Stocks
//Columns's name
$header2=array('Ticker','Volume','Price');
$pdf->BasicTable2($header2,$data);


$pdf->Output();
?>