number"; if(isset($data[$id]) && $data[$id] === $map->value) { $data[$id] = $map->text; } } foreach ($texts as $question) { $id = "q$question->number"; $data[$question->text] = $data[$id]; unset($data[$id]); } $data['form'] = $info['title'].'-'.$data['form']; $data["ip"] = get_user_ip(); $data["timestamp"] = time(); try { storeUserSubmission(json_encode($data, JSON_UNESCAPED_UNICODE), $info['qid'], $data['uuid']); } catch (Exception $e) { echo print_error($e->getMessage()); exit; } header("Location: thanks.php?id=$hash"); } /** * Imprime as mensagens de erro padrão: * @param $code - identifica o erro a ser retornado */ function print_error ($code) { switch($code) { case 'key_missing': return "Error: The data could not be stored.
Reason: The 'form' parameter was not sent in the request. This parameter is required, it identifies which form this data is associated."; case 'empty_data': return "Error: The data could not be stored.
Reason: None parameter was sent in the request.
"; } } function get_user_ip () { $ip = ""; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } ?>