<?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;
}


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

    $errorCode = 2;
}

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

    $errorCode = 3;
}


$description = $_REQUEST['description'];
$channelId = $_REQUEST['channelId'];
$opId = $_REQUEST['opId'];
$itemId = $_REQUEST['itemId'];



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

    $errorCode = 4;
}


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

    $errorCode = 5;
}



$systemType = $_REQUEST['systemType'];
$serviceType = $_REQUEST['serviceType'];
$charset = $_REQUEST['charset'];
$mode = $_REQUEST['mode'];
$srcTon = $_REQUEST['srcTon'];
$srcNpi = $_REQUEST['srcNpi'];
$dstTon = $_REQUEST['dstTon'];
$dstNpi = $_REQUEST['dstNpi']; 
$msgIdType = $_REQUEST['msgIdType'];






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

    $errorCode = 6;
}


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

    $errorCode = 7;
}


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

    $errorCode = 8;
}






$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->UpdateAddDelSMPPChannel($opId, $itemId, $host, $port, $port, $systemId, $password, $mode, $systemType, $srcTon, $srcNpi, $dstTon, $dstNpi, $serviceType, $enquireLinkDelay, $reconnectDelay, $msgIdType, $sendThrPut, $sendThrPut, $charset,$itemId, 0);
    
}


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'IDENTIFIANT SYSTEME EST INVALIDE !\"  }";
        break;
    case 3 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE MOT DE PASSE EST INVALIDE !\"  }";
        break;
    case 4 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'ADRESSE DU SERVEUR EST INVALIDE !\"  }";
        break;
    case 5 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE PORT DU SERVEUR EST INVALIDE !\"  }";
        break;
    case 6 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE DEBIT DU COMPTE EST INVALIDE !\"  }";
        break;
    case 7 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE DELAI DE RECONNEXION EST INVALIDE !\"  }";
        break;
    case 8 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE DELAI DE VERIFICATION DU LIEN EST INVALIDE !\"  }";
        break;
  

}


echo $msg;
?>