30if (!defined(
'NOLOGIN')) {
33if (!defined(
'NOCSRFCHECK')) {
34 define(
"NOCSRFCHECK", 1);
36if (!defined(
'NOIPCHECK')) {
37 define(
'NOIPCHECK',
'1');
39if (!defined(
'NOBROWSERNOTIF')) {
40 define(
'NOBROWSERNOTIF',
'1');
46$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
47if (is_numeric($entity)) {
48 define(
"DOLENTITY", $entity);
52require
'../../main.inc.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
63$backtopage =
GETPOST(
'backtopage',
'alpha');
64$action =
GETPOST(
'action',
'aZ09');
67$langs->loadLangs(array(
"members",
"companies",
"install",
"other",
"projects"));
70 print $langs->trans(
"Form for public lead registration has not been enabled");
75$hookmanager->initHooks(array(
'publicnewleadcard',
'globalcard'));
81$user->loadDefaultValues();
84if (empty($conf->project->enabled)) {
100function 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.
'"';
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>';
135 print
'<div class="backimagepublicnewlead">';
136 print
'<img id="idPROJECT_IMAGE_PUBLIC_NEWLEAD" src="' .
getDolGlobalString(
'PROJECT_IMAGE_PUBLIC_NEWLEAD').
'">';
142 print
'<div class="divmainbodylarge">';
166$parameters = array();
168$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
174if (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";
212 $thirdparty =
new Societe($db);
216 $result = $thirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'',
GETPOST(
'email'));
218 $proj->socid = $thirdparty->id;
222 $thirdparty->name =
GETPOST(
'societe');
227 $thirdparty->email =
GETPOST(
'email');
228 $thirdparty->address =
GETPOST(
'address');
229 $thirdparty->zip =
GETPOST(
'zip');
230 $thirdparty->town =
GETPOST(
'town');
231 $thirdparty->country_id =
GETPOST(
'country_id',
'int');
232 $thirdparty->state_id =
GETPOST(
'state_id');
233 $thirdparty->client = $thirdparty::PROSPECT;
234 $thirdparty->code_client =
'auto';
235 $thirdparty->code_fournisseur =
'auto';
238 $extrafields->fetch_name_optionals_label($thirdparty->table_element);
239 $ret = $extrafields->setOptionalsFromPost(
null, $thirdparty,
'', 1);
243 $errmsg = ($extrafields->error ? $extrafields->error.
'<br>' :
'').join(
'<br>', $extrafields->errors);
247 $result = $thirdparty->create($user);
250 $errmsg = ($thirdparty->error ? $thirdparty->error.
'<br>' :
'').join(
'<br>', $thirdparty->errors);
252 $proj->socid = $thirdparty->id;
261 $modele = !
getDolGlobalString(
'PROJECT_ADDON') ?
'mod_project_simple' : $conf->global->PROJECT_ADDON;
267 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
268 foreach ($dirmodels as $reldir) {
269 $file =
dol_buildpath($reldir.
"core/modules/project/".$modele.
'.php', 0);
270 if (file_exists($file)) {
272 $classname = $modele;
279 $modProject =
new $classname();
281 $defaultref = $modProject->getNextValue($thirdparty, $object);
284 if (is_numeric($defaultref) && $defaultref <= 0) {
288 if (empty($defaultref)) {
289 $defaultref =
'PJ'.dol_print_date(
dol_now(),
'dayrfc');
292 if ($visibility ===
"1") {
294 } elseif ($visibility ===
"0") {
296 } elseif (empty($visibility)) {
300 $proj->ref = $defaultref;
301 $proj->statut = $proj::STATUS_DRAFT;
302 $proj->status = $proj::STATUS_DRAFT;
303 $proj->usage_opportunity = 1;
304 $proj->title = $langs->trans(
"LeadFromPublicForm");
305 $proj->description =
GETPOST(
"description",
"alphanohtml");
306 $proj->opp_status = $defaultoppstatus;
307 $proj->fk_opp_status = $defaultoppstatus;
310 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
314 if ($nb_post_max > 0) {
315 $sql =
"SELECT COUNT(rowid) as nb_projets";
316 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
317 $sql .=
" WHERE ip = '".$db->escape($proj->ip).
"'";
318 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
319 $resql = $db->query($sql);
321 $num = $db->num_rows($resql);
325 $obj = $db->fetch_object($resql);
326 $nb_post_ip = $obj->nb_projets;
332 $extrafields->fetch_name_optionals_label($proj->table_element);
333 $ret = $extrafields->setOptionalsFromPost(
null, $proj);
338 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
340 $errmsg = $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
341 array_push($proj->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
345 $result = $proj->create($user);
347 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
350 if ($object->email) {
355 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
359 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
361 $outputlangs->loadLangs(array(
"main",
"members",
"projects"));
363 $arraydefaultmessage =
null;
364 $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD;
366 if (!empty($labeltouse)) {
367 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'project', $user, $outputlangs, 0, 1, $labeltouse);
370 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
371 $subject = $arraydefaultmessage->topic;
372 $msg = $arraydefaultmessage->content;
374 if (empty($labeltosue)) {
375 $appli = $mysoc->name;
377 $labeltouse =
'['.$appli.
'] '.$langs->trans(
"YourMessage");
378 $msg = $langs->trans(
"YourMessageHasBeenReceived");
385 if ($subjecttosend && $texttosend) {
386 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/lead/new.php'.
"\r\n";
388 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(),
"",
"", 0, -1,
'', $moreinheader);
396 if (!empty($backtopage)) {
397 $urlback = $backtopage;
399 $urlback = $conf->global->PROJECT_URL_REDIRECT_LEAD;
402 $urlback = $_SERVER[
"PHP_SELF"].
"?action=added&token=".newToken();
405 if (!empty($entity)) {
406 $urlback .=
'&entity='.$entity;
409 dol_syslog(
"project lead ".$proj->ref.
" has been created, we redirect to ".$urlback);
412 $errmsg .= $proj->error.
'<br>'.join(
'<br>', $proj->errors);
422 Header(
"Location: ".$urlback);
431if (empty($reshook) && $action ==
'added') {
436 print
'<div class="center">';
437 print $langs->trans(
"NewLeadbyWeb");
450$form =
new Form($db);
453$extrafields->fetch_name_optionals_label($object->table_element);
461print
'<div align="center">';
462print
'<div id="divsubscribe">';
464print
'<div class="center subscriptionformhelptext opacitymedium justify">';
466 print $langs->trans($conf->global->PROJECT_NEWFORM_TEXT).
"<br>\n";
468 print $langs->trans(
"FormForNewLeadDesc",
getDolGlobalString(
"MAIN_INFO_SOCIETE_MAIL")).
"<br>\n";
475print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newlead">'.
"\n";
476print
'<input type="hidden" name="token" value="'.newToken().
'" / >';
477print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
478print
'<input type="hidden" name="action" value="add" />';
482print
'<br><span class="opacitymedium">'.$langs->trans(
"FieldsWithAreMandatory",
'*').
'</span><br>';
487print
'<script type="text/javascript">
488jQuery(document).ready(function () {
489 jQuery(document).ready(function () {
490 jQuery("#selectcountry_id").change(function() {
491 document.newlead.action.value="create";
492 document.newlead.submit();
499print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
502print
'<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";
504print
'<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";
506print
'<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";
508print
'<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";
510print
'<tr><td>'.$langs->trans(
"Address").
'</td><td>'.
"\n";
511print
'<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(
GETPOST(
'address',
'restricthtml'), 0, 1).
'</textarea></td></tr>'.
"\n";
513print
'<tr><td>'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
514print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6, 1);
516print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
519print
'<tr><td>'.$langs->trans(
'Country').
'</td><td>';
520$country_id =
GETPOST(
'country_id');
522 $country_id =
getCountry($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
524if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
528 $new_country_id =
getCountry($country_code, 3, $db, $langs);
530 if ($new_country_id) {
531 $country_id = $new_country_id;
535$country_code =
getCountry($country_id, 2, $db, $langs);
536print $form->select_country($country_id,
'country_id');
540 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
542 print $formcompany->select_state(
GETPOST(
"state_id",
'int'), $country_code);
550$parameters[
'tpl_context']=
'public';
551include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
554print
'<td class="tdtop">'.$langs->trans(
"Message").
' <span class="star">*</span></td>';
555print
'<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>';
563print
'<div class="center">';
564print
'<input type="submit" value="'.$langs->trans(
"Submit").
'" id="submitsave" class="button">';
565if (!empty($backtopage)) {
566 print
' <input type="submit" value="'.$langs->trans(
"Cancel").
'" id="submitcancel" class="button button-cancel">';
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge()
Header function.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
llxFooterVierge()
Show footer for new societe.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_user_country()
Return country code for current user.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.