Source for file dbconnexion.class.php
Documentation is available at dbconnexion.class.php
*@=@=@=@ START LICENSE @=@=@=@*
Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
This software is a computer program whose purpose is to make a
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*@=@=@=@ END LICENSE @=@=@=@*
* @version $Id: dbconnexion.class.php 872 2008-01-31 16:09:33Z stephanet $
require_once('internal_components/common/cache_class/object_cached.class.php');
* The object to make request and be connected to the databases
* @version $Id: dbconnexion.class.php 872 2008-01-31 16:09:33Z stephanet $
// print_r(get_html_translation_table (HTML_ENTITIES));
// $Id: dbconnexion.class.php 872 2008-01-31 16:09:33Z stephanet $
// $siteName = nom du site
// je vais sur le admin_super afin de trouver les codes d'accès
// en fonction de la demande de site réalisée
* The id for current web site
* Store list of table use in master
* Store list of fields use in master
* SQL Request : Get web site group
"SELECT dbc_dbname, dbc_group
WHERE dbc_dblogin<>'ALIAS'
* SQL Request : Lock tables
LOCK TABLES t_address READ, t_attribut READ, t_attributvalue READ, t_area_has_t_deliverycosts_type READ,
t_country READ, t_customer_has_t_productmaster WRITE, t_deliverycosts_type READ,
t_globalscope READ, t_lang READ, t_payment_method READ, t_payment_method_special READ,
t_productmaster READ, t_productslave WRITE, t_productmodifier READ,
t_order WRITE, t_orderdetail WRITE, t_order_id WRITE,
t_setting READ, t_shoppingcart WRITE, t_text READ, t_text_field READ, t_text_field_bbcode READ, t_tvatype WRITE ;";
* SQL Request : Unlok tables
* Active this var to debug any request
var $debug_is_on =
false; // variable de DEBUG qui doit rester là
* table not destroying cache
* Active this var to debug connectivity
* Constructor, init the requests and objects
global $g_object_loader, $g_object_siteinformation;
if (!isset
($g_object_siteinformation))
// Temp - usefull to detect problem
//$g_object_siteinformation =& $g_object_loader->getSiteInformation();
$p_database_site_name =
$g_object_siteinformation->getDatabaseSiteName();
// Permet de faire un tableau des TAG HTML supportés par
$supported_tags_base =
array();
$supported_tags =
array();
$supported_tags_base[sizeof($supported_tags_base)] =
"TABLE";
$supported_tags_base[sizeof($supported_tags_base)] =
"CAPTION";
$supported_tags_base[sizeof($supported_tags_base)] =
"TBODY";
$supported_tags_base[sizeof($supported_tags_base)] =
"TR";
$supported_tags_base[sizeof($supported_tags_base)] =
"TD";
$supported_tags_base[sizeof($supported_tags_base)] =
"P";
$supported_tags_base[sizeof($supported_tags_base)] =
"HR";
$supported_tags_base[sizeof($supported_tags_base)] =
"STRONG";
$supported_tags_base[sizeof($supported_tags_base)] =
"EM";
$supported_tags_base[sizeof($supported_tags_base)] =
"U";
$supported_tags_base[sizeof($supported_tags_base)] =
"STRIKE";
$supported_tags_base[sizeof($supported_tags_base)] =
"SUB";
$supported_tags_base[sizeof($supported_tags_base)] =
"SUP";
$supported_tags_base[sizeof($supported_tags_base)] =
"OL";
$supported_tags_base[sizeof($supported_tags_base)] =
"LI";
$supported_tags_base[sizeof($supported_tags_base)] =
"DIV";
$supported_tags_base[sizeof($supported_tags_base)] =
"BR";
$supported_tags_base[sizeof($supported_tags_base)] =
"FONT";
$supported_tags_base[sizeof($supported_tags_base)] =
"A";
$supported_tags_base[sizeof($supported_tags_base)] =
"IMG";
$save_count_supported_tags =
sizeof($supported_tags_base);
for ($i =
0; $i <
$save_count_supported_tags; $i++
) {
$supported_tags[sizeof($supported_tags)] =
$supported_tags_base[$i];
$supported_tags[sizeof($supported_tags)] =
"/".
$supported_tags_base[$i].
">";
// liste des talbes n'affectant pas le cache du front office
// inverse HTML_SPECIALCHARS dans HTML_SPECIALCHARS_REVERSED
for ($i=
0; $i<
sizeof($keys); $i++
)
for ($i=
0; $i<
sizeof($keys); $i++
)
// Store list of table use in master
// This table was locked during order so we must check
//$this->m_master_website_group_table_and_field['t_globalscope'][] = "a_m_s";
//$this->m_master_website_group_table_and_field['t_globalscope'][] = "swif_";
// Not be good because we can have 2 same id for 2 picture <>
// One in master and other in slave
* @param resource $r_super_admin_sql_connection_id
* @param resource $r_sql_connection_information
* @param string $p_database
* @return bool TRUE on error
function getConnection(&$r_super_admin_sql_connection_id, &$r_sql_connection_information, $p_database)
$r_super_admin_sql_connection_id =
NULL;
$r_sql_connection_information =
array();
$r_sql_connection_information['dbc_connection'] =
NULL;
$r_sql_connection_information['dbc_sitename'] =
'NC';
$r_sql_connection_information['dbc_dbname'] =
'NC';
$r_sql_connection_information['dbc_dblogin'] =
'NC';
$r_sql_connection_information['dbc_dbpass'] =
'NC';
$r_sql_connection_information['dbc_dbhost'] =
'NC';
global $g_object_loader, $g_object_siteinformation, $_PLICI_CFG;
if (!isset
($g_object_siteinformation))
// Temp - usefull to detect problem
if ($this->xIsRemembered("sql_super_adm_connection_id", $r_super_admin_sql_connection_id)) {
// Connect to super admin
$r_super_admin_sql_connection_id =
plici_mysql_connect($_PLICI_CFG['superadmin_hostname'], $_PLICI_CFG['superadmin_username'], $_PLICI_CFG['superadmin_password']);
$this->xRemember("sql_super_adm_connection_id", $r_super_admin_sql_connection_id);
// Check cache for databaseconnect information
if ($this->xIsRemembered("sql_db_connection_info_".
$p_database, $r_sql_connection_information)) {
$select_db_is_ok =
@mysql_select_db($_PLICI_CFG['superadmin_databasename'], $r_super_admin_sql_connection_id);
echo_net("mysql_connect(".
$_PLICI_CFG['superadmin_hostname'].
", ".
$_PLICI_CFG['superadmin_username'].
", ".
$_PLICI_CFG['superadmin_password'].
")");
echo_net("@mysql_select_db(".
$_PLICI_CFG['superadmin_databasename'].
", $r_super_admin_sql_connection_id)");
// Error during select database
$g_object_siteinformation->generateFatalError404();
// Get information about select database
$sql_query =
"SELECT * FROM databaseconnect WHERE dbc_dbname = '".
$p_database.
"' AND dbc_dblogin<>'ALIAS';";
echo
("<br />$r_super_admin_sql_connection_id - $sql_query");
$result =
@mysql_query($sql_query, $r_super_admin_sql_connection_id);
$g_object_siteinformation->generateFatalError404();
$r_sql_connection_information['dbc_sitename'] =
$row[0];
$r_sql_connection_information['dbc_dbname'] =
$row[1];
$r_sql_connection_information['dbc_dblogin'] =
$row[2];
$r_sql_connection_information['dbc_dbpass'] =
$row[3];
$r_sql_connection_information['dbc_inherited_sitename'] =
$row[4];
$r_sql_connection_information['dbc_ecommerce'] =
$row[5];
$r_sql_connection_information['dbc_dbhost'] =
$row[6];
$r_sql_connection_information['dbc_available'] =
$row[7];
$r_sql_connection_information['dbc_group'] =
$row[8];
$this->xRemember("sql_db_connection_info_".
$p_database, $r_sql_connection_information);
// Site is not available ?
if ($r_sql_connection_information['dbc_available'] !=
'Y') {
$g_object_siteinformation->generateBusyPage();
if ($this->xIsRemembered("sql_db_connection_id_".
$r_sql_connection_information['dbc_dbhost'].
"_".
$r_sql_connection_information['dbc_dblogin'].
"_".
$r_sql_connection_information['dbc_dbpass'], $r_sql_connection_information['dbc_connection'])) {
// Connect with correct user
$r_sql_connection_information['dbc_connection'] =
plici_mysql_connect($r_sql_connection_information['dbc_dbhost'], $r_sql_connection_information['dbc_dblogin'], $r_sql_connection_information['dbc_dbpass']);
echo_net("@mysql_connect(".
$r_sql_connection_information['dbc_dbhost'].
", ".
$r_sql_connection_information['dbc_dblogin'].
", ".
$r_sql_connection_information['dbc_dbpass'].
");");
echo_net("$select_db_is_ok = @mysql_select_db(".
$r_sql_connection_information['dbc_dbname'].
", ".
$r_sql_connection_information['dbc_connection'].
")");
if (!@mysql_select_db($r_sql_connection_information['dbc_dbname'], $r_sql_connection_information['dbc_connection']))
$g_object_siteinformation->generateFatalError404();
$this->xRemember("sql_db_connection_id_".
$r_sql_connection_information['dbc_dbhost'].
"_".
$r_sql_connection_information['dbc_dblogin'].
"_".
$r_sql_connection_information['dbc_dbpass'], $r_sql_connection_information['dbc_connection']);
* Connect to db and store this cnnection in this object
* @param resource $r_id_connect
* @return bool TRUE on error
// Declare parameters var
$admin_sql_connection_id =
NULL;
$sql_connection_information =
array();
// Get connection info and connection to admin super
$this->getConnection($admin_sql_connection_id, $sql_connection_information, $p_db);
$this->m_id_sql =
& $sql_connection_information['dbc_connection'];
$r_result['dbc_sitename'] =
'NC';
$r_result['dbc_dbname'] =
'NC';
$r_result['dbc_dblogin'] =
'NC';
$r_result['dbc_dbpass'] =
'NC';
$r_result['dbc_dbhost'] =
'NC';
global $g_object_loader, $g_object_siteinformation;
if (!isset
($g_object_siteinformation))
// Temp - usefull to detect problem
//$g_object_siteinformation =& $g_object_loader->getSiteInformation();
//on va chercher sur notre admin_super la base qui correspond au site $siteName
//$id_sql_admin_super = plici_mysql_connect($_PLICI_CFG['superadmin_hostname'], $_PLICI_CFG['superadmin_username'], $_PLICI_CFG['superadmin_password']);
//$id_sql_admin_super = @mysql_connect($_PLICI_CFG['superadmin_hostname'], $_PLICI_CFG['superadmin_username'], $_PLICI_CFG['superadmin_password']);
echo_net("mysql_connect(".
$_PLICI_CFG['superadmin_hostname'].
", ".
$_PLICI_CFG['superadmin_username'].
", ".
$_PLICI_CFG['superadmin_password'].
")");
$g_object_siteinformation->generateFatalError404();
//récuperation des informations de connections
$sql_query =
"SELECT * FROM databaseconnect WHERE dbc_dbname = '".
$p_db.
"' AND dbc_dblogin<>'ALIAS';";
$g_object_siteinformation->generateFatalError404();
// tout semble bon, donc on affecte la connection du admin_super
//$this->m_id_sql_admin_super =& $id_sql_admin_super;
//echo "<br />".print_r_net($row);
$dbc_inherited_sitename =
"";
$r_result['dbc_sitename'] =
$row[0];
$r_result['dbc_dbname'] =
$row[1];
$r_result['dbc_dblogin'] =
$row[2];
$r_result['dbc_dbpass'] =
$row[3];
$r_result['dbc_inherited_sitename'] =
$row[4];
$r_result['dbc_ecommerce'] =
$row[5];
$r_result['dbc_dbhost'] =
$row[6];
$r_result['dbc_available'] =
$row[7];
if ($r_result['dbc_available'] !=
'Y') {
// this site web is not available :(
$g_object_siteinformation->generateBusyPage();
//$id_sql = @mysql_connect($this->m_database_host, $this->m_database_user_name, $this->m_database_user_pass);
$g_object_siteinformation->generateFatalError404();
//tout semble bon, donc on affecte la connection du admin_super
* Get connexion information
* @param string $r_db_name
* @param string $r_user_name
* @param string $r_user_pass
* @return bool TRUE on error
* Get current web site name
* Return the inherited site name for the current web site
* Make an sql query in PLICI into the super admin
* @param string $p_request in vsprintf format with $r_table_params
* @param array $r_table_params
* @param resource $r_result_set
* @return bool TRUE on error
global $g_object_time_elapser;
$id_db_connexion =
$g_object_time_elapser->beginningSQL($sql_query);
$g_object_dbindexsupervision =
& $g_object_loader->getDbIndexSupervision();
$g_object_dbindexsupervision->requestPlayed($sql_query, $this->m_id_sql_admin_super, $_PLICI_CFG['superadmin_databasename']);
echo
"\n<br />Debug - Class dbconnection - makeSqlQuery - Request before vsprintf= <samp>".
$p_request.
"</samp>";
trigger_error("Debug - Class dbconnection - makeSqlQuery - Requete after vsprintf= ".
$p_request);
echo
"\n<br />Array Parameters - <samp>".
print_r($r_table_params,true).
"</samp>";
echo
("<br />Request = <samp>".
$sql_query.
"</samp><br />");
//echo("<br />Request = <br /><pre style='text-align:left;'><samp>".$sql_query."</samp></pre><br />");
$g_object_time_elapser->endingSQL($id_db_connexion);
* Make an sql query in PLICI and return the insert id
* @param string $p_request in vsprintf format with $r_table_params
* @param array $r_table_params
* @param resource $r_result_set
* @param integer $r_insert_id
* @return bool TRUE on error
function makeSqlQueryWithId($p_request, &$r_table_params, &$r_result_set, &$r_insert_id) {
$error =
$this->makeSqlQuery($p_request, $r_table_params, $r_result_set);
* Format and protect any request
* @param array $r_table_params
* @param string $p_request in vsprintf format with $r_table_params
* @return bool TRUE on error
if (sizeof($r_table_params) ==
0)
// Protection sql injection
for ($i=
0;$i<
sizeof($r_table_params);$i++
) {
//Fusion requete<->parametre
return vsprintf($p_request, $r_table_params);
* Make an sql query in PLICI, in the current website
* @param string $p_request in vsprintf format with $r_table_params
* @param array $r_table_params
* @param resource $r_result_set
* @param string $p_database_selected
* @return bool TRUE on error
function makeSqlQuery($p_request, &$r_table_params, &$r_result_set, $p_database_selected=
"") {
global $g_object_time_elapser;
// Protection sql injection
$id_db_connexion =
$g_object_time_elapser->beginningSQL($sql_query);
// on determine si on doit vider ou non le cache, pour cela deux critères
// l'instruction doit être un insert ou un update
$sql_query =
trim($sql_query);
global $g_object_siteinformation;
if ($g_object_siteinformation->isAdmin())
if (preg_match("/(insert[ ]*into|update)+[ ]+([[:alnum:]_]+)/i",$sql_query, $found) >
0) {
//echo("i must destroy cache");
$smarty =
& $g_object_loader->getSmarty_Custom();
//$caching = $smarty->caching;
//$smarty->caching = true;
// on vide le cache du FrontOffice à cause de l'update ou insert
$tmp_cache_dir =
$smarty->cache_dir;
$smarty->cache_dir =
$g_object_siteinformation->getTemplateCacheFilePath(true);
$smarty->clear_all_cache();
$smarty->cache_dir =
$tmp_cache_dir;
foreach($slaves as $slave_dbname) {
$tmp_cache_dir =
$smarty->cache_dir;
$smarty->cache_dir =
$g_object_siteinformation->getTemplateCacheFilePathSpecific($slave_dbname);
$smarty->clear_all_cache();
$smarty->cache_dir =
$tmp_cache_dir;
//$smarty->caching = $caching;
// Set database selected and slq connection id
$sql_connection_selected =
$this->m_id_sql;
// If database selected, we are in master of websitegroup but we must load slave information
// We must select slave database
// Set super admin sql connection id var
$super_admin_connection_id =
NULL;
// Connection to slave group database
$slave_group_sql_connection_information =
array();
$this->getConnection($super_admin_connection_id, $slave_group_sql_connection_information ,$p_database_selected);
$database_selected =
$p_database_selected;
$sql_connection_selected =
$slave_group_sql_connection_information['dbc_connection'];
// Check if the website is a slave of a website group
$master_website_group =
"";
//echo "<br /> (".$master_website_group.") - ".$sql_query;
// This site is in web site group and
// request can be played in master of group
// Set number of table to detect
// Detect table in request
while (($not_found) &&
($ind<
$nof_table_to_detect))
// Not found specific table
// Search in globascope with special parameters
foreach($sql_fields as $sql_field)
$not_found =
$not_found &&
((false===
(stristr($sql_query, $sql_table))) ||
(false===
(stristr($sql_query, $sql_field))));
// echo "<strong>Ailleurs</strong> - ";
//echo "Request: ".$sql_query;
// We must select master database
// Set super admin sql connection id var
$super_admin_connection_id =
NULL;
// Connection to master group database
$master_group_sql_connection_information =
array();
$this->getConnection($super_admin_connection_id, $master_group_sql_connection_information ,$master_website_group);
$database_selected =
$master_website_group;
$sql_connection_selected =
$master_group_sql_connection_information['dbc_connection'];
// Set sql connection result var
$r_result_set =
mysql_query($sql_query, $sql_connection_selected);
$g_object_dbindexsupervision =
& $g_object_loader->getDbIndexSupervision();
$g_object_dbindexsupervision->requestPlayed($sql_query, $sql_connection_selected, $database_selected);
/*if (0== strcasecmp("INSERT",substr(trim($sql_query), 0, 6))) {
$r_result_set = mysql_insert_id($sql_connection_selected);
//echo("<br>Requete = <font color='#FF0000'>".$sql_query."</font><br>");
echo
"\n<br />Debug - Class dbconnection - makeSqlQuery - Request before vsprintf= <samp>".
$p_request.
"</samp>";
trigger_error("Debug - Class dbconnection - makeSqlQuery - Request after vsprintf= ".
$p_request);
echo
"\n<br />Array Parameters - <samp>".
print_r($r_table_params,true).
"</samp>";
//echo("<br />Request = <samp>".$sql_query."</samp><br />");
echo
("<br />Request = <br /><pre style='text-align:left;'><samp>".
$sql_query.
"</samp></pre><br />");
//print_r($r_result_set);
$g_object_time_elapser->endingSQL($id_db_connexion);
* @return bool TRUE on error
// Set request parameters var
$request_parameter =
array();
// Set request result var
$request_result =
array();
// Search if database_name is in group member
$r_result[$row[0]] =
$row[1];
* Return master of web group for selected database
* @param string $r_result
* @param string $dbc_dbname
* @return bool TRUE on error
// This member is empty => Get value and fill it
$tmp_website_group =
array();
// Search master of group
* Return Slave for this master
* @param array $r_result Slaves
* @param string $p_dbc_dbname master database name
* @return bool TRUE on error
// This member is empty => Get value and fill it
$tmp_website_group =
array();
if ($master_dbname ==
$p_dbc_dbname)
$r_result[] =
$dbc_dbname;
* Must if we must check website master group for specified table (and field)
// Méthodes de nettoyage de données //
//Méthode qui convertit(encode/décode) les données
// Toutes les données insérées en BD ne sont pas encodées EXCEPTE celle de FCK_EDITOR
// Différents cas de figure:
// ->FCK => Aucun changement et texte encodé
// ->Autres => Aucun changement et texte brut
// ->FCK => Aucune modification
// ->Autres => Aucune modification. La protection contre " et ' est faite par le modificateur smarty net_value
// ->FCK => Aucun changement car texte déjà encodé
// ->Autres => Encodé les entité, les caractères spéciaux ?, transformer les nl en <br>
// ->Affichage en plain text
// ->FCK => Decodage des caractères, suppression des balises,...
// ->Autres => Suppressions des balises,....
* Translate a parameter before or after receiving from database
* @param string $p_type 'FCK_TO_DB_FCK','TO_DB','DB_FCK_TO_INPUT','DB_TO_INPUT','DB_FCK_TO_HTML','DB_TO_HTML','DB_TO_ALT','DB_TO_ARRAY_INDEX','HTML_TO_PLAIN_STRING','HTML_TO_PLAIN','HTML_TO_RSS'
$translate_definition =
array();
$translate_definition["FCK_TO_DB_FCK"] =
array("html"=>
"clean");
$translate_definition["TO_DB"] =
array();
$translate_definition["DB_FCK_TO_INPUT"]=
array();
$translate_definition["DB_TO_INPUT"] =
array();
$translate_definition["DB_FCK_TO_HTML"] =
array();
$translate_definition["DB_TO_HTML"] =
array("entity"=>
"encode",
$translate_definition["DB_TO_ALT"] =
array();/*A completer*/
// ->Utilisation pour l'index d'un tableau
$translate_definition["DB_TO_ARRAY_INDEX"]=
array("entity"=>
"decode",
// ->Affichage en plain text
$translate_definition["HTML_TO_PLAIN_STRING"]=
array(
$translate_definition["HTML_TO_PLAIN"] =
array("entity"=>
"decode",
// Non utilisé => Utilisation de HTML_TO_PLAIN à utiliser
$translate_definition["HTML_TO_RSS"]=
array("entity"=>
"decode",
//Récupération des opérations a effectuer
//Correction erreur fck qui normalement devrait pas apparaitre et qui font apparaitre https:// et ../../ dans liens vers
$result =
preg_replace("@(href|src)=\"(\.\./\.\./\.\./\.\.|http(s?)://".
$_SERVER["SERVER_NAME"].
")/@","\$1=\"/", $result);
//$clean_result = $result; //Debug
// Suppression class Microsoft
$result =
preg_replace("@class=\"MsoNormal\"@i", "", $result);
//Desactivate, the result hasn't the same look that the customer see in the html editor
//The first cause was the option bare and clean
'drop-proprietary-attributes' => true,
//'drop-font-tags'=> true,
'drop-empty-paras' => true,
'show-body-only' => true,
$tidy->parseString($result, $tidy_config, 'latin1');
//Traitement des balises des css
// L'option clean a ajouter tous les styles dans le head
$tidy_head = tidy_get_head($tidy);
//On récupère la liste des styles
preg_match_all("/([a-zA-Z0-9]*)\.c([0-9])* {([^}]*)}/", $tidy_head->value, $style_list);
// On les applique au niveau des balises
for($i=0; $i<count($style_list[2]);$i++)
$result = preg_replace("@<".$style_list[1][$i]." class=\"c".$style_list[2][$i]."\">@i",
"<".$style_list[1][$i]." style=\"".$style_list[3][$i]."\">", $result);
$result =
preg_replace("@margin(-(right|left|top|bottom))?: (-?[1-9 ][0-9. ]+(%|ex|em|px|cm|mm|pc|in|pt|))+@i", "", $result);
Stef j'ai supprimé pour FS#111 — fck editor add _fcksavedurl
FS#112 — balise ALT disparait
// Suppression des balises vides
$array_balise_inline = array('a href','b','caption','cite','col','em','font','h1','h2','h3','h4'
,'h5','i','kdb','label','legend','pre','q','small','span','strong','sub','sup','var');
foreach($array_balise_inline as $value)
$result = preg_replace("@<".$value."[^>]*?>[\s| ]*</".$value.">@i", "", $result);
$array_balise = array('p');
foreach($array_balise as $value)
$result = preg_replace("@<".$value."[^>]*?>[\s| ]*</".$value.">@i", "<br />", $result);
$result = preg_replace("@(<div[^>]*?>[\s| ]*</div[^>]*?>[\s]*)+@i", "<br />", $result);
//$result = $clean_result; //Debug
//! A positionner avant car on est susceptible de supprimer les balises après ! //
// Voir a la fin. Sinon les caractères du br risque d'être encodé
$result =
str_replace(array("\n", "\r"), array("", ""), $result);
//suppression des lignes modes windows et Mac. Tout en UNIX
//$result = preg_replace("/<(br|p)/is", " ", $result);
"/<!--.*?-->/is",// Supp Commentaire
"/<body[^>]*>(.*)<\/body>/is", // Supp Head
"/<script[^>]*>.*?<\/script>/is",// Supp Balises spéciales
"/<noscript[^>]*>.*?<\/noscript>/is",
"/<style[^>]*>.*?<\/style>/is"
$array_replacement =
array("", "\\1", "", "", "");
$result =
preg_replace($array_pattern, $array_replacement, $result);
// // Supp des tags restants
//$result = str_replace("'", "'", $result);
//Placé ici car les caractères < et> peuvent être encodé
$result =
nl2br($result);
$result =
preg_replace("/<br *\/>([ \n\t\r]*<br *\/>)+/is", "<br />", $result);
// if ($p_type == "HTML_TO_PLAIN_STRING" || $p_type == "HTML_TO_PLAIN")
// echo_net("before translate($p_type, $p_data) => $result");
* Test if table name exist
* @param string $p_table_name
* @return bool TRUE = table exist
$requ =
"SHOW TABLE STATUS like '%s';";
$parameter =
array($p_table_name);
* Execute multiple request in a string
* @param string $sql_to_play
* @return bool TRUE on error
$array_request =
array();
$is_car_inhibiter =
false;
$remember_initial_quote =
'';
$waiting_for_possible_comment =
true;
$first_comment_finded =
false;
$second_comment_finded =
false;
for($i=
0; $i<
strlen($sql_to_play);$i++
) {
if ($second_comment_finded &&
$sql_to_play[$i] ==
"\n"){
} else if ($second_comment_finded) {
if ($sql_to_play[$i] ==
"\n") {
$waiting_for_possible_comment =
true;
$first_comment_finded =
false;
$second_comment_finded =
false;
} else if ($waiting_for_possible_comment &&
$sql_to_play[$i] ==
"-") {
if ($first_comment_finded)
$second_comment_finded =
true;
$first_comment_finded =
true;
} else if ($sql_to_play[$i] !=
" " &&
$sql_to_play[$i] !=
"\t") {
$waiting_for_possible_comment =
false;
$first_comment_finded =
false;
$second_comment_finded =
false;
$first_comment_finded =
false;
$second_comment_finded =
false;
$is_car_inhibiter =
false;
// echo_net("inhibiter to FALSE ".$sql_to_play[$i]." (remembered quote :".$remember_initial_quote.")");
if ($sql_to_play[$i] ==
"\\") {
$is_car_inhibiter =
true;
// echo_net("inhibiter to TRUE ".$sql_to_play[$i]." (remembered quote :".$remember_initial_quote.")");
if (($remember_initial_quote ==
"") &&
(($sql_to_play[$i] ==
"'") ||
($sql_to_play[$i] ==
'"'))){
$remember_initial_quote =
$sql_to_play[$i];
// echo_net("STARTING quote : ".$sql_to_play[$i]." (remembered quote :".$remember_initial_quote.")");
} else if (($remember_initial_quote !=
'') &&
($sql_to_play[$i] ==
$remember_initial_quote )) {
// echo_net("ENDING quote : ".$sql_to_play[$i]." (remembered quote :".$remember_initial_quote.")");
$remember_initial_quote =
'';
} else if (($sql_to_play[$i] ==
";") &&
!$i_am_in_quote) {
$new_request =
substr($sql_to_play, $last_start, $i+
1-
$last_start);
// on desactive les LOCK TABLES
if (preg_match('/^LOCK[\s]+TABLES/i', $new_request) ||
preg_match('/^UNLOCK[\s]+TABLES[\s]*;/i', $new_request))
if ($new_request !=
"" &&
$new_request !=
";") {
$this->makeSqlQuery($new_request, $parameters, $mysql_result);
// $mysql_result = mysql_query($new_request, $mysql_link);
// echo("$file_path.$end_line \n\n<br/>ERROR mysql_execute_script : ".mysql_error($mysql_link)." for request <br/>".$new_request."<br/>");
// echo_net("finded ;"." (remembered quote :".$remember_initial_quote.")");
// echo_net("Making string ".$new_request." (remembered quote :".$remember_initial_quote.")");
// echo_net("car not used : ".$sql_to_play[$i]." (remembered quote :".$remember_initial_quote.")");
// print_r_net($array_request);
* Lock tables for order process
* @return bool TRUE on error
// Prevent script stop by user
global $g_lang_access_db;
// Prevent t_lang class to access to db
$g_lang_access_db =
false;
$parameters_for_lock_table =
array();
$result_for_lock_table =
array();
$g_lang_access_db =
false;
* Unlock tables for commande process
* @return bool TRUE on error
$parameters_for_unlock_table =
array();
$result_for_unlock_table =
array();
global $g_lang_access_db;
// Prevent t_lang class to access to db
$g_lang_access_db =
true;
// Stop Prevent script stop by user
Documentation generated on Tue, 25 Mar 2008 15:34:36 +0100 by phpDocumentor 1.3.2