dolibarr  9.0.0
box_members.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 Frederic 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 <http://www.gnu.org/licenses/>.
19  */
20 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
33 class box_members extends ModeleBoxes
34 {
35  var $boxcode="lastmembers";
36  var $boximg="object_user";
37  var $boxlabel="BoxLastMembers";
38  var $depends = array("adherent");
39 
43  public $db;
44 
45  var $param;
46  var $enabled = 1;
47 
48  var $info_box_head = array();
49  var $info_box_contents = array();
50 
51 
58  function __construct($db,$param='')
59  {
60  global $conf, $user;
61 
62  $this->db = $db;
63 
64  // disable module for such cases
65  $listofmodulesforexternal=explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL);
66  if (! in_array('adherent',$listofmodulesforexternal) && ! empty($user->societe_id)) $this->enabled=0; // disabled for external users
67 
68  $this->hidden=! ($user->rights->adherent->lire);
69  }
70 
77  function loadBox($max=5)
78  {
79  global $user, $langs, $db, $conf;
80  $langs->load("boxes");
81 
82  $this->max=$max;
83 
84  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
85  $memberstatic=new Adherent($db);
86 
87  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedMembers",$max));
88 
89  if ($user->rights->adherent->lire)
90  {
91  $sql = "SELECT a.rowid, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
92  $sql.= " a.datec, a.tms, a.statut as status, a.datefin as date_end_subscription,";
93  $sql.= " t.subscription";
94  $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as t";
95  $sql.= " WHERE a.entity IN (".getEntity('member').")";
96  $sql.= " AND a.fk_adherent_type = t.rowid";
97  $sql.= " ORDER BY a.tms DESC";
98  $sql.= $db->plimit($max, 0);
99 
100  $result = $db->query($sql);
101  if ($result)
102  {
103  $num = $db->num_rows($result);
104 
105  $line = 0;
106  while ($line < $num)
107  {
108  $objp = $db->fetch_object($result);
109  $datec=$db->jdate($objp->datec);
110  $datem=$db->jdate($objp->tms);
111 
112  $memberstatic->lastname=$objp->lastname;
113  $memberstatic->firstname=$objp->firstname;
114  $memberstatic->id = $objp->rowid;
115  $memberstatic->ref = $objp->rowid;
116  $memberstatic->company = $objp->company;
117 
118  if (! empty($objp->fk_soc)) {
119  $memberstatic->socid = $objp->fk_soc;
120  $memberstatic->fetch_thirdparty();
121  $memberstatic->name=$memberstatic->thirdparty->name;
122  } else {
123  $memberstatic->name=$objp->company;
124  }
125 
126  $this->info_box_contents[$line][] = array(
127  'td' => '',
128  'text' => $memberstatic->getNomUrl(1),
129  'asis' => 1,
130  );
131 
132  $this->info_box_contents[$line][] = array(
133  'td' => '',
134  'text' => $memberstatic->company,
135  'url' => DOL_URL_ROOT."/adherents/card.php?rowid=".$objp->rowid,
136  );
137 
138  $this->info_box_contents[$line][] = array(
139  'td' => 'class="right"',
140  'text' => dol_print_date($datem, "day"),
141  );
142 
143  $this->info_box_contents[$line][] = array(
144  'td' => 'align="right" width="18"',
145  'text' => $memberstatic->LibStatut($objp->status,$objp->subscription,$db->jdate($objp->date_end_subscription),3),
146  );
147 
148  $line++;
149  }
150 
151  if ($num==0)
152  $this->info_box_contents[$line][0] = array(
153  'td' => 'align="center"',
154  'text'=>$langs->trans("NoRecordedCustomers"),
155  );
156 
157  $db->free($result);
158  } else {
159  $this->info_box_contents[0][0] = array(
160  'td' => '',
161  'maxlength'=>500,
162  'text' => ($db->error().' sql='.$sql),
163  );
164  }
165  } else {
166  $this->info_box_contents[0][0] = array(
167  'td' => 'align="left" class="nohover opacitymedium"',
168  'text' => $langs->trans("ReadPermissionNotAllowed")
169  );
170  }
171  }
172 
181  function showBox($head = null, $contents = null, $nooutput=0)
182  {
183  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
184  }
185 }
186 
__construct($db, $param='')
Constructor.
Definition: box_members.php:58
Class ModeleBoxes.
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_members.php:77
Class to manage members of a foundation.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage the box to show last members.
Definition: box_members.php:33