30 if (!defined(
'NOLOGIN')) {
33 if (!defined(
'NOCSRFCHECK')) {
34 define(
"NOCSRFCHECK", 1);
36 if (!defined(
'NOIPCHECK')) {
37 define(
'NOIPCHECK',
'1');
39 if (!defined(
'NOBROWSERNOTIF')) {
40 define(
'NOBROWSERNOTIF',
'1');
42 if (!defined(
'NOIPCHECK')) {
43 define(
'NOIPCHECK',
'1');
48 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
49 if (is_numeric($entity)) {
50 define(
"DOLENTITY", $entity);
53 require
'../../main.inc.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
56 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
63 $backtopage =
GETPOST(
'backtopage',
'alpha');
64 $action =
GETPOST(
'action',
'aZ09');
67 $langs->loadLangs(array(
"members",
"companies",
"install",
"other",
"projects"));
69 if (empty($conf->global->PROJECT_ENABLE_PUBLIC)) {
70 print $langs->trans(
"Form for public lead registration has not been enabled");
75 $hookmanager->initHooks(array(
'publicnewleadcard',
'globalcard'));
81 $user->loadDefaultValues();
84 if (empty($conf->project->enabled)) {
100 function llxHeaderVierge($title, $head =
"", $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'')
102 global $user, $conf, $langs, $mysoc;
104 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
106 print
'<body id="mainbody" class="publicnewmemberform">';
109 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
111 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
112 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_small);
113 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
114 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.$mysoc->logo);
115 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg')) {
116 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
119 print
'<div class="center">';
123 print
'<div class="backgreypublicpayment">';
124 print
'<div class="logopublicpayment">';
125 print
'<img id="dolpaymentlogo" src="'.$urllogo.
'"';
128 if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
129 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="'.DOL_URL_ROOT.
'/theme/dolibarr_logo.svg" width="80px"></a></div>';
134 if (!empty($conf->global->PROJECT_IMAGE_PUBLIC_NEWLEAD)) {
135 print
'<div class="backimagepublicnewlead">';
136 print
'<img id="idPROJECT_IMAGE_PUBLIC_NEWLEAD" src="'.$conf->global->PROJECT_IMAGE_PUBLIC_NEWLEAD.
'">';
142 print
'<div class="divmainbodylarge">';
166 $parameters = array();
168 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
174 if (empty($reshook) && $action ==
'add') {
182 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Lastname")).
"<br>\n";
186 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Firstname")).
"<br>\n";
190 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Email")).
"<br>\n";
194 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Message")).
"<br>\n";
198 $langs->load(
"errors");
199 $errmsg .= $langs->trans(
"ErrorBadEMail",
GETPOST(
"email")).
"<br>\n";
202 $defaultoppstatus =
getDolGlobalString(
'PROJECT_DEFAULT_OPPORTUNITY_STATUS_FOR_ONLINE_LEAD');
203 if (empty($defaultoppstatus)) {
205 $langs->load(
"errors");
206 $errmsg .= $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Project")).
"<br>\n";
210 $thirdparty =
new Societe($db);
214 $result = $thirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'', $object->email);
216 $proj->socid = $thirdparty->id;
220 $thirdparty->name =
GETPOST(
'societe');
225 $thirdparty->address =
GETPOST(
'address');
226 $thirdparty->zip =
GETPOST(
'zip');
227 $thirdparty->town =
GETPOST(
'town');
228 $thirdparty->country_id =
GETPOST(
'country_id',
'int');
229 $thirdparty->state_id =
GETPOST(
'state_id');
230 $thirdparty->client = $thirdparty::PROSPECT;
231 $thirdparty->code_client =
'auto';
232 $thirdparty->code_fournisseur =
'auto';
235 $extrafields->fetch_name_optionals_label($thirdparty->table_element);
236 $ret = $extrafields->setOptionalsFromPost(
null, $thirdparty,
'', 1);
240 $errmsg = ($extrafields->error ? $extrafields->error.
'<br>' :
'').join(
'<br>', $extrafields->errors);
244 $result = $thirdparty->create($user);
247 $errmsg = ($thirdparty->error ? $thirdparty->error.
'<br>' :
'').join(
'<br>', $thirdparty->errors);
249 $proj->socid = $thirdparty->id;
258 $modele = empty($conf->global->PROJECT_ADDON) ?
'mod_project_simple' : $conf->global->PROJECT_ADDON;
261 $file =
''; $classname =
''; $filefound = 0;
262 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
263 foreach ($dirmodels as $reldir) {
264 $file =
dol_buildpath($reldir.
"core/modules/project/".$modele.
'.php', 0);
265 if (file_exists($file)) {
267 $classname = $modele;
274 $modProject =
new $classname;
276 $defaultref = $modProject->getNextValue($thirdparty, $object);
279 if (is_numeric($defaultref) && $defaultref <= 0) {
283 if (empty($defaultref)) {
284 $defaultref =
'PJ'.dol_print_date(
dol_now(),
'dayrfc');
287 $proj->ref = $defaultref;
288 $proj->statut = $proj::STATUS_DRAFT;
289 $proj->status = $proj::STATUS_DRAFT;
290 $proj->email =
GETPOST(
"email");
292 $proj->usage_opportunity = 1;
293 $proj->title = $langs->trans(
"LeadFromPublicForm");
294 $proj->description =
GETPOST(
"description",
"alphanohtml");
295 $proj->opp_status = $defaultoppstatus;
296 $proj->fk_opp_status = $defaultoppstatus;
299 $extrafields->fetch_name_optionals_label($proj->table_element);
300 $ret = $extrafields->setOptionalsFromPost(
null, $proj);
306 $result = $proj->create($user);
308 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
311 if ($object->email) {
316 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
320 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
322 $outputlangs->loadLangs(array(
"main",
"members",
"projects"));
324 $arraydefaultmessage =
null;
325 $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD;
327 if (!empty($labeltouse)) {
328 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'project', $user, $outputlangs, 0, 1, $labeltouse);
331 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
332 $subject = $arraydefaultmessage->topic;
333 $msg = $arraydefaultmessage->content;
335 if (empty($labeltosue)) {
336 $labeltouse =
'['.$mysoc->name.
'] '.$langs->trans(
"YourMessage");
337 $msg = $langs->trans(
"YourMessageHasBeenReceived");
345 if ($subjecttosend && $texttosend) {
346 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/lead/new.php'.
"\r\n";
348 $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(),
"",
"", 0, -1,
'', $moreinheader);
356 if (!empty($backtopage)) {
357 $urlback = $backtopage;
358 } elseif (!empty($conf->global->PROJECT_URL_REDIRECT_LEAD)) {
359 $urlback = $conf->global->PROJECT_URL_REDIRECT_LEAD;
362 $urlback = $_SERVER[
"PHP_SELF"].
"?action=added&token=".
newToken();
365 if (!empty($entity)) {
366 $urlback .=
'&entity='.$entity;
369 dol_syslog(
"project lead ".$proj->ref.
" has been created, we redirect to ".$urlback);
372 $errmsg .= $proj->error.
'<br>'.join(
'<br>', $proj->errors);
379 Header(
"Location: ".$urlback);
389 if (empty($reshook) && $action ==
'added') {
394 print
'<div class="center">';
395 print $langs->trans(
"NewLeadbyWeb");
411 $extrafields->fetch_name_optionals_label($object->table_element);
416 print
load_fiche_titre($langs->trans(
"NewContact"),
'',
'', 0, 0,
'center');
419 print
'<div align="center">';
420 print
'<div id="divsubscribe">';
422 print
'<div class="center subscriptionformhelptext justify">';
423 if (!empty($conf->global->PROJECT_NEWFORM_TEXT)) {
424 print $langs->trans($conf->global->PROJECT_NEWFORM_TEXT).
"<br>\n";
426 print $langs->trans(
"FormForNewLeadDesc", $conf->global->MAIN_INFO_SOCIETE_MAIL).
"<br>\n";
433 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newlead">'.
"\n";
434 print
'<input type="hidden" name="token" value="'.newToken().
'" / >';
435 print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
436 print
'<input type="hidden" name="action" value="add" />';
440 print
'<br><span class="opacitymedium">'.$langs->trans(
"FieldsWithAreMandatory",
'*').
'</span><br>';
445 print
'<script type="text/javascript">
446 jQuery(document).ready(function () {
447 jQuery(document).ready(function () {
448 jQuery("#selectcountry_id").change(function() {
449 document.newlead.action.value="create";
450 document.newlead.submit();
457 print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
460 print
'<tr><td>'.$langs->trans(
"Lastname").
' <span style="color: red">*</span></td><td><input type="text" name="lastname" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'lastname')).
'" required></td></tr>'.
"\n";
462 print
'<tr><td>'.$langs->trans(
"Firstname").
' <span style="color: red">*</span></td><td><input type="text" name="firstname" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'firstname')).
'" required></td></tr>'.
"\n";
464 print
'<tr><td>'.$langs->trans(
"Email").
' <span style="color: red">*</span></td><td><input type="text" name="email" maxlength="255" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'email')).
'" required></td></tr>'.
"\n";
466 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";
468 print
'<tr><td>'.$langs->trans(
"Address").
'</td><td>'.
"\n";
469 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";
471 print
'<tr><td>'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
472 print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6, 1);
474 print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
477 print
'<tr><td>'.$langs->trans(
'Country').
'</td><td>';
478 $country_id =
GETPOST(
'country_id');
479 if (!$country_id && !empty($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE)) {
480 $country_id =
getCountry($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
482 if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
486 $new_country_id =
getCountry($country_code, 3, $db, $langs);
488 if ($new_country_id) {
489 $country_id = $new_country_id;
493 $country_code =
getCountry($country_id, 2, $db, $langs);
494 print
$form->select_country($country_id,
'country_id');
497 if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
498 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
500 print $formcompany->select_state(
GETPOST(
"state_id",
'int'), $country_code);
508 $tpl_context =
'public';
509 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
512 print
'<td class="tdtop">'.$langs->trans(
"Message").
' <span style="color: red">*</span></td>';
513 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>';
521 print
'<div class="center">';
522 print
'<input type="submit" value="'.$langs->trans(
"Submit").
'" id="submitsave" class="button">';
523 if (!empty($backtopage)) {
524 print
' <input type="submit" value="'.$langs->trans(
"Cancel").
'" id="submitcancel" class="button button-cancel">';
531 print
'</div></div>';