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

$svaTool = new svaTool();

//print_r($_REQUEST);


$errorCode = 0;

$password = NULL;
$confPasswd = NULL;
// Ajout de calendrier 



if(isset($_REQUEST['calendardName']) && strlen($_REQUEST['calendardName'])> 0 ) {
	$calendardName = addslashes($_REQUEST['calendardName']) ;
}
else {
    
    $errorCode = 1; 
}

$description = $_REQUEST['description'] ;
$daysList =   $_REQUEST['daysList'] ;

$selectedDays = implode(",", $daysList);


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



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


$startDate = addslashes($_REQUEST['startDate']);
$endDate = addslashes($_REQUEST['endDate']);
$startHour= addslashes($_REQUEST['startHour']);
$endHour = addslashes($_REQUEST['endHour']);

$userId = $_SESSION['ownerId'];


$uid = $_REQUEST['uid'] ;
$opId = $_REQUEST['opId'] ;
$id = $_REQUEST['itemId'] ;

//echo "Vue = ".$opId;




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

if ($errorCode == 0) {
  
 
 $dba->UpdateAddDelCalendar($opId, $id, $userId, $calendardName, $description, $selectedDays, "", $fullTimeIndicator, $calendarType, $startDate, $startHour, $endDate, $endHour);


}




switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"CALENBDRIER $label AVEC SUCCES !\"  }"; 
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SAISIR L'IDENTIFIANT DU CALENDRIER  !\"  }";
        break;
    case 2 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LE TYPE DE CALENDRIER!\"  }"; 
        break;
    case 3 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LE MODE DU CALENDRIER !\"  }"; 
        break;
	 
}


echo $msg ;

?>