Source for file t_design.class.php

Documentation is available at t_design.class.php

  1. <?php   /*
  2.    *@=@=@=@ START LICENSE @=@=@=@*
  3.    Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
  4.    
  5.    stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
  6.    
  7.    This software is a computer program whose purpose is to make a
  8.    web hosting platform
  9.    
  10.    This software is governed by the CeCILL  license under French law and
  11.    abiding by the rules of distribution of free software.  You can  use, 
  12.    modify and/ or redistribute the software under the terms of the CeCILL
  13.    license as circulated by CEA, CNRS and INRIA at the following URL
  14.    "http://www.cecill.info". 
  15.    
  16.    As a counterpart to the access to the source code and  rights to copy,
  17.    modify and redistribute granted by the license, users are provided only
  18.    with a limited warranty  and the software's author,  the holder of the
  19.    economic rights,  and the successive licensors  have only  limited
  20.    liability. 
  21.    
  22.    In this respect, the user's attention is drawn to the risks associated
  23.    with loading,  using,  modifying and/or developing or reproducing the
  24.    software by the user in light of its specific status of free software,
  25.    that may mean  that it is complicated to manipulate,  and  that  also
  26.    therefore means  that it is reserved for developers  and  experienced
  27.    professionals having in-depth computer knowledge. Users are therefore
  28.    encouraged to load and test the software's suitability as regards their
  29.    requirements in conditions enabling the security of their systems and/or 
  30.    data to be ensured and,  more generally, to use and operate it in the 
  31.    same conditions as regards security. 
  32.    
  33.    The fact that you are presently reading this means that you have had
  34.    knowledge of the CeCILL license and that you accept its terms.
  35.    *@=@=@=@ END   LICENSE @=@=@=@*
  36.  
  37. */?><?php  
  38. /**
  39.  * TDesign Class
  40.  * 
  41.  * 
  42.  * @author SimpliciWeb
  43.  * @version $Id: t_design.class.php 724 2007-11-23 12:12:07Z stephanet $
  44.  * @package Common
  45.  * @subpackage FrameWork
  46.  */    
  47.  
  48. /**
  49.  * Include 'internal_components/common/cache_class/object_cached.class.php'
  50.  */
  51. require_once('internal_components/common/cache_class/object_cached.class.php');
  52.   
  53. /**
  54.  * Manage the designs for a container or a page
  55.  * (a design is a php and a template to print a page)
  56.  *
  57.  * @todo supprimer les tcontent invalidpagedesid, invalidpagedesid, invalidpagetitle, sqlinsert
  58.  * @author SimpliciWeb
  59.  * @version $Id: t_design.class.php 724 2007-11-23 12:12:07Z stephanet $
  60.  * @package Common
  61.  * @subpackage FrameWork
  62.  */
  63. class TDesign extends ObjectCached{
  64.  
  65.     //  BACK OFFICE CLASS
  66.  
  67.     
  68.     
  69.     // member object
  70.     /**
  71.      * Format Object
  72.      *
  73.      * @var Format 
  74.      */
  75.     var $m_object_format             = NULL;
  76.     /**
  77.      * Database Connexion object
  78.      *
  79.      * @var DbConnexion 
  80.      */
  81.     var $m_object_dbconnexion         = NULL;
  82.     /**
  83.      * types
  84.      *
  85.      * @var array 
  86.      */
  87.     var $m_type                        = NULL;
  88.     /**
  89.      * reversed types
  90.      *
  91.      * @var array 
  92.      */
  93.     var $m_r_type                    = NULL;
  94.     /**
  95.      * entry exec
  96.      *
  97.      * @var array 
  98.      */
  99.     var $m_entry_exec                = NULL;
  100.     /**
  101.      * entry exec reversed
  102.      *
  103.      * @var array 
  104.      */
  105.     var $m_r_entry_exec                = NULL;
  106.     /**
  107.      * page id
  108.      *
  109.      * @var integer 
  110.      */
  111.     var $m_page_id                    = NULL;
  112.     /**
  113.      * Design list
  114.      *
  115.      * @var array 
  116.      */
  117.     var $m_design_list                = array();
  118.  
  119.     // member request
  120.     /**
  121.      * SQL Request : Get by page id
  122.      *
  123.      * @var string 
  124.      */
  125.     var $req_get_by_id_page                = "SELECT des_id, des_title FROM t_design WHERE des_page_id=%d;";
  126.     /**
  127.      * SQL Request : get default detail design
  128.      *
  129.      * @var string 
  130.      */
  131.     var $req_get_default_detail_design    = "SELECT MIN(des_id) FROM t_design WHERE des_type = 'DETAIL';";
  132.     /**
  133.      * SQL Request : get default link design
  134.      *
  135.      * @var string 
  136.      */
  137.     var $req_get_default_link_design    = "SELECT MIN(des_id),des_level FROM t_design WHERE des_type='LINK' AND des_page_id = %d GROUP BY des_level;";
  138.     /**
  139.      * SQL Request : Get design list
  140.      *
  141.      * @var string 
  142.      */
  143.     var $req_get_design_list            = "SELECT des_id, des_page_id, des_title, des_level FROM t_design WHERE des_type='%s' @des_page_id@ ORDER BY des_level, des_id;";
  144.     /**
  145.      * SQL Request : Get design list by array
  146.      *
  147.      * @var string 
  148.      */
  149.     var $req_get_design_list_by_array     = "
  150. SELECT des_id, des_entry, des_entry_parameter, des_entry_exec, des_template 
  151. FROM t_design 
  152. WHERE des_id IN %s;";
  153.  
  154.     /**
  155.      * SQL Request : get design by template name
  156.      *
  157.      * @var string 
  158.      */
  159.     var $req_get_design_by_template_name"SELECT des_id, des_entry, des_template FROM t_design WHERE des_template = '%s';";
  160.         /**
  161.      * SQL Request : get design by page id type
  162.      *
  163.      * @var string 
  164.      */
  165.     var $req_get_design_by_page_id_type    = "SELECT des_id, des_entry, des_template FROM t_design WHERE des_type = '%s' AND des_page_id = %d;";
  166.     /**
  167.      * SQL Request : Select by primary key
  168.      *
  169.      * @var string 
  170.      */
  171.     var $req_select_by_primary_key    = "SELECT des_type, des_page_id, des_title, 
  172.                                         des_entry, des_template, des_level                         
  173.                                         FROM t_design 
  174.                                         WHERE des_id = %d;";
  175.     /**
  176.      * SQL Request : Select all
  177.      *
  178.      * @var string 
  179.      */
  180.     var $req_select_all =      "SELECT des_type, des_page_id, des_title, 
  181.                                         des_entry, des_template, des_level, des_id                         
  182.                                         FROM t_design ;";
  183.     /**
  184.      * SQL Request : Select product design
  185.      *
  186.      * @var string 
  187.      */
  188.     var $req_select_product_design    = "SELECT des_id, des_entry, des_template FROM t_design WHERE des_type='PRODUCT' AND des_page_id IN %s;";
  189.     /**
  190.      * SQL Request : Insert
  191.      *
  192.      * @var string 
  193.      */
  194.     var $req_insert                    = "INSERT INTO t_design(des_type, des_page_id, des_title, des_entry, des_template, des_level) VALUES ('%s', %d, '%s', @des_entry@, '%s', @des_level@);";
  195.     /**
  196.      * SQL Request : Delete design list
  197.      *
  198.      * @var string 
  199.      */
  200.     var $req_delete_design_list        = "DELETE FROM t_design WHERE des_id IN %s;";
  201.     /**
  202.      * SQL Request : Valid link design sub links
  203.      *
  204.      * @var string 
  205.      */
  206.     var $valid_link_design_sub_links            = "SELECT max( des_level )
  207.                                                         FROM t_design
  208.                                                         WHERE des_page_id =%d
  209.                                                         AND des_type = 'LINK'
  210.                                                         AND des_level <=%d;";
  211.     /**
  212.      * SQL Request : valid link design
  213.      *
  214.      * @var string 
  215.      */
  216.     var $valid_link_design            = "SELECT des_id
  217.                                         FROM t_design
  218.                                         WHERE des_id=%d
  219.                                         AND (
  220.                                                 (
  221.                                                     des_type = 'SPE_LINK'
  222.                                                 )
  223.                                             OR (
  224.                                                     des_page_id =%d
  225.                                                     AND des_type = 'LINK'
  226.                                                     AND des_level
  227.                                                     IN (%d)
  228.                                                 )
  229.                                         );";
  230.     
  231.     
  232.     /**
  233.      * array already loaded
  234.      *
  235.      * @var array 
  236.      */
  237.     var $m_array_already_loader = array();
  238.  
  239.  
  240.     /**
  241.      * Constructor, init the requests and objects
  242.      *
  243.      * @return TDesign 
  244.      */
  245.     function TDesign({
  246.         global $g_object_loader;
  247.         $this->m_object_format =$g_object_loader->getFormat();
  248.         $this->m_object_dbconnexion =$g_object_loader->getDbConnexion();
  249.  
  250.         $tihs->m_page_id["TRASH"70;
  251.  
  252.         $this->m_type["LINK"]="LINK";
  253.         $this->m_type["DETAIL"]="DETAIL";
  254.         $this->m_type["CONTAINER"]="CONTAINER";
  255.         $this->m_type["SPECIAL_LINK"]="SPE_LINK";
  256.         $this->m_type["SPECIAL_DETAIL"]="SPE_DETAIL";
  257.         $this->m_type["PRODUCT"]="PRODUCT";
  258.         $this->m_r_type = array_flip($this->m_type);
  259.  
  260.         $this->m_entry_exec["ALWAYS_BEFORE_SESSION_DESTROY""ALWAYS_BEFORE";
  261.         $this->m_entry_exec["ALWAYS""ALWAYS";
  262.         $this->m_entry_exec["NOTIFCACHED""CACHED";
  263.         $this->m_entry_exec["ALWAYS_AFTER""ALWAYS_AFTER";
  264.         $this->m_r_entry_exec = array_flip($this->m_entry_exec);
  265.  
  266.         $this->m_design_list = array();
  267.     
  268.     
  269.     //  xIsNotValid
  270.     //  **********
  271.     /**
  272.      * Parameter Integrity checker
  273.      *
  274.      * @access private
  275.      * @param string $p_value 
  276.      * @return  bool TRUE if not valid
  277.      */
  278.     function isNotValidDesId($p_value{
  279.         return $this->m_object_format->isNotUnsignedInteger($p_value8);
  280.     
  281.     /**
  282.      * Parameter Integrity checker
  283.      *
  284.      * @access private
  285.      * @param string $p_value 
  286.      * @return  bool TRUE if not valid
  287.      */
  288.     function xIsNotValidDesType($p_value{
  289.         return $this->m_object_format->isNotEnum($p_value$this->m_r_type);
  290.     
  291.     /**
  292.      * Parameter Integrity checker
  293.      *
  294.      * @access private
  295.      * @param string $p_value 
  296.      * @return  bool TRUE if not valid
  297.      */
  298.     function xIsNotValidDesPageId($p_value{
  299.         return $this->m_object_format->isNotUnsignedInteger($p_value8);
  300.     
  301.     /**
  302.      * Parameter Integrity checker
  303.      *
  304.      * @access private
  305.      * @param string $p_value 
  306.      * @return  bool TRUE if not valid
  307.      */
  308.     function isNotValidDesTitle($p_value{
  309.         return $this->m_object_format->isNotVarchar($p_value32);
  310.     
  311.     /**
  312.      * Parameter Integrity checker
  313.      *
  314.      * @access private
  315.      * @param string $p_value 
  316.      * @return  bool TRUE if not valid
  317.      */
  318.     function isNotValidDesEntry($p_value{
  319.         return $this->m_object_format->isNotVarchar($p_value255);
  320.     
  321.     /**
  322.      * Parameter Integrity checker
  323.      *
  324.      * @access private
  325.      * @param string $p_value 
  326.      * @return  bool TRUE if not valid
  327.      */
  328.     function isNotValidDesTemplate($p_value{
  329.         return $this->m_object_format->isNotVarchar($p_value255);
  330.     
  331.     /**
  332.      * Parameter Integrity checker
  333.      *
  334.      * @access private
  335.      * @param string $p_value 
  336.      * @return  bool TRUE if not valid
  337.      */
  338.     function xIsNotValidDesLevel($p_value{
  339.         return $this->m_object_format->isNotUnsignedInteger($p_value3);
  340.     
  341.  
  342.  
  343.     /**
  344.      * Add member design list
  345.      *
  346.      * @param array $p_design 
  347.      */
  348.     function addMemberDesignList($p_design{
  349.         if (0<count($p_design)) {
  350.             $this->m_design_list = array_merge($this->m_design_list,$p_design);
  351.         }
  352.     }
  353.     /**
  354.      * Get member design list
  355.      *
  356.      * @param array $r_result 
  357.      */
  358.     function getMemberDesignList(&$r_result{
  359.         $r_result $this->m_design_list;
  360.     }
  361.  
  362.  
  363.     ////////
  364.     // FO //
  365.     ////////
  366.  
  367.     /**
  368.      * Get all the entry to exec
  369.      *
  370.      * Renvoit la liste des types du champs des_entry_exe
  371.      *
  372.      * @param array $r_result 
  373.      */
  374.     function getEntryExec(&$r_result
  375.     {
  376.         $r_result $this->m_entry_exec;
  377.     }
  378.  
  379.     /**
  380.      * Get the designs in an array
  381.      *
  382.      * Renvoit les designs contenus dans un tableau et un tableau contenant les templates ayant du t_content et un tableau contenant cette liste indexée par le nom du tpl
  383.      * 
  384.      * @param array $p_design_list_array 
  385.      * @param array $r_result 
  386.      * @return bool TRUE on error
  387.      */
  388.     function getDesignListByArray($p_design_list_array&$r_result{
  389.         
  390.         $r_result $name_indexed_list array();
  391.  
  392.         if (0<count($p_design_list_array)) {
  393.             $parameters array("(".implode(",",array_unique($p_design_list_array)).")");
  394.             $result array();
  395.             if ($this->m_object_dbconnexion->makeSqlQuery($this->req_get_design_list_by_array$parameters$result)) {
  396.                 return onErrorThrow(true,plici_lang("lang_error_internal"));
  397.             }
  398.             while ($row mysql_fetch_row($result)) {
  399.                 $r_result[$row[0]]['des_entry'$row[1];
  400.                 $r_result[$row[0]]['des_entry_parameter'$row[2];
  401.                 $r_result[$row[0]]['des_entry_exec'$this->m_r_entry_exec[$row[3]];
  402.                 $r_result[$row[0]]['des_template'$row[4];
  403.                 $name_indexed_list[$row[4]] array("des_id"=>$row[0]"des_entry"=>$row[1]"startup_loaded"=>TRUE);
  404.             }
  405.         }
  406.         //print_r_net($name_indexed_list);
  407.         $this->addMemberDesignList($name_indexed_list);
  408.  
  409.         return false;
  410.     }
  411.  
  412.  
  413.     /**
  414.      * Get design by template
  415.      *
  416.      * @param integer $p_design_template_name 
  417.      * @param array $r_result 
  418.      * @return bool TRUE on error
  419.      */
  420.     function getDesignByTemplateName($p_design_template_name&$r_result{
  421.         
  422.         $r_result array();
  423.         if ($this->isNotValidDesTemplate($p_design_template_name))
  424.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  425.         $result array();
  426.         $parameters array($p_design_template_name);
  427.         if ($this->m_object_dbconnexion->makeSqlQuery($this->req_get_design_by_template_name$parameters$result)) {
  428.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  429.         }
  430.         while ($row mysql_fetch_row($result)) {
  431.                 $r_result array("des_id"=>$row[0]"des_entry"=>$row[1]"startup_loaded"=>FALSE);
  432.         }
  433.         return false;
  434.     }
  435.  
  436.  
  437.     /**
  438.      * Get the template to use to print products
  439.      *
  440.      * Renvoit le fichier template a utiliser pour afficher la fiche produit
  441.      * @param integer $p_page_id 
  442.      * @param array $r_result 
  443.      * @return bool TRUE on error
  444.      */
  445.     function getProductPageDesign($p_page_id&$r_result{
  446.         
  447.         $r_result "";
  448.         if ($this->xIsNotValidDesPageId($p_page_id))
  449.             return onErrorThrow(true,plici_lang("lang_error_pkpageid"));
  450.         $result array();
  451.         $parameters array("(0, ".$p_page_id.")");
  452.         if ($this->m_object_dbconnexion->makeSqlQuery($this->req_select_product_design$parameters$result)) {
  453.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  454.         }
  455.         $list array();
  456.         while ($row mysql_fetch_row($result)) {
  457.             array_push($listarray("des_id"=> $row[0]"des_entry"=>$row[1]"des_template"=>$row[2]) );
  458.         }
  459.         // Il y a forcement le résultat par défaut. Si plus on prend celui associé a la page
  460.         $r_result 1<count($list)?$list[1]:$list[0];
  461.         return false;
  462.     }
  463.  
  464.  
  465.     ////////
  466.     // BO //
  467.     ////////
  468.  
  469.  
  470.     /**
  471.      * Test if a deesign can be used into a container
  472.      *
  473.      * Indique si une apparence peut être utilisé au niveau du conteneur réclamé
  474.      * 
  475.      * @access private
  476.      * @param integer $p_des_id 
  477.      * @param integer $p_page_des_id 
  478.      * @param integer $p_level 
  479.      * @param array $r_result 
  480.      * @return bool TRUE on error
  481.      */
  482.     function isValidDesignForContainer($p_des_id$p_page_des_id$p_level&$r_result{
  483.         $r_result false;
  484.  
  485.         if ($this->isNotValidDesID($p_des_id))
  486.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  487.         if ($this->xIsNotValidDesPageId($p_page_des_id))
  488.             return onErrorThrow(true,plici_lang("lang_error_internal"));    
  489.         if ($this->xIsNotValidDesLevel($p_level))
  490.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  491.  
  492.  
  493.  
  494.         
  495.         $parameters $result array();
  496.         array_push($parameters$p_page_des_id);
  497.         array_push($parameters$p_level);
  498.         if ($this->m_object_dbconnexion->makeSqlQuery($this->valid_link_design_sub_links$parameters$result)) {
  499.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  500.         }
  501.         $tem_row mysql_fetch_row($result);
  502.         $max_des_level $tem_row[0]
  503.         
  504.         $parameters $result array();
  505.         array_push($parameters$p_des_id);
  506.         array_push($parameters$p_page_des_id);
  507.         array_push($parameters$max_des_level);
  508.         if ($this->m_object_dbconnexion->makeSqlQuery($this->valid_link_design$parameters$result)) {
  509.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  510.         }
  511.         
  512.         $r_result 0>=mysql_num_rows($result)?false:true;
  513.         
  514.         return false;
  515.     }
  516.  
  517.  
  518.     /**
  519.      * Get the list of designs of type $p_page_type linked to the page
  520.      *
  521.      * Renvoit la liste de design de type $p_page_type associée a la page
  522.      * 
  523.      * @param string $p_page_type 
  524.      * @param integer $p_page_id 
  525.      * @param array $r_result 
  526.      * @return bool TRUE on error
  527.      */
  528.     function getDesignList($p_page_type$p_page_id&$r_result{
  529.         return $this->getDesignListByTypeAndIdPageList($p_page_typearray($p_page_id)$r_result);
  530.     }
  531.     
  532.     /**
  533.      * Get design list by type and page list
  534.      *
  535.      * @param string $p_page_type 
  536.      * @param array $p_liste_page_id 
  537.      * @param array $r_result 
  538.      * @return bool TRUE on error
  539.      */
  540.     function getDesignListByTypeAndIdPageList($p_page_type$p_liste_page_id&$r_result{
  541.         
  542.         $r_result array();
  543.  
  544.         if ($this->xIsNotValidDesType($p_page_type))
  545.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  546.         $list_page_id array();
  547.         for($i=0$i<count($p_liste_page_id)$i++{
  548.             if ((null != $p_liste_page_id[$i]&& ($this->xIsNotValidDesPageId($p_liste_page_id[$i])))
  549.                 return onErrorThrow(true,plici_lang("lang_error_pagedesid"))
  550.             if (!= $p_liste_page_id[$i]
  551.                 array_push($list_page_id ,$p_liste_page_id[$i]);
  552.         }
  553.  
  554.  
  555.         $request $this->req_get_design_list;
  556.  
  557.         $parameters array();
  558.         array_push($parameters$this->m_type[$p_page_type]);
  559.         switch ($p_page_type{
  560.             case "PRODUCT" 
  561.             case "DETAIL" :
  562.                 if (0>=count($list_page_id)) {
  563.                     $request str_replace('@des_page_id@'''$request);
  564.                     break;
  565.                 }
  566.             default 
  567.                 $request str_replace('@des_page_id@'"AND des_page_id IN %s"$request);
  568.                 array_push($parameters"(".implode(","$p_liste_page_id).")");
  569.                 break;
  570.         }
  571.  
  572.         $result array();
  573.         if ($this->m_object_dbconnexion->makeSqlQuery($request$parameters$result)) {
  574.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  575.         }
  576.         $r_result_count 0;
  577.         while ($row mysql_fetch_row($result)) {
  578.               $r_result[$r_result_count]['des_id'$row[0];
  579.               $r_result[$r_result_count]['des_page_id'$row[1];
  580.             $r_result[$r_result_count]['des_title'$row[2];
  581.             $r_result[$r_result_count]['des_level'$row[3];
  582.             $r_result_count++;
  583.         }
  584.  
  585.         return false;
  586.     }
  587.  
  588.  
  589.  
  590.     /**
  591.      * Get design
  592.      *
  593.      * @param integer $p_design_id 
  594.      * @param array $r_result 
  595.      * @return bool TRUE on error
  596.      */
  597.     function getDesign($p_design_id&$r_result{
  598.         
  599.         $r_result array();
  600.         if ($this->isNotValidDesId($p_design_id))
  601.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  602.  
  603.         if ($this->xIsRemembered("d_".$p_design_id$r_remembered_object)) {
  604.             $r_result $r_remembered_object;
  605.             return false;
  606.         }
  607.  
  608.         $parameters array($p_design_id);
  609.         $result array();
  610. //$this->m_object_dbconnexion->debug_is_on = true;
  611.         if ($this->m_object_dbconnexion->makeSqlQuery($this->req_select_by_primary_key$parameters$result)) {
  612.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  613.         }
  614. //$this->m_object_dbconnexion->debug_is_on = false;
  615.  
  616.         while ($row mysql_fetch_row($result)) {
  617.               $r_result['des_id'$p_design_id;
  618.               $r_result['des_type'$this->m_r_type[$row[0]];
  619.             $r_result['des_page_id'$row[1];
  620.             $r_result['des_title'$row[2];
  621.             $r_result['des_entry'$row[3];
  622.             $r_result['des_template'$row[4];
  623.             $r_result['des_level'$row[5];
  624.         }
  625.  
  626.         $this->xRemember("d_".$p_design_id$r_result);
  627.  
  628.         return false;
  629.     }
  630.  
  631.     /**
  632.      * Get designs
  633.      *
  634.      * @param array $r_result_all 
  635.      * @return bool TRUE on error
  636.      */
  637.     function xGetDesigns(&$r_result_all{
  638.         
  639.         
  640.         $r_result_all array();
  641.  
  642.         $parameters array();
  643.         $result array();
  644.         if ($this->m_object_dbconnexion->makeSqlQuery($this->req_select_all$parameters$result)) {
  645.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  646.         }
  647.  
  648.         while ($row mysql_fetch_row($result)) {
  649.             $r_result array();
  650.               $r_result['des_id'$row[6];
  651.               $r_result['des_type'$this->m_r_type[$row[0]];
  652.             $r_result['des_page_id'$row[1];
  653.             $r_result['des_title'$row[2];
  654.             $r_result['des_entry'$row[3];
  655.             $r_result['des_template'$row[4];
  656.             $r_result['des_level'$row[5];
  657.             array_push($r_result_all$r_result);
  658.         }
  659.  
  660.  
  661.         return false;
  662.     }
  663.  
  664.  
  665.     /**
  666.      * insert
  667.      *
  668.      * @param string $p_des_type           'CONTAINER', 'LINK', 'DETAIL', 'SPE_LINK', 'SPE_DETAIL', 'PRODUCT'
  669.      * @param integer $p_des_page_id 
  670.      * @param string $p_page_type 
  671.      * @param string $p_des_title 
  672.      * @param string $p_des_entry 
  673.      * @param string $p_des_template 
  674.      * @param integer $p_des_level 
  675.      * @param array $r_result 
  676.      * @return bool TRUE on error
  677.      */
  678.     function insert($p_des_type$p_des_page_id$p_page_type$p_des_title$p_des_entry$p_des_template$p_des_level&$r_result{
  679.         
  680.         $r_result = -1;
  681.         global $g_object_loader;
  682.         $g_object_message =$g_object_loader->getMessage()
  683.         onErrorThrow($this->xIsNotValidDesType($p_des_type|| (null==$p_des_type),plici_lang("lang_error_field"));
  684.         onErrorThrow($this->xIsNotValidDesPageId($p_des_page_id),plici_lang("lang_error_field"));
  685.         switch ($p_des_type{
  686.             case "DETAIL":
  687.                 break;
  688.             default :
  689.                 onErrorThrow(== $p_des_page_id,plici_lang("lang_error_field"));
  690.                 break;
  691.         }
  692.         onErrorThrow($this->isNotValidDesTitle($p_des_title|| (null==$p_des_title),plici_lang("lang_error_field"));
  693.         onErrorThrow($this->isNotValidDesEntry($p_des_entry),plici_lang("lang_error_internal"));
  694.         onErrorThrow($this->isNotValidDesTemplate($p_des_template|| (null==$p_des_template)'invalidDesTemplate'$function_nameEFN_4j1xcbCPhuRqXbmSuIiDQjS0jouyAfWa);
  695.         if (null != $p_des_level
  696.             onErrorThrow($this->xIsNotValidDesLevel($p_des_level),plici_lang("lang_error_internal"));
  697.         else {
  698.             onErrorThrow("LINK"==$p_des_type,plici_lang("lang_error_internal"));
  699.         }
  700.         //Vérification - Pour faire plus beau, il faudrait recharger les informations à partir du des_page_ids
  701.         switch ($p_des_type{
  702.             case "CONTAINER" 
  703.             case "LINK" onErrorThrow("CONTAINER" != $p_page_type,plici_lang("lang_error_field"));
  704.                 break;
  705.             case "DETAIL" $p_des_page_id 0;
  706.                 break;
  707.             case "SPECIAL_LINK" 
  708.             case "SPECIAL_DETAIL" onErrorThrow("SYSTEM" == $p_page_type,plici_lang("lang_error_field"));
  709.                 break;
  710.             default 
  711.                 break;
  712.         }
  713.         if ($g_object_message->thereIsAnError()) {
  714.             return true;    
  715.         }
  716.         
  717.  
  718.         $parameters array();
  719.         $request $this->req_insert;
  720.         array_push($parameters$this->m_type[$p_des_type]);
  721.         array_push($parameters$p_des_page_id);
  722.         array_push($parameterstrim($p_des_title));
  723.         if (null == $p_des_entry{
  724.             $request str_replace("@des_entry@"" null "$request);
  725.         else {
  726.             $request str_replace("@des_entry@"" '%s' "$request);
  727.             array_push($parameterstrim($p_des_entry));
  728.         }
  729.         array_push($parameterstrim($p_des_template));
  730.         if (null == $p_des_level{
  731.             $request str_replace("@des_level@"" null "$request);
  732.         else {
  733.             $request str_replace("@des_level@"" %d "$request);
  734.             array_push($parameters$p_des_level);
  735.         }
  736.  
  737.         $result array();
  738.         if ($this->m_object_dbconnexion->makeSqlQueryWithId($request$parameters$result$r_result)) {
  739.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  740.         }
  741.  
  742.         $this->xClearRemember("d_".$r_result);
  743.         $this->xClearRemember("l_".$p_des_page_id."_".$p_des_type);
  744.         
  745.         return false;
  746.     }
  747.  
  748.     
  749.     /**
  750.      * Get link design id for insertion
  751.      *
  752.      * @param integer $p_page_id 
  753.      * @param array $r_result 
  754.      * @return bool TRUE on error
  755.      */
  756.     function getLinkDesignIdForInsertion($p_page_id&$r_result{
  757.         
  758.         $r_result array();
  759.         if ($this->xIsNotValidDesPageId($p_page_id))
  760.             return onErrorThrow(true,plici_lang("lang_error_pkpageid"));
  761.         if ($this->m_page_id["TRASH"!= $p_page_id//Si ce n'est pas la page poubelle
  762.             $parameters $result =array();
  763.             array_push($parameters$p_page_id);
  764.             if ($this->m_object_dbconnexion->makeSqlQuery($this->req_get_default_link_design$parameters$result)) {
  765.                 return onErrorThrow(true,plici_lang("lang_error_internal"));
  766.             }
  767.             $ind 0;
  768.             while ($row mysql_fetch_row($result)) {
  769.                 while($ind<=$row[1]{
  770.                     $r_result[$ind$row[0];
  771.                     $ind++;
  772.                 }
  773.             }
  774.         }
  775.  
  776.         return false;    
  777.     }
  778.     
  779.     /**
  780.      * Get Detail design id for insertion
  781.      *
  782.      * @param array $r_result 
  783.      * @return bool TRUE on error
  784.      */
  785.     function getDetailDesignIdForInsertion(&$r_result{
  786.         
  787.         $r_result = -1;
  788.         $parameters $result =array();
  789.         if ($this->m_object_dbconnexion->makeSqlQuery($this->req_get_default_detail_design$parameters$result)) {
  790.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  791.         }
  792.  
  793.         while ($row mysql_fetch_row($result)) {
  794.             $r_result $row[0];
  795.         }
  796.  
  797.         return false;
  798.     }
  799.  
  800.     ///////////
  801.     // ADMIN //
  802.     ///////////
  803.  
  804.     /**
  805.      * Delete a design
  806.      * Delete all the designs by type associated to a page id.
  807.      * Return into $r_result the list of files to delete
  808.      *
  809.      * Supprime toutes les apparences d'un certain type associées à un id de page. Va renvoyer la liste des fichiers supprimables
  810.      * 
  811.      * @param string $p_des_type 
  812.      * @param integer $p_page_id 
  813.      * @param array $r_result 
  814.      * @return bool TRUE on error
  815.      */
  816.     function delete($p_des_type$p_page_id&$r_result){
  817.         
  818.         $r_result array();
  819.         $r_result["entry"$r_result["template"array();
  820.         if ($this->xIsNotValidDesType($p_des_type)) 
  821.             return onErrorThrow(TRUE,plici_lang("lang_error_field"));
  822.         if ($this->xIsNotValidDesPageId($p_page_id))
  823.             return onErrorThrow(TRUE,plici_lang("lang_error_pkpageid"));
  824.  
  825.         $parameters $result array();
  826.         array_push($parameters$this->m_type[$p_des_type]);
  827.         array_push($parameters$p_page_id);
  828.         if ($this->m_object_dbconnexion->makeSqlQuery($this->req_get_design_by_page_id_type$parameters$result)) {
  829.             return onErrorThrow(true,plici_lang("lang_error_internal"));
  830.         }
  831.  
  832.         $design_list $entry_file $template_file =  array();
  833.         while ($row mysql_fetch_row($result)) {
  834.             array_push($design_list$row[0]);
  835.             if ((null != $row[1]&& (0<strlen($row[1])))
  836.                 array_push($entry_file$row[1]);
  837.             if ((null != $row[2]&& (0<strlen($row[2])))
  838.                 array_push($template_file$row[2]);
  839.         }        
  840.  
  841.         //Suppression des apparences
  842.         $design_deleted = -1;
  843.         if (0<count($design_list)) {
  844.             $parameters $result array();
  845.             array_push($parameters"(".implode(",",$design_list).")");
  846.             if ($this->m_object_dbconnexion->makeSqlQuery($this->req_delete_design_list$parameters$result)) {
  847.                 return onErrorThrow(true,plici_lang("lang_error_internal"));
  848.             }
  849.             $design_deleted mysql_affected_rows();
  850.         }
  851.  
  852.         //Création de la liste des fichiers entréer a supprimer - ON NE PEUT PAS ETRE SUR CAR LES FICHIERS ENTREE SONT PARTAGES AVEC TOUS LES CLIENTS
  853.         $r_result["entry"$entry_file;
  854.  
  855.         //Création de la liste des fichiers template a supprimer
  856.         for ($i=0$i<count($template_file)$i++{
  857.             if ($this->m_object_dbconnexion->makeSqlQuery("SELECT count(des_id) FROM t_design WHERE des_template='".$template_file[$i]."';"$parameters$result)) {
  858.                 return onErrorThrow(true,plici_lang("lang_error_internal"));
  859.             }
  860.             $row mysql_fetch_row($result);
  861.             if (1==$row[0])
  862.                 array_push($r_result["template"]$template_file[$i]);
  863.         }
  864.  
  865.         return false;
  866.     }
  867.  
  868.  
  869.  
  870.     /**
  871.      * Check integrity
  872.      *
  873.      * @param array $r_resut_final 
  874.      * @return bool TRUE on error
  875.      */
  876.     function _check(&$r_resut_final{
  877.         $function_name "_check";
  878.         $r_result_get_all array();
  879.         global $g_object_siteinformation;
  880.         
  881.         $this->xGetDesigns($r_result_get_all);
  882.         $r_resut_final array();
  883.         // des_id,des_type,des_page_id,des_title,des_entry,des_template,des_level
  884.         foreach ($r_result_get_all as $value{
  885.             // test si ce design sert pour une page
  886.             //             soit des_id = page_link_des_id ou page_detail_des_id
  887.             //            soit des_id = page_des_id
  888.             $find_utility "";
  889.              $request "SELECT count(*) FROM t_page WHERE page_link_des_id=".$value['des_id'].";";
  890.             $parameters $result array();
  891.             if ($this->m_object_dbconnexion->makeSqlQuery($request$parameters$result)) {
  892.                 return onErrorThrow(true,plici_lang("lang_error_selectnoflinkdes"));
  893.             }
  894.             //$result = mysql_query($request);
  895.             $row mysql_fetch_row($result);
  896.             $r_result $row[0];
  897.             if ($r_result 0)
  898.                 $find_utility .= "|page_link_des_id";
  899.  
  900.              $request "SELECT count(*) FROM t_page WHERE page_detail_des_id=%d;";
  901.             $parameters $result array();
  902.             $parameters[$value['des_id'];
  903.             if ($this->m_object_dbconnexion->makeSqlQuery($request$parameters$result)) {
  904.                 return onErrorThrow(true,plici_lang("lang_error_selectnofdetaildes"));
  905.             }
  906.             //$result = mysql_query($request);
  907.             $row mysql_fetch_row($result);
  908.             $r_result $row[0];
  909.             //Une page de détail, ou de produit peut exister mais être associé a personne
  910.             if (($r_result 0|| ((== $value['des_type']&& (("DETAIL" == $value['des_type']|| ("SPE_DETAIL" == $value['des_type']|| ("PRODUCT" == $value['des_type']))))
  911.                 $find_utility .= "|page_detail_des_id";
  912.             
  913.              $request "SELECT count(*) FROM t_page WHERE page_id=%d;";
  914.             $parameters $result array();
  915.             $parameters[$value['des_page_id'];
  916.             if ($this->m_object_dbconnexion->makeSqlQuery($request$parameters$result)) {
  917.                 return onErrorThrow(true,plici_lang("lang_error_selectnofdes"));
  918.             }
  919.             //$result = mysql_query($request);
  920.             $row mysql_fetch_row($result);
  921.             $r_result $row[0];
  922.             if ($r_result 0)
  923.                 $find_utility .= "|des_page_id";
  924.  
  925.             // si on a pas trouvé d'utilité au design, on le signale 
  926.             if ($find_utility == ""{
  927.                 $to_write $value['des_id']."|".$value['des_type']."|".$value['des_page_id']."|".$value['des_title']."|".$value['des_entry']."|".$value['des_template']."|".$value['des_level'];
  928.                 $to_write .= "<br/> delete from t_design where des_type='".$value['des_type']."' and des_page_id ='".$value['des_page_id']."'    and des_title='".$value['des_title']."'    and des_template='".$value['des_template']."';";
  929.                 array_push($r_resut_finalarray(
  930.                                 'col1' => 'AUCUNE PAGE LIEE'
  931.                                 ,'col2'=> $to_write));
  932.             else {
  933.             
  934.                 // si il sert, on test que les fichiers utiles soient bien en action
  935.                 if (!file_exists($g_object_siteinformation->getFrontSiteEntry().PLICI_MY_DIRECTORY."/".$value['des_entry'])
  936.             && !file_exists($g_object_siteinformation->getFrontSiteEntry().PLICI_MY_DIRECTORY."/".$value['des_entry'])) {
  937.                     $to_write $value['des_id']."|".$value['des_type']."|".$value['des_page_id']."|".$value['des_title']."|".$value['des_entry']."|".$value['des_template']."|".$value['des_level'];
  938.                     $to_write .= "<br/> delete from t_design where des_type='".$value['des_type']."' and des_page_id ='".$value['des_page_id']."'    and des_title='".$value['des_title']."'    and des_template='".$value['des_template']."';";
  939.                     array_push($r_resut_finalarray(
  940.                                     'col1' => 'des_entry INEXISTANT'
  941.                                     ,'col2'=> $to_write));
  942.                 }
  943.                 if (!$g_object_siteinformation->getExistTemplateNotCompiledFilePath($value['des_template']$r_not_usedtrue,$this->m_object_dbconnexion->m_database_name)) {
  944.                     $to_write $value['des_id']."|".$value['des_type']."|".$value['des_page_id']."|".$value['des_title']."|".$value['des_entry']."|".$value['des_template']."|".$value['des_level'];
  945.                     $to_write .= "<br/> delete from t_design where des_type='".$value['des_type']."' and des_page_id ='".$value['des_page_id']."'    and des_title='".$value['des_title']."'    and des_template='".$value['des_template']."';";
  946.                     array_push($r_resut_finalarray(
  947.                                     'col1' => 'des_template INEXISTANT'
  948.                                     ,'col2'=> $to_write));
  949.                 }
  950.                     
  951.             }
  952.         }
  953.  
  954.         $to_write sizeof($r_result_get_all);
  955.         array_push($r_resut_finalarray(
  956.                                 'col1' => 'NB lignes lues'
  957.                                 ,'col2'=> $to_write));
  958.  
  959.         $r_result $r_resut_final;
  960.         
  961.         
  962.         return false;
  963.     }
  964.  
  965. }
  966.  
  967. ?>

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