suggestbooth.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. <?php
  2. /* Copyright (C) 2021 Dorian Vabre <dorian.vabre@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/public/project/suggestbooth.php
  19. * \ingroup member
  20. * \brief Example of form to suggest a booth
  21. */
  22. if (!defined('NOLOGIN')) {
  23. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  24. }
  25. if (!defined('NOCSRFCHECK')) {
  26. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  27. }
  28. if (!defined('NOIPCHECK')) {
  29. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  30. }
  31. if (!defined('NOBROWSERNOTIF')) {
  32. define('NOBROWSERNOTIF', '1');
  33. }
  34. // For MultiCompany module.
  35. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  36. // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
  37. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  38. if (is_numeric($entity)) {
  39. define("DOLENTITY", $entity);
  40. }
  41. // Load Dolibarr environment
  42. require '../../main.inc.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  50. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  52. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  53. global $dolibarr_main_url_root;
  54. // Init vars
  55. $errmsg = '';
  56. $num = 0;
  57. $error = 0;
  58. $backtopage = GETPOST('backtopage', 'alpha');
  59. $action = GETPOST('action', 'aZ09');
  60. $eventtype = GETPOST("eventtype");
  61. $email = GETPOST("email");
  62. $societe = GETPOST("societe");
  63. $label = GETPOST("label");
  64. $note = GETPOST("note");
  65. $datestart = dol_mktime(0, 0, 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int'));
  66. $dateend = dol_mktime(23, 59, 59, GETPOST('dateendmonth', 'int'), GETPOST('dateendday', 'int'), GETPOST('dateendyear', 'int'));
  67. $id = GETPOST('id');
  68. $project = new Project($db);
  69. $resultproject = $project->fetch($id);
  70. if ($resultproject < 0) {
  71. $error++;
  72. $errmsg .= $project->error;
  73. }
  74. // Security check
  75. $securekeyreceived = GETPOST('securekey', 'alpha');
  76. $securekeytocompare = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth'.$id, 'md5');
  77. if ($securekeytocompare != $securekeyreceived) {
  78. print $langs->trans('MissingOrBadSecureKey');
  79. exit;
  80. }
  81. // Load translation files
  82. $langs->loadLangs(array("main", "companies", "install", "other", "eventorganization"));
  83. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  84. $hookmanager->initHooks(array('publicnewmembercard', 'globalcard'));
  85. $extrafields = new ExtraFields($db);
  86. $user->loadDefaultValues();
  87. $cactioncomm = new CActionComm($db);
  88. $arrayofconfboothtype = $cactioncomm->liste_array('', 'id', '', 0, "module='booth@eventorganization'");
  89. // Security check
  90. if (empty($conf->eventorganization->enabled)) {
  91. httponly_accessforbidden('Module Event organization not enabled');
  92. }
  93. /**
  94. * Show header for new member
  95. *
  96. * @param string $title Title
  97. * @param string $head Head array
  98. * @param int $disablejs More content into html header
  99. * @param int $disablehead More content into html header
  100. * @param array $arrayofjs Array of complementary js files
  101. * @param array $arrayofcss Array of complementary css files
  102. * @return void
  103. */
  104. function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
  105. {
  106. global $user, $conf, $langs, $mysoc;
  107. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  108. print '<body id="mainbody" class="publicnewmemberform">';
  109. // Define urllogo
  110. $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
  111. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
  112. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
  113. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
  114. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$mysoc->logo);
  115. } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
  116. $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
  117. }
  118. print '<div class="center">';
  119. // Output html code for logo
  120. if ($urllogo) {
  121. print '<div class="backgreypublicpayment">';
  122. print '<div class="logopublicpayment">';
  123. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  124. print '>';
  125. print '</div>';
  126. if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
  127. 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>';
  128. }
  129. print '</div>';
  130. }
  131. if (getDolGlobalString('PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH')) {
  132. print '<div class="backimagepublicsuggestbooth">';
  133. print '<img id="idPROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH" src="' . getDolGlobalString('PROJECT_IMAGE_PUBLIC_SUGGEST_BOOTH').'">';
  134. print '</div>';
  135. }
  136. print '</div>';
  137. print '<div class="divmainbodylarge">';
  138. }
  139. /**
  140. * Show footer for new member
  141. *
  142. * @return void
  143. */
  144. function llxFooterVierge()
  145. {
  146. print '</div>';
  147. printCommonFooter('public');
  148. print "</body>\n";
  149. print "</html>\n";
  150. }
  151. /*
  152. * Actions
  153. */
  154. $parameters = array();
  155. // Note that $action and $object may have been modified by some hooks
  156. $reshook = $hookmanager->executeHooks('doActions', $parameters, $project, $action);
  157. if ($reshook < 0) {
  158. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  159. }
  160. // Action called when page is submitted
  161. if (empty($reshook) && $action == 'add') {
  162. $error = 0;
  163. $urlback = '';
  164. $db->begin();
  165. if (!GETPOST("lastname")) {
  166. $error++;
  167. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name"))."<br>\n";
  168. }
  169. if (!GETPOST("email")) {
  170. $error++;
  171. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email"))."<br>\n";
  172. }
  173. if (!GETPOST("country_id") && !empty((float) $project->price_booth)) {
  174. $error++;
  175. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Country"))."<br>\n";
  176. }
  177. if (!GETPOST("societe")) {
  178. $error++;
  179. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Societe"))."<br>\n";
  180. }
  181. if (!GETPOST("label")) {
  182. $error++;
  183. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label"))."<br>\n";
  184. }
  185. if (!GETPOST("note")) {
  186. $error++;
  187. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Note"))."<br>\n";
  188. }
  189. if (GETPOST("email") && !isValidEmail(GETPOST("email"))) {
  190. $error++;
  191. $langs->load("errors");
  192. $errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email"))."<br>\n";
  193. }
  194. if (!$error) {
  195. // Getting the thirdparty or creating it
  196. $thirdparty = new Societe($db);
  197. $resultfetchthirdparty = $thirdparty->fetch('', $societe);
  198. if ($resultfetchthirdparty < 0) {
  199. // If an error was found
  200. $error++;
  201. $errmsg .= $thirdparty->error;
  202. $errors = array_merge($errors, $thirdparty->errors);
  203. } elseif ($resultfetchthirdparty == 0) { // No thirdparty found + a payment is expected
  204. // Creation of a new thirdparty
  205. $genericcompanyname = 'Unknown company';
  206. if (!empty($societe)) {
  207. $thirdparty->name = $societe;
  208. } else {
  209. $thirdparty->name = $genericcompanyname;
  210. }
  211. $thirdparty->address = GETPOST("address");
  212. $thirdparty->zip = GETPOST("zipcode");
  213. $thirdparty->town = GETPOST("town");
  214. $thirdparty->client = $thirdparty::PROSPECT;
  215. $thirdparty->fournisseur = 0;
  216. $thirdparty->country_id = GETPOST("country_id", 'int');
  217. $thirdparty->state_id = GETPOST("state_id", 'int');
  218. $thirdparty->email = ($emailcompany ? $emailcompany : $email);
  219. // Load object modCodeTiers
  220. $module = (getDolGlobalString('SOCIETE_CODECLIENT_ADDON') ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
  221. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  222. $module = substr($module, 0, dol_strlen($module) - 4);
  223. }
  224. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  225. foreach ($dirsociete as $dirroot) {
  226. $res = dol_include_once($dirroot.$module.'.php');
  227. if ($res) {
  228. break;
  229. }
  230. }
  231. $modCodeClient = new $module($db);
  232. if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
  233. $tmpcode = $modCodeClient->getNextValue($thirdparty, 0);
  234. }
  235. $thirdparty->code_client = $tmpcode;
  236. $readythirdparty = $thirdparty->create($user);
  237. if ($readythirdparty <0) {
  238. $error++;
  239. $errmsg .= $thirdparty->error;
  240. $errors = array_merge($errors, $thirdparty->errors);
  241. } else {
  242. $thirdparty->country_code = getCountry($thirdparty->country_id, 2, $db, $langs);
  243. $thirdparty->country = getCountry($thirdparty->country_code, 0, $db, $langs);
  244. }
  245. }
  246. // From there we have a thirdparty, now looking for the contact
  247. if (!$error) {
  248. $contact = new Contact($db);
  249. $resultcontact = $contact->fetch('', '', '', $email);
  250. if ($resultcontact<=0) {
  251. // Need to create a contact
  252. $contact->socid = $thirdparty->id;
  253. $contact->lastname = (string) GETPOST("lastname", 'alpha');
  254. $contact->firstname = (string) GETPOST("firstname", 'alpha');
  255. $contact->address = (string) GETPOST("address", 'alpha');
  256. $contact->zip = (string) GETPOST("zipcode", 'alpha');
  257. $contact->town = (string) GETPOST("town", 'alpha');
  258. $contact->country_id = (int) GETPOST("country_id", 'int');
  259. $contact->state_id = (int) GETPOST("state_id", 'int');
  260. $contact->email = $email;
  261. $contact->statut = 1; //Default status to Actif
  262. $resultcreatecontact = $contact->create($user);
  263. if ($resultcreatecontact<0) {
  264. $error++;
  265. $errmsg .= $contact->error;
  266. }
  267. }
  268. }
  269. if (!$error) {
  270. // Adding supplier tag and tag from setup to thirdparty
  271. $category = new Categorie($db);
  272. $resultcategory = $category->fetch($conf->global->EVENTORGANIZATION_CATEG_THIRDPARTY_BOOTH);
  273. if ($resultcategory<=0) {
  274. $error++;
  275. $errmsg .= $category->error;
  276. } else {
  277. $resultsetcategory = $thirdparty->setCategoriesCommon(array($category->id), Categorie::TYPE_CUSTOMER, false);
  278. if ($resultsetcategory < 0) {
  279. $error++;
  280. $errmsg .= $thirdparty->error;
  281. } else {
  282. $thirdparty->fournisseur = 1;
  283. // Load object modCodeFournisseur
  284. $module = (getDolGlobalString('SOCIETE_CODECLIENT_ADDON') ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
  285. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  286. $module = substr($module, 0, dol_strlen($module) - 4);
  287. }
  288. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  289. foreach ($dirsociete as $dirroot) {
  290. $res = dol_include_once($dirroot.$module.'.php');
  291. if ($res) {
  292. break;
  293. }
  294. }
  295. $modCodeFournisseur = new $module();
  296. if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
  297. $tmpcode = $modCodeFournisseur->getNextValue($thirdparty, 1);
  298. }
  299. $thirdparty->code_fournisseur = $tmpcode;
  300. $res = $thirdparty->update(0, $user, 1, 1, 1);
  301. if ($res <= 0) {
  302. $error++;
  303. }
  304. }
  305. }
  306. }
  307. if (!$error) {
  308. // We have the contact and the thirdparty
  309. $conforbooth = new ConferenceOrBooth($db);
  310. $conforbooth->label = $label;
  311. $conforbooth->fk_soc = $thirdparty->id;
  312. $conforbooth->fk_project = $project->id;
  313. $conforbooth->note = $note;
  314. $conforbooth->fk_action = $eventtype;
  315. $conforbooth->datep = $datestart;
  316. $conforbooth->datep2 = $dateend;
  317. $conforbooth->datec = dol_now();
  318. $conforbooth->tms = dol_now();
  319. $conforbooth->ip = getUserRemoteIP();
  320. $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
  321. $now = dol_now();
  322. $minmonthpost = dol_time_plus_duree($now, -1, "m");
  323. // Calculate nb of post for IP
  324. $nb_post_ip = 0;
  325. if ($nb_post_max > 0) { // Calculate only if there is a limit to check
  326. $sql = "SELECT COUNT(ref) as nb_confs";
  327. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
  328. $sql .= " WHERE ip = '".$db->escape($conforbooth->ip)."'";
  329. $sql .= " AND datec > '".$db->idate($minmonthpost)."'";
  330. $resql = $db->query($sql);
  331. if ($resql) {
  332. $num = $db->num_rows($resql);
  333. $i = 0;
  334. while ($i < $num) {
  335. $i++;
  336. $obj = $db->fetch_object($resql);
  337. $nb_post_ip = $obj->nb_confs;
  338. }
  339. }
  340. }
  341. $resultconforbooth = 0;
  342. if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
  343. $error++;
  344. $errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
  345. array_push($conforbooth->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
  346. setEventMessage($errmsg, 'errors');
  347. } else {
  348. $resultconforbooth = $conforbooth->create($user);
  349. }
  350. if ($resultconforbooth<=0) {
  351. $error++;
  352. $errmsg .= $conforbooth->error;
  353. } else {
  354. // Adding the contact to the project
  355. $resultaddcontact = $conforbooth->add_contact($contact->id, 'RESPONSIBLE');
  356. if ($resultaddcontact<0) {
  357. $error++;
  358. $errmsg .= $conforbooth->error;
  359. } else {
  360. // If this is a paying booth, we have to redirect to payment page and create an invoice
  361. if (!empty((float) $project->price_booth)) {
  362. $productforinvoicerow = new Product($db);
  363. $resultprod = $productforinvoicerow->fetch($conf->global->SERVICE_BOOTH_LOCATION);
  364. if ($resultprod < 0) {
  365. $error++;
  366. $errmsg .= $productforinvoicerow->error;
  367. } else {
  368. $facture = new Facture($db);
  369. $facture->type = Facture::TYPE_STANDARD;
  370. $facture->socid = $thirdparty->id;
  371. $facture->paye = 0;
  372. $facture->date = dol_now();
  373. $facture->cond_reglement_id = $contact->cond_reglement_id;
  374. $facture->fk_project = $project->id;
  375. if (empty($facture->cond_reglement_id)) {
  376. $paymenttermstatic = new PaymentTerm($contact->db);
  377. $facture->cond_reglement_id = $paymenttermstatic->getDefaultId();
  378. if (empty($facture->cond_reglement_id)) {
  379. $error++;
  380. $contact->error = 'ErrorNoPaymentTermRECEPFound';
  381. $contact->errors[] = $contact->error;
  382. }
  383. }
  384. $resultfacture = $facture->create($user);
  385. if ($resultfacture <= 0) {
  386. $contact->error = $facture->error;
  387. $contact->errors = $facture->errors;
  388. $error++;
  389. } else {
  390. $db->commit();
  391. $facture->add_object_linked($conforbooth->element, $conforbooth->id);
  392. }
  393. }
  394. if (!$error) {
  395. // Add line to draft invoice
  396. $vattouse = get_default_tva($mysoc, $thirdparty, $productforinvoicerow->id);
  397. $result = $facture->addline($langs->trans("BoothLocationFee", $conforbooth->label, dol_print_date($conforbooth->datep, '%d/%m/%y %H:%M:%S'), dol_print_date($conforbooth->datep2, '%d/%m/%y %H:%M:%S')), (float) $project->price_booth, 1, $vattouse, 0, 0, $productforinvoicerow->id, 0, dol_now(), '', 0, 0, '', 'HT', 0, 1);
  398. if ($result <= 0) {
  399. $contact->error = $facture->error;
  400. $contact->errors = $facture->errors;
  401. $error++;
  402. }
  403. /*if (!$error) {
  404. $valid = true;
  405. $sourcetouse = 'boothlocation';
  406. $reftouse = $facture->id;
  407. $redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source='.$sourcetouse.'&ref='.$reftouse.'&booth='.$conforbooth->id;
  408. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
  409. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
  410. $redirection .= '&securekey='.dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $sourcetouse . $reftouse, 2); // Use the source in the hash to avoid duplicates if the references are identical
  411. } else {
  412. $redirection .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
  413. }
  414. }
  415. Header("Location: ".$redirection);
  416. exit;
  417. }*/
  418. }
  419. } else {
  420. // If no price has been set for the booth, we confirm it as suggested and we update
  421. $conforbooth->status = ConferenceOrBooth::STATUS_SUGGESTED;
  422. $conforbooth->update($user);
  423. }
  424. }
  425. }
  426. }
  427. }
  428. if (!$error) {
  429. $db->commit();
  430. // Sending mail
  431. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  432. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  433. $formmail = new FormMail($db);
  434. // Set output language
  435. $outputlangs = new Translate('', $conf);
  436. $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
  437. // Load traductions files required by page
  438. $outputlangs->loadLangs(array("main", "members", "eventorganization"));
  439. // Get email content from template
  440. $arraydefaultmessage = null;
  441. $labeltouse = getDolGlobalString('EVENTORGANIZATION_TEMPLATE_EMAIL_ASK_BOOTH');
  442. if (!empty($labeltouse)) {
  443. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'conferenceorbooth', $user, $outputlangs, $labeltouse, 1, '');
  444. }
  445. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  446. $subject = $arraydefaultmessage->topic;
  447. $msg = $arraydefaultmessage->content;
  448. }
  449. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
  450. complete_substitutions_array($substitutionarray, $outputlangs, $project);
  451. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  452. $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
  453. $sendto = $thirdparty->email;
  454. $from = $conf->global->MAILING_EMAIL_FROM;
  455. $urlback = $_SERVER["REQUEST_URI"];
  456. $trackid = 'proj'.$project->id;
  457. $ishtml = dol_textishtml($texttosend); // May contain urls
  458. $mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml, '', '', $trackid);
  459. $result = $mailfile->sendfile();
  460. if ($result) {
  461. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  462. } else {
  463. dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
  464. }
  465. $securekeyurl = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth'.$id, 2);
  466. $redirection = $dolibarr_main_url_root.'/public/eventorganization/subscriptionok.php?id='.$id.'&securekey='.$securekeyurl;
  467. Header("Location: ".$redirection);
  468. exit;
  469. } else {
  470. $db->rollback();
  471. }
  472. }
  473. /*
  474. * View
  475. */
  476. $form = new Form($db);
  477. $formcompany = new FormCompany($db);
  478. llxHeaderVierge($langs->trans("NewSuggestionOfBooth"));
  479. print '<div align="center">';
  480. print '<div id="divsubscribe">';
  481. print '<br>';
  482. // Sub banner
  483. print '<div class="center subscriptionformbanner subbanner justify margintoponly paddingtop marginbottomonly padingbottom">';
  484. print load_fiche_titre($langs->trans("NewSuggestionOfBooth"), '', '', 0, 0, 'center');
  485. // Welcome message
  486. print '<span class="opacitymedium">'.$langs->trans("EvntOrgRegistrationWelcomeMessage").'</span>';
  487. print '<br>';
  488. // Title
  489. print '<span class="eventlabel large">'.dol_escape_htmltag($project->title . ' '. $project->label).'</span><br>';
  490. print '</div>';
  491. // Help text
  492. print '<div class="justify subscriptionformhelptext">';
  493. if ($project->date_start_event || $project->date_end_event) {
  494. print '<br><span class="fa fa-calendar pictofixedwidth opacitymedium"></span>';
  495. }
  496. if ($project->date_start_event) {
  497. $format = 'day';
  498. $tmparray = dol_getdate($project->date_start_event, false, '');
  499. if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
  500. $format = 'dayhour';
  501. }
  502. print dol_print_date($project->date_start_event, $format);
  503. }
  504. if ($project->date_start_event && $project->date_end_event) {
  505. print ' - ';
  506. }
  507. if ($project->date_end_event) {
  508. $format = 'day';
  509. $tmparray = dol_getdate($project->date_end_event, false, '');
  510. if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
  511. $format = 'dayhour';
  512. }
  513. print dol_print_date($project->date_end_event, $format);
  514. }
  515. if ($project->date_start_event || $project->date_end_event) {
  516. print '<br>';
  517. }
  518. if ($project->location) {
  519. print '<span class="fa fa-map-marked-alt pictofixedwidth opacitymedium"></span>'.dol_escape_htmltag($project->location).'<br>';
  520. }
  521. if ($project->note_public) {
  522. print '<br><span class="opacitymedium">'.dol_htmlentitiesbr($project->note_public).'</span><br>';
  523. }
  524. print '</div>';
  525. print '<br>';
  526. dol_htmloutput_errors($errmsg, $errors);
  527. // Print form
  528. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="newmember">'."\n";
  529. print '<input type="hidden" name="token" value="'.newToken().'" / >';
  530. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  531. print '<input type="hidden" name="action" value="add" />';
  532. print '<input type="hidden" name="id" value="'.$id.'" />';
  533. print '<input type="hidden" name="securekey" value="'.$securekeyreceived.'" />';
  534. print '<br><span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span><br>';
  535. //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
  536. print dol_get_fiche_head('');
  537. print '<script type="text/javascript">
  538. jQuery(document).ready(function () {
  539. jQuery(document).ready(function () {
  540. jQuery("#selectcountry_id").change(function() {
  541. document.newmember.action.value="create";
  542. document.newmember.submit();
  543. });
  544. });
  545. });
  546. </script>';
  547. print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
  548. // Name
  549. print '<tr><td><label for="lastname">'.$langs->trans("Lastname").'<span class="star">*</span></label></td>';
  550. print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname", 'alpha') ? GETPOST("lastname", 'alpha') : $object->lastname).'" autofocus="autofocus"></td>';
  551. print '</tr>';
  552. // Email
  553. 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')).'"></td></tr>'."\n";
  554. // Company
  555. print '<tr id="trcompany" class="trcompany"><td>'.$langs->trans("Company").'<span class="star">*</span>';
  556. print ' </td><td><input type="text" name="societe" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('societe')).'"></td></tr>'."\n";
  557. // Address
  558. print '<tr><td>'.$langs->trans("Address").'</td><td>'."\n";
  559. print '<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag(GETPOST('address', 'restricthtml'), 0, 1).'</textarea></td></tr>'."\n";
  560. // Zip / Town
  561. print '<tr><td>'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td>';
  562. print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1);
  563. print ' / ';
  564. print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
  565. print '</td></tr>';
  566. // Country
  567. print '<tr><td>'.$langs->trans('Country');
  568. print '<span class="star">*</span>';
  569. print '</td><td>';
  570. $country_id = GETPOST('country_id');
  571. if (!$country_id && getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE')) {
  572. $country_id = getCountry($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
  573. }
  574. if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
  575. $country_code = dol_user_country();
  576. //print $country_code;
  577. if ($country_code) {
  578. $new_country_id = getCountry($country_code, 3, $db, $langs);
  579. //print 'xxx'.$country_code.' - '.$new_country_id;
  580. if ($new_country_id) {
  581. $country_id = $new_country_id;
  582. }
  583. }
  584. }
  585. $country_code = getCountry($country_id, 2, $db, $langs);
  586. print $form->select_country($country_id, 'country_id');
  587. print '</td></tr>';
  588. // State
  589. if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
  590. print '<tr><td>'.$langs->trans('State').'</td><td>';
  591. if ($country_code) {
  592. print $formcompany->select_state(GETPOST("state_id"), $country_code);
  593. } else {
  594. print '';
  595. }
  596. print '</td></tr>';
  597. }
  598. // Type of event
  599. print '<tr><td>'.$langs->trans("Format").'<span class="star">*</span></td>'."\n";
  600. print '<td>'.Form::selectarray('eventtype', $arrayofconfboothtype, $eventtype, 1).'</td>';
  601. // Label
  602. print '<tr><td>'.$langs->trans("LabelOfBooth").'<span class="star">*</span></td>'."\n";
  603. print '</td><td><input type="text" name="label" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>'."\n";
  604. // Note
  605. print '<tr><td>'.$langs->trans("Description").'<span class="star">*</span></td>'."\n";
  606. print '<td><textarea name="note" id="note" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag(GETPOST('note', 'restricthtml'), 0, 1).'</textarea></td></tr>'."\n";
  607. print "</table>\n";
  608. print dol_get_fiche_end();
  609. // Show all action buttons
  610. print '<div class="center">';
  611. print '<br>';
  612. print '<input type="submit" value="'.$langs->trans("SuggestBooth").'" name="suggestbooth" id="suggestbooth" class="button">';
  613. print '</div>';
  614. print '<br><br>';
  615. print "</form>\n";
  616. print "<br>";
  617. print '</div></div>';
  618. llxFooterVierge();
  619. $db->close();