dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32
33
38{
42 public $table_element = 'adherent_type';
43
47 public $element = 'adherent_type';
48
52 public $picto = 'members';
53
59 public $libelle;
60
64 public $label;
65
69 public $morphy;
70
74 public $duration;
75
79 public $duration_value;
80
84 public $duration_unit;
85
89 public $subscription;
90
94 public $amount;
95
99 public $caneditamount;
100
105 public $note;
106
108 public $note_public;
109
113 public $vote;
114
116 public $mail_valid;
117
119 public $mail_subscription = '';
120
122 public $mail_resiliate = '';
123
125 public $mail_exclude = '';
126
128 public $members = array();
129
133 public $description;
134
138 public $email;
139
143 public $multilangs = array();
144
145
146 // BEGIN MODULEBUILDER PROPERTIES
151 public $fields = array(
152 "rowid" => array("type" => "integer", "label" => "TechnicalID", "enabled" => "1", 'position' => 10, 'notnull' => 1, "visible" => "-1",),
153 "tms" => array("type" => "timestamp", "label" => "DateModification", "enabled" => "1", 'position' => 20, 'notnull' => 1, "visible" => "-1",),
154 "statut" => array("type" => "smallint(6)", "label" => "Statut", "enabled" => "1", 'position' => 500, 'notnull' => 1, "visible" => "-1",),
155 "libelle" => array("type" => "varchar(50)", "label" => "Label", "enabled" => "1", 'position' => 30, 'notnull' => 1, "visible" => "-1",),
156 "subscription" => array("type" => "varchar(3)", "label" => "Subscription", "enabled" => "1", 'position' => 35, 'notnull' => 1, "visible" => "-1",),
157 "amount" => array("type" => "double(24,8)", "label" => "Amount", "enabled" => "1", 'position' => 40, 'notnull' => 0, "visible" => "-1",),
158 "caneditamount" => array("type" => "integer", "label" => "Caneditamount", "enabled" => "1", 'position' => 45, 'notnull' => 0, "visible" => "-1",),
159 "vote" => array("type" => "varchar(3)", "label" => "Vote", "enabled" => "1", 'position' => 50, 'notnull' => 1, "visible" => "-1",),
160 "note" => array("type" => "longtext", "label" => "Note", "enabled" => "1", 'position' => 55, 'notnull' => 0, "visible" => "-1",),
161 "mail_valid" => array("type" => "longtext", "label" => "Mailvalid", "enabled" => "1", 'position' => 60, 'notnull' => 0, "visible" => "-1",),
162 "morphy" => array("type" => "varchar(3)", "label" => "Morphy", "enabled" => "1", 'position' => 65, 'notnull' => 0, "visible" => "-1",),
163 "duration" => array("type" => "varchar(6)", "label" => "Duration", "enabled" => "1", 'position' => 70, 'notnull' => 0, "visible" => "-1",),
164 );
165 // END MODULEBUILDER PROPERTIES
166
167
173 public function __construct($db)
174 {
175 $this->db = $db;
176
177 $this->ismultientitymanaged = 1;
178 $this->status = 1;
179 }
180
186 public function getMultiLangs()
187 {
188 global $langs;
189
190 $current_lang = $langs->getDefaultLang();
191
192 $sql = "SELECT lang, label, description, email";
193 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
194 $sql .= " WHERE fk_type = ".((int) $this->id);
195
196 $result = $this->db->query($sql);
197 if ($result) {
198 while ($obj = $this->db->fetch_object($result)) {
199 //print 'lang='.$obj->lang.' current='.$current_lang.'<br>';
200 if ($obj->lang == $current_lang) { // si on a les traduct. dans la langue courante on les charge en infos principales.
201 $this->label = $obj->label;
202 $this->description = $obj->description;
203 $this->email = $obj->email;
204 }
205 $this->multilangs[(string) $obj->lang]["label"] = $obj->label;
206 $this->multilangs[(string) $obj->lang]["description"] = $obj->description;
207 $this->multilangs[(string) $obj->lang]["email"] = $obj->email;
208 }
209 return 1;
210 } else {
211 $this->error = "Error: ".$this->db->lasterror()." - ".$sql;
212 return -1;
213 }
214 }
215
222 public function setMultiLangs($user)
223 {
224 global $langs;
225
226 $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
227 $current_lang = $langs->getDefaultLang();
228
229 foreach ($langs_available as $key => $value) {
230 if ($key == $current_lang) {
231 $sql = "SELECT rowid";
232 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
233 $sql .= " WHERE fk_type = ".((int) $this->id);
234 $sql .= " AND lang = '".$this->db->escape($key)."'";
235
236 $result = $this->db->query($sql);
237
238 if ($this->db->num_rows($result)) { // if there is already a description line for this language
239 $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
240 $sql2 .= " SET";
241 $sql2 .= " label = '".$this->db->escape($this->label)."',";
242 $sql2 .= " description = '".$this->db->escape($this->description)."'";
243 $sql2 .= " WHERE fk_type = ".((int) $this->id)." AND lang='".$this->db->escape($key)."'";
244 } else {
245 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
246 $sql2 .= ")";
247 $sql2 .= " VALUES(".((int) $this->id).",'".$this->db->escape($key)."','".$this->db->escape($this->label)."',";
248 $sql2 .= " '".$this->db->escape($this->description)."'";
249 $sql2 .= ")";
250 }
251 dol_syslog(get_class($this).'::setMultiLangs key = current_lang = '.$key);
252 if (!$this->db->query($sql2)) {
253 $this->error = $this->db->lasterror();
254 return -1;
255 }
256 } elseif (isset($this->multilangs[$key])) {
257 $sql = "SELECT rowid";
258 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
259 $sql .= " WHERE fk_type = ".((int) $this->id);
260 $sql .= " AND lang = '".$this->db->escape($key)."'";
261
262 $result = $this->db->query($sql);
263
264 if ($this->db->num_rows($result)) { // if there is already a description line for this language
265 $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
266 $sql2 .= " SET ";
267 $sql2 .= " label = '".$this->db->escape($this->multilangs["$key"]["label"])."',";
268 $sql2 .= " description = '".$this->db->escape($this->multilangs["$key"]["description"])."'";
269 $sql2 .= " WHERE fk_type = ".((int) $this->id)." AND lang='".$this->db->escape($key)."'";
270 } else {
271 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
272 $sql2 .= ")";
273 $sql2 .= " VALUES(".((int) $this->id).",'".$this->db->escape($key)."','".$this->db->escape($this->multilangs["$key"]["label"])."',";
274 $sql2 .= " '".$this->db->escape($this->multilangs["$key"]["description"])."'";
275 $sql2 .= ")";
276 }
277
278 // We do not save if main fields are empty
279 if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) {
280 if (!$this->db->query($sql2)) {
281 $this->error = $this->db->lasterror();
282 return -1;
283 }
284 }
285 } else {
286 // language is not current language and we didn't provide a multilang description for this language
287 }
288 }
289
290 // Call trigger
291 $result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user);
292 if ($result < 0) {
293 $this->error = $this->db->lasterror();
294 return -1;
295 }
296 // End call triggers
297
298 return 1;
299 }
300
308 public function delMultiLangs($langtodelete, $user)
309 {
310 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type_lang";
311 $sql .= " WHERE fk_type = ".((int) $this->id)." AND lang = '".$this->db->escape($langtodelete)."'";
312
313 dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG);
314 $result = $this->db->query($sql);
315 if ($result) {
316 // Call trigger
317 $result = $this->call_trigger('MEMBER_TYPE_DEL_MULTILANGS', $user);
318 if ($result < 0) {
319 $this->error = $this->db->lasterror();
320 dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
321 return -1;
322 }
323 // End call triggers
324 return 1;
325 } else {
326 $this->error = $this->db->lasterror();
327 dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
328 return -1;
329 }
330 }
331
339 public function create($user, $notrigger = 0)
340 {
341 global $conf;
342
343 $error = 0;
344
345 $this->status = (int) $this->status;
346 $this->label = trim($this->label);
347
348 $this->db->begin();
349
350 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
351 $sql .= " morphy";
352 $sql .= ", libelle";
353 $sql .= ", entity";
354 $sql .= ") VALUES (";
355 $sql .= "'".$this->db->escape($this->morphy)."'";
356 $sql .= ", '".$this->db->escape($this->label)."'";
357 $sql .= ", ".((int) $conf->entity);
358 $sql .= ")";
359
360 dol_syslog("Adherent_type::create", LOG_DEBUG);
361 $result = $this->db->query($sql);
362 if ($result) {
363 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
364
365 $result = $this->update($user, 1);
366 if ($result < 0) {
367 $this->db->rollback();
368 return -3;
369 }
370
371 if (!$notrigger) {
372 // Call trigger
373 $result = $this->call_trigger('MEMBER_TYPE_CREATE', $user);
374 if ($result < 0) {
375 $error++;
376 }
377 // End call triggers
378 }
379
380 if (!$error) {
381 $this->db->commit();
382 return $this->id;
383 } else {
384 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
385 $this->db->rollback();
386 return -2;
387 }
388 } else {
389 $this->error = $this->db->lasterror();
390 $this->db->rollback();
391 return -1;
392 }
393 }
394
402 public function update($user, $notrigger = 0)
403 {
404 global $langs;
405
406 $error = 0;
407
408 $this->label = trim($this->label);
409
410 if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility
411 $this->note_public = $this->note;
412 }
413
414 $this->db->begin();
415
416 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
417 $sql .= "SET ";
418 $sql .= "statut = ".((int) $this->status).",";
419 $sql .= "libelle = '".$this->db->escape($this->label)."',";
420 $sql .= "morphy = '".$this->db->escape($this->morphy)."',";
421 $sql .= "subscription = '".$this->db->escape($this->subscription)."',";
422 $sql .= "amount = ".((empty($this->amount) && $this->amount == '') ? "null" : ((float) $this->amount)).",";
423 $sql .= "caneditamount = ".((int) $this->caneditamount).",";
424 $sql .= "duration = '".$this->db->escape($this->duration_value.$this->duration_unit)."',";
425 $sql .= "note = '".$this->db->escape($this->note_public)."',";
426 $sql .= "vote = ".(int) $this->db->escape($this->vote).",";
427 $sql .= "mail_valid = '".$this->db->escape($this->mail_valid)."'";
428 $sql .= " WHERE rowid =".((int) $this->id);
429
430 $result = $this->db->query($sql);
431 if ($result) {
432 $this->description = $this->db->escape($this->note_public);
433
434 // Multilangs
435 if (getDolGlobalInt('MAIN_MULTILANGS')) {
436 if ($this->setMultiLangs($user) < 0) {
437 $this->error = $langs->trans("Error")." : ".$this->db->error()." - ".$sql;
438 return -2;
439 }
440 }
441
442 // Actions on extra fields
443 if (!$error) {
444 $result = $this->insertExtraFields();
445 if ($result < 0) {
446 $error++;
447 }
448 }
449
450 if (!$error && !$notrigger) {
451 // Call trigger
452 $result = $this->call_trigger('MEMBER_TYPE_MODIFY', $user);
453 if ($result < 0) {
454 $error++;
455 }
456 // End call triggers
457 }
458
459 if (!$error) {
460 $this->db->commit();
461 return 1;
462 } else {
463 $this->db->rollback();
464 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
465 return -$error;
466 }
467 } else {
468 $this->error = $this->db->lasterror();
469 $this->db->rollback();
470 return -1;
471 }
472 }
473
480 public function delete($user)
481 {
482 $error = 0;
483
484 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type";
485 $sql .= " WHERE rowid = ".((int) $this->id);
486
487 $resql = $this->db->query($sql);
488 if ($resql) {
489 // Call trigger
490 $result = $this->call_trigger('MEMBER_TYPE_DELETE', $user);
491 if ($result < 0) {
492 $error++;
493 $this->db->rollback();
494 return -2;
495 }
496 // End call triggers
497
498 $this->db->commit();
499 return 1;
500 } else {
501 $this->db->rollback();
502 $this->error = $this->db->lasterror();
503 return -1;
504 }
505 }
506
513 public function fetch($rowid)
514 {
515 $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";
516 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
517 $sql .= " WHERE d.rowid = ".(int) $rowid;
518
519 dol_syslog("Adherent_type::fetch", LOG_DEBUG);
520
521 $resql = $this->db->query($sql);
522 if ($resql) {
523 if ($this->db->num_rows($resql)) {
524 $obj = $this->db->fetch_object($resql);
525
526 $this->id = $obj->rowid;
527 $this->ref = $obj->rowid;
528 $this->label = $obj->label;
529 $this->morphy = $obj->morphy;
530 $this->status = $obj->status;
531 $this->duration = $obj->duration;
532 $this->duration_value = (int) substr($obj->duration, 0, dol_strlen($obj->duration) - 1);
533 $this->duration_unit = substr($obj->duration, -1);
534 $this->subscription = $obj->subscription;
535 $this->amount = $obj->amount;
536 $this->caneditamount = $obj->caneditamount;
537 $this->mail_valid = $obj->mail_valid;
538 $this->note = $obj->note_public; // deprecated
539 $this->note_public = $obj->note_public;
540 $this->vote = $obj->vote;
541
542 // multilangs
543 if (getDolGlobalInt('MAIN_MULTILANGS')) {
544 $this->getMultiLangs();
545 }
546
547 // fetch optionals attributes and labels
548 $this->fetch_optionals();
549 return $this->id;
550 } else {
551 return 0;
552 }
553 } else {
554 $this->error = $this->db->lasterror();
555 return -1;
556 }
557 }
558
559 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
566 public function liste_array($status = -1)
567 {
568 // phpcs:enable
569 global $langs;
570
571 $adherenttypes = array();
572
573 $sql = "SELECT rowid, libelle as label";
574 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
575 $sql .= " WHERE entity IN (".getEntity('member_type').")";
576 if ($status >= 0) {
577 $sql .= " AND statut = ".((int) $status);
578 }
579
580 $resql = $this->db->query($sql);
581 if ($resql) {
582 $nump = $this->db->num_rows($resql);
583
584 if ($nump) {
585 $i = 0;
586 while ($i < $nump) {
587 $obj = $this->db->fetch_object($resql);
588
589 $adherenttypes[$obj->rowid] = $langs->trans($obj->label);
590 $i++;
591 }
592 }
593 } else {
594 print $this->db->error();
595 }
596 return $adherenttypes;
597 }
598
605 public function amountByType($status = null)
606 {
607 $amountbytype = array();
608
609 $sql = "SELECT rowid, amount";
610 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
611 $sql .= " WHERE entity IN (".getEntity('member_type').")";
612 if ($status !== null) {
613 $sql .= " AND statut = ".((int) $status);
614 }
615
616 $resql = $this->db->query($sql);
617 if ($resql) {
618 $nump = $this->db->num_rows($resql);
619
620 if ($nump) {
621 $i = 0;
622 while ($i < $nump) {
623 $obj = $this->db->fetch_object($resql);
624
625 $amountbytype[$obj->rowid] = $obj->amount;
626 $i++;
627 }
628 }
629 } else {
630 print $this->db->error();
631 }
632
633 return $amountbytype;
634 }
635
645 public function listMembersForMemberType($excludefilter = '', $mode = 0)
646 {
647 $ret = array();
648
649 $sql = "SELECT a.rowid";
650 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
651 $sql .= " WHERE a.entity IN (".getEntity('member').")";
652 $sql .= " AND a.fk_adherent_type = ".((int) $this->id);
653 if (!empty($excludefilter)) {
654 $sql .= ' AND ('.$excludefilter.')';
655 }
656
657 dol_syslog(get_class($this)."::listMembersForMemberType", LOG_DEBUG);
658 $resql = $this->db->query($sql);
659 if ($resql) {
660 while ($obj = $this->db->fetch_object($resql)) {
661 if (!array_key_exists($obj->rowid, $ret)) {
662 if ($mode < 2) {
663 $memberstatic = new Adherent($this->db);
664 if ($mode == 1) {
665 $memberstatic->fetch($obj->rowid, '', 0, '', false, false);
666 } else {
667 $memberstatic->fetch($obj->rowid);
668 }
669 $ret[$obj->rowid] = $memberstatic;
670 } else {
671 $ret[$obj->rowid] = $obj->rowid;
672 }
673 }
674 }
675
676 $this->db->free($resql);
677
678 $this->members = $ret;
679
680 return $ret;
681 } else {
682 $this->error = $this->db->lasterror();
683 return -1;
684 }
685 }
686
693 public function getmorphylib($morphy = '')
694 {
695 global $langs;
696 if ($morphy == 'phy') {
697 return $langs->trans("Physical");
698 } elseif ($morphy == 'mor') {
699 return $langs->trans("Moral");
700 } else {
701 return $langs->trans("MorAndPhy");
702 }
703 //return $morphy;
704 }
705
712 public function getTooltipContentArray($params)
713 {
714 global $langs;
715
716 $langs->load('members');
717
718 $datas = [];
719 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("MemberType").'</u> '.$this->getLibStatut(4);
720 $datas['label'] = '<br>'.$langs->trans("Label").': '.$this->label;
721 if (isset($this->subscription)) {
722 $datas['subscription'] = '<br>'.$langs->trans("SubscriptionRequired").': '.yn($this->subscription);
723 }
724 if (isset($this->vote)) {
725 $datas['vote'] = '<br>'.$langs->trans("VoteAllowed").': '.yn($this->vote);
726 }
727 if (isset($this->duration)) {
728 $datas['duration'] = '<br>'.$langs->trans("Duration").': '.$this->duration_value;
729 if ($this->duration_value > 1) {
730 $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"));
731 } elseif ($this->duration_value > 0) {
732 $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"));
733 }
734 $datas['duration'] .= "&nbsp;" . (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ? $langs->trans($dur[$this->duration_unit]) : '');
735 }
736
737 return $datas;
738 }
739
750 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
751 {
752 $result = '';
753 $option = '';
754
755 $classfortooltip = 'classfortooltip';
756 $dataparams = '';
757 $params = [
758 'id' => $this->id,
759 'objecttype' => $this->element,
760 'option' => $option,
761 'nofetch' => 1,
762 ];
763 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
764 $classfortooltip = 'classforajaxtooltip';
765 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
766 $label = '';
767 } else {
768 $label = implode($this->getTooltipContentArray($params));
769 }
770
771 $url = DOL_URL_ROOT.'/adherents/type.php?rowid='.((int) $this->id);
772 if ($option != 'nolink') {
773 // Add param to save lastsearch_values or not
774 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
775 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
776 $add_save_lastsearch_values = 1;
777 }
778 if ($add_save_lastsearch_values) {
779 $url .= '&save_lastsearch_values=1';
780 }
781 }
782 $linkstart = '<a href="'.$url.'"';
783 $linkstart .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
784 $linkstart .= $dataparams.' class="'.$classfortooltip.'">';
785
786 $linkend = '</a>';
787
788 $result .= $linkstart;
789 if ($withpicto) {
790 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (' class="'.(($withpicto != 2) ? 'paddingright' : '').'"'), 0, 0, $notooltip ? 0 : 1);
791 }
792 if ($withpicto != 2) {
793 $result .= ($maxlen ? dol_trunc($this->label, $maxlen) : $this->label);
794 }
795 $result .= $linkend;
796
797 return $result;
798 }
799
806 public function getLibStatut($mode = 0)
807 {
808 return $this->LibStatut($this->status, $mode);
809 }
810
811 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
819 public function LibStatut($status, $mode = 0)
820 {
821 // phpcs:enable
822 global $langs;
823 $langs->load('companies');
824
825 $statusType = 'status4';
826 if ($status == 0) {
827 $statusType = 'status5';
828 }
829
830 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
831 $this->labelStatus[0] = $langs->transnoentitiesnoconv("ActivityCeased");
832 $this->labelStatus[1] = $langs->transnoentitiesnoconv("InActivity");
833 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv("ActivityCeased");
834 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv("InActivity");
835 }
836
837 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
838 }
839
840 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
841 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
851 public function _load_ldap_dn($info, $mode = 0)
852 {
853 // phpcs:enable
854 $dn = '';
855 if ($mode == 0) {
856 $dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')]."," . getDolGlobalString('LDAP_MEMBER_TYPE_DN');
857 }
858 if ($mode == 1) {
859 $dn = getDolGlobalString('LDAP_MEMBER_TYPE_DN');
860 }
861 if ($mode == 2) {
862 $dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')];
863 }
864 return $dn;
865 }
866
867
868 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
869 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
875 public function _load_ldap_info()
876 {
877 // phpcs:enable
878 $info = array();
879
880 // Object classes
881 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS'));
882
883 if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility
884 $this->note_public = $this->note;
885 }
886
887 // Champs
888 if ($this->label && getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME')) {
889 $info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME')] = $this->label;
890 }
891 if ($this->note_public && getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION')) {
892 $info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_public, 0, 'UTF-8', 1);
893 }
894 if (getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS')) {
895 $valueofldapfield = array();
896 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
897 $member = new Adherent($this->db);
898 $member->fetch($val->id, '', 0, '', false, false);
899 $info2 = $member->_load_ldap_info();
900 $valueofldapfield[] = $member->_load_ldap_dn($info2);
901 }
902 $info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
903 }
904 return $info;
905 }
906
914 public function initAsSpecimen()
915 {
916 global $user;
917
918 // Initialise parameters
919 $this->id = 0;
920 $this->ref = 'MTSPEC';
921 $this->specimen = 1;
922
923 $this->label = 'MEMBERS TYPE SPECIMEN';
924 $this->note_public = 'This is a public note';
925 $this->mail_valid = 'This is welcome email';
926 $this->subscription = 1;
927 $this->caneditamount = 0;
928 $this->vote = 0;
929
930 $this->status = 1;
931
932 // Members of this member type is just me
933 $this->members = array(
934 $user->id => $user
935 );
936
937 return 1;
938 }
939
945 public function getMailOnValid()
946 {
947 if (!empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid))) {
948 return $this->mail_valid;
949 }
950
951 return '';
952 }
953
959 public function getMailOnSubscription()
960 {
961 // mail_subscription not defined so never used
962 if (!empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) { // Property not yet defined
963 return $this->mail_subscription;
964 }
965
966 return '';
967 }
968
974 public function getMailOnResiliate()
975 {
976 // NOTE mail_resiliate not defined so never used
977 if (!empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) { // Property not yet defined
978 return $this->mail_resiliate;
979 }
980
981 return '';
982 }
983
989 public function getMailOnExclude()
990 {
991 // NOTE mail_exclude not defined so never used
992 if (!empty($this->mail_exclude) && trim(dol_htmlentitiesbr_decode($this->mail_exclude))) { // Property not yet defined
993 return $this->mail_exclude;
994 }
995
996 return '';
997 }
998
999
1007 public function getKanbanView($option = '', $arraydata = null)
1008 {
1009 global $langs, $user;
1010
1011 //$selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1012
1013 $return = '<div class="box-flex-item box-flex-grow-zero">';
1014 $return .= '<div class="info-box info-box-sm">';
1015 $return .= '<span class="info-box-icon bg-infobox-action">';
1016 $return .= img_picto('', $this->picto);
1017 $return .= '</span>';
1018 $return .= '<div class="info-box-content">';
1019 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1020
1021 //$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1022
1023 if ($user->hasRight('adherent', 'configurer')) {
1024 $return .= '<span class="right paddingleft"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit&rowid='.urlencode($this->ref).'">'.img_edit().'</a></span>';
1025 } else {
1026 $return .= '<span class="right">&nbsp;</span>';
1027 }
1028 if (property_exists($this, 'vote')) {
1029 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("VoteAllowed").' : '.yn($this->vote).'</span>';
1030 }
1031 if (property_exists($this, 'amount')) {
1032 if (is_null($this->amount) || $this->amount === '') {
1033 $return .= '<br>';
1034 } else {
1035 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Amount").'</span>';
1036 $return .= '<span class="amount"> : '.price($this->amount).'</span>';
1037 }
1038 }
1039 if (method_exists($this, 'getLibStatut')) {
1040 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1041 }
1042 $return .= '</div>';
1043 $return .= '</div>';
1044 $return .= '</div>';
1045 return $return;
1046 }
1047}
$object ref
Definition info.php:89
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 clickable link of object (with eventually picto)
update($user, $notrigger=0)
Updating the type in the database.
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 clickable name (with picto eventually)
create($user, $notrigger=0)
Function to create the member type.
$fields
Array with all fields and their property.
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 $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
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)
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.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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 a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79