<?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['callReasonType']) && $_REQUEST['callReasonType'] != "-1")
    $callReasonType = addslashes($_REQUEST['callReasonType']);
else
    $errorCode = 1;


if (isset($_REQUEST['csrDetails']) && strlen($_REQUEST['csrDetails'])>0 )
    $csrDetails = addslashes($_REQUEST['csrDetails']);
else
    $errorCode = 2;

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

if (isset($_REQUEST['firstName']) && strlen($_REQUEST['firstName'])>0 )
    $firstName = addslashes($_REQUEST['firstName']);
else
    $errorCode = 5;
	
if (isset($_REQUEST['company']) && strlen($_REQUEST['company']) >0 )
    $company = addslashes($_REQUEST['company']);
else
    $errorCode = 6;
	
$emailId = addslashes($_REQUEST['emailId']);
/*
if (isset($_REQUEST['callerNumber']) && strlen($_REQUEST['callerNumber'])>0 && is_numeric($_REQUEST['callerNumber']) )
    $callerNumber = addslashes($_REQUEST['callerNumber']);
else
    $errorCode = 8;
	*/
	


$csrId = addslashes($_REQUEST['csrId']);
$callerId = addslashes($_REQUEST['callerId']);
$firstName = addslashes($_REQUEST['firstName']); 
$lastName = addslashes($_REQUEST['lastName']);

//$address = addslashes($_REQUEST['address']);
$mobileNumber = addslashes($_REQUEST['mobileNumber']);
$emailId = addslashes($_REQUEST['emailId']);
$callId = addslashes($_REQUEST['callId']);
$userId = $_SESSION['ownerId'];
$statut = addslashes($_REQUEST['operationId']);
$actionType = addslashes($_REQUEST['actionType']);
$callType = addslashes($_REQUEST['callType']);




/************* Nouvelles données ***********/

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


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


if (isset($_REQUEST['callprority']) && $_REQUEST['callprority'] != "-1")
    $callprority = addslashes($_REQUEST['callprority']);
else
    $errorCode = 12;






if ($errorCode == 0) {
$id = 0;
$field[0] = date('Y-m-d H:i:s');
$field[1] = '';
$field[2] = '';
$field[3] = '';
$field[4] = '';
$callerNumber = null;
$agencyName = $dba->getSCCAgencyByUserId( $userId );
$res = $dba->UpdateAddTicketExtend($id, $firstName, $lastName, $callId, $userId, $csrId, $callerId, $company, $company, $mobileNumber, $emailId, $callReasonType, $csrDetails,$callType, $actionType,$customerType , $agencyName, $callModule, $submodule, $callprority) ;

$customerName = $firstName." ".$lastName ;
$dba->UpdateAddSCCCustomer(0,0,$firstName, $lastName, $mobileNumber, "", $company, $emailId,$field);
$dba->UpdateAddComment($id, $userId, $csrId, $csrDetails, 0, $customerName,0 );
sleep(1);
$dba->UpdateAddComment($id, $userId, $csrId, $csrComment, 1, $customerName,0 );

$dba->UpdateCallHistory($callId, $statut );
$dba->UploadTicketHistory( $userId, $profileId , $csrId, $type, $comment, $actionType);

   //$errorCode = 10;
}




switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"TICKET EDITE AVEC SUCCES !\"  }"; 
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LE MOTIF DE L'APPEL !\"  }";
        break;
    case 10 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LE MODULE !\"  }";
        break;
    case 2 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ DETAILLER LA REQUETE DU CLIENT !\"  }"; 
        break;
    case 3 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ INSERER UN COMMENTAIRE SUR LE TICKET.\"  }"; 
        break;
	case 4 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ ENTRER LE NUMERO DE L'APPELANT.\"  }";
        break;
    case 5 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE NOM  EST INVALIDE.\"  }"; 
        break;
    case 6 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SAISIR LE MATRICULE .\"  }";
        break;
    case 7 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'EMAIL  EST INVALIDE.\"  }";
        break;
	case 8 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE NUMERO APPELANT EST INVALIDE !\"  }";
        break;
	case 9 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ CHOISIR LE STATUT USAGER!\"  }";
        break;
    case 11 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LE SOUS-MODULE !\"  }";
        break;
    
    case 12 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER LA PRIORITE !\"  }";
        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 ;


?>