Source for file CMS_PAGE.phpclass

Documentation is available at CMS_PAGE.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package cms
  7.   *
  8.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-16.06.2008
  12.   * @version $Id: CMS_PAGE.phpclass,v 1.25 2008/12/17 16:28:51 peterkrebs Exp $
  13.   */
  14.  
  15. // ---------------------------------------------------------
  16. // requirements
  17. // ---------------------------------------------------------
  18.  
  19.     pcf_require_interface('INFA_CMS_PAGE',dirname(__FILE__"/INFA_CMS_PAGE.phpclass");
  20.  
  21.     pcf_require_class('CMS_TABLEOBJ',__OCSP_PHPINCPATH__ "cms/CMS_TABLEOBJ.phpclass");
  22.     pcf_require_class('CMS_PAGE_TEMPLATE',__OCSP_PHPINCPATH__ "cms/template/page/CMS_PAGE_TEMPLATE.phpclass");
  23.  
  24. /**
  25.   * openCSP class file
  26.   *
  27.   * @project Open CSP-Management
  28.   * @package cms
  29.   *
  30.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  31.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   * @since pk-16.06.2008
  34.   * @version $Id: CMS_PAGE.phpclass,v 1.25 2008/12/17 16:28:51 peterkrebs Exp $
  35.   */
  36. class CMS_PAGE extends CMS_TABLEOBJ implements INFA_CMS_PAGE
  37. {
  38.     // ---------------------------------------------------------------------------
  39.     // constants
  40.     // ---------------------------------------------------------------------------
  41.     
  42.     /**
  43.      * @constant string CLASS_SRC_FILE
  44.      *
  45.      * @abstract
  46.      */
  47.     const CLASS_SRC_FILE = __FILE__;
  48.     
  49.     // ---------------------------------------------------------------------------
  50.     // class (static)
  51.     // ---------------------------------------------------------------------------
  52.     
  53.     /*** class vars ------------------------------------------------------ */
  54.     
  55.     /**
  56.      * array of loaded pages can be used as unit of work
  57.      * together with the getInstanceXxxx functions
  58.      *
  59.      * @staticvar array $loadedPages 
  60.      * 
  61.      * @since pk-08-08-08
  62.      */
  63.     protected static $loadedPages array();
  64.     
  65.     /*** class methods --------------------------------------------------- */
  66.     
  67.     /**
  68.      * requires the class source file for $str_class
  69.      *
  70.      * @param string $str_class 
  71.      * @param boolean $debug 
  72.      * 
  73.      * @return string 
  74.      * 
  75.      * @version pk-08-03-31
  76.      */
  77.     public static function requirePageClass($str_class,$debug=False)
  78.     {
  79.         if ($debugechoDebugMethod(__FILE__,"static","CMS_PAGE::requirePageClass({$str_class});");
  80.         
  81.         if (class_exists($str_class)) 
  82.         {
  83.             return $str_class;
  84.         }
  85.         
  86.         if (!CMS_TABLEOBJ::pageType_requireClass($str_class))
  87.         {
  88.             if (file_exists(dirname(__FILE___OCSP_DIRSEP_ $str_class ".phpclass"))
  89.             {
  90.                 require_once dirname(__FILE___OCSP_DIRSEP_ $str_class ".phpclass";
  91.             else {
  92.                 throw new Exception(_OCSP_EXCEP_CLASSNOTFOUND_ ":" $str_class);
  93.             }
  94.         }
  95.         
  96.         if (!class_exists($str_class))
  97.         {
  98.             throw new Exception(_OCSP_EXCEP_CLASSNOTFOUND_ ":" $str_class);
  99.         }
  100.  
  101.         return $str_class;
  102.     }
  103.     
  104.     // ------ unit of work -----
  105.     
  106.     /**
  107.      * returns an unit of work instance
  108.      *
  109.      * @param int $aId 
  110.      * @param boolean $debug 
  111.      * 
  112.      * @return CMS_PAGE 
  113.      */
  114.     public static function &getInstance($aId,$debug=False)
  115.     {
  116.         if ($debugechoDebugMethod(__FILE__,"static","CMS_PAGE::getInstance({$aId})");
  117.         
  118.         if (!isset(self::$loadedPages[intval($aId)]|| !(self::$loadedPages[intval($aId)]))
  119.         {
  120.             self::$loadedPages[intval($aId)self::factoryFromId($aId,False,$debug);
  121.         }
  122.         
  123.         return self::$loadedPages[intval($aId)];        
  124.     }
  125.     
  126.     /**
  127.      * sets an unit of work instance
  128.      *
  129.      * @param int $aId 
  130.      * @param CMS_PAGE $aPage 
  131.      * @param boolean $debug 
  132.      *
  133.      */
  134.     public static function setInstance(&$aPage,$debug=False)
  135.     {
  136.         if (method_exists($aPage,'getId'))
  137.         {
  138.             self::$loadedPages[$aPage->getId()]=$aPage;
  139.         }
  140.     }  
  141.  
  142.     /**
  143.      * returns if a page is instanciated
  144.      *
  145.      * @param int $aId 
  146.      * 
  147.      * @return boolean 
  148.      */
  149.     public static function isInstanced($aId)
  150.     {
  151.         return (isset(self::$loadedPages[intval($aId)]&& (self::$loadedPages[intval($aId)]));
  152.     }
  153.     
  154.     // ---------------------------------------------------------------------------
  155.     // object vars
  156.     // ---------------------------------------------------------------------------
  157.     
  158.     /*** compostion --------------------------------------------------- */
  159.             
  160.     /**
  161.      * @var CMS_PAGE_TEMPLATE $myTemplate 
  162.      */
  163.     protected $myTemplate Null;
  164.     
  165.     /**
  166.       * @var CMS_HTML_PAGE $myHTMLPage 
  167.       * @access protected
  168.       */
  169.     protected $myHTMLPage Null;    
  170.     
  171.     /**
  172.      * sorted array of chpater
  173.      * 
  174.      * myChapterList[CHA_SHOWMODE][CHA_SORTORDER] = CMS_CHAPTER
  175.      * 
  176.      * @var array of chapters
  177.      */
  178.     protected $myChapterList array();
  179.     
  180.     /*** attributes  -------------------------------------------------- */
  181.     
  182.     /**
  183.      * @var string $myTable   name of the table holding the data
  184.      */
  185.     protected $myTable = "T_CMS_PAGE"
  186.  
  187.     /**
  188.      * Id of the template to use if PTMP_ID is not used
  189.      * @var int $myTemplateId 
  190.      */
  191.     protected $myTemplateId 0;
  192.         
  193.     /**
  194.      * did we get the contents?
  195.      * 
  196.      * if no OCSP_CMS_HTMLPAGE will set Templatevar PAGECONTENT
  197.      * @var boolean $contentWasCalled 
  198.      */
  199.     protected $contentWasCalled False;
  200.     
  201.     /**
  202.      * timestamp the myChapterList has been populated
  203.      * 
  204.      * @var double $chapterListPopulated 
  205.      */
  206.     protected $chapterListPopulated 0;
  207.     
  208.     // ---------------------------------------------------------------------------
  209.     // factory / construct
  210.     // ---------------------------------------------------------------------------
  211.         
  212.     /**
  213.      * factory a new page object form $_GET
  214.      *
  215.      * @param boolean $force (always return a page object even if no id is set)
  216.      * @param boolean $debug 
  217.      * 
  218.      * @return CMS_PAGE 
  219.      */
  220.     public static function factoryFromQueryString($force=false,$debug=false)
  221.     {
  222.         if ($debugechoDebugMethod(__FILE__,'(static)','CMS_PAGE::factoryFromQueryString()');
  223.  
  224.         if (isset($_GET[CMS_TABLEOBJ::getPageIdGetName()]&& intval($_GET[CMS_TABLEOBJ::getPageIdGetName()]))
  225.         {
  226.             return self::factoryFromId(intval($_GET[CMS_TABLEOBJ::getPageIdGetName()]),$force,$debug);
  227.         else if ((isset($_GET[CMS_TABLEOBJ::getPageIdColName()]&& intval($_GET[CMS_TABLEOBJ::getPageIdColName()]))) {
  228.             return self::factoryFromId(intval($_GET[CMS_TABLEOBJ::getPageIdColName()]),$force,$debug);
  229.         }
  230.  
  231.         $int_projId (isset($_GET[CMS_TABLEOBJ::getProjIdGetName()]intval($_GET[CMS_TABLEOBJ::getProjIdGetName()](isset($_GET[CMS_TABLEOBJ::getProjIdColName()]intval($_GET[CMS_TABLEOBJ::getProjIdColName()]0));            
  232.            $int_menId  (isset($_GET[CMS_TABLEOBJ::getMenuIdGetName()]intval($_GET[CMS_TABLEOBJ::getMenuIdGetName()](isset($_GET[CMS_TABLEOBJ::getMenuIdColName()]intval($_GET[CMS_TABLEOBJ::getMenuIdColName()]0));            
  233.  
  234.            $obj_db OCSP_OBJ::defaultReadDBObj();
  235.            
  236.            $arr_filter array(
  237.                CMS_TABLEOBJ::getProjIdColName(=> $int_projId,
  238.                CMS_TABLEOBJ::getMenuIdColName(=> $int_menId
  239.            );
  240.         
  241.            if ($arr_pages $obj_db->getArray(CMS_TABLEOBJ::getPageTable(),$arr_filter,0,0,CMS_TABLEOBJ::getPageSortColName(),$debug))
  242.            {
  243.                if ($debugechoDebugLine(__FILE__,__LINE__,"Pages: <pre>" print_r($arr_pages,True"</pre>");
  244.                if ((sizeof($arr_pages== 1|| $force)
  245.                {
  246.                    return CMS_PAGE::factoryFromDBRow($arr_pages[0],$debug);    
  247.                }               
  248.            }
  249.                       
  250.         if ($force)
  251.         {
  252.             $obj_ret new CMS_PAGE();
  253.             $obj_ret->setProjId($int_projId);
  254.             $obj_ret->setMenId($int_menId);            
  255.         else {
  256.             return NULL;
  257.         }        
  258.     }    
  259.     
  260.     /**
  261.      * factory a page object from an id
  262.      *
  263.      * @param int $aId 
  264.      * @param boolean $force (always return a page object eaven if not found)
  265.      * @param boolean $debug 
  266.      * 
  267.      * @return CMS_PAGE | Null
  268.      * 
  269.      */    
  270.     public static function factoryFromId($aId,$force=false,$debug=false)
  271.     {
  272.         if ($debugechoDebugMethod(__FILE__,'(static)',"CMS_PAGE::factoryFromId();");
  273.                 
  274.         if (intval($aId)) 
  275.         {
  276.             if ($arr_row OCSP_CMS_CACHE::getInstance()->getPageRow($aId))
  277.             {
  278.                 if ($debugechoDebugLine(__FILE__,__LINE__,"using cached value");
  279.                 return self::factoryFromDBRow($arr_row,$debug);
  280.             else if ($arr_row OCSP_OBJ::defaultReadDBObj()->getRow('T_CMS_PAGE',array('PAG_ID'=>intval($aId)))) {
  281.                 if ($debugechoDebugLine(__FILE__,__LINE__,"using db value");
  282.                 return self::factoryFromDBRow($arr_row,$debug);
  283.             }
  284.         }
  285.         
  286.         if ($force)
  287.         {
  288.             $obj_ret new CMS_PAGE();
  289.             $obj_ret->setId($aId);
  290.             return $obj_ret;
  291.         }
  292.            
  293.            return Null;
  294.     }
  295.   
  296.     /**
  297.      * factories a page and sets the project ?????
  298.      *
  299.      * @param CMS_PROJECT $aProj 
  300.      * @param int $aId 
  301.      * @param boolean $force 
  302.      * @param boolean $debug 
  303.      * 
  304.      * @return CMS_PAGE 
  305.      */
  306.     public static function factoryProjectPage(&$aProj,$aId,$force=False,$debug=False)
  307.     {
  308.         if ($obj_ret self::factoryFromId($aId,False,$debug))
  309.         {
  310.             if (is_object($aProj))
  311.             {
  312.                 if ($obj_ret->getProjId(== $aProj->getId())
  313.                 {
  314.                     $obj_ret->setMyProject($aProj);
  315.                     return $obj_ret;        
  316.                 }
  317.             }
  318.         }
  319.     }
  320.     
  321.     /**
  322.      * faktories the page object form the db row
  323.      *
  324.      * @param array $dbRow 
  325.      * @param boolean $debug 
  326.      * 
  327.      * @return CMS_PAGE 
  328.      * 
  329.      * @todo CMS_PAGE_V2 is used
  330.      */
  331.     public static function factoryFromDBRow($dbRow,$debug=False)
  332.     {       
  333.         if ($debugechoDebugMethod(__FILE__,"(static)","CMS_PAGE::factoryFromDBRow()",print_r($dbRow,True));
  334.         if (!isset($dbRow['PAG_OBJCLASS']|| ($dbRow['PAG_OBJCLASS']=='CMS_PAGE'))
  335.         {
  336.             $dbRow['PAG_OBJCLASS'"CMS_PAGE_V2";
  337.         }
  338.         
  339.         if (!CMS_TABLEOBJ::pageType_requireClass($dbRow['PAG_OBJCLASS'],$debug))
  340.         {
  341.             throw new Exception(_OCSP_EXCEP_NOINCLUDE_ ":" $dbRow['PAG_OBJCLASS'"<pre>" print_r($dbRow,True"</pre>");
  342.         }
  343.         
  344.         $obj_ret new $dbRow['PAG_OBJCLASS']();  
  345.         $obj_ret->setDBRow($dbRow,True);
  346.         
  347.         return $obj_ret;        
  348.     }
  349.         
  350.     
  351.     /*** getter / setter ---------------------------------------------- */
  352.     
  353.     /**
  354.      * returns the page id
  355.      *
  356.      * @return int 
  357.      */
  358.     public function getId()
  359.     {
  360.         return intval($this->getDBField('PAG_ID'));
  361.     }
  362.     
  363.     /**
  364.      * sets the page id
  365.      *
  366.      * @param int $aId 
  367.      */
  368.     public function setId($aId)
  369.     {
  370.         $this->setDBField('PAG_ID',intval($aId));
  371.     }
  372.     
  373.     /**
  374.       * returns the page title
  375.       *
  376.       * @returns string
  377.       *
  378.       *
  379.       */
  380.     public function getTitle($debug=False
  381.     {
  382.         $str_ret OCSP_CONF::getInstance('CMS')->getValue('PAGETITLE_PREPEND');
  383.         
  384.         $str_title=$this->getDBField('PAG_TITLE');
  385.         if (empty($str_title)) {
  386.             $this->getMyMenuNode();
  387.             $str_title=$this->myMenuNode->getTitle();
  388.         }
  389.         $str_ret.=$str_title;
  390.         
  391.         $str_ret .= OCSP_CONF::getInstance('CMS')->getValue('PAGETITLE_APPEND');
  392.         return $str_ret;
  393.     }    
  394.     
  395.     /**
  396.       * returns the page state id
  397.       *
  398.       * @returns int
  399.       */
  400.     public function getStateId(
  401.     {
  402.         return intval($this->getDBField('PAG_STATE'));
  403.     }       
  404.     
  405.     /**
  406.      * has the method getContent been called?
  407.      *
  408.      * @return boolean 
  409.      */
  410.     public function getContentCalled()
  411.     {
  412.         return $this->contentWasCalled;
  413.     }
  414.     
  415.     /**
  416.      * sets contentWasCalled
  417.      *
  418.      * @param boolean $called 
  419.      */
  420.     public function setContentCalled($called='True')
  421.     {
  422.         $this->contentWasCalled=$called;
  423.     }
  424.           
  425.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  426.     // db methods
  427.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  428.         
  429.     /**
  430.       * returns a array of variables used by the page object
  431.       *
  432.       * array[varName]=array(
  433.       *     [TYPE]          datatype
  434.       *     [FLDCLASS]      name of DBMS_FIELD* class
  435.       *     [CLASSVALS]     array of values of [FLDCLASS]
  436.       *
  437.       * @returns array
  438.       * 
  439.       * @abstract
  440.       */
  441.     protected function getObjVarDef($debug=False
  442.     {
  443.           if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getObjVarDef");
  444.         $arr_ret array();
  445.         return $arr_ret;
  446.     }
  447.     
  448.     /**
  449.       * returns a field => value array
  450.       *
  451.       * make sure to not include some special values
  452.       * and object columns are serialised
  453.       *
  454.       * @param boolean $withoutNull  null values are not added to the array
  455.       * @param boolean $debug        show debug info?
  456.       * @param boolean $withoutOV 
  457.       * @param boolean $fldAutoPopulate 
  458.       *
  459.       * @returns array
  460.       *
  461.       */
  462.     public function getDBRow($withoutNull=True,$debug=False,$withoutOV=False,$fldAutoPopulate=True
  463.     {
  464.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getDBRow(".($withoutNull "without NULL" "with NULL").")");
  465.         $arr_ret=parent::getDBRow($withoutNull,$debug,$withoutOV,$fldAutoPopulate);
  466.  
  467.         if (($arr_objVars=$this->getObjVarDef()) && is_array($arr_objVars)) {
  468.             $arr_vars=array();
  469.             foreach($arr_objVars as $key => $descArr
  470.             {
  471.                 if ($debugecho "<p>Setting Key$key</p>";
  472.  
  473.                 if (isset($this->{$key})) 
  474.                 {
  475.                     $arr_vars[$key]=$this->{$key};
  476.                 }                 
  477.             }
  478.             $arr_ret['PAG_OBJECTVARS']=serialize($arr_vars);
  479.         }
  480.         return $arr_ret;
  481.     }
  482.  
  483.     /**
  484.       * sets a database row to the object fields
  485.       *
  486.       * sets each key (=columname) value
  487.       *
  488.       * @param  array $row            the row form a select * from DBMS_TABLEOBJ::myTable
  489.       * @param  bool $asPopulated    set populateTS as if the object has been populated
  490.       * @param  bool $debug 
  491.       *
  492.       * @returns boolean
  493.       *
  494.       */
  495.     public function setDBRow($row,$asPopulated=True,$debug=False
  496.     {    
  497.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::setDBRow()");
  498.         if (parent::setDBRow($row,$asPopulated,$debug)) 
  499.         {
  500.             $arr_objVarVals=@unserialize($row['PAG_OBJECTVARS']);
  501.             if (is_array($arr_objVarVals)) {
  502.                 foreach($arr_objVarVals as $key => $val{
  503.                     $this->{$key}=$val;
  504.                 }
  505.             else {
  506.                 if ($debugocsp_logError(__FILE__,__LINE__,"unserialize of <pre>--\n{$row['PAG_OBJECTVARS']}\n--</prefailed",E_NOTICE);
  507.             }
  508.             return True;
  509.         else {
  510.             return False;
  511.         }
  512.     }    
  513.     
  514.     /**
  515.       * sets all fields of an array to the objcet
  516.       *
  517.       * @param array $valArr 
  518.       * @param boolean $debug 
  519.       *
  520.       * @return boolean 
  521.       *
  522.       */
  523.     public function setDBVal($valArr,$debug=False
  524.     {
  525.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::setDBVal()",print_r($valArr,True));
  526.  
  527.         $arr_objVar=$this->getObjVarDef();
  528.         if (is_array($arr_objVar)) {
  529.             if ($debugechoDebugLine(__FILE__,__LINE__,"setting PageObjVals");
  530.             foreach($arr_objVar as $key => $descArr{
  531.                 if ($debugechoDebugLine(__FILE__,__LINE__,"setting PageObjVal $key to".htmlspecialchars($valArr[$key]));
  532.                 $this->{$key}=$valArr[$key];               
  533.                 unset($valArr[$key]);
  534.             }
  535.         }
  536.         return parent::setDBVal($valArr,$debug);
  537.     }
  538.     
  539.     /**
  540.       * returns a field => value array for dbms
  541.       *
  542.       * use this in cms and dbms elements to get
  543.       * $DBVAL array
  544.       *
  545.       * overwrite this and add some special values
  546.       * for objects if needed
  547.       *
  548.       * @see dbms
  549.       *
  550.       * @param bool $setFIELDS    if true $ret['_DBMS_FIELDS'] is filled
  551.       * @param bool $debug        show debug info?
  552.       *
  553.       * @returns array
  554.       *
  555.       */
  556.     public function getDBVal($setFIELDS=False,$debug=False
  557.     {
  558.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE_V2::getDBVal()",($setFIELDS "SET FIELDS" ""));
  559.  
  560.         $arr_ret=parent::getDBVal($setFIELDS,$debug);
  561.  
  562.         $arr_objVar=$this->getObjVarDef();
  563.         if (is_array($arr_objVar)) {
  564.             $c_sep=(sizeof($arr_ret',' '');
  565.             foreach($arr_objVar as $key => $descArr
  566.             {
  567.                 if (isset($this->{$key})) 
  568.                     $arr_ret[$key]=$this->{$key};
  569.                 else {
  570.                     $arr_ret[$key]=Null;
  571.                 }
  572.             }
  573.         }
  574.         
  575.         if (!isset($arr_ret['PAG_OBJCLASS']|| empty($arr_ret['PAG_OBJCLASS']))
  576.         {
  577.             $arr_ret['PAG_OBJCLASS']=get_class($this);
  578.         }
  579.         
  580.         return $arr_ret;
  581.     }
  582.     
  583.     
  584.     /**
  585.       *
  586.       * @param boolean $debug  show debug info
  587.       * @param boolean $ignorPopulated 
  588.       *
  589.       * @returns boolean
  590.       *
  591.       */
  592.     function dbReplace($debug=false,$ignorPopulated=false{
  593.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::dbReplace(...)");
  594.  
  595.         $this->setDBField('PAG_LASTCHANGE_BY',OCSP_OBJ::currentUser()->getId());
  596.         $this->setDBField('PAG_LASTCHANGE',"CURRENT_TIMESTAMP");
  597.         
  598.         $str_storedClass=$this->getDBField('PAG_OBJCLASS');
  599.         if (empty($str_storedClass))
  600.         {
  601.             if (CMS_TABLEOBJ::pageType_getClassSrc(get_class($this)))
  602.             {
  603.                 $this->setDBField('PAG_OBJCLASS',get_class($this));
  604.             else {
  605.                 $this->setDBField('PAG_OBJCLASS',"CMS_PAGE");
  606.             }
  607.         else if (!$str_storedClass == get_class($this)) {
  608.             if (!(CMS_TABLEOBJ::pageType_getClassSrc(get_class($this))))
  609.             {
  610.                 throw new Exception(_OCSP_EXCEP_NOINCLUDE_.":".get_class($this));
  611.             }            
  612.         }  
  613.         
  614.         OCSP_CMS_CACHE::getInstance()->clearPageCache($this,$debug);
  615.         return parent::dbReplace($debug,$ignorPopulated);
  616.     }    
  617.     
  618.     /*** form / editing ----------------------------------------------- */
  619.     
  620.     /**
  621.      * returns the page form name
  622.      *
  623.      * @return string 
  624.      */
  625.     public function getFormName()
  626.     {
  627.         return "PAGEFORM_".strtoupper(get_class($this));
  628.     }    
  629.     
  630.     /**
  631.      * returns the form for the page
  632.      *  
  633.      * @param int $mode (form mode)
  634.      * @param string $frmName 
  635.      * @param string $frmClass 
  636.      * @param boolean $debug 
  637.      *
  638.      * @return CMS_PAGE_FORM 
  639.      * 
  640.      * @requires CMS_PAGE_FORM
  641.      * 
  642.      * @version pk-08-08-11
  643.      */
  644.     public function &getForm($mode=FRM_MODE_READONLY,$frmName='',$frmClass='CMS_PAGE_FORM',$debug=False)
  645.     {                      
  646.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getForm(".$frmName.")");
  647.                 
  648.         if (empty($frmClass|| ($frmClass == 'CMS_PAGE_FORM')) 
  649.         {
  650.             $frmClass='CMS_PAGE_FORM';
  651.             pcf_require_class('CMS_PAGE_FORM',dirname(__FILE__)._OCSP_DIRSEP_."CMS_PAGE_FORM.phpclass");
  652.         }
  653.         
  654.         if (!class_exists($frmClass))
  655.         {
  656.             throw new Exception(_OCSP_EXCEP_CLASSNOTFOUND_ ":" $frmClass);
  657.         }
  658.                     
  659.         if (empty($frmName))
  660.         {  
  661.             $frmName=$this->getFormName();
  662.         }
  663.  
  664.         $obj_form=OCSP_FORM::factory_from_Name($frmName,$frmClass,$debug);
  665.  
  666.         if (!intval($obj_form->getId()))
  667.         {
  668.             if ($debugechoDebugLine(__FILE__,__LINE__,"generating new form");
  669.             
  670.             if ($obj_form parent::getForm($mode,Null,$frmClass,$debug)) 
  671.             {
  672.                 $obj_form->setId(0)
  673.                 $obj_form->setName($frmName);                
  674.             else {
  675.                 throw new Exception(_OCSP_EXCEP_NOFORM_ ":" $frmName);    
  676.             }            
  677.             $b_toSave True;
  678.         else {
  679.             $b_toSave False;
  680.         }
  681.         
  682.         $arr_objVars=$this->getObjVarDef();
  683.         if ($debugechoDebugLine(__FILE__,__LINE__,"\$objVars: (".get_class($this).")<pre>".print_r($arr_objVars,True)."</pre>");
  684.  
  685.         foreach($arr_objVars as $str_key => $arr_descArr)
  686.         {
  687.             if (!($obj_form->getField("PAGEOBJVAL.".$str_key,$debug)))
  688.             {
  689.                 $arr_fldValues=$arr_descArr['CLASSVALS'];                    
  690.                     
  691.                 if (!isset($arr_fldValues['myTable'])) $arr_fldValues['myTable']='PAGEOBJVAL';
  692.                 if (!isset($arr_fldValues['myTableAlias'])) $arr_fldValues['myTableAlias']='PAGEOBJVAL';
  693.                     
  694.                 $arr_dbDesc=array(
  695.                            'TYPE'  => $arr_descArr['TYPE'],
  696.                         'NULL'  => False,
  697.                         'TABLE' => $arr_fldValues['myTable'// <pk-08-06-17 />
  698.                     );
  699.                     
  700.                 if ($obj_field=$obj_form->factory_field($str_key,$arr_descArr['FLDCLASS'],$arr_dbDesc,$arr_fldValues,$debug))
  701.                 {
  702.                     $obj_block=$obj_form->getBlock(0);
  703.                     $obj_block->addFieldObj($obj_field,$debug);
  704.                     if ($debugechoDebugLine(__FILE__,__LINE__,"Field ".$obj_field->getKey()." generated");
  705.                     $b_toSave=True;
  706.                  else {
  707.                     ocsp_logError(__FILE__,__LINE__,"opjVar Field$str_key not in form: <strong>".$obj_form->getName()."</strong><pre>".print_r($arr_descArr,True)."</pre>");
  708.                 }
  709.             }
  710.          }
  711.         
  712.          if ($b_toSave)
  713.         {
  714.             $obj_form->storeToDb($debug);
  715.           }
  716.  
  717.         $obj_form->setMyTblObj($this);
  718.         $str_classSrc $this->get_mySourceFile();
  719.         if (!empty($str_classSrc&& strstr($str_classSrc,get_class($this)))
  720.         {
  721.             $obj_form->setTblObjInc($str_classSrc);
  722.             $obj_form->setTblObjClass(get_class($this));                
  723.           else if (!empty($this->myClassSrcFile)) {
  724.             $obj_form->setTblObjInc($this->myClassSrcFile);
  725.                $obj_form->setTblObjClass(get_class($this));
  726.         else {
  727.             ocsp_logError(__FILE__,__LINE__,"no source file for " get_class($this" (" $str_classSrc ");",E_WARNING);
  728.         }            
  729.             
  730.           $obj_form->setMyTblObj($this);
  731.         $str_classSrc $this->get_mySourceFile();
  732.         if (!empty($str_classSrc&& strstr($str_classSrc,get_class($this)))
  733.         {
  734.             $obj_form->setTblObjInc($str_classSrc);
  735.             $obj_form->setTblObjClass(get_class($this));                
  736.         else if (!empty($this->myClassSrcFile)) {
  737.             $obj_form->setTblObjInc($this->myClassSrcFile);
  738.             $obj_form->setTblObjClass(get_class($this));
  739.         else {
  740.               ocsp_logError(__FILE__,__LINE__,"no source file for " get_class($this" (" $str_classSrc ");",E_WARNING);
  741.         }
  742.         $obj_form->setFrmMode($mode);            
  743.  
  744.         return $obj_form;                
  745.     }
  746.  
  747.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  748.     /* chapter methods                                                          */
  749.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  750.     
  751.     /**
  752.      * returns a new chapter object
  753.      * 
  754.      * @param int $tmplId 
  755.      * 
  756.      * @return CMS_CHAPTER 
  757.      * 
  758.      * @since pk-08-01-14
  759.      * 
  760.      */
  761.     function getNewChapter($tmplId,$debug=False)
  762.     {
  763.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getNewChapter()");
  764.            
  765.         $obj_chapter $this->getTemplate()->getChapterTemplate($tmplId,$debug)->getChaObj(0,$debug);
  766.         $obj_chapter->setMyPageObj($this);
  767.         $obj_chapter->setProjId($this->getProjId());
  768.         $obj_chapter->setMenId($this->getMenId());       
  769.         $obj_chapter->setPageId($this->getId());
  770.         
  771.         return $obj_chapter;
  772.         
  773.     }    
  774.     
  775.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  776.     // rights and state
  777.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  778.  
  779.     /**
  780.      * returns if the page is the current page
  781.      *
  782.      * @param boolean $debug 
  783.      * @return boolean 
  784.      * 
  785.      * @since pk-08-07-25
  786.      */
  787.     public function isCurrent($debug=False)
  788.     {
  789.         if (($obj_page=CMS_TABLEOBJ::get_currentPage()) && ($obj_page->getId(== $this->getId()))
  790.         {
  791.             return True;
  792.         }
  793.         return False;
  794.     }
  795.     
  796.     /**
  797.       * returns if the current page is online
  798.       *
  799.       * @param boolean $debug 
  800.       *
  801.       * @global array  $OCSP_CONF 
  802.       *
  803.       * @return boolean 
  804.       * @access public
  805.       * @since pk-07-06-07
  806.       * @version pk-08-07-25
  807.       */
  808.     public function isOnline($debug=False)
  809.     {
  810.         if ($arr_states OCSP_CMS_CONF::getInstance()->getValue('PAGESTATE'))
  811.         {
  812.             $int_stateId $this->getStateId();
  813.             if (isset($arr_states[$int_stateId]))
  814.             {
  815.                 $arr_myState $arr_states[$int_stateId];
  816.                 if (!($bol_chkShow $arr_myState['SHOW']))
  817.                 {
  818.                     $bol_chkShow ($this->isCurrent(&& $arr_myState['DIRECTSHOW']);
  819.                 
  820.                 
  821.                 if (!$bol_chkShow)
  822.                 {
  823.                       if ($debugechoDebugLine(__FILE__,__LINE__,'page is not in online state');
  824.                       return False;                    
  825.                 }
  826.                 
  827.                      pcf_require_class('OCSP_DATE','common/');
  828.                   $obj_date new OCSP_DATE();
  829.                   $obj_date->setDbString($this->getDBField('PAG_SHOWFROM'));
  830.                   if ($obj_date->isInFutur())
  831.                   {
  832.                       if ($debugechoDebugLine(__FILE__,__LINE__,"page will come in future");
  833.                       return False;
  834.                   }
  835.                   
  836.                   if ($this->isExpired())
  837.                   {
  838.                       if ($debugechoDebugLine(__FILE__,__LINE__,"page is expired");
  839.                       return False;
  840.                   }                
  841.  
  842.                   $str_showQuery $this->getDBField('CHA_SHOWQUERY');
  843.                   if (!empty($str_showQuery))
  844.                   {
  845.                       $mix_ret OCSP_OBJ::defaultReadDBObj()->getOne("SELECT " $str_showQuery);
  846.                       if (empty($mix_ret))
  847.                       {
  848.                           if ($debugechoDebugLine(__FILE__,__LINE__,"Show Query: <br />SELECT " $str_showQuery "<br /> failed");
  849.                           return False;
  850.                       }
  851.                   }
  852.                   return True;
  853.             }
  854.         else {
  855.             throw new Exception(_OCSP_EXCEP_NOTCONFIGURED_.":PAGESTATE");
  856.         }
  857.         
  858.         return False;
  859.     }
  860.     
  861.     /**
  862.      * returns if the page is expired
  863.      * (PAG_SHOWTILL < NOW())
  864.      *
  865.      * @param boolean $debug 
  866.      * 
  867.      * @return boolean 
  868.      */
  869.     public function isExpired($debug=False)
  870.     {
  871.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::isExpired()");
  872.         
  873.         pcf_require_class('OCSP_DATE','common/');
  874.         $obj_date new OCSP_DATE();        
  875.         $obj_date->setDbString($this->getDBField('PAG_SHOWTILL'));
  876.         if ($obj_date->isInPast())
  877.         {
  878.             if ($debugechoDebugLine(__FILE__,__LINE__,"page is out of date");
  879.             return True;
  880.           else {
  881.               return False;         
  882.           }
  883.     }
  884.  
  885.     /**
  886.       * returns if the current user can open the page
  887.       *
  888.       * @param boolean $debug 
  889.       *
  890.       * @return boolean 
  891.       *
  892.       * @since pk-06-11-12
  893.       *
  894.       ***/
  895.     function curUserCanOpen($debug=False
  896.     {
  897.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE_V2::curUserCanOpen()");
  898.  
  899.         $this->getMyMenuNode()// ensure $this->myMenuNode is up to date;
  900.         if ($this->myMenuNode->curUserCanOpen($debug)) {
  901.             if (!intval($this->getDBField('PAG_SHOWGROUP'))) {
  902.                 // the page is public
  903.                 return True;
  904.             else {                
  905.                 if (OCSP_OBJ::currentUser()->isGroupMember($this->getDBField('PAG_SHOWGROUP'))) 
  906.                 {
  907.                     return True;
  908.                 }
  909.                 return $this->curUserCanEdit();
  910.             }
  911.         else {
  912.             return False;
  913.         }
  914.     }
  915.  
  916.     /**
  917.       * returns if the user can edit the page
  918.       *
  919.       * @param boolean $debug 
  920.       *
  921.       * @return boolean 
  922.       *
  923.       * @since pk-05-09-01
  924.       * @version pk-07-05-07
  925.       *
  926.       ***/
  927.     function curUserCanEdit($debug=False{       
  928.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::curUserCanEdit()");
  929.  
  930.         if (OCSP_OBJ::currentUser()->isPublic()) return False;
  931.         if (OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_CMSADMIN_)) return True;
  932.  
  933.         $this->getMyMenuNode($debug);
  934.         if ($this->isOnline())
  935.         {
  936.             if (intval($this->getDBField("PAG_EDITORGRP"))
  937.                 && OCSP_OBJ::currentUser()->isGroupMember($this->getDBField("PAG_EDITORGRP")))
  938.             {
  939.                 return True;
  940.             }
  941.             return $this->myMenuNode->curUserCanEdit($debug);
  942.         else {
  943.             if (intval($this->getDBField("PAG_EDITORGRP"))
  944.                 && OCSP_OBJ::currentUser()->isGroupMember($this->getDBField("PAG_EDITORGRP")))
  945.             {
  946.                 return True;
  947.             }
  948.             return $this->myMenuNode->curUserCanEdit($debug);
  949.         }
  950.  
  951.         return False;
  952.     }
  953.  
  954.     /**
  955.       * returns if the user can insert a new page
  956.       *
  957.       * @param boolean $debug 
  958.       *
  959.       * @return boolean 
  960.       * @access public
  961.       *
  962.       * @since pk-07-05-07
  963.       */
  964.     function curUserCanInsert($debug=False)
  965.     {   
  966.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::curUserCanInsert()");    
  967.         $this->getMyMenuNode($debug);
  968.         
  969.         if (!intval($this->myMenuNode->getId()))
  970.         {
  971.             var_dump($this->getMyProject());
  972.         }
  973.                 
  974.         if ($this->myMenuNode->curUserCanAddPage())
  975.         {
  976.             return True;
  977.         else {
  978.             return False;
  979.         }
  980.     }
  981.  
  982.     /**
  983.      * returns if the current user can delete the page
  984.      *
  985.      * @param boolean $debug 
  986.      * 
  987.      * @return boolean 
  988.      */
  989.     function curUserCanDelete($debug=False)
  990.     {
  991.         if ($debugechoDebugMethod(__FILE__,get_class($this),curUserCanDelete());
  992.         if ($this->curUserCanEdit($debug))        
  993.         {
  994.             return $this->getMyMenuNode()->curUserCanAddPage($debug);
  995.         
  996.         return False;
  997.     }
  998.  
  999.     // ---------------------------------------------------------------------------
  1000.     // navigation
  1001.     // ---------------------------------------------------------------------------
  1002.     
  1003.     /*** preview / editing ----------------------------------------------- */
  1004.     
  1005.     /**
  1006.      * returns the preview uri
  1007.      * 
  1008.      * @return string 
  1009.      *
  1010.      */
  1011.     public function getPreviewUri()
  1012.     {
  1013.         $str_ret "";
  1014.            if (file_exists($_SERVER['DOCUMENT_ROOT']."/index.php")) {
  1015.            $str_ret .= "/index.php";
  1016.         else if (file_exists($_SERVER['DOCUMENT_ROOT']."/content.php")) {
  1017.             $str_ret .= "/content.php";
  1018.         else {
  1019.             $str_ret .= "/cms/page.php";
  1020.         }    
  1021.  
  1022.         $str_ret .= "?" $this->myProjIdCol "=" $this->getProjId();
  1023.         $str_ret .= "&" $this->myMenuIdCol "=" $this->getMenId();
  1024.         $str_ret .= "&" $this->myPageIdCol "=" $this->getId();
  1025.         $str_ret .= "&PREVIEWMODE=1";
  1026.         $str_ret .= "&RL=" time("-" rand(100,900);
  1027.         
  1028.         return $str_ret;
  1029.     }    
  1030.     
  1031.     /**
  1032.       * returns the link to the page without additional get params
  1033.       *
  1034.       * @param boolean $debug 
  1035.       * 
  1036.       * @returns string
  1037.       *
  1038.       * @since pk-05-03-16
  1039.       * @version pk-05-11-30 $GLOBALS['OCSP_CMS']['PAGLINKTMPL'] if $GLOBALS['OCSP_CMS']['REWRITE']
  1040.       * @version pk-07-02-16 just ask the menu
  1041.       * @version pk-08-10-01 $arr_tmplVals for PAGLINKTMPL
  1042.       *
  1043.       */
  1044.     function getMyLink($debug=False{
  1045.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE_V2::getMyLink()");
  1046.  
  1047.         if (!empty($GLOBALS['OCSP_CMS']['PAGLINKTMPL'])) {
  1048.             // we have a template for a page set use this
  1049.             
  1050.             $arr_tmplVals $this->getDBVal(False);
  1051.             $arr_tmplVals['MEN_ID'$this->getMyMenuNode()->getKey();
  1052.             
  1053.             if ($debugechoDebugLIne(__FILE__,__LINE__,"using \$GLOBALS['OCSP_CMS']['PAGLINKTMPL']: " htmlspecialchars($GLOBALS['OCSP_CMS']['PAGLINKTMPL']"<pre>" print_r($arr_tmplVals,True"</pre>");
  1054.             pcf_require_class('OCSP_TEMPLATE',"common/");
  1055.            
  1056.             return OCSP_TEMPLATE::parse($GLOBALS['OCSP_CMS']['PAGLINKTMPL'],$arr_tmplVals);
  1057.         }
  1058.  
  1059.         $a_getVals=$_GET;
  1060.         $a_getVals['PROJ_ID']=$this->getProjId();
  1061.         $a_getVals['MEN_ID'=$this->getMyMenuNode()->getKey();
  1062.         $a_getVals['PAG_ID'=$this->getId();
  1063.  
  1064.         if ($o_myMenu=$this->getMyMenuNode()) {
  1065.             return $o_myMenu->getLinkUrl($a_getVals,$debug);
  1066.         else {
  1067.             $s_link="/";
  1068.             foreach($a_getVals as $s_key => $s_val{
  1069.                 $s_link=pcf_HTML_changeURI_GetValue($s_link,$s_key,$s_val);
  1070.             }
  1071.             return $s_link;
  1072.         }
  1073.     }
  1074.     
  1075.     // ---------------------------------------------------------------------------
  1076.     // output
  1077.     // ---------------------------------------------------------------------------
  1078.     
  1079.     /**
  1080.       * executes a prepend script before the page output starts
  1081.       *
  1082.       * @param boolean $debug 
  1083.       */ 
  1084.     function execPrependCmds($debug=False)
  1085.     {
  1086.         if ($debugechoDebugMethod(__FILE__,get_class($this),"<i>abstract</i> CMS_PHPINC_PAGE::execPrependCmds()");
  1087.     }    
  1088.     
  1089.     /*** HTML_PAGE  --------------------------------------------------- */
  1090.     
  1091.     /**
  1092.       * @param CMS_HTML_PAGE $aHTMLPage 
  1093.       */
  1094.     function setMyHTMLPage(&$aHTMLPage)
  1095.     {
  1096.         $this->myHTMLPage=$aHTMLPage;
  1097.     }
  1098.  
  1099.     /**
  1100.       * @return CMS_HTML_PAGE 
  1101.       */
  1102.     function getMyHTMLPage()
  1103.     {
  1104.         return $this->myHTMLPage;
  1105.     }      
  1106.     
  1107.     /*** templates ---------------------------------------------------- */
  1108.     
  1109.     /**
  1110.       * returns the template id
  1111.       * 
  1112.       * if col PTMP_ID is 0 the menu is asked for a template id
  1113.       *
  1114.       * @param boolean $debug 
  1115.       *
  1116.       * @return int 
  1117.       * @access public
  1118.       *
  1119.       * @since pk-07-06-07
  1120.       */
  1121.     public function getTemplateId($debug=False)
  1122.     {
  1123.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getTemplateId()");    
  1124.                 
  1125.         
  1126.         if (pcf_class_implements($this->myTemplate,'INFA_CMS_PAGE_TEMPLATE'))
  1127.         {
  1128.             return $this->myTemplate->getId();
  1129.         }
  1130.  
  1131.         if (intval($this->getDBField('PTMP_ID')))
  1132.         {
  1133.             return $this->getDBField('PTMP_ID');
  1134.         else {
  1135.             return $this->getMyMenuNode()->getTemplateId($debug);
  1136.         }
  1137.     }
  1138.     
  1139.     /**
  1140.      * returns the template object
  1141.      *
  1142.      * @param boolean $debug 
  1143.      * 
  1144.      * @return CMS_PAGE_TEMPLATE 
  1145.      */
  1146.     public function &getTemplate($debug=False)
  1147.     {        
  1148.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getTemplate()");
  1149.         if (!pcf_class_implements($this->myTemplate,'INFA_CMS_PAGE_TEMPLATE'))
  1150.         {
  1151.             $this->myTemplate CMS_PAGE_TEMPLATE::getInstance($this->getTemplateId(),$debug);            
  1152.         }
  1153.         
  1154.         if (!is_object($this->myTemplate))
  1155.         {
  1156.             //echoDebugLine(__FILE__,__LINE__,"no template set <pre>" . print_r($this->getDBRow(),True) . "</pre>");
  1157.             $this->myTemplate new CMS_PAGE_TEMPLATE();
  1158.         }
  1159.         return $this->myTemplate;        
  1160.     }
  1161.     
  1162.     /**
  1163.       * returns an array of chapter template names with chapter template ID as index
  1164.       * returns false if the page does not support chapter input
  1165.       *
  1166.       * @param bool $debug 
  1167.       * @param boolean $getAll 
  1168.       * 
  1169.       * @returns array
  1170.       *
  1171.       */
  1172.     public function getChaTemplates($debug=False,$getAll=False
  1173.     {
  1174.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getChaTemplates()");
  1175.  
  1176.         if ($this->getTemplate())
  1177.         {
  1178.             return $this->myTemplate->getChaTemplateNames($getAll,$debug)
  1179.         }        
  1180.     }    
  1181.  
  1182.       /*** chapters ---------------------------------------------------- */
  1183.     
  1184.     /**
  1185.       * returns a comma seperated list of chapter states to show
  1186.       *
  1187.       * @returns array
  1188.       *
  1189.       * @since pk-03-12-18
  1190.       * 
  1191.       * @version pk-07-09-11
  1192.       * @version pk-08-07-25
  1193.       * 
  1194.       */
  1195.     function getChapOnlineStates({
  1196.         $arr_ret=array();
  1197.       
  1198.         $arr_chaStates OCSP_CMS_CONF::getInstance()->getValue('CHAPTERSTATE');
  1199.         
  1200.         if (is_array($arr_chaStates))
  1201.         {
  1202.             foreach($arr_chaStates as $int_state => $arr_settings)
  1203.             {
  1204.                 if ($arr_settings['SHOW'])
  1205.                 {
  1206.                     $arr_ret[$int_state;    
  1207.                 }
  1208.             }
  1209.         }
  1210.         return $arr_ret;
  1211.     }    
  1212.     
  1213.     /**
  1214.      * populates $this->myChapterlist as sorted array
  1215.      * 
  1216.      * $this->my
  1217.      *
  1218.      * @param unknown_type $debug 
  1219.      */
  1220.     protected function populateChapterArr($debug=False)
  1221.     {       
  1222.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::populateChapterArr()");
  1223.         
  1224.         $str_query "SELECT * FROM T_CMS_CHAPTER";
  1225.         $str_query.= " WHERE PAG_ID = " $this->getId();
  1226.         $str_query.= " ORDER BY CHA_SHOWMODE,CHA_SORTORDER";
  1227.         
  1228.         $this->myChapterList array();
  1229.         if ($obj_cursor OCSP_OBJ::defaultReadDBObj()->query($str_query))
  1230.         {
  1231.             $obj_pageTmpl $this->getTemplate($debug);
  1232.             while($arr_row $obj_cursor->fetchArrayFld())
  1233.             {
  1234.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>" print_r($arr_row,True"</pre>");
  1235.                 
  1236.                 $int_sortOrder intval($arr_row['CHA_SORTORDER']);
  1237.                 while(isset($this->myChapterList[$arr_row['CHA_SHOWMODE']][$int_sortOrder]))
  1238.                 {
  1239.                     $int_sortOrder++;
  1240.                 }                                
  1241.                 $this->myChapterList[$arr_row['CHA_SHOWMODE']][$int_sortOrder$obj_pageTmpl->getChapterTemplate($arr_row['CTMP_ID'])->getChaObjFromRow($arr_row);
  1242.                 $this->myChapterList[$arr_row['CHA_SHOWMODE']][$int_sortOrder]->setOrderNr($int_sortOrder);
  1243.             }
  1244.         }
  1245.         
  1246.         $this->chapterListPopulated time();
  1247.         
  1248.     }
  1249.     
  1250.     /**
  1251.      * returns an array with the chapters
  1252.      *
  1253.      * @param int $showMode 
  1254.      * @param boolean $onlineOnly 
  1255.      * @param int $langId 
  1256.      * @param boolean $debug 
  1257.      * 
  1258.      * @return array 
  1259.      */
  1260.     public function getChapterArr($showMode=0,$onlineOnly=True,$langId=0,$debug=False)
  1261.     {
  1262.         if ($debugechoDebugMethod(__FILE__,get_class($this),'CMS_PAGE::getChapterArr');
  1263.         if ($this->chapterListPopulated (time(ini_get('max_execution_time')))
  1264.         {
  1265.             $this->populateChapterArr($debug);
  1266.         }
  1267.                 
  1268.            if (intval($showMode))
  1269.            {
  1270.                return $this->myChapterList[$showMode];
  1271.            else {
  1272.                // flatten the array
  1273.                $arr_ret array();
  1274.                foreach($this->myChapterList as $int_showMode => $arr_chapters)
  1275.                {
  1276.                    if (is_array($arr_chapters))
  1277.                    {
  1278.                        foreach($arr_chapters as $int_sort => &$obj_chapter)
  1279.                        {
  1280.                            $arr_ret[$int_showMode "_" $int_sort$obj_chapter;
  1281.                        }
  1282.                    }                    
  1283.                }
  1284.                return $arr_ret;
  1285.            }
  1286.     }
  1287.     
  1288.       /*** rendering ---------------------------------------------------- */
  1289.  
  1290.     /**
  1291.       * returns the headline HTML tags
  1292.       *
  1293.       * @param boolean $debug 
  1294.       * @return string 
  1295.       * @access public
  1296.       * 
  1297.       * @todo pageing
  1298.       */
  1299.     function getHeadlineTag($debug=False{
  1300.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getHeadLineTag()");
  1301.  
  1302.         /*
  1303.         if (!intval($this->prevId)) {
  1304.             $this->prevId=$this->getPreviousPage($debug);
  1305.         }
  1306.         if (!intval($this->nextId)) {
  1307.             $this->nextId=$this->getNextPage($debug);
  1308.         }
  1309.  
  1310.         if (!is_object($this->myTemplate)) {
  1311.             $this->loadTemplate($debug);
  1312.         }
  1313.         */
  1314.  
  1315.         $txt $this->getTemplate()->getHeadLineTag()."\n";
  1316.         $txt .=$this->getDBField("PAG_HEADER");
  1317.         /*
  1318.         if ($this->prevId) $txt=str_replace("\$*PREVPAGE\$",$this->prevId,$txt);
  1319.         if ($this->nextId) $txt=str_replace("\$*NEXTPAGE\$",$this->nextId,$txt);
  1320.         */
  1321.         return $txt;
  1322.     }    
  1323.  
  1324.     /**
  1325.      * returns the feeter tag
  1326.      *
  1327.      * @param boolean $debug 
  1328.      * 
  1329.      * @return string 
  1330.      * 
  1331.      * @todo pageing
  1332.      */
  1333.      function getFeeterTag($debug=False{
  1334.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PAGE::getFeeterTag()");
  1335.         
  1336.         $str_ret $this->getTemplate()->getFeeterTag();
  1337.         /*
  1338.         if ($this->prevId) $str_ret=str_replace("\$*PREVPAGE\$",$this->prevId,$txt);
  1339.         if ($this->nextId) $str_ret=str_replace("\$*NEXTPAGE\$",$this->nextId,$txt);
  1340.         */        
  1341.         return $str_ret;
  1342.      }
  1343.     
  1344.     
  1345.     /**
  1346.       * returns all chapter with $mode
  1347.       *
  1348.       *
  1349.       * @param int $mode 
  1350.       * @param boolean $debug 
  1351.       *
  1352.       * @returns string
  1353.       *
  1354.       * @version pk-05-04-01
  1355.       * @version pk-05-11-10
  1356.       *
  1357.       * @version pk-08-07-25
  1358.       * 
  1359.       */
  1360.     function renderChapters($mode=0,$debug=FALSE
  1361.     {       
  1362.         if ($debugechoDebugMethod(__FILE__,__LINE__,"CMS_PAGE::getChapterTags({$mode})");
  1363.         
  1364.         $str_ret "";
  1365.         if ($mode == 0)
  1366.         {
  1367.             $str_ret .= $this->renderChapters(CHAPTER_SHOWMODE_ALLWAYS_TOP,$debug);
  1368.             $str_ret .= $this->renderChapters(CHAPTER_SHOWMODE_ALLWAYS_BOTTOM,$debug)
  1369.             return $str_ret;
  1370.         }
  1371.         
  1372.         if ($this->chapterListPopulated (time(ini_get('max_execution_time')))
  1373.         {
  1374.             $this->populateChapterArr($debug);
  1375.         }
  1376.         
  1377.         if (isset($this->myChapterList[$mode]&& is_array($this->myChapterList[$mode]))
  1378.         {
  1379.             foreach($this->myChapterList[$modeas &$obj_chap)
  1380.             {
  1381.                 if ($obj_chap->isOnline($debug))
  1382.                 {
  1383.                     if ($obj_chap->curUserCanShow($debug))
  1384.                     {
  1385.                         if ($debugechoDebugLine(__FILE__,__LINE__,"<p>SHOW CHAPTER " $obj_chap->getId("</p>");
  1386.                         $str_ret .= "\n<!-- START CHAPTER " $obj_chap->getId(" -->\n";
  1387.                         $str_ret .= $obj_chap->render($debug);
  1388.                         $str_ret .= "\n<!-- END CHAPTER "$obj_chap->getId(." -->\n\n";                                                
  1389.                     }
  1390.                 }
  1391.             }
  1392.         }        
  1393.         
  1394.         return $str_ret;
  1395.         
  1396. /*
  1397.         if ($debug) echo "<p><b>CMS_PAGE_V2::getChapter($mode,...)</b> (".get_class($this).")</p>";
  1398.  
  1399.         $GLOBALS['CHAMODE_COUNTER']=1; // <pk-06-02-21
  1400.  
  1401.         require_once __OCSP_PHPINCPATH__."common/OCSP_DATE.phpclass";
  1402.  
  1403.         if (!$this->isConnected(TRUE))
  1404.         {
  1405.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1406.             return "";
  1407.         }
  1408.  
  1409.         $query ="SELECT * FROM ".$this->cTable;
  1410.         $query.=" WHERE ".$this->colPrevix."ID=".intval($this->getId());
  1411.         $query.=" AND ".$this->myProjIdCol."=".intval($this->getProjId());
  1412.         $query.=" AND LANG_ID=".intval($this->getLangId());
  1413.  
  1414.         $query.=" AND ".$this->chapPrevix."STATE IN (".implode(",",$this->getChapOnlineStates()).")";
  1415.  
  1416.         if ($debug) echo $query;
  1417.  
  1418.         if (!intval($mode))     $query.=" AND ".$this->chapPrevix."SHOWMODE < 4";
  1419.         else                    $query.=" AND ".$this->chapPrevix."SHOWMODE = $mode";
  1420.         $query.=" ORDER BY ".$this->chapPrevix."SORTORDER";
  1421.  
  1422.         $ret="";
  1423.         if ($cursor=$this->myDBObj->query($query)) {
  1424.             while($row=$cursor->fetchArray()) {
  1425.                 if ($debug) echo "<pre>".print_r($row,TRUE)."</pre>";
  1426.                 // <pk-04-09-08> 
  1427.                 $show=FALSE;
  1428.                 switch(intval($row[$this->chapPrevix.'SHOWGROUP'])) {
  1429.                     case 0:
  1430.                         $show=TRUE;
  1431.                         break;
  1432.                     case -2: // only not logged in
  1433.                         if ((!is_object($GLOBALS['OCSP_OBJ']['USER'])) || (!$GLOBALS['OCSP_OBJ']['USER']->getId())) $show=TRUE;
  1434.                         break;
  1435.                     case -1: // logged in user
  1436.                         if ($GLOBALS['OCSP_OBJ']['USER']->getId()) $show=TRUE;
  1437.                         break;
  1438.                     default:
  1439.                         $show=$GLOBALS['OCSP_OBJ']['USER']->isGroupMember(intval($row[$this->chapPrevix.'SHOWGROUP']));
  1440.                 }
  1441.  
  1442.                 // <pk-05-10-11>
  1443.                 if ($show && (!empty($row[$this->chapPrevix.'SHOWFROM']))) {
  1444.                     $o_ShowDate=new OCSP_DATE();
  1445.                     $o_ShowDate->setDateStr($row[$this->chapPrevix.'SHOWFROM']);
  1446.                     if ($o_ShowDate->isInFutur()) $show=FALSE;
  1447.                     if ($debug) echo "<p>SHOWFROM: ".$row[$this->chapPrevix.'SHOWFROM']." ".($show ? "OK" : "NOT OK")."</p>";
  1448.                 }
  1449.  
  1450.                 if ($show && (!empty($row[$this->chapPrevix.'SHOWTILL']))) {
  1451.                     $o_ShowDate=new OCSP_DATE();
  1452.                     $o_ShowDate->setDateStr($row[$this->chapPrevix.'SHOWTILL']);
  1453.                     if ($o_ShowDate->isInPast()) $show=FALSE;
  1454.                     if ($debug) echo "<p>SHOWTILL: ".$row[$this->chapPrevix.'SHOWTILL']." ".($show ? "OK" : "NOT OK")."</p>";
  1455.                 }
  1456.                 // </pk-05-10-11>
  1457.  
  1458.                 // <pk-05-04-01 >
  1459.                 if (($show) && (!empty($row[$this->chapPrevix.'SHOWQUERY']))) {
  1460.                     require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  1461.                     $cmd=pcf_tmpl_parse($row[$this->chapPrevix.'SHOWQUERY'],$row,$debug);
  1462.                     $query = "SELECT ".$cmd;
  1463.                     // $debug=TRUE; echo "<tr><td>"; foreach($_SESSION as $key => $val) echo "<li>$key = $val</li>"; echo "</td></tr>";
  1464.                     if ($debug) echo "<p>checkShowChapter(".$row[$this->chapPrevix.'ID'].") SHOWQUERY: \n$query</p>";
  1465.                     $show=intval($GLOBALS[$this->gDBIDX]->quickQuery($query,0));
  1466.                 }
  1467.                 // </ pk-05-04-01 >
  1468.  
  1469.                 if ($show) {
  1470.                 } else if (($this->curUserCanEdit()) && (intval($_GET['PREVIEWMODE']))) { // <pk-05-11-10>
  1471.                     $ret.="\n<div style=\"background-color: #AE3E2E; color:#FFFFFF\">\n";
  1472.                     $ret.="\n<p style=\"text-align:left;\">&gt;&gt;&gt;&gt;&gt; &nbsp;&nbsp;OFFLINE ID: ".$row[$this->colPrevix."ID"]."</p>";
  1473.                     $ret.="\n</div>\n";
  1474.                     $ret.=$this->getChapterTag($row);
  1475.                     $GLOBALS['CHAMODE_COUNTER']++; // <pk-06-02-21>
  1476.                     $ret.="\n<div style=\"background-color: #AE3E2E; color:#FFFFFF\">\n";
  1477.                     $ret.="\n<p style=\"text-align:right;\"> OFFLINE ID: ".$row[$this->colPrevix."ID"]." &nbsp; &nbsp; &lt;&lt;&lt;&lt;&lt;</p>";
  1478.                     $ret.="\n</div>\n";
  1479.  
  1480.                 }
  1481.                 // </pk-04-09-08>
  1482.  
  1483.             }
  1484.         }
  1485.         return $ret;
  1486. */
  1487.     }    
  1488.     
  1489.     
  1490.     /**
  1491.       * returns the content
  1492.       *
  1493.       * @param int $chaShowMode 
  1494.       * @param boolean $debug 
  1495.       *
  1496.       * @return string 
  1497.       *
  1498.       * @sice pk-07-08-18
  1499.       */
  1500.     function getContent($chaShowMode=0,$debug=False
  1501.     {
  1502.         $debug=($debug || (isset($_GET['CONTENTDEBUG']&& intval($_GET['CONTENTDEBUG']&& ($this->curUserCanEdit())));
  1503.         if ($debugechoDebugMethod(__FILE__,get_class($this),"<p>CMS_PAGE::content($chaShowMode)");
  1504.  
  1505.         if (($chaShowMode == 0&& $this->getContentCalled())
  1506.         {
  1507.             throw new Exception('content called twice');
  1508.         }
  1509.         
  1510.         $str_ret="";
  1511.         if ($chaShowMode==0)
  1512.         {
  1513.             if (method_exists($this,'getHeadlineTag'))
  1514.             {
  1515.                 $str_ret.= $this->getHeadlineTag($debug);
  1516.             }
  1517.         }
  1518.         ob_start();
  1519.         $str_ret.=$this->renderChapters($chaShowMode,$debug);
  1520.         $str_ret.=ob_get_contents();
  1521.         ob_end_clean();
  1522.  
  1523.         if ($chaShowMode==0)
  1524.         {
  1525.             $str_ret.= $this->getFeeterTag($debug);
  1526.             $this->setContentCalled(True);
  1527.         }        
  1528.         return $str_ret;
  1529.     }    
  1530.     
  1531. }
  1532.  
  1533. ?>

Documentation generated on Thu, 08 Jan 2009 17:39:33 +0100 by phpDocumentor 1.4.0a2