planning.php 5.39 KB
Newer Older
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
31
32
33
34
35
36
<?php

/* Copyright 2010
 * - Mathieu Briand < briandmathieu AT hyprua DOT org >
 *
 * 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");


$site = new site ();

if (!$site->user->is_in_group ("gestion_ae"))
  $site->error_forbidden();

if ($_REQUEST['action'] == "pdf")
{
37
38
39
40
41
42
  require_once($topdir. "include/pdf/planning_news.inc.php");

  $pdf = new pdfplanning_news($_REQUEST['title']);

  foreach($_REQUEST['news'] as $jour => $num_textes)
  {
43
    $textes = array();
44
    foreach($num_textes as $num_texte => $bleh)
45
46
47
48
49
      $textes[] = $_REQUEST['textes'][$num_texte];
    $pdf->add_day($jour, $textes);
  }

  $pdf->Output();
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  exit();
}

$site->start_page("none", "Génération d'un planning de la semaine");

/* Deuxième formulaire : on choisit les évènements
 */
if ($_REQUEST['action'] == "choix_even")
{
  $firstday = $_REQUEST['date'];

  if (date("N", $firstday) != 1)
    $firstday = strtotime("last Monday", $firstday);
  $lastday = strtotime("next Sunday", $firstday);

65
  $title = "Planning du ".strftime("%A %d %B", $firstday)." au ".strftime("%A %d %B", $lastday);
66
67
68
69
70
71
72
73
74

  $frm = new form ("createplaning", "planning.php", false, "POST", "Création d'un planning");
  $frm->add_hidden("action", "pdf");
  $frm->add_hidden("date", $firstday);
  $frm->add_text_field("title", "Titre", $title, true);

  /* Pour chaque jour on permet de choisir parmis la liste des nouvelles
  */
  $date = $firstday;
mbriand's avatar
Miaou ?    
mbriand committed
75
  $i = 0;
76
77
78
79
80
  do
  {
    /* On ne cherche que dans les nouvelles ponctuelles ou répétitives
     * si elles ont commencées avant le jour concerné, elles doivent se finir après 10h00
     */
81
    $req = new requete($site->db, "
82
      SELECT id_nouvelle, titre_nvl, date_debut_eve, id_lieu, nom_lieu
83
84
      FROM `nvl_dates`
      INNER JOIN `nvl_nouvelles` USING (`id_nouvelle`)
85
      LEFT JOIN `loc_lieu` USING ( `id_lieu` )
86
87
88
89
90
91
92
93
      WHERE
        (
          (date_debut_eve > '".date("Y-m-d", $date)." 00:00'
          AND date_debut_eve < '".date("Y-m-d", $date)." 24:00')
        OR
          (date_debut_eve < '".date("Y-m-d", $date)." 00:00'
          AND date_fin_eve > '".date("Y-m-d", $date)." 10:00')
        )
94
        AND `type_nvl` IN ( 1, 2 )");
95
96
97
98

    if ($req->lines > 0)
    {
      $subfrm = new subform("createplaning_".date("N", $date),
99
                            strftime("%A %d %B", $date));
100
101
102
      while($row = $req->get_row())
      {
        $txt = "";
103

104
105
        $time = strtotime($row['date_debut_eve']);
        if ($time > $date)
106
          $txt .= date("G:i", $time);
107
108
109
110
111
112
113
114
115

        if ($row['id_lieu'] != null)
        {
          if ($txt != "")
            $txt .= ", ";
          $txt .= $row['nom_lieu']." : ";
        }
        elseif ($txt != "")
          $txt .= " : ";
116
117
118

        $txt .= $row['titre_nvl'];

mbriand's avatar
Miaou ?    
mbriand committed
119
        $subfrm->add_checkbox("news[".date("N", $date)."|".$i."]", $row['titre_nvl'], true);
mbriand's avatar
Miaou ?    
mbriand committed
120
        $subfrm->add_text_field("textes[".$i."]", "", $txt, true);
121
        $i++;
122
123
      }

124
      $frm->addsub($subfrm, false);
125
126
127
128
129
130
131
132
    }

    $date = strtotime("+1 day", $date);
  } while (date("N", $date) != 1);


  /* On affiches les nouvelles longues
  */
133
  $req = new requete($site->db, "
134
135
136
137
138
    SELECT id_nouvelle, titre_nvl, date_debut_eve, date_fin_eve
    FROM `nvl_dates`
    INNER JOIN `nvl_nouvelles` USING (`id_nouvelle`)
    WHERE date_debut_eve < '".date("Y-m-d", $lastday)." 24:00'
      AND date_fin_eve > '".date("Y-m-d", $firstday)." 00:00'
139
      AND `type_nvl` = 0");
140
141
142

  if ($req->lines > 0)
  {
143
    $subfrm = new subform("createplaning_sem", "Toute la semaine");
144
145
146
    while($row = $req->get_row())
    {
      $txt = "";
147

148
149
150
151
152
153
154
155
156
157
158
159
      $time1 = strtotime($row['date_debut_eve']);
      $time2 = strtotime($row['date_fin_eve']);

      if (($time1 > $firstday ) && ($time2 < $lastday ))
        $txt .= "De ".strftime("%A", $time1)." à ".strftime("%A", $time2)." : ";
      elseif ($time1 > $firstday )
        $txt .= "À partir de ".strftime("%A", $time1)." : ";
      elseif ($time2 < $lastday )
        $txt .= "Jusqu'à ".strftime("%A", $time2)." : ";

      $txt .= $row['titre_nvl'];

160
      $subfrm->add_checkbox("news[sem][".$i."]", $row['titre_nvl'], true);
mbriand's avatar
Miaou ?    
mbriand committed
161
      $subfrm->add_text_field("textes[".$i."]", "", $txt, true);
162
      $i++;
163
164
    }

165
    $frm->addsub($subfrm, false);
166
167
168
169
170
171
172
173
174
175
176
177
178
  }


  $frm->add_submit("valid","Générer");

  $site->add_contents ($frm);
}
/* Premier formulaire : on choisit la date du planning
 */
else
{
  $frm = new form ("createplaning","planning.php",false,"POST","Création d'un planning");
  $frm->add_hidden("action","choix_even");
179
  $frm->add_date_field("date","Semaine concernée", time(), true);
180
181
182
183
184
185
186
187
188

  $frm->add_submit("valid","Choisir les évènements");

  $site->add_contents ($frm);
}

$site->end_page();

?>