card.php 74 KB

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