<?php
require_once("../rtf/Rtf.php");

//////////////
//Font formats
$font1 = new Font(11'Times new Roman''#000055');

//////////////
//Paragraph formats
$parFC = new ParFormat('center');

$parFL = new ParFormat('left');

//////////////
//Rtf document
$rtf = new Rtf();
$null null;
//section
$sect = &$rtf->addSection();

$sect->writeText('Chess tournamet information (write your data)
'
, new Font(14'Arial'), new ParFormat());

$chessPlayers = array('Mike Smith''Jim Morgan''Jochgan Berg''Bill Scott''Bill Martines''John Po''Aleck Harrison''Ann Scott''Johnatan Fredericson''Eva Carter');

/*$chessResults = (array(
                array(0  , 1  , 0.5, 1  , 0  , 1  , 0  , 0.5  , 1  , 1  ),
                array(0, 0, 0.5, 0.5, 0, 0, 0, 0, 0, 1),
                array(0.5, 1, 0, 1, 0.5, 1, 0.5, 0, 0, 1),
                array(0, 0.5, 0.5, 0, 0, 0.5, 0.5, 0, 0, 1),                


                array(1, 0.5, 1, 0, 0, 0.5, 0.5, 0, 0, 1),            

));*/

$count count($chessPlayers);
$countCols $count 2;
$countRows $count 1;

$colWidth = ($sect->getLayoutWidth() - 5) / $count;

//table creating and rows ands columns adding
$table = &$sect->addTable();
$table->addRows(12);
$table->addRows($count, -0.6);

$table->addColumn(3);
for (
$i 1$i <= count($chessPlayers); $i ++) {    
    
$table->addColumn($colWidth);
}
$table->addColumn(2);

//borders
$table->setBordersOfCells(new BorderFormat(1'#555555'), 11$countRows$countCols);

//top row
$table->rotateCells('right'121$countCols 1);
$table->setVerticalAlignmentOfCells('center'121$countCols);

$i 2;
foreach (
$chessPlayers as $player) {  
      
$table->writeToCell(1$i$player$font1$null);      
      
$table->writeToCell($i1$player$font1, new ParFormat(), $null);      
      
$table->setBordersOfCells(new BorderFormat(1'#0000ff'), $i$i);
      
$table->setBackgroundOfCells('#dddddd'$i$i);          
      
$i ++;
}

//tournament result
/*$i = 1;
foreach ($chessResults as $playerResult) {  
      $j = 1; 
      $sum = 0;
      foreach ($playerResult as $result)  {
            if ($i != $j) {
            $table->writeToCell($i + 1, $j + 1, $result, new Font(11, 'Times new Roman', '#7A2900'), new ParFormat('center'));          
            $sum += $result;        
        }
        $j ++;        
    }
    $table->writeToCell($i + 1, $j + 1, '<b>'.$sum.'</b>', new Font(11, 'Times new Roman', '#7A2900'), new ParFormat('center'));  
    $i ++;
}*/

$fontBold = new Font(11'Times new Roman''#7A2900');
$fontBold->setBold();

$table->setDefaultAlignmentOfCells('center'22$countRows$countCols);
$table->setDefaultFontOfCells(new Font(11'Times new Roman''#7A2900'), 22$countRows$countCols 1);
$table->setDefaultFontOfCells($fontBold2$countCols$countRows);

$table->writeToCell(1$countCols'TOTAL'$font1, new ParFormat('center'));

$table->setBordersOfCells(new BorderFormat(1.5'#000000'), $countCols$countRows$countCols);
$table->setBordersOfCells(new BorderFormat(1'#0000ff''dash'), 2$countCols$countRows 1$countCols0001);

$sect->writeText('Chess tournamet play-offs (write your data)
'
, new Font(14'Arial'), new ParFormat());


$count 8;
$rows 16;


$countSmall 5;
$countLarge 6;

$smallWidth '0.75';
$bigWidth = ($sect->getLayoutWidth() - $countSmall $smallWidth) / $countLarge;

$table = &$sect->addTable();
$table->addRows(16, -0.5);
$table->addColumnsList(array($smallWidth$bigWidth$bigWidth$smallWidth$smallWidth$bigWidth$bigWidth$smallWidth$smallWidth$bigWidth$bigWidth));

$table->setDefaultAlignmentOfCells('center'111611);
$table->setDefaultFontOfCells(new Font(11'Times new Roman''#7A2900'), 111611);


$table->setBordersOfCells(new BorderFormat(1), 2133);
$table->setBordersOfCells(new BorderFormat(1), 6173);
$table->setBordersOfCells(new BorderFormat(1), 101113);
$table->setBordersOfCells(new BorderFormat(1), 141153);

$table->setBordersOfCells(new BorderFormat(1), 4557);
$table->setBordersOfCells(new BorderFormat(1), 125137);

$table->setBordersOfCells(new BorderFormat(1), 89911);
$table->setBordersOfCells(new BorderFormat(1), 1491511);

$table->setBordersOfCells(new BorderFormat(1), 110311);

$table->writeToCell(21'P1'$font1$null);
$table->writeToCell(31'P8'$font1$null);
$table->writeToCell(61'P2'$font1$null);
$table->writeToCell(71'P7'$font1$null);
$table->writeToCell(101'P3'$font1$null);
$table->writeToCell(111'P6'$font1$null);
$table->writeToCell(141'P4'$font1$null);
$table->writeToCell(151'P5'$font1$null);

$table->writeToCell(11'A1'$font1$null);
$table->writeToCell(51'A2'$font1$null);
$table->writeToCell(91'A3'$font1$null);
$table->writeToCell(131'A4'$font1$null);

$table->writeToCell(35'B1'$font1$null);
$table->writeToCell(45'A1'$font1$null);
$table->writeToCell(55'A2'$font1$null);

$table->writeToCell(115'B2'$font1$null);
$table->writeToCell(125'A3'$font1$null);
$table->writeToCell(135'A4'$font1$null);

$table->writeToCell(710'1-st place'$font1$null);
$table->writeToCell(89'B1'$font1$null);
$table->writeToCell(99'B2'$font1$null);

$table->writeToCell(1310'3-d place'$font1$null);
$table->writeToCell(149'B1'$font1$null);
$table->writeToCell(159'B2'$font1$null);


$table->setBackgroundOfCells('#ffff88'110111);
$table->setBackgroundOfCells('#cccccc'210211);
$table->setBackgroundOfCells('#ffAA66'310311);


$table->writeToCell(110'1-st place'$font1$null);
$table->writeToCell(210'2-st place'$font1$null);
$table->writeToCell(310'3-d place'$font1$null);

$rtf->sendRtf();

?>