aussiexile Posted June 29, 2008 Share Posted June 29, 2008 Hi this is a bit of a conglomerate of issue's and i will try and explain it as best i can. I dont know if this is the right section or not for this and if it isnt can a mod please move it tot he correct one??? thanx. ok now the code.... index.php <?php $title = 'Admin'; $db_host = 'localhost'; $db_user = 'local_user'; $db_pass = 'local_user'; $db_name = 'main_page'; if($_SERVER['REMOTE_ADDR'] == $ashAddr){ $table = 'ashlinks'; $iLink = ''; $onTemps = false; } if($_SERVER['REMOTE_ADDR'] == $nathAddr || isset($_GET['nath_away'])){ $table = 'nathlinks'; $iLink = 'http://www.pcpowerplay.com.au/forums/subscription.php?do=viewsubscription&folderid=all'; $onTemps = true; } include('inc/db_connect.php'); ?> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/JavaScript"> <!-- function setEngine(term, engine){ document.searchForm.action = engine + "="+ term; return true; } //--> </script> <link href="styles/style.css" rel="stylesheet" type="text/css"> </head> <body> <div class="leftside"><img src="img/left_side.jpg" /></div> <div class="rightside"><img src="img/right_side.jpg" /></div> <div class="header"><img src="img/header.jpg" /></div> <div class="main"> <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000"> <tr> <td id="linkHdr" colspan="3"> <a href="edit_links.php" target="mainFrame" class="glink">Edit Links</a> <?php $query = 'SELECT * FROM '.$table.' WHERE link_pos = "top" ORDER BY link_order'; $result = mysql_query($query, $db_link); while ($row = mysql_fetch_assoc($result)){ if($row['link_order'] != 0){ if($row['link_name'] == "Serials" || $row['link_name'] == "Movies"){ echo '<a href="'.$row['link_address'].'" target="mainFrame" class="glink">'.$row['link_name'].'</a>'; } else { ?> <a href="<?= $row['link_address'] ?>" class="glink"><?= $row['link_name'] ?></a> <?php } } } ?> <div class="search"> <form method="post" name="searchForm" action="" onSubmit="return setEngine(document.searchForm.searchTerm.value, document.searchForm.searchEngine.value)">Search <input type=text name="searchTerm" size=15 maxlength=255 value="" /> <select name="searchEngine"> <option value="http://isohunt.com/torrents/?ihq" selected="selected">isohunt.com</option> <option value="http://search.ebay.com.au/search/search.dll?from=R40&_trksid=m37&satitle">ebay.com.au</option> <option value="http://www.imdb.com/find?s=all&q">imdb.com</option> </select> <input class="go" type=submit value="Go" /> </form> </div> </td> </tr> <tr> <td width="14%" rowspan="4"> <div id="sectionLinks"> <?php $query = 'SELECT * FROM '.$table.' WHERE link_pos = "left" ORDER BY link_order'; $result = mysql_query($query, $db_link); while ($row = mysql_fetch_assoc($result)){ if($row['link_order'] != 0){ if($row['link_name'] == "Serials" || $row['link_name'] == "Movies"){ echo '<a href="'.$row['link_address'].'" target="mainFrame">'.$row['link_name'].'</a>'; } else { ?> <a href="<?= $row['link_address'] ?>"><?= $row['link_name'] ?></a> <?php } } } ?> </div> <!--<div class="cssnav2"><a href=""><img src="downbtn.jpg" /><span></span></a></div>--> </td> <td rowspan="4" width="69%"><iframe frameborder="0" name="mainFrame" width="100%" height="600px" src="<?= $iLink ?>"></iframe></td> <td width="16%"> <?php if($onTemps){ $list_ignore = array ('.','..'); $dir = 'templates'; $handle=opendir($dir); while ($file = readdir($handle)) { //$file is just the filename $path = $dir.'/'.$file; //$path is now the full path including the directory name if (is_dir($path) && !in_array($file,$list_ignore)) { echo '<div class="cssnav"><a href="'.$path.'"><img src="img/dossier.gif"/><span>'.$file.'</span></a></div>'; } } closedir($handle); } else { echo ' '; } ?> </td> </tr> <tr> <td width="1%"> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> </table> </div> </body> </html> edit_links.php <?php $title = 'Admin'; $db_host = 'localhost'; $db_user = 'local_user'; $db_pass = 'local_user'; $db_name = 'main_page'; if($_SERVER['REMOTE_ADDR'] == $ashAddr){ $table = 'ashlinks'; } if($_SERVER['REMOTE_ADDR'] == $nathAddr || isset($_GET['nath_away'])){ $table = 'nathlinks'; } include('inc/db_connect.php'); if(isset($_POST['form_sub'])){ $name = str_replace('"','\"',$_POST['link_name']); $link = str_replace('"','\"',$_POST['link_address']); $order = $_POST['link_order']; $pos = $_POST['link_pos']; $query = 'INSERT INTO '.$table.' ( link_name,link_address,link_order,link_pos ) VALUES ( "'.$name.'", "'.$link.'", "'.$order.'", "'.$pos.'" )'; if(!mysql_query($query, $db_link)){ echo mysql_error(); exit; } header('Location: '.$_SERVER['PHP_SELF']); exit; } if(isset($_POST['edit_id'])){ $name = str_replace('"','\"',$_POST['link_name'.$_POST['edit_id']]); $link = str_replace('"','\"',$_POST['link_address'.$_POST['edit_id']]); $order = $_POST['link_order'.$_POST['edit_id']]; $pos = $_POST['link_pos'.$_POST['edit_id']]; $query = 'UPDATE '.$table.' SET link_name = "'.$name.'", link_address = "'.$link.'", link_order = "'.$order.'", link_pos = "'.$pos.'" WHERE id = "'.$_POST['edit_id'].'" '; if(!mysql_query($query, $db_link)){ echo mysql_error(); exit; } header('Location: '.$_SERVER['PHP_SELF']); exit; } if(isset($_GET['delete_id'])){ $query = 'DELETE FROM '.$table.' WHERE id = "'.$_GET['delete_id'].'"'; if(!mysql_query($query, $db_link)){ echo mysql_error(); exit; } header('Location: '.$_SERVER['PHP_SELF']); exit; } function buildOrdNum($id,$pos,$table,$db_link,$rowID){ $list_ignore = array (); $query = 'SELECT link_order FROM '.$table.' WHERE link_pos = "'.$pos.'"'; $result = mysql_query($query, $db_link); $i = 0; while ($row = mysql_fetch_assoc($result)){ $list_ignore[$i] = $row['link_order']; $i++; } echo '<select name="link_order'.$rowID.'">'; for($a=0;$a<16;$a++){ if($a == $id){ $selected = ' selected="selected"'; } else{ $selected = ''; } if(!in_array($a,$list_ignore) || $a == $id || $a == 0){ echo "<option value=\"$a\"$selected>$a</option>"; } } echo '</select>'; } function buildPos($pos,$table,$db_link,$rowID){ $posNum = ''; switch($pos){ case "Top": $posNum = 0; break; case "Left": $posNum = 1; break; case "Right": $posNum = 2; break; case "Footer": $posNum = 3; break; } $posNames = array('Top','Left','Right','Footer'); echo '<select name="link_pos'.$rowID.'">'; for($a=0;$a<4;$a++){ if($a == $posNum){ $selected = ' selected="selected"'; } else{ $selected = ''; } echo "<option value=\"$posNames[$a]\"$selected>$posNames[$a]</option>"; } echo '</select>'; } ?> <table id="container" width="773" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="773" height="auto"> <?php if(isset($_GET['add']) || isset($_GET['edit_id'])){ $item_id = 0; $name = ''; $link = ''; $order = ''; $pos = ''; ?> <form id="form1" name="form1" method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> <input type="hidden" name="item_id" value="<?= $item_id ?>" /> <table width="467" border="0" cellpadding="3" cellspacing="1" bgcolor="#000000"> <tr> <td width="150" bgcolor="#FFFFFF">Name</td> <td width="302" bgcolor="#FFFFFF"><input name="link_name" type="text" class="textfield" id="link_name" value="<?= $name ?>" size="50" maxlength="255" /></td> </tr> <tr> <td bgcolor="#FFFFFF">Link </td> <td bgcolor="#FFFFFF"><input name="link_address" type="text" class="textfield" id="link_address" value="<?= $link ?>" size="50" maxlength="255" /></td> </tr> <tr> <td bgcolor="#FFFFFF">Order</td> <td bgcolor="#FFFFFF"><?php buildOrdNum(0,'Footer',$table,$db_link,'') ?></td> </tr> <tr> <td bgcolor="#FFFFFF">Position</td> <td align="left" bgcolor="#FFFFFF"><?php buildPos("",$table,$db_link,'') ?></td> </tr> <tr> <td bgcolor="#FFFFFF"> </td> <td align="right" bgcolor="#FFFFFF"><input name="form_sub" type="submit" id="form_sub" value="Submit" /></td> </tr> </table> </form> <br /> <?php } else { ?> <a href="<?= $_SERVER['PHP_SELF'] ?>?add=1">Add a new Link</a> <br /> <a href="javascript:history.go(-1)">Back</a> <br /> <h2>Top</h2> <form id="editForm" name="editForm" method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> <table width="62%" border="0" cellspacing="0" cellpadding="3"> <tr bgcolor="#E1E1E1"> <td width="120" bgcolor="#E1E1E1">Name</td> <td width="420" align="center" bgcolor="#E1E1E1">Link</td> <td width="37" align="center" bgcolor="#E1E1E1">Order</td> <td width="23" align="center" bgcolor="#E1E1E1">Pos</td> <td width="45" align="center" bgcolor="#E1E1E1">Update</td> <td width="39" align="center">Delete</td> </tr> <?php $query = 'SELECT * FROM '.$table.' WHERE link_pos = "top" ORDER BY link_order'; $result = mysql_query($query, $db_link); while ($row = mysql_fetch_assoc($result)){ ?> <tr> <td><input name="<?= 'link_name'.$row['id'] ?>" type="text" value="<?= $row['link_name'] ?>" size="20" /></td> <td align="center" valign="middle"><input name="<?= 'link_address'.$row['id'] ?>" size="70" type="text" value="<?= $row['link_address'] ?>" /></td> <td align="center" valign="middle"><?php buildOrdNum($row['link_order'],'top',$table,$db_link,$row['id']) ?></td> <td align="center" valign="middle"><?php buildPos($row['link_pos'],$table,$db_link,$row['id']) ?></td> <td align="center" valign="middle"><input type="image" name="edit_id" value="<?= $row['id'] ?>" src="img/b_tick.png" /></td> <td align="center" valign="middle"><a href="<?= $_SERVER['PHP_SELF'].'?delete_id='.$row['id'] ?>"><img src="img/b_delete.png" width="16" height="19" border="0" /></a></td> </tr> <?php } ?> </table> <h2>Left</h2> <table width="62%" border="0" cellspacing="0" cellpadding="3"> <tr bgcolor="#E1E1E1"> <td width="120" bgcolor="#E1E1E1">Name</td> <td width="420" align="center" bgcolor="#E1E1E1">Link</td> <td width="37" align="center" bgcolor="#E1E1E1">Order</td> <td width="23" align="center" bgcolor="#E1E1E1">Pos</td> <td width="45" align="center" bgcolor="#E1E1E1">Update</td> <td width="39" align="center">Delete</td> </tr> <?php $query = 'SELECT * FROM '.$table.' WHERE link_pos = "Left" ORDER BY link_order'; $result = mysql_query($query, $db_link); while ($row = mysql_fetch_assoc($result)){ ?> <tr> <td><input name="<?= 'link_name'.$row['id'] ?>" type="text" value="<?= $row['link_name'] ?>" size="20" /></td> <td align="center" valign="middle"><input name="<?= 'link_address'.$row['id'] ?>" size="70" type="text" value="<?= $row['link_address'] ?>" /></td> <td align="center" valign="middle"><?php buildOrdNum($row['link_order'],'Left',$table,$db_link,$row['id']) ?></td> <td align="center" valign="middle"><?php buildPos($row['link_pos'],$table,$db_link,$row['id']) ?></td> <td align="center" valign="middle"><input type="image" name="edit_id" value="<?= $row['id'] ?>" src="img/b_tick.png" /></td> <td align="center" valign="middle"><a href="<?= $_SERVER['PHP_SELF'].'?delete_id='.$row['id'] ?>"><img src="img/b_delete.png" width="16" height="19" border="0" /></a></td> </tr> <?php } ?> </table> </form> <br /> <br /> <?php } //closes main if statement ?> </body> </html> (probably no the most optimised code in the world ) ok now the story lol. im using this a home network startpage, with each user having a table in database for personal links...when a user wants to change their links they click on the edit links link and it loads edit_links.php into a <iframe> user edits the link the want or adds a new one and the edit_links.php page refresh's in the iframe, and as it stands for the new links to show up user has to manually refresh home page. Im looking for a way to update the index.php when the user has finished either editing or adding, preferably without actually refreshing hence where JS comes into it. i know the easy way to fix this would be to get rid of the iframe and just have the pages load like normal but would like to not have to do that. any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/112450-php-javascript-and-iframesarghhhh/ Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 This belongs in the Javascript section! I'm sure a mod will move it. After a quick search on Google I found this function that might be of use. It will refresh the parent frame which ofcourse will refresh any frames contained within it. <script type="text/javascript" language="javascript"> <!-- function refreshIframe(){ var iframeid = "sessionlog"; var h = parent.window.getElementById(iframeid).src; parent.window.getElementById(iframeid).src = h; } //--> </script> Quote Link to comment https://forums.phpfreaks.com/topic/112450-php-javascript-and-iframesarghhhh/#findComment-577320 Share on other sites More sharing options...
aussiexile Posted June 30, 2008 Author Share Posted June 30, 2008 preferably id like to not have to refresh the parent window instead to have the parent window actively looking for a var change which is why i need JS if that cant be done a PHP method to refresh the parent window would be more ideal Quote Link to comment https://forums.phpfreaks.com/topic/112450-php-javascript-and-iframesarghhhh/#findComment-577823 Share on other sites More sharing options...
br0ken Posted June 30, 2008 Share Posted June 30, 2008 Hmmm it sounds to me like you need to read up on Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/112450-php-javascript-and-iframesarghhhh/#findComment-578140 Share on other sites More sharing options...
DeanWhitehouse Posted June 30, 2008 Share Posted June 30, 2008 read up on a xmlHTTPrequest (i think). Quote Link to comment https://forums.phpfreaks.com/topic/112450-php-javascript-and-iframesarghhhh/#findComment-578142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.