new.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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. * Copyright (C) 2022 Udo Tamm <dev@dolibit.de>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/public/members/new.php
  27. * \ingroup member
  28. * \brief Example of form to add a new member
  29. *
  30. * Note that you can add following constant to change behaviour of page
  31. * MEMBER_NEWFORM_AMOUNT Default amount for auto-subscribe form
  32. * MEMBER_MIN_AMOUNT Minimum amount
  33. * MEMBER_NEWFORM_PAYONLINE Suggest payment with paypal, paybox or stripe
  34. * MEMBER_NEWFORM_DOLIBARRTURNOVER Show field turnover (specific for dolibarr foundation)
  35. * MEMBER_URL_REDIRECT_SUBSCRIPTION Url to redirect once registration form has been submitted (hidden option, by default we just show a message on same page or redirect to the payment page)
  36. * MEMBER_NEWFORM_FORCETYPE Force type of member
  37. * MEMBER_NEWFORM_FORCEMORPHY Force nature of member (mor/phy)
  38. * MEMBER_NEWFORM_FORCECOUNTRYCODE Force country
  39. */
  40. if (!defined('NOLOGIN')) {
  41. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  42. }
  43. if (!defined('NOCSRFCHECK')) {
  44. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  45. }
  46. if (!defined('NOBROWSERNOTIF')) {
  47. define('NOBROWSERNOTIF', '1');
  48. }
  49. if (!defined('NOIPCHECK')) {
  50. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  51. }
  52. // For MultiCompany module.
  53. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  54. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  55. if (is_numeric($entity)) {
  56. define("DOLENTITY", $entity);
  57. }
  58. // Load Dolibarr environment
  59. require '../../main.inc.php';
  60. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  61. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  62. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  63. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  64. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  65. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  66. require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
  67. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  68. // Init vars
  69. $backtopage = GETPOST('backtopage', 'alpha');
  70. $action = GETPOST('action', 'aZ09');
  71. $errmsg = '';
  72. $num = 0;
  73. $error = 0;
  74. // Load translation files
  75. $langs->loadLangs(array("main", "members", "companies", "install", "other"));
  76. // Security check
  77. if (empty($conf->adherent->enabled)) {
  78. httponly_accessforbidden('Module Membership not enabled');
  79. }
  80. if (empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
  81. httponly_accessforbidden("Auto subscription form for public visitors has not been enabled");
  82. }
  83. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  84. $hookmanager->initHooks(array('publicnewmembercard', 'globalcard'));
  85. $extrafields = new ExtraFields($db);
  86. $object = new Adherent($db);
  87. $user->loadDefaultValues();
  88. /**
  89. * Show header for new member
  90. *
  91. * @param string $title Title
  92. * @param string $head Head array
  93. * @param int $disablejs More content into html header
  94. * @param int $disablehead More content into html header
  95. * @param array $arrayofjs Array of complementary js files
  96. * @param array $arrayofcss Array of complementary css files
  97. * @return void
  98. */
  99. function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
  100. {
  101. global $user, $conf, $langs, $mysoc;
  102. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  103. print '<body id="mainbody" class="publicnewmemberform">';
  104. // Define urllogo
  105. $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
  106. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
  107. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
  108. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
  109. $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$mysoc->logo);
  110. } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
  111. $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
  112. }
  113. print '<div class="center">';
  114. // Output html code for logo
  115. if ($urllogo) {
  116. print '<div class="backgreypublicpayment">';
  117. print '<div class="logopublicpayment">';
  118. print '<img id="dolpaymentlogo" src="'.$urllogo.'">';
  119. print '</div>';
  120. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  121. 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>';
  122. }
  123. print '</div>';
  124. }
  125. if (!empty($conf->global->MEMBER_IMAGE_PUBLIC_REGISTRATION)) {
  126. print '<div class="backimagepublicregistration">';
  127. print '<img id="idEVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->MEMBER_IMAGE_PUBLIC_REGISTRATION.'">';
  128. print '</div>';
  129. }
  130. print '</div>';
  131. print '<div class="divmainbodylarge">';
  132. }
  133. /**
  134. * Show footer for new member
  135. *
  136. * @return void
  137. */
  138. function llxFooterVierge()
  139. {
  140. print '</div>';
  141. printCommonFooter('public');
  142. print "</body>\n";
  143. print "</html>\n";
  144. }
  145. /*
  146. * Actions
  147. */
  148. $parameters = array();
  149. // Note that $action and $object may have been modified by some hooks
  150. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  151. if ($reshook < 0) {
  152. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  153. }
  154. // Action called when page is submitted
  155. if (empty($reshook) && $action == 'add') {
  156. $error = 0;
  157. $urlback = '';
  158. $db->begin();
  159. // test if login already exists
  160. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  161. if (!GETPOST('login')) {
  162. $error++;
  163. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"))."<br>\n";
  164. }
  165. $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login = '".$db->escape(GETPOST('login'))."'";
  166. $result = $db->query($sql);
  167. if ($result) {
  168. $num = $db->num_rows($result);
  169. }
  170. if ($num != 0) {
  171. $error++;
  172. $langs->load("errors");
  173. $errmsg .= $langs->trans("ErrorLoginAlreadyExists")."<br>\n";
  174. }
  175. if (!GETPOSTISSET("pass1") || !GETPOSTISSET("pass2") || GETPOST("pass1", 'none') == '' || GETPOST("pass2", 'none') == '' || GETPOST("pass1", 'none') != GETPOST("pass2", 'none')) {
  176. $error++;
  177. $langs->load("errors");
  178. $errmsg .= $langs->trans("ErrorPasswordsMustMatch")."<br>\n";
  179. }
  180. if (!GETPOST('email')) {
  181. $error++;
  182. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("EMail"))."<br>\n";
  183. }
  184. }
  185. if (GETPOST('typeid') <= 0) {
  186. $error++;
  187. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."<br>\n";
  188. }
  189. if (!in_array(GETPOST('morphy'), array('mor', 'phy'))) {
  190. $error++;
  191. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('Nature'))."<br>\n";
  192. }
  193. if (!GETPOST('lastname')) {
  194. $error++;
  195. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
  196. }
  197. if (!GETPOST('firstname')) {
  198. $error++;
  199. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
  200. }
  201. if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && empty(GETPOST('email'))) {
  202. $error++;
  203. $errmsg .= $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Email'))."<br>\n";
  204. } elseif (GETPOST("email") && !isValidEmail(GETPOST("email"))) {
  205. $langs->load('errors');
  206. $error++;
  207. $errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email"))."<br>\n";
  208. }
  209. $birthday = dol_mktime(GETPOST("birthhour", 'int'), GETPOST("birthmin", 'int'), GETPOST("birthsec", 'int'), GETPOST("birthmonth", 'int'), GETPOST("birthday", 'int'), GETPOST("birthyear", 'int'));
  210. if (GETPOST("birthmonth") && empty($birthday)) {
  211. $error++;
  212. $langs->load("errors");
  213. $errmsg .= $langs->trans("ErrorBadDateFormat")."<br>\n";
  214. }
  215. if (!empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER)) {
  216. if (GETPOST("morphy") == 'mor' && GETPOST('budget') <= 0) {
  217. $error++;
  218. $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TurnoverOrBudget"))."<br>\n";
  219. }
  220. }
  221. $public = GETPOSTISSET('public') ? 1 : 0;
  222. if (!$error) {
  223. // E-mail looks OK and login does not exist
  224. $adh = new Adherent($db);
  225. $adh->statut = -1;
  226. $adh->public = $public;
  227. $adh->firstname = GETPOST('firstname');
  228. $adh->lastname = GETPOST('lastname');
  229. $adh->gender = GETPOST('gender');
  230. $adh->civility_id = GETPOST('civility_id');
  231. $adh->societe = GETPOST('societe');
  232. $adh->address = GETPOST('address');
  233. $adh->zip = GETPOST('zipcode');
  234. $adh->town = GETPOST('town');
  235. $adh->email = GETPOST('email');
  236. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  237. $adh->login = GETPOST('login');
  238. $adh->pass = GETPOST('pass1');
  239. }
  240. $adh->photo = GETPOST('photo');
  241. $adh->country_id = getDolGlobalString("MEMBER_NEWFORM_FORCECOUNTRYCODE", GETPOST('country_id', 'int'));
  242. $adh->state_id = GETPOST('state_id', 'int');
  243. $adh->typeid = getDolGlobalString("MEMBER_NEWFORM_FORCETYPE", GETPOST('typeid', 'int'));
  244. $adh->note_private = GETPOST('note_private');
  245. $adh->morphy = getDolGlobalString("MEMBER_NEWFORM_FORCEMORPHY", GETPOST('morphy'));
  246. $adh->birth = $birthday;
  247. $adh->ip = getUserRemoteIP();
  248. $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
  249. $now = dol_now();
  250. $minmonthpost = dol_time_plus_duree($now, -1, "m");
  251. // Calculate nb of post for IP
  252. $nb_post_ip = 0;
  253. if ($nb_post_max > 0) { // Calculate only if there is a limit to check
  254. $sql = "SELECT COUNT(ref) as nb_adh";
  255. $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
  256. $sql .= " WHERE ip = '".$db->escape($adh->ip)."'";
  257. $sql .= " AND datec > '".$db->idate($minmonthpost)."'";
  258. $resql = $db->query($sql);
  259. if ($resql) {
  260. $num = $db->num_rows($resql);
  261. $i = 0;
  262. while ($i < $num) {
  263. $i++;
  264. $obj = $db->fetch_object($resql);
  265. $nb_post_ip = $obj->nb_adh;
  266. }
  267. }
  268. }
  269. // Fill array 'array_options' with data from add form
  270. $extrafields->fetch_name_optionals_label($adh->table_element);
  271. $ret = $extrafields->setOptionalsFromPost(null, $adh);
  272. if ($ret < 0) {
  273. $error++;
  274. $errmsg .= $adh->error;
  275. }
  276. if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
  277. $error++;
  278. $errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
  279. array_push($adh->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
  280. }
  281. if (!$error) {
  282. $result = $adh->create($user);
  283. if ($result > 0) {
  284. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  285. $object = $adh;
  286. $adht = new AdherentType($db);
  287. $adht->fetch($object->typeid);
  288. if ($object->email) {
  289. $subject = '';
  290. $msg = '';
  291. // Send subscription email
  292. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  293. $formmail = new FormMail($db);
  294. // Set output language
  295. $outputlangs = new Translate('', $conf);
  296. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  297. // Load traductions files required by page
  298. $outputlangs->loadLangs(array("main", "members"));
  299. // Get email content from template
  300. $arraydefaultmessage = null;
  301. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_AUTOREGISTER;
  302. if (!empty($labeltouse)) {
  303. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  304. }
  305. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  306. $subject = $arraydefaultmessage->topic;
  307. $msg = $arraydefaultmessage->content;
  308. }
  309. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  310. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  311. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  312. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
  313. if ($subjecttosend && $texttosend) {
  314. $moreinheader = 'X-Dolibarr-Info: send_an_email by public/members/new.php'."\r\n";
  315. $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
  316. }
  317. /*if ($result < 0) {
  318. $error++;
  319. setEventMessages($object->error, $object->errors, 'errors');
  320. }*/
  321. }
  322. // Send email to the foundation to say a new member subscribed with autosubscribe form
  323. if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL) && !empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT) &&
  324. !empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL)) {
  325. // Define link to login card
  326. $appli = constant('DOL_APPLICATION_TITLE');
  327. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  328. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  329. if (preg_match('/\d\.\d/', $appli)) {
  330. if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
  331. $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
  332. }
  333. } else {
  334. $appli .= " ".DOL_VERSION;
  335. }
  336. } else {
  337. $appli .= " ".DOL_VERSION;
  338. }
  339. $to = $adh->makeSubstitution($conf->global->MAIN_INFO_SOCIETE_MAIL);
  340. $from = $conf->global->ADHERENT_MAIL_FROM;
  341. $mailfile = new CMailFile(
  342. '['.$appli.'] '.$conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT,
  343. $to,
  344. $from,
  345. $adh->makeSubstitution($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL),
  346. array(),
  347. array(),
  348. array(),
  349. "",
  350. "",
  351. 0,
  352. -1
  353. );
  354. if (!$mailfile->sendfile()) {
  355. dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR);
  356. }
  357. }
  358. // Auto-create thirdparty on member creation
  359. if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) {
  360. $company = new Societe($db);
  361. $result = $company->create_from_member($adh);
  362. if ($result < 0) {
  363. $error++;
  364. $errmsg .= join('<br>', $company->errors);
  365. }
  366. }
  367. if (!empty($backtopage)) {
  368. $urlback = $backtopage;
  369. } elseif (!empty($conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION)) {
  370. $urlback = $conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION;
  371. // TODO Make replacement of __AMOUNT__, etc...
  372. } else {
  373. $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken();
  374. }
  375. if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE) && $conf->global->MEMBER_NEWFORM_PAYONLINE != '-1') {
  376. if (empty($adht->caneditamount)) { // If edition of amount not allowed
  377. // TODO Check amount is same than the amount required for the type of member or if not defined as the defeault amount into $conf->global->MEMBER_NEWFORM_AMOUNT
  378. // It is not so important because a test is done on return of payment validation.
  379. }
  380. $urlback = getOnlinePaymentUrl(0, 'member', $adh->ref, price2num(GETPOST('amount', 'alpha'), 'MT'), '', 0);
  381. if (GETPOST('email')) {
  382. $urlback .= '&email='.urlencode(GETPOST('email'));
  383. }
  384. if ($conf->global->MEMBER_NEWFORM_PAYONLINE != '-1' && $conf->global->MEMBER_NEWFORM_PAYONLINE != 'all') {
  385. $urlback .= '&paymentmethod='.urlencode($conf->global->MEMBER_NEWFORM_PAYONLINE);
  386. }
  387. } else {
  388. if (!empty($entity)) {
  389. $urlback .= '&entity='.((int) $entity);
  390. }
  391. }
  392. } else {
  393. $error++;
  394. $errmsg .= join('<br>', $adh->errors);
  395. }
  396. }
  397. }
  398. if (!$error) {
  399. $db->commit();
  400. Header("Location: ".$urlback);
  401. exit;
  402. } else {
  403. $db->rollback();
  404. $action = "create";
  405. }
  406. }
  407. // Action called after a submitted was send and member created successfully
  408. // If MEMBER_URL_REDIRECT_SUBSCRIPTION is set to an url, we never go here because a redirect was done to this url. Same if we ask to redirect to the payment page.
  409. // backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url.
  410. if (empty($reshook) && $action == 'added') {
  411. llxHeaderVierge($langs->trans("NewMemberForm"));
  412. // If we have not been redirected
  413. print '<br><br>';
  414. print '<div class="center">';
  415. print $langs->trans("NewMemberbyWeb");
  416. print '</div>';
  417. llxFooterVierge();
  418. exit;
  419. }
  420. /*
  421. * View
  422. */
  423. $form = new Form($db);
  424. $formcompany = new FormCompany($db);
  425. $adht = new AdherentType($db);
  426. $extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes and labels
  427. llxHeaderVierge($langs->trans("NewSubscription"));
  428. print '<br>';
  429. print load_fiche_titre($langs->trans("NewSubscription"), '', '', 0, 0, 'center');
  430. print '<div align="center">';
  431. print '<div id="divsubscribe">';
  432. print '<div class="center subscriptionformhelptext opacitymedium justify">';
  433. if (!empty($conf->global->MEMBER_NEWFORM_TEXT)) {
  434. print $langs->trans($conf->global->MEMBER_NEWFORM_TEXT)."<br>\n";
  435. } else {
  436. print $langs->trans("NewSubscriptionDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL"))."<br>\n";
  437. }
  438. print '</div>';
  439. dol_htmloutput_errors($errmsg);
  440. dol_htmloutput_events();
  441. // Print form
  442. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="newmember">'."\n";
  443. print '<input type="hidden" name="token" value="'.newToken().'" / >';
  444. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  445. if (!empty($conf->global->MEMBER_SKIP_TABLE) || !empty($conf->global->MEMBER_NEWFORM_FORCETYPE) || $action == 'create') {
  446. print '<input type="hidden" name="action" value="add" />';
  447. print '<br>';
  448. print '<br><span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span><br>';
  449. //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
  450. print dol_get_fiche_head('');
  451. print '<script type="text/javascript">
  452. jQuery(document).ready(function () {
  453. jQuery(document).ready(function () {
  454. function initmorphy()
  455. {
  456. console.log("Call initmorphy");
  457. if (jQuery("#morphy").val() == \'phy\') {
  458. jQuery("#trcompany").hide();
  459. }
  460. if (jQuery("#morphy").val() == \'mor\') {
  461. jQuery("#trcompany").show();
  462. }
  463. };
  464. initmorphy();
  465. jQuery("#morphy").change(function() {
  466. initmorphy();
  467. });
  468. jQuery("#selectcountry_id").change(function() {
  469. document.newmember.action.value="create";
  470. document.newmember.submit();
  471. });
  472. jQuery("#typeid").change(function() {
  473. document.newmember.action.value="create";
  474. document.newmember.submit();
  475. });
  476. });
  477. });
  478. </script>';
  479. print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
  480. // Type
  481. if (empty($conf->global->MEMBER_NEWFORM_FORCETYPE)) {
  482. $listoftype = $adht->liste_array();
  483. $tmp = array_keys($listoftype);
  484. $defaulttype = '';
  485. $isempty = 1;
  486. if (count($listoftype) == 1) {
  487. $defaulttype = $tmp[0];
  488. $isempty = 0;
  489. }
  490. print '<tr><td class="titlefield">'.$langs->trans("Type").' <span style="color: red">*</span></td><td>';
  491. print $form->selectarray("typeid", $adht->liste_array(1), GETPOST('typeid') ? GETPOST('typeid') : $defaulttype, $isempty);
  492. print '</td></tr>'."\n";
  493. } else {
  494. $adht->fetch($conf->global->MEMBER_NEWFORM_FORCETYPE);
  495. print '<input type="hidden" id="typeid" name="typeid" value="'.$conf->global->MEMBER_NEWFORM_FORCETYPE.'">';
  496. }
  497. // Moral/Physic attribute
  498. $morphys["phy"] = $langs->trans("Physical");
  499. $morphys["mor"] = $langs->trans("Moral");
  500. if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY)) {
  501. print '<tr class="morphy"><td class="titlefield">'.$langs->trans('MemberNature').' <span style="color: red">*</span></td><td>'."\n";
  502. print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1);
  503. print '</td></tr>'."\n";
  504. } else {
  505. //print $morphys[$conf->global->MEMBER_NEWFORM_FORCEMORPHY];
  506. print '<input type="hidden" id="morphy" name="morphy" value="'.$conf->global->MEMBER_NEWFORM_FORCEMORPHY.'">';
  507. }
  508. // Company // TODO : optional hide
  509. print '<tr id="trcompany" class="trcompany"><td>'.$langs->trans("Company").'</td><td>';
  510. print img_picto('', 'company', 'class="pictofixedwidth"');
  511. print '<input type="text" name="societe" class="minwidth150 widthcentpercentminusx" value="'.dol_escape_htmltag(GETPOST('societe')).'"></td></tr>'."\n";
  512. // Title
  513. print '<tr><td class="titlefield">'.$langs->trans('UserTitle').'</td><td>';
  514. print $formcompany->select_civility(GETPOST('civility_id'), 'civility_id').'</td></tr>'."\n";
  515. // Lastname
  516. 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";
  517. // Firstname
  518. 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";
  519. // EMail
  520. print '<tr><td>'.$langs->trans("Email").(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? ' <span style="color:red;">*</span>' : '').'</td><td>';
  521. //print img_picto('', 'email', 'class="pictofixedwidth"');
  522. print '<input type="text" name="email" maxlength="255" class="minwidth200" value="'.dol_escape_htmltag(GETPOST('email')).'"></td></tr>'."\n";
  523. // Login
  524. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  525. print '<tr><td>'.$langs->trans("Login").' <span style="color: red">*</span></td><td><input type="text" name="login" maxlength="50" class="minwidth100"value="'.dol_escape_htmltag(GETPOST('login')).'"></td></tr>'."\n";
  526. print '<tr><td>'.$langs->trans("Password").' <span style="color: red">*</span></td><td><input type="password" maxlength="128" name="pass1" class="minwidth100" value="'.dol_escape_htmltag(GETPOST("pass1", "none", 2)).'"></td></tr>'."\n";
  527. print '<tr><td>'.$langs->trans("PasswordRetype").' <span style="color: red">*</span></td><td><input type="password" maxlength="128" name="pass2" class="minwidth100" value="'.dol_escape_htmltag(GETPOST("pass2", "none", 2)).'"></td></tr>'."\n";
  528. }
  529. // Gender
  530. print '<tr><td>'.$langs->trans("Gender").'</td>';
  531. print '<td>';
  532. $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
  533. print $form->selectarray('gender', $arraygender, GETPOST('gender', 'alphanohtml'), 1, 0, 0, '', 0, 0, 0, '', '', 1);
  534. print '</td></tr>';
  535. // Address
  536. print '<tr><td>'.$langs->trans("Address").'</td><td>'."\n";
  537. 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";
  538. // Zip / Town
  539. print '<tr><td>'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td>';
  540. print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 1, '', 'width75');
  541. print ' / ';
  542. print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
  543. print '</td></tr>';
  544. // Country
  545. print '<tr><td>'.$langs->trans('Country').'</td><td>';
  546. print img_picto('', 'country', 'class="pictofixedwidth"');
  547. $country_id = GETPOST('country_id', 'int');
  548. if (!$country_id && !empty($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE)) {
  549. $country_id = getCountry($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
  550. }
  551. if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
  552. $country_code = dol_user_country();
  553. //print $country_code;
  554. if ($country_code) {
  555. $new_country_id = getCountry($country_code, 3, $db, $langs);
  556. //print 'xxx'.$country_code.' - '.$new_country_id;
  557. if ($new_country_id) {
  558. $country_id = $new_country_id;
  559. }
  560. }
  561. }
  562. $country_code = getCountry($country_id, 2, $db, $langs);
  563. print $form->select_country($country_id, 'country_id');
  564. print '</td></tr>';
  565. // State
  566. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  567. print '<tr><td>'.$langs->trans('State').'</td><td>';
  568. if ($country_code) {
  569. print $formcompany->select_state(GETPOST("state_id"), $country_code);
  570. }
  571. print '</td></tr>';
  572. }
  573. // Birthday
  574. print '<tr id="trbirth" class="trbirth"><td>'.$langs->trans("DateOfBirth").'</td><td>';
  575. print $form->selectDate(!empty($birthday) ? $birthday : "", 'birth', 0, 0, 1, "newmember", 1, 0);
  576. print '</td></tr>'."\n";
  577. // Photo
  578. print '<tr><td>'.$langs->trans("URLPhoto").'</td><td><input type="text" name="photo" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('photo')).'"></td></tr>'."\n";
  579. // Public
  580. print '<tr><td>'.$langs->trans("Public").'</td><td><input type="checkbox" name="public"></td></tr>'."\n";
  581. // Other attributes
  582. $parameters['tpl_context']='public'; // define template context to public
  583. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  584. // Comments
  585. print '<tr>';
  586. print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
  587. 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>';
  588. print '</tr>'."\n";
  589. // Add specific fields used by Dolibarr foundation for example
  590. // TODO Move this into generic feature.
  591. if (!empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER)) {
  592. $arraybudget = array('50'=>'<= 100 000', '100'=>'<= 200 000', '200'=>'<= 500 000', '300'=>'<= 1 500 000', '600'=>'<= 3 000 000', '1000'=>'<= 5 000 000', '2000'=>'5 000 000+');
  593. print '<tr id="trbudget" class="trcompany"><td>'.$langs->trans("TurnoverOrBudget").' <span style="color: red">*</span></td><td>';
  594. print $form->selectarray('budget', $arraybudget, GETPOST('budget'), 1);
  595. print ' € or $';
  596. print '<script type="text/javascript">
  597. jQuery(document).ready(function () {
  598. initturnover();
  599. jQuery("#morphy").click(function() {
  600. initturnover();
  601. });
  602. jQuery("#budget").change(function() {
  603. if (jQuery("#budget").val() > 0) { jQuery(".amount").val(jQuery("#budget").val()); }
  604. else { jQuery("#budget").val(\'\'); }
  605. });
  606. /*jQuery("#typeid").change(function() {
  607. if (jQuery("#typeid").val()==1) { jQuery("#morphy").val(\'mor\'); }
  608. if (jQuery("#typeid").val()==2) { jQuery("#morphy").val(\'phy\'); }
  609. if (jQuery("#typeid").val()==3) { jQuery("#morphy").val(\'mor\'); }
  610. if (jQuery("#typeid").val()==4) { jQuery("#morphy").val(\'mor\'); }
  611. initturnover();
  612. });*/
  613. function initturnover() {
  614. if (jQuery("#morphy").val()==\'phy\') {
  615. jQuery(".amount").val(20);
  616. jQuery("#trbudget").hide();
  617. jQuery("#trcompany").hide();
  618. }
  619. if (jQuery("#morphy").val()==\'mor\') {
  620. jQuery(".amount").val(\'\');
  621. jQuery("#trcompany").show();
  622. jQuery("#trbirth").hide();
  623. jQuery("#trbudget").show();
  624. if (jQuery("#budget").val() > 0) { jQuery(".amount").val(jQuery("#budget").val()); }
  625. else { jQuery("#budget").val(\'\'); }
  626. }
  627. }
  628. });
  629. </script>';
  630. print '</td></tr>'."\n";
  631. }
  632. if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) {
  633. $typeid = $conf->global->MEMBER_NEWFORM_FORCETYPE ? $conf->global->MEMBER_NEWFORM_FORCETYPE : GETPOST('typeid', 'int');
  634. $adht = new AdherentType($db);
  635. $adht->fetch($typeid);
  636. $caneditamount = $adht->caneditamount;
  637. // Set amount for the subscription:
  638. // - First check the amount of the member type.
  639. $amountbytype = $adht->amountByType(1); // Load the array of amount per type
  640. $amount = empty($amountbytype[$typeid]) ? (isset($amount) ? $amount : 0) : $amountbytype[$typeid];
  641. // - If not found, take the default amount only of the user is authorized to edit it
  642. if ($caneditamount && empty($amount) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  643. $amount = $conf->global->MEMBER_NEWFORM_AMOUNT;
  644. }
  645. // - If not set, we accept ot have amount defined as parameter (for backward compatibility).
  646. if (empty($amount)) {
  647. $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : '');
  648. }
  649. // Clean the amount
  650. $amount = price2num($amount);
  651. $showedamount = $amount>0? $amount: 0;
  652. // $conf->global->MEMBER_NEWFORM_PAYONLINE is 'paypal', 'paybox' or 'stripe'
  653. print '<tr><td>'.$langs->trans("Subscription");
  654. if (!empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) {
  655. print ' - <a href="'.$conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO.'" rel="external" target="_blank" rel="noopener noreferrer">'.$langs->trans("SeeHere").'</a>';
  656. }
  657. print '</td><td class="nowrap">';
  658. if (empty($amount) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  659. $amount = $conf->global->MEMBER_NEWFORM_AMOUNT;
  660. }
  661. if ($caneditamount) {
  662. print '<input type="text" name="amount" id="amount" class="flat amount width50" value="'.$showedamount.'">';
  663. print ' '.$langs->trans("Currency".$conf->currency).'<span class="opacitymedium"> – ';
  664. print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)): $langs->trans("AnyAmountWithoutAdvisedAmount");
  665. print '</span>';
  666. } else {
  667. print '<input type="hidden" name="amount" id="amount" class="flat amount" value="'.$showedamount.'">';
  668. print '<input type="text" name="amount" id="amounthidden" class="flat amount width50" disabled value="'.$showedamount.'">';
  669. print ' '.$langs->trans("Currency".$conf->currency);
  670. }
  671. print '</td></tr>';
  672. }
  673. print "</table>\n";
  674. print dol_get_fiche_end();
  675. // Save / Submit
  676. print '<div class="center">';
  677. print '<input type="submit" value="'.$langs->trans("GetMembershipButtonLabel").'" id="submitsave" class="button">';
  678. if (!empty($backtopage)) {
  679. print ' &nbsp; &nbsp; <input type="submit" value="'.$langs->trans("Cancel").'" id="submitcancel" class="button button-cancel">';
  680. }
  681. print '</div>';
  682. print "</form>\n";
  683. print "<br>";
  684. print '</div></div>';
  685. } else { // Show the table of membership types
  686. // Get units
  687. $measuringUnits = new CUnits($db);
  688. $result = $measuringUnits->fetchAll('', '', 0, 0, array('t.active' => 1));
  689. $units = array();
  690. foreach ($measuringUnits->records as $lines)
  691. $units[$lines->short_label] = $langs->trans(ucfirst($lines->label));
  692. $publiccounters = getDolGlobalString("MEMBER_COUNTERS_ARE_PUBLIC");
  693. $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut as status, d.morphy,";
  694. $sql .= " COUNT(a.rowid) AS membercount";
  695. $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
  696. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as a";
  697. $sql .= " ON d.rowid = a.fk_adherent_type AND a.statut > 0";
  698. $sql .= " WHERE d.entity IN (".getEntity('member_type').")";
  699. $sql .= " AND d.statut=1";
  700. $sql .= " GROUP BY d.rowid, d.libelle, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut, d.morphy";
  701. $result = $db->query($sql);
  702. if ($result) {
  703. $num = $db->num_rows($result);
  704. print '<br><div class="div-table-responsive">';
  705. print '<table class="tagtable liste">'."\n";
  706. print '<input type="hidden" name="action" value="create">';
  707. print '<tr class="liste_titre">';
  708. print '<th>'.$langs->trans("Label").'</th>';
  709. print '<th class="center">'.$langs->trans("MembershipDuration").'</th>';
  710. print '<th class="center">'.$langs->trans("Amount").'</th>';
  711. print '<th class="center">'.$langs->trans("MembersNature").'</th>';
  712. print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
  713. if ($publiccounters) print '<th class="center">'.$langs->trans("Members").'</th>';
  714. print '<th class="center">'.$langs->trans("NewSubscription").'</th>';
  715. print "</tr>\n";
  716. $i = 0;
  717. while ($i < $num) {
  718. $objp = $db->fetch_object($result); // Load the member type and information on it
  719. print '<tr class="oddeven">';
  720. print '<td>'.dol_escape_htmltag($objp->label).'</td>';
  721. print '<td class="nowrap">';
  722. $unit = preg_replace("/[^a-zA-Z]+/", "", $objp->duration);
  723. print max(1, intval($objp->duration)).' '.$units[$unit];
  724. print '</td>';
  725. print '<td class="center"><span class="amount nowrap">';
  726. $displayedamount = max(intval($objp->amount), intval(getDolGlobalInt("MEMBER_MIN_AMOUNT")));
  727. $caneditamount = $objp->caneditamount;
  728. if ($objp->subscription) {
  729. if ($displayedamount > 0 || !$caneditamount) {
  730. print $displayedamount.' '.strtoupper($conf->currency);
  731. }
  732. if ($caneditamount && $displayedamount>0) {
  733. print $form->textwithpicto('', $langs->transnoentities("CanEditAmountShortForValues"), 1, 'help', '', 0, 3);
  734. } elseif ($caneditamount) {
  735. print $langs->transnoentities("CanEditAmountShort");
  736. }
  737. } else {
  738. print "–"; // No subscription required
  739. }
  740. print '</span></td>';
  741. print '<td class="center">';
  742. if ($objp->morphy == 'phy') {
  743. print $langs->trans("Physical");
  744. } elseif ($objp->morphy == 'mor') {
  745. print $langs->trans("Moral");
  746. } else {
  747. print $langs->trans("MorAndPhy");
  748. }
  749. print '</td>';
  750. print '<td class="center">'.yn($objp->vote).'</td>';
  751. $membercount = $objp->membercount>0? $objp->membercount: "–";
  752. if ($publiccounters) print '<td class="center">'.$membercount.'</td>';
  753. print '<td class="center"><button class="button button-save reposition" name="typeid" type="submit" name="submit" value="'.$objp->rowid.'">'.$langs->trans("GetMembershipButtonLabel").'</button></td>';
  754. print "</tr>";
  755. $i++;
  756. }
  757. // If no record found
  758. if ($num == 0) {
  759. $colspan = 8;
  760. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  761. }
  762. print "</table>";
  763. print '</div>';
  764. print '</form>';
  765. } else {
  766. dol_print_error($db);
  767. }
  768. }
  769. llxFooterVierge();
  770. $db->close();