new.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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@capnetworks.com>
  6. * Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/public/members/new.php
  23. * \ingroup member
  24. * \brief Example of form to add a new member
  25. *
  26. * Note that you can add following constant to change behaviour of page
  27. * MEMBER_NEWFORM_AMOUNT Default amount for auto-subscribe form
  28. * MEMBER_NEWFORM_EDITAMOUNT Amount can be edited
  29. * MEMBER_NEWFORM_PAYONLINE Suggest payment with paypal, paybox or stripe
  30. * MEMBER_NEWFORM_DOLIBARRTURNOVER Show field turnover (specific for dolibarr foundation)
  31. * MEMBER_URL_REDIRECT_SUBSCRIPTION Url to redirect once subscribe submitted
  32. * MEMBER_NEWFORM_FORCETYPE Force type of member
  33. * MEMBER_NEWFORM_FORCEMORPHY Force nature of member (mor/phy)
  34. * MEMBER_NEWFORM_FORCECOUNTRYCODE Force country
  35. */
  36. define("NOLOGIN",1); // This means this output page does not require to be logged.
  37. define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
  38. // For MultiCompany module.
  39. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  40. // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
  41. $entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  42. if (is_numeric($entity)) define("DOLENTITY", $entity);
  43. require '../../main.inc.php';
  44. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  49. // Init vars
  50. $errmsg='';
  51. $num=0;
  52. $error=0;
  53. $backtopage=GETPOST('backtopage','alpha');
  54. $action=GETPOST('action','alpha');
  55. // Load translation files
  56. $langs->load("main");
  57. $langs->load("members");
  58. $langs->load("companies");
  59. $langs->load("install");
  60. $langs->load("other");
  61. // Security check
  62. if (empty($conf->adherent->enabled)) accessforbidden('',0,0,1);
  63. if (empty($conf->global->MEMBER_ENABLE_PUBLIC))
  64. {
  65. print $langs->trans("Auto subscription form for public visitors has not been enabled");
  66. exit;
  67. }
  68. $extrafields = new ExtraFields($db);
  69. /**
  70. * Show header for new member
  71. *
  72. * @param string $title Title
  73. * @param string $head Head array
  74. * @param int $disablejs More content into html header
  75. * @param int $disablehead More content into html header
  76. * @param array $arrayofjs Array of complementary js files
  77. * @param array $arrayofcss Array of complementary css files
  78. * @return void
  79. */
  80. function llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='')
  81. {
  82. global $user, $conf, $langs, $mysoc;
  83. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  84. print '<body id="mainbody" class="publicnewmemberform" style="margin-top: 10px;">';
  85. // Print logo
  86. $urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
  87. if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small))
  88. {
  89. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('thumbs/'.$mysoc->logo_small);
  90. }
  91. elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo))
  92. {
  93. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode($mysoc->logo);
  94. $width=128;
  95. }
  96. elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.png'))
  97. {
  98. $urllogo=DOL_URL_ROOT.'/theme/dolibarr_logo.png';
  99. }
  100. print '<div class="center">';
  101. print '<img alt="Logo" id="logosubscribe" title="" src="'.$urllogo.'" />';
  102. print '</div><br>';
  103. print '<div style="margin-left: 50px; margin-right: 50px;">';
  104. }
  105. /**
  106. * Show footer for new member
  107. *
  108. * @return void
  109. */
  110. function llxFooterVierge()
  111. {
  112. print '</div>';
  113. printCommonFooter('public');
  114. print "</body>\n";
  115. print "</html>\n";
  116. }
  117. /*
  118. * Actions
  119. */
  120. // Action called when page is submitted
  121. if ($action == 'add')
  122. {
  123. // test if login already exists
  124. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  125. {
  126. if(! GETPOST('login'))
  127. {
  128. $error+=1;
  129. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Login"))."<br>\n";
  130. }
  131. $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape(GETPOST('login'))."'";
  132. $result = $db->query($sql);
  133. if ($result)
  134. {
  135. $num = $db->num_rows($result);
  136. }
  137. if ($num !=0)
  138. {
  139. $error+=1;
  140. $langs->load("errors");
  141. $errmsg .= $langs->trans("ErrorLoginAlreadyExists")."<br>\n";
  142. }
  143. if (!isset($_POST["pass1"]) || !isset($_POST["pass2"]) || $_POST["pass1"] == '' || $_POST["pass2"] == '' || $_POST["pass1"]!=$_POST["pass2"])
  144. {
  145. $error+=1;
  146. $langs->load("errors");
  147. $errmsg .= $langs->trans("ErrorPasswordsMustMatch")."<br>\n";
  148. }
  149. if (! GETPOST("email"))
  150. {
  151. $error+=1;
  152. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("EMail"))."<br>\n";
  153. }
  154. }
  155. if (GETPOST('type') <= 0)
  156. {
  157. $error+=1;
  158. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"))."<br>\n";
  159. }
  160. if (! in_array(GETPOST('morphy'),array('mor','phy')))
  161. {
  162. $error+=1;
  163. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Nature'))."<br>\n";
  164. }
  165. if (empty($_POST["lastname"]))
  166. {
  167. $error+=1;
  168. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Lastname"))."<br>\n";
  169. }
  170. if (empty($_POST["firstname"]))
  171. {
  172. $error+=1;
  173. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Firstname"))."<br>\n";
  174. }
  175. if (GETPOST("email") && ! isValidEmail(GETPOST("email")))
  176. {
  177. $error+=1;
  178. $langs->load("errors");
  179. $errmsg .= $langs->trans("ErrorBadEMail",GETPOST("email"))."<br>\n";
  180. }
  181. $birthday=dol_mktime($_POST["birthhour"],$_POST["birthmin"],$_POST["birthsec"],$_POST["birthmonth"],$_POST["birthday"],$_POST["birthyear"]);
  182. if ($_POST["birthmonth"] && empty($birthday))
  183. {
  184. $error+=1;
  185. $langs->load("errors");
  186. $errmsg .= $langs->trans("ErrorBadDateFormat")."<br>\n";
  187. }
  188. if (! empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER))
  189. {
  190. if (GETPOST("morphy") == 'mor' && GETPOST('budget') <= 0)
  191. {
  192. $error+=1;
  193. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("TurnoverOrBudget"))."<br>\n";
  194. }
  195. }
  196. if (isset($public)) $public=1;
  197. else $public=0;
  198. if (! $error)
  199. {
  200. // email a peu pres correct et le login n'existe pas
  201. $adh = new Adherent($db);
  202. $adh->statut = -1;
  203. $adh->public = $public;
  204. $adh->firstname = $_POST["firstname"];
  205. $adh->lastname = $_POST["lastname"];
  206. $adh->civility_id = $_POST["civility_id"];
  207. $adh->societe = $_POST["societe"];
  208. $adh->address = $_POST["address"];
  209. $adh->zip = $_POST["zipcode"];
  210. $adh->town = $_POST["town"];
  211. $adh->email = $_POST["email"];
  212. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  213. {
  214. $adh->login = $_POST["login"];
  215. $adh->pass = $_POST["pass1"];
  216. }
  217. $adh->photo = $_POST["photo"];
  218. $adh->country_id = $_POST["country_id"];
  219. $adh->state_id = $_POST["state_id"];
  220. $adh->typeid = $_POST["type"];
  221. $adh->note_private= $_POST["note_private"];
  222. $adh->morphy = $_POST["morphy"];
  223. $adh->birth = $birthday;
  224. // Fill array 'array_options' with data from add form
  225. $extralabels=$extrafields->fetch_name_optionals_label($adh->table_element);
  226. $ret = $extrafields->setOptionalsFromPost($extralabels,$adh);
  227. if ($ret < 0) $error++;
  228. $result=$adh->create($user);
  229. if ($result > 0)
  230. {
  231. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  232. // Send email to say it has been created and will be validated soon...
  233. if (! empty($conf->global->ADHERENT_AUTOREGISTER_MAIL) && ! empty($conf->global->ADHERENT_AUTOREGISTER_MAIL_SUBJECT))
  234. {
  235. $result=$adh->send_an_email($conf->global->ADHERENT_AUTOREGISTER_MAIL,$conf->global->ADHERENT_AUTOREGISTER_MAIL_SUBJECT,array(),array(),array(),"","",0,-1);
  236. }
  237. // Send email to the foundation to say a new member subscribed with autosubscribe form
  238. if (! empty($conf->global->MAIN_INFO_SOCIETE_MAIL) && ! empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT) &&
  239. ! empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL) )
  240. {
  241. $to=$adh->makeSubstitution($conf->global->MAIN_INFO_SOCIETE_MAIL);
  242. $from=$conf->global->ADHERENT_MAIL_FROM;
  243. $mailfile = new CMailFile(
  244. $conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT,
  245. $to,
  246. $from,
  247. $adh->makeSubstitution($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL),
  248. array(),
  249. array(),
  250. array(),
  251. "",
  252. "",
  253. 0,
  254. -1
  255. );
  256. if (! $mailfile->sendfile())
  257. {
  258. dol_syslog($langs->trans("ErrorFailedToSendMail",$from,$to), LOG_ERR);
  259. }
  260. }
  261. if (! empty($backtopage)) $urlback=$backtopage;
  262. else if (! empty($conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION))
  263. {
  264. $urlback=$conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION;
  265. // TODO Make replacement of __AMOUNT__, etc...
  266. }
  267. else $urlback=$_SERVER["PHP_SELF"]."?action=added";
  268. if (! empty($conf->global->MEMBER_NEWFORM_PAYONLINE))
  269. {
  270. if ($conf->global->MEMBER_NEWFORM_PAYONLINE == 'paybox')
  271. {
  272. $urlback=DOL_MAIN_URL_ROOT.'/public/paybox/newpayment.php?from=membernewform&source=membersubscription&ref='.urlencode($adh->ref);
  273. if (price2num(GETPOST('amount'))) $urlback.='&amount='.price2num(GETPOST('amount'));
  274. if (GETPOST('email')) $urlback.='&email='.urlencode(GETPOST('email'));
  275. }
  276. else if ($conf->global->MEMBER_NEWFORM_PAYONLINE == 'paypal')
  277. {
  278. $urlback=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?from=membernewform&source=membersubscription&ref='.urlencode($adh->ref);
  279. if (price2num(GETPOST('amount'))) $urlback.='&amount='.price2num(GETPOST('amount'));
  280. if (GETPOST('email')) $urlback.='&email='.urlencode(GETPOST('email'));
  281. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
  282. {
  283. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  284. {
  285. $urlback.='&securekey='.urlencode(dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2));
  286. }
  287. else
  288. {
  289. $urlback.='&securekey='.urlencode($conf->global->PAYPAL_SECURITY_TOKEN);
  290. }
  291. }
  292. }
  293. else if ($conf->global->MEMBER_NEWFORM_PAYONLINE == 'stripe')
  294. {
  295. $urlback=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?from=membernewform&source=membersubscription&ref='.$adh->ref;
  296. if (price2num(GETPOST('amount'))) $urlback.='&amount='.price2num(GETPOST('amount'));
  297. if (GETPOST('email')) $urlback.='&email='.urlencode(GETPOST('email'));
  298. if (! empty($conf->global->STRIPE_SECURITY_TOKEN))
  299. {
  300. if (! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE))
  301. {
  302. $urlback.='&securekey='.urlencode(dol_hash($conf->global->STRIPE_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2));
  303. }
  304. else
  305. {
  306. $urlback.='&securekey='.urlencode($conf->global->STRIPE_SECURITY_TOKEN);
  307. }
  308. }
  309. }
  310. else
  311. {
  312. dol_print_error('',"Autosubscribe form is setup to ask an online payment for a not managed online payment");
  313. exit;
  314. }
  315. }
  316. if (! empty($entity)) $urlback.='&entity='.$entity;
  317. dol_syslog("member ".$adh->ref." was created, we redirect to ".$urlback);
  318. Header("Location: ".$urlback);
  319. exit;
  320. }
  321. else
  322. {
  323. $errmsg .= join('<br>',$adh->errors);
  324. }
  325. }
  326. }
  327. // Action called after a submitted was send and member created successfully
  328. // If MEMBER_URL_REDIRECT_SUBSCRIPTION is set to url we never go here because a redirect was done to this url.
  329. // backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url.
  330. if ($action == 'added')
  331. {
  332. llxHeaderVierge($langs->trans("NewMemberForm"));
  333. // Si on a pas ete redirige
  334. print '<br>';
  335. print '<div class="center">';
  336. print $langs->trans("NewMemberbyWeb");
  337. print '</div>';
  338. llxFooterVierge();
  339. exit;
  340. }
  341. /*
  342. * View
  343. */
  344. $form = new Form($db);
  345. $formcompany = new FormCompany($db);
  346. $adht = new AdherentType($db);
  347. $extrafields->fetch_name_optionals_label('adherent'); // fetch optionals attributes and labels
  348. llxHeaderVierge($langs->trans("NewSubscription"));
  349. print load_fiche_titre($langs->trans("NewSubscription"));
  350. if (! empty($conf->global->MEMBER_NEWFORM_TEXT)) print $langs->trans($conf->global->MEMBER_NEWFORM_TEXT)."<br>\n";
  351. else print $langs->trans("NewSubscriptionDesc",$conf->global->MAIN_INFO_SOCIETE_MAIL)."<br>\n";
  352. dol_htmloutput_errors($errmsg);
  353. print '<div align="center">';
  354. print '<div id="divsubscribe">';
  355. // Print form
  356. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="newmember">'."\n";
  357. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" / >';
  358. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  359. print '<input type="hidden" name="action" value="add" />';
  360. print '<br>'.$langs->trans("FieldsWithAreMandatory",'*').'<br>';
  361. //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
  362. dol_fiche_head('');
  363. print '<script type="text/javascript">
  364. jQuery(document).ready(function () {
  365. jQuery(document).ready(function () {
  366. function initmorphy()
  367. {
  368. if (jQuery("#morphy").val()==\'phy\') {
  369. jQuery("#trcompany").hide();
  370. }
  371. if (jQuery("#morphy").val()==\'mor\') {
  372. jQuery("#trcompany").show();
  373. }
  374. };
  375. initmorphy();
  376. jQuery("#morphy").click(function() {
  377. initmorphy();
  378. });
  379. jQuery("#selectcountry_id").change(function() {
  380. document.newmember.action.value="create";
  381. document.newmember.submit();
  382. });
  383. });
  384. });
  385. </script>';
  386. print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
  387. // Type
  388. if (empty($conf->global->MEMBER_NEWFORM_FORCETYPE))
  389. {
  390. $listoftype=$adht->liste_array();
  391. $tmp=array_keys($listoftype);
  392. $defaulttype='';
  393. $isempty=1;
  394. if (count($listoftype)==1) { $defaulttype=$tmp[0]; $isempty=0; }
  395. print '<tr><td width="15%">'.$langs->trans("Type").' <FONT COLOR="red">*</FONT></td><td width="35%">';
  396. print $form->selectarray("type", $adht->liste_array(), GETPOST('type')?GETPOST('type'):$defaulttype, $isempty);
  397. print '</td></tr>'."\n";
  398. }
  399. else
  400. {
  401. $adht->fetch($conf->global->MEMBER_NEWFORM_FORCETYPE);
  402. //print $adht->libelle;
  403. print '<input type="hidden" id="type" name="type" value="'.$conf->global->MEMBER_NEWFORM_FORCETYPE.'">';
  404. }
  405. // Moral/Physic attribute
  406. $morphys["phy"] = $langs->trans("Physical");
  407. $morphys["mor"] = $langs->trans("Moral");
  408. if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY))
  409. {
  410. print '<tr class="morphy"><td>'.$langs->trans('Nature').' <FONT COLOR="red">*</FONT></td><td>'."\n";
  411. print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1);
  412. print '</td></tr>'."\n";
  413. }
  414. else
  415. {
  416. print $morphys[$conf->global->MEMBER_NEWFORM_FORCEMORPHY];
  417. print '<input type="hidden" id="morphy" name="morphy" value="'.$conf->global->MEMBER_NEWFORM_FORCEMORPHY.'">';
  418. }
  419. // Civility
  420. print '<tr><td>'.$langs->trans('UserTitle').'</td><td>';
  421. print $formcompany->select_civility(GETPOST('civility_id'),'civility_id').'</td></tr>'."\n";
  422. // Lastname
  423. print '<tr><td>'.$langs->trans("Lastname").' <FONT COLOR="red">*</FONT></td><td><input type="text" name="lastname" size="40" value="'.dol_escape_htmltag(GETPOST('lastname')).'"></td></tr>'."\n";
  424. // Firstname
  425. print '<tr><td>'.$langs->trans("Firstname").' <FONT COLOR="red">*</FONT></td><td><input type="text" name="firstname" size="40" value="'.dol_escape_htmltag(GETPOST('firstname')).'"></td></tr>'."\n";
  426. // Company
  427. print '<tr id="trcompany" class="trcompany"><td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.dol_escape_htmltag(GETPOST('societe')).'"></td></tr>'."\n";
  428. // Address
  429. print '<tr><td>'.$langs->trans("Address").'</td><td>'."\n";
  430. print '<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag(GETPOST('address')).'</textarea></td></tr>'."\n";
  431. // Zip / Town
  432. print '<tr><td>'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td>';
  433. print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town','selectcountry_id','state_id'), 6, 1);
  434. print ' / ';
  435. print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode','selectcountry_id','state_id'), 0, 1);
  436. print '</td></tr>';
  437. // Country
  438. print '<tr><td width="25%">'.$langs->trans('Country').'</td><td>';
  439. $country_id=GETPOST('country_id');
  440. if (! $country_id && ! empty($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE)) $country_id=getCountry($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE,2,$db,$langs);
  441. if (! $country_id && ! empty($conf->geoipmaxmind->enabled))
  442. {
  443. $country_code=dol_user_country();
  444. //print $country_code;
  445. if ($country_code)
  446. {
  447. $new_country_id=getCountry($country_code,3,$db,$langs);
  448. //print 'xxx'.$country_code.' - '.$new_country_id;
  449. if ($new_country_id) $country_id=$new_country_id;
  450. }
  451. }
  452. $country_code=getCountry($country_id,2,$db,$langs);
  453. print $form->select_country($country_id,'country_id');
  454. print '</td></tr>';
  455. // State
  456. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  457. {
  458. print '<tr><td>'.$langs->trans('State').'</td><td>';
  459. if ($country_code) print $formcompany->select_state(GETPOST("state_id"),$country_code);
  460. else print '';
  461. print '</td></tr>';
  462. }
  463. // EMail
  464. print '<tr><td>'.$langs->trans("Email").' <FONT COLOR="red">*</FONT></td><td><input type="text" name="email" size="40" value="'.dol_escape_htmltag(GETPOST('email')).'"></td></tr>'."\n";
  465. // Login
  466. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  467. {
  468. print '<tr><td>'.$langs->trans("Login").' <FONT COLOR="red">*</FONT></td><td><input type="text" name="login" size="20" value="'.dol_escape_htmltag(GETPOST('login')).'"></td></tr>'."\n";
  469. print '<tr><td>'.$langs->trans("Password").' <FONT COLOR="red">*</FONT></td><td><input type="password" name="pass1" size="20" value="'.GETPOST("pass1").'"></td></tr>'."\n";
  470. print '<tr><td>'.$langs->trans("PasswordAgain").' <FONT COLOR="red">*</FONT></td><td><input type="password" name="pass2" size="20" value="'.GETPOST("pass2").'"></td></tr>'."\n";
  471. }
  472. // Birthday
  473. print '<tr id="trbirth" class="trbirth"><td>'.$langs->trans("DateToBirth").'</td><td>';
  474. print $form->select_date($birthday,'birth',0,0,1,"newmember",1,0,1);
  475. print '</td></tr>'."\n";
  476. // Photo
  477. print '<tr><td>'.$langs->trans("URLPhoto").'</td><td><input type="text" name="photo" size="40" value="'.dol_escape_htmltag(GETPOST('photo')).'"></td></tr>'."\n";
  478. // Public
  479. print '<tr><td>'.$langs->trans("Public").'</td><td><input type="checkbox" name="public"></td></tr>'."\n";
  480. // Extrafields
  481. foreach($extrafields->attribute_label as $key=>$value)
  482. {
  483. print "<tr><td>".$value."</td><td>";
  484. print $extrafields->showInputField($key,GETPOST('options_'.$key));
  485. print "</td></tr>\n";
  486. }
  487. // Comments
  488. print '<tr>';
  489. print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
  490. print '<td class="tdtop"><textarea name="note_private" id="note_private" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag(GETPOST('note_private')).'</textarea></td>';
  491. print '</tr>'."\n";
  492. // Add specific fields used by Dolibarr foundation for example
  493. if (! empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER))
  494. {
  495. $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+');
  496. print '<tr id="trbudget" class="trcompany"><td>'.$langs->trans("TurnoverOrBudget").' <FONT COLOR="red">*</FONT></td><td>';
  497. print $form->selectarray('budget', $arraybudget, GETPOST('budget'), 1);
  498. print ' € or $';
  499. print '<script type="text/javascript">
  500. jQuery(document).ready(function () {
  501. initturnover();
  502. jQuery("#morphy").click(function() {
  503. initturnover();
  504. });
  505. jQuery("#budget").change(function() {
  506. if (jQuery("#budget").val() > 0) { jQuery(".amount").val(jQuery("#budget").val()); }
  507. else { jQuery("#budget").val(\'\'); }
  508. });
  509. /*jQuery("#type").change(function() {
  510. if (jQuery("#type").val()==1) { jQuery("#morphy").val(\'mor\'); }
  511. if (jQuery("#type").val()==2) { jQuery("#morphy").val(\'phy\'); }
  512. if (jQuery("#type").val()==3) { jQuery("#morphy").val(\'mor\'); }
  513. if (jQuery("#type").val()==4) { jQuery("#morphy").val(\'mor\'); }
  514. initturnover();
  515. });*/
  516. function initturnover() {
  517. if (jQuery("#morphy").val()==\'phy\') {
  518. jQuery(".amount").val(20);
  519. jQuery("#trbudget").hide();
  520. jQuery("#trcompany").hide();
  521. }
  522. if (jQuery("#morphy").val()==\'mor\') {
  523. jQuery(".amount").val(\'\');
  524. jQuery("#trcompany").show();
  525. jQuery("#trbirth").hide();
  526. jQuery("#trbudget").show();
  527. if (jQuery("#budget").val() > 0) { jQuery(".amount").val(jQuery("#budget").val()); }
  528. else { jQuery("#budget").val(\'\'); }
  529. }
  530. }
  531. });
  532. </script>';
  533. print '</td></tr>'."\n";
  534. }
  535. if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)
  536. || ! empty($conf->global->MEMBER_NEWFORM_PAYONLINE))
  537. {
  538. // $conf->global->MEMBER_NEWFORM_SHOWAMOUNT is an amount
  539. $amount=0;
  540. if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  541. $amount=$conf->global->MEMBER_NEWFORM_AMOUNT;
  542. }
  543. if (! empty($conf->global->MEMBER_NEWFORM_PAYONLINE))
  544. {
  545. $amount=GETPOST('amount')?GETPOST('amount'):$conf->global->MEMBER_NEWFORM_AMOUNT;
  546. }
  547. // $conf->global->MEMBER_NEWFORM_PAYONLINE is 'paypal', 'paybox' or 'stripe'
  548. print '<tr><td>'.$langs->trans("Subscription").'</td><td class="nowrap">';
  549. if (! empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT))
  550. {
  551. print '<input type="text" name="amount" id="amount" class="flat amount" size="6" value="'.$amount.'">';
  552. }
  553. else
  554. {
  555. print '<input type="text" name="amount" id="amounthidden" class="flat amount" disabled size="6" value="'.$amount.'">';
  556. print '<input type="hidden" name="amount" id="amount" class="flat amount" size="6" value="'.$amount.'">';
  557. }
  558. print ' '.$langs->trans("Currency".$conf->currency);
  559. print '</td></tr>';
  560. }
  561. print "</table>\n";
  562. dol_fiche_end();
  563. // Save
  564. print '<div class="center">';
  565. print '<input type="submit" value="'.$langs->trans("Save").'" id="submitsave" class="button">';
  566. if (! empty($backtopage))
  567. {
  568. print ' &nbsp; &nbsp; <input type="submit" value="'.$langs->trans("Cancel").'" id="submitcancel" class="button">';
  569. }
  570. print '</div>';
  571. print "</form>\n";
  572. print "<br>";
  573. print '</div></div>';
  574. llxFooterVierge();
  575. $db->close();