card.php 84 KB

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