new.php 27 KB

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