31if (!defined(
'NOLOGIN')) {
34if (!defined(
'NOCSRFCHECK')) {
35 define(
"NOCSRFCHECK", 1);
37if (!defined(
'NOIPCHECK')) {
38 define(
'NOIPCHECK',
'1');
40if (!defined(
'NOBROWSERNOTIF')) {
41 define(
'NOBROWSERNOTIF',
'1');
48$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
49if (is_numeric($entity)) {
50 define(
"DOLENTITY", $entity);
54require
'../../main.inc.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
64$backtopage =
GETPOST(
'backtopage',
'alpha');
65$action =
GETPOST(
'action',
'aZ09');
77$langs->loadLangs(array(
"members",
"companies",
"install",
"other",
"projects"));
80 print $langs->trans(
"FormForPublicLeadRegistrationHasNotBeenEnabled");
85$hookmanager->initHooks(array(
'publicnewleadcard',
'globalcard'));
91$user->loadDefaultValues();
94if (empty(
$conf->project->enabled)) {
113function llxHeaderVierge($title, $head =
"", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $ws =
'')
117 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
119 print
'<body id="mainbody" class="publicnewmemberform">';
121 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
124 print
'<div class="divmainbodylarge">';
150$parameters = array();
152$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
158if (empty($reshook) && $action ==
'add') {
164 if (!
GETPOST(
'lastname',
'alpha')) {
166 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Lastname")).
"<br>\n";
168 if (!
GETPOST(
'firstname',
'alpha')) {
170 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Firstname")).
"<br>\n";
172 if (!
GETPOST(
'email',
'alpha')) {
174 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Email")).
"<br>\n";
176 if (!
GETPOST(
'description',
'alpha')) {
178 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Message")).
"<br>\n";
182 $langs->load(
"errors");
183 $errmsg .= $langs->trans(
"ErrorBadEMail",
GETPOST(
'email',
'alpha')).
"<br>\n";
186 $defaultoppstatus =
getDolGlobalInt(
'PROJECT_DEFAULT_OPPORTUNITY_STATUS_FOR_ONLINE_LEAD');
187 if (empty($defaultoppstatus)) {
189 $langs->load(
"errors");
190 $errmsg .= $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Project")).
"<br>\n";
200 $result = $thirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'',
GETPOST(
'email',
'alpha'));
202 $proj->socid = $thirdparty->id;
205 if (
GETPOST(
'societe',
'alpha')) {
206 $thirdparty->name =
GETPOST(
'societe',
'alpha');
211 $thirdparty->email =
GETPOST(
'email',
'alpha');
212 $thirdparty->address =
GETPOST(
'address',
'alpha');
213 $thirdparty->zip =
GETPOST(
'zip',
'int');
214 $thirdparty->town =
GETPOST(
'town',
'alpha');
215 $thirdparty->country_id =
GETPOSTINT(
'country_id');
216 $thirdparty->state_id =
GETPOSTINT(
'state_id');
217 $thirdparty->client = $thirdparty::PROSPECT;
218 $thirdparty->code_client =
'auto';
219 $thirdparty->code_fournisseur =
'auto';
222 $extrafields->fetch_name_optionals_label($thirdparty->table_element);
223 $ret = $extrafields->setOptionalsFromPost(
null, $thirdparty,
'', 1);
226 $errmsg = ($extrafields->error ? $extrafields->error.
'<br>' :
'').implode(
'<br>', $extrafields->errors);
230 $result = $thirdparty->create($user);
233 $errmsg = ($thirdparty->error ? $thirdparty->error.
'<br>' :
'').implode(
'<br>', $thirdparty->errors);
235 $proj->socid = $thirdparty->id;
251 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
252 foreach ($dirmodels as $reldir) {
253 $file =
dol_buildpath($reldir.
"core/modules/project/".$modele.
'.php', 0);
254 if (file_exists($file)) {
256 $classname = $modele;
261 if ($filefound && !empty($classname)) {
263 if (class_exists($classname)) {
264 $modProject =
new $classname();
265 '@phan-var-force ModeleNumRefProjects $modProject';
267 $defaultref = $modProject->getNextValue($thirdparty, $object);
271 if (is_numeric($defaultref) && $defaultref <= 0) {
275 if (empty($defaultref)) {
276 $defaultref =
'PJ'.dol_print_date(
dol_now(),
'dayrfc');
279 if ($visibility ===
"1") {
281 } elseif ($visibility ===
"0") {
283 } elseif (empty($visibility)) {
287 $proj->ref = $defaultref;
288 $proj->statut = $proj::STATUS_DRAFT;
289 $proj->status = $proj::STATUS_DRAFT;
290 $proj->usage_opportunity = 1;
291 $proj->title = $langs->trans(
"LeadFromPublicForm");
292 $proj->description =
GETPOST(
"description",
"alphanohtml");
293 $proj->opp_status = $defaultoppstatus;
294 $proj->fk_opp_status = $defaultoppstatus;
297 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
301 if ($nb_post_max > 0) {
302 $sql =
"SELECT COUNT(rowid) as nb_projets";
303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
304 $sql .=
" WHERE ip = '".$db->escape($proj->ip).
"'";
305 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
306 $resql =
$db->query($sql);
308 $num =
$db->num_rows($resql);
312 $obj =
$db->fetch_object($resql);
313 $nb_post_ip = $obj->nb_projets;
319 $extrafields->fetch_name_optionals_label($proj->table_element);
320 $ret = $extrafields->setOptionalsFromPost(
null, $proj);
325 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
327 $errmsg = $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
328 array_push($proj->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
332 $result = $proj->create($user);
334 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
342 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
346 $outputlangs->setDefaultLang(empty(
$object->thirdparty->default_lang) ?
$mysoc->default_lang :
$object->thirdparty->default_lang);
348 $outputlangs->loadLangs(array(
"main",
"members",
"projects"));
350 $arraydefaultmessage =
null;
353 if (!empty($labeltouse)) {
354 $arraydefaultmessage = $formmail->getEMailTemplate(
$db,
'project', $user, $outputlangs, 0, 1, $labeltouse);
357 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
358 $subject = $arraydefaultmessage->topic;
359 $msg = $arraydefaultmessage->content;
361 if (empty($labeltosue)) {
364 $labeltouse =
'['.$appli.
'] '.$langs->trans(
"YourMessage");
365 $msg = $langs->trans(
"YourMessageHasBeenReceived");
368 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $object);
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;
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>'.implode(
'<br>', $proj->errors);
409 header(
"Location: ".$urlback);
418if (empty($reshook) && $action ==
'added') {
423 print
'<div class="center">';
424 print $langs->trans(
"NewLeadbyWeb");
440$extrafields->fetch_name_optionals_label(
$object->table_element);
446print
load_fiche_titre($langs->trans(
"NewContact"),
'',
'', 0,
'',
'center');
449print
'<div align="center">';
450print
'<div id="divsubscribe">';
452print
'<div class="center subscriptionformhelptext opacitymedium justify">';
456 print $langs->trans(
"FormForNewLeadDesc",
getDolGlobalString(
"MAIN_INFO_SOCIETE_MAIL")).
"<br>\n";
463print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newlead">'.
"\n";
464print
'<input type="hidden" name="token" value="'.newToken().
'" / >';
465print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
466print
'<input type="hidden" name="action" value="add" />';
470print
'<br><span class="opacitymedium">'.$langs->trans(
"FieldsWithAreMandatory",
'*').
'</span><br>';
475print
'<script type="text/javascript">
476jQuery(document).ready(function () {
477 jQuery(document).ready(function () {
478 jQuery("#selectcountry_id").change(function() {
479 document.newlead.action.value="create";
480 document.newlead.submit();
487print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
490print
'<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";
492print
'<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";
494print
'<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";
496print
'<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";
498print
'<tr><td>'.$langs->trans(
"Address").
'</td><td>'.
"\n";
499print
'<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(
GETPOST(
'address',
'restricthtml'), 0, 1).
'</textarea></td></tr>'.
"\n";
501print
'<tr><td>'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
502print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6, 1);
504print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
507print
'<tr><td>'.$langs->trans(
'Country').
'</td><td>';
508$country_id =
GETPOST(
'country_id');
510 $country_id =
getCountry(
$conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE,
'2',
$db, $langs);
512if (!$country_id && !empty(
$conf->geoipmaxmind->enabled)) {
516 $new_country_id =
getCountry($country_code,
'3',
$db, $langs);
518 if ($new_country_id) {
519 $country_id = $new_country_id;
524print $form->select_country($country_id,
'country_id');
528 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
530 print $formcompany->select_state(
GETPOSTINT(
"state_id"), $country_code);
538$parameters[
'tpl_context'] =
'public';
539include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
542print
'<td class="tdtop">'.$langs->trans(
"Message").
' <span class="star">*</span></td>';
543print
'<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>';
551print
'<div class="center">';
552print
'<input type="submit" value="'.$langs->trans(
"Submit").
'" id="submitsave" class="button">';
553if (!empty($backtopage)) {
554 print
' <input type="submit" value="'.$langs->trans(
"Cancel").
'" id="submitcancel" class="button button-cancel">';
if(! $sortfield) if(! $sortorder) $object
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $ws='')
Show header for new prospect.
llxFooterVierge()
Show footer for new societe.
htmlPrintOnlineHeader($mysoc, $langs, $showlogo=1, $alttext='', $subimageconst='', $altlogo1='', $altlogo2='')
Show the header of a company in HTML public pages.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $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.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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, $attop=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-...
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted 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)
Output 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.