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