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');
76$langs->loadLangs(array(
"members",
"companies",
"install",
"other",
"projects"));
79 print $langs->trans(
"Form for public lead registration has not been enabled");
84$hookmanager->initHooks(array(
'publicnewleadcard',
'globalcard'));
90$user->loadDefaultValues();
93if (empty(
$conf->project->enabled)) {
111function llxHeaderVierge($title, $head =
"", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
113 global
$conf, $langs, $mysoc;
115 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
117 print
'<body id="mainbody" class="publicnewmemberform">';
119 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
122 print
'<div class="divmainbodylarge">';
148$parameters = array();
150$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
156if (empty($reshook) && $action ==
'add') {
162 if (!
GETPOST(
'lastname',
'alpha')) {
164 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Lastname")).
"<br>\n";
166 if (!
GETPOST(
'firstname',
'alpha')) {
168 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Firstname")).
"<br>\n";
170 if (!
GETPOST(
'email',
'alpha')) {
172 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Email")).
"<br>\n";
174 if (!
GETPOST(
'description',
'alpha')) {
176 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Message")).
"<br>\n";
180 $langs->load(
"errors");
181 $errmsg .= $langs->trans(
"ErrorBadEMail",
GETPOST(
'email',
'alpha')).
"<br>\n";
184 $defaultoppstatus =
getDolGlobalInt(
'PROJECT_DEFAULT_OPPORTUNITY_STATUS_FOR_ONLINE_LEAD');
185 if (empty($defaultoppstatus)) {
187 $langs->load(
"errors");
188 $errmsg .= $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Project")).
"<br>\n";
194 $thirdparty =
new Societe($db);
198 $result = $thirdparty->fetch(0,
'',
'',
'',
'',
'',
'',
'',
'',
'',
GETPOST(
'email',
'alpha'));
200 $proj->socid = $thirdparty->id;
203 if (
GETPOST(
'societe',
'alpha')) {
204 $thirdparty->name =
GETPOST(
'societe',
'alpha');
209 $thirdparty->email =
GETPOST(
'email',
'alpha');
210 $thirdparty->address =
GETPOST(
'address',
'alpha');
211 $thirdparty->zip =
GETPOST(
'zip',
'int');
212 $thirdparty->town =
GETPOST(
'town',
'alpha');
213 $thirdparty->country_id =
GETPOSTINT(
'country_id');
214 $thirdparty->state_id =
GETPOSTINT(
'state_id');
215 $thirdparty->client = $thirdparty::PROSPECT;
216 $thirdparty->code_client =
'auto';
217 $thirdparty->code_fournisseur =
'auto';
220 $extrafields->fetch_name_optionals_label($thirdparty->table_element);
221 $ret = $extrafields->setOptionalsFromPost(
null, $thirdparty,
'', 1);
224 $errmsg = ($extrafields->error ? $extrafields->error.
'<br>' :
'').implode(
'<br>', $extrafields->errors);
228 $result = $thirdparty->create($user);
231 $errmsg = ($thirdparty->error ? $thirdparty->error.
'<br>' :
'').implode(
'<br>', $thirdparty->errors);
233 $proj->socid = $thirdparty->id;
249 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
250 foreach ($dirmodels as $reldir) {
251 $file =
dol_buildpath($reldir.
"core/modules/project/".$modele.
'.php', 0);
252 if (file_exists($file)) {
254 $classname = $modele;
259 if ($filefound && !empty($classname)) {
261 if (class_exists($classname)) {
262 $modProject =
new $classname();
263 '@phan-var-force ModeleNumRefProjects $modProject';
265 $defaultref = $modProject->getNextValue($thirdparty,
$object);
269 if (is_numeric($defaultref) && $defaultref <= 0) {
273 if (empty($defaultref)) {
274 $defaultref =
'PJ'.dol_print_date(
dol_now(),
'dayrfc');
277 if ($visibility ===
"1") {
279 } elseif ($visibility ===
"0") {
281 } elseif (empty($visibility)) {
285 $proj->ref = $defaultref;
286 $proj->statut = $proj::STATUS_DRAFT;
287 $proj->status = $proj::STATUS_DRAFT;
288 $proj->usage_opportunity = 1;
289 $proj->title = $langs->trans(
"LeadFromPublicForm");
290 $proj->description =
GETPOST(
"description",
"alphanohtml");
291 $proj->opp_status = $defaultoppstatus;
292 $proj->fk_opp_status = $defaultoppstatus;
295 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
299 if ($nb_post_max > 0) {
300 $sql =
"SELECT COUNT(rowid) as nb_projets";
301 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
302 $sql .=
" WHERE ip = '".$db->escape($proj->ip).
"'";
303 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
304 $resql = $db->query($sql);
306 $num = $db->num_rows($resql);
310 $obj = $db->fetch_object($resql);
311 $nb_post_ip = $obj->nb_projets;
317 $extrafields->fetch_name_optionals_label($proj->table_element);
318 $ret = $extrafields->setOptionalsFromPost(
null, $proj);
323 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
325 $errmsg = $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
326 array_push($proj->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
330 $result = $proj->create($user);
332 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
340 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
344 $outputlangs->setDefaultLang(empty(
$object->thirdparty->default_lang) ? $mysoc->default_lang :
$object->thirdparty->default_lang);
346 $outputlangs->loadLangs(array(
"main",
"members",
"projects"));
348 $arraydefaultmessage =
null;
351 if (!empty($labeltouse)) {
352 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'project', $user, $outputlangs, 0, 1, $labeltouse);
355 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
356 $subject = $arraydefaultmessage->topic;
357 $msg = $arraydefaultmessage->content;
359 if (empty($labeltosue)) {
360 $appli = $mysoc->name;
362 $labeltouse =
'['.$appli.
'] '.$langs->trans(
"YourMessage");
363 $msg = $langs->trans(
"YourMessageHasBeenReceived");
366 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null,
$object);
370 if ($subjecttosend && $texttosend) {
371 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/lead/new.php'.
"\r\n";
373 $result =
$object->sendEmail($texttosend, $subjecttosend, array(), array(), array(),
"",
"", 0, -1,
'', $moreinheader);
381 if (!empty($backtopage)) {
382 $urlback = $backtopage;
387 $urlback = $_SERVER[
"PHP_SELF"].
"?action=added&token=".
newToken();
390 if (!empty($entity)) {
391 $urlback .=
'&entity='.$entity;
394 dol_syslog(
"project lead ".$proj->ref.
" has been created, we redirect to ".$urlback);
397 $errmsg .= $proj->error.
'<br>'.implode(
'<br>', $proj->errors);
407 header(
"Location: ".$urlback);
416if (empty($reshook) && $action ==
'added') {
421 print
'<div class="center">';
422 print $langs->trans(
"NewLeadbyWeb");
435$form =
new Form($db);
438$extrafields->fetch_name_optionals_label(
$object->table_element);
444print
load_fiche_titre($langs->trans(
"NewContact"),
'',
'', 0,
'',
'center');
447print
'<div align="center">';
448print
'<div id="divsubscribe">';
450print
'<div class="center subscriptionformhelptext opacitymedium justify">';
454 print $langs->trans(
"FormForNewLeadDesc",
getDolGlobalString(
"MAIN_INFO_SOCIETE_MAIL")).
"<br>\n";
461print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newlead">'.
"\n";
462print
'<input type="hidden" name="token" value="'.newToken().
'" / >';
463print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
464print
'<input type="hidden" name="action" value="add" />';
468print
'<br><span class="opacitymedium">'.$langs->trans(
"FieldsWithAreMandatory",
'*').
'</span><br>';
473print
'<script type="text/javascript">
474jQuery(document).ready(function () {
475 jQuery(document).ready(function () {
476 jQuery("#selectcountry_id").change(function() {
477 document.newlead.action.value="create";
478 document.newlead.submit();
485print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
488print
'<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";
490print
'<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";
492print
'<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";
494print
'<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";
496print
'<tr><td>'.$langs->trans(
"Address").
'</td><td>'.
"\n";
497print
'<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(
GETPOST(
'address',
'restricthtml'), 0, 1).
'</textarea></td></tr>'.
"\n";
499print
'<tr><td>'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
500print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6, 1);
502print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
505print
'<tr><td>'.$langs->trans(
'Country').
'</td><td>';
506$country_id =
GETPOST(
'country_id');
508 $country_id =
getCountry(
$conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE,
'2', $db, $langs);
510if (!$country_id && !empty(
$conf->geoipmaxmind->enabled)) {
514 $new_country_id =
getCountry($country_code,
'3', $db, $langs);
516 if ($new_country_id) {
517 $country_id = $new_country_id;
521$country_code =
getCountry($country_id,
'2', $db, $langs);
522print $form->select_country($country_id,
'country_id');
526 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
528 print $formcompany->select_state(
GETPOSTINT(
"state_id"), $country_code);
536$parameters[
'tpl_context'] =
'public';
537include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
540print
'<td class="tdtop">'.$langs->trans(
"Message").
' <span class="star">*</span></td>';
541print
'<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>';
549print
'<div class="center">';
550print
'<input type="submit" value="'.$langs->trans(
"Submit").
'" id="submitsave" class="button">';
551if (!empty($backtopage)) {
552 print
' <input type="submit" value="'.$langs->trans(
"Cancel").
'" id="submitcancel" class="button button-cancel">';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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-...
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.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.