new.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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-2019 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  9. * Copyright (C) 2021 Waël Almoman <info@almoman.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/public/partnership/new.php
  26. * \ingroup member
  27. * \brief Example of form to add a new member
  28. */
  29. if (!defined('NOLOGIN')) {
  30. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  31. }
  32. if (!defined('NOCSRFCHECK')) {
  33. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  34. }
  35. if (!defined('NOIPCHECK')) {
  36. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  37. }
  38. if (!defined('NOBROWSERNOTIF')) {
  39. define('NOBROWSERNOTIF', '1');
  40. }
  41. if (!defined('NOIPCHECK')) {
  42. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  43. }
  44. // For MultiCompany module.
  45. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  46. // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
  47. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  48. if (is_numeric($entity)) {
  49. define("DOLENTITY", $entity);
  50. }
  51. // Load Dolibarr environment
  52. require '../../main.inc.php';
  53. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  54. require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
  55. require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership_type.class.php';
  56. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  57. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  58. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  59. // Init vars
  60. $errmsg = '';
  61. $num = 0;
  62. $error = 0;
  63. $backtopage = GETPOST('backtopage', 'alpha');
  64. $action = GETPOST('action', 'aZ09');
  65. // Load translation files
  66. $langs->loadLangs(array("main", "members", "partnership", "companies", "install", "other"));
  67. // Security check
  68. if (empty($conf->partnership->enabled)) {
  69. httponly_accessforbidden('Module Partnership not enabled');
  70. }
  71. if (empty($conf->global->PARTNERSHIP_ENABLE_PUBLIC)) {
  72. httponly_accessforbidden("Auto subscription form for public visitors has not been enabled");
  73. }
  74. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  75. $hookmanager->initHooks(array('publicnewpartnershipcard', 'globalcard'));
  76. $extrafields = new ExtraFields($db);
  77. $object = new Partnership($db);
  78. $user->loadDefaultValues();
  79. /**
  80. * Show header for new partnership
  81. *
  82. * @param string $title Title
  83. * @param string $head Head array
  84. * @param int $disablejs More content into html header
  85. * @param int $disablehead More content into html header
  86. * @param array $arrayofjs Array of complementary js files
  87. * @param array $arrayofcss Array of complementary css files
  88. * @return void
  89. */
  90. function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
  91. {
  92. global $user, $conf, $langs, $mysoc;
  93. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  94. print '<body id="mainbody" class="publicnewmemberform">';
  95. // Define urllogo
  96. $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
  97. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
  98. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
  99. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
  100. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$mysoc->logo);
  101. } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
  102. $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
  103. }
  104. print '<div class="center">';
  105. // Output html code for logo
  106. if ($urllogo) {
  107. print '<div class="backgreypublicpayment">';
  108. print '<div class="logopublicpayment">';
  109. print '<img id="dolpaymentlogo" src="'.$urllogo.'">';
  110. print '</div>';
  111. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  112. 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>';
  113. }
  114. print '</div>';
  115. }
  116. if (!empty($conf->global->PARTNERSHIP_IMAGE_PUBLIC_REGISTRATION)) {
  117. print '<div class="backimagepublicregistration">';
  118. print '<img id="idPARTNERSHIP_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->PARTNERSHIP_IMAGE_PUBLIC_REGISTRATION.'">';
  119. print '</div>';
  120. }
  121. print '</div>';
  122. print '<div class="divmainbodylarge">';
  123. }
  124. /**
  125. * Show footer for new member
  126. *
  127. * @return void
  128. */
  129. function llxFooterVierge()
  130. {
  131. print '</div>';
  132. printCommonFooter('public');
  133. print "</body>\n";
  134. print "</html>\n";
  135. }
  136. /*
  137. * Actions
  138. */
  139. $parameters = array();
  140. // Note that $action and $object may have been modified by some hooks
  141. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  142. if ($reshook < 0) {
  143. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  144. }
  145. // Action called when page is submitted
  146. if (empty($reshook) && $action == 'add') {
  147. $error = 0;
  148. $urlback = '';
  149. $db->begin();
  150. if (GETPOST('partnershiptype', 'int') <= 0) {
  151. $error++;
  152. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."<br>\n";
  153. }
  154. if (!GETPOST('societe')) {
  155. $error++;
  156. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("societe"))."<br>\n";
  157. }
  158. if (!GETPOST('lastname')) {
  159. $error++;
  160. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
  161. }
  162. if (!GETPOST('firstname')) {
  163. $error++;
  164. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
  165. }
  166. if (empty(GETPOST('email'))) {
  167. $error++;
  168. $errmsg .= $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Email'))."<br>\n";
  169. } elseif (GETPOST("email") && !isValidEmail(GETPOST("email"))) {
  170. $langs->load('errors');
  171. $error++;
  172. $errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email"))."<br>\n";
  173. }
  174. $public = GETPOSTISSET('public') ? 1 : 0;
  175. if (!$error) {
  176. $partnership = new Partnership($db);
  177. // We try to find the thirdparty or the member
  178. if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') {
  179. $partnership->fk_member = 0;
  180. } elseif (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'member') {
  181. $partnership->fk_soc = 0;
  182. }
  183. $partnership->status = 0;
  184. $partnership->note_private = GETPOST('note_private');
  185. $partnership->date_creation = dol_now();
  186. $partnership->date_partnership_start = dol_now();
  187. $partnership->fk_user_creat = 0;
  188. $partnership->fk_type = GETPOST('partnershiptype', 'int');
  189. //$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int');
  190. $partnership->ip = getUserRemoteIP();
  191. $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
  192. $now = dol_now();
  193. $minmonthpost = dol_time_plus_duree($now, -1, "m");
  194. // Calculate nb of post for IP
  195. $nb_post_ip = 0;
  196. if ($nb_post_max > 0) { // Calculate only if there is a limit to check
  197. $sql = "SELECT COUNT(ref) as nb_partnerships";
  198. $sql .= " FROM ".MAIN_DB_PREFIX."partnership";
  199. $sql .= " WHERE ip = '".$db->escape($partnership->ip)."'";
  200. $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
  201. $resql = $db->query($sql);
  202. if ($resql) {
  203. $num = $db->num_rows($resql);
  204. $i = 0;
  205. while ($i < $num) {
  206. $i++;
  207. $obj = $db->fetch_object($resql);
  208. $nb_post_ip = $obj->nb_partnerships;
  209. }
  210. }
  211. }
  212. // test if societe already exist
  213. $company = new Societe($db);
  214. $result = $company->fetch(0, GETPOST('societe'));
  215. if ($result == 0) { // si il ya pas d'entree sur le nom on teste l'email
  216. $result1 = $company->fetch(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, GETPOST('email'));
  217. if ($result1 > 0) {
  218. $error++;
  219. $errmsg = $langs->trans("EmailAlreadyExistsPleaseRewriteYourCompanyName");
  220. } else {
  221. //create thirdparty
  222. $company = new Societe($db);
  223. $company->name = GETPOST('societe');
  224. $company->address = GETPOST('address');
  225. $company->zip = GETPOST('zipcode');
  226. $company->town = GETPOST('town');
  227. $company->email = GETPOST('email');
  228. $company->url = GETPOST('url');
  229. $company->country_id = GETPOST('country_id', 'int');
  230. $company->state_id = GETPOST('state_id', 'int');
  231. $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname'));
  232. $resultat=$company->create($user);
  233. if ($resultat < 0) {
  234. $error++;
  235. $errmsg .= join('<br>', $company->errors);
  236. }
  237. $partnership->fk_soc = $company->id;
  238. }
  239. } elseif ($result == -2) {
  240. $error++;
  241. $errmsg = $langs->trans("TwoRecordsOfCompanyName");
  242. } else {
  243. $partnership->fk_soc = $company->id;
  244. // update thirdparty fields
  245. if (empty($company->address)) {
  246. $company->address = GETPOST('address');
  247. }
  248. if (empty($company->zip)) {
  249. $company->zip = GETPOST('zipcode');
  250. }
  251. if (empty($company->town)) {
  252. $company->town = GETPOST('town');
  253. }
  254. if (empty($company->country_id)) {
  255. $company->country_id = GETPOST('country_id', 'int');
  256. }
  257. if (empty($company->email)) {
  258. $company->email = GETPOST('email');
  259. }
  260. if (empty($company->url)) {
  261. $company->url = GETPOST('url');
  262. }
  263. if (empty($company->state_id)) {
  264. $company->state_id = GETPOST('state_id', 'int');
  265. }
  266. if (empty($company->name_alias)) {
  267. $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname'));
  268. }
  269. $company->update(0);
  270. }
  271. // Fill array 'array_options' with data from add form
  272. $extrafields->fetch_name_optionals_label($partnership->table_element);
  273. $ret = $extrafields->setOptionalsFromPost(null, $partnership);
  274. if ($ret < 0) {
  275. $error++;
  276. }
  277. if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
  278. $error++;
  279. $errmsg = $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
  280. array_push($partnership->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
  281. }
  282. if (!$error) {
  283. $result = $partnership->create($user);
  284. if ($result > 0) {
  285. /*
  286. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  287. $object = $partnership;
  288. $partnershipt = new PartnershipType($db);
  289. $partnershipt->fetch($object->typeid);
  290. if ($object->email) {
  291. $subject = '';
  292. $msg = '';
  293. // Send subscription email
  294. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  295. $formmail = new FormMail($db);
  296. // Set output language
  297. $outputlangs = new Translate('', $conf);
  298. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  299. // Load traductions files required by page
  300. $outputlangs->loadLangs(array("main", "members"));
  301. // Get email content from template
  302. $arraydefaultmessage = null;
  303. $labeltouse = $conf->global->PARTNERSHIP_EMAIL_TEMPLATE_AUTOREGISTER;
  304. if (!empty($labeltouse)) {
  305. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  306. }
  307. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  308. $subject = $arraydefaultmessage->topic;
  309. $msg = $arraydefaultmessage->content;
  310. }
  311. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  312. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  313. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  314. $texttosend = make_substitutions(dol_concatdesc($msg, $partnershipt->getMailOnValid()), $substitutionarray, $outputlangs);
  315. if ($subjecttosend && $texttosend) {
  316. $moreinheader = 'X-Dolibarr-Info: send_an_email by public/members/new.php'."\r\n";
  317. $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
  318. }
  319. }
  320. // Send email to the foundation to say a new member subscribed with autosubscribe form
  321. /*
  322. if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') && !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL_SUBJECT) &&
  323. !empty($conf->global->PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL)) {
  324. // Define link to login card
  325. $appli = constant('DOL_APPLICATION_TITLE');
  326. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  327. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  328. if (preg_match('/\d\.\d/', $appli)) {
  329. if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
  330. $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
  331. }
  332. } else {
  333. $appli .= " ".DOL_VERSION;
  334. }
  335. } else {
  336. $appli .= " ".DOL_VERSION;
  337. }
  338. $to = $partnership->makeSubstitution(getDolGlobalString('MAIN_INFO_SOCIETE_MAIL'));
  339. $from = getDolGlobalString('PARTNERSHIP_MAIL_FROM');
  340. $mailfile = new CMailFile(
  341. '['.$appli.'] '.getDolGlobalString('PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL_SUBJECT', 'Partnership request'),
  342. $to,
  343. $from,
  344. $partnership->makeSubstitution(getDolGlobalString('PARTNERSHIP_AUTOREGISTER_NOTIF_MAIL')),
  345. array(),
  346. array(),
  347. array(),
  348. "",
  349. "",
  350. 0,
  351. -1
  352. );
  353. if (!$mailfile->sendfile()) {
  354. dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR);
  355. }
  356. }*/
  357. if (!empty($backtopage)) {
  358. $urlback = $backtopage;
  359. } elseif (!empty($conf->global->PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION)) {
  360. $urlback = $conf->global->PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION;
  361. // TODO Make replacement of __AMOUNT__, etc...
  362. } else {
  363. $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken();
  364. }
  365. /*
  366. if (!empty($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE) && $conf->global->PARTNERSHIP_NEWFORM_PAYONLINE != '-1') {
  367. if ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'all') {
  368. $urlback = DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref);
  369. if (price2num(GETPOST('amount', 'alpha'))) {
  370. $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha'));
  371. }
  372. if (GETPOST('email')) {
  373. $urlback .= '&email='.urlencode(GETPOST('email'));
  374. }
  375. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
  376. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
  377. $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2));
  378. } else {
  379. $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
  380. }
  381. }
  382. } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'paybox') {
  383. $urlback = DOL_MAIN_URL_ROOT.'/public/paybox/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref);
  384. if (price2num(GETPOST('amount', 'alpha'))) {
  385. $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha'));
  386. }
  387. if (GETPOST('email')) {
  388. $urlback .= '&email='.urlencode(GETPOST('email'));
  389. }
  390. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
  391. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
  392. $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2));
  393. } else {
  394. $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
  395. }
  396. }
  397. } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'paypal') {
  398. $urlback = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.urlencode($partnership->ref);
  399. if (price2num(GETPOST('amount', 'alpha'))) {
  400. $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha'));
  401. }
  402. if (GETPOST('email')) {
  403. $urlback .= '&email='.urlencode(GETPOST('email'));
  404. }
  405. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
  406. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
  407. $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2));
  408. } else {
  409. $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
  410. }
  411. }
  412. } elseif ($conf->global->PARTNERSHIP_NEWFORM_PAYONLINE == 'stripe') {
  413. $urlback = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?from=partnershipnewform&source=membersubscription&ref='.$partnership->ref;
  414. if (price2num(GETPOST('amount', 'alpha'))) {
  415. $urlback .= '&amount='.price2num(GETPOST('amount', 'alpha'));
  416. }
  417. if (GETPOST('email')) {
  418. $urlback .= '&email='.urlencode(GETPOST('email'));
  419. }
  420. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
  421. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
  422. $urlback .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$partnership->ref, 2));
  423. } else {
  424. $urlback .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
  425. }
  426. }
  427. } else {
  428. dol_print_error('', "Autosubscribe form is setup to ask an online payment for a not managed online payment");
  429. exit;
  430. }
  431. }*/
  432. if (!empty($entity)) {
  433. $urlback .= '&entity='.$entity;
  434. }
  435. dol_syslog("partnership ".$partnership->ref." was created, we redirect to ".$urlback);
  436. } else {
  437. $error++;
  438. $errmsg .= join('<br>', $partnership->errors);
  439. }
  440. } else {
  441. setEventMessage($errmsg, 'errors');
  442. }
  443. }
  444. if (!$error) {
  445. $db->commit();
  446. Header("Location: ".$urlback);
  447. exit;
  448. } else {
  449. $db->rollback();
  450. }
  451. }
  452. // Action called after a submitted was send and member created successfully
  453. // If PARTNERSHIP_URL_REDIRECT_SUBSCRIPTION is set to url we never go here because a redirect was done to this url.
  454. // backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url.
  455. if (empty($reshook) && $action == 'added') {
  456. llxHeaderVierge($langs->trans("NewPartnershipForm"));
  457. // Si on a pas ete redirige
  458. print '<br><br>';
  459. print '<div class="center">';
  460. print $langs->trans("NewPartnershipbyWeb");
  461. print '</div>';
  462. llxFooterVierge();
  463. exit;
  464. }
  465. /*
  466. * View
  467. */
  468. $form = new Form($db);
  469. $formcompany = new FormCompany($db);
  470. $extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes and labels
  471. llxHeaderVierge($langs->trans("NewPartnershipRequest"));
  472. print '<br>';
  473. print load_fiche_titre($langs->trans("NewPartnershipRequest"), '', '', 0, 0, 'center');
  474. print '<div align="center">';
  475. print '<div id="divsubscribe">';
  476. print '<div class="center subscriptionformhelptext opacitymedium justify">';
  477. if (!empty($conf->global->PARTNERSHIP_NEWFORM_TEXT)) {
  478. print $langs->trans($conf->global->PARTNERSHIP_NEWFORM_TEXT)."<br>\n";
  479. } else {
  480. print $langs->trans("NewPartnershipRequestDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL"))."<br>\n";
  481. }
  482. print '</div>';
  483. dol_htmloutput_errors($errmsg);
  484. // Print form
  485. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="newmember">'."\n";
  486. print '<input type="hidden" name="token" value="'.newToken().'" / >';
  487. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  488. print '<input type="hidden" name="action" value="add" />';
  489. print '<br>';
  490. print '<br><span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span><br>';
  491. //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
  492. print dol_get_fiche_head('');
  493. print '<script type="text/javascript">
  494. jQuery(document).ready(function () {
  495. jQuery(document).ready(function () {
  496. jQuery("#selectcountry_id").change(function() {
  497. document.newmember.action.value="create";
  498. document.newmember.submit();
  499. });
  500. });
  501. });
  502. </script>';
  503. // Type
  504. $partnershiptype = new PartnershipType($db);
  505. $listofpartnershipobj = $partnershiptype->fetchAll('', '', 1000, 0, array('active'=>1));
  506. $listofpartnership = array();
  507. foreach ($listofpartnershipobj as $partnershipobj) {
  508. $listofpartnership[$partnershipobj->id] = $partnershipobj->label;
  509. }
  510. if (getDolGlobalString('PARTNERSHIP_NEWFORM_FORCETYPE')) {
  511. print $listofpartnership[$conf->global->PARTNERSHIP_NEWFORM_FORCETYPE];
  512. print '<input type="hidden" id="partnershiptype" name="partnershiptype" value="'.$conf->global->PARTNERSHIP_NEWFORM_FORCETYPE.'">';
  513. }
  514. print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
  515. if (!getDolGlobalString('PARTNERSHIP_NEWFORM_FORCETYPE')) {
  516. print '<tr class="morphy"><td>'.$langs->trans('PartnershipType').' <span style="color: red">*</span></td><td>'."\n";
  517. print $form->selectarray("partnershiptype", $listofpartnership, GETPOSTISSET('partnershiptype') ? GETPOST('partnershiptype', 'int') : 'ifone', 1);
  518. print '</td></tr>'."\n";
  519. }
  520. // Company
  521. print '<tr id="trcompany" class="trcompany"><td>'.$langs->trans("Company").' <span style="color:red;">*</span></td><td>';
  522. print img_picto('', 'company', 'class="pictofixedwidth"');
  523. print '<input type="text" name="societe" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('societe')).'"></td></tr>'."\n";
  524. // Lastname
  525. 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')).'"></td></tr>'."\n";
  526. // Firstname
  527. 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')).'"></td></tr>'."\n";
  528. // EMail
  529. print '<tr><td>'.$langs->trans("Email").' <span style="color:red;">*</span></td><td>';
  530. //print img_picto('', 'email', 'class="pictofixedwidth"');
  531. print '<input type="text" name="email" maxlength="255" class="minwidth200" value="'.dol_escape_htmltag(GETPOST('email')).'"></td></tr>'."\n";
  532. // Url
  533. print '<tr><td>'.$langs->trans("Url").' <span style="color:red;">*</span></td><td>';
  534. print '<input type="text" name="url" maxlength="255" class="minwidth200" value="'.dol_escape_htmltag(GETPOST('url')).'">';
  535. if (getDolGlobalString('PARTNERSHIP_BACKLINKS_TO_CHECK')) {
  536. $listofkeytocheck = explode('|', getDolGlobalString('PARTNERSHIP_BACKLINKS_TO_CHECK'));
  537. $i = 0;
  538. $s = '';
  539. foreach ($listofkeytocheck as $val) {
  540. $i++;
  541. $s .= ($s ? ($i == count($listofkeytocheck) ? ' '.$langs->trans("or").' ' : ', ') : '').$val;
  542. }
  543. print '<br><span class="opacitymedium small">'.$langs->trans("ThisUrlMustContainsAtLeastOneLinkToWebsite", $s).'</small>';
  544. }
  545. print '</td></tr>'."\n";
  546. // Address
  547. print '<tr><td>'.$langs->trans("Address").'</td><td>'."\n";
  548. 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";
  549. // Zip / Town
  550. print '<tr><td>'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td>';
  551. print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1);
  552. print ' / ';
  553. print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
  554. print '</td></tr>';
  555. // Country
  556. print '<tr><td>'.$langs->trans('Country').'</td><td>';
  557. print img_picto('', 'country', 'class="pictofixedwidth"');
  558. $country_id = GETPOST('country_id', 'int');
  559. if (!$country_id && !empty($conf->global->PARTNERSHIP_NEWFORM_FORCECOUNTRYCODE)) {
  560. $country_id = getCountry($conf->global->PARTNERSHIP_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
  561. }
  562. if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
  563. $country_code = dol_user_country();
  564. //print $country_code;
  565. if ($country_code) {
  566. $new_country_id = getCountry($country_code, 3, $db, $langs);
  567. //print 'xxx'.$country_code.' - '.$new_country_id;
  568. if ($new_country_id) {
  569. $country_id = $new_country_id;
  570. }
  571. }
  572. }
  573. $country_code = getCountry($country_id, 2, $db, $langs);
  574. print $form->select_country($country_id, 'country_id');
  575. print '</td></tr>';
  576. // State
  577. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  578. print '<tr><td>'.$langs->trans('State').'</td><td>';
  579. if ($country_code) {
  580. print $formcompany->select_state(GETPOST("state_id"), $country_code);
  581. }
  582. print '</td></tr>';
  583. }
  584. // Logo
  585. //print '<tr><td>'.$langs->trans("URLPhoto").'</td><td><input type="text" name="photo" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('photo')).'"></td></tr>'."\n";
  586. // Other attributes
  587. $parameters['tdclass']='titlefieldauto';
  588. $parameters['tpl_context']='public'; // define template context to public
  589. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  590. // Comments
  591. print '<tr>';
  592. print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
  593. print '<td class="tdtop"><textarea name="note_private" id="note_private" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag(GETPOST('note_private', 'restricthtml'), 0, 1).'</textarea></td>';
  594. print '</tr>'."\n";
  595. print "</table>\n";
  596. print dol_get_fiche_end();
  597. // Save
  598. print '<div class="center">';
  599. print '<input type="submit" value="'.$langs->trans("Submit").'" id="submitsave" class="button">';
  600. if (!empty($backtopage)) {
  601. print ' &nbsp; &nbsp; <input type="submit" value="'.$langs->trans("Cancel").'" id="submitcancel" class="button button-cancel">';
  602. }
  603. print '</div>';
  604. print "</form>\n";
  605. print "<br>";
  606. print '</div></div>';
  607. llxFooterVierge();
  608. $db->close();