royjm
royjm

Reputation: 107

Why are my popup page functions not working?

I have a PHP calendar application that presents a schedule in table form. Each cell is selectable and has the following Jquery popup code behind it:

document.getElementsByTagName('body')[0].appendChild(f);
if (roleID > 2)
{
    window.open("","popUpForm","height=550,width=1050,toolbar=0,menubar=0,location=100,status=no,scrollbars=1,resizable=1,right=300,top=100");
    $('.jobTime').submit();
}

That works fine and presents a form called newJobForm.php in the popup window. The user enters selected times...and submits. If there is a conflict with the attempted schedule the window popup is closed and the form is reopened with with conflict information:

else
{
    $userSTime = new DateTime($params[0]);
    $userSTime = date_format($userSTime,'m/d/Y h:i a');
    $userETime = new DateTime($params[1]);
    $userETime = date_format($userETime,'m/d/Y h:i a');     
    $_SESSION['jbNum'] = $params[2];
    $_SESSION['asset'] = $params[4];
    $_SESSION['userSTime'] = $userSTime;
    $_SESSION['userETime'] = $userETime;
    $_SESSION['userDesc'] = trim($params[3]);
    $_SESSION['conJbNum'] = $msg['JobNum'];
    $_SESSION['conSTime'] = date_format($msg['StartTime'], 'm/d/Y h:i a');
    $_SESSION['conETime'] = date_format($msg['EndTime'], 'm/d/Y h:i a');
    $_SESSION['dueDate'] = $params[5];
    $_SESSION['comment'] = $params[6];
    $_SESSION['destination'] = $params[7];
    $_SESSION['jStat'] = $params[8];
    $_SESSION['ujob'] = $params[9];


    if ($_SESSION['recurring'] == 'n')
    {
        echo '<script>window.open("../forms/newJobForm.php","popUpForm","height=550,width=900,status=yes, scrollbars=1, toolbar=no,menubar=no,location=no");</script>';
        windowClose();      
        exit;
    }

This part works fine if the user makes the right corrections. However, if the user makes another scheduling error the form will close and redisplay information. At this point the close function quits working and the original parent page doesn't refresh. The parent page not refreshing I kind of understand, but the close function is simply that 'close'.

function windowClose()
{
    echo "<script>window.close()</script>";
}

what is going wrong? I can't really post the whole code because there is about 1000 lines of code, give or take... How can I get this to work properly?

Upvotes: 0

Views: 108

Answers (1)

royjm
royjm

Reputation: 107

Thanks to @CBroe I was able to solve this particular problem with the following modifications to my application. In my file where I check the user input for any conflicts with existing entries I changed:

if ($_SESSION['recurring'] == 'n')
    {
        echo '<script>window.open("../forms/newJobForm.php","popUpForm","height=550,width=900,status=yes, scrollbars=1, toolbar=no,menubar=no,location=no");</script>';
        windowClose();      
        exit;
    }

to:

if ($_SESSION['recurring'] == 'n')
{
    echo "<meta http-equiv='refresh' content='0;URL=../forms/newJobForm.php' target = '_SELF'/>";       
    exit;
}

Which simply refreshes the original form with the new conflict (if there is a conflict) information, or allows the user to submit or cancel the attempted action regardless of how many times they try. And to the form its self I added the following javascript make sure the user's actions refresh the parent page:

window.onunload = refreshParent;
function refreshParent() 
{
    window.opener.location.href = window.opener.location.href;
}

And the function that creates the initial popup was slightly modified like this:

document.getElementsByTagName('body')[0].appendChild(f);
if (roleID > 2)
{
    popUpForm = window.open("","popUpForm","height=550,width=1050,toolbar=0,menubar=0,location=100,status=no,scrollbars=1,resizable=1,right=300,top=100");
    $('.jobTime').submit();
}

I hope others will find this useful.

Upvotes: 1

Related Questions