cotisations.php 27.7 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
<?php
/* Copyright 2006
 * - Julien Etelain < julien at pmad dot net >
Ayolo's avatar
Ayolo committed
4
 * - Simon Lopez < simon DOT lopez AT ayolo DOT org >
BenC's avatar
debug    
BenC committed
5
 * - Benjamin Collet < bcollet AT oxynux DOT org >
Ayolo's avatar
Ayolo committed
6
 *
7
 * Ce fichier fait partie du site de l'Association des Étudiants de
Ayolo's avatar
Ayolo committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
$topdir = "../";

Feu's avatar
Feu committed
27
28
29
30
31
/**
 * @deprecated
 * @todo à refaire complétement
 */

Ayolo's avatar
Ayolo committed
32
33
34
35
require_once($topdir. "include/site.inc.php");
require_once($topdir. "include/cts/sqltable.inc.php");
require_once($topdir. "include/entities/cotisation.inc.php");
require_once($topdir. "include/cts/special.inc.php");
Ayolo's avatar
bleh    
Ayolo committed
36
37
require_once($topdir . "include/entities/ville.inc.php");
require_once($topdir . "include/entities/pays.inc.php");
mbriand's avatar
mbriand committed
38
require_once($topdir. "include/entities/partenariat_utl.inc.php");
39
require_once($topdir. "include/cts/fsearchcache.inc.php");
Ayolo's avatar
Ayolo committed
40
41
42
43

$site = new site ();

if ( !$site->user->is_in_group("gestion_ae") )
44
  $site->error_forbidden("services");
Ayolo's avatar
Ayolo committed
45
46
47
48
49

if (date("m-d") < "02-15")
{
  $date1 = date("Y") . "-02-15";
  $date2 = date("Y") . "-08-15";
50
51
  $date3 = date("Y") + 1 . "-08-15";
  $date4 = date("Y") + 2 . "-08-15";
Ayolo's avatar
Ayolo committed
52
53
54
55
}
else
{
  if (date("m-d") < "08-15")
Ayolo's avatar
bleh    
Ayolo committed
56
57
58
  {
    $date1 = date("Y") . "-08-15";
    $date2 = date("Y") + 1 . "-02-15";
BenC's avatar
BenC committed
59
60
    $date3 = date("Y") + 2 . "-02-15";
    $date4 = date("Y") + 3 . "-02-15";
Ayolo's avatar
bleh    
Ayolo committed
61
  }
Ayolo's avatar
Ayolo committed
62
  else
Ayolo's avatar
bleh    
Ayolo committed
63
64
65
  {
    $date1 = date("Y") + 1 . "-02-15";
    $date2 = date("Y") + 1 . "-08-15";
BenC's avatar
BenC committed
66
67
    $date3 = date("Y") + 2 . "-08-15";
    $date4 = date("Y") + 3 . "-08-15";
Ayolo's avatar
bleh    
Ayolo committed
68
  }
Ayolo's avatar
Ayolo committed
69
70
}

mbriand's avatar
mbriand committed
71
72
73
74
$partenariats = array(1=> "Ce cotisant vient d'ouvrir un compte à la Société Générale",
                      2=> "Ce cotisant est à la SMEREB",
                      );

75
$site->start_page ("services", "Gestion des cotisations");
Ayolo's avatar
Ayolo committed
76
77
78
79
80

function add_search_form()
{
  global $topdir, $ch;
  $cts = new contents("Gestion des cotisations");
BenC's avatar
BenC committed
81
  $frm = new form("searchstudent","cotisations.php",true,"POST","Recherche d'un utilisateur existant");
Ayolo's avatar
Ayolo committed
82
  $frm->add_hidden("action","searchstudent");
Ayolo's avatar
ergo    
Ayolo committed
83
84
85
  $subfrm = new form("quicksearch","cotisations.php",false,"POST","Recherche rapide ...");
  $subfrm->add_user_fieldv2("id_utilisateur","Prenom Nom/Surnom");
  $subfrm->add_submit("valid","Cotisation");
Ayolo's avatar
ergo    
Ayolo committed
86
  $frm->add($subfrm,false,false,false,false,false,true,true);
Ayolo's avatar
ergo    
Ayolo committed
87
88
89
  $subfrm = new form("searchemail","cotisations.php",false,"POST","Recherche par email ...");
  $subfrm->add_text_field("email","Adresse e-mail");
  $subfrm->add_submit("valid","Cotisation");
Ayolo's avatar
ergo    
Ayolo committed
90
  $frm->add($subfrm,false,false,false,false,false,true,false);
Ayolo's avatar
debug    
Ayolo committed
91
  /*$subfrm = new form("searchcarte","cotisations.php",false,"POST","Par carte AE ...");
Ayolo's avatar
ergo    
Ayolo committed
92
93
  $subfrm->add_text_field("numcarte","Carte AE");
  $subfrm->add_submit("valid","Cotisation");
Ayolo's avatar
debug    
Ayolo committed
94
  $frm->add($subfrm,false,false,false,false,false,true,false);*/
Ayolo's avatar
ergo    
Ayolo committed
95
  $cts->add($frm,true);
Ayolo's avatar
Ayolo committed
96
97
98
99
100
101
  return $cts;
}

