fields['connection'] = 'int'; $this->fields['sql'] = 'longstring'; $this->fieldMapping = $this->field_mapping($this->fields); } function editor(){ $html = ' Ajouter une base

- utilisez [[attribut]] pour acceder à une donnée ou {{attribut}} pour acceder à un filtre
Exécuter
'; return $html; } function preview($data = array(),$filters = array()){ $response = array('data'=>array()); require_once (__DIR__.SLASH.'..'.SLASH.'Connection.class.php'); if(isset($this->connection) && $this->connection!=false) { $connection = Connection::getById($this->connection); if($connection!=false && !empty($connection->handler) ){ try{ $pdo = $connection->getPdo(); if(!isset($pdo)) throw new Exception("Connexion à la base impossible"); $query = self::template($this->sql,$filters,true); $query = preg_replace('/\[\[([^\]]*)\]\]/iU','{{$1}}', $query); $query = self::template($query,$data,true); $query = html_entity_decode($query,ENT_QUOTES); $response['meta'] = array('Requete finale' => $query); $results = $pdo->prepare($query); $results->execute(array()); foreach ($results->fetchAll(PDO::FETCH_ASSOC) as $element){ foreach($element as $index => $row){ if($connection->handler == 'Oracle'){ $element[$index] =iconv("Windows-1254", "UTF-8", html_entity_decode($row, ENT_QUOTES, 'UTF-8')); }else{ $element[$index] =html_entity_decode($row, ENT_QUOTES, 'UTF-8'); } } $response['data'][] = $element; } } catch(Exception $e) { $error = utf8_encode($e->getMessage()); if(isset($pdo)) $error .= json_encode($pdo->errorInfo()); if(isset($query)) $error .= '
'.$query; $error = str_replace( array('Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ','SQLSTATE[42000]'), array(' ...','Mauvaise Syntaxe'),$error); throw new Exception("SQL ".PHP_EOL.$error); } } } return $response; } } ?>