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