card.php 84 KB

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