function add_new_form($id = null)
{
  global $topdir, $ch;
Feu's avatar
Feu committed
102

mbriand's avatar
mbriand committed
103
  global $date1, $date2, $date3, $date4, $partenariats;
Ayolo's avatar
Ayolo committed
104
105
106

  $cts = new contents("Gestion des cotisations");

BenC's avatar
BenC committed
107
  $frm = new form("newstudent","cotisations.php",true,"POST","Inscription d'un nouvel étudiant UTBM ou administratif UTBM");
Ayolo's avatar
Ayolo committed
108
109
110
111
  $frm->add_hidden("action","newstudent");
  if ( $ErreurNewStudent )
    $frm->error($ErreurNewStudent);

BenC's avatar
BenC committed
112
  $sub_frm_ident = new form("ident",null,null,null,"Identité");
BenC's avatar
BenC committed
113

BenC's avatar
BenC committed
114
  $sub_frm_ident->add_text_field("nom","Nom","",true);
Ayolo's avatar
Ayolo committed
115

BenC's avatar
BenC committed
116
  $sub_frm_ident->add_text_field("prenom","Prénom","",true);
Ayolo's avatar
Ayolo committed
117

mbriand's avatar
mbriand committed
118
  $sub_frm_ident->add_text_field("emailutbm","e-mail (UTBM si possible)","",true,false,false,true);
Ayolo's avatar
Ayolo committed
119
120
121
122

  $frm->add($sub_frm_ident);
  $frm->add_info("&nbsp;");

BenC's avatar
BenC committed
123
  $sub_frm_cotiz = new form("cotisation",null,null,null,"Cotisation");
mbriand's avatar
mbriand committed
124
125
126
127
128
129
130
131
  $sub_frm_cotiz->add_select_field("cotiz","Cotisation",
      array(  0 => "1 Semestre, 15 Euros, $date1",
              1 => "2 Semestres, 28 Euros, $date2",
              2 => "Cursus Tronc Commun, 45 €, jusqu'au $date3",
              3 => "Cursus Branche, 45 €, jusqu'au $date4",
              4 => "Membre honoraire ou occasionnel, 0 €, jusqu'au $date2",
              5 => "Cotisation par Assidu, 4€, jusqu'au $date2",
              6 => "Cotisation par l'Amicale, 4€, jusqu'au $date2",
132
              7 => "Cotisation réseau UT, 0€, jusqu'au $date1, preuve de cotisation nécessaire",
mbriand's avatar
mbriand committed
133
134
              8 => "Cotisation CROUS, 4€, jusqu'au $date2",
      ),1);
BenC's avatar
BenC committed
135
  $sub_frm_cotiz->add_select_field("paiement","Mode de paiement",array(1 => "Chèque", 3 => "Liquide", 4 => "Administration"));
Ayolo's avatar
Ayolo committed
136
137
  $sub_frm_cotiz->add_info("&nbsp;");

BenC's avatar
BenC committed
138
  $sub_frm_cotiz_ecole = new form("ecoleform",null,null,null,"Étudiant");
Ayolo's avatar
Ayolo committed
139
140
141
142
143
144
  //$sub_frm_cotiz_ecole->add_hidden("etudiant",true);
  //$sub_frm_cotiz_ecole->add_checkbox("etudiant","Etudiant",true);
  $sub_frm_cotiz_ecole->add_text_field("ecole","Ecole","UTBM",true);

  $sub_frm_cotiz->add($sub_frm_cotiz_ecole,false,true,true,"ecole",false,true,true);

BenC's avatar
BenC committed
145
  $sub_frm_cotiz_other = new form("ecoleform",null,null,null,"Prof/Administratif");
Ayolo's avatar
Ayolo committed
146
147
148
149
  //$sub_frm_cotiz_other->add_hidden("etudiant",false);
  $sub_frm_cotiz->add($sub_frm_cotiz_other,false,true,false,"other",false,true,false);

  $sub_frm_cotiz->add_info("&nbsp;");
BenC's avatar
BenC committed
150
  $sub_frm_cotiz->add_checkbox("droit_image","Droit à l'image",false);
Ayolo's avatar
Ayolo committed
151
152
153
  $sub_frm_cotiz->add_checkbox("cadeau","Cadeau",false);
  $sub_frm_cotiz->add_info("&nbsp;");

mbriand's avatar
mbriand committed
154
155
  $sub_frm_cotiz->add_info("&nbsp;");
  foreach ($partenariats as $id_partenariat => $texte_partenariat)
mbriand's avatar
mbriand committed
156
    $sub_frm_cotiz->add_checkbox("partenariats[".$id_partenariat."]",$texte_partenariat,false);
mbriand's avatar
mbriand committed
157

Ayolo's avatar
Ayolo committed
158
159
160
161
162
163
164
165
166
167
  $frm->add($sub_frm_cotiz);

  $frm->add_submit("submit","Enregistrer");
  $cts->add($frm,true);

  return $cts;
}

