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-2025 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'])) {
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 if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) {
418 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
419 } else {
420 // Create thumbs
421 $object->addThumbs($newfile);
422 }
423 }
424 } else {
425 setEventMessages("ErrorBadImageFormat", null, 'errors');
426 }
427 } else {
428 switch ($_FILES['photo']['error']) {
429 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
430 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
431 $errors[] = "ErrorFileSizeTooLarge";
432 break;
433 case 3: //uploaded file was only partially uploaded
434 $errors[] = "ErrorFilePartiallyUploaded";
435 break;
436 }
437 }
438
439 $rowid = $object->id;
440 $id = $object->id;
441 $action = '';
442
443 if (!empty($backtopage)) {
444 header("Location: ".$backtopage);
445 exit;
446 }
447 } else {
448 setEventMessages($object->error, $object->errors, 'errors');
449 $action = '';
450 }
451 } else {
452 $action = 'edit';
453 }
454 } else {
455 $action = 'edit';
456 }
457 }
458
459 if ($action == 'add' && $user->hasRight('adherent', 'creer')) {
460 if ($canvas) {
461 $object->canvas = $canvas;
462 }
463 $birthdate = '';
464 if (GETPOSTISSET("birthday") && GETPOST("birthday") && GETPOSTISSET("birthmonth") && GETPOST("birthmonth") && GETPOSTISSET("birthyear") && GETPOST("birthyear")) {
465 $birthdate = dol_mktime(12, 0, 0, GETPOSTINT("birthmonth"), GETPOSTINT("birthday"), GETPOSTINT("birthyear"));
466 }
467 $datesubscription = '';
468 if (GETPOSTISSET("reday") && GETPOSTISSET("remonth") && GETPOSTISSET("reyear")) {
469 $datesubscription = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
470 }
471
472 $typeid = GETPOSTINT("typeid");
473 $civility_id = GETPOST("civility_id", 'alphanohtml');
474 $lastname = GETPOST("lastname", 'alphanohtml');
475 $firstname = GETPOST("firstname", 'alphanohtml');
476 $gender = GETPOST("gender", 'alphanohtml');
477 $societe = GETPOST("societe", 'alphanohtml');
478 $address = GETPOST("address", 'alphanohtml');
479 $zip = GETPOST("zipcode", 'alphanohtml');
480 $town = GETPOST("town", 'alphanohtml');
481 $state_id = GETPOSTINT("state_id");
482 $country_id = GETPOSTINT("country_id");
483
484 $phone = GETPOST("phone", 'alpha');
485 $phone_perso = GETPOST("phone_perso", 'alpha');
486 $phone_mobile = GETPOST("phone_mobile", 'alpha');
487 $email = preg_replace('/\s+/', '', GETPOST("member_email", 'aZ09arobase'));
488 $url = trim(GETPOST('url', 'url'));
489 $login = GETPOST("member_login", 'alphanohtml');
490 $pass = GETPOST("password", 'password'); // For password, we use 'none'
491 $photo = GETPOST("photo", 'alphanohtml');
492 $morphy = GETPOST("morphy", 'alphanohtml');
493 $public = GETPOSTINT("public");
494
495 $userid = GETPOSTINT("userid");
496 $socid = GETPOSTINT("socid");
497 $default_lang = GETPOST('default_lang', 'alpha');
498
499 $object->civility_id = $civility_id;
500 $object->firstname = $firstname;
501 $object->lastname = $lastname;
502 $object->gender = $gender;
503 $object->societe = $societe; // deprecated
504 $object->company = $societe;
505 $object->address = $address;
506 $object->zip = $zip;
507 $object->town = $town;
508 $object->state_id = $state_id;
509 $object->country_id = $country_id;
510 $object->phone = $phone;
511 $object->phone_perso = $phone_perso;
512 $object->phone_mobile = $phone_mobile;
513 $object->socialnetworks = array();
514 if (isModEnabled('socialnetworks')) {
515 foreach ($socialnetworks as $key => $value) {
516 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
517 $object->socialnetworks[$key] = GETPOST("member_".$key, 'alphanohtml');
518 }
519 }
520 }
521
522 $object->email = $email;
523 $object->url = $url;
524 $object->login = $login;
525 $object->pass = $pass;
526 $object->birth = $birthdate;
527 $object->photo = $photo;
528 $object->typeid = $typeid;
529 //$object->note = $comment;
530 $object->morphy = $morphy;
531 $object->user_id = $userid;
532 $object->socid = $socid;
533 $object->public = $public;
534 $object->default_lang = $default_lang;
535 // Fill array 'array_options' with data from add form
536 $ret = $extrafields->setOptionalsFromPost(null, $object);
537 if ($ret < 0) {
538 $error++;
539 }
540
541 // Check parameters
542 if (empty($morphy) || $morphy == "-1") {
543 $error++;
544 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MemberNature")), null, 'errors');
545 }
546 // Tests if the login already exists
547 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
548 if (empty($login)) {
549 $error++;
550 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")), null, 'errors');
551 } else {
552 $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'";
553 $result = $db->query($sql);
554 $num = 0;
555 if ($result) {
556 $num = $db->num_rows($result);
557 }
558 if ($num) {
559 $error++;
560 $langs->load("errors");
561 setEventMessages($langs->trans("ErrorLoginAlreadyExists", $login), null, 'errors');
562 }
563 }
564 if (empty($pass)) {
565 $error++;
566 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Password")), null, 'errors');
567 }
568 }
569 if ($morphy == 'mor' && empty($societe)) {
570 $error++;
571 $langs->load("errors");
572 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors');
573 }
574 if ($morphy != 'mor' && empty($lastname)) {
575 $error++;
576 $langs->load("errors");
577 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors');
578 }
579 if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) {
580 $error++;
581 $langs->load("errors");
582 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors');
583 }
584 if (!($typeid > 0)) { // Keep () before !
585 $error++;
586 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
587 }
588 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($email)) {
589 $error++;
590 $langs->load("errors");
591 setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
592 }
593 if (!empty($object->url) && !isValidUrl($object->url)) {
594 $langs->load("errors");
595 setEventMessages($langs->trans("ErrorBadUrl", $object->url), null, 'errors');
596 }
597 $public = 0;
598 if (isset($public)) {
599 $public = 1;
600 }
601
602 if (!$error) {
603 $db->begin();
604
605 // Create the member
606 $result = $object->create($user);
607 if ($result > 0) {
608 // Foundation categories
609 $memcats = GETPOST('memcats', 'array');
610 $object->setCategories($memcats);
611
612 $db->commit();
613
614 $rowid = $object->id;
615 $id = $object->id;
616
617 $backtopage = preg_replace('/__ID__/', (string) $id, $backtopage);
618 } else {
619 $db->rollback();
620
621 $error++;
622 setEventMessages($object->error, $object->errors, 'errors');
623 }
624
625 // Auto-create thirdparty on member creation
626 if (getDolGlobalString('ADHERENT_DEFAULT_CREATE_THIRDPARTY')) {
627 if ($result > 0) {
628 // Create third party out of a member
629 $company = new Societe($db);
630 $result = $company->create_from_member($object);
631 if ($result < 0) {
632 $langs->load("errors");
633 setEventMessages($langs->trans($company->error), null, 'errors');
634 setEventMessages($company->error, $company->errors, 'errors');
635 }
636 } else {
637 setEventMessages($object->error, $object->errors, 'errors');
638 }
639 }
640 }
641 $action = ($result < 0 || !$error) ? '' : 'create';
642
643 if (!$error && $backtopage) {
644 header("Location: ".$backtopage);
645 exit;
646 }
647 }
648
649 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_delete' && $confirm == 'yes') {
650 $result = $object->delete($user);
651 if ($result > 0) {
652 setEventMessages($langs->trans("RecordDeleted"), null, 'errors');
653 if (!empty($backtopage) && !preg_match('/'.preg_quote($_SERVER["PHP_SELF"], '/').'/', $backtopage)) {
654 header("Location: ".$backtopage);
655 exit;
656 } else {
657 header("Location: list.php");
658 exit;
659 }
660 } else {
661 setEventMessages($object->error, null, 'errors');
662 }
663 }
664
665 if ($user->hasRight('adherent', 'creer') && $action == 'confirm_valid' && $confirm == 'yes') {
666 $error = 0;
667
668 $db->begin();
669
670 $adht = new AdherentType($db);
671 $adht->fetch($object->typeid);
672
673 $result = $object->validate($user);
674
675 if ($result >= 0 && !count($object->errors)) {
676 // Send confirmation email (according to parameters of member type. Otherwise generic)
677 if ($object->email && GETPOST("send_mail")) {
678 $subject = '';
679 $msg = '';
680
681 // Send subscription email
682 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
683 $formmail = new FormMail($db);
684 // Set output language
685 $outputlangs = new Translate('', $conf);
686 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
687 // Load traductions files required by page
688 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
689 // Get email content from template
690 $arraydefaultmessage = null;
691 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION');
692
693 if (!empty($labeltouse)) {
694 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
695 }
696
697 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
698 $subject = (string) $arraydefaultmessage->topic;
699 $msg = (string) $arraydefaultmessage->content;
700 }
701
702 if (empty($labeltouse) || (int) $labeltouse === -1) {
703 //fallback on the old configuration.
704 $langs->load("errors");
705 setEventMessages('<a href="'.DOL_URL_ROOT.'/adherents/admin/member_emails.php">'.$langs->trans('WarningMandatorySetupNotComplete').'</a>', null, 'errors');
706 $error++;
707 } else {
708 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
709 complete_substitutions_array($substitutionarray, $outputlangs, $object);
710 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
711 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
712
713 $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
714
715 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
716 if ($result < 0) {
717 $error++;
718 setEventMessages($object->error, $object->errors, 'errors');
719 }
720 }
721 }
722 } else {
723 $error++;
724 setEventMessages($object->error, $object->errors, 'errors');
725 }
726
727 if (!$error) {
728 $db->commit();
729 } else {
730 $db->rollback();
731 }
732 $action = '';
733 }
734
735 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_resiliate') {
736 $error = 0;
737
738 if ($confirm == 'yes') {
739 $adht = new AdherentType($db);
740 $adht->fetch($object->typeid);
741
742 $result = $object->resiliate($user);
743
744 if ($result >= 0 && !count($object->errors)) {
745 if ($object->email && GETPOST("send_mail")) {
746 $subject = '';
747 $msg = '';
748
749 // Send subscription email
750 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
751 $formmail = new FormMail($db);
752 // Set output language
753 $outputlangs = new Translate('', $conf);
754 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
755 // Load traductions files required by page
756 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
757 // Get email content from template
758 $arraydefaultmessage = null;
759 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_CANCELATION');
760
761 if (!empty($labeltouse)) {
762 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
763 }
764
765 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
766 $subject = (string) $arraydefaultmessage->topic;
767 $msg = (string) $arraydefaultmessage->content;
768 }
769
770 if (empty($labeltouse) || (int) $labeltouse === -1) {
771 //fallback on the old configuration.
772 setEventMessages('WarningMandatorySetupNotComplete', null, 'errors');
773 $error++;
774 } else {
775 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
776 complete_substitutions_array($substitutionarray, $outputlangs, $object);
777 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
778 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs);
779
780 $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
781
782 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
783 if ($result < 0) {
784 $error++;
785 setEventMessages($object->error, $object->errors, 'errors');
786 }
787 }
788 }
789 } else {
790 $error++;
791
792 setEventMessages($object->error, $object->errors, 'errors');
793 $action = '';
794 }
795 }
796 if (!empty($backtopage) && !$error) {
797 header("Location: ".$backtopage);
798 exit;
799 }
800 }
801
802 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_exclude') {
803 $error = 0;
804
805 if ($confirm == 'yes') {
806 $adht = new AdherentType($db);
807 $adht->fetch($object->typeid);
808
809 $result = $object->exclude($user);
810
811 if ($result >= 0 && !count($object->errors)) {
812 if ($object->email && GETPOST("send_mail")) {
813 $subject = '';
814 $msg = '';
815
816 // Send subscription email
817 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
818 $formmail = new FormMail($db);
819 // Set output language
820 $outputlangs = new Translate('', $conf);
821 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
822 // Load traductions files required by page
823 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
824 // Get email content from template
825 $arraydefaultmessage = null;
826 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_EXCLUSION');
827
828 if (!empty($labeltouse)) {
829 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
830 }
831
832 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
833 $subject = (string) $arraydefaultmessage->topic;
834 $msg = (string) $arraydefaultmessage->content;
835 }
836
837 if (empty($labeltouse) || (int) $labeltouse === -1) {
838 //fallback on the old configuration.
839 setEventMessages('WarningMandatorySetupNotComplete', null, 'errors');
840 $error++;
841 } else {
842 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
843 complete_substitutions_array($substitutionarray, $outputlangs, $object);
844 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
845 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs);
846
847 $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
848
849 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
850 if ($result < 0) {
851 $error++;
852 setEventMessages($object->error, $object->errors, 'errors');
853 }
854 }
855 }
856 } else {
857 $error++;
858
859 setEventMessages($object->error, $object->errors, 'errors');
860 $action = '';
861 }
862 }
863 if (!empty($backtopage) && !$error) {
864 header("Location: ".$backtopage);
865 exit;
866 }
867 }
868
869 if ($action == 'update_extras' && $permissiontoeditextra) {
870 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
871 $attribute_name = GETPOST('attribute', 'aZ09');
872
873 // Fill array 'array_options' with data from update form
874 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
875 if ($ret < 0) {
876 $error++;
877 }
878 if (!$error) {
879 $result = $object->updateExtraField($attribute_name, 'MEMBER_MODIFY');
880 if ($result < 0) {
881 setEventMessages($object->error, $object->errors, 'errors');
882 $error++;
883 }
884 }
885 if ($error) {
886 $action = 'edit_extras';
887 }
888 }
889
890 // SPIP Management
891 if (is_object($mailmanspip)) {
892 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_del_spip' && $confirm == 'yes') {
893 if (!count($object->errors)) {
894 if (!$mailmanspip->del_to_spip($object)) {
895 setEventMessages($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, null, 'errors');
896 }
897 }
898 }
899
900 if ($user->hasRight('adherent', 'creer') && $action == 'confirm_add_spip' && $confirm == 'yes') {
901 if (!count($object->errors)) {
902 if (!$mailmanspip->add_to_spip($object)) {
903 setEventMessages($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, null, 'errors');
904 }
905 }
906 }
907 }
908
909 // Actions when printing a doc from card
910 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
911
912 // Actions to build doc
913 $upload_dir = $conf->member->dir_output;
914 $permissiontoadd = $user->hasRight('adherent', 'creer');
915 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
916
917 // Actions to send emails
918 $triggersendname = 'MEMBER_SENTBYMAIL';
919 $paramname = 'id';
920 $mode = 'emailfrommember';
921 $trackid = 'mem'.$object->id;
922 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
923}
924
925
926/*
927 * View
928 */
929
930$form = new Form($db);
931$formfile = new FormFile($db);
932$formadmin = new FormAdmin($db);
933$formcompany = new FormCompany($db);
934
935$title = $langs->trans("Member")." - ".$langs->trans("Card");
936$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
937
938llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-card');
939
940$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
941
942if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
943 // -----------------------------------------
944 // When used with CANVAS
945 // -----------------------------------------
946 if (empty($object->error) && $id) {
947 $object = new Adherent($db);
948 $result = $object->fetch($id);
949 if ($result <= 0) {
950 dol_print_error(null, $object->error);
951 }
952 }
953 $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
954 $objcanvas->display_canvas($action); // Show template
955} else {
956 // -----------------------------------------
957 // When used in standard mode
958 // -----------------------------------------
959
960 // Create mode
961 if ($action == 'create') {
962 $object->canvas = $canvas;
963 $object->state_id = GETPOSTINT('state_id');
964
965 // We set country_id, country_code and country for the selected country
966 $object->country_id = GETPOSTINT('country_id') ? GETPOSTINT('country_id') : $mysoc->country_id;
967 if ($object->country_id) {
968 $tmparray = getCountry($object->country_id, 'all');
969 $object->country_code = $tmparray['code'];
970 $object->country = $tmparray['label'];
971 }
972
973 $soc = new Societe($db);
974 if (!empty($socid)) {
975 if ($socid > 0) {
976 $soc->fetch($socid);
977 }
978
979 if (!($soc->id > 0)) {
980 $langs->load("errors");
981 print($langs->trans('ErrorRecordNotFound'));
982 exit;
983 }
984 }
985
986 $adht = new AdherentType($db);
987
988 print load_fiche_titre($langs->trans("NewMember"), '', $object->picto);
989
990 if ($conf->use_javascript_ajax) {
991 print "\n".'<script type="text/javascript">'."\n";
992 print 'jQuery(document).ready(function () {
993 jQuery("#selectcountry_id").change(function() {
994 document.formsoc.action.value="create";
995 document.formsoc.submit();
996 });
997 function initfieldrequired() {
998 jQuery("#tdcompany").removeClass("fieldrequired");
999 jQuery("#tdlastname").removeClass("fieldrequired");
1000 jQuery("#tdfirstname").removeClass("fieldrequired");
1001 if (jQuery(\'input[name="morphy"]:checked\').val() == \'mor\') {
1002 jQuery("#tdcompany").addClass("fieldrequired");
1003 }
1004 if (jQuery(\'input[name="morphy"]:checked\').val() == \'phy\') {
1005 jQuery("#tdlastname").addClass("fieldrequired");
1006 jQuery("#tdfirstname").addClass("fieldrequired");
1007 }
1008 }
1009 jQuery(\'input[name="morphy"]\').change(function() {
1010 initfieldrequired();
1011 });
1012 initfieldrequired();
1013 })';
1014 print '</script>'."\n";
1015 }
1016
1017 print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
1018 print '<input type="hidden" name="token" value="'.newToken().'">';
1019 print '<input type="hidden" name="action" value="add">';
1020 print '<input type="hidden" name="socid" value="'.$socid.'">';
1021 if ($backtopage) {
1022 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1023 }
1024
1025 print dol_get_fiche_head(array());
1026
1027 print '<table class="border centpercent">';
1028 print '<tbody>';
1029
1030 // Login
1031 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1032 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>';
1033 }
1034
1035 // Password
1036 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1037 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1038 $generated_password = getRandomPassword(false);
1039 print '<tr><td><span class="fieldrequired">'.$langs->trans("Password").'</span></td><td>';
1040 print '<input type="text" class="minwidth300" maxlength="50" name="password" value="'.dol_escape_htmltag($generated_password).'">';
1041 print '</td></tr>';
1042 }
1043
1044 // Type
1045 print '<tr><td class="fieldrequired">'.$langs->trans("MemberType").'</td><td>';
1046 $listetype = $adht->liste_array(1);
1047 print img_picto('', $adht->picto, 'class="pictofixedwidth"');
1048 if (count($listetype)) {
1049 print $form->selectarray("typeid", $listetype, (GETPOSTINT('typeid') ? GETPOSTINT('typeid') : $typeid), (count($listetype) > 1 ? 1 : 0), 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1050 } else {
1051 print '<span class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</span>';
1052 }
1053 if ($user->hasRight('member', 'configurer')) {
1054 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>';
1055 }
1056 print "</td>\n";
1057
1058 // Morphy
1059 $morphys = array();
1060 $morphys["phy"] = $langs->trans("Physical");
1061 $morphys["mor"] = $langs->trans("Moral");
1062 $checkednature = GETPOST("morphy", 'alpha');
1063
1064 print '<tr><td class="fieldrequired">'.$langs->trans("MemberNature")."</td><td>\n";
1065 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>';
1066 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>';
1067
1068 // Add js to manage the background of nature
1069 if ($conf->use_javascript_ajax) {
1070 print '<script>
1071 function refreshNatureCss() {
1072 jQuery(".spannature").each(function( index ) {
1073 console.log(jQuery("#spannature"+(index+1)+" .checkforselect").is(":checked"));
1074 if (jQuery("#spannature"+(index+1)+" .checkforselect").is(":checked")) {
1075 if (index+1 == 1) {
1076 jQuery("#spannature"+(index+1)).addClass("member-individual-back").removeClass("nonature-back");
1077 }
1078 if (index+1 == 2) {
1079 jQuery("#spannature"+(index+1)).addClass("member-company-back").removeClass("nonature-back");
1080 }
1081 } else {
1082 jQuery("#spannature"+(index+1)).removeClass("member-individual-back").removeClass("member-company-back").addClass("nonature-back");
1083 }
1084 });
1085 }
1086 jQuery(".spannature").click(function(){
1087 console.log("We click on a nature");
1088 refreshNatureCss();
1089 });
1090 refreshNatureCss();
1091 </script>';
1092 }
1093
1094 print "</td>\n";
1095
1096 // Company
1097 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>';
1098
1099 // Civility
1100 print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1101 print $formcompany->select_civility(GETPOSTINT('civility_id') ? GETPOSTINT('civility_id') : $object->civility_id, 'civility_id', 'maxwidth150', 1).'</td>';
1102 print '</tr>';
1103
1104 // Lastname
1105 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>';
1106 print '</tr>';
1107
1108 // Firstname
1109 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>';
1110 print '</tr>';
1111
1112 // Gender
1113 print '<tr><td>'.$langs->trans("Gender").'</td>';
1114 print '<td>';
1115 $arraygender = array('man' => $langs->trans("Genderman"), 'woman' => $langs->trans("Genderwoman"), 'other' => $langs->trans("Genderother"));
1116 print $form->selectarray('gender', $arraygender, GETPOST('gender', 'alphanohtml'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1117 print '</td></tr>';
1118
1119 // EMail
1120 print '<tr><td>'.(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '</span>' : '').'</td>';
1121 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>';
1122
1123 // Website
1124 print '<tr><td>'.$form->editfieldkey('Web', 'member_url', GETPOST('member_url', 'alpha'), $object, 0).'</td>';
1125 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>';
1126
1127 // Address
1128 print '<tr><td class="tdtop">'.$langs->trans("Address").'</td><td>';
1129 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="2">'.(GETPOSTISSET('address') ? GETPOST('address', 'alphanohtml') : $soc->address).'</textarea>';
1130 print '</td></tr>';
1131
1132 // Zip / Town
1133 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1134 print $formcompany->select_ziptown((GETPOSTISSET('zipcode') ? GETPOST('zipcode', 'alphanohtml') : $soc->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1135 print ' ';
1136 print $formcompany->select_ziptown((GETPOSTISSET('town') ? GETPOST('town', 'alphanohtml') : $soc->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1137 print '</td></tr>';
1138
1139 // Country
1140 if (empty($soc->country_id)) {
1141 $soc->country_id = $mysoc->country_id;
1142 $soc->country_code = $mysoc->country_code;
1143 $soc->state_id = $mysoc->state_id;
1144 }
1145 print '<tr><td>'.$langs->trans('Country').'</td><td>';
1146 print img_picto('', 'country', 'class="pictofixedwidth"');
1147 print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'alpha') : $soc->country_id, 'country_id');
1148 if ($user->admin) {
1149 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1150 }
1151 print '</td></tr>';
1152
1153 // State
1154 if (!getDolGlobalString('MEMBER_DISABLE_STATE')) {
1155 print '<tr><td>'.$langs->trans('State').'</td><td>';
1156 if ($soc->country_id || GETPOSTISSET('country_id')) {
1157 print img_picto('', 'state', 'class="pictofixedwidth"');
1158 print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOSTINT('state_id') : $soc->state_id, GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $soc->country_code);
1159 } else {
1160 print $countrynotdefined;
1161 }
1162 print '</td></tr>';
1163 }
1164
1165 // Pro phone
1166 print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1167 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>';
1168
1169 // Personal phone
1170 print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1171 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>';
1172
1173 // Mobile phone
1174 print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1175 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>';
1176
1177 if (isModEnabled('socialnetworks')) {
1178 foreach ($socialnetworks as $key => $value) {
1179 if (!$value['active']) {
1180 break;
1181 }
1182 $val = (GETPOSTISSET('member_'.$key) ? GETPOST('member_'.$key, 'alpha') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key]));
1183 print '<tr><td>'.$langs->trans($value['label']).'</td><td><input type="text" name="member_'.$key.'" size="40" value="'.$val.'"></td></tr>';
1184 }
1185 }
1186
1187 // Birth Date
1188 print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1189 print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
1190 print "</td></tr>\n";
1191
1192 // Public profil
1193 print "<tr><td>";
1194 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1195 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1196 print "</td><td>\n";
1197 print $form->selectyesno("public", $object->public, 1, false, 0, 1);
1198 print "</td></tr>\n";
1199
1200 // Categories
1201 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1202 print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td><td>';
1203 print $form->selectCategories(Categorie::TYPE_MEMBER, 'memcats', $object);
1204 print "</td></tr>";
1205 }
1206
1207 // Other attributes
1208 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1209
1210 print '<tbody>';
1211 print "</table>\n";
1212
1213 print dol_get_fiche_end();
1214
1215 print $form->buttonsSaveCancel("AddMember");
1216
1217 print "</form>\n";
1218 }
1219
1220 // Edit mode
1221 if ($action == 'edit') {
1222 $res = $object->fetch($id);
1223 if ($res < 0) {
1224 dol_print_error($db, $object->error);
1225 exit;
1226 }
1227 $res = $object->fetch_optionals();
1228 if ($res < 0) {
1229 dol_print_error($db);
1230 exit;
1231 }
1232
1233 $adht = new AdherentType($db);
1234 $adht->fetch($object->typeid);
1235
1236 // We set country_id, and country_code, country of the chosen country
1237 $country = GETPOSTINT('country');
1238 if (!empty($country) || $object->country_id) {
1239 $sql = "SELECT rowid, code, label from ".MAIN_DB_PREFIX."c_country";
1240 $sql .= " WHERE rowid = ".(int) (!empty($country) ? $country : $object->country_id);
1241 $resql = $db->query($sql);
1242 if ($resql) {
1243 $obj = $db->fetch_object($resql);
1244 } else {
1245 dol_print_error($db);
1246 $obj = null;
1247 }
1248 if (is_object($obj)) {
1249 $object->country_id = $obj->rowid;
1250 $object->country_code = $obj->code;
1251 $object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
1252 }
1253 }
1254
1256
1257
1258 if ($conf->use_javascript_ajax) {
1259 print "\n".'<script type="text/javascript">';
1260 print 'jQuery(document).ready(function () {
1261 jQuery("#selectcountry_id").change(function() {
1262 document.formsoc.action.value="edit";
1263 document.formsoc.submit();
1264 });
1265 function initfieldrequired() {
1266 jQuery("#tdcompany").removeClass("fieldrequired");
1267 jQuery("#tdlastname").removeClass("fieldrequired");
1268 jQuery("#tdfirstname").removeClass("fieldrequired");
1269 if (jQuery(\'input[name="morphy"]:checked\').val() == \'mor\') {
1270 jQuery("#tdcompany").addClass("fieldrequired");
1271 }
1272 if (jQuery(\'input[name="morphy"]:checked\').val() == \'phy\') {
1273 jQuery("#tdlastname").addClass("fieldrequired");
1274 jQuery("#tdfirstname").addClass("fieldrequired");
1275 }
1276 }
1277 jQuery(\'input[name="morphy"]\').change(function() {
1278 initfieldrequired();
1279 });
1280 initfieldrequired();
1281 })';
1282 print '</script>'."\n";
1283 }
1284
1285 print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
1286 print '<input type="hidden" name="token" value="'.newToken().'" />';
1287 print '<input type="hidden" name="action" value="update" />';
1288 print '<input type="hidden" name="rowid" value="'.$id.'" />';
1289 print '<input type="hidden" name="statut" value="'.$object->status.'" />';
1290 if ($backtopage) {
1291 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1292 }
1293
1294 print dol_get_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
1295
1296 print '<table class="border centpercent">';
1297
1298 // Ref
1299 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td class="valeur">'.$object->ref.'</td></tr>';
1300
1301 // Login
1302 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1303 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>';
1304 }
1305
1306 // Password
1307 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1308 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>';
1309 }
1310
1311 // Type
1312 print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
1313 if ($user->hasRight('adherent', 'creer')) {
1314 print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOSTINT("typeid") : $object->typeid), 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1315 } else {
1316 print $adht->getNomUrl(1);
1317 print '<input type="hidden" name="typeid" value="'.$object->typeid.'">';
1318 }
1319 print "</td></tr>";
1320
1321 // Morphy
1322 $morphys["phy"] = $langs->trans("Physical");
1323 $morphys["mor"] = $langs->trans("Moral");
1324 $checkednature = (GETPOSTISSET("morphy") ? GETPOST("morphy", 'alpha') : $object->morphy);
1325 print '<tr><td><span class="fieldrequired">'.$langs->trans("MemberNature").'</span></td><td>';
1326 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>';
1327 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>';
1328 print "</td></tr>";
1329
1330 // Company
1331 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>';
1332
1333 // Civility
1334 print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1335 print $formcompany->select_civility(GETPOSTISSET("civility_id") ? GETPOST("civility_id", 'alpha') : $object->civility_id, 'civility_id', 'maxwidth150', 1);
1336 print '</td>';
1337 print '</tr>';
1338
1339 // Lastname
1340 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>';
1341 print '</tr>';
1342
1343 // Firstname
1344 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>';
1345 print '</tr>';
1346
1347 // Gender
1348 print '<tr><td>'.$langs->trans("Gender").'</td>';
1349 print '<td>';
1350 $arraygender = array('man' => $langs->trans("Genderman"), 'woman' => $langs->trans("Genderwoman"), 'other' => $langs->trans("Genderother"));
1351 print $form->selectarray('gender', $arraygender, GETPOSTISSET('gender') ? GETPOST('gender', 'alphanohtml') : $object->gender, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1352 print '</td></tr>';
1353
1354 // Photo
1355 print '<tr><td>'.$langs->trans("Photo").'</td>';
1356 print '<td class="hideonsmartphone" valign="middle">';
1357 print $form->showphoto('memberphoto', $object)."\n";
1358 if ($caneditfieldmember) {
1359 if ($object->photo) {
1360 print "<br>\n";
1361 }
1362 print '<table class="nobordernopadding">';
1363 if ($object->photo) {
1364 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>';
1365 }
1366 print '<tr><td>';
1367 $maxfilesizearray = getMaxFileSizeArray();
1368 $maxmin = $maxfilesizearray['maxmin'];
1369 if ($maxmin > 0) {
1370 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1371 }
1372 print '<input type="file" class="flat" name="photo" id="photoinput">';
1373 print '</td></tr>';
1374 print '</table>';
1375 }
1376 print '</td></tr>';
1377
1378 // EMail
1379 print '<tr><td>'.(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '</span>' : '').'</td>';
1380 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>';
1381
1382 // Website
1383 print '<tr><td>'.$form->editfieldkey('Web', 'member_url', GETPOST('member_url', 'alpha'), $object, 0).'</td>';
1384 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>';
1385
1386 // Address
1387 print '<tr><td>'.$langs->trans("Address").'</td><td>';
1388 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.'">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml', 2) : $object->address).'</textarea>';
1389 print '</td></tr>';
1390
1391 // Zip / Town
1392 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1393 print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode", 'alphanohtml', 2) : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1394 print ' ';
1395 print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town", 'alphanohtml', 2) : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1396 print '</td></tr>';
1397
1398 // Country
1399 //$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
1400 print '<tr><td>'.$langs->trans('Country').'</td><td>';
1401 print img_picto('', 'country', 'class="pictofixedwidth"');
1402 print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id, 'country_id');
1403 if ($user->admin) {
1404 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1405 }
1406 print '</td></tr>';
1407
1408 // State
1409 if (!getDolGlobalString('MEMBER_DISABLE_STATE')) {
1410 print '<tr><td>'.$langs->trans('State').'</td><td>';
1411 print img_picto('', 'state', 'class="pictofixedwidth"');
1412 print $formcompany->select_state($object->state_id, GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id);
1413 print '</td></tr>';
1414 }
1415
1416 // Pro phone
1417 print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1418 print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone" value="'.(GETPOSTISSET("phone") ? GETPOST("phone") : $object->phone).'"></td></tr>';
1419
1420 // Personal phone
1421 print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1422 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>';
1423
1424 // Mobile phone
1425 print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1426 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>';
1427
1428 if (isModEnabled('socialnetworks')) {
1429 foreach ($socialnetworks as $key => $value) {
1430 if (!$value['active']) {
1431 break;
1432 }
1433 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>';
1434 }
1435 }
1436
1437 // Birth Date
1438 print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1439 print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
1440 print "</td></tr>\n";
1441
1442 // Default language
1443 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1444 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
1445 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, array(), 1);
1446 print '</td>';
1447 print '</tr>';
1448 }
1449
1450 // Public profil
1451 print "<tr><td>";
1452 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1453 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1454 print "</td><td>\n";
1455 print $form->selectyesno("public", (GETPOSTISSET("public") ? GETPOST("public", 'alphanohtml', 2) : $object->public), 1, false, 0, 1);
1456 print "</td></tr>\n";
1457
1458 // Categories
1459 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1460 print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td>';
1461 print '<td>';
1462 print $form->selectCategories(Categorie::TYPE_MEMBER, 'memcats', $object);
1463 print "</td></tr>";
1464 }
1465
1466 // Third party Dolibarr
1467 if (isModEnabled('societe')) {
1468 print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2" class="valeur">';
1469 if ($object->socid) {
1470 $company = new Societe($db);
1471 $result = $company->fetch($object->socid);
1472 print $company->getNomUrl(1);
1473 } else {
1474 print $langs->trans("NoThirdPartyAssociatedToMember");
1475 }
1476 print '</td></tr>';
1477 }
1478
1479 // Login Dolibarr
1480 print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td colspan="2" class="valeur">';
1481 if ($object->user_id) {
1482 $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, (string) $object->user_id, 'none');
1483 } else {
1484 print $langs->trans("NoDolibarrAccess");
1485 }
1486 print '</td></tr>';
1487
1488 // Other attributes. Fields from hook formObjectOptions and Extrafields.
1489 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
1490
1491 print '</table>';
1492 print dol_get_fiche_end();
1493
1494 print $form->buttonsSaveCancel("Save", 'Cancel');
1495
1496 print '</form>';
1497 }
1498
1499 // View
1500 if ($id > 0 && $action != 'edit') {
1501 $res = $object->fetch($id);
1502 if ($res < 0) {
1503 dol_print_error($db, $object->error);
1504 exit;
1505 }
1506 $res = $object->fetch_optionals();
1507 if ($res < 0) {
1508 dol_print_error($db);
1509 exit;
1510 }
1511
1512 $adht = new AdherentType($db);
1513 $res = $adht->fetch($object->typeid);
1514 if ($res < 0) {
1515 dol_print_error($db);
1516 exit;
1517 }
1518
1519
1520 /*
1521 * Show tabs
1522 */
1524
1525 print dol_get_fiche_head($head, 'general', $langs->trans("Member"), -1, 'user', 0, '', '', 0, '', 1);
1526
1527 // Confirm create user
1528 if ($action == 'create_user') {
1529 $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login);
1530 if (empty($login)) {
1531 // Full firstname and name separated with a dot : firstname.name
1532 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1533 $login = dol_buildlogin($object->lastname, $object->firstname);
1534 }
1535 if (empty($login)) {
1536 $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4));
1537 }
1538
1539 // Create a form array
1540 $formquestion = array(
1541 array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
1542 );
1543 if (isModEnabled('societe') && $object->socid > 0) {
1544 $object->fetch_thirdparty();
1545 $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")));
1546 }
1547 $text = '';
1548 if (isModEnabled('societe') && $object->socid <= 0) {
1549 $text .= $langs->trans("UserWillBeInternalUser").'<br>';
1550 }
1551 $text .= $langs->trans("ConfirmCreateLogin");
1552 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1553 }
1554
1555 // Confirm create third party
1556 if ($action == 'create_thirdparty') {
1557 $companyalias = '';
1558 $fullname = $object->getFullName($langs);
1559
1560 if ($object->morphy == 'mor') {
1561 $companyname = (string) $object->company;
1562 if (!empty($fullname)) {
1563 $companyalias = (string) $fullname;
1564 }
1565 } else {
1566 $companyname = $fullname;
1567 if (!empty($object->company)) {
1568 $companyalias = (string) $object->company;
1569 }
1570 }
1571
1572 // Create a form array
1573 $formquestion = array(
1574 array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
1575 array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
1576 );
1577
1578 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 'yes');
1579 }
1580
1581 // Confirm validate member
1582 if ($action == 'valid') {
1583 $langs->load("mails");
1584
1585 $adht = new AdherentType($db);
1586 $adht->fetch($object->typeid);
1587
1588 $subject = '';
1589 $msg = '';
1590
1591 // Send subscription email
1592 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1593 $formmail = new FormMail($db);
1594 // Set output language
1595 $outputlangs = new Translate('', $conf);
1596 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1597 // Load traductions files required by page
1598 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
1599 // Get email content from template
1600 $arraydefaultmessage = null;
1601 $labeltouse = getDolGlobalString("ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION");
1602
1603 if (!empty($labeltouse)) {
1604 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1605 }
1606
1607 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1608 $subject = (string) $arraydefaultmessage->topic;
1609 $msg = (string) $arraydefaultmessage->content;
1610 }
1611
1612 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1613 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1614 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1615 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
1616
1617 $tmp = $langs->trans("SendingAnEMailToMember");
1618 $tmp .= '<br>'.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'</b>, ';
1619 $tmp .= '<br>'.$langs->trans("MailRecipient").': <b>'.$object->email.'</b>';
1620 $helpcontent = '';
1621 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'<br>'."\n";
1622 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1623 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1624 $helpcontent .= $subjecttosend."\n";
1625 $helpcontent .= "<br>";
1626 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1627 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1628 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1629 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1630
1631 // Create form popup
1632 $formquestion = array();
1633 if ($object->email) {
1634 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? true : false));
1635 }
1636 if (isModEnabled('mailman') && getDolGlobalString('ADHERENT_USE_MAILMAN')) {
1637 $formquestion[] = array('type' => 'other', 'label' => $langs->transnoentitiesnoconv("SynchroMailManEnabled"), 'value' => '');
1638 }
1639 if (isModEnabled('mailman') && getDolGlobalString('ADHERENT_USE_SPIP')) {
1640 $formquestion[] = array('type' => 'other', 'label' => $langs->transnoentitiesnoconv("SynchroSpipEnabled"), 'value' => '');
1641 }
1642 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ValidateMember"), $langs->trans("ConfirmValidateMember"), "confirm_valid", $formquestion, 'yes', 1, 250);
1643 }
1644
1645 // Confirm resiliate
1646 if ($action == 'resiliate') {
1647 $langs->load("mails");
1648
1649 $adht = new AdherentType($db);
1650 $adht->fetch($object->typeid);
1651
1652 $subject = '';
1653 $msg = '';
1654
1655 // Send subscription email
1656 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1657 $formmail = new FormMail($db);
1658 // Set output language
1659 $outputlangs = new Translate('', $conf);
1660 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1661 // Load traductions files required by page
1662 $outputlangs->loadLangs(array("main", "members"));
1663 // Get email content from template
1664 $arraydefaultmessage = null;
1665 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_CANCELATION');
1666
1667 if (!empty($labeltouse)) {
1668 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1669 }
1670
1671 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1672 $subject = (string) $arraydefaultmessage->topic;
1673 $msg = (string) $arraydefaultmessage->content;
1674 }
1675
1676 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1677 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1678 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1679 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs);
1680
1681 $tmp = $langs->trans("SendingAnEMailToMember");
1682 $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'</b>, ';
1683 $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1684 $helpcontent = '';
1685 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'<br>'."\n";
1686 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1687 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1688 $helpcontent .= $subjecttosend."\n";
1689 $helpcontent .= "<br>";
1690 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1691 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1692 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1693 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1694
1695 // Create an array
1696 $formquestion = array();
1697 if ($object->email) {
1698 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? 'true' : 'false'));
1699 }
1700 if ($backtopage) {
1701 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1702 }
1703 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ResiliateMember"), $langs->trans("ConfirmResiliateMember"), "confirm_resiliate", $formquestion, 'no', 1, 240);
1704 }
1705
1706 // Confirm exclude
1707 if ($action == 'exclude') {
1708 $langs->load("mails");
1709
1710 $adht = new AdherentType($db);
1711 $adht->fetch($object->typeid);
1712
1713 $subject = '';
1714 $msg = '';
1715
1716 // Send subscription email
1717 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1718 $formmail = new FormMail($db);
1719 // Set output language
1720 $outputlangs = new Translate('', $conf);
1721 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1722 // Load traductions files required by page
1723 $outputlangs->loadLangs(array("main", "members"));
1724 // Get email content from template
1725 $arraydefaultmessage = null;
1726 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_EXCLUSION');
1727
1728 if (!empty($labeltouse)) {
1729 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1730 }
1731
1732 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1733 $subject = (string) $arraydefaultmessage->topic;
1734 $msg = (string) $arraydefaultmessage->content;
1735 }
1736
1737 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1738 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1739 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1740 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs);
1741
1742 $tmp = $langs->trans("SendingAnEMailToMember");
1743 $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'</b>, ';
1744 $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1745 $helpcontent = '';
1746 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from).'<br>'."\n";
1747 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1748 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1749 $helpcontent .= $subjecttosend."\n";
1750 $helpcontent .= "<br>";
1751 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1752 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1753 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1754 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1755
1756 // Create an array
1757 $formquestion = array();
1758 if ($object->email) {
1759 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? 'true' : 'false'));
1760 }
1761 if ($backtopage) {
1762 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1763 }
1764 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ExcludeMember"), $langs->trans("ConfirmExcludeMember"), "confirm_exclude", $formquestion, 'no', 1, 240);
1765 }
1766
1767 // Confirm remove member
1768 if ($action == 'delete') {
1769 $formquestion = array();
1770 if ($backtopage) {
1771 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1772 }
1773 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("DeleteMember"), $langs->trans("ConfirmDeleteMember"), "confirm_delete", $formquestion, 'no', 1);
1774 }
1775
1776 // Confirm add in spip
1777 if ($action == 'add_spip') {
1778 print $form->formconfirm("card.php?rowid=".$id, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip');
1779 }
1780 // Confirm removed from spip
1781 if ($action == 'del_spip') {
1782 print $form->formconfirm("card.php?rowid=$id", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip');
1783 }
1784
1785 $rowspan = 17;
1786 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1787 $rowspan++;
1788 }
1789 if (isModEnabled('societe')) {
1790 $rowspan++;
1791 }
1792
1793 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1794
1795 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
1796 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
1797 $morehtmlref .= '</a>';
1798
1799
1800 dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1801
1802 print '<div class="fichecenter">';
1803 print '<div class="fichehalfleft">';
1804
1805 print '<div class="underbanner clearboth"></div>';
1806 print '<table class="border tableforfield centpercent">';
1807
1808 // Login
1809 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1810 print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
1811 }
1812
1813 // Type
1814 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
1815 print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
1816
1817 // Morphy
1818 print '<tr><td>'.$langs->trans("MemberNature").'</td>';
1819 print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
1820 print '</tr>';
1821
1822 // Company
1823 print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
1824
1825 // Civility
1826 print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
1827 print '</tr>';
1828
1829 // Password
1830 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1831 print '<tr><td>'.$langs->trans("Password").'</td><td>';
1832 if ($object->pass) {
1833 print preg_replace('/./i', '*', $object->pass);
1834 } else {
1835 if ($user->admin) {
1836 print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
1837 }
1838 print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1839 }
1840 if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
1841 $langs->load("errors");
1842 $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
1843 print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
1844 }
1845 print '</td></tr>';
1846 }
1847
1848 // Date end subscription
1849 print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
1850 if ($object->datefin) {
1851 print dol_print_date($object->datefin, 'day');
1852 if ($object->hasDelay()) {
1853 print " ".img_warning($langs->trans("Late"));
1854 }
1855 } else {
1856 if ($object->need_subscription == 0) {
1857 print $langs->trans("SubscriptionNotNeeded");
1858 } elseif (!$adht->subscription) {
1859 print $langs->trans("SubscriptionNotRecorded");
1860 if (Adherent::STATUS_VALIDATED == $object->status) {
1861 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1862 }
1863 } else {
1864 print $langs->trans("SubscriptionNotReceived");
1865 if (Adherent::STATUS_VALIDATED == $object->status) {
1866 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1867 }
1868 }
1869 }
1870 print '</td></tr>';
1871
1872 print '</table>';
1873
1874 print '</div>';
1875
1876 print '<div class="fichehalfright">';
1877 print '<div class="underbanner clearboth"></div>';
1878
1879 print '<table class="border tableforfield centpercent">';
1880
1881 // Tags / Categories
1882 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1883 print '<tr><td>'.$langs->trans("Categories").'</td>';
1884 print '<td colspan="2">';
1885 print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
1886 print '</td></tr>';
1887 }
1888
1889 // Birth Date
1890 print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
1891
1892 // Default language
1893 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1894 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1895 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
1896 //$s=picto_from_langcode($object->default_lang);
1897 //print ($s?$s.' ':'');
1898 $langs->load("languages");
1899 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
1900 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
1901 print $labellang;
1902 print '</td></tr>';
1903 }
1904
1905 // Public
1906 print '<tr><td>';
1907 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1908 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1909 print '</td><td class="valeur">'.yn($object->public).'</td></tr>';
1910
1911 // Other attributes
1912 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1913
1914 // Third party Dolibarr
1915 if (isModEnabled('societe')) {
1916 print '<tr><td>';
1917 $editenable = $user->hasRight('adherent', 'creer');
1918 print $form->editfieldkey('LinkedToDolibarrThirdParty', 'thirdparty', '', $object, $editenable);
1919 print '</td><td colspan="2" class="valeur">';
1920 if ($action == 'editthirdparty') {
1921 $htmlname = 'socid';
1922 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
1923 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
1924 print '<input type="hidden" name="action" value="set'.$htmlname.'">';
1925 print '<input type="hidden" name="token" value="'.newToken().'">';
1926 print '<table class="nobordernopadding">';
1927 print '<tr><td>';
1928 print $form->select_company($object->socid, 'socid', '', 1);
1929 print '</td>';
1930 print '<td class="left"><input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans("Modify").'"></td>';
1931 print '</tr></table></form>';
1932 } else {
1933 if ($object->socid) {
1934 $company = new Societe($db);
1935 $result = $company->fetch($object->socid);
1936 print $company->getNomUrl(1);
1937
1938 // Show link to invoices
1939 $tmparray = $company->getOutstandingBills('customer');
1940 if (!empty($tmparray['refs'])) {
1941 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']).')';
1942 // TODO Add alert if warning on at least one invoice late
1943 print '</a>';
1944 }
1945 } else {
1946 print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
1947 }
1948 }
1949 print '</td></tr>';
1950 }
1951
1952 // Login Dolibarr - Link to user
1953 print '<tr><td>';
1954 $editenable = $user->hasRight('adherent', 'creer') && $user->hasRight('user', 'user', 'creer');
1955 print $form->editfieldkey('LinkedToDolibarrUser', 'login', '', $object, (int) $editenable);
1956 print '</td><td colspan="2" class="valeur">';
1957 if ($action == 'editlogin') {
1958 $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, (string) $object->user_id, 'userid', array());
1959 } else {
1960 if ($object->user_id) {
1961 $linkeduser = new User($db);
1962 $linkeduser->fetch($object->user_id);
1963 print $linkeduser->getNomUrl(-1);
1964 } else {
1965 print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1966 }
1967 }
1968 print '</td></tr>';
1969
1970 print "</table>\n";
1971
1972 print "</div></div>\n";
1973 print '<div class="clearboth"></div>';
1974
1975 print dol_get_fiche_end();
1976
1977
1978 /*
1979 * Action bar
1980 */
1981
1982 print '<div class="tabsAction">';
1983 $isinspip = 0;
1984 $parameters = array();
1985 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1986 if (empty($reshook)) {
1987 if ($action != 'editlogin' && $action != 'editthirdparty') {
1988 // Send
1989 if (empty($user->socid)) {
1990 if (Adherent::STATUS_VALIDATED == $object->status) {
1991 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
1992 }
1993 }
1994
1995 // Send card by email
1996 // TODO Remove this to replace with a template
1997 /*
1998 if ($user->hasRight('adherent', 'creer')) {
1999 if (Adherent::STATUS_VALIDATED == $object->status) {
2000 if ($object->email) print '<a class="butAction" href="card.php?rowid='.$object->id.'&action=sendinfo">'.$langs->trans("SendCardByMail")."</a>\n";
2001 else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendCardByMail")."</a>\n";
2002 } else {
2003 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("SendCardByMail")."</span>";
2004 }
2005 } else {
2006 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("SendCardByMail")."</span>";
2007 }*/
2008
2009 // Modify
2010 if ($user->hasRight('adherent', 'creer')) {
2011 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
2012 } else {
2013 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Modify").'</span>'."\n";
2014 }
2015
2016 // Validate
2017 if (Adherent::STATUS_DRAFT == $object->status) {
2018 if ($user->hasRight('adherent', 'creer')) {
2019 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=valid&token='.newToken().'">'.$langs->trans("Validate").'</a>'."\n";
2020 } else {
2021 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span>'."\n";
2022 }
2023 }
2024
2025 // Reactivate
2027 if ($user->hasRight('adherent', 'creer')) {
2028 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=valid&token='.newToken().'">'.$langs->trans("Reenable")."</a>\n";
2029 } else {
2030 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Reenable").'</span>'."\n";
2031 }
2032 }
2033
2034 // Resiliate
2035 if (Adherent::STATUS_VALIDATED == $object->status) {
2036 if ($user->hasRight('adherent', 'supprimer')) {
2037 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=resiliate&token='.newToken().'">'.$langs->trans("Resiliate")."</a></span>\n";
2038 } else {
2039 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Resiliate").'</span>'."\n";
2040 }
2041 }
2042
2043 // Exclude
2044 if (Adherent::STATUS_VALIDATED == $object->status) {
2045 if ($user->hasRight('adherent', 'supprimer')) {
2046 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=exclude&token='.newToken().'">'.$langs->trans("Exclude")."</a></span>\n";
2047 } else {
2048 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Exclude").'</span>'."\n";
2049 }
2050 }
2051
2052 // Create third party
2053 if (isModEnabled('societe') && !$object->socid) {
2054 if ($user->hasRight('societe', 'creer')) {
2055 if (Adherent::STATUS_DRAFT != $object->status) {
2056 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";
2057 } else {
2058 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a>'."\n";
2059 }
2060 } else {
2061 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrThirdParty").'</span>'."\n";
2062 }
2063 }
2064
2065 // Create user
2066 if (!$user->socid && !$object->user_id) {
2067 if ($user->hasRight('user', 'user', 'creer')) {
2068 if (Adherent::STATUS_DRAFT != $object->status) {
2069 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";
2070 } else {
2071 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrLogin").'</a>'."\n";
2072 }
2073 } else {
2074 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin").'</span>'."\n";
2075 }
2076 }
2077
2078 // Action SPIP
2079 if (isModEnabled('mailmanspip') && getDolGlobalString('ADHERENT_USE_SPIP')) {
2080 $isinspip = $mailmanspip->is_in_spip($object);
2081
2082 if ($isinspip == 1) {
2083 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=del_spip&token='.newToken().'">'.$langs->trans("DeleteIntoSpip").'</a>'."\n";
2084 }
2085 if ($isinspip == 0) {
2086 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=add_spip&token='.newToken().'">'.$langs->trans("AddIntoSpip").'</a>'."\n";
2087 }
2088 }
2089
2090 // Delete
2091 if ($user->hasRight('adherent', 'supprimer')) {
2092 print '<a class="butActionDelete" href="card.php?rowid='.((int) $object->id).'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
2093 } else {
2094 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Delete").'</span>'."\n";
2095 }
2096 }
2097 }
2098 print '</div>';
2099
2100 if ($isinspip == -1) {
2101 print '<br><br><span class="error">'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.'</span>';
2102 }
2103
2104
2105 // Select mail models is same action as presend
2106 if (GETPOST('modelselected')) {
2107 $action = 'presend';
2108 }
2109
2110 if ($action != 'presend') {
2111 print '<div class="fichecenter"><div class="fichehalfleft">';
2112 print '<a name="builddoc"></a>'; // ancre
2113
2114 // Generated documents
2115 $filename = dol_sanitizeFileName($object->ref);
2116 $filedir = $conf->member->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member');
2117 $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
2118 $genallowed = $user->hasRight('adherent', 'lire');
2119 $delallowed = $user->hasRight('adherent', 'creer');
2120
2121 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);
2122 $somethingshown = $formfile->numoffiles;
2123
2124 // Show links to link elements
2125 //$tmparray = $form->showLinkToObjectBlock($object, null, array('subscription'), 1);
2126 //$somethingshown = $form->showLinkedObjectBlock($object, '');
2127
2128 // Show online payment link
2129 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
2130 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2131 $validpaymentmethod = getValidOnlinePaymentMethods('');
2132 $useonlinepayment = count($validpaymentmethod);
2133
2134 if ($useonlinepayment) {
2135 print '<br>';
2136 if (empty($amount)) { // Take the maximum amount among what the member is supposed to pay / has paid in the past
2137 $amount = max($adht->amount, $object->first_subscription_amount, $object->last_subscription_amount);
2138 }
2139 if (empty($amount)) {
2140 $amount = 0;
2141 }
2142 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2143 print showOnlinePaymentUrl('membersubscription', $object->ref, $amount);
2144 }
2145
2146 print '</div><div class="fichehalfright">';
2147
2148 $MAXEVENT = 10;
2149
2150 $morehtmlcenter = '';
2151 $messagingUrl = DOL_URL_ROOT.'/adherents/messaging.php?rowid='.$object->id;
2152 $morehtmlcenter .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
2153 $morehtmlcenter .= dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/adherents/agenda.php?id='.$object->id);
2154
2155 // List of actions on element
2156 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2157 $formactions = new FormActions($db);
2158 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter);
2159
2160 print '</div></div>';
2161 }
2162
2163 // Presend form
2164 $modelmail = 'member';
2165 $defaulttopic = 'CardContent';
2166 $diroutput = $conf->member->dir_output;
2167 $trackid = 'mem'.$object->id;
2168
2169 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2170 }
2171}
2172
2173// End of page
2174llxFooter();
2175$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.