SandPrince
Registered
такааа... реших да направя и аз една системка за пускане на уроци. та реших да я постна тука преди да я пусна като урок. базирана е на урока ми за форума.
ето о кодовете. демото ще закаснее защото сега нямам време.
nov_urok.php
', 'code', 'code');" onMouseOver="helpline('code')" />
<input type="button" class="button" value="url" name="url" onclick="javascript:tag('url', '', 'url*', '', 'url', 'url');" onMouseOver="helpline('url')" />
<input type="button" class="button" value="img" name="img" onclick="javascript:tag('img', '
', 'img', 'img');" onMouseOver="helpline('img')" />
<hr>
Font size: <select name="fontsize" onChange="font('.value + ']', ''); this.selectedIndex=2;" onMouseOver="helpline('fontsize')" class="form_elements_dropdown">
<option value="50%" >Tiny</option>
<option value="75%" >Small</option>
<option value="100%" selected >Normal</option>
<option value="150%" >Large</option>
<option value="200%" >Huge</option>
</select>
Font color: <select name="fontcolor" onChange="font('[color=' + this.form.fontcolor.options[this.form.fontcolor.selectedIndex].value + ']', '[/color]'); this.selectedIndex=0;" onMouseOver="helpline('fontcolor')" class="form_elements_dropdown" >
<option value="black" style="color:black">Black</option>
<option value="silver" style="color:silver">Silver</option>
<option value="gray" style="color:gray">Gray</option>
<option value="maroon" style="color:maroon">Maroon</option>
<option value="red" style="color:red">Red</option>
<option value="purple" style="colorurple">Purple</option>
<option value="fuchsia" style="color:fuchsia">Fuchsia</option>
<option value="navy" style="color:navy">Navy</option>
<option value="blue" style="color:blue">Blue</option>
<option value="aqua" style="color:aqua">Aqua</option>
<option value="teal" style="color:teal">Teal</option>
<option value="lime" style="color:lime">Lime</option>
<option value="green" style="color:green">Green</option>
<option value="olive" style="colorlive">Olive</option>
<option value="yellow" style="color:yellow">Yellow</option>
<option value="white" style="color:white">White</option> </select>
<hr>
<textarea rows="10" cols="43" name="post" class="form_elements_text"></textarea>
</td>
</tr>
<tr>
<td><strong>Автор</strong></td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
[/code]
add_topic.php
main_forum.php
view_topic.php
таблица: forum_answer.sql
таблица: forum_question.sql
editor.js
";
img_help = "Insert image:
";
url_help = "Insert URL: http://url or URL text";
fontcolor_help = "Font color: text Tip: you can also use color=#FF0000";
fontsize_help = "Font size: small text";
//Function for displaying help information
// Shows the help messages in the helpline window
function helpline(help) {
var helpbox = document.editform.helpbox;
helpbox.value = eval(help + "_help");
}
//Function to confirm reset
function confirm_reset () {
if(confirm("If you continue you will loose everything you have entered so far. \n \n" +
"Click OK to proceed and start again. \n \n Alternatively click cancel to continue " +
"working on your post.")) {
return true;
}
else {
return false;
}
}
//Check the form submission for errors
function checkForm() {
var subject = document.editform.subject;
var post = document.editform.post;
//Check to make sure post lengths are sensible
if (subject.value.length < 2 && post.value.length < 2) {
alert("This is a short post!" + " \n \n " +
"We require that each post (and subject) \n" +
"be at least 2 characters long. \n \n" +
"Go back and try again.");
return false;
}
else { if (subject.value.length < 2) {
alert("We require that the subject \n" +
"be at least 2 characters long. \n \n" +
"Go back and try again.");
return false;
}
else { if (post.value.length < 2) {
alert("We require that each post \n" +
"be at least 2 characters long. \n \n" +
"Go back and try again.");
return false;
}
else {
return true;
}
}
}
}
[/code]
само да кажа че съм ползвал малко от урока за BBCode в сайт и да питам admin дали да го пускам като урок ако работи. казвайте ако има някъде грешки да ги оправям
ето о кодовете. демото ще закаснее защото сега нямам време.
nov_urok.php
Код:
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" height="312">
<tr>
<form id="form1" name="form1" method="post" action="add_topic.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3" bgcolor="#E6E6E6"><strong>Нов урок</strong></td>
</tr>
<tr>
<td width="14%"><strong>Заглавие</strong></td>
<td width="2%">:</td>
<td width="84%"><input name="topic" type="text" id="topic" size="50" /></td>
</tr>
<tr>
<td valign="top" height="127"><strong>Урок</strong></td>
<td valign="top" height="127">:</td>
<td height="127"> <script src="editor.js" type="text/javascript" ></script>
<?
function bbcode($text){
$text=preg_replace("/\[b\](.+?)\[\/b\]/s", '<b>$1</b>',$text);
$text=preg_replace("/\[i\](.+?)\[\/i\]/s", '<i>$1</i>',$text);
$text=preg_replace("/\[u\](.+?)\[\/u\]/s", '<u>$1</u>',$text);
$text=preg_replace("/\[quote\](.+?)\[\/quote\]/s", '<table cellspacing="1" width="100%" border="0"><tr><td>Quote:</td></tr><tr><td width="100%" style="border:solid 1px black">$1</td></tr></table>',$text);
$text=preg_replace("/\[quote\=(.+?)](.+?)\[\/quote\]/s", '<table cellspacing="1" width="100%" border="0"><tr><td>$1 êàçà:</td></tr><tr><td width="100%" style="border:solid 1px black">$2</td></tr></table>',$text);
$text=preg_replace("/\[url\](.+?)\[\/url\]/s", '<a href="$1">$1</a>',$text);
$text=preg_replace("/\[url\=(.+?)\](.+?)\[\/url\]/s", '<a href="$1">$2</a>',$text);
$text=preg_replace("/\[img\](.+?)\[\/img\]/s", '<img src="$1" alt="User submitted image" title="User submitted image"/>',$text);
$text=preg_replace("/\[color\=(.+?)\](.+?)\[\/color\]/s", '<span style="color:$1">$2</span>',$text);
$text=preg_replace("/\[size\=(.+?)\](.+?)\[\/size\]/s", '<span style="font-size:$1">$2</span>',$text);
$text=preg_replace("/\[code\](.+?)\[\/code\]/s",'<table cellspacing="1" width="100%" border="0"><tr><td>Code:</td></tr><tr><td width="100%" style="border:solid 1px black">$1</td></tr></table>',$text);
$text = nl2br($text);
return $text;
}
$htmlcode = $_POST['post'];
if (!$htmlcode){
?>
<form action="bbcode_form.php" method="post" name="editform" onsubmit="return checkForm(this)">
<input type="button" class="button" value="bold" name="bold" onclick="javascript:tag('b', '[b]', 'bold*', '[/b]', 'bold', 'bold');" onMouseOver="helpline('bold')" />
<input type="button" class="button" value="italic" name="italic" onclick="javascript:tag('i', '[i]', 'italic*', '[/i]', 'italic', 'italic');" onMouseOver="helpline('italic')" />
<input type="button" class="button" value="underline" name="underline" onclick="javascript:tag('u', '[u]', 'underline*', '[/u]', 'underline', 'underline');" onMouseOver="helpline('underline')" />
<input type="button" class="button" value="quote" name="quote" onclick="javascript:tag('q', '[quote]', 'quote*', '[/quote]', 'quote', 'quote');" onMouseOver="helpline('quote')" />
<input type="button" class="button" value="code" name="code" onclick="javascript:tag('c', '[code]', 'code*', '
<input type="button" class="button" value="url" name="url" onclick="javascript:tag('url', '', 'url*', '', 'url', 'url');" onMouseOver="helpline('url')" />
<input type="button" class="button" value="img" name="img" onclick="javascript:tag('img', '
<hr>
Font size: <select name="fontsize" onChange="font('.value + ']', ''); this.selectedIndex=2;" onMouseOver="helpline('fontsize')" class="form_elements_dropdown">
<option value="50%" >Tiny</option>
<option value="75%" >Small</option>
<option value="100%" selected >Normal</option>
<option value="150%" >Large</option>
<option value="200%" >Huge</option>
</select>
Font color: <select name="fontcolor" onChange="font('[color=' + this.form.fontcolor.options[this.form.fontcolor.selectedIndex].value + ']', '[/color]'); this.selectedIndex=0;" onMouseOver="helpline('fontcolor')" class="form_elements_dropdown" >
<option value="black" style="color:black">Black</option>
<option value="silver" style="color:silver">Silver</option>
<option value="gray" style="color:gray">Gray</option>
<option value="maroon" style="color:maroon">Maroon</option>
<option value="red" style="color:red">Red</option>
<option value="purple" style="colorurple">Purple</option>
<option value="fuchsia" style="color:fuchsia">Fuchsia</option>
<option value="navy" style="color:navy">Navy</option>
<option value="blue" style="color:blue">Blue</option>
<option value="aqua" style="color:aqua">Aqua</option>
<option value="teal" style="color:teal">Teal</option>
<option value="lime" style="color:lime">Lime</option>
<option value="green" style="color:green">Green</option>
<option value="olive" style="colorlive">Olive</option>
<option value="yellow" style="color:yellow">Yellow</option>
<option value="white" style="color:white">White</option> </select>
<hr>
<textarea rows="10" cols="43" name="post" class="form_elements_text"></textarea>
</td>
</tr>
<tr>
<td><strong>Автор</strong></td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
[/code]
add_topic.php
Код:
<?php
$host="";
$username="";
$password="";
$db_name="";
$tbl_name="forum_question";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get data that sent from form
$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['name'];
$email=$_POST['email'];
$datetime=date("d/m/y h:i:s"); //create date time
$name=htmlspecialchars($name);
$email=htmlspecialchars($email);
$comment=htmlspecialchars($comment);
$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo "<a href=main_forum.php>Виж урока!!!</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
main_forum.php
Код:
<?php
$host="";
$username="";
$password="";
$db_name="";
$tbl_name="forum_question";
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><strong><span lang="bg">
<a href="nov_urok.php">Пусни нов урок</a></span></strong><a href="nov_urok.php"> </a></td>
</tr>
</table>
view_topic.php
Код:
<?php
$host="";
$username="";
$password="";
$db_name="";
$tbl_name="forum_question";
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong><? echo $rows['topic']; ?></strong></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><? echo $rows['detail']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> <strong>Email : </strong><? echo $rows['email'];?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
$tbl_name2="forum_answer"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Email</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Answer</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
</tr>
</table></td>
</tr>
</table><br>
<?
}
$sql3="SELECT view FROM $tbl_name WHERE id='$id'";
$result3=mysql_query($sql3);
$rows=mysql_fetch_array($result3);
$view=$rows['view'];
// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
$result4=mysql_query($sql4);
}
// count more value
$addview=$view+1;
$sql5="update $tbl_name set view='$addview' WHERE id='$id'";
$result5=mysql_query($sql5);
mysql_close();
?>
<BR>
таблица: forum_answer.sql
Код:
CREATE TABLE `forum_answer` (
`question_id` int(4) NOT NULL default '0',
`a_id` int(4) NOT NULL default '0',
`a_name` varchar(65) NOT NULL default '',
`a_email` varchar(65) NOT NULL default '',
`a_answer` longtext NOT NULL,
`a_datetime` varchar(25) NOT NULL default '',
KEY `a_id` (`a_id`)
) TYPE=MyISAM;
таблица: forum_question.sql
Код:
CREATE TABLE `forum_question` (
`id` int(4) NOT NULL auto_increment,
`topic` varchar(255) NOT NULL default '',
`detail` longtext NOT NULL,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`datetime` varchar(25) NOT NULL default '',
`view` int(4) NOT NULL default '0',
`reply` int(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
editor.js
Код:
//Variables for controlling opening and closing tags (function tag)
var b = 2;
var i = 2;
var u = 2;
var q = 2;
var c = 2;
var url = 2;
var img = 2;
//Function for creating non-font tags
function tag(v, tagadd, newbut, tagclose, oldbut, name) {
if (eval(v)%2 == 0) {
eval("window.document.editform."+name+".value = newbut;");
var post = window.document.editform.post.value;
window.document.editform.post.value = post + tagadd;
window.document.editform.post.focus();
} else {
eval("window.document.editform."+name+".value = oldbut;");
var post = window.document.editform.post.value;
window.document.editform.post.value = post + tagclose;
window.document.editform.post.focus();
}
eval(v+"++;");
}
//Function for adding font color and size tags
function font(bbopen, bbclose) {
var post = document.editform.post;
post.value += bbopen + bbclose;
post.focus();
return;
}
//Function for adding smilies
function smilie (smilie) {
var post = document.editform.post;
post.value += smilie;
post.focus();
return;
}
//Helpbox messages
bold_help = "Bold text: [b]text[/b]";
italic_help = "Italic text: [i]text[/i]";
underline_help = "Underline text: [u]text[/u]";
quote_help = "Quote text: [quote]text[/quote] or [quote="name"]text[/quote]";
code_help = "Code display: [code]code
img_help = "Insert image:
url_help = "Insert URL: http://url or URL text";
fontcolor_help = "Font color: text Tip: you can also use color=#FF0000";
fontsize_help = "Font size: small text";
//Function for displaying help information
// Shows the help messages in the helpline window
function helpline(help) {
var helpbox = document.editform.helpbox;
helpbox.value = eval(help + "_help");
}
//Function to confirm reset
function confirm_reset () {
if(confirm("If you continue you will loose everything you have entered so far. \n \n" +
"Click OK to proceed and start again. \n \n Alternatively click cancel to continue " +
"working on your post.")) {
return true;
}
else {
return false;
}
}
//Check the form submission for errors
function checkForm() {
var subject = document.editform.subject;
var post = document.editform.post;
//Check to make sure post lengths are sensible
if (subject.value.length < 2 && post.value.length < 2) {
alert("This is a short post!" + " \n \n " +
"We require that each post (and subject) \n" +
"be at least 2 characters long. \n \n" +
"Go back and try again.");
return false;
}
else { if (subject.value.length < 2) {
alert("We require that the subject \n" +
"be at least 2 characters long. \n \n" +
"Go back and try again.");
return false;
}
else { if (post.value.length < 2) {
alert("We require that each post \n" +
"be at least 2 characters long. \n \n" +
"Go back and try again.");
return false;
}
else {
return true;
}
}
}
}
[/code]
само да кажа че съм ползвал малко от урока за BBCode в сайт и да питам admin дали да го пускам като урок ако работи. казвайте ако има някъде грешки да ги оправям