new.php 33 KB

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