How do I Change active window size

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Wed Oct 21, 2015 3:17 pm

Hello, total nube to php and need a little guidance.

Our phone system (which is web based) can force a popup window to appear within IE or whichever browser we're using. It defines the window size. It also passes various parameters which we can analyze with php code. Following is an example...

Code: Select all

$queue=$_POST["Queue"];

if (is_null($queue)) {
                printf('No queue data was given');

}

else {
switch ($queue) {
case "test Environment":

header("Location: http://www.8x8.com");
break;
default:
echo "<script>window.close();</script>";
break;
}
}
?>
What I need to do is change the window size when the "test Environment" section processes to something other than what is set in the phone system settings that cause the window to popup.

If it passes to default, then no change needs to be made.

Thanks in advance.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Wed Oct 21, 2015 4:28 pm

It depends on how you're creating the window. where is the code you're using to fire popup?

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Thu Oct 22, 2015 6:55 am

seandisanti wrote:It depends on how you're creating the window. where is the code you're using to fire popup?
This is called from a setting within the phone system's "Integration" settings. We create the file as I showed above, stick it on any web server (currently it's on our intranet server) and provide the URL for it within the Integration/ScreenPop settings of the phone system. In there we also can define the initial window size and placement.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Thu Oct 22, 2015 9:00 pm

For your benefit I've commented the code you attached and I'm happy to explain comments or answer any questions you have, but the code you've posted still doesn't actually create a pop up. If I had to guess, the page at 8x8.com actually creates the popup using javascript or jquery when it's accessed, or your system is doing it with code that they've encapsulated out of view.

Code: Select all

<?php
// means to populate $queue variable
// and will throw an error for undefined index "Queue" if it's not populated
$queue=$_POST["Queue"];

// incorrectly handles the failure mentioned above, too late to stop the error
if (is_null($queue)) {
    printf('No queue data was given');
}
// unnecessary else clause which could be avoided completely by exiting after
// output above
else {
    // switch case to add unnecessary complexity to an already unneeded condition
    switch ($queue) {
        
        // redirects to 8x8.com if $queue contains 'test Environment'
        // doesn't exit execution, just breaks out of switch
        // which could cause code after the switch to still execute
        case "test Environment":
            header("Location: http://www.8x8.com");
        break;
        
        // on anything else, uses javascript to close the window
        // assuming they have javascript enabled 
        default:
        
            // why use printf above when no additional formatting is necessary
            // and then use echo here?
            echo "<script>window.close();</script>";
        break;
    }
}
?>


SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 7:45 am

sean, that "code" is the entire php file and it works as intended. I have no idea how, nor do I have access to, the back end of the phone system. All I know is I enter specific information into a form in the phone system's configuration screen, save it, and it calls that php file, passing various information to it, one being the "Queue" (which is the name of the phone queue that specific calls come in on).

Att'd is a screen grab of where I put the necessary info to cause the window to popup and run the php file.
ScreenPop1.png
ScreenPop1.png (23.94 KiB) Viewed 2077 times
ScreenPop2.png
ScreenPop2.png (22.62 KiB) Viewed 2077 times
Thanks for your assistance.

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 7:50 am

Forgot to mention, the page at 8x8.com is just used for testing. This could be any web page. We will eventually be creating our own page that will "popup". It will serve as a "notification" to our agents that answer the phones that a specific type of call is coming in and it should be routed to a specific agent.

The "test Environment" is also a "test" que that we've created within our phone system for purposes of getting all this to work as we need it to. Once it works under a test environment, we'll then simply change the queue to the live one.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 8:30 am

I promise I'm trying to help and my critical comments on the code were to explain that it doesn't actually do what you think it does, and it isn't really even doing what it IS doing properly. I'm not condemning you or your effort, just trying to free you from the misconception that the code "works as intended" which is based on a misunderstanding of both the code's function and intent.

Ok, let's move forward. step one should be to fix the php you've already shared. It won't answer your question, but it will give you more exposure to the language, and proper implementation, and will potentially avoid growing error logs assuming your server is logging the errors it's obviously not displaying.

