<?php /** * VAA * calculate match */ session_start(); $relative_path = "../"; include "../common.php"; //answers of voters $qfile = $relative_path . 'answers_' . $cc . '.json'; $answers = json_decode(file_get_contents($qfile)); $user = get_user_values(); //calculate match, for selected CC only $results = calc_match($user, $answers); //encode user, answers and qcoefs for direct print into file $user_json = json_encode($user); $answers_json = json_encode($answers); //this page $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $smarty->assign('t', $t); $smarty->assign('query_string', $_SERVER['QUERY_STRING']); $smarty->assign('results', $results); $smarty->assign('url', $url); $smarty->assign('user', $user_json); $smarty->assign('answers_json', $answers_json); $smarty->display('match.tpl'); //save results $str = session_id() . "\t" . $settings->election_code . "\t" . date("Y-m-d H:i:s") . "\t" . json_encode($_GET) . "\t" . $_SERVER['REMOTE_ADDR'] . "\n"; $file = fopen('../result.txt', 'a'); fwrite($file, $str);
require '/usr/local/lib/php/Smarty/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->setTemplateDir('../../../smarty/templates/' . $text['template_code']); $smarty->setCompileDir('../../../smarty/templates_c'); //answers of voters $answers = json_decode(file_get_contents('../answers.json')); $answers2 = json_decode(file_get_contents('../answers2.json')); $answers3 = json_decode(file_get_contents('../answers3.json')); //print_r($answers3);die(); //missing voters $missing = json_decode(file_get_contents('../noreply.json')); //extract user values $user = get_user_values(); //calculate match, for selected CC only $results = calc_match($user, $answers, $config); $results2 = calc_match($user, $answers2, $config); //encode user, answers and qcoefs for direct print into file $user_json = json_encode($user); $answers_json = json_encode($answers); $answers2_json = json_encode($answers2); $answers3_json = json_encode($answers3); $qcoefs_json = file_get_contents('../qcoefs.json'); //this page $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //partners if (isset($_GET['partner'])) { $partner = sanitize($_GET['partner']); } else { $partner = 'default'; } if (file_exists('../css/' . $partner . '.css')) {
// put full path to Smarty.class.php require '/usr/local/lib/php/Smarty/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->setTemplateDir('../../smarty/templates'); $smarty->setCompileDir('../../smarty/templates_c'); $smarty->setCacheDir('../../smarty/cache'); $smarty->setConfigDir('../../smarty/configs'); $parties_file = '../../data/answers_jm.json'; $parties_file = '../plzensky-kraj-2012/answers_pl.json'; //extract user values $user = get_user_values(); //read parties $parties = json_decode(file_get_contents($parties_file)); //calculate match $results = calc_match($user, $parties); //create additional link for comparison $additional_string = create_additional_string($results); $smarty->assign('query_string', $_SERVER['QUERY_STRING'] . '&' . $additional_string); $smarty->assign('results', $results); $smarty->display('match.tpl'); /** * creates additional string with order of parties */ function create_additional_string($results) { $out = 'order='; foreach ($results as $row) { $out .= $row['id'] . '|' . $row['result_percent'] . ','; } return rtrim($out, ',');
include "../texts.php"; include "../common.php"; include "../config.php"; // put full path to Smarty.class.php require '/usr/local/lib/php/Smarty/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->setTemplateDir('../../../smarty/templates/' . $text['election_code']); $smarty->setCompileDir('../../../smarty/templates_c'); //answers of voters $answers = json_decode(file_get_contents('../answers.json')); //missing voters $missing = json_decode(file_get_contents('../noreply.json')); //extract user values $user = get_user_values(); //calculate match, for selected CC only $results = calc_match($user, $answers, $config); //create EU link $eu_link = create_eu_link($user, $results[0]['id']); //encode user, answers and qcoefs for direct print into file $user_json = json_encode($user); $answers_json = json_encode($answers); $qcoefs_json = file_get_contents('../qcoefs.json'); //this page $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //partners if (isset($_GET['partner'])) { $partner = sanitize($_GET['partner']); } else { $partner = 'default'; } if (file_exists('../css/' . $partner . '.css')) {
$partner = array('name'=>'ihned','swatch_bar' => 'g', 'swatch_question_body' => 'd', 'swatch_progressbar' => 'a'); break; case 'denik': $partner = array('name'=>'denik','swatch_bar' => 'h', 'swatch_question_body' => 'd', 'swatch_progressbar' => 'a'); break; case 'idnes': $partner = array('name'=>'idnes','swatch_bar' => 'i', 'swatch_question_body' => 'd', 'swatch_progressbar' => 'a'); break; default: $partner = array('name'=>'default','swatch_bar' => 'f', 'swatch_question_body' => 'e', 'swatch_progressbar' => 'e'); } } else */ $partner = array('name' => 'default', 'swatch_bar' => 'q', 'swatch_footer' => 'r', 'swatch_question_body' => 'q', 'swatch_progressbar' => 'q'); //calculate match, for selected CC only //$start = microtime(true); $results = calc_match($user, $candidates); //$time_taken = microtime(true) - $start; //echo $time_taken;die(); //this page $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI']; //winner color //$winner_color[0] = party2color($results[0]['party']); //$winner_color[1] = party2color($results[1]['party']); //$winner_color[2] = party2color($results[2]['party']); $smarty->assign('missing', $missing); $smarty->assign('text', $text); $smarty->assign('partner', $partner); //$smarty->assign('winner_color', $winner_color); $smarty->assign('query_string', $_SERVER['QUERY_STRING']); $smarty->assign('results', $results); $smarty->assign('url', $url);
$partner = array('name' => 'denik', 'swatch_bar' => 'h', 'swatch_question_body' => 'd', 'swatch_progressbar' => 'a'); break; default: $partner = array('name' => 'default', 'swatch_bar' => 'f', 'swatch_question_body' => 'e', 'swatch_progressbar' => 'e'); } } else { $partner = array('name' => 'default', 'swatch_bar' => 'f', 'swatch_question_body' => 'e', 'swatch_progressbar' => 'e'); } //calculate match, for selected CC only $selected_candidates = array(); foreach ($candidates as $c) { if ($c->constituency_code == $cc) { $selected_candidates[] = $c; } } $results = calc_match($user, $selected_candidates); //create additional link for comparison $additional_string = create_additional_string($results); //create twitter and facebook text (in case there are less than 3 parties, using foreach $twitter_text = 'Nejvíc se do Senátu shodnu s '; $facebook_text = 'VolebníKalkulačka.cz pro Senát - obvod ' . $region . ', moje shoda: '; $i = 0; foreach ($results as $r) { $twitter_text .= $r['last_name'] . ' ' . $r['result_percent'] . '%'; $facebook_text .= $r['last_name'] . ' (' . $r['result_percent'] . '%)'; $i++; if ($i == 3) { break; } $twitter_text .= ','; $facebook_text .= ',';