Witam, jestem zielony, ale to naprawdę zielony w PHP, także też zwracam się z prośbą do was, o pomoc.

Mianowicie chodzi mi o takie coś w postaci Quizu, na silnik MyBB - działa to jakoś tak:

- wchodzisz w link z quizem, odpowiadasz na pytania, wysyłasz, wypełniony quiz dostaję na PW forum lub Email, dobrze by było, aby jednak było to połączone z bazą danych forum aby wyciągnąć login nadawcy wysłanego quizu, przeglądając google natknąłem się na taki kod, nie wiem kompletnie co zrobić:
  1. <?php
  2. //Functions used
  3. //MyBB Shizzle
  4. define('IN_MYBB', 1); // Are we in MyBB? Yep!
  5. require "./global.php"; // We need this to get the templates and database functions.
  6. function get_random_numbers($num, $max){
  7. $array = array();
  8. while($num--){
  9. do {
  10. $c = rand(1, $max);
  11. } while (in_array($c, $array));
  12. $array[] = $c;
  13. }
  14. return $array;
  15. }
  16. add_breadcrumb("Quiz", "quiz.php"); // This is the navbit part. People like to know where they are ;)
  17. if(!$mybb->user['uid'] || $mybb->settings['enabled_t10q'] != 1){
  18. error_no_permission();
  19. } else {
  20. $reg = "/".$mybb->settings['t10q_to_group']."/";
  21. $user2= $mybb->user['additionalgroups'];
  22. if($user2!=""){
  23. if(preg_match($reg,$user2)) error("<br />You already have access to the protected forum, you do not need to re-do the quiz.<br /><br />", "Quiz Already Complete!");
  24. }
  25. }
  26. $act = $mybb->input['action'];
  27. if(!$act || $act=="start"){
  28. $uid = intval($mybb->user['uid']);
  29. $query = $db->simple_select("t10q_sessions", "*", "`uid`='".$uid."'");
  30. $session = $db->num_rows($query);
  31. $result = $db->fetch_array($query);
  32. if($session > 0){
  33. $complete = $result['completed'];
  34. if($complete == "true"){
  35. $time = $result['time'];
  36. $hours = ($mybb->settings['t10q_cooldown'] / 60);
  37. if(time() < $time) error("You have already entered the quiz in the last $hours hours. You will be able to re-enter the quiz after the $hours hours is up.");
  38. else $db->delete_query("t10q_sessions","`uid`='".$uid."'");
  39. }
  40. }
  41. $query = $db->simple_select("t10q_questions","*");
  42. $rows = $db->num_rows($query);
  43. $questions = $mybb->settings['t10q_num_questions'];
  44. if($questions > $rows) error('<br />Not enough questions added yet! The setting for number of questions is higher than the number of questions added.<br /><br />', 'Not enough questions!');
  45. $_SESSION['questions'] = get_random_numbers($mybb->settings['t10q_num_questions'], $rows);
  46. $startmsg = $mybb->settings['t10q_start_msg'];
  47. $content = "<tr><td class='trow1'><center><br />
  48. $startmsg<br /><br />
  49. </center></td></tr><tr><td class='trow2'><center><br />
  50. <form action='quiz.php' method='POST'>
  51. <input type='hidden' name='action' value='savequestions' />
  52. <input type='submit' value='Start!' /><br /><br />
  53. </form></center>
  54. </td></tr>";
  55. }
  56. if($act == "savequestions"){
  57. $uid = $mybb->user['uid'];
  58. $query = $db->query("SELECT * FROM `".TABLE_PREFIX."t10q_sessions` WHERE `uid`=$uid");
  59. $num = $db->num_rows($query);
  60. if($num == 0 ){
  61. $questions = implode("|",$_SESSION['questions']);
  62. $array = array(
  63. "uid"=>$uid,
  64. "questions"=>$db->escape_string($questions),
  65. );
  66. $db->insert_query("t10q_sessions", $array);
  67. } else {
  68. $session = $db->fetch_array($query);
  69. $_SESSION['questions'] = explode("|", $session['questions']);
  70. }
  71. header("Location: quiz.php?action=doquiz");
  72. }
  73. if($act == "doquiz"){
  74. $i=0;
  75. if(!isset($_SESSION['questions'])) header('Location: quiz.php');
  76. foreach($_SESSION['questions'] as $qid){
  77. if($i++%2 == 0) $td = 1;
  78. else $td = 2;
  79. $query = $db->simple_select("t10q_questions", "*", "`qid`='".$qid."'");
  80. $question = $db->fetch_array($query);
  81. if($db->num_rows($query) > 0){
  82. $echo .= "<tr><td class='trow".$td."'><br /> <b>".$question['question']."</b><br /><br />";
  83. $an = 1;
  84. foreach(explode("\n",$question['answers']) as $answer){
  85. $echo .= "   <input type='radio' name='".$qid."' value='".$an."'/> $answer<br /><br />";
  86. $an++;
  87. }
  88. $echo .= "</td></tr>";
  89. }
  90. }
  91. $content = "<tr><td class='trow1' style='margin-left: 50px!important;'><center><form action='quiz.php?action=mark' method='POST'><br />
  92. $echo <tr><td class='trow1'><input type='submit' value='Submit!' onclick='return check()'/></td></tr>
  93. <br /><br /></form></center></td></tr>";
  94. }
  95. if($act == "mark"){
  96. if(!isset($_SESSION['questions'])) header('Location: quiz.php');
  97. $correct = 0;
  98. $incorrect = 0;
  99. $uid = intval($mybb->user['uid']);
  100. foreach($_SESSION['questions'] as $qid){
  101. $uanswer = $mybb->input[$qid];
  102. $query = $db->simple_select("t10q_questions","*","`qid`='".$qid."'");
  103. $answer1 = $db->fetch_array($query);
  104. $answer = $answer1['answer'];
  105. if($answer == $uanswer){
  106. $correct++;
  107. $array = array(
  108. "correct"=>$answer1['correct'] + 1,
  109. );
  110. $db->update_query("t10q_questions",$array,"`qid`=$qid");
  111. }
  112. else {
  113. $array = array(
  114. "incorrect"=>$answer1['incorrect'] + 1,
  115. );
  116. $db->update_query("t10q_questions",$array,"`qid`=$qid");
  117. $incorrect++;
  118. }
  119. }
  120. $pass = $mybb->settings['t10q_passrate'];
  121. if($correct >= $pass){
  122. $result = $mybb->user['additionalgroups'];
  123. if(empty($result)){
  124. $groups = $mybb->settings['t10q_to_group'];
  125. } else {
  126. $groups = $result.",".$mybb->settings['t10q_to_group'];
  127. }
  128. $array = array(
  129. "additionalgroups" => $groups,
  130. );
  131. $db->update_query("users",$array,"`uid`='".$uid."'");
  132. $content = "<tr><td class='trow1'>".$mybb->settings['t10q_start_msg']."</td></tr>";#
  133. unset($_SESSION['questions']);
  134. } else {
  135. $setting = $mybb->settings['t10q_cooldown'];
  136. $time = time() + ($setting * 60);
  137. $array = array(
  138. "completed"=>"true",
  139. "time"=>$time,
  140. "result"=>$correct,
  141. );
  142. $db->update_query("t10q_sessions",$array,"`uid`='".$uid."'");
  143. $content = "<tr><td class='trow1'>".$mybb->settings['t10q_fail_msg']."</td></tr>";
  144. unset($_SESSION['questions']);
  145. }
  146. }
  147. $message = "
  148. <html>
  149. <head>
  150. <title>{$mybb->settings['bbname']} - Quiz</title>
  151. {$headerinclude}
  152. <script>
  153. function check(){
  154. var c = confirm('Are you sure you want to submit? Please make sure you have answered all the questions to the best of your ability.');
  155. return c;
  156. }
  157. </script>
  158. </head>
  159. <body>
  160. {$header}
  161. <table border='0' cellspacing='1' cellpadding='4' class='tborder'>
  162. <thead>
  163. <tr>
  164. <td class='thead' colspan='5'>
  165. <div><strong>Quiz</strong><br /><div class='smalltext'></div></div>
  166. </td>
  167. </tr>
  168. </thead>
  169. <tbody>
  170. $content
  171. </tbody>
  172. </table>
  173. {$footer}
  174. </body>
  175. </html>
  176. ";
  177. output_page($message);
  178. ?>

Za rozwiązanie mojego problemu lub udzielenie jakichkolwiek rad byłbym bardzo wdzięczny. smile.gif

Jeśli są inne sposoby, na to to prosiłbym o podanie ich. biggrin.gif

(jeżeli jest to zły dział, to przepraszam i proszę o przeniesienie do właściwego. : )