suggestbooth.php 26 KB

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