function add_user_info_form ($user = null)
{
Ayolo's avatar
debug    
Ayolo committed
168
  global $site;
Ayolo's avatar
bleh    
Ayolo committed
169
  $ville = new ville($site->db);
Ayolo's avatar
bleh    
Ayolo committed
170
  $pays = new pays($site->db);
Ayolo's avatar
bleh    
Ayolo committed
171
172
  $ville->load_by_id($user->id_ville);
  $pays->load_by_id($user->id_pays);
Ayolo's avatar
debug    
Ayolo committed
173
174
  $ville_parents = new ville($site->db);
  $pays_parents = new pays($site->db);
Ayolo's avatar
debug    
Ayolo committed
175
176
  $pays_parents->load_by_id($user->id_pays_parents);
  $ville_parents->load_by_id($user->id_ville_parents);
Ayolo's avatar
debug    
Ayolo committed
177

BenC's avatar
BenC committed
178
  $sub_frm = new form("infosmmt",null,null,null,"Informations complémentaires");
Ayolo's avatar
Ayolo committed
179
180
181
  $sub_frm->add_info("&nbsp;");
  $sub_frm->add_select_field("sexe","Sexe",array(1=>"Homme",2=>"Femme"),$user->sexe);
  if ($user->date_naissance)
Feu's avatar
Feu committed
182
    $sub_frm->add_date_field("date_naissance","Date de naissance",$user->date_naissance,false,true);
Ayolo's avatar
Ayolo committed
183
  else
BenC's avatar
debug    
BenC committed
184
    $sub_frm->add_date_field("date_naissance","Date de naissance",strtotime("1986-01-01"),false,true);
Ayolo's avatar
Ayolo committed
185

Ayolo's avatar
bleh    
Ayolo committed
186
  if ($user->utbm)
Ayolo's avatar
Ayolo committed
187
  {
Ayolo's avatar
bleh    
Ayolo committed
188
189
190
    $sub_frm->add_select_field("role","Role",$GLOBALS["utbm_roles"],$user->role);
    $sub_frm->add_select_field("departement","Departement",$GLOBALS["utbm_departements"],$user->departement);
    $sub_frm->add_text_field("semestre","Semestre",$user->semestre);
Ayolo's avatar
Ayolo committed
191
  }
Ayolo's avatar
Ayolo committed
192
  $sub_frm->add_text_field("addresse","Adresse",$user->addresse);
Ayolo's avatar
bleh    
Ayolo committed
193
194
  $sub_frm->add_entity_smartselect("id_ville","Ville (France)", $ville,true);
  $sub_frm->add_entity_smartselect("id_pays","ou pays", $pays,true);
Ayolo's avatar
Ayolo committed
195
196
197
198
  $sub_frm->add_text_field("tel_maison","Telephone (fixe)",$user->tel_maison);
  $sub_frm->add_info("et/ou");
  $sub_frm->add_text_field("tel_portable","Telephone (portable)",$user->tel_portable);
  $sub_frm->add_text_field("citation","Citation",$user->citation);
Ayolo's avatar
bleh    
Ayolo committed
199
200
201

  $sub_frm->add_entity_smartselect ("id_ville_parents","Ville parents (France)", $ville_parents,true);
  $sub_frm->add_entity_smartselect ("id_pays_parents","ou pays parents", $pays_parents,true);
202
  $sub_frm->add_select_field("taille_tshirt","Taille de t-shirt (non publié***)",
Ayolo's avatar
bleh    
Ayolo committed
203
204
205
206
207
208
209
210
211
                             array(0=>"-",
                                   "XS"=>"XS",
                                   "S"=>"S",
                                   "M"=>"M",
                                   "L"=>"L",
                                   "XL"=>"XL",
                                   "XXL"=>"XXL",
                                   "XXXL"=>"XXXL"),
                             $user->taille_tshirt);
Ayolo's avatar
Ayolo committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
  $sub_frm->add_info("&nbsp;");

  return $sub_frm;
}

/** Actions */

if ( $_REQUEST["action"] == "cadeau" )
{
  $cotisation = new cotisation($site->db,$site->dbrw);
  $cotisation->load_by_id($_REQUEST["id_cotisation"]);

  if ( $cotisation->id > 0 )
    $cotisation->mark_cadeau();
}

