This topic is locked

Printing a letter automatically when arecord is saved

7/3/2008 6:28:34 PM
PHPRunner General questions
T
thesofa author

When a kid is given a detention to be done after school, we have to send a letter to its parents telling them what it has done and when it will be detained.

I am required to have this letter printed automatically from any workstation when a detention is saved, on whichever printer happens to be the default.

The letter has a grapic at the top and varoius sentences which have to be customised to say Tommy is a git, he killed the cook so he will have to pay.

ETC

but if it is Serena who killed the cook, then the letter is female.

I know how to do all that (Thanks Jane) but how do I get the letter to print automatically without the teacher having to click print and choose a printer?

Cos if they have to, they will not.

I need an "After Record Saved" event which prints the letter and then returns to the Pick a brat to detain Page.

T
thesofa author 7/4/2008

OK, I have been playing with this a bit more, I have all the relavent info on the reort page, in fact, I have too much, so what I need to know now is 2 things.

How do I get the record number of the record I have just saved, bearing in mind that there may be multiple saves going on from many users.

Once I have that information in terms of the Detention ID for the record, how can I call the report with an "After record saved" event and pass the record ID to the report?

T
thesofa author 7/4/2008

The journey continues,.......

I have found the ID number for the record just saved by using $keys["id_det"]

How do I pass the value from this array variable as the filter for the report?

Or even to a printer friendly page where I can extract the data from other tables with queries run in an event, then build the letter up from variables.

How do I pass this value to a printer friendly page for one record?

AAAAAAAAAAAAAAAAAAAAAAARRRRRRRRRGGGGGGGHHHHHHHHHHHHHHHH!

I hate these things when I get stuck....................

J
Jane 7/7/2008

Hi,
here is an example:

//redirect to printer friendly page

header("Location: tablename_print.php?recordid=".$keys["id_det"]);

exit();


Then check this parameter in the Print page: Before SQL query event:

if (@$_REQUEST["recordid"])

$strWhereClause = whereAdd($strWhereClause,"id_det=".$_REQUEST["recordid"]);

T
thesofa author 7/7/2008

You are a star, one of the brightest in the firmament.

Thank you.

S
swanside 7/7/2008

The journey continues,.......

I have found the ID number for the record just saved by using $keys["id_det"]

How do I pass the value from this array variable as the filter for the report?

Or even to a printer friendly page where I can extract the data from other tables with queries run in an event, then build the letter up from variables.

How do I pass this value to a printer friendly page for one record?

AAAAAAAAAAAAAAAAAAAAAAARRRRRRRRRGGGGGGGHHHHHHHHHHHHHHHH!

I hate these things when I get stuck....................


You seem to be trying to do what I was 6 months ago, and with the help of Jane and Sergey I am getting very close to completeing.

What I ended up doing was on the database, I have fields like Customer_Name which I am assuming you could call it Childrens_Name
And other fields Like Job_Description Which could be classed as Detention Reason plus various other fields.
I built my project, Went into the output folder and Templates. I have a htm file called Full_Invoice_List which I made up from a Custom_View.
I opened the file with MS Frontpage and found thigs like {$show_Customer_Name} {$show_Job_Description} I then made my own table above the table PHPRunner made and copied the required Fields into the table, Saved the file and look at my running project. Once I was happy all the infomation was in the correct place, I opened up the file again with MS Frontpage and deleted the table PHPRunner made leaving my layout with all the {$show_Customer_Name} {$show_Job_Description} items in the places I wanted them.
When I was happy with this I made a new folder in the root of my project called invoices and copied the files I changed into this folder, as everytime I rebuild my project, it over writes the Invoices, so then I just copy them back.
If it is of any help, email me your database (EMPTY) and project and I will try to show you .
Paul.

T
thesofa author 7/7/2008

OK, I have this all but sussed out, here is what I have done.

First, I made a custom view in PHPR for the letters, linking to all the tables from which I need to draw information with inner joins

I then prepared my sql statement to concatenate the names to make them man-readable.

I then delete all the fields and footers and headers from the visual editor for the letters as well as the table of all the variables and labels, I do this from the html side of he visual editor.

Next I make a load of variables in the custom code part of the events tab, see code later. , then using the 'echo' statement, i place stuff on the page, having used the code from Jane (above) to get the record I need and palacing the bits I want in the sentences I want and again i use echo to place them on the page,

Once this is in place, I build the project and find the filename for the page that prints and I direct the add detention page after saving to the print page, which comes up with the printable page for the record.

here is the code, make of it what you will. This goes in the BeforeProcessRowPrint(&$data) event

function BeforeProcessRowPrint(&$data)

