card.php 83 KB

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