Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help with php5 issue - loading a pdf file

Posted on 2009-04-29
6
Medium Priority
?
308 Views
Last Modified: 2012-05-06
I have a question (or plea for help) that I'm not sure even fits the scope of this site . . . . but here goes:

I have a web app that was written in php5 by someone no longer here.   It communicates with a computer in our office (written by me) to give web access to plant data.  One of the functions is not working in an acceptable format and I need help with a work around.

Basically, the web user requests a copy of a document.  The php5 code sends the request to the computer in our office, which generates the pdf and then uplaods it to a specific file name/location on the web server.  The computer in our office then sends the url to the web app and it is supposed to open it in a new tab or window.

The way it works now . . is that when the user requests the document copy, it pops up a small window and says 'Waiting' with an OK button.   The user actually has to click 'OK' before it continues.  This is unacceptable to our customers.

Previously, a blank window opened with no activity in it until the web app recieved the pdf url . . and then briefly flashed up a 'please wait' before loading the pdf.  We had complained about that because the user thinks there is a problem and closes the window when nothing happens quickly.  We wanted the 'please wait' to show up as soon as the new window opens.  What the programmer did really didn't work . . .but was meant to hide the problem by making the user do something before the window popped up.  But it only made it worse.

I'm now trying to make some changes to the app and I need to 1> get rid of the first pop up box that makes the user press 'OK'.  And 2> try to make the 'please wait' show up as soon as the window opens. . . not when it starts loading the pdf file.

You can see what it is doing by going to the following website . . . www.excelss.net/libermans/index.php5  and log in as clthames account number 10001    Then mouse over one of the 'job numbers' listed and select 'View Acknowledgment'.
relevant code form the 'calling' php5 file:
 
		mywindow = window.open ("genpdf.php5?keyjob="+keysent+"&ctype="+ctype,"mywindow","resizable=no,location=0,status=0,scrollbars=0,width=800,height=600");
 
code from the genpdf.php5 file - look down the code for '*******' for where I think this is happening.  The beginning lines are building the request to send via the socket
 
<?php
session_start();
set_time_limit(0);
$host="xx.xx.xx.xx";
$port = xxx;
 
$socket = socket_create(AF_INET, SOCK_STREAM,  getprotobyname('tcp')) or die("Could not create socket\n");
$result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");
$ctype = $_GET['ctype'];
$keyjob = trim($_GET['keyjob']);
if($ctype=="Bill")
{
$out = "[getdoc]type=bol,field=order_num,key=$keyjob,acctno=".$_SESSION['acctno'].",user=".$_SESSION['username'];
}
if($ctype=="Ack")
{
$out = "[getdoc]type=acknowledgement,field=order_num,key=$keyjob,acctno=".$_SESSION['acctno'].",user=".$_SESSION['username'];
}
if($ctype=="Inv")
{
$out = "[getdoc]type=invoice,field=order_num,key=$keyjob,acctno=".$_SESSION['acctno'].",user=".$_SESSION['username'];
}
if($ctype=="erp")
{
$out = "[launch_report]reportid=ols00001.rpt, begin_date=".$_GET['bdate'].",end_date=".$_GET['edate'].",acctno=".$_SESSION['acctno'].",user=".$_SESSION['username'];
}
if($ctype=="jsh")
{
$out = "[launch_report]reportid=ols00002.rpt, begin_date=".$_GET['bdate'].",end_date=".$_GET['edate'].",acctno=".$_SESSION['acctno'].",user=".$_SESSION['username'];
}
if($ctype=="oo")
{
$out = "[launch_report]reportid=ols00003.rpt,acctno=".$_SESSION['acctno'].", begin_date=".$_GET['bdate'].",end_date=".$_GET['edate'].",user=".$_SESSION['username'];
}
if($ctype=="ocum")
{
$out = "[launch_report]reportid=ols00004.rpt,acctno=".$_SESSION['acctno'].", begin_date=".$_GET['bdate'].",end_date=".$_GET['edate'].",user=".$_SESSION['username'];
}
 
if($ctype=="osd")
{
$out = "[launch_report]reportid=ols00005.rpt,acctno=".$_SESSION['acctno'].", begin_date=".$_GET['bdate'].",end_date=".$_GET['edate'].",user=".$_SESSION['username'];
}
if($ctype=="idv")
{
$out = "[launch_report]reportid=ols00006.rpt,acctno=".$_SESSION['acctno'].", begin_date=".$_GET['bdate'].",end_date=".$_GET['edate'].",user=".$_SESSION['username'];
}
if($ctype=="ode")
{
$out = "[launch_report]reportid=ols00007.rpt,acctno=".$_SESSION['acctno'].", begin_date=".$_GET['bdate'].",end_date=".$_GET['edate'].",user=".$_SESSION['username'];
}
 
//*******************************
//echo "<img src='wait.gif' height=100 border=0 /> <br/>".$out;
 
 $out .= "Connection: Close\r\n\r\n";
socket_write($socket, $out, strlen($out)) or die("Could not send data to server\n");
 
$result = socket_read ($socket, 100000,PHP_NORMAL_READ) or die("Could not read server response\n");
//echo "<br/>".$result."<br/>";
$tokeme = strtok($result,"~");
$theVariables = array();
$theVariables[0] = $tokeme;
 
