dolibarr 18.0.6
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 * Copyright (C) 2018-2019 Thibault Foucart <support@ptibogxiv.net>
7 * Copyright (C) 2021 Waël Almoman <info@almoman.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
36{
40 public $table_element = 'adherent_type';
41
45 public $element = 'adherent_type';
46
50 public $picto = 'members';
51
56 public $ismultientitymanaged = 1;
57
63 public $libelle;
64
68 public $label;
69
73 public $morphy;
74
75 public $duration;
76
77 /*
78 * type expiration
79 */
80 public $duration_value;
81
86
90 public $subscription;
91
95 public $amount;
96
100 public $caneditamount;
101
106 public $note;
107
109 public $note_public;
110
112 public $vote;
113
115 public $mail_valid;
116
118 public $mail_subscription = '';
119
121 public $mail_resiliate = '';
122
124 public $mail_exclude = '';
125
127 public $members = array();
128
130 public $other = array();
131
135 public $description;
136
140 public $email;
141
145 public $multilangs = array();
146
147
153 public function __construct($db)
154 {
155 $this->db = $db;
156 $this->status = 1;
157 }
158
164 public function getMultiLangs()
165 {
166 global $langs;
167
168 $current_lang = $langs->getDefaultLang();
169
170 $sql = "SELECT lang, label, description, email";
171 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
172 $sql .= " WHERE fk_type = ".((int) $this->id);
173
174 $result = $this->db->query($sql);
175 if ($result) {
176 while ($obj = $this->db->fetch_object($result)) {
177 //print 'lang='.$obj->lang.' current='.$current_lang.'<br>';
178 if ($obj->lang == $current_lang) { // si on a les traduct. dans la langue courante on les charge en infos principales.
179 $this->label = $obj->label;
180 $this->description = $obj->description;
181 $this->email = $obj->email;
182 }
183 $this->multilangs["$obj->lang"]["label"] = $obj->label;
184 $this->multilangs["$obj->lang"]["description"] = $obj->description;
185 $this->multilangs["$obj->lang"]["email"] = $obj->email;
186 }
187 return 1;
188 } else {
189 $this->error = "Error: ".$this->db->lasterror()." - ".$sql;
190 return -1;
191 }
192 }
193
200 public function setMultiLangs($user)
201 {
202 global $conf, $langs;
203
204 $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
205 $current_lang = $langs->getDefaultLang();
206
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)."'";
213
214 $result = $this->db->query($sql);
215
216 if ($this->db->num_rows($result)) { // if there is already a description line for this language
217 $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
218 $sql2 .= " SET";
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)."'";
222 } else {
223 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
224 $sql2 .= ")";
225 $sql2 .= " VALUES(".((int) $this->id).",'".$this->db->escape($key)."','".$this->db->escape($this->label)."',";
226 $sql2 .= " '".$this->db->escape($this->description)."'";
227 $sql2 .= ")";
228 }
229 dol_syslog(get_class($this).'::setMultiLangs key = current_lang = '.$key);
230 if (!$this->db->query($sql2)) {
231 $this->error = $this->db->lasterror();
232 return -1;
233 }
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)."'";
239
240 $result = $this->db->query($sql);
241
242 if ($this->db->num_rows($result)) { // if there is already a description line for this language
243 $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
244 $sql2 .= " SET ";
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)."'";
248 } else {
249 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
250 $sql2 .= ")";
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"])."'";
253 $sql2 .= ")";
254 }
255
256 // We do not save if main fields are empty
257 if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) {
258 if (!$this->db->query($sql2)) {
259 $this->error = $this->db->lasterror();
260 return -1;
261 }
262 }
263 } else {
264 // language is not current language and we didn't provide a multilang description for this language
265 }
266 }
267
268 // Call trigger
269 $result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user);
270 if ($result < 0) {
271 $this->error = $this->db->lasterror();
272 return -1;
273 }
274 // End call triggers
275
276 return 1;
277 }
278
286 public function delMultiLangs($langtodelete, $user)
287 {
288 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type_lang";
289 $sql .= " WHERE fk_type = ".((int) $this->id)." AND lang = '".$this->db->escape($langtodelete)."'";
290
291 dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG);
292 $result = $this->db->query($sql);
293 if ($result) {
294 // Call trigger
295 $result = $this->call_trigger('MEMBER_TYPE_DEL_MULTILANGS', $user);
296 if ($result < 0) {
297 $this->error = $this->db->lasterror();
298 dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
299 return -1;
300 }
301 // End call triggers
302 return 1;
303 } else {
304 $this->error = $this->db->lasterror();
305 dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
306 return -1;
307 }
308 }
309
317 public function create($user, $notrigger = 0)
318 {
319 global $langs, $conf;
320
321 $error = 0;
322
323 $this->status = (int) $this->status;
324 $this->label = trim($this->label);
325
326 $this->db->begin();
327
328 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
329 $sql .= " morphy";
330 $sql .= ", libelle";
331 $sql .= ", entity";
332 $sql .= ") VALUES (";
333 $sql .= "'".$this->db->escape($this->morphy)."'";
334 $sql .= ", '".$this->db->escape($this->label)."'";
335 $sql .= ", ".((int) $conf->entity);
336 $sql .= ")";
337
338 dol_syslog("Adherent_type::create", LOG_DEBUG);
339 $result = $this->db->query($sql);
340 if ($result) {
341 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
342
343 $result = $this->update($user, 1);
344 if ($result < 0) {
345 $this->db->rollback();
346 return -3;
347 }
348
349 if (!$notrigger) {
350 // Call trigger
351 $result = $this->call_trigger('MEMBER_TYPE_CREATE', $user);
352 if ($result < 0) {
353 $error++;
354 }
355 // End call triggers
356 }
357
358 if (!$error) {
359 $this->db->commit();
360 return $this->id;
361 } else {
362 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
363 $this->db->rollback();
364 return -2;
365 }
366 } else {
367 $this->error = $this->db->lasterror();
368 $this->db->rollback();
369 return -1;
370 }
371 }
372
380 public function update($user, $notrigger = 0)
381 {
382 global $langs, $conf, $hookmanager;
383
384 $error = 0;
385
386 $this->label = trim($this->label);
387
388 if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility
389 $this->note_public = $this->note;
390 }
391
392 $this->db->begin();
393
394 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
395 $sql .= "SET ";
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);
407
408 $result = $this->db->query($sql);
409 if ($result) {
410 $this->description = $this->db->escape($this->note_public);
411
412 // Multilangs
413 if (getDolGlobalInt('MAIN_MULTILANGS')) {
414 if ($this->setMultiLangs($user) < 0) {
415 $this->error = $langs->trans("Error")." : ".$this->db->error()." - ".$sql;
416 return -2;
417 }
418 }
419
420 $action = 'update';
421
422 // Actions on extra fields
423 if (!$error) {
424 $result = $this->insertExtraFields();
425 if ($result < 0) {
426 $error++;
427 }
428 }
429
430 if (!$error && !$notrigger) {
431 // Call trigger
432 $result = $this->call_trigger('MEMBER_TYPE_MODIFY', $user);
433 if ($result < 0) {
434 $error++;
435 }
436 // End call triggers
437 }
438
439 if (!$error) {
440 $this->db->commit();
441 return 1;
442 } else {
443 $this->db->rollback();
444 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
445 return -$error;
446 }
447 } else {
448 $this->error = $this->db->lasterror();
449 $this->db->rollback();
450 return -1;
451 }
452 }
453
460 public function delete()
461 {
462 global $user;
463
464 $error = 0;
465
466 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type";
467 $sql .= " WHERE rowid = ".((int) $this->id);
468
469 $resql = $this->db->query($sql);
470 if ($resql) {
471 // Call trigger
472 $result = $this->call_trigger('MEMBER_TYPE_DELETE', $user);
473 if ($result < 0) {
474 $error++; $this->db->rollback(); return -2;
475 }
476 // End call triggers
477
478 $this->db->commit();
479 return 1;
480 } else {
481 $this->db->rollback();
482 $this->error = $this->db->lasterror();
483 return -1;
484 }
485 }
486
493 public function fetch($rowid)
494 {
495 global $langs, $conf;
496
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;
500
501 dol_syslog("Adherent_type::fetch", LOG_DEBUG);
502
503 $resql = $this->db->query($sql);
504 if ($resql) {
505 if ($this->db->num_rows($resql)) {
506 $obj = $this->db->fetch_object($resql);
507
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; // deprecated
521 $this->note_public = $obj->note_public;
522 $this->vote = $obj->vote;
523
524 // multilangs
525 if (getDolGlobalInt('MAIN_MULTILANGS')) {
526 $this->getMultiLangs();
527 }
528
529 // fetch optionals attributes and labels
530 $this->fetch_optionals();
531 }
532
533 return 1;
534 } else {
535 $this->error = $this->db->lasterror();
536 return -1;
537 }
538 }
539
540 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
547 public function liste_array($status = -1)
548 {
549 // phpcs:enable
550 global $conf, $langs;
551
552 $adherenttypes = array();
553
554 $sql = "SELECT rowid, libelle as label";
555 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
556 $sql .= " WHERE entity IN (".getEntity('member_type').")";
557 if ($status >= 0) {
558 $sql .= " AND statut = ".((int) $status);
559 }
560
561 $resql = $this->db->query($sql);
562 if ($resql) {
563 $nump = $this->db->num_rows($resql);
564
565 if ($nump) {
566 $i = 0;
567 while ($i < $nump) {
568 $obj = $this->db->fetch_object($resql);
569
570 $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
571 $i++;
572 }
573 }
574 } else {
575 print $this->db->error();
576 }
577 return $adherenttypes;
578 }
579
586 public function amountByType($status = null)
587 {
588 global $conf, $langs;
589
590 $amountbytype = array();
591
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);
597 }
598
599 $resql = $this->db->query($sql);
600 if ($resql) {
601 $nump = $this->db->num_rows($resql);
602
603 if ($nump) {
604 $i = 0;
605 while ($i < $nump) {
606 $obj = $this->db->fetch_object($resql);
607
608 $amountbytype[$obj->rowid] = $obj->amount;
609 $i++;
610 }
611 }
612 } else {
613 print $this->db->error();
614 }
615
616 return $amountbytype;
617 }
618
628 public function listMembersForMemberType($excludefilter = '', $mode = 0)
629 {
630 global $conf, $user;
631
632 $ret = array();
633
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.')';
640 }
641
642 dol_syslog(get_class($this)."::listMembersForMemberType", LOG_DEBUG);
643 $resql = $this->db->query($sql);
644 if ($resql) {
645 while ($obj = $this->db->fetch_object($resql)) {
646 if (!array_key_exists($obj->rowid, $ret)) {
647 if ($mode < 2) {
648 $memberstatic = new Adherent($this->db);
649 if ($mode == 1) {
650 $memberstatic->fetch($obj->rowid, '', '', '', false, false);
651 } else {
652 $memberstatic->fetch($obj->rowid);
653 }
654 $ret[$obj->rowid] = $memberstatic;
655 } else {
656 $ret[$obj->rowid] = $obj->rowid;
657 }
658 }
659 }
660
661 $this->db->free($resql);
662
663 $this->members = $ret;
664
665 return $ret;
666 } else {
667 $this->error = $this->db->lasterror();
668 return -1;
669 }
670 }
671
678 public function getmorphylib($morphy = '')
679 {
680 global $langs;
681 if ($morphy == 'phy') {
682 return $langs->trans("Physical");
683 } elseif ($morphy == 'mor') {
684 return $langs->trans("Moral");
685 } else {
686 return $langs->trans("MorAndPhy");
687 }
688 //return $morphy;
689 }
690
697 public function getTooltipContentArray($params)
698 {
699 global $conf, $langs, $user;
700
701 $langs->load('members');
702
703 $datas = [];
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);
708 }
709 if (isset($this->vote)) {
710 $datas['vote'] = '<br>'.$langs->trans("VoteAllowed").': '.yn($this->vote);
711 }
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"));
718 }
719 $datas['duration'] .= "&nbsp;" . (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ? $langs->trans($dur[$this->duration_unit]) : '');
720 }
721
722 return $datas;
723 }
724
735 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
736 {
737 global $langs;
738
739 $result = '';
740 $option = '';
741
742 $classfortooltip = 'classfortooltip';
743 $dataparams = '';
744 $params = [
745 'id' => $this->id,
746 'objecttype' => $this->element,
747 'option' => $option,
748 'nofetch' => 1,
749 ];
750 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
751 $classfortooltip = 'classforajaxtooltip';
752 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
753 $label = '';
754 } else {
755 $label = implode($this->getTooltipContentArray($params));
756 }
757
758 $url = DOL_URL_ROOT.'/adherents/type.php?rowid='.((int) $this->id);
759 if ($option != 'nolink') {
760 // Add param to save lastsearch_values or not
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;
764 }
765 if ($add_save_lastsearch_values) {
766 $url .= '&save_lastsearch_values=1';
767 }
768 }
769 $linkstart = '<a href="'.$url.'"';
770 $linkstart .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
771 $linkstart .= $dataparams.' class="'.$classfortooltip.'">';
772
773 $linkend = '</a>';
774
775 $result .= $linkstart;
776 if ($withpicto) {
777 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (' class="'.(($withpicto != 2) ? 'paddingright' : '').'"'), 0, 0, $notooltip ? 0 : 1);
778 }
779 if ($withpicto != 2) {
780 $result .= ($maxlen ?dol_trunc($this->label, $maxlen) : $this->label);
781 }
782 $result .= $linkend;
783
784 return $result;
785 }
786
793 public function getLibStatut($mode = 0)
794 {
795 return $this->LibStatut($this->status, $mode);
796 }
797
798 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
806 public function LibStatut($status, $mode = 0)
807 {
808 // phpcs:enable
809 global $langs;
810 $langs->load('companies');
811
812 $statusType = 'status4';
813 if ($status == 0) {
814 $statusType = 'status5';
815 }
816
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");
822 }
823
824 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
825 }
826
827 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
828 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
838 public function _load_ldap_dn($info, $mode = 0)
839 {
840 // phpcs:enable
841 global $conf;
842 $dn = '';
843 if ($mode == 0) {
844 $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].",".$conf->global->LDAP_MEMBER_TYPE_DN;
845 }
846 if ($mode == 1) {
847 $dn = $conf->global->LDAP_MEMBER_TYPE_DN;
848 }
849 if ($mode == 2) {
850 $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES];
851 }
852 return $dn;
853 }
854
855
856 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
857 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
863 public function _load_ldap_info()
864 {
865 // phpcs:enable
866 global $conf, $langs;
867
868 $info = array();
869
870 // Object classes
871 $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS);
872
873 if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility
874 $this->note_public = $this->note;
875 }
876
877 // Champs
878 if ($this->label && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) {
879 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label;
880 }
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);
883 }
884 if (!empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)) {
885 $valueofldapfield = array();
886 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
887 $member = new Adherent($this->db);
888 $member->fetch($val->id, '', '', '', false, false);
889 $info2 = $member->_load_ldap_info();
890 $valueofldapfield[] = $member->_load_ldap_dn($info2);
891 }
892 $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : '');
893 }
894 return $info;
895 }
896
904 public function initAsSpecimen()
905 {
906 global $user;
907
908 // Initialise parametres
909 $this->id = 0;
910 $this->ref = 'MTSPEC';
911 $this->specimen = 1;
912
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;
918 $this->vote = 0;
919
920 $this->status = 1;
921
922 // Members of this member type is just me
923 $this->members = array(
924 $user->id => $user
925 );
926 }
927
933 public function getMailOnValid()
934 {
935 if (!empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid))) {
936 return $this->mail_valid;
937 }
938
939 return '';
940 }
941
947 public function getMailOnSubscription()
948 {
949 // mail_subscription not defined so never used
950 if (!empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) { // Property not yet defined
951 return $this->mail_subscription;
952 }
953
954 return '';
955 }
956
962 public function getMailOnResiliate()
963 {
964 // NOTE mail_resiliate not defined so never used
965 if (!empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) { // Property not yet defined
966 return $this->mail_resiliate;
967 }
968
969 return '';
970 }
971
977 public function getMailOnExclude()
978 {
979 // NOTE mail_exclude not defined so never used
980 if (!empty($this->mail_exclude) && trim(dol_htmlentitiesbr_decode($this->mail_exclude))) { // Property not yet defined
981 return $this->mail_exclude;
982 }
983
984 return '';
985 }
986
987
995 public function getKanbanView($option = '', $arraydata = null)
996 {
997 global $langs, $user;
998
999 //$selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1000
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">';
1004 $return .= img_picto('', $this->picto);
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>';
1008
1009 //$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1010
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>';
1013 } else {
1014 $return .= '<span class="right">&nbsp;</span>';
1015 }
1016 if (property_exists($this, 'vote')) {
1017 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("VoteAllowed").' : '.yn($this->vote).'</span>';
1018 }
1019 if (property_exists($this, 'amount')) {
1020 if (is_null($this->amount) || $this->amount === '') {
1021 $return .= '<br>';
1022 } else {
1023 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Amount").'</span>';
1024 $return .= '<span class="amount"> : '.price($this->amount).'</span>';
1025 }
1026 }
1027 if (method_exists($this, 'getLibStatut')) {
1028 $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
1029 }
1030 $return .= '</div>';
1031 $return .= '</div>';
1032 $return .= '</div>';
1033 return $return;
1034 }
1035}
$object ref
Definition info.php:78
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.