gtd-php
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 09, 2010, 03:15:28 AM

Login with username, password and session length
Search:     Advanced search
1756 Posts in 305 Topics by 425 Members
Latest Member: joey_ser33
* Home Help Search Calendar Login Register
+  gtd-php
|-+  gtd-php
| |-+  gtd-php users
| | |-+  Next Actions booklet for gtd-php 0.9
« previous next »
Pages: [1] Print
Author Topic: Next Actions booklet for gtd-php 0.9  (Read 786 times)
gusfn
Jr. Member
**
Posts: 2


View Profile
« on: January 20, 2009, 10:34:52 AM »

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:

Code:
<?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:

Code:
<?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(); 
?>
Logged
Andrew
Administrator
Hero Member
*****
Posts: 375


View Profile
« Reply #1 on: January 30, 2009, 01:56:48 AM »

ok, that's now included in the SVN trunk, so it will come as part of the standard download package.

The options can be tweaked in options.inc.php.  It seems happy enough with paper sizes of letter (the default) or A4, though any paper sizes radically different to that will be very messy.

It needs a bit of work in wrapping long lines, but it's looking quite good now.

Andrew
Logged
bg
Guest
« Reply #2 on: March 10, 2009, 02:36:50 AM »

Hi there.

Thank you for sharing the updates.

I have v0.9 but unfortunately, I donnot manage to set up the booklet. Can you please share more details about where to put each file and what to do to set it up, step by step? I would be very grateful for that.

Benjamin
« Last Edit: December 01, 2009, 05:46:07 AM by Andrew » Logged
bg
Guest
« Reply #3 on: March 15, 2009, 01:10:58 PM »

I am alright with it now. Please, see the other topic re same subject for updateS.
« Last Edit: December 01, 2009, 05:46:02 AM by Andrew » Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!