views.php 9.24 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) {
22
23
24
25
26
27
28
    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>';
Stephane Crozat's avatar
Stephane Crozat committed
29
    echo '<h1>Foire aux Api '.$admin->activeSemester().$admin->activeYear().'</h1>';
30
31
    }

32
    public function printInstructions($row) {
Stephane Crozat's avatar
Stephane Crozat committed
33
        echo '<hr/>';
34
35
        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>';
36
        echo '<h2>Instructions</h2>';
37
        echo '<ul>';
38
        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
39
        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>';
40
41
        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>';
42
        echo '</ul>';
43
44
    }

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

60
    private function printApi($row) {
61
62
63
64
65
      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]";
66
    }
67

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

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

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

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

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

Stephane Crozat's avatar
Stephane Crozat committed
186
187
188
  public function apiStudents($students) {
    echo "<hr/>";
    if (isset($students[0])) {
189
      // Api Title
Stephane Crozat's avatar
Stephane Crozat committed
190
      echo '<h2>'.$this->printApi($students[0]).'</h2>';
191
      // Api mailing list
192
193
194
195
      $mailinglist='mailto:';
      foreach ($students as $s) {
        $mailinglist = $mailinglist."$s[email],";
      }
196
197
198
199
200
201
202
203
204
      // 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>";
205
      echo "<hr/>";
Stephane Crozat's avatar
Stephane Crozat committed
206
207
    }
    else {
208
      echo '<h2>Aucun inscrit validé</h2>';
Stephane Crozat's avatar
Stephane Crozat committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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]'
              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";
    }
  }

227
228
229
230
  public function adminFunction ($utclogin, $mailresp, $students) {
    echo '<h2>Super-pouvoirs</h2>';
    // Resp Emails
    echo '<h3>Mails aux reponsables d\'Api</h3>';
231
    echo '<div>';
232
233
234
235
236
237
    $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>";
238
239
240
241
    echo '</div>';
    // Student list
    echo '<h3>Liste des inscrits</h3>';
    echo '<script src="js/main.js"></script>';
242
    echo "<script>var csvstudents = [['Semaine','Code','Api','Nom','Prénom','Niveau','Mail','Login'],";
243
    foreach ($students as $s) {
244
      echo "['$s[week]','$s[normcode]','$s[name]','$s[surname]','$s[firstname]','$s[level]','$s[email]','$s[utclogin]'],";
245
246
247
248
    }
    echo "];</script>";
    // Api Menu
    echo "<div><a id='csvlink' onclick='download_csv(csvstudents)' href=''>[Fichier CSV]</a></div>";
249
  }
250
}