29 require_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;
113 public $mail_subscription =
'';
116 public $mail_resiliate =
'';
119 public $mail_exclude =
'';
122 public $members = array();
125 public $other = array();
127 public $multilangs = array();
150 $current_lang = $langs->getDefaultLang();
152 $sql =
"SELECT lang, label, description, email";
153 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
154 $sql .=
" WHERE fk_type = ".((int) $this->
id);
156 $result = $this->
db->query($sql);
158 while ($obj = $this->
db->fetch_object($result)) {
160 if ($obj->lang == $current_lang) {
161 $this->label = $obj->label;
163 $this->email = $obj->email;
165 $this->multilangs[
"$obj->lang"][
"label"] = $obj->label;
166 $this->multilangs[
"$obj->lang"][
"description"] = $obj->description;
167 $this->multilangs[
"$obj->lang"][
"email"] = $obj->email;
171 $this->error =
"Error: ".$this->db->lasterror().
" - ".$sql;
184 global $conf, $langs;
186 $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
187 $current_lang = $langs->getDefaultLang();
189 foreach ($langs_available as $key => $value) {
190 if ($key == $current_lang) {
191 $sql =
"SELECT rowid";
192 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
193 $sql .=
" WHERE fk_type = ".((int) $this->
id);
194 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
196 $result = $this->
db->query($sql);
198 if ($this->
db->num_rows($result)) {
199 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type_lang";
201 $sql2 .=
" label = '".$this->db->escape($this->label).
"',";
202 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
203 $sql2 .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang='".$this->
db->escape($key).
"'";
205 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type_lang (fk_type, lang, label, description";
207 $sql2 .=
" VALUES(".((int) $this->
id).
",'".$this->
db->escape($key).
"','".$this->
db->escape($this->label).
"',";
208 $sql2 .=
" '".$this->db->escape($this->
description).
"'";
211 dol_syslog(get_class($this).
'::setMultiLangs key = current_lang = '.$key);
212 if (!$this->
db->query($sql2)) {
213 $this->error = $this->
db->lasterror();
216 } elseif (isset($this->multilangs[$key])) {
217 $sql =
"SELECT rowid";
218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
219 $sql .=
" WHERE fk_type = ".((int) $this->
id);
220 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
222 $result = $this->
db->query($sql);
224 if ($this->
db->num_rows($result)) {
225 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type_lang";
227 $sql2 .=
" label = '".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
228 $sql2 .=
" description = '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
229 $sql2 .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang='".$this->
db->escape($key).
"'";
231 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type_lang (fk_type, lang, label, description";
233 $sql2 .=
" VALUES(".$this->id.
",'".$this->
db->escape($key).
"','".$this->
db->escape($this->multilangs[
"$key"][
"label"]).
"',";
234 $sql2 .=
" '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
239 if ($this->multilangs[
"$key"][
"label"] || $this->multilangs[
"$key"][
"description"]) {
240 if (!$this->
db->query($sql2)) {
241 $this->error = $this->
db->lasterror();
251 $result = $this->
call_trigger(
'MEMBER_TYPE_SET_MULTILANGS', $user);
253 $this->error = $this->
db->lasterror();
270 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"adherent_type_lang";
271 $sql .=
" WHERE fk_type = ".((int) $this->
id).
" AND lang = '".$this->
db->escape($langtodelete).
"'";
273 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
274 $result = $this->
db->query($sql);
277 $result = $this->
call_trigger(
'MEMBER_TYPE_DEL_MULTILANGS', $user);
279 $this->error = $this->
db->lasterror();
280 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
286 $this->error = $this->
db->lasterror();
287 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
299 public function create($user, $notrigger = 0)
301 global $langs, $conf;
305 $this->status = (int) $this->status;
306 $this->label = trim($this->label);
310 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent_type (";
314 $sql .=
") VALUES (";
315 $sql .=
"'".$this->db->escape($this->morphy).
"'";
316 $sql .=
", '".$this->db->escape($this->label).
"'";
317 $sql .=
", ".$conf->entity;
320 dol_syslog(
"Adherent_type::create", LOG_DEBUG);
321 $result = $this->
db->query($sql);
323 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"adherent_type");
325 $result = $this->
update($user, 1);
327 $this->
db->rollback();
333 $result = $this->
call_trigger(
'MEMBER_TYPE_CREATE', $user);
344 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
345 $this->
db->rollback();
349 $this->error = $this->
db->lasterror();
350 $this->
db->rollback();
362 public function update($user, $notrigger = 0)
364 global $langs, $conf, $hookmanager;
368 $this->label = trim($this->label);
370 if (empty($this->note_public) && !empty($this->note)) {
371 $this->note_public = $this->note;
376 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent_type ";
378 $sql .=
"statut = ".((int) $this->status).
",";
379 $sql .=
"libelle = '".$this->db->escape($this->label).
"',";
380 $sql .=
"morphy = '".$this->db->escape($this->morphy).
"',";
381 $sql .=
"subscription = '".$this->db->escape($this->subscription).
"',";
382 $sql .=
"amount = ".((empty($this->amount) && $this->amount ==
'') ?
'null' : ((
float) $this->amount)).
",";
383 $sql .=
"duration = '".$this->db->escape($this->duration_value.$this->duration_unit).
"',";
384 $sql .=
"note = '".$this->db->escape($this->note_public).
"',";
385 $sql .=
"vote = ".(integer) $this->
db->escape($this->vote).
",";
386 $sql .=
"mail_valid = '".$this->db->escape($this->mail_valid).
"'";
387 $sql .=
" WHERE rowid =".((int) $this->
id);
389 $result = $this->
db->query($sql);
394 if (!empty($conf->global->MAIN_MULTILANGS)) {
396 $this->error = $langs->trans(
"Error").
" : ".$this->
db->error().
" - ".$sql;
411 if (!$error && !$notrigger) {
413 $result = $this->
call_trigger(
'MEMBER_TYPE_MODIFY', $user);
424 $this->
db->rollback();
425 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
429 $this->error = $this->
db->lasterror();
430 $this->
db->rollback();
441 public function delete()
447 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"adherent_type";
448 $sql .=
" WHERE rowid = ".((int) $this->
id);
453 $result = $this->
call_trigger(
'MEMBER_TYPE_DELETE', $user);
455 $error++; $this->
db->rollback();
return -2;
462 $this->
db->rollback();
463 $this->error = $this->
db->lasterror();
476 global $langs, $conf;
478 $sql =
"SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.mail_valid, d.note as note_public, d.vote";
479 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as d";
480 $sql .=
" WHERE d.rowid = ".(int) $rowid;
482 dol_syslog(
"Adherent_type::fetch", LOG_DEBUG);
487 $obj = $this->
db->fetch_object(
$resql);
489 $this->
id = $obj->rowid;
490 $this->
ref = $obj->rowid;
491 $this->label = $obj->label;
492 $this->morphy = $obj->morphy;
493 $this->status = $obj->status;
494 $this->duration = $obj->duration;
495 $this->duration_value = substr($obj->duration, 0,
dol_strlen($obj->duration) - 1);
496 $this->duration_unit = substr($obj->duration, -1);
497 $this->subscription = $obj->subscription;
498 $this->amount = $obj->amount;
499 $this->mail_valid = $obj->mail_valid;
500 $this->note = $obj->note_public;
501 $this->note_public = $obj->note_public;
502 $this->vote = $obj->vote;
505 if (!empty($conf->global->MAIN_MULTILANGS)) {
515 $this->error = $this->
db->lasterror();
530 global $conf, $langs;
532 $adherenttypes = array();
534 $sql =
"SELECT rowid, libelle as label";
535 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
536 $sql .=
" WHERE entity IN (".getEntity(
'member_type').
")";
538 $sql .=
" AND statut = ".((int) $status);
543 $nump = $this->
db->num_rows(
$resql);
548 $obj = $this->
db->fetch_object(
$resql);
550 $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
555 print $this->
db->error();
557 return $adherenttypes;
568 global $conf, $langs;
570 $amountbytype = array();
572 $sql =
"SELECT rowid, amount";
573 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
574 $sql .=
" WHERE entity IN (".getEntity(
'member_type').
")";
575 if ($status !==
null) {
576 $sql .=
" AND statut = ".((int) $status);
581 $nump = $this->
db->num_rows(
$resql);
586 $obj = $this->
db->fetch_object(
$resql);
588 $amountbytype[$obj->rowid] = $obj->amount;
593 print $this->
db->error();
596 return $amountbytype;
614 $sql =
"SELECT a.rowid";
615 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
616 $sql .=
" WHERE a.entity IN (".getEntity(
'member').
")";
617 $sql .=
" AND a.fk_adherent_type = ".((int) $this->
id);
618 if (!empty($excludefilter)) {
619 $sql .=
' AND ('.$excludefilter.
')';
622 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
625 while ($obj = $this->
db->fetch_object(
$resql)) {
626 if (!array_key_exists($obj->rowid, $ret)) {
630 $memberstatic->fetch($obj->rowid,
'',
'',
'',
false,
false);
632 $memberstatic->fetch($obj->rowid);
634 $ret[$obj->rowid] = $memberstatic;
636 $ret[$obj->rowid] = $obj->rowid;
643 $this->members = $ret;
647 $this->error = $this->
db->lasterror();
661 if ($morphy ==
'phy') {
662 return $langs->trans(
"Physical");
663 } elseif ($morphy ==
'mor') {
664 return $langs->trans(
"Moral");
666 return $langs->trans(
"MorAndPhy");
681 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
687 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"MemberType").
'</u>';
688 $label .=
' '.$this->getLibStatut(4);
689 $label .=
'<br>'.$langs->trans(
"Label").
': '.$this->label;
690 if (isset($this->subscription)) {
691 $label .=
'<br>'.$langs->trans(
"SubscriptionRequired").
': '.
yn($this->subscription);
696 $url = DOL_URL_ROOT.
'/adherents/type.php?rowid='.((int) $this->
id);
698 if ($option !=
'nolink') {
700 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
701 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
702 $add_save_lastsearch_values = 1;
704 if ($add_save_lastsearch_values) {
705 $url .=
'&save_lastsearch_values=1';
709 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
712 $result .= $linkstart;
714 $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);
716 if ($withpicto != 2) {
717 $result .= ($maxlen ?
dol_trunc($this->label, $maxlen) : $this->label);
733 return $this->
LibStatut($this->status, $mode);
747 $langs->load(
'companies');
749 $statusType =
'status4';
751 $statusType =
'status5';
754 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
755 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
756 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
"InActivity");
757 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
"ActivityCeased");
758 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
"InActivity");
761 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
781 $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES.
"=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].
",".$conf->global->LDAP_MEMBER_TYPE_DN;
784 $dn = $conf->global->LDAP_MEMBER_TYPE_DN;
787 $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES.
"=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES];
803 global $conf, $langs;
808 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS);
810 if (empty($this->note_public) && !empty($this->note)) {
811 $this->note_public = $this->note;
815 if ($this->label && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) {
816 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label;
818 if ($this->note_public && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) {
819 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] =
dol_string_nohtmltag($this->note_public, 0,
'UTF-8', 1);
821 if (!empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)) {
822 $valueofldapfield = array();
823 foreach ($this->members as $key => $val) {
825 $member->fetch($val->id,
'',
'',
'',
false,
false);
826 $info2 = $member->_load_ldap_info();
827 $valueofldapfield[] = $member->_load_ldap_dn($info2);
829 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
847 $this->
ref =
'MTSPEC';
850 $this->label =
'MEMBERS TYPE SPECIMEN';
851 $this->note_public =
'This is a public note';
852 $this->mail_valid =
'This is welcome email';
853 $this->subscription = 1;
859 $this->members = array(
872 return $this->mail_valid;
887 return $this->mail_subscription;
902 return $this->mail_resiliate;
917 return $this->mail_exclude;