dolibarr  9.0.0
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 = '55';
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->picto='user';
60 
61  // Data directories to create when module is enabled
62  $this->dirs = array("/adherent/temp");
63 
64  // Config pages
65  $this->config_page_url = array("adherent.php@adherents");
66 
67  // Dependencies
68  $this->hidden = false; // A condition to hide module
69  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
70  $this->requiredby = array(); // List of module ids to disable if this one is disabled
71  $this->conflictwith = array('modMailmanSpip'); // List of module class names as string this module is in conflict with
72  $this->langfiles = array("members","companies");
73  $this->phpmin = array(5,4); // Minimum version of PHP required by module
74 
75  // Constants
76  $this->const = array();
77  $r=0;
78 
79  $this->const[$r][0] = "ADHERENT_ADDON_PDF";
80  $this->const[$r][1] = "chaine";
81  $this->const[$r][2] = "standard";
82  $this->const[$r][3] = 'Name of PDF model of member';
83  $this->const[$r][4] = 0;
84  $r++;
85 
86  // For emails
87  $this->const[$r][0] = "ADHERENT_MAIL_FROM";
88  $this->const[$r][1] = "chaine";
89  $this->const[$r][2] = "";
90  $this->const[$r][3] = "From des mails";
91  $this->const[$r][4] = 0;
92  $r++;
93 
94  $this->const[$r][0] = "ADHERENT_EMAIL_TEMPLATE_AUTOREGISTER";
95  $this->const[$r][1] = "emailtemplate:member";
96  $this->const[$r][2] = "(SendingEmailOnAutoSubscription)";
97  $this->const[$r][3] = "";
98  $this->const[$r][4] = 0;
99  $r++;
100 
101  $this->const[$r][0] = "ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION";
102  $this->const[$r][1] = "emailtemplate:member";
103  $this->const[$r][2] = "(SendingEmailOnNewSubscription)";
104  $this->const[$r][3] = "";
105  $this->const[$r][4] = 0;
106  $r++;
107 
108  $this->const[$r][0] = "ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION";
109  $this->const[$r][1] = "emailtemplate:member";
110  $this->const[$r][2] = "(SendingReminderForExpiredSubscription)";
111  $this->const[$r][3] = "";
112  $this->const[$r][4] = 0;
113  $r++;
114 
115  $this->const[$r][0] = "ADHERENT_EMAIL_TEMPLATE_CANCELATION";
116  $this->const[$r][1] = "emailtemplate:member";
117  $this->const[$r][2] = "(SendingEmailOnCancelation)";
118  $this->const[$r][3] = "";
119  $this->const[$r][4] = 0;
120  $r++;
121 
122  // For cards
123  $this->const[$r][0] = "ADHERENT_CARD_HEADER_TEXT";
124  $this->const[$r][1] = "chaine";
125  $this->const[$r][2] = "__YEAR__";
126  $this->const[$r][3] = "Texte imprimé sur le haut de la carte adhérent";
127  $this->const[$r][4] = 0;
128  $r++;
129 
130  $this->const[$r][0] = "ADHERENT_CARD_FOOTER_TEXT";
131  $this->const[$r][1] = "chaine";
132  $this->const[$r][2] = "__COMPANY__";
133  $this->const[$r][3] = "Texte imprimé sur le bas de la carte adhérent";
134  $this->const[$r][4] = 0;
135  $r++;
136 
137  $this->const[$r][0] = "ADHERENT_CARD_TEXT";
138  $this->const[$r][1] = "texte";
139  $this->const[$r][2] = "__FULLNAME__\r\nID: __ID__\r\n__EMAIL__\r\n__ADDRESS__\r\n__ZIP__ __TOWN__\r\n__COUNTRY__";
140  $this->const[$r][3] = "Text to print on member cards";
141  $this->const[$r][4] = 0;
142  $r++;
143 
144  $this->const[$r][0] = "ADHERENT_MAILMAN_ADMINPW";
145  $this->const[$r][1] = "chaine";
146  $this->const[$r][2] = "";
147  $this->const[$r][3] = "Mot de passe Admin des liste mailman";
148  $this->const[$r][4] = 0;
149  $r++;
150 
151  $this->const[$r][0] = "ADHERENT_ETIQUETTE_TYPE";
152  $this->const[$r][1] = "chaine";
153  $this->const[$r][2] = "L7163";
154  $this->const[$r][3] = "Type of address sheets";
155  $this->const[$r][4] = 0;
156  $r++;
157 
158  $this->const[$r][0] = "ADHERENT_ETIQUETTE_TEXT";
159  $this->const[$r][1] = "texte";
160  $this->const[$r][2] = "__FULLNAME__\n__ADDRESS__\n__ZIP__ __TOWN__\n__COUNTRY%";
161  $this->const[$r][3] = "Text to print on member address sheets";
162  $this->const[$r][4] = 0;
163  $r++;
164 
165  // For subscriptions
166  $this->const[$r][0] = "ADHERENT_BANK_ACCOUNT";
167  $this->const[$r][1] = "chaine";
168  $this->const[$r][2] = "";
169  $this->const[$r][3] = "ID of bank account to use";
170  $this->const[$r][4] = 0;
171  $r++;
172 
173  $this->const[$r][0] = "ADHERENT_BANK_CATEGORIE";
174  $this->const[$r][1] = "chaine";
175  $this->const[$r][2] = "";
176  $this->const[$r][3] = "ID of bank transaction category to use";
177  $this->const[$r][4] = 0;
178  $r++;
179 
180 
181  // Boxes
182  //-------
183  $this->boxes = array(0=>array('file'=>'box_members.php','enabledbydefaulton'=>'Home'));
184 
185  // Permissions
186  //------------
187  $this->rights = array();
188  $this->rights_class = 'adherent';
189  $r=0;
190 
191  // $this->rights[$r][0] Id permission (unique tous modules confondus)
192  // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
193  // $this->rights[$r][2] Non utilise
194  // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
195  // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
196  // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
197 
198  $r++;
199  $this->rights[$r][0] = 71;
200  $this->rights[$r][1] = 'Read members\' card';
201  $this->rights[$r][2] = 'r';
202  $this->rights[$r][3] = 0;
203  $this->rights[$r][4] = 'lire';
204 
205  $r++;
206  $this->rights[$r][0] = 72;
207  $this->rights[$r][1] = 'Create/modify members (need also user module permissions if member linked to a user)';
208  $this->rights[$r][2] = 'w';
209  $this->rights[$r][3] = 0;
210  $this->rights[$r][4] = 'creer';
211 
212  $r++;
213  $this->rights[$r][0] = 74;
214  $this->rights[$r][1] = 'Remove members';
215  $this->rights[$r][2] = 'd';
216  $this->rights[$r][3] = 0;
217  $this->rights[$r][4] = 'supprimer';
218 
219  $r++;
220  $this->rights[$r][0] = 76;
221  $this->rights[$r][1] = 'Export members';
222  $this->rights[$r][2] = 'r';
223  $this->rights[$r][3] = 0;
224  $this->rights[$r][4] = 'export';
225 
226  $r++;
227  $this->rights[$r][0] = 75;
228  $this->rights[$r][1] = 'Setup types of membership';
229  $this->rights[$r][2] = 'w';
230  $this->rights[$r][3] = 0;
231  $this->rights[$r][4] = 'configurer';
232 
233  $r++;
234  $this->rights[$r][0] = 78;
235  $this->rights[$r][1] = 'Read subscriptions';
236  $this->rights[$r][2] = 'r';
237  $this->rights[$r][3] = 0;
238  $this->rights[$r][4] = 'cotisation';
239  $this->rights[$r][5] = 'lire';
240 
241  $r++;
242  $this->rights[$r][0] = 79;
243  $this->rights[$r][1] = 'Create/modify/remove subscriptions';
244  $this->rights[$r][2] = 'w';
245  $this->rights[$r][3] = 0;
246  $this->rights[$r][4] = 'cotisation';
247  $this->rights[$r][5] = 'creer';
248 
249 
250  // Menus
251  //-------
252  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
253 
254 
255  // Exports
256  //--------
257  $r=0;
258 
259  // $this->export_code[$r] Code unique identifiant l'export (tous modules confondus)
260  // $this->export_label[$r] Libelle par defaut si traduction de cle "ExportXXX" non trouvee (XXX = Code)
261  // $this->export_permission[$r] Liste des codes permissions requis pour faire l'export
262  // $this->export_fields_sql[$r] Liste des champs exportables en codif sql
263  // $this->export_fields_name[$r] Liste des champs exportables en codif traduction
264  // $this->export_sql[$r] Requete sql qui offre les donnees a l'export
265 
266  $r++;
267  $this->export_code[$r]=$this->rights_class.'_'.$r;
268  $this->export_label[$r]='MembersAndSubscriptions';
269  $this->export_permission[$r]=array(array("adherent","export"));
270  $this->export_fields_array[$r]=array(
271  'a.rowid'=>'Id','a.civility'=>"UserTitle",'a.lastname'=>"Lastname",'a.firstname'=>"Firstname",'a.login'=>"Login",'a.morphy'=>'Nature',
272  'a.societe'=>'Company','a.address'=>"Address",'a.zip'=>"Zip",'a.town'=>"Town",'d.nom'=>"State",'co.code'=>"CountryCode",'co.label'=>"Country",
273  'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",'a.email'=>"Email",'a.birth'=>"Birthday",'a.statut'=>"Status",
274  'a.photo'=>"Photo",'a.note_public'=>"NotePublic",'a.note_private'=>"NotePrivate",'a.datec'=>'DateCreation','a.datevalid'=>'DateValidation',
275  'a.tms'=>'DateLastModification','a.datefin'=>'DateEndSubscription','ta.rowid'=>'MemberTypeId','ta.libelle'=>'MemberTypeLabel',
276  'c.rowid'=>'SubscriptionId','c.dateadh'=>'DateSubscription','c.subscription'=>'Amount'
277  );
278  $this->export_TypeFields_array[$r]=array(
279  'a.civility'=>"Text",'a.lastname'=>"Text",'a.firstname'=>"Text",'a.login'=>"Text",'a.morphy'=>'Text','a.societe'=>'Text','a.address'=>"Text",
280  '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",
281  'a.email'=>"Text",'a.birth'=>"Date",'a.statut'=>"Status",'a.note_public'=>"Text",'a.note_private'=>"Text",'a.datec'=>'Date','a.datevalid'=>'Date',
282  '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  );
284  $this->export_entities_array[$r]=array(
285  'a.rowid'=>'member','a.civility'=>"member",'a.lastname'=>"member",'a.firstname'=>"member",'a.login'=>"member",'a.morphy'=>'member',
286  'a.societe'=>'member','a.address'=>"member",'a.zip'=>"member",'a.town'=>"member",'d.nom'=>"member",'co.code'=>"member",'co.label'=>"member",
287  'a.phone'=>"member",'a.phone_perso'=>"member",'a.phone_mobile'=>"member",'a.email'=>"member",'a.birth'=>"member",'a.statut'=>"member",
288  'a.photo'=>"member",'a.note_public'=>"member",'a.note_private'=>"member",'a.datec'=>'member','a.datevalid'=>'member','a.tms'=>'member',
289  'a.datefin'=>'member','ta.rowid'=>'member_type','ta.libelle'=>'member_type','c.rowid'=>'subscription','c.dateadh'=>'subscription','c.subscription'=>'subscription'
290  );
291  // Add extra fields
292  $keyforselect='adherent'; $keyforelement='member'; $keyforaliasextra='extra';
293  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
294  // End add axtra fields
295  $this->export_sql_start[$r]='SELECT DISTINCT ';
296  $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'adherent_type as ta, '.MAIN_DB_PREFIX.'adherent as a)';
297  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as extra ON a.rowid = extra.fk_object';
298  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'subscription as c ON c.fk_adherent = a.rowid';
299  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON a.state_id = d.rowid';
300  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON a.country = co.rowid';
301  $this->export_sql_end[$r] .=' WHERE a.fk_adherent_type = ta.rowid AND ta.entity IN ('.getEntity('member_type').') ';
302  $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
303 
304  // Imports
305  //--------
306  $r=0;
307 
308  $now=dol_now();
309  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
310 
311  $r++;
312  $this->import_code[$r]=$this->rights_class.'_'.$r;
313  $this->import_label[$r]="Members"; // Translation key
314  $this->import_icon[$r]=$this->picto;
315  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
316  $this->import_tables_array[$r]=array('a'=>MAIN_DB_PREFIX.'adherent','extra'=>MAIN_DB_PREFIX.'adherent_extrafields');
317  $this->import_tables_creator_array[$r]=array('a'=>'fk_user_author'); // Fields to store import user id
318  $this->import_fields_array[$r]=array(
319  'a.civility'=>"UserTitle",'a.lastname'=>"Lastname*",'a.firstname'=>"Firstname",'a.login'=>"Login*","a.pass"=>"Password",
320  "a.fk_adherent_type"=>"MemberType*",'a.morphy'=>'Nature*','a.societe'=>'Company','a.address'=>"Address",'a.zip'=>"Zip",'a.town'=>"Town",
321  'a.state_id'=>'StateId','a.country'=>"CountryId",'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",
322  'a.email'=>"Email",'a.birth'=>"Birthday",'a.statut'=>"Status*",'a.photo'=>"Photo",'a.note_public'=>"NotePublic",'a.note_private'=>"NotePrivate",
323  'a.datec'=>'DateCreation','a.datefin'=>'DateEndSubscription'
324  );
325  // Add extra fields
326  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'adherent' AND entity IN (0,".$conf->entity.")";
327  $resql=$this->db->query($sql);
328  if ($resql) // This can fail when class is used on old database (during migration for example)
329  {
330  while ($obj=$this->db->fetch_object($resql))
331  {
332  $fieldname='extra.'.$obj->name;
333  $fieldlabel=ucfirst($obj->label);
334  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
335  }
336  }
337  // End add extra fields
338  $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'adherent'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
339  $this->import_regex_array[$r]=array(
340  'a.civility'=>'code@'.MAIN_DB_PREFIX.'c_civility','a.fk_adherent_type'=>'rowid@'.MAIN_DB_PREFIX.'adherent_type','a.morphy'=>'(phy|mor)',
341  '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]$');
342  $this->import_examplevalues_array[$r]=array(
343  'a.civility'=>"MR",'a.lastname'=>'Smith','a.firstname'=>'John','a.login'=>'jsmith','a.pass'=>'passofjsmith','a.fk_adherent_type'=>'1',
344  'a.morphy'=>'"mor" or "phy"','a.societe'=>'JS company','a.address'=>'21 jump street','a.zip'=>'55000','a.town'=>'New York','a.country'=>'1',
345  '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",
346  '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')
347  );
348 
349  // Cronjobs
350  $arraydate=dol_getdate(dol_now());
351  $datestart=dol_mktime(22, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
352  $this->cronjobs = array(
353  0=>array(
354  'label'=>'SendReminderForExpiredSubscriptionTitle',
355  'jobtype'=>'method', 'class'=>'adherents/class/adherent.class.php',
356  'objectname'=>'Adherent',
357  'method'=>'sendReminderForExpiredSubscription',
358  'parameters'=>'10;0',
359  'comment'=>'SendReminderForExpiredSubscription',
360  'frequency'=>1,
361  'unitfrequency'=> 3600 * 24,
362  'priority'=>50,
363  'status'=>1,
364  'test'=>'$conf->adherent->enabled',
365  'datestart'=>$datestart
366  ),
367  );
368  }
369 
370 
379  function init($options='')
380  {
381  global $conf,$langs;
382 
383  // Permissions
384  $this->remove($options);
385 
386  //ODT template
387  /*
388  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt';
389  $dirodt=DOL_DATA_ROOT.'/doctemplates/orders';
390  $dest=$dirodt.'/template_order.odt';
391 
392  if (file_exists($src) && ! file_exists($dest))
393  {
394  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
395  dol_mkdir($dirodt);
396  $result=dol_copy($src,$dest,0,0);
397  if ($result < 0)
398  {
399  $langs->load("errors");
400  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
401  return 0;
402  }
403  }*/
404 
405  $sql = array(
406  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type='member' AND entity = ".$conf->entity,
407  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','member',".$conf->entity.")"
408  );
409 
410  return $this->_init($sql,$options);
411  }
412 }
Class DolibarrModules.
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:1053
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="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< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
dol_now($mode='gmt')
Return date for now.
Class to describe and enable module Adherent.
__construct($db)
Constructor.
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.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116