Tutortial system


Well this tutorial system is a little messed up but im sure it is well worth it! just so you know it does all come together in the end!
First off run this query in PHP my admin!
PHP Code
  1. CREATE TABLE `tutorials` (
  2. `id` int(11) NOT NULL auto_increment,
  3. `name` varchar(225) NOT NULL,
  4. `tutorial` text NOT NULL,
  5. `approved` varchar(2) NOT NULL default '0',
  6. `type` text NOT NULL,
  7. `desc` text NOT NULL,
  8. `views` varchar(20) NOT NULL default '1',
  9. PRIMARY KEY (`id`)
  10. ) TYPE=MyISAM;

bbcode.php
PHP Code
  1. <?php
  2. session_start(); //allows session
  3. include "config.php";
  4. function bb2html($content){
  5. $content = nl2br($content);
  6.  
  7. $match = array(
  8. '#[ b](.*?)#se', // Bold Tag;;Remove Spaces
  9. '#[ i](.*?)#se', // Italic Tag;;Remove Spaces
  10. '#[ u](.*?)#se', // Underlined Tag;;Remove Spaces
  11. '#[ url=(.*?)](.*?)[/url]#se', // Url Tag;;Remove Spaces
  12. '#[ code ](.*?)[/ code ]#se', // CODE Tag;;Remove Spaces
  13. '#[ img](.*?)[/img]#se', // Image Tag;;Remove Spaces
  14. '#[ php](.*?)[ /php]#se', // PHP Tag;;Remove Spaces
  15. );
  16.  
  17. $replace = array(
  18. "'<b>\1</b>'", // Bold
  19. "'<i>\1</i>'", // Itlaic
  20. "'<u>\1</u>'", //Underlined
  21. "'<a href=\"\1\" target=\"_BLANK\">\2</a>'", // Url
  22. "'
  23. <style type=\"text/css\">
  24. <!--
  25. .style2 {font-size: 11}
  26. -->
  27. </style>
  28. <table width=\"95%\" border=\"0\">
  29. <tr>
  30. <td bgcolor=\"#999999\"><b>Code</b></td>
  31. </tr>
  32. <tr>
  33. <td bgcolor=\"#999999\"><span class=\"style2\">".highlight_string(stripslashes(str_replace('', '', '$1')), true)."</span></td> </tr>
  34. </table>'", // Url
  35. "'<img border=\"0\" src=\"\1\">'", // Image
  36. "'<style type=\"text/css\">
  37. <!--
  38. .style2 {font-size: 12}
  39. -->
  40. </style>
  41. <table width=\"95%\" border=\"0\">
  42. <tr>
  43. <td bgcolor=\"#999999\"><b>PHP Code</b></td>
  44. </tr>
  45. <tr>
  46. <td bgcolor=\"#999999\"><span class=\"style2\">".highlight_string(stripslashes(str_replace('', '', '$1')), true)."</span></td>
  47. </tr>
  48. </table>'"
  49. );
  50.  
  51. return preg_replace($match, $replace, $content); // Replaces the bbcode array with the html array.
  52. }
  53. ?>




