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)) {
112function llxHeaderVierge($title, $head =
"", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
114 global $conf, $langs,
$mysoc;
116 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
118 print
'<body id="mainbody" class="publicnewmemberform">';
120 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
123 print
'<div class="divmainbodylarge">';
149$parameters = array();
151$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
157if (empty($reshook) && $action ==
'add') {
163 if (!
GETPOST(
'lastname',
'alpha')) {
165 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Lastname")).
"<br>\n";
167 if (!
GETPOST(
'firstname',
'alpha')) {
169 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Firstname")).
"<br>\n";
171 if (!
GETPOST(
'email',
'alpha')) {
173 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Email")).
"<br>\n";
175 if (!
GETPOST(
'description',
'alpha')) {
177 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Message")).
"<br>\n";
181 $langs->load(
"errors");
182 $errmsg .= $langs->trans(
"ErrorBadEMail",
GETPOST(
'email',
'alpha')).
"<br>\n";
185 $defaultoppstatus =
getDolGlobalInt(
'PROJECT_DEFAULT_OPPORTUNITY_STATUS_FOR_ONLINE_LEAD');
186 if (empty($defaultoppstatus)) {
188 $langs->load(
"errors");
189 $errmsg .= $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Project")).
"<br>\n";
195 $thirdparty =
new Societe($db);
199 $result = $thirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'',
GETPOST(
'email',
'alpha'));
201 $proj->socid = $thirdparty->id;
204 if (
GETPOST(
'societe',
'alpha')) {
205 $thirdparty->name =
GETPOST(
'societe',
'alpha');
210 $thirdparty->email =
GETPOST(
'email',
'alpha');
211 $thirdparty->address =
GETPOST(
'address',
'alpha');
212 $thirdparty->zip =
GETPOST(
'zip',
'int');
213 $thirdparty->town =
GETPOST(
'town',
'alpha');
214 $thirdparty->country_id =
GETPOSTINT(
'country_id');
215 $thirdparty->state_id =
GETPOSTINT(
'state_id');
216 $thirdparty->client = $thirdparty::PROSPECT;
217 $thirdparty->code_client =
'auto';
218 $thirdparty->code_fournisseur =
'auto';
221 $extrafields->fetch_name_optionals_label($thirdparty->table_element);
222 $ret = $extrafields->setOptionalsFromPost(
null, $thirdparty,
'', 1);
225 $errmsg = ($extrafields->error ? $extrafields->error.
'<br>' :
'').implode(
'<br>', $extrafields->errors);
229 $result = $thirdparty->create($user);
232 $errmsg = ($thirdparty->error ? $thirdparty->error.
'<br>' :
'').implode(
'<br>', $thirdparty->errors);
234 $proj->socid = $thirdparty->id;
250 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
251 foreach ($dirmodels as $reldir) {
252 $file =
dol_buildpath($reldir.
"core/modules/project/".$modele.
'.php', 0);
253 if (file_exists($file)) {
255 $classname = $modele;
260 if ($filefound && !empty($classname)) {
262 if (class_exists($classname)) {
263 $modProject =
new $classname();
264 '@phan-var-force ModeleNumRefProjects $modProject';
266 $defaultref = $modProject->getNextValue($thirdparty, $object);
270 if (is_numeric($defaultref) && $defaultref <= 0) {
274 if (empty($defaultref)) {
275 $defaultref =
'PJ'.dol_print_date(
dol_now(),
'dayrfc');
278 if ($visibility ===
"1") {
280 } elseif ($visibility ===
"0") {
282 } elseif (empty($visibility)) {
286 $proj->ref = $defaultref;
287 $proj->statut = $proj::STATUS_DRAFT;
288 $proj->status = $proj::STATUS_DRAFT;
289 $proj->usage_opportunity = 1;
290 $proj->title = $langs->trans(
"LeadFromPublicForm");
291 $proj->description =
GETPOST(
"description",
"alphanohtml");
292 $proj->opp_status = $defaultoppstatus;
293 $proj->fk_opp_status = $defaultoppstatus;
296 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
300 if ($nb_post_max > 0) {
301 $sql =
"SELECT COUNT(rowid) as nb_projets";
302 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
303 $sql .=
" WHERE ip = '".$db->escape($proj->ip).
"'";
304 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
305 $resql = $db->query($sql);
307 $num = $db->num_rows($resql);
311 $obj = $db->fetch_object($resql);
312 $nb_post_ip = $obj->nb_projets;
318 $extrafields->fetch_name_optionals_label($proj->table_element);
319 $ret = $extrafields->setOptionalsFromPost(
null, $proj);
324 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
326 $errmsg = $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
327 array_push($proj->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
331 $result = $proj->create($user);
333 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
341 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
345 $outputlangs->setDefaultLang(empty(
$object->thirdparty->default_lang) ?
$mysoc->default_lang :
$object->thirdparty->default_lang);
347 $outputlangs->loadLangs(array(
"main",
"members",
"projects"));
349 $arraydefaultmessage =
null;
352 if (!empty($labeltouse)) {
353 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'project', $user, $outputlangs, 0, 1, $labeltouse);
356 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
357 $subject = $arraydefaultmessage->topic;
358 $msg = $arraydefaultmessage->content;
360 if (empty($labeltosue)) {
363 $labeltouse =
'['.$appli.
'] '.$langs->trans(
"YourMessage");
364 $msg = $langs->trans(
"YourMessageHasBeenReceived");
367 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $object);
371 if ($subjecttosend && $texttosend) {
372 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/lead/new.php'.
"\r\n";
374 $result =
$object->sendEmail($texttosend, $subjecttosend, array(), array(), array(),
"",
"", 0, -1,
'', $moreinheader);
382 if (!empty($backtopage)) {
383 $urlback = $backtopage;
388 $urlback = $_SERVER[
"PHP_SELF"].
"?action=added&token=".
newToken();
391 if (!empty($entity)) {
392 $urlback .=
'&entity='.$entity;
395 dol_syslog(
"project lead ".$proj->ref.
" has been created, we redirect to ".$urlback);
398 $errmsg .= $proj->error.
'<br>'.implode(
'<br>', $proj->errors);
408 header(
"Location: ".$urlback);
417if (empty($reshook) && $action ==
'added') {
422 print
'<div class="center">';
423 print $langs->trans(
"NewLeadbyWeb");
436$form =
new Form($db);
439$extrafields->fetch_name_optionals_label(
$object->table_element);
445print
load_fiche_titre($langs->trans(
"NewContact"),
'',
'', 0,
'',
'center');
448print
'<div align="center">';
449print
'<div id="divsubscribe">';
451print
'<div class="center subscriptionformhelptext opacitymedium justify">';
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');
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');
527 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
529 print $formcompany->select_state(
GETPOSTINT(
"state_id"), $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(! $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=[])
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.