index.php 1.69 KB
Newer Older
stc's avatar
stc committed
1 2 3
<?php
session_start();

4
include 'lib/cas_connect.php';
stc's avatar
stc committed
5

6
include 'lib/db.php';
7
include 'lib/views.php';
8
include 'lib/admin.php';
9

stc's avatar
stc committed
10
$db = new DB();
11
//if ($_SESSION['localcopy']) {
12
  $db->copyUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname'], $_SESSION['mail']);
13
  $_SESSION['localcopy']=false;
14
//}
15 16 17
$admin = new Admin($db);
$view = new Views($admin, $_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);

Stephane Crozat's avatar
Stephane Crozat committed
18
$view->printHtmlBegin($admin);
19
$view->printUser($db->isResp($_SESSION['utclogin']), $db->isAdmin($_SESSION['utclogin']));
20 21 22

if (isset($_GET['mode'])) {
  if ($_GET['mode']=='resp') {
23 24
    if (isset($_GET['action']) && isset($_GET['api']) && isset($_GET['login'])) {
      if ($_GET['action']=='validate') {
stph's avatar
Add #28  
stph committed
25 26 27 28
        $db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login'], 'TRUE');
      }
      elseif ($_GET['action']=='decline') {
        $db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login'], 'FALSE');
29 30
      }
    }
31
    $view->respValidation($db->apiListResp($admin, $_SESSION['utclogin']));
32 33
  }
  if ($_GET['mode']=='admin') {
34
    $view->adminFunction($_SESSION['utclogin'], $db->mailresp(), $db->apiStudentsAll());
35 36
  }
}
37 38
else {
  /** Subscription and unsubscription management **/
Stephane Crozat's avatar
Stephane Crozat committed
39
  if (isset($_GET['api'])) {
40
    if (isset($_GET['action'])) {
Stephane Crozat's avatar
Stephane Crozat committed
41
      if ($_GET['action']=='sub' && $admin->isActive()) {
42
        $db->subToApi($admin, $_SESSION['utclogin'], $_GET['api']);
43 44 45 46
      }
      elseif ($_GET['action']=='unsub') {
        $db->unsubToApi($_SESSION['utclogin'], $_GET['api']);
      }
stc's avatar
stc committed
47 48
    }
  }
stph's avatar
stph committed
49
  $view->printInstructions($admin);
50
  $view->printSubList($db->subList($_SESSION['utclogin']));
51
  $view->printApiList($db->apiList($admin, $_SESSION['utclogin']));
stc's avatar
stc committed
52 53
}
?>