Ok so now we have the bbcode next we have the submit tutorials page (addtut.php)
addtut.php
PHP Code
  1. <?php
  2. session_start(); //allows session
  3. include "config.php";
  4. include("bbcode.php");
  5. ?>
  6. <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
  7. <table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
  8. <tr>
  9. <td style="border-style: none; border-width: medium" bgcolor="#3399ff" height="14"><b> <font face="Verdana" size="1" color="#FFFFFF">Submit a tutorial </font></b></td>
  10. </tr>
  11. </table><?
  12. if ($logged[username])
  13. {
  14. // the user is logged in! We continue...
  15. if (!$_POST[update])
  16. {
  17.  
  18. echo("
  19. <form method=\"POST\">
  20. <table width=\"100\">
  21. <tr>
  22. <td align=\"left\" width=\"25%\">
  23. Name of tutorial <br>
  24. </td>
  25. <td align=\"left\">
  26. <input type=\"text\" size=\"25\" class='input' maxlength=\"500\" name=\"name\"></td>
  27. </tr>
  28. <tr>
  29. <td align=\"left\" width=\"25%\">
  30. Description <br>
  31. </td>
  32. <td align=\"left\">
  33. <input type=\"text\" size=\"30\" class='input' maxlength=\"500\" name=\"desc\"></td>
  34. </tr>
  35. <tr>
  36. <td align=\"left\" width=\"25%\">
  37. catagory<br>
  38. </td>
  39. <td align=\"left\">
  40. <select name=\"type\" class='button'>
  41. <option value=\"PHP\">PHP</option>
  42. <option value=\"HTML\">HTML</option>
  43. <option value=\"Photoshop\">Photoshop</option>
  44. <option value=\"CSS\">CSS</option>
  45. <option value=\"Fireworks\">Fireworks</option>
  46. <option value=\"MySQL\">MySQL</option>
  47. <option value=\"Flash\">Flash</option>
  48. <option value=\"Javascript\">Javascript</option>
  49. <option value=\"Tips\">Site tips 'n' tricks</option>
  50. </select></td>
  51. </tr>
  52. <tr>
  53. <td align=\"left\" width=\"25%\">
  54. Tutorial<br></td>
  55. <td align=\"left\">
  56. <textarea name=\"tutorial\" rows='15' class='input' cols='50'>Tutorial here</textarea></td>
  57. </tr>
  58. <td align=\"left\">
  59. <input type=\"submit\" name=\"update\" class='button' value=\"Submit my tutorial!\"></td>
  60. </tr>
  61. </table>
  62. </form>
  63. ");
  64. }
  65. else
  66. {
  67.  
  68. $name = $_POST[name];
  69. $type = $_POST[type];
  70.  
  71.  
  72. $updatebadges = mysql_query("INSERT INTO tutorials (`username`, `tutorial`, `approved`, `name`, `desc`, `type`) VALUES ('$logged[username]','$_POST[tutorial]','0','$name','$_POST[desc]','$type')");
  73. echo("Thank you $logged[username], Your tutorial has been posted for admin review. Check back later to see if it has been approved!");
  74. }
  75. }
  76. else
  77. {
  78. // They aren't logged in!
  79. echo ("Sorry, you MUST be logged in to see this page!");
  80. }
  81. ?>


Ok now the next bit is where we display the tutorials in one catagory so here goes (tutorial.php)
PHP Code
  1. <?
  2.  
  3. session_start(); //allows session
  4. include "config.php";
  5. include("bbcode.php");
  6.  
  7. $cat = $_GET[catagory];
  8. echo("
  9. <table border=\"1\" width=\"100%\" cellspacing=\"0\" id=\"table1\" style=\"border-width: 0px\" cellpadding=\"0\" height=\"16\">
  10. <tr>
  11. <td style=\"border-style: none; border-width: medium\" bgcolor=\"#3399ff\" height=\"14\"><b><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana\">&nbsp;$cat</font></b></td>
  12. </tr>
  13. </table>");
  14. echo("<table width='100%' border='0' bgcolor='#33ccff'>
  15. <tr>
  16. <td width='60%' bgcolor='#33ccff'>Tutorial name and description</td>
  17. <td width='10%' bgcolor='#33ccff'><div align='center'>#Views</div></td>
  18. <td width='20%' bgcolor='#33ccff'><div align='center'>Author</div></td>
  19. </tr>
  20. </table><br>");
  21.  
  22. if ($_GET[catagory])
  23. {
  24. $colour1 = '#ffffff';
  25. $colour2 = '#d8d8d8';
  26. $row_count = 0;
  27. $tutorials = mysql_query("SELECT * from tutorials where type = '$_GET[catagory]' and approved = '1' order by id desc");
  28. while ($tutorial = mysql_fetch_array($tutorials))
  29. {
  30.  
  31. $row_colour = ($row_count % 2) ? $colour1 : $colour2;
  32.  
  33. echo ("<table width='100%' border='0' bgcolor='$row_colour'>
  34. <tr>
  35. <td width='60%'><a href='tutorials.php?&catagory=$_GET[catagory]&id=$tutorial[id]'> $tutorial[name]</a>
  36. $user[desc]</td>
  37. <td width='10%'><div align='center'>$tutorial[views]</div></td>
  38. <td width='20%'><div align='center'>$tutorial[username]</div></td>
  39. </tr>
  40. </table>
  41. ");
  42. $row_count++;
  43. }
  44. }
  45. ELSE
  46. {
  47.  
  48. echo ("HMMMM how did you get here?");
  49.  
  50. }
  51. ?>

tutorials.php
PHP Code
  1. <?
  2. include("bbcode.php");
  3.  
  4. if (!$_GET[catagory])
  5. {
  6. $getuser = mysql_query("SELECT * from tutorials where type = '$_GET[catagory]' and approved = '1'");
  7. while ($user = mysql_fetch_array($getuser))
  8. {
  9. echo ("<a href='tutorials.php?catagory=$_GET[catagory]&name=$_GET[name]'>$user[name]</a>");
  10. }
  11. }
  12. ELSE
  13. {
  14. $getuser = mysql_query("SELECT * from tutorials where id = '$_GET[id]' and approved = '1'");
  15. $usernum = mysql_num_rows($getuser);
  16. if ($usernum == 0)
  17. {
  18. echo ("You need to select a tutorial");
  19. }
  20. else
  21. {
  22. $profile = mysql_fetch_array($getuser);
  23. $content = bb2html($profile[tutorial]);
  24. echo ("<table border=\"1\" width=\"100%\" cellspacing=\"0\" id=\"table1\" style=\"border-width: 0px\" cellpadding=\"0\" height=\"16\">
  25. <tr>
  26. <td style=\"border-style: none; border-width: medium\" bgcolor=\"#3399ff\" height=\"14\"><b><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana\"><b>$profile[name]</b> - <a href='members?user=$profile[username]'><font color='#FFFFFF'>$profile[username] - ");
  27. if($logged[username] && $logged[userlevel] == 6){
  28.  
  29. ?>
  30. [<a href="mtut.php?act=tedit&tid=<? echo ("$profile[id]"); ?>">Edit</a>]
  31. [<a href="mtut.php?act=tdel&tid=<? echo("$profile[id]"); ?>">Delete</a>]
  32. <?
  33. }
  34. echo("
  35. </font></a></font></b></td>
  36. </tr>
  37. </table>
  38.  
  39. <br> $content");
  40. $views=stripslashes($profile['views']);
  41.  
  42. $views++;
  43. mysql_query("UPDATE `tutorials` SET views='$views' WHERE id = '$profile[id]'");
  44.  
  45. }
  46. }
  47. ?>

Ok so now we have add tutorial, view tutorials in catagory now we need view the tutorials...(tutorials.php)
PHP Code
  1. <?
  2. include("bbcode.php");
  3.  
  4. if (!$_GET[catagory])
  5. {
  6. $getuser = mysql_query("SELECT * from tutorials where type = '$_GET[catagory]' and approved = '1'");
  7. while ($user = mysql_fetch_array($getuser))
  8. {
  9. echo ("<a href='tutorials.php?catagory=$_GET[catagory]&name=$_GET[name]'>$user[name]</a>");
  10. }
  11. }
  12. ELSE
  13. {
  14. $getuser = mysql_query("SELECT * from tutorials where id = '$_GET[id]' and approved = '1'");
  15. $usernum = mysql_num_rows($getuser);
  16. if ($usernum == 0)
  17. {
  18. echo ("You need to select a tutorial");
  19. }
  20. else
  21. {
  22. $profile = mysql_fetch_array($getuser);
  23. $content = bb2html($profile[tutorial]);
  24. echo ("<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
  25. <tr>
  26. <td style="border-style: none; border-width: medium" bgcolor="#3399ff" height="14"><b><font color="#FFFFFF" size="1" face="Verdana"><b>$profile[name]</b> - <a href='members?user=$profile[username]'><font color='#FFFFFF'>$profile[username] - ");
  27. if($logged[username] && $logged[userlevel] == 6){
  28.  
  29. ?>
  30. [<a href="mtut.php?act=tedit&tid=<? echo ("$profile[id]"); ?>">Edit</a>]
  31. [<a href="mtut.php?act=tdel&tid=<? echo("$profile[id]"); ?>">Delete</a>]
  32. <?
  33. }
  34. echo("
  35. </font></a></font></b></td>
  36. </tr>
  37. </table>
  38.  
  39. <br> $content");
  40. $views=stripslashes($profile['views']);
  41.  
  42. $views++;
  43. mysql_query("UPDATE `tutorials` SET views='$views' WHERE id = '$profile[id]'");
  44.  
  45. }
  46. }
  47. }
  48. }
  49. }
  50. ?>

Next we have the mtut.php (which allows admins to edit tutorials) PLEASE keep it as mtut.php else the links will not work!
PHP Code
  1. <?php
  2. if($logged[username] && $logged[userlevel] == 6){
  3.  
  4. switch ($_GET['act']) { // Get action
  5.  
  6. case "tedit"; // First action m
  7. $id = $_GET['tid']; // We add slashes for security purposes
  8.  
  9. if ($_POST['Submit']) { // If the form was submitted we check it
  10. $post = ($_POST['post']); // Clean the edited tutorial
  11. if (empty($post)) { // Check to see if the user has anything
  12. exit("You gotta type something. <a href='".$_SERVER['REQUEST_URI']."'>Back?</a>"); // Error go back?
  13. } // Close if
  14. mysql_query("UPDATE `tutorials` SET tutorial = '$post' WHERE id = '$id'"); // Update the new post into the database
  15. echo "Tutorial Updated. "; // Let user know we updated and for them to go back to the post
  16. } else { // Now we show the form if it hasn't been submitted
  17. $q = mysql_fetch_array(mysql_query("SELECT * FROM `tutorials` WHERE id = '$id'")); //Now grab the post from database
  18. $post = ($q['tutorial']); // Clean out post
  19. echo ("
  20. <form method=\"post\">
  21. Post:
  22. <textarea name=\"post\" class='input' cols=\"50\" rows=\"10\">$post </textarea>
  23. <input type=\"submit\" class='button' name=\"Submit\" value=\"Update\" />
  24. </form>
  25. "); // End echo
  26. }
  27. break;
  28. case "tdel";
  29. $id = $_GET['tid'];
  30. if (empty($id) | !is_numeric($id)) {
  31. exit ("Invalid ID given.");
  32. } // All the same stuff up there
  33. $q = mysql_fetch_array(mysql_query("SELECT * FROM `tutorials` WHERE `id` = '$id'")); // First we need the post id from the table tutorial
  34. $pid = $q['id']; // Change it to $pid
  35. mysql_query("DELETE FROM `tutorials` WHERE `id` = '$id'");
  36.  
  37. echo ("Tutorial deleted!!"); // Let user know tutorial was deleted
  38. break;
  39. }
  40. }else{
  41. echo "<b>Error</b>: You Do Not Have Access To This File"; // no access
  42. } //end level check
  43. ?>

So now we need to make the page where admins see all the tutorials to be approved (atut.php)
PHP Code
  1. <?
  2. if($logged[username] && $logged[usrelevel] == 6)
  3. {
  4. echo('<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
  5. <tr>
  6. <td style="border-style: none; border-width: medium" bgcolor="#3399ff" height="14"><b><font color="#FFFFFF" size="1" face="Verdana">Tutorials to be approved</font></b></td>
  7. </tr>
  8. </table><br>');
  9. $getuser = mysql_query("SELECT * from tutorials where approved = '0'");
  10. while ($user = mysql_fetch_array($getuser))
  11. {
  12. // gets all the users information.
  13. echo ("<a href='index.php?page=apptut&id=$user[id]'>$user[name] - $user[type]</a>");
  14. }
  15. }else{
  16. echo("sorry only admins here please");
  17. }
  18. ?>

ok now last but not least we need the admin approval. (apptut.php) *NOTE* that this page does something different to atut.php
PHP Code
  1. <?
  2. include("bbcode.php");
  3. if($logged[username] && $logged[userlevel] == 6)
  4. {
  5. if(!$_POST[update]) {
  6. $getuser = mysql_query("SELECT * from tutorials where id = '$_GET[id]'");
  7. $profile = mysql_fetch_array($getuser);
  8. $content = bb2html($profile[tutorial]);
  9. echo ('Tutorial name:<b>$profile[name]</b></center>
  10. BY: $profile[username]
  11. Catagory - $profile[type]
  12. Tutorial: $content<br><br>
  13. <form method="POST">
  14. Approved? <select name="app" class=\'button\'>
  15. <option value="1">Approve</option>
  16. <option value="2">Decline</option>
  17. </select>
  18. <input type="submit" name="update" class=\'button\' value="Approve/Decline">
  19. </form>');
  20. # The Edit A Badge Form
  21.  
  22. }else{
  23. # The Form Has Been Submitted
  24.  
  25. $updatebadge = mysql_query("UPDATE tutorials SET `approved` = '$_POST[app]' WHERE id = '$_GET[id]'");
  26. echo("The tutorial has been Sorted!");
  27. # Updates Badge
  28. }
  29. }
  30. else{
  31. echo(" Sorry only admins can be here");
  32. }
  33. ?>
Well that concludes. i hope i havent missed anything out! Sorry that it was a bit of a ong tutorial that i could of cut short if i realy tried to. I hope this helps a lot of people that have been requesting tutorial also just one last thing. Please the following code anywhere you like in your usersystem!
PHP Code
  1. <?
  2. if($logged[username] && $logged[userlevel] == 6) {
  3. $tut = mysql_query("select * from tutorials where approved = '0'");
  4. $tut = mysql_num_rows($tut);
  5. echo("<a href='atut.php'> Sort tutorials ($tut) ")
  6. }else{
  7. echo(" ");
  8. }
  9. ?>

I hope this helps some people!
MOD-Dan's Avatar
Author:
Views:
3,681
Rating:
Posted on Sunday 23rd August 2015 at 06:24 AM
xensor
xensor's Avatar
after i am done with the code i will post the new code so it be more understanding that way new people that are looking for ways to add a tutorial system can.
Posted on Sunday 23rd August 2015 at 06:24 AM
xensor
xensor's Avatar
this tutorial is so unorganized and badly written. its so confusing that myself can barely make sense of it.

the 2 tutorial pages are like wow. so many $_GETs to get results when really one should be about showing all the tutorials and then clicking on a link to show a certain record or section.

but one of em isn't that way.
Posted on Sunday 8th June 2008 at 08:59 PM
Adam981
Adam981's Avatar
Well in apptut.php it displays

Tutorial name:$profile[name]
BY: $profile[username] Catagory - $profile[type] Tutorial: $content

mtut.php doesnt display anything


atut.php link doesnt work


addtut.php says it needs to be apprioved but doesnt go into the database
Posted on Sunday 8th June 2008 at 05:54 PM
Diablosblizz
Diablosblizz's Avatar
Adam, some more information other than it doesn't work would be helpful.
Posted on Sunday 8th June 2008 at 03:32 PM
Adam981
Adam981's Avatar
Alright well i added all my code and what not, but this just doesnt want to work.. things that dont work are, atut.php apptut.php mtut.php

can someone either msg me and help me fix it or maybe update the codes? either way please let me know!
Posted on Tuesday 3rd June 2008 at 07:39 PM
ShadowMage
ShadowMage's Avatar
Hey guys, use the Highlighted code. the person who edited added 2 of one file. I'll go fix.
Posted on Tuesday 3rd June 2008 at 07:38 PM
Adam981
Adam981's Avatar
Nathan u should really read the comments made by other users theres a fix for ur error like 3 comments up lol..

PHP Code
  1. echo("<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
Posted on Thursday 17th April 2008 at 06:57 AM
Nathan
Nathan's Avatar
Parse error: syntax error, unexpected T_LNUMBER in /home/rdlegend/public_html/tut/tutorials.php on line 24
Posted on Thursday 17th April 2008 at 06:47 AM
Nathan
Nathan's Avatar
error in app tut

Setup name:" . $profile . " BY: $tutorials[username] Catagory - " . $profile . " Setup: " . $content . "
Posted on Friday 11th April 2008 at 09:30 PM
DanielXP
DanielXP's Avatar
Test you need the blackslash before the quotes inside an echo using the same quotes.

PHP Code
  1. echo("<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">


Its weird because the tutorial has the backslashes in so it should work.