dolibarr 19.0.4
new.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2001-2002 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org>
7 * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
8 * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
9 * Copyright (C) 2021 Waël Almoman <info@almoman.com>
10 * Copyright (C) 2022 Udo Tamm <dev@dolibit.de>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
33if (!defined('NOLOGIN')) {
34 define("NOLOGIN", 1); // This means this output page does not require to be logged.
35}
36if (!defined('NOCSRFCHECK')) {
37 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
38}
39if (!defined('NOBROWSERNOTIF')) {
40 define('NOBROWSERNOTIF', '1');
41}
42
43
44// For MultiCompany module.
45// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
46$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
47if (is_numeric($entity)) {
48 define("DOLENTITY", $entity);
49}
50
51
52// Load Dolibarr environment
53require '../../main.inc.php';
54require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
55require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php';
56require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
57require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php';
58require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
59require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
60require_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php';
61require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
62require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
63// Init vars
64$backtopage = GETPOST('backtopage', 'alpha');
65$action = GETPOST('action', 'aZ09');
66
67$errmsg = '';
68$num = 0;
69$error = 0;
70
71// Load translation files
72$langs->loadLangs(array("main", "members", "companies", "install", "other", "errors"));
73
74// Security check
75if (!isModEnabled('societe')) {
76 httponly_accessforbidden('Module Thirdparty not enabled');
77}
78
79if (!getDolGlobalString('SOCIETE_ENABLE_PUBLIC')) {
80 httponly_accessforbidden("Online form for contact for public visitors has not been enabled");
81}
82
83
84//permissions
85
86$permissiontoadd = $user->hasRight('societe', 'creer');
87
88// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
89$hookmanager->initHooks(array('publicnewmembercard', 'globalcard'));
90
91$extrafields = new ExtraFields($db);
92
93
94$objectsoc = new Societe($db);
95$user->loadDefaultValues();
96
97
109function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
110{
111 global $conf, $langs, $mysoc;
112
113 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
114
115 print '<body id="mainbody" class="publicnewmemberform">';
116
117 // Define urllogo
118 $urllogo = DOL_URL_ROOT . '/theme/common/login_logo.png';
119
120 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
121 $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file=' . urlencode('logos/thumbs/' . $mysoc->logo_small);
122 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
123 $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file=' . urlencode('logos/' . $mysoc->logo);
124 } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.svg')) {
125 $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.svg';
126 }
127
128 print '<header class="center">';
129
130 // Output html code for logo
131 if ($urllogo) {
132 print '<div class="backgreypublicpayment">';
133 print '<div class="logopublicpayment">';
134 print '<img id="dolpaymentlogo" src="' . $urllogo . '">';
135 print '</div>';
136 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
137 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>';
138 }
139 print '</div>';
140 }
141
142 if (getDolGlobalString('MEMBER_IMAGE_PUBLIC_REGISTRATION')) {
143 print '<div class="backimagepublicregistration">';
144 print '<img id="idEVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('MEMBER_IMAGE_PUBLIC_REGISTRATION') . '">';
145 print '</div>';
146 }
147
148 print '</header>';
149
150 print '<div class="divmainbodylarge">';
151}
152
159{
160 global $conf, $langs;
161
162 $ext = '';
163
164 print '</div>';
165
166 printCommonFooter('public');
167
168 if (!empty($conf->use_javascript_ajax)) {
169 print "\n" . '<!-- Includes JS Footer of Dolibarr -->' . "\n";
170 print '<script src="' . DOL_URL_ROOT . '/core/js/lib_foot.js.php?lang=' . $langs->defaultlang . (!empty($ext) ? '&' . $ext : '') . '"></script>' . "\n";
171 }
172
173 print "</body>\n";
174 print "</html>\n";
175}
176
177
178
179/*
180 * Actions
181 */
182
183$parameters = array();
184// Note that $action and $object may have been modified by some hooks
185$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
186if ($reshook < 0) {
187 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
188}
189
190// Action called when page is submitted
191if (empty($reshook) && $action == 'add') {
192 $error = 0;
193 $urlback = '';
194
195 $db->begin();
196
197 if (!GETPOST('name')) {
198 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Company")), null, 'errors');
199 $error++;
200 }
201
202 // Check Captcha code if is enabled
203 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
204 $sessionkey = 'dol_antispam_value';
205 $ok = (array_key_exists($sessionkey, $_SESSION) === true && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
206 if (!$ok) {
207 $error++;
208 $errmsg .= $langs->trans("ErrorBadValueForCode") . "<br>\n";
209 $action = '';
210 }
211 }
212
213 if (!$error) {
214 $societe = new Societe($db);
215
216 $societe->name = GETPOST('name', 'alphanohtml');
217
218 $societe->client = GETPOST('client', 'int') ? GETPOST('client', 'int') : $societe->client;
219
220 $societe->address = GETPOST('address', 'alphanohtml');
221
222 $societe->country_id = GETPOST('country_id', 'int');
223
224 $societe->phone = GETPOST('phone', 'alpha');
225
226 $societe->fax = GETPOST('fax', 'alpha');
227
228 $societe->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
229
230 $societe->client = 2 ; // our client is a prospect
231
232 $societe->code_client = -1;
233
234 $societe->name_alias = GETPOST('name_alias', 'alphanohtml');
235
236 $societe->note_private = GETPOST('note_private');
237 if (!$error) {
238 $result = $societe->create($user);
239 if ($result > 0) {
240 require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
241 $objectsoc = $societe;
242
243 if (!empty($backtopage)) {
244 $urlback = $backtopage;
245 } elseif (getDolGlobalString('MEMBER_URL_REDIRECT_SUBSCRIPTION')) {
246 $urlback = $conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION;
247 // TODO Make replacement of __AMOUNT__, etc...
248 } else {
249 $urlback = $_SERVER["PHP_SELF"] . "?action=added&token=" . newToken();
250 }
251 } else {
252 $error++;
253 $errmsg .= join('<br>', $societe->errors);
254 }
255 }
256 }
257
258 if (!$error) {
259 $db->commit();
260
261 Header("Location: " . $urlback);
262 exit;
263 } else {
264 $db->rollback();
265 $action = "create";
266 }
267}
268
269// Action called after a submitted was send and prospect created successfully
270// If MEMBER_URL_REDIRECT_SUBSCRIPTION is set to an url, we never go here because a redirect was done to this url. Same if we ask to redirect to the payment page.
271// backtopage parameter with an url was set on prospect submit page, we never go here because a redirect was done to this url.
272
273if (empty($reshook) && $action == 'added') {
274 llxHeaderVierge("newSocieteAdded");
275
276 // If we have not been redirected
277 print '<br><br>';
278 print '<div class="center">';
279 print $langs->trans("newSocieteAdded");
280 print '</div>';
281
283 exit;
284}
285
286
287
288/*
289 * View
290 */
291
292$form = new Form($db);
293$formcompany = new FormCompany($db);
294$adht = new AdherentType($db);
295$formadmin = new FormAdmin($db);
296$extrafields->fetch_name_optionals_label($objectsoc->table_element); // fetch optionals attributes and labels
297
298
299llxHeaderVierge($langs->trans("ContactUs"));
300
301print '<br>';
302print load_fiche_titre(img_picto('', 'member_nocolor', 'class="pictofixedwidth"') . ' &nbsp; ' . $langs->trans("ContactUs"), '', '', 0, 0, 'center');
303
304
305print '<div align="center">';
306print '<div id="divsubscribe">';
307
308print '<div class="center subscriptionformhelptext opacitymedium justify">';
309if (getDolGlobalString('COMPANY_NEWFORM_TEXT')) {
310 print $langs->trans($conf->global->COMPANY_NEWFORM_TEXT) . "<br>\n";
311} else {
312 print $langs->trans("ContactUsDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL")) . "<br>\n";
313}
314print '</div>';
315
316dol_htmloutput_errors($errmsg);
318
319// Print form
320print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="newprospect">' . "\n";
321print '<input type="hidden" name="token" value="' . newToken() . '" / >';
322print '<input type="hidden" name="entity" value="' . $entity . '" />';
323print '<input type="hidden" name="action" value="add" />';
324print '<br>';
325
326$messagemandatory = '<span class="">' . $langs->trans("FieldsWithAreMandatory", '*') . '</span>';
327//print '<br><span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span><br>';
328//print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
329
330print dol_get_fiche_head('');
331
332print '<script type="text/javascript">
333jQuery(document).ready(function () {
334 jQuery(document).ready(function () {
335 function initmorphy()
336 {
337 console.log("Call initmorphy");
338 if (jQuery("#morphy").val() == \'phy\') {
339 jQuery("#trcompany").hide();
340 }
341 if (jQuery("#morphy").val() == \'mor\') {
342 jQuery("#trcompany").show();
343 }
344 }
345 initmorphy();
346 jQuery("#morphy").change(function() {
347 initmorphy();
348 });
349 jQuery("#selectcountry_id").change(function() {
350 document.newprospect.action.value="create";
351 document.newprospect.submit();
352 });
353 jQuery("#typeid").change(function() {
354 document.newprospect.action.value="create";
355 document.newprospect.submit();
356 });
357 });
358});
359</script>';
360
361
362print '<table class="border" summary="form to subscribe" id="tablesubscribe">' . "\n";
363//Third party name
364/*
365if ($objectsoc->particulier || $private) {
366 print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
367} else {
368 print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $objectsoc, 0).'</span>';
369}
370*/
371print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">'; // text appreas left
372print '<input type="hidden" name="ThirdPartyName" value="' . $langs->trans('ThirdPartyName') . '">';
373print '<span id="TypeName" class="fieldrequired" title="' .dol_escape_htmltag($langs->trans("FieldsWithAreMandatory", '*')) . '" >' . $form->editfieldkey('Company', 'name', '', $objectsoc, 0) . '<span class="star"> *</span></span>';
374print '</td><td>'; // inline input
375print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="' . dol_escape_htmltag($objectsoc->name) . '" autofocus="autofocus">';
376//
377
378// Name and lastname
379print '<tr><td class="classfortooltip" title="' . dol_escape_htmltag($messagemandatory) . '">' . $langs->trans("Firstname") . ' <span class="star">*</span></td><td><input type="text" name="firstname" class="minwidth150" value="' . dol_escape_htmltag(GETPOST('firstname')) . '"></td></tr>' . "\n";
380
381print '<tr><td class="classfortooltip" title="' . dol_escape_htmltag($messagemandatory) . '">' . $langs->trans("Lastname") . ' <span class="star">*</span></td><td><input type="text" name="lastname" class="minwidth150" value="' . dol_escape_htmltag(GETPOST('lastname')) . '"></td></tr>' . "\n";
382
383// Address
384print '<tr><td class="tdtop">';
385print $form->editfieldkey('Address', 'address', '', $objectsoc, 0);
386print '</td>';
387print '<td>';
388print '<textarea name="address" id="address" class="quatrevingtpercent" rows="' . ROWS_2 . '" wrap="soft">';
389print dol_escape_htmltag($objectsoc->address, 0, 1);
390print '</textarea>';
391print $form->widgetForTranslation("address", $objectsoc, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
392print '</td></tr>';
393
394// Country
395print '<tr><td>' . $form->editfieldkey('Country', 'selectcountry_id', '', $objectsoc, 0) . '</td><td class="maxwidthonsmartphone">';
396print img_picto('', 'country', 'class="pictofixedwidth"');
397print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $objectsoc->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
398if ($user->admin) {
399 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
400}
401print '</td></tr>';
402
403// Phone / Fax
404print '<tr><td>' . $form->editfieldkey('Phone', 'phone', '', $objectsoc, 0) . '</td>';
405print '<td>' . img_picto('', 'object_phoning', 'class="pictofixedwidth"') . ' <input type="text" name="phone" id="phone" class="maxwidth200 widthcentpercentminusx" value="' . (GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $objectsoc->phone) . '"></td>';
406print '</tr>';
407
408print '<tr>';
409print '<td>' . $form->editfieldkey('Fax', 'fax', '', $objectsoc, 0) . '</td>';
410print '<td>' . img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"') . ' <input type="text" name="fax" id="fax" class="maxwidth200 widthcentpercentminusx" value="' . (GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $objectsoc->fax) . '"></td>';
411print '</tr>';
412
413// Email / Web
414print '<tr><td>' . $form->editfieldkey('EMail', 'email', '', $objectsoc, 0, 'string', '', !getDolGlobalString('SOCIETE_EMAIL_MANDATORY') ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY) . '</td>';
415print '<td>' . img_picto('', 'object_email', 'class="pictofixedwidth"') . ' <input type="text" class="maxwidth200 widthcentpercentminusx" name="email" id="email" value="' . $objectsoc->email . '"></td>';
416if (isModEnabled('mailing') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
417 if ($conf->browser->layout == 'phone') {
418 print '</tr><tr>';
419 }
420 print '<td class="individualline noemail">' . $form->editfieldkey($langs->trans('No_Email') . ' (' . $langs->trans('Contact') . ')', 'contact_no_email', '', $objectsoc, 0) . '</td>';
421 print '<td class="individualline" ' . (($conf->browser->layout == 'phone') || !isModEnabled('mailing') ? ' colspan="3"' : '') . '>' . $form->selectyesno('contact_no_email', (GETPOSTISSET("contact_no_email") ? GETPOST("contact_no_email", 'alpha') : (empty($objectsoc->no_email) ? 0 : 1)), 1, false, 1) . '</td>';
422}
423print '</tr>';
424
425print '<tr><td>' . $form->editfieldkey('Web', 'url', '', $objectsoc, 0) . '</td>';
426print '<td>' . img_picto('', 'globe', 'class="pictofixedwidth"') . ' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="' . $objectsoc->url . '"></td></tr>';
427
428
429// Comments
430print '<tr>';
431print '<td class="tdtop">' . $langs->trans("Comments") . '</td>';
432print '<td class="tdtop"><textarea name="note_private" id="note_private" wrap="soft" class="quatrevingtpercent" rows="' . ROWS_3 . '">' . dol_escape_htmltag(GETPOST('note_private', 'restricthtml'), 0, 1) . '</textarea></td>';
433print '</tr>' . "\n";
434// TODO Move this into generic feature.
435
436
437
438// Display Captcha code if is enabled
439if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
440 require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
441 print '<tr><td class="titlefield"><label for="email"><span class="fieldrequired">' . $langs->trans("SecurityCode") . '</span></label></td><td>';
442 print '<span class="span-icon-security inline-block">';
443 print '<input id="securitycode" placeholder="' . $langs->trans("SecurityCode") . '" class="flat input-icon-security width150" type="text" maxlength="5" name="code" tabindex="3" />';
444 print '</span>';
445 print '<span class="nowrap inline-block">';
446 print '<img class="inline-block valignmiddle" src="' . DOL_URL_ROOT . '/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />';
447 print '<a class="inline-block valignmiddle" href="' . $php_self . '" tabindex="4" data-role="button">' . img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"') . '</a>';
448 print '</span>';
449 print '</td></tr>';
450}
451
452print "</table>\n";
453
454print dol_get_fiche_end();
455
456// Save / Submit
457print '<div class="center">';
458print '<input type="submit" value="' . $langs->trans("Send") . '" id="submitsave" class="button">';
459if (!empty($backtopage)) {
460 print ' &nbsp; &nbsp; <input type="submit" value="' . $langs->trans("Cancel") . '" id="submitcancel" class="button button-cancel">';
461}
462print '</div>';
463
464
465print "</form>\n";
466print "<br>";
467print '</div></div>';
468
469
470
472
473$db->close();
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 members type.
Class to manage standard extra fields.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
llxFooterVierge()
Show footer for new societe.
Definition new.php:158
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_get_fiche_end($notab=0)
Return tab footer of a card.
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
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.