Ciao a tutti, stamattina ho composto uno script per creare una sezione di news sul mio sito.
Il form è il seguente, tuttavia ha un piccolo problemino.
Il form dovrebbe avere dei tasti di formattazione del testo e quando clicco su uno di questi il tag del pulsante dovrebbe essere riportato sulla textarea, ma non funziona, non riporta i tag la pagina web su cui lo apro mi dice che c'è un'errore nella pagina.
In tutti i casi il file news.php è il seguente.
Infinitamente grazie a chiunque sarà così gentile da darmi un mano.


<html>
<body bgcolor=yellow>

<basefont size=2 face=arial>

Aggiungi Articolo
<?
include ("template.inc");
include ("config.php");

$summary_template = "t_summary.html";
$article_template = "t_article.html";
$max_summary = 5;

function summary_page ($subject, $date, $summary, $article_id)
{
global $summary_template;
$t = new Template();
$t->set_file("SummaryPage", $summary_template);
$article_url = "article_".$article_id.".html";
$date = nl2br($date);
$summary = nl2br($summary);
$t->set_var( array(
"subject" => $subject,
"date" => $date,
"summary" => $summary,
"article_url" => $article_url
));
$t->parse("Summary", "SummaryPage");
return $t->get_var("Summary");
}

function main_page ($subject, $date, $summary, $article_id, $body)
{
global $article_template;

$t = new Template();
$t->set_file("ArticlePage", $article_template);
$article_url = "article_".$article_id.".html";
$date = nl2br($date);
$summary = nl2br($summary);
$body = nl2br($body);
$t->set_var( array(
"subject" => $subject,
"date" => $date,
"summary" => $summary,
"body" => $body,
"article_url" => $article_url
));
$t->parse("Article", "ArticlePage");
return $t->get_var("Article");
}

function add_article($filename, $news)
{

if(file_exists($filename)){
$fh = fopen($filename, "r");
$old_news = fread($fh, filesize($filename));
fclose($fh);
}

/* TODO: Multipage articles
preg_match_all("", $old_news, $matches;

if( count($matches[0]) >= $max_summary){
$oldfilename = $filename.($matches[0][0]+1);
}
*/

$fh = fopen($filename, "w");
$news = stripslashes($news);
fwrite($fh, "\n\n$news $old_news");
fclose($fh);
}

?>

<?
if(strcmp($subject, "")){
if(!(strcmp($passwd, $password))){
add_article("article_summary.html", summary_page($subject, $date, $summary, $article_id));
add_article("article_$article_id.html", main_page($subject, $date, $summary, $article_id, $body));
echo "

Article has been added!

";
}else{
echo "

Password is wrong! ";
}
}
?>

<script type="text/javascript" src="file.js"></script>
<form action=news.php method=post>
<table border=0>
<tr> <td> Password(obbligatoria): </td><td> <input type=text name=passwd size=30> </td></tr>
<tr> <td> Sogetto: </td><td> <input type=text name=subject size=30> </td></tr>
<tr> <td> ID Articolo: </td><td> <input type=text name=article_id value=<? echo date("Y_m_j_is"); ?> size=30> </td></tr>
<tr> <td> Data/ora/ecc.: </td><td> <textarea name=date rows=2 cols=30 wrap=soft><? echo date("M j, Y\n"); ?>Author: </textarea> </td></tr>
<tr> <td> Riassunto: </td><td> <textarea name=summary rows=5 cols=30 wrap=soft></textarea> </td></tr>
<tr><td>Notizia</td>

<td>


[img]img/bold.gif[/img][img]img/italic.gif[/img][img]img/underline.gif[/img][img]img/strike.gif[/img][img]img/sub.gif[/img][img]img/sup.gif[/img][img]img/shadow.gif[/img][img]img/glow.gif[/img][img]img/color.gif[/img][img]img/fontface.gif[/img][img]img/fontsize.gif[/img][img]img/fontleft.gif[/img][img]img/tele.gif[/img][img]img/hr.gif[/img][img]img/move.gif[/img][img]img/quote2.gif[/img][img]img/flash.gif[/img][img]img/img.gif[/img][img]img/email2.gif[/img][img]img/url.gif[/img][img]img/list.gif[/img]

<script type="text/javascript" src="jsfunc.js"></script>
<textarea name="body" rows="15" cols="80"></textarea>
</td>
</tr>

</table>
<input type=submit name=submit value=Add>
</form>



<a href=source.php?f=news.php>Source</a>


Mentre il file file.js è il seguente:

//<![CDATA[

function smiley_bbcode ( form_name, textbox_name, text )
{
// Thanks to ricrat51 @ fusionnews.net forums for reporting this
// bug and then providing me with a fix

if ( document.all )
{
var textbox = document.forms[form_name].elements[textbox_name];
}
else
{
var textbox = document.getElementById(textbox_name);
}

//IE support
if ( document.selection )
{
textbox.focus();
sel = document.selection.createRange();
sel.text = text;
textbox.focus();
}
//MOZILLA/NETSCAPE support
else if ( textbox.selectionStart || textbox.selectionStart == '0' )
{
var startPos = textbox.selectionStart;
var endPos = textbox.selectionEnd;
var scrollTop = textbox.scrollTop;
textbox.value = textbox.value.substring (0, startPos) + ' ' + text + ' ' + textbox.value.substring (endPos, textbox.value.length);

textbox.focus();

textbox.selectionStart = startPos + text.length;
textbox.selectionEnd = startPos + text.length;
textbox.scrollTop = scrollTop;
}
else
{
textbox.value += ' ' + text + ' ';
textbox.focus();
}
}
//]]>