now stores state in JSON file, added utility to create JSON file
This commit is contained in:
194
includes/elements.php
Normal file
194
includes/elements.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
function print_result_detail_table($answers, $data){
|
||||
$theses_count = sizeof($data['theses']);
|
||||
for($i = 0; $i < sizeof($data['lists']); $i = $i + 1){
|
||||
$classname = str_replace(' ','',$data['lists'][$i]['name']);
|
||||
echo "<th class='hidden-xs hidden-sm list-$classname'>{$data['lists'][$i]['name_x']} (".calculate_points($data['answers'][$i], $answers).")</th>";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
|
||||
for($i = 0; $i < $theses_count; $i = $i + 1){
|
||||
char_to_multiply($answers[$i])==2 ? $star = '<span class="glyphicon glyphicon-star" title="Doppelte Gewichtung"></span>' : $star = '';
|
||||
char_to_multiply($answers[$i])==2 ? $tdcl = ' class="warning"' : $tdcl = '';
|
||||
$labelclass = code_to_labelclass(char_to_value($answers[$i]));
|
||||
echo "<tr$tdcl>\n";
|
||||
echo '<td><p class="text-center">'.$star.'</p></td>';
|
||||
echo '<td><a id="thesis'.$i.'" class="btn '.code_to_btnclass(char_to_value($answers[$i])).' btn-block" onclick="toggleNext(this)">'.$data['theses'][$i]['s'].'</a></td>';
|
||||
for($listid = 0; $listid < sizeof($data['lists']); $listid = $listid + 1){
|
||||
echo get_list_result_td($data, $listid, $i);
|
||||
}
|
||||
echo "</tr>\n";
|
||||
|
||||
// Statements
|
||||
echo "<tr class='multheseslong'><td class='mtl'></td><td class='mtl' colspan='".(sizeof($data['lists'])+1)."'><!--<span class='label $labelclass'>These ".($i+1).": ".$data['theses'][$i]['s']."</span><br>--> <p class='well'>".$data['theses'][$i]['l']."</p>";
|
||||
for($listid = 0; $listid < sizeof($data['lists']); $listid = $listid + 1){
|
||||
echo get_list_statement($data, $listid ,$i);
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function print_list_result_bar($data, $listindex, $answers, $class){
|
||||
$list_name = $data['lists'][$listindex]['name_x'];
|
||||
$list_points = calculate_points($data['answers'][$listindex], $answers);
|
||||
$ach_points = count_achievable_points($answers);
|
||||
if($ach_points != 0){
|
||||
$list_percentage = intval( 100 * $list_points / $ach_points);
|
||||
} else {
|
||||
$list_percentage = 0;
|
||||
}
|
||||
|
||||
echo "<tr class='$class'>
|
||||
<td><b>$list_name</b></td><td>$list_points von $ach_points</td>
|
||||
<td><div class='progress'>
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='$list_points' aria-valuemin='0' aria-valuemax='$ach_points' style='width: $list_percentage%;'>
|
||||
$list_percentage %
|
||||
</div>
|
||||
</div></td>
|
||||
</tr>";
|
||||
|
||||
}
|
||||
|
||||
/* unused
|
||||
function print_list_result_bar_tricolore($list, $votes, $emph, $class){
|
||||
$list_name = $list['name'];
|
||||
$list_percentage_equal = intval( 100 * count_equal_answers($list['answers'], $votes) / count_relevant_answers($votes));
|
||||
$list_percentage_contrary = intval( 100 * count_contrary_answers($list['answers'], $votes) / count_relevant_answers($votes));
|
||||
$list_percentage_medium = 100 - $list_percentage_equal - $list_percentage_contrary;
|
||||
|
||||
echo "<tr class='$class'>
|
||||
<td><b>$list_name</b></td><td>$list_percentage_equal %</td>
|
||||
<td><div class='progress'>
|
||||
<div class='bar bar-success' style='width: $list_percentage_equal%;'></div>
|
||||
<div class='bar bar-warning' style='width: $list_percentage_medium%;'></div>
|
||||
<div class='bar bar-danger' style='width: $list_percentage_contrary%;'></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>";
|
||||
}*/
|
||||
|
||||
function get_list_result_td($data, $listid, $thesisid){
|
||||
$vote = char_to_value($data['answers'][$listid][$thesisid]['selection']);
|
||||
$listclass = "list-".str_replace(' ','',$data['lists'][$listid]['name']);
|
||||
|
||||
if($vote === 'skip'){
|
||||
return "<td class='hidden-xs hidden-sm $listclass'><a class='btn btn-default btn-block disabled listanswer' >-</a></td>\n";
|
||||
}
|
||||
if($vote == 1){
|
||||
return "<td class='hidden-xs hidden-sm $listclass'><a class='btn btn-success btn-block disabled listanswer' ><span class='glyphicon glyphicon-thumbs-up'></span></a></td>\n";
|
||||
}
|
||||
if($vote == 0){
|
||||
return "<td class='hidden-xs hidden-sm $listclass'><a class='btn btn-warning btn-block disabled listanswer' ><span class='glyphicon glyphicon-tree-deciduous'></span></a></td>\n";
|
||||
}
|
||||
if($vote == -1){
|
||||
return "<td class='hidden-xs hidden-sm $listclass'><a class='btn btn-danger btn-block disabled listanswer' ><span class='glyphicon glyphicon-thumbs-down'></i></a></td>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_list_statement($data, $listid, $thesisid){
|
||||
$vote = char_to_value($data['answers'][$listid][$thesisid]['selection']);
|
||||
$etext = $data['answers'][$listid][$thesisid]['statement'];
|
||||
$name = $data['lists'][$listid]['name'];
|
||||
$listclass = "list-".str_replace(' ','',$data['lists'][$listid]['name']);
|
||||
$prefix = "";
|
||||
|
||||
if($vote === 'skip'){
|
||||
$prefix = "<span class='label label-default'>$name</span>\n";
|
||||
}
|
||||
elseif($vote == 1){
|
||||
$prefix = "<span class='label label-success'>$name</span>\n";
|
||||
}
|
||||
elseif($vote == 0){
|
||||
$prefix = "<span class='label label-warning'>$name</span>\n";
|
||||
}
|
||||
elseif($vote == -1){
|
||||
$prefix = "<span class='label label-danger'>$name</span>\n";
|
||||
}
|
||||
|
||||
return "<div class='$listclass'>
|
||||
$prefix
|
||||
<p>$etext</p>
|
||||
</div>\n\n";
|
||||
}
|
||||
|
||||
function code_to_btnclass($int){
|
||||
if($int === 'skip'){
|
||||
return 'btn-default';
|
||||
}
|
||||
if($int == 1){
|
||||
return 'btn-success';
|
||||
}
|
||||
if($int == 0){
|
||||
return 'btn-warning';
|
||||
}
|
||||
if($int == -1){
|
||||
return 'btn-danger';
|
||||
}
|
||||
}
|
||||
|
||||
function code_to_labelclass($int){
|
||||
if($int === 'skip'){
|
||||
return '';
|
||||
}
|
||||
if($int == 1){
|
||||
return 'label-success';
|
||||
}
|
||||
if($int == 0){
|
||||
return 'label-warning';
|
||||
}
|
||||
if($int == -1){
|
||||
return 'label-important';
|
||||
}
|
||||
}
|
||||
|
||||
function pagitem($i, $curr){
|
||||
if($i == $curr){
|
||||
return '<li class="active"><a href="#">'.$i."</a></li>\n";
|
||||
} else {
|
||||
return '<li class=""><a href="mahlowat.php?id='.$i.'">'.$i."</a></li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function print_pagination($theses_count){
|
||||
echo '<ul id="navigation" class="pagination pagination-sm">';
|
||||
for($i = 1; $i < ($theses_count+1); $i = $i + 1){
|
||||
echo "<li><a href='#$i' onclick='loadThesis($i)'>$i</a></li>";
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
function print_thesesbox($theses, $form=false, $list=null){
|
||||
echo '<div id="thesesbox">';
|
||||
|
||||
for($q_id = 0; $q_id < count($theses); $q_id++){
|
||||
echo "<div id='thesis$q_id' class='singlethesis'>";
|
||||
echo "<h1>These ".($q_id+1)."</h1>
|
||||
|
||||
<div class='well well-large statement'>
|
||||
<p style='margin-bottom: 0px;' class='lead'>";
|
||||
|
||||
echo $theses[$q_id]['l'];
|
||||
echo "</p>";
|
||||
if($theses[$q_id]['x'] != ''){
|
||||
echo "<button class='btn btn-link explanationbutton'>Erklärung</button>\n";
|
||||
echo "<div class='explic'>".$theses[$q_id]['x']."</div>";
|
||||
}
|
||||
echo "</div>";
|
||||
|
||||
if($form){
|
||||
$input = $list['comments'][$q_id];
|
||||
echo "<div class='row'>
|
||||
<div class='col-xs-12 col-sm-12 col-md-8 col-md-offset-2'>
|
||||
<textarea id='input-$q_id' name='comments[$q_id]' class='form-control' rows='3' placeholder='Hier die Begründung eingeben...'>$input</textarea>
|
||||
</div>
|
||||
</div>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,405 +0,0 @@
|
||||
<?php
|
||||
|
||||
function count_equal_answers($hsg, $votes){
|
||||
$len = max(sizeof($hsg), sizeof($votes));
|
||||
$count = 0;
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
if($hsg[$i] == $votes[$i] and !('skip' === $my[$i])){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_contrary_answers($hsg, $votes){
|
||||
$len = max(sizeof($hsg), sizeof($votes));
|
||||
$count = 0;
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
if(($hsg[$i] == 1 and $votes[$i] == -1) or ($hsg[$i] == -1 and $votes[$i] == 1)){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_relevant_answers($votes){
|
||||
$count = 0;
|
||||
for($i = 0; $i < sizeof($votes); $i++){
|
||||
if(!('skip' === $my[$i])){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_achievable_points($my, $emph){
|
||||
$count = 0;
|
||||
for($i = 0; $i < sizeof($my); $i++){
|
||||
if(!($my[$i] === 'skip')){
|
||||
$count += 2 * $emph[$i];
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_party_points($hsg, $votes, $emph){
|
||||
return calculate_points($votes, $hsg, $emph);
|
||||
}
|
||||
|
||||
function html_hsg_bar($hsg, $votes, $emph, $class){
|
||||
$hsg_name = $hsg['name_x'];
|
||||
$party_points = count_party_points($hsg['answers'], $votes, $emph);
|
||||
$ach_points = count_achievable_points($votes, $emph);
|
||||
if($ach_points != 0){
|
||||
$hsg_percentage = intval( 100 * $party_points / $ach_points);
|
||||
} else {
|
||||
$hsg_percentage = 0;
|
||||
}
|
||||
|
||||
echo "<tr class='$class'>
|
||||
<td><b>$hsg_name</b></td><td>$party_points von $ach_points</td>
|
||||
<td><div class='progress'>
|
||||
<div class='progress-bar' role='progressbar' aria-valuenow='$party_points' aria-valuemin='0' aria-valuemax='$ach_points' style='width: $hsg_percentage%;'>
|
||||
$hsg_percentage %
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>";
|
||||
|
||||
}
|
||||
|
||||
/* unused
|
||||
function html_hsg_bar_tricolore($hsg, $votes, $emph, $class){
|
||||
$hsg_name = $hsg['name'];
|
||||
$hsg_percentage_equal = intval( 100 * count_equal_answers($hsg['answers'], $votes) / count_relevant_answers($votes));
|
||||
$hsg_percentage_contrary = intval( 100 * count_contrary_answers($hsg['answers'], $votes) / count_relevant_answers($votes));
|
||||
$hsg_percentage_medium = 100 - $hsg_percentage_equal - $hsg_percentage_contrary;
|
||||
|
||||
echo "<tr class='$class'>
|
||||
<td><b>$hsg_name</b></td><td>$hsg_percentage_equal %</td>
|
||||
<td><div class='progress'>
|
||||
<div class='bar bar-success' style='width: $hsg_percentage_equal%;'></div>
|
||||
<div class='bar bar-warning' style='width: $hsg_percentage_medium%;'></div>
|
||||
<div class='bar bar-danger' style='width: $hsg_percentage_contrary%;'></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>";
|
||||
}*/
|
||||
|
||||
function result_from_string($str, $numberoftheses){
|
||||
$answers = Array();
|
||||
$multiplier = Array();
|
||||
$err = false;
|
||||
if(strlen($str) != $numberoftheses){
|
||||
$err = true;
|
||||
} else {
|
||||
$items = str_split($str);
|
||||
for($i = 0; $i < sizeof($items); $i++){
|
||||
if($items[$i] === 'a' ){
|
||||
$answers[$i] = 1;
|
||||
$multiplier[$i] = 1;
|
||||
}
|
||||
elseif($items[$i] === 'b'){
|
||||
$answers[$i] = 0;
|
||||
$multiplier[$i] = 1;
|
||||
}
|
||||
elseif($items[$i] === 'c'){
|
||||
$answers[$i] = -1;
|
||||
$multiplier[$i] = 1;
|
||||
}
|
||||
elseif($items[$i] === 'd'){
|
||||
$answers[$i] = 'skip';
|
||||
$multiplier[$i] = 1;
|
||||
}
|
||||
elseif($items[$i] === 'e' ){
|
||||
$answers[$i] = 1;
|
||||
$multiplier[$i] = 2;
|
||||
}
|
||||
elseif($items[$i] === 'f'){
|
||||
$answers[$i] = 0;
|
||||
$multiplier[$i] = 2;
|
||||
}
|
||||
elseif($items[$i] === 'g'){
|
||||
$answers[$i] = -1;
|
||||
$multiplier[$i] = 2;
|
||||
}
|
||||
elseif($items[$i] === 'h'){
|
||||
$answers[$i] = 'skip';
|
||||
$multiplier[$i] = 2;
|
||||
}
|
||||
else{
|
||||
$err = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($err){
|
||||
for($i = 0; $i < $numberoftheses; $i++){
|
||||
$answers[$i] = 'skip';
|
||||
$multiplier[$i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$retval[0] = $answers;
|
||||
$retval[1] = $multiplier;
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
function result_to_string($answers, $multiplier){
|
||||
$resstring = '';
|
||||
$err = false;
|
||||
for($i = 0; $i < sizeof($answers); $i++){
|
||||
if($answers[$i] === 'skip' && $multiplier[$i] == 1){
|
||||
$resstring .= 'd';
|
||||
}
|
||||
elseif($answers[$i] == 1 && $multiplier[$i] == 1){
|
||||
$resstring .= 'a';
|
||||
}
|
||||
elseif($answers[$i] == 0 && $multiplier[$i] == 1){
|
||||
$resstring .= 'b';
|
||||
}
|
||||
elseif($answers[$i] == -1 && $multiplier[$i] == 1){
|
||||
$resstring .= 'c';
|
||||
}
|
||||
elseif($answers[$i] === 'skip' && $multiplier[$i] == 2){
|
||||
$resstring .= 'h';
|
||||
}
|
||||
elseif($answers[$i] == 1 && $multiplier[$i] == 2){
|
||||
$resstring .= 'e';
|
||||
}
|
||||
elseif($answers[$i] == 0 && $multiplier[$i] == 2){
|
||||
$resstring .= 'f';
|
||||
}
|
||||
elseif($answers[$i] == -1 && $multiplier[$i] == 2){
|
||||
$resstring .= 'g';
|
||||
}
|
||||
else{
|
||||
$err = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($err){
|
||||
return '==error==';
|
||||
}
|
||||
|
||||
return $resstring;
|
||||
}
|
||||
|
||||
function code_to_answer($code){
|
||||
if($code === 'skip'){
|
||||
return '-';
|
||||
}
|
||||
if($code == 1){
|
||||
return 'Zustimmung';
|
||||
}
|
||||
if($code == 0){
|
||||
return 'Neutral';
|
||||
}
|
||||
if($code == -1){
|
||||
return 'Ablehnung';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function hsg_get_td($hsg, $i){
|
||||
$vote = $hsg['answers'][$i];
|
||||
$hsgclass = "hsg-".str_replace(' ','',$hsg['name']);
|
||||
|
||||
if($vote === 'skip'){
|
||||
return "<td class='hidden-xs hidden-sm $hsgclass'><a class='btn btn-default btn-block disabled hsganswer' >-</a></td>\n";
|
||||
}
|
||||
if($vote == 1){
|
||||
return "<td class='hidden-xs hidden-sm $hsgclass'><a class='btn btn-success btn-block disabled hsganswer' ><span class='glyphicon glyphicon-thumbs-up'></span></a></td>\n";
|
||||
}
|
||||
if($vote == 0){
|
||||
return "<td class='hidden-xs hidden-sm $hsgclass'><a class='btn btn-warning btn-block disabled hsganswer' ><span class='glyphicon glyphicon-tree-deciduous'></span></a></td>\n";
|
||||
}
|
||||
if($vote == -1){
|
||||
return "<td class='hidden-xs hidden-sm $hsgclass'><a class='btn btn-danger btn-block disabled hsganswer' ><span class='glyphicon glyphicon-thumbs-down'></i></a></td>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function hsg_get_explanation($hsg, $i){
|
||||
$vote = $hsg['answers'][$i];
|
||||
$etext = $hsg['comments'][$i];
|
||||
$name = $hsg['name'];
|
||||
$hsgclass = "hsg-".str_replace(' ','',$hsg['name']);
|
||||
$prefix = "";
|
||||
|
||||
if($vote === 'skip'){
|
||||
$prefix = "<span class='label label-default'>$name</span>\n";
|
||||
}
|
||||
elseif($vote == 1){
|
||||
$prefix = "<span class='label label-success'>$name</span>\n";
|
||||
}
|
||||
elseif($vote == 0){
|
||||
$prefix = "<span class='label label-warning'>$name</span>\n";
|
||||
}
|
||||
elseif($vote == -1){
|
||||
$prefix = "<span class='label label-danger'>$name</span>\n";
|
||||
}
|
||||
|
||||
return "<div class='$hsgclass'>
|
||||
$prefix
|
||||
<p>$etext</p>
|
||||
</div>\n\n";
|
||||
}
|
||||
|
||||
function code_to_btnclass($int){
|
||||
if($int === 'skip'){
|
||||
return 'btn-default';
|
||||
}
|
||||
if($int == 1){
|
||||
return 'btn-success';
|
||||
}
|
||||
if($int == 0){
|
||||
return 'btn-warning';
|
||||
}
|
||||
if($int == -1){
|
||||
return 'btn-danger';
|
||||
}
|
||||
}
|
||||
|
||||
function code_to_labelclass($int){
|
||||
if($int === 'skip'){
|
||||
return '';
|
||||
}
|
||||
if($int == 1){
|
||||
return 'label-success';
|
||||
}
|
||||
if($int == 0){
|
||||
return 'label-warning';
|
||||
}
|
||||
if($int == -1){
|
||||
return 'label-important';
|
||||
}
|
||||
}
|
||||
|
||||
function calculate_points($my, $hsg, $emph){
|
||||
$max = max(sizeof($my), sizeof($hsg));
|
||||
|
||||
$pointvector = Array();
|
||||
/* my = skip: skip / skip
|
||||
* my != skip && hsg = skip: +0 / +0
|
||||
* |my - hsg| = 0: +2 / +4
|
||||
* |my - hsg| = 1: +1 / +2
|
||||
* |my - hsg| = 2: +0 / +0
|
||||
*/
|
||||
for($i = 0; $i < $max; $i = $i + 1){
|
||||
$pointvector[$i] = 0;
|
||||
if($my[$i] === 'skip'){continue;}
|
||||
elseif(!('skip' === $my[$i]) and $hsg[$i] === 'skip'){$pointvector[$i] = 0;}
|
||||
else{ $pointvector[$i] = 2-abs($my[$i]-$hsg[$i]);}
|
||||
}
|
||||
|
||||
$pointvector = vec_mul($pointvector, $emph);
|
||||
|
||||
return vectorsum($pointvector);
|
||||
|
||||
}
|
||||
|
||||
function vectorsum($vec){
|
||||
$sum = 0;
|
||||
for($i = 0; $i < sizeof($vec); $i = $i + 1){
|
||||
$sum = $sum + $vec[$i];
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
|
||||
function vec_mul($a, $b){
|
||||
if(sizeof($a) != sizeof($b)){
|
||||
echo 'vector dimensions do not match|'.sizeof($a).'|'.sizeof($b).'<br />';
|
||||
} else {
|
||||
for($i = 0; $i < sizeof($a); $i = $i + 1){
|
||||
$a[$i] = $a[$i] * $b[$i];
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
function pagitem($i, $curr){
|
||||
if($i == $curr){
|
||||
return '<li class="active"><a href="#">'.$i."</a></li>\n";
|
||||
} else {
|
||||
return '<li class=""><a href="mahlowat.php?id='.$i.'">'.$i."</a></li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function sort_hsgs($my, $hsg_array, $emph){
|
||||
$offset = 1/floatval(sizeof($hsg_array));
|
||||
|
||||
for($i = 0; $i < sizeof($hsg_array); $i = $i + 1){
|
||||
$sorted[$i] = (calculate_points($my, $hsg_array[$i]['answers'], $emph)-($i*$offset));
|
||||
$temp[(string)(calculate_points($my, $hsg_array[$i]['answers'], $emph)-($i*$offset))] = $hsg_array[$i];
|
||||
}
|
||||
|
||||
sort($sorted);
|
||||
|
||||
for($i = 0; $i < sizeof($sorted); $i = $i + 1){
|
||||
$sorted[$i] = $temp[(string)$sorted[$i]];
|
||||
}
|
||||
|
||||
$sorted = rev_arr($sorted);
|
||||
|
||||
return $sorted;
|
||||
}
|
||||
|
||||
function rev_arr($arr){
|
||||
$len = sizeof($arr);
|
||||
for($i = 0; $i < (($len / 2)); $i = $i + 1){
|
||||
$temp = $arr[$i];
|
||||
$arr[$i] = $arr[$len - 1 - $i];
|
||||
$arr[$len - 1 - $i] = $temp;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
function print_pagination($theses_count){
|
||||
echo '<ul id="navigation" class="pagination pagination-sm">';
|
||||
for($i = 1; $i < ($theses_count+1); $i = $i + 1){
|
||||
echo "<li><a href='#$i' onclick='loadThesis($i)'>$i</a></li>";
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
function print_thesesbox($theses, $form=false, $hsg=null){
|
||||
echo '<div id="thesesbox">';
|
||||
|
||||
for($q_id = 0; $q_id < count($theses); $q_id++){
|
||||
echo "<div id='thesis$q_id' class='singlethesis'>";
|
||||
echo "<h1>These ".($q_id+1)."</h1>
|
||||
|
||||
<div class='well well-large statement'>
|
||||
<p style='margin-bottom: 0px;' class='lead'>";
|
||||
|
||||
echo $theses[$q_id]['l'];
|
||||
|
||||
echo "</p>";
|
||||
if($theses[$q_id]['x'] != ''){
|
||||
echo "<button class='btn btn-link explanationbutton'>Erklärung</button>\n";
|
||||
echo "<div class='explic'>".$theses[$q_id]['x']."</div>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
|
||||
if($form){
|
||||
$input = $hsg['comments'][$q_id];
|
||||
echo "<div class='row'>
|
||||
<div class='col-xs-12 col-sm-12 col-md-8 col-md-offset-2'>
|
||||
<textarea id='input-$q_id' name='comments[$q_id]' class='form-control' rows='3' placeholder='Hier die Begründung eingeben...'>$input</textarea>
|
||||
</div>
|
||||
</div>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
220
includes/functions.php
Normal file
220
includes/functions.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
function count_equal_answers($list, $votes){
|
||||
$len = max(sizeof($list), sizeof($votes));
|
||||
$count = 0;
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
if($list[$i] == $votes[$i] and !('skip' === $my[$i])){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_contrary_answers($list, $votes){
|
||||
$len = max(sizeof($list), sizeof($votes));
|
||||
$count = 0;
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
if(($list[$i] == 1 and $votes[$i] == -1) or ($list[$i] == -1 and $votes[$i] == 1)){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_relevant_answers($votes){
|
||||
$count = 0;
|
||||
for($i = 0; $i < sizeof($votes); $i++){
|
||||
if(!('skip' === $my[$i])){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_achievable_points($answers){
|
||||
$count = 0;
|
||||
for($i = 0; $i < sizeof($answers); $i++){
|
||||
if(!(char_to_value($answers[$i]) === 'skip')){
|
||||
$count += 2 * char_to_multiply($answers[$i]);
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function count_list_points($list, $answers){
|
||||
return calculate_points($list, $answers);
|
||||
}
|
||||
|
||||
|
||||
function result_from_string($str, $numberoftheses){
|
||||
$answers = Array();
|
||||
$multiplier = Array();
|
||||
$err = false;
|
||||
if(strlen($str) != $numberoftheses){
|
||||
$err = true;
|
||||
} else {
|
||||
$items = str_split($str);
|
||||
for($i = 0; $i < sizeof($items); $i++){
|
||||
$answers[$i] = ($items[$i]);
|
||||
$multiplier[$i] = char_to_multiply($items[$i]);
|
||||
|
||||
if($answers[$i] === 'error' or $multiplier[$i] == 0){
|
||||
$err = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($err){
|
||||
for($i = 0; $i < $numberoftheses; $i++){
|
||||
$answers[$i] = 'skip';
|
||||
$multiplier[$i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$retval[0] = $answers;
|
||||
$retval[1] = $multiplier;
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
function char_to_value($char){
|
||||
switch($char){
|
||||
case 'a':
|
||||
case 'e':
|
||||
return 1;
|
||||
case 'b':
|
||||
case 'f':
|
||||
return 0;
|
||||
case 'c':
|
||||
case 'g':
|
||||
return -1;
|
||||
case 'd':
|
||||
case 'h':
|
||||
return 'skip';
|
||||
default:
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
function char_to_multiply($char){
|
||||
switch($char){
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
return 1;
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'h':
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function calculate_points($list, $answers){
|
||||
$max = max(sizeof($answers), sizeof($list));
|
||||
|
||||
$pointvector = Array();
|
||||
/* my = skip: skip / skip
|
||||
* my != skip && list = skip: +0 / +0
|
||||
* |my - list| = 0: +2 / +4
|
||||
* |my - list| = 1: +1 / +2
|
||||
* |my - list| = 2: +0 / +0
|
||||
*/
|
||||
for($i = 0; $i < $max; $i = $i + 1){
|
||||
$pointvector[$i] = 0;
|
||||
$value = char_to_value($list[$i]['selection']);
|
||||
|
||||
if(char_to_value($answers[$i]) === 'skip'){
|
||||
continue;
|
||||
} elseif(!('skip' === char_to_value($answers[$i])) and $value === 'skip'){
|
||||
$pointvector[$i] = 0;
|
||||
} else {
|
||||
$pointvector[$i] = 2-abs(char_to_value($answers[$i])-$value);
|
||||
}
|
||||
}
|
||||
|
||||
$multiply = Array();
|
||||
for($i = 0; $i < sizeof($answers); $i++){
|
||||
$multiply[$i] = char_to_multiply($answers[$i]);
|
||||
}
|
||||
|
||||
$pointvector = vec_mul($pointvector, $multiply);
|
||||
|
||||
return vectorsum($pointvector);
|
||||
|
||||
}
|
||||
|
||||
function vectorsum($vec){
|
||||
$sum = 0;
|
||||
for($i = 0; $i < sizeof($vec); $i = $i + 1){
|
||||
$sum = $sum + $vec[$i];
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
|
||||
function vec_mul($a, $b){
|
||||
if(sizeof($a) != sizeof($b)){
|
||||
echo 'vector dimensions do not match|'.sizeof($a).'|'.sizeof($b).'<br />';
|
||||
} else {
|
||||
for($i = 0; $i < sizeof($a); $i = $i + 1){
|
||||
$a[$i] = $a[$i] * $b[$i];
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function sort_lists_by_points($data, $answers){
|
||||
$offset = 1/floatval(sizeof($data['lists']));
|
||||
|
||||
$sorted = Array();
|
||||
$temp_answers = Array();
|
||||
$temp_names = Array();
|
||||
for($i = 0; $i < sizeof($data['answers']); $i = $i + 1){
|
||||
$sorted[$i] = (calculate_points($data['answers'][$i], $answers)-($i*$offset));
|
||||
$temp_answers[(string)(calculate_points($data['answers'][$i], $answers)-($i*$offset))] = $data['answers'][$i];
|
||||
$temp_names[(string)(calculate_points($data['answers'][$i], $answers)-($i*$offset))] = $data['lists'][$i];
|
||||
}
|
||||
|
||||
sort($sorted);
|
||||
|
||||
$sorted_answers = Array();
|
||||
$sorted_names = Array();
|
||||
for($i = 0; $i < sizeof($sorted); $i = $i + 1){
|
||||
$sorted_answers[$i] = $temp_answers[(string)$sorted[$i]];
|
||||
$sorted_names[$i] = $temp_names[(string)$sorted[$i]];
|
||||
}
|
||||
|
||||
$sorted_answers = rev_arr($sorted_answers);
|
||||
$sorted_names = rev_arr($sorted_names);
|
||||
|
||||
for($i = 0; $i < sizeof($data['answers']); $i = $i + 1){
|
||||
$data['answers'][$i] = $sorted_answers[$i];
|
||||
$data['lists'][$i] = $sorted_names[$i];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function rev_arr($arr){
|
||||
$len = sizeof($arr);
|
||||
for($i = 0; $i < (($len / 2)); $i = $i + 1){
|
||||
$temp = $arr[$i];
|
||||
$arr[$i] = $arr[$len - 1 - $i];
|
||||
$arr[$len - 1 - $i] = $temp;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
?>
|
||||
116
includes/hsg.php
116
includes/hsg.php
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
function get_hsg_array(){
|
||||
$hsg_array[0]['name'] = 'Liste X';
|
||||
$hsg_array[0]['name_x'] = '<abbr title="Liste X">Liste X</abbr>';
|
||||
$hsg_array[0]['answers'] = Array(1,1,-1,'skip',1,-1,'skip',0,1,1);
|
||||
$hsg_array[0]['comments'] = Array(
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[0]['name']." keine Begründung angegeben."
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$hsg_array[1]['name'] = 'STIFT';
|
||||
$hsg_array[1]['name_x'] = '<abbr title="Kugelschreibär">STIFT</abbr>';
|
||||
$hsg_array[1]['answers'] = Array(-1,0,1,1,1,0,1,-1,-1,1);
|
||||
$hsg_array[1]['comments'] = Array(
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[1]['name']." keine Begründung angegeben."
|
||||
);
|
||||
|
||||
|
||||
|
||||
$hsg_array[2]['name'] = 'Liste Oben';
|
||||
$hsg_array[2]['name_x'] = '<abbr title="Liste Oben">Liste Oben</abbr>';
|
||||
$hsg_array[2]['answers'] = Array(1,-1,-1,1,'skip',-1,-1,1,1,1);
|
||||
$hsg_array[2]['comments'] = Array(
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[2]['name']." keine Begründung angegeben."
|
||||
);
|
||||
|
||||
|
||||
$hsg_array[3]['name'] = 'TACKER';
|
||||
$hsg_array[3]['name_x'] = '<abbr title="The ACKERdemikerliste">TACKER</abbr>';
|
||||
$hsg_array[3]['answers'] = Array(-1,1,1,1,1,-1,1,-1,0,-1);
|
||||
$hsg_array[3]['comments'] = Array(
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[3]['name']." keine Begründung angegeben."
|
||||
);
|
||||
|
||||
|
||||
|
||||
$hsg_array[4]['name'] = 'Vitamin B';
|
||||
$hsg_array[4]['name_x'] = '<abbr title="Vitamin B">Vitamin B</abbr>';
|
||||
$hsg_array[4]['answers'] = Array(1,-1,-1,-1,-1,-1,-1,1,1,1);
|
||||
$hsg_array[4]['comments'] = Array(
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[4]['name']." keine Begründung angegeben."
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$hsg_array[5]['name'] = 'NEIN';
|
||||
$hsg_array[5]['name_x'] = '<abbr title="Niemals nicht">NEIN</abbr>';
|
||||
$hsg_array[5]['answers'] = Array(1,1,-1,0,-1,-1,-1,-1,1,1);
|
||||
$hsg_array[5]['comments'] = Array(
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben.",
|
||||
"Zu dieser These hat ".$hsg_array[5]['name']." keine Begründung angegeben."
|
||||
);
|
||||
|
||||
|
||||
|
||||
return $hsg_array;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
function get_theses_array(){
|
||||
|
||||
$theses_array = Array(
|
||||
Array(
|
||||
"s" => 'These 1',
|
||||
"l" => 'These 1 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam',
|
||||
"x" => 'Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam er'
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 2',
|
||||
"l" => 'These 2 m dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ',
|
||||
"x" => ''
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 3',
|
||||
"l" => 'These 3 ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lore',
|
||||
"x" => 'takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.'
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 4',
|
||||
"l" => 'These 4 sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et ',
|
||||
"x" => 'tetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eo'
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 5',
|
||||
"l" => 'These 5 elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et just',
|
||||
"x" => ''
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 6',
|
||||
"l" => 'These 6 Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel i',
|
||||
"x" => ''
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 7',
|
||||
"l" => 'These 7 tatum zzril delenit augue duis dolore te feugait nulla facilisi',
|
||||
"x" => ''
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 8',
|
||||
"l" => 'These 8 invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eo',
|
||||
"x" => 'ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit a'
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 9',
|
||||
"l" => 'These 9 imata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos',
|
||||
"x" => ''
|
||||
),
|
||||
Array(
|
||||
"s" => 'These 10',
|
||||
"l" => 'These 10 ergren, no sea takimata sanctus est Lorem ipsum dolor',
|
||||
"x" => ''
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
return $theses_array;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user