<?php

session_start();
$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir'] . "core.php");

$svaTool = new svaTool();

//print_r($_REQUEST);


$errorCode = 0;
$opId = $userId = $username = $pwd = $userType = $profileId = $onwerId = $lang = $citizen = $firstName = $lastName = $primaryPhone = $secondaryPhone = $homePhone = $mobilePhone = $email = $primAddress = $secondAddress = $profession = $char1 = $char2 = $char3 = $char4 = $char5 = $char6 = $char7 = $char8 = $char9 = $char10 = $status = "";

$password = NULL;
$confPasswd = NULL;
// Ajout de nouvel utilisateur


if (isset($_REQUEST['channelName']) && strlen($_REQUEST['channelName']) > 0) {
    $channelName = $_REQUEST['channelName'];
} else {

    $errorCode = 1;
}


$description = $_REQUEST['description'];
$channelId = $_REQUEST['channelId'];
$opId = $_REQUEST['opId'];
$itemId = $_REQUEST['itemId'];
if (isset($_REQUEST['outgoingUrl']) && strlen($_REQUEST['outgoingUrl']) > 0) {
    $outgoingUrl = addslashes($_REQUEST['outgoingUrl']);
} else {

    $errorCode = 2;
}




if (isset($_REQUEST['requestTimeOut']) && strlen($_REQUEST['requestTimeOut']) > 0 && is_numeric($_REQUEST['requestTimeOut'])) {
    $requestTimeOut = $_REQUEST['requestTimeOut'];
} else {

    $errorCode = 3;
}





$userId = $_SESSION['ownerId'];



if ($opId == 0) {
    $label = "CREE";
} else {
    $label = "MODIFIE";
}


if ($errorCode == 0) {
    
    
    $res = $dba->UpdateAddSCCChannel($opId, $itemId, $channelId, $userId, $channelName, $description, 0);
    
    if($opId == 0){
        $itemId = $res ;
    }
     $res = $dba->UpdateAddDelHTTPChannel($opId, $itemId, $outgoingUrl, $requestTimeOut, $itemId, $status);

}


switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"CANAL DE SERVICE $label AVEC SUCCES !\"  }";
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'IDENTIFIANT DE SERVICE EST INVALIDE !\"  }";
        break;
    case 2 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'URL EST INVALIDE !\"  }";
        break;
    case 3 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE DELAI DE REPONSE PAR DEFAUT EST INVALIDE !\"  }";
        break;
   
}


echo $msg;
?>