elseif ( $_REQUEST["action"] == "savecotiz" )
{
  $user = new utilisateur($site->db,$site->dbrw);
  $user->load_by_id($_REQUEST['id_utilisateur']);

Ayolo's avatar
Ayolo committed
233
234
  if ( $user->id < 0 )
  {
235
    $site->error_not_found("services");
Ayolo's avatar
Ayolo committed
236
    exit();
Ayolo's avatar
Ayolo committed
237
238
239
  }
  else
  {
mbriand's avatar
mbriand committed
240
    if ( $user->cotisant )
Ayolo's avatar
Ayolo committed
241
    {
Ayolo's avatar
debug    
Ayolo committed
242
243
      global $site;
      $req = new requete($site->db,
Ayolo's avatar
Ayolo committed
244
245
246
247
248
249
                         "SELECT date_fin_cotis ".
                         "FROM `ae_cotisations` " .
                         "WHERE `id_utilisateur`='".$user->id."' " .
                         "ORDER BY `date_fin_cotis` DESC LIMIT 1");
      if ( $req->lines == 1 )
      {
250
        /* on fait de l'incrémental */
Ayolo's avatar
Ayolo committed
251
252
253
        list($curend) = $req->get_row();
        $prevdate=strtotime($curend);

254
        /* calculs identiques au mode normal mais basé sur la dernière cotiz */
Ayolo's avatar
Ayolo committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
        if (date("m-d",$prevdate) < "02-15")
        {
            $date1 = date("Y",$prevdate) . "-02-15";
            $date2 = date("Y",$prevdate) . "-08-15";
        }
        else
        {
          if (date("m-d",$prevdate) < "08-15")
          {
            $date1 = date("Y",$prevdate) . "-08-15";
            $date2 = date("Y",$prevdate) + 1 . "-02-15";
          }
          else
          {
            $date1 = date("Y",$prevdate) + 1 . "-02-15";
            $date2 = date("Y",$prevdate) + 1 . "-08-15";
          }
        }
      }
    }
Ayolo's avatar
Ayolo committed
275
276
277
278
    $cotisation = new cotisation($site->db,$site->dbrw);
    if ( $_REQUEST["cotiz"] == 0 ) {
      $date_fin = strtotime($date1);
      $prix_paye = 1500;
BenC's avatar
BenC committed
279
    } elseif ( $_REQUEST["cotiz"] == 1 ) {
Ayolo's avatar
Ayolo committed
280
281
      $date_fin = strtotime($date2);
      $prix_paye = 2800;
BenC's avatar
BenC committed
282
283
284
    } elseif ( $_REQUEST["cotiz"] == 2 ) {
      $date_fin = strtotime($date3);
      $prix_paye = 4500;
285
    } elseif ( $_REQUEST["cotiz"] == 3 ) {
BenC's avatar
BenC committed
286
287
      $date_fin = strtotime($date4);
      $prix_paye = 4500;
mbriand's avatar
mbriand committed
288
    } elseif ( $_REQUEST["cotiz"] == 4 ) {
289
290
      $date_fin = strtotime($date2);
      $prix_paye = 0;
mbriand's avatar
mbriand committed
291
292
    } elseif ( $_REQUEST["cotiz"] == 5 ) {
      $date_fin = strtotime($date2);
mbriand's avatar
bleh    
mbriand committed
293
      $prix_paye = 400;
mbriand's avatar
mbriand committed
294
    } elseif ( $_REQUEST["cotiz"] == 6 ) {
mbriand's avatar
mbriand committed
295
      $date_fin = strtotime($date2);
mbriand's avatar
bleh    
mbriand committed
296
      $prix_paye = 400;
mbriand's avatar
mbriand committed
297
    } elseif ( $_REQUEST["cotiz"] == 7 ) {
mbriand's avatar
mbriand committed
298
299
      $date_fin = strtotime($date1);
      $prix_paye = 0;
mbriand's avatar
mbriand committed
300
301
302
303
304
305
    } elseif ( $_REQUEST["cotiz"] == 8 ) {
      $date_fin = strtotime($date2);
      $prix_paye = 400;
    } else {
      $list->add("Le type de cotisation n'est pas valide");
      $site->add_contents($info);
Ayolo's avatar
Ayolo committed
306
307
308
    }

    $cotisation->load_lastest_by_user ( $user->id );
mbriand's avatar
mbriand committed
309
    $cotisation->add ( $user->id, $date_fin, $_REQUEST["paiement"], $prix_paye, $_REQUEST["cotiz"] );
Ayolo's avatar
Ayolo committed
310
311
312
313
314
315
316
317
318
319

    $a_pris_cadeau = $_REQUEST["cadeau"] == true;

    if ($a_pris_cadeau && $cotisation->id > 0)
      $cotisation->mark_cadeau();

    $user->load_all_extra();
    $user->droit_image = $_REQUEST["droit"]==true;
    $user->sexe = $_REQUEST['sexe'];
    $user->surnom = $_REQUEST['surnom'];
BenC's avatar
debug    
BenC committed
320
    $user->date_naissance = $_REQUEST['date_naissance'];
Ayolo's avatar
debug    
Ayolo committed
321
322
323
324
325
    $user->addresse = $_REQUEST['addresse'];
    $ville = new ville($site->db);
    $pays = new pays($site->db);
    $ville_parents = new ville($site->db);
    $pays_parents = new pays($site->db);
Ayolo's avatar
debug    
Ayolo committed
326
    if ( $_REQUEST['id_ville'] )
Ayolo's avatar
debug    
Ayolo committed
327
328
329
330
331
332
333
334
335
336
    {
      $ville->load_by_id($_REQUEST['id_ville']);
      $user->id_ville = $ville->id;
      $user->id_pays = $ville->id_pays;
    }
    else
    {
      $user->id_ville = null;
      $user->id_pays = $_REQUEST['id_pays'];
    }
Ayolo's avatar
Ayolo committed
337
338
339
340
341
    $user->tel_maison = telephone_userinput($_REQUEST['tel_maison']);
    $user->tel_portable = telephone_userinput($_REQUEST['tel_portable']);
    $user->date_maj = time();

    if ( $user->etudiant )
Ayolo's avatar
debug    
Ayolo committed
342
343
    {
      $user->citation = $_REQUEST['citation'];
Ayolo's avatar
debug    
Ayolo committed
344
345
346
347
348
349
350
351
352
353
354
355
      $user->adresse_parents = $_REQUEST['adresse_parents'];
      if ( $_REQUEST['id_ville_parents'] )
      {
        $ville_parents->load_by_id($_REQUEST['id_ville_parents']);
        $user->id_ville_parents = $ville_parents->id;
        $user->id_pays_parents = $ville_parents->id_pays;
      }
      else
      {
        $user->id_ville_parents = null;
        $user->id_pays_parents = $_REQUEST['id_pays_parents'];
      }
Ayolo's avatar
debug    
Ayolo committed
356
357
358
      $user->tel_parents = NULL;
      $user->nom_ecole_etudiant = "UTBM";
    }
Ayolo's avatar
Ayolo committed
359
    if ( $user->utbm )
Ayolo's avatar
debug    
Ayolo committed
360
361
    {
      $user->surnom = $_REQUEST['surnom'];
BenC's avatar
debug    
BenC committed
362
      $user->departement = $_REQUEST['departement'];
Ayolo's avatar
debug    
Ayolo committed
363
364
365
      $user->semestre = $_REQUEST['semestre'];
      $user->role = $_REQUEST['role'];
    }
BenC's avatar
debug    
BenC committed
366
    $user->taille_tshirt = $_REQUEST['taille_tshirt'];
Ayolo's avatar
Ayolo committed
367
368
    $user->saveinfos();

mbriand's avatar
mbriand committed
369
370
371
372
    $partenariat = new Partenariat($site->db, $site->dbrw);
    if (isset($_REQUEST['partenariats']))
      foreach ($_REQUEST['partenariats'] as $id_partenariat => $val)
        $partenariat->add($id_partenariat, $user->id);
mbriand's avatar
mbriand committed
373

BenC's avatar
BenC committed
374
    $info = new contents("Nouvelle cotisation","<img src=\"".$topdir."images/actions/done.png\">&nbsp;&nbsp;La cotisation a bien &eacute;t&eacute; enregistr&eacute;e.<br /><a href=\"" . $topdir . "ae/cotisations.php\">Retour</a>");
Ayolo's avatar
Ayolo committed
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394


    $list = new itemlist();
    $list->add("<a href=\"" . $topdir . "ae/cotisations.php\">Retour aux cotisations</a>");
    $list->add("<a href=\"" . $topdir . "user.php?id_utilisateur=" . $user->id . "\">Retour &agrave; l'utilisateur</a>");
    $info->add($list);

    $info->set_toolbox(new toolbox(array($topdir . "ae/cotisations.php" => "Retour")));
    $site->add_contents($info);
  }
}

