-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenviar.php
113 lines (100 loc) · 3.11 KB
/
enviar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?
header('Content-Type: text/html; charset=utf-8');
include('variables.php');
?>
<body style="background: url(assets/img/logo-cra-cor.png) center center no-repeat #fff; height: 100%">
<div style="display: none">
<?
function bindParameters(&$statement, &$params) {
$args = array();
$args[] = implode('', array_values($params));
foreach ($params as $paramName => $paramType) {
$args[] = &$params[$paramName];
$params[$paramName] = null;
}
call_user_func_array(array(&$statement, 'bind_param'), $args);
}
mysqli_report(MYSQLI_REPORT_ALL);
function sql_insert ($data, $typeDef, $table) {
$mysqli = mysqli_connect("$host", "$user", "$pass", "programadorabr");
$keys = array_keys($data);
$vals = array_values($data);
$key = '';
$val = '';
$type = '';
foreach($keys AS $key_value) {
if($key == '') {
$key = 'cra_acervo_'.$key_value;
$val = '?';
} else {
$key .= ', '.'cra_acervo_'.$key_value;
$val .= ',?';
}
}
$stmt = $mysqli->prepare("INSERT INTO $table ($key) values ($val)");
if ($stmt !== false) {
for($i = 0; $i < count($typeDef); $i++) {
/* Set params value for binding */
$params[$keys[$i]] = $typeDef[$i];
}
/* Bind our params */
bindParameters($stmt, $params);
for($i = 0; $i < count($typeDef); $i++) {
/* Set params for query */
$params[$keys[$i]] = $vals[$i];
}
/* Execute the prepared Statement */
if(!$stmt->execute() ) { printf("Execute Statement Error: %s\n", $stmt->error); exit; }
/* Close the statement */
$stmt->close();
return true;
}
else {
/* Error */
die ("Mysql Error: " . $mysqli->error);
return false;
}
};
$datas = array_filter($_POST);
$n = count($datas);
$s = array();
for($z = 0; $z < $n; $z++) {
array_push($s,'s');
}
if(sql_insert($datas, $s, "cra_acervo")) {
$to = "[email protected]";
$subject = "[CRA] Nova inscrição: $_POST[dados_id], $_POST[dados_nome]";
$txt = "$datas";
$headers = "From: $_POST[dados_email]" . "\r\n";
if(mail($to,$subject,$txt,$headers)){
?>
<script>
alert("Questionário preenchido com sucesso! Muito obrigado por sua inestimável contribuição.");
window.location = "http://programadorabrasil.gov.br/cra";
</script>
<?
}
else {
?>
<script>
alert("Questionário preenchido com sucesso! Muito obrigado por sua inestimável contribuição.");
window.location = "http://programadorabrasil.gov.br/cra";
</script>
<?
}
}
else {
$to = "[email protected]";
$subject = "[CRA] ERRO: $_POST[dados_id], $_POST[dados_nome]";
$txt = "$datas";
$headers = "From: $_POST[dados_email]" . "\r\n";
mail($to,$subject,$txt,$headers);
?>
<script>
alert("Houve algum erro no processamento de seus dados, por favor tente mais tarde novamente. ");
window.location = "http://programadorabrasil.gov.br/cra";
</script>
<?
}
?>
</div>