30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $table_element =
'adherent_type';
46 public $element =
'adherent_type';
51 public $picto =
'members';
95 public $caneditamount;
113 public $mail_subscription =
'';
116 public $mail_resiliate =
'';
119 public $mail_exclude =
'';
122 public $members = array();
137 public $multilangs = array();
149 $this->ismultientitymanaged = 1;
162 $current_lang = $langs->getDefaultLang();
164 $sql =
"SELECT lang, label, description, email";
165 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
166 $sql .=
" WHERE fk_type = ".((int) $this->
id);
168 $result = $this->db->query($sql);
170 while ($obj = $this->db->fetch_object($result)) {
172 if ($obj->lang == $current_lang) {
173 $this->label = $obj->label;
175 $this->email = $obj->email;
177 $this->multilangs[
"$obj->lang"][
"label"] = $obj->label;
178 $this->multilangs[
"$obj->lang"][
"description"] = $obj->description;
179 $this->multilangs[
"$obj->lang"][
"email"] = $obj->email;
183 $this->error =
"Error: ".$this->db->lasterror().
" - ".$sql;
198 $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
199 $current_lang = $langs->getDefaultLang();
201 foreach ($langs_available as $key => $value) {
202 if ($key == $current_lang) {
203 $sql =
"SELECT rowid";
204 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
205 $sql .=
" WHERE fk_type = ".((int) $this->
id);
206 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
208 $result = $this->db->query($sql);
210 if ($this->db->num_rows($result)) {
211 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type_lang";
213 $sql2 .=
" label = '".$this->db->escape($this->label).
"',";
214 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
215 $sql2 .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
217 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type_lang (fk_type, lang, label, description";
219 $sql2 .=
" VALUES(".((int) $this->
id).
",'".$this->db->escape($key).
"','".$this->db->escape($this->label).
"',";
220 $sql2 .=
" '".$this->db->escape($this->
description).
"'";
223 dol_syslog(get_class($this).
'::setMultiLangs key = current_lang = '.$key);
224 if (!$this->db->query($sql2)) {
225 $this->error = $this->db->lasterror();
228 } elseif (isset($this->multilangs[$key])) {
229 $sql =
"SELECT rowid";
230 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
231 $sql .=
" WHERE fk_type = ".((int) $this->
id);
232 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
234 $result = $this->db->query($sql);
236 if ($this->db->num_rows($result)) {
237 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type_lang";
239 $sql2 .=
" label = '".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
240 $sql2 .=
" description = '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
241 $sql2 .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
243 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type_lang (fk_type, lang, label, description";
245 $sql2 .=
" VALUES(".((int) $this->
id).
",'".$this->db->escape($key).
"','".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
246 $sql2 .=
" '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
251 if ($this->multilangs[
"$key"][
"label"] || $this->multilangs[
"$key"][
"description"]) {
252 if (!$this->db->query($sql2)) {
253 $this->error = $this->db->lasterror();
263 $result = $this->
call_trigger(
'MEMBER_TYPE_SET_MULTILANGS', $user);
265 $this->error = $this->db->lasterror();
282 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
283 $sql .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang = '".$this->db->escape($langtodelete).
"'";
285 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
286 $result = $this->db->query($sql);
289 $result = $this->
call_trigger(
'MEMBER_TYPE_DEL_MULTILANGS', $user);
291 $this->error = $this->db->lasterror();
292 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
298 $this->error = $this->db->lasterror();
299 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
311 public function create($user, $notrigger = 0)
318 $this->label = trim($this->label);
322 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type (";
326 $sql .=
") VALUES (";
327 $sql .=
"'".$this->db->escape($this->morphy).
"'";
328 $sql .=
", '".$this->db->escape($this->label).
"'";
329 $sql .=
", ".((int) $conf->entity);
332 dol_syslog(
"Adherent_type::create", LOG_DEBUG);
333 $result = $this->db->query($sql);
335 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"adherent_type");
337 $result = $this->
update($user, 1);
339 $this->db->rollback();
345 $result = $this->
call_trigger(
'MEMBER_TYPE_CREATE', $user);
356 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
357 $this->db->rollback();
361 $this->error = $this->db->lasterror();
362 $this->db->rollback();
374 public function update($user, $notrigger = 0)
380 $this->label = trim($this->label);
382 if (empty($this->note_public) && !empty($this->note)) {
383 $this->note_public = $this->note;
388 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type ";
390 $sql .=
"statut = ".((int) $this->
status).
",";
391 $sql .=
"libelle = '".$this->db->escape($this->label).
"',";
392 $sql .=
"morphy = '".$this->db->escape($this->morphy).
"',";
393 $sql .=
"subscription = '".$this->db->escape($this->subscription).
"',";
394 $sql .=
"amount = ".((empty($this->amount) && $this->amount ==
'') ?
"null" : ((float) $this->amount)).
",";
395 $sql .=
"caneditamount = ".((int) $this->caneditamount).
",";
396 $sql .=
"duration = '".$this->db->escape($this->duration_value.$this->duration_unit).
"',";
397 $sql .=
"note = '".$this->db->escape($this->note_public).
"',";
398 $sql .=
"vote = ".(int) $this->db->escape($this->vote).
",";
399 $sql .=
"mail_valid = '".$this->db->escape($this->mail_valid).
"'";
400 $sql .=
" WHERE rowid =".((int) $this->
id);
402 $result = $this->db->query($sql);
404 $this->
description = $this->db->escape($this->note_public);
409 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
422 if (!$error && !$notrigger) {
424 $result = $this->
call_trigger(
'MEMBER_TYPE_MODIFY', $user);
435 $this->db->rollback();
436 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
440 $this->error = $this->db->lasterror();
441 $this->db->rollback();
452 public function delete($user)
456 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"adherent_type";
457 $sql .=
" WHERE rowid = ".((int) $this->
id);
459 $resql = $this->db->query($sql);
462 $result = $this->
call_trigger(
'MEMBER_TYPE_DELETE', $user);
465 $this->db->rollback();
473 $this->db->rollback();
474 $this->error = $this->db->lasterror();
487 $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";
488 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as d";
489 $sql .=
" WHERE d.rowid = ".(int) $rowid;
491 dol_syslog(
"Adherent_type::fetch", LOG_DEBUG);
493 $resql = $this->db->query($sql);
495 if ($this->db->num_rows($resql)) {
496 $obj = $this->db->fetch_object($resql);
498 $this->
id = $obj->rowid;
499 $this->
ref = $obj->rowid;
500 $this->label = $obj->label;
501 $this->morphy = $obj->morphy;
502 $this->
status = $obj->status;
503 $this->duration = $obj->duration;
504 $this->duration_value = substr($obj->duration, 0,
dol_strlen($obj->duration) - 1);
505 $this->duration_unit = substr($obj->duration, -1);
506 $this->subscription = $obj->subscription;
507 $this->amount = $obj->amount;
508 $this->caneditamount = $obj->caneditamount;
509 $this->mail_valid = $obj->mail_valid;
510 $this->note = $obj->note_public;
511 $this->note_public = $obj->note_public;
512 $this->vote = $obj->vote;
526 $this->error = $this->db->lasterror();
543 $adherenttypes = array();
545 $sql =
"SELECT rowid, libelle as label";
546 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
547 $sql .=
" WHERE entity IN (".getEntity(
'member_type').
")";
549 $sql .=
" AND statut = ".((int) $status);
552 $resql = $this->db->query($sql);
554 $nump = $this->db->num_rows($resql);
559 $obj = $this->db->fetch_object($resql);
561 $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
566 print $this->db->error();
568 return $adherenttypes;
579 $amountbytype = array();
581 $sql =
"SELECT rowid, amount";
582 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
583 $sql .=
" WHERE entity IN (".getEntity(
'member_type').
")";
584 if ($status !==
null) {
585 $sql .=
" AND statut = ".((int) $status);
588 $resql = $this->db->query($sql);
590 $nump = $this->db->num_rows($resql);
595 $obj = $this->db->fetch_object($resql);
597 $amountbytype[$obj->rowid] = $obj->amount;
602 print $this->db->error();
605 return $amountbytype;
621 $sql =
"SELECT a.rowid";
622 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
623 $sql .=
" WHERE a.entity IN (".getEntity(
'member').
")";
624 $sql .=
" AND a.fk_adherent_type = ".((int) $this->
id);
625 if (!empty($excludefilter)) {
626 $sql .=
' AND ('.$excludefilter.
')';
629 dol_syslog(get_class($this).
"::listMembersForMemberType", LOG_DEBUG);
630 $resql = $this->db->query($sql);
632 while ($obj = $this->db->fetch_object($resql)) {
633 if (!array_key_exists($obj->rowid, $ret)) {
635 $memberstatic =
new Adherent($this->db);
637 $memberstatic->fetch($obj->rowid,
'',
'',
'',
false,
false);
639 $memberstatic->fetch($obj->rowid);
641 $ret[$obj->rowid] = $memberstatic;
643 $ret[$obj->rowid] = $obj->rowid;
648 $this->db->free($resql);
650 $this->members = $ret;
654 $this->error = $this->db->lasterror();
668 if ($morphy ==
'phy') {
669 return $langs->trans(
"Physical");
670 } elseif ($morphy ==
'mor') {
671 return $langs->trans(
"Moral");
673 return $langs->trans(
"MorAndPhy");
688 $langs->load(
'members');
691 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"MemberType").
'</u> '.$this->
getLibStatut(4);
692 $datas[
'label'] =
'<br>'.$langs->trans(
"Label").
': '.$this->label;
693 if (isset($this->subscription)) {
694 $datas[
'subscription'] =
'<br>'.$langs->trans(
"SubscriptionRequired").
': '.
yn($this->subscription);
696 if (isset($this->vote)) {
697 $datas[
'vote'] =
'<br>'.$langs->trans(
"VoteAllowed").
': '.
yn($this->vote);
699 if (isset($this->duration)) {
701 if ($this->duration_value > 1) {
702 $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"));
703 } elseif ($this->duration_value > 0) {
704 $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"));
706 $datas[
'duration'] .=
" " . (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ? $langs->trans($dur[$this->duration_unit]) :
'');
722 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
727 $classfortooltip =
'classfortooltip';
731 'objecttype' => $this->element,
736 $classfortooltip =
'classforajaxtooltip';
737 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
743 $url = DOL_URL_ROOT.
'/adherents/type.php?rowid='.((int) $this->
id);
744 if ($option !=
'nolink') {
746 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
747 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
748 $add_save_lastsearch_values = 1;
750 if ($add_save_lastsearch_values) {
751 $url .=
'&save_lastsearch_values=1';
754 $linkstart =
'<a href="'.$url.
'"';
755 $linkstart .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
756 $linkstart .= $dataparams.
' class="'.$classfortooltip.
'">';
760 $result .= $linkstart;
762 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (
' class="'.(($withpicto != 2) ?
'paddingright' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
764 if ($withpicto != 2) {
765 $result .= ($maxlen ?
dol_trunc($this->label, $maxlen) : $this->label);
795 $langs->load(
'companies');
797 $statusType =
'status4';
799 $statusType =
'status5';
802 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
803 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
804 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
805 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
806 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
809 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
853 $info[
"objectclass"] = explode(
',',
getDolGlobalString(
'LDAP_MEMBER_TYPE_OBJECT_CLASS'));
855 if (empty($this->note_public) && !empty($this->note)) {
856 $this->note_public = $this->note;
867 $valueofldapfield = array();
868 foreach ($this->members as $key => $val) {
870 $member->fetch($val->id,
'',
'',
'',
false,
false);
871 $info2 = $member->_load_ldap_info();
872 $valueofldapfield[] = $member->_load_ldap_dn($info2);
874 $info[
getDolGlobalString(
'LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
892 $this->
ref =
'MTSPEC';
895 $this->label =
'MEMBERS TYPE SPECIMEN';
896 $this->note_public =
'This is a public note';
897 $this->mail_valid =
'This is welcome email';
898 $this->subscription = 1;
899 $this->caneditamount = 0;
905 $this->members = array(
920 return $this->mail_valid;
935 return $this->mail_subscription;
950 return $this->mail_resiliate;
965 return $this->mail_exclude;
981 global $langs, $user;
985 $return =
'<div class="box-flex-item box-flex-grow-zero">';
986 $return .=
'<div class="info-box info-box-sm">';
987 $return .=
'<span class="info-box-icon bg-infobox-action">';
989 $return .=
'</span>';
990 $return .=
'<div class="info-box-content">';
991 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
995 if ($user->hasRight(
'adherent',
'configurer')) {
996 $return .=
'<span class="right paddingleft"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&rowid='.urlencode($this->
ref).
'">'.
img_edit().
'</a></span>';
998 $return .=
'<span class="right"> </span>';
1000 if (property_exists($this,
'vote')) {
1001 $return .=
'<br><span class="info-box-label opacitymedium">'.$langs->trans(
"VoteAllowed").
' : '.
yn($this->vote).
'</span>';
1003 if (property_exists($this,
'amount')) {
1004 if (is_null($this->amount) || $this->amount ===
'') {
1007 $return .=
'<br><span class="info-box-label opacitymedium">'.$langs->trans(
"Amount").
'</span>';
1008 $return .=
'<span class="amount"> : '.price($this->amount).
'</span>';
1011 if (method_exists($this,
'getLibStatut')) {
1012 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1014 $return .=
'</div>';
1015 $return .=
'</div>';
1016 $return .=
'</div>';
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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)
$duration_value
type expiration
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.