new.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. /**
  26. * \file htdocs/public/company/new.php
  27. * \ingroup prospect
  28. * \brief Example of form to add a new prospect
  29. *
  30. */
  31. if (!defined('NOLOGIN')) {
  32. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  33. }
  34. if (!defined('NOCSRFCHECK')) {
  35. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  36. }
  37. if (!defined('NOBROWSERNOTIF')) {
  38. define('NOBROWSERNOTIF', '1');
  39. }
  40. // For MultiCompany module.
  41. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  42. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  43. if (is_numeric($entity)) {
  44. define("DOLENTITY", $entity);
  45. }
  46. // Load Dolibarr environment
  47. require '../../main.inc.php';
  48. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  49. require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php';
  50. require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
  51. require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php';
  52. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  53. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  54. require_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php';
  55. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  56. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
  57. // Init vars
  58. $backtopage = GETPOST('backtopage', 'alpha');
  59. $action = GETPOST('action', 'aZ09');
  60. $errmsg = '';
  61. $num = 0;
  62. $error = 0;
  63. // Load translation files
  64. $langs->loadLangs(array("main", "members", "companies", "install", "other", "errors"));
  65. // Security check
  66. if (!isModEnabled('societe')) {
  67. httponly_accessforbidden('Module Thirdparty not enabled');
  68. }
  69. if (!getDolGlobalString('SOCIETE_ENABLE_PUBLIC')) {
  70. httponly_accessforbidden("Online form for contact for public visitors has not been enabled");
  71. }
  72. //permissions
  73. $permissiontoadd = $user->hasRight('societe', 'creer');
  74. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  75. $hookmanager->initHooks(array('publicnewmembercard', 'globalcard'));
  76. $extrafields = new ExtraFields($db);
  77. $objectsoc = new Societe($db);
  78. $user->loadDefaultValues();
  79. /**
  80. * Show header for new prospect
  81. *
  82. * @param string $title Title
  83. * @param string $head Head array
  84. * @param int $disablejs More content into html header
  85. * @param int $disablehead More content into html header
  86. * @param array $arrayofjs Array of complementary js files
  87. * @param array $arrayofcss Array of complementary css files
  88. * @return void
  89. */
  90. function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
  91. {
  92. global $conf, $langs, $mysoc;
  93. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  94. print '<body id="mainbody" class="publicnewmemberform">';
  95. // Define urllogo
  96. $urllogo = DOL_URL_ROOT . '/theme/common/login_logo.png';
  97. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
  98. $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file=' . urlencode('logos/thumbs/' . $mysoc->logo_small);
  99. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
  100. $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file=' . urlencode('logos/' . $mysoc->logo);
  101. } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.svg')) {
  102. $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.svg';
  103. }
  104. print '<header class="center">';
  105. // Output html code for logo
  106. if ($urllogo) {
  107. print '<div class="backgreypublicpayment">';
  108. print '<div class="logopublicpayment">';
  109. print '<img id="dolpaymentlogo" src="' . $urllogo . '">';
  110. print '</div>';
  111. if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
  112. 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>';
  113. }
  114. print '</div>';
  115. }
  116. if (getDolGlobalString('MEMBER_IMAGE_PUBLIC_REGISTRATION')) {
  117. print '<div class="backimagepublicregistration">';
  118. print '<img id="idEVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('MEMBER_IMAGE_PUBLIC_REGISTRATION') . '">';
  119. print '</div>';
  120. }
  121. print '</header>';
  122. print '<div class="divmainbodylarge">';
  123. }
  124. /**
  125. * Show footer for new societe
  126. *
  127. * @return void
  128. */
  129. function llxFooterVierge()
  130. {
  131. global $conf, $langs;
  132. $ext = '';
  133. print '</div>';
  134. printCommonFooter('public');
  135. if (!empty($conf->use_javascript_ajax)) {
  136. print "\n" . '<!-- Includes JS Footer of Dolibarr -->' . "\n";
  137. print '<script src="' . DOL_URL_ROOT . '/core/js/lib_foot.js.php?lang=' . $langs->defaultlang . (!empty($ext) ? '&' . $ext : '') . '"></script>' . "\n";
  138. }
  139. print "</body>\n";
  140. print "</html>\n";
  141. }
  142. /*
  143. * Actions
  144. */
  145. $parameters = array();
  146. // Note that $action and $object may have been modified by some hooks
  147. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  148. if ($reshook < 0) {
  149. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  150. }
  151. // Action called when page is submitted
  152. if (empty($reshook) && $action == 'add') {
  153. $error = 0;
  154. $urlback = '';
  155. $db->begin();
  156. if (!GETPOST('name')) {
  157. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Company")), null, 'errors');
  158. $error++;
  159. }
  160. // Check Captcha code if is enabled
  161. if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
  162. $sessionkey = 'dol_antispam_value';
  163. $ok = (array_key_exists($sessionkey, $_SESSION) === true && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
  164. if (!$ok) {
  165. $error++;
  166. $errmsg .= $langs->trans("ErrorBadValueForCode") . "<br>\n";
  167. $action = '';
  168. }
  169. }
  170. if (!$error) {
  171. $societe = new Societe($db);
  172. $societe->name = GETPOST('name', 'alphanohtml');
  173. $societe->client = GETPOST('client', 'int') ? GETPOST('client', 'int') : $societe->client;
  174. $societe->address = GETPOST('address', 'alphanohtml');
  175. $societe->country_id = GETPOST('country_id', 'int');
  176. $societe->phone = GETPOST('phone', 'alpha');
  177. $societe->fax = GETPOST('fax', 'alpha');
  178. $societe->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
  179. $societe->client = 2 ; // our client is a prospect
  180. $societe->code_client = -1;
  181. $societe->name_alias = GETPOST('name_alias', 'alphanohtml');
  182. $societe->note_private = GETPOST('note_private');
  183. if (!$error) {
  184. $result = $societe->create($user);
  185. if ($result > 0) {
  186. require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
  187. $objectsoc = $societe;
  188. if (!empty($backtopage)) {
  189. $urlback = $backtopage;
  190. } elseif (getDolGlobalString('MEMBER_URL_REDIRECT_SUBSCRIPTION')) {
  191. $urlback = $conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION;
  192. // TODO Make replacement of __AMOUNT__, etc...
  193. } else {
  194. $urlback = $_SERVER["PHP_SELF"] . "?action=added&token=" . newToken();
  195. }
  196. } else {
  197. $error++;
  198. $errmsg .= join('<br>', $societe->errors);
  199. }
  200. }
  201. }
  202. if (!$error) {
  203. $db->commit();
  204. Header("Location: " . $urlback);
  205. exit;
  206. } else {
  207. $db->rollback();
  208. $action = "create";
  209. }
  210. }
  211. // Action called after a submitted was send and prospect created successfully
  212. // 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.
  213. // backtopage parameter with an url was set on prospect submit page, we never go here because a redirect was done to this url.
  214. if (empty($reshook) && $action == 'added') {
  215. llxHeaderVierge("newSocieteAdded");
  216. // If we have not been redirected
  217. print '<br><br>';
  218. print '<div class="center">';
  219. print $langs->trans("newSocieteAdded");
  220. print '</div>';
  221. llxFooterVierge();
  222. exit;
  223. }
  224. /*
  225. * View
  226. */
  227. $form = new Form($db);
  228. $formcompany = new FormCompany($db);
  229. $adht = new AdherentType($db);
  230. $formadmin = new FormAdmin($db);
  231. $extrafields->fetch_name_optionals_label($objectsoc->table_element); // fetch optionals attributes and labels
  232. llxHeaderVierge($langs->trans("ContactUs"));
  233. print '<br>';
  234. print load_fiche_titre(img_picto('', 'member_nocolor', 'class="pictofixedwidth"') . ' &nbsp; ' . $langs->trans("ContactUs"), '', '', 0, 0, 'center');
  235. print '<div align="center">';
  236. print '<div id="divsubscribe">';
  237. print '<div class="center subscriptionformhelptext opacitymedium justify">';
  238. if (getDolGlobalString('COMPANY_NEWFORM_TEXT')) {
  239. print $langs->trans($conf->global->COMPANY_NEWFORM_TEXT) . "<br>\n";
  240. } else {
  241. print $langs->trans("ContactUsDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL")) . "<br>\n";
  242. }
  243. print '</div>';
  244. dol_htmloutput_errors($errmsg);
  245. dol_htmloutput_events();
  246. // Print form
  247. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="newprospect">' . "\n";
  248. print '<input type="hidden" name="token" value="' . newToken() . '" / >';
  249. print '<input type="hidden" name="entity" value="' . $entity . '" />';
  250. print '<input type="hidden" name="action" value="add" />';
  251. print '<br>';
  252. $messagemandatory = '<span class="">' . $langs->trans("FieldsWithAreMandatory", '*') . '</span>';
  253. //print '<br><span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span><br>';
  254. //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
  255. print dol_get_fiche_head('');
  256. print '<script type="text/javascript">
  257. jQuery(document).ready(function () {
  258. jQuery(document).ready(function () {
  259. function initmorphy()
  260. {
  261. console.log("Call initmorphy");
  262. if (jQuery("#morphy").val() == \'phy\') {
  263. jQuery("#trcompany").hide();
  264. }
  265. if (jQuery("#morphy").val() == \'mor\') {
  266. jQuery("#trcompany").show();
  267. }
  268. }
  269. initmorphy();
  270. jQuery("#morphy").change(function() {
  271. initmorphy();
  272. });
  273. jQuery("#selectcountry_id").change(function() {
  274. document.newprospect.action.value="create";
  275. document.newprospect.submit();
  276. });
  277. jQuery("#typeid").change(function() {
  278. document.newprospect.action.value="create";
  279. document.newprospect.submit();
  280. });
  281. });
  282. });
  283. </script>';
  284. print '<table class="border" summary="form to subscribe" id="tablesubscribe">' . "\n";
  285. //Third party name
  286. /*
  287. if ($objectsoc->particulier || $private) {
  288. print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
  289. } else {
  290. print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $objectsoc, 0).'</span>';
  291. }
  292. */
  293. print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">'; // text appreas left
  294. print '<input type="hidden" name="ThirdPartyName" value="' . $langs->trans('ThirdPartyName') . '">';
  295. print '<span id="TypeName" class="fieldrequired" title="' .dol_escape_htmltag($langs->trans("FieldsWithAreMandatory", '*')) . '" >' . $form->editfieldkey('Company', 'name', '', $objectsoc, 0) . '<span class="star"> *</span></span>';
  296. print '</td><td>'; // inline input
  297. print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="' . dol_escape_htmltag($objectsoc->name) . '" autofocus="autofocus">';
  298. //
  299. // Name and lastname
  300. print '<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";
  301. print '<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";
  302. // Address
  303. print '<tr><td class="tdtop">';
  304. print $form->editfieldkey('Address', 'address', '', $objectsoc, 0);
  305. print '</td>';
  306. print '<td>';
  307. print '<textarea name="address" id="address" class="quatrevingtpercent" rows="' . ROWS_2 . '" wrap="soft">';
  308. print dol_escape_htmltag($objectsoc->address, 0, 1);
  309. print '</textarea>';
  310. print $form->widgetForTranslation("address", $objectsoc, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
  311. print '</td></tr>';
  312. // Country
  313. print '<tr><td>' . $form->editfieldkey('Country', 'selectcountry_id', '', $objectsoc, 0) . '</td><td class="maxwidthonsmartphone">';
  314. print img_picto('', 'country', 'class="pictofixedwidth"');
  315. print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $objectsoc->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
  316. if ($user->admin) {
  317. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  318. }
  319. print '</td></tr>';
  320. // Phone / Fax
  321. print '<tr><td>' . $form->editfieldkey('Phone', 'phone', '', $objectsoc, 0) . '</td>';
  322. print '<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>';
  323. print '</tr>';
  324. print '<tr>';
  325. print '<td>' . $form->editfieldkey('Fax', 'fax', '', $objectsoc, 0) . '</td>';
  326. print '<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>';
  327. print '</tr>';
  328. // Email / Web
  329. print '<tr><td>' . $form->editfieldkey('EMail', 'email', '', $objectsoc, 0, 'string', '', !getDolGlobalString('SOCIETE_EMAIL_MANDATORY') ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY) . '</td>';
  330. print '<td>' . img_picto('', 'object_email', 'class="pictofixedwidth"') . ' <input type="text" class="maxwidth200 widthcentpercentminusx" name="email" id="email" value="' . $objectsoc->email . '"></td>';
  331. if (isModEnabled('mailing') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
  332. if ($conf->browser->layout == 'phone') {
  333. print '</tr><tr>';
  334. }
  335. print '<td class="individualline noemail">' . $form->editfieldkey($langs->trans('No_Email') . ' (' . $langs->trans('Contact') . ')', 'contact_no_email', '', $objectsoc, 0) . '</td>';
  336. 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>';
  337. }
  338. print '</tr>';
  339. print '<tr><td>' . $form->editfieldkey('Web', 'url', '', $objectsoc, 0) . '</td>';
  340. print '<td>' . img_picto('', 'globe', 'class="pictofixedwidth"') . ' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="' . $objectsoc->url . '"></td></tr>';
  341. // Comments
  342. print '<tr>';
  343. print '<td class="tdtop">' . $langs->trans("Comments") . '</td>';
  344. print '<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>';
  345. print '</tr>' . "\n";
  346. // TODO Move this into generic feature.
  347. // Display Captcha code if is enabled
  348. if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) {
  349. require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
  350. print '<tr><td class="titlefield"><label for="email"><span class="fieldrequired">' . $langs->trans("SecurityCode") . '</span></label></td><td>';
  351. print '<span class="span-icon-security inline-block">';
  352. print '<input id="securitycode" placeholder="' . $langs->trans("SecurityCode") . '" class="flat input-icon-security width150" type="text" maxlength="5" name="code" tabindex="3" />';
  353. print '</span>';
  354. print '<span class="nowrap inline-block">';
  355. print '<img class="inline-block valignmiddle" src="' . DOL_URL_ROOT . '/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />';
  356. 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>';
  357. print '</span>';
  358. print '</td></tr>';
  359. }
  360. print "</table>\n";
  361. print dol_get_fiche_end();
  362. // Save / Submit
  363. print '<div class="center">';
  364. print '<input type="submit" value="' . $langs->trans("Send") . '" id="submitsave" class="button">';
  365. if (!empty($backtopage)) {
  366. print ' &nbsp; &nbsp; <input type="submit" value="' . $langs->trans("Cancel") . '" id="submitcancel" class="button button-cancel">';
  367. }
  368. print '</div>';
  369. print "</form>\n";
  370. print "<br>";
  371. print '</div></div>';
  372. llxFooterVierge();
  373. $db->close();