dolibarr 22.0.5
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2012-2020 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2015-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2021 Waël Almoman <info@almoman.com>
11 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
34// Load Dolibarr environment
35require '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
42require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
43require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
44require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
45require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
50
51
61// Load translation files required by the page
62$langs->loadLangs(array("companies", "bills", "members", "users", "other", "paypal"));
63
64
65// Get parameters
66$action = GETPOST('action', 'aZ09');
67$cancel = GETPOST('cancel', 'alpha');
68$backtopage = GETPOST('backtopage', 'alpha');
69$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
70$confirm = GETPOST('confirm', 'alpha');
71$rowid = GETPOSTINT('rowid');
72$id = GETPOST('id') ? GETPOSTINT('id') : $rowid;
73$typeid = GETPOSTINT('typeid');
74$userid = GETPOSTINT('userid');
75$socid = GETPOSTINT('socid');
76$ref = GETPOST('ref', 'alpha');
77$error = 0;
78
79if (isModEnabled('mailmanspip')) {
80 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
81
82 $langs->load('mailmanspip');
83
84 $mailmanspip = new MailmanSpip($db);
85} else {
86 $mailmanspip = null;
87}
88
89$object = new Adherent($db);
90$extrafields = new ExtraFields($db);
91
92// fetch optionals attributes and labels
93$extrafields->fetch_name_optionals_label($object->table_element);
94
95$socialnetworks = getArrayOfSocialNetworks();
96
97// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
98$object->getCanvas($id);
99$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
100$objcanvas = null;
101if (!empty($canvas)) {
102 require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
103 $objcanvas = new Canvas($db, $action);
104 $objcanvas->getCanvas('adherent', 'membercard', $canvas);
105}
106
107// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
108$hookmanager->initHooks(array('membercard', 'globalcard'));
109
110// Fetch object
111if ($id > 0 || !empty($ref)) {
112 // Load member
113 $result = $object->fetch($id, $ref);
114
115 // Define variables to know what current user can do on users
116 $canadduser = ($user->admin || $user->hasRight('user', 'user', 'creer'));
117 // Define variables to know what current user can do on properties of user linked to edited member
118 if ($object->user_id) {
119 // $User is the user who edits, $object->user_id is the id of the related user in the edited member
120 $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'creer'))
121 || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'creer')));
122 $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight('user', 'self', 'password'))
123 || (($user->id != $object->user_id) && $user->hasRight('user', 'user', 'password')));
124 }
125}
126
127// Define variables to determine what the current user can do on the members
128$canaddmember = $user->hasRight('adherent', 'creer');
129$caneditfieldmember = false;
130// Define variables to determine what the current user can do on the properties of a member
131if ($id) {
132 $caneditfieldmember = $user->hasRight('adherent', 'creer');
133}
134$permissiontoeditextra = $canaddmember;
135if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
136 // For action 'update_extras', is there a specific permission set for the attribute to update
137 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
138}
139
140// Security check
141$result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
142
143if (!$user->hasRight('adherent', 'creer') && $action == 'edit') {
144 accessforbidden('Not enough permission');
145}
146
147$linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.$conf->entity : '');
148
149
150/*
151 * Actions
152 */
153
154$parameters = array('id' => $id, 'rowid' => $id, 'objcanvas' => $objcanvas, 'confirm' => $confirm);
155$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
156if ($reshook < 0) {
157 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
158}
159
160if (empty($reshook)) {
161 $backurlforlist = DOL_URL_ROOT.'/adherents/list.php';
162
163 if (empty($backtopage) || ($cancel && empty($id))) {
164 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
165 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
166 $backtopage = $backurlforlist;
167 } else {
168 $backtopage = DOL_URL_ROOT.'/adherents/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
169 }
170 }
171 }
172
173 if ($cancel) {
174 if (!empty($backtopageforcancel)) {
175 header("Location: ".$backtopageforcancel);
176 exit;
177 } elseif (!empty($backtopage)) {
178 header("Location: ".$backtopage);
179 exit;
180 }
181 $action = '';
182 }
183
184 if ($action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) {
185 $error = 0;
186 if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only
187 if ($userid != $user->id && $userid != $object->user_id) {
188 $error++;
189 setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
190 }
191 }
192
193 if (!$error) {
194 if ($userid != $object->user_id) { // If link differs from currently in database
195 $result = $object->setUserId($userid);
196 if ($result < 0) {
197 dol_print_error($object->db, $object->error);
198 }
199 $action = '';
200 }
201 }
202 }
203
204 if ($action == 'setsocid' && $caneditfieldmember) {
205 $error = 0;
206 if (!$error) {
207 if ($socid != $object->socid) { // If link differs from currently in database
208 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
209 $sql .= " WHERE socid = ".((int) $socid);
210 $sql .= " AND entity = ".$conf->entity;
211 $resql = $db->query($sql);
212 if ($resql) {
213 $obj = $db->fetch_object($resql);
214 if ($obj && $obj->rowid > 0) {
215 $othermember = new Adherent($db);
216 $othermember->fetch($obj->rowid);
217 $thirdparty = new Societe($db);
218 $thirdparty->fetch($socid);
219 $error++;
220 setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
221 }
222 }
223
224 if (!$error) {
225 $result = $object->setThirdPartyId($socid);
226 if ($result < 0) {
227 dol_print_error($object->db, $object->error);
228 }
229 $action = '';
230 }
231 }
232 }
233 }
234
235 // Create user from a member
236 if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->hasRight('user', 'user', 'creer')) {
237 if ($result > 0) {
238 // Creation user
239 $nuser = new User($db);
240 $tmpuser = dol_clone($object, 2);
241 if (GETPOST('internalorexternal', 'aZ09') == 'internal') {
242 $tmpuser->fk_soc = 0;
243 }
244
245 $result = $nuser->create_from_member($tmpuser, GETPOST('login', 'alphanohtml'));
246
247 if ($result < 0) {
248 $langs->load("errors");
249 setEventMessages($langs->trans($nuser->error), null, 'errors');
250 } else {
251 setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs');
252 $action = '';
253 }
254 } else {
255 setEventMessages($object->error, $object->errors, 'errors');
256 }
257 }
258
259 // Create third party from a member
260 if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
261 if ($result > 0) {
262 // User creation
263 $company = new Societe($db);
264 $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'));
265
266 if ($result < 0) {
267 $langs->load("errors");
268 setEventMessages($langs->trans($company->error), null, 'errors');
269 setEventMessages($company->error, $company->errors, 'errors');
270 }
271 } else {
272 setEventMessages($object->error, $object->errors, 'errors');
273 }
274 }
275
276 if ($action == 'update' && !$cancel && $user->hasRight('adherent', 'creer')) {
277 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
278
279 $birthdate = '';
280 if (GETPOSTINT("birthday") && GETPOSTINT("birthmonth") && GETPOSTINT("birthyear")) {
281 $birthdate = dol_mktime(12, 0, 0, GETPOSTINT("birthmonth"), GETPOSTINT("birthday"), GETPOSTINT("birthyear"));
282 }
283 $lastname = GETPOST("lastname", 'alphanohtml');
284 $firstname = GETPOST("firstname", 'alphanohtml');
285 $gender = GETPOST("gender", 'alphanohtml');
286 $societe = GETPOST("societe", 'alphanohtml');
287 $morphy = GETPOST("morphy", 'alphanohtml');
288 $login = GETPOST("login", 'alphanohtml');
289 if ($morphy != 'mor' && empty($lastname)) {
290 $error++;
291 $langs->load("errors");
292 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors');
293 }
294 if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) {
295 $error++;
296 $langs->load("errors");
297 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors');
298 }
299 if ($morphy == 'mor' && empty($societe)) {
300 $error++;
301 $langs->load("errors");
302 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors');
303 }
304 // Check if the login already exists
305 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
306 if (empty($login)) {
307 $error++;
308 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")), null, 'errors');
309 }
310 }
311 // Create new object
312 if ($result > 0 && !$error) {
313 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
314
315 // Change values
316 $object->civility_id = trim(GETPOST("civility_id", 'alphanohtml'));
317 $object->firstname = trim(GETPOST("firstname", 'alphanohtml'));
318 $object->lastname = trim(GETPOST("lastname", 'alphanohtml'));
319 $object->gender = trim(GETPOST("gender", 'alphanohtml'));
320 $object->login = trim(GETPOST("login", 'alphanohtml'));
321 if (GETPOSTISSET('pass')) {
322 $object->pass = trim(GETPOST("pass", 'password')); // For password, we must use 'none'
323 }
324
325 $object->societe = trim(GETPOST("societe", 'alphanohtml')); // deprecated
326 $object->company = trim(GETPOST("societe", 'alphanohtml'));
327
328 $object->address = trim(GETPOST("address", 'alphanohtml'));
329 $object->zip = trim(GETPOST("zipcode", 'alphanohtml'));
330 $object->town = trim(GETPOST("town", 'alphanohtml'));
331 $object->state_id = GETPOSTINT("state_id");
332 $object->country_id = GETPOSTINT("country_id");
333
334 $object->phone = trim(GETPOST("phone", 'alpha'));
335 $object->phone_perso = trim(GETPOST("phone_perso", 'alpha'));
336 $object->phone_mobile = trim(GETPOST("phone_mobile", 'alpha'));
337 $object->email = preg_replace('/\s+/', '', GETPOST("member_email", 'alpha'));
338 $object->url = trim(GETPOST('member_url', 'url'));
339 $object->socialnetworks = array();
340 foreach ($socialnetworks as $key => $value) {
341 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
342 $object->socialnetworks[$key] = trim(GETPOST($key, 'alphanohtml'));
343 }
344 }
345 $object->birth = $birthdate;
346 $object->default_lang = GETPOST('default_lang', 'alpha');
347 $object->typeid = GETPOSTINT("typeid");
348 //$object->note = trim(GETPOST("comment", "restricthtml"));
349 $object->morphy = GETPOST("morphy", 'alpha');
350
351 if (GETPOST('deletephoto', 'alpha')) {
352 $object->photo = '';
353 } elseif (!empty($_FILES['photo']['name']) && empty($_FILES['photo']['error'])) { // A refused upload keeps the current photo
354 $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
355 }
356
357 // Get status and public property
358 $object->statut = GETPOSTINT("statut");
359 $object->status = GETPOSTINT("statut");
360 $object->public = GETPOSTINT("public");
361
362 // Fill array 'array_options' with data from add form
363 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
364 if ($ret < 0) {
365 $error++;
366 }
367
368 // Check if we need to also synchronize user information
369 $nosyncuser = 0;
370 if ($object->user_id) { // If linked to a user
371 if ($user->id != $object->user_id && !$user->hasRight('user', 'user', 'creer')) {
372 $nosyncuser = 1; // Disable synchronizing
373 }
374 }
375
376 // Check if we need to also synchronize password information
377 $nosyncuserpass = 1; // no by default
378 if (GETPOSTISSET('pass')) {
379 if ($object->user_id) { // If member is linked to a user
380 $nosyncuserpass = 0; // We may try to sync password
381 if ($user->id == $object->user_id) {
382 if (!$user->hasRight('user', 'self', 'password')) {
383 $nosyncuserpass = 1; // Disable synchronizing
384 }
385 } else {
386 if (!$user->hasRight('user', 'user', 'password')) {
387 $nosyncuserpass = 1; // Disable synchronizing
388 }
389 }
390 }
391 }
392
393 if (!$error) {
394 $result = $object->update($user, 0, $nosyncuser, $nosyncuserpass);
395
396 if ($result >= 0 && !count($object->errors)) {
397 $categories = GETPOST('memcats', 'array');
398 $object->setCategories($categories);
399
400 // Logo/Photo save
401 $dir = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos';
402 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
403 if ($file_OK) {
404 if (GETPOST('deletephoto')) {
405 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
406 $fileimg = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos/'.$object->photo;
407 $dirthumbs = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos/thumbs';
408 dol_delete_file($fileimg);
409 dol_delete_dir_recursive($dirthumbs);
410 }
411
412 if (image_format_supported($_FILES['photo']['name']) > 0) {
413 dol_mkdir($dir);
414
415 if (@is_dir($dir)) {
416 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
417 $resultupload = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
418 // Note: $resultupload is a string when the file was refused and, in PHP 8, such a string compares as greater than 0
419 if (!is_numeric($resultupload) || $resultupload <= 0) {
420 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
421 } else {
422 // Create thumbs
423 $object->addThumbs($newfile);
424 }
425 }
426 } else {
427 $langs->load("errors");
428 setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
429 }
430 } else {
431 switch ($_FILES['photo']['error']) {
432 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
433 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
434 $langs->load("errors");
435 setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors');
436 break;
437 case 3: //uploaded file was only partially uploaded
438 setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
439 break;
440 }
441 }
442
443 $rowid = $object->id;
444 $id = $object->id;
445 $action = '';
446
447 if (!empty($backtopage)) {
448 header("Location: ".$backtopage);
449 exit;
450 }
451 } else {
452 setEventMessages($object->error, $object->errors, 'errors');
453 $action = '';
454 }
455 } else {
456 $action = 'edit';
457 }
458 } else {
459 $action = 'edit';
460 }
461 }
462
463 if ($action == 'add' && $user->hasRight('adherent', 'creer')) {
464 if ($canvas) {
465 $object->canvas = $canvas;
466 }
467 $birthdate = '';
468 if (GETPOSTISSET("birthday") && GETPOST("birthday") && GETPOSTISSET("birthmonth") && GETPOST("birthmonth") && GETPOSTISSET("birthyear") && GETPOST("birthyear")) {
469 $birthdate = dol_mktime(12, 0, 0, GETPOSTINT("birthmonth"), GETPOSTINT("birthday"), GETPOSTINT("birthyear"));
470 }
471 $datesubscription = '';
472 if (GETPOSTISSET("reday") && GETPOSTISSET("remonth") && GETPOSTISSET("reyear")) {
473 $datesubscription = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
474 }
475
476 $typeid = GETPOSTINT("typeid");
477 $civility_id = GETPOST("civility_id", 'alphanohtml');
478 $lastname = GETPOST("lastname", 'alphanohtml');
479 $firstname = GETPOST("firstname", 'alphanohtml');
480 $gender = GETPOST("gender", 'alphanohtml');
481 $societe = GETPOST("societe", 'alphanohtml');
482 $address = GETPOST("address", 'alphanohtml');
483 $zip = GETPOST("zipcode", 'alphanohtml');
484 $town = GETPOST("town", 'alphanohtml');
485 $state_id = GETPOSTINT("state_id");
486 $country_id = GETPOSTINT("country_id");
487
488 $phone = GETPOST("phone", 'alpha');
489 $phone_perso = GETPOST("phone_perso", 'alpha');
490 $phone_mobile = GETPOST("phone_mobile", 'alpha');
491 $email = preg_replace('/\s+/', '', GETPOST("member_email", 'aZ09arobase'));
492 $url = trim(GETPOST('url', 'url'));
493 $login = GETPOST("member_login", 'alphanohtml');
494 $pass = GETPOST("password", 'password'); // For password, we use 'none'
495 $photo = GETPOST("photo", 'alphanohtml');
496 $morphy = GETPOST("morphy", 'alphanohtml');
497 $public = GETPOSTINT("public");
498
499 $userid = GETPOSTINT("userid");
500 $socid = GETPOSTINT("socid");
501 $default_lang = GETPOST('default_lang', 'alpha');
502
503 $object->civility_id = $civility_id;
504 $object->firstname = $firstname;
505 $object->lastname = $lastname;
506 $object->gender = $gender;
507 $object->societe = $societe; // deprecated
508 $object->company = $societe;
509 $object->address = $address;
510 $object->zip = $zip;
511 $object->town = $town;
512 $object->state_id = $state_id;
513 $object->country_id = $country_id;
514 $object->phone = $phone;
515 $object->phone_perso = $phone_perso;
516 $object->phone_mobile = $phone_mobile;
517 $object->socialnetworks = array();
518 if (isModEnabled('socialnetworks')) {
519 foreach ($socialnetworks as $key => $value) {
520 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
521 $object->socialnetworks[$key] = GETPOST("member_".$key, 'alphanohtml');
522 }
523 }
524 }
525
526 $object->email = $email;
527 $object->url = $url;
528 $object->login = $login;
529 $object->pass = $pass;
530 $object->birth = $birthdate;
531 $object->photo = $photo;
532 $object->typeid = $typeid;
533 //$object->note = $comment;
534 $object->morphy = $morphy;
535 $object->user_id = $userid;
536 $object->socid = $socid;
537 $object->public = $public;
538 $object->default_lang = $default_lang;
539 // Fill array 'array_options' with data from add form
540 $ret = $extrafields->setOptionalsFromPost(null, $object);
541 if ($ret < 0) {
542 $error++;
543 }
544
545 // Check parameters
546 if (empty($morphy) || $morphy == "-1") {
547 $error++;
548 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MemberNature")), null, 'errors');
549 }
550 // Tests if the login already exists
551 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
552 if (empty($login)) {
553 $error++;
554 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")), null, 'errors');
555 } else {
556 $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'";
557 $result = $db->query($sql);
558 $num = 0;
559 if ($result) {
560 $num = $db->num_rows($result);
561 }
562 if ($num) {
563 $error++;
564 $langs->load("errors");
565 setEventMessages($langs->trans("ErrorLoginAlreadyExists", $login), null, 'errors');
566 }
567 }
568 if (empty($pass)) {
569 $error++;
570 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Password")), null, 'errors');
571 }
572 }
573 if ($morphy == 'mor' && empty($societe)) {
574 $error++;
575 $langs->load("errors");
576 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors');
577 }
578 if ($morphy != 'mor' && empty($lastname)) {
579 $error++;
580 $langs->load("errors");
581 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors');
582 }
583 if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) {
584 $error++;
585 $langs->load("errors");
586 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors');
587 }
588 if (!($typeid > 0)) { // Keep () before !
589 $error++;
590 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
591 }
592 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($email)) {
593 $error++;
594 $langs->load("errors");
595 setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
596 }
597 if (!empty($object->url) && !isValidUrl($object->url)) {
598 $langs->load("errors");
599 setEventMessages($langs->trans("ErrorBadUrl", $object->url), null, 'errors');
600 }
601 $public = 0;
602 if (isset($public)) {
603 $public = 1;
604 }
605
606 if (!$error) {
607 $db->begin();
608
609 // Create the member
610 $result = $object->create($user);
611 if ($result > 0) {
612 // Foundation categories
613 $memcats = GETPOST('memcats', 'array');
614 $object->setCategories($memcats);
615
616 $db->commit();
617
618 $rowid = $object->id;
619 $id = $object->id;
620
621 $backtopage = preg_replace('/__ID__/', (string) $id, $backtopage);
622 } else {
623 $db->rollback();
624
625 $error++;
626 setEventMessages($object->error, $object->errors, 'errors');
627 }
628
629 // Auto-create thirdparty on member creation
630 if (getDolGlobalString('ADHERENT_DEFAULT_CREATE_THIRDPARTY')) {
631 if ($result > 0) {
632 // Create third party out of a member
633 $company = new Societe($db);
634 $result = $company->create_from_member($object);
635 if ($result < 0) {
636 $langs->load("errors");
637 setEventMessages($langs->trans($company->error), null, 'errors');
638 setEventMessages($company->error, $company->errors, 'errors');
639 }
640 } else {
641 setEventMessages($object->error, $object->errors, 'errors');
642 }
643 }
644 }
645 $action = ($result < 0 || !$error) ? '' : 'create';
646
647 if (!$error && $backtopage) {
648 header("Location: ".$backtopage);
649 exit;
650 }
651 }
652
653 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_delete' && $confirm == 'yes') {
654 $result = $object->delete($user);
655 if ($result > 0) {
656 setEventMessages($langs->trans("RecordDeleted"), null, 'errors');
657 if (!empty($backtopage) && !preg_match('/'.preg_quote($_SERVER["PHP_SELF"], '/').'/', $backtopage)) {
658 header("Location: ".$backtopage);
659 exit;
660 } else {
661 header("Location: list.php");
662 exit;
663 }
664 } else {
665 setEventMessages($object->error, null, 'errors');
666 }
667 }
668
669 if ($user->hasRight('adherent', 'creer') && $action == 'confirm_valid' && $confirm == 'yes') {
670 $error = 0;
671
672 $db->begin();
673
674 $adht = new AdherentType($db);
675 $adht->fetch($object->typeid);
676
677 $result = $object->validate($user);
678
679 if ($result >= 0 && !count($object->errors)) {
680 // Send confirmation email (according to parameters of member type. Otherwise generic)
681 if ($object->email && GETPOST("send_mail")) {
682 $subject = '';
683 $msg = '';
684
685 // Send subscription email
686 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
687 $formmail = new FormMail($db);
688 // Set output language
689 $outputlangs = new Translate('', $conf);
690 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
691 // Load traductions files required by page
692 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
693 // Get email content from template
694 $arraydefaultmessage = null;
695 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION');
696
697 if (!empty($labeltouse)) {
698 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
699 }
700
701 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
702 $subject = (string) $arraydefaultmessage->topic;
703 $msg = (string) $arraydefaultmessage->content;
704 }
705
706 if (empty($labeltouse) || (int) $labeltouse === -1) {
707 //fallback on the old configuration.
708 $langs->load("errors");
709 setEventMessages('<a href="'.DOL_URL_ROOT.'/adherents/admin/member_emails.php">'.$langs->trans('WarningMandatorySetupNotComplete').'</a>', null, 'errors');
710 $error++;
711 } else {
712 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
713 complete_substitutions_array($substitutionarray, $outputlangs, $object);
714 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
715 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
716
717 $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
718
719 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
720 if ($result < 0) {
721 $error++;
722 setEventMessages($object->error, $object->errors, 'errors');
723 }
724 }
725 }
726 } else {
727 $error++;
728 setEventMessages($object->error, $object->errors, 'errors');
729 }
730
731 if (!$error) {
732 $db->commit();
733 } else {
734 $db->rollback();
735 }
736 $action = '';
737 }
738
739 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_resiliate') {
740 $error = 0;
741
742 if ($confirm == 'yes') {
743 $adht = new AdherentType($db);
744 $adht->fetch($object->typeid);
745
746 $result = $object->resiliate($user);
747
748 if ($result >= 0 && !count($object->errors)) {
749 if ($object->email && GETPOST("send_mail")) {
750 $subject = '';
751 $msg = '';
752
753 // Send subscription email
754 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
755 $formmail = new FormMail($db);
756 // Set output language
757 $outputlangs = new Translate('', $conf);
758 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
759 // Load traductions files required by page
760 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
761 // Get email content from template
762 $arraydefaultmessage = null;
763 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_CANCELATION');
764
765 if (!empty($labeltouse)) {
766 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
767 }
768
769 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
770 $subject = (string) $arraydefaultmessage->topic;
771 $msg = (string) $arraydefaultmessage->content;
772 }
773
774 if (empty($labeltouse) || (int) $labeltouse === -1) {
775 //fallback on the old configuration.
776 setEventMessages('WarningMandatorySetupNotComplete', null, 'errors');
777 $error++;
778 } else {
779 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
780 complete_substitutions_array($substitutionarray, $outputlangs, $object);
781 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
782 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs);
783
784 $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
785
786 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
787 if ($result < 0) {
788 $error++;
789 setEventMessages($object->error, $object->errors, 'errors');
790 }
791 }
792 }
793 } else {
794 $error++;
795
796 setEventMessages($object->error, $object->errors, 'errors');
797 $action = '';
798 }
799 }
800 if (!empty($backtopage) && !$error) {
801 header("Location: ".$backtopage);
802 exit;
803 }
804 }
805
806 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_exclude') {
807 $error = 0;
808
809 if ($confirm == 'yes') {
810 $adht = new AdherentType($db);
811 $adht->fetch($object->typeid);
812
813 $result = $object->exclude($user);
814
815 if ($result >= 0 && !count($object->errors)) {
816 if ($object->email && GETPOST("send_mail")) {
817 $subject = '';
818 $msg = '';
819
820 // Send subscription email
821 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
822 $formmail = new FormMail($db);
823 // Set output language
824 $outputlangs = new Translate('', $conf);
825 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
826 // Load traductions files required by page
827 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
828 // Get email content from template
829 $arraydefaultmessage = null;
830 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_EXCLUSION');
831
832 if (!empty($labeltouse)) {
833 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
834 }
835
836 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
837 $subject = (string) $arraydefaultmessage->topic;
838 $msg = (string) $arraydefaultmessage->content;
839 }
840
841 if (empty($labeltouse) || (int) $labeltouse === -1) {
842 //fallback on the old configuration.
843 setEventMessages('WarningMandatorySetupNotComplete', null, 'errors');
844 $error++;
845 } else {
846 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
847 complete_substitutions_array($substitutionarray, $outputlangs, $object);
848 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
849 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs);
850
851 $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
852
853 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
854 if ($result < 0) {
855 $error++;
856 setEventMessages($object->error, $object->errors, 'errors');
857 }
858 }
859 }
860 } else {
861 $error++;
862
863 setEventMessages($object->error, $object->errors, 'errors');
864 $action = '';
865 }
866 }
867 if (!empty($backtopage) && !$error) {
868 header("Location: ".$backtopage);
869 exit;
870 }
871 }
872
873 if ($action == 'update_extras' && $permissiontoeditextra) {
874 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
875 $attribute_name = GETPOST('attribute', 'aZ09');
876
877 // Fill array 'array_options' with data from update form
878 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
879 if ($ret < 0) {
880 $error++;
881 }
882 if (!$error) {
883 $result = $object->updateExtraField($attribute_name, 'MEMBER_MODIFY');
884 if ($result < 0) {
885 setEventMessages($object->error, $object->errors, 'errors');
886 $error++;
887 }
888 }
889 if ($error) {
890 $action = 'edit_extras';
891 }
892 }
893
894 // SPIP Management
895 if (is_object($mailmanspip)) {
896 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_del_spip' && $confirm == 'yes') {
897 if (!count($object->errors)) {
898 if (!$mailmanspip->del_to_spip($object)) {
899 setEventMessages($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, null, 'errors');
900 }
901 }
902 }
903
904 if ($user->hasRight('adherent', 'creer') && $action == 'confirm_add_spip' && $confirm == 'yes') {
905 if (!count($object->errors)) {
906 if (!$mailmanspip->add_to_spip($object)) {
907 setEventMessages($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, null, 'errors');
908 }
909 }
910 }
911 }
912
913 // Actions when printing a doc from card
914 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
915
916 // Actions to build doc
917 $upload_dir = $conf->member->dir_output;
918 $permissiontoadd = $user->hasRight('adherent', 'creer');
919 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
920
921 // Actions to send emails
922 $triggersendname = 'MEMBER_SENTBYMAIL';
923 $paramname = 'id';
924 $mode = 'emailfrommember';
925 $trackid = 'mem'.$object->id;
926 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
927}
928
929
930/*
931 * View
932 */
933
934$form = new Form($db);
935$formfile = new FormFile($db);
936$formadmin = new FormAdmin($db);
937$formcompany = new FormCompany($db);
938
939$title = $langs->trans("Member")." - ".$langs->trans("Card");
940$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
941
942llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-card');
943
944$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
945
946if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
947 // -----------------------------------------
948 // When used with CANVAS
949 // -----------------------------------------
950 if (empty($object->error) && $id) {
951 $object = new Adherent($db);
952 $result = $object->fetch($id);
953 if ($result <= 0) {
954 dol_print_error(null, $object->error);
955 }
956 }
957 $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
958 $objcanvas->display_canvas($action); // Show template
959} else {
960 // -----------------------------------------
961 // When used in standard mode
962 // -----------------------------------------
963
964 // Create mode
965 if ($action == 'create') {
966 $object->canvas = $canvas;
967 $object->state_id = GETPOSTINT('state_id');
968
969 // We set country_id, country_code and country for the selected country
970 $object->country_id = GETPOSTINT('country_id') ? GETPOSTINT('country_id') : $mysoc->country_id;
971 if ($object->country_id) {
972 $tmparray = getCountry($object->country_id, 'all');
973 $object->country_code = $tmparray['code'];
974 $object->country = $tmparray['label'];
975 }
976
977 $soc = new Societe($db);
978 if (!empty($socid)) {
979 if ($socid > 0) {
980 $soc->fetch($socid);
981 }
982
983 if (!($soc->id > 0)) {
984 $langs->load("errors");
985 print($langs->trans('ErrorRecordNotFound'));
986 exit;
987 }
988 }
989
990 $adht = new AdherentType($db);
991
992 print load_fiche_titre($langs->trans("NewMember"), '', $object->picto);
993
994 if ($conf->use_javascript_ajax) {
995 print "\n".'<script type="text/javascript">'."\n";
996 print 'jQuery(document).ready(function () {
997 jQuery("#selectcountry_id").change(function() {
998 document.formsoc.action.value="create";
999 document.formsoc.submit();
1000 });
1001 function initfieldrequired() {
1002 jQuery("#tdcompany").removeClass("fieldrequired");
1003 jQuery("#tdlastname").removeClass("fieldrequired");
1004 jQuery("#tdfirstname").removeClass("fieldrequired");
1005 if (jQuery(\'input[name="morphy"]:checked\').val() == \'mor\') {
1006 jQuery("#tdcompany").addClass("fieldrequired");
1007 }
1008 if (jQuery(\'input[name="morphy"]:checked\').val() == \'phy\') {
1009 jQuery("#tdlastname").addClass("fieldrequired");
1010 jQuery("#tdfirstname").addClass("fieldrequired");
1011 }
1012 }
1013 jQuery(\'input[name="morphy"]\').change(function() {
1014 initfieldrequired();
1015 });
1016 initfieldrequired();
1017 })';
1018 print '</script>'."\n";
1019 }
1020
1021 print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
1022 print '<input type="hidden" name="token" value="'.newToken().'">';
1023 print '<input type="hidden" name="action" value="add">';
1024 print '<input type="hidden" name="socid" value="'.$socid.'">';
1025 if ($backtopage) {
1026 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1027 }
1028
1029 print dol_get_fiche_head(array());
1030
1031 print '<table class="border centpercent">';
1032 print '<tbody>';
1033
1034 // Login
1035 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1036 print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td><input type="text" name="member_login" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("member_login") ? GETPOST("member_login", 'alphanohtml', 2) : $object->login).'" autofocus="autofocus"></td></tr>';
1037 }
1038
1039 // Password
1040 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1041 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1042 $generated_password = getRandomPassword(false);
1043 print '<tr><td><span class="fieldrequired">'.$langs->trans("Password").'</span></td><td>';
1044 print '<input type="text" class="minwidth300" maxlength="50" name="password" value="'.dol_escape_htmltag($generated_password).'">';
1045 print '</td></tr>';
1046 }
1047
1048 // Type
1049 print '<tr><td class="fieldrequired">'.$langs->trans("MemberType").'</td><td>';
1050 $listetype = $adht->liste_array(1);
1051 print img_picto('', $adht->picto, 'class="pictofixedwidth"');
1052 if (count($listetype)) {
1053 print $form->selectarray("typeid", $listetype, (GETPOSTINT('typeid') ? GETPOSTINT('typeid') : $typeid), (count($listetype) > 1 ? 1 : 0), 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1054 } else {
1055 print '<span class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</span>';
1056 }
1057 if ($user->hasRight('member', 'configurer')) {
1058 print ' <a href="'.DOL_URL_ROOT.'/adherents/type.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&typeid=--IDFORBACKTOPAGE--').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("NewMemberType").'"></span></a>';
1059 }
1060 print "</td>\n";
1061
1062 // Morphy
1063 $morphys = array();
1064 $morphys["phy"] = $langs->trans("Physical");
1065 $morphys["mor"] = $langs->trans("Moral");
1066 $checkednature = GETPOST("morphy", 'alpha');
1067
1068 print '<tr><td class="fieldrequired">'.$langs->trans("MemberNature")."</td><td>\n";
1069 print '<span id="spannature1" class="nonature-back spannature paddinglarge marginrightonly"><label for="phisicalinput" class="valignmiddle">'.$morphys["phy"].'<input id="phisicalinput" class="flat checkforselect marginleftonly valignmiddle" type="radio" name="morphy" value="phy"'.($checkednature == "phy" ? ' checked="checked"' : '').'></label></span>';
1070 print '<span id="spannature2" class="nonature-back spannature paddinglarge marginrightonly"><label for="moralinput" class="valignmiddle">'.$morphys["mor"].'<input id="moralinput" class="flat checkforselect marginleftonly valignmiddle" type="radio" name="morphy" value="mor"'.($checkednature == "mor" ? ' checked="checked"' : '').'></label></span>';
1071
1072 // Add js to manage the background of nature
1073 if ($conf->use_javascript_ajax) {
1074 print '<script>
1075 function refreshNatureCss() {
1076 jQuery(".spannature").each(function( index ) {
1077 console.log(jQuery("#spannature"+(index+1)+" .checkforselect").is(":checked"));
1078 if (jQuery("#spannature"+(index+1)+" .checkforselect").is(":checked")) {
1079 if (index+1 == 1) {
1080 jQuery("#spannature"+(index+1)).addClass("member-individual-back").removeClass("nonature-back");
1081 }
1082 if (index+1 == 2) {
1083 jQuery("#spannature"+(index+1)).addClass("member-company-back").removeClass("nonature-back");
1084 }
1085 } else {
1086 jQuery("#spannature"+(index+1)).removeClass("member-individual-back").removeClass("member-company-back").addClass("nonature-back");
1087 }
1088 });
1089 }
1090 jQuery(".spannature").click(function(){
1091 console.log("We click on a nature");
1092 refreshNatureCss();
1093 });
1094 refreshNatureCss();
1095 </script>';
1096 }
1097
1098 print "</td>\n";
1099
1100 // Company
1101 print '<tr><td id="tdcompany">'.$langs->trans("Company").'</td><td><input type="text" name="societe" class="minwidth300" maxlength="128" value="'.(GETPOSTISSET('societe') ? GETPOST('societe', 'alphanohtml') : $soc->name).'"></td></tr>';
1102
1103 // Civility
1104 print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1105 print $formcompany->select_civility(GETPOSTINT('civility_id') ? GETPOSTINT('civility_id') : $object->civility_id, 'civility_id', 'maxwidth150', 1).'</td>';
1106 print '</tr>';
1107
1108 // Lastname
1109 print '<tr><td id="tdlastname">'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET('lastname') ? GETPOST('lastname', 'alphanohtml') : $object->lastname).'"></td>';
1110 print '</tr>';
1111
1112 // Firstname
1113 print '<tr><td id="tdfirstname">'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET('firstname') ? GETPOST('firstname', 'alphanohtml') : $object->firstname).'"></td>';
1114 print '</tr>';
1115
1116 // Gender
1117 print '<tr><td>'.$langs->trans("Gender").'</td>';
1118 print '<td>';
1119 $arraygender = array('man' => $langs->trans("Genderman"), 'woman' => $langs->trans("Genderwoman"), 'other' => $langs->trans("Genderother"));
1120 print $form->selectarray('gender', $arraygender, GETPOST('gender', 'alphanohtml'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1121 print '</td></tr>';
1122
1123 // EMail
1124 print '<tr><td>'.(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '</span>' : '').'</td>';
1125 print '<td>'.img_picto('', 'object_email').' <input type="text" name="member_email" class="minwidth300" maxlength="255" value="'.(GETPOSTISSET('member_email') ? GETPOST('member_email', 'alpha') : $soc->email).'"></td></tr>';
1126
1127 // Website
1128 print '<tr><td>'.$form->editfieldkey('Web', 'member_url', GETPOST('member_url', 'alpha'), $object, 0).'</td>';
1129 print '<td>'.img_picto('', 'globe').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="member_url" id="member_url" value="'.(GETPOSTISSET('member_url') ? GETPOST('member_url', 'alpha') : $object->url).'"></td></tr>';
1130
1131 // Address
1132 print '<tr><td class="tdtop">'.$langs->trans("Address").'</td><td>';
1133 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="2">'.(GETPOSTISSET('address') ? GETPOST('address', 'alphanohtml') : $soc->address).'</textarea>';
1134 print '</td></tr>';
1135
1136 // Zip / Town
1137 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1138 print $formcompany->select_ziptown((GETPOSTISSET('zipcode') ? GETPOST('zipcode', 'alphanohtml') : $soc->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1139 print ' ';
1140 print $formcompany->select_ziptown((GETPOSTISSET('town') ? GETPOST('town', 'alphanohtml') : $soc->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1141 print '</td></tr>';
1142
1143 // Country
1144 if (empty($soc->country_id)) {
1145 $soc->country_id = $mysoc->country_id;
1146 $soc->country_code = $mysoc->country_code;
1147 $soc->state_id = $mysoc->state_id;
1148 }
1149 print '<tr><td>'.$langs->trans('Country').'</td><td>';
1150 print img_picto('', 'country', 'class="pictofixedwidth"');
1151 print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'alpha') : $soc->country_id, 'country_id');
1152 if ($user->admin) {
1153 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1154 }
1155 print '</td></tr>';
1156
1157 // State
1158 if (!getDolGlobalString('MEMBER_DISABLE_STATE')) {
1159 print '<tr><td>'.$langs->trans('State').'</td><td>';
1160 if ($soc->country_id || GETPOSTISSET('country_id')) {
1161 print img_picto('', 'state', 'class="pictofixedwidth"');
1162 print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOSTINT('state_id') : $soc->state_id, GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $soc->country_code);
1163 } else {
1164 print $countrynotdefined;
1165 }
1166 print '</td></tr>';
1167 }
1168
1169 // Pro phone
1170 print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1171 print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone" size="20" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $soc->phone).'"></td></tr>';
1172
1173 // Personal phone
1174 print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1175 print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone_perso" size="20" value="'.(GETPOSTISSET('phone_perso') ? GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td></tr>';
1176
1177 // Mobile phone
1178 print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1179 print '<td>'.img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"').'<input type="text" name="phone_mobile" size="20" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td></tr>';
1180
1181 if (isModEnabled('socialnetworks')) {
1182 foreach ($socialnetworks as $key => $value) {
1183 if (!$value['active']) {
1184 break;
1185 }
1186 $val = (GETPOSTISSET('member_'.$key) ? GETPOST('member_'.$key, 'alpha') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key]));
1187 print '<tr><td>'.$langs->trans($value['label']).'</td><td><input type="text" name="member_'.$key.'" size="40" value="'.$val.'"></td></tr>';
1188 }
1189 }
1190
1191 // Birth Date
1192 print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1193 print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
1194 print "</td></tr>\n";
1195
1196 // Public profil
1197 print "<tr><td>";
1198 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1199 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1200 print "</td><td>\n";
1201 print $form->selectyesno("public", $object->public, 1, false, 0, 1);
1202 print "</td></tr>\n";
1203
1204 // Categories
1205 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1206 print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td><td>';
1207 print $form->selectCategories(Categorie::TYPE_MEMBER, 'memcats', $object);
1208 print "</td></tr>";
1209 }
1210
1211 // Other attributes
1212 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1213
1214 print '<tbody>';
1215 print "</table>\n";
1216
1217 print dol_get_fiche_end();
1218
1219 print $form->buttonsSaveCancel("AddMember");
1220
1221 print "</form>\n";
1222 }
1223
1224 // Edit mode
1225 if ($action == 'edit') {
1226 $res = $object->fetch($id);
1227 if ($res < 0) {
1228 dol_print_error($db, $object->error);
1229 exit;
1230 }
1231 $res = $object->fetch_optionals();
1232 if ($res < 0) {
1233 dol_print_error($db);
1234 exit;
1235 }
1236
1237 $adht = new AdherentType($db);
1238 $adht->fetch($object->typeid);
1239
1240 // We set country_id, and country_code, country of the chosen country
1241 $country = GETPOSTINT('country');
1242 if (!empty($country) || $object->country_id) {
1243 $sql = "SELECT rowid, code, label from ".MAIN_DB_PREFIX."c_country";
1244 $sql .= " WHERE rowid = ".(int) (!empty($country) ? $country : $object->country_id);
1245 $resql = $db->query($sql);
1246 if ($resql) {
1247 $obj = $db->fetch_object($resql);
1248 } else {
1249 dol_print_error($db);
1250 $obj = null;
1251 }
1252 if (is_object($obj)) {
1253 $object->country_id = $obj->rowid;
1254 $object->country_code = $obj->code;
1255 $object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
1256 }
1257 }
1258
1260
1261
1262 if ($conf->use_javascript_ajax) {
1263 print "\n".'<script type="text/javascript">';
1264 print 'jQuery(document).ready(function () {
1265 jQuery("#selectcountry_id").change(function() {
1266 document.formsoc.action.value="edit";
1267 document.formsoc.submit();
1268 });
1269 function initfieldrequired() {
1270 jQuery("#tdcompany").removeClass("fieldrequired");
1271 jQuery("#tdlastname").removeClass("fieldrequired");
1272 jQuery("#tdfirstname").removeClass("fieldrequired");
1273 if (jQuery(\'input[name="morphy"]:checked\').val() == \'mor\') {
1274 jQuery("#tdcompany").addClass("fieldrequired");
1275 }
1276 if (jQuery(\'input[name="morphy"]:checked\').val() == \'phy\') {
1277 jQuery("#tdlastname").addClass("fieldrequired");
1278 jQuery("#tdfirstname").addClass("fieldrequired");
1279 }
1280 }
1281 jQuery(\'input[name="morphy"]\').change(function() {
1282 initfieldrequired();
1283 });
1284 initfieldrequired();
1285 })';
1286 print '</script>'."\n";
1287 }
1288
1289 print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
1290 print '<input type="hidden" name="token" value="'.newToken().'" />';
1291 print '<input type="hidden" name="action" value="update" />';
1292 print '<input type="hidden" name="rowid" value="'.$id.'" />';
1293 print '<input type="hidden" name="statut" value="'.$object->status.'" />';
1294 if ($backtopage) {
1295 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1296 }
1297
1298 print dol_get_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
1299
1300 print '<table class="border centpercent">';
1301
1302 // Ref
1303 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td class="valeur">'.$object->ref.'</td></tr>';
1304
1305 // Login
1306 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1307 print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td><input type="text" name="login" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("login") ? GETPOST("login", 'alphanohtml', 2) : $object->login).'"></td></tr>';
1308 }
1309
1310 // Password
1311 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1312 print '<tr><td class="fieldrequired">'.$langs->trans("Password").'</td><td><input type="password" name="pass" class="minwidth300" maxlength="50" value="'.dol_escape_htmltag(GETPOSTISSET("pass") ? GETPOST("pass", 'password', 2) : '').'"></td></tr>';
1313 }
1314
1315 // Type
1316 print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
1317 if ($user->hasRight('adherent', 'creer')) {
1318 print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOSTINT("typeid") : $object->typeid), 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1319 } else {
1320 print $adht->getNomUrl(1);
1321 print '<input type="hidden" name="typeid" value="'.$object->typeid.'">';
1322 }
1323 print "</td></tr>";
1324
1325 // Morphy
1326 $morphys["phy"] = $langs->trans("Physical");
1327 $morphys["mor"] = $langs->trans("Moral");
1328 $checkednature = (GETPOSTISSET("morphy") ? GETPOST("morphy", 'alpha') : $object->morphy);
1329 print '<tr><td><span class="fieldrequired">'.$langs->trans("MemberNature").'</span></td><td>';
1330 print '<span id="spannature1" class="member-individual-back spannature paddinglarge marginrightonly"><label for="phisicalinput" class="valignmiddle">'.$morphys["phy"].'<input id="phisicalinput" class="flat checkforselect marginleftonly valignmiddle" type="radio" name="morphy" value="phy"'.($checkednature == "phy" ? ' checked="checked"' : '').'></label></span>';
1331 print '<span id="spannature1" class="member-company-back spannature paddinglarge marginrightonly"><label for="moralinput" class="valignmiddle">'.$morphys["mor"].'<input id="moralinput" class="flat checkforselect marginleftonly valignmiddle" type="radio" name="morphy" value="mor"'.($checkednature == "mor" ? ' checked="checked"' : '').'></label></span>';
1332 print "</td></tr>";
1333
1334 // Company
1335 print '<tr><td id="tdcompany">'.$langs->trans("Company").'</td><td><input type="text" name="societe" class="minwidth300" maxlength="128" value="'.(GETPOSTISSET("societe") ? GETPOST("societe", 'alphanohtml', 2) : $object->company).'"></td></tr>';
1336
1337 // Civility
1338 print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1339 print $formcompany->select_civility(GETPOSTISSET("civility_id") ? GETPOST("civility_id", 'alpha') : $object->civility_id, 'civility_id', 'maxwidth150', 1);
1340 print '</td>';
1341 print '</tr>';
1342
1343 // Lastname
1344 print '<tr><td id="tdlastname">'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("lastname") ? GETPOST("lastname", 'alphanohtml', 2) : $object->lastname).'"></td>';
1345 print '</tr>';
1346
1347 // Firstname
1348 print '<tr><td id="tdfirstname">'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname", 'alphanohtml', 3) : $object->firstname).'"></td>';
1349 print '</tr>';
1350
1351 // Gender
1352 print '<tr><td>'.$langs->trans("Gender").'</td>';
1353 print '<td>';
1354 $arraygender = array('man' => $langs->trans("Genderman"), 'woman' => $langs->trans("Genderwoman"), 'other' => $langs->trans("Genderother"));
1355 print $form->selectarray('gender', $arraygender, GETPOSTISSET('gender') ? GETPOST('gender', 'alphanohtml') : $object->gender, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1356 print '</td></tr>';
1357
1358 // Photo
1359 print '<tr><td>'.$langs->trans("Photo").'</td>';
1360 print '<td class="hideonsmartphone" valign="middle">';
1361 print $form->showphoto('memberphoto', $object)."\n";
1362 if ($caneditfieldmember) {
1363 if ($object->photo) {
1364 print "<br>\n";
1365 }
1366 print '<table class="nobordernopadding">';
1367 if ($object->photo) {
1368 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"><label for="photodelete" class="paddingleft">'.$langs->trans("Delete").'</label><br></td></tr>';
1369 }
1370 print '<tr><td>';
1371 $maxfilesizearray = getMaxFileSizeArray();
1372 $maxmin = $maxfilesizearray['maxmin'];
1373 if ($maxmin > 0) {
1374 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1375 }
1376 print '<input type="file" class="flat" name="photo" id="photoinput">';
1377 print '</td></tr>';
1378 print '</table>';
1379 }
1380 print '</td></tr>';
1381
1382 // EMail
1383 print '<tr><td>'.(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '</span>' : '').'</td>';
1384 print '<td>'.img_picto('', 'object_email', 'class="pictofixedwidth"').'<input type="text" name="member_email" class="minwidth300" maxlength="255" value="'.(GETPOSTISSET("member_email") ? GETPOST("member_email", 'alphanohtml', 2) : $object->email).'"></td></tr>';
1385
1386 // Website
1387 print '<tr><td>'.$form->editfieldkey('Web', 'member_url', GETPOST('member_url', 'alpha'), $object, 0).'</td>';
1388 print '<td>'.img_picto('', 'globe', 'class="pictofixedwidth"').'<input type="text" name="member_url" id="member_url" class="maxwidth200onsmartphone maxwidth500 widthcentpercentminusx " value="'.(GETPOSTISSET('member_url') ? GETPOST('member_url', 'alpha') : $object->url).'"></td></tr>';
1389
1390 // Address
1391 print '<tr><td>'.$langs->trans("Address").'</td><td>';
1392 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.'">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml', 2) : $object->address).'</textarea>';
1393 print '</td></tr>';
1394
1395 // Zip / Town
1396 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1397 print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode", 'alphanohtml', 2) : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1398 print ' ';
1399 print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town", 'alphanohtml', 2) : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1400 print '</td></tr>';
1401
1402 // Country
1403 //$object->country_id=$object->country_id?$object->country_id:$mysoc->country_id; // In edit mode we don't force to company country if not defined
1404 print '<tr><td>'.$langs->trans('Country').'</td><td>';
1405 print img_picto('', 'country', 'class="pictofixedwidth"');
1406 print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id, 'country_id');
1407 if ($user->admin) {
1408 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1409 }
1410 print '</td></tr>';
1411
1412 // State
1413 if (!getDolGlobalString('MEMBER_DISABLE_STATE')) {
1414 print '<tr><td>'.$langs->trans('State').'</td><td>';
1415 print img_picto('', 'state', 'class="pictofixedwidth"');
1416 print $formcompany->select_state($object->state_id, GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id);
1417 print '</td></tr>';
1418 }
1419
1420 // Pro phone
1421 print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1422 print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone" value="'.(GETPOSTISSET("phone") ? GETPOST("phone") : $object->phone).'"></td></tr>';
1423
1424 // Personal phone
1425 print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1426 print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone_perso" value="'.(GETPOSTISSET("phone_perso") ? GETPOST("phone_perso") : $object->phone_perso).'"></td></tr>';
1427
1428 // Mobile phone
1429 print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1430 print '<td>'.img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"').'<input type="text" name="phone_mobile" value="'.(GETPOSTISSET("phone_mobile") ? GETPOST("phone_mobile") : $object->phone_mobile).'"></td></tr>';
1431
1432 if (isModEnabled('socialnetworks')) {
1433 foreach ($socialnetworks as $key => $value) {
1434 if (!$value['active']) {
1435 break;
1436 }
1437 print '<tr><td>'.$langs->trans($value['label']).'</td><td><input type="text" name="'.$key.'" class="minwidth100" value="'.(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : (isset($object->socialnetworks[$key]) ? $object->socialnetworks[$key] : null)).'"></td></tr>';
1438 }
1439 }
1440
1441 // Birth Date
1442 print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1443 print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
1444 print "</td></tr>\n";
1445
1446 // Default language
1447 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1448 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
1449 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, array(), 1);
1450 print '</td>';
1451 print '</tr>';
1452 }
1453
1454 // Public profil
1455 print "<tr><td>";
1456 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1457 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1458 print "</td><td>\n";
1459 print $form->selectyesno("public", (GETPOSTISSET("public") ? GETPOST("public", 'alphanohtml', 2) : $object->public), 1, false, 0, 1);
1460 print "</td></tr>\n";
1461
1462 // Categories
1463 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1464 print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td>';
1465 print '<td>';
1466 print $form->selectCategories(Categorie::TYPE_MEMBER, 'memcats', $object);
1467 print "</td></tr>";
1468 }
1469
1470 // Third party Dolibarr
1471 if (isModEnabled('societe')) {
1472 print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2" class="valeur">';
1473 if ($object->socid) {
1474 $company = new Societe($db);
1475 $result = $company->fetch($object->socid);
1476 print $company->getNomUrl(1);
1477 } else {
1478 print $langs->trans("NoThirdPartyAssociatedToMember");
1479 }
1480 print '</td></tr>';
1481 }
1482
1483 // Login Dolibarr
1484 print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td colspan="2" class="valeur">';
1485 if ($object->user_id) {
1486 $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, (string) $object->user_id, 'none');
1487 } else {
1488 print $langs->trans("NoDolibarrAccess");
1489 }
1490 print '</td></tr>';
1491
1492 // Other attributes. Fields from hook formObjectOptions and Extrafields.
1493 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
1494
1495 print '</table>';
1496 print dol_get_fiche_end();
1497
1498 print $form->buttonsSaveCancel("Save", 'Cancel');
1499
1500 print '</form>';
1501 }
1502
1503 // View
1504 if ($id > 0 && $action != 'edit') {
1505 $res = $object->fetch($id);
1506 if ($res < 0) {
1507 dol_print_error($db, $object->error);
1508 exit;
1509 }
1510 $res = $object->fetch_optionals();
1511 if ($res < 0) {
1512 dol_print_error($db);
1513 exit;
1514 }
1515
1516 $adht = new AdherentType($db);
1517 $res = $adht->fetch($object->typeid);
1518 if ($res < 0) {
1519 dol_print_error($db);
1520 exit;
1521 }
1522
1523
1524 /*
1525 * Show tabs
1526 */
1528
1529 print dol_get_fiche_head($head, 'general', $langs->trans("Member"), -1, 'user', 0, '', '', 0, '', 1);
1530
1531 // Confirm create user
1532 if ($action == 'create_user') {
1533 $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login);
1534 if (empty($login)) {
1535 // Full firstname and name separated with a dot : firstname.name
1536 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1537 $login = dol_buildlogin($object->lastname, $object->firstname);
1538 }
1539 if (empty($login)) {
1540 $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4));
1541 }
1542
1543 // Create a form array
1544 $formquestion = array(
1545 array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
1546 );
1547 if (isModEnabled('societe') && $object->socid > 0) {
1548 $object->fetch_thirdparty();
1549 $formquestion[] = array('label' => $langs->trans("UserWillBe"), 'type' => 'radio', 'name' => 'internalorexternal', 'default' => 'external', 'values' => array('external' => $langs->trans("External").' - '.$langs->trans("LinkedToDolibarrThirdParty").' '.$object->thirdparty->getNomUrl(1, '', 0, 1), 'internal' => $langs->trans("Internal")));
1550 }
1551 $text = '';
1552 if (isModEnabled('societe') && $object->socid <= 0) {
1553 $text .= $langs->trans("UserWillBeInternalUser").'<br>';
1554 }
1555 $text .= $langs->trans("ConfirmCreateLogin");
1556 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1557 }
1558
1559 // Confirm create third party
1560 if ($action == 'create_thirdparty') {
1561 $companyalias = '';
1562 $fullname = $object->getFullName($langs);
1563
1564 if ($object->morphy == 'mor') {
1565 $companyname = (string) $object->company;
1566 if (!empty($fullname)) {
1567 $companyalias = (string) $fullname;
1568 }
1569 } else {
1570 $companyname = $fullname;
1571 if (!empty($object->company)) {
1572 $companyalias = (string) $object->company;
1573 }
1574 }
1575
1576 // Create a form array
1577 $formquestion = array(
1578 array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
1579 array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
1580 );
1581
1582 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 'yes');
1583 }
1584
1585 // Confirm validate member
1586 if ($action == 'valid') {
1587 $langs->load("mails");
1588
1589 $adht = new AdherentType($db);
1590 $adht->fetch($object->typeid);
1591
1592 $subject = '';
1593 $msg = '';
1594
1595 // Send subscription email
1596 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1597 $formmail = new FormMail($db);
1598 // Set output language
1599 $outputlangs = new Translate('', $conf);
1600 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
1601 // Load traductions files required by page
1602 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
1603 // Get email content from template
1604 $arraydefaultmessage = null;
1605 $labeltouse = getDolGlobalString("ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION");
1606
1607 if (!empty($labeltouse)) {
1608 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1609 }
1610
1611 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1612 $subject = (string) $arraydefaultmessage->topic;
1613 $msg = (string) $arraydefaultmessage->content;
1614 }
1615
1616 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1617 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1618 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1619 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
1620
1621 $tmp = $langs->trans("SendingAnEMailToMember");
1622 $tmp .= '<br>'.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'</b>, ';
1623 $tmp .= '<br>'.$langs->trans("MailRecipient").': <b>'.$object->email.'</b>';
1624 $helpcontent = '';
1625 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'<br>'."\n";
1626 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1627 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1628 $helpcontent .= $subjecttosend."\n";
1629 $helpcontent .= "<br>";
1630 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1631 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1632 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1633 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1634
1635 // Create form popup
1636 $formquestion = array();
1637 if ($object->email) {
1638 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? true : false));
1639 }
1640 if (isModEnabled('mailman') && getDolGlobalString('ADHERENT_USE_MAILMAN')) {
1641 $formquestion[] = array('type' => 'other', 'label' => $langs->transnoentitiesnoconv("SynchroMailManEnabled"), 'value' => '');
1642 }
1643 if (isModEnabled('mailman') && getDolGlobalString('ADHERENT_USE_SPIP')) {
1644 $formquestion[] = array('type' => 'other', 'label' => $langs->transnoentitiesnoconv("SynchroSpipEnabled"), 'value' => '');
1645 }
1646 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ValidateMember"), $langs->trans("ConfirmValidateMember"), "confirm_valid", $formquestion, 'yes', 1, 250);
1647 }
1648
1649 // Confirm resiliate
1650 if ($action == 'resiliate') {
1651 $langs->load("mails");
1652
1653 $adht = new AdherentType($db);
1654 $adht->fetch($object->typeid);
1655
1656 $subject = '';
1657 $msg = '';
1658
1659 // Send subscription email
1660 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1661 $formmail = new FormMail($db);
1662 // Set output language
1663 $outputlangs = new Translate('', $conf);
1664 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
1665 // Load traductions files required by page
1666 $outputlangs->loadLangs(array("main", "members"));
1667 // Get email content from template
1668 $arraydefaultmessage = null;
1669 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_CANCELATION');
1670
1671 if (!empty($labeltouse)) {
1672 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1673 }
1674
1675 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1676 $subject = (string) $arraydefaultmessage->topic;
1677 $msg = (string) $arraydefaultmessage->content;
1678 }
1679
1680 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1681 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1682 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1683 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs);
1684
1685 $tmp = $langs->trans("SendingAnEMailToMember");
1686 $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'</b>, ';
1687 $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1688 $helpcontent = '';
1689 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'<br>'."\n";
1690 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1691 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1692 $helpcontent .= $subjecttosend."\n";
1693 $helpcontent .= "<br>";
1694 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1695 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1696 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1697 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1698
1699 // Create an array
1700 $formquestion = array();
1701 if ($object->email) {
1702 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? 'true' : 'false'));
1703 }
1704 if ($backtopage) {
1705 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1706 }
1707 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ResiliateMember"), $langs->trans("ConfirmResiliateMember"), "confirm_resiliate", $formquestion, 'no', 1, 240);
1708 }
1709
1710 // Confirm exclude
1711 if ($action == 'exclude') {
1712 $langs->load("mails");
1713
1714 $adht = new AdherentType($db);
1715 $adht->fetch($object->typeid);
1716
1717 $subject = '';
1718 $msg = '';
1719
1720 // Send subscription email
1721 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1722 $formmail = new FormMail($db);
1723 // Set output language
1724 $outputlangs = new Translate('', $conf);
1725 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
1726 // Load traductions files required by page
1727 $outputlangs->loadLangs(array("main", "members"));
1728 // Get email content from template
1729 $arraydefaultmessage = null;
1730 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_EXCLUSION');
1731
1732 if (!empty($labeltouse)) {
1733 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1734 }
1735
1736 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1737 $subject = (string) $arraydefaultmessage->topic;
1738 $msg = (string) $arraydefaultmessage->content;
1739 }
1740
1741 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1742 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1743 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1744 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs);
1745
1746 $tmp = $langs->trans("SendingAnEMailToMember");
1747 $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'</b>, ';
1748 $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1749 $helpcontent = '';
1750 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'<br>'."\n";
1751 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1752 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1753 $helpcontent .= $subjecttosend."\n";
1754 $helpcontent .= "<br>";
1755 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1756 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1757 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1758 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1759
1760 // Create an array
1761 $formquestion = array();
1762 if ($object->email) {
1763 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? 'true' : 'false'));
1764 }
1765 if ($backtopage) {
1766 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1767 }
1768 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ExcludeMember"), $langs->trans("ConfirmExcludeMember"), "confirm_exclude", $formquestion, 'no', 1, 240);
1769 }
1770
1771 // Confirm remove member
1772 if ($action == 'delete') {
1773 $formquestion = array();
1774 if ($backtopage) {
1775 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1776 }
1777 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("DeleteMember"), $langs->trans("ConfirmDeleteMember"), "confirm_delete", $formquestion, 'no', 1);
1778 }
1779
1780 // Confirm add in spip
1781 if ($action == 'add_spip') {
1782 print $form->formconfirm("card.php?rowid=".$id, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip');
1783 }
1784 // Confirm removed from spip
1785 if ($action == 'del_spip') {
1786 print $form->formconfirm("card.php?rowid=$id", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip');
1787 }
1788
1789 $rowspan = 17;
1790 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1791 $rowspan++;
1792 }
1793 if (isModEnabled('societe')) {
1794 $rowspan++;
1795 }
1796
1797 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1798
1799 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
1800 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
1801 $morehtmlref .= '</a>';
1802
1803
1804 dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1805
1806 print '<div class="fichecenter">';
1807 print '<div class="fichehalfleft">';
1808
1809 print '<div class="underbanner clearboth"></div>';
1810 print '<table class="border tableforfield centpercent">';
1811
1812 // Login
1813 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1814 print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
1815 }
1816
1817 // Type
1818 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
1819 print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
1820
1821 // Morphy
1822 print '<tr><td>'.$langs->trans("MemberNature").'</td>';
1823 print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
1824 print '</tr>';
1825
1826 // Company
1827 print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
1828
1829 // Civility
1830 print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
1831 print '</tr>';
1832
1833 // Password
1834 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1835 print '<tr><td>'.$langs->trans("Password").'</td><td>';
1836 if ($object->pass) {
1837 print preg_replace('/./i', '*', $object->pass);
1838 } else {
1839 if ($user->admin) {
1840 print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
1841 }
1842 print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1843 }
1844 if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
1845 $langs->load("errors");
1846 $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
1847 print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
1848 }
1849 print '</td></tr>';
1850 }
1851
1852 // Date end subscription
1853 print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
1854 if ($object->datefin) {
1855 print dol_print_date($object->datefin, 'day');
1856 if ($object->hasDelay()) {
1857 print " ".img_warning($langs->trans("Late"));
1858 }
1859 } else {
1860 if ($object->need_subscription == 0) {
1861 print $langs->trans("SubscriptionNotNeeded");
1862 } elseif (!$adht->subscription) {
1863 print $langs->trans("SubscriptionNotRecorded");
1864 if (Adherent::STATUS_VALIDATED == $object->status) {
1865 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1866 }
1867 } else {
1868 print $langs->trans("SubscriptionNotReceived");
1869 if (Adherent::STATUS_VALIDATED == $object->status) {
1870 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1871 }
1872 }
1873 }
1874 print '</td></tr>';
1875
1876 print '</table>';
1877
1878 print '</div>';
1879
1880 print '<div class="fichehalfright">';
1881 print '<div class="underbanner clearboth"></div>';
1882
1883 print '<table class="border tableforfield centpercent">';
1884
1885 // Tags / Categories
1886 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1887 print '<tr><td>'.$langs->trans("Categories").'</td>';
1888 print '<td colspan="2">';
1889 print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
1890 print '</td></tr>';
1891 }
1892
1893 // Birth Date
1894 print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
1895
1896 // Default language
1897 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1898 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1899 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
1900 //$s=picto_from_langcode($object->default_lang);
1901 //print ($s?$s.' ':'');
1902 $langs->load("languages");
1903 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
1904 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
1905 print $labellang;
1906 print '</td></tr>';
1907 }
1908
1909 // Public
1910 print '<tr><td>';
1911 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1912 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1913 print '</td><td class="valeur">'.yn($object->public).'</td></tr>';
1914
1915 // Other attributes
1916 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1917
1918 // Third party Dolibarr
1919 if (isModEnabled('societe')) {
1920 print '<tr><td>';
1921 $editenable = $user->hasRight('adherent', 'creer');
1922 print $form->editfieldkey('LinkedToDolibarrThirdParty', 'thirdparty', '', $object, $editenable);
1923 print '</td><td colspan="2" class="valeur">';
1924 if ($action == 'editthirdparty') {
1925 $htmlname = 'socid';
1926 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
1927 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
1928 print '<input type="hidden" name="action" value="set'.$htmlname.'">';
1929 print '<input type="hidden" name="token" value="'.newToken().'">';
1930 print '<table class="nobordernopadding">';
1931 print '<tr><td>';
1932 print $form->select_company($object->socid, 'socid', '', 1);
1933 print '</td>';
1934 print '<td class="left"><input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans("Modify").'"></td>';
1935 print '</tr></table></form>';
1936 } else {
1937 if ($object->socid) {
1938 $company = new Societe($db);
1939 $result = $company->fetch($object->socid);
1940 print $company->getNomUrl(1);
1941
1942 // Show link to invoices
1943 $tmparray = $company->getOutstandingBills('customer');
1944 if (!empty($tmparray['refs'])) {
1945 print ' - '.img_picto($langs->trans("Invoices"), 'bill', 'class="paddingright"').'<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->socid.'">'.$langs->trans("Invoices").' ('.count($tmparray['refs']).')';
1946 // TODO Add alert if warning on at least one invoice late
1947 print '</a>';
1948 }
1949 } else {
1950 print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
1951 }
1952 }
1953 print '</td></tr>';
1954 }
1955
1956 // Login Dolibarr - Link to user
1957 print '<tr><td>';
1958 $editenable = $user->hasRight('adherent', 'creer') && $user->hasRight('user', 'user', 'creer');
1959 print $form->editfieldkey('LinkedToDolibarrUser', 'login', '', $object, (int) $editenable);
1960 print '</td><td colspan="2" class="valeur">';
1961 if ($action == 'editlogin') {
1962 $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, (string) $object->user_id, 'userid', array());
1963 } else {
1964 if ($object->user_id) {
1965 $linkeduser = new User($db);
1966 $linkeduser->fetch($object->user_id);
1967 print $linkeduser->getNomUrl(-1);
1968 } else {
1969 print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1970 }
1971 }
1972 print '</td></tr>';
1973
1974 print "</table>\n";
1975
1976 print "</div></div>\n";
1977 print '<div class="clearboth"></div>';
1978
1979 print dol_get_fiche_end();
1980
1981
1982 /*
1983 * Action bar
1984 */
1985
1986 print '<div class="tabsAction">';
1987 $isinspip = 0;
1988 $parameters = array();
1989 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1990 if (empty($reshook)) {
1991 if ($action != 'editlogin' && $action != 'editthirdparty') {
1992 // Send
1993 if (empty($user->socid)) {
1994 if (Adherent::STATUS_VALIDATED == $object->status) {
1995 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
1996 }
1997 }
1998
1999 // Send card by email
2000 // TODO Remove this to replace with a template
2001 /*
2002 if ($user->hasRight('adherent', 'creer')) {
2003 if (Adherent::STATUS_VALIDATED == $object->status) {
2004 if ($object->email) print '<a class="butAction" href="card.php?rowid='.$object->id.'&action=sendinfo">'.$langs->trans("SendCardByMail")."</a>\n";
2005 else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendCardByMail")."</a>\n";
2006 } else {
2007 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("SendCardByMail")."</span>";
2008 }
2009 } else {
2010 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("SendCardByMail")."</span>";
2011 }*/
2012
2013 // Modify
2014 if ($user->hasRight('adherent', 'creer')) {
2015 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
2016 } else {
2017 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Modify").'</span>'."\n";
2018 }
2019
2020 // Validate
2021 if (Adherent::STATUS_DRAFT == $object->status) {
2022 if ($user->hasRight('adherent', 'creer')) {
2023 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=valid&token='.newToken().'">'.$langs->trans("Validate").'</a>'."\n";
2024 } else {
2025 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span>'."\n";
2026 }
2027 }
2028
2029 // Reactivate
2031 if ($user->hasRight('adherent', 'creer')) {
2032 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=valid&token='.newToken().'">'.$langs->trans("Reenable")."</a>\n";
2033 } else {
2034 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Reenable").'</span>'."\n";
2035 }
2036 }
2037
2038 // Resiliate
2039 if (Adherent::STATUS_VALIDATED == $object->status) {
2040 if ($user->hasRight('adherent', 'supprimer')) {
2041 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=resiliate&token='.newToken().'">'.$langs->trans("Resiliate")."</a></span>\n";
2042 } else {
2043 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Resiliate").'</span>'."\n";
2044 }
2045 }
2046
2047 // Exclude
2048 if (Adherent::STATUS_VALIDATED == $object->status) {
2049 if ($user->hasRight('adherent', 'supprimer')) {
2050 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=exclude&token='.newToken().'">'.$langs->trans("Exclude")."</a></span>\n";
2051 } else {
2052 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Exclude").'</span>'."\n";
2053 }
2054 }
2055
2056 // Create third party
2057 if (isModEnabled('societe') && !$object->socid) {
2058 if ($user->hasRight('societe', 'creer')) {
2059 if (Adherent::STATUS_DRAFT != $object->status) {
2060 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.((int) $object->id).'&action=create_thirdparty&token='.newToken().'" title="'.dol_escape_htmltag($langs->trans("CreateDolibarrThirdPartyDesc")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a>'."\n";
2061 } else {
2062 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a>'."\n";
2063 }
2064 } else {
2065 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrThirdParty").'</span>'."\n";
2066 }
2067 }
2068
2069 // Create user
2070 if (!$user->socid && !$object->user_id) {
2071 if ($user->hasRight('user', 'user', 'creer')) {
2072 if (Adherent::STATUS_DRAFT != $object->status) {
2073 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.((int) $object->id).'&action=create_user&token='.newToken().'" title="'.dol_escape_htmltag($langs->trans("CreateDolibarrLoginDesc")).'">'.$langs->trans("CreateDolibarrLogin").'</a>'."\n";
2074 } else {
2075 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrLogin").'</a>'."\n";
2076 }
2077 } else {
2078 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin").'</span>'."\n";
2079 }
2080 }
2081
2082 // Action SPIP
2083 if (isModEnabled('mailmanspip') && getDolGlobalString('ADHERENT_USE_SPIP')) {
2084 $isinspip = $mailmanspip->is_in_spip($object);
2085
2086 if ($isinspip == 1) {
2087 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=del_spip&token='.newToken().'">'.$langs->trans("DeleteIntoSpip").'</a>'."\n";
2088 }
2089 if ($isinspip == 0) {
2090 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=add_spip&token='.newToken().'">'.$langs->trans("AddIntoSpip").'</a>'."\n";
2091 }
2092 }
2093
2094 // Delete
2095 if ($user->hasRight('adherent', 'supprimer')) {
2096 print '<a class="butActionDelete" href="card.php?rowid='.((int) $object->id).'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
2097 } else {
2098 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Delete").'</span>'."\n";
2099 }
2100 }
2101 }
2102 print '</div>';
2103
2104 if ($isinspip == -1) {
2105 print '<br><br><span class="error">'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.'</span>';
2106 }
2107
2108
2109 // Select mail models is same action as presend
2110 if (GETPOST('modelselected')) {
2111 $action = 'presend';
2112 }
2113
2114 if ($action != 'presend') {
2115 print '<div class="fichecenter"><div class="fichehalfleft">';
2116 print '<a name="builddoc"></a>'; // ancre
2117
2118 // Generated documents
2119 $filename = dol_sanitizeFileName($object->ref);
2120 $filedir = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member');
2121 $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
2122 $genallowed = $user->hasRight('adherent', 'lire');
2123 $delallowed = $user->hasRight('adherent', 'creer');
2124
2125 print $formfile->showdocuments('member', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', (empty($object->default_lang) ? '' : $object->default_lang), '', $object);
2126 $somethingshown = $formfile->numoffiles;
2127
2128 // Show links to link elements
2129 //$tmparray = $form->showLinkToObjectBlock($object, null, array('subscription'), 1);
2130 //$somethingshown = $form->showLinkedObjectBlock($object, '');
2131
2132 // Show online payment link
2133 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
2134 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2135 $validpaymentmethod = getValidOnlinePaymentMethods('');
2136 $useonlinepayment = count($validpaymentmethod);
2137
2138 if ($useonlinepayment) {
2139 print '<br>';
2140 if (empty($amount)) { // Take the maximum amount among what the member is supposed to pay / has paid in the past
2141 $amount = max($adht->amount, $object->first_subscription_amount, $object->last_subscription_amount);
2142 }
2143 if (empty($amount)) {
2144 $amount = 0;
2145 }
2146 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2147 print showOnlinePaymentUrl('membersubscription', $object->ref, $amount);
2148 }
2149
2150 print '</div><div class="fichehalfright">';
2151
2152 $MAXEVENT = 10;
2153
2154 $morehtmlcenter = '';
2155 $messagingUrl = DOL_URL_ROOT.'/adherents/messaging.php?rowid='.$object->id;
2156 $morehtmlcenter .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
2157 $morehtmlcenter .= dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/adherents/agenda.php?id='.$object->id);
2158
2159 // List of actions on element
2160 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2161 $formactions = new FormActions($db);
2162 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter);
2163
2164 print '</div></div>';
2165 }
2166
2167 // Presend form
2168 $modelmail = 'member';
2169 $defaulttopic = 'CardContent';
2170 $diroutput = $conf->member->dir_output;
2171 $trackid = 'mem'.$object->id;
2172
2173 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2174 }
2175}
2176
2177// End of page
2178llxFooter();
2179$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage members of a foundation.
const STATUS_EXCLUDED
Excluded.
const STATUS_DRAFT
Draft status.
const STATUS_RESILIATED
Resiliated (membership end and was not renew)
const STATUS_VALIDATED
Validated status.
Class to manage members type.
Class to manage canvas.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class to manage mailman and spip.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
isValidUrl($url, $http=0, $pass=0, $port=0, $path=0, $query=0, $anchor=0)
Url string validation <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor].
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
div refaddress div address
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object information.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.