repair_users.php 9.83 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
4
5
6
7
<?php

$topdir="../";

require_once($topdir. "include/site.inc.php");
$site = new site();

Ayolo's avatar
Ayolo committed
8
$site->start_page("","Réparation de la base utilisateur");
Ayolo's avatar
Ayolo committed
9

10
$echec="";
Ayolo's avatar
Ayolo committed
11
12
13
if(isset($_POST["action"]) && $_POST["action"]=="merge")
{
  $_id=0;
Ayolo's avatar
Ayolo committed
14
15
16
17
18
19
  if(isset($_POST["ids"]))
    $ids=$_POST["ids"];
  elseif(isset($_POST["magicform"]))
    $ids=$_POST["magicform"]["boolean"];
  else
    $ids=null;
Ayolo's avatar
Ayolo committed
20
21
  if(count($ids) >1)
  {
22
23
24
25
26
27
    $ae=false;
    $utbm=false;
    $user = new utilisateur($site->db,$site->dbrw);
    foreach($ids as $id => $value)
    {
      $user->load_by_id($id);
Ayolo's avatar
bleh    
Ayolo committed
28
      $user->load_all_extra();
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
      if($user->ae && $user->utbm)
      {
        $_id=$user->id;
        break;
      }
      elseif($user->ae)
        $ae=true;
      elseif($user->utbm)
        $utbm=true;
    }
    if($_id==0 && ($ae||$utbm))
    {
      foreach($ids as $id => $value)
      {
        $user->load_by_id($id);
Ayolo's avatar
bleh    
Ayolo committed
44
        $user->load_all_extra();
45
46
47
48
49
50
51
52
53
54
55
56
        if($ae && !$utbm && $user->ae)
        {
          $_id=$user->id;
          break;
        }
        elseif(!$ae && $utbm && $user->utbm)
        {
          $_id=$user->id;
          break;
        }
      }
    }
Ayolo's avatar
Ayolo committed
57
58
59
60
    foreach($ids as $id => $value)
    {
      if($_id==0)
      {
Ayolo's avatar
Ayolo committed
61
        $user->load_by_id($id);
Ayolo's avatar
bleh    
Ayolo committed
62
        $user->load_all_extra();
Ayolo's avatar
Ayolo committed
63
64
        $_id=$id;
      }
65
66
      elseif($_id==$id)
        continue;
Ayolo's avatar
Ayolo committed
67
68
69
      else
      {
        /* on merge tout vers $_id */
Ayolo's avatar
Ayolo committed
70
71
72
        $user2 = new utilisateur($site->db,$site->dbrw);
        $user2->load_by_id($id);
        /* on merge les infos utilisateur */
73
74
75
        //email
        //$user->set_email($email);
        //$user->set_email_utbm($email);
76
77
        if(!$user->utbm && $user2->utbm)
        {
78
79
80
81
          if($user2->email_utbm)
            $email==$user2->email_utbm;
          else
            $email==$user2->email;
82
          $user->became_utbm($email,true);
83
          $user->became_etudiant( $user2->nom_ecole_etudiant, $user2->ancien_etudiant, true);
84
85
        }
        if(!$user->etudiant && $user2->etudiant)
Ayolo's avatar
bleh    
Ayolo committed
86
          $user->became_etudiant( $user2->nom_ecole_etudiant, $user2->ancien_etudiant, true);
87
88
89
90
91
92
93
94
95
96
        //sexe
        if($user->sexe < $user2->sexe)
          $user->sexe=2;
        //date_naissance
        if($user->date_naissance == strtotime("1970-01-01"))
          $user->date_naissance=$user2->date_naissance;
        // else comment je fais moi ???
        //droit_image(true or false)
        $user->droit_image=true;
        //publique
97
        $user->publique=1; //nazi :P
98
99
100
        //publique_mmtpapier
        $user->publique_mmtpapier=true; //nazi aussi :P
        //signature_utl
Ayolo's avatar
bleh    
Ayolo committed
101
        $user->signalure_utl="l'AE c'est bien";
102

Ayolo's avatar
bleh    
Ayolo committed
103
        $user->montant_compte=$user->montant_compte+$user2->montant_compte;
104
105
        // on sauvegarde
        $user->saveinfos();
Ayolo's avatar
Ayolo committed
106
107
108

        /* on déplace les photos matmat */

Ayolo's avatar
bleh    
Ayolo committed
109
110
        /* avatar forum */
        $_photo =  "/var/www/ae/www/var/matmatronch/" . $id . ".jpg";
111
        if(file_exists($_photo))
Ayolo's avatar
bleh    
Ayolo committed
112
          @unlink($_photo);
113

Ayolo's avatar
bleh    
Ayolo committed
114
115
        /* photo mmt */
        $_photo =  "/var/www/ae/www/var/matmatronch/" . $id . ".identity.jpg";
116
        $photo = "/var/www/ae/www/var/matmatronch/" . $_id . ".identity.jpg";
Ayolo's avatar
bleh    
Ayolo committed
117
        $_identityi =  "/var/www/ae/www/var/matmatronch/" . $id . ".identity.i.jpg";
118
119
120
121
122
123
        $identityi = "/var/www/ae/www/var/matmatronch/" . $_id . ".identity.i.jpg";
        if(!file_exists($photo) && file_exists($_photo))
        {
          @copy($_photo, $photo);
          @copy($_identityi, $identityi);
        }
124
        if(file_exists($_photo))
Ayolo's avatar
bleh    
Ayolo committed
125
126
127
128
        {
          @unlink($_photo);
          @unlink($_identityi);
        }
129

Ayolo's avatar
bleh    
Ayolo committed
130
131
132
        /* blouse */
        $_photo =  "/var/www/ae/www/var/matmatronch/" . $id . ".blouse.jpg";
        $_blousemini =  "/var/www/ae/www/var/matmatronch/" . $id . ".blouse.mini.jpg";
133
        if(file_exists($_photo))
Ayolo's avatar
bleh    
Ayolo committed
134
135
136
137
        {
          @unlink($_photo);
          @unlink($_blousemini);
        }
pedrov's avatar
pedrov committed
138

Ayolo's avatar
Ayolo committed
139
        /* on vérifie les cotises */
Ayolo's avatar
bleh    
Ayolo committed
140
141
        /* en bougeant les "cotises" on bouge les carte */
        /* TODO : vérifier qu'il n'existe qu'une carte */
142
143
        if($user2->ae)
          $echec.="$user2->id => vérifier les cotisations\n";
144
145
        /*new update($site->dbrw,
                   "ae_cotisations",
Ayolo's avatar
bleh    
Ayolo committed
146
                   array('id_utilisateur' => $_id),
147
                   array('id_utilisateur'  => $id));//, true);*/
Ayolo's avatar
Ayolo committed
148
149
150

        /* on vérifie les photos */

Ayolo's avatar
bleh    
Ayolo committed
151
        /* on vérifie le forum */
152
153
        new update($site->dbrw,
                   "frm_message",
Ayolo's avatar
bleh    
Ayolo committed
154
155
                   array('id_utilisateur' => $_id),
                   array('id_utilisateur'  => $id));//, true);
Ayolo's avatar
bleh    
Ayolo committed
156
157
158
159
160
161
162
163
164
165
        new update($site->dbrw,
                   "frm_forum",
                   array('id_utilisateur' => $_id),
                   array('id_utilisateur'  => $id));
        new update($site->dbrw,
                   "frm_sujet",
                   array('id_utilisateur' => $_id),
                   array('id_utilisateur'  => $id));
        new update($site->dbrw,
                   "frm_sujet",
166
                   array('id_utilisateur_moderateur' => $_id),
Ayolo's avatar
bleh    
Ayolo committed
167
168
169
170
171
172
173
174
                   array('id_utilisateur_moderateur'  => $id));
        new update($site->dbrw,
                   "frm_sujet_utilisateur",
                   array('id_utilisateur' => $_id),
                   array('id_utilisateur'  => $id));
        new delete($site->dbrw,
                   "frm_sujet_utilisateur",
                   array('id_utilisateur'  => $id));
175

pedrov's avatar
pedrov committed
176

Ayolo's avatar
Ayolo committed
177
178

        /* on vérifie les emprunts matériel */
179
180
        new update($site->dbrw,
                   "inv_emprunt",
Ayolo's avatar
bleh    
Ayolo committed
181
182
                   array('id_utilisateur' => $_id),
                   array('id_utilisateur'  => $id));//, true);
Ayolo's avatar
Ayolo committed
183
184

        /* on vérifie les réservations de salles */
185
186
        new update($site->dbrw,
                   "sl_reservation",
Ayolo's avatar
bleh    
Ayolo committed
187
188
                   array('id_utilisateur' => $_id),
                   array('id_utilisateur'  => $id));//, true);
189

Ayolo's avatar
Ayolo committed
190
        /* on vérifie les asso */
Ayolo's avatar
bleh    
Ayolo committed
191
192
193
194
        new update($site->dbrw,
                   "asso_membre",
                   array('id_utilisateur' => $_id),
                   array('id_utilisateur' => $id));
195

Ayolo's avatar
Ayolo committed
196
        /* on vérifie les groupes */
Ayolo's avatar
bleh    
Ayolo committed
197
198
199
200
201
        /*
          is_in_group_id();
          add_to_group();
        */

Ayolo's avatar
Ayolo committed
202
203
204
205
206
207
208
209

        /* on vérifie les planings */

        /* on vérifie les sondages */

        /* on vérifie les votes */

        /* on vérifie les factures */
Ayolo's avatar
bleh    
Ayolo committed
210
211
212
213
214
215
        new update($site->dbrw,"cpt_rechargements",array('id_utilisateur' => $_id),array('id_utilisateur' => $id));
        new update($site->dbrw,"cpt_rechargements",array('id_utilisateur_operateur' => $_id),array('id_utilisateur_operateur' => $id));
        new update($site->dbrw,"cpt_debitfacture",array('id_utilisateur' => $_id),array('id_utilisateur' => $id));
        new update($site->dbrw,"cpt_debitfacture",array('id_utilisateur_client' => $_id),array('id_utilisateur_client' => $id));
        new update($site->dbrw,"cpt_rechargements",array('id_utilisateur' => $_id),array('id_utilisateur' => $id));

Ayolo's avatar
Ayolo committed
216
217
218

        /* on vérifie les cartes ae et la lettre clé */

Ayolo's avatar
bleh    
Ayolo committed
219
220
        /* on vérifie les edt */

Ayolo's avatar
bleh    
Ayolo committed
221
        /* on supprimme le doublon */
222
223
224
225
226
227
228
        new delete($site->dbrw,"utilisateurs",array("id_utilisateur" => $id));
        new delete($site->dbrw,"utl_etu",array("id_utilisateur" => $id));
        new delete($site->dbrw,"utl_etu_utbm",array("id_utilisateur" => $id));
        new delete($site->dbrw,"utl_extra",array("id_utilisateur" => $id));
        new delete($site->dbrw,"utl_groupe",array("id_utilisateur" => $id));
        new delete($site->dbrw,"utl_joue_instru",array("id_utilisateur" => $id));
        new delete($site->dbrw,"utl_parametres",array("id_utilisateur" => $id));
Ayolo's avatar
bleh    
Ayolo committed
229

Ayolo's avatar
Ayolo committed
230
        /* on reset le mot de passe */
231

Ayolo's avatar
Ayolo committed
232
233
      }
    }
234
235
236
237
    $pass = genere_pass(10);
    $user->send_autopassword_email($_REQUEST["email"],$pass);
    $user->invalidate();
    $user->change_password($pass);
Ayolo's avatar
Ayolo committed
238
239
240
  }
}