elseif ( $_REQUEST["action"] == "searchstudent" )
{
  $conds="";

  $user = array();
  if ( $_REQUEST['search_id'] && XMLRPC_USE )
    $user = $ch->getById($_REQUEST['search_id']);

BenC's avatar
BenC committed
395
  if ( $_REQUEST["nom"] )
Ayolo's avatar
Ayolo committed
396
  {
Ayolo's avatar
Ayolo committed
397
          $by = "nom";
BenC's avatar
BenC committed
398
          $on = $_REQUEST['nom'];
Ayolo's avatar
Ayolo committed
399
400
          if ($on)
            $conds .= " AND utilisateurs.nom_utl LIKE '".mysql_real_escape_string($on)."%'";
Ayolo's avatar
Ayolo committed
401
  }
BenC's avatar
BenC committed
402
  if ( $_REQUEST["prenom"] )
Ayolo's avatar
Ayolo committed
403
  {
404
          $by = "prénom";
BenC's avatar
BenC committed
405
          $on = $_REQUEST['prenom'];
Ayolo's avatar
Ayolo committed
406
407
          if ($on)
            $conds .= " AND utilisateurs.prenom_utl LIKE '".mysql_real_escape_string($on)."%'";
Ayolo's avatar
Ayolo committed
408
  }
BenC's avatar
BenC committed
409
  if ( $_REQUEST["email"] )
Ayolo's avatar
Ayolo committed
410
  {
Ayolo's avatar
Ayolo committed
411
          $by = "E Mail";
BenC's avatar
BenC committed
412
          $on = $_REQUEST['email'];
Ayolo's avatar
Ayolo committed
413
414
415
          if ($on)
            $conds .= " AND (`utilisateurs`.`email_utl` = '" . mysql_real_escape_string($on) . "' OR " .
              "`utl_etu_utbm`.`email_utbm` = '" . mysql_real_escape_string($on) . "') ";
Ayolo's avatar
Ayolo committed
416
  }
BenC's avatar
BenC committed
417
  if ( $_REQUEST["numcarte"] )
Ayolo's avatar
Ayolo committed
418
  {
Ayolo's avatar
Ayolo committed
419
420
421
422
          $by = "Code Barre Carte AE";
          list($num,$extra)=explode(" ",$_REQUEST["numcarte"]);
          $on = intval($num);
          $conds .= " AND ae_carte.id_carte_ae = '". mysql_real_escape_string($on)."'";
Ayolo's avatar
Ayolo committed
423
  }
BenC's avatar
BenC committed
424
425
  if ( isset($_REQUEST['id_utilisateur']) && ($_REQUEST['id_utilisateur'] > 0))
  {
Ayolo's avatar
Ayolo committed
426
427
428
429
    $by = "Identifiant AE";
    $on = intval($_REQUEST['id_utilisateur']);
    $conds .= " AND utilisateurs.id_utilisateur = '" . mysql_real_escape_string($on) . "'";
  }
Ayolo's avatar
Ayolo committed
430

Ayolo's avatar
Ayolo committed
431
432
433
434
435
436
437
438
439
440
  $req = new requete($site->db,"SELECT utilisateurs.nom_utl AS nom_utilisateur, " .
                     "utilisateurs.prenom_utl AS prenom_utilisateur, ".
                     "utilisateurs.id_utilisateur AS id_utl, utilisateurs.ae_utl, ae_cotisations.date_fin_cotis, " .
                     "utl_etu_utbm.branche_utbm, utl_etu_utbm.semestre_utbm" .
                     ", ae_cotisations.a_pris_cadeau ".
                     "FROM utilisateurs " .
                     "LEFT JOIN ae_cotisations ON (utilisateurs.id_utilisateur=ae_cotisations.id_utilisateur AND ae_cotisations.date_fin_cotis > NOW()) " .
                     "LEFT JOIN ae_carte ON `ae_cotisations`.`id_cotisation`=`ae_carte`.`id_cotisation` " .
                     "LEFT JOIN `utl_etu_utbm` ON `utl_etu_utbm`.`id_utilisateur` = `utilisateurs`.`id_utilisateur` " .
                     "WHERE 1 $conds " .
Ayolo's avatar
debug    
Ayolo committed
441
                     "ORDER BY utilisateurs.nom_utl, utilisateurs.prenom_utl LIMIT 1");
Ayolo's avatar
debug    
Ayolo committed
442

Ayolo's avatar
Ayolo committed
443
444
  $nb = $req->lines;
  if ($nb == 1)
Ayolo's avatar
Ayolo committed
445
  {
Ayolo's avatar
Ayolo committed
446
447
448
449
450
451
    $res = $req->get_row();

    $user = new utilisateur($site->db,$site->dbrw);

    $user->load_by_id($res['id_utl']);
    if ( $user->id < 0 )
Ayolo's avatar
Ayolo committed
452
    {
453
      $site->error_not_found("services");
Ayolo's avatar
Ayolo committed
454
      exit();
Ayolo's avatar
Ayolo committed
455
    }
Ayolo's avatar
Ayolo committed
456

Ayolo's avatar
Ayolo committed
457
458
459
460
461
462
463
464
    if ( $user->id > 0 )
    {
      $user->load_all_extra();

      $cts = new contents("Cotisant ".$user->prenom." ".$user->nom);

      $cts->set_toolbox(new toolbox(array($_SERVER['SCRIPT_NAME']=>"Rechercher un autre cotisant")));

Ayolo's avatar
debug    
Ayolo committed
465
466
467
468
469
      $ville = new ville($site->db);
      $pays = new pays($site->db);
      $ville->load_by_id($user->id_ville);
      $pays->load_by_id($user->id_pays);

Ayolo's avatar
Ayolo committed
470
471
472
473
474
475
      $cts->add(new image($user->prenom . " " . $user->nom,$topdir."/var/img/matmatronch/".$user->id.".identity.jpg","fiche_image"));
      $cts->add_paragraph(
                          "<b>". $user->prenom . " " . $user->nom . "</b><br/>" .
                          $user->surnom."<br/>\n".
                          date("d/m/Y",$user->date_naissance) . "<br />" .
                          $user->addresse . "<br />" .
Ayolo's avatar
debug    
Ayolo committed
476
                          $ville->get_html_link()." (".sprintf("%05d", $ville->cpostal).")<br/>".$pays->get_html_link()."<br/>" .
Ayolo's avatar
Ayolo committed
477
478
479
480
                          $user->tel_maison . "<br/>" .
                          $user->tel_portable . "<br/>"
                         );

481
      $cts->add_paragraph("Fiche utilisateur : ".$user->get_html_link());
Ayolo's avatar
Ayolo committed
482
483
484
485
486

      $cts->add_paragraph("&nbsp;");

      $frm = new form("newcotiz","cotisations.php?id_utilisateur=".$user->id,true,"POST","Nouvelle cotisation");
      $frm->add_hidden("action","newcotiz");
mbriand's avatar
mbriand committed
487
488
489
490
491
492
493
494
      $frm->add_select_field("cotiz","Cotisation",
          array(  0 => "1 Semestre, 15 Euros, $date1",
                  1 => "2 Semestres, 28 Euros, $date2",
                  2 => "Cursus Tronc Commun, 45 €, jusqu'au $date3",
                  3 => "Cursus Branche, 45 €, jusqu'au $date4",
                  4 => "Membre honoraire ou occasionnel, 0 €, jusqu'au $date2",
                  5 => "Cotisation par Assidu, 4€, jusqu'au $date2",
                  6 => "Cotisation par l'Amicale, 4€, jusqu'au $date2",
mbriand's avatar
mbriand committed
495
496
497
                  7 => "Cotisation inter UT, 0€, jusqu'au $date1, preuve de cotisation nécessaire",
                  8 => "Cotisation CROUS, 4€, jusqu'au $date2",
          ),1);
BenC's avatar
BenC committed
498
      $frm->add_select_field("paiement","Mode de paiement",array(1 => "Chèque", 3 => "Liquide", 4 => "Administration"));
Ayolo's avatar
Ayolo committed
499
      $frm->add_checkbox("droit_image","Droit &agrave; l'image",$user->droit_image);
BenC's avatar
BenC committed
500
      $frm->add_checkbox("a_pris_cadeau","Cadeau distribué",false);
mbriand's avatar
mbriand committed
501
      foreach ($partenariats as $id_partenariat => $texte_partenariat)
mbriand's avatar
mbriand committed
502
        $frm->add_checkbox("partenariats[".$id_partenariat."]",$texte_partenariat,false);
Ayolo's avatar
Ayolo committed
503
504
505
506
507
508
509
      $frm->add_submit("submit","Enregistrer");
      $cts->add($frm,true);


      $req = new requete($site->db,
                         "SELECT * ".
                         "FROM `ae_cotisations` " .
Ayolo's avatar
Ayolo committed
510
                         "WHERE `id_utilisateur`='".$user->id."' AND `date_fin_cotis` < NOW()" .
Ayolo's avatar
Ayolo committed
511
512
513
514
                         "ORDER BY `date_cotis` DESC");

      $tbl = new sqltable(
                          "listcotiz_effectue",
BenC's avatar
BenC committed
515
                          "Cotisations effectuées", $req, "cotisations.php?id_utilisateur=".$user->id,
Ayolo's avatar
Ayolo committed
516
517
518
519
520
521
                          "id_cotisation",
                          array("date_cotis"=>"Le",
                                "date_fin_cotis"=>"Jusqu'au",
                                "a_pris_cadeau"=>"Cadeau"),
                          array(), array(), array("a_pris_cadeau"=>array(0=>"Non pris",1=>"Pris"))
                         );
Ayolo's avatar
Ayolo committed
522

Ayolo's avatar
Ayolo committed
523
524
525
      $req = new requete($site->db,
                         "SELECT * ".
                         "FROM `ae_cotisations` " .
Ayolo's avatar
Ayolo committed
526
527
                         "WHERE `id_utilisateur`='".$user->id."' AND `date_fin_cotis` > NOW() " .
                         "ORDER BY `date_cotis` DESC");
Ayolo's avatar
Ayolo committed
528
529
530

      if ($req->lines)
      {
Ayolo's avatar
Ayolo committed
531
532
533
534
535
        $_req= new requete($site->db,
                           "SELECT * ".
                           "FROM `ae_cotisations` " .
                           "WHERE `id_utilisateur`='".$user->id."' AND `date_fin_cotis` > NOW() " .
                           "ORDER BY `date_cotis` DESC LIMIT 1");
Ayolo's avatar
Ayolo committed
536
537
538
        $max = 0;
        while( $row = $_req->get_row() )
          if( strtotime($row["date_fin_cotis"]) > time() && strtotime($row["date_fin_cotis"]) > $max )
Ayolo's avatar
Ayolo committed
539
            $max = strtotime($row["date_fin_cotis"]);
Ayolo's avatar
Ayolo committed
540
        if($max>0)
Ayolo's avatar
Ayolo committed
541
          $cts->add_paragraph("<br /><b><font color=\"red\">D&eacute;j&agrave; cotisant jusqu'au : ".date("d/m/Y",$max)." !!!</font></b>");
Ayolo's avatar
Ayolo committed
542

Ayolo's avatar
Ayolo committed
543
        $tbl2 = new sqltable(
Ayolo's avatar
Ayolo committed
544
                            "listcotiz_encours",
BenC's avatar
BenC committed
545
                            "Cotisation en cours", $req, "cotisations.php?id_utilisateur=".$user->id,
Ayolo's avatar
Ayolo committed
546
547
548
549
550
551
                            "id_cotisation",
                            array("date_cotis"=>"Le",
                                  "date_fin_cotis"=>"Jusqu'au",
                                  "a_pris_cadeau"=>"Cadeau"),
                            array("Action"=>"Marquer le cadeau pris"), array(), array("a_pris_cadeau"=>array(0=>"Non pris",1=>"Pris"))
                           );
Ayolo's avatar
Ayolo committed
552
        $cts->add($tbl2,true);
Ayolo's avatar
Ayolo committed
553
      }
Ayolo's avatar
Ayolo committed
554
555

      $cts->add($tbl,true);
Ayolo's avatar
Ayolo committed
556
557
558

      $site->add_contents($cts);
    }
Ayolo's avatar
Ayolo committed
559

Ayolo's avatar
Ayolo committed
560
  }
Ayolo's avatar
Ayolo committed
561
  else if ($nb == 0)
Ayolo's avatar
Ayolo committed
562
  {
Ayolo's avatar
Ayolo committed
563
    $cts_2 = add_new_form($_REQUEST['search_id']);
BenC's avatar
BenC committed
564
    $cts_2->set_toolbox(new toolbox(array($_SERVER['SCRIPT_NAME']=>"Rechercher un cotisant")));
Ayolo's avatar
Ayolo committed
565
    $site->add_contents($cts_2);
Ayolo's avatar
Ayolo committed
566
  }
Ayolo's avatar
Ayolo committed
567
  else if ($nb > 1 && !XMLRPC_USE)
Ayolo's avatar
Ayolo committed
568
  {
Ayolo's avatar
Ayolo committed
569

Ayolo's avatar
Ayolo committed
570
571
572
    $res = $req->get_row();
    $tbl = new sqltable(
                        "listcotiz",
BenC's avatar
BenC committed
573
                         $nb." Résultats de la recherche de cotisants par ".$by." sur ".$on, $req, "cotisations.php",
Ayolo's avatar
Ayolo committed
574
575
                         "id_utilisateur",
                          array("nom_utilisateur"=>"Nom",
BenC's avatar
BenC committed
576
                                "prenom_utilisateur"=>"Prénom",
Ayolo's avatar
Ayolo committed
577
578
579
580
581
582
583
584
                                "branche_utbm"=>"Branche",
                                "semestre_utbm"=>"Semestre",
                                "ae_utl"=>"Cotisant",
                                "date_fin_cotis"=>"Jusqu'au",
                                "a_pris_cadeau"=>"Cadeau"),
                          array("pagecotis"=>"Nouvelle cotisation","cadeau"=>"Marquer le cadeau comme pris"), array(), array("ae_utl"=>array(0=>"Non",1=>"Oui"),"a_pris_cadeau"=>array(0=>"NON Pris",1=>"Pris"))
                         );
    $site->add_contents($tbl);
Ayolo's avatar
Ayolo committed
585
  }
BenC's avatar
BenC committed
586

Ayolo's avatar
Ayolo committed
587
588
589
590
591
592
593
594
595
596
597
}

