dolibarr  9.0.0
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@inodbox.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 {
38  public $table_element = 'adherent_type';
39 
43  public $element = 'adherent_type';
44 
48  public $picto = 'group';
49 
54  public $ismultientitymanaged = 1;
55 
61  public $libelle;
62 
66  public $label;
67 
72  public $subscription;
73 
75  public $note;
76 
78  public $vote;
79 
81  public $mail_valid;
82 
84  public $members=array();
85 
86 
92  function __construct($db)
93  {
94  $this->db = $db;
95  $this->statut = 1;
96  }
97 
98 
106  function create($user,$notrigger=0)
107  {
108  global $conf;
109 
110  $error=0;
111 
112  $this->statut=(int) $this->statut;
113  $this->label=trim($this->label);
114 
115  $this->db->begin();
116 
117  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
118  $sql.= "libelle";
119  $sql.= ", entity";
120  $sql.= ") VALUES (";
121  $sql.= "'".$this->db->escape($this->label)."'";
122  $sql.= ", ".$conf->entity;
123  $sql.= ")";
124 
125  dol_syslog("Adherent_type::create", LOG_DEBUG);
126  $result = $this->db->query($sql);
127  if ($result)
128  {
129  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
130 
131  $result = $this->update($user,1);
132  if ($result < 0)
133  {
134  $this->db->rollback();
135  return -3;
136  }
137 
138  if (! $notrigger)
139  {
140  // Call trigger
141  $result=$this->call_trigger('MEMBER_TYPE_CREATE',$user);
142  if ($result < 0) { $error++; }
143  // End call triggers
144  }
145 
146  if (! $error)
147  {
148  $this->db->commit();
149  return $this->id;
150  }
151  else
152  {
153  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
154  $this->db->rollback();
155  return -2;
156  }
157  }
158  else
159  {
160  $this->error=$this->db->lasterror();
161  $this->db->rollback();
162  return -1;
163  }
164  }
165 
173  function update($user,$notrigger=0)
174  {
175  global $conf, $hookmanager;
176 
177  $error=0;
178 
179  $this->label=trim($this->label);
180 
181  $this->db->begin();
182 
183  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
184  $sql.= "SET ";
185  $sql.= "statut = ".$this->statut.",";
186  $sql.= "libelle = '".$this->db->escape($this->label) ."',";
187  $sql.= "subscription = '".$this->db->escape($this->subscription)."',";
188  $sql.= "note = '".$this->db->escape($this->note)."',";
189  $sql.= "vote = ".(integer) $this->db->escape($this->vote).",";
190  $sql.= "mail_valid = '".$this->db->escape($this->mail_valid)."'";
191  $sql.= " WHERE rowid =".$this->id;
192 
193  $result = $this->db->query($sql);
194  if ($result)
195  {
196  $action='update';
197 
198  // Actions on extra fields
199  if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
200  {
201  $result=$this->insertExtraFields();
202  if ($result < 0)
203  {
204  $error++;
205  }
206  }
207 
208  if (! $error && ! $notrigger)
209  {
210  // Call trigger
211  $result=$this->call_trigger('MEMBER_TYPE_MODIFY',$user);
212  if ($result < 0) { $error++; }
213  // End call triggers
214  }
215 
216  if (! $error)
217  {
218  $this->db->commit();
219  return 1;
220  }
221  else
222  {
223  $this->db->rollback();
224  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
225  return -$error;
226  }
227  }
228  else
229  {
230  $this->error=$this->db->lasterror();
231  $this->db->rollback();
232  return -1;
233  }
234  }
235 
241  function delete()
242  {
243  global $user;
244 
245  $error = 0;
246 
247  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type";
248  $sql.= " WHERE rowid = ".$this->id;
249 
250  $resql=$this->db->query($sql);
251  if ($resql)
252  {
253  // Call trigger
254  $result=$this->call_trigger('MEMBER_TYPE_DELETE',$user);
255  if ($result < 0) { $error++; $this->db->rollback(); return -2; }
256  // End call triggers
257 
258  $this->db->commit();
259  return 1;
260  }
261  else
262  {
263  $this->db->rollback();
264  $this->error=$this->db->lasterror();
265  return -1;
266  }
267  }
268 
275  function fetch($rowid)
276  {
277  $sql = "SELECT d.rowid, d.libelle as label, d.statut, d.subscription, d.mail_valid, d.note, d.vote";
278  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
279  $sql .= " WHERE d.rowid = ".(int) $rowid;
280 
281  dol_syslog("Adherent_type::fetch", LOG_DEBUG);
282 
283  $resql=$this->db->query($sql);
284  if ($resql)
285  {
286  if ($this->db->num_rows($resql))
287  {
288  $obj = $this->db->fetch_object($resql);
289 
290  $this->id = $obj->rowid;
291  $this->ref = $obj->rowid;
292  $this->label = $obj->label;
293  $this->statut = $obj->statut;
294  $this->subscription = $obj->subscription;
295  $this->mail_valid = $obj->mail_valid;
296  $this->note = $obj->note;
297  $this->vote = $obj->vote;
298  }
299 
300  return 1;
301  }
302  else
303  {
304  $this->error=$this->db->lasterror();
305  return -1;
306  }
307  }
308 
309  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
315  function liste_array()
316  {
317  // phpcs:enable
318  global $conf,$langs;
319 
320  $adherenttypes = array();
321 
322  $sql = "SELECT rowid, libelle as label";
323  $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type";
324  $sql.= " WHERE entity IN (".getEntity('member_type').")";
325 
326  $resql=$this->db->query($sql);
327  if ($resql)
328  {
329  $nump = $this->db->num_rows($resql);
330 
331  if ($nump)
332  {
333  $i = 0;
334  while ($i < $nump)
335  {
336  $obj = $this->db->fetch_object($resql);
337 
338  $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
339  $i++;
340  }
341  }
342  }
343  else
344  {
345  print $this->db->error();
346  }
347  return $adherenttypes;
348  }
349 
359  function listMembersForMemberType($excludefilter='', $mode=0)
360  {
361  global $conf, $user;
362 
363  $ret=array();
364 
365  $sql = "SELECT a.rowid";
366  $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
367  $sql.= " WHERE a.entity IN (".getEntity('member').")";
368  $sql.= " AND a.fk_adherent_type = ".$this->id;
369  if (! empty($excludefilter)) $sql.=' AND ('.$excludefilter.')';
370 
371  dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
372  $resql = $this->db->query($sql);
373  if ($resql)
374  {
375  while ($obj = $this->db->fetch_object($resql))
376  {
377  if (! array_key_exists($obj->rowid, $ret))
378  {
379  if ($mode < 2)
380  {
381  $memberstatic=new Adherent($this->db);
382  if ($mode == 1) {
383  $memberstatic->fetch($obj->rowid,'','','',false, false);
384  } else {
385  $memberstatic->fetch($obj->rowid);
386  }
387  $ret[$obj->rowid]=$memberstatic;
388  }
389  else $ret[$obj->rowid]=$obj->rowid;
390  }
391  }
392 
393  $this->db->free($resql);
394 
395  $this->members=$ret;
396 
397  return $ret;
398  }
399  else
400  {
401  $this->error=$this->db->lasterror();
402  return -1;
403  }
404  }
405 
414  function getNomUrl($withpicto=0, $maxlen=0, $notooltip=0)
415  {
416  global $langs;
417 
418  $result='';
419  $label=$langs->trans("ShowTypeCard",$this->label);
420 
421  $linkstart = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
422  $linkend='</a>';
423 
424  $result .= $linkstart;
425  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);
426  if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->label,$maxlen):$this->label);
427  $result .= $linkend;
428 
429  return $result;
430  }
431 
437  function getLibStatut()
438  {
439  return '';
440  }
441 
442  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
452  function _load_ldap_dn($info,$mode=0)
453  {
454  // phpcs:enable
455  global $conf;
456  $dn='';
457  if ($mode==0) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].",".$conf->global->LDAP_MEMBER_TYPE_DN;
458  if ($mode==1) $dn=$conf->global->LDAP_MEMBER_TYPE_DN;
459  if ($mode==2) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES];
460  return $dn;
461  }
462 
463 
464  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
470  function _load_ldap_info()
471  {
472  // phpcs:enable
473  global $conf,$langs;
474 
475  $info=array();
476 
477  // Object classes
478  $info["objectclass"]=explode(',',$conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS);
479 
480  // Champs
481  if ($this->label && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label;
482  if ($this->note && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 0, 'UTF-8', 1);
483  if (! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS))
484  {
485  $valueofldapfield=array();
486  foreach($this->members as $key=>$val) // This is array of users for group into dolibarr database.
487  {
488  $member=new Adherent($this->db);
489  $member->fetch($val->id,'','','',false,false);
490  $info2 = $member->_load_ldap_info();
491  $valueofldapfield[] = $member->_load_ldap_dn($info2);
492  }
493  $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield)?$valueofldapfield:'');
494  }
495  return $info;
496  }
497 
505  function initAsSpecimen()
506  {
507  global $conf, $user, $langs;
508 
509  // Initialise parametres
510  $this->id = 0;
511  $this->ref = 'MTSPEC';
512  $this->specimen=1;
513 
514  $this->label='MEMBERS TYPE SPECIMEN';
515  $this->note='This is a note';
516  $this->mail_valid='This is welcome email';
517  $this->subscription=1;
518  $this->vote=0;
519 
520  $this->statut=1;
521 
522  // Members of this member type is just me
523  $this->members=array(
524  $user->id => $user
525  );
526  }
527 
533  function getMailOnValid()
534  {
535  global $conf;
536 
537  if (! empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid)))
538  {
539  return $this->mail_valid;
540  }
541 
542  return '';
543  }
544 
551  {
552  global $conf;
553 
554  // mail_subscription not defined so never used
555  if (! empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) // Property not yet defined
556  {
557  return $this->mail_subscription;
558  }
559 
560  return '';
561  }
562 
569  {
570  global $conf;
571 
572  // NOTE mail_resiliate not defined so never used
573  if (! empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) // Property not yet defined
574  {
575  return $this->mail_resiliate;
576  }
577 
578  return '';
579  }
580 }
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags) ...
print
Draft customers invoices.
Definition: index.php:91
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
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
if(! empty($search_group)) natural_search(array("g.nom" g note
Definition: list.php:123
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&#39;adherent.
fetch($rowid)
Fonction qui permet de recuperer le status de l&#39;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&#39;annuaire LDAP pour l&#39;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.
Class to manage members type.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0)
Clean a string from all HTML tags and entities.
liste_array()
Return list of members&#39; 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, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)