JehovahsWord
09-14-2003, 12:57 AM
hi,
Well I am making this script, and I am trying to integrate a javascript into it, but I don't know how to make this work.
it is an ftp script, and made out of php. what I have is after logging in, there is two tables, one listing the directories and one listing the files. each file and directory have a checkbox to it. the checkboxes for each file is called files[] and the ones with the directories is called dirs[]. the [] is so that that will capture an array so that when I click to delete the selected files or directories, it carries over as an array. so I got this javascript to check all boxes when the checkbox is clicked. what I want is one checkbox to check all the boxes with the files, and another to check all the boxes with the directories. but javascript seems not to like that [] to be there after the name of the box. I have something like this, out of membory excuse any mistakes
if (ftpcom.check_all1.checked == true) {
for (i=0; i<ftpcom.files[].length; i++) {
document.ftpcom.files[][i].checked == true;
}
}
etc etc, you get the point. but that doesn't work. how can I make it work? or is there another way I could do this to get the desired effect? I'm not sure if my code will help...it's kind of long, but here's the function where this script is and all the listings and all:
<?php
function view($lhost,$lport,$luser,$lpass,$pasv,$lang) {
global $title;
$start = gettime();
if (isset($_POST["dir"])) {
$dir = $_POST["dir"];
}
if (isset($_POST["file"])) {
$file = $_POST["file"];
}
if (isset($_POST["action"])) {
$action = $_POST["action"];
}
if (isset($_POST["lang"])) {
$lang = $_POST["lang"];
}
php_headers($lhost,$luser,$lang);
newlang($lang);
$conn_id = ftp_connect($lhost, $lport, 150);
$login = ftp_login($conn_id, $luser, $lpass);
if ($pasv == "yes") {
ftp_pasv($conn_id,true);
}
$title = _FTP."—".$lhost;
head($lhost,$pasv,$title);
if ((!$login) || (!$conn_id)) {
echo _FLOGIN." ".$lhost." "._WUSER." ".$luser." "._WPASS." ".$lpass.".";
exit();
}
echo dblline;
if ($action == "chdir") {
ftpchdir($conn_id,$dir);
}
if ($action == "refresh") {
ftprefresh($conn_id,$dir);
}
if ($action == "delete_file") {
$files = $_POST["files"];
ftpdelete_file2($conn_id,$files,$lang,$dir);
}
if ($action == "delete_dir") {
$files = $_POST["files"];
ftpdelete_dir2($conn_id,$dirs,$lang,$dir);
}
$dir = ftp_pwd($conn_id);
echo dblline;
links($dir,$lang);
echo dblline;
lang($lang);
echo dblline;
echo _CDIR.": ".$dir.dblline;
$list = ftp_rawlist($conn_id, $dir);
echo "<form action=\"".path."\" method=\"post\" name=\"jump\">";
if (is_array($list)) {
echo "<select name=\"dir\">\n";
for ($i=0; $i<count($list); $i++) {
if (ereg("([-dl])([rwxst-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+[ ]+[0-9:]+)[ ]+(.*)", $list[$i], $r) == true) {
if (($r[1] == "d") || ($r[1] == "l")) {
if (($r[8] != ".") && ($r[8] != "..")) {
if (ereg("([^ />]+)", $r[8], $reg) == true) {
echo "<option value=\"".$dir."/".$reg[1]."\">".$reg[1]."</option>\n";
}
else {
echo "<option value=\"".$dir."/".$r[8]."\">".$r[8]."</option>\n";
}
}
}
}
else {
die("Error. The information from the FTP is not readable or usable. The output was: ".$list[$i]);
}
}
echo "</select>\n";
echo "\n<input type=\"button\" value=\""._GO."\" onclick=\"subftpcom('main',document.jump.dir.options[document.jump.dir.selectedIndex].value,'','chdir','".$lang."');\" />\n";
echo "</form>\n";
echo dblline;
echo "<form action=\"".path."\" method=\"post\" name=\"ftpcom\">
<input type=\"hidden\" name=\"lhost\" value=\"".$lhost."\" />
<input type=\"hidden\" name=\"lport\" value=\"".$lport."\" />
<input type=\"hidden\" name=\"luser\" value=\"".$luser."\" />
<input type=\"hidden\" name=\"lpass\" value=\"".$lpass."\" />
<input type=\"hidden\" name=\"pasv\" value=\"".$pasv."\" />
<input type=\"hidden\" name=\"state\" />
<input type=\"hidden\" name=\"dir\" />
<input type=\"hidden\" name=\"file\" />
<input type=\"hidden\" name=\"action\" />
<input type=\"hidden\" name=\"lang\" />
<script language=\"javascript\">
<!--
function subftpcom(state, dir, file, action, lang) {
document.ftpcom.state.value=state;
document.ftpcom.dir.value=dir;
document.ftpcom.file.value=file;
document.ftpcom.action.value=action;
document.ftpcom.lang.value=lang;
document.ftpcom.submit();
}
//-->
</script>\n";
if ($dir != "/") {
echo "<input type=\"button\" value=\""._LEVEL."\" onclick=\"subftpcom('main','".$dir."','','cdup','".$lang."');\" />\n";
}
echo dblline;
showbuttons($dir,$lang);
echo dblline;
echo "<script language=\"javascript\">
var i
function checkboxes1() {
if (ftpcom.check_all1.checked == true) {
for (i=0; i < ftpcom.files.length; i++) {
document.ftpcom.files[i].checked = true;
}
}
if (ftpcom.check_all1.checked == false) {
for (i=0; i < ftpcom.files[].length; i++) {
document.ftpcom.files[][i].checked = false;
}
}
}
</script>
<script language=\"javascript\" <script language=\"javascript\">
var i
function checkboxes2() {
if (ftpcom.check_all2.checked == true) {
for (i=0; i < ftpcom.dirs[].length; i++) {
document.ftpcom.dirs[][i].checked = true;
}
}
if (ftpcom.check_all2.checked == false) {
for (i=0; i < ftpcom.dirs[].length; i++) {
document.ftpcom.dirs[][i].checked = false;
}
}
}
</script>\n";
echo ""._DIRS." ".$dir.dblline;
echo "<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\">\n";
echo "<tr>\n";
echo "<td>"._NAME."</td>\n";
echo "<td>"._OWNER."</td>\n";
echo "<td>"._GROUP."</td>\n";
echo "<td>"._PERM."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"4\"><input type=\"checkbox\" name=\"check_all2\" onclick=\"checkboxes2();\" />check all directories</td>\n";
echo "</tr>\n";
for ($i=0; $i<count($list); $i++) {
if (ereg("([-dl])([rwxst-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+[ ]+[0-9:]+)[ ]+(.*)", $list[$i], $r) == true) {
if (($r[1] == "d") || ($r[1] == "l")) {
if (($r[8] != ".") && ($r[8] != "..")) {
echo "<tr>\n";
echo "<td>";
if (ereg("([^ />]+)", $r[8], $reg) == true) {
echo "<input type=\"checkbox\" name=\"dirs[]\" value=\"".$dir."/".$reg[1]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','".$dir."/".$reg[1]."','','chdir','".$lang."');\">".$reg[1]."</a>\n";
}
else {
echo "<input type=\"checkbox\" name=\"dirs[]\" value=\"".$dir."/".$r[8]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','".$dir."/".$r[8]."','','chdir','".$lang."');\">".$r[8]."</a>\n";
}
echo "</td>\n<td>".$r[4]."</td>\n";
echo "<td>".$r[5]."</td>\n";
echo "<td>".$r[2]."</td>\n";
echo "</tr>\n";
}
}
}
}
echo "</table>\n";
echo dblline;
echo ""._FILES." ".$dir.dblline;
echo "<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\">\n";
echo "<tr>\n";
echo "<td>"._NAME."</td>\n";
echo "<td>"._FSIZE."</td>\n";
echo "<td>"._OWNER."</td>\n";
echo "<td>"._GROUP."</td>\n";
echo "<td>"._PERM."</td>\n";
echo "<td>"._LMOD."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"6\"><input type=\"checkbox\" name=\"check_all1\" onclick=\"checkboxes1();\" />check all files</td>\n";
echo "</td>\n";
for ($i=0; $i<count($list); $i++) {
if (ereg("([-dl])([rwxst-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+[ ]+[0-9:]+)[ ]+(.*)", $list[$i], $r) == true) {
if (($r[1] != "d") && ($r[1] != "l")) {
echo "<tr>\n";
echo "<td>";
if (ereg("([^ />]+)", $r[8], $reg) == true) {
echo "<input type=\"checkbox\" name=\"files[]\" value=\"".$dir."/".$reg[1]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','','".$dir."/".$reg[1]."','chdir','".$lang."');\">".$reg[1]."</a>";
}
else {
echo "<input type=\"checkbox\" name=\"files[]\" value=\"".$dir."/".$r[8]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','','".$dir."/".$r[8]."','chdir','".$lang."');\">".$r[8]."</a>";
}
echo "</td>\n<td>";
$b = $r[6];
$byte = number_format($b);
$kb = round($b / 1024, 2);
$kbyte = number_format(round($b / 1024, 2), 2);
$mb = number_format(round(($b / 1024) / 1024, 2), 2);
if ($kb > 1024) {
echo $mb." MB (".$kbyte." KB (".$byte." ";
if ($b == 1) {
echo "byte";
} // end if
else {
echo "bytes";
} // end if
echo "))";
} // end if
elseif ($b > 1024) {
echo $kbyte." KB (".$byte." ";
if ($b == 1) {
echo "byte";
} // end if
else {
echo "bytes";
} // end if
echo ")";
} // end if
else {
echo $byte." ";
if ($b == 1) {
echo "byte";
} // end if
else {
echo "bytes";
} // end if
} // end if
echo "</td>\n";
echo "<td>".$r[4]."</td>\n";
echo "<td>".$r[5]."</td>\n";
echo "<td>".$r[2]."</td>\n";
echo "<td>".$r[7]."</td>\n";
echo "</tr>\n";
}
}
}
echo "</table>\n";
echo "</form>\n";
}
echo dblline;
showbuttons($dir,$lang);
ftp_close($conn_id);
footer($start,$lang);
}
?>
Brandon
Well I am making this script, and I am trying to integrate a javascript into it, but I don't know how to make this work.
it is an ftp script, and made out of php. what I have is after logging in, there is two tables, one listing the directories and one listing the files. each file and directory have a checkbox to it. the checkboxes for each file is called files[] and the ones with the directories is called dirs[]. the [] is so that that will capture an array so that when I click to delete the selected files or directories, it carries over as an array. so I got this javascript to check all boxes when the checkbox is clicked. what I want is one checkbox to check all the boxes with the files, and another to check all the boxes with the directories. but javascript seems not to like that [] to be there after the name of the box. I have something like this, out of membory excuse any mistakes
if (ftpcom.check_all1.checked == true) {
for (i=0; i<ftpcom.files[].length; i++) {
document.ftpcom.files[][i].checked == true;
}
}
etc etc, you get the point. but that doesn't work. how can I make it work? or is there another way I could do this to get the desired effect? I'm not sure if my code will help...it's kind of long, but here's the function where this script is and all the listings and all:
<?php
function view($lhost,$lport,$luser,$lpass,$pasv,$lang) {
global $title;
$start = gettime();
if (isset($_POST["dir"])) {
$dir = $_POST["dir"];
}
if (isset($_POST["file"])) {
$file = $_POST["file"];
}
if (isset($_POST["action"])) {
$action = $_POST["action"];
}
if (isset($_POST["lang"])) {
$lang = $_POST["lang"];
}
php_headers($lhost,$luser,$lang);
newlang($lang);
$conn_id = ftp_connect($lhost, $lport, 150);
$login = ftp_login($conn_id, $luser, $lpass);
if ($pasv == "yes") {
ftp_pasv($conn_id,true);
}
$title = _FTP."—".$lhost;
head($lhost,$pasv,$title);
if ((!$login) || (!$conn_id)) {
echo _FLOGIN." ".$lhost." "._WUSER." ".$luser." "._WPASS." ".$lpass.".";
exit();
}
echo dblline;
if ($action == "chdir") {
ftpchdir($conn_id,$dir);
}
if ($action == "refresh") {
ftprefresh($conn_id,$dir);
}
if ($action == "delete_file") {
$files = $_POST["files"];
ftpdelete_file2($conn_id,$files,$lang,$dir);
}
if ($action == "delete_dir") {
$files = $_POST["files"];
ftpdelete_dir2($conn_id,$dirs,$lang,$dir);
}
$dir = ftp_pwd($conn_id);
echo dblline;
links($dir,$lang);
echo dblline;
lang($lang);
echo dblline;
echo _CDIR.": ".$dir.dblline;
$list = ftp_rawlist($conn_id, $dir);
echo "<form action=\"".path."\" method=\"post\" name=\"jump\">";
if (is_array($list)) {
echo "<select name=\"dir\">\n";
for ($i=0; $i<count($list); $i++) {
if (ereg("([-dl])([rwxst-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+[ ]+[0-9:]+)[ ]+(.*)", $list[$i], $r) == true) {
if (($r[1] == "d") || ($r[1] == "l")) {
if (($r[8] != ".") && ($r[8] != "..")) {
if (ereg("([^ />]+)", $r[8], $reg) == true) {
echo "<option value=\"".$dir."/".$reg[1]."\">".$reg[1]."</option>\n";
}
else {
echo "<option value=\"".$dir."/".$r[8]."\">".$r[8]."</option>\n";
}
}
}
}
else {
die("Error. The information from the FTP is not readable or usable. The output was: ".$list[$i]);
}
}
echo "</select>\n";
echo "\n<input type=\"button\" value=\""._GO."\" onclick=\"subftpcom('main',document.jump.dir.options[document.jump.dir.selectedIndex].value,'','chdir','".$lang."');\" />\n";
echo "</form>\n";
echo dblline;
echo "<form action=\"".path."\" method=\"post\" name=\"ftpcom\">
<input type=\"hidden\" name=\"lhost\" value=\"".$lhost."\" />
<input type=\"hidden\" name=\"lport\" value=\"".$lport."\" />
<input type=\"hidden\" name=\"luser\" value=\"".$luser."\" />
<input type=\"hidden\" name=\"lpass\" value=\"".$lpass."\" />
<input type=\"hidden\" name=\"pasv\" value=\"".$pasv."\" />
<input type=\"hidden\" name=\"state\" />
<input type=\"hidden\" name=\"dir\" />
<input type=\"hidden\" name=\"file\" />
<input type=\"hidden\" name=\"action\" />
<input type=\"hidden\" name=\"lang\" />
<script language=\"javascript\">
<!--
function subftpcom(state, dir, file, action, lang) {
document.ftpcom.state.value=state;
document.ftpcom.dir.value=dir;
document.ftpcom.file.value=file;
document.ftpcom.action.value=action;
document.ftpcom.lang.value=lang;
document.ftpcom.submit();
}
//-->
</script>\n";
if ($dir != "/") {
echo "<input type=\"button\" value=\""._LEVEL."\" onclick=\"subftpcom('main','".$dir."','','cdup','".$lang."');\" />\n";
}
echo dblline;
showbuttons($dir,$lang);
echo dblline;
echo "<script language=\"javascript\">
var i
function checkboxes1() {
if (ftpcom.check_all1.checked == true) {
for (i=0; i < ftpcom.files.length; i++) {
document.ftpcom.files[i].checked = true;
}
}
if (ftpcom.check_all1.checked == false) {
for (i=0; i < ftpcom.files[].length; i++) {
document.ftpcom.files[][i].checked = false;
}
}
}
</script>
<script language=\"javascript\" <script language=\"javascript\">
var i
function checkboxes2() {
if (ftpcom.check_all2.checked == true) {
for (i=0; i < ftpcom.dirs[].length; i++) {
document.ftpcom.dirs[][i].checked = true;
}
}
if (ftpcom.check_all2.checked == false) {
for (i=0; i < ftpcom.dirs[].length; i++) {
document.ftpcom.dirs[][i].checked = false;
}
}
}
</script>\n";
echo ""._DIRS." ".$dir.dblline;
echo "<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\">\n";
echo "<tr>\n";
echo "<td>"._NAME."</td>\n";
echo "<td>"._OWNER."</td>\n";
echo "<td>"._GROUP."</td>\n";
echo "<td>"._PERM."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"4\"><input type=\"checkbox\" name=\"check_all2\" onclick=\"checkboxes2();\" />check all directories</td>\n";
echo "</tr>\n";
for ($i=0; $i<count($list); $i++) {
if (ereg("([-dl])([rwxst-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+[ ]+[0-9:]+)[ ]+(.*)", $list[$i], $r) == true) {
if (($r[1] == "d") || ($r[1] == "l")) {
if (($r[8] != ".") && ($r[8] != "..")) {
echo "<tr>\n";
echo "<td>";
if (ereg("([^ />]+)", $r[8], $reg) == true) {
echo "<input type=\"checkbox\" name=\"dirs[]\" value=\"".$dir."/".$reg[1]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','".$dir."/".$reg[1]."','','chdir','".$lang."');\">".$reg[1]."</a>\n";
}
else {
echo "<input type=\"checkbox\" name=\"dirs[]\" value=\"".$dir."/".$r[8]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','".$dir."/".$r[8]."','','chdir','".$lang."');\">".$r[8]."</a>\n";
}
echo "</td>\n<td>".$r[4]."</td>\n";
echo "<td>".$r[5]."</td>\n";
echo "<td>".$r[2]."</td>\n";
echo "</tr>\n";
}
}
}
}
echo "</table>\n";
echo dblline;
echo ""._FILES." ".$dir.dblline;
echo "<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\">\n";
echo "<tr>\n";
echo "<td>"._NAME."</td>\n";
echo "<td>"._FSIZE."</td>\n";
echo "<td>"._OWNER."</td>\n";
echo "<td>"._GROUP."</td>\n";
echo "<td>"._PERM."</td>\n";
echo "<td>"._LMOD."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"6\"><input type=\"checkbox\" name=\"check_all1\" onclick=\"checkboxes1();\" />check all files</td>\n";
echo "</td>\n";
for ($i=0; $i<count($list); $i++) {
if (ereg("([-dl])([rwxst-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+[ ]+[0-9:]+)[ ]+(.*)", $list[$i], $r) == true) {
if (($r[1] != "d") && ($r[1] != "l")) {
echo "<tr>\n";
echo "<td>";
if (ereg("([^ />]+)", $r[8], $reg) == true) {
echo "<input type=\"checkbox\" name=\"files[]\" value=\"".$dir."/".$reg[1]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','','".$dir."/".$reg[1]."','chdir','".$lang."');\">".$reg[1]."</a>";
}
else {
echo "<input type=\"checkbox\" name=\"files[]\" value=\"".$dir."/".$r[8]."\" />".dblline;
echo "<a href=\"javascript:subftpcom('main','','".$dir."/".$r[8]."','chdir','".$lang."');\">".$r[8]."</a>";
}
echo "</td>\n<td>";
$b = $r[6];
$byte = number_format($b);
$kb = round($b / 1024, 2);
$kbyte = number_format(round($b / 1024, 2), 2);
$mb = number_format(round(($b / 1024) / 1024, 2), 2);
if ($kb > 1024) {
echo $mb." MB (".$kbyte." KB (".$byte." ";
if ($b == 1) {
echo "byte";
} // end if
else {
echo "bytes";
} // end if
echo "))";
} // end if
elseif ($b > 1024) {
echo $kbyte." KB (".$byte." ";
if ($b == 1) {
echo "byte";
} // end if
else {
echo "bytes";
} // end if
echo ")";
} // end if
else {
echo $byte." ";
if ($b == 1) {
echo "byte";
} // end if
else {
echo "bytes";
} // end if
} // end if
echo "</td>\n";
echo "<td>".$r[4]."</td>\n";
echo "<td>".$r[5]."</td>\n";
echo "<td>".$r[2]."</td>\n";
echo "<td>".$r[7]."</td>\n";
echo "</tr>\n";
}
}
}
echo "</table>\n";
echo "</form>\n";
}
echo dblline;
showbuttons($dir,$lang);
ftp_close($conn_id);
footer($start,$lang);
}
?>
Brandon