dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "box_members_last_subscriptions";
37 public $boximg = "object_user";
38 public $boxlabel = "BoxLastMembersSubscriptions";
39 public $depends = array("adherent");
40
41 public $enabled = 1;
42
49 public function __construct($db, $param = '')
50 {
51 global $conf, $user;
52
53 $this->db = $db;
54
55 // disable module for such cases
56 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
57 if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
58 $this->enabled = 0; // disabled for external users
59 }
60
61 $this->hidden = !(isModEnabled('member') && $user->hasRight('adherent', 'lire'));
62
63 $this->urltoaddentry = DOL_URL_ROOT.'/adherents/card.php?leftmenu=members&action=create';
64 $this->msgNoRecords = 'NoRecordedMembers';
65 }
66
73 public function loadBox($max = 5)
74 {
75 global $user, $langs, $conf;
76 $langs->load("boxes");
77
78 $this->max = $max;
79
80 include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
81 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
82 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
83 $staticmember = new Adherent($this->db);
84 $statictype = new AdherentType($this->db);
85 $subscriptionstatic = new Subscription($this->db);
86
87 $this->info_box_head = array('text' => $langs->trans("LastSubscriptionsModified", $max));
88
89 if ($user->hasRight('adherent', 'lire')) {
90 $sql = "SELECT a.rowid, a.statut as status, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
91 $sql .= " a.gender, a.email, a.photo, a.morphy,";
92 $sql .= " a.datefin as date_end_subscription,";
93 $sql .= " ta.rowid as typeid, ta.libelle as label, ta.subscription as need_subscription,";
94 $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";
95 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta, ".MAIN_DB_PREFIX."subscription as c";
96 $sql .= " WHERE a.entity IN (".getEntity('adherent').")";
97 $sql .= " AND a.fk_adherent_type = ta.rowid";
98 $sql .= " AND c.fk_adherent = a.rowid";
99 $sql .= $this->db->order("c.tms", "DESC");
100 $sql .= $this->db->plimit($max, 0);
101
102 $result = $this->db->query($sql);
103 if ($result) {
104 $num = $this->db->num_rows($result);
105
106 $line = 0;
107 while ($line < $num) {
108 $obj = $this->db->fetch_object($result);
109 $staticmember->id = $obj->rowid;
110 $staticmember->ref = $obj->rowid;
111 $staticmember->lastname = $obj->lastname;
112 $staticmember->firstname = $obj->firstname;
113 $staticmember->gender = $obj->gender;
114 $staticmember->email = $obj->email;
115 $staticmember->photo = $obj->photo;
116 $staticmember->morphy = $obj->morphy;
117 $staticmember->status = $obj->status;
118 $staticmember->need_subscription = $obj->need_subscription;
119 $staticmember->datefin = $this->db->jdate($obj->date_end_subscription);
120 if (!empty($obj->fk_soc)) {
121 $staticmember->fk_soc = $obj->fk_soc;
122 $staticmember->fetch_thirdparty();
123 $staticmember->name = $staticmember->thirdparty->name;
124 } else {
125 $staticmember->name = $obj->company;
126 }
127
128 $subscriptionstatic->id = $obj->cid;
129 $subscriptionstatic->ref = $obj->cid;
130
131 $this->info_box_contents[$line][] = array(
132 'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
133 'text' => $subscriptionstatic->getNomUrl(1),
134 'asis' => 1,
135 );
136
137 $this->info_box_contents[$line][] = array(
138 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
139 'text' => $staticmember->getNomUrl(-1, 32, 'card'),
140 'asis' => 1,
141 );
142
143 $daterange = get_date_range($this->db->jdate($obj->date_start), $this->db->jdate($obj->date_end));
144 $this->info_box_contents[$line][] = array(
145 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone" title="'.dol_escape_htmltag($daterange).'"',
146 'text' => $daterange,
147 );
148
149 $this->info_box_contents[$line][] = array(
150 'td' => 'class="nowraponall right amount" width="18"',
151 'text' => price($obj->subscription),
152 );
153
154 $this->info_box_contents[$line][] = array(
155 'td' => 'class="right tdoverflowmax150 maxwidth150onsmartphone" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($obj->datem, 'dayhour', 'tzuserrel')).'"',
156 'text' => dol_print_date($this->db->jdate($obj->datem ? $obj->datem : $obj->datec), 'dayhour', 'tzuserrel'),
157 );
158
159 $line++;
160 }
161
162
163 $this->db->free($result);
164 } else {
165 $this->info_box_contents[0][0] = array(
166 'td' => '',
167 'maxlength' => 500,
168 'text' => ($this->db->error().' sql='.$sql),
169 );
170 }
171 } else {
172 $this->info_box_contents[0][0] = array(
173 'td' => 'class="nohover left"',
174 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
175 );
176 }
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 a 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...