* Copyright (C) 2001-2002 Jean-Louis Bergamo * Copyright (C) 2006-2013 Laurent Destailleur * Copyright (C) 2012 Regis Houssin * Copyright (C) 2012 J. Fernando Lagrange * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2018 Alexandre Spangaro * Copyright (C) 2021 Waël Almoman * Copyright (C) 2022 Udo Tamm * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/public/company/new.php * \ingroup prospect * \brief Example of form to add a new prospect * */ if (!defined('NOLOGIN')) { define("NOLOGIN", 1); // This means this output page does not require to be logged. } if (!defined('NOCSRFCHECK')) { define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. } if (!defined('NOBROWSERNOTIF')) { define('NOBROWSERNOTIF', '1'); } // For MultiCompany module. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php // Because 2 entities can have the same ref $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); // if (is_numeric($entity)) { // value is casted to int so always numeric define("DOLENTITY", $entity); // } // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php'; require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/public.lib.php'; /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Init vars $backtopage = GETPOST('backtopage', 'alpha'); $action = GETPOST('action', 'aZ09'); $errmsg = ''; $num = 0; $error = 0; // Load translation files $langs->loadLangs(array("main", "members", "companies", "install", "other", "errors")); // Security check if (!isModEnabled('societe')) { httponly_accessforbidden('Module Thirdparty not enabled'); } if (!getDolGlobalString('SOCIETE_ENABLE_PUBLIC')) { httponly_accessforbidden("Online form for contact for public visitors has not been enabled"); } // permissions $permissiontoadd = $user->hasRight('societe', 'creer'); // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context $hookmanager->initHooks(array('publicnewmembercard', 'globalcard')); $extrafields = new ExtraFields($db); $objectsoc = new Societe($db); $user->loadDefaultValues(); $extrafields->fetch_name_optionals_label($objectsoc->table_element); // fetch optionals attributes and labels /** * Show header for new prospect * * @param string $title Title * @param string $head Head array * @param int $disablejs More content into html header * @param int $disablehead More content into html header * @param string[]|string $arrayofjs Array of complementary js files * @param string[]|string $arrayofcss Array of complementary css files * @return void */ function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = []) { global $conf, $langs, $mysoc; top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers print ''; // Define urllogo $urllogo = DOL_URL_ROOT . '/theme/common/login_logo.png'; if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) { $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=mycompany&file=' . urlencode('logos/thumbs/' . $mysoc->logo_small); } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) { $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=mycompany&file=' . urlencode('logos/' . $mysoc->logo); } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.svg')) { $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.svg'; } print '
'; // Output html code for logo // if ($urllogo) { // test always true print '
'; print '
'; print ''; print '
'; if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) { print ''; } print '
'; // } if (getDolGlobalString('MEMBER_IMAGE_PUBLIC_REGISTRATION')) { print '
'; print ''; print '
'; } print '
'; print '
'; } /** * Show footer for new societe * * @return void */ function llxFooterVierge() { global $conf, $langs; print '
'; printCommonFooter('public'); if (!empty($conf->use_javascript_ajax)) { print "\n" . '' . "\n"; print '' . "\n"; } print "\n"; print "\n"; } /* * Actions */ $parameters = array(); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } // Action called when page is submitted if (empty($reshook) && $action == 'add') { // Test on permission not required here. This is a public page. Security is done on constant and mitigation. $error = 0; $urlback = ''; $db->begin(); if (!GETPOST('name')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Company")), null, 'errors'); $error++; } // Check Captcha code if is enabled if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { $sessionkey = 'dol_antispam_value'; $ok = (array_key_exists($sessionkey, $_SESSION) && (strtolower($_SESSION[$sessionkey]) == strtolower(GETPOST('code')))); if (!$ok) { $error++; $errmsg .= $langs->trans("ErrorBadValueForCode") . "
\n"; $action = ''; } } if (!$error) { $societe = new Societe($db); $societe->name = GETPOST('name', 'alphanohtml'); $societe->client = GETPOSTINT('client') ? GETPOSTINT('client') : $societe->client; $societe->address = GETPOST('address', 'alphanohtml'); $societe->country_id = GETPOSTINT('country_id'); $societe->phone = GETPOST('phone', 'alpha'); $societe->fax = GETPOST('fax', 'alpha'); $societe->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); $societe->client = 2 ; // our client is a prospect $societe->code_client = '-1'; $societe->name_alias = GETPOST('name_alias', 'alphanohtml'); $societe->note_private = GETPOST('note_private', 'alphanohtml'); // Fill array 'array_options' with data from add form /* $extrafields->fetch_name_optionals_label($societe->table_element); $ret = $extrafields->setOptionalsFromPost(null, $societe); if ($ret < 0) { $error++; $errmsg .= $societe->error; } */ $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200); if (checkNbPostsForASpeceificIp($societe, $nb_post_max) <= 0) { $error++; $errmsg .= implode('
', $societe->errors); } if (!$error) { $result = $societe->create($user); if ($result > 0) { require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; $objectsoc = $societe; if (!empty($backtopage)) { $urlback = $backtopage; } elseif (getDolGlobalString('MEMBER_URL_REDIRECT_SUBSCRIPTION')) { $urlback = getDolGlobalString('MEMBER_URL_REDIRECT_SUBSCRIPTION'); // TODO Make replacement of __AMOUNT__, etc... } else { $urlback = $_SERVER["PHP_SELF"] . "?action=added&token=" . newToken(); } } else { $error++; $errmsg .= implode('
', $societe->errors); } } } if (!$error) { $db->commit(); header("Location: " . $urlback); exit; } else { $db->rollback(); $action = "create"; } } // Action called after a submitted was send and prospect created successfully // 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. // backtopage parameter with an url was set on prospect submit page, we never go here because a redirect was done to this url. if (empty($reshook) && $action == 'added') { // Test on permission not required here llxHeaderVierge("newSocieteAdded"); // If we have not been redirected print '

'; print '
'; print $langs->trans("newSocieteAdded"); print '
'; llxFooterVierge(); exit; } /* * View */ $form = new Form($db); $formcompany = new FormCompany($db); $adht = new AdherentType($db); $formadmin = new FormAdmin($db); llxHeaderVierge($langs->trans("ContactUs")); print '
'; print load_fiche_titre(img_picto('', 'member_nocolor', 'class="pictofixedwidth"') . '   ' . $langs->trans("ContactUs"), '', '', 0, '', 'center'); print '
'; print '
'; print '
'; if (getDolGlobalString('COMPANY_NEWFORM_TEXT')) { print $langs->trans(getDolGlobalString('COMPANY_NEWFORM_TEXT')) . "
\n"; } else { print $langs->trans("ContactUsDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL")) . "
\n"; } print '
'; dol_htmloutput_errors($errmsg); dol_htmloutput_events(); // Print form print '
' . "\n"; print ''; print ''; print ''; print '
'; $messagemandatory = '' . $langs->trans("FieldsWithAreMandatory", '*') . ''; //print '
'.$langs->trans("FieldsWithAreMandatory", '*').'
'; //print $langs->trans("FieldsWithIsForPublic",'**').'
'; print dol_get_fiche_head(); print ''; print '' . "\n"; //Third party name /* if ($objectsoc->particulier || $private) { print ''.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').''; } else { print ''.$form->editfieldkey('ThirdPartyName', 'name', '', $objectsoc, 0).''; } */ print '' . "\n"; print '' . "\n"; // Address print ''; print ''; // Country print ''; // Phone / Fax print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Email / Web print ''; print ''; if (isModEnabled('mailing') && getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) { if ($conf->browser->layout == 'phone') { print ''; } print ''; print ''; } print ''; print ''; print ''; // Comments print ''; print ''; print ''; print '' . "\n"; // Other attributes $parameters['tpl_context'] = 'public'; // define template context to public include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; // TODO Move this into generic feature. // Display Captcha code if is enabled if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA')) { require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; print ''; } print "
'; // text appreas left print ''; print '' . $form->editfieldkey('Company', 'name', '', $objectsoc, 0) . ' *'; print ''; // inline input print ''; // // Name and lastname print '
' . $langs->trans("Firstname") . ' *
' . $langs->trans("Lastname") . ' *
'; print $form->editfieldkey('Address', 'address', '', $objectsoc, 0); print ''; print ''; print $form->widgetForTranslation("address", $objectsoc, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent'); print '
' . $form->editfieldkey('Country', 'selectcountry_id', '', $objectsoc, 0) . ''; print img_picto('', 'country', 'class="pictofixedwidth"'); print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $objectsoc->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx'); if ($user->admin) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } print '
' . $form->editfieldkey('Phone', 'phone', '', $objectsoc, 0) . '' . img_picto('', 'object_phoning', 'class="pictofixedwidth"') . '
' . $form->editfieldkey('Fax', 'fax', '', $objectsoc, 0) . '' . img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"') . '
' . $form->editfieldkey('EMail', 'email', '', $objectsoc, 0, 'string', '', !getDolGlobalString('SOCIETE_EMAIL_MANDATORY') ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY) . '' . img_picto('', 'object_email', 'class="pictofixedwidth"') . '
' . $form->editfieldkey($langs->trans('No_Email') . ' (' . $langs->trans('Contact') . ')', 'contact_no_email', '', $objectsoc, 0) . '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) . '
' . $form->editfieldkey('Web', 'url', '', $objectsoc, 0) . '' . img_picto('', 'globe', 'class="pictofixedwidth"') . '
' . $langs->trans("Comments") . '
'; print ''; print ''; print ''; print ''; print ''; print '' . img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"') . ''; print ''; print '
\n"; print dol_get_fiche_end(); // Save / Submit print '
'; print ''; if (!empty($backtopage)) { print '     '; } print '
'; print "
\n"; print "
"; print '
'; llxFooterVierge(); $db->close();