elseif ($_REQUEST['action'] == "modifyUser" && $_POST['search_id'])
  $cts = add_new_form($_POST['search_id']);

elseif ( $_REQUEST["action"] == "newcotiz" )
{
  $user = new utilisateur($site->db,$site->dbrw);

  $user->load_by_id($_REQUEST['id_utilisateur']);
  if ( $user->id < 0 )
Ayolo's avatar
Ayolo committed
598
  {
599
    $site->error_not_found("services");
Ayolo's avatar
Ayolo committed
600
601
    exit();
  }
Ayolo's avatar
Ayolo committed
602
603

  if ( $user->id > 0 )
Ayolo's avatar
Ayolo committed
604
  {
Ayolo's avatar
Ayolo committed
605
    $user->load_all_extra();
BenC's avatar
BenC committed
606
    $cts = new contents("Mise à jour des infos indispensable pour l'impression de la carte AE");
Ayolo's avatar
Ayolo committed
607
608
609
610
611
    $frm = new form("infos","cotisations.php?id_utilisateur=".$user->id,true,"POST",null);
    $frm->add_hidden("action","savecotiz");
    if ( $user->utbm )
    {
      $frm->add_text_field("nom","Nom",$user->nom,true,false,false,false);
BenC's avatar
BenC committed
612
      $frm->add_text_field("prenom","Prénom",$user->prenom,true,false,false,false);
Ayolo's avatar
Ayolo committed
613
      $frm->add_text_field("surnom","Surnom",$user->surnom);
Ayolo's avatar
Ayolo committed
614

Ayolo's avatar
Ayolo committed
615
      $sub_frm = add_user_info_form($user);
Ayolo's avatar
Ayolo committed
616

Ayolo's avatar
Ayolo committed
617
      $frm->add($sub_frm,false,false,false,false,false,true,true);
Ayolo's avatar
Ayolo committed
618
    }
Ayolo's avatar
Ayolo committed
619
620
621
622
623
624
625
    else
      $frm->add_info("Cotisant non UTBM");

    $frm->add_hidden("cotiz",$_POST['cotiz']);
    $frm->add_hidden("paiement",$_POST['paiement']);
    $frm->add_hidden("droit_image",$_POST['droit_image']);
    $frm->add_hidden("cadeau",$_REQUEST["cadeau"]);
mbriand's avatar
mbriand committed
626
627
628
629
    if (isset($_REQUEST['partenariats']))
      foreach ($_REQUEST['partenariats'] as $id_partenariat => $val)
        $frm->add_hidden("partenariats[".$id_partenariat."]","1");

Ayolo's avatar
Ayolo committed
630
631
632
633
    $frm->add_submit("submit","Enregistrer");
    $cts->add($frm);
    $site->add_contents($cts);
  }
Ayolo's avatar
Ayolo committed
634
635
636
637
638
639
640
}

