1<?php
2/* Copyright (C) 2001-2003	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003	Jean-Louis Bergamo		<jlb@j1b.org>
4 * Copyright (C) 2004-2009	Laurent Destailleur		<eldy@users.sourceforge.net>
5 * Copyright (C) 2012		Regis Houssin			<regis.houssin@inodbox.com>
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
21/**
22 *	\file       htdocs/public/members/public_list.php
23 *	\ingroup    member
24 *  \brief      File sample to list members
25 */
26
27if (!defined('NOLOGIN')) {
28	define("NOLOGIN", 1); // This means this output page does not require to be logged.
29}
30if (!defined('NOCSRFCHECK')) {
31	define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
32}
33if (!defined('NOIPCHECK')) {
34	define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
35}
36if (!defined('NOBROWSERNOTIF')) {
37	define('NOBROWSERNOTIF', '1');
38}
39
40// For MultiCompany module.
41// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
42// TODO This should be useless. Because entity must be retrieve from object ref and not from url.
43$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
44if (is_numeric($entity)) {
45	define("DOLENTITY", $entity);
46}
47
48require '../../main.inc.php';
49
50// Security check
51if (empty($conf->adherent->enabled)) {
52	accessforbidden('', 0, 0, 1);
53}
54
55
56$langs->loadLangs(array("main", "members", "companies", "other"));
57
58
59/**
60 * Show header for member list
61 *
62 * @param 	string		$title		Title
63 * @param 	string		$head		More info into header
64 * @return	void
65 */
66function llxHeaderVierge($title, $head = "")
67{
68	global $user, $conf, $langs;
69
70	header("Content-type: text/html; charset=".$conf->file->character_set_client);
71	print "<html>\n";
72	print "<head>\n";
73	print "<title>".$title."</title>\n";
74	if ($head) {
75		print $head."\n";
76	}
77	print "</head>\n";
78	print '<body class="public_body">'."\n";
79}
80
81/**
82 * Show footer for member list
83 *
84 * @return	void
85 */
86function llxFooterVierge()
87{
88	printCommonFooter('public');
89
90	print "</body>\n";
91	print "</html>\n";
92}
93
94
95$sortfield = GETPOST("sortfield", 'alpha');
96$sortorder = GETPOST("sortorder", 'alpha');
97$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
98$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
99if (empty($page) || $page == -1) {
100	$page = 0;
101}     // If $page is not defined, or '' or -1
102$offset = $limit * $page;
103$pageprev = $page - 1;
104$pagenext = $page + 1;
105
106$filter = GETPOST('filter');
107$statut = GETPOST('statut');
108
109if (!$sortorder) {
110	$sortorder = "ASC";
111}
112if (!$sortfield) {
113	$sortfield = "lastname";
114}
115
116
117/*
118 * View
119 */
120
121$form = new Form($db);
122
123$morehead = '';
124if (!empty($conf->global->MEMBER_PUBLIC_CSS)) {
125	$morehead = '<link rel="stylesheet" type="text/css" href="'.$conf->global->MEMBER_PUBLIC_CSS.'">';
126} else {
127	$morehead = '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/eldy/style.css.php">';
128}
129
130llxHeaderVierge($langs->trans("ListOfValidatedPublicMembers"), $morehead);
131
132$sql = "SELECT rowid, firstname, lastname, societe, zip, town, email, birth, photo";
133$sql .= " FROM ".MAIN_DB_PREFIX."adherent";
134$sql .= " WHERE entity = ".((int) $entity);
135$sql .= " AND statut = 1";
136$sql .= " AND public = 1";
137$sql .= $db->order($sortfield, $sortorder);
138$sql .= $db->plimit($conf->liste_limit + 1, $offset);
139//$sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, zip, town, d.email, t.libelle as type, d.morphy, d.statut, t.subscription";
140//$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
141//$sql .= " WHERE d.fk_adherent_type = t.rowid AND d.statut = $statut";
142//$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit, $offset);
143
144$result = $db->query($sql);
145if ($result) {
146	$num = $db->num_rows($result);
147	$i = 0;
148
149	$param = "&statut=$statut&sortorder=$sortorder&sortfield=$sortfield";
150	print_barre_liste($langs->trans("ListOfValidatedPublicMembers"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
151	print '<table class="public_border centpercent">';
152
153	print '<tr class="public_liste_titre">';
154	print '<td><a href="'.$_SERVER["PHP_SELF"].'?page='.$page.'&sortorder=ASC&sortfield=firstname">'.dolGetFirstLastname($langs->trans("Firstname"), $langs->trans("Lastname")).'</a></td>';
155	print '<td><a href="'.$_SERVER["PHP_SELF"].'?page='.$page.'&sortorder=ASC&sortfield=societe">'.$langs->trans("Company").'</a></td>'."\n";
156	//print_liste_field_titre("DateOfBirth", $_SERVER["PHP_SELF"],"birth",'',$param,$sortfield,$sortorder); // est-ce nécessaire ??
157	print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "email", '', $param, '', $sortfield, $sortorder, 'public_');
158	print_liste_field_titre("Zip", $_SERVER["PHP_SELF"], "zip", "", $param, '', $sortfield, $sortorder, 'public_');
159	print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "town", "", $param, '', $sortfield, $sortorder, 'public_');
160	print_liste_field_titre("Photo", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'public_');
161	print "</tr>\n";
162
163	while ($i < $num && $i < $conf->liste_limit) {
164		$objp = $db->fetch_object($result);
165
166		print '<tr class="oddeven">';
167		print '<td><a href="public_card.php?id='.$objp->rowid.'">'.dolGetFirstLastname($objp->firstname, $objp->lastname).'</a></td>'."\n";
168		print '<td>'.$objp->societe.'</td>'."\n";
169		print '<td>'.$objp->email.'</td>'."\n";
170		print '<td>'.$objp->zip.'</td>'."\n";
171		print '<td>'.$objp->town.'</td>'."\n";
172		if (isset($objp->photo) && $objp->photo != '') {
173			print '<td>';
174			print $form->showphoto('memberphoto', $objp, 64);
175			print '</td>'."\n";
176		} else {
177			print "<td>&nbsp;</td>\n";
178		}
179		print "</tr>";
180		$i++;
181	}
182	print "</table>";
183} else {
184	dol_print_error($db);
185}
186
187
188llxFooterVierge();
189
190$db->close();
191