if (($this->PageNr == $this->CountPages()) && ($this->Answers == '')) $out .= '<input type="submit" id="Check" name="Check" value="'.$this->CheckButtonName.'" />'.BR; $out .= '</div>'.BR; $out .= '</fieldset>'.BR; $out .= '</form>'.BR; }
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:
<?php require('baza.php'); # wczytanie biblioteki $Test = new Test; # utworzenie egzemplarza klasy Test $Test->PointsPerPage = 1; # zmiana liczby pytań na stronę # wczytanie pytań require('pytania.php'); # wywołanie testu ?>
baza.php
<?php class Point { var $Question; var $Options; var $Answer; } class Test { var $TestName = 'Nazwa'; var $PageName = 'strona'; var $ResultsName = 'wyniki testu'; var $PrevPageButtonName = '< cofnij'; var $NextPageButtonName = 'dalej >'; var $CheckButtonName = 'sprawdz test'; var $Points; var $PointsPerPage = 5; var $PageNr; var $TmpAnswers; var $Answers; var $count_points=0; function CountPages() { } function CountPoints() { } function NewPoint($Question, $Options, $Answer, $Points2) { $Nr = $this->CountPoints() + 1; $this->Points[$Nr] = new Point; $this->Points[$Nr]->Question = $Question; $this->Points[$Nr]->Options = $Options; $this->Points[$Nr]->Answer = $Answer; $this->Points[$Nr]->Points = $Points2; } function ViewPoint($Nr, $SelectedOption, $SelectRightAnswer) { if (($Nr <= $this->CountPoints()) && ($Nr > 0)) { $out = '<li class="point">'.BR; $out .= $this->Points[$Nr]->Question.BR; $out .= '<ul>'.BR; foreach ($this->Points[$Nr]->Options as $Key => $Option) { $Key = $Key + 1; $out .= '<li'; if ($SelectRightAnswer > 0) { $DisabledRadio = 'disabled="disabled" '; if ($Key == $SelectRightAnswer) $out .= ' class="right-answer" style="color:'.$this->CorrectAnswersColor.'"'; elseif ($Key == $SelectedOption) $out .= ' class="wrong-answer" style="color:'.$this->WrongAnswersColor.'"'; } if ($SelectedOption == $Key) $CheckedRadio = 'checked="checked" '; else $CheckedRadio = ''; $out .= '><input type="radio" '.$DisabledRadio.'id="r'.$Nr.$Key.'" name="'.$Nr.'" value="'.$Key.'" '.$CheckedRadio.'/>'; $out .= '<label for="r'.$Nr.$Key.'">'.$Option.'</label></li>'."\r\n"; } $out .= '</ul>'.BR; $out .= '</li>'."\r\n"; return $out; } } function ViewCustomList($FromNr, $NrOfPoints) { for ($i = $FromNr; $i < $FromNr+$NrOfPoints; $i++) if ($this->Answers == '') $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], 0); else $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], $this->Points[$i]->Answer); return $out; } function TakePost() { # zbieranie odpowiedzi $this->TmpAnswers = $_POST['TmpAnswers']; $FromNr = ($_POST['PageNr'] - 1) * $this->PointsPerPage + 1; if ($_POST['PageNr'] == $this->CountPages()) $NrOfPoints = $this->CountPoints() - $FromNr + 1; else $NrOfPoints = $this->PointsPerPage; for ($i = $FromNr; $i < $FromNr + $NrOfPoints; $i++) { if ($_POST[$i] == '') $this->TmpAnswers[$i - 1] = '0'; else $this->TmpAnswers[$i - 1] = $_POST[$i]; } } } # naciśnięcie przycisku NextPage if ($this->CountPages() > $_POST['PageNr']) $this->PageNr = $_POST['PageNr'] + 1; else $this->PageNr = 1; } # naciśnięcie przycisku PrevPage if ($_POST['PageNr'] > 1) $this->PageNr = $_POST['PageNr'] - 1; else $this->PageNr = $this->CountPages(); } } else { # wielkości startowe $this->PageNr = 1; $this->TmpAnswers = $_POST['TmpAnswers']; else for ($i = 1; $i <= $this->CountPoints(); $i++) $this->TmpAnswers .= '0'; } #pobierz czy jest odpowiedz $this->Answers .= $_POST['Answers']; } } #sprawdź odpowiedzi function CheckAnswers() { $this->CorrectAnswers = 0; $this->BlankAnswers = 0; for ($i = 1; $i <= $this->CountPoints(); $i++) { if ($this->TmpAnswers[$i - 1] == $this->Points[$i]->Answer) $this->CorrectAnswers += 1; if ($this->TmpAnswers[$i - 1] == '0') $this->BlankAnswers += 1; else $this->count_points+=$this->Points[$i]->Points[$this->TmpAnswers[$i - 1]-1]; } } function ViewTest() { $this->TakePost(); # formularz wyników $this->CheckAnswers(); $out = '<form id ="test" action="" method="post">'.BR; $out .= '<fieldset>'.BR; $out .= '<legend>'.$this->TestName.' ['.$this->ResultsName.']</legend>'.BR; $out .= '<ul id="results">'.BR; if($this->count_points<50) $out .= 'MAŁO! Twoja ilosc punktow to '.$this->count_points.' ! <br /><br /> .BR; elseif($this->count_points<70) $out .= 'ŚREDNIO, Twoja ilosc punktow to '.$this->count_points.' ! <br /><br /> .BR; elseif($this->count_points<80) $out .= 'DUŻO. Twoja ilosc punktow to '.$this->count_points.' ! <br /><br />.BR; elseif($this->count_points>80) $out .= 'UBER DUŻO. Twoja ilosc punktow to '.$this->count_points.' ! <br /><br />.BR; $out .= '</ul>'.BR; $out .= '<input type="hidden" name="TmpAnswers" value="'.$this->TmpAnswers.'" />'.BR; $out .= '<input type="hidden" name="Answers" value="Check" />'.BR; $out .= '<div id="buttons">'.BR; $out .= '</div>'.BR; $out .= '</fieldset>'.BR; $out .= '</form>'.BR; } else { #formularz pytań i odpowiedzi $out = '<form id ="test" action="" method="post">'.BR; $out .= '<fieldset>'.BR; $out .= '<legend>'.$this->TestName.' ['.$this->PageName.' '.$this->PageNr.'/'.$this->CountPages().']</legend>'.BR; $out .= '<ul>'.BR; $out .= $this->ViewCustomList(($this->PageNr - 1) * $this->PointsPerPage + 1, $this->PointsPerPage); $out .= '</ul>'.BR; $out .= '<input type="hidden" name="TmpAnswers" value="'.$this->TmpAnswers.'" />'.BR; if ($this->Answers != '') $out .= '<input type="hidden" name="Answers" value="'.$this->Answers.'" />'.BR; $out .= '<input type="hidden" name="PageNr" value="'.$this->PageNr.'" />'.BR; $out .= '<div id="buttons">'.BR; if ($this->PageNr > 1) $out .= '<input type="submit" id="PrevPage" name="PrevPage" value="'.$this->PrevPageButtonName.'" />'.BR; if ($this->PageNr < $this->CountPages()) $out .= '<input type="submit" id="NextPage" name="NextPage" value="'.$this->NextPageButtonName.'" />'.BR; if (($this->PageNr == $this->CountPages()) && ($this->Answers == '')) $out .= '<input type="submit" id="Check" name="Check" value="'.$this->CheckButtonName.'" />'.BR; $out .= '</div>'.BR; $out .= '</fieldset>'.BR; $out .= '</form>'.BR; } return $out; } } ?>