29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $table_element =
'adherent_type';
45 public $element =
'adherent_type';
50 public $picto =
'members';
56 public $ismultientitymanaged = 1;
80 public $duration_value;
100 public $caneditamount;
118 public $mail_subscription =
'';
121 public $mail_resiliate =
'';
124 public $mail_exclude =
'';
127 public $members = array();
130 public $other = array();
145 public $multilangs = array();
168 $current_lang = $langs->getDefaultLang();
170 $sql =
"SELECT lang, label, description, email";
171 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
172 $sql .=
" WHERE fk_type = ".((int) $this->
id);
174 $result = $this->db->query($sql);
176 while ($obj = $this->db->fetch_object($result)) {
178 if ($obj->lang == $current_lang) {
179 $this->label = $obj->label;
181 $this->email = $obj->email;
183 $this->multilangs[
"$obj->lang"][
"label"] = $obj->label;
184 $this->multilangs[
"$obj->lang"][
"description"] = $obj->description;
185 $this->multilangs[
"$obj->lang"][
"email"] = $obj->email;
189 $this->error =
"Error: ".$this->db->lasterror().
" - ".$sql;
202 global $conf, $langs;
204 $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
205 $current_lang = $langs->getDefaultLang();
207 foreach ($langs_available as $key => $value) {
208 if ($key == $current_lang) {
209 $sql =
"SELECT rowid";
210 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
211 $sql .=
" WHERE fk_type = ".((int) $this->
id);
212 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
214 $result = $this->db->query($sql);
216 if ($this->db->num_rows($result)) {
217 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type_lang";
219 $sql2 .=
" label = '".$this->db->escape($this->label).
"',";
220 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
221 $sql2 .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
223 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type_lang (fk_type, lang, label, description";
225 $sql2 .=
" VALUES(".((int) $this->
id).
",'".$this->db->escape($key).
"','".$this->db->escape($this->label).
"',";
226 $sql2 .=
" '".$this->db->escape($this->
description).
"'";
229 dol_syslog(get_class($this).
'::setMultiLangs key = current_lang = '.$key);
230 if (!$this->db->query($sql2)) {
231 $this->error = $this->db->lasterror();
234 } elseif (isset($this->multilangs[$key])) {
235 $sql =
"SELECT rowid";
236 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
237 $sql .=
" WHERE fk_type = ".((int) $this->
id);
238 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
240 $result = $this->db->query($sql);
242 if ($this->db->num_rows($result)) {
243 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type_lang";
245 $sql2 .=
" label = '".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
246 $sql2 .=
" description = '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
247 $sql2 .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
249 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type_lang (fk_type, lang, label, description";
251 $sql2 .=
" VALUES(".$this->id.
",'".$this->db->escape($key).
"','".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
252 $sql2 .=
" '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
257 if ($this->multilangs[
"$key"][
"label"] || $this->multilangs[
"$key"][
"description"]) {
258 if (!$this->db->query($sql2)) {
259 $this->error = $this->db->lasterror();
269 $result = $this->
call_trigger(
'MEMBER_TYPE_SET_MULTILANGS', $user);
271 $this->error = $this->db->lasterror();
288 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
289 $sql .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang = '".$this->db->escape($langtodelete).
"'";
291 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
292 $result = $this->db->query($sql);
295 $result = $this->
call_trigger(
'MEMBER_TYPE_DEL_MULTILANGS', $user);
297 $this->error = $this->db->lasterror();
298 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
304 $this->error = $this->db->lasterror();
305 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
317 public function create($user, $notrigger = 0)
319 global $langs, $conf;
323 $this->status = (int) $this->status;
324 $this->label = trim($this->label);
328 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type (";
332 $sql .=
") VALUES (";
333 $sql .=
"'".$this->db->escape($this->morphy).
"'";
334 $sql .=
", '".$this->db->escape($this->label).
"'";
335 $sql .=
", ".((int) $conf->entity);
338 dol_syslog(
"Adherent_type::create", LOG_DEBUG);
339 $result = $this->db->query($sql);
341 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"adherent_type");
343 $result = $this->
update($user, 1);
345 $this->db->rollback();
351 $result = $this->
call_trigger(
'MEMBER_TYPE_CREATE', $user);
362 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
363 $this->db->rollback();
367 $this->error = $this->db->lasterror();
368 $this->db->rollback();
380 public function update($user, $notrigger = 0)
382 global $langs, $conf, $hookmanager;
386 $this->label = trim($this->label);
388 if (empty($this->note_public) && !empty($this->note)) {
389 $this->note_public = $this->note;
394 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type ";
396 $sql .=
"statut = ".((int) $this->status).
",";
397 $sql .=
"libelle = '".$this->db->escape($this->label).
"',";
398 $sql .=
"morphy = '".$this->db->escape($this->morphy).
"',";
399 $sql .=
"subscription = '".$this->db->escape($this->subscription).
"',";
400 $sql .=
"amount = ".((empty($this->amount) && $this->amount ==
'') ?
'null' : ((float) $this->amount)).
",";
401 $sql .=
"caneditamount = ".((int) $this->caneditamount).
",";
402 $sql .=
"duration = '".$this->db->escape($this->duration_value.$this->duration_unit).
"',";
403 $sql .=
"note = '".$this->db->escape($this->note_public).
"',";
404 $sql .=
"vote = ".(integer) $this->db->escape($this->vote).
",";
405 $sql .=
"mail_valid = '".$this->db->escape($this->mail_valid).
"'";
406 $sql .=
" WHERE rowid =".((int) $this->
id);
408 $result = $this->db->query($sql);
410 $this->
description = $this->db->escape($this->note_public);
415 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
430 if (!$error && !$notrigger) {
432 $result = $this->
call_trigger(
'MEMBER_TYPE_MODIFY', $user);
443 $this->db->rollback();
444 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
448 $this->error = $this->db->lasterror();
449 $this->db->rollback();
460 public function delete()
466 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"adherent_type";
467 $sql .=
" WHERE rowid = ".((int) $this->
id);
469 $resql = $this->db->query($sql);
472 $result = $this->
call_trigger(
'MEMBER_TYPE_DELETE', $user);
474 $error++; $this->db->rollback();
return -2;
481 $this->db->rollback();
482 $this->error = $this->db->lasterror();
495 global $langs, $conf;
497 $sql =
"SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.caneditamount, d.mail_valid, d.note as note_public, d.vote";
498 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as d";
499 $sql .=
" WHERE d.rowid = ".(int) $rowid;
501 dol_syslog(
"Adherent_type::fetch", LOG_DEBUG);
503 $resql = $this->db->query($sql);
505 if ($this->db->num_rows($resql)) {
506 $obj = $this->db->fetch_object($resql);
508 $this->
id = $obj->rowid;
509 $this->
ref = $obj->rowid;
510 $this->label = $obj->label;
511 $this->morphy = $obj->morphy;
512 $this->status = $obj->status;
513 $this->duration = $obj->duration;
514 $this->duration_value = substr($obj->duration, 0,
dol_strlen($obj->duration) - 1);
515 $this->duration_unit = substr($obj->duration, -1);
516 $this->subscription = $obj->subscription;
517 $this->amount = $obj->amount;
518 $this->caneditamount = $obj->caneditamount;
519 $this->mail_valid = $obj->mail_valid;
520 $this->note = $obj->note_public;
521 $this->note_public = $obj->note_public;
522 $this->vote = $obj->vote;
535 $this->error = $this->db->lasterror();
550 global $conf, $langs;
552 $adherenttypes = array();
554 $sql =
"SELECT rowid, libelle as label";
555 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
556 $sql .=
" WHERE entity IN (".getEntity(
'member_type').
")";
558 $sql .=
" AND statut = ".((int) $status);
561 $resql = $this->db->query($sql);
563 $nump = $this->db->num_rows($resql);
568 $obj = $this->db->fetch_object($resql);
570 $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
575 print $this->db->error();
577 return $adherenttypes;
588 global $conf, $langs;
590 $amountbytype = array();
592 $sql =
"SELECT rowid, amount";
593 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
594 $sql .=
" WHERE entity IN (".getEntity(
'member_type').
")";
595 if ($status !==
null) {
596 $sql .=
" AND statut = ".((int) $status);
599 $resql = $this->db->query($sql);
601 $nump = $this->db->num_rows($resql);
606 $obj = $this->db->fetch_object($resql);
608 $amountbytype[$obj->rowid] = $obj->amount;
613 print $this->db->error();
616 return $amountbytype;
634 $sql =
"SELECT a.rowid";
635 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
636 $sql .=
" WHERE a.entity IN (".getEntity(
'member').
")";
637 $sql .=
" AND a.fk_adherent_type = ".((int) $this->
id);
638 if (!empty($excludefilter)) {
639 $sql .=
' AND ('.$excludefilter.
')';
642 dol_syslog(get_class($this).
"::listMembersForMemberType", LOG_DEBUG);
643 $resql = $this->db->query($sql);
645 while ($obj = $this->db->fetch_object($resql)) {
646 if (!array_key_exists($obj->rowid, $ret)) {
648 $memberstatic =
new Adherent($this->db);
650 $memberstatic->fetch($obj->rowid,
'',
'',
'',
false,
false);
652 $memberstatic->fetch($obj->rowid);
654 $ret[$obj->rowid] = $memberstatic;
656 $ret[$obj->rowid] = $obj->rowid;
661 $this->db->free($resql);
663 $this->members = $ret;
667 $this->error = $this->db->lasterror();
681 if ($morphy ==
'phy') {
682 return $langs->trans(
"Physical");
683 } elseif ($morphy ==
'mor') {
684 return $langs->trans(
"Moral");
686 return $langs->trans(
"MorAndPhy");
699 global $conf, $langs, $user;
701 $langs->load(
'members');
704 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"MemberType").
'</u> '.$this->
getLibStatut(4);
705 $datas[
'label'] =
'<br>'.$langs->trans(
"Label").
': '.$this->label;
706 if (isset($this->subscription)) {
707 $datas[
'subscription'] =
'<br>'.$langs->trans(
"SubscriptionRequired").
': '.
yn($this->subscription);
709 if (isset($this->vote)) {
710 $datas[
'vote'] =
'<br>'.$langs->trans(
"VoteAllowed").
': '.
yn($this->vote);
712 if (isset($this->duration)) {
713 $datas[
'duration'] =
'<br>'.$langs->trans(
"Duration").
': '.$this->duration_value;
714 if ($this->duration_value > 1) {
715 $dur = array(
"i"=>$langs->trans(
"Minutes"),
"h"=>$langs->trans(
"Hours"),
"d"=>$langs->trans(
"Days"),
"w"=>$langs->trans(
"Weeks"),
"m"=>$langs->trans(
"Months"),
"y"=>$langs->trans(
"Years"));
716 } elseif ($this->duration_value > 0) {
717 $dur = array(
"i"=>$langs->trans(
"Minute"),
"h"=>$langs->trans(
"Hour"),
"d"=>$langs->trans(
"Day"),
"w"=>$langs->trans(
"Week"),
"m"=>$langs->trans(
"Month"),
"y"=>$langs->trans(
"Year"));
719 $datas[
'duration'] .=
" " . (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ? $langs->trans($dur[$this->duration_unit]) :
'');
735 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
742 $classfortooltip =
'classfortooltip';
746 'objecttype' => $this->element,
751 $classfortooltip =
'classforajaxtooltip';
752 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
758 $url = DOL_URL_ROOT.
'/adherents/type.php?rowid='.((int) $this->
id);
759 if ($option !=
'nolink') {
761 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
762 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
763 $add_save_lastsearch_values = 1;
765 if ($add_save_lastsearch_values) {
766 $url .=
'&save_lastsearch_values=1';
769 $linkstart =
'<a href="'.$url.
'"';
770 $linkstart .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
771 $linkstart .= $dataparams.
' class="'.$classfortooltip.
'">';
775 $result .= $linkstart;
777 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
779 if ($withpicto != 2) {
780 $result .= ($maxlen ?
dol_trunc($this->label, $maxlen) : $this->label);
795 return $this->
LibStatut($this->status, $mode);
810 $langs->load(
'companies');
812 $statusType =
'status4';
814 $statusType =
'status5';
817 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
818 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
819 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
820 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
821 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
824 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
844 $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES.
"=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].
",".$conf->global->LDAP_MEMBER_TYPE_DN;
847 $dn = $conf->global->LDAP_MEMBER_TYPE_DN;
850 $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES.
"=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES];
866 global $conf, $langs;
871 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS);
873 if (empty($this->note_public) && !empty($this->note)) {
874 $this->note_public = $this->note;
878 if ($this->label && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) {
879 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label;
881 if ($this->note_public && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) {
882 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] =
dol_string_nohtmltag($this->note_public, 0,
'UTF-8', 1);
884 if (!empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)) {
885 $valueofldapfield = array();
886 foreach ($this->members as $key => $val) {
888 $member->fetch($val->id,
'',
'',
'',
false,
false);
889 $info2 = $member->_load_ldap_info();
890 $valueofldapfield[] = $member->_load_ldap_dn($info2);
892 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
910 $this->
ref =
'MTSPEC';
913 $this->label =
'MEMBERS TYPE SPECIMEN';
914 $this->note_public =
'This is a public note';
915 $this->mail_valid =
'This is welcome email';
916 $this->subscription = 1;
917 $this->caneditamount = 0;
923 $this->members = array(
936 return $this->mail_valid;
951 return $this->mail_subscription;
966 return $this->mail_resiliate;
981 return $this->mail_exclude;
997 global $langs, $user;
1001 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1002 $return .=
'<div class="info-box info-box-sm">';
1003 $return .=
'<span class="info-box-icon bg-infobox-action">';
1005 $return .=
'</span>';
1006 $return .=
'<div class="info-box-content">';
1007 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1011 if ($user->hasRight(
'adherent',
'configurer')) {
1012 $return .=
'<span class="right paddingleft"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&rowid='.urlencode($this->
ref).
'">'.
img_edit().
'</a></span>';
1014 $return .=
'<span class="right"> </span>';
1016 if (property_exists($this,
'vote')) {
1017 $return .=
'<br><span class="info-box-label opacitymedium">'.$langs->trans(
"VoteAllowed").
' : '.
yn($this->vote).
'</span>';
1019 if (property_exists($this,
'amount')) {
1020 if (is_null($this->amount) || $this->amount ===
'') {
1023 $return .=
'<br><span class="info-box-label opacitymedium">'.$langs->trans(
"Amount").
'</span>';
1024 $return .=
'<span class="amount"> : '.price($this->amount).
'</span>';
1027 if (method_exists($this,
'getLibStatut')) {
1028 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1030 $return .=
'</div>';
1031 $return .=
'</div>';
1032 $return .=
'</div>';
Class to manage members of a foundation.
Class to manage members type.
amountByType($status=null)
Return the array of all amounts per membership type id.
__construct($db)
Constructor.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
update($user, $notrigger=0)
Updating the type in the database.
$duration_unit
Expiration unit.
getMailOnExclude()
getMailOnExclude
fetch($rowid)
Function that retrieves the properties of a membership type.
getNomUrl($withpicto=0, $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
create($user, $notrigger=0)
Function to create the member type.
getTooltipContentArray($params)
getTooltipContentArray
setMultiLangs($user)
Update or add a translation for this member type.
getMailOnValid()
getMailOnValid
getMailOnSubscription()
getMailOnSubscription
initAsSpecimen()
Initialise an instance with random values.
liste_array($status=-1)
Return list of members' type.
getLibStatut($mode=0)
Return label of status (activity, closed)
delMultiLangs($langtodelete, $user)
Delete a language for this member type.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
getmorphylib($morphy='')
Return translated label by the nature of a adherent (physical or moral)
getMultiLangs()
Load array this->multilangs.
getMailOnResiliate()
getMailOnResiliate
LibStatut($status, $mode=0)
Return the label of a given status.
_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)
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.