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

Stéphane Crozat's avatar
Stéphane Crozat committed
4
5
6
$DEVMODE = True;

if (!$DEVMODE && !isset($_SESSION['ticket'])) {
stc's avatar
stc committed
7
8
9
10
11
12
13
  /*  If session is already open for current PHP file, user is already logged in, do nothing
      If session is not open on current PHP file, check if it is open on CAS server
        If it is open on CAS server retrieve session informations
        If it is not on open on CAS server, ask for login to CAS server
  */

  include $_SERVER['DOCUMENT_ROOT'].'/apisub/lib/cas.php';
14
15
  $cas = new CAS('https://cas.utc.fr/cas/','http');
  $info = $cas->authenticate();
stc's avatar
stc committed
16
17
18
19
20
21
22
  if ($info != -1) 	{
    $_SESSION['ticket'] = $_GET['ticket'];
    $_SESSION['utclogin'] = $info['cas:user'];
    $_SESSION['mail'] = $info['cas:attributes']['cas:mail'];
    $_SESSION['surname'] = strtoupper($info['cas:attributes']['cas:sn']);
    $_SESSION['firstname'] = $info['cas:attributes']['cas:givenName'];
  }
23
  else {
24
    $cas->login();
25
26
  }
  $_SESSION['localcopy'] =  true; //call localcopy once per session
stc's avatar
stc committed
27
}
Stéphane Crozat's avatar
Stéphane Crozat committed
28
29
30
31
32
33
34
else {
  $_SESSION['ticket'] = '-1';
  $_SESSION['utclogin'] = 'crozatst';
  $_SESSION['mail'] = 'dev@mail.fr';
  $_SESSION['surname'] = 'Crozat/dev';
  $_SESSION['firstname'] = 'Stéphane/dev';
}
stc's avatar
stc committed
35

36
include 'lib/db.php';
37
include 'lib/views.php';
38
include 'lib/admin.php';
39

stc's avatar
stc committed
40
$db = new DB();
41
if ($_SESSION['localcopy']) {
42
  $db->copyUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname'], $_SESSION['mail']);
43
44
  $_SESSION['localcopy']=false;
}
45
46
47
48
49
$admin = new Admin($db);
$view = new Views($admin, $_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);

$view->printHtmlBegin();
$view->printUser($db->isResp($_SESSION['utclogin']), $db->isAdmin($_SESSION['utclogin']));
50
51
52

if (isset($_GET['mode'])) {
  if ($_GET['mode']=='resp') {
53
54
    if (isset($_GET['action']) && isset($_GET['api']) && isset($_GET['login'])) {
      if ($_GET['action']=='validate') {
55
        $db->validate($_SESSION['utclogin'], $_GET['api'], $_GET['login']);
56
57
      }
    }
58
    $view->respValidation($db->apiListResp($admin, $_SESSION['utclogin']));
59
60
61
62
63
  }
  if ($_GET['mode']=='admin') {
    $view->adminFunction($_SESSION['utclogin']);
  }
}
64
65
66
67
68
else {
  /** Subscription and unsubscription management **/
  if (isset($_GET['api']) && $admin->isActive()) {
    if (isset($_GET['action'])) {
      if ($_GET['action']=='sub') {
69
        $db->subToApi($admin, $_SESSION['utclogin'], $_GET['api']);
70
71
72
73
      }
      elseif ($_GET['action']=='unsub') {
        $db->unsubToApi($_SESSION['utclogin'], $_GET['api']);
      }
stc's avatar
stc committed
74
75
    }
  }
76
77
  $view->printInstructions($db->config());
  $view->printSubList($db->subList($_SESSION['utclogin']));
78
  $view->printApiList($db->apiList($admin, $_SESSION['utclogin']));
stc's avatar
stc committed
79
80
}
?>