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