Warning: Creating default object from empty value in /home/dakor/release2.5/modules/CGExtensions/CGExtensions.module.php on line 515
 
 

Dakor News

You are here: Home >> Blogs

Warning: Creating default object from empty value in /home/dakor/release2.5/modules/CGExtensions/CGExtensions.module.php on line 515

Aug 15, 2009

I decided to set the daunting task of dynamic PDF generation for myself today. I want to be able to create invoices from the back-end of my website, have them PDF'd and emailed directly to my clients.

Invoices can be created from either website maintenance projects, purchases entered via the back-end or website design purchases entered via the front-end. I have already set up the functionality that logs the invoice in the database, assigns the products to it and creates the invoice via Smarty template. I was originally going to send the HTML invoice via email but thought it would be nicer to send it as an attachment and I could also save the PDF on the server for future reference.

I started researching it this morning. I came across a few different classes out there, like FPDF and PDFLIB but it's wasn't quite what I was looking for. You have to recreate the PDF from bottom up with those. What I wanted to to feed in the HTML and have the class create the PDF. Lo-andbehold, I found it, dompdf.

dompdf was easy to install on my Windows Vista machine, I downloaded it, unzipped it. I also had to download and execute the ttf2pt1 utility. I changed the path to the utility in the config file, ran a test script and Voila! it worked.

I then went back into the Invoice module where the invoices are created. I needed to capture the HTML from the Smarty template and feed it into the dompdf class then save it to a folder. I wanted the file names in the following fashion CLIENT_invoice_DATE.pdf. I also needed to check if this filename already existed and add a _1 after date, so that I didn't end up overwriting a file if two invoices where created on the same date for the same client. This was easy enough to do, I just put it into a while loop checking for the filename with is_file and using an incremental count variable to the _NUMBER.

I wrote out the code, tested it and got a load of errors. <code>Notice: Undefined variable: idProject in...</code> I was sure I hadn't changed the error_reporting in my php.ini file, checked it and it was still 'E_ALL & ~E_NOTICE' I eventually tracked down the problem to the config file in dompdf. It was setting the error_reporting to E_STRICT. I commented it out, and it worked.... yee haa.

A few small clean ups and I'm done for the day.

Mar 26, 2009

I want to put a news feature on my website, but I want it to be different. I like the scrolling news idea, but not the ticker type. I have a Javascript that will provide the functionality of the scrolling news but I need to integrate it with the News module of the CMS system. Here is what I needed to do:
  • Create a Javascript file for the scroller functionality
  • Create a new summary template for the News module to use
  • Create a User Defined Tag that calls the Javascript file
  • Modify the News module to display a Javascript array of news items
  • Add a parameter to the News module call to include "summarytemplate='scroller' "
  • Call the UDT on the main template
I created a Javascript file with the current script that I have. The script iterates through an array of news items scrolling through each one. I then modified the News module default page, so that it displays the Javascript array of news items. I created a new Summary Template called scroller. The scroller template only displays the Javascript array of news items. I created a User Defined Tag that calls the Javascript file. I added the UDT to the my main template, right after the News module call. I also added the parameters to the News call so that it would use the 'scroller' template instead of the 'Summary Template' See the finished product on the left.