Recent Changes - Search:

Users

Developers

Wiki help.

Next Actions Booklet

This marvellous add-on was created by Robert Deeken, and submitted in trac ticket 397.

This requires fpdf, which is a free php library for creating PDFs. To use the default config shown below, fpdf should be a subdirectory of the parent directory of gtd-php, so the path from gtd-php to fdpf is ../fpdf/

Note, this add-on is suitable for people who like hipsterPDAs. You can now download actions from GTD-PHP to your hipsterPDA. -- Crisses

In the add-ons section of config.php, add:

$config['addons']['booklet']=array(
        "link"=>"addons/actionBooklet/actionBooklet.php",
        'title'=>"Booklet of next actions", 'label' => "NA Booklet",
        'where'=>'reportContext.php','when'=>'after',
        'options'=>array('fpdf'=>'../fpdf/')
        );

For this add-on, I think the options we need are:

 * print blank lines for notes on page 8, or use page 8 for next actions as we do pages 1-7
 * paper size - a4, letter, ...
 * truncate project and item titles after N characters
 * only print out specific contexts
 * path to fpdf

addons/actionBooklet/actionBooklet.php

<?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() { 
global $config; 
        // Get Projects 
       $query = "SELECT 
                     i.itemId 
                     ,i.title 
                  FROM 
                     ".$config['prefix']."items i 
                    ,".$config['prefix']."itemattributes 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 
                     ,ia.deadline 
                     ,na.nextaction 
                     ,l.parentId 
                  FROM 
                     ".$config['prefix']."items i 
                        LEFT OUTER JOIN ".$config['prefix']."nextactions na ON i.itemId = na.nextaction 
                        LEFT OUTER JOIN ".$config['prefix']."lookup l ON i.itemId = l.itemId 
                     ,".$config['prefix']."itemstatus gis 
                     ,".$config['prefix']."itemattributes ia 
                        LEFT OUTER JOIN ".$config['prefix']."context c ON ia.contextId = c.contextId 
                  WHERE 
                     i.itemId = ia.itemId 
                     AND i.itemId = gis.itemId 
                     AND ia.type = 'a' 
                     AND ia.suppress = 'n' 
                     AND gis.dateCompleted IS NULL 
                  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(); 
?> 

Edit - History - Print - Recent Changes - Search
Page last modified on March 23, 2008, at 12:05 AM