241
if(!empty($echec))
pedrov's avatar
pedrov committed
242
{
243
244
245
  $cts = new contents("y'a eu des merdes");
  $cts->add_paragraph($echec);
  $site->add_contents($cts);
pedrov's avatar
pedrov committed
246
247
}

Ayolo's avatar
Ayolo committed
248
249
250
251
252
253
254
$sql = new requete($site->db,"SELECT * FROM `utilisateurs`");

while ( $row = $sql->get_row() )
{
  if(!isset($names[$row['nom_utl']]))
  {
    $names[$row['nom_utl']]=array();
Ayolo's avatar
Ayolo committed
255
256
    $names[$row['nom_utl']][$row['prenom_utl']]=array();
    $names[$row['nom_utl']][$row['prenom_utl']][]=$row['id_utilisateur'];
Ayolo's avatar
Ayolo committed
257
258
259
  }
  else
  {
Ayolo's avatar
Ayolo committed
260
    if(!isset($names[$row['nom_utl']][$row['prenom_utl']]))
Ayolo's avatar
Ayolo committed
261
262
263
264
    {
      $names[$row['nom_utl']][$row['prenom_utl']]=array();
      $names[$row['nom_utl']][$row['prenom_utl']][]=$row['id_utilisateur'];
    }
Ayolo's avatar
Ayolo committed
265
    else
Ayolo's avatar
Ayolo committed
266
      $names[$row['nom_utl']][$row['prenom_utl']][]=$row['id_utilisateur'];
Ayolo's avatar
Ayolo committed
267
268
269
  }
}