Replace your code with this:

Code: Select all

if (empty($_POST['Queue']) === false){
    $queue = $_POST['Queue'];
    if ($queue == 'test Environment'){
        header("Location: http://www.8x8.com");
        exit;
    }
   echo "<script>window.close();</script>";
} else {
    echo 'No queue data was given';
}
Even without any intimate knowledge of the language, the flow of execution should be clearer, and it avoids the bad practices pointed out in the original which are definitely generating errors even if your server is not configured to report or log them.

Now in regards to your actual question regarding the popup window; is the code that we've been discussing the contents of the ScreenPop.htm file? If not, then we probably need to dive into the html and javascript in that file.

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 9:35 am

Thanks a ton for helping. I tried your code, the window doesn't go anywhere, it just opens and closes.

That said, I have found a solution and here it is ....

Code: Select all


<?php

header("X-XSS-Protection: 0");

$queue=$_POST["Queue"];


if (is_null($queue)) {
                printf('No queue data was given');

}

else {
switch ($queue) {
case "test Environment":
echo "<script>self.resizeTo(640,480);</script>";
echo "this is working";

break;
default:
echo "this isn't working";
echo "<script>window.close();</script>";
break;
}
}
?>

<html>
<head>
<title>My first PHP Page</title>
</head>
<body>
This is normal HTML code

</body>
</html>
As mentioned, we would eventually be creating our own "page" so, the above code, if queue="test Environment" (or whatever), it resets the window size, skips past the rest of the php code and carries on with the html. It will be there that we will put the html code for what we want to display in the popup window.

If the queue is something other, it hits the "default" and closes the window.

While the code may be crude, it works.

