<?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 nouvel utilisateur





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




$ticketId = addslashes($_REQUEST['ticketId']);

if($dba->checkSaveTicketDetails($ticketId) ==0){
    
    $errorCode = 1;
}

$userId = $_SESSION['ownerId'];
$profileId = $_SESSION['right'];


if ($errorCode == 0) {
$dba->UploadTicketHistory( $userId, $profileId , $ticketId, 0, $comment, 11);
$dba->updateTicketByStatus($ticketId, 11);
$dba->updateTicketTransferMode($ticketId, 11);

 $queryres = $dba->getSCCStdTicketDetailsByTicket($ticketId);

    if ($queryres[0]['fwdBy'] != "") {

        $eRes = $dba->getSystemUserById($userId);

        $ccList = $eRes['email_v'];

        $subject = " NOTIFICATION TICKET N° " . $ticketId;
        $ccList = rtrim($ccList, ",");
        $attachments = "";

        $content = $svaTool->prepareMailEventBody($ticketId, $queryres[0]['fwdBy'], $queryres[0]['fwdTo'], $queryres[0]['priorityName'], $queryres[0]['clientComment'], $moduleName, $submoduleName, $queryres[0]['ticket_reason_desc_v'], 'Résolu');

        $dba->SCCUploadMailNotification($emailRes[0]['email_v'], $ccList, $subject, $content, $attachments);
    }

   //$errorCode = 10;

if($profileId ==4 ){
    
    $dba->UploadTicketHistory( $userId, 2 , $ticketId, 0, $comment, 10);
    
    
}
}




switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"TICKET RESOLU AVEC SUCCES !\"  }"; 
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ ENREGISTRER LE TICKET AVANT DE TRANSFERER !\"  }";
        break;
    case 2 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER  LE PROFIL!\"  }";
        break;
    
    case 3 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ ECRIRE UN COMMENTAIRE! \"  }";
        break;
    
    
 /*   case 4 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LA STRATEGIE DES APPELS ENTRANTS.\"  }";
        break;
   /* case 5 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE LOGIN EST INVALIDE.\"  }"; 
        break;
    case 6 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'EMAIL EST INVALIDE.\"  }";
        break;
    /*case 7 : $msg =  "ERREUR ! LE MOT DE PASSE EST INVALIDE.";
        break;
    case 8 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE MOT DE PASSE DE CONFIRMATION EST INVALIDE .!\"  }"; 
        break;
    case 9 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LES MOTS DE PASSE NE CONCORDENT PAS.\"  }";
        break; */
    case 13 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! IMPOSSIBLE DE CREER LE COMPTE. VEUILLEZ RE-ESSAYER ULTERIEUREMENT!\"  }";  break;
	/*
		case 14 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LE PLAN TARIFAIRE ASSOCIE AU COMPTE !\"  }";   break; */
   
	 
}


echo $msg ;


?>