dolibarr 20.0.5
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2012-2020 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2015-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 if ($action == 'update_extras' && $user->hasRight('adherent', 'creer')) {
850 $object->oldcopy = dol_clone($object, 2);
851 $attribute_name = GETPOST('attribute', 'restricthtml');
852
853 // Fill array 'array_options' with data from update form
854 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
855 if ($ret < 0) {
856 $error++;
857 }
858 if (!$error) {
859 $result = $object->updateExtraField($attribute_name, 'MEMBER_MODIFY');
860 if ($result < 0) {
861 setEventMessages($object->error, $object->errors, 'errors');
862 $error++;
863 }
864 }
865 if ($error) {
866 $action = 'edit_extras';
867 }
868 }
869
870 // SPIP Management
871 if ($user->hasRight('adherent', 'supprimer') && $action == 'confirm_del_spip' && $confirm == 'yes') {
872 if (!count($object->errors)) {
873 if (!$mailmanspip->del_to_spip($object)) {
874 setEventMessages($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, null, 'errors');
875 }
876 }
877 }
878
879 if ($user->hasRight('adherent', 'creer') && $action == 'confirm_add_spip' && $confirm == 'yes') {
880 if (!count($object->errors)) {
881 if (!$mailmanspip->add_to_spip($object)) {
882 setEventMessages($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, null, 'errors');
883 }
884 }
885 }
886
887 // Actions when printing a doc from card
888 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
889
890 // Actions to build doc
891 $upload_dir = $conf->adherent->dir_output;
892 $permissiontoadd = $user->hasRight('adherent', 'creer');
893 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
894
895 // Actions to send emails
896 $triggersendname = 'MEMBER_SENTBYMAIL';
897 $paramname = 'id';
898 $mode = 'emailfrommember';
899 $trackid = 'mem'.$object->id;
900 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
901}
902
903
904/*
905 * View
906 */
907
908$form = new Form($db);
909$formfile = new FormFile($db);
910$formadmin = new FormAdmin($db);
911$formcompany = new FormCompany($db);
912
913$title = $langs->trans("Member")." - ".$langs->trans("Card");
914$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
915llxHeader('', $title, $help_url);
916
917$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
918
919if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
920 // -----------------------------------------
921 // When used with CANVAS
922 // -----------------------------------------
923 if (empty($object->error) && $id) {
924 $object = new Adherent($db);
925 $result = $object->fetch($id);
926 if ($result <= 0) {
927 dol_print_error(null, $object->error);
928 }
929 }
930 $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
931 $objcanvas->display_canvas($action); // Show template
932} else {
933 // -----------------------------------------
934 // When used in standard mode
935 // -----------------------------------------
936
937 // Create mode
938 if ($action == 'create') {
939 $object->canvas = $canvas;
940 $object->state_id = GETPOSTINT('state_id');
941
942 // We set country_id, country_code and country for the selected country
943 $object->country_id = GETPOSTINT('country_id') ? GETPOSTINT('country_id') : $mysoc->country_id;
944 if ($object->country_id) {
945 $tmparray = getCountry($object->country_id, 'all');
946 $object->country_code = $tmparray['code'];
947 $object->country = $tmparray['label'];
948 }
949
950 $soc = new Societe($db);
951 if (!empty($socid)) {
952 if ($socid > 0) {
953 $soc->fetch($socid);
954 }
955
956 if (!($soc->id > 0)) {
957 $langs->load("errors");
958 print($langs->trans('ErrorRecordNotFound'));
959 exit;
960 }
961 }
962
963 $adht = new AdherentType($db);
964
965 print load_fiche_titre($langs->trans("NewMember"), '', $object->picto);
966
967 if ($conf->use_javascript_ajax) {
968 print "\n".'<script type="text/javascript">'."\n";
969 print 'jQuery(document).ready(function () {
970 jQuery("#selectcountry_id").change(function() {
971 document.formsoc.action.value="create";
972 document.formsoc.submit();
973 });
974 function initfieldrequired() {
975 jQuery("#tdcompany").removeClass("fieldrequired");
976 jQuery("#tdlastname").removeClass("fieldrequired");
977 jQuery("#tdfirstname").removeClass("fieldrequired");
978 if (jQuery("#morphy").val() == \'mor\') {
979 jQuery("#tdcompany").addClass("fieldrequired");
980 }
981 if (jQuery("#morphy").val() == \'phy\') {
982 jQuery("#tdlastname").addClass("fieldrequired");
983 jQuery("#tdfirstname").addClass("fieldrequired");
984 }
985 }
986 jQuery("#morphy").change(function() {
987 initfieldrequired();
988 });
989 initfieldrequired();
990 })';
991 print '</script>'."\n";
992 }
993
994 print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
995 print '<input type="hidden" name="token" value="'.newToken().'">';
996 print '<input type="hidden" name="action" value="add">';
997 print '<input type="hidden" name="socid" value="'.$socid.'">';
998 if ($backtopage) {
999 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1000 }
1001
1002 print dol_get_fiche_head('');
1003
1004 print '<table class="border centpercent">';
1005 print '<tbody>';
1006
1007 // Login
1008 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1009 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>';
1010 }
1011
1012 // Password
1013 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1014 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1015 $generated_password = getRandomPassword(false);
1016 print '<tr><td><span class="fieldrequired">'.$langs->trans("Password").'</span></td><td>';
1017 print '<input type="text" class="minwidth300" maxlength="50" name="password" value="'.dol_escape_htmltag($generated_password).'">';
1018 print '</td></tr>';
1019 }
1020
1021 // Type
1022 print '<tr><td class="fieldrequired">'.$langs->trans("MemberType").'</td><td>';
1023 $listetype = $adht->liste_array(1);
1024 print img_picto('', $adht->picto, 'class="pictofixedwidth"');
1025 if (count($listetype)) {
1026 print $form->selectarray("typeid", $listetype, (GETPOSTINT('typeid') ? GETPOSTINT('typeid') : $typeid), (count($listetype) > 1 ? 1 : 0), 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1027 } else {
1028 print '<span class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</span>';
1029 }
1030 if ($user->hasRight('member', 'configurer')) {
1031 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>';
1032 }
1033 print "</td>\n";
1034
1035 // Morphy
1036 $morphys = array();
1037 $morphys["phy"] = $langs->trans("Physical");
1038 $morphys["mor"] = $langs->trans("Moral");
1039 print '<tr><td class="fieldrequired">'.$langs->trans("MemberNature")."</td><td>\n";
1040 print $form->selectarray("morphy", $morphys, (GETPOST('morphy', 'alpha') ? GETPOST('morphy', 'alpha') : $object->morphy), 1, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1041 print "</td>\n";
1042
1043 // Company
1044 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>';
1045
1046 // Civility
1047 print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1048 print $formcompany->select_civility(GETPOSTINT('civility_id') ? GETPOSTINT('civility_id') : $object->civility_id, 'civility_id', 'maxwidth150', 1).'</td>';
1049 print '</tr>';
1050
1051 // Lastname
1052 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>';
1053 print '</tr>';
1054
1055 // Firstname
1056 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>';
1057 print '</tr>';
1058
1059 // Gender
1060 print '<tr><td>'.$langs->trans("Gender").'</td>';
1061 print '<td>';
1062 $arraygender = array('man' => $langs->trans("Genderman"), 'woman' => $langs->trans("Genderwoman"), 'other' => $langs->trans("Genderother"));
1063 print $form->selectarray('gender', $arraygender, GETPOST('gender', 'alphanohtml'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1064 print '</td></tr>';
1065
1066 // EMail
1067 print '<tr><td>'.(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '</span>' : '').'</td>';
1068 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>';
1069
1070 // Website
1071 print '<tr><td>'.$form->editfieldkey('Web', 'member_url', GETPOST('member_url', 'alpha'), $object, 0).'</td>';
1072 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>';
1073
1074 // Address
1075 print '<tr><td class="tdtop">'.$langs->trans("Address").'</td><td>';
1076 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="2">'.(GETPOSTISSET('address') ? GETPOST('address', 'alphanohtml') : $soc->address).'</textarea>';
1077 print '</td></tr>';
1078
1079 // Zip / Town
1080 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1081 print $formcompany->select_ziptown((GETPOSTISSET('zipcode') ? GETPOST('zipcode', 'alphanohtml') : $soc->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1082 print ' ';
1083 print $formcompany->select_ziptown((GETPOSTISSET('town') ? GETPOST('town', 'alphanohtml') : $soc->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1084 print '</td></tr>';
1085
1086 // Country
1087 if (empty($soc->country_id)) {
1088 $soc->country_id = $mysoc->country_id;
1089 $soc->country_code = $mysoc->country_code;
1090 $soc->state_id = $mysoc->state_id;
1091 }
1092 print '<tr><td>'.$langs->trans('Country').'</td><td>';
1093 print img_picto('', 'country', 'class="pictofixedwidth"');
1094 print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'alpha') : $soc->country_id, 'country_id');
1095 if ($user->admin) {
1096 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1097 }
1098 print '</td></tr>';
1099
1100 // State
1101 if (!getDolGlobalString('MEMBER_DISABLE_STATE')) {
1102 print '<tr><td>'.$langs->trans('State').'</td><td>';
1103 if ($soc->country_id || GETPOSTISSET('country_id')) {
1104 print img_picto('', 'state', 'class="pictofixedwidth"');
1105 print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOSTINT('state_id') : $soc->state_id, GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $soc->country_code);
1106 } else {
1107 print $countrynotdefined;
1108 }
1109 print '</td></tr>';
1110 }
1111
1112 // Pro phone
1113 print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1114 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>';
1115
1116 // Personal phone
1117 print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1118 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>';
1119
1120 // Mobile phone
1121 print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1122 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>';
1123
1124 if (isModEnabled('socialnetworks')) {
1125 foreach ($socialnetworks as $key => $value) {
1126 if (!$value['active']) {
1127 break;
1128 }
1129 $val = (GETPOSTISSET('member_'.$key) ? GETPOST('member_'.$key, 'alpha') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key]));
1130 print '<tr><td>'.$langs->trans($value['label']).'</td><td><input type="text" name="member_'.$key.'" size="40" value="'.$val.'"></td></tr>';
1131 }
1132 }
1133
1134 // Birth Date
1135 print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1136 print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
1137 print "</td></tr>\n";
1138
1139 // Public profil
1140 print "<tr><td>";
1141 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1142 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1143 print "</td><td>\n";
1144 print $form->selectyesno("public", $object->public, 1, false, 0, 1);
1145 print "</td></tr>\n";
1146
1147 // Categories
1148 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1149 print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td><td>';
1150 $cate_arbo = $form->select_all_categories(Categorie::TYPE_MEMBER, '', 'parent', 64, 0, 3);
1151 print img_picto('', 'category').$form->multiselectarray('memcats', $cate_arbo, GETPOST('memcats', 'array'), 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1152 print "</td></tr>";
1153 }
1154
1155 // Other attributes
1156 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1157
1158 print '<tbody>';
1159 print "</table>\n";
1160
1161 print dol_get_fiche_end();
1162
1163 print $form->buttonsSaveCancel("AddMember");
1164
1165 print "</form>\n";
1166 }
1167
1168 // Edit mode
1169 if ($action == 'edit') {
1170 $res = $object->fetch($id);
1171 if ($res < 0) {
1172 dol_print_error($db, $object->error);
1173 exit;
1174 }
1175 $res = $object->fetch_optionals();
1176 if ($res < 0) {
1177 dol_print_error($db);
1178 exit;
1179 }
1180
1181 $adht = new AdherentType($db);
1182 $adht->fetch($object->typeid);
1183
1184 // We set country_id, and country_code, country of the chosen country
1185 $country = GETPOSTINT('country');
1186 if (!empty($country) || $object->country_id) {
1187 $sql = "SELECT rowid, code, label from ".MAIN_DB_PREFIX."c_country";
1188 $sql .= " WHERE rowid = ".(int) (!empty($country) ? $country : $object->country_id);
1189 $resql = $db->query($sql);
1190 if ($resql) {
1191 $obj = $db->fetch_object($resql);
1192 } else {
1193 dol_print_error($db);
1194 }
1195 $object->country_id = $obj->rowid;
1196 $object->country_code = $obj->code;
1197 $object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
1198 }
1199
1201
1202
1203 if ($conf->use_javascript_ajax) {
1204 print "\n".'<script type="text/javascript">';
1205 print 'jQuery(document).ready(function () {
1206 jQuery("#selectcountry_id").change(function() {
1207 document.formsoc.action.value="edit";
1208 document.formsoc.submit();
1209 });
1210 function initfieldrequired() {
1211 jQuery("#tdcompany").removeClass("fieldrequired");
1212 jQuery("#tdlastname").removeClass("fieldrequired");
1213 jQuery("#tdfirstname").removeClass("fieldrequired");
1214 if (jQuery("#morphy").val() == \'mor\') {
1215 jQuery("#tdcompany").addClass("fieldrequired");
1216 }
1217 if (jQuery("#morphy").val() == \'phy\') {
1218 jQuery("#tdlastname").addClass("fieldrequired");
1219 jQuery("#tdfirstname").addClass("fieldrequired");
1220 }
1221 }
1222 jQuery("#morphy").change(function() {
1223 initfieldrequired();
1224 });
1225 initfieldrequired();
1226 })';
1227 print '</script>'."\n";
1228 }
1229
1230 print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
1231 print '<input type="hidden" name="token" value="'.newToken().'" />';
1232 print '<input type="hidden" name="action" value="update" />';
1233 print '<input type="hidden" name="rowid" value="'.$id.'" />';
1234 print '<input type="hidden" name="statut" value="'.$object->status.'" />';
1235 if ($backtopage) {
1236 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1237 }
1238
1239 print dol_get_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
1240
1241 print '<table class="border centpercent">';
1242
1243 // Ref
1244 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td class="valeur">'.$object->ref.'</td></tr>';
1245
1246 // Login
1247 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1248 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>';
1249 }
1250
1251 // Password
1252 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1253 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>';
1254 }
1255
1256 // Type
1257 print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
1258 if ($user->hasRight('adherent', 'creer')) {
1259 print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOSTINT("typeid") : $object->typeid), 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1260 } else {
1261 print $adht->getNomUrl(1);
1262 print '<input type="hidden" name="typeid" value="'.$object->typeid.'">';
1263 }
1264 print "</td></tr>";
1265
1266 // Morphy
1267 $morphys["phy"] = $langs->trans("Physical");
1268 $morphys["mor"] = $langs->trans("Moral");
1269 print '<tr><td><span class="fieldrequired">'.$langs->trans("MemberNature").'</span></td><td>';
1270 print $form->selectarray("morphy", $morphys, (GETPOSTISSET("morphy") ? GETPOST("morphy", 'alpha') : $object->morphy), 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
1271 print "</td></tr>";
1272
1273 // Company
1274 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>';
1275
1276 // Civility
1277 print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1278 print $formcompany->select_civility(GETPOSTISSET("civility_id") ? GETPOST("civility_id", 'alpha') : $object->civility_id, 'civility_id', 'maxwidth150', 1);
1279 print '</td>';
1280 print '</tr>';
1281
1282 // Lastname
1283 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>';
1284 print '</tr>';
1285
1286 // Firstname
1287 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>';
1288 print '</tr>';
1289
1290 // Gender
1291 print '<tr><td>'.$langs->trans("Gender").'</td>';
1292 print '<td>';
1293 $arraygender = array('man' => $langs->trans("Genderman"), 'woman' => $langs->trans("Genderwoman"), 'other' => $langs->trans("Genderother"));
1294 print $form->selectarray('gender', $arraygender, GETPOSTISSET('gender') ? GETPOST('gender', 'alphanohtml') : $object->gender, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
1295 print '</td></tr>';
1296
1297 // Photo
1298 print '<tr><td>'.$langs->trans("Photo").'</td>';
1299 print '<td class="hideonsmartphone" valign="middle">';
1300 print $form->showphoto('memberphoto', $object)."\n";
1301 if ($caneditfieldmember) {
1302 if ($object->photo) {
1303 print "<br>\n";
1304 }
1305 print '<table class="nobordernopadding">';
1306 if ($object->photo) {
1307 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>';
1308 }
1309 print '<tr><td>';
1310 $maxfilesizearray = getMaxFileSizeArray();
1311 $maxmin = $maxfilesizearray['maxmin'];
1312 if ($maxmin > 0) {
1313 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1314 }
1315 print '<input type="file" class="flat" name="photo" id="photoinput">';
1316 print '</td></tr>';
1317 print '</table>';
1318 }
1319 print '</td></tr>';
1320
1321 // EMail
1322 print '<tr><td>'.(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '</span>' : '').'</td>';
1323 print '<td>'.img_picto('', 'object_email', 'class="pictofixedwidth"').'<input type="text" name="member_email" class="minwidth300" maxlength="255" value="'.(GETPOSTISSET("member_email") ? GETPOST("member_email", 'alphanohtml', 2) : $object->email).'"></td></tr>';
1324
1325 // Website
1326 print '<tr><td>'.$form->editfieldkey('Web', 'member_url', GETPOST('member_url', 'alpha'), $object, 0).'</td>';
1327 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>';
1328
1329 // Address
1330 print '<tr><td>'.$langs->trans("Address").'</td><td>';
1331 print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.'">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml', 2) : $object->address).'</textarea>';
1332 print '</td></tr>';
1333
1334 // Zip / Town
1335 print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1336 print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode", 'alphanohtml', 2) : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1337 print ' ';
1338 print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town", 'alphanohtml', 2) : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1339 print '</td></tr>';
1340
1341 // Country
1342 //$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
1343 print '<tr><td>'.$langs->trans('Country').'</td><td>';
1344 print img_picto('', 'country', 'class="pictofixedwidth"');
1345 print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id, 'country_id');
1346 if ($user->admin) {
1347 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1348 }
1349 print '</td></tr>';
1350
1351 // State
1352 if (!getDolGlobalString('MEMBER_DISABLE_STATE')) {
1353 print '<tr><td>'.$langs->trans('State').'</td><td>';
1354 print img_picto('', 'state', 'class="pictofixedwidth"');
1355 print $formcompany->select_state($object->state_id, GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id);
1356 print '</td></tr>';
1357 }
1358
1359 // Pro phone
1360 print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1361 print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone" value="'.(GETPOSTISSET("phone") ? GETPOST("phone") : $object->phone).'"></td></tr>';
1362
1363 // Personal phone
1364 print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1365 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>';
1366
1367 // Mobile phone
1368 print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1369 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>';
1370
1371 if (isModEnabled('socialnetworks')) {
1372 foreach ($socialnetworks as $key => $value) {
1373 if (!$value['active']) {
1374 break;
1375 }
1376 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>';
1377 }
1378 }
1379
1380 // Birth Date
1381 print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1382 print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
1383 print "</td></tr>\n";
1384
1385 // Default language
1386 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1387 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
1388 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1);
1389 print '</td>';
1390 print '</tr>';
1391 }
1392
1393 // Public profil
1394 print "<tr><td>";
1395 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1396 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1397 print "</td><td>\n";
1398 print $form->selectyesno("public", (GETPOSTISSET("public") ? GETPOST("public", 'alphanohtml', 2) : $object->public), 1, false, 0, 1);
1399 print "</td></tr>\n";
1400
1401 // Categories
1402 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1403 print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td>';
1404 print '<td>';
1405 $cate_arbo = $form->select_all_categories(Categorie::TYPE_MEMBER, '', '', 64, 0, 3);
1406 $c = new Categorie($db);
1407 $cats = $c->containing($object->id, Categorie::TYPE_MEMBER);
1408 $arrayselected = array();
1409 if (is_array($cats)) {
1410 foreach ($cats as $cat) {
1411 $arrayselected[] = $cat->id;
1412 }
1413 }
1414 print img_picto('', 'category', 'class="pictofixedwidth"');
1415 print $form->multiselectarray('memcats', $cate_arbo, $arrayselected, 0, 0, 'widthcentpercentminusx', 0, '100%');
1416 print "</td></tr>";
1417 }
1418
1419 // Third party Dolibarr
1420 if (isModEnabled('societe')) {
1421 print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2" class="valeur">';
1422 if ($object->socid) {
1423 $company = new Societe($db);
1424 $result = $company->fetch($object->socid);
1425 print $company->getNomUrl(1);
1426 } else {
1427 print $langs->trans("NoThirdPartyAssociatedToMember");
1428 }
1429 print '</td></tr>';
1430 }
1431
1432 // Login Dolibarr
1433 print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td colspan="2" class="valeur">';
1434 if ($object->user_id) {
1435 $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'none');
1436 } else {
1437 print $langs->trans("NoDolibarrAccess");
1438 }
1439 print '</td></tr>';
1440
1441 // Other attributes. Fields from hook formObjectOptions and Extrafields.
1442 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
1443
1444 print '</table>';
1445 print dol_get_fiche_end();
1446
1447 print $form->buttonsSaveCancel("Save", 'Cancel');
1448
1449 print '</form>';
1450 }
1451
1452 // View
1453 if ($id > 0 && $action != 'edit') {
1454 $res = $object->fetch($id);
1455 if ($res < 0) {
1456 dol_print_error($db, $object->error);
1457 exit;
1458 }
1459 $res = $object->fetch_optionals();
1460 if ($res < 0) {
1461 dol_print_error($db);
1462 exit;
1463 }
1464
1465 $adht = new AdherentType($db);
1466 $res = $adht->fetch($object->typeid);
1467 if ($res < 0) {
1468 dol_print_error($db);
1469 exit;
1470 }
1471
1472
1473 /*
1474 * Show tabs
1475 */
1477
1478 print dol_get_fiche_head($head, 'general', $langs->trans("Member"), -1, 'user');
1479
1480 // Confirm create user
1481 if ($action == 'create_user') {
1482 $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login);
1483 if (empty($login)) {
1484 // Full firstname and name separated with a dot : firstname.name
1485 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1486 $login = dol_buildlogin($object->lastname, $object->firstname);
1487 }
1488 if (empty($login)) {
1489 $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4));
1490 }
1491
1492 // Create a form array
1493 $formquestion = array(
1494 array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
1495 );
1496 if (isModEnabled('societe') && $object->socid > 0) {
1497 $object->fetch_thirdparty();
1498 $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")));
1499 }
1500 $text = '';
1501 if (isModEnabled('societe') && $object->socid <= 0) {
1502 $text .= $langs->trans("UserWillBeInternalUser").'<br>';
1503 }
1504 $text .= $langs->trans("ConfirmCreateLogin");
1505 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1506 }
1507
1508 // Confirm create third party
1509 if ($action == 'create_thirdparty') {
1510 $companyalias = '';
1511 $fullname = $object->getFullName($langs);
1512
1513 if ($object->morphy == 'mor') {
1514 $companyname = $object->company;
1515 if (!empty($fullname)) {
1516 $companyalias = $fullname;
1517 }
1518 } else {
1519 $companyname = $fullname;
1520 if (!empty($object->company)) {
1521 $companyalias = $object->company;
1522 }
1523 }
1524
1525 // Create a form array
1526 $formquestion = array(
1527 array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
1528 array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
1529 );
1530
1531 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 'yes');
1532 }
1533
1534 // Confirm validate member
1535 if ($action == 'valid') {
1536 $langs->load("mails");
1537
1538 $adht = new AdherentType($db);
1539 $adht->fetch($object->typeid);
1540
1541 $subject = '';
1542 $msg = '';
1543
1544 // Send subscription email
1545 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1546 $formmail = new FormMail($db);
1547 // Set output language
1548 $outputlangs = new Translate('', $conf);
1549 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1550 // Load traductions files required by page
1551 $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
1552 // Get email content from template
1553 $arraydefaultmessage = null;
1554 $labeltouse = getDolGlobalString("ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION");
1555
1556 if (!empty($labeltouse)) {
1557 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1558 }
1559
1560 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1561 $subject = $arraydefaultmessage->topic;
1562 $msg = $arraydefaultmessage->content;
1563 }
1564
1565 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1566 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1567 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1568 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
1569
1570 $tmp = $langs->trans("SendingAnEMailToMember");
1571 $tmp .= '<br>'.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM').'</b>, ';
1572 $tmp .= '<br>'.$langs->trans("MailRecipient").': <b>'.$object->email.'</b>';
1573 $helpcontent = '';
1574 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM').'<br>'."\n";
1575 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1576 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1577 $helpcontent .= $subjecttosend."\n";
1578 $helpcontent .= "<br>";
1579 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1580 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1581 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1582 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1583
1584 // Create form popup
1585 $formquestion = array();
1586 if ($object->email) {
1587 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? true : false));
1588 }
1589 if (isModEnabled('mailman') && getDolGlobalString('ADHERENT_USE_MAILMAN')) {
1590 $formquestion[] = array('type' => 'other', 'label' => $langs->transnoentitiesnoconv("SynchroMailManEnabled"), 'value' => '');
1591 }
1592 if (isModEnabled('mailman') && getDolGlobalString('ADHERENT_USE_SPIP')) {
1593 $formquestion[] = array('type' => 'other', 'label' => $langs->transnoentitiesnoconv("SynchroSpipEnabled"), 'value' => '');
1594 }
1595 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ValidateMember"), $langs->trans("ConfirmValidateMember"), "confirm_valid", $formquestion, 'yes', 1, 220);
1596 }
1597
1598 // Confirm resiliate
1599 if ($action == 'resiliate') {
1600 $langs->load("mails");
1601
1602 $adht = new AdherentType($db);
1603 $adht->fetch($object->typeid);
1604
1605 $subject = '';
1606 $msg = '';
1607
1608 // Send subscription email
1609 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1610 $formmail = new FormMail($db);
1611 // Set output language
1612 $outputlangs = new Translate('', $conf);
1613 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1614 // Load traductions files required by page
1615 $outputlangs->loadLangs(array("main", "members"));
1616 // Get email content from template
1617 $arraydefaultmessage = null;
1618 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_CANCELATION');
1619
1620 if (!empty($labeltouse)) {
1621 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1622 }
1623
1624 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1625 $subject = $arraydefaultmessage->topic;
1626 $msg = $arraydefaultmessage->content;
1627 }
1628
1629 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1630 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1631 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1632 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs);
1633
1634 $tmp = $langs->trans("SendingAnEMailToMember");
1635 $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM').'</b>, ';
1636 $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1637 $helpcontent = '';
1638 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM').'<br>'."\n";
1639 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1640 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1641 $helpcontent .= $subjecttosend."\n";
1642 $helpcontent .= "<br>";
1643 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1644 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1645 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1646 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1647
1648 // Create an array
1649 $formquestion = array();
1650 if ($object->email) {
1651 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? 'true' : 'false'));
1652 }
1653 if ($backtopage) {
1654 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1655 }
1656 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ResiliateMember"), $langs->trans("ConfirmResiliateMember"), "confirm_resiliate", $formquestion, 'no', 1, 240);
1657 }
1658
1659 // Confirm exclude
1660 if ($action == 'exclude') {
1661 $langs->load("mails");
1662
1663 $adht = new AdherentType($db);
1664 $adht->fetch($object->typeid);
1665
1666 $subject = '';
1667 $msg = '';
1668
1669 // Send subscription email
1670 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1671 $formmail = new FormMail($db);
1672 // Set output language
1673 $outputlangs = new Translate('', $conf);
1674 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1675 // Load traductions files required by page
1676 $outputlangs->loadLangs(array("main", "members"));
1677 // Get email content from template
1678 $arraydefaultmessage = null;
1679 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_EXCLUSION');
1680
1681 if (!empty($labeltouse)) {
1682 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1683 }
1684
1685 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1686 $subject = $arraydefaultmessage->topic;
1687 $msg = $arraydefaultmessage->content;
1688 }
1689
1690 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1691 complete_substitutions_array($substitutionarray, $outputlangs, $object);
1692 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1693 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs);
1694
1695 $tmp = $langs->trans("SendingAnEMailToMember");
1696 $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.getDolGlobalString('ADHERENT_MAIL_FROM').'</b>, ';
1697 $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1698 $helpcontent = '';
1699 $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM').'<br>'."\n";
1700 $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1701 $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1702 $helpcontent .= $subjecttosend."\n";
1703 $helpcontent .= "<br>";
1704 $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1705 $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1706 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1707 $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1708
1709 // Create an array
1710 $formquestion = array();
1711 if ($object->email) {
1712 $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? 'true' : 'false'));
1713 }
1714 if ($backtopage) {
1715 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1716 }
1717 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ExcludeMember"), $langs->trans("ConfirmExcludeMember"), "confirm_exclude", $formquestion, 'no', 1, 240);
1718 }
1719
1720 // Confirm remove member
1721 if ($action == 'delete') {
1722 $formquestion = array();
1723 if ($backtopage) {
1724 $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1725 }
1726 print $form->formconfirm("card.php?rowid=".$id, $langs->trans("DeleteMember"), $langs->trans("ConfirmDeleteMember"), "confirm_delete", $formquestion, 'no', 1);
1727 }
1728
1729 // Confirm add in spip
1730 if ($action == 'add_spip') {
1731 print $form->formconfirm("card.php?rowid=".$id, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip');
1732 }
1733 // Confirm removed from spip
1734 if ($action == 'del_spip') {
1735 print $form->formconfirm("card.php?rowid=$id", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip');
1736 }
1737
1738 $rowspan = 17;
1739 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1740 $rowspan++;
1741 }
1742 if (isModEnabled('societe')) {
1743 $rowspan++;
1744 }
1745
1746 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1747
1748 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
1749 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
1750 $morehtmlref .= '</a>';
1751
1752
1753 dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1754
1755 print '<div class="fichecenter">';
1756 print '<div class="fichehalfleft">';
1757
1758 print '<div class="underbanner clearboth"></div>';
1759 print '<table class="border tableforfield centpercent">';
1760
1761 // Login
1762 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1763 print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
1764 }
1765
1766 // Type
1767 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
1768 print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
1769
1770 // Morphy
1771 print '<tr><td>'.$langs->trans("MemberNature").'</td>';
1772 print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
1773 print '</tr>';
1774
1775 // Company
1776 print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
1777
1778 // Civility
1779 print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
1780 print '</tr>';
1781
1782 // Password
1783 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
1784 print '<tr><td>'.$langs->trans("Password").'</td><td>';
1785 if ($object->pass) {
1786 print preg_replace('/./i', '*', $object->pass);
1787 } else {
1788 if ($user->admin) {
1789 print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
1790 }
1791 print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1792 }
1793 if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
1794 $langs->load("errors");
1795 $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
1796 print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
1797 }
1798 print '</td></tr>';
1799 }
1800
1801 // Date end subscription
1802 print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
1803 if ($object->datefin) {
1804 print dol_print_date($object->datefin, 'day');
1805 if ($object->hasDelay()) {
1806 print " ".img_warning($langs->trans("Late"));
1807 }
1808 } else {
1809 if ($object->need_subscription == 0) {
1810 print $langs->trans("SubscriptionNotNeeded");
1811 } elseif (!$adht->subscription) {
1812 print $langs->trans("SubscriptionNotRecorded");
1813 if (Adherent::STATUS_VALIDATED == $object->status) {
1814 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1815 }
1816 } else {
1817 print $langs->trans("SubscriptionNotReceived");
1818 if (Adherent::STATUS_VALIDATED == $object->status) {
1819 print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1820 }
1821 }
1822 }
1823 print '</td></tr>';
1824
1825 print '</table>';
1826
1827 print '</div>';
1828
1829 print '<div class="fichehalfright">';
1830 print '<div class="underbanner clearboth"></div>';
1831
1832 print '<table class="border tableforfield centpercent">';
1833
1834 // Tags / Categories
1835 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1836 print '<tr><td>'.$langs->trans("Categories").'</td>';
1837 print '<td colspan="2">';
1838 print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
1839 print '</td></tr>';
1840 }
1841
1842 // Birth Date
1843 print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
1844
1845 // Default language
1846 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1847 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1848 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
1849 //$s=picto_from_langcode($object->default_lang);
1850 //print ($s?$s.' ':'');
1851 $langs->load("languages");
1852 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
1853 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
1854 print $labellang;
1855 print '</td></tr>';
1856 }
1857
1858 // Public
1859 print '<tr><td>';
1860 $htmltext = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
1861 print $form->textwithpicto($langs->trans("MembershipPublic"), $htmltext, 1, 'help', '', 0, 3, 'membershippublic');
1862 print '</td><td class="valeur">'.yn($object->public).'</td></tr>';
1863
1864 // Other attributes
1865 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1866
1867 // Third party Dolibarr
1868 if (isModEnabled('societe')) {
1869 print '<tr><td>';
1870 $editenable = $user->hasRight('adherent', 'creer');
1871 print $form->editfieldkey('LinkedToDolibarrThirdParty', 'thirdparty', '', $object, $editenable);
1872 print '</td><td colspan="2" class="valeur">';
1873 if ($action == 'editthirdparty') {
1874 $htmlname = 'socid';
1875 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
1876 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
1877 print '<input type="hidden" name="action" value="set'.$htmlname.'">';
1878 print '<input type="hidden" name="token" value="'.newToken().'">';
1879 print '<table class="nobordernopadding">';
1880 print '<tr><td>';
1881 print $form->select_company($object->socid, 'socid', '', 1);
1882 print '</td>';
1883 print '<td class="left"><input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans("Modify").'"></td>';
1884 print '</tr></table></form>';
1885 } else {
1886 if ($object->socid) {
1887 $company = new Societe($db);
1888 $result = $company->fetch($object->socid);
1889 print $company->getNomUrl(1);
1890
1891 // Show link to invoices
1892 $tmparray = $company->getOutstandingBills('customer');
1893 if (!empty($tmparray['refs'])) {
1894 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']).')';
1895 // TODO Add alert if warning on at least one invoice late
1896 print '</a>';
1897 }
1898 } else {
1899 print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
1900 }
1901 }
1902 print '</td></tr>';
1903 }
1904
1905 // Login Dolibarr - Link to user
1906 print '<tr><td>';
1907 $editenable = $user->hasRight('adherent', 'creer') && $user->hasRight('user', 'user', 'creer');
1908 print $form->editfieldkey('LinkedToDolibarrUser', 'login', '', $object, $editenable);
1909 print '</td><td colspan="2" class="valeur">';
1910 if ($action == 'editlogin') {
1911 $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
1912 } else {
1913 if ($object->user_id) {
1914 $linkeduser = new User($db);
1915 $linkeduser->fetch($object->user_id);
1916 print $linkeduser->getNomUrl(-1);
1917 } else {
1918 print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1919 }
1920 }
1921 print '</td></tr>';
1922
1923 print "</table>\n";
1924
1925 print "</div></div>\n";
1926 print '<div class="clearboth"></div>';
1927
1928 print dol_get_fiche_end();
1929
1930
1931 /*
1932 * Action bar
1933 */
1934
1935 print '<div class="tabsAction">';
1936 $isinspip = 0;
1937 $parameters = array();
1938 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1939 if (empty($reshook)) {
1940 if ($action != 'editlogin' && $action != 'editthirdparty') {
1941 // Send
1942 if (empty($user->socid)) {
1943 if (Adherent::STATUS_VALIDATED == $object->status) {
1944 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
1945 }
1946 }
1947
1948 // Send card by email
1949 // TODO Remove this to replace with a template
1950 /*
1951 if ($user->hasRight('adherent', 'creer')) {
1952 if (Adherent::STATUS_VALIDATED == $object->status) {
1953 if ($object->email) print '<a class="butAction" href="card.php?rowid='.$object->id.'&action=sendinfo">'.$langs->trans("SendCardByMail")."</a>\n";
1954 else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendCardByMail")."</a>\n";
1955 } else {
1956 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("SendCardByMail")."</span>";
1957 }
1958 } else {
1959 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("SendCardByMail")."</span>";
1960 }*/
1961
1962 // Modify
1963 if ($user->hasRight('adherent', 'creer')) {
1964 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
1965 } else {
1966 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Modify").'</span>'."\n";
1967 }
1968
1969 // Validate
1970 if (Adherent::STATUS_DRAFT == $object->status) {
1971 if ($user->hasRight('adherent', 'creer')) {
1972 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=valid&token='.newToken().'">'.$langs->trans("Validate").'</a>'."\n";
1973 } else {
1974 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span>'."\n";
1975 }
1976 }
1977
1978 // Reactivate
1980 if ($user->hasRight('adherent', 'creer')) {
1981 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=valid&token='.newToken().'">'.$langs->trans("Reenable")."</a>\n";
1982 } else {
1983 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Reenable").'</span>'."\n";
1984 }
1985 }
1986
1987 // Resiliate
1988 if (Adherent::STATUS_VALIDATED == $object->status) {
1989 if ($user->hasRight('adherent', 'supprimer')) {
1990 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=resiliate&token='.newToken().'">'.$langs->trans("Resiliate")."</a></span>\n";
1991 } else {
1992 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Resiliate").'</span>'."\n";
1993 }
1994 }
1995
1996 // Exclude
1997 if (Adherent::STATUS_VALIDATED == $object->status) {
1998 if ($user->hasRight('adherent', 'supprimer')) {
1999 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=exclude&token='.newToken().'">'.$langs->trans("Exclude")."</a></span>\n";
2000 } else {
2001 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Exclude").'</span>'."\n";
2002 }
2003 }
2004
2005 // Create third party
2006 if (isModEnabled('societe') && !$object->socid) {
2007 if ($user->hasRight('societe', 'creer')) {
2008 if (Adherent::STATUS_DRAFT != $object->status) {
2009 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";
2010 } else {
2011 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a>'."\n";
2012 }
2013 } else {
2014 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrThirdParty").'</span>'."\n";
2015 }
2016 }
2017
2018 // Create user
2019 if (!$user->socid && !$object->user_id) {
2020 if ($user->hasRight('user', 'user', 'creer')) {
2021 if (Adherent::STATUS_DRAFT != $object->status) {
2022 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";
2023 } else {
2024 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrLogin").'</a>'."\n";
2025 }
2026 } else {
2027 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin").'</span>'."\n";
2028 }
2029 }
2030
2031 // Action SPIP
2032 if (isModEnabled('mailmanspip') && getDolGlobalString('ADHERENT_USE_SPIP')) {
2033 $isinspip = $mailmanspip->is_in_spip($object);
2034
2035 if ($isinspip == 1) {
2036 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=del_spip&token='.newToken().'">'.$langs->trans("DeleteIntoSpip").'</a>'."\n";
2037 }
2038 if ($isinspip == 0) {
2039 print '<a class="butAction" href="card.php?rowid='.((int) $object->id).'&action=add_spip&token='.newToken().'">'.$langs->trans("AddIntoSpip").'</a>'."\n";
2040 }
2041 }
2042
2043 // Delete
2044 if ($user->hasRight('adherent', 'supprimer')) {
2045 print '<a class="butActionDelete" href="card.php?rowid='.((int) $object->id).'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
2046 } else {
2047 print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Delete").'</span>'."\n";
2048 }
2049 }
2050 }
2051 print '</div>';
2052
2053 if ($isinspip == -1) {
2054 print '<br><br><span class="error">'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.'</span>';
2055 }
2056
2057
2058 // Select mail models is same action as presend
2059 if (GETPOST('modelselected')) {
2060 $action = 'presend';
2061 }
2062
2063 if ($action != 'presend') {
2064 print '<div class="fichecenter"><div class="fichehalfleft">';
2065 print '<a name="builddoc"></a>'; // ancre
2066
2067 // Generated documents
2068 $filename = dol_sanitizeFileName($object->ref);
2069 $filedir = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member');
2070 $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
2071 $genallowed = $user->hasRight('adherent', 'lire');
2072 $delallowed = $user->hasRight('adherent', 'creer');
2073
2074 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);
2075 $somethingshown = $formfile->numoffiles;
2076
2077 // Show links to link elements
2078 //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
2079 //$somethingshown = $form->showLinkedObjectBlock($object, '');
2080
2081 // Show links to link elements
2082 /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
2083 if ($linktoelem) {
2084 print ($somethingshown?'':'<br>').$linktoelem;
2085 }
2086 */
2087
2088 // Show online payment link
2089 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
2090 include_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2091 $validpaymentmethod = getValidOnlinePaymentMethods('');
2092 $useonlinepayment = count($validpaymentmethod);
2093
2094 if ($useonlinepayment) {
2095 print '<br>';
2096 if (empty($amount)) { // Take the maximum amount among what the member is supposed to pay / has paid in the past
2097 $amount = max($adht->amount, $object->first_subscription_amount, $object->last_subscription_amount);
2098 }
2099 if (empty($amount)) {
2100 $amount = 0;
2101 }
2102 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2103 print showOnlinePaymentUrl('membersubscription', $object->ref, $amount);
2104 }
2105
2106 print '</div><div class="fichehalfright">';
2107
2108 $MAXEVENT = 10;
2109
2110 $morehtmlcenter = '';
2111 $messagingUrl = DOL_URL_ROOT.'/adherents/messaging.php?rowid='.$object->id;
2112 $morehtmlcenter .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
2113 $morehtmlcenter .= dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/adherents/agenda.php?id='.$object->id);
2114
2115 // List of actions on element
2116 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2117 $formactions = new FormActions($db);
2118 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter);
2119
2120 print '</div></div>';
2121 }
2122
2123 // Presend form
2124 $modelmail = 'member';
2125 $defaulttopic = 'CardContent';
2126 $diroutput = $conf->adherent->dir_output;
2127 $trackid = 'mem'.$object->id;
2128
2129 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2130 }
2131}
2132
2133// End of page
2134llxFooter();
2135$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.