{

//********** Custom code ************

// put your custom code here

global $conn;

$b="</big><p><big></b>";

$given=date("l, F j, Y");

$dep=$data["Department"];

$pup="<b>".$data["Pupil"]."</b>";

$d4d=$data["Day for Detention"];
//this bit of code blagged from http://www.webmasterworld.com/forum88/1132.htm with thanks

$stringArray = explode("-", $d4d);
$date = mktime(0,0,0,$stringArray[1],$stringArray[2],$stringArray[0]);
$converteddate = date("l, F j, Y", $date);

$why="<b>".$data["Reason"].".</b> ".$data["Comments"];

$giver=$data["Teacher"];

$open=$given."<p><p><p><big>Dear Parent/Carer of ".$pup.",<p><big><b>School Detention for ".$dep."</b></big></p>";
$a="In line with school policy, which applies the 1997 Education Act regarding the legalities of detention, I am writing to give you the required 24 hours notice that I shall be detaining ".$pup." from 3.00pm to 4.00pm on <b>".$converteddate."</b>.";

$a1="The reason for detention is: ".$why.".";

$c="Transport home is the responsibility of parents so you may need to arrange suitable alternative transport home if he/she normally travels on a school bus. (There is a late bus in operation which leaves school at 4.30pm prompt to most local areas).";

$d="The decision to place pupils in detention is not taken lightly and the offence is deemed serious. It is hoped that you will work with the school in the attempt to correct breaches of discipline.";

$e="Yours sincerely,";

$f="<b>Teacher: ".$giver."</b>";

echo "<IMG src=images/head.jpg width =667 height = 144 border=0>";

echo $b;

echo $open;

echo $b;

echo $b;

echo $b;

echo $a;

echo $b;

echo $a1;

echo $b;

echo $c;

echo $b;

echo $d;

echo $b;

echo $e;

echo $b;

echo $b;

echo $b;

echo $b;

echo $f;

echo $b;

return true;
// return true if you like to display row on in the list

// return false otherwise

}


It works well so far, but it does not open a separate page, in the way it would if I called the print page from the list page, what do I need to change in the line calling the printable page to keep the original database window open?

T
thesofa author 7/7/2008

Hi,

here is an example:
Then check this parameter in the Print page: Before SQL query event:



This is wonderful, but how do I open the printer friendly page and leave the database table page open below it, so when I have printed, I can close the print friendly page and revert back to the main master page, can I do an event after printing, or on the closing of the window?

J
Jane 7/8/2008

Hi,
to redirect to the main page and open print page use JavaScript code in your event:

?><script>

window.open('tablename_print.php?recordid=<?php echo $keys["id_det"]?>');

window.location.href='tablename_list.php';

</script><?php

Z
zeitsprung 7/17/2008


//redirect to printer friendly page

header("Location: tablename_print.php?recordid=".$keys["id_det"]);

exit();


Then check this parameter in the Print page: Before SQL query event:

if (@$_REQUEST["recordid"])

$strWhereClause = whereAdd($strWhereClause,"id_det=".$_REQUEST["recordid"]);[/quote]



I was very pleased to find out, that this worked for me (I also have to go to print a new dataset) - alas, when in 'inline edit' mode I get an error. When hovering over error info, the print page is shown in a pop-up window...

Since I only allow to alter 2 checkboxes in inline edit, I can live without redirecting to printer friendly page after inline edit.

Could it be managed to only redirect after 'add' and 'form edit'?
Another issue: you offered a solution where a user can open a separate 'printer friendly' page and stay in list mode:

?><script>

window.open('tablename_print.php?recordid=<?php echo $keys["id_det"]?>');

window.location.href='tablename_list.php';

</script><?php



To put this snippet into the event editor (custom code?) there always appears a

function ....

{

}


already filled in. Have I to put this particular code snippet /w JS code just between the braces?
When I'm back home from office I will u/l the project to your server.
Overall, the program even works together with a php/mysql-rookie and shows results... that work <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=31149&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

J
Jane 7/17/2008

Hi,
simple redirect works for add/edit pages only. If you use inline edit use JavaScript code in your event.

Have I to put this particular code snippet /w JS code just between the braces?



Yes.
Here is the code for Inline Edit:

?><script>

window.open('tablename_print.php?recordid=<?php echo $keys["RecordID"]?>');

</script><?php

Z
zeitsprung 7/20/2008

Hi,

going to printer friendly page after 'edit/add' now works like charm due to the really helpful tips I found in other posts and got from Jane. Thanks a lot.

Since I use two logical fields (checkboxes) for altering only in inline edit mode, but need to go to printer friendly page when only one particular checkbox was altered, thus I guess I have to make some changes to the following code
Enter this parameter in the Print page: Before SQL query event:

if (@$_REQUEST["recordid"])

$strWhereClause = whereAdd($strWhereClause,"id_det=".$_REQUEST["recordid"]);



The two logical fields are 'printed' (either 0 or 1) and 'exported' (either 0 or 1), and I only want to print when 'printed' =1 and 'exported' =0 - or as long a 'exported'=0 respectively.

Since it's just a week ago I learned to work with phpRunner and my knowledge with php and mySQL is really poor, I'm still dependent on some help how to manage this.

Thank you.
BTW: I also evaluated AsAP, Appgini and PHPMaker5 - but found phpRunner much more flexible and more powerful - even for a novice like me. I decided to buy a license for our office within the next days.

J
Jane 7/21/2008

Hi,
I think you need to add If condition to your AfterEdit event:

if ($values["printed"]==1 && $values["exported"]==0)

{

//redirect to printer friendly page

...

}