dolibarr  7.0.0-beta
adherent_type.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
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 3 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 
27 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28 
29 
34 {
35  public $table_element = 'adherent_type';
36  public $element = 'adherent_type';
37  public $picto = 'group';
38 
44  public $libelle;
46  public $label;
52  public $cotisation;
57  public $subscription;
59  public $note;
61  public $vote;
63  public $mail_valid;
65  public $members=array();
66 
67 
73  function __construct($db)
74  {
75  $this->db = $db;
76  $this->statut = 1;
77  }
78 
79 
87  function create($user,$notrigger=0)
88  {
89  global $conf;
90 
91  $error=0;
92 
93  $this->statut=(int) $this->statut;
94  $this->label=trim($this->label);
95 
96  $this->db->begin();
97 
98  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
99  $sql.= "libelle";
100  $sql.= ", entity";
101  $sql.= ") VALUES (";
102  $sql.= "'".$this->db->escape($this->label)."'";
103  $sql.= ", ".$conf->entity;
104  $sql.= ")";
105 
106  dol_syslog("Adherent_type::create", LOG_DEBUG);
107  $result = $this->db->query($sql);
108  if ($result)
109  {
110  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
111 
112  $result = $this->update($user,1);
113  if ($result < 0)
114  {
115  $this->db->rollback();
116  return -3;
117  }
118 
119  if (! $notrigger)
120  {
121  // Call trigger
122  $result=$this->call_trigger('MEMBER_TYPE_CREATE',$user);
123  if ($result < 0) { $error++; }
124  // End call triggers
125  }
126 
127  if (! $error)
128  {
129  $this->db->commit();
130  return $this->id;
131  }
132  else
133  {
134  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
135  $this->db->rollback();
136  return -2;
137  }
138  }
139  else
140  {
141  $this->error=$this->db->lasterror();
142  $this->db->rollback();
143  return -1;
144  }
145  }
146 
154  function update($user,$notrigger=0)
155  {
156  global $conf, $hookmanager;
157 
158  $error=0;
159 
160  $this->label=trim($this->label);
161 
162  $this->db->begin();
163 
164  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
165  $sql.= "SET ";
166  $sql.= "statut = ".$this->statut.",";
167  $sql.= "libelle = '".$this->db->escape($this->label) ."',";
168  $sql.= "subscription = '".$this->db->escape($this->subscription)."',";
169  $sql.= "note = '".$this->db->escape($this->note)."',";
170  $sql.= "vote = ".(integer) $this->db->escape($this->vote).",";
171  $sql.= "mail_valid = '".$this->db->escape($this->mail_valid)."'";
172  $sql.= " WHERE rowid =".$this->id;
173 
174  $result = $this->db->query($sql);
175  if ($result)
176  {
177  $action='update';
178 
179  // Actions on extra fields (by external module or standard code)
180  $hookmanager->initHooks(array('membertypedao'));
181  $parameters=array('membertype'=>$this->id);
182  $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
183  if (empty($reshook))
184  {
185  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
186  {
187  $result=$this->insertExtraFields();
188  if ($result < 0)
189  {
190  $error++;
191  }
192  }
193  }
194  else if ($reshook < 0) $error++;
195 
196  if (! $error && ! $notrigger)
197  {
198  // Call trigger
199  $result=$this->call_trigger('MEMBER_TYPE_MODIFY',$user);
200  if ($result < 0) { $error++; }
201  // End call triggers
202  }
203 
204  if (! $error)
205  {
206  $this->db->commit();
207  return 1;
208  }
209  else
210  {
211  $this->db->rollback();
212  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
213  return -$error;
214  }
215  }
216  else
217  {
218  $this->error=$this->db->lasterror();
219  $this->db->rollback();
220  return -1;
221  }
222  }
223 
229  function delete()
230  {
231  global $user;
232 
233  $error = 0;
234 
235  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type";
236  $sql.= " WHERE rowid = ".$this->id;
237 
238  $resql=$this->db->query($sql);
239  if ($resql)
240  {
241  // Call trigger
242  $result=$this->call_trigger('MEMBER_TYPE_DELETE',$user);
243  if ($result < 0) { $error++; $this->db->rollback(); return -2; }
244  // End call triggers
245 
246  $this->db->commit();
247  return 1;
248  }
249  else
250  {
251  $this->db->rollback();
252  $this->error=$this->db->lasterror();
253  return -1;
254  }
255  }
256 
263  function fetch($rowid)
264  {
265  $sql = "SELECT d.rowid, d.libelle as label, d.statut, d.subscription, d.mail_valid, d.note, d.vote";
266  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
267  $sql .= " WHERE d.rowid = ".$rowid;
268 
269  dol_syslog("Adherent_type::fetch", LOG_DEBUG);
270 
271  $resql=$this->db->query($sql);
272  if ($resql)
273  {
274  if ($this->db->num_rows($resql))
275  {
276  $obj = $this->db->fetch_object($resql);
277 
278  $this->id = $obj->rowid;
279  $this->ref = $obj->rowid;
280  $this->label = $obj->label;
281  $this->statut = $obj->statut;
282  $this->subscription = $obj->subscription;
283  $this->mail_valid = $obj->mail_valid;
284  $this->note = $obj->note;
285  $this->vote = $obj->vote;
286  }
287 
288  return 1;
289  }
290  else
291  {
292  $this->error=$this->db->lasterror();
293  return -1;
294  }
295  }
296 
302  function liste_array()
303  {
304  global $conf,$langs;
305 
306  $adherenttypes = array();
307 
308  $sql = "SELECT rowid, libelle as label";
309  $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type";
310  $sql.= " WHERE entity IN (".getEntity('adherent').")";
311 
312  $resql=$this->db->query($sql);
313  if ($resql)
314  {
315  $nump = $this->db->num_rows($resql);
316 
317  if ($nump)
318  {
319  $i = 0;
320  while ($i < $nump)
321  {
322  $obj = $this->db->fetch_object($resql);
323 
324  $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
325  $i++;
326  }
327  }
328  }
329  else
330  {
331  print $this->db->error();
332  }
333  return $adherenttypes;
334  }
335 
343  function listMembersForMemberType($excludefilter='', $mode=0)
344  {
345  global $conf, $user;
346 
347  $ret=array();
348 
349  $sql = "SELECT a.rowid";
350  $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
351  $sql.= " WHERE a.entity IN (".getEntity('member').")";
352  $sql.= " AND a.fk_adherent_type = ".$this->id;
353  if (! empty($excludefilter)) $sql.=' AND ('.$excludefilter.')';
354 
355  dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
356  $resql = $this->db->query($sql);
357  if ($resql)
358  {
359  while ($obj = $this->db->fetch_object($resql))
360  {
361  if (! array_key_exists($obj->rowid, $ret))
362  {
363  if ($mode != 1)
364  {
365  $memberstatic=new Adherent($this->db);
366  $memberstatic->fetch($obj->rowid);
367  $ret[$obj->rowid]=$memberstatic;
368  }
369  else $ret[$obj->rowid]=$obj->rowid;
370  }
371  }
372 
373  $this->db->free($resql);
374 
375  $this->members=$ret;
376 
377  return $ret;
378  }
379  else
380  {
381  $this->error=$this->db->lasterror();
382  return -1;
383  }
384  }
385 
394  function getNomUrl($withpicto=0, $maxlen=0, $notooltip=0)
395  {
396  global $langs;
397 
398  $result='';
399  $label=$langs->trans("ShowTypeCard",$this->label);
400 
401  $linkstart = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
402  $linkend='</a>';
403 
404  $result .= $linkstart;
405  if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
406  if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->label,$maxlen):$this->label);
407  $result .= $linkend;
408 
409  return $result;
410  }
411 
417  function getLibStatut()
418  {
419  return '';
420  }
421 
431  function _load_ldap_dn($info,$mode=0)
432  {
433  global $conf;
434  $dn='';
435  if ($mode==0) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].",".$conf->global->LDAP_MEMBER_TYPE_DN;
436  if ($mode==1) $dn=$conf->global->LDAP_MEMBER_TYPE_DN;
437  if ($mode==2) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES];
438  return $dn;
439  }
440 
441 
447  function _load_ldap_info()
448  {
449  global $conf,$langs;
450 
451  $info=array();
452 
453  // Object classes
454  $info["objectclass"]=explode(',',$conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS);
455 
456  // Champs
457  if ($this->label && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label;
458  if ($this->note && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] = $this->note;
459  if (! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS))
460  {
461  $valueofldapfield=array();
462  foreach($this->members as $key=>$val) // This is array of users for group into dolibarr database.
463  {
464  $member=new Adherent($this->db);
465  $member->fetch($val->id);
466  $info2 = $member->_load_ldap_info();
467  $valueofldapfield[] = $member->_load_ldap_dn($info2);
468  }
469  $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield)?$valueofldapfield:'');
470  }
471  return $info;
472  }
473 
481  function initAsSpecimen()
482  {
483  global $conf, $user, $langs;
484 
485  // Initialise parametres
486  $this->id = 0;
487  $this->ref = 'MTSPEC';
488  $this->specimen=1;
489 
490  $this->label='MEMBERS TYPE SPECIMEN';
491  $this->note='This is a note';
492  $this->mail_valid='This is welcome email';
493  $this->subscription=1;
494  $this->vote=0;
495 
496  $this->statut=1;
497 
498  // Members of this member type is just me
499  $this->members=array(
500  $user->id => $user
501  );
502  }
503 
509  function getMailOnValid()
510  {
511  global $conf;
512 
513  if (! empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid)))
514  {
515  return $this->mail_valid;
516  }
517  else
518  {
519  return $conf->global->ADHERENT_MAIL_VALID;
520  }
521  }
522 
529  {
530  global $conf;
531 
532  // mail_subscription not defined so never used
533  if (! empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) // Property not yet defined
534  {
535  return $this->mail_subscription;
536  }
537  else
538  {
539  return $conf->global->ADHERENT_MAIL_COTIS;
540  }
541  }
542 
549  {
550  global $conf;
551 
552  // NOTE mail_resiliate not defined so never used
553  if (! empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) // Property not yet defined
554  {
555  return $this->mail_resiliate;
556  }
557  else
558  {
559  return $conf->global->ADHERENT_MAIL_RESIL;
560  }
561  }
562 
563 }
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags) ...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getLibStatut()
getLibStatut
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
__construct($db)
Constructor.
getMailOnResiliate()
getMailOnResiliate
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
getMailOnSubscription()
getMailOnSubscription
create($user, $notrigger=0)
Fonction qui permet de creer le status de l'adherent.
fetch($rowid)
Fonction qui permet de recuperer le status de l'adherent.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
listMembersForMemberType($excludefilter='', $mode=0)
Return array of Member objects for member type this->id (or all if this->id not defined) ...
getMailOnValid()
getMailOnValid
Class to manage members of a foundation.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage members type.
print
Draft customers invoices.
Definition: index.php:91
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
liste_array()
Return list of members' type.
getNomUrl($withpicto=0, $maxlen=0, $notooltip=0)
Return clicable name (with picto eventually)
update($user, $notrigger=0)
Met a jour en base donnees du type.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
initAsSpecimen()
Initialise an instance with random values.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)