source: extensions/Register_FluxBB/admin/Register_FluxBB_admin.php @ 3351

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

First commit

  • Property svn:eol-style set to LF
File size: 35.4 KB
Line 
1<?php
2
3global $user, $lang, $conf, $template, $errors;
4
5if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
6
7//ini_set('error_reporting', E_ALL);
8//ini_set('display_errors', true);
9
10include_once (PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
11include_once (PHPWG_ROOT_PATH.'/include/constants.php');
12include_once (Register_FluxBB_PATH.'include/constants.php');
13include_once (Register_FluxBB_PATH.'include/functions_Register_FluxBB.inc.php');
14$my_base_url = get_admin_plugin_menu_link(__FILE__);
15load_language('plugin.lang', Register_FluxBB_PATH);
16
17// +-----------------------------------------------------------------------+
18// |                            Tabssheet                                  |
19// +-----------------------------------------------------------------------+
20if (!isset($_GET['tab']))
21    $page['tab'] = 'info';
22else
23    $page['tab'] = $_GET['tab'];
24
25$tabsheet = new tabsheet();
26$tabsheet->add('info',
27               l10n('Tab_Info'),
28               $my_base_url.'&amp;tab=info');
29$tabsheet->add('manage',
30               l10n('Tab_Manage'),
31               $my_base_url.'&amp;tab=manage');
32$tabsheet->add('Migration',
33               l10n('Tab_Migration'),
34               $my_base_url.'&amp;tab=Migration');
35$tabsheet->add('Synchro',
36               l10n('Tab_Synchro'),
37               $my_base_url.'&amp;tab=Synchro');
38$tabsheet->select($page['tab']);
39$tabsheet->assign();
40
41
42$page['infos'] = array();
43$error = array();
44
45// +-----------------------------------------------------------------------+
46// |                            Functions
47// +-----------------------------------------------------------------------+
48function Audit_PWG_FluxBB()
49{
50  global $page, $conf, $errors;
51
52  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
53
54  $page_Register_FluxBB_admin = get_admin_plugin_menu_link(__FILE__);
55 
56
57
58  $msg_error_PWG_Dup = '';
59  $msg_error_FluxBB_Dup = '';
60  $msg_error_Link_Break = '';
61  $msg_error_Link_Bad = '';
62  $msg_error_Synchro = '';
63  $msg_ok_Synchro = '';
64  $msg_error_PWG2FluxBB = '';
65  $msg_error_FluxBB2PWG = '';
66
67
68
69  $query = "
70    SELECT COUNT(*) AS nbr_dup, id, username
71    FROM ".USERS_TABLE."
72    GROUP BY BINARY username
73    HAVING COUNT(*) > 1
74  ;";
75  $result = pwg_query($query);
76 
77  while($row = mysql_fetch_array($result))
78    $msg_error_PWG_Dup .= '<br/>'.l10n('Register_FluxBB_Error_PWG_Dup').$row['nbr_dup'].' x '.$row['username'];
79
80  if ($msg_error_PWG_Dup == '')
81    array_push($page['infos'], l10n('Register_FluxBB_Audit_PWG_Dup').'<br/>'.l10n('Register_FluxBB_Audit_OK'));
82  else
83    $msg_error_PWG_Dup = l10n('Register_FluxBB_Audit_PWG_Dup').$msg_error_PWG_Dup.'<br>'.l10n('Register_FluxBB_Advise_PWG_Dup');
84 
85
86
87  $query = "
88    SELECT COUNT(*) AS nbr_dup, username
89    FROM ".FluxBB_USERS_TABLE."
90    GROUP BY BINARY username
91    HAVING COUNT(*) > 1
92  ;";
93  $result = pwg_query($query);
94 
95  while($row = mysql_fetch_array($result))
96  {
97    $msg_error_FluxBB_Dup .= '<br/>'.l10n('Register_FluxBB_Error_FluxBB_Dup').$row['nbr_dup'].' x '.$row['username'];
98
99    $subquery = "
100      SELECT id, username, email
101      FROM ".FluxBB_USERS_TABLE."
102      WHERE BINARY username = BINARY '".$row['username']."'
103    ;";
104    $subresult = pwg_query($subquery);
105 
106    while($subrow = mysql_fetch_array($subresult))
107    {
108      $msg_error_FluxBB_Dup .= '<br/>id:'.$subrow['id'].'='.$subrow['username'].' ('.$subrow['email'].')';
109 
110      if ( !is_adviser() )
111      {
112        $msg_error_FluxBB_Dup .= ' <a href="';
113     
114        $msg_error_FluxBB_Dup .= add_url_params($page_Register_FluxBB_admin, array(
115          'action' => 'del_user',
116          'id' => $subrow['id'],
117        ));
118        $msg_error_FluxBB_Dup .= '" title="'.l10n('Register_FluxBB_Del_User').$subrow['username'].'"';
119        $msg_error_FluxBB_Dup .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
120        $msg_error_FluxBB_Dup .= '><img src="'.Register_FluxBB_PATH.'/icon/user_delete.png" alt="'.l10n('Register_FluxBB_Del_User').$subrow['username'].'" /></a>';
121      }
122    }
123  }
124
125  if ($msg_error_FluxBB_Dup == '')
126    array_push($page['infos'], l10n('Register_FluxBB_Audit_FluxBB_Dup').'<br/>'.l10n('Register_FluxBB_Audit_OK'));
127  else
128    $msg_error_FluxBB_Dup = l10n('Register_FluxBB_Audit_FluxBB_Dup').$msg_error_FluxBB_Dup.'<br>'.l10n('Register_FluxBB_Advise_FluxBB_Dup');
129 
130
131
132  $query = "
133    SELECT pwg.id as pwg_id, bb.id as bb_id, pwg.username as pwg_user, pwg.mail_address as pwg_mail
134    FROM ".FluxBB_USERS_TABLE." AS bb, ".USERS_TABLE." as pwg
135    WHERE bb.id NOT in (
136      SELECT id_user_FluxBB
137      FROM ".Register_FluxBB_ID_TABLE."
138    )
139    AND pwg.id NOT in (
140      SELECT id_user_pwg
141      FROM ".Register_FluxBB_ID_TABLE."
142    )
143    AND pwg.username = bb.username
144    AND pwg.mail_address = bb.email
145  ;";
146  $result = pwg_query($query);
147 
148  while($row = mysql_fetch_array($result))
149  {
150    $msg_error_Link_Break .= '<br/>'.l10n('Register_FluxBB_Error_Link_Break').$row['pwg_user'].' ('.$row['pwg_mail'].')';
151
152    if ( !is_adviser() )
153    {
154      $msg_error_Link_Break .= ' <a href="';
155 
156      $msg_error_Link_Break .= add_url_params($page_Register_FluxBB_admin, array(
157        'action'   => 'new_link',
158        'pwg_id' => $row['pwg_id'],
159        'bb_id' => $row['bb_id'],
160      ));
161      $msg_error_Link_Break .= '" title="'.l10n('Register_FluxBB_New_Link').$row['pwg_user'].'"';
162      $msg_error_Link_Break .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
163      $msg_error_Link_Break .= '><img src="'.Register_FluxBB_PATH.'/icon/link_break.png" alt="'.l10n('Register_FluxBB_New_Link').$row['pwg_user'].'" /></a>';
164    }
165  }
166
167  if ($msg_error_Link_Break == '')
168    array_push($page['infos'], l10n('Register_FluxBB_Audit_Link_Break').'<br/>'.l10n('Register_FluxBB_Audit_OK'));
169  else
170    $msg_error_Link_Break = l10n('Register_FluxBB_Audit_Link_Break').$msg_error_Link_Break;
171   
172
173 
174  $query = "
175    SELECT pwg.username as pwg_user, pwg.id as pwg_id, pwg.mail_address as pwg_mail, bb.id as bb_id, bb.username as bb_user, bb.email as bb_mail
176    FROM ".FluxBB_USERS_TABLE." AS bb
177    INNER JOIN ".Register_FluxBB_ID_TABLE." AS link ON link.id_user_FluxBB = bb.id
178        INNER JOIN ".USERS_TABLE." as pwg ON link.id_user_pwg = pwg.id
179    WHERE pwg.username <> bb.username
180  ;";
181  $result = pwg_query($query);
182 
183  while($row = mysql_fetch_array($result))
184  {
185    $msg_error_Link_Bad .= '<br/>'.l10n('Register_FluxBB_Error_Link_Del').$row['pwg_user'].' ('.$row['pwg_mail'].')'.' -- '.$row['bb_user'].' ('.$row['bb_mail'].')';
186
187    if ( !is_adviser() )
188    {
189      $msg_error_Link_Bad .= ' <a href="';
190 
191      $msg_error_Link_Bad .= add_url_params($page_Register_FluxBB_admin, array(
192        'action'   => 'link_del',
193        'pwg_id' => $row['pwg_id'],
194        'bb_id'  => $row['bb_id'],
195      ));
196      $msg_error_Link_Bad .= '" title="'.l10n('Register_FluxBB_Link_Del').$row['pwg_user'].' -- '.$row['bb_user'].'"';
197      $msg_error_Link_Bad .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
198      $msg_error_Link_Bad .= '><img src="'.Register_FluxBB_PATH.'/icon/link_delete.png" alt="'.l10n('Register_FluxBB_Link_Del').$row['pwg_user'].' -- '.$row['bb_user'].'" /></a>';
199
200      $msg_error_Link_Bad .= ' -- <a href="';
201
202      $msg_error_Link_Bad .= add_url_params($page_Register_FluxBB_admin, array(
203        'action' => 'sync_user',
204        'username' => $row['pwg_user'],
205      ));
206      $msg_error_Link_Bad .= '" title="'.l10n('Register_FluxBB_Sync_User').$row['pwg_user'].' --> '.$row['bb_user'].'"';
207      $msg_error_Link_Bad .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
208      $msg_error_Link_Bad .= '><img src="'.Register_FluxBB_PATH.'/icon/arrow_switch.png" alt="'.l10n('Register_FluxBB_Sync_User').$row['pwg_user'].' --> '.$row['bb_user'].'" /></a>';
209    }
210  }
211
212
213  $query = "
214    SELECT COUNT(*) as nbr_dead
215    FROM ".Register_FluxBB_ID_TABLE." AS Link
216    WHERE id_user_FluxBB NOT IN (
217      SELECT id
218      FROM ".FluxBB_USERS_TABLE."
219    )
220    OR id_user_pwg NOT IN (
221      SELECT id
222      FROM ".USERS_TABLE."
223    )
224  ;";
225  $Compteur = mysql_fetch_array(pwg_query($query));
226
227  if ( !empty($Compteur) and $Compteur['nbr_dead'] > 0)
228  { 
229    $msg_error_Link_Bad .= '<br/>'.l10n('Register_FluxBB_Error_Link_Dead').$Compteur['nbr_dead'];
230
231    if ( !is_adviser() )
232    {
233      $msg_error_Link_Bad .= ' <a href="';
234 
235      $msg_error_Link_Bad .= add_url_params($page_Register_FluxBB_admin, array(
236      'action'   => 'link_dead',
237      ));
238      $msg_error_Link_Bad .= '" title="'.l10n('Register_FluxBB_Link_Dead').$Compteur['nbr_dead'].'"';
239      $msg_error_Link_Bad .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
240      $msg_error_Link_Bad .= '><img src="'.Register_FluxBB_PATH.'/icon/link_delete.png" alt="'.l10n('Register_FluxBB_Link_Dead').$Compteur['nbr_dead'].'" /></a>';
241    }
242  }
243
244  $query = "
245    SELECT COUNT(*) AS nbr_dup, pwg.id AS pwg_id, pwg.username AS pwg_user, bb.username AS bb_user, bb.id AS bb_id
246    FROM ".FluxBB_USERS_TABLE." AS bb
247    INNER JOIN ".Register_FluxBB_ID_TABLE." AS link ON link.id_user_FluxBB = bb.id
248        INNER JOIN ".USERS_TABLE." as pwg ON link.id_user_pwg = pwg.id
249    GROUP BY link.id_user_pwg, link.id_user_FluxBB
250    HAVING COUNT(*) > 1
251  ;";
252  $result = pwg_query($query);
253 
254  while($row = mysql_fetch_array($result))
255  {
256    $msg_error_Link_Bad .= '<br/>'.l10n('Register_FluxBB_Error_Link_Dup').$row['nbr_dup'].' = '.$row['pwg_user'].' -- '.$row['bb_user'].')';
257
258    if ( !is_adviser() )
259    {
260      $msg_error_Link_Bad .= ' <a href="';
261
262      $msg_error_Link_Bad .= add_url_params($page_Register_FluxBB_admin, array(
263        'action'   => 'new_link',
264        'pwg_id' => $row['pwg_id'],
265        'bb_id' => $row['bb_id'],
266      ));
267      $msg_error_Link_Bad .= '" title="'.l10n('Register_FluxBB_Link_Dup').$row['pwg_user'].' -- '.$row['bb_user'].'"';
268      $msg_error_Link_Bad .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
269      $msg_error_Link_Bad .= '><img src="'.Register_FluxBB_PATH.'/icon/link_error.png" alt="'.l10n('Register_FluxBB_Link_Dup').$row['pwg_user'].' -- '.$row['bb_user'].'" /></a>';
270    }     
271  }
272
273  if ($msg_error_Link_Bad == '')
274    array_push($page['infos'], l10n('Register_FluxBB_Audit_Link_Bad').'<br/>'.l10n('Register_FluxBB_Audit_OK'));
275  else
276    $msg_error_Link_Bad = l10n('Register_FluxBB_Audit_Link_Bad').$msg_error_Link_Bad;
277   
278
279 
280  $query = "
281    SELECT pwg.username as username, pwg.password as pwg_pwd, pwg.mail_address as pwg_eml, FluxBB.password as bb_pwd, FluxBB.email as bb_eml
282    FROM ".FluxBB_USERS_TABLE." AS FluxBB
283    INNER JOIN ".Register_FluxBB_ID_TABLE." AS link ON link.id_user_FluxBB = FluxBB.id
284        INNER JOIN ".USERS_TABLE." as pwg ON link.id_user_pwg = pwg.id
285        AND BINARY pwg.username = BINARY FluxBB.username
286        ORDER BY LOWER(pwg.username)
287  ;";
288  $result = pwg_query($query);
289 
290  while($row = mysql_fetch_array($result))
291  {
292    if ( ($row['pwg_pwd'] != $row['bb_pwd']) or ($row['pwg_eml'] != $row['bb_eml']) )
293    {
294      $msg_error_Synchro .= '<br/>'.l10n('Register_FluxBB_Error_Synchro').$row['username'];
295
296      if ( !is_adviser() )
297      {
298        $msg_error_Synchro .= ' <a href="';
299 
300        $msg_error_Synchro .= add_url_params($page_Register_FluxBB_admin, array(
301          'action' => 'sync_user',
302          'username' => $row['username'],
303        ));
304        $msg_error_Synchro .= '" title="'.l10n('Register_FluxBB_Sync_User').$row['username'].'"';
305        $msg_error_Synchro .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
306        $msg_error_Synchro .= '><img src="'.Register_FluxBB_PATH.'/icon/user_refresh.png" alt="'.l10n('Register_FluxBB_Sync_User').$row['username'].'" /></a>';
307      }
308     
309      if ($row['pwg_pwd'] != $row['bb_pwd'])
310        $msg_error_Synchro .= '<br>'.l10n('Register_FluxBB_Error_Synchro_Pswd');
311     
312      if ($row['pwg_eml'] != $row['bb_eml'])
313        $msg_error_Synchro .= '<br>'.l10n('Register_FluxBB_Error_Synchro_Mail').'<br/>-- PWG = '.$row['pwg_eml'].'<br/>-- FluxBB = '.$row['bb_eml'];
314    }
315    else
316      if ( $conf_Register_FluxBB[5] == 'true')
317        $msg_ok_Synchro .= '<br/> - '.$row['username'].' ('.$row['pwg_eml'].')'.l10n('Register_FluxBB_Audit_Synchro_OK');
318  }
319
320  if ($msg_error_Synchro <> '')
321    $msg_error_Synchro = l10n('Register_FluxBB_Audit_Synchro').$msg_error_Synchro;
322   
323  if ($msg_ok_Synchro <> '')
324    if ($msg_error_Synchro <> '')
325      array_push($page['infos'], l10n('Register_FluxBB_Audit_Synchro').$msg_ok_Synchro.'<br/><br/>');
326    else
327      array_push($page['infos'], l10n('Register_FluxBB_Audit_Synchro').$msg_ok_Synchro.'<br/><br/>'.l10n('Register_FluxBB_Audit_OK'));
328
329
330  $query = "
331    SELECT username, mail_address FROM ".USERS_TABLE."
332    WHERE BINARY username <> BINARY 'guest'
333    AND id not in (
334      SELECT id_user_pwg FROM ".Register_FluxBB_ID_TABLE."
335    )
336    AND BINARY username not in (
337      SELECT username FROM ".FluxBB_USERS_TABLE."
338    )
339        ORDER BY LOWER(username)
340  ;";
341  $result = pwg_query($query);
342
343  while($row = mysql_fetch_array($result))
344  {
345    $msg_error_PWG2FluxBB .= '<br/>'.l10n('Register_FluxBB_Error_PWG2FluxBB').$row['username'].' ('.$row['mail_address'].')';
346
347    if ( !is_adviser() )
348    {
349      $msg_error_PWG2FluxBB .= ' <a href="';
350
351      $msg_error_PWG2FluxBB .= add_url_params($page_Register_FluxBB_admin, array(
352        'action' => 'add_user',
353        'username' => $row['username'],
354      ));
355      $msg_error_PWG2FluxBB .= '" title="'.l10n('Register_FluxBB_Add_User').$row['username'].'" ';
356      $msg_error_PWG2FluxBB .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
357      $msg_error_PWG2FluxBB .= '><img src="'.Register_FluxBB_PATH.'/icon/user_add.png" alt="'.l10n('Register_FluxBB_Add_User').$row['username'].'" /></a>';
358    }
359  }
360
361  if ($msg_error_PWG2FluxBB == '')
362    array_push($page['infos'], l10n('Register_FluxBB_Audit_PWG2FluxBB').'<br/>'.l10n('Register_FluxBB_Audit_OK'));
363  else
364    $msg_error_PWG2FluxBB = l10n('Register_FluxBB_Audit_PWG2FluxBB').$msg_error_PWG2FluxBB;
365
366 
367
368  $query = "
369    SELECT id, username, email FROM ".FluxBB_USERS_TABLE."
370    WHERE BINARY username <> BINARY '".$conf_Register_FluxBB[2]."'
371    AND id not in (
372      SELECT id_user_FluxBB FROM ".Register_FluxBB_ID_TABLE."
373    )
374    AND BINARY username not in (
375      SELECT username FROM ".USERS_TABLE."
376    )
377        ORDER BY LOWER(username)
378  ;";
379  $result = pwg_query($query);
380
381  while($row = mysql_fetch_array($result))
382  {
383    $msg_error_FluxBB2PWG .= '<br/>'.l10n('Register_FluxBB_Error_FluxBB2PWG').$row['username'].' ('.$row['email'].')';
384
385    if ( !is_adviser() )
386    {
387      $msg_error_FluxBB2PWG .= ' <a href="';
388   
389      $msg_error_FluxBB2PWG .= add_url_params($page_Register_FluxBB_admin, array(
390        'action' => 'del_user',
391        'id' => $row['id'],
392      ));
393      $msg_error_FluxBB2PWG .= '" title="'.l10n('Register_FluxBB_Del_User').$row['username'].'"';
394      $msg_error_FluxBB2PWG .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
395      $msg_error_FluxBB2PWG .= '><img src="'.Register_FluxBB_PATH.'/icon/user_delete.png" alt="'.l10n('Register_FluxBB_Del_User').$row['username'].'" /></a>';
396    }
397  }
398
399  if ($msg_error_FluxBB2PWG == '')
400    array_push($page['infos'], l10n('Register_FluxBB_Audit_FluxBB2PWG').'<br/>'.l10n('Register_FluxBB_Audit_OK'));
401  else
402    $msg_error_FluxBB2PWG = l10n('Register_FluxBB_Audit_FluxBB2PWG').$msg_error_FluxBB2PWG;
403
404
405
406  if ($msg_error_PWG_Dup <> '')
407    $errors[] = $msg_error_PWG_Dup . ( ($msg_error_FluxBB_Dup == '' and $msg_error_Link_Break == '' and $msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
408 
409  if ($msg_error_FluxBB_Dup <> '')
410    $errors[] = $msg_error_FluxBB_Dup . ( ($msg_error_Link_Break == '' and $msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
411
412  if ($msg_error_Link_Break <> '')
413    $errors[] = $msg_error_Link_Break . ( ($msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
414
415  if ($msg_error_Link_Bad <> '')
416    $errors[] = $msg_error_Link_Bad . ( ($msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
417
418  if ($msg_error_Synchro <> '')
419    $errors[] = $msg_error_Synchro . ( ($msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
420
421  if ($msg_error_PWG2FluxBB <> '')
422    $errors[] = $msg_error_PWG2FluxBB . ( ($msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
423
424  if ($msg_error_FluxBB2PWG <> '')
425    $errors[] = $msg_error_FluxBB2PWG;
426}
427
428
429
430
431// +-----------------------------------------------------------------------+
432// |                            Actions process
433// +-----------------------------------------------------------------------+
434
435if ( isset($_GET['action']) and ($_GET['action']=='link_dead') and !is_adviser() )
436{
437  $query = "
438                DELETE FROM ".Register_FluxBB_ID_TABLE."
439    WHERE id_user_FluxBB NOT IN (
440      SELECT id
441      FROM ".FluxBB_USERS_TABLE."
442    )
443    OR id_user_pwg NOT IN (
444      SELECT id
445      FROM ".USERS_TABLE."
446    )
447  ;";
448  $result = pwg_query($query);
449 
450  Audit_PWG_FluxBB();
451}
452else if ( isset($_GET['action']) and ($_GET['action']=='link_del') and isset($_GET['pwg_id']) and isset($_GET['bb_id']) and !is_adviser() )
453{
454  $query = "
455                DELETE FROM ".Register_FluxBB_ID_TABLE."
456                WHERE id_user_pwg = ".$_GET['pwg_id']."
457                AND id_user_FluxBB = ".$_GET['bb_id']."
458  ;";
459  $result = pwg_query($query);
460 
461  Audit_PWG_FluxBB();
462}
463else if ( isset($_GET['action']) and ($_GET['action']=='new_link') and isset($_GET['pwg_id']) and isset($_GET['bb_id']) and !is_adviser() )
464{
465  FluxBB_Linkuser($_GET['pwg_id'], $_GET['bb_id']);
466 
467  Audit_PWG_FluxBB();
468}
469else if ( isset($_GET['action']) and ($_GET['action']=='sync_user') and isset($_GET['username']) and !is_adviser() )
470{
471  $query = "
472    SELECT id AS id_pwg, username, password, mail_address
473        FROM ".USERS_TABLE."
474        WHERE BINARY username = BINARY '".$_GET['username']."'
475        LIMIT 1
476  ;";
477  $data = mysql_fetch_array(pwg_query($query));
478 
479  if (!empty($data))
480  {
481    FluxBB_Updateuser($data['id_pwg'], $data['username'], $data['password'], $data['mail_address']);
482  }
483 
484  Audit_PWG_FluxBB();
485}
486else if ( isset($_GET['action']) and ($_GET['action']=='add_user') and isset($_GET['username']) and !is_adviser() )
487{
488  $query = "
489    SELECT id, username, password, mail_address
490        FROM ".USERS_TABLE."
491        WHERE BINARY username = BINARY '".$_GET['username']."'
492        LIMIT 1
493  ;";
494  $data = mysql_fetch_array(pwg_query($query));
495 
496  if (!empty($data))
497    FluxBB_Adduser($data['id'], $data['username'], $data['password'], $data['mail_address']); 
498 
499  Audit_PWG_FluxBB();
500}
501else if ( isset($_GET['action']) and ($_GET['action']=='del_user') and isset($_GET['id']) and !is_adviser() )
502{
503  FluxBB_Deluser( $_GET['id'], true );
504 
505  Audit_PWG_FluxBB();
506}
507
508
509// +-----------------------------------------------------------------------+
510// |                            Tabssheet select                           |
511// +-----------------------------------------------------------------------+
512
513switch ($page['tab'])
514{
515        case 'info':
516 
517$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/info.tpl');
518$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
519
520        break;
521
522        case 'manage':
523 
524if ( isset($_POST['submit']) and !is_adviser() and isset($_POST['FluxBB_prefix']) and isset($_POST['FluxBB_admin']) and isset($_POST['FluxBB_guest']) 
525  and isset($_POST['FluxBB_del_pt']) and isset($_POST['FluxBB_confirm']) and isset($_POST['FluxBB_details']) )
526{
527  $conf['Register_FluxBB'] = $_POST['FluxBB_prefix'].';'.$_POST['FluxBB_admin'].';'.$_POST['FluxBB_guest'].';'.$_POST['FluxBB_del_pt'].';'.$_POST['FluxBB_confirm'].';'.$_POST['FluxBB_details'];
528
529  $query = '
530    UPDATE '.CONFIG_TABLE.'
531    SET value="'.$conf['Register_FluxBB'].'"
532    WHERE param="Register_FluxBB"
533    LIMIT 1
534  ;';
535  pwg_query($query);
536
537  array_push($page['infos'], l10n('Register_FluxBB_save_config'));
538}
539
540$conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
541
542$template->assign(array(
543    'FluxBB_PREFIX'           => $conf_Register_FluxBB[0],
544    'FluxBB_ADMIN'            => $conf_Register_FluxBB[1],
545    'FluxBB_GUEST'            => $conf_Register_FluxBB[2],
546    'FluxBB_DEL_PT_TRUE'      => (isset($conf_Register_FluxBB[3]) and $conf_Register_FluxBB[3] == 'true') ? 'checked="checked"' : '' ,
547    'FluxBB_DEL_PT_FALSE'     => (isset($conf_Register_FluxBB[3]) and $conf_Register_FluxBB[3] == 'false') ? 'checked="checked"' : '' ,
548    'FluxBB_CONFIRM_TRUE'     => (isset($conf_Register_FluxBB[4]) and $conf_Register_FluxBB[4] == 'true') ? 'checked="checked"' : '' ,
549    'FluxBB_CONFIRM_FALSE'    => (isset($conf_Register_FluxBB[4]) and $conf_Register_FluxBB[4] == 'false') ? 'checked="checked"' : '' ,
550    'FluxBB_DETAILS_TRUE'     => (isset($conf_Register_FluxBB[5]) and $conf_Register_FluxBB[5] == 'true') ? 'checked="checked"' : '' ,
551    'FluxBB_DETAILS_FALSE'    => (isset($conf_Register_FluxBB[5]) and $conf_Register_FluxBB[5] == 'false') ? 'checked="checked"' : '' ,
552  )
553);
554
555
556$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/manage.tpl');
557$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
558
559        break;
560
561        case 'Migration':
562       
563if ( isset($_POST['Migration']) and !is_adviser() )
564{
565  array_push($page['infos'], l10n('Register_FluxBB_Mig_Start').'<br/><br/>');
566 
567 
568  array_push($page['infos'], l10n('Register_FluxBB_Mig_Del_Link').'<br/><br/>');
569
570  $query = "TRUNCATE ".Register_FluxBB_ID_TABLE.";";
571  $result = pwg_query($query);
572 
573 
574  $msg_Mig_Del_AllUsers = '';
575
576  $query = "
577    SELECT username, id
578    FROM ".FluxBB_USERS_TABLE."
579  ;";
580  $result = pwg_query($query);
581 
582  while ($row = mysql_fetch_array($result))
583  {
584    if(($row['username'] != $conf_Register_FluxBB[2]) and ($row['username'] != $conf_Register_FluxBB[1]) )
585    {
586      $msg_Mig_Del_AllUsers .= '<br/> - '.l10n('Register_FluxBB_Mig_Del_User').$row['username'];
587       
588      FluxBB_Deluser($row['id'], false);
589    }
590  }
591
592  array_push($page['infos'], l10n('Register_FluxBB_Mig_Del_AllUsers').$msg_Mig_Del_AllUsers.'<br/><br/>');
593
594
595  $query = "
596    SELECT id, username, password, mail_address
597    FROM ".USERS_TABLE."
598  ;";
599  $result = pwg_query($query);
600 
601  $registred = time();
602  $registred_ip = $_SERVER['REMOTE_ADDR'];
603 
604  $msg_Mig_Add_AllUsers = '';
605 
606  while ($row = mysql_fetch_array($result))
607  {
608    if(($row['username'] != 'guest') and ($row['username'] != $conf_Register_FluxBB[1]) )
609    {
610      $msg_Mig_Add_AllUsers .= '<br/> - '.l10n('Register_FluxBB_Mig_Add_User').$row['username'];
611
612      FluxBB_Adduser($row['id'], $row['username'], $row['password'], $row['mail_address']);
613    }
614  }
615
616  array_push($page['infos'], l10n('Register_FluxBB_Mig_Add_AllUsers').$msg_Mig_Add_AllUsers.'<br/><br/>');
617
618
619  $query = "
620    SELECT id, username, password, mail_address
621    FROM ".USERS_TABLE."
622    WHERE username = '".$conf_Register_FluxBB[1]."'
623  ;";
624  $row = mysql_fetch_array(pwg_query($query));
625 
626  if (!empty($row))
627  {
628    array_push($page['infos'], l10n('Register_FluxBB_Sync_User').$row['username'].'<br/><br/>');
629     
630    FluxBB_Updateuser($row['id'], $row['username'], $row['password'], $row['mail_address']);
631  }
632
633  array_push($page['infos'], l10n('Register_FluxBB_Mig_End'));
634}
635else if ( isset($_POST['Audit']))
636{
637  Audit_PWG_FluxBB();
638}
639
640$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/migration.tpl');
641$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
642
643        break;
644 
645        case 'Synchro':
646 
647if ( isset($_POST['Synchro']) and !is_adviser() )
648{
649  global $page,$conf, $errors;
650
651  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
652
653  $page_Register_FluxBB_admin = get_admin_plugin_menu_link(__FILE__);
654 
655
656
657  $msg_error_PWG_Dup = '';
658  $msg_error_FluxBB_Dup = '';
659  $msg_error_Link_Break = '';
660  $msg_error_Link_Bad = '';
661  $msg_error_Synchro = '';
662  $msg_ok_Synchro = '';
663  $msg_error_FluxBB2PWG = '';
664  $msg_error_PWG2FluxBB = '';
665
666
667
668  $query = "
669    SELECT COUNT(*) AS nbr_dup, id, username
670    FROM ".USERS_TABLE."
671    GROUP BY BINARY username
672    HAVING COUNT(*) > 1
673  ;";
674  $result = pwg_query($query);
675 
676  while($row = mysql_fetch_array($result))
677    $msg_error_PWG_Dup .= '<br/>'.l10n('Register_FluxBB_Error_PWG_Dup').$row['nbr_dup'].' x '.$row['username'];
678
679  if ($msg_error_PWG_Dup <> '')
680    $msg_error_PWG_Dup = l10n('Register_FluxBB_Audit_PWG_Dup').$msg_error_PWG_Dup.'<br>'.l10n('Register_FluxBB_Advise_PWG_Dup');
681 
682
683
684  $query = "
685    SELECT COUNT(*) AS nbr_dup, username
686    FROM ".FluxBB_USERS_TABLE."
687    GROUP BY BINARY username
688    HAVING COUNT(*) > 1
689  ;";
690  $result = pwg_query($query);
691 
692  while($row = mysql_fetch_array($result))
693  {
694    $msg_error_FluxBB_Dup .= '<br/>'.l10n('Register_FluxBB_Error_FluxBB_Dup').$row['nbr_dup'].' x '.$row['username'];
695
696    $subquery = "
697      SELECT id, username, email
698      FROM ".FluxBB_USERS_TABLE."
699      WHERE BINARY username = BINARY '".$row['username']."'
700    ;";
701    $subresult = pwg_query($subquery);
702 
703    while($subrow = mysql_fetch_array($subresult))
704    {
705      $msg_error_FluxBB_Dup .= '<br/>id:'.$subrow['id'].'='.$subrow['username'].' ('.$subrow['email'].')';
706 
707      if ( !is_adviser() )
708      {
709        $msg_error_FluxBB_Dup .= ' <a href="';
710     
711        $msg_error_FluxBB_Dup .= add_url_params($page_Register_FluxBB_admin, array(
712          'action' => 'del_user',
713          'id' => $subrow['id'],
714        ));
715        $msg_error_FluxBB_Dup .= '" title="'.l10n('Register_FluxBB_Del_User').$subrow['username'].'"';
716        $msg_error_FluxBB_Dup .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
717        $msg_error_FluxBB_Dup .= '><img src="'.Register_FluxBB_PATH.'/icon/user_delete.png" alt="'.l10n('Register_FluxBB_Del_User').$subrow['username'].'" /></a>';
718      }
719    }
720  }
721
722  if ($msg_error_FluxBB_Dup <> '')
723    $msg_error_FluxBB_Dup = l10n('Register_FluxBB_Sync_Check_Dup').$msg_error_FluxBB_Dup.'<br>'.l10n('Register_FluxBB_Advise_FluxBB_Dup');
724
725 
726
727  if ($msg_error_FluxBB_Dup == '' and $msg_error_PWG_Dup == '')
728  {
729    $query = "
730      SELECT pwg.id as pwg_id, bb.id as bb_id, pwg.username as pwg_user, pwg.mail_address as pwg_mail
731      FROM ".FluxBB_USERS_TABLE." AS bb, ".USERS_TABLE." as pwg
732      WHERE bb.id NOT in (
733        SELECT id_user_FluxBB
734        FROM ".Register_FluxBB_ID_TABLE."
735      )
736      AND pwg.id NOT in (
737        SELECT id_user_pwg
738        FROM ".Register_FluxBB_ID_TABLE."
739      )
740      AND pwg.username = bb.username
741      AND pwg.mail_address = bb.email
742    ;";
743    $result = pwg_query($query);
744   
745    while($row = mysql_fetch_array($result))
746    {
747      $msg_error_Link_Break .= '<br/>'.l10n('Register_FluxBB_New_Link').$row['pwg_user'].' ('.$row['pwg_mail'].')';
748 
749      FluxBB_Linkuser($row['pwg_id'], $row['bb_id']);
750    }
751 
752    if ($msg_error_Link_Break == '')
753      array_push($page['infos'], l10n('Register_FluxBB_Sync_Link_Break').'<br/>'.l10n('Register_FluxBB_Sync_OK'));
754    else
755      $msg_error_Link_Break = l10n('Register_FluxBB_Sync_Link_Break').$msg_error_Link_Break;
756
757 
758   
759    $query = "
760      SELECT pwg.username as pwg_user, pwg.id as pwg_id, pwg.mail_address as pwg_mail, bb.id as bb_id, bb.username as bb_user, bb.email as bb_mail
761      FROM ".FluxBB_USERS_TABLE." AS bb
762      INNER JOIN ".Register_FluxBB_ID_TABLE." AS link ON link.id_user_FluxBB = bb.id
763        INNER JOIN ".USERS_TABLE." as pwg ON link.id_user_pwg = pwg.id
764      WHERE BINARY pwg.username <> BINARY bb.username
765    ;";
766    $result = pwg_query($query);
767   
768    while($row = mysql_fetch_array($result))
769    {
770      $msg_error_Link_Bad .= '<br/>'.l10n('Register_FluxBB_Link_Del').$row['pwg_user'].' ('.$row['pwg_mail'].')'.' -- '.$row['bb_user'].' ('.$row['bb_mail'].')';
771
772      $subquery = "
773                DELETE FROM ".Register_FluxBB_ID_TABLE."
774                WHERE id_user_pwg = ".$row['pwg_id']."
775                AND id_user_FluxBB = ".$row['bb_id']."
776      ;";
777      $subresult = pwg_query($subquery);
778    }
779
780
781    $query = "
782      SELECT COUNT(*) as nbr_dead
783      FROM ".Register_FluxBB_ID_TABLE." AS Link
784      WHERE id_user_FluxBB NOT IN (
785        SELECT id
786        FROM ".FluxBB_USERS_TABLE."
787      )
788      OR id_user_pwg NOT IN (
789        SELECT id
790        FROM ".USERS_TABLE."
791      )
792    ;";
793    $Compteur = mysql_fetch_array(pwg_query($query));
794   
795    if ( !empty($Compteur) and $Compteur['nbr_dead'] > 0)
796    { 
797      $msg_error_Link_Bad .= '<br/>'.l10n('Register_FluxBB_Link_Dead').$Compteur['nbr_dead'];
798   
799      $query = "
800                DELETE FROM ".Register_FluxBB_ID_TABLE."
801        WHERE id_user_FluxBB NOT IN (
802          SELECT id
803          FROM ".FluxBB_USERS_TABLE."
804        )
805        OR id_user_pwg NOT IN (
806          SELECT id
807          FROM ".USERS_TABLE."
808        )
809      ;";
810      $result = pwg_query($query);
811    }
812   
813     
814    $query = "
815      SELECT COUNT(*) AS nbr_dup, pwg.id AS pwg_id, pwg.username AS pwg_user, bb.username AS bb_user, bb.id AS bb_id
816      FROM ".FluxBB_USERS_TABLE." AS bb
817      INNER JOIN ".Register_FluxBB_ID_TABLE." AS link ON link.id_user_FluxBB = bb.id
818        INNER JOIN ".USERS_TABLE." as pwg ON link.id_user_pwg = pwg.id
819      GROUP BY link.id_user_pwg, link.id_user_FluxBB
820      HAVING COUNT(*) > 1
821    ;";
822    $result = pwg_query($query);
823   
824    while($row = mysql_fetch_array($result))
825    {
826      $msg_error_Link_Bad .= '<br/>'.l10n('Register_FluxBB_Link_Dup').$row['nbr_dup'].' = '.$row['pwg_user'].' -- '.$row['bb_user'].')';
827 
828      FluxBB_Linkuser($row['pwg_id'], $row['bb_id']);
829    }
830
831    if ($msg_error_Link_Bad == '')
832      array_push($page['infos'], l10n('Register_FluxBB_Sync_Link_Bad').'<br/>'.l10n('Register_FluxBB_Sync_OK'));
833    else
834      $msg_error_Link_Bad = l10n('Register_FluxBB_Sync_Link_Bad').$msg_error_Link_Bad;
835     
836 
837   
838    $query = "
839      SELECT pwg.id as pwg_id, pwg.username as username, pwg.password as pwg_pwd, pwg.mail_address as pwg_eml, FluxBB.id as bb_id, FluxBB.password as bb_pwd, FluxBB.email as bb_eml
840      FROM ".FluxBB_USERS_TABLE." AS FluxBB
841      INNER JOIN ".Register_FluxBB_ID_TABLE." AS link ON link.id_user_FluxBB = FluxBB.id
842        INNER JOIN ".USERS_TABLE." as pwg ON link.id_user_pwg = pwg.id
843        AND BINARY pwg.username = BINARY FluxBB.username
844        ORDER BY LOWER(pwg.username)
845    ;";
846    $result = pwg_query($query);
847   
848    while($row = mysql_fetch_array($result))
849    {
850      if ( ($row['pwg_pwd'] != $row['bb_pwd']) or ($row['pwg_eml'] != $row['bb_eml']) )
851      {
852        $msg_error_Synchro .= '<br/>'.l10n('Register_FluxBB_Sync_User').$row['username'];
853 
854        $query = "
855          SELECT id, username, password, mail_address
856                FROM ".USERS_TABLE."
857                WHERE BINARY id = '".$row['pwg_id']."'
858        ;";
859        $data = mysql_fetch_array(pwg_query($query));
860       
861        if (!empty($data))
862          FluxBB_Updateuser($data['id'], $data['username'], $data['password'], $data['mail_address']);
863      }
864    }
865 
866    if ($msg_error_Synchro == '')
867      array_push($page['infos'], l10n('Register_FluxBB_Sync_DataUser').'<br/>'.l10n('Register_FluxBB_Sync_OK'));
868    else
869      $msg_error_Synchro = l10n('Register_FluxBB_Sync_DataUser').$msg_error_Synchro;
870
871 
872 
873    $query = "
874      SELECT username, mail_address FROM ".USERS_TABLE."
875      WHERE BINARY username <> BINARY 'guest'
876      AND id not in (
877        SELECT id_user_pwg FROM ".Register_FluxBB_ID_TABLE."
878      )
879      AND BINARY username not in (
880        SELECT username FROM ".FluxBB_USERS_TABLE."
881      )
882        ORDER BY LOWER(username)
883    ;";
884    $result = pwg_query($query);
885 
886    while($row = mysql_fetch_array($result))
887    {
888      $msg_error_PWG2FluxBB .= '<br/>'.l10n('Register_FluxBB_Add_User').$row['username'].' ('.$row['mail_address'].')';
889
890      $query = "
891        SELECT id, username, password, mail_address
892        FROM ".USERS_TABLE."
893        WHERE BINARY username = BINARY '".$row['username']."'
894        LIMIT 1
895      ;";
896      $data = mysql_fetch_array(pwg_query($query));
897     
898      if (!empty($data))
899        FluxBB_Adduser($data['id'], $data['username'], $data['password'], $data['mail_address']); 
900    }
901 
902    if ($msg_error_PWG2FluxBB == '')
903      array_push($page['infos'], l10n('Register_FluxBB_Sync_PWG2FluxBB').'<br/>'.l10n('Register_FluxBB_Sync_OK'));
904    else
905      $msg_error_PWG2FluxBB = l10n('Register_FluxBB_Sync_PWG2FluxBB').$msg_error_PWG2FluxBB;
906 
907   
908 
909    $query = "
910      SELECT id, username, email FROM ".FluxBB_USERS_TABLE."
911      WHERE BINARY username <> BINARY '".$conf_Register_FluxBB[2]."'
912      AND id not in (
913        SELECT id_user_FluxBB FROM ".Register_FluxBB_ID_TABLE."
914      )
915      AND BINARY username not in (
916        SELECT username FROM ".USERS_TABLE."
917      )
918        ORDER BY LOWER(username)
919    ;";
920    $result = pwg_query($query);
921 
922    while($row = mysql_fetch_array($result))
923    {
924      $msg_error_FluxBB2PWG .= '<br/>'.l10n('Register_FluxBB_Error_FluxBB2PWG').$row['username'].' ('.$row['email'].')';
925 
926      if ( !is_adviser() )
927      {
928        $msg_error_FluxBB2PWG .= ' <a href="';
929     
930        $msg_error_FluxBB2PWG .= add_url_params($page_Register_FluxBB_admin, array(
931          'action' => 'del_user',
932          'id' => $row['id'],
933        ));
934        $msg_error_FluxBB2PWG .= '" title="'.l10n('Register_FluxBB_Del_User').$row['username'].'"';
935        $msg_error_FluxBB2PWG .= $conf_Register_FluxBB[4]=='false' ?  ' onclick="return confirm(\''.l10n('Are you sure?').'\');" ' : ' ';
936        $msg_error_FluxBB2PWG .= '><img src="'.Register_FluxBB_PATH.'/icon/user_delete.png" alt="'.l10n('Register_FluxBB_Del_User').$row['username'].'" /></a>';
937      }
938    }
939 
940    if ($msg_error_FluxBB2PWG == '')
941      array_push($page['infos'], l10n('Register_FluxBB_Sync_FluxBB2PWG').'<br/>'.l10n('Register_FluxBB_Sync_OK'));
942    else
943      $msg_error_FluxBB2PWG = l10n('Register_FluxBB_Sync_FluxBB2PWG').$msg_error_FluxBB2PWG;
944  }
945  else
946    $errors[] = l10n('Register_FluxBB_Advise_Check_Dup');
947
948
949
950  if ($msg_error_PWG_Dup <> '')
951    $errors[] = $msg_error_PWG_Dup . ( ($msg_error_FluxBB_Dup == '' and $msg_error_Link_Break == '' and $msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
952 
953  if ($msg_error_FluxBB_Dup <> '')
954    $errors[] = $msg_error_FluxBB_Dup . ( ($msg_error_Link_Break == '' and $msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
955
956  if ($msg_error_Link_Break <> '')
957    $errors[] = $msg_error_Link_Break . ( ($msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
958
959  if ($msg_error_Link_Bad <> '')
960    $errors[] = $msg_error_Link_Bad . ( ($msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
961
962  if ($msg_error_Synchro <> '')
963    $errors[] = $msg_error_Synchro . ( ($msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
964
965  if ($msg_error_PWG2FluxBB <> '')
966    $errors[] = $msg_error_PWG2FluxBB . ( ($msg_error_FluxBB2PWG == '') ? '' : '<br/><br/>' );
967
968  if ($msg_error_FluxBB2PWG <> '')
969    $errors[] = $msg_error_FluxBB2PWG;
970}
971else if ( isset($_POST['Audit']))
972{
973  Audit_PWG_FluxBB();
974}
975
976$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/synchro.tpl');
977$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');     
978
979        break;
980}
981
982?>
Note: See TracBrowser for help on using the repository browser.