<?php 
require_once("../../base/php/startSession.php");
require_once("../../base/php//classDatabase.php");
require_once("../../base/php/Functions.php");
require_once("../../base/php/WebAppLog.php");

global $database;
global $finess;
global $typeEts;
global $tmp_path;

global $in_import_id;


set_time_limit(3600);
ini_set('memory_limit','256M');


$in_import_id = @$_POST["import_id"];
if ($in_import_id == "") {
	$in_import_id = @$_GET["import_id"];
}

$returnCode = "OK";
$returnTexte = "";

control($returnCode, $returnTexte);


$httpString = "";
$httpString = $httpString . "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
$httpString = $httpString . "\n<HTTP_SERVICE returnCode=\"$returnCode\" returnTexte=\"$returnTexte\" import_id=\"$import_id\" >";
$httpString = $httpString . "\n</HTTP_SERVICE>";
 

$httpString = gzcompress($httpString,9);
$httpString = "_c_" . base64_encode($httpString); 

echo "<CTICONTENT>$httpString</CTICONTENT>";
//echo "$httpString";





// récupération historique
function control(&$returnCode, &$returnTexte) {

	global $database;
	global $in_import_id;
	
	$database = new Database("iCTI");
	
	$sqlcmd = "UPDATE pmsi.p_imports SET etat_en_cours = '', traitement_a_faire = 'C' WHERE oid = $in_import_id ";
	$result = $database->exec($sqlcmd);
	
	$submitCmd = "..\import_rss_rsf\iCTI_import_rss_rsf.exe";
	$return = exec($submitCmd);
	
	$result  =  $database->exec("SELECT nb_erreurs, nb_avertissements FROM pmsi.p_imports WHERE oid = $in_import_id ");
	if ($result != false) {
		$record = $database->nextRecordInto();
		if ($record != FALSE) {
			$nb_erreurs = $record[0] + 0;
			$nb_avertissements = $record[1] + 0;
			
			if ($nb_erreurs > 0) {
				$returnCode = "KO";
				$returnTexte = "$nb_erreurs erreur(s) grave(s)";
				if ($nb_avertissements > 0) {
					$returnTexte = $returnTexte . ", $nb_avertissements avertissement(s)";
				}
			}
			else {
				if ($nb_avertissements > 0) {
					$returnCode = "ATT";
					$returnTexte = "$nb_avertissements avertissement(s)";
				}
			}
		}
	}
						
					

}



?> 