recherche_creneau.php 5.31 KB
Newer Older
slopez's avatar
slopez committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
 * Copyright 2008
 * - Manuel Vonthron  <manuel DOT vonthron AT acadis DOT org>
 * - Pierre Mauduit <pierre POINT mauduit CHEZ utbm POINT fr>
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * 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 = "../";

require_once($topdir . "include/site.inc.php");
require_once("include/pedagogie.inc.php");
require_once("include/pedag_user.inc.php");
slopez's avatar
slopez committed
31
require_once("include/cts/edt_render.inc.php");
slopez's avatar
slopez committed
32
33
34
35
36
37
38

$site = new site();
$site->add_js("pedagogie/pedagogie.js");
$site->allow_only_logged_users();

$site->start_page("services", "AE Pédagogie");
$user = new pedag_user($site->db);
slopez's avatar
slopez committed
39
$id_utls = array(1827);//,2536,4040,3458);
slopez's avatar
slopez committed
40
41

$lines = array();
slopez's avatar
slopez committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$horraires = array('08:00',
                   '09:00',
                   '10:00',
                   '10:15',
                   '11:15',
                   '12:15',
                   '13:00',
                   '14:00',
                   '15:00',
                   '16:00',
                   '16:15',
                   '17:15',
                   '18:15',
                   '19:15',
                   '20:15');
slopez's avatar
slopez committed
57
58
59
60
61
$jours = array('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi');
$oqp = array();
foreach($jours as $jour)
{
  $oqp[$jour]=array();
slopez's avatar
slopez committed
62
  foreach($horraires as $horraire)
slopez's avatar
slopez committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    $oqp[$jour][$horraire]=array('A'=>0,'B'=>0);
}
foreach($id_utls as $id_utl)
{
  $user->load_by_id($id_utl);
  if($user->is_valid())
  {
    if(in_array(SEMESTER_NOW, $user->get_edt_list()))
    {
      $groups = $user->get_groups_detail(SEMESTER_NOW);
      if(!empty($groups))
      {
        foreach($groups as $group)
        {
          $jour  = get_day($group['jour']);
          $debut = substr($group['debut'], 0,5);
          $fin   = substr($group['fin'], 0, 5);
          $sem   = $group['semaine'];
          $add   = 0;
slopez's avatar
slopez committed
82
          foreach($horraires as $horraire)
slopez's avatar
slopez committed
83
84
          {
            if($horraire==$debut)
slopez's avatar
slopez committed
85
            {
slopez's avatar
slopez committed
86
              $add = 1;
slopez's avatar
slopez committed
87
            }
slopez's avatar
slopez committed
88
89
            if(is_null($sem))
            {
slopez's avatar
slopez committed
90
91
              $oqp[$jour][$horraire]['A']+=$add;
              $oqp[$jour][$horraire]['B']+=$add;
slopez's avatar
slopez committed
92
93
            }
            else
slopez's avatar
slopez committed
94
              $oqp[$jour][$horraire][$sem]+=$add;
slopez's avatar
slopez committed
95
96
97
98
99
100
101
102
103
104
105
106
107
            if($horraire==$fin)
            {
              $add = 0;
              break;
            }
          }
        }
      }
    }
  }
}

$free = array();
slopez's avatar
slopez committed
108
foreach($oqp as $jour => $_horraires)
slopez's avatar
slopez committed
109
110
111
112
113
{
  $startA = false;
  $startB = false;
  $lastA = false;
  $lastB = false;
slopez's avatar
slopez committed
114
  foreach($_horraires as $horraire => $_oqp)
slopez's avatar
slopez committed
115
  {
slopez's avatar
slopez committed
116
    if((int)$_oqp['A']==0)
slopez's avatar
slopez committed
117
118
119
120
    {
      $lastA=$horraire;
      if(!$startA)
        $startA=$horraire;
slopez's avatar
slopez committed
121
    }
slopez's avatar
slopez committed
122
    elseif((int)$_oqp['B']==0)
slopez's avatar
slopez committed
123
124
    {
      $lastB=$horraire;
slopez's avatar
slopez committed
125
      if(!$startB)
slopez's avatar
slopez committed
126
        $startB=$horraire;
slopez's avatar
slopez committed
127
    }
slopez's avatar
slopez committed
128
    elseif((int)$_oqp['B']>0)
slopez's avatar
slopez committed
129
130
131
132
133
134
135
136
137
138
139
140
    {
      if($startB && $startB!=$lastB)
      {
        $free[] = array("semaine_seance" =>'B',
                        "hr_deb_seance"  => $startB,
                        "hr_fin_seance"  => $lastB,
                        "jour_seance"    => $jour,
                        "type_seance"    => '',
                        "grp_seance"     => 0,
                        "nom_uv"         => '',
                        "salle_seance"   => '');
      }
slopez's avatar
slopez committed
141
142
      $startB = false;
      $lastB = false;
slopez's avatar
slopez committed
143
    }
slopez's avatar
slopez committed
144
    elseif((int)$_oqp['A']>0)
slopez's avatar
slopez committed
145
146
147
148
149
150
151
152
153
154
155
156
    {
      if($startA && $startA!=$lastA)
      {
        $free[] = array("semaine_seance" =>'A',
                        "hr_deb_seance"  => $startA,
                        "hr_fin_seance"  => $lastA,
                        "jour_seance"    => $jour,
                        "type_seance"    => '',
                        "grp_seance"     => 0,
                        "nom_uv"         => '',
                        "salle_seance"   => '');
      }
slopez's avatar
slopez committed
157
158
      $startA = false;
      $lastA = false;
slopez's avatar
slopez committed
159
160
    }
  }
slopez's avatar
slopez committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  if($startB && $startB!=$lastB)
  {
    $free[] = array("semaine_seance" =>'B',
                    "hr_deb_seance"  => $startB,
                    "hr_fin_seance"  => $lastB,
                    "jour_seance"    => $jour,
                    "type_seance"    => '',
                    "grp_seance"     => 0,
                    "nom_uv"         => '',
                    "salle_seance"   => '');
  }
  if($startA && $startA!=$lastA)
  {
    $free[] = array("semaine_seance" =>'B',
                    "hr_deb_seance"  => $startA,
                    "hr_fin_seance"  => $lastA,
                    "jour_seance"    => $jour,
                    "type_seance"    => '',
                    "grp_seance"     => 0,
                    "nom_uv"         => '',
                    "salle_seance"   => '');
  }
slopez's avatar
slopez committed
183
184
185
186
187
188
}
$edt = new edt_img('Créneaux disponibles', $free);
$edt->generate(false);
exit;

?>