<?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['routeName']) && strlen($_REQUEST['routeName']) > 0) {
    $routeName = $_REQUEST['routeName'];
} else {

    $errorCode = 1;
}


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

$channelId = $_REQUEST['channelId'];
if (isset($_REQUEST['dstType']) && $_REQUEST['dstType'] != -1) {
    $dstType = $_REQUEST['dstType'];
} else {

    $errorCode = 3;
}

if (isset($_REQUEST['dstEntity']) && $_REQUEST['dstEntity'] != -1) {
    $dstEntity = $_REQUEST['dstEntity'];
} else {

    $errorCode = 4;
}

if (isset($_REQUEST['formId']) && $_REQUEST['formId'] != -1) {
    $formId = $_REQUEST['formId'];
} else {

    $errorCode = 5;
}



$userId = $_SESSION['ownerId'];

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


if ($errorCode == 0) {


    $res = $dba->UpdateAddDelRouteConfig($opId, $itemId, $routeName, $description, $userId, $channelId, $dstType, $dstEntity,$formId, 0);
}


switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ROUTE $label AVEC SUCCES !\"  }";
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'IDENTIFIANT DE LA ROUTE  EST INVALIDE !\"  }";
        break;
    case 2 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'EXTENSION EST INVALIDE !\"  }";
        break;
    case 3 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE TYPE DE DESTINATION EST INVALIDE !\"  }";
        break;
    case 4 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LA DESTINATION EST INVALIDE !\"  }";
        break;
    case 5 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LA FICHE A REMONTER !\"  }";
        break;
}


echo $msg;
?>