elseif ($_REQUEST["action"] == "newstudent")
{
  /* on va lui creer un compte utilisateur */
  $user = new utilisateur($site->db, $site->dbrw);

641
642
643
644
645
  /* D'abord on desactive le cache de fastsearch histoire que
     l'etudiant soit immediatement accessible par fsearch */
  $cache = new fsearchcache ();
  $cache->disable_cache_temporarily (5);

Ayolo's avatar
Ayolo committed
646
647
648
  /* Si on a le nom d'une ecole parce que c'est un etudiant */
  $email_utbm_needed = false;
  if ($_REQUEST['ecoleform'] == "ecole")
Ayolo's avatar
Ayolo committed
649
650
651
652
653
654
  {
    $etudiant = true;
    $nom_ecole = $_REQUEST['ecole'];
    if ($_REQUEST['ecole'] == "UTBM")
      $email_utbm_needed = true;
  }
Ayolo's avatar
Ayolo committed
655
656
657
658
659
660
661
  /* cas d'un prof */
  elseif ($_REQUEST['ecoleform'] == "other")
  {
    $etudiant = false;
    $nom_ecole = "UTBM";
    $email_utbm_needed = true;
  }
Ayolo's avatar
Ayolo committed
662
  else
Ayolo's avatar
Ayolo committed
663
664
665
666
  {
    $nom_ecole = null;
    $etudiant = false;
  }
Ayolo's avatar
Ayolo committed
667
668
669

  /* Verif de disponibilite */
  if (!$user->is_email_avaible($_REQUEST['emailutbm']))
Ayolo's avatar
Ayolo committed
670
671
  {
    $cts = new contents("WARNING");
BenC's avatar
BenC committed
672
    $cts->set_toolbox(new toolbox(array("javascript:history.go(-1);"=>"Retour")));
Ayolo's avatar
Ayolo committed
673
674
675
676
    if(CheckEmail($_REQUEST['emailutbm'],3))
      $cts->add_paragraph("<img src=\"".$topdir."images/actions/info.png\">&nbsp;&nbsp;L'email existe d&eacute;j&agrave; v&eacute;rifier que l'utilisateur ne figure pas dans la liste de la base de donn&eacute;es commune !");
    else
      $cts->add_paragraph("<img src=\"".$topdir."images/actions/info.png\">&nbsp;&nbsp;L'email N'EST PAS VALIDE !!! avec toute sa sympathie, l'équipe informatique qui en a marre de corriger les erreurs de saisies.");
Ayolo's avatar
Ayolo committed
677
678
679
680
    $site->add_contents($cts,true);
    $site->end_page();
    exit();
  }
Ayolo's avatar
Ayolo committed
681

682
  $pass = null;
Ayolo's avatar
Ayolo committed
683
684
  $user->new_utbm_user($_REQUEST['nom'],
                       $_REQUEST['prenom'],
Feu's avatar
Feu committed
685
                       $_REQUEST['emailutbm'], $_REQUEST['emailutbm'],
686
                       $pass,null,null,null,
Ayolo's avatar
Ayolo committed
687
688
689
690
691
                       $etudiant,
                       $_REQUEST['droit_image']==true,
                       $nom_ecole);

  if ($user->id < 0)
Ayolo's avatar
Ayolo committed
692
693
  {
    $cts = new contents("WARNING");
BenC's avatar
BenC committed
694
    $cts->set_toolbox(new toolbox(array("javascript:history.go(-1);"=>"Retour")));
Ayolo's avatar
Ayolo committed
695
696
697
698
699
    $cts->add_paragraph("<img src=\"".$topdir."images/actions/delete.png\">&nbsp;&nbsp;Probleme lors de l'ajout de l'utilisateur".$user->id);
    $site->add_contents($cts,true);
    $site->end_page();
    exit();
  }
Ayolo's avatar
Ayolo committed
700
  else
Ayolo's avatar
Ayolo committed
701
702
  {
    $user->load_all_extra();
703
704
    $pcts = new contents("Informations de creation");
    $pcts->add_paragraph ('Nouvel utilisateur cree, mot de passe temporaire : '.$pass);
BenC's avatar
BenC committed
705
    $cts = new contents("Mise à jour des infos indispensable pour l'impression de la carte AE");
Ayolo's avatar
Ayolo committed
706
707
708
    $frm = new form("infos","cotisations.php?id_utilisateur=".$user->id,true,"POST",null);
    $frm->add_hidden("action","savecotiz");
    $frm->add_text_field("nom","Nom",$user->nom,true,false,false,false);
BenC's avatar
BenC committed
709
    $frm->add_text_field("prenom","Prénom",$user->prenom,true,false,false,false);
Ayolo's avatar
Ayolo committed
710
711
712
713
714
715
716
    $frm->add_text_field("surnom","Surnom (facultatif) ",$user->surnom);
    $sub_frm = add_user_info_form($user);
    $frm->add($sub_frm,false,false,false,false,false,true,true);
    $frm->add_hidden("cotiz",$_POST['cotiz']);
    $frm->add_hidden("paiement",$_POST['paiement']);
    $frm->add_hidden("droit",$_REQUEST["droit_image"]);
    $frm->add_hidden("cadeau",$_REQUEST["cadeau"]);
mbriand's avatar
mbriand committed
717
718
719
    if (isset($_REQUEST['partenariats']))
      foreach ($_REQUEST['partenariats'] as $id_partenariat => $val)
        $frm->add_hidden("partenariats[".$id_partenariat."]","1");
mbriand's avatar
mbriand committed
720

Ayolo's avatar
Ayolo committed
721
722
723
724
    $frm->add_submit("submit","Enregistrer");
    $cts->add($frm);
    $site->add_contents($cts);
  }
Ayolo's avatar
Ayolo committed
725
726
727
728
729
730
731
732
733
734
735
736
}

else
{
  $cts = add_search_form();
  $cts->add(add_new_form());
  $site->add_contents($cts);
}

$site->end_page ();

?>