views.php 10.2 KB
Newer Older
1
2
3
<?php

class Views {
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
    private $admin;
    private $utclogin;
    private $surname;
    private $firstname;

    public function __construct ($admin, $utclogin, $surname, $firstname) {
      $this->admin=$admin;
      $this->utclogin=$utclogin;
      $this->surname=$surname;
      $this->firstname=$firstname;
    }

    public function isActive() {
      return $this->admin->isActive();
19
20
    }

Stephane Crozat's avatar
Stephane Crozat committed
21
    public function printHtmlBegin($admin) {
stph's avatar
stph committed
22
23
24
25
26
      echo '<html>';
      echo '<head>';
      echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
      echo '<title>Api Sub</title>';
      echo '<link href="css/main.css" type="text/css" rel="stylesheet"/>';
stph's avatar
Add #28  
stph committed
27
      echo '<script src="js/main.js" defer></script>';
stph's avatar
stph committed
28
29
30
      echo '</head>';
      echo '<body>';
      echo '<h1>Foire aux Api '.$admin->activeSemester().$admin->activeYear().'</h1>';
31
32
    }

stph's avatar
stph committed
33
    public function printInstructions($admin) {
Stephane Crozat's avatar
Stephane Crozat committed
34
        echo '<hr/>';
stph's avatar
stph committed
35
36
        echo '<h2>Planning</h2>';
        echo '<p>Inscriptions ouvertes du '.$admin->openbegin().' au '.$admin->openend().'.</p>';
37
38
        echo '<h2>Catalogue</h2>';
        echo '<p>Les Api sont décrites ici : <b><a href="https://apint.utc.fr/cat">https://apint.utc.fr/cat</a></b>. Veillez à avoir bien lu la fiche avant de vous inscrire (pré-requis, dates...).</p>';
39
        echo '<h2>Instructions</h2>';
40
        echo '<ul>';
41
        echo '<li>Les Api sont ajoutées au fil du semestre par les responsables des Api. Dès qu\'une Api est au catalogue, les étudiants peuvent commencer à s\'inscrire.';
Stephane Crozat's avatar
Stephane Crozat committed
42
        echo '<li>Un étudiant peut s\'inscrire à plusieurs Api la même semaine, mais il ne pourra en suivre qu\'une seule. Il peut librement se désinscrire tant que l\'inscription n\'est pas validée.</li>';
43
        echo '<li><span class="goldenrule">Règle d\'or : dès qu\'un responsable d\'Api a validé une inscription, celle-ci est irréversible (ni l\'enseignant ni l\'étudiant ne peuvent l\'annuler). Si un étudiant était inscrit à d\'autres Api la même semaine, ces autres inscriptions sont annulées.</span></li>';
stph's avatar
stph committed
44
        echo '<li><span class="goldenrule">Corollaire : Si un responsable d\'Api commence à valider des inscriptions, alors l\'Api sera nécessairement ouverte.</span></li>';
45
        echo '</ul>';
46
47
    }

48
    public function printUser($isResp, $isAdmin) {
Stephane Crozat's avatar
Stephane Crozat committed
49
        echo "<div class='user'><span class='name'>$this->firstname $this->surname</span> (<span class='login'>$this->utclogin</span>)</div>";
Stephane Crozat's avatar
Stephane Crozat committed
50
51
        echo "<div class='menu'>";
        if ($isResp) {
52
          echo '<a href="index.php?mode=resp">[Gérer ses Api]</a> ';
53
54
        }
        if ($isAdmin) {
55
56
57
          echo '<a href="index.php?mode=admin">[Super-pouvoirs]</a> ';
        }
        if ($isResp || $isAdmin) {
Stephane Crozat's avatar
Stephane Crozat committed
58
          echo '<a href="index.php">[Inscriptions]</a>';
59
        }
Stephane Crozat's avatar
Stephane Crozat committed
60
        echo "</div>";
Stephane Crozat's avatar
Fix #1  
Stephane Crozat committed
61
62
    }

63
    private function printApi($row) {
stph's avatar
stph committed
64
      return "$row[normcode] - $row[name] (du $row[normdbegin] au $row[normdend]) (Demandes $row[nbask] | Inscriptions $row[nbval]/$row[size])";
65
66
67
68
    }

