get( $_REQUEST['t'] ); if ( ! $token || $token['object_class'] != 'event' ){ echo 'Invalid token'; exit; } $votingId = array_pop( $Params ); $eventId = implode( '/', $Params ); $msg = new ParTCP_Outgoing_Message( $token['server'], $token['identity'], 'voting-details-request' ); $msg->set( 'Event-Id', $token['object_id'] ); $msg->set( 'Voting-Id', $_REQUEST['v'] ); $msg->set( 'Include-Event-Data', TRUE ); $response = pas_check_response( $msg->send() ); if ( is_string( $response ) ){ eval( '?'.'>' . $tpl->compile( 'error.html' ) ); exit; } $voting = $response->get('Voting-Data'); $event = $response->get('Event-Data'); if ( empty( $voting['voting_result']['options'] ) ){ die('Ballots have not been counted yet'); } include 'inc/voting_types.php'; $type = $votingTypes[ $voting['type'] ]; $totalVotes = $voting['voting_result']['participants'] - $voting['voting_result']['invalid']; if ( substr( $voting['type'], 0, 15 ) == 'multiple-choice' ){ $count = substr( $voting['type'], 16 ); $totalVotes *= ( $count == 'all' ? count( $voting['options'] ) : (int) $count ); } $options = array_column( $voting['options'], NULL, 'id' ); $results = []; foreach ( $voting['voting_result']['options'] as $option => $votes ){ $optionId = substr( $option, 7 ); $data = $options[ $optionId ]; foreach ( $type['values'] as $key => $name ){ $count = $votes[ "vote:{$key}" ] ?? 0; $data['counts'][ $key ] = [ 'name' => $name, 'count' => $count, 'percentage' => round( 100 * $count / $totalVotes, 3 ), ]; } if ( ! empty( $type['approval'] ) ){ $data['approval'] = $type['approval']( $data['counts'], $totalVotes, count( $options ) ); } $results[] = $data; } eval( '?'.'>' . $tpl->compile('voting_results.html') ); // end of file voting_results.php