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

Last change on this file since 5099 was 5099, checked in by Eric, 14 years ago

[nbc_HistoryIPExcluder] Initial SVN creation

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