<?php

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

$svaTool = new svaTool();

/* Get all interface -> getinterface Details by Id -> Build physical config -> reload config */
$stdSipAccntData = "";
$registrySipAccntData = "";
$errorCode = 0;

$queuelist = "";
$res = $dba->SCCGetVoiceQueueAll();
$total = count($res);

for ($i = 0; $i < $total; $i++) {

    $ures = $dba->SCCGetVoiceQueueMembersById($res[$i]['queue_id_n']);
    
    $memberlist ="";
    for ($p = 0; $p < count($ures); $p++) {

        if(strlen($ures[$p]['caller_id_v'])> 0) {
            
          $memberlist .= $svaTool->getQueueMemberConfig($ures[$p]['caller_id_v']);
        
        }
        
    }
    
    $queuelist .= $svaTool->getQueueConfigExtend($res[$i]['name'], $res[$i]['wrapuptime'], $res[$i]['strategy'],$memberlist);

    
}

/*     * ************** Writing related file ********* */
$fp = fopen($_SESSION['cfg']['scc']['queues.additional.file'], 'w') or die ('Impossible d\'accéder au fichier.');

if ($fp) {

        fputs($fp,$queuelist);
fclose($fp);
    }
    else {
        
        $errorCode = 1;
        
    }



$manager->reloadConfig();







switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"CONFIGURATION SYNCHRONISEE AVEC SUCCES !\"  }";
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! ECHEC DE LA SYNCHRONISATION !\"  }";
        break;
  
}

echo $msg;
?>