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