How can I tell if it printed?
Discussion
Aargh.... I'm trying to audit print events when a user prints from my application.
What I've done works. I set a region's background to a .PHP script and pass a variable to it which then calls a MySQL insert statement.
Unfortunately I get a duplicate entry as IE seems to fire two printing events when it prints onbeforeprint() and onafterprint() and if the user presses cancel it still gets logged
Does anyone know of anything that's exposed that I can hook into to audit printing events from my PHP application?
I just can't see a way of doing it cross platform and even if could do it for Windows surely I'm looking at some nasty scripting?
Someone put me out of my misery please...
What I've done works. I set a region's background to a .PHP script and pass a variable to it which then calls a MySQL insert statement.
Unfortunately I get a duplicate entry as IE seems to fire two printing events when it prints onbeforeprint() and onafterprint() and if the user presses cancel it still gets logged

Does anyone know of anything that's exposed that I can hook into to audit printing events from my PHP application?
I just can't see a way of doing it cross platform and even if could do it for Windows surely I'm looking at some nasty scripting?
Someone put me out of my misery please...
pdV6 said:
Just handle the onafterprint? This gets raised when the entire print job has been queued, so hopefully not if the user cancels.
That's what you'd think, but it seems it is called after the job is spooled and has nothing to do with the actual print subsystem.Then there's the fun of getting a variable from js and shipping it over to PHP! I've spent a day fiddling with it thus far and still not cracked it.
Actually, reading a little about those 2 events it seems they both must always get fired as the onbeforeprint is intended to let you re-format the page for printing and the onafterprint to put it back how it should be for on-screen viewing. Therefore you'd need both even if the user cancelled. Sorry about that.
Must keep schtumm when not in possession of enough knowledge
I feel I know how IE formats and sends print jobs more than most now!
The on print actions don't refresh the page properly so I can't set a PHP variable and increment it either... Can't think of a way to get a PHP variable into JS.... I'm on the verge of being scuppered. For now I've just changed the text I put in the log and put up with a double entry.
The on print actions don't refresh the page properly so I can't set a PHP variable and increment it either... Can't think of a way to get a PHP variable into JS.... I'm on the verge of being scuppered. For now I've just changed the text I put in the log and put up with a double entry.
The Griffalo said:
pdV6 said:
Just handle the onafterprint? This gets raised when the entire print job has been queued, so hopefully not if the user cancels.
That's what you'd think, but it seems it is called after the job is spooled and has nothing to do with the actual print subsystem.Then there's the fun of getting a variable from js and shipping it over to PHP! I've spent a day fiddling with it thus far and still not cracked it.
I'd be very surprised if you can get an 'on_print_complete_guranteed_to_be_in_the_print_tray_of_the_printer_but_only_printed_on_cyan_coz_the_black_cartridge_is_empty_event' back into the browser.
Way to go is, get the user to certify they have printed the sheet. You put a page up on the on the onafterprint event. The user is bound legally in their work contract to only click the button when they are holding the bit of paper in their hand.
(You need to provide a button for 'It didn't work, print it again please')
There's no other way to do this.
best
ADe
The Griffalo said:
I feel I know how IE formats and sends print jobs more than most now!
The on print actions don't refresh the page properly so I can't set a PHP variable and increment it either... Can't think of a way to get a PHP variable into JS.... I'm on the verge of being scuppered. For now I've just changed the text I put in the log and put up with a double entry.
You can set PHP variables via Javascript, it's dead easy, but you need to use AJAX, AJAX allows you to send stuff to the server (URL encoded - so you may want to use HTTPS) and server acts on this, and returns a result.The on print actions don't refresh the page properly so I can't set a PHP variable and increment it either... Can't think of a way to get a PHP variable into JS.... I'm on the verge of being scuppered. For now I've just changed the text I put in the log and put up with a double entry.
All of this is done without the page in the browser being refreshed. By example, I send DB search paramters using AJAX via an on Key-Up event from a text box on a web page - the contents are sent to a php page, where I can update $_SESSION variables.
The server interepets the contents of the text box, performs a query on the db and returns a count of matching records, the reults of this are populated into a DIV on the web page the user is viewing.
It's slick!
Once you've done this once you'll never look back.
I had a feeling it would be Ajax!
What I'm doing at the mo. I have a file called logit.php.
logit.php
I can call it by doing the following and it works, but it fires twice (I've left the alerts and some commented out code that I've been playing with in for testing).
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
<script language="javascript" type="text/javascript">
function window.onafterprint()
{
alert('This fires after printing!');
var logit = "2";
alert (logit);
}
</script>
<?php
if ($BeenPrinted =='1') {
//$BGImage = "" . + ('logit');
//$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo)";
}
else {
$BGImage = "background-image:none;";
}
}}}
I then PHP echo $BGImage in a blank table cell.
Now in theory if I could get the var (logit) into the string it should work but it always ends up as zero. I've played around and I can echo the string "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" or "background-image:none;" by setting it as a var in the onbeforeprint() and onafterprint() events but I can't seem to pass it to logit.php (or into a PHP MySQl script on the submitting page for that matter)
Any pointers on how to do this with Ajax greatly appreciated
What I'm doing at the mo. I have a file called logit.php.
logit.php
<?php require_once('Connections/localhost.php'); ?>
<?php
session_start();
//We use this file as a hidden background image to put an entry in the log when a document is printed.
//$BeenPrinted =
I had a feeling it would be Ajax!
What I'm doing at the mo. I have a file called logit.php.
logit.php
[NOWIKI]
I can call it by doing the following and it works, but it fires twice (I've left the alerts and some commented out code that I've been playing with in for testing).
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
<script language="javascript" type="text/javascript">
function window.onafterprint()
{
alert('This fires after printing!');
var logit = "2";
alert (logit);
}
</script>
<?php
if ($BeenPrinted =='1') {
//$BGImage = "" . + ('logit');
//$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo)";
}
else {
$BGImage = "background-image:none;";
}
}}}
I then PHP echo $BGImage in a blank table cell.
Now in theory if I could get the var (logit) into the string it should work but it always ends up as zero. I've played around and I can echo the string "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" or "background-image:none;" by setting it as a var in the onbeforeprint() and onafterprint() events but I can't seem to pass it to logit.php (or into a PHP MySQl script on the submitting page for that matter)
Any pointers on how to do this with Ajax greatly appreciated
GET['BeenPrinted']
$PermitNo=
I had a feeling it would be Ajax!
What I'm doing at the mo. I have a file called logit.php.
logit.php
[NOWIKI]
I can call it by doing the following and it works, but it fires twice (I've left the alerts and some commented out code that I've been playing with in for testing).
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
<script language="javascript" type="text/javascript">
function window.onafterprint()
{
alert('This fires after printing!');
var logit = "2";
alert (logit);
}
</script>
<?php
if ($BeenPrinted =='1') {
//$BGImage = "" . + ('logit');
//$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo)";
}
else {
$BGImage = "background-image:none;";
}
}}}
I then PHP echo $BGImage in a blank table cell.
Now in theory if I could get the var (logit) into the string it should work but it always ends up as zero. I've played around and I can echo the string "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" or "background-image:none;" by setting it as a var in the onbeforeprint() and onafterprint() events but I can't seem to pass it to logit.php (or into a PHP MySQl script on the submitting page for that matter)
Any pointers on how to do this with Ajax greatly appreciated
GET['PermitNo'];
mysql_query("INSERT INTO log (UserID, EventType, IPAddress) VALUES ('
I had a feeling it would be Ajax!
What I'm doing at the mo. I have a file called logit.php.
logit.php
[NOWIKI]
I can call it by doing the following and it works, but it fires twice (I've left the alerts and some commented out code that I've been playing with in for testing).
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
<script language="javascript" type="text/javascript">
function window.onafterprint()
{
alert('This fires after printing!');
var logit = "2";
alert (logit);
}
</script>
<?php
if ($BeenPrinted =='1') {
//$BGImage = "" . + ('logit');
//$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo)";
}
else {
$BGImage = "background-image:none;";
}
}}}
I then PHP echo $BGImage in a blank table cell.
Now in theory if I could get the var (logit) into the string it should work but it always ends up as zero. I've played around and I can echo the string "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" or "background-image:none;" by setting it as a var in the onbeforeprint() and onafterprint() events but I can't seem to pass it to logit.php (or into a PHP MySQl script on the submitting page for that matter)
Any pointers on how to do this with Ajax greatly appreciated
SESSION[FullName]', 'Processing permit No " ."$PermitNo" . " for printing', '
I had a feeling it would be Ajax!
What I'm doing at the mo. I have a file called logit.php.
logit.php
[NOWIKI]
I can call it by doing the following and it works, but it fires twice (I've left the alerts and some commented out code that I've been playing with in for testing).
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
<script language="javascript" type="text/javascript">
function window.onafterprint()
{
alert('This fires after printing!');
var logit = "2";
alert (logit);
}
</script>
<?php
if ($BeenPrinted =='1') {
//$BGImage = "" . + ('logit');
//$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo)";
}
else {
$BGImage = "background-image:none;";
}
}}}
I then PHP echo $BGImage in a blank table cell.
Now in theory if I could get the var (logit) into the string it should work but it always ends up as zero. I've played around and I can echo the string "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" or "background-image:none;" by setting it as a var in the onbeforeprint() and onafterprint() events but I can't seem to pass it to logit.php (or into a PHP MySQl script on the submitting page for that matter)
Any pointers on how to do this with Ajax greatly appreciated
SESSION[IP]')") or die(mysql_error());
?>
I can call it by doing the following and it works, but it fires twice (I've left the alerts and some commented out code that I've been playing with in for testing).
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
<script language="javascript" type="text/javascript">
function window.onafterprint()
{
alert('This fires after printing!');
var logit = "2";
alert (logit);
}
</script>
<?php
if ($BeenPrinted =='1') {
//$BGImage = "" . + ('logit');
//$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo)";
}
else {
$BGImage = "background-image:none;";
}
}}}
I then PHP echo $BGImage in a blank table cell.
Now in theory if I could get the var (logit) into the string it should work but it always ends up as zero. I've played around and I can echo the string "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" or "background-image:none;" by setting it as a var in the onbeforeprint() and onafterprint() events but I can't seem to pass it to logit.php (or into a PHP MySQl script on the submitting page for that matter)
Any pointers on how to do this with Ajax greatly appreciated

