<?php

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

$svaTool = new svaTool();

//print_r($_REQUEST);


$errorCode = 0;
$opId = $userId = $username = $pwd = $userType = $profileId = $onwerId = $lang = $citizen = $firstName = $lastName = $primaryPhone = $secondaryPhone = $homePhone = $mobilePhone = $email = $primAddress = $secondAddress = $profession = $char1 = $char2 = $char3 = $char4 = $char5 = $char6 = $char7 = $char8 = $char9 = $char10 = $status = "";

$password = NULL;
$confPasswd = NULL;
// Ajout de nouvel utilisateur


if (isset($_REQUEST['queueName']) && strlen($_REQUEST['queueName']) > 0) {
    $queueName = $_REQUEST['queueName'];
} else {

    $errorCode = 1;
}


$description = $_REQUEST['description'];
$strategy = $_REQUEST['strategy'];
$opId = $_REQUEST['opId'];
$itemId = $_REQUEST['itemId'];
$channelType = $_REQUEST['channelId'];


 if(isset($_REQUEST['groupTypeId']) && $_REQUEST!= -1) {
            $groupTypeId = $_REQUEST['groupTypeId'];
        }else {
            
            $errorCode = 3;
        }






$userId = $_SESSION['ownerId'];



if ($opId == 0) {
    $label = "CREE";
} else {
    $label = "MODIFIE";
}


if ($errorCode == 0) {
    
    
    if( $opId == 1 ) {
	
	  
  }
  else {
	  
	  // Droppting current data
	  //$dba->UpdateAddDelRolesDetails(3, $roleIds, 0, 0 ,0, 0 , 0, 0, 0, 0,0,0,0,  0);
	     $dba->UpdateAddDelQueueTeamDetails(3,  $itemId, 0, 0 ) ;
	  
  }if( $opId == 0 ) {
	
	  
  }
  else {
	  
	
	  // Droppting current data
	  //$dba->UpdateAddDelRolesDetails(3, $roleIds, 0, 0 ,0, 0 , 0, 0, 0, 0,0,0,0,  0);
	     $dba->UpdateAddDelQueueTeamDetails(3,  $itemId, 0, 0 ) ;
	  
  }
    
    
    
    $res = $dba->UpdateAddDelQueue($opId, $itemId, $userId, $queueName, $description, $strategy, $channelType,$groupTypeId, 0);
    
  if($opId == 0){
        $itemId = $res ;
    }
    
   // print_r($_REQUEST['list']);
foreach($_REQUEST['teams'] as $selected) {
	$opId = 0 ;
$res = $dba->UpdateAddDelQueueTeamDetails($opId, $itemId , $selected,0) ;
 
}

}


switch ($errorCode) {

    case 0 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"FILE D'ATTENTE  $label AVEC SUCCES !\"  }";
        break;
    case 1 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! L'IDENTIFIANT DE LA FILE  EST INVALIDE !\"  }";
        break;
    case 2 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! LE TEMPS DE REPOS EST INVALIDE !\"  }";
        break;
    case 3 : $msg = "{ \"errorCode\": $errorCode,\"errorMessage\" :\"ERREUR ! VEUILLEZ SELECTIONNER UN GROUPE DE QUALIFICATION !\"  }";
        break;
}


echo $msg;
?>