FWIW, the original code I displayed was supplied to us by the programmers at Bell Canada (http://www.bell.ca/) who provide the phone system and who developed the phone configuration manager, a part of which I showed in the above screen shots. Unfortunately they don't go beyond that point without us having to pay for custom consulting.

I appreciate your time and effort; however, I feel my question is now resolved.

Thanks again.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 11:06 am

SnoopyDawg wrote:the window doesn't go anywhere, it just opens and closes.
That means that $_POST['Queue'] is being passed, but does not contain the literal string 'test Environment'
SnoopyDawg wrote: That said, I have found a solution and here it is ....
Your "solution" and I am only calling it that to avoid confusing you, persists the same convoluted logic and error causing practices as the first sample, but compounds it in a number of ways including echoing html and text to a page outside of your html tags, and attempting to explicitly disable cross site scripting protection in the user's browser.

I'm sure you won't even be reading this, but I'm writing it to hopefully help anyone else avoid using that code. On the bright side if they're too stupid and lazy to look up how to use $_POST variables they probably won't land here from the search page.

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 11:47 am

seandisanti wrote:
SnoopyDawg wrote:the window doesn't go anywhere, it just opens and closes.
That means that $_POST['Queue'] is being passed, but does not contain the literal string 'test Environment'
SnoopyDawg wrote: That said, I have found a solution and here it is ....
Your "solution" and I am only calling it that to avoid confusing you, persists the same convoluted logic and error causing practices as the first sample, but compounds it in a number of ways including echoing html and text to a page outside of your html tags, and attempting to explicitly disable cross site scripting protection in the user's browser.

I'm sure you won't even be reading this, but I'm writing it to hopefully help anyone else avoid using that code. On the bright side if they're too stupid and lazy to look up how to use $_POST variables they probably won't land here from the search page.
Of course I'm reading it and I'm always open to learn; however, when one thing works (the one I'm using) and another doesn't (the one you're offering), how do you (or anyone else for that matter) expect a guy like me to go with your offering??
seandisanti wrote:
SnoopyDawg wrote:the window doesn't go anywhere, it just opens and closes.
That means that $_POST['Queue'] is being passed, but does not contain the literal string 'test Environment'
If it contained the literal sting "test Environment" in the first instance, it contains it in the second instance. It's the ONLY one being used.

A slight modification to your code to see what happens....

Code: Select all

<?php
if (empty($_POST['Queue']) === false){
    $queue = $_POST['Queue'];
    if ($queue == 'test Environment'){
        /*header("Location: http://www.8x8.com");*/
		echo "This works";
        exit;
    }
   echo "This doesn't work";
   echo $queue;
} else {
    echo 'No queue data was given';
}
?>
The above code produces a window that says ...

"This doesn't workTest Environment"

Which PROVES that the literal string is being passed; however I do see where my initial test did not work and it has to do with "exact match" where you use the double equals '==' and my test string starts with a lower case 't'.

I'll do some more testing using your sample code.

BTW,
You're "stupid" and "lazy" inference is totally unwarranted.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 1:01 pm

Try this, it may clear things up.

Code: Select all

<?php
if (empty($_POST['Queue']) === false){
    echo '<pre>';
    print_r($_POST);
    $queue = $_POST['Queue'];
    if ($queue == 'test Environment'){
        /*header("Location: http://www.8x8.com");*/
      echo "This works";
        exit;
    }
   echo '"' . $queue . '" does not equal "test Environment"';
} else {
    echo 'No queue data was given';
}
?>
Of course I'm reading it and I'm always open to learn; however, when one thing works (the one I'm using) and another doesn't (the one you're offering), how do you (or anyone else for that matter) expect a guy like me to go with your offering??

Your prior post made it sound like you were done with the topic so I inferred that to be the case. As stated my goal is and was to help, and towards that end I pointed out objective flaws with the code you were using and then offered one solution (of many) that would clean it up a bit.
If it contained the literal sting "test Environment" in the first instance, it contains it in the second instance. It's the ONLY one being used.
Focus only on the current instance and don't make assumptions about your data without verbosely comparing your assumption and your actual value as I've done in the code in THIS post.

"This doesn't workTest Environment" ... Which PROVES
"test Environment" isn't the same as "test Environment" Which PROVES my statement correct actually, and the mixed capitalization I used came from your original snippet.
BTW,
You're "stupid" and "lazy" inference is totally unwarranted.
Technically they were aimed at a theoretical third party who also chose to ignore or misread each of my other posts, rather than making the cursory effort to look up any one of them, but I will not argue the point if you choose to take it personally.

If you'd like help with the rest of the new issues introduced by your most recent submission I am sincere about wanting to help if you're willing to read the constructive comments as diligently as the critical ones.

***edit*** removed unsupported [spoiler] tag

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 1:06 pm

OK, so I've managed to utilize your version of the code successfully.

Here's my end result...

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>***LANGUAGE CALL***</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#99FFFF" text="#000099">
<p><strong>On ODCC</strong><br>
  - Instruction 1<br>
  - Instruction 2<br>
  - Instruction 3<br>
  - etc… etc<br>
<p></p>
</body>
</html>



<?php


if (empty($_POST['Queue']) === false){
    $queue = $_POST['Queue'];
    if ($queue == 'test Environment'){
		echo "<script>self.resizeTo(748,720);</script>";
        exit;
    }
   echo "<script>window.close();</script>";

} else {
    echo 'No queue data was given';

}
?>


I tried having the html part below the php code but it wouldn't get to that point so I stuck it at the top.

You can see what I'm trying to do so if you have any further suggestions, I'm "all ears".

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 1:14 pm

There are other "variables" (for lack of a better word) being passed to the php file besides 'queue'. for example, there's one called 'Language'.
Language could equal German, Punjabi, Hindi, etc, etc...

I'd ultimately like to be able to display somewhere within the html body what the language being passed is.

For example, near the top of the body we might want it to say ...

ATTENTION ** There is a French language call coming in

-OR-

ATTENTION ** There is a Punjabi language call coming in

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 1:18 pm

It didn't work with the html tags below the php because the html tags you were echoing were not enclosed within the html document so they weren't being rendered with the page. You're kind of running into the same thing with your most recent submission, because you're closing the html element and then writing to the page.

For the page to render correctly, you want to have your doctype right up top as the first line, and then your html closing tag as the last thing the browser sees.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 1:29 pm

There are other "variables" (for lack of a better word) being passed to the php file besides 'queue'. for example, there's one called 'Language'.
Language could equal German, Punjabi, Hindi, etc, etc...

I'd ultimately like to be able to display somewhere within the html body what the language being passed is.

For example, near the top of the body we might want it to say ...

ATTENTION ** There is a French language call coming in

-OR-

ATTENTION ** There is a Punjabi language call coming in
Variables is the right word, you're good there. Those are POST variables coming in, and they're all available just like the queue one. If you have a list of variables you know you're going to use, you can do something like:

Code: Select all

<?php
// quit with message if nothing passed in POST
if (empty($_POST) === true){
    die('you need to give me something here');
}
// or define defaults:
$defaults = array(
    'Language' => 'English',
    'Queue' => 'test Environment'
    );
$variables = array_merge($defaults,$_POST);
echo "The next call for the {$variables['Queue']} queue is a(n) {$variables['Language']} call";
?>
***edit*** fixed typo

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 1:38 pm

seandisanti wrote:It didn't work with the html tags below the php because the html tags you were echoing were not enclosed within the html document so they weren't being rendered with the page. You're kind of running into the same thing with your most recent submission, because you're closing the html element and then writing to the page.

For the page to render correctly, you want to have your doctype right up top as the first line, and then your html closing tag as the last thing the browser sees.
ok, I tried some variations of that and all I wind up with is a blank page.

If I put all my html above my php, the thing works. I just can't display any of the php variables within ... no biggie at this time.

If I put all my html below the php nothing works and the page simply opens and then closes.

If I put the php just below the "doctype" code but before the opening html code I get a blank page.

If I put the php just below the "doctype" and "html" opening code I get a blank page.

as you can see I'm lost as I'm not a web programmer by any variation of the term. I am; however, a VB, and VBA programmer of over 20 years.

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 2:29 pm

Well, after a lot of "fiddling" around with it, I was able to get the html and the php code working together and displaying the content of the $queue variable where I needed it.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 2:58 pm

SnoopyDawg wrote:Well, after a lot of "fiddling" around with it, I was able to get the html and the php code working together and displaying the content of the $queue variable where I needed it.
Awesome, good job. Sorry I haven't been near a computer since my last post. One thing that may help if you're able is to view source on the generated page. In modern browsers a lot of times it will show syntax highlighting and will even flag miss matched tags, etc.

SnoopyDawg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Oct 21, 2015 3:08 pm

Fri Oct 23, 2015 3:02 pm

seandisanti wrote: Awesome, good job. Sorry I haven't been near a computer since my last post. One thing that may help if you're able is to view source on the generated page. In modern browsers a lot of times it will show syntax highlighting and will even flag miss matched tags, etc.
I can do that!

FWIW, I use Notepad++ and it highlights tags and code constructs so it's easy to see where things begin and end.

Any idea how I can run this kind of code in a debugger so I can do tracing, etc?

Thanks once again for all your help and "push".
Last edited by SnoopyDawg on Fri Oct 23, 2015 3:10 pm, edited 1 time in total.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 3:08 pm

No problem, I really am always happy to help and am glad we have gotten to the productive stage I almost gave up on

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Oct 23, 2015 3:17 pm

SnoopyDawg wrote:
seandisanti wrote: Awesome, good job. Sorry I haven't been near a computer since my last post. One thing that may help if you're able is to view source on the generated page. In modern browsers a lot of times it will show syntax highlighting and will even flag miss matched tags, etc.
I can do that!

FWIW, I use Notepad++ and it highlights tags and code constructs so it's easy to see where things begin and end.

Any idea how I can run this kind of code in a debugger so I can do tracing, etc?

Thanks once again for all your help and "push".
There are actually lots of options for debugging. You're not typically going to have step through debugging like you're used to with vba except for with your front end JavaScript. (Which you can access by pressing F12 in chrome or Firefox)

Another thing you can do is install WAMP for local debugging or you could do a virtual machine or vagrant box. WAMP is probably the easiest way to go but make sure you get the same version as you're running on your production server to avoid issues from feature discrepancies

Post Reply