while ($tokeme) {
        //print ("$tokeme");
		$tokeme = strtok("~");
		$theVariables[] = $tokeme;
		
		
       
 
    }
   if(trim(str_ireplace('[end]','',$theVariables[1]))=="conntimeout")
{
echo '<br>Sorry. The Request Timed Out.';
}
else{
if(trim(str_ireplace('[end]','',$theVariables[1]))=="norecs")
{
echo '<br>Sorry. No Matching Records were found';
}
else
{
 
//echo trim(str_ireplace('[end]','',$theVariables[1]));
?>
<center><img src='wait.gif' height=100 border=0 /> <br/></center>
<body onload='mywindow = window.open ("<?php echo trim(str_ireplace('[end]','',$theVariables[1]));?>","mywindow","location=0,status=0,scrollbars=0,resizable=0,width=800,height=600");'>
 
</body>
 
<?php
}
}
socket_close($socket);
?>

Open in new window

0
Comment
Question by:lthames
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
AtanAsfaloth earned 2000 total points
ID: 24263423
Hi lthames,

The popup box code is in the original site. The following javascript snippet should be changed to get rid of it. Simply remove the alert("Please wait") lines and the popup box shall be no more.

The 'please wait' image is displayed this late because the php output isn't generated until the server is done responding with the generated pdf.
When 'View Acknowledgement' is clicked the user should be redirected to a new page in a new window with a please wait image, and when that page is loaded the 'genpdf.php' page should be called.

Hoping this helps,

Atan
function setCommand(ctype)
{
	if(ctype!=1)
	{
		alert("Please Wait.....");
		mywindow = window.open ("genpdf.php5?keyjob="+keysent+"&ctype="+ctype,"mywindow","resizable=no,location=0,status=0,scrollbars=0,width=800,height=600");
	}
	else
	{	alert("Please Wait.....");
		window.location = "getdata.php5?keyjob="+keysent+"&ctype="+ctype;
	}
	//alert(keysent);
	
}

Open in new window

0
 

Author Comment

by:lthames
ID: 24263918
ahhh, I see now that I was looking at the old code version, not the live code.

I've taken care of that issue.

On your second suggestion, is this something I can do with the existing window.open command in the calling program?  The 2 pieces of code (I think) are below.

Thanks for your help!!!!!




code from calling file:
 
mywindow = window.open ("genpdf.php5?keyjob="+keysent+"&ctype="+ctype,"mywindow","resizable=no,location=0,status=0,scrollbars=0,width=800,height=600");
 
code where it is actually displayed:
 
?>
<head>
<title>Please Wait.....</title>
</head>
<center><img src='wait.gif' height=100 border=0 /> <br/></center>
<body onload='mywindow = window.open ("<?php echo trim(str_ireplace('[end]','',$theVariables[1]));?>","mywindow","location=0,status=0,scrollbars=0,resizable=1,width=800,height=600");'>

Open in new window

0
 
LVL 5

Assisted Solution

by:AtanAsfaloth
AtanAsfaloth earned 2000 total points
ID: 24264248
The problem is that the sequence of events is not as you would want it.

1) User requests 'genpdf.php5'
2) genpdf.php5 communicates with server to generate pdf file (this takes a long time)
3) genpdf.php5 produces output, the code you posted above, including the 'please wait' message
4) The pdf file is requested by the user through the <body onload='window.open(... stuff
5) User gets to view the pdf

What you need is for step 3 to take place before the others. The easiest way to do that is by creating a new file that displays the image and causes the user to request genpdf.php5 afterwards

Maybe create a new file 'waitforgenpdf.php'. The code would be something similar to the attached snippet. Instead of the window.open("genpdf.php5?keyjob=...") use window.open("waitforgenpdf.php?keyjob=..."). Note that this is probably not the most elegant solution, but from what I can tell this would fit in your current system setup.

Good luck!
<?php
//Create array of get variables so none get lost
$argument = "";
foreach ($_GET as $key => $value) {
	//Append get argument
	$argument .= "$key=$value&";
}
//Remove trailing ampersand and add leading question mark
if (strlen($argument) > 0) {
	$argument = "?".substr($argument, 0, strlen($argument)-1);
}
?>
<html>
<head>
<title>Please wait...</title>
</head>
<body onload="window.location='genpdf.php5<? echo $argument; ?>'">
<center><img src="wait.gif" alt="Please Wait..." height=100 border=0 /> <br /></center>
</body>
</html>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:lthames
ID: 24264554
It may not be elegant . . .but it worked like a charm!!!  Thank you for everything!

Are we allowed to ask about hiring experts on this site?

0
 

Author Closing Comment

by:lthames
ID: 31576062
Excellent!  The suggested code changes worked the first time!
0
 
LVL 5

Expert Comment

by:AtanAsfaloth
ID: 24264987
You're welcome, glad to be of help.

A quick search of the site suggests 'no', one is probably not allowed to ask about hiring experts.
http://www.experts-exchange.com/Community_Support/New_to_EE/Q_22742185.html

Atan
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question