card.php 72 KB

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