index.php 1.4 KB
Newer Older
stc's avatar
stc committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?php
session_start();

if (!isset($_SESSION['ticket'])) {
  /*  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';
  $cas = new CAS('https://cas.utc.fr/cas/','https');
  $info = CAS::authenticate();
  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'];
  }
  else
    CAS::login();
}

include $_SERVER['DOCUMENT_ROOT'].'/apisub/lib/db.php';
$db = new DB();
$db->printHtmlBegin();
$db->printUser($_SESSION['utclogin'], $_SESSION['surname'], $_SESSION['firstname']);

if (isset($_GET['api']) && isset($_GET['utclogin'])) {
  if (isset($_GET['action'])) {
    if ($_GET['action']=='sub') {
      $db->subToApi($_GET['utclogin'], $_GET['api']);
    }
    elseif ($_GET['action']=='unsub') {
      $db->unsubToApi($_GET['utclogin'], $_GET['api']);
    }
  }
}

$db->subList($_SESSION['utclogin']);
$db->apiList($_SESSION['utclogin'], 'H', 2019);

?>