dolibarr  7.0.0-beta
modAdherent.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003,2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2012 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) 2013 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2014-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
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 
31 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
32 
37 {
38 
44  function __construct($db)
45  {
46  global $conf;
47 
48  $this->db = $db;
49  $this->numero = 310;
50 
51  $this->family = "hr";
52  $this->module_position = 20;
53  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54  $this->name = preg_replace('/^mod/i','',get_class($this));
55  $this->description = "Management of members of a foundation or association";
56  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57  $this->version = 'dolibarr';
58  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
59  $this->special = 0;
60  $this->picto='user';
61 
62  // Data directories to create when module is enabled
63  $this->dirs = array("/adherent/temp");
64 
65  // Config pages
66  //-------------
67  $this->config_page_url = array("adherent.php@adherents");
68 
69  // Dependencies
70  //------------
71  $this->depends = array();
72  $this->requiredby = array('modMailmanSpip');
73  $this->langfiles = array("members","companies");
74 
75  // Constants
76  //-----------
77  $this->const = array();
78  $r=0;
79 
80  $this->const[$r][0] = "ADHERENT_ADDON_PDF";
81  $this->const[$r][1] = "chaine";
82  $this->const[$r][2] = "standard";
83  $this->const[$r][3] = 'Name of PDF model of member';
84  $this->const[$r][4] = 0;
85  $r++;
86 
87  $this->const[$r][0] = "ADHERENT_MAIL_RESIL";
88  $this->const[$r][1] = "texte";
89  $this->const[$r][2] = "Votre adhésion vient d'être résiliée.\r\nNous espérons vous revoir très bientôt";
90  $this->const[$r][3] = "Mail de résiliation";
91  $this->const[$r][4] = 0;
92  $r++;
93 
94  $this->const[$r][0] = "ADHERENT_MAIL_VALID";
95  $this->const[$r][1] = "texte";
96  $this->const[$r][2] = "Votre adhésion vient d'être validée. \r\nVoici le rappel de vos coordonnées (toute information erronée entrainera la non validation de votre inscription) :\r\n\r\n__INFOS__\r\n\r\n";
97  $this->const[$r][3] = "Mail de validation";
98  $this->const[$r][4] = 0;
99  $r++;
100 
101  $this->const[$r][0] = "ADHERENT_MAIL_VALID_SUBJECT";
102  $this->const[$r][1] = "chaine";
103  $this->const[$r][2] = "Votre adhésion a été validée";
104  $this->const[$r][3] = "Sujet du mail de validation";
105  $this->const[$r][4] = 0;
106  $r++;
107 
108  $this->const[$r][0] = "ADHERENT_MAIL_RESIL_SUBJECT";
109  $this->const[$r][1] = "chaine";
110  $this->const[$r][2] = "Résiliation de votre adhésion";
111  $this->const[$r][3] = "Sujet du mail de résiliation";
112  $this->const[$r][4] = 0;
113  $r++;
114 
115  $this->const[$r][0] = "ADHERENT_MAIL_FROM";
116  $this->const[$r][1] = "chaine";
117  $this->const[$r][2] = "";
118  $this->const[$r][3] = "From des mails";
119  $this->const[$r][4] = 0;
120  $r++;
121 
122  $this->const[$r][0] = "ADHERENT_MAIL_COTIS";
123  $this->const[$r][1] = "texte";
124  $this->const[$r][2] = "Bonjour __FIRSTNAME__,\r\nCet email confirme que votre cotisation a été reçue\r\net enregistrée";
125  $this->const[$r][3] = "Mail de validation de cotisation";
126  $this->const[$r][4] = 0;
127  $r++;
128 
129  $this->const[$r][0] = "ADHERENT_MAIL_COTIS_SUBJECT";
130  $this->const[$r][1] = "chaine";
131  $this->const[$r][2] = "Reçu de votre cotisation";
132  $this->const[$r][3] = "Sujet du mail de validation de cotisation";
133  $this->const[$r][4] = 0;
134  $r++;
135 
136  $this->const[$r][0] = "ADHERENT_CARD_HEADER_TEXT";
137  $this->const[$r][1] = "chaine";
138  $this->const[$r][2] = "__YEAR__";
139  $this->const[$r][3] = "Texte imprimé sur le haut de la carte adhérent";
140  $this->const[$r][4] = 0;
141  $r++;
142 
143  $this->const[$r][0] = "ADHERENT_CARD_FOOTER_TEXT";
144  $this->const[$r][1] = "chaine";
145  $this->const[$r][2] = "__COMPANY__";
146  $this->const[$r][3] = "Texte imprimé sur le bas de la carte adhérent";
147  $this->const[$r][4] = 0;
148  $r++;
149 
150  $this->const[$r][0] = "ADHERENT_CARD_TEXT";
151  $this->const[$r][1] = "texte";
152  $this->const[$r][2] = "__FULLNAME__\r\nID: __ID__\r\n__EMAIL__\r\n__ADDRESS__\r\n__ZIP__ __TOWN__\r\n__COUNTRY__";
153  $this->const[$r][3] = "Text to print on member cards";
154  $this->const[$r][4] = 0;
155  $r++;
156 
157  $this->const[$r][0] = "ADHERENT_MAILMAN_ADMINPW";
158  $this->const[$r][1] = "chaine";
159  $this->const[$r][2] = "";
160  $this->const[$r][3] = "Mot de passe Admin des liste mailman";
161  $this->const[$r][4] = 0;
162  $r++;
163 
164  $this->const[$r][0] = "ADHERENT_BANK_ACCOUNT";
165  $this->const[$r][1] = "chaine";
166  $this->const[$r][2] = "";
167  $this->const[$r][3] = "ID du Compte banquaire utilise";
168  $this->const[$r][4] = 0;
169  $r++;
170 
171  $this->const[$r][0] = "ADHERENT_BANK_CATEGORIE";
172  $this->const[$r][1] = "chaine";
173  $this->const[$r][2] = "";
174  $this->const[$r][3] = "ID de la catégorie bancaire des cotisations";
175  $this->const[$r][4] = 0;
176  $r++;
177 
178  $this->const[$r][0] = "ADHERENT_ETIQUETTE_TYPE";
179  $this->const[$r][1] = "chaine";
180  $this->const[$r][2] = "L7163";
181  $this->const[$r][3] = "Type of address sheets";
182  $this->const[$r][4] = 0;
183  $r++;
184 
185  $this->const[$r][0] = "ADHERENT_ETIQUETTE_TEXT";
186  $this->const[$r][1] = "texte";
187  $this->const[$r][2] = "__FULLNAME__\n__ADDRESS__\n__ZIP__ __TOWN__\n__COUNTRY%";
188  $this->const[$r][3] = "Text to print on member address sheets";
189  $this->const[$r][4] = 0;
190  $r++;
191 
192  // Boxes
193  //-------
194  $this->boxes = array(0=>array('file'=>'box_members.php','enabledbydefaulton'=>'Home'));
195 
196  // Permissions
197  //------------
198  $this->rights = array();
199  $this->rights_class = 'adherent';
200  $r=0;
201 
202  // $this->rights[$r][0] Id permission (unique tous modules confondus)
203  // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
204  // $this->rights[$r][2] Non utilise
205  // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
206  // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
207  // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
208 
209  $r++;
210  $this->rights[$r][0] = 71;
211  $this->rights[$r][1] = 'Read members\' card';
212  $this->rights[$r][2] = 'r';
213  $this->rights[$r][3] = 0;
214  $this->rights[$r][4] = 'lire';
215 
216  $r++;
217  $this->rights[$r][0] = 72;
218  $this->rights[$r][1] = 'Create/modify members (need also user module permissions if member linked to a user)';
219  $this->rights[$r][2] = 'w';
220  $this->rights[$r][3] = 0;
221  $this->rights[$r][4] = 'creer';
222 
223  $r++;
224  $this->rights[$r][0] = 74;
225  $this->rights[$r][1] = 'Remove members';
226  $this->rights[$r][2] = 'd';
227  $this->rights[$r][3] = 0;
228  $this->rights[$r][4] = 'supprimer';
229 
230  $r++;
231  $this->rights[$r][0] = 76;
232  $this->rights[$r][1] = 'Export members';
233  $this->rights[$r][2] = 'r';
234  $this->rights[$r][3] = 0;
235  $this->rights[$r][4] = 'export';
236 
237  $r++;
238  $this->rights[$r][0] = 75;
239  $this->rights[$r][1] = 'Setup types of membership';
240  $this->rights[$r][2] = 'w';
241  $this->rights[$r][3] = 0;
242  $this->rights[$r][4] = 'configurer';
243 
244  $r++;
245  $this->rights[$r][0] = 78;
246  $this->rights[$r][1] = 'Read subscriptions';
247  $this->rights[$r][2] = 'r';
248  $this->rights[$r][3] = 0;
249  $this->rights[$r][4] = 'cotisation';
250  $this->rights[$r][5] = 'lire';
251 
252  $r++;
253  $this->rights[$r][0] = 79;
254  $this->rights[$r][1] = 'Create/modify/remove subscriptions';
255  $this->rights[$r][2] = 'w';
256  $this->rights[$r][3] = 0;
257  $this->rights[$r][4] = 'cotisation';
258  $this->rights[$r][5] = 'creer';
259 
260 
261  // Menus
262  //-------
263  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
264 
265 
266  // Exports
267  //--------
268  $r=0;
269 
270  // $this->export_code[$r] Code unique identifiant l'export (tous modules confondus)
271  // $this->export_label[$r] Libelle par defaut si traduction de cle "ExportXXX" non trouvee (XXX = Code)
272  // $this->export_permission[$r] Liste des codes permissions requis pour faire l'export
273  // $this->export_fields_sql[$r] Liste des champs exportables en codif sql
274  // $this->export_fields_name[$r] Liste des champs exportables en codif traduction
275  // $this->export_sql[$r] Requete sql qui offre les donnees a l'export
276 
277  $r++;
278  $this->export_code[$r]=$this->rights_class.'_'.$r;
279  $this->export_label[$r]='MembersAndSubscriptions';
280  $this->export_permission[$r]=array(array("adherent","export"));
281  $this->export_fields_array[$r]=array('a.rowid'=>'Id','a.civility'=>"UserTitle",'a.lastname'=>"Lastname",'a.firstname'=>"Firstname",'a.login'=>"Login",'a.morphy'=>'Nature','a.societe'=>'Company','a.address'=>"Address",'a.zip'=>"Zip",'a.town'=>"Town",'d.nom'=>"State",'co.code'=>"CountryCode",'co.label'=>"Country",'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",'a.email'=>"Email",'a.birth'=>"Birthday",'a.statut'=>"Status",'a.photo'=>"Photo",'a.note_public'=>"NotePublic",'a.note_private'=>"NotePrivate",'a.datec'=>'DateCreation','a.datevalid'=>'DateValidation','a.tms'=>'DateLastModification','a.datefin'=>'DateEndSubscription','ta.rowid'=>'MemberTypeId','ta.libelle'=>'MemberTypeLabel','c.rowid'=>'SubscriptionId','c.dateadh'=>'DateSubscription','c.subscription'=>'Amount');
282  $this->export_TypeFields_array[$r]=array('a.civility'=>"Text",'a.lastname'=>"Text",'a.firstname'=>"Text",'a.login'=>"Text",'a.morphy'=>'Text','a.societe'=>'Text','a.address'=>"Text",'a.zip'=>"Text",'a.town'=>"Text",'d.nom'=>"Text",'co.code'=>'Text','co.label'=>"Text",'a.phone'=>"Text",'a.phone_perso'=>"Text",'a.phone_mobile'=>"Text",'a.email'=>"Text",'a.birth'=>"Date",'a.statut'=>"Status",'a.note_public'=>"Text",'a.note_private'=>"Text",'a.datec'=>'Date','a.datevalid'=>'Date','a.tms'=>'Date','a.datefin'=>'Date','ta.rowid'=>'List:adherent_type:libelle','ta.libelle'=>'Text','c.rowid'=>'Numeric','c.dateadh'=>'Date','c.subscription'=>'Numeric');
283  $this->export_entities_array[$r]=array('a.rowid'=>'member','a.civility'=>"member",'a.lastname'=>"member",'a.firstname'=>"member",'a.login'=>"member",'a.morphy'=>'member','a.societe'=>'member','a.address'=>"member",'a.zip'=>"member",'a.town'=>"member",'d.nom'=>"member",'co.code'=>"member",'co.label'=>"member",'a.phone'=>"member",'a.phone_perso'=>"member",'a.phone_mobile'=>"member",'a.email'=>"member",'a.birth'=>"member",'a.statut'=>"member",'a.photo'=>"member",'a.note_public'=>"member",'a.note_private'=>"member",'a.datec'=>'member','a.datevalid'=>'member','a.tms'=>'member','a.datefin'=>'member','ta.rowid'=>'member_type','ta.libelle'=>'member_type','c.rowid'=>'subscription','c.dateadh'=>'subscription','c.subscription'=>'subscription');
284  // Add extra fields
285  $keyforselect='adherent'; $keyforelement='member'; $keyforaliasextra='extra';
286  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
287  // End add axtra fields
288  $this->export_sql_start[$r]='SELECT DISTINCT ';
289  $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'adherent_type as ta, '.MAIN_DB_PREFIX.'adherent as a)';
290  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as extra ON a.rowid = extra.fk_object';
291  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'subscription as c ON c.fk_adherent = a.rowid';
292  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON a.state_id = d.rowid';
293  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON a.country = co.rowid';
294  $this->export_sql_end[$r] .=' WHERE a.fk_adherent_type = ta.rowid AND ta.entity IN ('.getEntity('adherent').') ';
295  $this->export_dependencies_array[$r]=array('subscription'=>'c.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
296 
297  // Imports
298  //--------
299  $r=0;
300 
301  $now=dol_now();
302  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
303 
304  $r++;
305  $this->import_code[$r]=$this->rights_class.'_'.$r;
306  $this->import_label[$r]="Members"; // Translation key
307  $this->import_icon[$r]=$this->picto;
308  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
309  $this->import_tables_array[$r]=array('a'=>MAIN_DB_PREFIX.'adherent','extra'=>MAIN_DB_PREFIX.'adherent_extrafields');
310  $this->import_tables_creator_array[$r]=array('a'=>'fk_user_author'); // Fields to store import user id
311  $this->import_fields_array[$r]=array('a.civility'=>"UserTitle",'a.lastname'=>"Lastname*",'a.firstname'=>"Firstname",'a.login'=>"Login*","a.pass"=>"Password","a.fk_adherent_type"=>"MemberType*",'a.morphy'=>'Nature*','a.societe'=>'Company','a.address'=>"Address",'a.zip'=>"Zip",'a.town'=>"Town",'a.state_id'=>'StateId','a.country'=>"CountryId",'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",'a.email'=>"Email",'a.birth'=>"Birthday",'a.statut'=>"Status*",'a.photo'=>"Photo",'a.note_public'=>"NotePublic",'a.note_private'=>"NotePrivate",'a.datec'=>'DateCreation','a.datefin'=>'DateEndSubscription');
312  // Add extra fields
313  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'adherent' AND entity = ".$conf->entity;
314  $resql=$this->db->query($sql);
315  if ($resql) // This can fail when class is used on old database (during migration for example)
316  {
317  while ($obj=$this->db->fetch_object($resql))
318  {
319  $fieldname='extra.'.$obj->name;
320  $fieldlabel=ucfirst($obj->label);
321  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
322  }
323  }
324  // End add extra fields
325  $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'adherent'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
326  $this->import_regex_array[$r]=array('a.civility'=>'code@'.MAIN_DB_PREFIX.'c_civility','a.fk_adherent_type'=>'rowid@'.MAIN_DB_PREFIX.'adherent_type','a.morphy'=>'(phy|mor)','a.statut'=>'^[0|1]','a.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','a.datefin'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
327  $this->import_examplevalues_array[$r]=array('a.civility'=>"MR",'a.lastname'=>'Smith','a.firstname'=>'John','a.login'=>'jsmith','a.pass'=>'passofjsmith','a.fk_adherent_type'=>'1','a.morphy'=>'"mor" or "phy"','a.societe'=>'JS company','a.address'=>'21 jump street','a.zip'=>'55000','a.town'=>'New York','a.country'=>'1','a.email'=>'jsmith@example.com','a.birth'=>'1972-10-10','a.statut'=>"0 or 1",'a.note_public'=>"This is a public comment on member",'a.note_private'=>"This is private comment on member",'a.datec'=>dol_print_date($now,'%Y-%m__%d'),'a.datefin'=>dol_print_date(dol_time_plus_duree($now, 1, 'y'),'%Y-%m-%d'));
328  }
329 
330 
339  function init($options='')
340  {
341  global $conf,$langs;
342 
343  // Permissions
344  $this->remove($options);
345 
346  //ODT template
347  /*
348  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt';
349  $dirodt=DOL_DATA_ROOT.'/doctemplates/orders';
350  $dest=$dirodt.'/template_order.odt';
351 
352  if (file_exists($src) && ! file_exists($dest))
353  {
354  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
355  dol_mkdir($dirodt);
356  $result=dol_copy($src,$dest,0,0);
357  if ($result < 0)
358  {
359  $langs->load("errors");
360  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
361  return 0;
362  }
363  }*/
364 
365  $sql = array(
366  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type='member' AND entity = ".$conf->entity,
367  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','member',".$conf->entity.")"
368  );
369 
370  return $this->_init($sql,$options);
371  }
372 }
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
dol_now($mode='gmt')
Return date for now.
Class to describe and enable module Adherent.
__construct($db)
Constructor.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_init($array_sql, $options='')
Enables a module.
init($options='')
Function called when module is enabled.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116