0, 'error' => 'Kein Server ausgewählt' ] ) ); } if ( empty( $idLong ) ){ die( json_encode( [ 'status' => 0, 'error' => 'Keine Identität ausgewählt' ] ) ); } if ( empty( $_REQUEST['eventId'] ) || empty( $_REQUEST['votingId'] ) ){ die( json_encode( [ 'status' => 0, 'error' => 'Daten unvollständig' ] ) ); } $msg = new ParTCP_Outgoing_Message( $serverLong, $idLong, 'voting-details-request' ); $msg->set( 'Event-Id', $_REQUEST['eventId'] ); $msg->set( 'Voting-Id', $_REQUEST['votingId'] ); $response = pas_check_response( $msg->send() ); if ( is_string( $response ) ){ die( json_encode( [ 'status' => 0, 'error' => $response ] ) ); } $voting = $response->get('Voting-Data'); if ( empty( $voting['voting_result']['options'] ) ){ die( json_encode( [ 'status' => 0, 'error' => 'Stimmen wurden noch nicht ausgezählt' ] ) ); } include dirname( __DIR__ ) . '/inc/voting_types.php'; $type = $votingTypes[ $voting['type'] ]; $options = array_column( $voting['options'], NULL, 'id' ); $results = []; foreach ( $voting['voting_result']['options'] as $option => $votes ){ $row = []; $row['id'] = substr( $option, 7 ); $row['name'] = $options[ $row['id'] ]['name']; foreach ( $type['values'] as $key => $name ){ $row[ $key ] = $votes[ "vote:{$key}" ] ?? 0; } $results[] = $row; } $fp = fopen( 'php://memory', 'r+' ); if ( empty( $type['labels'] ) ){ fputcsv( $fp, array_merge( [ 'ID', 'Option', 'Stimmen' ] ) ); } else { fputcsv( $fp, array_merge( [ 'ID', 'Option' ], array_values( $type['labels'] ) ) ); } foreach ( $results as $row ){ fputcsv( $fp, array_values( $row ) ); } rewind( $fp ); echo json_encode( [ 'status' => 1, 'file_name' => 'results ' . basename( $_REQUEST['eventId'] ) . " {$_REQUEST['votingId']}.csv", 'file_data' => stream_get_contents( $fp ) ] ); // end of file ajax/export_voting_results.php