The Griffalo said:
Aargh.... I'm trying to audit print events when a user prints from my application.
What I've done works. I set a region's background to a .PHP script and pass a variable to it which then calls a MySQL insert statement.
Unfortunately I get a duplicate entry as IE seems to fire two printing events when it prints onbeforeprint() and onafterprint() and if the user presses cancel it still gets logged
Does anyone know of anything that's exposed that I can hook into to audit printing events from my PHP application?
I just can't see a way of doing it cross platform and even if could do it for Windows surely I'm looking at some nasty scripting?
Someone put me out of my misery please...
Hi!What I've done works. I set a region's background to a .PHP script and pass a variable to it which then calls a MySQL insert statement.
Unfortunately I get a duplicate entry as IE seems to fire two printing events when it prints onbeforeprint() and onafterprint() and if the user presses cancel it still gets logged

Does anyone know of anything that's exposed that I can hook into to audit printing events from my PHP application?
I just can't see a way of doing it cross platform and even if could do it for Windows surely I'm looking at some nasty scripting?
Someone put me out of my misery please...
What I tend to do is in the HEAD section have a little Javascript section that sets a few vars - either from PHP or using Javascript.
For instance, f_lan to detect when it's local, set by PHP, or isIE set by either.
Then my Javascript (when run) can determine if it needs to act differently if IE. BTW Opera seems to copy IE in most respects, so I usually end up doing different stuff for both of them.
Does that make any sense - or have I answered a different question?
In general for two(or more) event items, when you need one action on two events, or one or the other event, implement a small timer queue in JS driven by either event, and when it times out, have a look at the events that triggered it and decide (now you know the final tally) what to do.
Ok, let me simplify this....
I can set this in the onbeforeprint() and onafterprint events
ie
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
}}}
But how do I tack the js variable logit to the url. If I can crack that it works perfectly! My attempt is below but for some reason logit always seems to be 0 when I pass it
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
I can set this in the onbeforeprint() and onafterprint events
ie
{{{
<script language="javascript" type="text/javascript">
function window.onbeforeprint()
{
var logit = "1";
alert (logit);
}
</script>
}}}
But how do I tack the js variable logit to the url. If I can crack that it works perfectly! My attempt is below but for some reason logit always seems to be 0 when I pass it

