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