dolibarr 20.0.0
box_members_last_subscriptions.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
29
34{
35 public $boxcode = "box_members_last_subscriptions";
36 public $boximg = "object_user";
37 public $boxlabel = "BoxLastMembersSubscriptions";
38 public $depends = array("adherent");
39
40 public $enabled = 1;
41
48 public function __construct($db, $param = '')
49 {
50 global $conf, $user;
51
52 $this->db = $db;
53
54 // disable module for such cases
55 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
56 if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
57 $this->enabled = 0; // disabled for external users
58 }
59
60 $this->hidden = !(isModEnabled('member') && $user->hasRight('adherent', 'lire'));
61 }
62
69 public function loadBox($max = 5)
70 {
71 global $user, $langs, $conf;
72 $langs->load("boxes");
73
74 $this->max = $max;
75
76 include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
77 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
78 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
79 $staticmember = new Adherent($this->db);
80 $statictype = new AdherentType($this->db);
81 $subscriptionstatic = new Subscription($this->db);
82
83 $this->info_box_head = array('text' => $langs->trans("LastSubscriptionsModified", $max));
84
85 if ($user->hasRight('adherent', 'lire')) {
86 $sql = "SELECT a.rowid, a.statut as status, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
87 $sql .= " a.gender, a.email, a.photo, a.morphy,";
88 $sql .= " a.datefin as date_end_subscription,";
89 $sql .= " ta.rowid as typeid, ta.libelle as label, ta.subscription as need_subscription,";
90 $sql .= " c.rowid as cid, c.tms as datem, c.datec as datec, c.dateadh as date_start, c.datef as date_end, c.subscription";
91 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta, ".MAIN_DB_PREFIX."subscription as c";
92 $sql .= " WHERE a.entity IN (".getEntity('adherent').")";
93 $sql .= " AND a.fk_adherent_type = ta.rowid";
94 $sql .= " AND c.fk_adherent = a.rowid";
95 $sql .= $this->db->order("c.tms", "DESC");
96 $sql .= $this->db->plimit($max, 0);
97
98 $result = $this->db->query($sql);
99 if ($result) {
100 $num = $this->db->num_rows($result);
101
102 $line = 0;
103 while ($line < $num) {
104 $obj = $this->db->fetch_object($result);
105 $staticmember->id = $obj->rowid;
106 $staticmember->ref = $obj->rowid;
107 $staticmember->lastname = $obj->lastname;
108 $staticmember->firstname = $obj->firstname;
109 $staticmember->gender = $obj->gender;
110 $staticmember->email = $obj->email;
111 $staticmember->photo = $obj->photo;
112 $staticmember->morphy = $obj->morphy;
113 $staticmember->status = $obj->status;
114 $staticmember->need_subscription = $obj->need_subscription;
115 $staticmember->datefin = $this->db->jdate($obj->date_end_subscription);
116 if (!empty($obj->fk_soc)) {
117 $staticmember->fk_soc = $obj->fk_soc;
118 $staticmember->fetch_thirdparty();
119 $staticmember->name = $staticmember->thirdparty->name;
120 } else {
121 $staticmember->name = $obj->company;
122 }
123
124 $subscriptionstatic->id = $obj->cid;
125 $subscriptionstatic->ref = $obj->cid;
126
127 $this->info_box_contents[$line][] = array(
128 'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
129 'text' => $subscriptionstatic->getNomUrl(1),
130 'asis' => 1,
131 );
132
133 $this->info_box_contents[$line][] = array(
134 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
135 'text' => $staticmember->getNomUrl(-1, 32, 'card'),
136 'asis' => 1,
137 );
138
139 $daterange = get_date_range($this->db->jdate($obj->date_start), $this->db->jdate($obj->date_end));
140 $this->info_box_contents[$line][] = array(
141 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone" title="'.dol_escape_htmltag($daterange).'"',
142 'text' => $daterange,
143 );
144
145 $this->info_box_contents[$line][] = array(
146 'td' => 'class="nowraponall right amount" width="18"',
147 'text' => price($obj->subscription),
148 );
149
150 $this->info_box_contents[$line][] = array(
151 'td' => 'class="right tdoverflowmax150 maxwidth150onsmartphone" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($obj->datem, 'dayhour', 'tzuserrel')).'"',
152 'text' => dol_print_date($this->db->jdate($obj->datem ? $obj->datem : $obj->datec), 'dayhour', 'tzuserrel'),
153 );
154
155 $line++;
156 }
157
158 if ($num == 0) {
159 $this->info_box_contents[$line][0] = array(
160 'td' => 'class="center"',
161 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedMembers").'</span>',
162 );
163 }
164
165 $this->db->free($result);
166 } else {
167 $this->info_box_contents[0][0] = array(
168 'td' => '',
169 'maxlength'=>500,
170 'text' => ($this->db->error().' sql='.$sql),
171 );
172 }
173 } else {
174 $this->info_box_contents[0][0] = array(
175 'td' => 'class="nohover left"',
176 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
177 );
178 }
179 }
180
189 public function showBox($head = null, $contents = null, $nooutput = 0)
190 {
191 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
192 }
193}
Class to manage members of a foundation.
Class to manage members type.
Class ModeleBoxes.
Class to manage subscriptions of foundation members.
Class to manage the box to show last members subscriptions.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...