$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
The Griffalo said:
Ok, let me simplify this....
My attempt is below but for some reason logit always seems to be 0 when I pass it
$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
If that PHP?!My attempt is below but for some reason logit always seems to be 0 when I pass it

$BGImage = "background-image:url(logit.php?PermitNo=$PermitNo&BeenPrinted=$BeenPrinted)" . +('logit');
If so - you need
global $logit;
then the string to incorporate $logit cleanly.
If it's JS, you need to get rid of the dot (.) and just use
var str = 'hello logit is '+logit;
syntax.
Try viewing the whole URL in an alert (to check) - and then using it, don;t view one thing and send another...!
The Griffalo said:
Yup, it's PHP... Global eh? I'll look into that, it could do just what I need 
You only need global if you are trying to use a global var inside a function..else PHP will assume uninitialised local - i.e. 0.I'm not familiar with the . +('logit') syntax, I'd tend to use:
. "$logit"
or even
. $logit
to join the value to the end of that string (although shirley you want . "&logit=$logit" in this case?)
The Griffalo said:
Yup, it's PHP... Global eh? I'll look into that, it could do just what I need 
Thinking about this (and actually looking at your bigger code above) it looks like you are mixing server and client code, and expecting the client JS variable 'logit' to be useful to the server, which of course it never can be because it is a) too late, and b) unknown to the server.I have had a lot of wine though, and about to expire.
You need to get the client JS to construct the final URL to request from the server (to notify the print). (this IS ajax in fact).
So you construct the URL in PHP ecept for the beenprinted item, and then you add in JS the
url += "&beenprinted=" + logit";
and then set the picture src from JS so the request is made.
The PHP server code will THEN see the correct value for logit.
HTH, must sleep now, travel tomorrow!
The Griffalo said:
I'll ponder on that in the morning when I'm more alert! 
Thanks
Rob, silly question, are you trying to print your forms/pages on the client's printer or a central server printer?
Thanks
Anyway, I'm going for the more alert option too...
And complicatingly from what we were talking about, you need some guarantee that the person is holding the bit of paper that has just been printed?
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff



Ted, the formatting's fubared 
