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"));
69if (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();
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.
'"';
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);
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";
210 $thirdparty =
new Societe($db);
214 $result = $thirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'',
GETPOST(
'email'));
216 $proj->socid = $thirdparty->id;
220 $thirdparty->name =
GETPOST(
'societe');
225 $thirdparty->email =
GETPOST(
'email');
226 $thirdparty->address =
GETPOST(
'address');
227 $thirdparty->zip =
GETPOST(
'zip');
228 $thirdparty->town =
GETPOST(
'town');
229 $thirdparty->country_id =
GETPOST(
'country_id',
'int');
230 $thirdparty->state_id =
GETPOST(
'state_id');
231 $thirdparty->client = $thirdparty::PROSPECT;
232 $thirdparty->code_client =
'auto';
233 $thirdparty->code_fournisseur =
'auto';
236 $extrafields->fetch_name_optionals_label($thirdparty->table_element);
237 $ret = $extrafields->setOptionalsFromPost(
null, $thirdparty,
'', 1);
241 $errmsg = ($extrafields->error ? $extrafields->error.
'<br>' :
'').join(
'<br>', $extrafields->errors);
245 $result = $thirdparty->create($user);
248 $errmsg = ($thirdparty->error ? $thirdparty->error.
'<br>' :
'').join(
'<br>', $thirdparty->errors);
250 $proj->socid = $thirdparty->id;
259 $modele = empty($conf->global->PROJECT_ADDON) ?
'mod_project_simple' : $conf->global->PROJECT_ADDON;
262 $file =
''; $classname =
''; $filefound = 0;
263 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
264 foreach ($dirmodels as $reldir) {
265 $file =
dol_buildpath($reldir.
"core/modules/project/".$modele.
'.php', 0);
266 if (file_exists($file)) {
268 $classname = $modele;
275 $modProject =
new $classname;
277 $defaultref = $modProject->getNextValue($thirdparty, $object);
280 if (is_numeric($defaultref) && $defaultref <= 0) {
284 if (empty($defaultref)) {
285 $defaultref =
'PJ'.dol_print_date(
dol_now(),
'dayrfc');
288 $proj->ref = $defaultref;
289 $proj->statut = $proj::STATUS_DRAFT;
290 $proj->status = $proj::STATUS_DRAFT;
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 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
303 if ($nb_post_max > 0) {
304 $sql =
"SELECT COUNT(rowid) as nb_projets";
305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
306 $sql .=
" WHERE ip = '".$db->escape($proj->ip).
"'";
307 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
308 $resql = $db->query($sql);
310 $num = $db->num_rows($resql);
314 $obj = $db->fetch_object($resql);
315 $nb_post_ip = $obj->nb_projets;
321 $extrafields->fetch_name_optionals_label($proj->table_element);
322 $ret = $extrafields->setOptionalsFromPost(
null, $proj);
327 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
329 $errmsg = $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
330 array_push($proj->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
334 $result = $proj->create($user);
336 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
339 if ($object->email) {
344 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
348 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
350 $outputlangs->loadLangs(array(
"main",
"members",
"projects"));
352 $arraydefaultmessage =
null;
353 $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD;
355 if (!empty($labeltouse)) {
356 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'project', $user, $outputlangs, 0, 1, $labeltouse);
359 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
360 $subject = $arraydefaultmessage->topic;
361 $msg = $arraydefaultmessage->content;
363 if (empty($labeltosue)) {
364 $labeltouse =
'['.$mysoc->name.
'] '.$langs->trans(
"YourMessage");
365 $msg = $langs->trans(
"YourMessageHasBeenReceived");
372 if ($subjecttosend && $texttosend) {
373 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/lead/new.php'.
"\r\n";
375 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(),
"",
"", 0, -1,
'', $moreinheader);
383 if (!empty($backtopage)) {
384 $urlback = $backtopage;
385 } elseif (!empty($conf->global->PROJECT_URL_REDIRECT_LEAD)) {
386 $urlback = $conf->global->PROJECT_URL_REDIRECT_LEAD;
389 $urlback = $_SERVER[
"PHP_SELF"].
"?action=added&token=".newToken();
392 if (!empty($entity)) {
393 $urlback .=
'&entity='.$entity;
396 dol_syslog(
"project lead ".$proj->ref.
" has been created, we redirect to ".$urlback);
399 $errmsg .= $proj->error.
'<br>'.join(
'<br>', $proj->errors);
409 Header(
"Location: ".$urlback);
418if (empty($reshook) && $action ==
'added') {
423 print
'<div class="center">';
424 print $langs->trans(
"NewLeadbyWeb");
437$form =
new Form($db);
440$extrafields->fetch_name_optionals_label($object->table_element);
448print
'<div align="center">';
449print
'<div id="divsubscribe">';
451print
'<div class="center subscriptionformhelptext opacitymedium justify">';
452if (!empty($conf->global->PROJECT_NEWFORM_TEXT)) {
453 print $langs->trans($conf->global->PROJECT_NEWFORM_TEXT).
"<br>\n";
455 print $langs->trans(
"FormForNewLeadDesc",
getDolGlobalString(
"MAIN_INFO_SOCIETE_MAIL")).
"<br>\n";
462print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newlead">'.
"\n";
463print
'<input type="hidden" name="token" value="'.newToken().
'" / >';
464print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
465print
'<input type="hidden" name="action" value="add" />';
469print
'<br><span class="opacitymedium">'.$langs->trans(
"FieldsWithAreMandatory",
'*').
'</span><br>';
474print
'<script type="text/javascript">
475jQuery(document).ready(function () {
476 jQuery(document).ready(function () {
477 jQuery("#selectcountry_id").change(function() {
478 document.newlead.action.value="create";
479 document.newlead.submit();
486print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
489print
'<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";
491print
'<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";
493print
'<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";
495print
'<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";
497print
'<tr><td>'.$langs->trans(
"Address").
'</td><td>'.
"\n";
498print
'<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(
GETPOST(
'address',
'restricthtml'), 0, 1).
'</textarea></td></tr>'.
"\n";
500print
'<tr><td>'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
501print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6, 1);
503print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
506print
'<tr><td>'.$langs->trans(
'Country').
'</td><td>';
507$country_id =
GETPOST(
'country_id');
508if (!$country_id && !empty($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE)) {
509 $country_id =
getCountry($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
511if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
515 $new_country_id =
getCountry($country_code, 3, $db, $langs);
517 if ($new_country_id) {
518 $country_id = $new_country_id;
522$country_code =
getCountry($country_id, 2, $db, $langs);
523print $form->select_country($country_id,
'country_id');
526if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
527 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
529 print $formcompany->select_state(
GETPOST(
"state_id",
'int'), $country_code);
537$parameters[
'tpl_context']=
'public';
538include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
541print
'<td class="tdtop">'.$langs->trans(
"Message").
' <span class="star">*</span></td>';
542print
'<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>';
550print
'<div class="center">';
551print
'<input type="submit" value="'.$langs->trans(
"Submit").
'" id="submitsave" class="button">';
552if (!empty($backtopage)) {
553 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.
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 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='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
llxFooterVierge()
Show footer for new member.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.