Witam mam pewien problem, mianowicie nie mogę w tym skrypcie sobie poradzić z tym aby ta funkcja wyświetlała mi test ale po zadaniu wszystkich pytań jedynie wyświetlała link ze strona do odpowiedzi którą generuje w osobnym pliku skryptem. Teraz działa to tak ze albo robi i jedno i drugie albo nie robi nic. Przypuszczam ze rozwiazanie jest w ostatnich kilkudziesieciu linijkach np gdzies tu, no ale pewien nie jestem.

  1.  
  2. if (($this->PageNr == $this->CountPages()) && ($this->Answers == ''))
  3.  
  4.  
  5. $out .= '<input type="submit" id="Check" name="Check" value="'.$this->CheckButtonName.'" />'.BR;
  6. $out .= '</div>'.BR;
  7. $out .= '</fieldset>'.BR;
  8. $out .= '</form>'.BR;
  9.  
  10. }
  11.  
  12.  
  13.  
  14. $fp=@fopen("wynik.html", 'w+');
  15.  
  16. fwrite($fp, "<html><head><title>testfile</title></head><body>");
  17. fwrite($fp, $out);
  18. fwrite($fp, "</body></html>");
  19. fclose($fp);




Nie jestem w tym super zaznajomiony i pomieszały mi się kompletnie zmienne, proszę pomóżcie bo znajoma na mnie liczy a ja nie w porę zdałem sobie sprawę że nie potrafię tego zrobić do końca.

to mam na stronie która wszystko wyswietla:

  1.  
  2. <?php
  3.  
  4. require('baza.php'); # wczytanie biblioteki
  5.  
  6. $Test = new Test; # utworzenie egzemplarza klasy Test
  7.  
  8. $Test->PointsPerPage = 1; # zmiana liczby pytań na stronę
  9.  
  10. # wczytanie pytań
  11.  
  12. require('pytania.php');
  13.  
  14. # wywołanie testu
  15.  
  16. echo $Test->ViewTest();
  17.  
  18. ?>
  19.  