Ayolo's avatar
Ayolo committed
270
$cts = new contents("Gestion des doublons");
Ayolo's avatar
bleh    
Ayolo committed
271
$num=0;
Ayolo's avatar
Ayolo committed
272
273
foreach($names as $name => $firstnames)
{
Ayolo's avatar
Ayolo committed
274
  foreach($firstnames as $firstname => $ids)
Ayolo's avatar
bleh    
Ayolo committed
275
  {
Ayolo's avatar
Ayolo committed
276
    if(count($ids)>1)
Ayolo's avatar
Ayolo committed
277
    {
Ayolo's avatar
bleh    
Ayolo committed
278
      $num++;
Ayolo's avatar
Ayolo committed
279
      if(count($ids)==2)
Ayolo's avatar
Ayolo committed
280
      {
Ayolo's avatar
bleh    
Ayolo committed
281
        $frm = new form("discard","repair_users.php",true,"POST",$num." - ".$name." ".$firstname);
Ayolo's avatar
Ayolo committed
282
283
        $frm->add_info("Faut il merger les fiches suivantes :<br />");
        $frm->add_info("<ul>");
Ayolo's avatar
Ayolo committed
284
285
        $frm->add_info("<li><a href='../user.php?id_utilisateur=".$ids[0]."'>".$ids[0]."</a></li>");
        $frm->add_info("<li><a href='../user.php?id_utilisateur=".$ids[1]."'>".$ids[1]."</a></li>");
Ayolo's avatar
Ayolo committed
286
287
288
        $frm->add_info("</ul>");
        $frm->add_info("");
        $frm->add_hidden("action","merge");
Ayolo's avatar
Ayolo committed
289
290
        $frm->add_hidden("ids[".$ids[0]."]",$ids[0]);
        $frm->add_hidden("ids[".$ids[1]."]",$ids[1]);
Ayolo's avatar
Ayolo committed
291
292
293
294
295
        $frm->add_submit("save","Merger");
        $cts->add($frm,true);
      }
      else
      {
Ayolo's avatar
bleh    
Ayolo committed
296
        $frm = new form("discard","repair_users.php",true,"POST",$num." - ".$name." ".$firstname);
Ayolo's avatar
Ayolo committed
297
298
        $frm->add_info("Faut il merger les fiches suivantes :<br />");
        for ($i=0; $i<count($ids); $i++)
Ayolo's avatar
Ayolo committed
299
          $frm->add_checkbox( $ids[$i],"<a href='../user.php?id_utilisateur=".$ids[$i]."'>".$ids[$i]."</a>");
Ayolo's avatar
Ayolo committed
300
301
302
        $frm->add_hidden("action","merge");
        $frm->add_submit("save","Merger");
        $cts->add($frm,true);
Ayolo's avatar
Ayolo committed
303
304
      }
    }
Ayolo's avatar
bleh    
Ayolo committed
305
  }
Ayolo's avatar
Ayolo committed
306
}
Ayolo's avatar
Ayolo committed
307
308
$site->add_contents($cts);
$site->end_page ();
Ayolo's avatar
Ayolo committed
309
?>