. */ /** * @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'] = ""; /** * Form template */ $_ENV['mccForm'] = ""; /** * * Array 2 XML class * Convert an array or multi-dimentional array to XML * * @author Kevin Waterson * @copyright 2009 PHPRO.ORG * */ class array2xml extends DomDocument { public $nodeName; private $xpath; private $root; private $node_name; /** * Constructor, duh * * Set up the DOM environment * * @param string $root The name of the root node * @param string $nod_name The name numeric keys are called * */ public function __construct($root='root', $node_name='node') { parent::__construct(); /*** set the encoding ***/ $this->encoding = "UTF-8"; /*** format the output ***/ $this->formatOutput = true; /*** set the node names ***/ $this->node_name = $node_name; /*** create the root element ***/ $this->root = $this->appendChild($this->createElement( $root )); $this->xpath = new DomXPath($this); } /* * creates the XML representation of the array * * @access public * @param array $arr The array to convert * @aparam string $node The name given to child nodes when recursing * */ public function createNode( $arr, $node = null) { if (is_null($node)) { $node = $this->root; } foreach($arr as $element => $value) { $element = is_numeric( $element ) ? $this->node_name : $element; $child = $this->createElement($element, (is_array($value) ? null : $value)); $node->appendChild($child); if (is_array($value)) { self::createNode($value, $child); } } } /* * Return the generated XML as a string * * @access public * @return string * */ public function __toString() { return $this->saveXML(); } /* * array2xml::query() - perform an XPath query on the XML representation of the array * @param str $query - query to perform * @return mixed */ public function query($query) { return $this->xpath->evaluate($query); } } // end of class /** * 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_get_customs.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; //loginCreation(); //writeLog("Get customs process"); $CONFIG =$xmlConfig -> CONFIG; $_ENV['mccPath'] = $CONFIG->MCC_PATH; $DATABASE =$xmlConfig -> DATABASE; $_ENV['databaseserver'] = $DATABASE->LOCATION; $_ENV['databaseport'] = $DATABASE->DATABASE_PORT; $_ENV['database'] = $DATABASE ->DATABASE; $_ENV['databasetype'] = $DATABASE->DATABASETYPE; $_ENV['databaseuser'] = $DATABASE -> USER_NAME; $_ENV['databasepwd'] = $DATABASE->PASSWORD; $_ENV['databaseworkspace'] = $DATABASE->DATABASEWORKSPACE; } //begin date_default_timezone_set('Europe/Paris'); $conf = 'config' . DIRECTORY_SEPARATOR . 'saasadmin.xml'; if (!file_exists($conf)) { die ('The read of the configuration file has been stopped by Maarch Capture Connector Server (Xml Error of get_customs.xml)'); } loadConfig($conf); $customs = ''; if ($_REQUEST['login'] <> '') { require('class_db.php'); $_ENV['db'] = new dbquery(); $_ENV['db']->connect(); $query = "select id from sf_guard_user where username = '" . $_REQUEST['login'] . "'"; $_ENV['db']->query($query); $loginRes = $_ENV['db']->fetch_object(); if (!isset($loginRes->id) && $loginRes->id == '') { die ('Login not exists on saasadmin'); } else { $userId = $loginRes->id; } $query = "select custom_identifier from custom where entity_id in " . "(select entity_id from user_entity where sf_guard_user_id = " . $userId . ") order by custom_identifier"; $_ENV['db']->query($query); while ($res = $_ENV['db']->fetch_object()) { $customs .= $res->custom_identifier . ';'; } //writeLog("End of the application"); header('Content-type: application/text; charset=utf-8'); echo $customs; exit(0); } if ($_REQUEST['customId'] <> '') { $master = $_ENV['mccPath'] . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'master.xml'; $newXml = $_ENV['mccPath'] . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config_' . $_REQUEST['customId'] . '.xml'; copy($master, $newXml); $content = file_get_contents($newXml); $content = str_replace('{{custom_id}}', $_REQUEST['customId'], $content); file_put_contents($newXml, $content); }