card.php 83 KB

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