2013-01-19 18:38:58 +00:00
< ? php
class Progress
{
var $topic ;
var $progress ;
var $lp_id ;
var $incorrect_answers ;
var $percentArray ;
var $maximum ;
2013-01-20 10:28:56 +00:00
var $passed ;
var $totalresult = array ();
2013-01-19 18:38:58 +00:00
function Progress () {
$this -> progress = array ();
$this -> incorrect_answers = array ();
$this -> maximum = 5 ;
$this -> topic = 0 ;
$this -> lp_id = 0 ;
$this -> percentArray = array ();
2013-01-20 10:28:56 +00:00
$this -> passed = 0 ;
2013-01-19 18:38:58 +00:00
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
function setTopic ( $t_id ){
$this -> topic = $t_id ;
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
function setLp_id ( $lp_id ){
2013-04-10 20:43:51 +00:00
$this -> lp_id = $lp_id ;
2013-01-19 18:38:58 +00:00
}
2013-01-20 10:28:56 +00:00
2013-04-10 20:43:51 +00:00
function setData ( $value ){
$this -> progress = $value ;
}
2013-01-19 18:38:58 +00:00
function getProgress (){
2013-04-10 20:43:51 +00:00
$sql = " SELECT lp_id,date,number,correct,wrong, passed FROM learnprogress WHERE user_id=' " . mysql_real_escape_string ( $_SESSION [ 'profile' ][ 'id' ]) . " ' AND t_id=' " . mysql_real_escape_string ( $this -> topic ) . " ' AND root =' " . mysql_real_escape_string ( $_SESSION [ 'profile' ][ 'root' ]) . " ' order by date " ;
$query = mysql_query ( $sql ) OR die ( mysql_error ());
$i = 1 ;
2013-01-20 10:28:56 +00:00
while ( $progress = mysql_fetch_array ( $query , MYSQL_BOTH )){
2013-01-19 18:38:58 +00:00
$this -> progress [ $i ][ 'lp_id' ] = $progress [ 'lp_id' ];
$this -> progress [ $i ][ 'date' ] = $progress [ 'date' ];
$this -> progress [ $i ][ 'number' ] = $progress [ 'number' ]; // in arra speichern
$this -> progress [ $i ][ 'correct' ] = $progress [ 'correct' ];
$this -> progress [ $i ][ 'wrong' ] = $progress [ 'wrong' ];
2013-01-20 10:28:56 +00:00
$this -> progress [ $i ][ 'passed' ] = $progress [ 'passed' ];
2013-01-19 18:38:58 +00:00
$i ++ ;
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
function count () {
2013-04-10 20:43:51 +00:00
$numberOfTests = count ( $this -> progress );
return $numberOfTests ;
2013-01-19 18:38:58 +00:00
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
function showTable () {
2013-01-20 10:28:56 +00:00
$this -> totalresult [ 'count' ] = 0 ;
$this -> totalresult [ 'passed' ] = 0 ;
2013-01-19 18:38:58 +00:00
if ( count ( $this -> progress ) == 0 ) echo " <div class='h8'> " . Global_07 . " </div> " ;
else {
echo " <br /> <br /> " ;
2013-01-20 10:28:56 +00:00
echo " <table class='table table_progress'> " ;
2013-01-19 18:38:58 +00:00
echo " <tr> " ;
echo " <td class='th th_pos'> " . Global_10 . " </td> " ;
echo " <td class='th th_pos_date'> " . Global_04 . " </td> " ;
echo " <td class='th th_count'> " . Class_Progress_01 . " </td> " ;
echo " <td class='th th_count'> " . Global_03 . " </td> " ;
2013-01-20 10:28:56 +00:00
echo " <td class='th th_count'> " . Statistic_04 . " </td> " ;
2013-01-19 18:38:58 +00:00
echo " <td class='th th_buttons'></td> " ;
echo " </tr> " ;
2013-04-10 20:43:51 +00:00
for ( $i = 1 ; $i <= count ( $this -> progress ); $i ++ ){
2013-01-20 10:28:56 +00:00
if ( 1 == $this -> progress [ $i ][ 'passed' ]) {
$this -> totalresult [ 'passed' ] += 1 ;
}
2013-01-19 18:38:58 +00:00
echo " <tr> " ;
2013-04-10 20:43:51 +00:00
echo " <td class='td'> $i </td> " ;
echo " <td class='td'> " . $this -> progress [ $i ][ 'date' ] . " </td> " ;
echo " <td class='td'> " . $this -> progress [ $i ][ 'number' ] . " </td> " ;
if ( $this -> progress [ $i ][ 'number' ] > 0 ) {
$percent = ( $this -> progress [ $i ][ 'correct' ] / $this -> progress [ $i ][ 'number' ]) * 100 ;
} else {
$percent = 0 ;
}
$percent = round ( $percent , 2 );
2013-04-10 21:30:42 +00:00
echo " <td class='td'> $percent %</td> " ;
echo " <td class='td'> " . $this -> getPassedImage ( $this -> progress [ $i ][ 'passed' ]) . " </td> " ;
echo " <td class='td'> <a href='?site=progress&action=showIncorrectAnswers&lp_id= " ;
echo $this -> progress [ $i ][ 'lp_id' ] . " &t_id= $this->topic '><img src='images/details.png' class='linkimage' alt='' /></a></td> " ;
2013-04-10 20:43:51 +00:00
echo " </tr> " ;
2013-01-19 18:38:58 +00:00
}
2013-04-10 21:56:15 +00:00
$this -> totalresult [ 'count' ] = $i - 1 ;
2013-04-10 20:43:51 +00:00
echo " <tr> " ;
echo " <td class='td' colspan='6' align='center'> " . Statistic_04 . ' ' . $this -> totalresult [ 'passed' ] . '/' . $this -> totalresult [ 'count' ] . " </td> " ;
2013-04-10 21:56:15 +00:00
echo " </tr> \n " ;
2013-01-20 10:28:56 +00:00
echo " </table> " ;
2013-04-10 21:56:15 +00:00
if ( $this -> totalresult [ 'passed' ] > 0 ) {
echo " <form class='info' action='index.php?site=start_test&action=requestCert' method='post'> " ;
echo " <input type='hidden' name='t_id' value=' $this->topic ' /> " ;
echo " <input name='submit' class='Button_middle' type='submit' value=' " . Class_Quiz_11_RequestCert . " ' /> " ;
echo " </form> " ;
}
2013-04-10 20:43:51 +00:00
}
2013-01-19 18:38:58 +00:00
}
2013-01-20 10:28:56 +00:00
2013-04-10 20:43:51 +00:00
function checkProgressData (){
2013-01-19 18:38:58 +00:00
if ( count ( $this -> progress ) == 0 ) echo " <div class='h8'> " . Global_07 . " </div> " ;
else {
$percentArray = array ();
$limit = count ( $this -> progress );
2013-04-10 20:43:51 +00:00
if ( $limit > $this -> maximum ){
$k = ( $limit - $this -> maximum ) + 1 ;
$limit = ( $k + $this -> maximum ) - 1 ;
echo '<h5 class="centered">' . Class_Progress_02 . " " . Class_Progress_03 . " $this->maximum " . Class_Progress_04 . " .</h5> " ;
} else $k = 1 ;
$j = 0 ;
for ( $i = $k ; $i <= $limit ; $i ++ ){
if ( $this -> progress [ $i ][ 'number' ] > 0 ) {
$percent = ( $this -> progress [ $i ][ 'correct' ] / $this -> progress [ $i ][ 'number' ]) * 100 ;
} else {
$percent = 0 ;
}
$this -> percentArray [ $j ][] = $this -> progress [ $i ][ 'date' ];
$this -> percentArray [ $j ][] = $percent ;
$j ++ ;
2013-01-19 18:38:58 +00:00
}
}
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
function showBalken (){
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
$this -> checkProgressData ();
$this -> percentArray = serialize ( $this -> percentArray );
$this -> percentArray = base64_encode ( $this -> percentArray );
$titley = Global_15 ;
$titlex = Global_04 ;
2013-01-20 10:28:56 +00:00
echo " <div id= \" learnprogress \" > \n " ;
2013-01-19 18:38:58 +00:00
echo " <img src='includes/graph_bib/bar.php?data= $this->percentArray &learnpath=true&titley= $titley &titlex= $titlex ' alt='' /> " ;
2013-01-20 10:28:56 +00:00
echo " </div> \n " ;
2013-01-19 18:38:58 +00:00
}
function showGraph (){
$this -> checkProgressData ();
$this -> percentArray = serialize ( $this -> percentArray );
$this -> percentArray = base64_encode ( $this -> percentArray );
$titley = Global_15 ;
$titlex = Global_04 ;
2013-01-20 10:28:56 +00:00
echo " <div id= \" learnprogress \" > \n " ;
2013-01-19 18:38:58 +00:00
echo " <img src='includes/graph_bib/curve.php?percentArray= $this->percentArray &learnpath=true&titley= $titley &titlex= $titlex ' alt='' /> " ;
2013-01-20 10:28:56 +00:00
echo " </div> \n " ;
2013-01-19 18:38:58 +00:00
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
function showPie (){
2013-01-20 10:28:56 +00:00
echo " <div id= \" learnprogress \" > \n " ;
2013-01-19 18:38:58 +00:00
echo " <img src='includes/graph_bib/pie.php' alt='' /> " ;
echo " </div> \n " ;
}
2013-01-20 10:28:56 +00:00
2013-01-19 18:38:58 +00:00
function getIncorrectAnswers ()
{
$sql = " SELECT q_id FROM answers_incorrect WHERE lp_id= " . intval ( $this -> lp_id ) . " " ;
$query = mysql_query ( $sql );
$i = 1 ;
2013-01-20 10:28:56 +00:00
while ( $incorrect_answers = mysql_fetch_array ( $query , MYSQL_BOTH ))
2013-04-10 20:43:51 +00:00
{
$this -> incorrect_answers [ $i ][ 'q_id' ] = $incorrect_answers [ 'q_id' ];
$i ++ ;
}
2013-01-19 18:38:58 +00:00
$this -> showIncorrectAnswers ();
}
2013-01-20 10:28:56 +00:00
function showIncorrectAnswers (){
echo " <form action='?site=progress&action=showTable&t_id= $this->topic ' method='post'> " ;
2013-01-19 18:38:58 +00:00
echo " <fieldset > " ;
echo " <legend class='table_show_incorrect'> " . Class_Progress_08 . " </legend> " ;
echo " <table class='table_show_incorrect'> " ;
2013-01-20 10:28:56 +00:00
2013-04-10 20:43:51 +00:00
for ( $i = 1 ; $i <= count ( $this -> incorrect_answers ); $i ++ ){
2013-01-19 18:38:58 +00:00
echo " <tr> " ;
2013-04-10 20:43:51 +00:00
echo " <td class='nr_incorrect' valign='top'> $i .) </td> " ;
$sql = " SELECT question,qt_id FROM questions WHERE q_id= " . intval ( $this -> incorrect_answers [ $i ][ 'q_id' ]) . " " ;
$query = mysql_query ( $sql );
while ( $question = mysql_fetch_array ( $query , MYSQL_BOTH )) {
2013-01-19 18:38:58 +00:00
if ( $question [ 'qt_id' ] == 4 ){
2013-04-10 20:43:51 +00:00
$questionText = $this -> getFIBQuestion ( $question [ 'question' ]);
2013-01-20 10:28:56 +00:00
2013-04-10 20:43:51 +00:00
echo " <td class='question_incorrect' valign='top'> " . $questionText . " </td> " ;
2013-01-20 10:28:56 +00:00
2013-04-10 20:43:51 +00:00
} else {
2013-01-19 18:38:58 +00:00
echo " <td class='question_incorrect' valign='top'> " . $question [ 'question' ] . " </td> " ;
2013-01-20 10:28:56 +00:00
}
2013-01-19 18:38:58 +00:00
}
2013-04-10 20:43:51 +00:00
echo " </tr> " ;
}
if ( $this -> progress [ $this -> lp_id ][ 'wrong' ] > count ( $this -> incorrect_answers )) {
$number = $this -> progress [ $this -> lp_id ][ 'wrong' ] - count ( $this -> incorrect_answers );
echo " <tr> " ;
echo " <td class='nr_incorrect' valign='top'> </td> " ;
echo " <td class='question_incorrect' valign='top' > " . Class_Progress_06 . " $number " . Class_Progress_07 . " </td> " ;
echo " </tr> " ;
}
2013-01-19 18:38:58 +00:00
echo " <tr> " ;
echo " <td class='nr_incorrect'> </td> " ;
echo " <td class='Button_row' > <input name='submit' class='Button_rightColumn' type='submit' value=' " . Global_02 . " '/></td> " ;
echo " </tr> " ;
echo " </table> " ;
echo " </fieldset> " ;
2013-01-20 10:28:56 +00:00
echo " </form> " ;
}
2013-01-19 18:38:58 +00:00
function getFIBQuestion ( $question ){
2013-04-10 20:43:51 +00:00
$addSlashes = preg_quote ( $question , '[^]' ); // Slash hinzuf<75> gen wenn KLammer gefunden wird
$array = explode ( '\\' , $addSlashes ); // String teilen
$questionText = $question ;
if ( substr_count ( $question , " [ " ) == substr_count ( $question , " ] " )) { // gleiche anzahl von Klammer auf und zu
for ( $i = 1 ; $i <= substr_count ( $question , " [ " ); $i ++ ){ // Wird solange durchlaufne wie Klammern vorhanden sind
$beginPos = strpos ( $questionText , " [ " ); // Anfangspunkt festlegen
$endPos = strpos ( $questionText , " ] " ); // Endpunkt festlegen
$length = (( $endPos + 1 ) - $beginPos ) ; // L<> nge der Strings ermitteln
$answer = substr ( $questionText , $beginPos , $length ); // den String zwischen den Klammern suchen
$questionText = str_replace ( $answer , '(xxx)' , $questionText ); // gespeicherten Wert aus string l<> schen
$answer = str_replace ( " ] " , '' , $answer ); // Klammer entfernen
$key = array_search ( $answer , $array );
$answer = str_replace ( " [ " , '' , $answer ); // Klammer entfernen
}
}
return $questionText ;
2013-01-19 18:38:58 +00:00
}
2013-01-20 10:28:56 +00:00
function getPassedImage ( $passed ){
// returns the image depending on the status of a test result
$img = " <img src='images/details.png' alt='' /> " ;
if ( 0 == $passed ) {
$img = " <img src='images/wrong.png' alt='' /> " ;
}
if ( 1 == $passed ) {
$img = " <img src='images/correct.png' alt='' /> " ;
}
return $img ;
}
}
2013-01-19 18:38:58 +00:00
?>