Source for file dbconnexion.class.php

Documentation is available at dbconnexion.class.php

  1. <?php   /*
  2.    *@=@=@=@ START LICENSE @=@=@=@*
  3.    Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
  4.    
  5.    stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
  6.    
  7.    This software is a computer program whose purpose is to make a
  8.    web hosting platform
  9.    
  10.    This software is governed by the CeCILL  license under French law and
  11.    abiding by the rules of distribution of free software.  You can  use, 
  12.    modify and/ or redistribute the software under the terms of the CeCILL
  13.    license as circulated by CEA, CNRS and INRIA at the following URL
  14.    "http://www.cecill.info". 
  15.    
  16.    As a counterpart to the access to the source code and  rights to copy,
  17.    modify and redistribute granted by the license, users are provided only
  18.    with a limited warranty  and the software's author,  the holder of the
  19.    economic rights,  and the successive licensors  have only  limited
  20.    liability. 
  21.    
  22.    In this respect, the user's attention is drawn to the risks associated
  23.    with loading,  using,  modifying and/or developing or reproducing the
  24.    software by the user in light of its specific status of free software,
  25.    that may mean  that it is complicated to manipulate,  and  that  also
  26.    therefore means  that it is reserved for developers  and  experienced
  27.    professionals having in-depth computer knowledge. Users are therefore
  28.    encouraged to load and test the software's suitability as regards their
  29.    requirements in conditions enabling the security of their systems and/or 
  30.    data to be ensured and,  more generally, to use and operate it in the 
  31.    same conditions as regards security. 
  32.    
  33.    The fact that you are presently reading this means that you have had
  34.    knowledge of the CeCILL license and that you accept its terms.
  35.    *@=@=@=@ END   LICENSE @=@=@=@*
  36.  
  37. */?><?php  
  38. /**
  39.  * DbConnexion Class
  40.  * 
  41.  * 
  42.  * @author SimpliciWeb
  43.  * @version $Id: dbconnexion.class.php 872 2008-01-31 16:09:33Z stephanet $
  44.  * @package Common
  45.  * @subpackage FrameWork
  46.  */    
  47. /**
  48.  * Require object cached
  49.  */
  50. require_once('internal_components/common/cache_class/object_cached.class.php');
  51.  
  52. /**
  53.  * The object to make request and be connected to the databases
  54.  *
  55.  * @author SimpliciWeb
  56.  * @version $Id: dbconnexion.class.php 872 2008-01-31 16:09:33Z stephanet $
  57.  * @package Common
  58.  * @subpackage FrameWork
  59.  */
  60.  
  61.  
  62. //    echo(HTML_ENTITIES);
  63. //    print_r(get_html_translation_table (HTML_ENTITIES));
  64.     
  65.  
  66.   // $Id: dbconnexion.class.php 872 2008-01-31 16:09:33Z stephanet $
  67.  
  68.   // en entrée :
  69.   //  $siteName = nom du site
  70.  
  71.   //  je vais sur le admin_super afin de trouver les codes d'accès
  72.   //  en fonction de la demande de site réalisée
  73.   // 
  74.   class DbConnexion extends ObjectCached {
  75.   
  76.     /**
  77.      * The id for admin super
  78.      *
  79.      * @var resource 
  80.      */    
  81.     var $m_id_sql_admin_super  = NULL ;
  82.     /**
  83.      * The id for current web site
  84.      *
  85.      * @var resource 
  86.      */    
  87.     var $m_id_sql            = NULL ;
  88.     /**
  89.      * Current site name
  90.      *
  91.      * @var string 
  92.      */    
  93.     var $m_site_name         = NULL ;
  94.     /**
  95.      * @var resource 
  96.      */    
  97.     var $m_last_connection_sql_id    = NULL;
  98.     /**
  99.      * Inherited site name
  100.      *
  101.      * @var string 
  102.      */    
  103.     var $m_database_inherited_sitename = "";
  104.  
  105.     /**
  106.      * Store list of table use in master
  107.      *
  108.      * @var array 
  109.      */
  110.     var $m_master_website_group_table             = array();
  111.     /**
  112.      * Store list of fields use in master
  113.      *
  114.      * @var array 
  115.      */
  116.     var $m_master_website_group_table_and_field = array();
  117.  
  118.     /**
  119.      * Is ecommerce website
  120.      *
  121.      * @var bool 
  122.      */
  123.     var $m_database_is_ecommerce_web_site = false;    
  124.  
  125.     /**
  126.      * Get website group
  127.      *
  128.      * @var array 
  129.      */
  130.     var  $m_website_group = array();
  131.  
  132.     /**
  133.      * SQL Request : Get web site group
  134.      *
  135.      * @var string 
  136.      */
  137.     var $req_get_websitegroup    =
  138. "SELECT dbc_dbname, dbc_group
  139. FROM databaseconnect 
  140. WHERE dbc_dblogin<>'ALIAS'
  141. ORDER BY dbc_dbname ;";
  142.     /**
  143.      * SQL Request : Lock tables
  144.      *
  145.      * @var string 
  146.      */
  147.     var $req_lock_table = "
  148. LOCK TABLES t_address READ, t_attribut READ, t_attributvalue READ, t_area_has_t_deliverycosts_type READ,
  149.         t_country READ, t_customer_has_t_productmaster WRITE, t_deliverycosts_type READ, 
  150.         t_globalscope READ, t_lang READ, t_payment_method READ, t_payment_method_special READ,
  151.         t_productmaster READ, t_productslave WRITE, t_productmodifier READ,
  152.         t_order WRITE, t_orderdetail WRITE, t_order_id WRITE, 
  153.         t_setting READ, t_shoppingcart WRITE, t_text READ, t_text_field READ, t_text_field_bbcode READ, t_tvatype WRITE ;";
  154.  
  155.     /**
  156.      * SQL Request : Unlok tables
  157.      *
  158.      * @var string 
  159.      */
  160.     var $req_unlock_table = "UNLOCK TABLES;";
  161.  
  162.     /**
  163.      * Active this var to debug any request
  164.      *
  165.      * @var bool 
  166.      */
  167.     var $debug_is_on = false// variable de DEBUG qui doit rester là
  168.     
  169.     /**
  170.      * Database name
  171.      *
  172.      * @var string 
  173.      */
  174.     var $m_database_name = NULL;
  175.     /**
  176.      * Database user
  177.      *
  178.      * @var string 
  179.      */
  180.     var $m_database_user_name = NULL;
  181.     /**
  182.      * Database pass
  183.      *
  184.      * @var string 
  185.      */
  186.     var $m_database_user_pass = NULL;
  187.     /**
  188.      * Database host
  189.      *
  190.      * @var string 
  191.      */
  192.     var $m_database_host = "";
  193.     
  194.     /**
  195.      * Supproted tags
  196.      *
  197.      * @var array 
  198.      */
  199.     var $m_supported_tags = array();
  200.     /**
  201.      * table not destroying cache
  202.      *
  203.      * @var array 
  204.      */
  205.     var $m_not_destroying_cache = array();
  206. /**
  207.  * @var array 
  208.  */
  209.     var $HTML_SPECIALCHARS_REVERSED = array();
  210. /**
  211.  * @var array 
  212.  */
  213.     var $HTML_ENTITIES_REVERSED = array();
  214.     
  215. /**
  216.  * @var array 
  217.  */
  218.     var $WINDOWS_SPECIAL_CHAR    = array();
  219.     
  220.     /**
  221.      * Active this var to debug connectivity
  222.      *
  223.      * @var bool 
  224.      */
  225.     var $m_debug_connectivity = FALSE;
  226.     
  227.     /**
  228.      * Constructor, init the requests and objects
  229.      *
  230.      * @return DbConnexion 
  231.      */
  232.     function DbConnexion ({
  233.  
  234.         global $g_object_loader$g_object_siteinformation;
  235.         if (!isset($g_object_siteinformation))
  236.         {
  237.             // Temp - usefull to detect problem
  238.             trigger_error("Bad call to siteInformation");
  239.             die();
  240.         }
  241.         //$g_object_siteinformation =& $g_object_loader->getSiteInformation();
  242.  
  243.         $p_database_site_name $g_object_siteinformation->getDatabaseSiteName();
  244.             
  245.         $this->m_site_name = $p_database_site_name;
  246.  
  247.         $id_sql NULL;
  248.         $this->connectToDB($this->m_site_name$id_sql);
  249.  
  250.  
  251.  
  252.         // Permet de faire un tableau des TAG HTML supportés par 
  253.         // le dbToHtml
  254.         $supported_tags_base array();
  255.         $supported_tags array();
  256.         
  257.         $supported_tags_base[sizeof($supported_tags_base)"TABLE";
  258.         $supported_tags_base[sizeof($supported_tags_base)"CAPTION";
  259.         $supported_tags_base[sizeof($supported_tags_base)"TBODY";
  260.         $supported_tags_base[sizeof($supported_tags_base)"TR";
  261.         $supported_tags_base[sizeof($supported_tags_base)"TD";
  262.         $supported_tags_base[sizeof($supported_tags_base)"P";
  263.         $supported_tags_base[sizeof($supported_tags_base)"HR";
  264.         $supported_tags_base[sizeof($supported_tags_base)"STRONG";
  265.         $supported_tags_base[sizeof($supported_tags_base)"EM";
  266.         $supported_tags_base[sizeof($supported_tags_base)"U";
  267.         $supported_tags_base[sizeof($supported_tags_base)"STRIKE";
  268.         $supported_tags_base[sizeof($supported_tags_base)"SUB";
  269.         $supported_tags_base[sizeof($supported_tags_base)"SUP";
  270.         $supported_tags_base[sizeof($supported_tags_base)"OL";
  271.         $supported_tags_base[sizeof($supported_tags_base)"LI";
  272.         $supported_tags_base[sizeof($supported_tags_base)"DIV";
  273.         $supported_tags_base[sizeof($supported_tags_base)"BR";
  274.         $supported_tags_base[sizeof($supported_tags_base)"FONT";
  275.         $supported_tags_base[sizeof($supported_tags_base)"A";
  276.         $supported_tags_base[sizeof($supported_tags_base)"IMG";
  277.  
  278.         $save_count_supported_tags sizeof($supported_tags_base);
  279.         for ($i =0$i $save_count_supported_tags$i++{
  280.             $supported_tags[sizeof($supported_tags)$supported_tags_base[$i];
  281.             $supported_tags[sizeof($supported_tags)"/".$supported_tags_base[$i].">";
  282.         }
  283.  
  284.         $this->m_supported_tags = $supported_tags;
  285.         
  286.         
  287.         
  288.         // liste des talbes n'affectant pas le cache du front office
  289.         $this->m_not_destroying_cache['t_shoppingcart']                 "no";
  290.         $this->m_not_destroying_cache['t_customer']                     "no";
  291.         $this->m_not_destroying_cache['t_session']                         "no";
  292.         $this->m_not_destroying_cache['t_searchedwords']                "no";
  293.         $this->m_not_destroying_cache['t_bo_users']                        "no";
  294.         $this->m_not_destroying_cache['t_bo_users_has_t_bo_group']        "no";
  295.         $this->m_not_destroying_cache['t_bo_group']                        "no";
  296.         $this->m_not_destroying_cache['t_bo_menu_has_t_bo_group']        "no";
  297.         $this->m_not_destroying_cache['t_bo_menu']        "no";
  298.         
  299.        
  300.  
  301.  
  302.  
  303.  
  304.         // inverse HTML_SPECIALCHARS dans HTML_SPECIALCHARS_REVERSED 
  305.         $this->HTML_SPECIALCHARS_REVERSED = get_html_translation_table (HTML_SPECIALCHARS);
  306.         $keys array_keys($this->HTML_SPECIALCHARS_REVERSED);
  307.         for ($i=0$i<sizeof($keys)$i++)
  308.             $this->HTML_SPECIALCHARS_REVERSED[strtoupper($keys[$i])$this->HTML_SPECIALCHARS_REVERSED[$keys[$i]];
  309.         
  310.         $this->HTML_ENTITIES_REVERSED = get_html_translation_table (HTML_ENTITIES);
  311.         $this->HTML_ENTITIES_REVERSED = array_flip ($this->HTML_ENTITIES_REVERSED);
  312.         $keys array_keys($this->HTML_ENTITIES_REVERSED);
  313.         for ($i=0$i<sizeof($keys)$i++)
  314.             $this->HTML_ENTITIES_REVERSED[strtoupper($keys[$i])$this->HTML_ENTITIES_REVERSED[$keys[$i]];
  315.         
  316.         $this->WINDOWS_SPECIAL_CHAR["ƒ""&fnof;";
  317.         $this->WINDOWS_SPECIAL_CHAR["…""&hellip;";
  318.         $this->WINDOWS_SPECIAL_CHAR["†""&dagger;";
  319.         $this->WINDOWS_SPECIAL_CHAR["‡""&Dagger;";
  320.         $this->WINDOWS_SPECIAL_CHAR["ˆ""&circ;";
  321.         $this->WINDOWS_SPECIAL_CHAR["‰""&permil;";
  322.         $this->WINDOWS_SPECIAL_CHAR["Š""&Scaron;";
  323.         $this->WINDOWS_SPECIAL_CHAR["Œ""&OElig;";
  324.         $this->WINDOWS_SPECIAL_CHAR["Ž""&Zcaron;";
  325.         $this->WINDOWS_SPECIAL_CHAR["‘""&lsquo;";
  326.         $this->WINDOWS_SPECIAL_CHAR["’""&rsquo;";
  327.         $this->WINDOWS_SPECIAL_CHAR["“""&ldquo;";
  328.         $this->WINDOWS_SPECIAL_CHAR["”""&rdquo;";
  329.         $this->WINDOWS_SPECIAL_CHAR["•""&bull;";
  330.         $this->WINDOWS_SPECIAL_CHAR["–""&ndash;";
  331.         $this->WINDOWS_SPECIAL_CHAR["—""&mdash;";
  332.         $this->WINDOWS_SPECIAL_CHAR["™""&trade;";
  333.         $this->WINDOWS_SPECIAL_CHAR["š""&scaron;";
  334.         $this->WINDOWS_SPECIAL_CHAR["œ""&oelig;";
  335.         $this->WINDOWS_SPECIAL_CHAR["ž""&zcaron;";
  336.         $this->WINDOWS_SPECIAL_CHAR["Ÿ""&Yuml;";
  337.         $this->WINDOWS_SPECIAL_CHAR["'""&#039;";
  338.         $this->WINDOWS_SPECIAL_CHAR["\"""&quote;";
  339.  
  340.         // Store list of table use in master
  341.            $this->m_master_website_group_table["t_page";
  342.            $this->m_master_website_group_table["t_keyword";
  343.            $this->m_master_website_group_table["t_customer";
  344.            $this->m_master_website_group_table["t_rss";
  345.            // This table was locked during order so we must check
  346.            $this->m_master_website_group_table["t_address";
  347.            $this->m_master_website_group_table["t_attribut";
  348.            $this->m_master_website_group_table["t_attributvalue";
  349.            $this->m_master_website_group_table["t_area_has_t_deliverycosts_type";
  350.            $this->m_master_website_group_table["t_bill";
  351.            $this->m_master_website_group_table["t_country";
  352.            $this->m_master_website_group_table["t_customer_has_t_productmaster";
  353.            $this->m_master_website_group_table["t_deliverycosts_type";
  354.            $this->m_master_website_group_table["t_design";
  355.            $this->m_master_website_group_table["t_payment_method";
  356.            $this->m_master_website_group_table["t_payment_method_special";
  357.            $this->m_master_website_group_table["t_productmaster";
  358.            $this->m_master_website_group_table["t_productslave";
  359.            $this->m_master_website_group_table["t_productmodifier";
  360.            $this->m_master_website_group_table["t_order";
  361.            $this->m_master_website_group_table["t_orderdetail";
  362.            $this->m_master_website_group_table["t_order_id";
  363.            $this->m_master_website_group_table["t_setting";
  364.            $this->m_master_website_group_table["t_shoppingcart";
  365.            $this->m_master_website_group_table["t_text_field";
  366.            $this->m_master_website_group_table["t_text_field_bbcode";
  367.            $this->m_master_website_group_table["t_tvatype";
  368.            $this->m_master_website_group_table["unlock";
  369.  
  370.         // Store table and field
  371.         $this->m_master_website_group_table_and_field['t_globalscope'array();
  372.         //$this->m_master_website_group_table_and_field['t_globalscope'][] = "a_m_s";
  373.         $this->m_master_website_group_table_and_field['t_globalscope']["a_p_f";
  374.         $this->m_master_website_group_table_and_field['t_globalscope']["a_d_f";
  375.         $this->m_master_website_group_table_and_field['t_globalscope']["a_w_f";
  376.         $this->m_master_website_group_table_and_field['t_globalscope']["m_ndf";
  377.         //$this->m_master_website_group_table_and_field['t_globalscope'][] = "swif_";
  378.         // Not be good because we can have 2 same id for 2 picture <>
  379.         // One in master and other in slave
  380.         $this->m_master_website_group_table_and_field['t_picture']array();
  381.         $this->m_master_website_group_table_and_field['t_picture']["pl";
  382.         $this->m_master_website_group_table_and_field['t_picture']["pm";
  383.         $this->m_master_website_group_table_and_field['t_picture']["pf";
  384.         $this->m_master_website_group_table_and_field['t_picture']["rl";
  385.         $this->m_master_website_group_table_and_field['t_picture']["rm";
  386.         $this->m_master_website_group_table_and_field['t_picture']["rf";
  387.  
  388.     }
  389.  
  390.     /**
  391.      * Get connection
  392.      *
  393.      * @param resource $r_super_admin_sql_connection_id 
  394.      * @param resource $r_sql_connection_information 
  395.      * @param string $p_database 
  396.      * @return bool TRUE on error
  397.      */
  398.     function getConnection(&$r_super_admin_sql_connection_id&$r_sql_connection_information$p_database)
  399.     {
  400.         // Set empty result
  401.         $r_super_admin_sql_connection_id NULL;
  402.         $r_sql_connection_information array();
  403.         $r_sql_connection_information['dbc_connection']    NULL;
  404.         $r_sql_connection_information['dbc_sitename']    'NC';
  405.         $r_sql_connection_information['dbc_dbname']        'NC';
  406.         $r_sql_connection_information['dbc_dblogin']    'NC';
  407.         $r_sql_connection_information['dbc_dbpass']        'NC';
  408.         $r_sql_connection_information['dbc_dbhost']        'NC';
  409.  
  410.         // Load global object
  411.         global $g_object_loader$g_object_siteinformation$_PLICI_CFG;
  412.            if (!isset($g_object_siteinformation))
  413.         {
  414.             // Temp - usefull to detect problem
  415.             trigger_error("Bad call to siteInformation");
  416.             die();
  417.         }
  418.  
  419.         // Check cache
  420.         if ($this->xIsRemembered("sql_super_adm_connection_id"$r_super_admin_sql_connection_id)) {
  421.             // Do nothing
  422.         else {
  423.             // Connect to super admin
  424.             $r_super_admin_sql_connection_id plici_mysql_connect($_PLICI_CFG['superadmin_hostname']$_PLICI_CFG['superadmin_username']$_PLICI_CFG['superadmin_password']);
  425.  
  426.             // Store in cache
  427.             $this->xRemember("sql_super_adm_connection_id"$r_super_admin_sql_connection_id);
  428.         }
  429.  
  430.         // Check cache for databaseconnect information
  431.         if ($this->xIsRemembered("sql_db_connection_info_".$p_database$r_sql_connection_information)) {
  432.             // Do nothing
  433.         else {
  434.                 // Select database
  435.             $select_db_is_ok @mysql_select_db($_PLICI_CFG['superadmin_databasename']$r_super_admin_sql_connection_id);
  436.                if ($this->m_debug_connectivity{
  437.                 echo_net("mysql_connect(".$_PLICI_CFG['superadmin_hostname'].", ".$_PLICI_CFG['superadmin_username'].", ".$_PLICI_CFG['superadmin_password'].")");
  438.                 echo_net("@mysql_select_db(".$_PLICI_CFG['superadmin_databasename']."$r_super_admin_sql_connection_id)");
  439.                }
  440.  
  441.             // Error during select database
  442.             if (!$select_db_is_ok
  443.                 $g_object_siteinformation->generateFatalError404();
  444.  
  445.                // Get information about select database
  446.             $sql_query "SELECT * FROM databaseconnect WHERE  dbc_dbname = '".$p_database."' AND dbc_dblogin<>'ALIAS';";
  447.  
  448.             if ($this->m_debug_connectivity
  449.                 echo("<br />$r_super_admin_sql_connection_id - $sql_query");
  450.  
  451.             // Execute query
  452.             $result @mysql_query($sql_query$r_super_admin_sql_connection_id);
  453.  
  454.             // Error during request
  455.             if (!$result)
  456.             {
  457.                 $g_object_siteinformation->generateFatalError404();
  458.             }
  459.  
  460.             // Retrieve result
  461.             $row @mysql_fetch_row($result);
  462.             if (sizeof($row0{
  463.                 $r_sql_connection_information['dbc_sitename']     $row[0];
  464.                 $r_sql_connection_information['dbc_dbname']     $row[1];
  465.                 $r_sql_connection_information['dbc_dblogin']     $row[2];
  466.                 $r_sql_connection_information['dbc_dbpass']     $row[3];
  467.                 $r_sql_connection_information['dbc_inherited_sitename'$row[4];
  468.                 $r_sql_connection_information['dbc_ecommerce']     $row[5];
  469.                 $r_sql_connection_information['dbc_dbhost']     $row[6];
  470.                 $r_sql_connection_information['dbc_available']     $row[7];
  471.                 $r_sql_connection_information['dbc_group']         $row[8];
  472.             }
  473.  
  474.             // Store in cache
  475.             $this->xRemember("sql_db_connection_info_".$p_database$r_sql_connection_information);
  476.         }
  477.  
  478.  
  479.         // Site is not available ?
  480.         if ($r_sql_connection_information['dbc_available'!= 'Y'{
  481.             $g_object_siteinformation->generateBusyPage();
  482.         }
  483.  
  484.         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'])) {
  485.         //     Do nothing
  486.         else {
  487.             // Connect with correct user
  488.             $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']);
  489.             if ($this->m_debug_connectivity{
  490.                 echo_net("@mysql_connect(".$r_sql_connection_information['dbc_dbhost'].", ".$r_sql_connection_information['dbc_dblogin'].", ".$r_sql_connection_information['dbc_dbpass'].");");
  491.                 echo_net("$select_db_is_ok = @mysql_select_db(".$r_sql_connection_information['dbc_dbname'].", ".$r_sql_connection_information['dbc_connection'].")");
  492.             }
  493.             // Select database
  494.             if (!@mysql_select_db($r_sql_connection_information['dbc_dbname']$r_sql_connection_information['dbc_connection']))
  495.                 $g_object_siteinformation->generateFatalError404();
  496.  
  497.                // Store in cache
  498.                $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']);
  499.         }
  500.  
  501.         
  502.         // Return no error code
  503.         return false;
  504.     }
  505.  
  506.     /**
  507.      * Connect to db and store this cnnection in this object
  508.      *
  509.      * @param string $p_db 
  510.      * @param resource $r_id_connect 
  511.      * @return bool TRUE on error
  512.      */
  513.     function connectToDB($p_db&$r_id_connect{
  514.  
  515.         // Declare parameters var
  516.         $admin_sql_connection_id NULL;
  517.         $sql_connection_information array();
  518.  
  519.         // Get connection info and connection to admin super
  520.         $this->getConnection($admin_sql_connection_id$sql_connection_information$p_db);
  521.  
  522.         // Store result
  523.         $this->m_id_sql_admin_super             = $admin_sql_connection_id;
  524.         $this->m_database_name                     = $sql_connection_information['dbc_dbname'];
  525.         $this->m_database_user_name             = $sql_connection_information['dbc_dblogin'];
  526.         $this->m_database_user_pass             = $sql_connection_information['dbc_dbpass'];
  527.         $this->m_database_inherited_sitename     = $sql_connection_information['dbc_inherited_sitename'];
  528.         $this->m_database_is_ecommerce_web_site = ($sql_connection_information['dbc_ecommerce'== 'Y');
  529.         $this->m_database_host                     = $sql_connection_information['dbc_dbhost'];
  530.         $this->m_id_sql                         =$sql_connection_information['dbc_connection'];
  531.  
  532.         // Set result
  533.         $r_id_connect $this->m_id_sql;
  534.  
  535.         return false;
  536.  
  537.         $r_id_connect NULL;
  538.         $r_result array();
  539.         $r_result['dbc_sitename']     'NC';
  540.         $r_result['dbc_dbname']     'NC';
  541.         $r_result['dbc_dblogin']     'NC';
  542.         $r_result['dbc_dbpass']     'NC';
  543.         $r_result['dbc_dbhost']     'NC';
  544.         global $g_object_loader$g_object_siteinformation;
  545.         if (!isset($g_object_siteinformation))
  546.         {
  547.             // Temp - usefull to detect problem
  548.             trigger_error("Bad call to siteInformation");
  549.             die();
  550.         }
  551.         //$g_object_siteinformation =& $g_object_loader->getSiteInformation();
  552.           
  553.         //on va chercher sur notre admin_super la base qui correspond au site $siteName
  554.         global $_PLICI_CFG;
  555.         
  556.           //$id_sql_admin_super = plici_mysql_connect($_PLICI_CFG['superadmin_hostname'], $_PLICI_CFG['superadmin_username'], $_PLICI_CFG['superadmin_password']);
  557.         
  558.         
  559.         
  560.         //$id_sql_admin_super = @mysql_connect($_PLICI_CFG['superadmin_hostname'], $_PLICI_CFG['superadmin_username'], $_PLICI_CFG['superadmin_password']);
  561.         $select_db_is_ok @mysql_select_db($_PLICI_CFG['superadmin_databasename']$this->m_id_sql_admin_super);
  562.  
  563.         if ($this->m_debug_connectivity{
  564.           echo_net("mysql_connect(".$_PLICI_CFG['superadmin_hostname'].", ".$_PLICI_CFG['superadmin_username'].", ".$_PLICI_CFG['superadmin_password'].")");
  565.           echo_net("@mysql_select_db(".$_PLICI_CFG['superadmin_databasename']."$this->m_id_sql_admin_super)");
  566.         }
  567.  
  568.  
  569.         if (!$select_db_is_ok
  570.             $g_object_siteinformation->generateFatalError404();
  571.  
  572.  
  573.         //récuperation des informations de connections 
  574.         $sql_query "SELECT * FROM databaseconnect WHERE  dbc_dbname = '".$p_db."' AND dbc_dblogin<>'ALIAS';";
  575.         if ($this->m_debug_connectivity
  576.           echo("$sql_query");
  577.         $result @mysql_query($sql_query$this->m_id_sql_admin_super);
  578.         //echo($result);        
  579.         if (!$result
  580.             $g_object_siteinformation->generateFatalError404();
  581.  
  582.         // tout semble bon, donc on affecte la connection du admin_super
  583.         //$this->m_id_sql_admin_super =& $id_sql_admin_super;
  584.  
  585.  
  586.         $row @mysql_fetch_row($result);
  587.         //echo "<br />".print_r_net($row);
  588.  
  589.         $dbc_inherited_sitename "";
  590.         if (sizeof($row0{
  591.             $r_result['dbc_sitename']     $row[0];
  592.             $r_result['dbc_dbname']     $row[1];
  593.             $r_result['dbc_dblogin']     $row[2];
  594.             $r_result['dbc_dbpass']     $row[3];
  595.             $r_result['dbc_inherited_sitename'$row[4];
  596.             $r_result['dbc_ecommerce']     $row[5];
  597.             $r_result['dbc_dbhost']     $row[6];
  598.             $r_result['dbc_available']     $row[7];
  599.         }
  600.         
  601.             if ($r_result['dbc_available'!= 'Y'{
  602.                 // this site web is not available :(
  603.                 $g_object_siteinformation->generateBusyPage();
  604.             }
  605.         
  606.           $this->m_database_name = $r_result['dbc_dbname'];
  607.           $this->m_database_user_name = $r_result['dbc_dblogin'];
  608.           $this->m_database_user_pass = $r_result['dbc_dbpass'];
  609.           $this->m_database_inherited_sitename = $r_result['dbc_inherited_sitename'];
  610.           $this->m_database_is_ecommerce_web_site = ($r_result['dbc_ecommerce'== 'Y')
  611.           $this->m_database_host = $r_result['dbc_dbhost'];
  612.  
  613.  
  614.  
  615.              $id_sql plici_mysql_connect($this->m_database_host$this->m_database_user_name$this->m_database_user_pass);
  616.  
  617.  
  618.         //$id_sql = @mysql_connect($this->m_database_host, $this->m_database_user_name, $this->m_database_user_pass);
  619.  
  620.         if ($this->m_debug_connectivity{
  621.           echo_net("@mysql_connect(".$this->m_database_host.", ".$this->m_database_user_name.", ".$this->m_database_user_pass.");");
  622.           echo_net("$select_db_is_ok = @mysql_select_db(".$this->m_database_name.", ".$id_sql.")");
  623.         }
  624.         $select_db_is_ok @mysql_select_db($this->m_database_name$id_sql);
  625.  
  626.         if (!$select_db_is_ok
  627.             $g_object_siteinformation->generateFatalError404();
  628.  
  629.         
  630.         //tout semble bon, donc on affecte la connection du admin_super
  631.         $this->m_id_sql =$id_sql;
  632.  
  633.         return false;
  634.     }
  635.     
  636.     
  637.     /**
  638.      * Get connexion information
  639.      *
  640.      * @param string $r_db_name 
  641.      * @param string $r_user_name 
  642.      * @param string $r_user_pass 
  643.      * @return bool TRUE on error
  644.      */
  645.     function getConnectionInfo(&$r_db_name&$r_user_name&$r_user_pass{
  646.           $r_db_name $this->m_database_name ;
  647.           $r_user_name $this->m_database_user_name ;
  648.           $r_user_pass $this->m_database_user_pass ;
  649.         
  650.         return false;    
  651.     }
  652.     
  653.     /**
  654.      * Get current web site name
  655.      *
  656.      * @return string 
  657.      */
  658.     function getCurrentSiteName({
  659.         return $this->m_site_name;
  660.     }
  661.     
  662.     /**
  663.      * Return the inherited site name for the current web site
  664.      *
  665.      * @return string 
  666.      */
  667.     function getCurrentInheritedSiteName(){
  668.         return $this->m_database_inherited_sitename;    
  669.     }
  670.     
  671.     /**
  672.      * Is ecommerce web site
  673.      *
  674.      * @return bool 
  675.      */
  676.     function getIsEcommerceWebSite({
  677.      return $this->m_database_is_ecommerce_web_site;
  678.     }
  679.   
  680.     /**
  681.      * Make an sql query in PLICI into the super admin
  682.      *
  683.      * @param string $p_request    in vsprintf format with $r_table_params
  684.      * @param array $r_table_params 
  685.      * @param resource $r_result_set 
  686.      * @return bool TRUE on error
  687.      */
  688.     function makeSqlQueryAdminSuper($p_request&$r_table_params&$r_result_set{
  689.         global $g_object_time_elapser;
  690.         
  691.         
  692.             $sql_query $this->formatAndProtectRequest($r_table_params$p_request);
  693.             $id_db_connexion $g_object_time_elapser->beginningSQL($sql_query);
  694.              
  695.             
  696.             global $_PLICI_CFG;
  697.                @mysql_select_db($_PLICI_CFG['superadmin_databasename']$this->m_id_sql_admin_super)
  698.             $r_result_set mysql_query($sql_query$this->m_id_sql_admin_super);
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.              global $g_object_loader;
  708.              global $_PLICI_CFG;
  709.             $g_object_dbindexsupervision =$g_object_loader->getDbIndexSupervision();
  710.  
  711.                $g_object_dbindexsupervision->requestPlayed($sql_query$this->m_id_sql_admin_super$_PLICI_CFG['superadmin_databasename']);
  712.  
  713.  
  714.              if (DBG_DBCONNEXION_IS_ON || $this->debug_is_on{
  715.                  echo "\n<br />Debug - Class dbconnection - makeSqlQuery - Request before vsprintf= <samp>".$p_request."</samp>";
  716.                  trigger_error("Debug - Class dbconnection - makeSqlQuery - Requete after vsprintf= ".$p_request);
  717.                  echo "\n<br />Array Parameters - <samp>".print_r($r_table_params,true)."</samp>";
  718.                  trigger_error("Array Parameters - ".print_r($r_table_params,true));
  719.                   echo("<br />Request = <samp>".$sql_query."</samp><br />");
  720.                   //echo("<br />Request = <br /><pre style='text-align:left;'><samp>".$sql_query."</samp></pre><br />");
  721.                   trigger_error("Request = ".$sql_query);
  722.              }
  723.              if (mysql_errno($this->m_id_sql_admin_super!= 0{
  724.                  trigger_error("Request/admin_super = ".$sql_query."");
  725.                    trigger_error("(".mysql_errno($this->m_id_sql_admin_super).")");
  726.                 trigger_error("(".mysql_error($this->m_id_sql_admin_super).")");
  727.              }
  728.              
  729.              $g_object_time_elapser->endingSQL($id_db_connexion);
  730.              
  731.              return !$r_result_set;
  732.     }    
  733.   
  734.     /**
  735.      * Make an sql query in PLICI and return the insert id
  736.      *
  737.      * @param string $p_request        in vsprintf format with $r_table_params
  738.      * @param array $r_table_params 
  739.      * @param resource $r_result_set 
  740.      * @param integer $r_insert_id 
  741.      * @return bool TRUE on error
  742.      */
  743.     function makeSqlQueryWithId($p_request&$r_table_params&$r_result_set&$r_insert_id{
  744.         $sql_connection "";
  745.         $error $this->makeSqlQuery($p_request$r_table_params$r_result_set);
  746.         if (is_null($this->m_last_connection_sql_id))
  747.             $r_insert_id mysql_insert_id();
  748.             else $r_insert_id mysql_insert_id($this->m_last_connection_sql_id);
  749.         
  750.         return $error;
  751.     }
  752.  
  753.  
  754.     /**
  755.      * Format and protect any request
  756.      *
  757.      * @param array $r_table_params 
  758.      * @param string $p_request        in vsprintf format with $r_table_params
  759.      * @return bool TRUE on error
  760.      */
  761.     function formatAndProtectRequest(&$r_table_params&$p_request{
  762.         
  763.         if (sizeof($r_table_params== 0)
  764.             return $p_request;
  765.             
  766.         // Protection sql injection
  767.         for ($i=0;$i<sizeof($r_table_params);$i++{
  768.             $r_table_params[$imysql_escape_string($r_table_params[$i]);
  769.         }
  770.  
  771.         //Fusion requete<->parametre
  772.         return vsprintf($p_request$r_table_params);
  773.     }
  774.  
  775.     /**
  776.      * Make an sql query in PLICI, in the current website
  777.      *
  778.      * @param string $p_request    in vsprintf format with $r_table_params
  779.      * @param array $r_table_params 
  780.      * @param resource $r_result_set 
  781.      * @param string $p_database_selected 
  782.      * @return bool TRUE on error
  783.      */
  784.     function makeSqlQuery($p_request&$r_table_params&$r_result_set$p_database_selected=""{
  785.         global $g_object_time_elapser;
  786.  
  787.         // Protection sql injection
  788.         $sql_query $this->formatAndProtectRequest($r_table_params$p_request);
  789.         $id_db_connexion $g_object_time_elapser->beginningSQL($sql_query);
  790.  
  791.  
  792.         // on determine si on doit vider ou non le cache, pour cela deux critères
  793.         // l'instruction doit être un insert ou un update
  794.         $sql_query trim($sql_query);
  795.         global $g_object_siteinformation;
  796.         $found false;
  797.         if ($g_object_siteinformation->isAdmin())
  798.         if (preg_match("/(insert[ ]*into|update)+[ ]+([[:alnum:]_]+)/i",$sql_query$found0{
  799.             $table_name $found[2];
  800.             if (!isset($this->m_not_destroying_cache[$table_name])) {
  801.                 //echo("i must destroy cache");
  802.                 //echo($sql_query);
  803.                 global $g_object_loader;
  804.                 $smarty =$g_object_loader->getSmarty_Custom();
  805.                 //$caching = $smarty->caching;
  806.                 //$smarty->caching = true;
  807.                 // on vide le cache du FrontOffice à cause de l'update ou insert
  808.                 $tmp_cache_dir $smarty->cache_dir;
  809.                 $smarty->cache_dir $g_object_siteinformation->getTemplateCacheFilePath(true);
  810.                 $smarty->clear_all_cache();
  811.                 $smarty->cache_dir $tmp_cache_dir;
  812.  
  813.                     // Search slave
  814.                 $slaves array();
  815.                 $this->xGetWebsiteSlave($slaves ,$this->m_database_name);
  816.                 foreach($slaves as $slave_dbname{
  817.                     $tmp_cache_dir $smarty->cache_dir;
  818.                     $smarty->cache_dir $g_object_siteinformation->getTemplateCacheFilePathSpecific($slave_dbname);
  819.                     $smarty->clear_all_cache();
  820.                     $smarty->cache_dir $tmp_cache_dir;
  821.                 }
  822.                 //$smarty->caching = $caching;
  823.             }
  824.         }
  825.  
  826.         // Set database selected and slq connection id
  827.         $database_selected             $this->m_database_name;
  828.         $sql_connection_selected     $this->m_id_sql;
  829.  
  830.         ///////////////////
  831.         // WEBSITE GROUP //
  832.         ///////////////////
  833.         // If database selected, we are in master of websitegroup but we must load slave information
  834.         if (0<strlen(trim($p_database_selected)))
  835.         {
  836.             // We must select slave database
  837.             // Set super admin sql connection id var
  838.             $super_admin_connection_id NULL;
  839.             // Connection to slave group database
  840.             $slave_group_sql_connection_information array();
  841.  
  842.             // Create new connection 
  843.             $this->getConnection($super_admin_connection_id$slave_group_sql_connection_information ,$p_database_selected);
  844.             $database_selected $p_database_selected;
  845.             $sql_connection_selected $slave_group_sql_connection_information['dbc_connection'];
  846.  
  847.         else {
  848.  
  849.             // Check if the website is a slave of a website group
  850.             $master_website_group "";
  851.             $this->getWebsiteGroupMaster($master_website_group$database_selected);
  852.  
  853.             if (0<strlen(trim($master_website_group)))
  854.             {
  855. //echo "<br /> (".$master_website_group.") - ".$sql_query;
  856.                 // This site is in web site group and
  857.                 //    request can be played in master of group
  858.                     // Set number of table to detect
  859.                 $nof_table_to_detect count($this->m_master_website_group_table);
  860.                     // Set var for loop
  861.                 $ind 0;
  862.                     // Set var to stop loop
  863.                 $not_found true;
  864.                     // Detect table in request
  865.                 while (($not_found&& ($ind<$nof_table_to_detect))
  866.                 {
  867.                     $not_found false===(stristr($sql_query$this->m_master_website_group_table[$ind]));
  868.                     $ind++;
  869.                 }
  870. //echo "<br />";
  871.                 // Not found specific table
  872.                 if ($not_found)
  873.                 {
  874. //echo "2nd passe - ";
  875.                     // Search in globascope with special parameters
  876.                     foreach($this->m_master_website_group_table_and_field as $sql_table=>$sql_fields)
  877.                     {
  878.                         foreach($sql_fields as $sql_field)
  879.                         {
  880.                             $not_found $not_found && ((false===(stristr($sql_query$sql_table))) || (false===(stristr($sql_query$sql_field))));
  881.                         }
  882.                     }
  883.                 }
  884.  
  885. //if (!$not_found)
  886. //    echo "<strong>Ailleurs</strong> - ";
  887. //echo "Request: ".$sql_query;
  888.                 if (!$not_found)
  889.                 {
  890.                     // Found specific table
  891.                         // We must select master database
  892.                     // Set super admin sql connection id var
  893.                     $super_admin_connection_id NULL;
  894.                     // Connection to master group database
  895.                     $master_group_sql_connection_information array();
  896.     
  897.                     // Create new connection 
  898.                     $this->getConnection($super_admin_connection_id$master_group_sql_connection_information ,$master_website_group);
  899.                     $database_selected $master_website_group;
  900.                     $sql_connection_selected $master_group_sql_connection_information['dbc_connection'];
  901.                 }
  902.             }
  903.         }
  904.  
  905.  
  906.         // Set sql connection result var
  907.         $this->m_last_connection_sql_id =  $sql_connection_selected;
  908.  
  909.         // Execute request
  910.         @mysql_select_db($database_selected$sql_connection_selected);
  911.         $r_result_set mysql_query($sql_query$sql_connection_selected);
  912.  
  913.          global $g_object_loader;
  914.         $g_object_dbindexsupervision =$g_object_loader->getDbIndexSupervision();
  915.         $g_object_dbindexsupervision->requestPlayed($sql_query$sql_connection_selected$database_selected);
  916.  
  917.  
  918.  
  919.         /*if (0== strcasecmp("INSERT",substr(trim($sql_query), 0, 6))) {
  920.             $r_result_set = mysql_insert_id($sql_connection_selected);
  921.         }*/
  922.         //echo("<br>Requete = <font color='#FF0000'>".$sql_query."</font><br>");
  923.          if (DBG_DBCONNEXION_IS_ON || $this->debug_is_on{
  924.                  echo "\n<br />Debug - Class dbconnection - makeSqlQuery - Request before vsprintf= <samp>".$p_request."</samp>";
  925.                  trigger_error("Debug - Class dbconnection - makeSqlQuery - Request after vsprintf= ".$p_request);
  926.                  echo "\n<br />Array Parameters - <samp>".print_r($r_table_params,true)."</samp>";
  927.                  trigger_error("Array Parameters - ".print_r($r_table_params,true));
  928.                   //echo("<br />Request = <samp>".$sql_query."</samp><br />");
  929.                   echo("<br />Request = <br /><pre style='text-align:left;'><samp>".$sql_query."</samp></pre><br />");
  930.                   trigger_error("Request = ".$sql_query);
  931.          }
  932.          if (mysql_errno($sql_connection_selected!= 0{
  933.             trigger_error("Request/front_bd = ".$sql_query."");
  934.                trigger_error("(".mysql_errno($sql_connection_selected).")");
  935.             trigger_error("(".mysql_error($sql_connection_selected).")");
  936.          }
  937.          //print_r($r_result_set);
  938.          
  939.          $g_object_time_elapser->endingSQL($id_db_connexion);
  940.          
  941.          return  !$r_result_set;
  942.     }
  943.  
  944.  
  945.     /**
  946.      * Get all webiste group
  947.      *
  948.      * @access private
  949.      * @param array $r_result 
  950.      * @return bool TRUE on error
  951.      */
  952.     function xGetWebsiteGroups(&$r_result)
  953.     {
  954.         // Set empty result
  955.         $r_result array();
  956.  
  957.         // Set request parameters var
  958.         $request_parameter         array();
  959.  
  960.         // Set request result var
  961.         $request_result array();
  962.  
  963.         // Search if database_name is in group member
  964.         $this->makeSqlQueryAdminSuper($this->req_get_websitegroup$request_parameter$request_result);
  965.  
  966.         // Retrieve result
  967.         while ($row mysql_fetch_row($request_result))
  968.         {
  969.             $r_result[$row[0]] $row[1]
  970.         }
  971.  
  972.         // Result no error code
  973.         return false;
  974.     }
  975.  
  976.     /**
  977.      * Return master of web group for selected database
  978.      *
  979.      * @param string $r_result 
  980.      * @param string $dbc_dbname 
  981.      * @return bool TRUE on error
  982.      */
  983.     function getWebsiteGroupMaster(&$r_result$dbc_dbname)
  984.     {
  985.         // Set empty result
  986.         $r_result "";
  987.  
  988.         if (0==count($this->m_website_group))
  989.         {
  990.             // This member is empty => Get value and fill it
  991.             // Set tmp var
  992.             $tmp_website_group array();
  993.             // Get values
  994.             $this->xGetWebsiteGroups($tmp_website_group);
  995.             // Fill member var
  996.             $this->m_website_group = $tmp_website_group;
  997.         }
  998.  
  999.         if (0!=count($this->m_website_group))
  1000.         {
  1001.             // Search master of group
  1002.             if (isset($this->m_website_group[$dbc_dbname]))
  1003.                 $r_result $this->m_website_group[$dbc_dbname];
  1004.         }
  1005.  
  1006.         // Return no error code
  1007.         return false;
  1008.     }
  1009.  
  1010.     /**
  1011.      * Return Slave for this master
  1012.      *
  1013.      * @param array $r_result         Slaves
  1014.      * @param string $p_dbc_dbname     master database name
  1015.      * @return bool TRUE on error
  1016.      */
  1017.     function xGetWebsiteSlave(&$r_result$p_dbc_dbname)
  1018.     {
  1019.         // Set empty result
  1020.         $r_result array();
  1021.  
  1022.         if (0==count($this->m_website_group))
  1023.         {
  1024.             // This member is empty => Get value and fill it
  1025.             // Set tmp var
  1026.             $tmp_website_group array();
  1027.             // Get values
  1028.             $this->xGetWebsiteGroups($tmp_website_group);
  1029.             // Fill member var
  1030.             $this->m_website_group = $tmp_website_group;
  1031.         }
  1032.  
  1033.         if (0!=count($this->m_website_group))
  1034.         {
  1035.             foreach($this->m_website_group as $dbc_dbname=>$master_dbname{
  1036.                 if ($master_dbname == $p_dbc_dbname)
  1037.                     $r_result[$dbc_dbname;
  1038.             }
  1039.         }
  1040.  
  1041.         // Return no error code
  1042.         return false;
  1043.     }    
  1044.  
  1045.     /**
  1046.      * Must if we must check website master group for specified table (and field)
  1047.      *
  1048.      * @param string $p_table 
  1049.      * @param string $p_field 
  1050.      * @return bool 
  1051.      */
  1052.     function mustWeCheckWebsiteMasterGroup($p_table$p_field=null){
  1053.         if (in_array($p_table$this->m_master_website_group_table))
  1054.         {
  1055.             return true;
  1056.         else {
  1057.             if ( (!is_null($p_field))
  1058.                 && (isset($this->m_master_website_group_table_and_field[$p_table]))
  1059.                 && (in_array($p_field$this->m_master_website_group_table_and_field[$p_table])))
  1060.             {
  1061.                 return true;
  1062.             else {
  1063.                 return false;
  1064.             }
  1065.         }
  1066.     }
  1067.  
  1068.  
  1069.     // Méthodes de nettoyage de données //
  1070.  
  1071.     //Méthode qui convertit(encode/décode) les données
  1072.     // PRE-REQUIS:
  1073.     // Toutes les données insérées en BD ne sont pas encodées EXCEPTE celle de FCK_EDITOR
  1074.     // Différents cas de figure:
  1075.     //    ->Insertion en BD
  1076.     //        ->FCK => Aucun changement et texte encodé
  1077.     //        ->Autres => Aucun changement et texte brut
  1078.     //    ->Modification en BO
  1079.     //        ->FCK => Aucune modification
  1080.     //        ->Autres => Aucune modification. La protection contre " et ' est faite par le modificateur smarty net_value
  1081.     //    ->Affichage en HTML
  1082.     //        ->FCK => Aucun changement car texte déjà encodé
  1083.     //        ->Autres => Encodé les entité, les caractères spéciaux ?, transformer les nl en <br>
  1084.     //    ->Affichage en plain text
  1085.     //        ->FCK => Decodage des caractères, suppression des balises,...
  1086.     //        ->Autres => Suppressions des balises,....
  1087.     
  1088.     /**
  1089.      * Translate a parameter before or after receiving from database
  1090.      *
  1091.      * @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'
  1092.      * @param string $p_data 
  1093.      * @return string 
  1094.      */
  1095.     function translate($p_type$p_data{
  1096.         
  1097.         
  1098.         $translate_definition array();
  1099.         //    ->Insertion en BD
  1100.         $translate_definition["FCK_TO_DB_FCK"]    array("html"=>"clean");
  1101.         $translate_definition["TO_DB"]            array();
  1102.         //    ->Modification en BO
  1103.         $translate_definition["DB_FCK_TO_INPUT"]array();
  1104.         $translate_definition["DB_TO_INPUT"]     array();
  1105.         //    ->Affichage en HTML
  1106.         $translate_definition["DB_FCK_TO_HTML"array();
  1107.         $translate_definition["DB_TO_HTML"]     array("entity"=>"encode",
  1108.                                                         "spe_car"=>"none",
  1109.                                                         "nl"=>"encode");
  1110.         $translate_definition["DB_TO_ALT"]        array();/*A completer*/
  1111.         //    ->Utilisation pour l'index d'un tableau
  1112.         $translate_definition["DB_TO_ARRAY_INDEX"]array("entity"=>"decode",
  1113.                                                           "spe_car"=>"none",
  1114.                                                           "nl"=>"delete");
  1115.         //    ->Affichage en plain text
  1116.         $translate_definition["HTML_TO_PLAIN_STRING"]array(
  1117.                                                             "entity"=>"decode",
  1118.                                                             "spe_car"=>"delete",
  1119.                                                             "nl"=>"delete",
  1120.                                                             "concat_br"=>"true");
  1121.                                                     
  1122.         $translate_definition["HTML_TO_PLAIN"]     array("entity"=>"decode",
  1123.                                                         "spe_car"=>"delete",
  1124.                                                         "nl"=>"none",
  1125.                                                             "concat_br"=>"true");
  1126.  
  1127.         // Non utilisé => Utilisation de HTML_TO_PLAIN à utiliser                                    
  1128.         $translate_definition["HTML_TO_RSS"]array("entity"=>"decode",
  1129.                                                     "spe_car"=>"decode",
  1130.                                                     "nl"=>"none");
  1131.  
  1132.         //Récupération des opérations a effectuer
  1133.         $f_html     strtoupper(getFromArray('html'$translate_definition[$p_type]"none"));
  1134.         $f_entity     strtoupper(getFromArray('entity'$translate_definition[$p_type]"none"));
  1135.         $f_spe_char strtoupper(getFromArray('spe_car'$translate_definition[$p_type]"none"));
  1136.         $f_nl         strtoupper(getFromArray('nl'$translate_definition[$p_type]"none"));
  1137.         $f_concat_br         strtoupper(getFromArray('concat_br'$translate_definition[$p_type]"none"));
  1138.  
  1139.         $result $p_data;
  1140.  
  1141.         switch ($f_html)
  1142.         {
  1143.             case "CLEAN":
  1144.                 //Correction erreur fck qui normalement devrait pas apparaitre et qui font apparaitre https:// et ../../ dans liens vers
  1145.                 $result preg_replace("@(href|src)=\"(\.\./\.\./\.\./\.\.|http(s?)://".$_SERVER["SERVER_NAME"].")/@","\$1=\"/"$result);
  1146.  
  1147.                 //$clean_result = $result; //Debug
  1148.  
  1149.                 // Suppression class Microsoft
  1150.                 $result preg_replace("@class=\"MsoNormal\"@i"""$result);
  1151.  
  1152.                 // Tidy
  1153.                 if (FALSE != phpversion('tidy'))
  1154.                 {
  1155.                     //Desactivate,  the result hasn't the same look that the customer see in the html editor
  1156.                     //The first cause was the option bare and clean
  1157.                     /*
  1158.                     $tidy_config = array(
  1159.                                            'indent'        => true,
  1160.                                            'output-xhtml'  => true,
  1161.                                         'bare'            => true,
  1162.                                         'clean'            => true,
  1163.                                         'drop-proprietary-attributes' => true,
  1164.                                         //'drop-font-tags'=> true,
  1165.                                         'drop-empty-paras' => true,
  1166.                                         'word-2000'        => true,
  1167.                                         'show-body-only'    => true,
  1168.                                         'join-styles'    => true,
  1169.                                         'wrap'          => 200);
  1170.  
  1171.                     $tidy = new tidy;
  1172.                     $tidy->parseString($result, $tidy_config, 'latin1');
  1173.                     $tidy->cleanRepair();
  1174.                     $result = $tidy;
  1175.  
  1176.                                         //Traitement des balises des css
  1177.                     // L'option clean a ajouter tous les styles dans le head
  1178.                     $tidy_head = tidy_get_head($tidy);
  1179.                     $style_list= array();
  1180.                     //On récupère la liste des styles
  1181.                     preg_match_all("/([a-zA-Z0-9]*)\.c([0-9])* {([^}]*)}/", $tidy_head->value, $style_list);
  1182.  
  1183.                     // On les applique au niveau des balises
  1184.                     for($i=0; $i<count($style_list[2]);$i++)
  1185.                     {
  1186.                         $result = preg_replace("@<".$style_list[1][$i]." class=\"c".$style_list[2][$i]."\">@i",
  1187.                                             "<".$style_list[1][$i]." style=\"".$style_list[3][$i]."\">", $result);
  1188.                     }
  1189.                     */
  1190.                 }
  1191.  
  1192.  
  1193.                 //Delete margin
  1194.                 $result preg_replace("@margin(-(right|left|top|bottom))?: (-?[1-9 ][0-9. ]+(%|ex|em|px|cm|mm|pc|in|pt|))+@i"""$result);
  1195.                 /*
  1196.                 
  1197.                         Stef j'ai supprimé pour  FS#111 — fck editor add _fcksavedurl
  1198.                                                  FS#112 — balise ALT disparait
  1199.                 // Suppression des balises vides
  1200.                 $array_balise_inline = array('a href','b','caption','cite','col','em','font','h1','h2','h3','h4'
  1201.                                     ,'h5','i','kdb','label','legend','pre','q','small','span','strong','sub','sup','var');
  1202.                 foreach($array_balise_inline as $value)
  1203.                     $result = preg_replace("@<".$value."[^>]*?>[\s|&nbsp;]*</".$value.">@i", "", $result);
  1204.  
  1205.                 $array_balise = array('p');
  1206.                 foreach($array_balise as $value)
  1207.                     $result = preg_replace("@<".$value."[^>]*?>[\s|&nbsp;]*</".$value.">@i", "<br />", $result);
  1208.                 
  1209.                 $result = preg_replace("@(<div[^>]*?>[\s|&nbsp;]*</div[^>]*?>[\s]*)+@i", "<br />", $result);
  1210.                 */
  1211.                 //$result = $clean_result; //Debug
  1212.                 break;
  1213.             default :
  1214.                 break;
  1215.         }
  1216.  
  1217.         //! A positionner avant car on est susceptible de supprimer les balises après ! //
  1218.         // Retour chariot
  1219.         switch ($f_nl
  1220.         {
  1221.             case "ENCODE" :
  1222.                 // Voir a la fin. Sinon les caractères du br risque d'être encodé
  1223.                 break;
  1224.             case "DECODE" :
  1225.                 $result stripslashes($result);
  1226.                 $result str_replace(array("\n""\r")array("""")$result);
  1227.                 $result preg_replace("/<br[ \/]*>/i","\n",$result);
  1228.                 break;
  1229.             case "DELETE" :
  1230.                 //suppression des lignes modes windows et Mac. Tout en UNIX
  1231.                 $result preg_replace("/\r/is"""$result);
  1232.                 //$result = preg_replace("/<(br|p)/is", " ", $result);
  1233.                 $result str_replace("<br />"" "$result);
  1234.                  $result preg_replace ("/(\n|\r)[\s]*/"""$result);
  1235.                  $result preg_replace ("/[\s]+/"" "$result);
  1236.                  $result trim($result);
  1237.                 break;
  1238.             default :
  1239.                 break;
  1240.         }
  1241.  
  1242.         // Special char
  1243.         switch ($f_spe_char
  1244.         {
  1245.             case "ENCODE" :
  1246.                 break;
  1247.             case "DELETE" :
  1248.  
  1249.                 $array_pattern array(
  1250.                             "/<!--.*?-->/is",// Supp Commentaire
  1251.                             "/<body[^>]*>(.*)<\/body>/is"// Supp Head
  1252.                             "/<script[^>]*>.*?<\/script>/is",// Supp Balises spéciales
  1253.                             "/<noscript[^>]*>.*?<\/noscript>/is",
  1254.                             "/<style[^>]*>.*?<\/style>/is"
  1255.                                         );
  1256.  
  1257.                 $array_replacement array("",    "\\1",    "",    "",    "");
  1258.  
  1259.                 $result preg_replace($array_pattern$array_replacement$result)
  1260. //                // Supp des tags restants
  1261.                 if ("ENCODE" == $f_nl
  1262.                     $result strip_tags($result"<br/><br>");
  1263.                 else
  1264.                     $result strip_tags($result);
  1265.                 $result str_replace ("&#x40;""@"$result);
  1266.             case "DECODE" :
  1267.                 $result strtr($result$this->HTML_SPECIALCHARS_REVERSED);
  1268.                 break;
  1269.             default :
  1270.                 break;
  1271.         }
  1272.  
  1273.         // entity
  1274.         switch ($f_entity
  1275.         {
  1276.             case "ENCODE" :
  1277.                 $result htmlentities($resultENT_QUOTES);
  1278.                     // Caractères windows //
  1279.                 $result str_replace(array_keys($this->WINDOWS_SPECIAL_CHAR)$this->WINDOWS_SPECIAL_CHAR$result);
  1280.                     // Caractères # //
  1281.                 $result =  str_replace("&amp;#","&#"$result)
  1282.                 break;
  1283.             case "DECODE" :
  1284.                 //$result = str_replace("&#039;", "'", $result);
  1285.                 $result str_replace($this->WINDOWS_SPECIAL_CHARarray_keys($this->WINDOWS_SPECIAL_CHAR)$result);
  1286.                 $result strtr($result$this->HTML_ENTITIES_REVERSED);
  1287.                 break;
  1288.             default :
  1289.                 break;
  1290.         }
  1291.  
  1292.         //Placé ici car les caractères < et> peuvent être encodé
  1293.         if ("ENCODE" == $f_nl)
  1294.             $result nl2br($result);
  1295.  
  1296.         switch($f_concat_br{
  1297.             case "TRUE" :
  1298.                 $result preg_replace("/<br *\/>([ \n\t\r]*<br *\/>)+/is""<br />"$result);
  1299.                 //echo_net($result);
  1300.                 break;
  1301.             default:
  1302.                 break;
  1303.         }
  1304.  
  1305. //        if ($p_type == "HTML_TO_PLAIN_STRING" || $p_type == "HTML_TO_PLAIN")
  1306. //        echo_net("before translate($p_type, $p_data) => $result");
  1307.  
  1308.         return $result;
  1309.     }
  1310.  
  1311.     
  1312.     
  1313.   /**
  1314.    * Test if table name exist
  1315.    *
  1316.    * @param string $p_table_name 
  1317.    * @return bool TRUE = table exist
  1318.    */
  1319.   function  tableExist($p_table_name{
  1320.     
  1321.     $requ "SHOW TABLE STATUS like '%s';";
  1322.     $parameter array($p_table_name);
  1323.     $this->makeSqlQuery($requ$parameter$mysql_result);
  1324.       if (!$mysql_result
  1325.         return onErrorThrow("ERROR tableExist request");
  1326.     
  1327.     $table_finded false;
  1328.  
  1329.     while($row mysql_fetch_row($mysql_result))
  1330.         $table_finded true;
  1331.     return $table_finded;
  1332. }
  1333.   
  1334.     
  1335.     
  1336.     
  1337.   /**
  1338.    * Execute multiple request in a string
  1339.    *
  1340.    * @param string $sql_to_play 
  1341.    * @return bool TRUE on error
  1342.    */
  1343.   function execute_multiplerequest($sql_to_play{
  1344.         $all_is_ok true;
  1345.     
  1346.           $next_request "";
  1347.         $i_am_in_quote false;
  1348.         $last_start 0;
  1349.         $array_request array();
  1350.         $is_car_inhibiter false;
  1351.         $remember_initial_quote '';
  1352.         $waiting_for_possible_comment true;
  1353.         $first_comment_finded false;
  1354.         $second_comment_finded false;
  1355.         for($i=0$i<strlen($sql_to_play);$i++{
  1356.                 
  1357.                 if (!$i_am_in_quote{
  1358.                     if ($second_comment_finded && $sql_to_play[$i== "\n"){
  1359.                         $last_start $i+1;
  1360.                     else if ($second_comment_finded{
  1361.                         continue;
  1362.                     }
  1363.                 
  1364.                 
  1365.                     if ($sql_to_play[$i== "\n"{
  1366.                         $waiting_for_possible_comment true;
  1367.                         $first_comment_finded false;
  1368.                         $second_comment_finded false;
  1369.                     else if ($waiting_for_possible_comment && $sql_to_play[$i== "-"{
  1370.                         if ($first_comment_finded)
  1371.                             $second_comment_finded true;
  1372.                         else
  1373.                             $first_comment_finded true;
  1374.                     else if ($sql_to_play[$i!= " " && $sql_to_play[$i!= "\t"{
  1375.                         $waiting_for_possible_comment false;
  1376.                         $first_comment_finded false;
  1377.                         $second_comment_finded false;
  1378.                     else {
  1379.                         $first_comment_finded false;
  1380.                         $second_comment_finded false;
  1381.                     }
  1382.                 }
  1383.  
  1384.                 
  1385.                 if ($is_car_inhibiter{
  1386.                     $is_car_inhibiter false;
  1387. //                    echo_net("inhibiter to FALSE ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1388.                     continue;
  1389.                 }
  1390.                 
  1391.                 
  1392.                 
  1393.                 
  1394.                 
  1395.                 if ($sql_to_play[$i== "\\"{
  1396.                     $is_car_inhibiter true;
  1397. //                    echo_net("inhibiter to TRUE ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1398.                 
  1399.                 else {
  1400.                     if (($remember_initial_quote == ""&& (($sql_to_play[$i== "'"|| ($sql_to_play[$i== '"'))){
  1401.                         $i_am_in_quote true;
  1402.                         $remember_initial_quote $sql_to_play[$i];
  1403. //                        echo_net("STARTING quote : ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1404.                     else if (($remember_initial_quote != ''&& ($sql_to_play[$i== $remember_initial_quote )) {
  1405.                         $i_am_in_quote false;
  1406. //                        echo_net("ENDING quote : ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1407.                         $remember_initial_quote '';
  1408.                     else if (($sql_to_play[$i== ";"&& !$i_am_in_quote{
  1409.                             $new_request substr($sql_to_play$last_start$i+1-$last_start);
  1410.                             
  1411.                             $new_request trim(ereg_replace("/^[ \n\r\t]*/i"""$new_request));
  1412.                             
  1413.                             
  1414.                             // on desactive les LOCK TABLES
  1415.                             if (preg_match('/^LOCK[\s]+TABLES/i'$new_request|| preg_match('/^UNLOCK[\s]+TABLES[\s]*;/i'$new_request))
  1416.                                 $new_request "";
  1417.                                 
  1418.                             
  1419.                             if ($new_request != "" && $new_request != ";"{
  1420.                                 
  1421.                                     $parameters array();
  1422.                                     $mysql_result false;
  1423.                                     $this->makeSqlQuery($new_request$parameters$mysql_result);
  1424. //                                    $mysql_result = mysql_query($new_request, $mysql_link);
  1425.                                     if (!$mysql_result{
  1426. //                                          echo("$file_path.$end_line \n\n<br/>ERROR mysql_execute_script : ".mysql_error($mysql_link)." for request <br/>".$new_request."<br/>");
  1427.                                           trigger_error("$file_path <br/>ERROR mysql_execute_script : ".mysql_error()." for request <br/>".$new_request."<br/>");
  1428.                                           $all_is_ok false;    
  1429.                                       else {
  1430.                                           //echo_net(".");    
  1431.                                     }                
  1432.                             }
  1433.                                 array_push($array_request$new_request);
  1434.                             $last_start $i+1;
  1435. //                            echo_net("finded ;"."     (remembered quote :".$remember_initial_quote.")");
  1436. //                            echo_net("Making string ".$new_request."     (remembered quote :".$remember_initial_quote.")");
  1437.                     else {
  1438. //                        echo_net("car not used : ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");                        
  1439.                     }
  1440.  
  1441.                 
  1442. //                echo("\n");
  1443.                     
  1444.         }
  1445. //        print_r_net($array_request);    
  1446.         return $all_is_ok;
  1447. }
  1448.     
  1449.     /**
  1450.      * Lock tables for order process
  1451.      *
  1452.      * @return bool TRUE on error
  1453.      */
  1454.     function lockTablesForCommandProcess()
  1455.     {
  1456.         // Prevent script stop by user
  1457.         ignore_user_abort(TRUE);
  1458.  
  1459.         global $g_lang_access_db;
  1460.         // Prevent t_lang class to access to db
  1461.         $g_lang_access_db false;
  1462.  
  1463.  
  1464.         $parameters_for_lock_table array();
  1465.         $result_for_lock_table array();
  1466.         if ($this->makeSqlQuery($this->req_lock_table$parameters_for_lock_table$result_for_lock_table))
  1467.         {
  1468.             $g_lang_access_db false;
  1469.             ignore_user_abort(FALSE);
  1470.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  1471.         }
  1472.  
  1473.         // Return no error code
  1474.         return false;
  1475.     }
  1476.  
  1477.     /**
  1478.      * Unlock tables for commande process
  1479.      *
  1480.      * @return bool TRUE on error
  1481.      */
  1482.     function unlockTablesForCommandProcess()
  1483.     {
  1484.         $parameters_for_unlock_table array();
  1485.         $result_for_unlock_table array();
  1486.  
  1487.         if ($this->makeSqlQuery($this->req_unlock_table$parameters_for_unlock_table$result_for_unlock_table))
  1488.             return true;
  1489.  
  1490.         global $g_lang_access_db;
  1491.         // Prevent t_lang class to access to db
  1492.         $g_lang_access_db true;
  1493.  
  1494.         // Stop Prevent script stop by user
  1495.         ignore_user_abort(FALSE);
  1496.  
  1497.         // Return no error code
  1498.         return false;
  1499.     }
  1500.     
  1501.     
  1502.     
  1503.     
  1504.     
  1505.     
  1506.   }
  1507.  
  1508.  
  1509. ?>

Documentation generated on Tue, 25 Mar 2008 15:34:36 +0100 by phpDocumentor 1.3.2