    private function printWeek($row) {
      return "$row[year] Semaine $row[week]";
69
    }
70

71
72
    private function printStudent($row) {
      if (!$row['surname']) {
Stephane Crozat's avatar
Stephane Crozat committed
73
        return "$row[utclogin] $row[level]  <a href='mailto:$row[utclogin]@etu.utc.fr'>[mail]</a> <a href='https://demeter.utc.fr/portal/pls/portal30/portal30.get_photo_utilisateur?username=$row[utclogin]'>[photo]</a>";
74
75
      }
      else {
Stephane Crozat's avatar
Stephane Crozat committed
76
        return "$row[firstname] $row[surname] $row[level] <a href='mailto:$row[email]'>[mail]</a> <a href='https://demeter.utc.fr/portal/pls/portal30/portal30.get_photo_utilisateur?username=$row[utclogin]'>[photo]</a>";
77
78
79
      }
    }

80
    public function printSubList($list) {
stph's avatar
stph committed
81
      echo '<hr/>';
82
83
      if ($list) {
        echo '<h2>Vos inscriptions</h2>';
84
        $week = '';
85
        foreach ($list as $row) {
86
87
88
89
          if ($row['week'] != $week) {
            $week = $row['week'];
            echo "<h3>".$this->printWeek($row)."</h3>";
          }
90
          echo '<p>';
Stephane Crozat's avatar
Stephane Crozat committed
91
92
93
94
95
96
97
98
          // If student has been validated
          if ($row['validation']) {
            echo "<span class='validation'>[validé]</span> ";
          }
          else {
            // If it has not been validated and subscription are still opened
            if ($this->isActive()) {
              $msg = 'désinscription';
99
            }
Stephane Crozat's avatar
Stephane Crozat committed
100
            // If it has not been validated and subscription are closed
101
            else {
Stephane Crozat's avatar
Stephane Crozat committed
102
103
              echo "<span class='validation'>[liste d'attente]</span> ";
              $msg = 'annulation';
104
            }
Stephane Crozat's avatar
Stephane Crozat committed
105
            echo "<a href='index.php?action=unsub&api=$row[id]' class='unsub'>[$msg]</a> ";
106
          }
107
          echo $this->printApi($row);
108
109
110
111
112
113
114
          echo '</p>';
        }
      }
      else {
        echo '<h2>Aucune inscription</h2>';
      }
    }
115

116
  public function printApiList($list) {
stph's avatar
stph committed
117
    echo '<hr/>';
stph's avatar
Add #28  
stph committed
118
    if ($list) {
119
      echo '<h2>Liste des Api</h2>';
120
      $week = '';
stph's avatar
Add #28  
stph committed
121
122
123
124
      foreach ($list as $api) {
        if ($api['week'] != $week) {
          $week = $api['week'];
          echo "<h3>".$this->printWeek($api)."</h3>";
125
        }
126
        echo '<p>';
127
        if ($this->isActive()) {
stph's avatar
Add #28  
stph committed
128
129
          if ($api['validation'] == 1) {
            echo "[validé] ";
130
          }
stph's avatar
Add #28  
stph committed
131
132
133
134
135
136
137
138
          elseif ($api['validation'] == 0.5) {
            echo "[en attente] ";
          }
          elseif ($api['validation'] == -1 || ! $api['is_available']) {
            echo "[<span class='impossible'>indisponible</span>] ";
          }
          elseif (! $api['open']) {
            echo "[<span class='impossible'>complet</span>] ";
139
140
          }
          else {
stph's avatar
Add #28  
stph committed
141
            echo "<a href='index.php?action=sub&api=$api[id]' class='sub'>[inscription]</a> ";
142
          }
143
        }
stph's avatar
Add #28  
stph committed
144
        echo $this->printApi($api);
145
146
147
148
149
150
151
        echo '</p>';
      }
    }
    else {
      echo '<h2>Aucune Api</h2>';
    }
  }
Stephane Crozat's avatar
Fix #1  
Stephane Crozat committed
152

153
  public function respValidation ($listsub) {
154
    // #KNOWN_BUG Si un resp a plusieurs Api, il peut changer un inscrit entre ses deux Api en modifiant l'URL (pas via l'interface)
Stephane Crozat's avatar
Stephane Crozat committed
155
156
157
158
159
160

    echo '<h1>Interface Responsable d\'Api</h1>';
    echo '<hr/>';
    echo '<h2>Rappel</h2>';
    echo '<ul>';
    echo '<li>La validation d\'une inscription entraîne la confirmation de l\'ouverture de l\'Api.</li>';
stph's avatar
Add #28  
stph committed
161
    echo '<li>Toute inscription validée ou déclinée est irréversible.</li>';
Stephane Crozat's avatar
Stephane Crozat committed
162
    echo '</ul>';
163
164
165
166
167
    if ($listsub) {
      $api = '';
      foreach ($listsub as $sub) {
        if ($api != $sub['id']) {
          $api = $sub['id'];
Stephane Crozat's avatar
Stephane Crozat committed
168
          echo '<hr/>';
stph's avatar
stph committed
169
170
          echo "<h2>".$this->printApi($sub)."<a href='api.php?api=$api'> [listing]</a></h2>";
          echo "<h3></h3>";
171
        }
172
173
174
        if ($sub['utclogin']) {
          if ($sub['validation']) {
            // Subscription already validated
175
            echo '<p><b>[validé] </b>'.$this->printStudent($sub).'</p>';
176
177
178
          }
          else if (is_null($sub['validation'])) {
            // At least one waiting subscription
stph's avatar
Add #28  
stph committed
179
180
181
182
183
184
            echo "<p>
              <a href='index.php?action=validate&api=$sub[id]&login=$sub[utclogin]&mode=resp' class='valid'>[valider]</a> "
              .$this->printStudent($sub).
              " <span>Exclusivité : $sub[indicator]%</span>
              <a href='index.php?action=decline&api=$sub[id]&login=$sub[utclogin]&mode=resp' class='decline'>[décliner]</a>
              </p>";
185
186
187
188
189
190
191
192
193
          }
          else {
            // validation = FALSE lignes ignored
          }
        }
        else {
          // Not yet any subscription for this Api (LEFT JOIN might have add null student line)
          echo "<p>Aucune inscription à gérer</p>";
        }
194
195
196
197
198
      }
    }
    else {
      echo "<p>Aucune Api à gérer</p>";
    }
199
200
  }

Stephane Crozat's avatar
Stephane Crozat committed
201
202
203
  public function apiStudents($students) {
    echo "<hr/>";
    if (isset($students[0])) {
204
      // Api Title
Stephane Crozat's avatar
Stephane Crozat committed
205
      echo '<h2>'.$this->printApi($students[0]).'</h2>';
206
      // Api mailing list
207
208
209
210
      $mailinglist='mailto:';
      foreach ($students as $s) {
        $mailinglist = $mailinglist."$s[email],";
      }
211
212
213
214
215
216
217
218
      // Api CSV data (for JavaScript function)
      echo "<script>var csvstudents = [['Nom','Prénom','Niveau','Mail','Login'],";
      foreach ($students as $s) {
        echo "['$s[surname]','$s[firstname]','$s[level]','$s[email]','$s[utclogin]'],";
      }
      echo "];</script>";
      // Api Menu
      echo "<div class='menu'><a href='$mailinglist'>[Mailing list]</a> <a id='csvlink' onclick='download_csv(csvstudents)' href=''>[Fichier CSV]</a></div>";
219
      echo "<hr/>";
Stephane Crozat's avatar
Stephane Crozat committed
220
221
    }
    else {
222
      echo '<h2>Aucun inscrit validé</h2>';
Stephane Crozat's avatar
Stephane Crozat committed
223
224
225
226
    }
    foreach ($students as $s) {
      echo "<div class='student'>
        <img  src='https://demeter.utc.fr/portal/pls/portal30/portal30.get_photo_utilisateur?username=$s[utclogin]'
stph's avatar
stph committed
227
228
              height='0px'
              width='0px'/>
Stephane Crozat's avatar
Stephane Crozat committed
229
230
231
232
233
234
235
236
237
238
239
240
        <span class='name'>$s[surname] $s[firstname] | $s[level] | <a href='mailto:$s[email]'>$s[email]</a> ($s[utclogin])</span>
        </div>";
    }
  }

