views.php 9.73 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
27
28
29
      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"/>';
      echo '</head>';
      echo '<body>';
      echo '<h1>Foire aux Api '.$admin->activeSemester().$admin->activeYear().'</h1>';
30
31
    }

stph's avatar
stph committed
32
    public function printInstructions($admin) {
Stephane Crozat's avatar
Stephane Crozat committed
33
        echo '<hr/>';
stph's avatar
stph committed
34
35
        echo '<h2>Planning</h2>';
        echo '<p>Inscriptions ouvertes du '.$admin->openbegin().' au '.$admin->openend().'.</p>';
36
37
        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>';
38
        echo '<h2>Instructions</h2>';
39
        echo '<ul>';
40
        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
41
        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>';
42
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>';
        echo '<li><span class="goldenrule">Corrolaire : Si un reponsable d\'Api commence à valider des inscriptions, alors l\'Api sera nécessairement ouverte.</span></li>';
44
        echo '</ul>';
45
46
    }

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

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

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

70
71
    private function printStudent($row) {
      if (!$row['surname']) {
Stephane Crozat's avatar
Stephane Crozat committed
72
        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>";
73
74
      }
      else {
Stephane Crozat's avatar
Stephane Crozat committed
75
        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>";
76
77
78
      }
    }

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

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

146
  public function respValidation ($listsub) {
147
    // #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
148
149
150
151
152
153
154
155

    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>';
    echo '<li>Toute inscription validée est irréversible.</li>';
    echo '</ul>';
156
157
158
159
160
    if ($listsub) {
      $api = '';
      foreach ($listsub as $sub) {
        if ($api != $sub['id']) {
          $api = $sub['id'];
Stephane Crozat's avatar
Stephane Crozat committed
161
          echo '<hr/>';
Stephane Crozat's avatar
Stephane Crozat committed
162
          echo "<h2><a href='api.php?api=$api'>".$this->printApi($sub).' 📷</a></h2>';
163
        }
164
165
166
        if ($sub['utclogin']) {
          if ($sub['validation']) {
            // Subscription already validated
167
            echo '<p><b>[validé] </b>'.$this->printStudent($sub).'</p>';
168
169
170
          }
          else if (is_null($sub['validation'])) {
            // At least one waiting subscription
Stephane Crozat's avatar
Stephane Crozat committed
171
            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></p>";
172
173
174
175
176
177
178
179
180
          }
          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>";
        }
181
182
183
184
185
      }
    }
    else {
      echo "<p>Aucune Api à gérer</p>";
    }
186
187
  }

Stephane Crozat's avatar
Stephane Crozat committed
188
189
190
  public function apiStudents($students) {
    echo "<hr/>";
    if (isset($students[0])) {
191
      // Api Title
Stephane Crozat's avatar
Stephane Crozat committed
192
      echo '<h2>'.$this->printApi($students[0]).'</h2>';
193
      // Api mailing list
194
195
196
197
      $mailinglist='mailto:';
      foreach ($students as $s) {
        $mailinglist = $mailinglist."$s[email],";
      }
198
199
200
201
202
203
204
205
206
      // Api CSV data (for JavaScript function)
      echo '<script src="js/main.js"></script>';
      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>";
207
      echo "<hr/>";
Stephane Crozat's avatar
Stephane Crozat committed
208
209
    }
    else {
210
      echo '<h2>Aucun inscrit validé</h2>';
Stephane Crozat's avatar
Stephane Crozat committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    }
    foreach ($students as $s) {
      echo "<div class='student'>
        <img  src='https://demeter.utc.fr/portal/pls/portal30/portal30.get_photo_utilisateur?username=$s[utclogin]'
              height='100px'
              width='100px'/>
        <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";
    }
  }

229
230
231
232
233
234
  private function prepare ($value, $comma=true) {
     $v = '"'.addslashes($value).'"';
     if ($comma) $v = $v.',';
     return $v;
  }

235
236
237
238
  public function adminFunction ($utclogin, $mailresp, $students) {
    echo '<h2>Super-pouvoirs</h2>';
    // Resp Emails
    echo '<h3>Mails aux reponsables d\'Api</h3>';
239
    echo '<div>';
240
241
242
243
244
245
    $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>";
246
247
248
249
    echo '</div>';
    // Student list
    echo '<h3>Liste des inscrits</h3>';
    echo '<script src="js/main.js"></script>';
250
    echo '<script>var csvstudents = [["Semaine","Code","Api","Nom","Prénom","Niveau","Mail","Login"],';
251
    foreach ($students as $s) {
252
253
254
255
256
257
258
259
260
261
      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)
        ."],";
262
263
264
265
    }
    echo "];</script>";
    // Api Menu
    echo "<div><a id='csvlink' onclick='download_csv(csvstudents)' href=''>[Fichier CSV]</a></div>";
266
  }
267
}