Log in

View Full Version : Can anyone tell me please why the alert(you have a callback) wont fire??



Bikash
08-14-2013, 09:36 PM
<?php
include("AgentLockout.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Agent-Homepage</title>
<link href="http://192.168.10.157:1234/iFixo_CRM/CSS/style_legend.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function ValidateOnDelete()
{
var ret = confirm("Are you sure you want to delete the callback?");
if (ret == true)
{
event.returnValue = true;
}
else
{
event.returnValue = false;
}
}
</script>

</head>
<body bgcolor="#1BD6E0">
<table border="0" cellpadding="1" cellspacing="1" width="100%" >
<tr>
<td colspan="3" style="width:100%; height:5pt;"></td>
</tr>
<tr>
<td style="width:15%;"></td>
<td style="width:70%;">
<table border="1" cellpadding="1" cellspacing="1" width="90%" bgcolor="#FFFFFF">
<tr bgcolor="#9E9598">
<td>
<a href="http://192.168.10.157:1234/iFixo_CRM/Agent_Homepage.php">Home</a>
</td>
<td>
<a href="http://192.168.10.157:1234/iFixo_CRM/Create_Case.php">Create Case</a>
</td>
<td>
<a href="http://192.168.10.157:1234/iFixo_CRM/Create_Callback.php">Create Callback</a>
</td>
<td>
<a href="http://192.168.10.157:1234/iFixo_CRM/View_Callback.php">View Callback</a>
</td>
<td>
<a href="http://192.168.10.157:1234/iFixo_CRM/Agent_Change_Password.php">Change Password</a>
</td>
<td>
<a href="http://192.168.10.157:1234/iFixo_CRM/Agent_Logout.php">Logout</a>
</td>
</tr>
<tr>
<td colspan="6" style="width:100%;">
<table width="100%">
<tr>
<td align="right" valign="top" width="28%">Agent Name : </td>
<td align="right" valign="top" width="2%"></td>
<td align="left" valign="top" width="70%"><?php echo $agent_name; ?></td>
</tr>
<tr>
<td colspan="3" width="100%">
<table border="0" cellspacing="1" cellpadding="1" width="100%" >
<tr>
<td align="right" valign="top" width="15%" >
<div class="foo" style="background-color:#FFFFFF;"></div>
</td>
<td align="left" valign="top" width="30%">Existing Customer</td>
<td align="center" valign="top" width="10%"></td>
<td align="right" valign="top" width="15%">
<div class="foo" style="background-color:#F2CBC9;"></div>
</td>
<td align="left" valign="top" width="30%">Prospect Customer</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" width="100%">
<table border="1" cellspacing="1" cellpadding="1" width="100%" >
<tr bgcolor="#9E9598">
<td align="center" valign="top" width="20%">Customer Name </td>
<td align="center" valign="top" width="20%">Callback Date </td>
<td align="center" valign="top" width="20%">Callback Time </td>
<td align="center" valign="top" width="20%">Contact Number </td>
<td align="center" valign="top" width="10%">Edit </td>
<td align="center" valign="top" width="10%">Delete </td>
</tr>
<?php
include("config.php");
date_default_timezone_set('Asia/kolkata');
$sql = "Select * from callback where userid='$agent_id'";
$result = mysql_query($sql);
while($res = mysql_fetch_array($result))
{
if($res[6] == date("h:i:s"))
{
echo "<script>alert(\"you have a callback\");</script>";
}
if($res[7] == '0')
{
?>
<tr>
<td align="center" valign="top" width="20%"><?php echo $res[4]; ?></td>
<td align="center" valign="top" width="20%"><?php echo $res[5]; ?></td>
<td align="center" valign="top" width="20%"><?php echo $res[6]; ?></td>
<td align="center" valign="top" width="20%"><?php echo $res[9]; ?></td>
<td align="center" valign="top" width="10%"><a href="editcallback.php?id=<?= $res[0];?>">edit</a></td>
<td align="center" valign="top" width="10%"><a href="deletecallback.php?id=<?=$res[0];?>" onclick="ValidateOnDelete()">delete</a></td>
</tr>
<?php }
else
{
?>
<tr bgcolor="#F2CBC9">
<td align="center" valign="top" width="20%"><?php echo $res[4]; ?></td>
<td align="center" valign="top" width="20%"><?php echo $res[5]; ?></td>
<td align="center" valign="top" width="20%"><?php echo $res[6]; ?></td>
<td align="center" valign="top" width="20%"><?php echo $res[9]; ?></td>
<td align="center" valign="top" width="10%"><a href="editcallback.php?id=<?= $res[0];?>">edit</a></td>
<td align="center" valign="top" width="10%"><a href="deletecallback.php?id=<?=$res[0];?>" onclick="ValidateOnDelete()">delete</a></td>
</tr>
<?php
}
}
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td style="width:15%;"></td>
</tr>
</table>
</body>
</html>

keyboard
08-14-2013, 09:53 PM
If you're never getting that alert, are you sure that if statement is firing?


if($res[6] == date("h:i:s"))
{
echo "<script>alert(\"you have a callback\");</script>";
}
Will $res[6] ever be equal to date("h:i:s")?

Bikash
08-14-2013, 10:30 PM
sorry i didn't get your point...i'm a newbie in php..can you please suggest me what should i do???

traq
08-14-2013, 11:00 PM
Since that line of code is inside a conditional block ( if ), you should check to see if it is even being run. The simplest way would be to check your output (i.e., the HTML markup) and see if that line is even printed.

If it's not, then your condition ( $res[6] == date( "h:i:s" ) ) is evaluating to false - if those two values should be equivalent, you can investigate what is causing them not to be.

If it is, then it's a javascript problem - we'd need to see your live page.

Bikash
08-14-2013, 11:05 PM
hey traq... thank you for taking out the time and trying to help me out..about "we'd need to see your live page." i cannot, as the live page is hosted on localhost..
and the if condition is returning false..

<?php
include("config.php");
date_default_timezone_set('Asia/kolkata');
$sql = "select * from callback where userid='1'";
$result = mysql_query($sql);
while($res = mysql_fetch_array($result))
{
if($res[6] == date("h:i:s"))
{
echo "ok";
}
else
{
echo "ko";
}
}
?>
the output of the above code is -----> kokoko
it got repeated three times as cuz the database callback had three diff datas in it..
nOw, what to do??

Bikash
08-15-2013, 12:06 AM
okay so i made a litle breakthorugh with the code...all i now need to do is refresh the page every sec using setinterval()..can you help me with this??
<?php
include("config.php");
date_default_timezone_set('Asia/kolkata');
$time = date("h:i:00");
echo $time;

$sql = "select * from callback where userid='1'";
$result = mysql_query($sql);
while($res = mysql_fetch_array($result))
{
if($res[6] == $time)
{
echo "ok";
echo "<script>alert(\"you have a callback\");</script>";
}
else
{
echo "ko";
}
}

the above code does output ok and displays alert when manually page is refreshed...

traq
08-15-2013, 01:08 AM
okay so i made a litle breakthorugh with the code...all i now need to do is refresh the page every sec using setinterval()..can you help me with this??

With what? You haven't shown us any code involving setInterval. Are you asking how to use setInterval (https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval)?

Also, have you solved your earlier problem? You don't appear to have changed anything substantial in the code you posted. Was it simply not the correct time of day to work?



about "we'd need to see your live page." i cannot, as the live page is hosted on localhost.

You can use an online service like jsfiddle (http://jsfiddle.net) or codepen (http://codepen.io).

Bikash
08-19-2013, 04:50 PM
With what? You haven't shown us any code involving setInterval. Are you asking how to use setInterval (https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval)?

Also, have you solved your earlier problem? You don't appear to have changed anything substantial in the code you posted. Was it simply not the correct time of day to work?




You can use an online service like jsfiddle (http://jsfiddle.net) or codepen (http://codepen.io).



<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>
<script>
var myVar=setInterval(function(){myTimer()},1000);

function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}
</script>

</body>
</html>

this mytimer() shows my system time..how can i now compare it to my $res[6]??
when they both are equal they will display a popup if not they wont do nything
yes i do need this piece of code..so will be glad if nyone can help me with this

traq
08-20-2013, 01:38 AM
this mytimer() shows my system time..how can i now compare it to my $res[6]??
when they both are equal they will display a popup if not they wont do nything

Is this intended only for your local machine? Or are you developing it for a live website?

There seems to be a bit of understanding you're missing: PHP happens on the server, while the user's local system clock... does not :).

You would need to poll the server every second (e.g., via AJAX (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)). The server would then run the PHP script, which would query the database, compare the two values, and then return an appropriate value (your "popup" if successful; probably nothing otherwise). Then, you would use javascript to do something with that response - e.g., display it in a new window.

There are many problems with this approach, not the least of which is efficiency. It's like sitting there, hitting the "refresh" button every second - if you have a significant number of users, you'll effectively launch a DOS attack on yourself. (I've actually done this before - with a script that posts live results to a darts tournament. It goes bad a lot faster than you'd imagine.) Querying the DB so often is also horribly inefficient.

Next would be reliability - what if the system clock is not accurate? What if there is extra latency in the AJAX request? You might skip the matching time, or accidentally return "true" at the wrong time. How important is this?

You might change your approach a bit - simply put the value of $res[6], and the popup URL, in the JS on the original page request. Let JS wait for the right time, and then display the popup.

Some thing like this:
/* "zerosec" is retrieved from your DB and printed in the JS by php. */
var zerotime = "06:45:00";

setInterval(
/* this function will run... */
function(){
/* this is a _current_ date object */
var countdown = new Date();
/* get the time component */
var now = countdown.toLocaleTimeString('en-US',{hour12:false});
/* compare to zerotime */
if( zerotime === now ){
/* launch your popup */
}
}
/* ...once every second */
,1000
);

working example on jsfiddle (http://jsfiddle.net/traq/9VGwe/)

Bikash
08-21-2013, 10:39 PM
Is this intended only for your local machine? Or are you developing it for a live website?

There seems to be a bit of understanding you're missing: PHP happens on the server, while the user's local system clock... does not :).

You would need to poll the server every second (e.g., via AJAX (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)). The server would then run the PHP script, which would query the database, compare the two values, and then return an appropriate value (your "popup" if successful; probably nothing otherwise). Then, you would use javascript to do something with that response - e.g., display it in a new window.

There are many problems with this approach, not the least of which is efficiency. It's like sitting there, hitting the "refresh" button every second - if you have a significant number of users, you'll effectively launch a DOS attack on yourself. (I've actually done this before - with a script that posts live results to a darts tournament. It goes bad a lot faster than you'd imagine.) Querying the DB so often is also horribly inefficient.

Next would be reliability - what if the system clock is not accurate? What if there is extra latency in the AJAX request? You might skip the matching time, or accidentally return "true" at the wrong time. How important is this?

You might change your approach a bit - simply put the value of $res[6], and the popup URL, in the JS on the original page request. Let JS wait for the right time, and then display the popup.

Some thing like this:
/* "zerosec" is retrieved from your DB and printed in the JS by php. */
var zerotime = "06:45:00";

setInterval(
/* this function will run... */
function(){
/* this is a _current_ date object */
var countdown = new Date();
/* get the time component */
var now = countdown.toLocaleTimeString('en-US',{hour12:false});
/* compare to zerotime */
if( zerotime === now ){
/* launch your popup */
}
}
/* ...once every second */
,1000
);

working example on jsfiddle (http://jsfiddle.net/traq/9VGwe/)

Hey Traq,
I Tried and tried and kept on failing probably i was heading on a wrong direction,it can be done through AJAX, so can you help me get this done??
1)Check if the time stored in database is equal to system time or not, if yes,then it will create an alert,if not then it wont do anything.
2)But the catch is here, it will have to check the script continuously as to without disturbing the page state.

traq
08-22-2013, 02:57 AM
Hey Traq,
I Tried and tried and kept on failing probably i was heading on a wrong direction,it can be done through AJAX, so can you help me get this done??
1)Check if the time stored in database is equal to system time or not, if yes,then it will create an alert,if not then it wont do anything.
2)But the catch is here, it will have to check the script continuously as to without disturbing the page state.

There's a good introductory AJAX tutorial on MDN (https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started). To handle the ajax request, you're going to have to create a script (or change the current script, to determine if the request is via AJAX and respond accordingly) that *only* queries the database, compares the times, and returns the result.