new.php 37 KB

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