. */ /** * @defgroup mcc Maarch Capture Connector */ /** * get datas for mcc for the form * * @file * @author Laurent Giovanonni * @date $date$ * @version $Revision$ * @ingroup mcc * @brief get datas for mcc for the form */ //Error mode and function error_reporting(E_ERROR); set_error_handler(errorHandler); //Global var of the program /** * maarch capture connector path */ $_ENV['mccPath'] = ""; /** * maarch tmp path */ $_ENV['maarchTmpPath'] = ""; /** * target path for preprocess */ $_ENV['targetPath'] = ""; /** * location of the database server */ $_ENV['databaseserver'] = ""; /** * port of the database server */ $_ENV['databaseport'] = 0; /** * name of the database */ $_ENV['database'] = ""; /** * type of the database */ $_ENV['databasetype'] = ""; /** * user name of the database */ $_ENV['databaseuser'] = ""; /** * password of the database */ $_ENV['databasepwd'] = ""; /** * path to the log file */ $_ENV['log'] = ""; /** * Creation of the log file */ function loginCreation() { if(!is_dir($_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR)) { mkdir($_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR,0777); } $_ENV['log'] = $_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR."mcc_server.log"; writeLog("Application start with : ".$_SERVER['SCRIPT_FILENAME']); } /** * Write on the log file * @param $eventInfo string text which is written in the log file */ function writeLog($eventInfo) { $logFileOpened = fopen($_ENV['log'], "a"); fwrite($logFileOpened, "[".date("d")."/".date("m")."/".date("Y")." ".date("H").":".date("i").":".date("s")."] ".$eventInfo."\r\n"); fclose($logFileOpened); } /** * Write on the log file errors * @param $eventInfo string text which is written in the log file * @param $errorLevel integer text return code of an error */ function manageError($eventInfo, $errorLevel) { $logFileOpened = fopen($_ENV['log'], "a"); fwrite($logFileOpened, "[".date("d")."/".date("m")."/".date("Y")." ".date("H").":".date("i").":".date("s")."][ERRNO]".$errorLevel."[ERRNO][ERROR]".$eventInfo."[ERROR]\r\n"); fclose($logFileOpened); echo $errorLevel." ".$eventInfo; exit($errorLevel); } /** * Managing of errors * @param $errno integer number of the error * @param $errstr string text of the error * @param $errfile string file concerned with the error * @param $errline integer line of the error * @param $errcontext string context of the error */ function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { $string = $errstr; $search1="'xml_file_loaded'"; $search2="'Undefined index'"; preg_match($search1,$string,$out); $count=count($out[0]); if($count == 1) { $find1 = true; } preg_match($search2,$string,$out); $count=count($out[0]); if($count == 1) { $find2 = true; } if(!$find1 && !$find2) { manageError("from line ".$errline." : ". $errstr, 1); $_ENV['errorLevel'] = 1; } } /** * Loading of the xml config file * @param $conf string path to the config file */ function loadConfig($conf) { //loading of the xml config file. $xmlConfig = simplexml_load_file($conf); $CONFIG =$xmlConfig -> CONFIG; $_ENV['mccPath'] = $CONFIG -> MCC_PATH; loginCreation(); writeLog("Get datas process"); writeLog("Loading xml config file : ".$conf); writeLog("mccPath : ".$_ENV['mccPath']); $_ENV['maarchTmpPath'] = $CONFIG -> MAARCH_TMP_PATH; writeLog("maarchTmpPath : ".$_ENV['maarchTmpPath']); $_ENV['targetPath'] = $CONFIG -> TARGET_PATH; writeLog("targetPath : ".$_ENV['targetPath']); $DATABASE =$xmlConfig -> DATABASE; $_ENV['databaseserver'] = $DATABASE->LOCATION; //writeLog("databaseserver : ".$_ENV['databaseserver']); $_ENV['databaseport'] = $DATABASE->DATABASE_PORT; //writeLog("databaseport : ".$_ENV['databaseport']); $_ENV['database'] = $DATABASE ->DATABASE; //writeLog("database : ".$_ENV['database']); $_ENV['databasetype'] = $DATABASE->DATABASETYPE; //writeLog("databasetype : ".$_ENV['databasetype']); $_ENV['databaseuser'] = $DATABASE -> USER_NAME; //writeLog("databaseuser : ".$_ENV['databaseuser']); $_ENV['databasepwd'] = $DATABASE->PASSWORD; //writeLog("databasepwd : ".$_ENV['databasepwd']); $_ENV['databaseworkspace'] = $DATABASE->DATABASEWORKSPACE; //writeLog("databaseworkspace : ".$_ENV['databaseworkspace']); } //begin date_default_timezone_set('Europe/Paris'); $conf = "config".DIRECTORY_SEPARATOR."config_".$_REQUEST['configName'][0].".xml"; if(!file_exists($conf)) { die ("The read of the configuration file has been stopped by Maarch Auto Import (Xml Error)"); } loadConfig($conf); //print_r($_REQUEST); require("class_db.php"); $_ENV['db'] = new dbquery(); $_ENV['db']->connect(); if($_REQUEST['isForMlb'][0] == "true") { $req = "select ID as idEntity, SERVICE As labelEntity from services order by SERVICE"; } else { if($_REQUEST['userId'][0] <> "") { $req = "select entity_id as idEntity, entity_label As labelEntity from entities where entity_id in (select entity_id from users_entities where user_id = '".$_REQUEST['userId'][0]."') order by entity_label"; } else { $req = "select entity_id as idEntity, entity_label As labelEntity from entities order by entity_label"; } } writeLog($req); $_ENV['db']->query($req); $result_xml = new DomDocument('1.0', 'UTF-8'); $root = $result_xml->appendChild($result_xml->createElement("ROOT")); while($reqResult = $_ENV['db']->fetch_array()) { $service = $result_xml->createElement("SERVICE"); $text = stripslashes($reqResult[1])." [".stripslashes($reqResult[0])."]"; //Conversion sytèmatique en UTF-8 $text = utf8_encode($text); $service->appendChild( $result_xml->createTextNode( $text ) ); $root->appendChild($service); } header('Content-type: application/xml; charset=utf-8'); echo $result_xml->saveXML(); exit(0); ?>