-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdo_volunteer.php
195 lines (141 loc) · 5.64 KB
/
do_volunteer.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
function startsWith($haystack, $needle) {
// search backwards starting from haystack length characters from the end
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
}
function endsWith($haystack, $needle) {
// search forward starting from end minus needle length characters
return $needle === "" || strpos($haystack, $needle, strlen($haystack) - strlen($needle)) !== FALSE;
}
include_once("config/database.php");
include_once("config/mail.php");
include_once("language/language.php");
require_once("engine/bo/AddressBo.php");
require_once("engine/bo/DocumentBo.php");
require_once("engine/bo/UserBo.php");
$connection = openConnection();
$addressBo = AddressBo::newInstance($connection);
$documentBo = DocumentBo::newInstance($connection);
$data = array();
if (!count($_REQUEST)) {
$data["ko"] = "ko";
echo json_encode($data);
exit();
}
if ($_REQUEST["email"]) {
exit();
}
$email = $_REQUEST["xxx"];
$confirmationMail = $_REQUEST["confirmationMail"];
if ($confirmationMail != $email) {
$data["ko"] = "ko";
}
else {
$address = array();
$firstname = $_REQUEST["firstname"];
$lastname = $_REQUEST["lastname"];
$address["add_entity"] = $firstname . " " . $lastname;
$address["add_line_1"] = $_REQUEST["line1"];
$address["add_line_2"] = $_REQUEST["line2"];
$address["add_zip_code"] = $_REQUEST["zipCode"];
$address["add_city"] = $_REQUEST["city"];
$address["add_company_name"] = "";
$address["add_country_id"] = 1;
$addressBo->addAddress($address);
$data["address_id"] = $address["add_id"];
$candidature = array();
$candidature["can_bodyshot_id"] = null;
$basePath = $_SERVER["SCRIPT_FILENAME"];
$basePath = substr($basePath, 0, strrpos($basePath, "/") + 1);
$documentPath = $config["document_directory"];
if (!endsWith($documentPath, "/")) {
$documentPath .= "/";
}
if (isset($_FILES["bodyshotFile"])) {
$file = $_FILES["bodyshotFile"];
if ($file["name"]) {
$document = array();
$data['files']["bodyshotFile"]['src'] = $file["name"];
$filename = time() . rand(0, time());
$computeFilename = UserBo::computePassword($filename);
move_uploaded_file($file["tmp_name"], $basePath . $documentPath . $computeFilename);
$document = array();
$document["doc_task_id"] = null;
$document["doc_campaign_id"] = null;
$document["doc_name"] = $file["name"];
$document["doc_size"] = $file["size"];
$document["doc_mime_type"] = $file["type"];
$document["doc_label"] = "bodyshot";
$document["doc_path"] = $documentPath . $computeFilename;
$documentBo->addDocument($document);
$data['files']["bodyshotFile"]['id'] = $document["doc_id"];
$candidature["can_bodyshot_id"] = $document["doc_id"];
}
}
$positions = explode(",", $_REQUEST["candidateInput"]);
// $positions = json_encode($positions);
$circonscriptions = explode(",", $_REQUEST["circonscriptions"]);
// $circonscriptions = json_encode($circonscriptions);
$candidature["can_address_id"] = $address["add_id"];
$candidature["can_sex"] = $_REQUEST["sexInput"];
$candidature["can_firstname"] = $firstname;
$candidature["can_lastname"] = $lastname;
$candidature["can_telephone"] = $_REQUEST["telephone"];
$candidature["can_mail"] = $email;
$candidature["can_authorize"] = isset($_REQUEST["authorize"]) ? $_REQUEST["authorize"] : 0;
$candidature["circonscriptions"] = $circonscriptions;
$candidature["positions"] = $positions;
$addressBo->addCandidature($candidature);
$data["candidature_id"] = $candidature["can_id"];
// Send mail
$mailMessage = "Bonjour
Vous avez manifesté votre volonté de participer aux élections législatives de 2017 sous l'étiquette du Parti Pirate.
Nous l'avons bien pris en compte et nous reviendrons vers vous très prochainement afin d'échanger au sujet de cette candidature.
Piratement,
L'équipe Élections";
$subject = "Votre Candidature aux elections legislatives de 2017 au nom du Parti Pirate";
$mail = getMailInstance();
$mail->setFrom($config["smtp"]["from.address"], $config["smtp"]["from.name"]);
$mail->addReplyTo($config["smtp"]["from.address"], $config["smtp"]["from.name"]);
$mail->Subject = subjectEncode($subject);
$mail->msgHTML(str_replace("\n", "<br>\n", utf8_decode($mailMessage)));
$mail->AltBody = utf8_decode($mailMessage);
$mail->addAddress($email);
$mail->SMTPSecure = "ssl";
if ($mail->send()) {
// echo "Send SN Mails<br/>";
}
$mail = getMailInstance();
$mail->setFrom($config["smtp"]["from.address"], $config["smtp"]["from.name"]);
$mail->addReplyTo($config["smtp"]["from.address"], $config["smtp"]["from.name"]);
$subject = "[2017] Un-e nouvel-le candidat-e";
$mailMessage = "La personne " . $candidature["can_lastname"] . " " . $candidature["can_firstname"] . " a fait acte de candidature.
Informations complémentaires :
------------------------------
Circonscriptions : " . $_REQUEST["circonscriptions"] . "
Positions : ";
$positionSeparator = "";
foreach($positions as $position) {
$mailMessage .= $positionSeparator;
$mailMessage .= lang("candidate_position_" . $position);
$positionSeparator = ", ";
}
$mailMessage .= "
Merci de vous en occuper.
Un bot qui distribue des tâches";
$mail->Subject = subjectEncode($subject);
$mail->msgHTML(str_replace("\n", "<br>\n", utf8_decode($mailMessage)));
$mail->AltBody = utf8_decode($mailMessage);
$mail->addAddress("elections@lists.partipirate.org", "Equipe Elections");
$mail->SMTPSecure = "ssl";
if ($mail->send()) {
// echo "Send SN Mails<br/>";
$data["sent"] = "sent";
}
$data["ok"] = "ok";
}
echo json_encode($data);
?>