card.php 84 KB

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