source: extensions/nbc_HistoryIPExcluder/trunk/admin/HIPE_admin.php @ 5615

Last change on this file since 5615 was 5615, checked in by Eric, 15 years ago

[nbc_HistoryIPExcluder]

  • Piwigo 2.1 compliance
  • Multiple database support
  • Improving the display of plugin's name
  • Property svn:eol-style set to LF
File size: 5.6 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5load_language('plugin.lang', HIPE_PATH);
6
7// +-----------------------------------------------------------------------+
8// |                      Getting plugin version                           |
9// +-----------------------------------------------------------------------+
10$plugin =  HIPE_infos(HIPE_PATH);
11$version = $plugin['version'];
12$name = $plugin['name'];
13
14
15$ip_geolocalisation1 = '<a href="http://www.geoiptool.com/fr/?IP=';
16$ip_geolocalisation2 = '" title="Geo IP localisation" target="_blank"><img src="'.HIPE_PATH.'/geoip.ico" class="button" alt="'.l10n('IP_geolocalisation').'"></a>';
17
18$ip_ripe1 = '<a href="http://www.ripe.net/whois?form_type=simple&amp;full_query_string=&amp;searchtext=';
19$ip_ripe2 = '+&amp;do_search=Search" title="Ripe Whois" target="_blank">';
20$ip_ripe3 = '</a>';
21
22
23
24if ( isset($_POST['submit']) and !is_adviser() )
25{
26  $v = $_POST['HIPE_IPs_Excluded'];
27  $v = str_replace( "\r\n", ",", $v );
28  $v = str_replace( ",,", ",", $v );
29
30  $conf['HistoryIPExcluder'] = stripslashes($v);
31
32  $query = '
33    UPDATE '.CONFIG_TABLE.'
34    SET value="'.$conf['HistoryIPExcluder'].'"
35    WHERE param="HistoryIPExcluder"
36    LIMIT 1';
37  pwg_query($query);
38
39  // information message
40  array_push($page['infos'], l10n('HIPE_save_config'));
41}
42elseif ( isset($_POST['CleanHist']) )
43{
44  $conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
45
46  foreach ( $conf_HIPE as $Exclusion )
47  {
48    $query = '
49      delete FROM '.HISTORY_TABLE.' where
50      IP like \''.$Exclusion.'\';';
51    pwg_query($query);
52   }
53
54
55  $query = '
56    truncate '.HISTORY_SUMMARY_TABLE.';';
57  pwg_query($query);
58
59  $query = '
60    UPDATE '.HISTORY_TABLE.'
61    SET summarized = \'false\';';
62  pwg_query($query);
63
64  // information message
65  array_push($page['infos'], l10n('HIPE_hist_cleaned'));
66}
67elseif ( isset($_POST['HIPE_IPByMember']) )
68{
69  $template->assign(
70    array(
71      'HIPE_DESCRIPTION2' => l10n('HIPE_IPByMember_description'),
72    )
73  );
74
75  $query = '
76    select distinct h.ip, u.username
77    from '.HISTORY_TABLE.' as h
78    inner join '.USERS_TABLE.' as u on u.id = h.user_id
79    where h.user_id <> 2
80    order by h.ip
81  ;';
82 
83  $subresult = pwg_query($query);
84
85  while ($subrow = pwg_db_fetch_assoc($subresult))
86  {
87    $template->assign(
88      'resultat',
89      array(
90        'HIPE_RESULTAT1' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
91        'HIPE_RESULTAT2' => $subrow['username'],
92      )
93    );   
94  }
95
96  // information message
97  array_push($page['infos'], l10n('HIPE_resquet_ok'));
98}
99elseif ( isset($_POST['HIPE_OnlyGuest']) )
100{
101  $template->assign(
102    array(
103      'HIPE_DESCRIPTION2' => l10n('HIPE_OnlyGuest_description'),
104    )
105  );
106
107  $query1 = '
108    select distinct h.ip
109    from '.HISTORY_TABLE.' as h
110    where h.user_id <> 2
111  ;';
112 
113  $IPsMember = array_from_query($query1, 'ip');
114
115  $query = '
116    select h.ip, count(h.ip) as nbreIP
117    from '.HISTORY_TABLE.' as h
118    where h.ip not in (\''.implode('\',\'', $IPsMember).'\')
119    group by h.ip
120    order by nbreIP desc
121  ;';
122 
123  $subresult = pwg_query($query);
124
125  while ($subrow = pwg_db_fetch_assoc($subresult))
126  {
127    $template->assign(
128      'resultat',
129      array(
130        'HIPE_RESULTAT1' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
131        'HIPE_RESULTAT2' => $subrow['nbreIP'],
132      )
133    );   
134  }
135
136  // information message
137  array_push($page['infos'], l10n('HIPE_resquet_ok'));
138}
139elseif ( isset($_POST['HIPE_IPForMember']) and isset($_POST['HIPE_input']))
140{
141  $template->assign(
142    array(
143      'HIPE_DESCRIPTION2' => l10n('HIPE_IPForMember_description'),
144    )
145  );
146
147  $query = '
148    select h.ip, u.username
149    from '.HISTORY_TABLE.' as h
150    inner join '.USERS_TABLE.' as u on u.id = h.user_id
151    where u.username like \''.$_POST['HIPE_input'].'\'
152    group by h.ip
153    order by h.ip
154  ;';
155 
156  $subresult = pwg_query($query);
157
158  while ($subrow = pwg_db_fetch_assoc($subresult))
159  {
160    $template->assign(
161      'resultat',
162      array(
163        'HIPE_RESULTAT1' => $subrow['username'],
164        'HIPE_RESULTAT2' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
165      )
166    );   
167  }
168
169  // information message
170  array_push($page['infos'], l10n('HIPE_resquet_ok'));
171}
172elseif ( isset($_POST['HIPE_MemberForIp']) and isset($_POST['HIPE_input']))
173{
174  $template->assign(
175    array(
176      'HIPE_DESCRIPTION2' => l10n('HIPE_MemberForIp_description'),
177    )
178  );
179
180  $query = '
181    select h.ip, u.username
182    from '.HISTORY_TABLE.' as h
183    inner join '.USERS_TABLE.' as u on u.id = h.user_id
184    where h.ip like \''.$_POST['HIPE_input'].'\'
185    group by u.username
186    order by u.username
187  ;';
188 
189  $subresult = pwg_query($query);
190
191  while ($subrow = pwg_db_fetch_assoc($subresult))
192  {
193    $template->assign(
194      'resultat',
195      array(
196        'HIPE_RESULTAT1' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
197        'HIPE_RESULTAT2' => $subrow['username'],
198      )
199    );   
200  }
201
202  // information message
203  array_push($page['infos'], l10n('HIPE_resquet_ok'));
204}
205
206$conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
207
208$template->assign(
209  array(
210    'HIPE_VERSION' => $version,
211    'HIPE_NAME'    => $name,
212    'HIPE_PATH'    => HIPE_PATH,
213    'IPs_EXCLUDED' => implode("\n", $conf_HIPE),
214  )
215);
216
217  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/HIPE_admin.tpl');
218  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
219
220?>
Note: See TracBrowser for help on using the repository browser.