baza.php

  1.  
  2. <?php
  3.  
  4.  
  5. define('BR', "\r\n");
  6.  
  7. class Point
  8. {
  9. var $Question;
  10. var $Options;
  11. var $Answer;
  12. }
  13.  
  14. class Test
  15. {
  16. var $TestName = 'Nazwa';
  17. var $PageName = 'strona';
  18. var $ResultsName = 'wyniki testu';
  19. var $PrevPageButtonName = '< cofnij';
  20. var $NextPageButtonName = 'dalej >';
  21. var $CheckButtonName = 'sprawdz test';
  22.  
  23.  
  24.  
  25. var $Points;
  26. var $PointsPerPage = 5;
  27. var $PageNr;
  28. var $TmpAnswers;
  29. var $Answers;
  30.  
  31. var $count_points=0;
  32.  
  33. function CountPages() {
  34. return ceil($this->CountPoints() / $this->PointsPerPage);
  35. }
  36.  
  37. function CountPoints() {
  38. return count($this->Points);
  39. }
  40.  
  41. function NewPoint($Question, $Options, $Answer, $Points2) {
  42.  
  43. $Nr = $this->CountPoints() + 1;
  44. $this->Points[$Nr] = new Point;
  45. $this->Points[$Nr]->Question = $Question;
  46. $this->Points[$Nr]->Options = $Options;
  47. $this->Points[$Nr]->Answer = $Answer;
  48. $this->Points[$Nr]->Points = $Points2;
  49.  
  50. }
  51.  
  52. function ViewPoint($Nr, $SelectedOption, $SelectRightAnswer) {
  53.  
  54. if (($Nr <= $this->CountPoints()) && ($Nr > 0)) {
  55. $out = '<li class="point">'.BR;
  56. $out .= $this->Points[$Nr]->Question.BR;
  57. $out .= '<ul>'.BR;
  58.  
  59. foreach ($this->Points[$Nr]->Options as $Key => $Option) {
  60.  
  61. $Key = $Key + 1;
  62. $out .= '<li';
  63.  
  64. if ($SelectRightAnswer > 0) {
  65.  
  66. $DisabledRadio = 'disabled="disabled" ';
  67.  
  68. if ($Key == $SelectRightAnswer)
  69. $out .= ' class="right-answer" style="color:'.$this->CorrectAnswersColor.'"';
  70. elseif ($Key == $SelectedOption)
  71. $out .= ' class="wrong-answer" style="color:'.$this->WrongAnswersColor.'"';
  72. }
  73.  
  74. if ($SelectedOption == $Key)
  75. $CheckedRadio = 'checked="checked" ';
  76. else
  77. $CheckedRadio = '';
  78.  
  79. $out .= '><input type="radio" '.$DisabledRadio.'id="r'.$Nr.$Key.'" name="'.$Nr.'" value="'.$Key.'" '.$CheckedRadio.'/>';
  80. $out .= '<label for="r'.$Nr.$Key.'">'.$Option.'</label></li>'."\r\n";
  81. }
  82. $out .= '</ul>'.BR;
  83. $out .= '</li>'."\r\n";
  84. return $out;
  85. }
  86. }
  87.  
  88. function ViewCustomList($FromNr, $NrOfPoints) {
  89.  
  90. for ($i = $FromNr; $i < $FromNr+$NrOfPoints; $i++)
  91. if ($this->Answers == '')
  92. $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], 0);
  93. else
  94. $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], $this->Points[$i]->Answer);
  95.  
  96. return $out;
  97. }
  98.  
  99. function TakePost() {
  100. if (isset($_POST['PageNr'])) {
  101.  
  102. # zbieranie odpowiedzi
  103. if (isset($_POST['TmpAnswers'])) {
  104.  
  105. $this->TmpAnswers = $_POST['TmpAnswers'];
  106.  
  107. if (!isset($_POST['Answers'])) {
  108.  
  109. $FromNr = ($_POST['PageNr'] - 1) * $this->PointsPerPage + 1;
  110.  
  111. if ($_POST['PageNr'] == $this->CountPages())
  112. $NrOfPoints = $this->CountPoints() - $FromNr + 1;
  113. else
  114. $NrOfPoints = $this->PointsPerPage;
  115.  
  116. for ($i = $FromNr; $i < $FromNr + $NrOfPoints; $i++) {
  117.  
  118. if ($_POST[$i] == '')
  119. $this->TmpAnswers[$i - 1] = '0';
  120. else
  121. $this->TmpAnswers[$i - 1] = $_POST[$i];
  122. }
  123. }
  124. }
  125.  
  126. # naciśnięcie przycisku NextPage
  127. if (isset($_POST['NextPage'])) {
  128.  
  129. if ($this->CountPages() > $_POST['PageNr'])
  130.  
  131. $this->PageNr = $_POST['PageNr'] + 1;
  132.  
  133. else
  134.  
  135. $this->PageNr = 1;
  136. }
  137.  
  138. # naciśnięcie przycisku PrevPage
  139. if (isset($_POST['PrevPage'])) {
  140.  
  141. if ($_POST['PageNr'] > 1)
  142.  
  143. $this->PageNr = $_POST['PageNr'] - 1;
  144.  
  145. else
  146.  
  147. $this->PageNr = $this->CountPages();
  148. }
  149.  
  150. } else {
  151.  
  152. # wielkości startowe
  153. $this->PageNr = 1;
  154.  
  155. if (isset($_POST['TmpAnswers']))
  156. $this->TmpAnswers = $_POST['TmpAnswers'];
  157. else
  158. for ($i = 1; $i <= $this->CountPoints(); $i++)
  159. $this->TmpAnswers .= '0';
  160. }
  161.  
  162. #pobierz czy jest odpowiedz
  163. if (isset($_POST['Answers'])) {
  164.  
  165. $this->Answers .= $_POST['Answers'];
  166. }
  167. }
  168.  
  169. #sprawdź odpowiedzi
  170. function CheckAnswers() {
  171.  
  172. $this->CorrectAnswers = 0;
  173. $this->BlankAnswers = 0;
  174.  
  175. for ($i = 1; $i <= $this->CountPoints(); $i++) {
  176. if ($this->TmpAnswers[$i - 1] == $this->Points[$i]->Answer) $this->CorrectAnswers += 1;
  177. if ($this->TmpAnswers[$i - 1] == '0') $this->BlankAnswers += 1;
  178. else $this->count_points+=$this->Points[$i]->Points[$this->TmpAnswers[$i - 1]-1];
  179. }
  180. }
  181.  
  182.  
  183. function ViewTest() {
  184.  
  185. $this->TakePost();
  186.  
  187. if (isset($_POST['Check'])) {
  188.  
  189. # formularz wyników
  190.  
  191.  
  192. $this->CheckAnswers();
  193.  
  194. $out = '<form id ="test" action="" method="post">'.BR;
  195. $out .= '<fieldset>'.BR;
  196. $out .= '<legend>'.$this->TestName.' ['.$this->ResultsName.']</legend>'.BR;
  197. $out .= '<ul id="results">'.BR;
  198.  
  199. if($this->count_points<50) $out .= 'MAŁO! Twoja ilosc punktow to '.$this->count_points.' ! <br /><br /> .BR;
  200. elseif($this->count_points<70) $out .= 'ŚREDNIO, Twoja ilosc punktow to '.$this->count_points.' ! <br /><br /> .BR;
  201. elseif($this->count_points<80) $out .= 'DUŻO. Twoja ilosc punktow to '.$this->count_points.' ! <br /><br />.BR;
  202. elseif($this->count_points>80) $out .= 'UBER DUŻO. Twoja ilosc punktow to '.$this->count_points.' ! <br /><br />.BR;
  203.  
  204. $out .= '</ul>'.BR;
  205. $out .= '<input type="hidden" name="TmpAnswers" value="'.$this->TmpAnswers.'" />'.BR;
  206. $out .= '<input type="hidden" name="Answers" value="Check" />'.BR;
  207. $out .= '<div id="buttons">'.BR;
  208.  
  209. $out .= '</div>'.BR;
  210. $out .= '</fieldset>'.BR;
  211. $out .= '</form>'.BR;
  212.  
  213. } else {
  214.  
  215. #formularz pytań i odpowiedzi
  216.  
  217. $out = '<form id ="test" action="" method="post">'.BR;
  218. $out .= '<fieldset>'.BR;
  219. $out .= '<legend>'.$this->TestName.' ['.$this->PageName.' '.$this->PageNr.'/'.$this->CountPages().']</legend>'.BR;
  220. $out .= '<ul>'.BR;
  221. $out .= $this->ViewCustomList(($this->PageNr - 1) * $this->PointsPerPage + 1, $this->PointsPerPage);
  222. $out .= '</ul>'.BR;
  223. $out .= '<input type="hidden" name="TmpAnswers" value="'.$this->TmpAnswers.'" />'.BR;
  224.  
  225.  
  226. if ($this->Answers != '')
  227.  
  228. $out .= '<input type="hidden" name="Answers" value="'.$this->Answers.'" />'.BR;
  229. $out .= '<input type="hidden" name="PageNr" value="'.$this->PageNr.'" />'.BR;
  230. $out .= '<div id="buttons">'.BR;
  231.  
  232.  
  233. if ($this->PageNr > 1)
  234.  
  235. $out .= '<input type="submit" id="PrevPage" name="PrevPage" value="'.$this->PrevPageButtonName.'" />'.BR;
  236.  
  237.  
  238.  
  239. if ($this->PageNr < $this->CountPages())
  240.  
  241. $out .= '<input type="submit" id="NextPage" name="NextPage" value="'.$this->NextPageButtonName.'" />'.BR;
  242.  
  243.  
  244. if (($this->PageNr == $this->CountPages()) && ($this->Answers == ''))
  245.  
  246.  
  247. $out .= '<input type="submit" id="Check" name="Check" value="'.$this->CheckButtonName.'" />'.BR;
  248. $out .= '</div>'.BR;
  249. $out .= '</fieldset>'.BR;
  250. $out .= '</form>'.BR;
  251.  
  252. }
  253.  
  254.  
  255.  
  256. $fp=@fopen("wynik.html", 'w+');
  257.  
  258. fwrite($fp, "<html><head><title>testfile</title></head><body>");
  259. fwrite($fp, $out);
  260. fwrite($fp, "</body></html>");
  261. fclose($fp);
  262.  
  263.  
  264. return $out;
  265. }
  266.  
  267.  
  268. }
  269.  
  270.  
  271.  
  272.  
  273. ?>
  274.