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

//var_dump($_REQUEST);

$svaTool = new svaTool();
$userId = $_SESSION['ownerId'];
$profileId = $_SESSION['right'];




$ticketlist = $_REQUEST['ticketlist'];
$comment = $_REQUEST['comment']; 
$comment = "Cloôturé automatiquement";
$ticketlist = rtrim($ticketlist,',');

$Id = "";
$ticketArray = explode(",", $ticketlist);

for($i =0 ; $i < count($ticketArray); $i++){
    
    $dba->UpdateAddComment(0, $userId, $ticketArray[$i], $comment, 1, "", 0);
    
    $dba->UploadTicketHistory( $userId, $profileId , $ticketArray[$i], 0, $comment, 3);
    $Id .= "'".$ticketArray[$i]."',";
    
}

$Id = rtrim($Id,',');


//$Id = $_REQUEST['data'];

$errorCode = 0;

if ($errorCode == 0) {
$qosCode = "";
$res = $dba->SCCBulkCloseTickets( $userId, $Id); 
   //$errorCode = 10;
}




switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ELEMENT(S) CLOTURE(S) AVEC SUCCES !\"  }"; 
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE NOM DU PARAMETRE EST INVALIDE !\"  }";
        break;
    case 2 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SAISIR UNE VALEUR POUR CE PARAMETRE. !\"  }"; 
        break;
   
   
	 
}


echo $msg ;


?>