Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
324 lines (299 sloc) 6.92 KB
<?php
require_once("user.class.php");
header('Content-Type: text/html; charset=utf-8');
define("SEPARATOR", ":_:");
define("VERSION", 4.6);
$login = isset($_REQUEST['login']) ? $_REQUEST['login'] : NULL;
$passwd = isset($_REQUEST['passwd']) ? $_REQUEST['passwd'] : NULL;
$passwd = urlencode($passwd);
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : NULL;
$date = isset($_REQUEST['date']) ? $_REQUEST['date'] : NULL;
$user = isset($_REQUEST['user']) ? $_REQUEST['user'] : NULL;
$url = isset($_REQUEST['url']) ? $_REQUEST['url'] : NULL;
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'oldway';
function toUTF8($param)
{
if(is_array($param)) {
array_walk_recursive($param, create_function('&$item, $index', '$item = toUTF8(trim($item));'));
return $param;
}
mb_detect_order('UTF-8, ISO-8859-15, ISO-8859-1, Windows-1252');
//parfois si le dernier caractère de la chaine est accentué, la conversion peut foirer,
//donc on force avec un caractère qui ne l'est pas.
//(astuce trouvée sur les commentaires de la doc sur php.net)
$param .= '_';
$currentCharset = mb_detect_encoding($param);
if ($currentCharset != 'UTF-8') {
$param = mb_convert_encoding($param, 'UTF-8', $currentCharset);
}
return substr($param, 0, strlen($param)-1);
}
function stripSpacesAndTabs($str)
{
$str = preg_replace( '/\s+/', ' ', $str);
return ($str);
}
if (!isset($login) || !isset($passwd) || !isset($action))
die('ERR_PARAMS');
$epiuser = new EpitechUser($login, $passwd);
if ($epiuser->isset == false)
{
if ($epiuser->error == EpitechUser::ERR_USER_NOTSET)
die('ERR_USER_NOTSET');
else if ($epiuser->error == EpitechUser::ERR_LOGIN)
die('ERR_LOGIN');
else if ($epiuser->error == EpitechUser::ERR_CURL)
die('ERR_INTRA');
die('ERR_UNKNOWN');
}
if ($action == 'day')
{
$day = $epiuser->get_day($date);
$day = toUTF8($day);
$jsonday = json_encode($day);
if ($format == "json")
echo $jsonday;
else if ($format == "debugjson")
print_r(json_decode($jsonday));
else if ($format == "oldway")
{
foreach ($day as $res) {
foreach($res as $e) {
echo epur_html($e);
echo SEPARATOR;
}
}
}
}
if ($action == 'week')
{
$week = $epiuser->get_week($date);
$i = 1;
$week = toUTF8($week);
$jsonweek = json_encode($week);
if ($format == "json")
echo $jsonweek;
else if ($format == "debugjson")
print_r(json_decode($jsonweek));
else if ($format == "oldway")
{
foreach ($week as $e => $day)
{
$wtf = substr($e, -8);
$mmonth = $wtf[2].$wtf[3];
$dday = $wtf[0].$wtf[1];
$yyear = substr($wtf, -4);
echo $i."-".$dday."/".$mmonth."/".$yyear.SEPARATOR;
foreach ($day as $res) {
foreach($res as $e) {
echo trim(epur_html($e));
echo SEPARATOR;
}
}
$i++;
}
}
}
if ($action == 'projects')
{
if ($format == "json" || $format == "debugjson")
$projects = $epiuser->get_projectsnew();
else
$projects = $epiuser->get_projects();
$projects = toUTF8($projects);
$jsonprojects = json_encode($projects);
if ($format == "json")
echo $jsonprojects;
else if ($format == "debugjson")
print_r(json_decode($jsonprojects));
else if($format == "oldway")
{
foreach ($projects as $res) {
foreach($res as $e) {
echo epur_html($e);
echo SEPARATOR;
}
}
}
}
if ($action == 'notes')
{
$notes = $epiuser->get_notes();
$notes = toUTF8($notes);
$jsonnotes = json_encode($notes);
if ($format == "json")
echo $jsonnotes;
else if ($format == "debugjson")
print_r(json_decode($jsonnotes));
else if ($format == "oldway")
{
foreach ($notes as $res) {
$i = 0;
foreach($res as $e) {
echo epur_html($e);
echo SEPARATOR;
$i++;
}
}
}
}
if ($action == 'fire')
{
$fire = $epiuser->get_fire();
$fire = toUTF8($fire);
$jsonfire = json_encode($fire);
if ($format == "json")
echo $jsonfire;
else if ($format == "debugjson")
print_r(json_decode($jsonfire));
else if ($format == "oldway")
{
foreach ($fire as $res) {
echo stripSpacesAndTabs(epur_html($res));
echo SEPARATOR;
}
}
}
if ($action == 'my_susie')
{
$susie = $epiuser->get_my_susie();
$i = 0;
$susie = toUTF8($susie);
$jsonsusie = json_encode($susie);
if ($format == "json")
echo $jsonsusie;
else if ($format == "debugjson")
print_r(json_decode($jsonsusie));
else if ($format == "oldway")
{
while ($i < sizeof($susie))
{
$j = 0;
while ($susie[$i][$j])
{
echo stripSpacesAndTabs(epur_html($susie[$i][$j]));
echo SEPARATOR;
$j++;
}
$i++;
}
}
}
if ($action == 'my_tokens')
{
$tokens = $epiuser->get_my_tokens();
$tokens = toUTF8($tokens);
$jsontokens = json_encode($tokens);
if ($format == "json")
echo $jsontokens;
else if ($format == "debugjson")
print_r(json_decode($jsontokens));
else if ($format == "oldway")
{
$i = 0;
while ($i < sizeof($tokens))
{
$j = 0;
while ($tokens[$i][$j])
{
echo stripSpacesAndTabs(epur_html($tokens[$i][$j]));
echo SEPARATOR;
$j++;
}
$i++;
}
}
}
if ($action == 'susie_register')
{
$rep = $epiuser->get_susie_register($url);
$rep = toUTF8($rep);
echo $rep;
}
if ($action == 'susie_unregister')
{
$rep = $epiuser->get_susie_unregister($url);
$rep = toUTF8($rep);
echo $rep;
}
if ($action == 'susie_status')
{
$fire = $epiuser->get_susiestatus($url);
$fire = toUTF8($fire);
$jsonfire = json_encode($fire);
if ($format == "json")
echo $jsonfire;
else if ($format == "debugjson")
print_r(json_decode($jsonfire));
else if ($format == "oldway")
{
$i = 0;
echo " ";
while ($fire[$i])
{
echo stripSpacesAndTabs(epur_html($fire[$i]));
echo SEPARATOR;
$i++;
}
}
}
if ($action == 'susie_list')
{
$susie = $epiuser->get_susielist($date);
$susie = toUTF8($susie);
$jsonsusie = json_encode($susie);
if ($format == "json")
echo $jsonsusie;
else if ($format == "debugjson")
print_r(json_decode($jsonsusie));
else if ($format == "oldway")
{
$i = 0;
while ($i < sizeof($susie))
{
$j = 0;
while ($susie[$i][$j])
{
echo stripSpacesAndTabs(epur_html($susie[$i][$j]));
echo SEPARATOR;
$j++;
}
$i++;
}
}
}
if ($action == 'report')
{
$projects = $epiuser->get_report($user);
$projects = toUTF8($projects);
$jsonprojects = json_encode($projects);
if ($format == "json")
echo $jsonprojects;
else if ($format == "debugjson")
print_r(json_decode($jsonprojects));
else if ($format == "oldway")
{
foreach ($projects['report'] as $e)
{
echo epur_html($e);
echo SEPARATOR;
}
foreach ($projects['notes'] as $res) {
foreach($res as $e) {
echo epur_html($e);
echo SEPARATOR;
}
}
}
}
if ($action == 'version')
echo VERSION;
if ($action == 'token')
{
$event_id = isset($_REQUEST['event_id']) ? $_REQUEST['event_id'] : NULL;
$token_val = isset($_REQUEST['token_val']) ? $_REQUEST['token_val'] : NULL;
if (!isset($event_id) || !isset($token_val))
die('ERR_PARAMS');
$epiuser->validate_token(array('event_id' => $event_id, 'token_val' => $token_val));
}
?>