planning.php 5.08 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?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")
{
  print_r($_REQUEST);
  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);

53
  $title = "Planning du ".strftime("%A %d %B", $firstday)." au ".strftime("%A %d %B", $lastday);
54
55
56
57
58
59
60
61
62
63
64
65
66
67

  $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;
  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
     */
68
    $req = new requete($site->db, "
69
      SELECT id_nouvelle, titre_nvl, date_debut_eve, id_lieu, nom_lieu
70
71
      FROM `nvl_dates`
      INNER JOIN `nvl_nouvelles` USING (`id_nouvelle`)
72
      LEFT JOIN `loc_lieu` USING ( `id_lieu` )
73
74
75
76
77
78
79
80
      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')
        )
81
        AND `type_nvl` IN ( 1, 2 )", 1);
82
83
84
85

    if ($req->lines > 0)
    {
      $subfrm = new subform("createplaning_".date("N", $date),
86
                            strftime("%A %d %B", $date), true);
87
88
89
90
91
      while($row = $req->get_row())
      {
        $txt = "";
        $time = strtotime($row['date_debut_eve']);
        if ($time > $date)
92
93
94
95
96
97
98
99
100
101
          $txt .= strftime("%G:%i", $date);

        if ($row['id_lieu'] != null)
        {
          if ($txt != "")
            $txt .= ", ";
          $txt .= $row['nom_lieu']." : ";
        }
        elseif ($txt != "")
          $txt .= " : ";
102
103
104

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

105
106
        $subfrm->add_checkbox("news[".$row['id_nouvelle']."]", $row['titre_nvl'], true);
        $subfrm->add_text_field("textes[".$row['id_nouvelle']."]", "Texte", $txt, true);
107
108
      }

109
      $frm->addsub($subfrm);
110
111
112
113
114
115
116
117
    }

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


  /* On affiches les nouvelles longues
  */
118
  $req = new requete($site->db, "
119
120
121
122
123
124
125
126
127
    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'
      AND `type_nvl` = 3");

  if ($req->lines > 0)
  {
128
    $subfrm = new subform("createplaning_sem", "Toute la semaine", true);
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    while($row = $req->get_row())
    {
      $txt = "";
      $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'];

144
145
      $subfrm->add_checkbox("news[".$row['id_nouvelle']."]", $row['titre_nvl'], true);
      $subfrm->add_text_field("textes[".$row['id_nouvelle']."]", "Texte", $txt, true);
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    }

    $frm->addsub($subfrm);
  }


  $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");
162
  $frm->add_date_field("date","Semaine concernée", time(), true);
163
164
165
166
167
168
169
170
171

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

  $site->add_contents ($frm);
}

$site->end_page();

?>