card.php 85 KB

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