LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-24-2010, 05:09 PM   #1
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Rep: Reputation: 15
Need script to generate vouchers


I have a file, two columns, first column has a list of 15000 (yes 15k) unique codes, second column has the afilliate codes of 60 locations repeated to fill out the 15000 rows of unique codes.

I need to produce a nice neat paper voucher which will fit onto A6 (1/4 A4) and is ready to print. Each voucher has the unique code and corresponding location.

So far I am thinking PHP will do the job. This does it somewhat, but doesn't let be split the fields between the ",".


I did this so far in PHP
Code:
<?
$fp = fopen('filein.csv','r') or die("can't open file");
print "<table>\n";
while($csv_line = fgetcsv($fp,1024)) {
    
	print '<tr>';
    for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
		print '<td>'.$csv_line[$i].'</td>';
    }
    print "</tr>\n";
}
print '</table>\n';
fclose($fp) or die("can't close file");
?>
How can I make sure my formatting fits to A5?
 
Old 06-24-2010, 11:43 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
I would use imagemagick to create each file, so that you can specify the dimensions.

Alternatively, use htmldoc to create a pdf for each voucher, you can specify the page dimensions there too. You will have to experiment to get the correct alignment.

Both those tools can be scripted and sent commands from your script. I once used perl to create individual certificates in pdf format from database fields, running as a cgi script on a web server.

Last edited by smoker; 06-24-2010 at 11:47 PM.
 
Old 06-25-2010, 06:40 AM   #3
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
I've now achieved what i want to do. Managed to get the list of afilliates re-organised thanks to some bash scripting. Took a while to get sed to play ball though. I don't think it likes variables that much!

Code:
for (( vet=1; vet<=60; vet++ )) ; do for (( repeat=1; repeat <=250; repeat++ )); do echo $vet; sed $vet'q;d' "populate.csv" >> newvetslist; done; done;
Code:
<?
$fp = fopen('filein.csv','r') or die("can't open file");

//print "<table border =1>\n";
while($csv_line = fgetcsv($fp,1024)) {
	//print '<tr>';
    for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
       
		print '<center>Some html<BR></center>';
        print '<center>';
        if ($i=2)
		{print 'Voucher Code: '.$csv_line[0].'';};
		if ($i=1)
		{print ' Affiliate Code: '.$csv_line[1].'';};
		print '';
    }
    		print '</center>';
			print '<HR>';

	//print "</tr>\n";
}
//print '</table>\n';
fclose($fp) or die("can't close file");
?>
finally did the job.
I hope its helpful to somebody.
 
Old 06-25-2010, 11:13 AM   #4
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Finally got it working, complete with page break every 3 pages

Code:
<STYLE>
    DIV.pageBreak { page-break-before: always; }
</STYLE>

<?
//for (( vet=1; vet<=60; vet++ )) ; do for (( repeat=1; repeat <=250; repeat++ )); do echo $vet; sed $vet'q;d' "populate.csv" >> newvetslist; done; done;
$count = 0;
$fp = fopen('filein.csv','r') or die("can't open file");
while($csv_line = fgetcsv($fp,20)) {
    for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
			print '<BR><BR><HR>';

	print '<center><img src=""><BR><font color="blue" size="5">URL</font></center>';

     	print '<center>Why not try  ? <BR></center>';
		print '<center>Text<BR></center>';
		print '<center>Some text<BR></center>';

		print '<center><b><font size="3" color="red">Some stuff</font></b><BR></center>';
		print '<BR>';

		print '<center>Just enter the following details at the checkout: <BR>';
		if ($i=2)
		{print 'Voucher Code <b> '.$csv_line[0].'</b>';};
		if ($i=1)
		{print ' Affiliate Code <b> '.$csv_line[1].'</b>';};
		print '';
		print '</center>';
		print '<BR><HR>';
$count++;			

	    if ($count==3) {print $count; print '<DIV CLASS="pageBreak"/>'; $count = 0; };

    }
    		
			

//if j=60, then output <DIV CLASS="pageBreak"/>.

}
fclose($fp) or die("can't close file");
?>

Last edited by suse_nerd; 06-25-2010 at 11:14 AM.
 
  


Reply

Tags
break, code, create, generate, html, online, page, php, website


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to generate package.use from currently installed packages mcolangelo Gentoo 1 05-27-2010 03:01 PM
[SOLVED] Script to generate SSH Banner MOTD geforce Programming 6 04-18-2010 05:26 PM
script /program to generate web hits jindalarpan Linux - Software 8 09-19-2009 03:05 PM
Using firestarter to generate an iptables script jc materi Linux - Security 2 03-28-2005 11:15 PM
how to generate iptables script using fwbuilder Skunk_Face Linux - Security 1 04-23-2004 11:06 PM


All times are GMT -5. The time now is 12:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration