Link to home
Start Free TrialLog in
Avatar of bpgillett
bpgillett

asked on

Need to refresh the php contained within a div

i have a calendar page that has a popup contained in a div.  the div has php code to include 'scheduler.php' which retrieves data from MySQL.  an onClick call launches the popup.  i need 'scheduler.php' to refresh with the variable that defines from which square the user is launching the popup.  

i would then use that variable in a MySQL query.  the variable is in my popup opener script as 's_box.value'.  i have successfully used ajax to pass this variable to a backend php script for writing to the database.  but i can't figure out how to make scheduler.php in the popup refresh with the updated php variable because the php script is already loaded when the main page loads.
//javascript popup launcher
function fireMyPopup_2(the_session) {
var session = the_session;
 document.getElementById("mypopup2").style.display = "block";
//set hidden 'session' variable in form
var s_box = document.getElementById('session_box');
  s_box.value = session;
  document.schedule.reset();
}
//onClick handler that passes calendar box variable to javascript
<a href="#" onClick='fireMyPopup_2(<?php $session = $i+1 . '.3'; echo $session; ?>)'>
 //the div
<div id='mypopup2' name='mypopup2'

Open in new window

Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

post entire code please
Avatar of bpgillett
bpgillett

ASKER

Thanks NerdsOfTech. Below is the complete code for both files.  Sort of long.

//calendar page
<?php require 'protected/admin_connect.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type='text/css'>
.dragme { cursor: move }
#mypopup2 {
border-left-style: solid;
border-left-color: black;
border-left-width: 1px;
border-right-style: solid;
border-right-color: black;
border-right-width: 1px;
border-bottom-style: solid;
border-bottom-color: black;
border-bottom-width: 1px;
}
</style>
<?php $color = "778899"; //color for inline css table borders ?>
 
		<script type="text/javascript" src="prototype.js"></script>
		<script>
 
			function sendRequest() {
			        var serializedForm = $('schedule').serialize()
				new Ajax.Request("scheduler_backend.php", 
					{ 
					method: 'post', 
					postBody: serializedForm,
					onComplete: showResponse 
					});
				}
 
			function showResponse(req){
			var respective_div = $F("session_box");
				document.getElementById(respective_div).innerHTML= req.responseText;
			}
 
function fireMyPopup_2(the_session) {
var session = the_session;
 document.getElementById("mypopup2").style.display = "block";
//set hidden 'session' variable in form
var s_box = document.getElementById('session_box');
  s_box.value = session;
  document.schedule.reset();
}
 
function closeScheduler() {
document.getElementById("mypopup2").style.display="none"
}
 
//movable popUp
var ie = document.all;
var nn6 = document.getElementById &&! document.all;
 
var isdrag = false;
var x, y;
var dobj;
 
function movemouse( e ) {
  if( isdrag ) {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}
 
function selectmouse( e ) {
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";
 
  while (fobj.tagName != topelement && fobj.className != "dragme") {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }
 
  if (fobj.className=="dragme") {
    isdrag = true;
    dobj = document.getElementById("mypopup2");
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}
 
document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");
</script>
 
</head>
 
<body>
<div id='mypopup2' name='mypopup2' style='width: 450; display:none; background: #F4F4F4; position: absolute; top: 150px; left: 50px;'>
<table width='450' cellpadding='0' cellspacing='0' border='0'>
<tr>
<td><img height='23' width='426' src='images/scheduler_title.gif' class='dragme'></td>
<td><a href='javascript:closeScheduler();'><img height='23' width='24' src='images/scheduler_close.gif' border='0'></a></td>
</tr>
<tr><td colspan='2'>
<?php 
//set strings based on the selected calendar
//after july 1
$year_minus_2 = date('Y') - 1;
$year_minus_1 = date('Y') - 0;
$year_curr = date('Y') + 1;
$year_plus_1 = date('Y') + 2;
 
/* before july 1
$year_minus_2 = date('Y') - 2;
$year_minus_1 = date('Y') - 1;
$year_curr = date('Y');
$year_plus_1 = date('Y') + 1;
*/
 
if($y=='prev'){
$calendar_table = 'calendar_ajax_prev';
$calendar_display = $year_minus_2 . "-" . $year_minus_1;
$year = $year_minus_2;
}
if($y=='curr'){
$calendar_table = 'calendar_ajax';
$calendar_display = $year_minus_1 . "-" . $year_curr;
$year = $year_minus_1;
}
if($y=='next'){
$calendar_table = 'calendar_ajax_next';
$calendar_display = $year_curr . "-" . $year_plus_1;
$year = $year_curr;
}
 
include 'scheduler.php'; ?>
</td></tr>
</table>
</div>
<?php
//function for putting mysql table data into array
function mysql_fetch_rowsarr($result, $numass=MYSQL_BOTH) {
  $j=0;
  $keys=array_keys(mysql_fetch_array($result, $numass));
  mysql_data_seek($result, 0);
    while ($row = mysql_fetch_array($result, $numass)) {
      foreach ($keys as $speckey) {
        $got[$j][$speckey]=$row[$speckey];
      }
    $j++;
    }
  return $got;
}
 
//get calendar data for displaying previously set sessions
	$result = mysql_query("SELECT attending_staff, resident_staff, residents FROM $calendar_table") or die ("Unable to Make the Query:" . mysql_error() ); 
// put results into an array
	for($j = 0; $calendar_array[$j] = mysql_fetch_assoc($result); $j++) ;
// delete last empty one
array_pop($calendar_array);
 
//find which day in july is the 1st wednesday
if (date("l", mktime(0,0,0,7,1,$year)) == "Wednesday"){$first_wednesday = "01";}
if (date("l", mktime(0,0,0,7,2,$year)) == "Wednesday"){$first_wednesday = "02";}
if (date("l", mktime(0,0,0,7,3,$year)) == "Wednesday"){$first_wednesday = "03";}
if (date("l", mktime(0,0,0,7,4,$year)) == "Wednesday"){$first_wednesday = "04";}
if (date("l", mktime(0,0,0,7,5,$year)) == "Wednesday"){$first_wednesday = "05";}
if (date("l", mktime(0,0,0,7,6,$year)) == "Wednesday"){$first_wednesday = "06";}
if (date("l", mktime(0,0,0,7,7,$year)) == "Wednesday"){$first_wednesday = "07";}
 
//set base date for calendar
$basedate1 = strtotime("$first_wednesday Jul $year");
$basedate2 = strtotime("+7 days", $basedate1);
$basedate3 = strtotime("+7 days", $basedate2);
$basedate4 = strtotime("+7 days", $basedate3);
 
//now, get dates from base date and organize into 4 arrays (one array for each week of every block); this is for calendar display
$date_column1[] = $basedate1;
$date_column2[] = $basedate2;
$date_column3[] = $basedate3;
$date_column4[] = $basedate4;
for($i=0; $i<13; $i++){
//column #1
$date_column1[] = strtotime("+28 days", $date_column1[$i]);
 
//column #2
$date_column2[] = strtotime("+28 days", $date_column2[$i]);
 
//column #3
$date_column3[] = strtotime("+28 days", $date_column3[$i]);
 
//column #4
$date_column4[] = strtotime("+28 days", $date_column4[$i]);
}
$i = 0;
?>
 
<font color="#006699" size="4" face="Arial, Helvetica, sans-serif"><strong>Calendar <?php echo $calendar_display; ?></strong></font><br><br>
<font color="#006699" size="2" face="Arial, Helvetica, sans-serif"><?php if ($y=="prev"){echo "<strong>";} ?><a href="index.php?link=calendar&y=prev" target="_self" style="text-decoration: none; color:blue;"><?php echo $year_minus_2 . "-" . $year_minus_1; ?></a><?php if ($y=="prev"){echo "</strong>";} ?> 
<font color="#999999">|</font> <?php if ($y=="curr"){echo "<strong>";} ?><a href="index.php?link=calendar&y=curr" target="_self" style="text-decoration: none; color:blue;"><?php echo $year_minus_1 . "-" . $year_curr; ?></a><?php if ($y=="curr"){echo "</strong>";} ?> 
<font color="#999999">|</font> <?php if ($y=="next"){echo "<strong>";} ?><a href="index.php?link=calendar&y=next" target="_self" style="text-decoration: none; color:blue;"><?php echo $year_curr . "-" . $year_plus_1; ?></a><?php if ($y=="next"){echo "</strong>";} ?></font><br>
 
<?php
//create calendar
echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: solid 1px #$color;\">\n";
echo "<tr bgcolor=\"#E4E4E4\"><td style=\"border: solid 1px #$color;\"><strong><font color=\"#666666\" size=\"1\" face=\"Arial, Helvetica, sans-serif\">&nbsp;BLOCK&nbsp;</font></strong></td>";
echo "<td style=\"border: solid 1px #$color;\"><strong><font color=\"#666666\" size=\"1\" face=\"Arial, Helvetica, sans-serif\"><p align=\"center\">WEEK 1</p></font></strong></td>";
echo "<td style=\"border: solid 1px #$color;\"><strong><font color=\"#666666\" size=\"1\" face=\"Arial, Helvetica, sans-serif\"><p align=\"center\">WEEK 2</p></font></strong></td>";
echo "<td style=\"border: solid 1px #$color;\"><strong><font color=\"#666666\" size=\"1\" face=\"Arial, Helvetica, sans-serif\"><p align=\"center\">WEEK 3</p></font></strong></td>";
echo "<td style=\"border: solid 1px #$color;\"><strong><font color=\"#666666\" size=\"1\" face=\"Arial, Helvetica, sans-serif\"><p align=\"center\">WEEK 4</p></font></strong></td></tr>";
 
//loop
//first set the counter for getting items from calendar array
$k=0;
for ( $counter = 0; $counter < 13; $counter++) {
?>
 
<tr> 
    <td bgcolor="#E4E4E4" align="center" style="border: solid 1px #<?php echo $color; ?>;"><strong><font color="#666666" size="1" face="Arial, Helvetica, sans-serif"><?php echo $counter+1; ?></font></strong></td>
 
  <td style="border: solid 1px #<?php echo $color; ?>;" valign="top">
  <table border="0" cellspacing="1" cellpadding="1" width="100%">
      <tr> 
        <td valign="top"><font color="#666666" size="1" face="Arial, Helvetica, sans-serif"><strong><?php echo date("M j, Y", $date_column1[$i]); ?></strong></font></td>
        <td valign="top"><div align="right"><font color="#990000" size="1" face="Arial, Helvetica, sans-serif"><a href="#" onClick='fireMyPopup_2(<?php $session = $i+1 . '.1'; echo $session; ?>)'><img src="images/modify_calendar.gif" width="15" height="15" border="0"></a></font></div></td>
      </tr>
      <tr> 
        <td><font color="#993333" size="2" face="Arial, Helvetica, sans-serif"> 
          <div id="<?php $session = $i+1 . '.1'; echo $session; ?>"> 
            <?php
//get session info from calendar array into individual arrays
$attending_staff_array = unserialize($calendar_array[$k]['attending_staff']);
$resident_staff_array = unserialize($calendar_array[$k]['resident_staff']);
$residents_array = unserialize($calendar_array[$k]['residents']);
//implode these arrays into a string and display
if($attending_staff_array){
$display_attending_staff = implode("<br>", $attending_staff_array);
echo "<font color=\"#990000\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_attending_staff</font><br>";
}else{echo "<br>";}
if($resident_staff_array){
$display_resident_staff = implode("<br>", $resident_staff_array);
echo "<font color=\"#006600\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_resident_staff</font><br>";
}else{echo "<br>";}
if($residents_array){
$display_residents = implode("<br>", $residents_array);
echo "<font color=\"#336699\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_residents</font><br>";
}else{echo "<br>";}
?>
          </div>
          </font></td>
      </tr>
    </table>
  </td>
    <td style="border: solid 1px #<?php echo $color; ?>;" valign="top">
  <table border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td valign="top"><font color="#666666" size="1" face="Arial, Helvetica, sans-serif"><strong><?php echo date("M j, Y", $date_column2[$i]); ?></strong></font></div></td>
  <td valign="top"><div align="right"><font color="#990000" size="1" face="Arial, Helvetica, sans-serif"><a href="#" onClick='fireMyPopup_2(<?php $session = $i+1 . '.2'; echo $session; ?>)'><img src="images/modify_calendar.gif" width="15" height="15" border="0"></a></font></td></tr>
  <tr><td><font color="#993333" size="2" face="Arial, Helvetica, sans-serif"><div id="<?php $session = $i+1 . '.2'; echo $session; ?>">
  <?php
//get session info from calendar array into individual arrays
$attending_staff_array = unserialize($calendar_array[$k+1]['attending_staff']);
$resident_staff_array = unserialize($calendar_array[$k+1]['resident_staff']);
$residents_array = unserialize($calendar_array[$k+1]['residents']);
//implode these arrays into a string and display
if($attending_staff_array){
$display_attending_staff = implode("<br>", $attending_staff_array);
echo "<font color=\"#990000\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_attending_staff</font><br>";
}else{echo "<br>";}
if($resident_staff_array){
$display_resident_staff = implode("<br>", $resident_staff_array);
echo "<font color=\"#006600\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_resident_staff</font><br>";
}else{echo "<br>";}
if($residents_array){
$display_residents = implode("<br>", $residents_array);
echo "<font color=\"#336699\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_residents</font><br>";
}else{echo "<br>";}
?>  
  </div></font></td></tr>
  </table>
  </td>  
    <td style="border: solid 1px #<?php echo $color; ?>;" valign="top">
  <table border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td valign="top"><font color="#666666" size="1" face="Arial, Helvetica, sans-serif"><strong><?php echo date("M j, Y", $date_column3[$i]); ?></strong></font></div></td>
  <td valign="top"><div align="right"><font color="#990000" size="1" face="Arial, Helvetica, sans-serif"><a href="#" onClick='fireMyPopup_2(<?php $session = $i+1 . '.3'; echo $session; ?>)'><img src="images/modify_calendar.gif" width="15" height="15" border="0"></a></font></td></tr>
  <tr><td><font color="#993333" size="2" face="Arial, Helvetica, sans-serif"><div id="<?php $session = $i+1 . '.3'; echo $session; ?>">
  <?php
//get session info from calendar array into individual arrays
$attending_staff_array = unserialize($calendar_array[$k+2]['attending_staff']);
$resident_staff_array = unserialize($calendar_array[$k+2]['resident_staff']);
$residents_array = unserialize($calendar_array[$k+2]['residents']);
//implode these arrays into a string and display
if($attending_staff_array){
$display_attending_staff = implode("<br>", $attending_staff_array);
echo "<font color=\"#990000\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_attending_staff</font><br>";
}else{echo "<br>";}
if($resident_staff_array){
$display_resident_staff = implode("<br>", $resident_staff_array);
echo "<font color=\"#006600\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_resident_staff</font><br>";
}else{echo "<br>";}
if($residents_array){
$display_residents = implode("<br>", $residents_array);
echo "<font color=\"#336699\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_residents</font><br>";
}else{echo "<br>";}
?>  
  </div></font></td></tr>
  </table>
  </td>
  
    <td style="border: solid 1px #<?php echo $color; ?>;" valign="top">
  <table border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td valign="top"><font color="#666666" size="1" face="Arial, Helvetica, sans-serif"><strong><?php echo date("M j, Y", $date_column4[$i]); ?></strong></font></div></td>
  <td valign="top"><div align="right"><font color="#990000" size="1" face="Arial, Helvetica, sans-serif"><a href="#" onClick='fireMyPopup_2(<?php $session = $i+1 . '.4'; echo $session; ?>)'><img src="images/modify_calendar.gif" width="15" height="15" border="0"></a></font></td></tr>
  <tr><td><font color="#993333" size="2" face="Arial, Helvetica, sans-serif"><div id="<?php $session = $i+1 . '.4'; echo $session; ?>">
  <?php
//get session info from calendar array into individual arrays
$attending_staff_array = unserialize($calendar_array[$k+3]['attending_staff']);
$resident_staff_array = unserialize($calendar_array[$k+3]['resident_staff']);
$residents_array = unserialize($calendar_array[$k+3]['residents']);
//implode these arrays into a string and display
if($attending_staff_array){
$display_attending_staff = implode("<br>", $attending_staff_array);
echo "<font color=\"#990000\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_attending_staff</font><br>";
}else{echo "<br>";}
if($resident_staff_array){
$display_resident_staff = implode("<br>", $resident_staff_array);
echo "<font color=\"#006600\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_resident_staff</font><br>";
}else{echo "<br>";}
if($residents_array){
$display_residents = implode("<br>", $residents_array);
echo "<font color=\"#336699\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$display_residents</font><br>";
}else{echo "<br>";}
?>  
  </div></font></td></tr>
  </table>
  </td>
  </tr>
<?php
//increment counter for array keys
$i= $i+1;
//adjust counter for getting items correctly from the calendar_array
$k = $k+4;
}
 
//'modify' or 'view only' option
 
 	echo "</table>\n";
 
?>
<p>&nbsp;</p>
</body>
</html>

Open in new window

the submit form would not let me post so much.  so here is the php file that needs refreshing with the variable.  Thanks again
<?php include 'protected/admin_connect.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
		<form id="schedule" name="schedule" action="" method="post" onSubmit="return false;">
  <table border="0" cellpadding="1" cellspacing="3" bgcolor="#F4F4F4">
    <tr bgcolor="#CCCCCC"> 
      <td><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">Attending 
        Staff <?php echo $calendar_box; ?></font></td>
      <td><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">Resident 
        Staff</font></td>
      <td><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">Residents</font></td>
    </tr>
    <tr> 
      <td><table border="0" cellspacing="0" cellpadding="0">
          <?php 
	  //attending staff
	  $result = mysql_query("SELECT first_name, last_name, id FROM users WHERE pgy='1000' ORDER BY first_name") or die ("Unable to Make the Query:" . mysql_error() ); 
    if ($myrow = mysql_fetch_array($result)) {
 
do {
 
  $name_formatted = "$myrow[first_name] $myrow[last_name]";
  echo"<tr><td><input name=\"attending_staff[]\" type=\"checkbox\" id=\"attending_staff\" value=\"$name_formatted\"></td><td><font color=\"#333333\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$myrow[first_name] $myrow[last_name]</font></td></tr>";    
	 
	  } while ($myrow = mysql_fetch_array($result));
    } else {
 
      // no records to display
      echo "";	
    }
	?>
        </table></td>
      <td><table border="0" cellspacing="0" cellpadding="0">
          <?php //resident staff
	  $result = mysql_query("SELECT first_name, last_name, id FROM users WHERE pgy !='1000' && (priv = 'a' || priv = 'h') ORDER BY first_name") or die ("Unable to Make the Query:" . mysql_error() ); 
    if ($myrow = mysql_fetch_array($result)) {
 
do {
 
  $name_formatted = "$myrow[first_name] $myrow[last_name]";
  echo"<tr><td><input name=\"resident_staff[]\" type=\"checkbox\" id=\"resident_staff\" value=\"$name_formatted\"></td><td><font color=\"#333333\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">$myrow[first_name] $myrow[last_name]</font></td></tr>";    
	 
	  } while ($myrow = mysql_fetch_array($result));
    } else {
 
      // no records to display
      echo "";	
    }
	?>
        </table></td>
      <td><select name="residents[]" size="10" multiple id="residents">
          <?php
		//residents				
   $result = mysql_query("SELECT first_name, last_name, id FROM users WHERE pgy != '1000'ORDER BY last_name",$db) or die ("Unable to Make the Query:" . mysql_error() ); 
    if ($myrow = mysql_fetch_array($result)) {
 
do {
 
  $name_formatted_value = "$myrow[first_name] $myrow[last_name]";
    $name_formatted_option = "$myrow[last_name], $myrow[first_name]";
  printf("<OPTION VALUE=%s>%s</OPTION>", urlencode($name_formatted_value), $name_formatted_option);
      } while ($myrow = mysql_fetch_array($result));
    } else {
 
      // no records to display
      echo "";	
    }				
	?>
        </select></td>
    </tr>
    <tr> 
      <td colspan="3"><input name="submit" type="submit" onClick="sendRequest()" value="submit">
	   <input type="hidden" name="session_box" id="session_box">
	   <input type="hidden" name="calendar_table" id="calendar_table" value="<?php echo $calendar_table; ?>"></td>
    </tr>
  </table>
</form>
		
</body>
 
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of bpgillett
bpgillett

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial