PHP gevorderde |
|
hallo,
ik heb een script gemaakt voor een treeview die de gegevens uit een SF database haalt:
<html>
<head>
<?php
function sp($str)
{
global $key;
$ret=str_replace(" ","_",$str);
return $ret.$key;
}
?>
<style>
div.domainlist {color: #000099; font-family: Arial,Helvetica; font-size: 12; margin-left: 10px; background-color: #ffffce;}
div#seldomain {color: #000099; font-family: Arial,Helvetica; font-size: 12; margin-left: 10px; background-color: #ffffce; position: absolute; left: 5px; top: 5px;}
</style>
<script type="text/javascript">
var setone=false;
var current="";
var cwrd="";
function insdom(target,twrd,tdesc)
{
if(setone)
current.style.backgroundColor="";
else
setone=true;
if(target==current)
{
current.style.backgroundColor="";
setone=false;
current="";
cwrd="";
}
else
{
target.style.backgroundColor="#FF4444";
current=target;
cwrd=twrd;
}
parent.scripture.location.href="descdom.php?title="+twrd+"&desc="+tdesc;
if(!setone)
seldomain.innerHTML="You haven't selected a domain. Click a domain to select it.";
else
{
seldomain.innerHTML="You've selected the domain "+cwrd+". <input type=\"button\" onClick=\"insert('"+cwrd+"');\" value=\"Insert\" />";
seldomain.innerHTML+="<input type=\"button\" onClick=\"clearfield();\" value=\"Clear\" />";
}
}
function insert(theword)
{
if(parent.navbar.entrysearch.selectlexical.value=="")
parent.navbar.entrysearch.selectlexical.value=theword;
else
parent.navbar.entrysearch.selectlexical.value+="; "+theword;
}
function clearfield()
{
parent.navbar.entrysearch.selectlexical.value="";
}
function toggledom( target, targetIdImg ){
if (target.style.display == "none"){
target.style.display = "block";
targetIdImg.src="minus.png";
} else {
target.style.display = "none";
targetIdImg.src="plus.png";
}
}
function clicktoggle(target,twrd,tdiv,tdesc)
{
if(setone)
current.style.backgroundColor="";
else
setone=true;
if(target==current)
{
current.style.backgroundColor="";
setone=false;
current="";
cwrd="";
}
else
{
target.style.backgroundColor="#FF4444";
current=target;
cwrd=twrd;
}
parent.scripture.location.href="descdom.php?title="+twrd+"&desc="+tdesc;
if(!setone)
seldomain.innerHTML="You haven't selected a domain. Click a domain to select it.";
else
{
seldomain.innerHTML="You've selected the domain "+cwrd+". <input type=\"button\" onClick=\"insert('"+cwrd+"');\" value=\"Insert\" />";
seldomain.innerHTML+="<input type=\"button\" onClick=\"clearfield();\" value=\"Clear\" />";
}
if (tdiv.style.display == "none"){
tdiv.style.display = "block";
tdivImg.src="minus.png";
} else {
tdiv.style.display = "none";
tdivImg.src="plus.png";
}
}
</script>
</head>
<body bgcolor="#ffffce">
<div id="seldomain">You haven't selected a domain. Click a domain to select it.<input type="button" onClick="clearfield();" value="Clear" /></div>
<br />
<div class="domainlist">
<?php
$confile=file("sdbh-u/sdbh-u.tv1") or die("\nFailed reading the database.\n");
$curniv=1;
foreach($confile as $key=>$value)
{
$temparr=explode("\$",$value);
$niv=substr($temparr[0],-1);
$name=$temparr[1];
$desc=htmlentities($temparr[2]);
$temparr=explode("\$",$confile[$key+1]);
$nw=substr($temparr[0],-1);
if($nw==$niv)
$same=true;
else
$same=false;
if($nw<=$niv)
echo "<br /><a id=\"lnk".sp($name)."\" href=\"javascript:insdom(lnk".sp($name).",'$name','$desc');\"><img id=\"img".sp($name)."\" border=0 src=\"arrow.png\" /> $name</a>\n";
else
echo "<br /><a href=\"javascript:toggledom(".sp($name).",img".sp($name).");\"><img id=\"img".sp($name)."\" border=0 src=\"plus.png\" /></a> <a id=\"lnk".sp($name)."\" href=\"javascript:clicktoggle(lnk".sp($name).",'$name',".sp($name).",img".sp($name).",'$desc');\">$name</a>\n";
echo "<div class=\"domainlist\" id=\"".sp($name)."\" style=\"display: none;\">\n";
if($nw<=$niv)
{
$togo=$niv-$nw;
for($i=0;$i<=$togo;$i++)
{
echo "</div>\n";
}
}
$curniv=$niv;
}
?>
</div>
</body>
</html>
<html> <head> <?php function sp($str) { return $ret.$key; } ?> <style> div.domainlist {color: #000099; font-family: Arial,Helvetica; font-size: 12; margin-left: 10px; background-color: #ffffce;} div#seldomain {color: #000099; font-family: Arial,Helvetica; font-size: 12; margin-left: 10px; background-color: #ffffce; position: absolute; left: 5px; top: 5px;} </style> <script type="text/javascript"> var setone=false; var current=""; var cwrd=""; function insdom(target,twrd,tdesc) { if(setone) current.style.backgroundColor=""; else setone=true; if(target==current) { current.style.backgroundColor=""; setone=false; current=""; cwrd=""; } else { target.style.backgroundColor="#FF4444"; current=target; cwrd=twrd; } parent.scripture.location.href="descdom.php?title="+twrd+"&desc="+tdesc; if(!setone) seldomain.innerHTML="You haven't selected a domain. Click a domain to select it."; else { seldomain.innerHTML="You've selected the domain "+cwrd+". <input type=\"button\" onClick=\"insert('"+cwrd+"');\" value=\"Insert\" />"; seldomain.innerHTML+="<input type=\"button\" onClick=\"clearfield();\" value=\"Clear\" />"; } } function insert(theword) { if(parent.navbar.entrysearch.selectlexical.value=="") parent.navbar.entrysearch.selectlexical.value=theword; else parent.navbar.entrysearch.selectlexical.value+="; "+theword; } function clearfield() { parent.navbar.entrysearch.selectlexical.value=""; } function toggledom( target, targetIdImg ){ if (target.style.display == "none"){ target.style.display = "block"; targetIdImg.src="minus.png"; } else { target.style.display = "none"; targetIdImg.src="plus.png"; } } function clicktoggle(target,twrd,tdiv,tdesc) { if(setone) current.style.backgroundColor=""; else setone=true; if(target==current) { current.style.backgroundColor=""; setone=false; current=""; cwrd=""; } else { target.style.backgroundColor="#FF4444"; current=target; cwrd=twrd; } parent.scripture.location.href="descdom.php?title="+twrd+"&desc="+tdesc; if(!setone) seldomain.innerHTML="You haven't selected a domain. Click a domain to select it."; else { seldomain.innerHTML="You've selected the domain "+cwrd+". <input type=\"button\" onClick=\"insert('"+cwrd+"');\" value=\"Insert\" />"; seldomain.innerHTML+="<input type=\"button\" onClick=\"clearfield();\" value=\"Clear\" />"; } if (tdiv.style.display == "none"){ tdiv.style.display = "block"; tdivImg.src="minus.png"; } else { tdiv.style.display = "none"; tdivImg.src="plus.png"; } } </script> </head> <body bgcolor="#ffffce"> <div id="seldomain">You haven't selected a domain. Click a domain to select it.<input type="button" onClick="clearfield();" value="Clear" /></div> <br /> <div class="domainlist"> <?php $confile=file("sdbh-u/sdbh-u.tv1") or die("\nFailed reading the database.\n"); $curniv=1; foreach($confile as $key=>$value) { $name=$temparr[1]; $temparr=explode("\$",$confile[$key+1]); if($nw==$niv) $same=true; else $same=false; if($nw<=$niv) echo "<br /><a id=\"lnk".sp ($name)."\" href=\"javascript:insdom(lnk".sp ($name).",'$name','$desc');\"><img id=\"img".sp ($name)."\" border=0 src=\"arrow.png\" /> $name</a>\n"; else echo "<br /><a href=\"javascript:toggledom(".sp ($name).",img".sp ($name).");\"><img id=\"img".sp ($name)."\" border=0 src=\"plus.png\" /></a> <a id=\"lnk".sp ($name)."\" href=\"javascript:clicktoggle(lnk".sp ($name).",'$name',".sp ($name).",img".sp ($name).",'$desc');\">$name</a>\n"; echo "<div class=\"domainlist\" id=\"".sp ($name)."\" style=\"display: none;\">\n"; if($nw<=$niv) { $togo=$niv-$nw; for($i=0;$i<=$togo;$i++) { } } $curniv=$niv; } ?> </div> </body> </html>
dus als je op een domein klikt weergeeftie in een ander frame de beschrijving van dat domein:
<html>
<head>
<style>
p {color: #000099; font-family: Arial,Helvetica; font-size: 12; margin-left: 10px;}
</style>
</head>
<body bgcolor="#ffffce">
<?php
$title=$_GET['title'];
$desc=$_GET['desc'];
echo "\n<p>\n".$title.":\n<br />\n<br />\n".$desc."\n</p>";
?>
</body>
</html>
<html> <head> <style> p {color: #000099; font-family: Arial,Helvetica; font-size: 12; margin-left: 10px;} </style> </head> <body bgcolor="#ffffce"> <?php $title=$_GET['title']; $desc=$_GET['desc']; echo "\n<p>\n".$title.":\n<br />\n<br />\n".$desc."\n</p>"; ?> </body> </html>
maar het probleem is:
bij sommige domeins weergeeftie de titel wel goed, maar bij de description zegtie [object].
het probleem ligt niet in PHP, maar in JavaScript.
Kan iemand me helpen?
|