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

$svaTool = new svaTool();

$Id = "";
$countNode =  count($_REQUEST['users']);


foreach($_REQUEST['users'] as $selected) {

$Id .= "'".$selected."',";
	
}
$Id = rtrim($Id,',');
$errorCode = 0;

if ($errorCode == 0) {
$qosCode = "";

$res = $dba->UpdateAddSCCUser(3, $Id, NULL, NULL, NULL, NULL,NULL,NULL,NULL,NULL,NULL) ;
/** Reconstruction des agents ***/
$res = $dba->getSIPDetailConfiguration(-1, 0);
$sipuserlist = "";
for($i=0;$i<count($res);$i++){
	
	$sipuserlist .= $svaTool->getSIPAgentConfig($res[$i]['username'], $res[$i]['type'], $res[$i]['host'], $res[$i]['secret'] );
	
}
$fp = fopen($_SESSION['cfg']['scc']['sip.additional.file'], 'w') or die ('Impossible d\'accéder au fichier.');
fputs($fp,$sipuserlist);
fclose($fp);

$manager->reloadSIPConfig();

/************ Reconstruction des File d'attente *********/

$res = $dba->crmGetAgentList($_SESSION['right'], $_SESSION['ownerId'], -1);
$memberlist = "" ;
for($i=0;$i<count($res);$i++){
	
	$memberlist .= $svaTool->getQueueMemberConfig($res[$i]['mobile_phone_v']);
	
}

/** Reconstruction des file d'attente ***/
$res = $dba->getSCCQueueDetails(0);
$queuelist = "";
for($i=0;$i<count($res);$i++){
	
	$queuelist .= $svaTool->getQueueConfig($res[$i]['name'], $res[$i]['wrapuptime'], $memberlist);
	
}
$fp = fopen($_SESSION['cfg']['scc']['queues.additional.file'], 'w') or die ('Impossible d\'accéder au fichier.');
fputs($fp,$queuelist);
fclose($fp);

$manager->reloadConfig();

/*** Fin reconstruction de la file ***********/



   //$errorCode = 10;
}




switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"PARAMETRE SUPPRIME 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 ;


?>