Source for file php_functions.inc.php

Documentation is available at php_functions.inc.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.  
  40.  
  41. /**
  42.  * All the function available into PLICI
  43.  * 
  44.  * 
  45.  * @author SimpliciWeb
  46.  * @version $Id: php_functions.inc.php 859 2008-01-23 08:50:43Z stephanet $
  47.  * @package Common
  48.  * @subpackage Start
  49.  */    
  50.  
  51. /**
  52.  * Include dirname(__FILE__)."/plicitag_function.inc.php"
  53.  */
  54. include_once(dirname(__FILE__)."/plicitag_function.inc.php");
  55.  
  56. // Define all path //
  57.  
  58. define('PLICI_MY_DIRECTORY',                                             'my');
  59. define('PLICI_FOR_PLICI_DIRECTORY',                                     'for_plici');
  60.  
  61. define('PLICI_LOG_DIRECTORY',                                             'log');
  62. define('PLICI_TMP_DIRECTORY',                                             'tmp');
  63.  
  64. define('PLICI_MOD_USER_DIRECTORY',                                        "module")// Module for user directoryin my directory
  65.  
  66. define('PLICI_ADMIN_SITES_DIRECTORY',                                     "admin_sites");
  67. define('PLICI_ADMIN_PLICI_DIRECTORY',                                     "admin_plici");
  68. define('PLICI_BD_DIRECTORY',                                             "bd");
  69. define('PLICI_BD_MY_DIRECTORY',                                         PLICI_BD_DIRECTORY."/".PLICI_MY_DIRECTORY);
  70. define('PLICI_BD_MY_ADMIN_SUPER_DIRECTORY',                             PLICI_BD_MY_DIRECTORY."/admin_super");
  71. define('PLICI_BD_MY_ALL_SITES_DIRECTORY',                                 PLICI_BD_MY_DIRECTORY."/_all_sites");
  72. define('PLICI_BD_FOR_PLICI_DIRECTORY',                                     PLICI_BD_DIRECTORY."/".PLICI_FOR_PLICI_DIRECTORY);
  73. define('PLICI_BD_FOR_PLICI_ADMIN_SUPER_DIRECTORY',                                     PLICI_BD_DIRECTORY."/".PLICI_FOR_PLICI_DIRECTORY."/admin_super");
  74.  
  75.  
  76. define('PLICI_CORE_DIRECTORY',                                            "core");
  77. define('PLICI_CORE_ENTREES_DIRECTORY',                                    PLICI_CORE_DIRECTORY."/entrees");
  78. define('PLICI_CORE_ENTREES_FRONT_SITES_DIRECTORY',                        PLICI_CORE_ENTREES_DIRECTORY."/front_sites");
  79. define('PLICI_CORE_ENTREES_ADMIN_SITES_DIRECTORY',                        PLICI_CORE_ENTREES_DIRECTORY."/".PLICI_ADMIN_SITES_DIRECTORY);
  80. define('PLICI_INCLUDE_ENTREES_FRONT_SITES_FOR_PLICI_DIRECTORY',            "entrees/front_sites/".PLICI_FOR_PLICI_DIRECTORY);
  81. define('PLICI_CORE_ENTREES_FRONT_SITES_MY_DIRECTORY',                    PLICI_CORE_ENTREES_FRONT_SITES_DIRECTORY."/".PLICI_MY_DIRECTORY);
  82. define('PLICI_CORE_ENTREES_FRONT_SITES_FOR_PLICI_DIRECTORY',            PLICI_CORE_ENTREES_FRONT_SITES_DIRECTORY."/".PLICI_FOR_PLICI_DIRECTORY);
  83. define('PLICI_CORE_ENTREES_ADMIN_SITES_MY_DIRECTORY',                    PLICI_CORE_ENTREES_ADMIN_SITES_DIRECTORY."/".PLICI_MY_DIRECTORY);
  84.  
  85. define('PLICI_CORE_EXTERNAL_COMPONENTS_PEAR_DIRECTORY',                    PLICI_CORE_DIRECTORY.'/external_components/pears');
  86. define('PLICI_CORE_INTERNAL_COMMON_GLOBALS',                            PLICI_CORE_DIRECTORY.'/internal_components/common/globals');
  87. define('PLICI_CORE_INTERNAL_COMPONENTS_FRONT_SITES_THEME_ELEMENT_DIRECTORY'PLICI_CORE_DIRECTORY."/internal_components/front_sites/theme_elements");
  88. define('PLICI_CORE_INTERNAL_COMPONENTS_FRONT_SITES_THEME_ELEMENT_MY_DIRECTORY'PLICI_CORE_INTERNAL_COMPONENTS_FRONT_SITES_THEME_ELEMENT_DIRECTORY."/".PLICI_MY_DIRECTORY);
  89. define('PLICI_CORE_MODULE_DIRECTORY',                                    PLICI_CORE_DIRECTORY."/module")// Internal module
  90.  
  91.  
  92. define('PLICI_MOD_SRC_DIRECTORY',                                            "original_module");
  93. define('PLICI_MOD_SRC_MY_DIRECTORY',                                        PLICI_MOD_SRC_DIRECTORY."/".PLICI_MY_DIRECTORY);
  94.  
  95.  
  96. define('PLICI_VIEW_DIRECTORY',                                            "view");
  97. define('PLICI_VIEW_SITES_DIRECTORY',                                     PLICI_VIEW_DIRECTORY."/sites");
  98. define('PLICI_VIEW_SITES_MY_DIRECTORY',                                 PLICI_VIEW_SITES_DIRECTORY."/".PLICI_MY_DIRECTORY);
  99. define('PLICI_VIEW_SITES_MY_ADMIN_SITES_DIRECTORY',                     PLICI_VIEW_SITES_DIRECTORY."/".PLICI_MY_DIRECTORY.'/'.PLICI_ADMIN_SITES_DIRECTORY);
  100. define('PLICI_VIEW_SITES_FOR_PLICI_DIRECTORY',                             PLICI_VIEW_SITES_DIRECTORY."/".PLICI_FOR_PLICI_DIRECTORY);
  101. define('PLICI_VIEW_SITES_FOR_PLICI_ADMIN_PLICI_DIRECTORY',                 PLICI_VIEW_SITES_FOR_PLICI_DIRECTORY."/".PLICI_ADMIN_PLICI_DIRECTORY);
  102. //define('PLICI_VIEW_THEME_REWRITING_DIRECTORY',                             PLICI_VIEW_DIRECTORY."/theme_rewriting");
  103. //define('PLICI_VIEW_THEME_REWRITING_MY_DIRECTORY',                             PLICI_VIEW_THEME_REWRITING_DIRECTORY."/".PLICI_MY_DIRECTORY);
  104. define('PLICI_VIEW_EXTERNAL_COMPONENTS_STATS_PHPMV2_LIBS_DIRECTORY',    PLICI_VIEW_DIRECTORY.'/external_components/stats/phpmv2/libs'                        );
  105. define('PLICI_VIEW_EXTERNAL_COMPONENTS_DIRECTORY',                        PLICI_VIEW_DIRECTORY.'/external_components'    );
  106. define('PLICI_VIEW_EXTERNAL_COMPONENTS_MY_DIRECTORY',                        PLICI_VIEW_EXTERNAL_COMPONENTS_DIRECTORY."/".PLICI_MY_DIRECTORY    );
  107.  
  108.  
  109. define('PLICI_PICTURE_DIRECTORY',                                         "picture");
  110. define('PLICI_PICTURE_EXT_DIRECTORY',                                     PLICI_PICTURE_DIRECTORY."/ext");
  111.  
  112.  
  113.  
  114. // Detect the file config path
  115.     // Detect use current file to determine root path of PLICI
  116. $current_dir dirname(__FILE__);
  117.     // Work on copy of directory
  118. $current_dir_for_search $current_dir;
  119. if (isWindows())
  120. {
  121.     // If windows replace \ by /
  122.         // Because the define used / as dir separator
  123.     $current_dir_for_search str_replace("\\""/"$current_dir_for_search);
  124. }
  125.     // Find position of this file(with all plici's dir) in the path
  126. $string_pos strpos($current_dir_for_searchPLICI_CORE_INTERNAL_COMMON_GLOBALS);
  127.     // Select only the path
  128. $plici_root_path substr($current_dir0$string_pos);
  129.  
  130. global $plici_config_file_path;
  131. $plici_config_file_path $plici_root_path."config/plici_config.php";
  132.  
  133.  
  134. global $smarty_bloc_not_cached_old_tpl_vars;
  135. $smarty_bloc_not_cached_old_tpl_vars array();
  136.  
  137.  
  138. /**
  139.  * Test if is a Windows server or not
  140.  *
  141.  * @return bool 
  142.  */
  143. function isWindows()
  144. {
  145.     return substr(PHP_OS,0,3== 'WIN');
  146. }
  147.  
  148.  
  149. /**
  150.  * Translate an array in a PHP script file wich declare this array
  151.  *
  152.  * @param array $array 
  153.  * @param string $array_name_in_php 
  154.  * @return string 
  155.  */
  156. function array_to_php_script($array$array_name_in_php{
  157.     $result "<?php  \n";
  158.  
  159.     $result .= "\$$array_name_in_php = array (\n";
  160.     foreach($array as $key => $value{
  161.         $result .= "    '$key' => '$value',    \n";
  162.     }
  163.     $result .= ");\n";
  164.     $result .= "?".">";
  165.  
  166.     return $result;
  167. }
  168.  
  169. /**
  170.  * Get list of MY directories needed for PLICI
  171.  *
  172.  * @param string $p_racin_path 
  173.  * @return array 
  174.  */
  175. function getArrayListOfMyDirectories($p_racin_path{
  176.  
  177.     $directory_to_make array(
  178.                                 $p_racin_path.'/'.PLICI_BD_MY_DIRECTORY.'/',
  179.                                 $p_racin_path.'/'.PLICI_BD_MY_ADMIN_SUPER_DIRECTORY.'/',
  180.                                 $p_racin_path.'/'.PLICI_BD_MY_ALL_SITES_DIRECTORY.'/',
  181.                                 $p_racin_path.'/'.PLICI_CORE_ENTREES_FRONT_SITES_MY_DIRECTORY.'/',
  182.                                 $p_racin_path.'/'.PLICI_VIEW_SITES_MY_DIRECTORY.'/',
  183.  
  184.                                 $p_racin_path.'/'.PLICI_MOD_SRC_MY_DIRECTORY.'/',
  185.  
  186.                                 $p_racin_path.'/'.PLICI_BD_FOR_PLICI_ADMIN_SUPER_DIRECTORY.'/',
  187.  
  188.  
  189. //                                $p_racin_path.'/'.PLICI_VIEW_THEME_REWRITING_MY_DIRECTORY.'/',
  190.                                 $p_racin_path.'/'.PLICI_CORE_ENTREES_ADMIN_SITES_MY_DIRECTORY.'/',
  191.                                 $p_racin_path.'/'.PLICI_CORE_INTERNAL_COMPONENTS_FRONT_SITES_THEME_ELEMENT_MY_DIRECTORY.'/',
  192.                                 $p_racin_path.'/'.PLICI_LOG_DIRECTORY.'/',
  193.                                 $p_racin_path.'/'.PLICI_TMP_DIRECTORY.'/',
  194.                                 //$p_racin_path.'/'.PLICI_VIEW_EXTERNAL_COMPONENTS_MY_DIRECTORY.'/',
  195.  
  196.                             );
  197.     return $directory_to_make;
  198. }
  199.  
  200.  
  201. /**
  202.  * Create the /my directories for PLICI environnement
  203.  *
  204.  * @param string $p_racin_path 
  205.  * @return bool TRUE on error
  206.  */
  207. function createMyDirectories($p_racin_path{
  208.  
  209.     $directory_to_make getArrayListOfMyDirectories($p_racin_path);
  210.  
  211.     $all_is_ok true;
  212.     foreach($directory_to_make as $directory_to_make{
  213.         if (!(file_exists($directory_to_make&& is_dir($directory_to_make))) {
  214.             if (!@plici_mkdir($directory_to_make)) {
  215.                  $all_is_ok false;
  216.                  echo("<br/>Error creating : $directory_to_make\n");
  217.             else {
  218.                 echo("<br/>Created dir$directory_to_make\n");
  219.             }
  220.         else
  221.             ;//echo("<br/>Not needed to create : $directory_to_make\n"); cette ligne induit les gens en erreur, ils croient que c'est une erreur
  222.     }
  223.     return $all_is_ok;
  224. }
  225.  
  226. /**
  227.  * Update the PLICI config
  228.  *
  229.  * @param array $array_cfg 
  230.  */
  231. function update_config_file($array_cfg{
  232.     global $plici_config_file_path;
  233.     net_file_put_contents($plici_config_file_patharray_to_php_script($array_cfg"_PLICI_CFG"));
  234. }
  235.  
  236. /**
  237.  * Escape a string to replace " and ' by html codes
  238.  *
  239.  * @param string $string 
  240.  * @return string 
  241.  */
  242. function net_value($string)
  243. {
  244.     return str_replace(array("\"","'")array("&quot;","&#39;")$string);
  245. }
  246.  
  247.  
  248. /**
  249.  * Connect to a database and wait 10 times for a free connexion if mysql is out.
  250.  *
  251.  * @param string $p_hostname 
  252.  * @param string $p_username 
  253.  * @param string $p_password 
  254.  * @param integer $p_max_attempt 
  255.  * @return resource 
  256.  */
  257. function plici_mysql_connect($p_hostname$p_username$p_password$p_max_attempt 10$p_force_new_connection false{
  258.           $id_sql FALSE;
  259.           $i 0;
  260.           while ($id_sql === FALSE{
  261. //            echo("<font color='blue'>Connecting $p_hostname, $p_username, $p_password</font>");
  262.               /*
  263.                *  Alors, voici pourquoi on utilise un mysql_connect et pas un mysql_Pconnect
  264.                *  Car, le pconnect va renvoyer une connexion SQL déjà existante
  265.                *  mais il va se référer au Login/Pass/Host pour l'identifier
  266.                *  Il peut ainsi renvoyer une connexion qui ne selectionne pas la bonne base de donnée
  267.                *
  268.                *  Donc le pconnect pause un problème avec une selection de bases multiples contenant des
  269.                *  identifiants et host identiques car la selection de la BD ne peux plus être fiable
  270.                *
  271.                */
  272.  
  273.               //$id_sql = @mysql_pconnect($p_hostname, $p_username, $p_password);
  274.               $id_sql mysql_connect($p_hostname$p_username$p_password$p_force_new_connection);
  275.               //, true);
  276.  
  277.               if ($id_sql === FALSE{
  278.                   trigger_error("BD_WAIT : Waiting for a free connexion (attempt $i)...");
  279.                   sleep(0.5);
  280.                   $i++;
  281.                   if ($i $p_max_attempt{
  282.                       trigger_error("BD_BAD : Sorry... Too many waiting time for a free connexion (attempt $i)...");
  283.                       break;
  284.                   }
  285.  
  286.               else if ($i 0)
  287.                   trigger_error("BD_OK : Waiting solve the problemyou have got a new connexion (attempt $i)...");
  288.           }
  289.           return $id_sql;
  290. }
  291.  
  292.  
  293.  
  294. /**
  295.  * Create multiple directories
  296.  *
  297.  * @param string $path 
  298.  * @param bool $all_is_ok 
  299.  * @return bool TRUE if all is of (BECAREFUL)
  300.  */
  301. function net_mkdirs($path$all_is_ok true{
  302.    $path preg_replace("|(.+)[/\\\\]$|is""\\1"$path);
  303. //   echo_net($path);
  304.    if (!file_exists($path)) {
  305.        $all_is_ok net_mkdirs(dirname($path)."/"$all_is_ok);
  306.        if (!@plici_mkdir($path0777)) {
  307.                $all_is_ok false;
  308.                echo_net("error creating ".$path);
  309.        }
  310.    }
  311. //   echo_net($all_is_ok);
  312.    return $all_is_ok;
  313. }
  314.  
  315. /**
  316.  * Net url build a PLICI URL
  317.  *
  318.  * @param array $params 
  319.  * @param bool $print_stdout 
  320.  * @param Smarty_custom $smarty 
  321.  * @return string 
  322.  */
  323. function net_url($params$print_stdout true$smarty=NULL){
  324.  
  325.  
  326.     //Récupération du type de lien
  327.     $p_type getFromArray("type"$params"PRODUCT");
  328.     //Utile si redirection => les & ne doivent pas être encodé
  329.     $separator getFromArray("nes"$paramsfalse)?"&":"&amp;"//Nes pour no-encode-separator
  330.     global $g_object_siteinformation;
  331.  
  332.     // Get plici page id
  333.     $p_plici_page_id getFromArray("plici_page_id"$params"");
  334.     if (0<strlen(trim($p_plici_page_id)))
  335.     {
  336.         // transform plici page id in page id //
  337.         // Declare object loader
  338.         global $g_object_loader;
  339.             // Load object for page
  340.         $o_page =$g_object_loader->getTPageFo();
  341.             // Get page id
  342.         $o_page->translatePliciPageId($p_plici_page_id$params["page_id"]);
  343.     }
  344.  
  345.     switch(strtoupper($p_type)) {
  346.         case "INDEX_FULL":
  347.             $url $g_object_siteinformation->getBaseFullHttp();
  348.             break;
  349.         case "INDEX":
  350.             $url $g_object_siteinformation->getBaseHttp();
  351.             break;
  352.         case "SELF":
  353.             $url $_SERVER['PHP_SELF'];
  354.             break;
  355.         case "SELF_FULL":
  356.             $url $g_object_siteinformation->getHTTPorHTTPS().$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
  357.             break;
  358.         case "PRODUCT":
  359.             $p_url_prefix getFromArray("url_prefix"$params"")// Utile pour le lien vers le produit dans les stats des paniers
  360.             $p_url_prefix "/"==$p_url_prefix[strlen($p_url_prefix)-1]?substr($p_url_prefix0-1):$p_url_prefix;
  361.             $p_product_id getFromArray("pro_id"$params0);
  362.             $p_product_title getFromArray("pro_title"$params"product")// Sert uniquement au référencement
  363.             $p_father_page getFromArray("id_page"$params0);
  364. //            global $g_object_siteinformation;
  365. //            if ($g_object_siteinformation->isAdmin())
  366. //                // ici on est dans l'admin est on veut une adresse du front
  367. //                $url = $g_object_siteinformation->getBaseFullHttpFoWithoutLanguage();
  368. //            else
  369. //                $url = $g_object_siteinformation->getBaseHttp();
  370.             $lang_current_id 0;
  371.             $g_object_siteinformation->getCurrentLanguageId($lang_current_id);
  372.             $url $p_url_prefix."/l".$lang_current_id."/p".$p_father_page."_r".$p_product_id."-".net_urlencode($p_product_title).".html";
  373.             break;
  374.         case "LINK_BACK":
  375.                 //Lien avec un lien vers la page qui a envoyé le lien
  376.                 $p_previous_id_page getFromArray("prev_page"$params0);
  377.                 $p_previous_id_product getFromArray("prev_pro"$params0);
  378.                 $p_previous_title net_urlencode(getFromArray("prev_title"$params"index"));
  379.                 if (!== $p_previous_id_page)
  380.                 {
  381.                     $previous_url "/p".$p_previous_id_page."_r".$p_previous_id_product."-".$p_previous_title.".html";
  382.                     $params["_prevUrl"$previous_url;
  383.                 }
  384.                 // Surtout pas de break;
  385.         case "LINK":
  386.         default:
  387.             //$p_tpl_uri = getFromArray("tpl", $params, null);
  388.             $p_page_id getFromArray("page_id"$params0);
  389.             $p_page_title getFromArray("page_title"$params"page")//Sert uniquement au référencement
  390.             $p_prefix_url getFromArray("prefix_url"$params"")//Sert uniquement au référencement
  391.  
  392.  
  393. //       trigger_error("Sorry you are still using net_url() but it is deprecated.".print_r(debug_backtrace(),true));
  394.  
  395.             $url_suffix "";
  396.             if (!is_null($smarty))
  397.             {
  398.                 if ($g_object_siteinformation->isAdmin())
  399.                 {
  400.                     // Admin => display link to add/modify page
  401.                     $mod_id     $smarty->get_template_vars('plici_page_mod_id');
  402.                     $mod_index     $smarty->get_template_vars('plici_page_mod_index');
  403.                 else {
  404.                     // Front office
  405.                     // Search if this page have an module
  406.                     $array_son_link is_array($smarty->get_template_vars('array_son_link'))?$smarty->get_template_vars('array_son_link'):array();
  407.                     $array_sub_link is_array($smarty->get_template_vars('array_sub_link'))?$smarty->get_template_vars('array_sub_link'):array();
  408.                     $array_link array_merge($array_son_link$array_sub_link);
  409.                     $not_find TRUE;
  410.                     $nof_array_link count($array_link);
  411.                     $i=0;
  412.                     while (($i<$nof_array_link&& ($not_find))
  413.                     {
  414.                         $not_find $p_page_id!=$array_link[$i]['page_id'];
  415.                         $i++;
  416.                     }
  417.                     $mod_id $not_find?$smarty->get_template_vars('plici_page_mod_id'):$array_link[$i-1]['page_mod_id'];
  418.                     $mod_index $not_find?$smarty->get_template_vars('plici_page_mod_index'):$array_link[$i-1]['mod_index'];
  419.                 }
  420.  
  421.                 if ((is_null($mod_id)) || ('|' == $mod_id)) {
  422.                     $url_suffix "-".net_urlencode($p_page_title).".html";
  423.                 else if ('' == $mod_id{
  424.                     //loader en bd
  425.                     $mod array();
  426.                     global $g_object_loader;
  427.                     $o_page =$g_object_loader->getTPageFo();
  428.                     $o_page->getModuleFromPage($p_page_id$mod);
  429.                     if (0<sizeof($mod))
  430.                         $url_suffix '/plici_mod/'.$mod['mod_id'].'/'.$mod['mod_index_file';
  431.                         else $url_suffix "-".net_urlencode($p_page_title).".html";
  432.                 else {
  433.                     $url_suffix'/plici_mod/'.$mod_id.'/'.$mod_index;
  434.                 }
  435.             else {
  436.                 $url_suffix "-".net_urlencode($p_page_title).".html";
  437.             }
  438.  
  439.  
  440.  
  441.             if (10 != $p_page_id{
  442.                 $lang_current_id 0;
  443.                 $g_object_siteinformation->getCurrentLanguageId($lang_current_id);
  444.                 $url "/l".$lang_current_id."/p".$p_page_id.$url_suffix;
  445.                 if ($p_prefix_url != ""{
  446.                     //echo_net($p_prefix_url[strlen($p_prefix_url)]);
  447.                     if ($p_prefix_url[strlen($p_prefix_url)-1== "/")
  448.                         $p_prefix_url=substr($p_prefix_url,0,strlen($p_prefix_url)-1);
  449.                     $url =     $p_prefix_url.$url;
  450.                 }
  451.             else {
  452.                 // Index
  453.                 // index.html in case of / because some time we use / to have a flash intro
  454.                 $url "/index.html";
  455.             }
  456.  
  457.  
  458.             break;
  459.     }
  460.  
  461.     //Récupération paramètres du lien
  462.     $string_param array();
  463.     foreach($params as $key=>$value{
  464.         if ("_"==$key[0])
  465.         {
  466.             array_push($string_paramsubstr($key,1)."=".urlencode($value));
  467.         }
  468.     }
  469.  
  470.     $p_cat_param getFromArray("cat_param"$params"");
  471.     if ("" != $p_cat_param)
  472.     {
  473.         //On supprime le premier &
  474.         if ("&"==$p_cat_param[0])
  475.             $p_cat_param substr($p_cat_param,1);
  476.  
  477.         $p_cat_param implode($separator ,explode("&"$p_cat_param));
  478.         array_push($string_param$p_cat_param);
  479.     }
  480.  
  481.     if (0<count($string_param))
  482.         $url .= "?".implode($separator ,$string_param);
  483.  
  484.  
  485.  
  486.  
  487.     if ($print_stdout)
  488.         @print($url);
  489.  
  490.  
  491.  
  492.  
  493.  
  494.     return $url;
  495. }
  496.  
  497. /**
  498.  * Transform a Smarty date to a string
  499.  *
  500.  * @param string $p_var_name 
  501.  * @param array $p_array 
  502.  * @param string $p_default_value 
  503.  * @return string 
  504.  */
  505. function getDateSmartyFromArray($p_var_name&$p_array$p_default_value{
  506.     $date_day (isset($p_array[$p_var_name.'Day'])?$p_array[$p_var_name.'Day']:"");
  507.     $date_month (isset($p_array[$p_var_name.'Month'])?$p_array[$p_var_name.'Month']:"");
  508.     $date_year (isset($p_array[$p_var_name.'Year'])?$p_array[$p_var_name.'Year']:"");
  509.  
  510.     if ($date_day=="" && $date_month=="" && $date_year=="")
  511.         return $p_default_value;
  512.  
  513.     $f_birthday $date_year;
  514.     $f_birthday .= "-".$date_month;
  515.     $f_birthday .= "-".$date_day;
  516.  
  517.     return $f_birthday;
  518. }
  519.  
  520. /**
  521.  * Transform a Smarty date to a string and assign to smarty
  522.  *
  523.  * @param string $p_var_name 
  524.  * @param array $p_array 
  525.  * @param string $p_default_value 
  526.  * @param Smarty_custom $smarty 
  527.  * @return string 
  528.  */
  529.  
  530. function getDateSmartyFromArrayAndAssign($p_var_name&$p_array$p_default_value&$smarty{
  531.     $result getDateSmartyFromArray($p_var_name$p_array$p_default_value);
  532.  
  533.     if ($result != ''{
  534.         $smarty->assign_by_ref($p_var_name$result);
  535.     }
  536.     return $result;
  537. }
  538.  
  539. /**
  540.  * Delete accent from a string
  541.  *
  542.  * $tofind = "+-àáâãäåÒÓÔÖØ=óôõöøèéêë>ÇçÝÏìíîïÝ<ùúûüÿÑñ";
  543.  * $replac = "--aaaaaaOOOOO-oooooeeee-CcYIiiiiY-uuuuyNn";
  544.  * @param string $chaine 
  545.  * @return string 
  546.  */
  547. function SuppAccents($chaine){
  548.     $tofind "+-àáâãäåÒÓÔÖØ=óôõöøèéêë>ÇçÝÏìíîïÝ<ùúûüÿÑñ";
  549.     $replac "--aaaaaaOOOOO-oooooeeee-CcYIiiiiY-uuuuyNn";
  550.     return(strtr($chaine,$tofind,$replac));
  551. }
  552.  
  553. /**
  554.  * Find a key in an array an return it or return default value
  555.  *
  556.  * @param string $p_var_name 
  557.  * @param array $p_array 
  558.  * @param string $p_default_value 
  559.  * @return mixed 
  560.  */
  561. function getFromArray($p_var_name&$p_array$p_default_value{
  562.     return isset($p_array[$p_var_name])?$p_array[$p_var_name]:$p_default_value;
  563. }
  564.  
  565. /**
  566.  * Find a key (or default value) in an array an assign it to smarty
  567.  *
  568.  * @param string $p_var_name 
  569.  * @param array $p_array 
  570.  * @param string $p_default_value 
  571.  * @param Smarty_custom $smarty 
  572.  * @return mixed 
  573.  */
  574. function getFromArrayAndAssign($p_var_name&$p_array$p_default_value&$smarty{
  575.     $result getFromArray($p_var_name$p_array$p_default_value);
  576.  
  577.     //if ($result != '') {
  578.         $smarty->assign_by_ref($p_var_name$result);
  579.     //}
  580.     return $result;
  581. }
  582.  
  583. /**
  584.  * Dump a var
  585.  *
  586.  * @access private
  587.  * @param mixed $data 
  588.  * @return string 
  589.  */
  590. function xDumpVar($data{
  591.     $B_echo true;
  592.     ob_start();
  593.     var_dump($data);
  594.     $c ob_get_contents();
  595.     ob_end_clean();
  596.  
  597.     $c preg_replace("/\r\n|\r/""\n"$c);
  598.     $c str_replace("]=>\n"'] = '$c);
  599.     $c preg_replace('/= {2,}/''= '$c);
  600.     $c preg_replace("/\[\"(.*?)\"\] = /i""[$1] = "$c);
  601.     $c preg_replace('/    /'"        "$c);
  602.     $c preg_replace("/\"\"(.*?)\"/i""\"$1\""$c);
  603.  
  604.     $c htmlspecialchars($cENT_NOQUOTES);
  605.  
  606.     // Expand numbers (ie. int(2) 10 => int(1) 2 10, float(6) 128.64 => float(1) 6 128.64 etc.)
  607.     $c preg_replace("/(int|float)\(([0-9\.]+)\)/ie""'$1('.strlen('$2').') <span class=\"number\">$2</span>'"$c);
  608.  
  609.     // Syntax Highlighting of Strings. This seems cryptic, but it will also allow non-terminated strings to get parsed.
  610.     $c preg_replace("/(\[[\w ]+\] = string\([0-9]+\) )\"(.*?)/sim""$1<span class=\"string\">\""$c);
  611.     $c preg_replace("/(\"\n{1,})( {0,}\})/sim""$1</span>$2"$c);
  612.     $c preg_replace("/(\"\n{1,})( {0,}\[)/sim""$1</span>$2"$c);
  613.     $c preg_replace("/(string\([0-9]+\) )\"(.*?)\"\n/sim""$1<span class=\"string\">\"$2\"</span>\n"$c);
  614.  
  615.     $regex array(
  616.             // Numberrs
  617.             'numbers' => array('/(^|] = )(array|float|int|string|resource|object\(.*\)|\&amp;object\(.*\))\(([0-9\.]+)\)/i''$1$2(<span class="number">$3</span>)'),
  618.  
  619.             // Keywords
  620.             'null' => array('/(^|] = )(null)/i''$1<span class="keyword">$2</span>'),
  621.             'bool' => array('/(bool)\((true|false)\)/i''$1(<span class="keyword">$2</span>)'),
  622.  
  623.             // Types
  624.             'types' => array('/(of type )\((.*)\)/i''$1(<span class="type">$2</span>)'),
  625.  
  626.             // Objects
  627.             'object' => array('/(object|\&amp;object)\(([\w]+)\)/i''$1(<span class="object">$2</span>)'),
  628.  
  629.             // Function
  630.             'function' => array('/(^|] = )(array|string|int|float|bool|resource|object|\&amp;object)\(/i''$1<span class="function">$2</span>('),
  631.     );
  632.  
  633.     foreach ($regex as $x{
  634.             $c preg_replace($x[0]$x[1]$c);
  635.     }
  636.  
  637.     $style '
  638.     /* outside div - it will float and match the screen */
  639.     .dumpr {
  640.             margin: 2px;
  641.             padding: 2px;
  642.             background-color: #fbfbfb;
  643.             float: left;
  644.             clear: both;
  645.     }
  646.     /* font size and family */
  647.     .dumpr pre {
  648.             color: #000000;
  649.             font-size: 9pt;
  650.             font-family: "Courier New",Courier,Monaco,monospace;
  651.             margin: 0px;
  652.             padding-top: 5px;
  653.             padding-bottom: 7px;
  654.             padding-left: 9px;
  655.             padding-right: 9px;
  656.     }
  657.     /* inside div */
  658.     .dumpr div {
  659.             background-color: #fcfcfc;
  660.             border: 1px solid #d9d9d9;
  661.             float: left;
  662.             clear: both;
  663.     }
  664.     /* syntax highlighting */
  665.     .dumpr span.string {color: #c40000;}
  666.     .dumpr span.number {color: #ff0000;}
  667.     .dumpr span.keyword {color: #007200;}
  668.     .dumpr span.function {color: #0000c4;}
  669.     .dumpr span.object {color: #ac00ac;}
  670.     .dumpr span.type {color: #0072c4;}
  671.     .legenddumpr {
  672.            background-color: #fcfcfc;
  673.         border: 1px solid #d9d9d9;
  674.         padding: 2px;
  675.     }
  676.     ';
  677.  
  678.     $style preg_replace("/ {2,}/"""$style);
  679.     $style preg_replace("/\t|\r\n|\r|\n/"""$style);
  680.     $style preg_replace("/\/\*.*?\*\//i"''$style);
  681.     $style str_replace('}''} '$style);
  682.     $style str_replace(' {''{'$style);
  683.     $style trim($style);
  684.  
  685.     $c trim($c);
  686.     $c preg_replace("/\n<\/span>/""</span>\n"$c);
  687.  
  688.     $S_from    '';
  689.     // Nom du fichier appelant la fonction
  690.     $A_backTrace    debug_backtrace();
  691.     if (is_array($A_backTrace&& array_key_exists(0$A_backTrace)) {
  692.         $S_from = <<< BACKTRACE
  693.             {$A_backTrace[1]{'file'}}ligne {$A_backTrace[1]{'line'}}
  694. BACKTRACE;
  695.  
  696.     else {
  697.         $S_from basename($_SERVER['SCRIPT_FILENAME']);
  698.  
  699.     }
  700.  
  701.     $S_out    '';
  702.     $S_out    .= "<style type=\"text/css\">".$style."</style>\n";
  703.     $S_out    .= '<fieldset class="dumpr">';
  704.     $S_out    .= '<legend class="legenddumpr">'.$S_from.'</legend>';
  705.     $S_out    .= '<pre>'.$c.'</pre>';
  706.     $S_out    .= '</fieldset>';
  707.     $S_out    .= "<div style=\"clear:both;\">&nbsp;</div>";
  708.  
  709.     if ($B_echo{
  710.         echo $S_out;
  711.  
  712.     else {
  713.         return $S_out;
  714.  
  715.     }
  716.  
  717.  
  718. }
  719.  
  720. /**
  721.  * PLICI debug function
  722.  *
  723.  * @param mixed $array 
  724.  */
  725. function print_r_net($array{
  726.     xDumpVar($array);
  727. }
  728.  
  729. /**
  730.  * PLICI Debug echo
  731.  *
  732.  * @param mixed $string 
  733.  */
  734. function echo_net($string{
  735.     xDumpVar($string);
  736. }
  737.  
  738. /**
  739.  * A plici debug function
  740.  *
  741.  * @return array ['file'] => filename,['call']=> error
  742.  */
  743. {
  744.     $debug_output array();
  745.     $debug_stack debug_backtrace();
  746.     // Reformat output
  747.     foreach($debug_stack as $debug_step)
  748.     {
  749.         $tmp array();
  750.         $tmp['file'$debug_step['file'];
  751.         $tmp['call'"(L. ".$debug_step['line'].") ";
  752.         $tmp['call'.= $debug_step['function'];
  753.         $tmp['call'.= "(";
  754.         if (is_array($debug_step['args']))
  755.             $tmp['call'.= implode(","$debug_step['args']);
  756.         else if (is_string($debug_step['args']))
  757.             $tmp['call'.= $debug_step['args'];
  758.         $tmp['call'.= ")";
  759.         $debug_output[$tmp;
  760.     }
  761.     return $debug_output;
  762. }
  763.  
  764.  
  765.  
  766.  
  767. /**
  768.  * encode url
  769.  *
  770.  * @param string $p_value 
  771.  * @return string 
  772.  */
  773. function net_urlencode($p_value{
  774.         $separator_car "-";
  775.         $p_value SuppAccents(html_entity_decode(trim($p_value),ENT_QUOTES));
  776.         $p_value ereg_replace("[^[:alnum:]]"$separator_car$p_value);
  777.         $p_value ereg_replace("[-]+"$separator_car$p_value);
  778.         return $p_value;
  779. }
  780.  
  781. /**
  782.  * Usefull function to support multilanguage request.
  783.  * 
  784.  * It change a "param_name" to "param_name_l1" for language 1 for example.
  785.  *
  786.  * @param string $param_name 
  787.  * @param bool $p_for_insert (deprecated)
  788.  * @return string 
  789.  */
  790. function multilang($param_name$p_for_insert=FALSE{
  791.  
  792.     global $g_object_siteinformation;
  793.     $id_lang "";
  794.     $g_object_siteinformation->getCurrentFrontLanguageId($id_lang);
  795.  
  796.     //$id_lang = 1;
  797.     $result $param_name."_l".$id_lang;
  798.  
  799.     if ((!$p_for_insert&& ($id_lang != 1)) {
  800.         if ($g_object_siteinformation->isAdmin())
  801.             $result " IFNULL(".$result.", CONCAT('non traduit :',".$param_name."_l1)) ";
  802.         else
  803.             $result " IFNULL(".$result.", ".$param_name."_l1) ";
  804.         return $result;
  805.     }
  806.  
  807.     /*
  808.     if ($is_for_select && $id_lang != 1)
  809.         $result = " COALESCE(".$result.",CONCAT('NT:',".$param_name."_l1)) ";
  810.     return $result;
  811.     */
  812.     return $result;
  813. }
  814.  
  815.  
  816. /**
  817.  * A Smarty bloc forcing to not use cache
  818.  *
  819.  * @param array $param 
  820.  * @param string $content 
  821.  * @param Smarty_custom $smarty 
  822.  * @return string 
  823.  */
  824. function smarty_bloc_dynamique($param$content&$smarty{
  825.  
  826.     global $smarty_bloc_not_cached_old_tpl_vars;
  827.     if (isset($param['design_id']&& isset($param['page_id'])) {
  828.         if (is_null($content)) {
  829.             // premier passage dans la fonction BLOC
  830. //echo("!START NO-CACHE!");
  831.             global $g_object_loader;
  832.             //$object_smarty =& $g_object_loader->getSmarty_Custom();
  833.             $object_tpage =$g_object_loader->getTPageFo();
  834.  
  835. //            $smarty_bloc_not_cached_old_tpl_vars = $object_smarty->_tpl_vars;
  836.             $smarty_bloc_not_cached_old_tpl_vars $smarty->_tpl_vars;
  837.  
  838.             /** Le cas de isnotset si dessus est possible pour un not_cached dans une page
  839.              * il ne s'agit pas d'un problème, mais il ne faut pas chercher les infos pour un
  840.              * include car sinon le tableau renvoyé est vide
  841.              * **/
  842.             if (isset($object_tpage->m_array_link_data[$param['page_id']]))
  843.                 $smarty->_tpl_vars array_merge($object_tpage->m_array_link_data[$param['page_id']]
  844.                                     $smarty->m_tpl_var_for_all);
  845. //                $object_smarty->_tpl_vars = array_merge($object_tpage->m_array_link_data[$param['page_id']]
  846. //                                    , $object_smarty->m_tpl_var_for_all);
  847.  
  848.  
  849.             $smarty->assign('design_id'$param['design_id']);
  850.             //$smarty->assign('page_id', $param['page_id']);
  851.  
  852.  
  853.         else{
  854. //echo("!END NO-CACHE!");
  855.             $smarty->_tpl_vars $smarty_bloc_not_cached_old_tpl_vars;
  856.         }
  857.     }
  858.             return $content;
  859.  
  860. }
  861.  
  862.  
  863.  
  864.  
  865. // hander pour la protection des Adresses mail
  866. /**
  867.  * Protect email
  868.  *
  869.  * @param string $tpl_output 
  870.  * @param Smarty_custom $smarty 
  871.  * @return string 
  872.  */
  873. function protect_email($tpl_output&$smarty)
  874. {
  875.  
  876. //    $tpl_output =
  877. //    preg_replace('!([_a-z0-9-]+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
  878. //    '$1&#x40;$2', $tpl_output);
  879.     return $tpl_output;
  880. }
  881.  
  882. /**
  883.  * Print an integer in byte
  884.  *
  885.  * @param integer $p_param  Value in Octets
  886.  * @return string 
  887.  */
  888. function print_byte($p_param{
  889.     $array_convertion array(=> "o"1024 => "Ko"1048576 => "Mo"1073741824 => "Go");
  890.     $ext $array_convertion[0];
  891.     $divide 0;
  892.     foreach($array_convertion as $key => $value{
  893.         if ($p_param >= $key{
  894.                 $ext $array_convertion[$key];
  895.                 $divide $key;
  896.         else {
  897.             break;
  898.         }
  899.     }
  900.  
  901.     if ($divide 0)
  902.         $p_param round($p_param/$divide3);
  903.  
  904.     return $p_param." ".$ext;
  905. }
  906.  
  907.  
  908. /**
  909.  * Print formated weight
  910.  *
  911.  * @param integer $p_param 
  912.  * @return string 
  913.  */
  914. function print_weight($p_param{
  915.     global $g_object_loader;
  916.     $weight_format "";
  917.     $object_weight_format =$g_object_loader->getTGlobalScopeVariable();
  918.     $object_weight_format->getWeightFormat($weight_format);
  919.     if ((!(isset($p_param))) || (!(is_numeric($p_param)))) {
  920.             $weight_string $weight_format['null']['symbol'];
  921.     else {
  922.         if (1000>$p_param{
  923.             $weight_string sprintf("%.".str_replace('%''%%',$weight_format['gr']['nof_decimal'])."f "$p_param);
  924.             $weight_string str_replace("."$weight_format['gr']['decimal_separator']$weight_string).$weight_format['gr']['symbol'];
  925.         else {
  926.             if (1000000>$p_param{
  927.                 $weight_string sprintf("%.".str_replace('%''%%',$weight_format['kg']['nof_decimal'])."f "$p_param/1000);
  928.                 $weight_string str_replace("."$weight_format['kg']['decimal_separator']$weight_string).$weight_format['kg']['symbol'];
  929.             else {
  930.                 $weight_string sprintf("%.".str_replace('%''%%',$weight_format['t']['nof_decimal'])."f "$p_param/1000000);
  931.                 $weight_string str_replace("."$weight_format['t']['decimal_separator']$weight_string).$weight_format['t']['symbol'];
  932.             }
  933.         }
  934.     }
  935.     return $weight_string;
  936. }
  937.  
  938. /**
  939.  * Print a price from a float
  940.  *
  941.  * @param float $p_param 
  942.  * @return string 
  943.  */
  944. function print_price($p_param{
  945.     //echo_net($p_param);
  946.     global $g_object_loader;
  947.     $price_format "";
  948.     $object_price_format =$g_object_loader->getTGlobalScopeVariable();
  949.     $object_price_format->getPriceFormat($price_format);
  950.     global $g_object_siteinformation;
  951.     //echo_net("($p_param)");
  952.     if ((!(isset($p_param)))  || (!(is_numeric($p_param))  )) {
  953.             $price_string $price_format['symbol_null'];
  954.     else {
  955.         if ((== $p_param&& (!($g_object_siteinformation->isAdmin()))) {
  956.             $price_string $price_format['symbol_free'];
  957.         else {
  958.             //echo($p_param);
  959.             $price explode("."$p_param2)// $price[0]=Partie entière; $price[1]=partie décimale
  960.             // Séparateur de milliers
  961.             $price[0strrev($price[0]);
  962.             $price[0wordwrap($price[0]3$price_format['hundred_separator']1);
  963.             $price[0strrev($price[0]);
  964.             // Nombre de décimales
  965.             $price[1]= isset($price[1])?substr($price[1],0,$price_format['number_of_decimal']):0;
  966.             $price[1str_pad($price[1]$price_format['number_of_decimal']"0");
  967.             // Séparateur de décimales
  968.             // Symbole
  969.             $price_string $price[0];
  970.             if  (0<$price[1]{
  971.                 $price_string $price_string.$price_format['decimal_separator'].$price[1];
  972.             }
  973.             $price_string $price_string." ".$price_format['symbol'];
  974.         }
  975.     }
  976.     return $price_string;
  977. }
  978.  
  979. /**
  980.  * Print an integer to the format 0.00%
  981.  *
  982.  * @param string $p_param   Ex : 0.4
  983.  * @return string           Ex : 0.40 %
  984.  */
  985. function print_perct($p_param{
  986.  
  987.     $default_value "0";
  988.     $symbol " %";
  989.     $nb_decimal 2;
  990.     $decimal_separator ".";
  991.     if ((!(isset($p_param))) || (!(is_numeric($p_param)))) {
  992.             $perct_string $default_value.$symbol;
  993.     else {
  994.             $perct explode("."$p_param2)// $perct[0]=Partie entière; $perct[1]=partie décimale
  995.  
  996.             // Nombre de décimales
  997.             $perct[1]= isset($perct[1])?substr($perct[1],0,$nb_decimal):0;
  998.             $perct[1str_pad($perct[1]$nb_decimal"0");
  999.             // Séparateur de décimales
  1000.             // Symbole
  1001.             $perct_string $perct[0];
  1002.             /*if  (0<$price[1])*/ {
  1003.                 $perct_string $perct_string.$decimal_separator.$perct[1];
  1004.             }
  1005.             $perct_string $perct_string." ".$symbol;
  1006.     }
  1007.     return $perct_string;
  1008. }
  1009.  
  1010. /**
  1011.  * Print price with 2 decimals
  1012.  *
  1013.  * @param unknown_type $p_param 
  1014.  * @return unknown 
  1015.  */
  1016. function print_price_2dec($p_param{
  1017.     global $g_object_loader;
  1018.     $price_format "";
  1019.     $object_price_format =$g_object_loader->getTGlobalScopeVariable();
  1020.     $object_price_format->getPriceFormat($price_format);
  1021.     global $g_object_siteinformation;
  1022.     if ((!(isset($p_param))) || (!(is_numeric($p_param)))) {
  1023.             $price_string $price_format['symbol_null'];
  1024.     else {
  1025.         if ((== $p_param&& (!($g_object_siteinformation->isAdmin()))) {
  1026.             $price_string $price_format['symbol_free'];
  1027.         else {
  1028.             $price explode("."$p_param2)// $price[0]=Partie entière; $price[1]=partie décimale
  1029.             // Séparateur de milliers
  1030.             $price[0strrev($price[0]);
  1031.             $price[0wordwrap($price[0]3$price_format['hundred_separator']1);
  1032.             $price[0strrev($price[0]);
  1033.             // Nombre de décimales
  1034.             $price_format['number_of_decimal'2;
  1035.             $price[1]= isset($price[1])?substr($price[1],0,$price_format['number_of_decimal']):0;
  1036.             $price[1str_pad($price[1]$price_format['number_of_decimal']"0");
  1037.             // Séparateur de décimales
  1038.             // Symbole
  1039.             $price_string $price[0];
  1040.             /*if  (0<$price[1])*/ {
  1041.                 $price_string $price_string.$price_format['decimal_separator'].$price[1];
  1042.             }
  1043.             $price_string $price_string." ".$price_format['symbol'];
  1044.         }
  1045.     }
  1046.     return $price_string;
  1047. }
  1048.  
  1049. /**
  1050.  * Print a string to the PLICI date format
  1051.  *
  1052.  * @param string $p_param 
  1053.  * @return string 
  1054.  */
  1055. function print_date($p_param{
  1056.     global $g_object_loader;
  1057.     $date_format "";
  1058.     $object_date_format =$g_object_loader->getTGlobalScopeVariable();
  1059.     $object_date_format->getDateFormat($date_format);
  1060.     if (NULL != $p_param{
  1061.         $date_string @date($date_formatstrtotime($p_param));
  1062.     else {$date_string "&nbsp;";}
  1063.     return $date_string;
  1064. }
  1065.  
  1066. /**
  1067.  * Print an integer with day or days.
  1068.  * Sample : 4 days, 0 day
  1069.  *
  1070.  * @param integer $p_param 
  1071.  * @return string 
  1072.  */
  1073. function print_day($p_param{
  1074.     if ($p_param>1)
  1075.         return $p_param." ".plici_lang('lang_str_days');
  1076.     else
  1077.         return $p_param." ".plici_lang('lang_str_day');
  1078. }
  1079.  
  1080.  
  1081.  
  1082. /**
  1083.  * Retreive from an id the convert string in the good language
  1084.  *
  1085.  * @param string $p_id 
  1086.  * @param array $params 
  1087.  * @param string $p_type 
  1088.  * @return string 
  1089.  */
  1090. function plici_lang($p_id$params array()$p_type "TPL"{
  1091.  
  1092.     global $plici_by_pass_tlang_for_webhosting$g_lang_access_db;
  1093.     if (!isset($g_lang_access_db))
  1094.         $g_lang_access_db true;
  1095.     if (($plici_by_pass_tlang_for_webhosting == true|| ($g_lang_access_db == false))
  1096.         return $p_id;
  1097.  
  1098.  
  1099.     $not_used array();
  1100.     $params array_merge(array('id'=>$p_id'tp'=>$p_type)$params);
  1101.     return     x_smarty_function_plici_lang($params$not_usedfalse);
  1102. }
  1103.  
  1104. /**
  1105.  * Print a string translated in the current language from smarty
  1106.  *
  1107.  * @access private
  1108.  * @param array $params 
  1109.  * @param Smarty_custom $smarty 
  1110.  * @param bool  $print_stdout 
  1111.  * @return string 
  1112.  */
  1113. function x_smarty_function_plici_lang($params&$smarty$print_stdout true)
  1114. {
  1115.  
  1116.  
  1117.  
  1118.     // on recupère la valeur de l'id
  1119.     $id getFromArray('id'$params'');
  1120.     if ('' == $id)
  1121.         return;
  1122.  
  1123.     // on recupère la valeur du type
  1124.     $tp getFromArray('tp'$params'');
  1125.     if ('' == $tp$tp "TPL";
  1126.  
  1127.     // on realise le tableau pour le sprintf
  1128.     unset($params['id']);
  1129.     unset($params['tp']);
  1130.  
  1131.     global $g_object_loader;
  1132.     $object_tlang =$g_object_loader->getTLang();
  1133.     $string $object_tlang->getString($tp$id);
  1134.  
  1135.     //echo_net($string);
  1136.  
  1137.     //trigger_error("$string, $params");
  1138.     $string str_replace('%''%%'$string);
  1139.     $string str_replace('%%VALEUR%%''%s'$string);
  1140.     if ($print_stdout{
  1141.         //trigger_error("$string, $params");
  1142.         @vprintf($string$params);
  1143.     else
  1144.         return @vsprintf($string$params);
  1145.  
  1146.     return ;
  1147.  
  1148.  
  1149. }
  1150.  
  1151. /**
  1152.  * delete a directory recursively
  1153.  *
  1154.  * @param array|string$p_array_dir 
  1155.  * @return bool TRUE on error
  1156.  */
  1157. function net_rmdir($p_array_dir{
  1158.  
  1159.     if (is_string($p_array_dir))
  1160.         $p_array_dir array($p_array_dir);
  1161.  
  1162.     $there_is_an_error false;
  1163.     foreach($p_array_dir as $p_dir{
  1164.         $r_files array();
  1165.         if (net_scandir($p_dir$r_filesfalse""""truearray()array()falsefalse))
  1166.             return true;
  1167.         $r_files array_reverse($r_files);
  1168.         array_push($r_filesarray('current_path' => $p_dir));
  1169.  
  1170.         foreach($r_files as $value{
  1171.  
  1172.             if (file_exists($value['current_path'])) {
  1173.  
  1174.  
  1175.                 $last_car substr($value['current_path']strlen($value['current_path'])-1);
  1176. //                trigger_error("last car = ".$last_car);
  1177.         if ($last_car == "/"{
  1178.  
  1179.                     $name_for_test_link substr($value['current_path']0strlen($value['current_path'])-1);
  1180. //                    trigger_error("name for link test = ".$name_for_test_link);
  1181.                 }
  1182.  
  1183.                 if     ($name_for_test_link != "" && is_link($name_for_test_link)) {
  1184. //                    trigger_error("is a link");
  1185.                     if (!@unlink($name_for_test_link)) {
  1186.                         $there_is_an_error true;
  1187.                     }
  1188.                 else if (is_dir($value['current_path'])) {
  1189. //                    trigger_error("is a dir");
  1190.                     if (!@rmdir($value['current_path'])) {
  1191.                         $there_is_an_error true;
  1192.                     }
  1193.                 else {
  1194. //                    trigger_error("is a unlink");
  1195.                     if (!@unlink($value['current_path'])) {
  1196.                         $there_is_an_error true;
  1197.                     }
  1198.                 }
  1199.             }
  1200.         }
  1201.     }
  1202.         return $there_is_an_error;
  1203. }
  1204.  
  1205.  
  1206.  
  1207. /**
  1208.  * Scan a directory to list is files and directory (replace the php scan_dir function and add functionnalities)
  1209.  *
  1210.  * @param string $dir 
  1211.  * @param array $r_files 
  1212.  * @param bool $p_only_path 
  1213.  * @param string $parent_dir 
  1214.  * @param string $filename_for_not_copy_directory 
  1215.  * @param bool $recurse_sub_folder 
  1216.  * @param array $exclude_dirs 
  1217.  * @param array $p_directory_not_parsed 
  1218.  * @param bool $p_get_filie_size 
  1219.  * @param bool $p_not_get_symbolic_links 
  1220.  * @param false $p_echo 
  1221.  * @param integer $p_deep 
  1222.  * @return true on error, else false
  1223.  */
  1224.  
  1225. function net_scandir(
  1226.     $dir,
  1227.     &$r_files,
  1228.     $p_only_path false,
  1229.     $parent_dir "",
  1230.     $filename_for_not_copy_directory "",
  1231.     $recurse_sub_folder true,
  1232.     $exclude_dirs array(),
  1233.     $p_directory_not_parsed array(".svn"=>"no"),
  1234.     $p_get_filie_size false,
  1235.     $p_not_get_symbolic_links true,
  1236.     $p_echo false,
  1237.     $p_deep 1{
  1238.  
  1239.     if ($p_echoecho("\n");
  1240.  
  1241.     $p_directory_not_parsed array_merge($p_directory_not_parsedarray("."=>"no"".."=>"no"));
  1242.  
  1243.     $return_value xnet_scandir($dir$r_files$p_only_path$parent_dir$filename_for_not_copy_directory$recurse_sub_folder,
  1244.                 $exclude_dirs$p_directory_not_parsed$p_get_filie_size$p_not_get_symbolic_links$p_echo$p_deep);
  1245.     if (!function_exists("sw_cmp_order_net_scan_dir")) {
  1246.         function sw_cmp_order_net_scan_dir($a$b)
  1247.         {
  1248.            return strcmp($a['current_path']$b['current_path']);
  1249.         }
  1250.     }
  1251.  
  1252.     usort($r_files"sw_cmp_order_net_scan_dir");
  1253.  
  1254.     return $return_value;
  1255. }
  1256.  
  1257.  
  1258.  
  1259.  
  1260. /**
  1261.  * List of file into a folder and sub folder
  1262.  * $exclude_dirs = Keys are the dirs to excludes
  1263.  *
  1264.  * @access private
  1265.  * @param string $dir 
  1266.  * @param array $r_files 
  1267.  * @param bool $p_only_path 
  1268.  * @param string $parent_dir 
  1269.  * @param stirng $filename_for_not_copy_directory 
  1270.  * @param bool $recurse_sub_folder 
  1271.  * @param array $exclude_dirs 
  1272.  * @param array $p_directory_not_parsed 
  1273.  * @param bool $p_get_filie_size 
  1274.  * @param bool $p_not_get_symbolic_links 
  1275.  * @param bool $p_echo 
  1276.  * @param integer $p_deep 
  1277.  * @return bool TRUE on error
  1278.  */
  1279. function xnet_scandir(
  1280.     $dir,
  1281.     &$r_files,
  1282.     $p_only_path,
  1283.     $parent_dir,
  1284.     $filename_for_not_copy_directory,
  1285.     $recurse_sub_folder,
  1286.     $exclude_dirs,
  1287.     $p_directory_not_parsed,
  1288.     $p_get_filie_size,
  1289.     $p_not_get_symbolic_links,
  1290.     $p_echo false,
  1291.     $p_deep 1{
  1292.  
  1293.  
  1294.     if (!is_dir($dir))
  1295.         return false;
  1296.  
  1297.     $dh  opendir($dir);
  1298.  
  1299.     $tmp_r_files array();
  1300.     $break_because_file_not_copy_finded false;
  1301.  
  1302.  
  1303.     while (false !== ($filename readdir($dh))) {
  1304.        if (($filename_for_not_copy_directory == $filename)&&($filename_for_not_copy_directory != "")){
  1305.                $break_because_file_not_copy_finded true;
  1306.                $tmp_r_files array();
  1307.                break;
  1308.        }
  1309.  
  1310.        if ($p_not_get_symbolic_links && is_link($dir.$filename)) {
  1311.                if ($p_echo)
  1312.                    echo("Excluded SymLink : ".$dir.$filename."\n");
  1313.            continue;
  1314.        }
  1315.  
  1316. //        echo_net($filename);
  1317. //       echo($p_directory_not_parsed[$filename]);
  1318.        if (isset($p_directory_not_parsed[$filename]&& (is_dir($dir.$filename."/"|| is_link($dir.$filename."/"))) {
  1319.                if ($p_echo && $filename != "." && $filename != ".." && $filename != ".svn")
  1320.                    echo("Excluded : ".$dir.$filename."\n");
  1321.                continue;
  1322.        }
  1323.  
  1324.            if (is_dir($dir.$filename)) {
  1325.                $informations array();
  1326.                $informations['name'$filename;
  1327.                $informations['parent_dir'$parent_dir;
  1328.                   $informations['type'"directory";
  1329.                $informations['current_path'$dir.$filename."/";
  1330.                $informations['deep'$p_deep;
  1331.  
  1332.                   if ($p_only_path == false{
  1333.                     array_push($tmp_r_files,$informations);
  1334.                   else {
  1335.                     //array_push($tmp_r_files,$informations['current_path']);
  1336.                   }
  1337.  
  1338.                    //echo($informations['current_path']."\n");
  1339.  
  1340.                    if (!is_link($dir.$filename&& $recurse_sub_folder && (!isset($exclude_dirs[$informations['current_path']])) && !is_link($informations['current_path'])) {
  1341.                        xnet_scandir($informations['current_path']$tmp_r_files$p_only_path$filename,
  1342.                            $filename_for_not_copy_directory$recurse_sub_folder$exclude_dirs,
  1343.                            $p_directory_not_parsed$p_get_filie_size$p_not_get_symbolic_links$p_echo$p_deep+1);
  1344.                    else {
  1345.                     if ($p_echo)echo("Excluded : ".$informations['current_path']."\n");
  1346.                    }
  1347.            else  {
  1348.                $informations array();
  1349.                $informations['name'$filename;
  1350.                $informations['parent_dir'$parent_dir;
  1351.                    $informations['type'"file";
  1352.                    $informations['current_path'$dir.$filename;
  1353.                    $informations['deep'$p_deep;
  1354.                    $pathinfo pathinfo($informations['current_path']);
  1355.                    if (isset($pathinfo["extension"]))
  1356.                         $informations['extension'$pathinfo["extension"];
  1357.                    else
  1358.                         $informations['extension''';
  1359.  
  1360.                 if ($p_get_filie_size)
  1361.                     $informations['size'filesize($informations['current_path']);
  1362.  
  1363.                   if ($p_only_path == false{
  1364.                     array_push($tmp_r_files,$informations);
  1365.                   else {
  1366.                     array_push($tmp_r_files,$informations['current_path']);
  1367.                   }
  1368.  
  1369.  
  1370.  
  1371.            }
  1372.     }
  1373.  
  1374.  
  1375.     if (sizeof($tmp_r_files)>0)
  1376.         foreach($tmp_r_files as $value)
  1377.             array_push($r_files$value);
  1378.     else if ($break_because_file_not_copy_finded)
  1379.         /* le repertoire ne doit pas etre listé pour cause de fichier "not copy"*/
  1380.         array_pop($r_files);
  1381.  
  1382.     closedir($dh);
  1383.     //sort($files);
  1384.  
  1385.     return false;
  1386. }
  1387.  
  1388.  
  1389. /**
  1390.  * Create the symbolic link for PLICI
  1391.  *
  1392.  * @ deprecated Not used
  1393.  * @ param bool $echo
  1394.  * @ return bool TRUE on error
  1395. function createDocRootSymbolicLink ($echo = true) {
  1396.     global $_PLICI_CFG;
  1397.     $all_is_ok = true;
  1398.  
  1399.     $docRoot  = $_SERVER["DOCUMENT_ROOT"]."/";
  1400.  
  1401.     if (file_exists($_SERVER["DOCUMENT_ROOT"]))
  1402.         if (!createSymbolicLinksForPlici($docRoot, $echo))
  1403.             $all_is_ok = false;
  1404.  
  1405.     if ($all_is_ok)
  1406.         if ($echo) echo("\n<br/> Links created successfully");
  1407.  
  1408.     return $all_is_ok;
  1409.  
  1410. }
  1411.  
  1412.  
  1413.  */
  1414.  
  1415. /**
  1416. function createViewSymbolicLink ($echo = true) {
  1417.     global $_PLICI_CFG;
  1418.     $all_is_ok = true;
  1419.     if (file_exists($_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_DIRECTORY."/"))
  1420.         if (!createSymbolicLinksForPlici($_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_DIRECTORY."/", $echo))
  1421.             $all_is_ok = false;
  1422.  
  1423.     if ($all_is_ok)
  1424.         if ($echo) echo("\n<br/> Links created successfully");
  1425.  
  1426.     return $all_is_ok;
  1427.  
  1428. }
  1429.  
  1430.  
  1431.  * Create picture external symbolic links
  1432.  *
  1433.  * @ deprecated Not used
  1434.  * @ param bool $echo
  1435.  * @ return bool TRUE on error
  1436.  */
  1437. /*
  1438. function createPictureExtSymbolicLink($echo = true) {
  1439.     global $_PLICI_CFG;
  1440.     $r_files = array();
  1441.     $all_is_ok = true;
  1442.     net_scandir($_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_MY_DIRECTORY."/", $r_files, false, "", "", false);
  1443.     array_push($r_files, array(
  1444.                                 'type' => 'directory',
  1445.                                 'current_path' => $_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_FOR_PLICI_ADMIN_PLICI_DIRECTORY
  1446.                                 ));
  1447.     foreach($r_files as $value) {
  1448.         if ($value['type'] == 'directory') {
  1449.             if (file_exists($value['current_path']."/".PLICI_PICTURE_EXT_DIRECTORY."/"))
  1450.             if (!createSymbolicLinksForPlici($value['current_path']."/".PLICI_PICTURE_EXT_DIRECTORY."/", $echo))
  1451.                 $all_is_ok = false;
  1452.         }
  1453.     }
  1454.  
  1455.     if ($all_is_ok)
  1456.         if ($echo) echo("\n<br/> Links created successfully");
  1457.  
  1458.     return $all_is_ok;
  1459.  
  1460. }
  1461.  
  1462. function createSymbolicLinksForPlici($p_base_dir, $echo = true) {
  1463.         global $_PLICI_CFG;
  1464.  
  1465.         $all_is_ok = true;
  1466.         $directory_to_create = $p_base_dir."/core";
  1467.         if (!((file_exists($directory_to_create) &&  is_dir($directory_to_create)) || @mkdir($directory_to_create))) {
  1468.             if ($echo) echo("\n<br/> Error creating directory '".$directory_to_create."'.");
  1469.             $all_is_ok = false;
  1470.         }
  1471.  
  1472.         $link_one_link = $p_base_dir."/core/entrees";
  1473.         if (str_replace("//","/",$_PLICI_CFG['racine_web']."/core/entrees/") != str_replace("//","/",$link_one_link)."/")
  1474.             if (!((file_exists($link_one_link) &&  is_link($link_one_link)) || @symlink( $_PLICI_CFG['racine_web']."/core/entrees/", $link_one_link ))) {
  1475.                 if ($echo) echo("\n<br/> Error creating link ".$link_one_link." to ".$_PLICI_CFG['racine_web']."/core/entrees/");
  1476.                 $all_is_ok = false;
  1477.             }
  1478.         $link_two_link = $p_base_dir."/view";
  1479.         if (str_replace("//","/",$_PLICI_CFG['racine_web']."/view/") != str_replace("//","/",$link_two_link."/"))
  1480.             if (!((file_exists($link_two_link) &&  is_link($link_two_link)) || @symlink ( $_PLICI_CFG['racine_web']."/view/", $link_two_link ))) {
  1481.                 if ($echo) echo("\n<br/> Error creating link ".$link_two_link." to ".$_PLICI_CFG['racine_web']."/view/");
  1482.                 $all_is_ok = false;
  1483.             }
  1484.         return $all_is_ok;
  1485. }
  1486. */
  1487. /*
  1488. function createSymbolicLinkPliciWebSite($site_name, $admin_site_name, $echo = true) {
  1489.     return xCreateSymbolicLinkWebSite($site_name, $admin_site_name, $echo, "for_plici");
  1490. }
  1491.  
  1492. function createSymbolicLinkMyWebSite($site_name, $admin_site_name, $echo = true) {
  1493.     return xCreateSymbolicLinkWebSite($site_name, $admin_site_name, $echo, "my");
  1494. }
  1495. function xCreateSymbolicLinkWebSite($site_name, $admin_site_name, $echo = true, $p_for_plici_or_my) {
  1496.  
  1497.     global $_PLICI_CFG;
  1498.     $all_is_ok = true;
  1499.     if ($p_for_plici_or_my == "my") {
  1500.         $array_base_dir = array (
  1501.                         $_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_MY_DIRECTORY."/".$site_name."/".$admin_site_name,
  1502.                         $_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_MY_DIRECTORY."/".$site_name,
  1503.                     );
  1504.     } else {
  1505.         $array_base_dir = array (
  1506.                         $_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_FOR_PLICI_DIRECTORY."/".$site_name."/".$admin_site_name,
  1507.                         $_PLICI_CFG['racine_web']."/".PLICI_VIEW_SITES_FOR_PLICI_DIRECTORY."/".$site_name,
  1508.                     );
  1509.     }
  1510.     foreach($array_base_dir as $base_dir) {
  1511.             if (!createSymbolicLinksForPlici($base_dir, $echo))
  1512.                 $all_is_ok = false;
  1513.     }
  1514.  
  1515.     if ($all_is_ok)
  1516.         if ($echo) echo("\n<br/> Links created successfully");
  1517.  
  1518.     return $all_is_ok;
  1519. }
  1520. */
  1521. /**
  1522.  * Put a string into a file
  1523.  *
  1524.  * @param string $filename 
  1525.  * @param string $data_string 
  1526.  * @return bool TRUE on error
  1527.  */
  1528. function net_file_put_contents($filename$data_string){
  1529.   $ressource @fopen($filename"w");
  1530.     if ($ressource === FALSE{
  1531.         return true;
  1532.     }
  1533.   flock($ressourceLOCK_EX);
  1534.     fwrite($ressource$data_string);
  1535.     flock($ressourceLOCK_UN);
  1536.     fclose($ressource);
  1537.  
  1538.     return false;
  1539. }
  1540.  
  1541. /**
  1542.  * Generate a random password
  1543.  *
  1544.  * @param integer $length 
  1545.  * @return string 
  1546.  */
  1547. function generatePassword ($length 8)
  1548. {
  1549.  
  1550.   // start with a blank password
  1551.   $password "";
  1552.  
  1553.   // define possible characters
  1554.   $possible "0123456789bcdfghjkmnpqrstvwxyz";
  1555.  
  1556.   // set up a counter
  1557.   $i 0;
  1558.  
  1559.   // add random characters to $password until $length is reached
  1560.   while ($i $length{
  1561.  
  1562.     // pick a random character from the possible ones
  1563.     $char substr($possiblemt_rand(0strlen($possible)-1)1);
  1564.  
  1565.     // we don't want this character if it's already in the password
  1566.     if (!strstr($password$char)) {
  1567.       $password .= $char;
  1568.       $i++;
  1569.     }
  1570.  
  1571.   }
  1572.  
  1573.   // done!
  1574.   return $password;
  1575.  
  1576. }
  1577.  
  1578. /**
  1579.  * Delete database cache (/bd/my/website/*.already_made) for a specific website
  1580.  *
  1581.  * @param unknown_type $p_database 
  1582.  * @param unknown_type $p_racine_web_path 
  1583.  * @param unknown_type $echo 
  1584.  * @return unknown 
  1585.  */
  1586. function deleteCacheForMyDatabase($p_database$p_racine_web_path$echo true{
  1587.     return xDeleteCacheForDatabase($p_database$p_racine_web_path$echo"my");
  1588. }
  1589.  
  1590. /**
  1591.  * Delete database cache (/bd/for_plici/website/*.already_made) for a specific website
  1592.  *
  1593.  * @param unknown_type $p_database 
  1594.  * @param unknown_type $p_racine_web_path 
  1595.  * @param unknown_type $echo 
  1596.  * @return unknown 
  1597.  */
  1598. function deleteCacheForPliciDatabase($p_database$p_racine_web_path$echo true{
  1599.     return xDeleteCacheForDatabase($p_database$p_racine_web_path$echo"for_plici");
  1600. }
  1601.  
  1602. /**
  1603.  * Delete the database script cache (already made)
  1604.  *
  1605.  * @access private
  1606.  * @param string $p_database 
  1607.  * @param string $p_racine_web_path 
  1608.  * @param bool $echo 
  1609.  * @param string $p_my_or_plici 
  1610.  */
  1611. function xDeleteCacheForDatabase($p_database$p_racine_web_path$echo true$p_my_or_plici ""{
  1612.  
  1613.     if ($echo)echo("<strong>Deleting lock files for '".$p_database."in '$p_my_or_plici'</strong>");
  1614.  
  1615.     global $_PLICI_CFG;
  1616.     if (isset($_PLICI_CFG['superadmin_databasename']&& ($p_database == $_PLICI_CFG['superadmin_databasename'])
  1617.         )
  1618.             $p_database "admin_super";
  1619. //    else
  1620. //        {if ($echo)echo("deleteCacheForDatabase");die();}
  1621.  
  1622.  
  1623.     if ($p_my_or_plici == 'my'{
  1624.         $cache_dir_to_delete $p_racine_web_path."/".PLICI_BD_MY_DIRECTORY."/".$p_database."/";
  1625.     else
  1626.         $cache_dir_to_delete $p_racine_web_path."/".PLICI_BD_FOR_PLICI_DIRECTORY."/".$p_database."/";
  1627.  
  1628.  
  1629.  
  1630.     $result_file array();
  1631.     net_scandir($cache_dir_to_delete$result_file);
  1632.  
  1633.     foreach($result_file as $key => $value{
  1634.         if ($value["extension"== "already_made"{
  1635.             if ($echo)echo("\n<br/>Deleting file : ".$value['name']);
  1636.             unlink($value['current_path']);
  1637.         }
  1638.     }
  1639.     if (sizeof($result_file== 0)
  1640.         if ($echo)echo("\n<br />Nothing to delete");
  1641.  
  1642.     if ($echo)echo ("\n<br />");
  1643. }
  1644.  
  1645. /**
  1646.  * Delete all cache (/tmp/website/) for a specific website
  1647.  *
  1648.  * @param string $p_web_site_name 
  1649.  * @param string $p_racine_web_path 
  1650.  * @param bool $echo 
  1651.  */
  1652.  
  1653. function deleteCompleteCacheForWebSite($p_web_site_name$p_racine_web_path$echo true{
  1654.  
  1655.     $cache_dir_to_delete $p_racine_web_path."/tmp/".$p_web_site_name.'/';
  1656.  
  1657.     // delete the host cache
  1658.     if (file_exists($p_racine_web_path."/tmp/host.cache"))
  1659.         @unlink($p_racine_web_path."/tmp/host.cache");
  1660.  
  1661.     if ($echo)echo("\n<br/><strong>Deleting complete cache dir for website:".$p_web_site_name." :</strong>");
  1662.     $result_file array();
  1663.     net_scandir($cache_dir_to_delete$result_file);
  1664.  
  1665.     foreach($result_file as $key => $value{
  1666.         if ($echo)echo(".");
  1667.         unlink($value['current_path']);
  1668.     }
  1669.     if (sizeof($result_file== 0)
  1670.         if ($echo)echo("\n<br/>Nothing to do");
  1671.  
  1672.     if ($echo)echo ("\n<br/>");
  1673. }
  1674.  
  1675. /**
  1676.  * Delete Smarty file cache (/tmp/websitename/cache/websitename/) for a specific website
  1677.  *
  1678.  * @param string $p_web_site_name 
  1679.  * @param string $p_racine_web_path 
  1680.  * @param bool $echo 
  1681.  */
  1682. function deleteCacheForWebSite($p_web_site_name$p_racine_web_path$echo true{
  1683.  
  1684.     $cache_dir_to_delete $p_racine_web_path."/tmp/".$p_web_site_name."/cache/".$p_web_site_name.'/';
  1685.  
  1686.     // delete the host cache
  1687.     $host_file_cache $p_racine_web_path."/tmp/host.cache";
  1688.     if (file_exists($host_file_cache))
  1689.         @unlink($host_file_cache);
  1690.  
  1691.  
  1692.     if ($echo)echo("\n<br/><strong>Deleting cache dir for website:".$p_web_site_name." :</strong>");
  1693.     $result_file array();
  1694.     net_scandir($cache_dir_to_delete$result_file);
  1695.  
  1696.     foreach($result_file as $key => $value{
  1697.         if ($echo)echo(".");
  1698.         unlink($value['current_path']);
  1699.     }
  1700.     if (sizeof($result_file== 0)
  1701.         if ($echo)echo("\n<br/>Nothing to do");
  1702.  
  1703.     if ($echo)echo ("\n<br/>");
  1704. }
  1705.  
  1706.  
  1707. /**
  1708.  * Copy a directory to another
  1709.  *
  1710.  * @param string $base_src 
  1711.  * @param string $base_dest 
  1712.  * @param array $extension_to_copy  Becareful sample $array ('html'=>'OK', 'php'=>'OK')
  1713.  * @param string $filename_for_not_copy_directory 
  1714.  * @param bool $is_no_error_if_file_exist_and_no_overwrite 
  1715.  * @return bool TRUE on error
  1716.  */
  1717. function net_copy($base_src$base_dest$extension_to_copy,
  1718.     $filename_for_not_copy_directory ".not_copy_this_directory"$is_no_error_if_file_exist_and_no_overwrite false{
  1719.  
  1720.      if (!file_exists($base_dest))
  1721.          if (net_mkdirs($base_dest=== FALSE{
  1722.              return true;
  1723.          }
  1724.      $sub_dir_and_files array();
  1725.      if (!file_exists($base_src))
  1726.          return true;
  1727.  
  1728.      net_scandir($base_src$sub_dir_and_filesfalse""$filename_for_not_copy_directory);
  1729.  
  1730.  
  1731.  
  1732.  
  1733.      foreach($sub_dir_and_files as $value{
  1734.  
  1735.          if ((sizeof($extension_to_copy== 0|| ($extension_to_copy[$value['extension']] == 'OK')) {
  1736.  
  1737.              // transformation du chemin pour créer le path de destination
  1738.              $value['current_path_dest'str_replace($base_src$base_dest$value['current_path']);
  1739. //echo($value['current_path_dest']."\n<br/>");
  1740.  
  1741.              // copie
  1742.              if ($value['type'== 'directory'){
  1743.                  if (file_exists($value['current_path_dest']&& is_dir($value['current_path_dest'])) {
  1744. //echo("Already exist directory ".$value['current_path_dest'].", is OK\n<br/>");
  1745.                      ;
  1746.                  else if (net_mkdirs($value['current_path_dest']== FALSE){
  1747. echo("Error creating the directory :".$value['current_path_dest']."\n<br/>");
  1748.                      return true;
  1749.                  }
  1750.              else if ($value['type'== 'file'{
  1751.                 if ($is_no_error_if_file_exist_and_no_overwrite && file_exists($value['current_path_dest'])){
  1752. //echo("Already exist file ".$value['current_path_dest'].", is OK\n<br/>");
  1753.                     continue;
  1754.                 }
  1755.                 if (!file_exists(dirname($value['current_path_dest']))) {
  1756. //echo("Directories doesn't exist, then create it ".dirname($value['current_path_dest'])."\n<br/>");
  1757.                     net_mkdirs(dirname($value['current_path_dest']));
  1758.                 }
  1759.  
  1760.                  if (copy($value['current_path']$value['current_path_dest']== FALSE{
  1761. echo("Error copying ".$value['current_path']." to ".$value['current_path_dest']."\n<br/>");
  1762.                      return true;
  1763.                  }
  1764.              }
  1765. //echo(".");
  1766.          }
  1767.      }
  1768.  
  1769.      return false;
  1770. }
  1771.  
  1772. /**
  1773.  * Generate a unique id (35 characters)
  1774.  *
  1775.  * @return unknown 
  1776.  */
  1777. function generateUniqueId({
  1778.     return md5(uniqid(rand()true));
  1779. }
  1780.  
  1781. /**
  1782.  * No return new directory, only return the actual admin dir.
  1783.  * @todo It is really wath we need ?
  1784.  *
  1785.  * @return string 
  1786.  */
  1787. function getNewAdminSuperDirectory()  {
  1788.     global $_PLICI_CFG;
  1789.     $base_directory $_PLICI_CFG['racine_web'].'/'.PLICI_VIEW_SITES_FOR_PLICI_ADMIN_PLICI_DIRECTORY.'/';
  1790.  
  1791.     $result array();
  1792.     net_scandir($base_directory$resultfalse""""false);
  1793.     $already_moved_to "";
  1794.     foreach($result as $key => $value{
  1795.         if (substr($value['name']07== 'admins_'{
  1796.             $already_moved_to $value['name'];
  1797.         }
  1798.     }
  1799.     return $already_moved_to;
  1800. }
  1801.  
  1802. /**
  1803.  * Find the admin directory of a web site
  1804.  *
  1805.  * @param string $p_dbname 
  1806.  * @return string 
  1807.  */
  1808. function getAdminDirectory($p_dbname)  {
  1809.     global $_PLICI_CFG;
  1810.     $base_directory $_PLICI_CFG['racine_web'].'/'.PLICI_VIEW_SITES_MY_DIRECTORY.'/'.$p_dbname.'/';
  1811.  
  1812.     $result array();
  1813.     net_scandir($base_directory$resultfalse""""false);
  1814.     $already_moved_to "";
  1815.     foreach($result as $key => $value{
  1816.         if (substr($value['name']06== 'admin_'{
  1817.             $already_moved_to $value['name'];
  1818.         }
  1819.     }
  1820.     return $already_moved_to;
  1821. }
  1822. /**
  1823.  * Replace in files
  1824.  *
  1825.  * @param array $array_files_to_parse 
  1826.  * @param array $parameters 
  1827.  * @param string $suffix_for_file_generated 
  1828.  * @return bool TRUE on error
  1829.  */
  1830. function replace_in_files($array_files_to_parse$parameters$suffix_for_file_generated ""{
  1831.     foreach($array_files_to_parse as $filename{
  1832.       // on va parser les fichiers qui en ont besoin
  1833.       $string_to_parse file_get_contents($filename);
  1834.       if ($string_to_parse === FALSE)
  1835.           return true;
  1836.       foreach($parameters as $key => $value)
  1837.         $string_to_parse str_replace($key$value,$string_to_parse);
  1838.  
  1839.       $ressource fopen($filename.$suffix_for_file_generated"w");
  1840.       if ($ressource === FALSE)
  1841.           return true;
  1842.  
  1843.     flock($ressourceLOCK_EX);
  1844.        fwrite($ressource$string_to_parse);
  1845.       flock($ressourceLOCK_UN);
  1846.       fclose($ressource);
  1847.       //file_put_contents(, $string_to_parse);
  1848.       //echo(".");
  1849.  
  1850.  
  1851.     }
  1852.     return false;
  1853. }
  1854.  
  1855. /**
  1856.  * Transform a string
  1857.  *
  1858.  * @param string $insert_for_admin_super 
  1859.  * @param array $parameters 
  1860.  * @return string 
  1861.  */
  1862. function transformWithParameters($insert_for_admin_super ,$parameters{
  1863.     foreach ($parameters as $key => $value)
  1864.     $insert_for_admin_super str_replace($key$value$insert_for_admin_super);
  1865.     return $insert_for_admin_super;
  1866. }
  1867.  
  1868.  
  1869. /**
  1870.  * Transform a string and write it
  1871.  *
  1872.  * @param string $string 
  1873.  * @param array $parameters [to_change]=>"change by"
  1874.  * @param string $filename 
  1875.  */
  1876. function transformStringAndWriteToFile($string$parameters$filename{
  1877.     $string =  transformWithParameters($string ,$parameters);
  1878.     $ressource fopen($filename"w");
  1879.   flock($ressourceLOCK_EX);
  1880.     fwrite($ressource$string);
  1881.   flock($ressourceLOCK_UN);
  1882.     fclose($ressource);
  1883. }
  1884.  
  1885.  
  1886. /**
  1887.  * run an SQL script file
  1888.  *
  1889.  * @param string $file_path 
  1890.  * @param resource $mysql_link 
  1891.  * @param string $end_line 
  1892.  * @return bool TRUE on error
  1893.  */
  1894. function mysql_execute_script($file_path&$mysql_link$end_line "<br/>"{
  1895.  
  1896.           $sql_to_play file_get_contents($file_path);
  1897.  
  1898.  
  1899.         return mysql_execute_multiplerequest($sql_to_play$mysql_link$end_line);
  1900.  
  1901. }
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907. /**
  1908.  * execute multiple SQL requests in a string
  1909.  * BECAREFULL : She is also declared in  databaseconnexion object
  1910.  *
  1911.  * @param string $sql_to_play 
  1912.  * @param resource $mysql_link 
  1913.  * @param string $end_line 
  1914.  * @return bool TRUE on error
  1915.  */
  1916. function mysql_execute_multiplerequest($sql_to_play&$mysql_link$end_line "<br/>"{
  1917.         $all_is_ok true;
  1918.  
  1919.           $next_request "";
  1920.         $i_am_in_quote false;
  1921.         $last_start 0;
  1922.         $array_request array();
  1923.         $is_car_inhibiter false;
  1924.         $remember_initial_quote '';
  1925.         $waiting_for_possible_comment true;
  1926.         $first_comment_finded false;
  1927.         $second_comment_finded false;
  1928.         for($i=0$i<strlen($sql_to_play);$i++{
  1929.  
  1930.                 if (!$i_am_in_quote{
  1931.                     if ($second_comment_finded && $sql_to_play[$i== "\n"){
  1932.                         $last_start $i+1;
  1933.                     else if ($second_comment_finded{
  1934.                         continue;
  1935.                     }
  1936.  
  1937.  
  1938.                     if ($sql_to_play[$i== "\n"{
  1939.                         $waiting_for_possible_comment true;
  1940.                         $first_comment_finded false;
  1941.                         $second_comment_finded false;
  1942.                     else if ($waiting_for_possible_comment && $sql_to_play[$i== "-"{
  1943.                         if ($first_comment_finded)
  1944.                             $second_comment_finded true;
  1945.                         else
  1946.                             $first_comment_finded true;
  1947.                     else if ($sql_to_play[$i!= " " && $sql_to_play[$i!= "\t"{
  1948.                         $waiting_for_possible_comment false;
  1949.                         $first_comment_finded false;
  1950.                         $second_comment_finded false;
  1951.                     else {
  1952.                         $first_comment_finded false;
  1953.                         $second_comment_finded false;
  1954.                     }
  1955.                 }
  1956.  
  1957.  
  1958.                 if ($is_car_inhibiter{
  1959.                     $is_car_inhibiter false;
  1960. //                    echo_net("inhibiter to FALSE ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1961.                     continue;
  1962.                 }
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.                 if ($sql_to_play[$i== "\\"{
  1969.                     $is_car_inhibiter true;
  1970. //                    echo_net("inhibiter to TRUE ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1971.  
  1972.                 else {
  1973.                     if (($remember_initial_quote == ""&& (($sql_to_play[$i== "'"|| ($sql_to_play[$i== '"'))){
  1974.                         $i_am_in_quote true;
  1975.                         $remember_initial_quote $sql_to_play[$i];
  1976. //                        echo_net("STARTING quote : ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1977.                     else if (($remember_initial_quote != ''&& ($sql_to_play[$i== $remember_initial_quote )) {
  1978.                         $i_am_in_quote false;
  1979. //                        echo_net("ENDING quote : ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  1980.                         $remember_initial_quote '';
  1981.                     else if (($sql_to_play[$i== ";"&& !$i_am_in_quote{
  1982.                             $new_request substr($sql_to_play$last_start$i+1-$last_start);
  1983.  
  1984.                             $new_request trim(ereg_replace("/^[ \n\r\t]*/i"""$new_request));
  1985.  
  1986.  
  1987.                             // on desactive les LOCK TABLES
  1988.                             if (preg_match('/^LOCK[\s]+TABLES/i'$new_request|| preg_match('/^UNLOCK[\s]+TABLES[\s]*;/i'$new_request))
  1989.                                 $new_request "";
  1990.  
  1991.  
  1992.                             if ($new_request != "" && $new_request != ";"{
  1993.                                     $mysql_result mysql_query($new_request$mysql_link);
  1994.                                     if (!$mysql_result{
  1995.                                           echo("\n\n<br/>ERROR mysql_execute_multiplerequest : ".mysql_error($mysql_link)." for request <br/>".$new_request."<br/> Link :".$mysql_link."<br/>");
  1996.                                           trigger_error("<br/>ERROR mysql_execute_multiplerequest : ".mysql_error($mysql_link)." for request <br/>".$new_request."<br/> Link :".$mysql_link."<br/>");
  1997.                                           $all_is_ok false;
  1998.                                       else {
  1999.                                           //echo_net(".");
  2000.                                     }
  2001.                             }
  2002.                                 array_push($array_request$new_request);
  2003.                             $last_start $i+1;
  2004. //                            echo_net("finded ;"."     (remembered quote :".$remember_initial_quote.")");
  2005. //                            echo_net("Making string ".$new_request."     (remembered quote :".$remember_initial_quote.")");
  2006.                     else {
  2007. //                        echo_net("car not used : ".$sql_to_play[$i]."     (remembered quote :".$remember_initial_quote.")");
  2008.                     }
  2009.  
  2010.                 }
  2011. //                echo("\n");
  2012.  
  2013.         }
  2014. //        print_r_net($array_request);
  2015.         return $all_is_ok;
  2016. }
  2017.  
  2018.  
  2019.  
  2020. global $g_plici_connexion_pool;
  2021. $g_plici_connexion_pool array();
  2022. /**
  2023.  * Find the link to connect to a database
  2024.  *
  2025.  * @param string $database_name 
  2026.  * @param string $p_dbc_inherited_sitename Inherited site name
  2027.  * @return resource 
  2028.  */
  2029. function get_mysql_link_for_database($database_name&$p_dbc_inherited_sitename{
  2030.  
  2031. //trigger_error("asking connection for $database_name.");
  2032. global $g_plici_connexion_pool;
  2033. global $_PLICI_CFG;
  2034.  
  2035. if ($database_name == "admin_super")
  2036.     $database_name $_PLICI_CFG['superadmin_databasename'];
  2037.  
  2038. //trigger_error(print_r($g_plici_connexion_pool, true));
  2039.     if (isset($g_plici_connexion_pool[$database_name])) {
  2040. //trigger_error("Connection exist.");
  2041.         if($result mysql_query("SELECT DATABASE();"$g_plici_connexion_pool[$database_name]['link'])) {
  2042.             $row mysql_fetch_row($result);
  2043.         //if(mysql_ping($g_plici_connexion_pool[$database_name]['link'])) {
  2044.         
  2045.             // i must select the bd because mysql_connect can give me same link but i need it for
  2046.             //    another BD
  2047.             if ($row[0<> $database_name{
  2048.                 $selected_is_ok mysql_select_db($database_name$g_plici_connexion_pool[$database_name]['link']);
  2049. //trigger_error("mysql_select_db($database_name, ".$g_plici_connexion_pool[$database_name]['link'].")");
  2050.                 if (!$selected_is_ok{
  2051. //trigger_error("mysql_select_db OK");
  2052.                 else {
  2053. //trigger_error("mysql_select_db BAD");
  2054.                 }
  2055.             else {
  2056. //trigger_error("mysql_select_db not needed connected and database selected is ".$row[0]);                
  2057.             }
  2058. //trigger_error("already connected to $database_name:)\n");
  2059.  
  2060.     $p_dbc_inherited_sitename $g_plici_connexion_pool[$database_name]['dbc_inherited_sitename'];
  2061.                 
  2062.             
  2063.             // on set dans une variable globale la connection courrante
  2064.             // pour les scripts
  2065.             global $run_db_directory_current_link;
  2066.             $run_db_directory_current_link =  $g_plici_connexion_pool[$database_name]['link'];
  2067.  
  2068.  
  2069.             return $g_plici_connexion_pool[$database_name]['link'];
  2070.         }
  2071.     }
  2072. //trigger_error("CREATING connection $database_name :( \n");
  2073.  
  2074.  
  2075.  
  2076.         $link_for_database "";
  2077.         $p_dbc_inherited_sitename "";
  2078.         $all_is_ok true;
  2079.  
  2080.         // correction pour OVH car trop de requete sur autre bd je pense (enfin a voir pas sûr)
  2081.         
  2082.         $admin_mysql_link =&
  2083.         plici_mysql_connect($_PLICI_CFG['superadmin_hostname'],
  2084.                     $_PLICI_CFG['superadmin_username']$_PLICI_CFG['superadmin_password']10true);
  2085.  
  2086.         if ($admin_mysql_link === FALSE{
  2087.                echo("ERROR get_mysql_link_for_database: connect error<br/>\n");
  2088.                trigger_error("ERROR get_mysql_link_for_database: connect error<br/>\n");
  2089.             return "error";
  2090.         }
  2091. //trigger_error("mysql_select_db(".$_PLICI_CFG['superadmin_databasename'].", ".$admin_mysql_link.")");
  2092.         $_3d6f_loc_select_db_is_ok mysql_select_db($_PLICI_CFG['superadmin_databasename']$admin_mysql_link);
  2093.  
  2094.         if ($database_name != $_PLICI_CFG['superadmin_databasename']{
  2095.  
  2096.             $request "SELECT dbc_dblogindbc_dbpassdbc_dbhostdbc_inherited_sitename FROM databaseconnect WHERE dbc_dbname = '$database_nameand dbc_dblogin <> 'ALIAS';";
  2097. //trigger_error($request);
  2098.             $result mysql_query($request    $admin_mysql_link);
  2099.                if (!$result){
  2100.                        echo("ERROR get_mysql_link_for_database: mysql_query<br/>\n");
  2101.                        trigger_error("ERROR get_mysql_link_for_database: mysql_query<br/>");
  2102.                     $all_is_ok false;
  2103.                }
  2104.     
  2105.             $row mysql_fetch_assoc($result);
  2106.             mysql_close($admin_mysql_link);
  2107.     
  2108.             $p_dbc_inherited_sitename $row["dbc_inherited_sitename"];
  2109.             
  2110. //trigger_error("mysql_connect(".$_PLICI_CFG['superadmin_hostname'].", ".$row["dbc_dblogin"].",    ".$row["dbc_dbpass"].")");
  2111. //trigger_error($row["dbc_dbhost"]." - ".$row["dbc_dblogin"]." - ".$row["dbc_dbpass"]);
  2112.  
  2113.             
  2114.             // on place un mysql_connect en forçant une nouvelle connextion car sinon, si login et pass et host
  2115.             // sont identiques on va avoir les même id de connexion et dans les script de update_database
  2116.             // quand on utilise l'id de connexion pour le super admin, on sera pas peut être plus sur la bonne bd.
  2117.             $link_for_database =plici_mysql_connect($row["dbc_dbhost"]$row["dbc_dblogin"],    $row["dbc_dbpass"]10true);
  2118.                if ($link_for_database === FALSE){
  2119.                        echo("ERROR get_mysql_link_for_database: can't connect<br/>\n");
  2120.                        trigger_error("ERROR get_mysql_link_for_database: can't connect<br/>");
  2121.                     $all_is_ok false;
  2122.                else {
  2123.  
  2124. //trigger_error("mysql_select_db(".$database_name.", ".$link_for_database.")");
  2125.                        if (mysql_select_db($database_name$link_for_database=== FALSE{
  2126.                            echo("ERROR get_mysql_link_for_databasecan't select db '$database_name'<br/>".mysql_error($link_for_database)."<br/>\n");
  2127.                            trigger_error("ERROR get_mysql_link_for_databasecan't select db '$database_name'<br/>".mysql_error($link_for_database)."<br/>\n");
  2128.  
  2129.                         $all_is_ok false;
  2130.                    }
  2131. //trigger_error("Connected to db : ".$database_name."<br/>");
  2132.                }
  2133.     
  2134.     
  2135. //trigger_error($link_for_database);
  2136.     
  2137.     
  2138.  
  2139.         }
  2140.       
  2141. //trigger_error(sprintf ("current thread id is %d\n", mysql_thread_id())); 
  2142.       
  2143.       if ($all_is_ok{
  2144.         $g_plici_connexion_pool[$database_namearray();
  2145.         if ($database_name == $_PLICI_CFG['superadmin_databasename']{
  2146.             $link_for_database =$admin_mysql_link;
  2147.             $g_plici_connexion_pool[$database_name]['dbc_inherited_sitename'"";
  2148.             $g_plici_connexion_pool[$database_name]['link'&$admin_mysql_link;
  2149.         else {
  2150.             $g_plici_connexion_pool[$database_name]['dbc_inherited_sitename'$p_dbc_inherited_sitename;
  2151.             $g_plici_connexion_pool[$database_name]['link'&$link_for_database;
  2152.         }
  2153. //trigger_error(print_r($g_plici_connexion_pool, true));
  2154.         
  2155.         global $run_db_directory_current_link;
  2156.         $run_db_directory_current_link =  $link_for_database;
  2157.  
  2158.  
  2159.           return $link_for_database;
  2160.       else
  2161.           return "error";
  2162.  
  2163.  
  2164. }
  2165.  
  2166. /**
  2167.  * Drop a database.
  2168.  * BECAREFULL : Use it with care !
  2169.  *
  2170.  * @param string $host 
  2171.  * @param string $databasename 
  2172.  * @param string $login 
  2173.  * @param string $pass 
  2174.  * @param bool $echo 
  2175.  * @return bool TRUE on error
  2176.  */
  2177. function mysql_drop_database($host$databasename$login$pass$echo true{
  2178. //    $_3d6f_loc_id_sql_admin_super = mysql_connect($host, $login, $pass);
  2179. //    $_3d6f_loc_select_db_is_ok = mysql_select_db($databasename);
  2180. //    mysql_list_tables();
  2181.  
  2182.     if($echo)echo("Cleanning database '$databasename'<br/>\n");
  2183.  
  2184.     $link plici_mysql_connect($host$login$pass10true);
  2185.   if (!$link{
  2186.        if($echo)print 'Could not connect to mysql';
  2187.        return true;
  2188.    }
  2189.  
  2190.    $result mysql_list_tables($databasename$link);
  2191.    mysql_select_db($databasename$link);
  2192.    if (!$result{
  2193.        if($echo)print "DB Error, could not list tables\n";
  2194.        if($echo)print 'MySQL Error: ' mysql_error();
  2195.        return true;
  2196.    }
  2197.  
  2198.     while ($row mysql_fetch_row($result)) {
  2199.        mysql_query("drop table ".$row[0].";"$link);
  2200.        if($echo)echo("Drop table ".$row[0]."<br/>\n");
  2201.    }
  2202.  
  2203.      mysql_close($link);
  2204.    return false;
  2205. }
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212. /**
  2213.  * Execute an SQL script an find the login to connect to the good database
  2214.  *
  2215.  * @param string $database_name 
  2216.  * @param string $script_filename 
  2217.  * @return bool TRUE on error
  2218.  */
  2219. function mysql_exec_script_and_search_login_from_admin (&$database_name$script_filename{
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.     $all_is_ok true;
  2226.     $link_for_database "";
  2227.     $close_db false;
  2228.     //if ($database_name != "admin_super") {
  2229.         // create a connection to the database
  2230.             $link_for_database "";
  2231.             //trigger_error("get_mysql_link_for_database($database_name, $admin_mysql_link, $link_for_database);");
  2232.  
  2233.             $not_used "";
  2234.             $link_for_database =get_mysql_link_for_database($database_name$not_used);
  2235. //            echo_net($link_for_database);
  2236.  
  2237.            $close_db true;
  2238.     //} else {
  2239.     //    $link_for_database = $admin_mysql_link;
  2240.     //}
  2241.  
  2242.     if ($all_is_ok)
  2243.         $all_is_ok mysql_execute_script($script_filename$link_for_database);
  2244.  
  2245. //    echo_net($link_for_database);
  2246.  
  2247. //       mysql_close($link_for_database);
  2248. //    echo_net($link_for_database." ENDED_PLOP");
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.     return $all_is_ok;
  2255. }
  2256.  
  2257. global $_3d6f_loc_extention_already_done;
  2258. $_3d6f_loc_extention_already_done ".already_made";
  2259.  
  2260.  
  2261. /**
  2262.  * For {@link run_db_directory}, make vars
  2263.  *
  2264.  * @param array $_PLICI_CFG 
  2265.  * @param string $_3d6f_loc_bd_director_name 
  2266.  * @param string $_3d6f_loc_extention_must_be_redone 
  2267.  * @param array $_3d6f_loc_directory_to_redo 
  2268.  * @param array $_3d6f_loc_accepted_extension 
  2269.  * @param string $_3d6f_loc_racine_web_path 
  2270.  * @param string $_3d6f_loc_bd_path 
  2271.  */
  2272. function getForRunDbDirectory($_PLICI_CFG&$_3d6f_loc_bd_director_name&$_3d6f_loc_extention_must_be_redone,
  2273.             &$_3d6f_loc_directory_to_redo&$_3d6f_loc_accepted_extension&$_3d6f_loc_racine_web_path,
  2274.             &$_3d6f_loc_bd_path{
  2275.  
  2276.     $_3d6f_loc_bd_director_name "/bd/";
  2277.     $_3d6f_loc_extention_must_be_redone ".to_redo";
  2278.     $_3d6f_loc_directory_to_redo  array('test_site'=>'redo''theme1com_site'=>'redo''theme2com_site'=>'redo');
  2279.     $_3d6f_loc_accepted_extension array('sql' => 'ok''php' => 'ok');
  2280.     $_3d6f_loc_racine_web_path $_PLICI_CFG['racine_web'];
  2281.     $_3d6f_loc_bd_path $_3d6f_loc_racine_web_path.$_3d6f_loc_bd_director_name;
  2282.  
  2283.  
  2284. }
  2285.  
  2286. /**
  2287.  * Run the database scripts on /db/
  2288.  *
  2289.  * @param array $_PLICI_CFG 
  2290.  * @param string $p_unique_database_to_load 
  2291.  * @param string $p_br_or_n 
  2292.  * @param bool $p_is_simulation 
  2293.  * @return bool TRUE on error
  2294.  */
  2295. function run_db_directory($_PLICI_CFG$p_unique_database_to_load ""$p_br_or_n "<br/>"$p_is_simulation false{
  2296.  
  2297.  
  2298.  
  2299.     if (isset($_PLICI_CFG['superadmin_databasename']&& $p_unique_database_to_load == $_PLICI_CFG['superadmin_databasename'])
  2300.         $p_unique_database_to_load "admin_super";
  2301.  
  2302.  
  2303.     global $_3d6f_loc_extention_already_done;
  2304.  
  2305.     $_3d6f_loc_bd_director_name "";
  2306.     $_3d6f_loc_extention_must_be_redone "";
  2307.     $_3d6f_loc_directory_to_redo "";
  2308.     $_3d6f_loc_accepted_extension "";
  2309.     $_3d6f_loc_racine_web_path "";
  2310.     $_3d6f_loc_bd_path "";
  2311.  
  2312.     $all_is_ok true;
  2313.  
  2314.     getForRunDbDirectory($_PLICI_CFG$_3d6f_loc_bd_director_name$_3d6f_loc_extention_must_be_redone,
  2315.     $_3d6f_loc_directory_to_redo,$_3d6f_loc_accepted_extension$_3d6f_loc_racine_web_path$_3d6f_loc_bd_path);
  2316.  
  2317.  
  2318.  
  2319. //    $_3d6f_loc_bd_director_name = "/bd/";
  2320. //    $_3d6f_loc_extention_must_be_redone = ".to_redo";
  2321. //    $_3d6f_loc_directory_to_redo  = array('test_site'=>'redo', 'theme1com_site'=>'redo', 'theme2com_site'=>'redo'/*, 'graphiste_site'=>'redo'*/);
  2322. //    $_3d6f_loc_accepted_extension = array('sql' => 'ok', 'php' => 'ok');
  2323.  
  2324.  
  2325.     //$_3d6f_loc_herit_begin = "_INHERIT_";
  2326.     //$_3d6f_loc_herit_begin_position = 6;
  2327.     //$_3d6f_loc_herit_begin_made = "_INHERITMADE_";
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337. //    //print_r($_SERVER['argv']);
  2338. //    foreach($_SERVER['argv'] as $_3d6f_loc_key => $_3d6f_loc_value)
  2339. //        $_SERVER['argv'][$_3d6f_loc_key] = trim($_3d6f_loc_value);
  2340. //
  2341. //    if (!isset($_SERVER['argv'][1]))
  2342. //        die() ;
  2343. //    if (!isset($_SERVER['argv'][2]))
  2344. //        die() ;
  2345.     /*
  2346.      *  on recoit en parametre le chemin racine : c:\racine_web
  2347.      *
  2348.      */
  2349.  
  2350.     if!ini_get('safe_mode') ) @set_time_limit(3600);
  2351.  
  2352.     //include('./../include/net_scandir.php');
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.     $_path_for_php_function_includes $_3d6f_loc_bd_path."_php_function_includes/";
  2374. /**
  2375.  * Include $_path_for_php_function_includes."_methods.php3"
  2376.  */
  2377. include_once($_path_for_php_function_includes."_methods.php3");
  2378.  
  2379.     echo("$p_br_or_n <strong>DB information :</strong>");
  2380.     echo ("$p_br_or_n File path for DB :".$_3d6f_loc_bd_path."");
  2381.     //echo ("liste des fichiers et repertoires<br/>");
  2382.  
  2383.     // si on demande que l'admin super il n'a pas besoin de faire l'héritage et comme on se connecte à l'admin_super
  2384.     // la BD peut ne pas exister et entrainer des soucis
  2385.     if ($p_unique_database_to_load != "admin_super"{
  2386.         plici_makeInherit($_PLICI_CFG$p_br_or_ntrue);
  2387.     }
  2388.  
  2389.     /*
  2390.      *
  2391.      *         Reelle partie de l'update database
  2392.      *
  2393.      */
  2394.     
  2395. //    die();
  2396.     $_3d6f_loc_sub_dir_and_files array();
  2397.     net_scandir($_3d6f_loc_bd_path$_3d6f_loc_sub_dir_and_files);
  2398.  
  2399.   // can have a order problem with the database then, it put the admin_super scripts in first.
  2400.   $new_array array();
  2401.   foreach($_3d6f_loc_sub_dir_and_files as $_3d6f_loc_key => $_3d6f_loc_value{
  2402.     if ($_3d6f_loc_value['parent_dir'== "admin_super"{
  2403.       array_push($new_array$_3d6f_loc_value);
  2404.     }
  2405.   }
  2406.   foreach($_3d6f_loc_sub_dir_and_files as $_3d6f_loc_key => $_3d6f_loc_value{
  2407.     if ($_3d6f_loc_value['parent_dir'!= "admin_super"{
  2408.       array_push($new_array$_3d6f_loc_value);
  2409.     }
  2410.   }
  2411.  
  2412.   $_3d6f_loc_sub_dir_and_files $new_array;
  2413.  
  2414.  
  2415. //  foreach($_3d6f_loc_sub_dir_and_files as $_3d6f_loc_key => $_3d6f_loc_value) {
  2416. //    if ($_3d6f_loc_key < 200)
  2417. //    echo($_3d6f_loc_value['current_path']."\n");
  2418. //  }
  2419.  
  2420.  
  2421. //  die();
  2422.  
  2423.  
  2424.  
  2425. //    $_tmp_to_not_used_can_be_bad =&
  2426. //    plici_mysql_connect($_PLICI_CFG['superadmin_hostname'], $_PLICI_CFG['superadmin_username'], $_PLICI_CFG['superadmin_password'], true);
  2427.  
  2428. //    echo_net("mysql_select_db(".$_PLICI_CFG['superadmin_databasename'].", ".$_3d6f_loc_id_sql_admin_super.")");
  2429. //    $_3d6f_loc_select_db_is_ok = mysql_select_db($_PLICI_CFG['superadmin_databasename'], $_tmp_to_not_used_can_be_bad);
  2430.     $tmp "";
  2431.     $_tmp_to_not_used_can_be_bad =get_mysql_link_for_database($_PLICI_CFG['superadmin_databasename']$tmp);
  2432.  
  2433.  
  2434. //    echo_net($_3d6f_loc_bd_path);
  2435. //    print_r_net($_3d6f_loc_sub_dir_and_files);
  2436.  
  2437.     $_3d6f_loc_array_cachedir_to_delete array();
  2438.  
  2439.  
  2440.     global $_3d6f_loc_force_run_db_directory_to_redo_all;
  2441.     $_3d6f_loc_force_run_db_directory_to_redo_all false;
  2442.  
  2443.     //echo("Legende : . = deja joue, S = sql a jouer, p = php a jouer<br/>");
  2444.     // on determine quelles scripts on doit jouer et sur quelle BD
  2445.     $_3d6f_loc_old_db_name "";
  2446.     $my_is_passed false;
  2447.     foreach($_3d6f_loc_sub_dir_and_files as $_3d6f_loc_key => $_3d6f_loc_value{
  2448.  
  2449.  
  2450.  
  2451.  
  2452.         if ($_3d6f_loc_value['type'== 'directory')
  2453.             $_3d6f_loc_last_directory $_3d6f_loc_value['current_path'];
  2454.  
  2455.  
  2456.          if (($_3d6f_loc_value['type'== 'directory' && $_3d6f_loc_value['name'== '_all_sites')
  2457.                  ||  $_3d6f_loc_value['parent_dir'== "_all_sites")
  2458.              continue;
  2459.  
  2460.         if ($_3d6f_loc_value['type'== 'directory' && $_3d6f_loc_value['name'== "my")
  2461.             $my_is_passed true;
  2462.  
  2463.         if ($_3d6f_loc_value['type'== 'directory' && $_3d6f_loc_value['parent_dir'== "my")    {
  2464.             /**
  2465.              * Make picture inherit
  2466.              * Copy the picture from the web_site Father (if there is one) to this child
  2467.              * Doesn't overwrite
  2468.              */
  2469.             $_3d6f_p_dbc_inherited_sitename "";
  2470.             get_mysql_link_for_database($_3d6f_loc_value['name']$_3d6f_p_dbc_inherited_sitename);
  2471.             
  2472.             $theme_directory "";
  2473.             if ($_3d6f_p_dbc_inherited_sitename != ""{
  2474.                 $theme_directory $_3d6f_loc_racine_web_path."/".PLICI_VIEW_SITES_FOR_PLICI_DIRECTORY.'/'.$_3d6f_p_dbc_inherited_sitename.'/';
  2475.                 if (!file_exists($theme_directory)) {
  2476.                     $theme_directory $_3d6f_loc_racine_web_path."/".PLICI_VIEW_SITES_MY_DIRECTORY."/".$_3d6f_p_dbc_inherited_sitename."/";
  2477.                     if (!file_exists($theme_directory)) 
  2478.                         $theme_directory "";
  2479.                 }
  2480.             }
  2481.  
  2482.             if ($theme_directory != ""{
  2483.                 $picture_files array();
  2484.                 $theme_picture_directory realpath($theme_directory."picture/")."/";
  2485.                 $dest_directory $_3d6f_loc_racine_web_path."/".PLICI_VIEW_SITES_MY_DIRECTORY."/".$_3d6f_loc_value['name']."/picture/";
  2486.                 net_scandir($theme_picture_directory$picture_files);
  2487.                 
  2488.                 $dest_directory realpath($dest_directory);
  2489.                 
  2490.                 echo("$p_br_or_n Start picture Inherit $p_br_or_n");
  2491.                 $picture_file_i 0;
  2492.                 // on evite de pusher des images à la racine car il manquerait un répertoire, ça fait désordre
  2493.                 if ($dest_directory != "" && $dest_directory != "/")
  2494.                 foreach($picture_files as $file_array{
  2495.                     $source_file $file_array['current_path'];
  2496.                     
  2497.                     
  2498.                     $dest_file $dest_directory."/".substr($file_array['current_path']strlen($theme_picture_directory));
  2499.                     if ($file_array['name'!= ".not_copy_this_directory")
  2500.                     if ($file_array['type'== 'directory' && !file_exists($dest_file)) {
  2501.                         @plici_mkdir($dest_file);
  2502.                         echo("D");
  2503.                     else if (!file_exists($dest_file)) {
  2504.                         copy($source_file$dest_file);
  2505.                         echo("F");
  2506.                     else {
  2507.                         echo("=");
  2508.                     }
  2509.                     $picture_file_i++;
  2510.                     if ($picture_file_i%40==0){
  2511.                         echo($p_br_or_n);
  2512.                     }
  2513.                 }
  2514.                 echo("$p_br_or_n End picture Inherit");
  2515.             }            
  2516.         }
  2517.             
  2518.             
  2519.         if (!$my_is_passed && $_3d6f_loc_value['parent_dir'!= "admin_super")
  2520.             continue;
  2521.  
  2522.  
  2523.         if ($p_unique_database_to_load != "" && $p_unique_database_to_load != $_3d6f_loc_value['parent_dir'])
  2524.             continue;
  2525.  
  2526.         flush();
  2527.  
  2528.         if (isset($_3d6f_loc_value['extension']&& isset($_3d6f_loc_accepted_extension[$_3d6f_loc_value['extension']])) {
  2529.  
  2530.  
  2531.             // un fichier sql ou php
  2532.             $_3d6f_loc_current_file_extension strtoupper($_3d6f_loc_value['extension']);
  2533.  
  2534.  
  2535.  
  2536.             if ($_3d6f_loc_old_db_name != $_3d6f_loc_value['parent_dir')
  2537.                 echo("$p_br_or_n <strong>Scripts for database '".$_3d6f_loc_value['parent_dir']."' :</strong>");
  2538.  
  2539.             $_3d6f_loc_file_already_made false;
  2540.             if (isset($_3d6f_loc_sub_dir_and_files[$_3d6f_loc_key+1])) {
  2541.                 // ce fichier a-t-il deja été joué ?
  2542. //                $a = $_3d6f_loc_value['current_path'].$_3d6f_loc_extention_already_done;
  2543. //                $b = $_3d6f_loc_sub_dir_and_files[$_3d6f_loc_key+1]['current_path'];
  2544. //                echo_net("comparaison de $a et $b");
  2545.                 if ($_3d6f_loc_value['current_path'].$_3d6f_loc_extention_already_done == $_3d6f_loc_sub_dir_and_files[$_3d6f_loc_key+1]['current_path']){
  2546.                     $_3d6f_loc_file_already_made true;
  2547.                     //echo("<br/>Already made");
  2548.                     //echo("($_3d6f_loc_current_file_extension)=> DEJA joue : ".$_3d6f_loc_value['name']." (".$_3d6f_loc_value['parent_dir'].")<br/>");
  2549.                 }
  2550.             }
  2551.             if (!$_3d6f_loc_file_already_made && !$p_is_simulation{
  2552.  
  2553.  
  2554.                 // on doit jouer le fichier SQL ou PHP
  2555.                 //echo("*Fichier a jouer: ".$_3d6f_loc_value['name']." (".$_3d6f_loc_value['parent_dir'].")<br/>");
  2556.  
  2557.                 // on determine si on doit selectionne une database ou pas
  2558.                 $_3d6f_loc_select_database true;
  2559.                 if ($_3d6f_loc_value['extension'== 'sql')
  2560.                     if ((substr($_3d6f_loc_value['name']01== "0"||
  2561.                         (substr($_3d6f_loc_value['name']01== "1"))
  2562.                         $_3d6f_loc_select_database false;
  2563.  
  2564.  
  2565.  
  2566.                 if (isset($_3d6f_loc_directory_to_redo[$_3d6f_loc_value['parent_dir']]))
  2567.                     $_3d6f_loc_filename_already $_3d6f_loc_value['current_path'].$_3d6f_loc_extention_already_done.$_3d6f_loc_extention_must_be_redone;
  2568.                 else
  2569.                     $_3d6f_loc_filename_already $_3d6f_loc_value['current_path'].$_3d6f_loc_extention_already_done;
  2570.                 //@unlink($_3d6f_loc_filename_already);
  2571.  
  2572.                 $temp_file_name $_3d6f_loc_value['current_path'].$_3d6f_loc_extention_already_done.$_3d6f_loc_extention_must_be_redone;
  2573.                 if (file_exists($temp_file_name))
  2574.                     @unlink($temp_file_name);
  2575.                 $temp_file_name $_3d6f_loc_value['current_path'].$_3d6f_loc_extention_already_done;
  2576.                 if (file_exists($temp_file_name))
  2577.                     @unlink($temp_file_name);
  2578.  
  2579.                 $_3d6f_loc_redirect_errors $_3d6f_loc_filename_already;
  2580.  
  2581.                     flush();
  2582.  
  2583.                 $_3d6f_loc_errors "";
  2584.                 if ($_3d6f_loc_value['extension'== 'sql'{
  2585.                   echo("$p_br_or_n Loading : ".$_3d6f_loc_value['name']."");
  2586.                     if ($_3d6f_loc_select_database{
  2587.  
  2588.  
  2589.  
  2590.                         if (mysql_exec_script_and_search_login_from_admin(
  2591.                                 $_3d6f_loc_value['parent_dir']$_3d6f_loc_value['current_path'])) {
  2592.                                 $_3d6f_loc_errors "";
  2593.                                 touch($_3d6f_loc_redirect_errors);
  2594.                         else {
  2595.                                 $_3d6f_loc_errors "$p_br_or_n Error : mysql_exec_script_and_search_login_from_admin";
  2596.                                 $all_is_ok false;
  2597.                         }
  2598.                         //shell_exec("\"".$_3d6f_loc_mysql_path."mysql.exe\"  -uroot -p".$_3d6f_loc_root_password." -D ".$_3d6f_loc_value['parent_dir']."  <  ".$_3d6f_loc_value['current_path'].$_3d6f_loc_redirect_errors);
  2599.                     else
  2600.                         touch($_3d6f_loc_redirect_errors);// devenu inutile : shell_exec("\"".$_3d6f_loc_mysql_path."mysql.exe\" -uroot -p".$_3d6f_loc_root_password."  <  ".$_3d6f_loc_value['current_path'].$_3d6f_loc_redirect_errors);
  2601.  
  2602.  
  2603.  
  2604.                     //$_3d6f_loc_errors = file_get_contents($_3d6f_loc_filename_already);
  2605.  
  2606.                     $_3d6f_loc_array_cachedir_to_delete[$_3d6f_loc_value['parent_dir']] "delete_cache";
  2607.  
  2608.                 else if ($_3d6f_loc_value['extension'== 'php'{
  2609.  
  2610.                      echo("$p_br_or_n Loading : ".$_3d6f_loc_value['name']."");
  2611.  
  2612.                     // on met en place une connexion de base de donnée vers la bd concernée
  2613.                     $link_for_database "";
  2614.                     $_3d6f_p_dbc_inherited_sitename "";
  2615.                     $link_for_database =get_mysql_link_for_database($_3d6f_loc_value['parent_dir']$_3d6f_p_dbc_inherited_sitename);
  2616.  
  2617. //                    mysql_connect("localhost", "root", $_3d6f_loc_root_password);
  2618. //                    $_3d6f_loc_select_db_is_ok = mysql_select_db($_3d6f_loc_value['parent_dir']);
  2619. //                    if (!$_3d6f_loc_select_db_is_ok)
  2620. //                        echo("$p_br_or_n erreur de connexion sur ".$_3d6f_loc_value['parent_dir']."$p_br_or_n");
  2621.  
  2622.                     flush();
  2623.  
  2624.                     ob_start();
  2625. /**
  2626.  * Include $_3d6f_loc_value['current_path']
  2627.  */
  2628. include($_3d6f_loc_value['current_path']);
  2629.                     $_3d6f_loc_errors ob_get_contents();
  2630.                     flush();
  2631.                     ob_end_clean();
  2632.                     flush();
  2633.                     if (trim($_3d6f_loc_errors=="")
  2634.                         touch($_3d6f_loc_filename_already);
  2635.  
  2636.                     $_3d6f_loc_array_cachedir_to_delete[$_3d6f_loc_value['parent_dir']] "delete_cache";
  2637.  
  2638.                     
  2639.                     if ($_3d6f_loc_value['parent_dir'!= "admin_super")
  2640.                     ;
  2641. //trigger_error("Changes for ppool normaly close");//                       mysql_close($link_for_database);
  2642.  
  2643.                 }
  2644.  
  2645.  
  2646.                 if (trim($_3d6f_loc_errors!=""{
  2647.                     echo("$p_br_or_n ($_3d6f_loc_current_file_extension)=> !!BAD!!  ".$_3d6f_loc_value['name']." (".$_3d6f_loc_value['parent_dir'].")$p_br_or_n");
  2648.                     echo(">>>>>".trim($_3d6f_loc_errors)."$p_br_or_n $p_br_or_n");
  2649.                     $all_is_ok false;
  2650.  
  2651.                 }
  2652.  
  2653.             else if (!$_3d6f_loc_file_already_made && $p_is_simulation{
  2654.                     echo("$p_br_or_n Will be done : ".$_3d6f_loc_value['name']."</strong>");
  2655.             }
  2656.             //echo("  redo_update :".($_3d6f_loc_force_run_db_directory_to_redo_all?'true':'false'));
  2657.  
  2658.  
  2659.             $_3d6f_loc_old_db_name $_3d6f_loc_value['parent_dir'];
  2660.         else if (isset($_3d6f_loc_value['extension']&& (($_3d6f_loc_value['extension'== substr($_3d6f_loc_extention_already_done1)) ||
  2661.                 ($_3d6f_loc_value['extension'== substr($_3d6f_loc_extention_must_be_redone1)))) {
  2662.  
  2663.             // un fichier non sql
  2664.             // on verifie qu'il y est bien son homologue
  2665.             $_3d6f_loc_is_already_done false;
  2666.             $_3d6f_loc_is_re_done false;
  2667.  
  2668.             $_3d6f_loc_truncated1 str_replace($_3d6f_loc_extention_already_done''$_3d6f_loc_value['name']);
  2669.             $_3d6f_loc_truncated str_replace($_3d6f_loc_extention_must_be_redone''$_3d6f_loc_truncated1);
  2670.             $_3d6f_loc_is_already_done ($_3d6f_loc_truncated != $_3d6f_loc_value['name']);
  2671.             $_3d6f_loc_is_re_done     ($_3d6f_loc_truncated != $_3d6f_loc_truncated1);
  2672.  
  2673.             if (($_3d6f_loc_is_already_done|| ($_3d6f_loc_is_already_done && $_3d6f_loc_is_re_done)) {
  2674.                 // on a bien un fichier qu'on a généré
  2675.                 // on cherche s'il a un équivalent
  2676.  
  2677.                 $_3d6f_loc_is_alone true;
  2678.                 if (isset($_3d6f_loc_sub_dir_and_files[$_3d6f_loc_key-1])) {
  2679.                      $_3d6f_loc_is_alone ($_3d6f_loc_sub_dir_and_files[$_3d6f_loc_key-1]['name'!= $_3d6f_loc_truncated);
  2680.                 }
  2681.                 if ($_3d6f_loc_is_alone{
  2682.                     @unlink($_3d6f_loc_value['current_path']);
  2683.                     echo("$p_br_or_n => CLEANING ".$_3d6f_loc_value['name']." (".$_3d6f_loc_value['parent_dir'].")$p_br_or_n ");
  2684.                 }
  2685.  
  2686.             }
  2687.  
  2688.  
  2689.  
  2690.         }
  2691.  
  2692.         //mysql_close($_3d6f_loc_id_sql_admin_super);
  2693.  
  2694.     }
  2695.  
  2696.  
  2697.  
  2698.     //$_3d6f_loc_directory_to_redo  = array('test_site'=>'redo', 'theme1com_site'=>'redo'/*, 'graphiste_site'=>'redo'*/);
  2699.     //
  2700.     // Il faut vider le caches des sites qui ont joué un script PHP ou SQL
  2701.     //
  2702.  
  2703.  
  2704.     if (!$p_is_simulation)
  2705.     foreach($_3d6f_loc_array_cachedir_to_delete as $key=>$value{
  2706.         deleteCacheForWebSite($key$_3d6f_loc_racine_web_path);
  2707.     }
  2708.  
  2709.  
  2710.     // @DONE : ne traiter que les fichiers sql
  2711.  
  2712.     // @DONE : lire le fichier SQL et le jouer sur la bonne BD
  2713.     // @DONE : creer le fichier de deja joué
  2714.     // @DONE : test_site ne doit pas creer de fichier indiquant que la requete a été jouée
  2715.  
  2716.  
  2717.     // on met a jour les le fichier pour les noms de domaine (urlrewriting)
  2718. //    echo("$p_br_or_n -> Generate the Url Rewriting htaccess $p_br_or_n ");
  2719. //require_once('internal_components/common/databaseconnect/databaseconnect.class.php');
  2720. //    $object_databaseconnet = new Databaseconnect(true);
  2721. //    $object_databaseconnet->xGenerateUrlRewriting($_3d6f_loc_id_sql_admin_super);
  2722.  
  2723.  
  2724.     echo($p_br_or_n);
  2725.     flush();
  2726.  
  2727.  
  2728.     // ATTENTION :    @mysql_close($_3d6f_loc_id_sql_admin_super);
  2729.     //                En fait il ne faut pas closer cette connexion SQL
  2730.     //                car comme on ne demande pas une connexion nouvelle dans le plic_mysql_connect pour executer les requêtes en admin
  2731.     //                ça peut utiliser la connexion actuelle de l'admin.
  2732.     //                car ce sont les meme login, pass, host (et c'est logique).
  2733.     //                mais si on ferme, ça ferme la connexion pour les autres requêtes (le cas est visible dans la mise à jour PLICI
  2734.     //                par diff)
  2735.  
  2736.  
  2737.  
  2738.     // on fait un test de verification de propagation de script
  2739.     //
  2740.     echo("All is ok : ".($all_is_ok?"true":"false")."\n");
  2741.     echo("Is Simulating : ".($p_is_simulation?"true":"false")."\n");
  2742.     echo("Must redo update : ".($_3d6f_loc_force_run_db_directory_to_redo_all?"true":"false")."\n");
  2743.  
  2744.     if($all_is_ok && !$p_is_simulation && $_3d6f_loc_force_run_db_directory_to_redo_all{
  2745.         return run_db_directory($_PLICI_CFG$p_unique_database_to_load$p_br_or_n$p_is_simulation);
  2746.     }
  2747.  
  2748.  
  2749.     return $all_is_ok;
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758. }
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774. /**
  2775.  * For the {@link run_db_directory}
  2776.  *
  2777.  * @param array $_PLICI_CFG 
  2778.  * @param string $p_br_or_n 
  2779.  * @param bool $echo 
  2780.  * @return bool TRUE on error
  2781.  */
  2782. function plici_makeInherit($_PLICI_CFG$p_br_or_n$echo false{
  2783.  
  2784.     $_3d6f_loc_sub_dir_and_files array();
  2785.  
  2786.     $_3d6f_loc_bd_director_name "";
  2787.     $_3d6f_loc_extention_must_be_redone "";
  2788.     $_3d6f_loc_directory_to_redo "";
  2789.     $_3d6f_loc_accepted_extension "";
  2790.     $_3d6f_loc_racine_web_path "";
  2791.     $_3d6f_loc_bd_path "";
  2792.  
  2793.     
  2794.     getForRunDbDirectory($_PLICI_CFG$_3d6f_loc_bd_director_name$_3d6f_loc_extention_must_be_redone,
  2795.     $_3d6f_loc_directory_to_redo,$_3d6f_loc_accepted_extension$_3d6f_loc_racine_web_path$_3d6f_loc_bd_path);
  2796.     /*
  2797.      *
  2798.      *         partie de la gestion de l'héritage
  2799.      *
  2800.      */
  2801.     global $_PLICI_CFG;
  2802.  
  2803.     $_3d6f_loc_id_sql_admin_super =
  2804.     plici_mysql_connect($_PLICI_CFG['superadmin_hostname']$_PLICI_CFG['superadmin_username']$_PLICI_CFG['superadmin_password']);
  2805.  
  2806. //    echo_net("mysql_select_db(".$_PLICI_CFG['superadmin_databasename'].", ".$_3d6f_loc_id_sql_admin_super.")");
  2807.     $_3d6f_loc_select_db_is_ok mysql_select_db($_PLICI_CFG['superadmin_databasename']$_3d6f_loc_id_sql_admin_super);
  2808.  
  2809.  
  2810.     $_3d6f_loc_heritage_finded false;
  2811.  
  2812.     $all_is_ok true;
  2813.  
  2814.  
  2815.  
  2816.     if ($echoecho("$p_br_or_n $p_br_or_n<strong>Script inherited :</strong>$p_br_or_n");
  2817.  
  2818.  
  2819.             $_3d6f_loc_sub_dir_and_files array();
  2820.  
  2821.             //echo_net($_3d6f_loc_bd_path);
  2822.  
  2823.             net_scandir($_3d6f_loc_bd_path$_3d6f_loc_sub_dir_and_files);
  2824.  
  2825.             //trigger_error(print_r($_3d6f_loc_sub_dir_and_files, true));
  2826.  
  2827.             //$_3d6f_loc_herit_begin_len = strlen($_3d6f_loc_herit_begin);
  2828.  
  2829.             // Mise en place du système d'héritage des _all_sites et des thèmes
  2830.  
  2831.             $inherit_files array(
  2832.                                     '_all_sites' => array(),
  2833.                                     '_all_sites_directory_made' => array(),
  2834.                                     'theme_made' => array(),
  2835.                                     );
  2836.  
  2837.             $inherit_all_sites_started false;
  2838.  
  2839.             $_3d6f_loc_last_directory "";
  2840.  
  2841.             $my_is_passed PLICI_FOR_PLICI_DIRECTORY;
  2842.  
  2843.             $for_new_line_of_point 0;
  2844.             foreach($_3d6f_loc_sub_dir_and_files as $_3d6f_loc_key => $_3d6f_loc_value{
  2845.  
  2846.  
  2847.  
  2848.                     if ($_3d6f_loc_value['type'== 'directory' && $_3d6f_loc_value['name'== "my")
  2849.                         $my_is_passed PLICI_MY_DIRECTORY;
  2850.  
  2851.  
  2852.  
  2853.                     if ($_3d6f_loc_value['type'== 'directory')
  2854.                         $_3d6f_loc_last_directory $_3d6f_loc_value['current_path'];
  2855.  
  2856.                     if (isset($_3d6f_loc_value['extension']&& isset($_3d6f_loc_accepted_extension[$_3d6f_loc_value['extension']])) {
  2857.  
  2858.  
  2859.                            /*
  2860.                             * Gestion de l'héritage qui vient de _all_sites
  2861.                             *
  2862.                             */
  2863.  
  2864.                            if ($_3d6f_loc_value['parent_dir'== '_all_sites'{
  2865.  
  2866.                                    // on remet à zéro si on entre dans '_all_sites'
  2867.         //                           if ($inherit_all_sites_started == false)
  2868.         //                               $inherit_files['_all_sites'] = array();
  2869.                                    // il s'agit d'un script qui va être répercuté sur tous les autres sites
  2870.                                    $inherit_all_sites_started true;
  2871.                                    // on stock le fichier qui est dans _all_sites
  2872.                                    array_push($inherit_files['_all_sites']$_3d6f_loc_value);
  2873.                            else if ($_3d6f_loc_value['parent_dir'!= "admin_super" && $_3d6f_loc_value['parent_dir'!= "admin_plici"){
  2874.  
  2875.                                    // si le répertoire n'a pas déjà été fait
  2876.                                    if (!isset($inherit_files['_all_sites_directory_made'][$my_is_passed.$_3d6f_loc_value['parent_dir']])){
  2877.                                        // dépose les fichier de _all_sites
  2878.  
  2879.                                        foreach($inherit_files['_all_sites'as $_3d6f_loc_value_all_sites{
  2880.                                            // on doit écrire les fichiers de _all_sites
  2881.                                            $source $_3d6f_loc_value_all_sites['current_path'];
  2882.                                            $dest   $_3d6f_loc_last_directory."/".$_3d6f_loc_value_all_sites['name']."_inherit.".$_3d6f_loc_value_all_sites['extension'];
  2883.                                         $dest_orig   $_3d6f_loc_last_directory."/".$_3d6f_loc_value_all_sites['name'];
  2884.                                         // on teste si le fichier original n'existe pas déjà (sans extension modifié)
  2885.                                         if (!file_exists($dest_orig)/* && !file_exists($dest)*/{
  2886.                                             if (!copy($source$dest)) {
  2887.                                                 echo("$p_br_or_n !BADCopy ".$_3d6f_loc_value_all_sites['name']." to ".$_3d6f_loc_value['parent_dir']);
  2888.                                                 $all_is_ok false;
  2889.                                             else {
  2890.                                                 $for_new_line_of_point++;
  2891.                                                 if ($echoecho(".");
  2892.                                                 if ($echo && $for_new_line_of_point%15==0echo(" ");
  2893.                                                                                                 //echo("$p_br_or_n OK Copy ".$_3d6f_loc_value_all_sites['name']." to ".$_3d6f_loc_value['parent_dir']);
  2894.                                                 $_3d6f_loc_heritage_finded true;
  2895.                                             }
  2896.                                         }
  2897.                                        }
  2898.  
  2899.                                        $inherit_files['_all_sites_directory_made'][$my_is_passed.$_3d6f_loc_value['parent_dir']] "made";
  2900.                                    }
  2901.  
  2902.                                    $inherit_all_sites_started false;
  2903.                            }
  2904.  
  2905.                            /*
  2906.                             * Gestion de l'héritage en fonction des thèmes
  2907.                             *
  2908.                             */
  2909.  
  2910.                                //@DONE : héritage de thème j'ai un souci car ca copie TOUS LES FICHIERS
  2911.                                //            - en fait je ne copie pas si le même nom de fichier existe déjà
  2912.  
  2913.                               //if ($_3d6f_loc_value['parent_dir'] != "admin_super" && $_3d6f_loc_value['parent_dir'] != "admin_plici")
  2914.  
  2915. //                              if ($echo) echo("\n my_passed : $my_is_passed\n exist : ".$_3d6f_loc_racine_web_path.$_3d6f_loc_bd_director_name.PLICI_BD_FOR_PLICI_DIRECTORY."/".$_3d6f_loc_value['parent_dir']."/"."\n");
  2916.  
  2917.                             // la condition evite que pour un site dans MY qui a le même nom qu'un theme de for_plici
  2918.                             // on a envoi ses propres scripts vers les autres themes
  2919.                             // enfin dans notre cas, evite que un script dans /my/theme1com soit envoyé vers
  2920.                             // tous les sites qui en heritent
  2921.                             if (($my_is_passed != PLICI_MY_DIRECTORY||
  2922.                                         ($my_is_passed == PLICI_MY_DIRECTORY &&
  2923.                                             !file_exists($_3d6f_loc_racine_web_path.$_3d6f_loc_bd_director_name.PLICI_MY_DIRECTORY."/".$_3d6f_loc_value['parent_dir']."/"))
  2924.                                     )
  2925.  
  2926.                               {
  2927.                                   // on charge à partir de la database les sites vers lesquels on doit copier les scripts
  2928.  
  2929.                                 if (!isset($inherit_files['theme_made'][$_3d6f_loc_value['parent_dir']])
  2930.                                 {
  2931.  
  2932.                                     $_3d6f_loc_request "select dbc_dbname from databaseconnect
  2933.                                                 where dbc_inherited_sitename <> 'ALIAS' and    dbc_inherited_sitename = '%s' ;";
  2934.                                     $req_temp sprintf($_3d6f_loc_request$_3d6f_loc_value['parent_dir']$_3d6f_loc_value['parent_dir']);
  2935.                                     //echo_net($req_temp);
  2936.                                     $_3d6f_loc_ressource mysql_query($req_temp$_3d6f_loc_id_sql_admin_super);
  2937.                                     $inherit_files['theme_made'][$_3d6f_loc_value['parent_dir']] array();
  2938.                                     while ((!$_3d6f_loc_ressource&& $_3d6f_loc_row mysql_fetch_row($_3d6f_loc_ressource))) {
  2939.                                         array_push($inherit_files['theme_made'][$_3d6f_loc_value['parent_dir']],
  2940.                                                 $_3d6f_loc_row[0]
  2941.                                                 );
  2942.                                     }
  2943.                                     //print_r($inherit_files['theme_made'][$_3d6f_loc_value['parent_dir']]);
  2944.  
  2945.                                 }
  2946.                                 foreach($inherit_files['theme_made'][$_3d6f_loc_value['parent_dir']] as $_3d6f_loc_value_theme{
  2947.                                            // on doit écrire les fichiers du nouveau thème
  2948.                                            $source $_3d6f_loc_value['current_path'];
  2949.                                            $dest   $_3d6f_loc_racine_web_path.$_3d6f_loc_bd_director_name.PLICI_MY_DIRECTORY."/".$_3d6f_loc_value_theme."/".$_3d6f_loc_value['name']."_inherit.".$_3d6f_loc_value['extension'];
  2950.                                         $dest_orig   $_3d6f_loc_racine_web_path.$_3d6f_loc_bd_director_name.PLICI_MY_DIRECTORY."/".$_3d6f_loc_value_theme."/".$_3d6f_loc_value['name'];
  2951.                                         if (!file_exists($dest_orig)
  2952.                                             /*&& !file_exists($dest)*/
  2953.                                             && substr($_3d6f_loc_value['name']012 )!= "3_0000_data_"
  2954.                                             {
  2955.                                             if (!copy($source$dest)) {
  2956.                                                  echo("$p_br_or_n !BADCopy ".$_3d6f_loc_value['name']." to ".$_3d6f_loc_value_theme);
  2957.                                                 $all_is_ok false;
  2958.                                             else {
  2959.                                                 $for_new_line_of_point++;
  2960.                                                 if ($echoecho(".");
  2961.                                                 if ($echo && $for_new_line_of_point%15==0echo(" ");
  2962.  
  2963.                                                 $_3d6f_loc_heritage_finded true;
  2964.                                                 //echo("$p_br_or_n OK Copy ".$_3d6f_loc_value['name']." to ".$_3d6f_loc_value_theme);
  2965.                                             }
  2966.                                         }
  2967.                                 }
  2968.                               }
  2969.  
  2970.                        }
  2971.             }
  2972.     if ($_3d6f_loc_heritage_finded == false{
  2973.         if ($echoecho("$p_br_or_n Nothing to do");
  2974.         return $_3d6f_loc_heritage_finded;
  2975.     else {
  2976.         if ($echoecho("$p_br_or_n Copy done");
  2977.         return $_3d6f_loc_heritage_finded;
  2978.     }
  2979.  
  2980.     //die();
  2981.     //echo("<br/>");
  2982.  
  2983.  
  2984.  
  2985.  
  2986.     // CLOSE THE FIRST CONNECTION
  2987.     //mysql_close($_3d6f_loc_id_sql_admin_super);
  2988.  
  2989. }
  2990.  
  2991.  
  2992.     /**
  2993.      * Translate a RSS to an Array
  2994.      *
  2995.      * @param string $url 
  2996.      * @return array 
  2997.      */
  2998.     function plici_rssToArray($url{
  2999.  
  3000.         global $g_object_siteinformation;
  3001.         if(!isset($g_object_siteinformation)) {
  3002.             trigger_error("plici_rssToArray : Error site Information not exist");
  3003.             return;
  3004.         }
  3005.  
  3006.  
  3007. /**
  3008.  * Include 'external_components/magpierss/rss_fetch.inc'
  3009.  */
  3010. require_once('external_components/magpierss/rss_fetch.inc');
  3011.  
  3012.         /*
  3013.          * CONSTANTS - redefine these in your script to change the
  3014.          * behaviour of fetch_rss() currently, most options effect the cache
  3015.          *
  3016.          * MAGPIE_CACHE_ON - Should Magpie cache parsed RSS objects?
  3017.          * For me a built in cache was essential to creating a "PHP-like"
  3018.          * feel to Magpie, see rss_cache.inc for rationale
  3019.          *
  3020.          *
  3021.          * MAGPIE_CACHE_DIR - Where should Magpie cache parsed RSS objects?
  3022.          * This should be a location that the webserver can write to.   If this
  3023.          * directory does not already exist Mapie will try to be smart and create
  3024.          * it.  This will often fail for permissions reasons.
  3025.          *
  3026.          *
  3027.          * MAGPIE_CACHE_AGE - How long to store cached RSS objects? In seconds.
  3028.          *
  3029.          *
  3030.          * MAGPIE_CACHE_FRESH_ONLY - If remote fetch fails, throw error
  3031.          * instead of returning stale object?
  3032.          *
  3033.          * MAGPIE_DEBUG - Display debugging notices?
  3034.          *
  3035.         */
  3036.  
  3037.         if (!defined('MAGPIE_CACHE_DIR'))
  3038.             define('MAGPIE_CACHE_DIR'$g_object_siteinformation->getTmpFilePath(true).'/magpierss_cache');
  3039.  
  3040.         $rss fetch_rss($url);
  3041.         $array_result array();
  3042.  
  3043.  
  3044.         $array_result $rss->channel;
  3045.         $array_result['items'$rss->items;
  3046.  
  3047.         return $array_result;
  3048.     }
  3049.  
  3050.  
  3051. /**
  3052.  * Returns true if the given file/dir has been made writable (or is already
  3053.  * writable).
  3054.  *
  3055.  * @param string $file 
  3056.  * @return bool 
  3057.  */
  3058. function plici_make_writable($file)
  3059. {
  3060.     $ret_val false;
  3061.     if(is_file($file|| is_dir($file))
  3062.     {
  3063.         if(is_writable($file))
  3064.         {
  3065.             $ret_val true;
  3066.         }
  3067.         else
  3068.         {
  3069.             $original_fileperms fileperms($file);
  3070.  
  3071.             // add user writable permission
  3072.             $new_fileperms $original_fileperms 0x0080;
  3073.             @chmod($file$new_fileperms);
  3074.  
  3075.             if(is_writable($file))
  3076.             {
  3077.                 $ret_val true;
  3078.             }
  3079.             else
  3080.             {
  3081.                 // add group writable permission
  3082.                 $new_fileperms $original_fileperms 0x0010;
  3083.                 @chmod($file$new_fileperms);
  3084.  
  3085.                 if(is_writable($file))
  3086.                 {
  3087.                     $ret_val true;
  3088.                 }
  3089.                 else
  3090.                 {
  3091.                     // add world writable permission
  3092.                     $new_fileperms $original_fileperms 0x0002;
  3093.                     @chmod($file$new_fileperms);
  3094.  
  3095.                     if(is_writable($file))
  3096.                     {
  3097.                         $ret_val true;
  3098.                     }
  3099.                 }
  3100.             }
  3101.         }
  3102.     }
  3103.     if (!$ret_val)
  3104.         echo("File that can't be writtent : ".$file."<br/>");
  3105.     return $ret_val;
  3106. }
  3107.  
  3108. /**
  3109.  * Function roud price
  3110.  *
  3111.  * @param float $p_price 
  3112.  * @return float 
  3113.  */
  3114. function plici_round_price($p_price)
  3115. {
  3116.     return round($p_price2);
  3117. }
  3118.  
  3119.  
  3120. /**
  3121.  * Returns true if the given file/dir has been made writable (or is already
  3122.  * writable).
  3123.  *
  3124.  * @param string $file 
  3125.  * @return bool 
  3126.  */
  3127. function make_writable($file)
  3128. {
  3129.     $ret_val false;
  3130.     if(is_file($file|| is_dir($file))
  3131.     {
  3132.         if(is_writable($file))
  3133.         {
  3134.             $ret_val true;
  3135.         }
  3136.         else
  3137.         {
  3138.             $original_fileperms fileperms($file);
  3139.  
  3140.             // add user writable permission
  3141.             $new_fileperms $original_fileperms 0x0080;
  3142.             @chmod($file$new_fileperms);
  3143.  
  3144.             if(is_writable($file))
  3145.             {
  3146.                 $ret_val true;
  3147.             }
  3148.             else
  3149.             {
  3150.                 // add group writable permission
  3151.                 $new_fileperms $original_fileperms 0x0010;
  3152.                 @chmod($file$new_fileperms);
  3153.                 
  3154.                 if(is_writable($file))
  3155.                 {
  3156.                     $ret_val true;
  3157.                 }
  3158.                 else
  3159.                 {
  3160.                     // add world writable permission
  3161.                     $new_fileperms $original_fileperms 0x0002;
  3162.                     @chmod($file$new_fileperms);
  3163.  
  3164.                     if(is_writable($file))
  3165.                     {
  3166.                         $ret_val true;
  3167.                     }
  3168.                 }
  3169.             }
  3170.         }
  3171.     }
  3172.     if (!$ret_val)
  3173.         trigger_error("make_writable => File that can't be writtent : ".$file."<br/>\n");
  3174.     return $ret_val;
  3175. }
  3176.  
  3177. /**
  3178.  * Recursive make writable
  3179.  *
  3180.  * @param string $start_file 
  3181.  * @return bool 
  3182.  */
  3183. function recursive_make_writable($start_file)
  3184. {
  3185.     $ret_val make_writable($start_file);
  3186.  
  3187.     if($ret_val && is_dir($start_file)  && !is_link($start_file))
  3188.     {
  3189.         // PHP 4 alternative to scandir()
  3190.         $files array();
  3191.         $dh opendir($start_file);
  3192.         $filename readdir($dh);
  3193.         
  3194.         while(!empty($filename))
  3195.         {
  3196.             if($filename != '.' && $filename != '..')
  3197.             {
  3198.                 $files[$filename;
  3199.             }
  3200.  
  3201.             $filename readdir($dh);
  3202.         }
  3203.  
  3204.         foreach($files as $file)
  3205.         {
  3206.             if(is_dir($start_file '/' $file&& $file != '.svn')
  3207.             $ret_val recursive_make_writable($start_file '/' $file);
  3208.  
  3209.             if(!$ret_val)
  3210.             {
  3211.                 break;
  3212.             }
  3213.         }
  3214.     }
  3215.  
  3216.     return $ret_val;
  3217. }
  3218. /**
  3219.  * Recursibly test if is writable
  3220.  *
  3221.  * @param string $start_file 
  3222.  * @return bool 
  3223.  */
  3224. function recursive_is_writable($start_file)
  3225. {
  3226.     $ret_val is_writable($start_file);
  3227.  
  3228.     if($ret_val && is_dir($start_file&& !is_link($start_file))
  3229.     {
  3230.         // PHP 4 alternative to scandir()
  3231.         $files array();
  3232.         $dh opendir($start_file);
  3233.         $filename readdir($dh);
  3234.         while(!empty($filename))
  3235.         {
  3236.             if($filename != '.' && $filename != '..')
  3237.             {
  3238.                 $files[$filename;
  3239.             }
  3240.  
  3241.             $filename readdir($dh);
  3242.         }
  3243.  
  3244.         foreach($files as $file)
  3245.         {
  3246.             $ret_val recursive_is_writable($start_file '/' $file);
  3247.  
  3248.             if(!$ret_val)
  3249.             {
  3250.                 break;
  3251.             }
  3252.         }
  3253.     }
  3254.  
  3255.     return $ret_val;
  3256. }
  3257.  
  3258.  
  3259. /**
  3260.  * Make a directory with path ending by a slash or not
  3261.  *
  3262.  * @param string $pathname 
  3263.  * @return bool TRUE on success or FALSE on failure.
  3264.  */
  3265. function plici_mkdir($pathname{
  3266.     $pathname preg_replace("|(.+)[/\\\\]$|is""\\1"$pathname);
  3267. //    echo_net($pathname);
  3268.     return mkdir($pathname);
  3269. }
  3270.  
  3271. /**
  3272.  * Print an image from t_graphic by smarty
  3273.  *
  3274.  * @access private
  3275.  * @param array $params 
  3276.  * @param Smarty_custom $smarty 
  3277.  * @return string 
  3278.  */
  3279. function x_smarty_function_net_img($params&$smarty)
  3280. {
  3281.     $id getFromArray('id'$params'');
  3282.     if ($id == '')
  3283.         return "";
  3284.  
  3285.     $notag getFromArray('notag'$params'');
  3286.  
  3287.  
  3288.     global $g_object_loader;
  3289.     $o_tgraphic =$g_object_loader->getTGraphic();
  3290.     $plici_net_img $o_tgraphic->initAndLoadNetImgArray();
  3291.     
  3292.     if (isset($plici_net_img[$id])) {
  3293.  
  3294.                 $current_element $plici_net_img[$id]["string"];
  3295.  
  3296.                 if ($notag == true{
  3297.                     $before_tag "";
  3298.                     $after_tag "";
  3299.                     $old_current_element_memory $current_element;
  3300.                     if (ereg ("(src[ ]*=[ ]*['\"][^'\"]*['\"])"$old_current_element_memory$regs)) {
  3301.                        //echo_net($regs[1]);
  3302.                        $current_element $regs[1];
  3303.                     }
  3304.  
  3305.                     if (ereg ("(align[ ]*=[ ]*['\"][^'\"]*['\"])"$old_current_element_memory$regs)) {
  3306.                        //echo_net($regs[1]);
  3307.                        $current_element .= " ".$regs[1];
  3308.                     }
  3309.  
  3310.  
  3311.  
  3312.  
  3313.                     //echo_net($current_element);
  3314.                 else {
  3315.                     $before_tag "<img ";
  3316.  
  3317.                     $after_tag " />";
  3318.                 }
  3319.  
  3320.                 // Correct xhtml warning
  3321.                 if (!preg_match("@alt=@"$current_element))
  3322.                     $after_tag " alt='' ".$after_tag;
  3323.  
  3324.                 $will_return  str_replace("%PICTURE_BASE_HTTP%",$smarty->get_template_vars("picture_path"),$current_element).$after_tag;
  3325.                 //$will_return = $before_tag." style='border: thin dashed red;' onMouseOver='findDOM(\"plici_change_design\").innerHTML = \"".ereg_replace("[<>'\"]+", "_", $will_return)."\";   '; ".$will_return;
  3326.                 $will_return $before_tag.$will_return;
  3327.  
  3328.                 return $will_return;
  3329.     }
  3330.     
  3331.     return "";
  3332. }
  3333.  
  3334.  
  3335.  
  3336.  
  3337. /**
  3338.  * Load php5 function for php4
  3339.  */
  3340. include(dirname(__FILE__)."/php5_function.inc.php");
  3341.  
  3342.  
  3343.  
  3344.  
  3345.  
  3346.  
  3347.  
  3348.  
  3349.  
  3350.  
  3351.  
  3352.  
  3353.  
  3354.  
  3355.  
  3356.  
  3357.  
  3358.  
  3359.  
  3360.  
  3361. ?>

Documentation generated on Tue, 25 Mar 2008 15:35:32 +0100 by phpDocumentor 1.3.2