|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <[email protected]> |
|
4
|
|
|
* Copyright (C) 2001-2002 Jean-Louis Bergamo <[email protected]> |
|
5
|
|
|
* Copyright (C) 2006-2013 Laurent Destailleur <[email protected]> |
|
6
|
|
|
* Copyright (C) 2012 Regis Houssin <[email protected]> |
|
7
|
|
|
* Copyright (C) 2012 J. Fernando Lagrange <[email protected]> |
|
8
|
|
|
* Copyright (C) 2018-2023 Frédéric France <[email protected]> |
|
9
|
|
|
* Copyright (C) 2018 Alexandre Spangaro <[email protected]> |
|
10
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
|
11
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU General Public License as published by |
|
15
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
16
|
|
|
* (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU General Public License |
|
24
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* \file htdocs/public/project/new.php |
|
29
|
|
|
* \ingroup project |
|
30
|
|
|
* \brief Page to record a message/lead into a project/lead |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
if (!defined('NOLOGIN')) { |
|
34
|
|
|
define("NOLOGIN", 1); // This means this output page does not require to be logged. |
|
35
|
|
|
} |
|
36
|
|
|
if (!defined('NOCSRFCHECK')) { |
|
37
|
|
|
define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. |
|
38
|
|
|
} |
|
39
|
|
|
if (!defined('NOIPCHECK')) { |
|
40
|
|
|
define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip |
|
41
|
|
|
} |
|
42
|
|
|
if (!defined('NOBROWSERNOTIF')) { |
|
43
|
|
|
define('NOBROWSERNOTIF', '1'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
// For MultiCompany module. |
|
48
|
|
|
// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php |
|
49
|
|
|
// Because 2 entities can have the same ref. |
|
50
|
|
|
$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); |
|
51
|
|
|
if (is_numeric($entity)) { |
|
52
|
|
|
define("DOLENTITY", $entity); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// Load Dolibarr environment |
|
56
|
|
|
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
|
57
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php'; |
|
58
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/json.lib.php'; |
|
59
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/projet/class/project.class.php'; |
|
60
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/class/extrafields.class.php'; |
|
61
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/class/html.formcompany.class.php'; |
|
62
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/date.lib.php'; |
|
63
|
|
|
|
|
64
|
|
|
// Init vars |
|
65
|
|
|
$errmsg = ''; |
|
66
|
|
|
$error = 0; |
|
67
|
|
|
$backtopage = GETPOST('backtopage', 'alpha'); |
|
68
|
|
|
$action = GETPOST('action', 'aZ09'); |
|
69
|
|
|
|
|
70
|
|
|
// Load translation files |
|
71
|
|
|
$langs->loadLangs(array("members", "companies", "install", "other", "projects")); |
|
72
|
|
|
|
|
73
|
|
|
if (!getDolGlobalString('PROJECT_ENABLE_PUBLIC')) { |
|
74
|
|
|
print $langs->trans("Form for public lead registration has not been enabled"); |
|
75
|
|
|
exit; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
|
79
|
|
|
$hookmanager->initHooks(array('publicnewleadcard', 'globalcard')); |
|
80
|
|
|
|
|
81
|
|
|
$extrafields = new ExtraFields($db); |
|
82
|
|
|
|
|
83
|
|
|
$object = new Project($db); |
|
84
|
|
|
|
|
85
|
|
|
$user->loadDefaultValues(); |
|
86
|
|
|
|
|
87
|
|
|
// Security check |
|
88
|
|
|
if (empty($conf->project->enabled)) { |
|
89
|
|
|
httponly_accessforbidden('Module Project not enabled'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Show header for new member |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $title Title |
|
97
|
|
|
* @param string $head Head array |
|
98
|
|
|
* @param int $disablejs More content into html header |
|
99
|
|
|
* @param int $disablehead More content into html header |
|
100
|
|
|
* @param array $arrayofjs Array of complementary js files |
|
101
|
|
|
* @param array $arrayofcss Array of complementary css files |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
|
|
function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = []) |
|
105
|
|
|
{ |
|
106
|
|
|
global $user, $conf, $langs, $mysoc; |
|
107
|
|
|
|
|
108
|
|
|
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers |
|
109
|
|
|
|
|
110
|
|
|
print '<body id="mainbody" class="publicnewmemberform">'; |
|
111
|
|
|
|
|
112
|
|
|
// Define urllogo |
|
113
|
|
|
$width = 0; |
|
114
|
|
|
$urllogo = Images::getLogo($conf->theme, $width, $mysoc->logo_small, $mysoc->logo); |
|
115
|
|
|
|
|
116
|
|
|
print '<div class="center">'; |
|
117
|
|
|
|
|
118
|
|
|
// Output html code for logo |
|
119
|
|
|
if ($urllogo) { |
|
120
|
|
|
print '<div class="backgreypublicpayment">'; |
|
121
|
|
|
print '<div class="logopublicpayment">'; |
|
122
|
|
|
print '<img id="dolpaymentlogo" src="' . $urllogo . '"'; |
|
123
|
|
|
print '>'; |
|
124
|
|
|
print '</div>'; |
|
125
|
|
|
if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) { |
|
126
|
|
|
print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">' . $langs->trans("PoweredBy") . '<br><img class="poweredbyimg" src="' . constant('DOL_URL_ROOT') . '/theme/dolibarr_logo.svg" width="80px"></a></div>'; |
|
127
|
|
|
} |
|
128
|
|
|
print '</div>'; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
if (getDolGlobalString('PROJECT_IMAGE_PUBLIC_NEWLEAD')) { |
|
132
|
|
|
print '<div class="backimagepublicnewlead">'; |
|
133
|
|
|
print '<img id="idPROJECT_IMAGE_PUBLIC_NEWLEAD" src="' . getDolGlobalString('PROJECT_IMAGE_PUBLIC_NEWLEAD') . '">'; |
|
134
|
|
|
print '</div>'; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
print '</div>'; |
|
138
|
|
|
|
|
139
|
|
|
print '<div class="divmainbodylarge">'; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Show footer for new member |
|
144
|
|
|
* |
|
145
|
|
|
* @return void |
|
146
|
|
|
*/ |
|
147
|
|
|
function llxFooterVierge() |
|
148
|
|
|
{ |
|
149
|
|
|
print '</div>'; |
|
150
|
|
|
|
|
151
|
|
|
printCommonFooter('public'); |
|
152
|
|
|
|
|
153
|
|
|
print "</body>\n"; |
|
154
|
|
|
print "</html>\n"; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/* |
|
160
|
|
|
* Actions |
|
161
|
|
|
*/ |
|
162
|
|
|
|
|
163
|
|
|
$parameters = array(); |
|
164
|
|
|
// Note that $action and $object may have been modified by some hooks |
|
165
|
|
|
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); |
|
166
|
|
|
if ($reshook < 0) { |
|
167
|
|
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
// Action called when page is submitted |
|
171
|
|
|
if (empty($reshook) && $action == 'add') { |
|
172
|
|
|
$error = 0; |
|
173
|
|
|
$urlback = ''; |
|
174
|
|
|
|
|
175
|
|
|
$db->begin(); |
|
176
|
|
|
|
|
177
|
|
|
if (!GETPOST("lastname")) { |
|
178
|
|
|
$error++; |
|
179
|
|
|
$errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname")) . "<br>\n"; |
|
180
|
|
|
} |
|
181
|
|
|
if (!GETPOST("firstname")) { |
|
182
|
|
|
$error++; |
|
183
|
|
|
$errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname")) . "<br>\n"; |
|
184
|
|
|
} |
|
185
|
|
|
if (!GETPOST("email")) { |
|
186
|
|
|
$error++; |
|
187
|
|
|
$errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email")) . "<br>\n"; |
|
188
|
|
|
} |
|
189
|
|
|
if (!GETPOST("description")) { |
|
190
|
|
|
$error++; |
|
191
|
|
|
$errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Message")) . "<br>\n"; |
|
192
|
|
|
} |
|
193
|
|
|
if (GETPOST("email") && !isValidEmail(GETPOST("email"))) { |
|
194
|
|
|
$error++; |
|
195
|
|
|
$langs->load("errors"); |
|
196
|
|
|
$errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email")) . "<br>\n"; |
|
197
|
|
|
} |
|
198
|
|
|
// Set default opportunity status |
|
199
|
|
|
$defaultoppstatus = getDolGlobalString('PROJECT_DEFAULT_OPPORTUNITY_STATUS_FOR_ONLINE_LEAD'); |
|
200
|
|
|
if (empty($defaultoppstatus)) { |
|
201
|
|
|
$error++; |
|
202
|
|
|
$langs->load("errors"); |
|
203
|
|
|
$errmsg .= $langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Project")) . "<br>\n"; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
$visibility = getDolGlobalString('PROJET_VISIBILITY'); |
|
207
|
|
|
|
|
208
|
|
|
$proj = new Project($db); |
|
209
|
|
|
$thirdparty = new Societe($db); |
|
210
|
|
|
|
|
211
|
|
|
if (!$error) { |
|
212
|
|
|
// Search thirdparty and set it if found to the new created project |
|
213
|
|
|
$result = $thirdparty->fetch(0, '', '', '', '', '', '', '', '', '', $object->email); |
|
|
|
|
|
|
214
|
|
|
if ($result > 0) { |
|
215
|
|
|
$proj->socid = $thirdparty->id; |
|
216
|
|
|
} else { |
|
217
|
|
|
// Create the prospect |
|
218
|
|
|
if (GETPOST('societe')) { |
|
219
|
|
|
$thirdparty->name = GETPOST('societe'); |
|
|
|
|
|
|
220
|
|
|
$thirdparty->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); |
|
221
|
|
|
} else { |
|
222
|
|
|
$thirdparty->name = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); |
|
223
|
|
|
} |
|
224
|
|
|
$thirdparty->email = GETPOST('email'); |
|
|
|
|
|
|
225
|
|
|
$thirdparty->address = GETPOST('address'); |
|
|
|
|
|
|
226
|
|
|
$thirdparty->zip = GETPOST('zip'); |
|
|
|
|
|
|
227
|
|
|
$thirdparty->town = GETPOST('town'); |
|
|
|
|
|
|
228
|
|
|
$thirdparty->country_id = GETPOSTINT('country_id'); |
|
229
|
|
|
$thirdparty->state_id = GETPOSTINT('state_id'); |
|
230
|
|
|
$thirdparty->client = $thirdparty::PROSPECT; |
|
231
|
|
|
$thirdparty->code_client = 'auto'; |
|
232
|
|
|
$thirdparty->code_fournisseur = 'auto'; |
|
233
|
|
|
|
|
234
|
|
|
// Fill array 'array_options' with data from the form |
|
235
|
|
|
$extrafields->fetch_name_optionals_label($thirdparty->table_element); |
|
236
|
|
|
$ret = $extrafields->setOptionalsFromPost(null, $thirdparty, '', 1); |
|
237
|
|
|
//var_dump($thirdparty->array_options);exit; |
|
238
|
|
|
if ($ret < 0) { |
|
239
|
|
|
$error++; |
|
240
|
|
|
$errmsg = ($extrafields->error ? $extrafields->error . '<br>' : '') . implode('<br>', $extrafields->errors); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
if (!$error) { |
|
244
|
|
|
$result = $thirdparty->create($user); |
|
245
|
|
|
if ($result <= 0) { |
|
246
|
|
|
$error++; |
|
247
|
|
|
$errmsg = ($thirdparty->error ? $thirdparty->error . '<br>' : '') . implode('<br>', $thirdparty->errors); |
|
248
|
|
|
} else { |
|
249
|
|
|
$proj->socid = $thirdparty->id; |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
if (!$error) { |
|
256
|
|
|
// Defined the ref into $defaultref |
|
257
|
|
|
$defaultref = ''; |
|
258
|
|
|
$modele = !getDolGlobalString('PROJECT_ADDON') ? 'mod_project_simple' : $conf->global->PROJECT_ADDON; |
|
259
|
|
|
|
|
260
|
|
|
// Search template files |
|
261
|
|
|
$file = ''; |
|
262
|
|
|
$classname = ''; |
|
263
|
|
|
$filefound = 0; |
|
264
|
|
|
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); |
|
265
|
|
|
foreach ($dirmodels as $reldir) { |
|
266
|
|
|
$file = dol_buildpath($reldir . "core/modules/project/" . $modele . '.php', 0); |
|
267
|
|
|
if (file_exists($file)) { |
|
268
|
|
|
$filefound = 1; |
|
269
|
|
|
$classname = $modele; |
|
270
|
|
|
break; |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
if ($filefound) { |
|
275
|
|
|
$result = dol_include_once($reldir . "core/modules/project/" . $modele . '.php'); |
|
276
|
|
|
$modProject = new $classname(); |
|
277
|
|
|
|
|
278
|
|
|
$defaultref = $modProject->getNextValue($thirdparty, $object); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
if (is_numeric($defaultref) && $defaultref <= 0) { |
|
282
|
|
|
$defaultref = ''; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
if (empty($defaultref)) { |
|
286
|
|
|
$defaultref = 'PJ' . dol_print_date(dol_now(), 'dayrfc'); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
if ($visibility === "1") { |
|
290
|
|
|
$proj->public = 1; |
|
291
|
|
|
} elseif ($visibility === "0") { |
|
292
|
|
|
$proj->public = 0; |
|
293
|
|
|
} elseif (empty($visibility)) { |
|
294
|
|
|
$proj->public = 1; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
$proj->ref = $defaultref; |
|
298
|
|
|
$proj->statut = $proj::STATUS_DRAFT; |
|
299
|
|
|
$proj->status = $proj::STATUS_DRAFT; |
|
300
|
|
|
$proj->usage_opportunity = 1; |
|
301
|
|
|
$proj->title = $langs->trans("LeadFromPublicForm"); |
|
302
|
|
|
$proj->description = GETPOST("description", "alphanohtml"); |
|
|
|
|
|
|
303
|
|
|
$proj->opp_status = $defaultoppstatus; |
|
304
|
|
|
$proj->fk_opp_status = $defaultoppstatus; |
|
305
|
|
|
|
|
306
|
|
|
$proj->ip = getUserRemoteIP(); |
|
307
|
|
|
$nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200); |
|
308
|
|
|
$now = dol_now(); |
|
309
|
|
|
$minmonthpost = dol_time_plus_duree($now, -1, "m"); |
|
310
|
|
|
$nb_post_ip = 0; |
|
311
|
|
|
if ($nb_post_max > 0) { // Calculate only if there is a limit to check |
|
312
|
|
|
$sql = "SELECT COUNT(rowid) as nb_projets"; |
|
313
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "projet"; |
|
314
|
|
|
$sql .= " WHERE ip = '" . $db->escape($proj->ip) . "'"; |
|
315
|
|
|
$sql .= " AND datec > '" . $db->idate($minmonthpost) . "'"; |
|
316
|
|
|
$resql = $db->query($sql); |
|
317
|
|
|
if ($resql) { |
|
318
|
|
|
$num = $db->num_rows($resql); |
|
319
|
|
|
$i = 0; |
|
320
|
|
|
while ($i < $num) { |
|
321
|
|
|
$i++; |
|
322
|
|
|
$obj = $db->fetch_object($resql); |
|
323
|
|
|
$nb_post_ip = $obj->nb_projets; |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
// Fill array 'array_options' with data from the form |
|
329
|
|
|
$extrafields->fetch_name_optionals_label($proj->table_element); |
|
330
|
|
|
$ret = $extrafields->setOptionalsFromPost(null, $proj); |
|
331
|
|
|
if ($ret < 0) { |
|
332
|
|
|
$error++; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) { |
|
336
|
|
|
$error++; |
|
337
|
|
|
$errmsg = $langs->trans("AlreadyTooMuchPostOnThisIPAdress"); |
|
338
|
|
|
array_push($proj->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress")); |
|
339
|
|
|
} |
|
340
|
|
|
// Create the project |
|
341
|
|
|
if (!$error) { |
|
342
|
|
|
$result = $proj->create($user); |
|
343
|
|
|
if ($result > 0) { |
|
344
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/class/CMailFile.class.php'; |
|
345
|
|
|
$object = $proj; |
|
346
|
|
|
|
|
347
|
|
|
if ($object->email) { |
|
348
|
|
|
$subject = ''; |
|
349
|
|
|
$msg = ''; |
|
350
|
|
|
|
|
351
|
|
|
// Send subscription email |
|
352
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; |
|
353
|
|
|
$formmail = new FormMail($db); |
|
354
|
|
|
// Set output language |
|
355
|
|
|
$outputlangs = new Translate('', $conf); |
|
356
|
|
|
$outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); |
|
357
|
|
|
// Load traductions files required by page |
|
358
|
|
|
$outputlangs->loadLangs(array("main", "members", "projects")); |
|
359
|
|
|
// Get email content from template |
|
360
|
|
|
$arraydefaultmessage = null; |
|
361
|
|
|
$labeltouse = getDolGlobalString('PROJECT_EMAIL_TEMPLATE_AUTOLEAD'); |
|
362
|
|
|
|
|
363
|
|
|
if (!empty($labeltouse)) { |
|
364
|
|
|
$arraydefaultmessage = $formmail->getEMailTemplate($db, 'project', $user, $outputlangs, 0, 1, $labeltouse); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { |
|
368
|
|
|
$subject = $arraydefaultmessage->topic; |
|
369
|
|
|
$msg = $arraydefaultmessage->content; |
|
370
|
|
|
} |
|
371
|
|
|
if (empty($labeltosue)) { |
|
372
|
|
|
$appli = $mysoc->name; |
|
373
|
|
|
|
|
374
|
|
|
$labeltouse = '[' . $appli . '] ' . $langs->trans("YourMessage"); |
|
375
|
|
|
$msg = $langs->trans("YourMessageHasBeenReceived"); |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
|
379
|
|
|
complete_substitutions_array($substitutionarray, $outputlangs, $object); |
|
380
|
|
|
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); |
|
381
|
|
|
$texttosend = make_substitutions($msg, $substitutionarray, $outputlangs); |
|
382
|
|
|
if ($subjecttosend && $texttosend) { |
|
383
|
|
|
$moreinheader = 'X-Dolibarr-Info: send_an_email by public/lead/new.php' . "\r\n"; |
|
384
|
|
|
|
|
385
|
|
|
$result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); |
|
386
|
|
|
} |
|
387
|
|
|
/*if ($result < 0) { |
|
388
|
|
|
$error++; |
|
389
|
|
|
setEventMessages($object->error, $object->errors, 'errors'); |
|
390
|
|
|
}*/ |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
if (!empty($backtopage)) { |
|
394
|
|
|
$urlback = $backtopage; |
|
395
|
|
|
} elseif (getDolGlobalString('PROJECT_URL_REDIRECT_LEAD')) { |
|
396
|
|
|
$urlback = getDolGlobalString('PROJECT_URL_REDIRECT_LEAD'); |
|
397
|
|
|
// TODO Make replacement of __AMOUNT__, etc... |
|
398
|
|
|
} else { |
|
399
|
|
|
$urlback = $_SERVER["PHP_SELF"] . "?action=added&token=" . newToken(); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
if (!empty($entity)) { |
|
403
|
|
|
$urlback .= '&entity=' . $entity; |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
|
|
dol_syslog("project lead " . $proj->ref . " has been created, we redirect to " . $urlback); |
|
407
|
|
|
} else { |
|
408
|
|
|
$error++; |
|
409
|
|
|
$errmsg .= $proj->error . '<br>' . implode('<br>', $proj->errors); |
|
410
|
|
|
} |
|
411
|
|
|
} else { |
|
412
|
|
|
setEventMessage($errmsg, 'errors'); |
|
413
|
|
|
} |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
if (!$error) { |
|
417
|
|
|
$db->commit(); |
|
418
|
|
|
|
|
419
|
|
|
header("Location: " . $urlback); |
|
420
|
|
|
exit; |
|
421
|
|
|
} else { |
|
422
|
|
|
$db->rollback(); |
|
423
|
|
|
} |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
// Action called after a submitted was send and member created successfully |
|
427
|
|
|
// backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url. |
|
428
|
|
|
if (empty($reshook) && $action == 'added') { |
|
429
|
|
|
llxHeaderVierge($langs->trans("NewLeadForm")); |
|
430
|
|
|
|
|
431
|
|
|
// Si on a pas ete redirige |
|
432
|
|
|
print '<br><br>'; |
|
433
|
|
|
print '<div class="center">'; |
|
434
|
|
|
print $langs->trans("NewLeadbyWeb"); |
|
435
|
|
|
print '</div>'; |
|
436
|
|
|
|
|
437
|
|
|
llxFooterVierge(); |
|
438
|
|
|
exit; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
|
|
442
|
|
|
|
|
443
|
|
|
/* |
|
444
|
|
|
* View |
|
445
|
|
|
*/ |
|
446
|
|
|
|
|
447
|
|
|
$form = new Form($db); |
|
448
|
|
|
$formcompany = new FormCompany($db); |
|
449
|
|
|
|
|
450
|
|
|
$extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes and labels |
|
451
|
|
|
|
|
452
|
|
|
llxHeaderVierge($langs->trans("NewContact")); |
|
453
|
|
|
|
|
454
|
|
|
|
|
455
|
|
|
print load_fiche_titre($langs->trans("NewContact"), '', '', 0, 0, 'center'); |
|
456
|
|
|
|
|
457
|
|
|
|
|
458
|
|
|
print '<div align="center">'; |
|
459
|
|
|
print '<div id="divsubscribe">'; |
|
460
|
|
|
|
|
461
|
|
|
print '<div class="center subscriptionformhelptext opacitymedium justify">'; |
|
462
|
|
|
if (getDolGlobalString('PROJECT_NEWFORM_TEXT')) { |
|
463
|
|
|
print $langs->trans(getDolGlobalString('PROJECT_NEWFORM_TEXT')) . "<br>\n"; |
|
464
|
|
|
} else { |
|
465
|
|
|
print $langs->trans("FormForNewLeadDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL")) . "<br>\n"; |
|
466
|
|
|
} |
|
467
|
|
|
print '</div>'; |
|
468
|
|
|
|
|
469
|
|
|
dol_htmloutput_errors($errmsg); |
|
470
|
|
|
|
|
471
|
|
|
// Print form |
|
472
|
|
|
print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="newlead">' . "\n"; |
|
473
|
|
|
print '<input type="hidden" name="token" value="' . newToken() . '" / >'; |
|
474
|
|
|
print '<input type="hidden" name="entity" value="' . $entity . '" />'; |
|
475
|
|
|
print '<input type="hidden" name="action" value="add" />'; |
|
476
|
|
|
|
|
477
|
|
|
print '<br>'; |
|
478
|
|
|
|
|
479
|
|
|
print '<br><span class="opacitymedium">' . $langs->trans("FieldsWithAreMandatory", '*') . '</span><br>'; |
|
480
|
|
|
//print $langs->trans("FieldsWithIsForPublic",'**').'<br>'; |
|
481
|
|
|
|
|
482
|
|
|
print dol_get_fiche_head(); |
|
483
|
|
|
|
|
484
|
|
|
print '<script type="text/javascript"> |
|
485
|
|
|
jQuery(document).ready(function () { |
|
486
|
|
|
jQuery(document).ready(function () { |
|
487
|
|
|
jQuery("#selectcountry_id").change(function() { |
|
488
|
|
|
document.newlead.action.value="create"; |
|
489
|
|
|
document.newlead.submit(); |
|
490
|
|
|
}); |
|
491
|
|
|
}); |
|
492
|
|
|
}); |
|
493
|
|
|
</script>'; |
|
494
|
|
|
|
|
495
|
|
|
|
|
496
|
|
|
print '<table class="border" summary="form to subscribe" id="tablesubscribe">' . "\n"; |
|
497
|
|
|
|
|
498
|
|
|
// Lastname |
|
499
|
|
|
print '<tr><td>' . $langs->trans("Lastname") . ' <span class="star">*</span></td><td><input type="text" name="lastname" class="minwidth150" value="' . dol_escape_htmltag(GETPOST('lastname')) . '" required></td></tr>' . "\n"; |
|
500
|
|
|
// Firstname |
|
501
|
|
|
print '<tr><td>' . $langs->trans("Firstname") . ' <span class="star">*</span></td><td><input type="text" name="firstname" class="minwidth150" value="' . dol_escape_htmltag(GETPOST('firstname')) . '" required></td></tr>' . "\n"; |
|
502
|
|
|
// EMail |
|
503
|
|
|
print '<tr><td>' . $langs->trans("Email") . ' <span class="star">*</span></td><td><input type="text" name="email" maxlength="255" class="minwidth150" value="' . dol_escape_htmltag(GETPOST('email')) . '" required></td></tr>' . "\n"; |
|
504
|
|
|
// Company |
|
505
|
|
|
print '<tr id="trcompany" class="trcompany"><td>' . $langs->trans("Company") . '</td><td><input type="text" name="societe" class="minwidth150" value="' . dol_escape_htmltag(GETPOST('societe')) . '"></td></tr>' . "\n"; |
|
506
|
|
|
// Address |
|
507
|
|
|
print '<tr><td>' . $langs->trans("Address") . '</td><td>' . "\n"; |
|
508
|
|
|
print '<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="' . ROWS_2 . '">' . dol_escape_htmltag(GETPOST('address', 'restricthtml'), 0, 1) . '</textarea></td></tr>' . "\n"; |
|
509
|
|
|
// Zip / Town |
|
510
|
|
|
print '<tr><td>' . $langs->trans('Zip') . ' / ' . $langs->trans('Town') . '</td><td>'; |
|
511
|
|
|
print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1); |
|
512
|
|
|
print ' / '; |
|
513
|
|
|
print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1); |
|
514
|
|
|
print '</td></tr>'; |
|
515
|
|
|
// Country |
|
516
|
|
|
print '<tr><td>' . $langs->trans('Country') . '</td><td>'; |
|
517
|
|
|
$country_id = GETPOST('country_id'); |
|
518
|
|
|
if (!$country_id && getDolGlobalString('PROJECT_NEWFORM_FORCECOUNTRYCODE')) { |
|
519
|
|
|
$country_id = getCountry($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs); |
|
520
|
|
|
} |
|
521
|
|
|
if (!$country_id && !empty($conf->geoipmaxmind->enabled)) { |
|
522
|
|
|
$country_code = dol_user_country(); |
|
523
|
|
|
//print $country_code; |
|
524
|
|
|
if ($country_code) { |
|
525
|
|
|
$new_country_id = getCountry($country_code, 3, $db, $langs); |
|
526
|
|
|
//print 'xxx'.$country_code.' - '.$new_country_id; |
|
527
|
|
|
if ($new_country_id) { |
|
528
|
|
|
$country_id = $new_country_id; |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
} |
|
532
|
|
|
$country_code = getCountry($country_id, 2, $db, $langs); |
|
533
|
|
|
print $form->select_country($country_id, 'country_id'); |
|
534
|
|
|
print '</td></tr>'; |
|
535
|
|
|
// State |
|
536
|
|
|
if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) { |
|
537
|
|
|
print '<tr><td>' . $langs->trans('State') . '</td><td>'; |
|
538
|
|
|
if ($country_code) { |
|
539
|
|
|
print $formcompany->select_state(GETPOSTINT("state_id"), $country_code); |
|
540
|
|
|
} else { |
|
541
|
|
|
print ''; |
|
542
|
|
|
} |
|
543
|
|
|
print '</td></tr>'; |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
// Other attributes |
|
547
|
|
|
$parameters['tpl_context'] = 'public'; // define template context to public |
|
548
|
|
|
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php'; |
|
549
|
|
|
// Comments |
|
550
|
|
|
print '<tr>'; |
|
551
|
|
|
print '<td class="tdtop">' . $langs->trans("Message") . ' <span class="star">*</span></td>'; |
|
552
|
|
|
print '<td class="tdtop"><textarea name="description" id="description" wrap="soft" class="quatrevingtpercent" rows="' . ROWS_5 . '" required>' . dol_escape_htmltag(GETPOST('description', 'restricthtml'), 0, 1) . '</textarea></td>'; |
|
553
|
|
|
print '</tr>' . "\n"; |
|
554
|
|
|
|
|
555
|
|
|
print "</table>\n"; |
|
556
|
|
|
|
|
557
|
|
|
print dol_get_fiche_end(); |
|
558
|
|
|
|
|
559
|
|
|
// Save |
|
560
|
|
|
print '<div class="center">'; |
|
561
|
|
|
print '<input type="submit" value="' . $langs->trans("Submit") . '" id="submitsave" class="button">'; |
|
562
|
|
|
if (!empty($backtopage)) { |
|
563
|
|
|
print ' <input type="submit" value="' . $langs->trans("Cancel") . '" id="submitcancel" class="button button-cancel">'; |
|
564
|
|
|
} |
|
565
|
|
|
print '</div>'; |
|
566
|
|
|
|
|
567
|
|
|
|
|
568
|
|
|
print "</form>\n"; |
|
569
|
|
|
print "<br>"; |
|
570
|
|
|
print '</div></div>'; |
|
571
|
|
|
|
|
572
|
|
|
|
|
573
|
|
|
llxFooterVierge(); |
|
574
|
|
|
|
|
575
|
|
|
$db->close(); |
|
576
|
|
|
|