  public function apiStudentsCsv($students) {
    //TODO
    foreach ($students as $s) {
        echo "$s[surname];$s[firstname];$s[level];$s[email];$s[utclogin]\n";
    }
  }

241
242
243
244
245
246
  private function prepare ($value, $comma=true) {
     $v = '"'.addslashes($value).'"';
     if ($comma) $v = $v.',';
     return $v;
  }

247
248
249
  public function adminFunction ($utclogin, $mailresp, $students) {
    echo '<h2>Super-pouvoirs</h2>';
    // Resp Emails
stph's avatar
stph committed
250
    echo '<h3>Mails aux responsables d\'Api</h3>';
251
    echo '<div>';
252
253
254
255
256
257
    $all = '';
    foreach ($mailresp as $m) {
        echo "<a href='mailto:$m[email]'>$m[email]</a> |";
        $all = "$all,$m[email]";
    }
    echo "<b><a href='mailto:$all'>[all]</a></b>";
258
259
260
261
    echo '</div>';
    // Student list
    echo '<h3>Liste des inscrits</h3>';
    echo '<script src="js/main.js"></script>';
262
    echo '<script>var csvstudents = [["Semaine","Code","Api","Nom","Prénom","Niveau","Mail","Login"],';
263
    foreach ($students as $s) {
264
265
266
267
268
269
270
271
272
273
      echo "["
        .$this->prepare($s["week"])
        .$this->prepare($s["normcode"])
        .$this->prepare($s["name"])
        .$this->prepare($s["firstname"])
        .$this->prepare($s["surname"])
        .$this->prepare($s["level"])
        .$this->prepare($s["email"])
        .$this->prepare($s["utclogin"], false)
        ."],";
274
275
276
277
    }
    echo "];</script>";
    // Api Menu
    echo "<div><a id='csvlink' onclick='download_csv(csvstudents)' href=''>[Fichier CSV]</a></div>";
278
  }
279
}