fiche.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  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-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/adherents/fiche.php
  22. * \ingroup member
  23. * \brief Page of member
  24. */
  25. require("../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
  31. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php");
  32. require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
  33. require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php");
  34. require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
  35. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php");
  36. $langs->load("companies");
  37. $langs->load("bills");
  38. $langs->load("members");
  39. $langs->load("users");
  40. // Security check
  41. if (! $user->rights->adherent->lire) accessforbidden();
  42. $object = new Adherent($db);
  43. $extrafields = new ExtraFields($db);
  44. $errmsg=''; $errmsgs=array();
  45. $action=GETPOST("action");
  46. $rowid=GETPOST("rowid");
  47. $typeid=GETPOST("typeid");
  48. if ($rowid)
  49. {
  50. // Load member
  51. $result = $object->fetch($rowid);
  52. // Define variables to know what current user can do on users
  53. $canadduser=($user->admin || $user->rights->user->user->creer);
  54. // Define variables to know what current user can do on properties of user linked to edited member
  55. if ($object->user_id)
  56. {
  57. // $user est le user qui edite, $object->user_id est l'id de l'utilisateur lies au membre edite
  58. $caneditfielduser=( (($user->id == $object->user_id) && $user->rights->user->self->creer)
  59. || (($user->id != $object->user_id) && $user->rights->user->user->creer) );
  60. $caneditpassworduser=( (($user->id == $object->user_id) && $user->rights->user->self->password)
  61. || (($user->id != $adh->user_id) && $user->rights->user->user->password) );
  62. }
  63. }
  64. // Define variables to know what current user can do on members
  65. $canaddmember=$user->rights->adherent->creer;
  66. // Define variables to know what current user can do on properties of a member
  67. if ($rowid)
  68. {
  69. $caneditfieldmember=$user->rights->adherent->creer;
  70. }
  71. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  72. include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
  73. $hookmanager=new HookManager($db);
  74. $hookmanager->callHooks(array('member_extrafields'));
  75. /*
  76. * Actions
  77. */
  78. $parameters=array('socid'=>$socid);
  79. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  80. if ($_POST['action'] == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
  81. {
  82. $error=0;
  83. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  84. {
  85. if ($_POST["userid"] != $user->id && $_POST["userid"] != $object->user_id)
  86. {
  87. $error++;
  88. $mesg='<div class="error">'.$langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly").'</div>';
  89. }
  90. }
  91. if (! $error)
  92. {
  93. if ($_POST["userid"] != $object->user_id) // If link differs from currently in database
  94. {
  95. $result=$object->setUserId($_POST["userid"]);
  96. if ($result < 0) dol_print_error($object->db,$object->error);
  97. $_POST['action']='';
  98. $action='';
  99. }
  100. }
  101. }
  102. if ($_POST['action'] == 'setsocid')
  103. {
  104. $error=0;
  105. if (! $error)
  106. {
  107. if ($_POST["socid"] != $object->fk_soc) // If link differs from currently in database
  108. {
  109. $sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
  110. $sql.=" WHERE fk_soc = '".$_POST["socid"]."'";
  111. $sql.=" AND entity = ".$conf->entity;
  112. $resql = $db->query($sql);
  113. if ($resql)
  114. {
  115. $obj = $db->fetch_object($resql);
  116. if ($obj && $obj->rowid > 0)
  117. {
  118. $othermember=new Adherent($db);
  119. $othermember->fetch($obj->rowid);
  120. $thirdparty=new Societe($db);
  121. $thirdparty->fetch($_POST["socid"]);
  122. $error++;
  123. $errmsg='<div class="error">'.$langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->nom).'</div>';
  124. }
  125. }
  126. if (! $error)
  127. {
  128. $result=$object->setThirdPartyId($_POST["socid"]);
  129. if ($result < 0) dol_print_error($object->db,$object->error);
  130. $_POST['action']='';
  131. $action='';
  132. }
  133. }
  134. }
  135. }
  136. // Create user from a member
  137. if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
  138. {
  139. if ($result > 0)
  140. {
  141. // Creation user
  142. $nuser = new User($db);
  143. $result=$nuser->create_from_member($object,$_POST["login"]);
  144. if ($result < 0)
  145. {
  146. $langs->load("errors");
  147. $errmsg=$langs->trans($nuser->error);
  148. }
  149. }
  150. else
  151. {
  152. $errmsg=$object->error;
  153. }
  154. }
  155. // Create third party from a member
  156. if ($_POST["action"] == 'confirm_create_thirdparty' && $_POST["confirm"] == 'yes' && $user->rights->societe->creer)
  157. {
  158. if ($result > 0)
  159. {
  160. // Creation user
  161. $company = new Societe($db);
  162. $result=$company->create_from_member($object,$_POST["companyname"]);
  163. if ($result < 0)
  164. {
  165. $langs->load("errors");
  166. $errmsg=$langs->trans($company->error);
  167. $errmsgs=$company->errors;
  168. }
  169. }
  170. else
  171. {
  172. $errmsg=$object->error;
  173. }
  174. }
  175. if ($_REQUEST["action"] == 'confirm_sendinfo' && $_REQUEST["confirm"] == 'yes')
  176. {
  177. if ($object->email)
  178. {
  179. $result=$object->send_an_email($langs->transnoentitiesnoconv("ThisIsContentOfYourCard")."\n\n%INFOS%\n\n",$langs->transnoentitiesnoconv("CardContent"));
  180. $mesg=$langs->trans("CardSent");
  181. }
  182. }
  183. if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
  184. {
  185. require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
  186. $datenaiss='';
  187. if (isset($_POST["naissday"]) && $_POST["naissday"]
  188. && isset($_POST["naissmonth"]) && $_POST["naissmonth"]
  189. && isset($_POST["naissyear"]) && $_POST["naissyear"])
  190. {
  191. $datenaiss=dol_mktime(12, 0, 0, $_POST["naissmonth"], $_POST["naissday"], $_POST["naissyear"]);
  192. }
  193. // Create new object
  194. if ($result > 0)
  195. {
  196. $object->oldcopy=dol_clone($object);
  197. // Change values
  198. $object->civilite_id = trim($_POST["civilite_id"]);
  199. $object->prenom = trim($_POST["prenom"]);
  200. $object->nom = trim($_POST["nom"]);
  201. $object->login = trim($_POST["login"]);
  202. $object->pass = trim($_POST["pass"]);
  203. $object->societe = trim($_POST["societe"]);
  204. $object->adresse = trim($_POST["address"]); // deprecated
  205. $object->address = trim($_POST["address"]);
  206. $object->cp = trim($_POST["zipcode"]); // deprecated
  207. $object->zip = trim($_POST["zipcode"]);
  208. $object->ville = trim($_POST["town"]); // deprecated
  209. $object->town = trim($_POST["town"]);
  210. $object->state_id = $_POST["departement_id"];
  211. $object->country_id = $_POST["pays_id"];
  212. $object->fk_departement = $_POST["departement_id"]; // deprecated
  213. $object->pays_id = $_POST["pays_id"]; // deprecated
  214. $object->phone = trim($_POST["phone"]);
  215. $object->phone_perso = trim($_POST["phone_perso"]);
  216. $object->phone_mobile= trim($_POST["phone_mobile"]);
  217. $object->email = trim($_POST["email"]);
  218. $object->naiss = $datenaiss;
  219. $object->typeid = $_POST["typeid"];
  220. $object->note = trim($_POST["comment"]);
  221. $object->morphy = $_POST["morphy"];
  222. $object->amount = $_POST["amount"];
  223. if (GETPOST('deletephoto')) $object->photo='';
  224. elseif (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
  225. // Get status and public property
  226. $object->statut = $_POST["statut"];
  227. $object->public = $_POST["public"];
  228. // Get extra fields
  229. foreach($_POST as $key => $value)
  230. {
  231. if (preg_match("/^options_/",$key))
  232. {
  233. $object->array_options[$key]=$_POST[$key];
  234. }
  235. }
  236. // Check if we need to also synchronize user information
  237. $nosyncuser=0;
  238. if ($object->user_id) // If linked to a user
  239. {
  240. if ($user->id != $object->user_id && empty($user->rights->user->user->creer)) $nosyncuser=1; // Disable synchronizing
  241. }
  242. // Check if we need to also synchronize password information
  243. $nosyncuserpass=0;
  244. if ($object->user_id) // If linked to a user
  245. {
  246. if ($user->id != $object->user_id && empty($user->rights->user->user->password)) $nosyncuserpass=1; // Disable synchronizing
  247. }
  248. $result=$object->update($user,0,$nosyncuser,$nosyncuserpass);
  249. if ($result >= 0 && ! sizeof($object->errors))
  250. {
  251. $dir= $conf->adherent->dir_output . '/' . get_exdir($object->id,2,0,1).'/photos';
  252. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  253. if ($file_OK)
  254. {
  255. if (GETPOST('deletephoto'))
  256. {
  257. $fileimg=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/'.$object->photo;
  258. $dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/thumbs';
  259. dol_delete_file($fileimg);
  260. dol_delete_dir_recursive($dirthumbs);
  261. }
  262. if (image_format_supported($_FILES['photo']['name']) > 0)
  263. {
  264. dol_mkdir($dir);
  265. if (@is_dir($dir))
  266. {
  267. $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  268. if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']) > 0)
  269. {
  270. $message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>';
  271. }
  272. else
  273. {
  274. // Create small thumbs for company (Ratio is near 16/9)
  275. // Used on logon for example
  276. $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
  277. // Create mini thumbs for company (Ratio is near 16/9)
  278. // Used on menu or for setup page for example
  279. $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
  280. }
  281. }
  282. }
  283. else
  284. {
  285. $errmsgs[] = "ErrorBadImageFormat";
  286. }
  287. }
  288. $_GET["rowid"]=$object->id;
  289. $_REQUEST["action"]='';
  290. }
  291. else
  292. {
  293. if ($object->error) $errmsg=$object->error;
  294. else $errmsgs=$object->errors;
  295. $action='';
  296. }
  297. }
  298. }
  299. if ($_POST["action"] == 'add' && $user->rights->adherent->creer)
  300. {
  301. $datenaiss='';
  302. if (isset($_POST["naissday"]) && $_POST["naissday"]
  303. && isset($_POST["naissmonth"]) && $_POST["naissmonth"]
  304. && isset($_POST["naissyear"]) && $_POST["naissyear"])
  305. {
  306. $datenaiss=dol_mktime(12, 0, 0, $_POST["naissmonth"], $_POST["naissday"], $_POST["naissyear"]);
  307. }
  308. $datecotisation='';
  309. if (isset($_POST["reday"]) && isset($_POST["remonth"]) && isset($_POST["reyear"]))
  310. {
  311. $datecotisation=dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
  312. }
  313. $typeid=$_POST["typeid"];
  314. $civilite_id=$_POST["civilite_id"];
  315. $nom=$_POST["nom"];
  316. $prenom=$_POST["prenom"];
  317. $societe=$_POST["societe"];
  318. $address=$_POST["address"];
  319. $zip=$_POST["zipcode"];
  320. $town=$_POST["town"];
  321. $departement_id=$_POST["departement_id"];
  322. $pays_id=$_POST["pays_id"];
  323. $phone=$_POST["phone"];
  324. $phone_perso=$_POST["phone_perso"];
  325. $phone_mobile=$_POST["phone_mobile"];
  326. $email=$_POST["member_email"];
  327. $login=$_POST["member_login"];
  328. $pass=$_POST["password"];
  329. $photo=$_POST["photo"];
  330. $comment=$_POST["comment"];
  331. $morphy=$_POST["morphy"];
  332. $cotisation=$_POST["cotisation"];
  333. $public=$_POST["public"];
  334. $userid=$_POST["userid"];
  335. $socid=$_POST["socid"];
  336. $object->civilite_id = $civilite_id;
  337. $object->prenom = $prenom;
  338. $object->nom = $nom;
  339. $object->societe = $societe;
  340. $object->adresse = $address; // deprecated
  341. $object->address = $address;
  342. $object->cp = $zip; // deprecated
  343. $object->zip = $zip;
  344. $object->ville = $town; // deprecated
  345. $object->town = $town;
  346. $object->fk_departement = $departement_id;
  347. $object->pays_id = $pays_id;
  348. $object->phone = $phone;
  349. $object->phone_perso = $phone_perso;
  350. $object->phone_mobile= $phone_mobile;
  351. $object->email = $email;
  352. $object->login = $login;
  353. $object->pass = $pass;
  354. $object->naiss = $datenaiss;
  355. $object->photo = $photo;
  356. $object->typeid = $typeid;
  357. $object->note = $comment;
  358. $object->morphy = $morphy;
  359. $object->user_id = $userid;
  360. $object->fk_soc = $socid;
  361. $object->public = $public;
  362. // Get extra fields
  363. foreach($_POST as $key => $value)
  364. {
  365. if (preg_match("/^options_/",$key))
  366. {
  367. $object->array_options[$key]=$_POST[$key];
  368. }
  369. }
  370. // Check parameters
  371. if (empty($morphy) || $morphy == "-1") {
  372. $error++;
  373. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Nature"))."<br>\n";
  374. }
  375. // Test si le login existe deja
  376. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  377. {
  378. if (empty($login)) {
  379. $error++;
  380. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->trans("Login"))."<br>\n";
  381. }
  382. else {
  383. $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'";
  384. $result = $db->query($sql);
  385. if ($result) {
  386. $num = $db->num_rows($result);
  387. }
  388. if ($num) {
  389. $error++;
  390. $langs->load("errors");
  391. $errmsg .= $langs->trans("ErrorLoginAlreadyExists",$login)."<br>\n";
  392. }
  393. }
  394. if (empty($pass)) {
  395. $error++;
  396. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentities("Password"))."<br>\n";
  397. }
  398. }
  399. if (empty($nom)) {
  400. $error++;
  401. $langs->load("errors");
  402. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname"))."<br>\n";
  403. }
  404. if ($morphy != 'mor' && (!isset($prenom) || $prenom=='')) {
  405. $error++;
  406. $langs->load("errors");
  407. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname"))."<br>\n";
  408. }
  409. if (! ($typeid > 0)) { // Keep () before !
  410. $error++;
  411. $errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"))."<br>\n";
  412. }
  413. if ($conf->global->ADHERENT_MAIL_REQUIRED && ! isValidEMail($email)) {
  414. $error++;
  415. $langs->load("errors");
  416. $errmsg .= $langs->trans("ErrorBadEMail",$email)."<br>\n";
  417. }
  418. $public=0;
  419. if (isset($public)) $public=1;
  420. if (! $error)
  421. {
  422. $db->begin();
  423. // Email a peu pres correct et le login n'existe pas
  424. $result=$object->create($user);
  425. if ($result > 0)
  426. {
  427. $db->commit();
  428. $rowid=$object->id;
  429. $action='';
  430. }
  431. else
  432. {
  433. $db->rollback();
  434. if ($object->error) $errmsg=$object->error;
  435. else $errmsgs=$object->errors;
  436. $action = 'create';
  437. }
  438. }
  439. else {
  440. $action = 'create';
  441. }
  442. }
  443. if ($user->rights->adherent->supprimer && $_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
  444. {
  445. $result=$object->delete($rowid);
  446. if ($result > 0)
  447. {
  448. Header("Location: liste.php");
  449. exit;
  450. }
  451. else
  452. {
  453. $errmesg=$object->error;
  454. }
  455. }
  456. if ($user->rights->adherent->creer && $_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes')
  457. {
  458. $result=$object->validate($user);
  459. $adht = new AdherentType($db);
  460. $adht->fetch($object->typeid);
  461. if ($result >= 0 && ! sizeof($object->errors))
  462. {
  463. // Send confirmation Email (selon param du type adherent sinon generique)
  464. if ($object->email && $_POST["send_mail"])
  465. {
  466. $result=$object->send_an_email($adht->getMailOnValid(),$conf->global->ADHERENT_MAIL_VALID_SUBJECT,array(),array(),array(),"","",0,2);
  467. if ($result < 0)
  468. {
  469. $errmsg.=$object->error;
  470. }
  471. }
  472. // Rajoute l'utilisateur dans les divers abonnements (mailman, spip, etc...)
  473. if ($object->add_to_abo() < 0)
  474. {
  475. // error
  476. $errmsg.= $langs->trans("FaildToAddToMailmanList").': '.$object->error."<br>\n";
  477. }
  478. }
  479. else
  480. {
  481. if ($object->error) $errmsg=$object->error;
  482. else $errmsgs=$object->errors;
  483. $action='';
  484. }
  485. }
  486. if ($user->rights->adherent->supprimer && $_POST["action"] == 'confirm_resign' && $_POST["confirm"] == 'yes')
  487. {
  488. $adht = new AdherentType($db);
  489. $adht->fetch($object->typeid);
  490. $result=$object->resiliate($user);
  491. if ($result >= 0 && ! sizeof($object->errors))
  492. {
  493. if ($object->email && $_POST["send_mail"])
  494. {
  495. $result=$object->send_an_email($adht->getMailOnResiliate(),$conf->global->ADHERENT_MAIL_RESIL_SUBJECT,array(),array(),array(),"","",0,-1);
  496. }
  497. if ($result < 0)
  498. {
  499. $errmsg.=$object->error;
  500. }
  501. // supprime l'utilisateur des divers abonnements ..
  502. if ($object->del_to_abo() < 0)
  503. {
  504. // error
  505. $errmsg.=$langs->trans("FaildToRemoveFromMailmanList").': '.$object->error."<br>\n";
  506. }
  507. }
  508. else
  509. {
  510. if ($object->error) $errmsg=$object->error;
  511. else $errmsgs=$object->errors;
  512. $action='';
  513. }
  514. }
  515. if ($user->rights->adherent->supprimer && $_POST["action"] == 'confirm_del_spip' && $_POST["confirm"] == 'yes')
  516. {
  517. if (! sizeof($object->errors))
  518. {
  519. if(!$object->del_to_spip()){
  520. $errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$object->error."<BR>\n";
  521. }
  522. }
  523. }
  524. if ($user->rights->adherent->creer && $_POST["action"] == 'confirm_add_spip' && $_POST["confirm"] == 'yes')
  525. {
  526. if (! sizeof($object->errors))
  527. {
  528. if (!$object->add_to_spip())
  529. {
  530. $errmsg.="Echec du rajout de l'utilisateur dans spip: ".$object->error."<BR>\n";
  531. }
  532. }
  533. }
  534. /*
  535. * View
  536. */
  537. // fetch optionals attributes and labels
  538. $extralabels=$extrafields->fetch_name_optionals_label('member');
  539. $help_url='EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros';
  540. llxHeader('',$langs->trans("Member"),$help_url);
  541. $html = new Form($db);
  542. $htmlcompany = new FormCompany($db);
  543. $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  544. if ($action == 'create')
  545. {
  546. /* ************************************************************************** */
  547. /* */
  548. /* Fiche creation */
  549. /* */
  550. /* ************************************************************************** */
  551. $object->fk_departement = $_POST["departement_id"];
  552. // We set pays_id, pays_code and label for the selected country
  553. $object->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
  554. if ($object->pays_id)
  555. {
  556. $sql = "SELECT rowid, code, libelle";
  557. $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
  558. $sql.= " WHERE rowid = ".$object->pays_id;
  559. $resql=$db->query($sql);
  560. if ($resql)
  561. {
  562. $obj = $db->fetch_object($resql);
  563. }
  564. else
  565. {
  566. dol_print_error($db);
  567. }
  568. $object->pays_id=$obj->rowid;
  569. $object->pays_code=$obj->code;
  570. $object->pays=$obj->libelle;
  571. }
  572. $adht = new AdherentType($db);
  573. print_fiche_titre($langs->trans("NewMember"));
  574. dol_htmloutput_mesg($errmsg,$errmsgs,'error');
  575. dol_htmloutput_mesg($mesg,$mesgs);
  576. if ($conf->use_javascript_ajax)
  577. {
  578. print "\n".'<script type="text/javascript" language="javascript">';
  579. print 'jQuery(document).ready(function () {
  580. jQuery("#selectpays_id").change(function() {
  581. document.formsoc.action.value="create";
  582. document.formsoc.submit();
  583. });
  584. })';
  585. print '</script>'."\n";
  586. }
  587. print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
  588. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  589. print '<input type="hidden" name="action" value="add">';
  590. print '<table class="border" width="100%">';
  591. // Login
  592. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  593. {
  594. print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td><input type="text" name="member_login" size="40" value="'.(isset($_POST["member_login"])?$_POST["member_login"]:$object->login).'"></td></tr>';
  595. }
  596. // Moral-Physique
  597. $morphys["phy"] = $langs->trans("Physical");
  598. $morphys["mor"] = $langs->trans("Moral");
  599. print '<tr><td><span class="fieldrequired">'.$langs->trans("Nature")."</span></td><td>\n";
  600. print $html->selectarray("morphy", $morphys, isset($_POST["morphy"])?$_POST["morphy"]:$object->morphy, 1);
  601. print "</td>\n";
  602. // Type
  603. print '<tr><td><span class="fieldrequired">'.$langs->trans("MemberType").'</span></td><td>';
  604. $listetype=$adht->liste_array();
  605. if (sizeof($listetype))
  606. {
  607. print $html->selectarray("typeid", $listetype, isset($_POST["typeid"])?$_POST["typeid"]:$typeid, 1);
  608. } else {
  609. print '<font class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</font>';
  610. }
  611. print "</td>\n";
  612. // Company
  613. print '<tr><td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.(isset($_POST["societe"])?$_POST["societe"]:$object->societe).'"></td></tr>';
  614. // Civility
  615. print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
  616. print $htmlcompany->select_civilite(isset($_POST["civilite_id"])?$_POST["civilite_id"]:$object->civilite_id,'civilite_id').'</td>';
  617. print '</tr>';
  618. // Lastname
  619. print '<tr><td><span class="fieldrequired">'.$langs->trans("Lastname").'</span></td><td><input type="text" name="nom" value="'.(isset($_POST["nom"])?$_POST["nom"]:$object->nom).'" size="40"></td>';
  620. print '</tr>';
  621. // Firstname
  622. print '<tr><td>'.$langs->trans("Firstname").'</td><td><input type="text" name="prenom" size="40" value="'.(isset($_POST["prenom"])?$_POST["prenom"]:$object->prenom).'"></td>';
  623. print '</tr>';
  624. // Password
  625. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  626. {
  627. include_once(DOL_DOCUMENT_ROOT.'/lib/security.lib.php');
  628. $generated_password=getRandomPassword('');
  629. print '<tr><td><span class="fieldrequired">'.$langs->trans("Password").'</span></td><td>';
  630. print '<input size="30" maxsize="32" type="text" name="password" value="'.$generated_password.'">';
  631. print '</td></tr>';
  632. }
  633. // Address
  634. print '<tr><td valign="top">'.$langs->trans("Address").'</td><td>';
  635. print '<textarea name="address" wrap="soft" cols="40" rows="2">'.(isset($_POST["address"])?$_POST["address"]:$object->address).'</textarea>';
  636. print '</td></tr>';
  637. // Zip / Town
  638. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
  639. print $htmlcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectpays_id','departement_id'),6);
  640. print ' ';
  641. print $htmlcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectpays_id','departement_id'));
  642. print '</td></tr>';
  643. // Country
  644. $object->pays_id=$object->pays_id?$object->pays_id:$mysoc->pays_id;
  645. print '<tr><td width="25%">'.$langs->trans('Country').'</td><td>';
  646. $html->select_pays(isset($_POST["pays_id"])?$_POST["pays_id"]:$object->pays_id,'pays_id');
  647. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  648. print '</td></tr>';
  649. // State
  650. if (empty($conf->global->MEMBER_DISABLE_STATE))
  651. {
  652. print '<tr><td>'.$langs->trans('State').'</td><td>';
  653. if ($object->pays_id)
  654. {
  655. $htmlcompany->select_departement(isset($_POST["departement_id"])?$_POST["departement_id"]:$object->fk_departement,$object->pays_code);
  656. }
  657. else
  658. {
  659. print $countrynotdefined;
  660. }
  661. print '</td></tr>';
  662. }
  663. // Tel pro
  664. print '<tr><td>'.$langs->trans("PhonePro").'</td><td><input type="text" name="phone" size="20" value="'.(isset($_POST["phone"])?$_POST["phone"]:$object->phone).'"></td></tr>';
  665. // Tel perso
  666. print '<tr><td>'.$langs->trans("PhonePerso").'</td><td><input type="text" name="phone_perso" size="20" value="'.(isset($_POST["phone_perso"])?$_POST["phone_perso"]:$object->phone_perso).'"></td></tr>';
  667. // Tel mobile
  668. print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td><input type="text" name="phone_mobile" size="20" value="'.(isset($_POST["phone_mobile"])?$_POST["phone_mobile"]:$object->phone_mobile).'"></td></tr>';
  669. // EMail
  670. 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" size="40" value="'.(isset($_POST["member_email"])?$_POST["member_email"]:$object->email).'"></td></tr>';
  671. // Birthday
  672. print "<tr><td>".$langs->trans("Birthday")."</td><td>\n";
  673. $html->select_date(($object->naiss ? $object->naiss : -1),'naiss','','',1,'formsoc');
  674. print "</td></tr>\n";
  675. // Profil public
  676. print "<tr><td>".$langs->trans("Public")."</td><td>\n";
  677. print $html->selectyesno("public",$object->public,1);
  678. print "</td></tr>\n";
  679. // Other attributes
  680. $parameters=array();
  681. $reshook=$hookmanager->executeHooks('showInputFields',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  682. if (empty($reshook))
  683. {
  684. foreach($extrafields->attribute_label as $key=>$label)
  685. {
  686. $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:'');
  687. print "<tr><td>".$label.'</td><td>';
  688. print $extrafields->showInputField($key,$value);
  689. print '</td></tr>'."\n";
  690. }
  691. }
  692. /*
  693. // Third party Dolibarr
  694. if ($conf->societe->enabled)
  695. {
  696. print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td class="valeur">';
  697. print $html->select_societes($object->fk_soc,'socid','',1);
  698. print '</td></tr>';
  699. }
  700. // Login Dolibarr
  701. print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td class="valeur">';
  702. print $html->select_users($object->user_id,'userid',1);
  703. print '</td></tr>';
  704. */
  705. print "</table>\n";
  706. print '<br>';
  707. print '<center><input type="submit" class="button" value="'.$langs->trans("AddMember").'"></center>';
  708. print "</form>\n";
  709. }
  710. if ($action == 'edit')
  711. {
  712. /********************************************
  713. *
  714. * Fiche en mode edition
  715. *
  716. ********************************************/
  717. //$object = new Adherent($db);
  718. $res=$object->fetch($rowid);
  719. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  720. //$res=$object->fetch_optionals($rowid,$extralabels);
  721. //if ($res < 0) { dol_print_error($db); exit; }
  722. $adht = new AdherentType($db);
  723. $adht->fetch($object->typeid);
  724. // We set pays_id, and pays_code label of the chosen country
  725. if (isset($_POST["pays"]) || $object->pays_id)
  726. {
  727. $sql = "SELECT rowid, code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".(isset($_POST["pays"])?$_POST["pays"]:$object->pays_id);
  728. $resql=$db->query($sql);
  729. if ($resql)
  730. {
  731. $obj = $db->fetch_object($resql);
  732. }
  733. else
  734. {
  735. dol_print_error($db);
  736. }
  737. $object->pays_id=$obj->rowid;
  738. $object->pays_code=$obj->code;
  739. $object->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
  740. }
  741. $head = member_prepare_head($object);
  742. dol_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
  743. dol_htmloutput_errors($errmsg,$errmsgs);
  744. if ($mesg) print '<div class="ok">'.$mesg.'</div>';
  745. if ($conf->use_javascript_ajax)
  746. {
  747. print "\n".'<script type="text/javascript" language="javascript">';
  748. print 'jQuery(document).ready(function () {
  749. jQuery("#selectpays").change(function() {
  750. document.formsoc.action.value="edit";
  751. document.formsoc.submit();
  752. });
  753. })';
  754. print '</script>'."\n";
  755. }
  756. $rowspan=15;
  757. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++;
  758. if ($conf->societe->enabled) $rowspan++;
  759. print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
  760. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
  761. print '<input type="hidden" name="action" value="update" />';
  762. print '<input type="hidden" name="rowid" value="'.$rowid.'" />';
  763. print '<input type="hidden" name="statut" value="'.$object->statut.'" />';
  764. print '<table class="border" width="100%">';
  765. // Ref
  766. print '<tr><td>'.$langs->trans("Ref").'</td><td class="valeur" colspan="2">'.$object->id.'</td></tr>';
  767. // Login
  768. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  769. {
  770. print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td colspan="2"><input type="text" name="login" size="30" value="'.(isset($_POST["login"])?$_POST["login"]:$object->login).'"></td></tr>';
  771. }
  772. // Physique-Moral
  773. $morphys["phy"] = $langs->trans("Physical");
  774. $morphys["mor"] = $langs->trans("Morale");
  775. print '<tr><td><span class="fieldrequired">'.$langs->trans("Nature").'</span></td><td>';
  776. print $html->selectarray("morphy", $morphys, isset($_POST["morphy"])?$_POST["morphy"]:$object->morphy);
  777. print "</td>";
  778. // Photo
  779. print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">';
  780. print $html->showphoto('memberphoto',$object)."\n";
  781. if ($caneditfieldmember)
  782. {
  783. if ($object->photo) print "<br>\n";
  784. print '<table class="nobordernopadding">';
  785. if ($object->photo) print '<tr><td align="center"><input type="checkbox" class="flat" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
  786. print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
  787. print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
  788. print '</table>';
  789. }
  790. print '</td>';
  791. // Type
  792. print '<tr><td><span class="fieldrequired">'.$langs->trans("Type").'</span></td><td>';
  793. if ($user->rights->adherent->creer)
  794. {
  795. print $html->selectarray("typeid", $adht->liste_array(), (isset($_POST["typeid"])?$_POST["typeid"]:$object->typeid));
  796. }
  797. else
  798. {
  799. print $adht->getNomUrl(1);
  800. print '<input type="hidden" name="typeid" value="'.$object->typeid.'">';
  801. }
  802. print "</td></tr>";
  803. // Company
  804. print '<tr><td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.(isset($_POST["societe"])?$_POST["societe"]:$object->societe).'"></td></tr>';
  805. // Civilite
  806. print '<tr><td width="20%">'.$langs->trans("UserTitle").'</td><td width="35%">';
  807. print $htmlcompany->select_civilite(isset($_POST["civilite_id"])?$_POST["civilite_id"]:$object->civilite_id)."\n";
  808. print '</td>';
  809. print '</tr>';
  810. // Name
  811. print '<tr><td><span class="fieldrequired">'.$langs->trans("Lastname").'</span></td><td><input type="text" name="nom" size="40" value="'.(isset($_POST["nom"])?$_POST["nom"]:$object->nom).'"></td>';
  812. print '</tr>';
  813. // Firstname
  814. print '<tr><td width="20%">'.$langs->trans("Firstname").'</td><td><input type="text" name="prenom" size="40" value="'.(isset($_POST["prenom"])?$_POST["prenom"]:$object->prenom).'"></td>';
  815. print '</tr>';
  816. // Password
  817. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  818. {
  819. print '<tr><td><span class="fieldrequired">'.$langs->trans("Password").'</span></td><td><input type="password" name="pass" size="30" value="'.(isset($_POST["pass"])?$_POST["pass"]:$object->pass).'"></td></tr>';
  820. }
  821. // Address
  822. print '<tr><td>'.$langs->trans("Address").'</td><td>';
  823. print '<textarea name="address" wrap="soft" cols="40" rows="2">'.(isset($_POST["address"])?$_POST["address"]:$object->address).'</textarea>';
  824. print '</td></tr>';
  825. // Zip / Town
  826. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
  827. print $htmlcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectpays_id','departement_id'),6);
  828. print ' ';
  829. print $htmlcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectpays_id','departement_id'));
  830. print '</td></tr>';
  831. // Country
  832. //$object->pays_id=$object->pays_id?$object->pays_id:$mysoc->pays_id; // In edit mode we don't force to company country if not defined
  833. print '<tr><td width="25%">'.$langs->trans('Country').'</td><td>';
  834. $html->select_pays(isset($_POST["pays_id"])?$_POST["pays_id"]:$object->pays_id,'pays_id');
  835. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  836. print '</td></tr>';
  837. // State
  838. if (empty($conf->global->MEMBER_DISABLE_STATE))
  839. {
  840. print '<tr><td>'.$langs->trans('State').'</td><td>';
  841. $htmlcompany->select_departement($object->fk_departement,$object->pays_code);
  842. print '</td></tr>';
  843. }
  844. // Tel
  845. print '<tr><td>'.$langs->trans("PhonePro").'</td><td><input type="text" name="phone" size="20" value="'.(isset($_POST["phone"])?$_POST["phone"]:$object->phone).'"></td></tr>';
  846. // Tel perso
  847. print '<tr><td>'.$langs->trans("PhonePerso").'</td><td><input type="text" name="phone_perso" size="20" value="'.(isset($_POST["phone_perso"])?$_POST["phone_perso"]:$object->phone_perso).'"></td></tr>';
  848. // Tel mobile
  849. print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td><input type="text" name="phone_mobile" size="20" value="'.(isset($_POST["phone_mobile"])?$_POST["phone_mobile"]:$object->phone_mobile).'"></td></tr>';
  850. // EMail
  851. 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="email" size="40" value="'.(isset($_POST["email"])?$_POST["email"]:$object->email).'"></td></tr>';
  852. // Date naissance
  853. print "<tr><td>".$langs->trans("Birthday")."</td><td>\n";
  854. $html->select_date(($object->naiss ? $object->naiss : -1),'naiss','','',1,'formsoc');
  855. print "</td></tr>\n";
  856. // Profil public
  857. print "<tr><td>".$langs->trans("Public")."</td><td>\n";
  858. print $html->selectyesno("public",(isset($_POST["public"])?$_POST["public"]:$object->public),1);
  859. print "</td></tr>\n";
  860. // Other attributes
  861. $parameters=array();
  862. $reshook=$hookmanager->executeHooks('showInputFields',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  863. if (empty($reshook))
  864. {
  865. foreach($extrafields->attribute_label as $key=>$label)
  866. {
  867. $value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$object->array_options["options_$key"]);
  868. print "<tr><td>".$label."</td><td>";
  869. print $extrafields->showInputField($key,$value);
  870. print "</td></tr>\n";
  871. }
  872. }
  873. // Third party Dolibarr
  874. if ($conf->societe->enabled)
  875. {
  876. print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2" class="valeur">';
  877. if ($object->fk_soc)
  878. {
  879. $company=new Societe($db);
  880. $result=$company->fetch($object->fk_soc);
  881. print $company->getNomUrl(1);
  882. }
  883. else
  884. {
  885. print $langs->trans("NoThirdPartyAssociatedToMember");
  886. }
  887. print '</td></tr>';
  888. }
  889. // Login Dolibarr
  890. print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td colspan="2" class="valeur">';
  891. if ($object->user_id)
  892. {
  893. print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'none');
  894. }
  895. else print $langs->trans("NoDolibarrAccess");
  896. print '</td></tr>';
  897. print '<tr><td colspan="3" align="center">';
  898. print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  899. print ' &nbsp; &nbsp; &nbsp; ';
  900. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  901. print '</td></tr>';
  902. print '</table>';
  903. print '</form>';
  904. print '</div>';
  905. }
  906. if ($rowid && $action != 'edit')
  907. {
  908. /* ************************************************************************** */
  909. /* */
  910. /* Mode affichage */
  911. /* */
  912. /* ************************************************************************** */
  913. //$object = new Adherent($db);
  914. $res=$object->fetch($rowid);
  915. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  916. //$res=$object->fetch_optionals($rowid,$extralabels);
  917. //if ($res < 0) { dol_print_error($db); exit; }
  918. $adht = new AdherentType($db);
  919. $res=$adht->fetch($object->typeid);
  920. if ($res < 0) { dol_print_error($db); exit; }
  921. /*
  922. * Affichage onglets
  923. */
  924. $head = member_prepare_head($object);
  925. dol_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
  926. dol_htmloutput_errors($errmsg,$errmsgs);
  927. // Confirm create user
  928. if ($_GET["action"] == 'create_user')
  929. {
  930. $login=$object->login;
  931. if (empty($login))
  932. {
  933. // Full firstname and name separated with a dot : firstname.name
  934. include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');
  935. $login=dol_buildlogin($object->nom,$object->prenom);
  936. }
  937. if (empty($login)) $login=strtolower(substr($object->prenom, 0, 4)) . strtolower(substr($object->nom, 0, 4));
  938. // Create a form array
  939. $formquestion=array(
  940. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
  941. );
  942. $text=$langs->trans("ConfirmCreateLogin").'<br>';
  943. if ($conf->societe->enabled)
  944. {
  945. if ($object->fk_soc > 0) $text.=$langs->trans("UserWillBeExternalUser");
  946. else $text.=$langs->trans("UserWillBeInternalUser");
  947. }
  948. $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrLogin"),$text,"confirm_create_user",$formquestion,'yes');
  949. if ($ret == 'html') print '<br>';
  950. }
  951. // Confirm create third party
  952. if ($_GET["action"] == 'create_thirdparty')
  953. {
  954. $name = $object->getFullName($langs);
  955. if (! empty($name))
  956. {
  957. if ($object->societe) $name.=' ('.$object->societe.')';
  958. }
  959. else
  960. {
  961. $name=$object->societe;
  962. }
  963. // Create a form array
  964. $formquestion=array(
  965. array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $name));
  966. $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion,1);
  967. if ($ret == 'html') print '<br>';
  968. }
  969. // Confirm validate member
  970. if ($action == 'valid')
  971. {
  972. $langs->load("mails");
  973. $adht = new AdherentType($db);
  974. $adht->fetch($object->typeid);
  975. $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_VALID_SUBJECT);
  976. $texttosend=$object->makeSubstitution($adht->getMailOnValid());
  977. $tmp=$langs->trans("SendAnEMailToMember");
  978. $tmp.=' ('.$langs->trans("MailFrom").': <b>'.$conf->global->ADHERENT_MAIL_FROM.'</b>, ';
  979. $tmp.=$langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
  980. $helpcontent='';
  981. $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  982. $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  983. $helpcontent.='<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
  984. $helpcontent.=$subjecttosend."\n";
  985. $helpcontent.="<br>";
  986. $helpcontent.='<b>'.$langs->trans("Content").'</b>:<br>';
  987. $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
  988. $label=$html->textwithpicto($tmp,$helpcontent,1,'help');
  989. // Cree un tableau formulaire
  990. $formquestion=array();
  991. if ($object->email) $formquestion[0]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => ($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL?true:false));
  992. $ret=$html->form_confirm("fiche.php?rowid=$rowid",$langs->trans("ValidateMember"),$langs->trans("ConfirmValidateMember"),"confirm_valid",$formquestion,1);
  993. if ($ret == 'html') print '<br>';
  994. }
  995. // Confirm send card by mail
  996. if ($action == 'sendinfo')
  997. {
  998. $ret=$html->form_confirm("fiche.php?rowid=$rowid",$langs->trans("SendCardByMail"),$langs->trans("ConfirmSendCardByMail",$object->email),"confirm_sendinfo",'',0,1);
  999. if ($ret == 'html') print '<br>';
  1000. }
  1001. // Confirm resiliate
  1002. if ($action == 'resign')
  1003. {
  1004. $langs->load("mails");
  1005. $adht = new AdherentType($db);
  1006. $adht->fetch($object->typeid);
  1007. $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_RESIL_SUBJECT);
  1008. $texttosend=$object->makeSubstitution($adht->getMailOnResiliate());
  1009. $tmp=$langs->trans("SendAnEMailToMember");
  1010. $tmp.=' ('.$langs->trans("MailFrom").': <b>'.$conf->global->ADHERENT_MAIL_FROM.'</b>, ';
  1011. $tmp.=$langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
  1012. $helpcontent='';
  1013. $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  1014. $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  1015. $helpcontent.='<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
  1016. $helpcontent.=$subjecttosend."\n";
  1017. $helpcontent.="<br>";
  1018. $helpcontent.='<b>'.$langs->trans("Content").'</b>:<br>';
  1019. $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
  1020. $label=$html->textwithpicto($tmp,$helpcontent,1,'help');
  1021. // Cree un tableau formulaire
  1022. $formquestion=array();
  1023. if ($object->email) $formquestion[0]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => ($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL?'true':'false'));
  1024. $ret=$html->form_confirm("fiche.php?rowid=$rowid",$langs->trans("ResiliateMember"),$langs->trans("ConfirmResiliateMember"),"confirm_resign",$formquestion);
  1025. if ($ret == 'html') print '<br>';
  1026. }
  1027. // Confirm remove member
  1028. if ($action == 'delete')
  1029. {
  1030. $ret=$html->form_confirm("fiche.php?rowid=$rowid",$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete",'',0,1);
  1031. if ($ret == 'html') print '<br>';
  1032. }
  1033. /*
  1034. * Confirm add in spip
  1035. */
  1036. if ($action == 'add_spip')
  1037. {
  1038. $ret=$html->form_confirm("fiche.php?rowid=$rowid","Ajouter dans spip","Etes-vous sur de vouloir ajouter cet adherent dans spip ? (serveur : ".ADHERENT_SPIP_SERVEUR.")","confirm_add_spip");
  1039. if ($ret == 'html') print '<br>';
  1040. }
  1041. /*
  1042. * Confirm removed from spip
  1043. */
  1044. if ($action == 'del_spip')
  1045. {
  1046. $ret=$html->form_confirm("fiche.php?rowid=$rowid","Supprimer dans spip","Etes-vous sur de vouloir effacer cet adherent dans spip ? (serveur : ".ADHERENT_SPIP_SERVEUR.")","confirm_del_spip");
  1047. if ($ret == 'html') print '<br>';
  1048. }
  1049. $rowspan=17;
  1050. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++;
  1051. if ($conf->societe->enabled) $rowspan++;
  1052. print '<table class="border" width="100%">';
  1053. // Ref
  1054. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  1055. print '<td class="valeur" colspan="2">';
  1056. print $html->showrefnav($object,'rowid');
  1057. print '</td></tr>';
  1058. $showphoto='<td rowspan="'.$rowspan.'" align="center" valign="middle" width="25%">';
  1059. $showphoto.=$html->showphoto('memberphoto',$object);
  1060. $showphoto.='</td>';
  1061. // Login
  1062. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  1063. {
  1064. print '<tr><td>'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td>';
  1065. print $showphoto; $showphoto='';
  1066. print '</tr>';
  1067. }
  1068. // Morphy
  1069. print '<tr><td>'.$langs->trans("Nature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
  1070. print $showphoto; $showphoto='';
  1071. print '</tr>';
  1072. // Type
  1073. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  1074. // Company
  1075. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->societe.'</td></tr>';
  1076. // Civility
  1077. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'&nbsp;</td>';
  1078. print '</tr>';
  1079. // Name
  1080. print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$object->nom.'&nbsp;</td>';
  1081. print '</tr>';
  1082. // Firstname
  1083. print '<tr><td>'.$langs->trans("Firstname").'</td><td class="valeur">'.$object->prenom.'&nbsp;</td></tr>';
  1084. // Password
  1085. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  1086. {
  1087. print '<tr><td>'.$langs->trans("Password").'</td><td>'.preg_replace('/./i','*',$object->pass).'</td></tr>';
  1088. }
  1089. // Address
  1090. print '<tr><td>'.$langs->trans("Address").'</td><td class="valeur">';
  1091. dol_print_address($object->address,'gmap','member',$object->id);
  1092. print '</td></tr>';
  1093. // Zip / Town
  1094. print '<tr><td nowrap="nowrap">'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td class="valeur">'.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'</td></tr>';
  1095. // Country
  1096. print '<tr><td>'.$langs->trans("Country").'</td><td class="valeur">';
  1097. $img=picto_from_langcode($object->pays_code);
  1098. if ($img) print $img.' ';
  1099. print getCountry($object->pays_code);
  1100. print '</td></tr>';
  1101. // State
  1102. print '<tr><td>'.$langs->trans('State').'</td><td class="valeur">'.$object->departement.'</td>';
  1103. // Tel pro.
  1104. print '<tr><td>'.$langs->trans("PhonePro").'</td><td class="valeur">'.dol_print_phone($object->phone,$object->pays_code,0,$object->fk_soc,1).'</td></tr>';
  1105. // Tel perso
  1106. print '<tr><td>'.$langs->trans("PhonePerso").'</td><td class="valeur">'.dol_print_phone($object->phone_perso,$object->pays_code,0,$object->fk_soc,1).'</td></tr>';
  1107. // Tel mobile
  1108. print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td class="valeur">'.dol_print_phone($object->phone_mobile,$object->pays_code,0,$object->fk_soc,1).'</td></tr>';
  1109. // EMail
  1110. print '<tr><td>'.$langs->trans("EMail").'</td><td class="valeur">'.dol_print_email($object->email,0,$object->fk_soc,1).'</td></tr>';
  1111. // Date naissance
  1112. print '<tr><td>'.$langs->trans("Birthday").'</td><td class="valeur">'.dol_print_date($object->naiss,'day').'</td></tr>';
  1113. // Public
  1114. print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
  1115. // Status
  1116. print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$object->getLibStatut(4).'</td></tr>';
  1117. // Other attributes
  1118. $parameters=array();
  1119. $reshook=$hookmanager->executeHooks('showOutputField',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1120. if (empty($reshook))
  1121. {
  1122. foreach($extrafields->attribute_label as $key=>$label)
  1123. {
  1124. $value=$object->array_options["options_$key"];
  1125. print "<tr><td>".$label."</td><td>";
  1126. print $extrafields->showOutputField($key,$value);
  1127. print "</td></tr>\n";
  1128. }
  1129. }
  1130. // Third party Dolibarr
  1131. if ($conf->societe->enabled)
  1132. {
  1133. print '<tr><td>';
  1134. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1135. print $langs->trans("LinkedToDolibarrThirdParty");
  1136. print '</td>';
  1137. if ($_GET['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>';
  1138. print '</tr></table>';
  1139. print '</td><td colspan="2" class="valeur">';
  1140. if ($_GET['action'] == 'editthirdparty')
  1141. {
  1142. $htmlname='socid';
  1143. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
  1144. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  1145. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  1146. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1147. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  1148. print '<tr><td>';
  1149. print $html->select_societes($object->fk_soc,'socid','',1);
  1150. print '</td>';
  1151. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  1152. print '</tr></table></form>';
  1153. }
  1154. else
  1155. {
  1156. if ($object->fk_soc)
  1157. {
  1158. $company=new Societe($db);
  1159. $result=$company->fetch($object->fk_soc);
  1160. print $company->getNomUrl(1);
  1161. }
  1162. else
  1163. {
  1164. print $langs->trans("NoThirdPartyAssociatedToMember");
  1165. }
  1166. }
  1167. print '</td></tr>';
  1168. }
  1169. // Login Dolibarr
  1170. print '<tr><td>';
  1171. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1172. print $langs->trans("LinkedToDolibarrUser");
  1173. print '</td>';
  1174. if ($_GET['action'] != 'editlogin' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlogin&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'),1).'</a></td>';
  1175. print '</tr></table>';
  1176. print '</td><td colspan="2" class="valeur">';
  1177. if ($_GET['action'] == 'editlogin')
  1178. {
  1179. /*$include=array();
  1180. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  1181. {
  1182. $include=array($object->user_id,$user->id);
  1183. }*/
  1184. print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'userid','');
  1185. }
  1186. else
  1187. {
  1188. if ($object->user_id)
  1189. {
  1190. print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'none');
  1191. }
  1192. else print $langs->trans("NoDolibarrAccess");
  1193. }
  1194. print '</td></tr>';
  1195. print "</table>\n";
  1196. print "</div>\n";
  1197. /*
  1198. * Barre d'actions
  1199. *
  1200. */
  1201. print '<div class="tabsAction">';
  1202. if ($action != 'valid' && $action != 'editlogin' && $action != 'editthirdparty')
  1203. {
  1204. // Modify
  1205. if ($user->rights->adherent->creer)
  1206. {
  1207. print "<a class=\"butAction\" href=\"fiche.php?rowid=$rowid&action=edit\">".$langs->trans("Modify")."</a>";
  1208. }
  1209. else
  1210. {
  1211. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("Modify")."</font>";
  1212. }
  1213. // Valider
  1214. if ($object->statut == -1)
  1215. {
  1216. if ($user->rights->adherent->creer)
  1217. {
  1218. print "<a class=\"butAction\" href=\"fiche.php?rowid=$rowid&action=valid\">".$langs->trans("Validate")."</a>\n";
  1219. }
  1220. else
  1221. {
  1222. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("Validate")."</font>";
  1223. }
  1224. }
  1225. // Reactiver
  1226. if ($object->statut == 0)
  1227. {
  1228. if ($user->rights->adherent->creer)
  1229. {
  1230. print "<a class=\"butAction\" href=\"fiche.php?rowid=$rowid&action=valid\">".$langs->trans("Reenable")."</a>\n";
  1231. }
  1232. else
  1233. {
  1234. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("Reenable")."</font>";
  1235. }
  1236. }
  1237. // Envoi fiche par mail
  1238. if ($object->statut >= 1)
  1239. {
  1240. if ($user->rights->adherent->creer)
  1241. {
  1242. if ($object->email) print "<a class=\"butAction\" href=\"fiche.php?rowid=$object->id&action=sendinfo\">".$langs->trans("SendCardByMail")."</a>\n";
  1243. else print "<a class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NoEMail"))."\">".$langs->trans("SendCardByMail")."</a>\n";
  1244. }
  1245. else
  1246. {
  1247. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("SendCardByMail")."</font>";
  1248. }
  1249. }
  1250. // Resilier
  1251. if ($object->statut >= 1)
  1252. {
  1253. if ($user->rights->adherent->supprimer)
  1254. {
  1255. print "<a class=\"butAction\" href=\"fiche.php?rowid=$rowid&action=resign\">".$langs->trans("Resiliate")."</a>\n";
  1256. }
  1257. else
  1258. {
  1259. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("Resiliate")."</font>";
  1260. }
  1261. }
  1262. // Create third party
  1263. if ($conf->societe->enabled && ! $object->fk_soc)
  1264. {
  1265. if ($user->rights->societe->creer)
  1266. {
  1267. if ($object->statut != -1) print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">'.$langs->trans("CreateDolibarrThirdParty").'</a>';
  1268. else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a>';
  1269. }
  1270. else
  1271. {
  1272. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("CreateDolibarrThirdParty")."</font>";
  1273. }
  1274. }
  1275. // Create user
  1276. if (! $user->societe_id && ! $object->user_id)
  1277. {
  1278. if ($user->rights->user->user->creer)
  1279. {
  1280. if ($object->statut != -1) print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a>';
  1281. else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrLogin").'</a>';
  1282. }
  1283. else
  1284. {
  1285. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("CreateDolibarrLogin")."</font>";
  1286. }
  1287. }
  1288. // Delete
  1289. if ($user->rights->adherent->supprimer)
  1290. {
  1291. print "<a class=\"butActionDelete\" href=\"fiche.php?rowid=$object->id&action=delete\">".$langs->trans("Delete")."</a>\n";
  1292. }
  1293. else
  1294. {
  1295. print "<font class=\"butActionRefused\" href=\"#\" title=\"".dol_escape_htmltag($langs->trans("NotEnoughPermissions"))."\">".$langs->trans("Delete")."</font>";
  1296. }
  1297. // Action SPIP
  1298. if ($conf->global->ADHERENT_USE_SPIP)
  1299. {
  1300. $isinspip=$object->is_in_spip();
  1301. if ($isinspip == 1)
  1302. {
  1303. print "<a class=\"butAction\" href=\"fiche.php?rowid=$object->id&action=del_spip\">".$langs->trans("DeleteIntoSpip")."</a>\n";
  1304. }
  1305. if ($isinspip == 0)
  1306. {
  1307. print "<a class=\"butAction\" href=\"fiche.php?rowid=$object->id&action=add_spip\">".$langs->trans("AddIntoSpip")."</a>\n";
  1308. }
  1309. if ($isinspip == -1) {
  1310. print '<br><font class="error">Failed to connect to SPIP: '.$object->error.'</font>';
  1311. }
  1312. }
  1313. }
  1314. print '</div>';
  1315. print "<br>\n";
  1316. }
  1317. $db->close();
  1318. llxFooter();
  1319. ?>