Source for file page.phpclass

Documentation is available at page.phpclass

  1. <?php
  2. /**
  3.   * Class file page.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   *
  8.   * @author     Peter Krebs <p.krebs@lvus.at>
  9.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @deprecated deprecated since version pk-03-12-x use CMS_PAGE_V2
  13.   *
  14.   ***/
  15.  
  16. require_once $GLOBALS['DEFAULTCONFPATH']."cms.conf.phpinc";
  17.  
  18. require_once $GLOBALS['PROJECT']['PHPINCPATH']."db/forms.phpclass";
  19. require_once $GLOBALS['CMS']['PHPINCPATH']."template/page/page.phpclass";
  20. require_once $GLOBALS['CMS']['PHPINCPATH']."template/chapter/chapter.phpclass";
  21. require_once $GLOBALS['CMS']['PHPINCPATH']."page/function.phpinc";
  22. // require_once $GLOBALS['CMS']['PHPINCPATH']."ms/cms_tableobj.phpclass";
  23.  
  24. /**
  25.   * class to handel PAGES
  26.   *
  27.   * major change to old version:
  28.   *
  29.   *     - the page don't hold a DB object only the GLOBAL INDEX is passed
  30.   *     - parent class is CMS_TABLEOBJ
  31.   *
  32.   * @project    Open CSP-Management
  33.   * @package    cms
  34.   *
  35.   * @author     Peter Krebs <p.krebs@lvus.at>
  36.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  37.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  38.   *
  39.   * @version    pk-03-10-24 parent changed DBMS_TBLOBJ -> CMS_TBLOBJ
  40.   *
  41.   * @deprecated deprecated since version pk-03-12-x use CMS_PAGE_V2
  42.   *
  43.   ***/
  44. class CMS_PAGE extends CMS_TABLEOBJ {
  45.     var $myTable = "T_CMS_PAGE";
  46.  
  47.     var $formObj=null;
  48.     var $dbRow  =array();
  49.     var $pageId =0;
  50.     var $projId =0;
  51.     var $langId =0;
  52.     var $myDB   =NULL;
  53.     var $myTmpl =NULL;
  54.     var $myForm =NULL;
  55.  
  56.     function CMS_PAGE($DB=NULL,$pageId=0,$projId=0,$langId=0,$menId=0,$debug=FALSE{
  57.         $DB=&$GLOBALS['USRDB'];
  58.         $this->init("USRDB");
  59.         $this->pageId=intval($pageId);
  60.         $this->projId=intval($projId);
  61.         $this->langId=intval($langId);
  62.         if (($this->checkDb($DB,$debug)) && (intval($pageId))) {
  63.             if ($this->loadFromDB($DB,$debug)) {
  64.                 $this->loadTemplate();
  65.             }
  66.         else {
  67.             $this->dbRow['PROJ_ID']=intval($projId);
  68.             $this->dbRow['LANG_ID']=intval($langId);
  69.             $this->dbRow['MEN_ID'=intval($menId);
  70.         }
  71.         if ($debugprint_r($this);
  72.     }
  73.  
  74.     function getClassName({
  75.         return "CMS_PAGE";
  76.     }
  77.     
  78.     function getObjVars({
  79.         return "";
  80.     }
  81.     
  82.     function getId({
  83.         return $this->pageId;
  84.     }
  85.     
  86.     function getDBField($fldName{
  87.         return $this->dbRow[$fldName];
  88.     }
  89.  
  90.     function setDBField($aField,$aValue{
  91.         $this->dbRow[$fldName]=$aValue;
  92.     }        
  93.     
  94.     function getDBRow({
  95.         return $this->dbRow;
  96.     }
  97.         
  98.     function setDB(&$DB{
  99.         $this->myDB=&$DB;
  100.     }
  101.  
  102.     function checkDb(&$DB,$debug=FALSE{
  103.         if (($DB&& (is_object($DB)) && ($DB->isConnected)) {
  104.             $this->myDB=&$DB;
  105.             if ($debugecho "<pre>DB SET 1</pre>";
  106.             return TRUE;
  107.         }
  108.  
  109.  
  110.         if (($this->myDB&& (is_object($this->myDB)) && ($this->myDB->isConnected)) {
  111.             if ($debugecho "<pre>DB ALREADY SET</pre>";
  112.             return TRUE;
  113.         }
  114.         if (is_object($GLOBALS['USER'])) {
  115.             if ($this->myDB=$GLOBALS['USER']->getDbObj()) {
  116.                 if ($debugecho "<pre>DB SET FROM USER</pre>";
  117.                 return TRUE;
  118.             }
  119.         }
  120.         if (is_object($GLOBALS['USRDB'])) {
  121.             $this->myDB=$GLOBALS['USRDB'];
  122.             return TRUE;
  123.         }
  124.  
  125.         if ($debugecho "<pre>NO DB SET</pre>";
  126.         return FALSE;
  127.     }
  128.  
  129.     function loadFromDB(&$DB,$debug=FALSE{
  130.         if (!$this->checkDB($DB)){
  131.             return FALSE;
  132.         }
  133.  
  134.         $query ="SELECT * FROM T_CMS_PAGE ";
  135.         $query.=" WHERE PROJ_ID=".$this->projId;
  136.         $query.=" AND PAG_ID=".$this->pageId;
  137.         $query.=" AND LANG_ID=".$this->langId;
  138.         if ($debugecho "<pre>$query</pre>";
  139.         return ($this->dbRow=$this->myDB->quickQuery($query));
  140.     }
  141.  
  142.     function setArray($arr,$debug=FALSE{
  143.         if ($debug{echo "<pre>";print_r($arr);echo "</pre>"}
  144.         $this->dbRow=$arr;
  145.         $this->pageId=intval($arr['PAG_ID']);
  146.         $this->projId=intval($arr['PROJ_ID']);
  147.         $this->langId=intval($arr['LANG_ID']);
  148.  
  149.         return $this->pageId;
  150.     }
  151.  
  152.  
  153.     function updateToDB($DB,$debug=FALSE{
  154.         if ((is_object($DB)) && ($DB->isConnected()) && ($this->pageId&& (sizeof($this->dbRow)>2)) {
  155.             return ($DB->replace("T_CMS_PAGE",$this->dbROW,$debug));
  156.         else {
  157.             return FALSE;
  158.         }
  159.     }
  160.  
  161.     ###############################################################
  162.  
  163.     function &getForm($debug=FALSE{
  164.         if (!$this->myForm{
  165.             $this->myForm=&DBMS_form_loadName("T_CMS_PAGE");
  166.         }
  167.         return $this->myForm;
  168.     }
  169.  
  170.     function writeADMForm($mode=FRM_MODE_NEW,$aktion=""{
  171.         if (!$this->myForm{
  172.             $frmObj=&$this->getForm();
  173.         else {
  174.             $frmObj=&$this->myForm;
  175.         }
  176.  
  177.         $DBVAL $this->dbRow;
  178.         if ($mode == FRM_MODE_NEW{
  179.             if (empty($aktion)) $aktion="insert.php";
  180.             
  181.             if (!strstr($aktion,"?")) $aktion .="?";
  182.             else $aktion .= "&";
  183.  
  184.             $frmAction=$aktion."PAGECLASS=".$this->getClassName();
  185.             $frmTitle="NEW PAGE";
  186.             
  187.             include $GLOBALS['PROJECT']['PHPINCPATH']."db/forms/new.phpinc";
  188.         }
  189.     }
  190.  
  191.     function getFormDateFromPost($arrName='DBVAL',$debug=FALSE{
  192.  
  193.     }
  194.  
  195.     ############################################################
  196.  
  197.     function loadTemplate($debug=FALSE{
  198.         if ($debugecho "<h1>loadTemplate</h1>";
  199.         if ((empty($this->dbRow['PTMP_ID'])) && (!$this->loadFromDB($this->myDB,$debug))) {
  200.             echo "<hr>NO ID's<hr>";
  201.             return FALSE;
  202.         }
  203.         $this->myTmpl=new CMS_PAGE_TEMPLATE($this->dbRow['PTMP_ID'],"",$this->projId);
  204.         if ($this->myTmpl->dbPopulate()) {
  205.             return TRUE;
  206.         else {
  207.             $this->myTmpl=NULL;
  208.             return FALSE;
  209.         }
  210.     }
  211.  
  212.     function getChaTemplates($debug=FALSE{
  213.         $DB=NULL;
  214.         if ((empty($this->dbRow['PTMP_ID'])) && (!$this->loadFromDB($DB,$debug))) {
  215.             return FALSE;
  216.         }
  217.  
  218.         $query ="SELECT CTMP_ID,CTMP_NAME FROM T_CMS_TMPL_CHAPTER WHERE PTMP_ID=".$this->dbRow['PTMP_ID'];
  219.         // Chapter Project link not used $query.=" AND PROJ_ID=".$this->dbRow['PROJ_ID'];
  220.  
  221.         if ($debugecho "<pre>".$query."</pre>";
  222.  
  223.         return $this->myDB->queryArray($query,0,1);
  224.     }
  225.  
  226.     // #########################################
  227.  
  228.     function getMenuId({
  229.         return intval($this->dbRow['MEN_ID']);
  230.     }
  231.  
  232.  
  233.     function getNextPage($debug=FALSE{
  234.         $DB=NULL;
  235.         if ((empty($this->dbRow['PAG_SORTORDER'])) && (!$this->loadFromDB($DB,$debug))) {
  236.             return FALSE;
  237.         }
  238.  
  239.         $query "SELECT PAG_ID FROM T_CMS_PAGE WHERE MEN_ID=".$this->dbRow['MEN_ID'];
  240.         $query.= " AND PROJ_ID=".$this->dbRow['PROJ_ID'];
  241.         $query.= " AND LANG_ID=".$this->dbRow['LANG_ID'];
  242.         $query.= " AND PAG_SORTORDER > ".$this->dbRow['PAG_SORTORDER'];
  243.         $query.= " AND PAG_SHOWFROM > NOW()";
  244.         $query.= " AND PAG_SHOWTILL < NOW()";
  245.         $query.= " AND PAG_STATE >= 2";
  246.  
  247.         return $this->myDB->quickQuery($query,0);
  248.     }
  249.  
  250.     function getPreviousPage($debug=FALSE{
  251.         $DB=NULL;
  252.         if ((empty($this->dbRow['PAG_SORTORDER'])) && (!$this->loadFromDB($DB,$debug))) {
  253.             return FALSE;
  254.         }
  255.  
  256.         if ($this->dbRow['PAG_SORTORDER'== 1return FALSE;
  257.  
  258.         $query "SELECT PAG_ID FROM T_CMS_PAGE WHERE MEN_ID=".$this->dbRow['MEN_ID'];
  259.         $query.= " AND PROJ_ID=".$this->dbRow['PROJ_ID'];
  260.         $query.= " AND LANG_ID=".$this->dbRow['LANG_ID'];
  261.         $query.= " AND PAG_SORTORDER < ".$this->dbRow['PAG_SORTORDER'];
  262.         $query.= " AND PAG_SHOWFROM > NOW()";
  263.         $query.= " AND PAG_SHOWTILL < NOW()";
  264.         $query.= " AND PAG_STATE >= 2";
  265.  
  266.         return $this->myDB->quickQuery($query,0);
  267.     }
  268.  
  269.     // ######################################
  270.     function preview($debug=FALSE{
  271.         if (!is_object($this->myTmpl)) {
  272.             if (!($this->loadTemplate($debug))) {
  273.                 $ERR="TEMPLATE_NOT_FOUND ".$query;
  274.                 include $GLOBALS['PROJECT']['PHPINCPATH']."io/errors.phpinc";
  275.                 die();
  276.             }
  277.         }
  278.         if ($debugprint_r($this->dbRow);
  279.         ?>
  280.             <!doctype public "-//w3c//dtd html 4.01 transitional//en"
  281.                 "http://www.w3.org/TR/html4/loose.dtd">
  282.             <html>
  283.             <head>
  284.                 <title><?php echo $this->dbRow['PAG_TITLE']?></title>
  285.                 <link type="text/css" rel="stylesheet" href="/cms/defaultStyles.php">
  286.                 <?php if intval($this->dbRow['STY_ID'])) {
  287.                     echo "<link type=\"text/css\" rel=\"stylesheet\"";
  288.                     echo " href=\"/cms/styles.php?STY_ID=".intval($this->dbRow['STY_ID']);
  289.                     echo "&PROJ_ID=".intval($this->dbRow['PROJ_ID']);
  290.                     echo "\">\n";
  291.                 ?>
  292.                 <?php echo $this->myTmpl->getMetaTag()?>
  293.                 <?php echo $this->myTmpl->getJavaScriptTag()?>
  294.             </head>
  295.         <?php
  296.  
  297.         echo $this->myTmpl->getBodyTag();
  298.         echo $this->myTmpl->getHeadLineTag();
  299.         echo $this->dbRow['PAG_HEADER'];
  300.  
  301.         $query ="SELECT * FROM T_CMS_CHAPTER ";
  302.         $query.=" WHERE PAG_ID=".intval($this->dbRow['PAG_ID']);
  303.         $query.=" AND PROJ_ID=".intval($this->dbRow['PROJ_ID']);
  304.         $query.=" AND LANG_ID=".intval($this->dbRow['LANG_ID']);
  305.         $query.=" ORDER BY CHA_SORTORDER";
  306.  
  307.         $chaTmplArr=array();
  308.         if ($cursor=$this->myDB->query($query)) {
  309.             while($row=$cursor->fetchArray()) {
  310.                 if (!is_object($chaTmplArr[$row['CTMP_ID']])) {
  311.                     $chaTmplArr[$row['CTMP_ID']]=new TMPL_CHAPTER (intval($this->dbRow['PROJ_ID']),intval($this->dbRow['PTMP_ID']),intval($row['CTMP_ID']));
  312.                     $chaTmplArr[$row['CTMP_ID']]->dbPopulateDB($this->myDB);
  313.                 }
  314.  
  315.                 echo $chaTmplArr[$row['CTMP_ID']]->getTag(unserialize($row['CHA_FIELDS']));
  316.  
  317.             }
  318.         }
  319.  
  320.  
  321.         echo $this->dbRow['PAG_FEETER'];
  322.         echo "<br />";
  323.         echo $this->myTmpl->getFeeterTag();
  324.         echo "</body>";
  325.         echo "</html>";
  326.  
  327.     }
  328.  
  329.     // ######################################
  330.     function getHead($withMenu=TRUE,$withStyles=FALSE,$debug=FALSE{
  331.         if (!is_object($this->myTmpl)) {
  332.             if (!($this->loadTemplate($debug))) {
  333.                 $ERR="TEMPLATE_NOT_FOUND ".$query;
  334.                 include $GLOBALS['PROJECT']['PHPINCPATH']."io/errors.phpinc";
  335.                 die();
  336.             }
  337.         }
  338.         if ($debugprint_r($this->dbRow);
  339.             
  340.  
  341.         $head ="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
  342.         $head.= "<html>\n";
  343.         $head.= "<head>\n";
  344.         $head.= "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n";
  345.         $head.= "<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\n";
  346.         $head.= "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">\n";
  347.         if (!intval($this->dbRow['PAG_ID'])) {
  348.             $this->dbRow['PAG_TITLE']=$GLOBALS['PROJECT']['TITLE'];
  349.         }                
  350.         $head.= "<title>".$this->dbRow['PAG_TITLE']."</title>\n\n";
  351.         $head.= $GLOBALS['PROJECT']['META']."\n\n";
  352.         $head.= "<link type=\"text/css\" rel=\"stylesheet\" href=\"/cms/defaultStyles.php\">\n";
  353.  
  354.         if ($withStyles$head.=$this->getStylesLink("SCREEN");
  355.        
  356.         if ($withMenu{
  357.             $head.= "<link type=\"text/css\" rel=\"stylesheet\" href=\"/cms/styles.php?STY_NAME=MENU&PROJ_ID=".intval($this->dbRow['PROJ_ID'])."\">\n";
  358.             $head.= "<script language=\"JavaScript\" src=\"".$GLOBALS['PROJECT']['JAVASCRIPTURL']."browser.js\" type=\"text/javascript\"></script>\n";
  359.             $head.= "<script language=\"JavaScript\" src=\"".$GLOBALS['PROJECT']['JAVASCRIPTURL']."window.js\" type=\"text/javascript\"></script>\n";
  360.         }
  361.  
  362.  
  363.         $head.= $this->myTmpl->getMetaTag();
  364.         $head.= $this->myTmpl->getJavaScriptTag();
  365.         $head.= "</head>\n\n";
  366.  
  367.         return $head;
  368.     }
  369.  
  370.     function getStylesLink($media=""{
  371.         switch($media{
  372.             default:
  373.                 if intval($this->dbRow['STY_ID'])) {
  374.                     $ret "<link type=\"text/css\" rel=\"stylesheet\"";
  375.                     $ret.= " href=\"/cms/styles.php?STY_ID=".intval($this->dbRow['STY_ID']);
  376.                     $ret.= "&PROJ_ID=".intval($this->dbRow['PROJ_ID']);
  377.                     $ret.= "\">\n";
  378.                 }
  379.         }
  380.         return $ret;
  381.     }
  382.  
  383.     function getHeadlineTag($debug=FALSE{
  384.         if (!isset($this->prevId)) {
  385.             $this->prevId=$this->getPreviousPage($debug);
  386.         }
  387.         if (!isset($this->prevId)) {
  388.             $this->nextId=$this->getNextPage($debug);
  389.         }
  390.  
  391.         if (!is_object($this->myTmpl)) {
  392.             $this->loadTemplate(TRUE);
  393.         }
  394.  
  395.         $txt $this->myTmpl->getHeadLineTag()."\n";
  396.         $txt .=$this->dbRow['PAG_HEADER'];
  397.         if ($prevId$txt=str_replace("\$*PREVPAGE\$",$this->prevId,$txt);
  398.         if ($nextId$txt=str_replace("\$*NEXTPAGE\$",$this->nextId,$txt);
  399.         return $txt;
  400.     }
  401.  
  402.     function getChapter($mode=0,$debug=FALSE{
  403.         if ($debugecho "<hr><p><b>CMS_PAGE::getChapter($mode,$debug)</b><p>";
  404.  
  405.         $query ="SELECT * FROM T_CMS_CHAPTER ";
  406.         $query.=" WHERE PAG_ID=".intval($this->dbRow['PAG_ID']);
  407.         $query.=" AND PROJ_ID=".intval($this->dbRow['PROJ_ID']);
  408.         $query.=" AND LANG_ID=".intval($this->dbRow['LANG_ID']);
  409.         $query.=" AND CHA_STATE > 2 ";
  410.         if (!intval($mode))     $query.=" AND CHA_SHOWMODE < 4";
  411.         else                    $query.=" AND CHA_SHOWMODE = $mode";
  412.         $query.=" ORDER BY CHA_SORTORDER";
  413.         
  414.         if ($debugecho "<pre style='font-size:10px;'>$query</pre>";
  415.         
  416.         $chaTmplArr=array();
  417.         if ($cursor=$GLOBALS[$this->gDBIDX]->query($query)) {
  418.             while($row=$cursor->fetchArray()) {
  419.                 if (!is_object($chaTmplArr[$row['CTMP_ID']])) {
  420.                     $chaTmplArr[$row['CTMP_ID']]=new TMPL_CHAPTER (intval($this->dbRow['PROJ_ID']),intval($this->dbRow['PTMP_ID']),intval($row['CTMP_ID']));
  421.                     $chaTmplArr[$row['CTMP_ID']]->dbPopulate($debug);
  422.                 }
  423.                 echo $chaTmplArr[$row['CTMP_ID']]->getTag(unserialize($row['CHA_FIELDS']));
  424.  
  425.             }
  426.         }
  427.  
  428.         return $ret;
  429.     }
  430.  
  431.     /**
  432.       * returns the feeter tag
  433.       *
  434.       * @param bool $debug 
  435.       *
  436.       * @return string 
  437.       *
  438.       ***/
  439.     function getFeeterTag($debug=FALSE{
  440.         if (!isset($this->prevId)) {
  441.             $this->prevId=$this->getPreviousPage($debug);
  442.         }
  443.         if (!isset($this->nextId)) {
  444.             $this->nextId=$this->getNextPage($debug);
  445.         }
  446.  
  447.         $txt .=$this->dbRow['PAG_FEETER'];
  448.         $txt .= $this->myTmpl->getFeeterTag()."\n";
  449.         if ($prevId$txt=str_replace("\$*PREVPAGE\$",$this->prevId,$txt);
  450.         if ($nextId$txt=str_replace("\$*NEXTPAGE\$",$this->nextId,$txt);
  451.         return $txt;
  452.     }
  453.  
  454.     /**
  455.       * returns the feeter tag
  456.       *
  457.       * @deprecated  RELEASE-2  calls CMS_PAGE::getFeeterTag()
  458.       *
  459.       * @param bool $debug 
  460.       *
  461.       * @return string 
  462.       *
  463.       ***/
  464.     function getFeeter($debug=FALSE{
  465.         if ($debugecho "<hr><p><b>CMS_PAGE::getFeeter($debug)</b><p>";
  466.  
  467.         // old *inconsistent style*
  468.         return $this->getFeeterTag($debug);
  469.     }
  470.  
  471.     /**
  472.       * echos an entire page
  473.       *
  474.       * @param int  $mode   view mode
  475.       * @param bool $debug 
  476.       *
  477.       ***/
  478.     function view($mode=1,$debug=FALSE{
  479.         if ($debugecho "<hr><p><b>CMS_PAGE::view($mode,$debug)</b><p>";
  480.  
  481.         echo $this->getHead(FALSE,$debug);
  482.         echo $this->myTmpl->getBodyTag($debug);
  483.         echo $this->getHeadlineTag($debug);
  484.  
  485.         if (!$mode{
  486.             echo $this->getChapter(CHAPTER_SHOWMODE_ALLWAYS_TOP,$debug);
  487.             echo $this->getChapter(CHAPTER_SHOWMODE_ALLWAYS_BOTTOM,$debug);
  488.         }
  489.  
  490.         echo $this->getFeeterTag($debug);
  491.  
  492.         echo "</body>";
  493.         echo "</html>";
  494.  
  495.     }
  496.  
  497.     /**
  498.       * returns the css tag
  499.       *
  500.       * @returns string
  501.       *
  502.       * @since pk-04-08-02
  503.       *
  504.       ***/
  505.     function getCSSHeaderTag($debug=FALSE{
  506.         if ($debugecho "<p><b>CMS_PAGE::getCSSHeaderTag()</b> (".get_class($this).")<br />NOT SUPPORTED BY OBJECT</p>";
  507.         return "";
  508.     }
  509.  
  510.     /**
  511.       * returns the meta tag
  512.       *
  513.       * @returns string
  514.       *
  515.       * @since pk-04-08-02
  516.       *
  517.       ***/
  518.     function getJavaHeaderTag({
  519.         if ($debugecho "<p><b>CMS_PAGE::getJavaHeaderTag()</b> (".get_class($this).")<br />NOT SUPPORTED BY OBJECT</p>";
  520.         return "";
  521.     }
  522.  
  523. }
  524.  
  525.  
  526. ?>

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