dolibarr  7.0.0-beta
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@capnetworks.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 
40  var $db;
41  var $param;
42  var $enabled = 1;
43 
44  var $info_box_head = array();
45  var $info_box_contents = array();
46 
47 
54  function __construct($db,$param='')
55  {
56  global $conf, $user;
57 
58  $this->db = $db;
59 
60  // disable module for such cases
61  $listofmodulesforexternal=explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL);
62  if (! in_array('adherent',$listofmodulesforexternal) && ! empty($user->societe_id)) $this->enabled=0; // disabled for external users
63 
64  $this->hidden=! ($user->rights->adherent->lire);
65  }
66 
73  function loadBox($max=5)
74  {
75  global $user, $langs, $db, $conf;
76  $langs->load("boxes");
77 
78  $this->max=$max;
79 
80  include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
81  $memberstatic=new Adherent($db);
82 
83  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedMembers",$max));
84 
85  if ($user->rights->adherent->lire)
86  {
87  $sql = "SELECT a.rowid, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
88  $sql.= " a.datec, a.tms, a.statut as status, a.datefin as date_end_subscription,";
89  $sql.= " t.subscription";
90  $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as t";
91  $sql.= " WHERE a.entity = ".$conf->entity;
92  $sql.= " AND a.fk_adherent_type = t.rowid";
93  $sql.= " ORDER BY a.tms DESC";
94  $sql.= $db->plimit($max, 0);
95 
96  $result = $db->query($sql);
97  if ($result)
98  {
99  $num = $db->num_rows($result);
100 
101  $line = 0;
102  while ($line < $num)
103  {
104  $objp = $db->fetch_object($result);
105  $datec=$db->jdate($objp->datec);
106  $datem=$db->jdate($objp->tms);
107 
108  $memberstatic->lastname=$objp->lastname;
109  $memberstatic->firstname=$objp->firstname;
110  $memberstatic->id = $objp->rowid;
111  $memberstatic->ref = $objp->rowid;
112  $memberstatic->company = $objp->company;
113 
114  if (! empty($objp->fk_soc)) {
115  $memberstatic->socid = $objp->fk_soc;
116  $memberstatic->fetch_thirdparty();
117  $memberstatic->name=$memberstatic->thirdparty->name;
118  } else {
119  $memberstatic->name=$objp->company;
120  }
121 
122  $this->info_box_contents[$line][] = array(
123  'td' => '',
124  'text' => $memberstatic->getNomUrl(1),
125  'asis' => 1,
126  );
127 
128  $this->info_box_contents[$line][] = array(
129  'td' => '',
130  'text' => $memberstatic->company,
131  'url' => DOL_URL_ROOT."/adherents/card.php?rowid=".$objp->rowid,
132  );
133 
134  $this->info_box_contents[$line][] = array(
135  'td' => 'class="right"',
136  'text' => dol_print_date($datem, "day"),
137  );
138 
139  $this->info_box_contents[$line][] = array(
140  'td' => 'align="right" width="18"',
141  'text' => $memberstatic->LibStatut($objp->status,$objp->subscription,$db->jdate($objp->date_end_subscription),3),
142  );
143 
144  $line++;
145  }
146 
147  if ($num==0)
148  $this->info_box_contents[$line][0] = array(
149  'td' => 'align="center"',
150  'text'=>$langs->trans("NoRecordedCustomers"),
151  );
152 
153  $db->free($result);
154  } else {
155  $this->info_box_contents[0][0] = array(
156  'td' => '',
157  'maxlength'=>500,
158  'text' => ($db->error().' sql='.$sql),
159  );
160  }
161  } else {
162  $this->info_box_contents[0][0] = array(
163  'td' => 'align="left" class="nohover opacitymedium"',
164  'text' => $langs->trans("ReadPermissionNotAllowed")
165  );
166  }
167 
168  }
169 
178  function showBox($head = null, $contents = null, $nooutput=0)
179  {
180  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
181  }
182 
183 }
184 
__construct($db, $param='')
Constructor.
Definition: box_members.php:54
Class ModeleBoxes.
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_members.php:73
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