Archive for April 29th, 2009

Nützliche Tools

Wednesday, April 29th, 2009

Einige nützliche Tools:

Harddisk Search & Stats – Harddisk nach Dateien und Dateiinhalt durchsuchen. Enthält einen praktischen Textviewer, mit dem man dann in den gefundenen Dateien suchen kann. Perfekt um Code von anderen zu verstehen

BambooInvoice and PDF Customisation

Wednesday, April 29th, 2009

Using the very cool  invoice package BambooInvoice built upon the CodeIgniter project. (Go check them both out, if you haven't done so already!)

The task set before me is to integrate an additional image in each PDF invoice file generated.

We start here: Z:\!tmp\bambooinvoice_089\bambooinvoice_089\bamboo_system_files\application\views\invoices

And edit pdf.phpthe company logo is already being included in the PDF output.

<?php if (isset($company_logo)) {echo $company_logo.'<br />';}?>

Now I'd like to see the content of this variable – which will probably be HTML – to build the new image code accordingly:

 <?php if (isset($company_logo)) {echo htmlentities($company_logo).'<br />';}?>

After generating a PDF we get:

<img src='/web/vhosts/0-iddres/bambooinvoice_089/img/logo/sevenvoicelogo1.jpg' />

OK, here we could go the easy way and just include a patched string. But we're tough boys, ain't we? If the  underlying adress changes, the image output would be broken. So, a search for the source of company_logo is in order.

invoices.php contains this piece of code: $data['company_logo'] = $this->_get_logo();

get_logo is found here:

 function _get_logo($target='', $context='web')
{
$this->load->helper('logo');
$this->load->helper('path');
return get_logo($this->settings_model->get_setting('logo'.$target), $context);
}

which in turn leads us to this snippet from logo_helper.php:

function get_logo($logo = 'logo.jpg', $context = 'web')
{
	$CI =& get_instance();

	// if they don't have a logo in the database, just default to logo.jpg
	if ($logo == '0' || $logo == NULL)
	{
		$logo = 'logo.jpg';
	}

	if ($context == 'web' OR $CI->config->item('logo_base_url') === TRUE)
	{
		$path = base_url().'img/logo/';
	}
	else
	{
		$path = set_realpath('./img/logo/');
	}

	return "<img src='{$path}{$logo}' />";
}

The solution is quite easy: specify 'name.jpg' as the first parameter to get_logo. Drop the code below into pdf.php:

<?php
$this->load->helper('logo');
$this->load->helper('path');
echo get_logo('name.jpg').'<br />';
?>

where name.jpg is the filename of your additional image. Don't forget to remove htmlentities again, if you followed me along instead of skipping to the solution immediately.