new.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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-2021 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/public/project/new.php
  25. * \ingroup project
  26. * \brief Page to record a message/lead into a project/lead
  27. */
  28. if (!defined('NOLOGIN')) {
  29. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  30. }
  31. if (!defined('NOCSRFCHECK')) {
  32. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  33. }
  34. if (!defined('NOIPCHECK')) {
  35. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  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/json.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  52. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  53. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  54. // Init vars
  55. $errmsg = '';
  56. $error = 0;
  57. $backtopage = GETPOST('backtopage', 'alpha');
  58. $action = GETPOST('action', 'aZ09');
  59. // Load translation files
  60. $langs->loadLangs(array("members", "companies", "install", "other", "projects"));
  61. if (!getDolGlobalString('PROJECT_ENABLE_PUBLIC')) {
  62. print $langs->trans("Form for public lead registration has not been enabled");
  63. exit;
  64. }
  65. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  66. $hookmanager->initHooks(array('publicnewleadcard', 'globalcard'));
  67. $extrafields = new ExtraFields($db);
  68. $object = new Project($db);
  69. $user->loadDefaultValues();
  70. // Security check
  71. if (empty($conf->project->enabled)) {
  72. httponly_accessforbidden('Module Project not enabled');
  73. }
  74. /**
  75. * Show header for new member
  76. *
  77. * @param string $title Title
  78. * @param string $head Head array
  79. * @param int $disablejs More content into html header
  80. * @param int $disablehead More content into html header
  81. * @param array $arrayofjs Array of complementary js files
  82. * @param array $arrayofcss Array of complementary css files
  83. * @return void
  84. */
  85. function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
  86. {
  87. global $user, $conf, $langs, $mysoc;
  88. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  89. print '<body id="mainbody" class="publicnewmemberform">';
  90. // Define urllogo
  91. $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
  92. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
  93. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
  94. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
  95. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$mysoc->logo);
  96. } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
  97. $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
  98. }
  99. print '<div class="center">';
  100. // Output html code for logo
  101. if ($urllogo) {
  102. print '<div class="backgreypublicpayment">';
  103. print '<div class="logopublicpayment">';
  104. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  105. print '>';
  106. print '</div>';
  107. if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
  108. 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>';
  109. }
  110. print '</div>';
  111. }
  112. if (getDolGlobalString('PROJECT_IMAGE_PUBLIC_NEWLEAD')) {
  113. print '<div class="backimagepublicnewlead">';
  114. print '<img id="idPROJECT_IMAGE_PUBLIC_NEWLEAD" src="' . getDolGlobalString('PROJECT_IMAGE_PUBLIC_NEWLEAD').'">';
  115. print '</div>';
  116. }
  117. print '</div>';
  118. print '<div class="divmainbodylarge">';
  119. }
  120. /**
  121. * Show footer for new member
  122. *
  123. * @return void
  124. */
  125. function llxFooterVierge()
  126. {
  127. print '</div>';
  128. printCommonFooter('public');
  129. print "</body>\n";
  130. print "</html>\n";
  131. }
  132. /*
  133. * Actions
  134. */
  135. $parameters = array();
  136. // Note that $action and $object may have been modified by some hooks
  137. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  138. if ($reshook < 0) {
  139. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  140. }
  141. // Action called when page is submitted
  142. if (empty($reshook) && $action == 'add') {
  143. $error = 0;
  144. $urlback = '';
  145. $db->begin();
  146. if (!GETPOST("lastname")) {
  147. $error++;
  148. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
  149. }
  150. if (!GETPOST("firstname")) {
  151. $error++;
  152. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
  153. }
  154. if (!GETPOST("email")) {
  155. $error++;
  156. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email"))."<br>\n";
  157. }
  158. if (!GETPOST("description")) {
  159. $error++;
  160. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Message"))."<br>\n";
  161. }
  162. if (GETPOST("email") && !isValidEmail(GETPOST("email"))) {
  163. $error++;
  164. $langs->load("errors");
  165. $errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email"))."<br>\n";
  166. }
  167. // Set default opportunity status
  168. $defaultoppstatus = getDolGlobalString('PROJECT_DEFAULT_OPPORTUNITY_STATUS_FOR_ONLINE_LEAD');
  169. if (empty($defaultoppstatus)) {
  170. $error++;
  171. $langs->load("errors");
  172. $errmsg .= $langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Project"))."<br>\n";
  173. }
  174. $visibility = getDolGlobalString('PROJET_VISIBILITY');
  175. $proj = new Project($db);
  176. $thirdparty = new Societe($db);
  177. if (!$error) {
  178. // Search thirdparty and set it if found to the new created project
  179. $result = $thirdparty->fetch(0, '', '', '', '', '', '', '', '', '', $object->email);
  180. if ($result > 0) {
  181. $proj->socid = $thirdparty->id;
  182. } else {
  183. // Create the prospect
  184. if (GETPOST('societe')) {
  185. $thirdparty->name = GETPOST('societe');
  186. $thirdparty->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname'));
  187. } else {
  188. $thirdparty->name = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname'));
  189. }
  190. $thirdparty->email = GETPOST('email');
  191. $thirdparty->address = GETPOST('address');
  192. $thirdparty->zip = GETPOST('zip');
  193. $thirdparty->town = GETPOST('town');
  194. $thirdparty->country_id = GETPOST('country_id', 'int');
  195. $thirdparty->state_id = GETPOST('state_id');
  196. $thirdparty->client = $thirdparty::PROSPECT;
  197. $thirdparty->code_client = 'auto';
  198. $thirdparty->code_fournisseur = 'auto';
  199. // Fill array 'array_options' with data from the form
  200. $extrafields->fetch_name_optionals_label($thirdparty->table_element);
  201. $ret = $extrafields->setOptionalsFromPost(null, $thirdparty, '', 1);
  202. //var_dump($thirdparty->array_options);exit;
  203. if ($ret < 0) {
  204. $error++;
  205. $errmsg = ($extrafields->error ? $extrafields->error.'<br>' : '').join('<br>', $extrafields->errors);
  206. }
  207. if (!$error) {
  208. $result = $thirdparty->create($user);
  209. if ($result <= 0) {
  210. $error++;
  211. $errmsg = ($thirdparty->error ? $thirdparty->error.'<br>' : '').join('<br>', $thirdparty->errors);
  212. } else {
  213. $proj->socid = $thirdparty->id;
  214. }
  215. }
  216. }
  217. }
  218. if (!$error) {
  219. // Defined the ref into $defaultref
  220. $defaultref = '';
  221. $modele = !getDolGlobalString('PROJECT_ADDON') ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
  222. // Search template files
  223. $file = '';
  224. $classname = '';
  225. $filefound = 0;
  226. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  227. foreach ($dirmodels as $reldir) {
  228. $file = dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0);
  229. if (file_exists($file)) {
  230. $filefound = 1;
  231. $classname = $modele;
  232. break;
  233. }
  234. }
  235. if ($filefound) {
  236. $result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
  237. $modProject = new $classname();
  238. $defaultref = $modProject->getNextValue($thirdparty, $object);
  239. }
  240. if (is_numeric($defaultref) && $defaultref <= 0) {
  241. $defaultref = '';
  242. }
  243. if (empty($defaultref)) {
  244. $defaultref = 'PJ'.dol_print_date(dol_now(), 'dayrfc');
  245. }
  246. if ($visibility === "1") {
  247. $proj->public = 1;
  248. } elseif ($visibility === "0") {
  249. $proj->public = 0;
  250. } elseif (empty($visibility)) {
  251. $proj->public = 1;
  252. }
  253. $proj->ref = $defaultref;
  254. $proj->statut = $proj::STATUS_DRAFT;
  255. $proj->status = $proj::STATUS_DRAFT;
  256. $proj->usage_opportunity = 1;
  257. $proj->title = $langs->trans("LeadFromPublicForm");
  258. $proj->description = GETPOST("description", "alphanohtml");
  259. $proj->opp_status = $defaultoppstatus;
  260. $proj->fk_opp_status = $defaultoppstatus;
  261. $proj->ip = getUserRemoteIP();
  262. $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
  263. $now = dol_now();
  264. $minmonthpost = dol_time_plus_duree($now, -1, "m");
  265. $nb_post_ip = 0;
  266. if ($nb_post_max > 0) { // Calculate only if there is a limit to check
  267. $sql = "SELECT COUNT(rowid) as nb_projets";
  268. $sql .= " FROM ".MAIN_DB_PREFIX."projet";
  269. $sql .= " WHERE ip = '".$db->escape($proj->ip)."'";
  270. $sql .= " AND datec > '".$db->idate($minmonthpost)."'";
  271. $resql = $db->query($sql);
  272. if ($resql) {
  273. $num = $db->num_rows($resql);
  274. $i = 0;
  275. while ($i < $num) {
  276. $i++;
  277. $obj = $db->fetch_object($resql);
  278. $nb_post_ip = $obj->nb_projets;
  279. }
  280. }
  281. }
  282. // Fill array 'array_options' with data from the form
  283. $extrafields->fetch_name_optionals_label($proj->table_element);
  284. $ret = $extrafields->setOptionalsFromPost(null, $proj);
  285. if ($ret < 0) {
  286. $error++;
  287. }
  288. if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
  289. $error++;
  290. $errmsg = $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
  291. array_push($proj->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
  292. }
  293. // Create the project
  294. if (!$error) {
  295. $result = $proj->create($user);
  296. if ($result > 0) {
  297. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  298. $object = $proj;
  299. if ($object->email) {
  300. $subject = '';
  301. $msg = '';
  302. // Send subscription email
  303. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  304. $formmail = new FormMail($db);
  305. // Set output language
  306. $outputlangs = new Translate('', $conf);
  307. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  308. // Load traductions files required by page
  309. $outputlangs->loadLangs(array("main", "members", "projects"));
  310. // Get email content from template
  311. $arraydefaultmessage = null;
  312. $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD;
  313. if (!empty($labeltouse)) {
  314. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'project', $user, $outputlangs, 0, 1, $labeltouse);
  315. }
  316. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  317. $subject = $arraydefaultmessage->topic;
  318. $msg = $arraydefaultmessage->content;
  319. }
  320. if (empty($labeltosue)) {
  321. $appli = $mysoc->name;
  322. $labeltouse = '['.$appli.'] '.$langs->trans("YourMessage");
  323. $msg = $langs->trans("YourMessageHasBeenReceived");
  324. }
  325. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  326. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  327. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  328. $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
  329. if ($subjecttosend && $texttosend) {
  330. $moreinheader = 'X-Dolibarr-Info: send_an_email by public/lead/new.php'."\r\n";
  331. $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
  332. }
  333. /*if ($result < 0) {
  334. $error++;
  335. setEventMessages($object->error, $object->errors, 'errors');
  336. }*/
  337. }
  338. if (!empty($backtopage)) {
  339. $urlback = $backtopage;
  340. } elseif (getDolGlobalString('PROJECT_URL_REDIRECT_LEAD')) {
  341. $urlback = $conf->global->PROJECT_URL_REDIRECT_LEAD;
  342. // TODO Make replacement of __AMOUNT__, etc...
  343. } else {
  344. $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken();
  345. }
  346. if (!empty($entity)) {
  347. $urlback .= '&entity='.$entity;
  348. }
  349. dol_syslog("project lead ".$proj->ref." has been created, we redirect to ".$urlback);
  350. } else {
  351. $error++;
  352. $errmsg .= $proj->error.'<br>'.join('<br>', $proj->errors);
  353. }
  354. } else {
  355. setEventMessage($errmsg, 'errors');
  356. }
  357. }
  358. if (!$error) {
  359. $db->commit();
  360. Header("Location: ".$urlback);
  361. exit;
  362. } else {
  363. $db->rollback();
  364. }
  365. }
  366. // Action called after a submitted was send and member created successfully
  367. // backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url.
  368. if (empty($reshook) && $action == 'added') {
  369. llxHeaderVierge($langs->trans("NewLeadForm"));
  370. // Si on a pas ete redirige
  371. print '<br><br>';
  372. print '<div class="center">';
  373. print $langs->trans("NewLeadbyWeb");
  374. print '</div>';
  375. llxFooterVierge();
  376. exit;
  377. }
  378. /*
  379. * View
  380. */
  381. $form = new Form($db);
  382. $formcompany = new FormCompany($db);
  383. $extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes and labels
  384. llxHeaderVierge($langs->trans("NewContact"));
  385. print load_fiche_titre($langs->trans("NewContact"), '', '', 0, 0, 'center');
  386. print '<div align="center">';
  387. print '<div id="divsubscribe">';
  388. print '<div class="center subscriptionformhelptext opacitymedium justify">';
  389. if (getDolGlobalString('PROJECT_NEWFORM_TEXT')) {
  390. print $langs->trans($conf->global->PROJECT_NEWFORM_TEXT)."<br>\n";
  391. } else {
  392. print $langs->trans("FormForNewLeadDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL"))."<br>\n";
  393. }
  394. print '</div>';
  395. dol_htmloutput_errors($errmsg);
  396. // Print form
  397. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="newlead">'."\n";
  398. print '<input type="hidden" name="token" value="'.newToken().'" / >';
  399. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  400. print '<input type="hidden" name="action" value="add" />';
  401. print '<br>';
  402. print '<br><span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span><br>';
  403. //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
  404. print dol_get_fiche_head('');
  405. print '<script type="text/javascript">
  406. jQuery(document).ready(function () {
  407. jQuery(document).ready(function () {
  408. jQuery("#selectcountry_id").change(function() {
  409. document.newlead.action.value="create";
  410. document.newlead.submit();
  411. });
  412. });
  413. });
  414. </script>';
  415. print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
  416. // Lastname
  417. print '<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";
  418. // Firstname
  419. print '<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";
  420. // EMail
  421. print '<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";
  422. // Company
  423. print '<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";
  424. // Address
  425. print '<tr><td>'.$langs->trans("Address").'</td><td>'."\n";
  426. print '<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.'">'.dol_escape_htmltag(GETPOST('address', 'restricthtml'), 0, 1).'</textarea></td></tr>'."\n";
  427. // Zip / Town
  428. print '<tr><td>'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td>';
  429. print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1);
  430. print ' / ';
  431. print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
  432. print '</td></tr>';
  433. // Country
  434. print '<tr><td>'.$langs->trans('Country').'</td><td>';
  435. $country_id = GETPOST('country_id');
  436. if (!$country_id && getDolGlobalString('PROJECT_NEWFORM_FORCECOUNTRYCODE')) {
  437. $country_id = getCountry($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
  438. }
  439. if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
  440. $country_code = dol_user_country();
  441. //print $country_code;
  442. if ($country_code) {
  443. $new_country_id = getCountry($country_code, 3, $db, $langs);
  444. //print 'xxx'.$country_code.' - '.$new_country_id;
  445. if ($new_country_id) {
  446. $country_id = $new_country_id;
  447. }
  448. }
  449. }
  450. $country_code = getCountry($country_id, 2, $db, $langs);
  451. print $form->select_country($country_id, 'country_id');
  452. print '</td></tr>';
  453. // State
  454. if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
  455. print '<tr><td>'.$langs->trans('State').'</td><td>';
  456. if ($country_code) {
  457. print $formcompany->select_state(GETPOST("state_id", 'int'), $country_code);
  458. } else {
  459. print '';
  460. }
  461. print '</td></tr>';
  462. }
  463. // Other attributes
  464. $parameters['tpl_context']='public'; // define template context to public
  465. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  466. // Comments
  467. print '<tr>';
  468. print '<td class="tdtop">'.$langs->trans("Message").' <span class="star">*</span></td>';
  469. print '<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>';
  470. print '</tr>'."\n";
  471. print "</table>\n";
  472. print dol_get_fiche_end();
  473. // Save
  474. print '<div class="center">';
  475. print '<input type="submit" value="'.$langs->trans("Submit").'" id="submitsave" class="button">';
  476. if (!empty($backtopage)) {
  477. print ' &nbsp; &nbsp; <input type="submit" value="'.$langs->trans("Cancel").'" id="submitcancel" class="button button-cancel">';
  478. }
  479. print '</div>';
  480. print "</form>\n";
  481. print "<br>";
  482. print '</div></div>';
  483. llxFooterVierge();
  484. $db->close();