PageRenderTime 68ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/adherent/class/adherent.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 1370 lines | 635 code | 138 blank | 597 comment | 151 complexity | c27591582ff7029177530aebf23b33d3 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2002-2003 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) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  7. * Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
  8. * Copyright (C) 2012 Herve Prot <herve.prot@symeos.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. require_once(DOL_DOCUMENT_ROOT . "/core/lib/functions2.lib.php");
  24. require_once(DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php");
  25. //require_once(DOL_DOCUMENT_ROOT."/adherent/class/cotisation.class.php");
  26. /**
  27. * \class Adherent
  28. * \brief Class to manage members of a foundation
  29. */
  30. class Adherent extends nosqlDocument {
  31. public $element = 'member';
  32. public $table_element = 'adherent';
  33. protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
  34. var $id;
  35. var $ref;
  36. var $civilite_id;
  37. var $Firstname;
  38. var $Lastname;
  39. var $login;
  40. var $pass;
  41. var $societe;
  42. var $adresse;
  43. var $address;
  44. var $cp;
  45. var $zip;
  46. var $ville;
  47. var $town;
  48. var $state_id; // Id of department
  49. var $state_code; // Code of department
  50. var $state; // Label of department
  51. var $fk_departement; // deprecated
  52. var $departement_code; // deprecated
  53. var $departement; // deprecated
  54. var $country_id;
  55. var $country_code;
  56. var $country;
  57. var $pays_id; // deprecated
  58. var $pays_code; // deprecated
  59. var $pays; // deprecated
  60. var $email;
  61. var $phone;
  62. var $phone_perso;
  63. var $phone_mobile;
  64. var $morphy;
  65. var $public;
  66. var $note; // Private note
  67. var $Status; // -1:resilie, 0:brouillon, >=1:valide,paye
  68. var $photo;
  69. var $datec;
  70. var $datem;
  71. var $datefin;
  72. var $datevalid;
  73. var $naiss;
  74. var $typeid; // Id type adherent
  75. var $type; // Libelle type adherent
  76. var $need_subscription;
  77. var $user_id;
  78. var $user_login;
  79. var $fk_soc;
  80. // Fields loaded by fetch_subscriptions()
  81. var $first_subscription_date;
  82. var $first_subscription_amount;
  83. var $last_subscription_date;
  84. var $last_subscription_amount;
  85. var $subscriptions = array();
  86. // var $public;
  87. var $array_options;
  88. var $oldcopy; // To contains a clone of this when we need to save old properties of object
  89. var $cotisations = array();
  90. /**
  91. * Constructor
  92. *
  93. * @param DoliDB $db Database handler
  94. */
  95. function __construct($db = '') {
  96. parent::__construct($db);
  97. try {
  98. $fk_extrafields = new ExtraFields($db);
  99. $this->fk_extrafields = $fk_extrafields->load("extrafields:" . get_class($this), true); // load and cache
  100. } catch (Exception $e) {
  101. dol_print_error('',$e->getMessage());
  102. exit;
  103. }
  104. $this->Status = 0;
  105. // l'adherent n'est pas public par defaut
  106. $this->public = 0;
  107. // les champs optionnels sont vides
  108. $this->array_options = array();
  109. return 1;
  110. }
  111. /**
  112. * Fonction envoyant un email a l'adherent avec le texte fourni en parametre.
  113. *
  114. * @param string $text Content of message (not html entities encoded)
  115. * @param string $subject Subject of message
  116. * @param array $filename_list Array of attached files
  117. * @param array $mimetype_list Array of mime types of attached files
  118. * @param array $mimefilename_list Array of public names of attached files
  119. * @param string $addr_cc Email cc
  120. * @param string $addr_bcc Email bcc
  121. * @param int $deliveryreceipt Ask a delivery receipt
  122. * @param int $msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection
  123. * @param string $errors_to erros to
  124. * @return int <0 if KO, >0 if OK
  125. */
  126. function send_an_email($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '') {
  127. global $conf, $langs;
  128. // Detect if message is HTML
  129. if ($msgishtml == -1) {
  130. $msgishtml = 0;
  131. if (dol_textishtml($text, 1))
  132. $msgishtml = 1;
  133. }
  134. $texttosend = $this->makeSubstitution($text);
  135. $subjecttosend = $this->makeSubstitution($subject);
  136. if ($msgishtml)
  137. $texttosend = dol_htmlentitiesbr($texttosend);
  138. // Envoi mail confirmation
  139. $from = $conf->email_from;
  140. if ($conf->global->ADHERENT_MAIL_FROM)
  141. $from = $conf->global->ADHERENT_MAIL_FROM;
  142. include_once(DOL_DOCUMENT_ROOT . "/core/class/CMailFile.class.php");
  143. $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml);
  144. if ($mailfile->sendfile()) {
  145. return 1;
  146. } else {
  147. $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email) . '. ' . $mailfile->error;
  148. return -1;
  149. }
  150. }
  151. /**
  152. * Make substitution
  153. *
  154. * @param string $text Text to make substitution to
  155. * @return string Value of input text string with substitutions done
  156. */
  157. function makeSubstitution($text) {
  158. global $conf, $langs;
  159. $birthday = dol_print_date($this->naiss, 'day');
  160. $msgishtml = 0;
  161. if (dol_textishtml($text, 1))
  162. $msgishtml = 1;
  163. $infos = '';
  164. if ($this->civilite_id)
  165. $infos.= $langs->transnoentities("UserTitle") . ": " . $this->getCivilityLabel(1) . "\n";
  166. $infos.= $langs->transnoentities("id") . ": " . $this->id . "\n";
  167. $infos.= $langs->transnoentities("Lastname") . ": " . $this->Lastname . "\n";
  168. $infos.= $langs->transnoentities("Firstname") . ": " . $this->Firstname . "\n";
  169. $infos.= $langs->transnoentities("Company") . ": " . $this->societe . "\n";
  170. $infos.= $langs->transnoentities("Address") . ": " . $this->address . "\n";
  171. $infos.= $langs->transnoentities("Zip") . ": " . $this->zip . "\n";
  172. $infos.= $langs->transnoentities("Town") . ": " . $this->town . "\n";
  173. $infos.= $langs->transnoentities("Country") . ": " . $this->country . "\n";
  174. $infos.= $langs->transnoentities("EMail") . ": " . $this->email . "\n";
  175. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  176. $infos.= $langs->transnoentities("Login") . ": " . $this->login . "\n";
  177. $infos.= $langs->transnoentities("Password") . ": " . $this->pass . "\n";
  178. }
  179. $infos.= $langs->transnoentities("Birthday") . ": " . $birthday . "\n";
  180. $infos.= $langs->transnoentities("Photo") . ": " . $this->photo . "\n";
  181. $infos.= $langs->transnoentities("Public") . ": " . yn($this->public);
  182. // Substitutions
  183. $substitutionarray = array(
  184. '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
  185. '%ID%' => $msgishtml ? dol_htmlentitiesbr($this->id) : $this->id,
  186. '%CIVILITE%' => $this->getCivilityLabel($msgishtml ? 0 : 1),
  187. '%FIRSTNAME%' => $msgishtml ? dol_htmlentitiesbr($this->Firstname) : $this->Firstname,
  188. '%LASTNAME%' => $msgishtml ? dol_htmlentitiesbr($this->Lastname) : $this->Lastname,
  189. '%FULLNAME%' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
  190. '%COMPANY%' => $msgishtml ? dol_htmlentitiesbr($this->societe) : $this->societe,
  191. '%ADDRESS%' => $msgishtml ? dol_htmlentitiesbr($this->address) : $this->address,
  192. '%ZIP%' => $msgishtml ? dol_htmlentitiesbr($this->zip) : $this->zip,
  193. '%TOWN%' => $msgishtml ? dol_htmlentitiesbr($this->town) : $this->town,
  194. '%COUNTRY%' => $msgishtml ? dol_htmlentitiesbr($this->country) : $this->country,
  195. '%EMAIL%' => $msgishtml ? dol_htmlentitiesbr($this->email) : $this->email,
  196. '%NAISS%' => $msgishtml ? dol_htmlentitiesbr($birthday) : $birthday,
  197. '%PHOTO%' => $msgishtml ? dol_htmlentitiesbr($this->photo) : $this->photo,
  198. '%LOGIN%' => $msgishtml ? dol_htmlentitiesbr($this->login) : $this->login,
  199. '%PASSWORD%' => $msgishtml ? dol_htmlentitiesbr($this->pass) : $this->pass,
  200. // For backward compatibility
  201. '%INFOS%' => $msgishtml ? dol_htmlentitiesbr($infos) : $infos,
  202. '%PRENOM%' => $msgishtml ? dol_htmlentitiesbr($this->Firstname) : $this->Firstname,
  203. '%NOM%' => $msgishtml ? dol_htmlentitiesbr($this->Lastname) : $this->Lastname,
  204. '%SOCIETE%' => $msgishtml ? dol_htmlentitiesbr($this->societe) : $this->societe,
  205. '%ADRESSE%' => $msgishtml ? dol_htmlentitiesbr($this->address) : $this->address,
  206. '%CP%' => $msgishtml ? dol_htmlentitiesbr($this->zip) : $this->zip,
  207. '%VILLE%' => $msgishtml ? dol_htmlentitiesbr($this->town) : $this->town,
  208. '%PAYS%' => $msgishtml ? dol_htmlentitiesbr($this->country) : $this->country,
  209. );
  210. complete_substitutions_array($substitutionarray, $langs);
  211. return make_substitutions($text, $substitutionarray);
  212. }
  213. /**
  214. * Renvoie le libelle traduit de la nature d'un adherent (physique ou morale)
  215. *
  216. * @param string $morphy Nature physique ou morale de l'adherent
  217. * @return string Label
  218. */
  219. function getmorphylib($morphy = '') {
  220. global $langs;
  221. if (!$morphy) {
  222. $morphy = $this->morphy;
  223. }
  224. if ($morphy == 'phy') {
  225. return $langs->trans("Physical");
  226. }
  227. if ($morphy == 'mor') {
  228. return $langs->trans("Moral");
  229. }
  230. return $morphy;
  231. }
  232. /**
  233. * Create a member into database
  234. *
  235. * @param User $user Objet user qui demande la creation
  236. * @param int $notrigger 1 ne declenche pas les triggers, 0 sinon
  237. * @return int <0 if KO, >0 if OK
  238. */
  239. function create($user, $notrigger = 0) {
  240. global $conf, $langs;
  241. $error = 0;
  242. $now = dol_now();
  243. // Check parameters
  244. if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
  245. $langs->load("errors");
  246. $this->error = $langs->trans("ErrorBadEMail", $this->email);
  247. return -1;
  248. }
  249. if (!$this->datec)
  250. $this->datec = $now;
  251. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
  252. if (empty($this->login)) {
  253. $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
  254. return -1;
  255. }
  256. }
  257. // Update minor fields
  258. $result = $this->update($user, 1, 1); // nosync is 1 to avoid update data of user
  259. if ($result < 0) {
  260. return -1;
  261. }
  262. // Add link to user
  263. /* if ($this->user_id)
  264. {
  265. // Add link to user
  266. $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
  267. $sql.= " fk_member = '".$this->id."'";
  268. $sql.= " WHERE rowid = ".$this->user_id;
  269. dol_syslog(get_class($this)."::create sql=".$sql);
  270. $resql = $this->db->query($sql);
  271. if (! $resql)
  272. {
  273. $this->error='Failed to update user to make link with member';
  274. $this->db->rollback();
  275. return -4;
  276. }
  277. } */
  278. if (!$notrigger) {
  279. // Appel des triggers
  280. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  281. $interface = new Interfaces($this->db);
  282. $result = $interface->run_triggers('MEMBER_CREATE', $this, $user, $langs, $conf);
  283. if ($result < 0) {
  284. $error++;
  285. $this->errors = $interface->errors;
  286. }
  287. // Fin appel triggers
  288. }
  289. if (count($this->errors)) {
  290. dol_syslog(get_class($this) . "::create " . join(',', $this->errors), LOG_ERR);
  291. return -3;
  292. } else {
  293. return $this->id;
  294. }
  295. }
  296. /**
  297. * Update a member in database (standard information and password)
  298. *
  299. * @param User $user User making update
  300. * @param int $notrigger 1=disable trigger UPDATE (when called by create)
  301. * @param int $nosyncuser 0=Synchronize linked user (standard info), 1=Do not synchronize linked user
  302. * @param int $nosyncuserpass 0=Synchronize linked user (password), 1=Do not synchronize linked user
  303. * @param int $nosyncthirdparty 0=Synchronize linked thirdparty (standard info), 1=Do not synchronize linked thirdparty
  304. * @return int <0 if KO, >0 if OK
  305. */
  306. function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0) {
  307. global $conf, $langs;
  308. $nbrowsaffected = 0;
  309. $error = 0;
  310. dol_syslog(get_class($this) . "::update notrigger=" . $notrigger . ", nosyncuser=" . $nosyncuser . ", nosyncuserpass=" . $nosyncuserpass . ", email=" . $this->email);
  311. // Clean parameters
  312. $this->Lastname = trim($this->Lastname);
  313. $this->Firstname = trim($this->Firstname);
  314. $this->address = ($this->address ? $this->address : $this->adresse);
  315. $this->zip = ($this->zip ? $this->zip : $this->cp);
  316. $this->town = ($this->town ? $this->town : $this->ville);
  317. $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->fk_pays);
  318. $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->fk_departement);
  319. if (!empty($conf->global->MAIN_FIRST_TO_UPPER))
  320. $this->Lastname = ucwords(trim($this->Lastname));
  321. if (!empty($conf->global->MAIN_FIRST_TO_UPPER))
  322. $this->Firstname = ucwords(trim($this->Firstname));
  323. // Check parameters
  324. if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
  325. $langs->load("errors");
  326. $this->error = $langs->trans("ErrorBadEMail", $this->email);
  327. return -1;
  328. }
  329. $result = parent::update($user); // save
  330. dol_syslog(get_class($this) . "::update update member sql=" . $sql);
  331. if ($result) {
  332. unset($this->country_code);
  333. unset($this->country);
  334. unset($this->state_code);
  335. unset($this->state);
  336. // Update password
  337. if (!$error && $this->pass) {
  338. dol_syslog(get_class($this) . "::update update password");
  339. if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
  340. // Si mot de passe saisi et different de celui en base
  341. $result = $this->setPassword($user, $this->pass, 0, $notrigger, $nosyncuserpass);
  342. if (!$nbrowsaffected)
  343. $nbrowsaffected++;
  344. }
  345. }
  346. // Remove links to user and replace with new one
  347. /* if (! $error)
  348. {
  349. dol_syslog(get_class($this)."::update update link to user");
  350. $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id;
  351. dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
  352. $resql = $this->db->query($sql);
  353. if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
  354. // If there is a user linked to this member
  355. if ($this->user_id > 0)
  356. {
  357. $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id." WHERE rowid = ".$this->user_id;
  358. dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
  359. $resql = $this->db->query($sql);
  360. if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
  361. }
  362. }
  363. if (! $error && $nbrowsaffected) // If something has change in main data
  364. {
  365. // Update information on linked user if it is an update
  366. if ($this->user_id > 0 && ! $nosyncuser)
  367. {
  368. require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php");
  369. dol_syslog(get_class($this)."::update update linked user");
  370. $luser=new User($this->db);
  371. $result=$luser->fetch($this->user_id);
  372. if ($result >= 0)
  373. {
  374. $luser->civilite_id=$this->civilite_id;
  375. $luser->firstname=$this->firstname;
  376. $luser->lastname=$this->lastname;
  377. $luser->prenom=$this->firstname; // deprecated
  378. $luser->nom=$this->lastname; // deprecated
  379. $luser->login=$this->user_login;
  380. $luser->pass=$this->pass;
  381. $luser->societe_id=$this->societe;
  382. $luser->email=$this->email;
  383. $luser->office_phone=$this->phone;
  384. $luser->user_mobile=$this->phone_mobile;
  385. $luser->note=$this->note;
  386. $luser->fk_member=$this->id;
  387. $result=$luser->update($user,0,1,1); // Use nosync to 1 to avoid cyclic updates
  388. if ($result < 0)
  389. {
  390. $this->error=$luser->error;
  391. dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
  392. $error++;
  393. }
  394. }
  395. else
  396. {
  397. $this->error=$luser->error;
  398. $error++;
  399. }
  400. }
  401. // Update information on linked thirdparty if it is an update
  402. if ($this->fk_soc > 0 && ! $nosyncthirdparty)
  403. {
  404. require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  405. dol_syslog(get_class($this)."::update update linked thirdparty");
  406. // This member is linked with a thirdparty, so we also update thirdparty informations
  407. // if this is an update.
  408. $lthirdparty=new Societe($this->db);
  409. $result=$lthirdparty->fetch($this->fk_soc);
  410. if ($result >= 0)
  411. {
  412. $lthirdparty->address=$this->address;
  413. $lthirdparty->zip=$this->zip;
  414. $lthirdparty->town=$this->town;
  415. $lthirdparty->email=$this->email;
  416. $lthirdparty->tel=$this->phone;
  417. $lthirdparty->state_id=$this->state_id;
  418. $lthirdparty->country_id=$this->country_id;
  419. $lthirdparty->pays_id=$this->country_id;
  420. //$lthirdparty->phone_mobile=$this->phone_mobile;
  421. $result=$lthirdparty->update($this->fk_soc,$user,0,1,1,'update'); // Use sync to 0 to avoid cyclic updates
  422. if ($result < 0)
  423. {
  424. $this->error=$lthirdparty->error;
  425. dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
  426. $error++;
  427. }
  428. }
  429. else
  430. {
  431. $this->error=$lthirdparty->error;
  432. $error++;
  433. }
  434. } */
  435. if (!$error && !$notrigger) {
  436. // Appel des triggers
  437. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  438. $interface = new Interfaces($this->db);
  439. $result = $interface->run_triggers('MEMBER_MODIFY', $this, $user, $langs, $conf);
  440. if ($result < 0) {
  441. $error++;
  442. $this->errors = $interface->errors;
  443. }
  444. // Fin appel triggers
  445. }
  446. }
  447. if (!$error) {
  448. return 1;
  449. } else {
  450. return -1;
  451. }
  452. }
  453. /**
  454. * Update denormalized last subscription date.
  455. * This function is called when we delete a subscription for example.
  456. *
  457. * @param User $user User making change
  458. * @return int <0 if KO, >0 if OK
  459. */
  460. /* function update_end_date($user) {
  461. global $conf, $langs;
  462. $error = 0;
  463. $this->db->begin();
  464. // Search for last subscription id and end date
  465. $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
  466. $sql.= " FROM " . MAIN_DB_PREFIX . "cotisation";
  467. $sql.= " WHERE fk_adherent='" . $this->id . "'";
  468. $sql.= " ORDER by dateadh DESC"; // Sort by start subscription date
  469. dol_syslog(get_class($this) . "::update_end_date sql=" . $sql);
  470. $resql = $this->db->query($sql);
  471. if ($resql) {
  472. $obj = $this->db->fetch_object($resql);
  473. $dateop = $this->db->jdate($obj->dateop);
  474. $datedeb = $this->db->jdate($obj->datedeb);
  475. $datefin = $this->db->jdate($obj->datefin);
  476. $sql = "UPDATE " . MAIN_DB_PREFIX . "adherent SET";
  477. $sql.= " datefin=" . ($datefin != '' ? "'" . $this->db->idate($datefin) . "'" : "null");
  478. $sql.= " WHERE rowid = " . $this->id;
  479. dol_syslog(get_class($this) . "::update_end_date sql=" . $sql);
  480. $resql = $this->db->query($sql);
  481. if ($resql) {
  482. $this->last_subscription_date = $dateop;
  483. $this->last_subscription_date_start = $datedeb;
  484. $this->last_subscription_date_end = $datefin;
  485. $this->datefin = $datefin;
  486. $this->db->commit();
  487. return 1;
  488. } else {
  489. $this->db->rollback();
  490. return -1;
  491. }
  492. } else {
  493. $this->error = $this->db->lasterror();
  494. dol_syslog(get_class($this) . "::update_end_date " . $this->error, LOG_ERR);
  495. $this->db->rollback();
  496. return -1;
  497. }
  498. } */
  499. /**
  500. * Fonction qui supprime l'adherent et les donnees associees
  501. *
  502. * @param int $rowid Id of member to delete
  503. * @return int <0 if KO, 0=nothing to do, >0 if OK
  504. */
  505. function delete() {
  506. global $conf, $langs, $user;
  507. $result = 0;
  508. $error = 0;
  509. return $this->deleteDoc();
  510. }
  511. /**
  512. * Change password of a user
  513. *
  514. * @param User $user Object user de l'utilisateur qui fait la modification
  515. * @param string $password New password (to generate if empty)
  516. * @param int $isencrypted 0 ou 1 si il faut crypter le mot de passe en base (0 par defaut)
  517. * @param int $notrigger 1=Ne declenche pas les triggers
  518. * @param int $nosyncuser Do not synchronize linked user
  519. * @return string If OK return clear password, 0 if no change, < 0 if error
  520. */
  521. function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0) {
  522. global $conf, $langs;
  523. $error = 0;
  524. dol_syslog(get_class($this) . "::setPassword user=" . $user->id . " password=" . preg_replace('/./i', '*', $password) . " isencrypted=" . $isencrypted);
  525. // If new password not provided, we generate one
  526. if (!$password) {
  527. require_once(DOL_DOCUMENT_ROOT . "/core/lib/security2.lib.php");
  528. $password = getRandomPassword('');
  529. }
  530. // Cryptage mot de passe
  531. if ($isencrypted) {
  532. // Encryption
  533. $password_indatabase = dol_hash($password);
  534. } else {
  535. $password_indatabase = $password;
  536. }
  537. $this->pass = $password;
  538. $this->pass_indatabase = $password_indatabase;
  539. if (!$error && !$notrigger) {
  540. // Appel des triggers
  541. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  542. $interface = new Interfaces($this->db);
  543. $result = $interface->run_triggers('MEMBER_NEW_PASSWORD', $this, $user, $langs, $conf);
  544. if ($result < 0) {
  545. $error++;
  546. $this->errors = $interface->errors;
  547. }
  548. // Fin appel triggers
  549. }
  550. return $this->pass;
  551. }
  552. /**
  553. * Set link to a user
  554. *
  555. * @param int $userid Id of user to link to
  556. * @return int 1=OK, -1=KO
  557. */
  558. function setUserId($userid) {
  559. global $conf, $langs;
  560. return 1;
  561. }
  562. /**
  563. * Set link to a third party
  564. *
  565. * @param int $thirdpartyid Id of user to link to
  566. * @return int 1=OK, -1=KO
  567. */
  568. function setThirdPartyId($thirdpartyid) {
  569. global $conf, $langs;
  570. $this->fk_soc = $thirdpartyid;
  571. $this->record();
  572. return 1;
  573. }
  574. /**
  575. * Method to load member from its login
  576. *
  577. * @param string $login login of member
  578. * @return void
  579. */
  580. function fetch_login($login) {
  581. global $conf;
  582. $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "adherent";
  583. $sql.= " WHERE login='" . $this->db->escape($login) . "'";
  584. $sql.= " AND entity = " . $conf->entity;
  585. $resql = $this->db->query($sql);
  586. if ($resql) {
  587. if ($this->db->num_rows($resql)) {
  588. $obj = $this->db->fetch_object($resql);
  589. $this->fetch($obj->rowid);
  590. }
  591. } else {
  592. dol_print_error($this->db);
  593. }
  594. }
  595. /**
  596. * Load member from database
  597. *
  598. * @param int $rowid Id of object to load
  599. * @param string $ref To load member from its ref
  600. * @param int $fk_soc To load member from its link to third party
  601. * @return int >0 if OK, 0 if not found, <0 if KO
  602. */
  603. function fetch($rowid, $ref = '', $fk_soc = '') {
  604. global $langs;
  605. if(!empty($rowid))
  606. $result = $this->load($rowid);
  607. return $result;
  608. /* $sql = "SELECT d.rowid, d.civilite, d.prenom as firstname, d.nom as lastname, d.societe, d.fk_soc, d.statut, d.public, d.adresse as address, d.cp as zip, d.ville as town, d.note,";
  609. $sql.= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass,";
  610. $sql.= " d.photo, d.fk_adherent_type, d.morphy,";
  611. $sql.= " d.datec as datec,";
  612. $sql.= " d.tms as datem,";
  613. $sql.= " d.datefin as datefin,";
  614. $sql.= " d.naiss as datenaiss,";
  615. $sql.= " d.datevalid as datev,";
  616. $sql.= " d.pays,";
  617. $sql.= " d.fk_departement,";
  618. $sql.= " p.rowid as country_id, p.code as country_code, p.libelle as country,";
  619. $sql.= " dep.nom as state, dep.code_departement as state_code,";
  620. $sql.= " t.libelle as type, t.cotisation as cotisation,";
  621. $sql.= " u.rowid as user_id, u.login as user_login";
  622. $sql.= " FROM " . MAIN_DB_PREFIX . "adherent_type as t, " . MAIN_DB_PREFIX . "adherent as d";
  623. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "c_pays as p ON d.pays = p.rowid";
  624. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "c_departements as dep ON d.fk_departement = dep.rowid";
  625. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON d.rowid = u.fk_member";
  626. $sql.= " WHERE d.fk_adherent_type = t.rowid";
  627. if ($rowid)
  628. $sql.= " AND d.rowid=" . $rowid;
  629. elseif ($ref || $fk_soc) {
  630. $sql.= " AND d.entity IN (" . getEntity() . ")";
  631. if ($ref)
  632. $sql.= " AND d.rowid='" . $ref . "'";
  633. elseif ($fk_soc)
  634. $sql.= " AND d.fk_soc='" . $fk_soc . "'";
  635. }
  636. dol_syslog(get_class($this) . "::fetch sql=" . $sql);
  637. $resql = $this->db->query($sql);
  638. if ($resql) {
  639. if ($this->db->num_rows($resql)) {
  640. $obj = $this->db->fetch_object($resql);
  641. $this->ref = $obj->rowid;
  642. $this->id = $obj->rowid;
  643. $this->civilite_id = $obj->civilite;
  644. $this->prenom = $obj->firstname; // deprecated
  645. $this->firstname = $obj->firstname;
  646. $this->nom = $obj->lastname; // deprecated
  647. $this->lastname = $obj->lastname;
  648. $this->login = $obj->login;
  649. $this->pass = $obj->pass;
  650. $this->societe = $obj->societe;
  651. $this->fk_soc = $obj->fk_soc;
  652. $this->adresse = $obj->address; // deprecated
  653. $this->address = $obj->address;
  654. $this->cp = $obj->zip; // deprecated
  655. $this->zip = $obj->zip;
  656. $this->ville = $obj->town; // deprecated
  657. $this->town = $obj->town;
  658. $this->state_id = $obj->fk_departement;
  659. $this->state_code = $obj->fk_departement ? $obj->state_code : '';
  660. $this->state = $obj->fk_departement ? $obj->state : '';
  661. $this->fk_departement = $obj->fk_departement; // deprecated
  662. $this->departement_code = $obj->fk_departement ? $obj->state_code : ''; // deprecated
  663. $this->departement = $obj->fk_departement ? $obj->state : ''; // deprecated
  664. $this->country_id = $obj->country_id;
  665. $this->country_code = $obj->country_code;
  666. if ($langs->trans("Country" . $obj->country_code) != "Country" . $obj->country_code)
  667. $this->country = $langs->transnoentitiesnoconv("Country" . $obj->country_code);
  668. else
  669. $this->country = $obj->country;
  670. $this->pays_id = $obj->country_id; // deprecated
  671. $this->pays_code = $obj->country_code; // deprecated
  672. $this->pays = $this->country; // deprecated
  673. $this->phone = $obj->phone;
  674. $this->phone_perso = $obj->phone_perso;
  675. $this->phone_mobile = $obj->phone_mobile;
  676. $this->email = $obj->email;
  677. $this->photo = $obj->photo;
  678. $this->statut = $obj->statut;
  679. $this->public = $obj->public;
  680. $this->datec = $this->db->jdate($obj->datec);
  681. $this->datem = $this->db->jdate($obj->datem);
  682. $this->datefin = $this->db->jdate($obj->datefin);
  683. $this->datevalid = $this->db->jdate($obj->datev);
  684. $this->naiss = $this->db->jdate($obj->datenaiss);
  685. $this->note = $obj->note;
  686. $this->morphy = $obj->morphy;
  687. $this->typeid = $obj->fk_adherent_type;
  688. $this->type = $obj->type;
  689. $this->need_subscription = ($obj->cotisation == 'yes' ? 1 : 0);
  690. $this->user_id = $obj->user_id;
  691. $this->user_login = $obj->user_login;
  692. // Load other properties
  693. $result = $this->fetch_subscriptions();
  694. return $result;
  695. }
  696. else {
  697. return 0;
  698. }
  699. } else {
  700. $this->error = $this->db->lasterror();
  701. dol_syslog(get_class($this) . "::fetch " . $this->error, LOG_ERR);
  702. return -1;
  703. } */
  704. }
  705. /**
  706. * Fonction qui recupere pour un adherent les parametres
  707. * first_subscription_date
  708. * first_subscription_amount
  709. * last_subscription_date
  710. * last_subscription_amount
  711. *
  712. * @return int <0 si KO, >0 si OK
  713. */
  714. /* function fetch_subscriptions() {
  715. global $langs;
  716. $sql = "SELECT c.rowid, c.fk_adherent, c.cotisation, c.note, c.fk_bank,";
  717. $sql.= " c.tms as datem,";
  718. $sql.= " c.datec as datec,";
  719. $sql.= " c.dateadh as dateadh,";
  720. $sql.= " c.datef as datef";
  721. $sql.= " FROM " . MAIN_DB_PREFIX . "cotisation as c";
  722. $sql.= " WHERE c.fk_adherent = " . $this->id;
  723. $sql.= " ORDER BY c.dateadh";
  724. dol_syslog(get_class($this) . "::fetch_subscriptions sql=" . $sql);
  725. $resql = $this->db->query($sql);
  726. if ($resql) {
  727. $this->subscriptions = array();
  728. $i = 0;
  729. while ($obj = $this->db->fetch_object($resql)) {
  730. if ($i == 0) {
  731. $this->first_subscription_date = $obj->dateadh;
  732. $this->first_subscription_amount = $obj->cotisation;
  733. }
  734. $this->last_subscription_date = $obj->dateadh;
  735. $this->last_subscription_amount = $obj->cotisation;
  736. $subscription = new Cotisation($this->db);
  737. $subscription->id = $obj->rowid;
  738. $subscription->fk_adherent = $obj->fk_adherent;
  739. $subscription->amount = $obj->cotisation;
  740. $subscription->note = $obj->note;
  741. $subscription->fk_bank = $obj->fk_bank;
  742. $subscription->datem = $this->db->jdate($obj->datem);
  743. $subscription->datec = $this->db->jdate($obj->datec);
  744. $subscription->dateadh = $this->db->jdate($obj->dateadh);
  745. $subscription->datef = $this->db->jdate($obj->datef);
  746. $this->subscriptions[] = $subscription;
  747. $i++;
  748. }
  749. return 1;
  750. } else {
  751. $this->error = $this->db->error() . ' sql=' . $sql;
  752. return -1;
  753. }
  754. } */
  755. /**
  756. * Insert subscription into database and eventually add links to banks, mailman, etc...
  757. *
  758. * @param timestamp $date Date d'effet de la cotisation
  759. * @param amount $montant Montant cotisation (accepte 0 pour les adherents non soumis e cotisation)
  760. * @param int $accountid Id compte bancaire
  761. * @param string $operation Type operation (si Id compte bancaire fourni)
  762. * @param string $label Label operation (si Id compte bancaire fourni)
  763. * @param string $num_chq Numero cheque (si Id compte bancaire fourni)
  764. * @param string $emetteur_nom Nom emetteur cheque
  765. * @param string $emetteur_banque Nom banque emetteur cheque
  766. * @param timestamp $datesubend Date fin adhesion
  767. * @return int rowid of record added, <0 if KO
  768. */
  769. function cotisation($date, $montant, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0) {
  770. global $conf, $langs, $user;
  771. $error = 0;
  772. // Clean parameters
  773. if (!$montant)
  774. $montant = 0;
  775. if ($datesubend) {
  776. $datefin = $datesubend;
  777. } else {
  778. // If no end date, end date = date + 1 year - 1 day
  779. $datefin = dol_time_plus_duree($date, 1, 'y');
  780. $datefin = dol_time_plus_duree($datefin, -1, 'd');
  781. }
  782. // Create subscription
  783. $cotisation = new stdClass($this->db);
  784. $cotisation->dateh = $date; // Date of new subscription
  785. $cotisation->datef = $datefin; // End data of new subscription
  786. $cotisation->amount = (float)$montant;
  787. $cotisation->note = $label;
  788. $cotisation->year = (int)strftime("%Y",$date);
  789. $this->cotisations[] = $cotisation;
  790. // Change properties of object (used by triggers)
  791. $this->last_subscription_date = dol_now();
  792. $this->last_subscription_amount = $montant;
  793. $this->last_subscription_date_start = $date;
  794. $this->last_subscription_date_end = $datefin;
  795. // Appel des triggers
  796. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  797. $interface = new Interfaces($this->db);
  798. $result = $interface->run_triggers('MEMBER_SUBSCRIPTION', $this, $user, $langs, $conf);
  799. if ($result < 0) {
  800. $error++;
  801. $this->errors = $interface->errors;
  802. }
  803. // Fin appel triggers
  804. $this->record();
  805. return $rowid;
  806. }
  807. /**
  808. * Function that validate a member
  809. *
  810. * @param User $user user adherent qui valide
  811. * @return int <0 if KO, 0 if nothing done, >0 if OK
  812. */
  813. function validate($user) {
  814. global $langs, $conf;
  815. $error = 0;
  816. $now = dol_now();
  817. // Check parameters
  818. if ($this->Status == 1) {
  819. dol_syslog(get_class($this) . "::validate statut of member does not allow this", LOG_WARNING);
  820. return 0;
  821. }
  822. $this->Status = 1;
  823. $this->datevalid = $now;
  824. $this->fk_user_valid = $user->login;
  825. $this->record();
  826. // Appel des triggers
  827. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  828. $interface = new Interfaces($this->db);
  829. $result = $interface->run_triggers('MEMBER_VALIDATE', $this, $user, $langs, $conf);
  830. if ($result < 0) {
  831. $error++;
  832. $this->errors = $interface->errors;
  833. }
  834. // Fin appel triggers
  835. return 1;
  836. }
  837. /**
  838. * Fonction qui resilie un adherent
  839. *
  840. * @param User $user User making change
  841. * @return int <0 if KO, >0 if OK
  842. */
  843. function resiliate($user) {
  844. global $langs, $conf;
  845. $error = 0;
  846. // Check paramaters
  847. if ($this->Status == -1) {
  848. dol_syslog(get_class($this) . "::resiliate statut of member does not allow this", LOG_WARNING);
  849. return 0;
  850. }
  851. $this->Status = -1;
  852. $this->fk_user_valid = $user->login;
  853. $this->record();
  854. // Appel des triggers
  855. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  856. $interface = new Interfaces($this->db);
  857. $result = $interface->run_triggers('MEMBER_RESILIATE', $this, $user, $langs, $conf);
  858. if ($result < 0) {
  859. $error++;
  860. $this->errors = $interface->errors;
  861. }
  862. // Fin appel triggers
  863. return 1;
  864. }
  865. /**
  866. * Fonction qui ajoute l'adherent au abonnements automatiques mailing-list, spip, etc.
  867. * TODO Move this into member creation trigger (trigger of mailmanspip module)
  868. *
  869. * @return int <0 if KO, >0 if OK
  870. */
  871. function add_to_abo() {
  872. global $conf;
  873. include_once(DOL_DOCUMENT_ROOT . '/mailmanspip/class/mailmanspip.class.php');
  874. $mailmanspip = new MailmanSpip($db);
  875. $err = 0;
  876. // mailman
  877. if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
  878. $result = $mailmanspip->add_to_mailman($this);
  879. if ($result < 0) {
  880. $err+=1;
  881. }
  882. }
  883. // spip
  884. if ($conf->global->ADHERENT_USE_SPIP && $conf->mailmanspip->enabled) {
  885. $result = $mailmanspip->add_to_spip($this);
  886. if ($result < 0) {
  887. $err+=1;
  888. }
  889. }
  890. if ($err) {
  891. // error
  892. return -$err;
  893. } else {
  894. return 1;
  895. }
  896. }
  897. /**
  898. * Fonction qui supprime l'adherent des abonnements automatiques mailing-list, spip, etc.
  899. * TODO Move this into member deletion trigger (trigger of mailmanspip module)
  900. *
  901. * @return int <0 if KO, >0 if OK
  902. */
  903. function del_to_abo() {
  904. global $conf;
  905. include_once(DOL_DOCUMENT_ROOT . '/mailmanspip/class/mailmanspip.class.php');
  906. $mailmanspip = new MailmanSpip($db);
  907. $err = 0;
  908. // mailman
  909. if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
  910. $result = $mailmanspip->del_to_mailman($this);
  911. if ($result < 0) {
  912. $err+=1;
  913. }
  914. }
  915. if ($conf->global->ADHERENT_USE_SPIP && $conf->mailmanspip->enabled) {
  916. $result = $mailmanspip->del_to_spip($this);
  917. if ($result < 0) {
  918. $err+=1;
  919. }
  920. }
  921. if ($err) {
  922. // error
  923. return -$err;
  924. } else {
  925. return 1;
  926. }
  927. }
  928. /**
  929. * Return label of a civility of a contact
  930. *
  931. * @param int $nohtmlentities 0=Encode with htmlentities for HTML output, 1=No htmlentities for memory translation
  932. * @return string Name translated of civility
  933. */
  934. function getCivilityLabel($nohtmlentities = 0) {
  935. global $langs;
  936. $langs->load("dict");
  937. $code = $this->civilite_id;
  938. if ($nohtmlentities)
  939. return $langs->transnoentities("Civility" . $code) != "Civility" . $code ? $langs->transnoentities("Civility" . $code) : $code;
  940. else
  941. return $langs->trans("Civility" . $code) != "Civility" . $code ? $langs->trans("Civility" . $code) : $code;
  942. }
  943. /**
  944. * Renvoie nom clicable (avec eventuellement le picto)
  945. *
  946. * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
  947. * @param int $maxlen length max libelle
  948. * @param string $option Page lien
  949. * @return string Chaine avec URL
  950. */
  951. function getNomUrl($withpicto = 0, $maxlen = 0, $option = 'card') {
  952. global $langs;
  953. $result = '';
  954. if ($option == 'card') {
  955. $lien = '<a href="' . DOL_URL_ROOT . '/adherent/fiche.php?id=' . $this->id . '">';
  956. $lienfin = '</a>';
  957. }
  958. if ($option == 'subscription') {
  959. $lien = '<a href="' . DOL_URL_ROOT . '/adherent/card_subscriptions.php?id=' . $this->id . '">';
  960. $lienfin = '</a>';
  961. }
  962. $picto = 'user';
  963. $label = $langs->trans("ShowMember");
  964. if ($withpicto)
  965. $result.=($lien . img_object($label, $picto) . $lienfin);
  966. if ($withpicto && $withpicto != 2)
  967. $result.=' ';
  968. $result.=$lien . ($maxlen ? dol_trunc($this->ref, $maxlen) : $this->ref) . $lienfin;
  969. return $result;
  970. }
  971. /**
  972. * Return full address of member
  973. *
  974. * @param int $withcountry 1=Add country into address string
  975. * @param string $sep Separator to use to build string
  976. * @return string Full address string
  977. */
  978. function getFullAddress($withcountry = 0, $sep = "\n") {
  979. $ret = '';
  980. if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) {
  981. require_once(DOL_DOCUMENT_ROOT . "/core/lib/company.lib.php");
  982. $tmparray = getCountry($this->country_id, 'all');
  983. $this->country_code = $tmparray['code'];
  984. $this->country = $tmparray['label'];
  985. }
  986. if (in_array($this->country_code, array('US'))) {
  987. $ret.=($this->address ? $this->address . $sep : '');
  988. $ret.=trim($this->zip . ' ' . $this->town);
  989. if ($withcountry)
  990. $ret.=($this->country ? $sep . $this->country : '');
  991. }
  992. else {
  993. $ret.=($this->address ? $this->address . $sep : '');
  994. $ret.=trim($this->zip . ' ' . $this->town);
  995. if ($withcountry)
  996. $ret.=($this->country ? $sep . $this->country : '');
  997. }
  998. return trim($ret);
  999. }
  1000. /**
  1001. * Retourne le libelle du statut d'un adherent (brouillon, valide, resilie)
  1002. *
  1003. * @return string Label
  1004. */
  1005. function getLibStatus() {
  1006. return $this->LibStatus($this->Status, array("dateEnd"=> $this->last_subscription_date_end));
  1007. }
  1008. /**
  1009. * Charge indicateurs this->nb de tableau de bord
  1010. *
  1011. * @return int <0 if KO, >0 if OK
  1012. */
  1013. function load_state_board() {
  1014. global $conf;
  1015. $this->nb = array();
  1016. $sql = "SELECT count(a.rowid) as nb";
  1017. $sql.= " FROM " . MAIN_DB_PREFIX . "adherent as a";
  1018. $sql.= " WHERE a.statut > 0";
  1019. $sql.= " AND a.entity = " . $conf->entity;
  1020. $resql = $this->db->query($sql);
  1021. if ($resql) {
  1022. while ($obj = $this->db->fetch_object($resql)) {
  1023. $this->nb["members"] = $obj->nb;
  1024. }
  1025. return 1;
  1026. } else {
  1027. dol_print_error($this->db);
  1028. $this->error = $this->db->error();
  1029. return -1;
  1030. }
  1031. }
  1032. /**
  1033. * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
  1034. *
  1035. * @param User $user Objet user
  1036. * @return int <0 if KO, >0 if OK
  1037. */
  1038. function load_board($user) {
  1039. global $conf;
  1040. $now = dol_now();
  1041. if ($user->societe_id)
  1042. return -1; // protection pour eviter appel par utilisateur externe
  1043. $this->nbtodo = $this->nbtodolate = 0;
  1044. $sql = "SELECT a.rowid, a.datefin";
  1045. $sql.= " FROM " . MAIN_DB_PREFIX . "adherent as a";
  1046. $sql.= " WHERE a.statut = 1";
  1047. $sql.= " AND a.entity = " . $conf->entity;
  1048. $sql.= " AND (a.datefin IS NULL or a.datefin < '" . $this->db->idate($now) . "')";
  1049. $resql = $this->db->query($sql);
  1050. if ($resql) {
  1051. while ($obj = $this->db->fetch_object($resql)) {
  1052. $this->nbtodo++;
  1053. if ($this->db->jdate($obj->datefin) < ($now - $conf->adherent->cotisation->warning_delay))
  1054. $this->nbtodolate++;
  1055. }
  1056. return 1;
  1057. }
  1058. else {
  1059. dol_print_error($this->db);
  1060. $this->error = $this->db->error();
  1061. return -1;
  1062. }
  1063. }
  1064. /**
  1065. * Initialise an instance with random values.
  1066. * Used to build previews or test instances.
  1067. * id must be 0 if object instance is a specimen.
  1068. *
  1069. * @return void
  1070. */
  1071. function initAsSpecimen() {
  1072. global $user, $langs;
  1073. // Initialise parametres
  1074. $this->id = 0;
  1075. $this->specimen = 1;
  1076. $this->civilite_id = 0;
  1077. $this->Lastname = 'DOLIBARR';
  1078. $this->Firstname = 'SPECIMEN';
  1079. $this->login = 'dolibspec';
  1080. $this->pass = 'dolibspec';
  1081. $this->societe = 'Societe ABC';
  1082. $this->address = '61 jump street';
  1083. $this->zip = '75000';
  1084. $this->town = 'Paris';
  1085. $this->country_id = 1;
  1086. $this->country_code = 'FR';
  1087. $this->country = 'France';
  1088. $this->morphy = 1;
  1089. $this->email = 'specimen@specimen.com';
  1090. $this->phone = '0999999999';
  1091. $this->phone_perso = '0999999998';
  1092. $this->phone_mobile = '0999999997';
  1093. $this->note = 'No comment';
  1094. $this->naiss = time();
  1095. $this->photo = '';
  1096. $this->public = 1;
  1097. $this->Status = 0;
  1098. $this->datefin = time();
  1099. $this->datevalid = time();
  1100. $this->typeid = 1; // Id type adherent
  1101. $this->type = 'Type adherent'; // Libelle type adherent
  1102. $this->need_subscription = 0;
  1103. $this->first_subscription_date = time();
  1104. $this->first_subscription_amount = 10;
  1105. $this->last_subscription_date = time();
  1106. $this->last_subscription_amount = 10;
  1107. }
  1108. /**
  1109. * Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
  1110. *
  1111. * @param string $info Info string loaded by _load_ldap_info
  1112. * @param int $mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb)
  1113. * 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb)
  1114. * 2=Return key only (uid=qqq)
  1115. * @return string DN
  1116. */
  1117. function _load_ldap_dn($info, $mode = 0) {
  1118. global $conf;
  1119. $dn = '';
  1120. if ($mode == 0)
  1121. $dn = $conf->global->LDAP_KEY_MEMBERS . "=" . $info[$conf->global->LDAP_KEY_MEMBERS] . "," . $conf->global->LDAP_MEMBER_DN;
  1122. if ($mode == 1)
  1123. $dn = $conf->global->LDAP_MEMBER_DN;
  1124. if ($mode == 2)
  1125. $dn = $conf->global->LDAP_KEY_MEMBERS . "=" . $info[$conf->global->LDAP_KEY_MEMBERS];
  1126. return $dn;
  1127. }
  1128. /**
  1129. * Initialise tableau info (tableau des attributs LDAP)
  1130. *
  1131. * @return array Tableau info des attributs
  1132. */
  1133. function _load_ldap_info() {
  1134. global $conf, $langs;
  1135. $info = array();
  1136. // Object classes
  1137. $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
  1138. $this->fullname = $this->getFullName($langs);
  1139. // Member
  1140. if ($this->fullname && $conf->global->LDAP_MEMBER_FIELD_FULLNAME)
  1141. $info[$conf->global->LDAP_MEMBER_FIELD_FULLNAME] = $this->fullname;
  1142. if ($this->login && $conf->global->LDAP_MEMBER_FIELD_LOGIN)
  1143. $info[$conf->global->LDAP_MEMBER_FIELD_LOGIN] = $this->login;
  1144. if ($this->pass && $conf->global->LDAP_MEMBER_FIELD_PASSWORD)
  1145. $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
  1146. if ($this->poste && $conf->global->LDAP_MEMBER_FIELD_TITLE)
  1147. $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
  1148. if ($this->adresse && $conf->global->LDAP_MEMBER_FIELD_ADDRESS)
  1149. $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->adresse;
  1150. if ($this->cp && $conf->global->LDAP_MEMBER_FIELD_ZIP)
  1151. $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->cp;
  1152. if ($this->ville && $conf->global->LDAP_MEMBER_FIELD_TOWN)
  1153. $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->ville;
  1154. if ($this->country_code && $conf->global->LDAP_MEMBER_FIELD_COUNTRY)
  1155. $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
  1156. if ($this->email && $conf->global->LDAP_MEMBER_FIELD_MAIL)
  1157. $info[$conf->global->LDAP_MEMBER_FIELD_MAIL] = $this->email;
  1158. if ($this->phone && $conf->global->LDAP_MEMBER_FIELD_PHONE)
  1159. $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
  1160. if ($this->phone_perso && $conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)
  1161. $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
  1162. if ($this->phone_mobile && $conf->global->LDAP_MEMBER_FIELD_MOBILE)
  1163. $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
  1164. if ($this->fax && $conf->global->LDAP_MEMBER_FIELD_FAX)
  1165. $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
  1166. if ($this->note && $conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)
  1167. $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = $this->note;
  1168. if ($this->naiss && $conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)
  1169. $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->naiss, 'dayhourldap');
  1170. if (isset($this->Status) && $conf->global->LDAP_FIELD_MEMBER_STATUS)
  1171. $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->Status;
  1172. if ($this->datefin && $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
  1173. $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin, 'dayhourldap');
  1174. // Subscriptions
  1175. if ($this->first_subscription_date && $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)
  1176. $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date, 'dayhourldap');
  1177. if (isset($this->first_subscription_amount) && $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)
  1178. $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
  1179. if ($this->last_subscription_date && $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)
  1180. $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date, 'dayhourldap');
  1181. if (isset($this->last_subscription_amount) && $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)
  1182. $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
  1183. return $info;
  1184. }
  1185. /**
  1186. * Charge les informations d'ordre info dans l'objet adherent
  1187. *
  1188. * @param int $id Id of member to load
  1189. * @return void
  1190. */
  1191. function info($id) {
  1192. $this->load($id);
  1193. }
  1194. }
  1195. ?>