Hello
I'm not a php coder, but I worked the Next Actions booklet's code to make it work on gtd-php 0.9.
Basically I only modified the database prefix variable and changed the mysql query to the new database structure. It worked for me.
I had to rename the file to actionBooklet.inc.php and create the setup.inc.php, of course.
Here is how the code is looking now:
for the setup.inc.php file:
<?php
$events[_GTD_ON_MENU]['*']=array(
'link' => "actionBooklet.inc.php",
'title' => 'Action Booklet',
'label' => 'ActionBooklet',
'where' => 'listItems.php?type=m',
'when' => 'after',
'options'=> array('fpdf'=>'../fpdf/')
);
for the actionBooklet.inc.php file:
<?php
require('../fpdf/fpdf.php');
require('headerDB.inc.php');
define('FPDF_FONTPATH','../fpdf/font/');
class PDF extends FPDF
{
var $angle=0;
var $projects;
var $records;
var $currentRecord=0;
var $currentContext;
var $currentProject;
var $margin=.635;
function Rotate($angle,$x=-1,$y=-1)
{
if($x==-1)
$x=$this->x;
if($y==-1)
$y=$this->y;
if($this->angle!=0)
$this->_out('Q');
$this->angle=$angle;
if($angle!=0)
{
$angle*=M_PI/180;
$c=cos($angle);
$s=sin($angle);
$cx=$x*$this->k;
$cy=($this->h-$y)*$this->k;
$this->_out(
sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',
$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
}
}
function _endpage()
{
if($this->angle!=0)
{
$this->angle=0;
$this->_out('Q');
}
parent::_endpage();
}
function RotatedText($x,$y,$txt,$angle)
{
//Text rotated around its origin
$this->Rotate($angle,$x,$y);
$this->Text($x,$y,$txt);
$this->Rotate(0);
}
function RotatedImage($file,$x,$y,$w,$h,$angle)
{
//Image rotated around its upper-left corner
$this->Rotate($angle,$x,$y);
$this->Image($file,$x,$y,$w,$h);
$this->Rotate(0);
}
function PrintContext($x,$y,$name,$angle)
{
$this->SetFont('Arial','B','10');
$this->RotatedText($x,$y,$name,$angle);
$this->SetFont('Arial','',8);
}
function PrintProject($x,$y,$name,$angle)
{
$this->SetFont('Arial','BU','8');
$this->RotatedText($x,$y,$name,$angle);
$this->SetFont('Arial','',8);
}
function PrintNextAction($x,$y,$name,$angle)
{
$this->SetFont('Arial','','8');
$this->RotatedText($x,$y,$name."*",$angle);
$this->SetFont('Arial','',8);
}
function PrintPageNumber($x,$y,$number,$angle)
{
$this->SetFont('Arial','','6');
$this->RotatedText($x,$y,$number,$angle);
$this->SetFont('Arial','',8);
}
function PrintPage1() {
$y = 6.985 + $this->margin;
if ( $this->currentRecord < count($this->records) ) {
$this->PrintRows($y,true);
} else {
$this->PrintNotes($y,true);
}
// Add page number
$this->PrintPageNumber($this->margin,$y,"1",270);
// Add timestamp
$this->SetFont('Arial','I','6');
$this->RotatedText($this->margin,8,"as of ".date("r"),270);
$this->SetFont('Arial','','8');
}
function PrintPage2()
{
$y = 13.97 + $this->margin;
if ( $this->currentRecord < count($this->records) ) {
$this->PrintRows($y,true);
} else {
$this->PrintNotes($y,true);
}
// Add page number
$this->PrintPageNumber($this->margin,$y,"2",270);
}
function PrintPage3()
{
$y = 20.955 + $this->margin;
if ( $this->currentRecord < count($this->records) ) {
$this->PrintRows($y,true);
} else {
$this->PrintNotes($y,true);
}
// Add page number
$this->PrintPageNumber($this->margin,$y,"3",270);
}
function PrintPage4()
{
$y = 27.305 - $this->margin;
if ( $this->currentRecord < count($this->records) ) {
$this->PrintRows($y,false);
} else {
$this->PrintNotes($y,false);
}
// Add page number
$this->PrintPageNumber(20.955,$y,"4",90);
}
function PrintPage5()
{
$y =20.955 - $this->margin;
if ( $this->currentRecord < count($this->records) ) {
$this->PrintRows($y,false);
} else {
$this->PrintNotes($y,false);
}
// Add page number
$this->PrintPageNumber(20.955,$y,"5",90);
}
function PrintPage6()
{
$y=13.97 - $this->margin;
if ( $this->currentRecord < count($this->records) ) {
$this->PrintRows($y,false);
} else {
$this->PrintNotes($y,false);
}
// Add page number
$this->PrintPageNumber(20.955,$y,"6",90);
}
function PrintPage7()
{
$y=6.985 - $this->margin;
if ( $this->currentRecord < count($this->records) ) {
$this->PrintRows($y,false);
} else {
$this->PrintNotes($y,false);
}
// Add page number
$this->PrintPageNumber(20.955,$y,"7",90);
}
function PrintPage8() {
$y=.635 + $this->margin;
$this->PrintNotes($y,true);
// Add page number
$this->PrintPageNumber($this->margin,$y,"8",270);
}
function PrintRows($y,$left)
{
$line = 0;
$increment=0;
$angle=90;
$x=0;
$indent=0;
if ( $left == true ) {
$x=10.16;
$angle=270;
$increment=-.37;
$indent=.37;
} else {
$x=11.43;
$angle=90;
$increment=.37;
$indent=-.37;
}
while ( $this->currentRecord < count($this->records)
&& $line < 23 ) {
$current = $this->records[$this->currentRecord];
// Prints the Context
if ( $current['name'] != $this->currentContext ) {
$this->PrintContext($x,$y,$current['name'],$angle);
$this->currentContext = $current['name'];
$line++;
$x += $increment;
continue;
}
// Prints the Project name
if ( $current['parentId'] != $this->currentProject && $current['parentId'] != null ) {
$this->PrintProject($x,$y+$indent,$this->projects[$current['parentId']],$angle);
$this->currentProject = $current['parentId'];
$line++;
$x += $increment;
continue;
}
// Prints the action
if ( $current['nextaction'] == null ) {
$this->RotatedText($x,$y+$indent+$indent,"[ ] ".$current['title'],$angle);
} else {
$this->PrintNextAction($x,$y+$indent+$indent,"[ ] ".$current['title'],$angle);
}
$this->currentRecord++;
$line++;
$x += $increment;
}
}
function PrintNotes($y,$left)
{
$increment=0;
$angle=90;
$x=0;
$endY=0;
if ( $left == true ) {
$x=10.16;
$increment=-.635;
$angle=270;
$endY=$y+5.08;
} else {
$x=11.43;
$angle=90;
$increment=.635;
$endY=$y-5.08;
}
// First we must print the title
$this->PrintContext($x,$y,"Notes",$angle);
$x +=$increment;
for ( $i=0; $i < 14; $i++ ) {
$this->Line($x,$y,$x,$endY);
$x +=$increment;
}
}
function PrintBooklet() {
$this->PrintPage1();
$this->PrintPage2();
$this->PrintPage3();
$this->PrintPage4();
$this->PrintPage5();
$this->PrintPage6();
$this->PrintPage7();
$this->PrintPage8();
}
function GetData() {
$today="'2009-01-23'";
// Get Projects
$query = "SELECT
i.itemId
,i.title
FROM
{$_SESSION['prefix']}items i
,{$_SESSION['prefix']}itemstatus ia
WHERE
i.itemId = ia.itemId
AND ia.type = 'p';";
$results = mysql_query($query) or die('Query failed-Getting Projects: ' . mysql_error());
// populate projects;
while ($row = mysql_fetch_array($results,MYSQL_ASSOC)) {
$this->projects[$row['itemId']] = $row['title'];
}
$query = "SELECT
i.itemId
,i.title
,c.name
,gis.deadline
,gis.nextaction
,l.parentId
FROM
{$_SESSION['prefix']}items i
LEFT OUTER JOIN {$_SESSION['prefix']}lookup l ON i.itemId = l.itemId
,{$_SESSION['prefix']}itemstatus gis
LEFT OUTER JOIN {$_SESSION['prefix']}context c ON gis.contextId = c.contextId
WHERE IF(
gis.tickledate IS NULL ,
i.itemId = gis.itemId
AND gis.type = 'a'
AND gis.dateCompleted IS NULL ,
i.itemId = gis.itemId
AND gis.type = 'a'
AND gis.dateCompleted IS NULL
AND gis.tickledate <= now( )
)
ORDER BY
c.name
,l.parentId;";
$results = mysql_query($query) or die('Query failed-Getting Tasks: ' . mysql_error());
// Populate Actions
$this->records=array();
while ($row = mysql_fetch_array($results,MYSQL_ASSOC)) {
array_push($this->records,$row);
}
// Free resultset
mysql_free_result($results);
}
}
$pdf=new PDF('P','cm','letter');
$pdf->GetData();
$pdf->AddPage();
$pdf->SetFont('Arial','',8);
$pdf->printBooklet();
$pdf->Output();
?>