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