new.php 20 KB

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