dolibarr 19.0.4
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-2020 Frederic France <frederic.france@netlogic.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
43 public $db;
44
45 public $param;
46 public $enabled = 1;
47
48 public $info_box_head = array();
49 public $info_box_contents = array();
50
51
58 public function __construct($db, $param = '')
59 {
60 global $conf, $user;
61
62 $this->db = $db;
63
64 // disable module for such cases
65 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
66 if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) {
67 $this->enabled = 0; // disabled for external users
68 }
69
70 $this->hidden = !(isModEnabled('adherent') && $user->hasRight('adherent', 'lire'));
71 }
72
79 public function loadBox($max = 5)
80 {
81 global $user, $langs, $conf;
82 $langs->load("boxes");
83
84 $this->max = $max;
85
86 include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
87 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
88 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
89 $staticmember = new Adherent($this->db);
90 $statictype = new AdherentType($this->db);
91 $subscriptionstatic = new Subscription($this->db);
92
93 $this->info_box_head = array('text' => $langs->trans("LastSubscriptionsModified", $max));
94
95 if ($user->hasRight('adherent', 'lire')) {
96 $sql = "SELECT a.rowid, a.statut as status, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
97 $sql .= " a.gender, a.email, a.photo, a.morphy,";
98 $sql .= " a.datefin as date_end_subscription,";
99 $sql .= " ta.rowid as typeid, ta.libelle as label, ta.subscription as need_subscription,";
100 $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";
101 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta, ".MAIN_DB_PREFIX."subscription as c";
102 $sql .= " WHERE a.entity IN (".getEntity('adherent').")";
103 $sql .= " AND a.fk_adherent_type = ta.rowid";
104 $sql .= " AND c.fk_adherent = a.rowid";
105 $sql .= $this->db->order("c.tms", "DESC");
106 $sql .= $this->db->plimit($max, 0);
107
108 $result = $this->db->query($sql);
109 if ($result) {
110 $num = $this->db->num_rows($result);
111
112 $line = 0;
113 while ($line < $num) {
114 $obj = $this->db->fetch_object($result);
115 $staticmember->id = $obj->rowid;
116 $staticmember->ref = $obj->rowid;
117 $staticmember->lastname = $obj->lastname;
118 $staticmember->firstname = $obj->firstname;
119 $staticmember->gender = $obj->gender;
120 $staticmember->email = $obj->email;
121 $staticmember->photo = $obj->photo;
122 $staticmember->morphy = $obj->morphy;
123 $staticmember->statut = $obj->status;
124 $staticmember->need_subscription = $obj->need_subscription;
125 $staticmember->datefin = $this->db->jdate($obj->date_end_subscription);
126 if (!empty($obj->fk_soc)) {
127 $staticmember->fk_soc = $obj->fk_soc;
128 $staticmember->fetch_thirdparty();
129 $staticmember->name = $staticmember->thirdparty->name;
130 } else {
131 $staticmember->name = $obj->company;
132 }
133
134 $subscriptionstatic->id = $obj->cid;
135 $subscriptionstatic->ref = $obj->cid;
136
137 $this->info_box_contents[$line][] = array(
138 'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"',
139 'text' => $subscriptionstatic->getNomUrl(1),
140 'asis' => 1,
141 );
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
145 'text' => $staticmember->getNomUrl(-1, 32, 'card'),
146 'asis' => 1,
147 );
148
149 $daterange = get_date_range($this->db->jdate($obj->date_start), $this->db->jdate($obj->date_end));
150 $this->info_box_contents[$line][] = array(
151 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone" title="'.dol_escape_htmltag($daterange).'"',
152 'text' => $daterange,
153 );
154
155 $this->info_box_contents[$line][] = array(
156 'td' => 'class="nowraponall right amount" width="18"',
157 'text' => price($obj->subscription),
158 );
159
160 $this->info_box_contents[$line][] = array(
161 'td' => 'class="right tdoverflowmax150 maxwidth150onsmartphone" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($obj->datem, 'dayhour', 'tzuserrel')).'"',
162 'text' => dol_print_date($this->db->jdate($obj->datem ? $obj->datem : $obj->datec), 'dayhour', 'tzuserrel'),
163 );
164
165 $line++;
166 }
167
168 if ($num == 0) {
169 $this->info_box_contents[$line][0] = array(
170 'td' => 'class="center"',
171 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedMembers").'</span>',
172 );
173 }
174
175 $this->db->free($result);
176 } else {
177 $this->info_box_contents[0][0] = array(
178 'td' => '',
179 'maxlength'=>500,
180 'text' => ($this->db->error().' sql='.$sql),
181 );
182 }
183 } else {
184 $this->info_box_contents[0][0] = array(
185 'td' => 'class="nohover left"',
186 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
187 );
188 }
189 }
190
199 public function showBox($head = null, $contents = null, $nooutput = 0)
200 {
201 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
202 }
203}
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.
get_date_range($date_start, $date_end, $format='', $outputlangs='', $withparenthesis=1)
Format output for start and end date.
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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...