chrismassey
Programmer
Hello,
I am currently developing V1.0 of a Webspace Explorer Script. The script itself is very long, and I am planning on cutting it down dramatically. However for the moment I just want to get every aspect functioning. I am having a problem with one section, though the syntax is fine and I can't see what I am doing wrong.
I have an image button (name="refresh_webspace_explorer") and when it is pressed I want the path to go back to the z drive (the initial drive, when the user first logs in). However when I click this button, I recieve an Error 500 although I am baffled why this is so...
In breakdown this is what this aspect of the script does...
So this gives you can idea of what i'm trying to achieve, but obviously the above code is within other code. So below i've printed most of my script (except some of the html output and also some of the other buttons functions)...
Any ideas why I recieve an Error 500, all that should happen is that the z drive is opened, and its contents printed onto the html webspace explorer template, and the $drive (which is "z") is printed into the textbox??? If you look, openb1 and openb2 do exactly the same thing, except they get their path in a slightly different way, however they work absolutely fine.
Thanks once again, what would I do without tek-tips
Chris
I am currently developing V1.0 of a Webspace Explorer Script. The script itself is very long, and I am planning on cutting it down dramatically. However for the moment I just want to get every aspect functioning. I am having a problem with one section, though the syntax is fine and I can't see what I am doing wrong.
I have an image button (name="refresh_webspace_explorer") and when it is pressed I want the path to go back to the z drive (the initial drive, when the user first logs in). However when I click this button, I recieve an Error 500 although I am baffled why this is so...
In breakdown this is what this aspect of the script does...
Code:
#declare variables
my ($refresh_website_explorer, $drive, $initial_path);
#name of $drive
$drive = "z";
#path to server
$initial_path = MYPATH;
#Link to form to pick up buttons name
$refresh_webspace_explorerb =
param('refresh_webspace_explorer');
#Check if the button has been pressed, and if so tell what path to open and print
if ($refresh_webspace_explorerb) {
$path = $initial_path .''. $drive;
$path_carry = $drive;
}
#use $path to open the z drive, and use $path_carry to print z into the form textbox
So this gives you can idea of what i'm trying to achieve, but obviously the above code is within other code. So below i've printed most of my script (except some of the html output and also some of the other buttons functions)...
Code:
##### Problems/Issues
# target for page or directory doesn't work - if page then should open in a new window
# printing the result of the foreach $_ (@_) onto a HTML template
# Once completed create new directory - run script to open the directory it was put into (add $directory_name)
# Once a page or directory has been opened it goes to that direc/page, I need it to return to 1 level back
# must let users know that to remove page/directory, all its contents must be deleted first
########## Opening Tags
#! /usr/bin/perl
use strict;
use CGI ':standard';
########## Declare variables
my ($initial_path, $open1, $open2, $path_carry, $openb1, $openb2, $path, $openb_target, @view_page, @directory_contents1, @directory_contents2, $directory_contents2_length, $direc_or_page, $drive);
my ($up_one_levelb, $refresh_webspace_explorerb);
my ($create_directoryb, $create_directoryb_execute, $create_directoryb_path, $directory_name);
my ($create_pageb, $create_pageb_execute, $create_pageb_path, $page_name);
my ($delete_direc_pageb, $delete_direc_pageb_execute, $delete_direc_pageb_path);
my ($rename_direc_pageb);
########## Connect to form
##### Path textboxes
$open1 = param('OpenText1');
$open2 = param('OpenText2');
##### Path open buttons
$openb1 = param('openb1');
$openb2 = param('openb2');
##### Top options
$up_one_levelb = param('up_one_level');
$refresh_webspace_explorerb = param('refresh_webspace_explorer');
$create_directoryb = param('create_directoryb');
$create_directoryb_execute = param('create_directoryb_execute');
$create_directoryb_path = param('create_directoryb_path');
$directory_name = param('directory_name');
$create_pageb = param('create_pageb');
$create_pageb_execute = param('create_pageb_execute');
$create_pageb_path = param('create_pageb_path');
$page_name = param('page_name');
$delete_direc_pageb = param('delete_direc_pageb');
$delete_direc_pageb_execute = param('delete_direc_pageb_execute');
$delete_direc_pageb_path = param('delete_direc_pageb_path');
$rename_direc_pageb = param('rename_direc_pageb');
######### Path to containing drive folder (z)
$initial_path = "MYPATH";
######### Drive label
$drive = "z";
########## Check which open button was pressed
if ($openb1) {
##### The path is...
$path = $initial_path .''. $open1;
$path_carry = $open1;
}
if ($openb2) {
##### The path is...
$path = $initial_path .''. $open1 .''. $open2;
$path_carry = $open1 .''. $open2;
}
if ($refresh_webspace_explorerb) {
$path = $initial_path .''. $drive;
$path_carry = $drive;
}
########## Create directory path and carry
if ($create_directoryb || $create_pageb || $delete_direc_pageb) {
$path_carry = $open1 .''. $open2;
}
if ($create_directoryb_execute) {
$path = $create_directoryb_path;
$path_carry = $create_directoryb_path;
}
if ($create_pageb_execute) {
$path = $create_pageb_path;
$path_carry = $create_pageb_path;
}
##############################################################################
##### Extract component parts from file
##### And then do if delete_direc_pageb one
if ($delete_direc_pageb_execute) {
$path = $delete_direc_pageb_path;
$path_carry = $delete_direc_pageb_path;
}
########## if one of the open buttons is pressed or a button which requires contents to print etc
if ($openb1 || $openb2 || $up_one_levelb || $refresh_webspace_explorerb || $create_directoryb_execute || $create_pageb_execute || $delete_direc_pageb_execute) {
#################### If a page is being opened
if ($path =~ m/.htm/){
$openb_target = qw(_blank);
open (LOG, "$path") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
@view_page = <LOG>;
close (LOG) || Error ('close', 'file');
print "Content-type: text/html\n\n";
print "@view_page";
}
#################### End if page
#################### If a directory is being opened
else {
$openb_target = qw(_self);
########## Open directory
opendir (LOGDIR, "$path") || Error ('open', 'directory');
@directory_contents1 = readdir (LOGDIR);
closedir (LOGDIR);
##### Sort contents into alphabetical order
@directory_contents2 = sort @directory_contents1;
##### Remove the . and the .. from array
shift(@directory_contents2);
shift(@directory_contents2);
##### Find length of $directory_contents2
$directory_contents2_length = @directory_contents2;
########## Print contents
##### Print form at the top
print "Content-type: text/html\n\n";
print <<"HTML code";
<HTML>
<head>
<title>Webspace Explorer Control Panel</title>
<script language="javascript">
function enableField()
{
document.form1.OpenText1.disabled=false;
document.form1.OpenText2.disabled=false;
}
</script>
<script language="javascript">
function disableField()
{
document.form1.OpenText1.disabled=true;
document.form1.OpenText2.disabled=true;
}
</script>
</head>
<body>
<FORM ACTION="script.pl" METHOD=POST NAME="form1">
<p><input type="submit" value="+ Directory" name="create_directoryb" target="_blank"> <input type="submit" value="+ Page" name="create_pageb" target="_blank"> <input type="submit" value="- Direc/Page" name="delete_direc_pageb" target="_blank"> <input type="submit" value="Rename Direc/Page" name="rename_direc_pageb" target="_blank"></p>
<p><input type="image" src="Images/UpOneLevel.bmp" name="up_one_level"> <input type="image" src="Images/RefreshWebspaceExplorer.bmp" name="refresh_webspace_explorer"></p>
<p><input type="text" name="OpenText1" size="50" value="$path_carry" readonly="true"><input type="submit" value="Open" name="openb1"></p>
<p><input type="text" name="OpenText2" size="50" readonly="true"><input type="submit" value="Open" name="openb2"></p>
</FORM>
</body>
</HTML>
HTML code
##### Print directory contents beneath
##### if there is no contents then indicate
if ($directory_contents2_length == 0) {
print "<font face=arial size=2><P>Directory <b>$path_carry</b> is empty.</font>";
}
else {
foreach (@directory_contents2) {
##### Check if directory or page
if ($_ =~ m/.htm/){ $direc_or_page = 'HTML Page'; }
else { $direc_or_page = 'Directory'; }
##### Main
print <<"HTML code";
<HTML>
<HEAD>
</HEAD>
<BODY>
<table>
<tr>
<td width="80" align="center" bgcolor="#E4E4E4"><input type=radio name="radiobuttongroup" value="/$_" OnClick="document.form1.OpenText2.value=this.value;"></td>
<td width="400" align="center" bgcolor="#E4E4E4"><font size="2" face="Arial">$_</font></td>
<td width="140" align="center" bgcolor="#E4E4E4"><b><font face="Arial" size="2">$direc_or_page</font></b></td>
</tr>
</table>
</BODY>
</HTML>
HTML code
}
##### End no contents indication
}
#################### End if directory
}
########## End if one of the open buttons is pressed
}
########## File opening error
sub Error {
print "Content-type: text/html\n\n";
print "<font face=arial size=2><P>Cannot Open File/Directory... Error 1.</font>";
print "<font face=arial size=2><P>$open1</font>";
print "<font face=arial size=2><P>$open2</font>";
print "<font face=arial size=2><P>$create_directoryb_path$directory_name</font>";
print "<font face=arial size=2><P>$create_pageb_path$page_name.htm</font>";
exit;
}
Any ideas why I recieve an Error 500, all that should happen is that the z drive is opened, and its contents printed onto the html webspace explorer template, and the $drive (which is "z") is printed into the textbox??? If you look, openb1 and openb2 do exactly the same thing, except they get their path in a slightly different way, however they work absolutely fine.
Thanks once again, what would I do without tek-tips
Chris