• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

PHP, Javascript & frames

I have a number of users who need the ability to edit an undefined number of files at the same time. This involves dividing the screen space into 2, 3, 4 or 6 windows so that a user can view all the files to be edited at the same time. If the user wants to edit more than 6 files at the same time then each file is presented in a fixed size "textarea" which will toghether occupy more than the screen space and scroll as a block.

I already have  tested "HTML frameset" for the purpose and what I need is  a PHP script that creates these framesets and displays in the frames the contents of the files to be edited (in textareas ?) then saves the files when editing is completed.

The files to be edited are already selected and the full paths are retrieved from an array from a previous PHP script. So this array is to be passed between scripts with the "PHP session".

With the basic PHP knowledge I have I can spend days in trial and error on this. I thought someone more experienced could give me a more efficient script to do this.

Thank you for your help.
0
rblampain
Asked:
rblampain
  • 2
  • 2
1 Solution
 
Marcus BointonCommented:
It might be more elegant to use iframes instead of real frames. Each frame contains a full HTML page, complete with headers etc., so you'll need to build a form that acts as an editor template for each editable file, something like:

<?php
$filename = '';
$filepath = '';
if (array_key_exists('file', $_REQUEST)) {
  $filename = $_REQUEST['file'];
  $filepath = "./editablefiles/$filename";
}
if (array_key_exists('editedtext', $_REQUEST) and ($filename != '')) { //Data has been sent back
$fp = fopen($filepath, 'w');
$fwrite($fp, $_REQUEST['editedtext']);
}
if (file_exists($filepath))
  $filecontents = file_get_contents($filepath);
else
  $filecontents = '';
}
?>
<html>
<head><title>Editing file <?php echo $filename; ?></title></head>
<body>
<form action="edit.php method="post">
<p>Editing file <?php echo $filename; ?></p>
<textarea name="editedtext"><?php echo $filecontents; ?></textarea>
<input type="hidden" name="file" value="<?php echo $filename; ?>">
<input type="submit" value="Save">
</form>
</body>
</html>

That should form the basis of a simple editor. I've restricted it to only editing files in one folder called 'editablefiles' for security reasons. You may want to check some other way and/or more thoroughly.

Next it's a matter of building the page containing the editors in iframes. Assuming that the names of all the files you want to edit are in $_SESSION['files']:

<html>
<head><title>Editing file <?php echo $filename; ?></title></head>
<body>
<?php
foreach($_SESSION['files'] as $file)
  echo "<iframe src=\"edit.php?file=$file\" /><br />\n";
?>
</body>
</html>

I've not had time to test this, but it should be workable. Please respond if you have trouble.
0
 
rblampainAuthor Commented:
Thanks to Squinky.
I didn't know anything about "iframes", I thought it was a MS thing, I use Linux.
My browser seems to support it but it's a bit more learning for me and I'd prefer to avoid it, I already have the html framesets ready and tested.
It looks like "frameset" will give me better control of the screen real estate, if this is correct then I won't use "iframe".  
It seems I can use parts of the scripts you provide but it's not really the solution I need. I'll wait a couple of days and if no other solution is  coming I'll try to adapt it to my needs.
0
 
Marcus BointonCommented:
iframes are part of W3C standard HTML, nothing particularly proprietary about them, and they're supported by all browsers. Their main advantage is that you don't have to use framesets - they act just like a div that happens to display content from elsewhere, so are easily styled and laid out using CSS.

Using regular frames is not hugely different to code. The editor page will remain the same, but the frameset generation could be:

<html>
<head><title>Editing file <?php echo $filename; ?></title></head>
<?php
$rows = repeat(100/count($_SESSION['files']).'%,', count($_SESSION['files']));
$rows = substr($rows, 0, -1); //Strip trailing comma
echo "<frameset rows=\"$rows\">\n";
foreach($_SESSION['files'] as $file)
  echo "<frame src=\"edit.php?file=$file\" />\n";
?>
<noframes>
<body>Your browser does not handle frames!</body>
</noframes>
</frameset>
</html>

As you can see, frameset syntax is noticeably more complex than iframe. The layout is fixed by the HTML (thus losing semantic markup value), and you can't lay it out with CSS. There's good info here: http://www.w3schools.com/html/html_frames.asp
0
 
rblampainAuthor Commented:
It will probably take me a few weeks to finalize this script so I gave your solution a "B" grade although it may deserve better.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now