Source for file function.phpinc

Documentation is available at function.phpinc

  1. <?php
  2.   /**
  3.     * CMS page Functions
  4.     *
  5.     * @project    Open CSP-Management
  6.     * @package    cms
  7.     * @category   page
  8.     *
  9.     * @author     Peter Krebs (pk) <p.krebs@lvus.at>
  10.     * @copyright  (c) 2002-2005 by LVUS <http://www.lvus.at>
  11.     * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.     *
  13.     * @version pk-04-12-28
  14.     *
  15.     ***/
  16.  
  17.  
  18.     if (!isset($GLOBALS['OCSP_CMS']['PAG_DEFAULT_CLASS'])) $GLOBALS['OCSP_CMS']['PAG_DEFAULT_CLASS']="CMS_PAGE_V2";
  19.  
  20. /**
  21.   * first selects a the page from T_CMS_PAGE
  22.   * and returns OCSPFUNC_getPageObjFromRow($row)
  23.   *
  24.   * @param DBOBJ &$DB 
  25.   * @param int $projId 
  26.   * @param int $pageId 
  27.   * @param int $langId 
  28.   * @param bool $debug 
  29.   *
  30.   * @returns mixed PAGE_* object or NULL in case of now row
  31.   *
  32.   * @since pk-04-07-30
  33.   *
  34.   ***/
  35.  
  36. function OCSPFUNC_loadFromDB(&$DB,$projId,$pageId,$langId=0,$debug=FALSE{
  37.     if ($debugecho "<p><b>CMSPAG_loadFromDB(&\$DB,$projId,$pageId,$langId....)</b>(PROJROOT/php/cms/page/function.phpinc)</p>";
  38.     $query ="SELECT * FROM T_CMS_PAGE WHERE PROJ_ID=".intval($projId);
  39.     $query.=" AND PAG_ID=".intval($pageId);
  40.     $query.=" AND LANG_ID=".intval($langId);
  41.  
  42.     if ($debug{echo "<blockquote>$query\n";echo "</blockquote>";}
  43.     if ($row=$DB->quickQuery($query)) {
  44.         return OCSPFUNC_getPageObjFromRow($row,$debug);
  45.     else {
  46.         return NULL;
  47.     }
  48. }
  49.  
  50. /**
  51.   * creates a page object out of a given row array
  52.   * by useing OCSPFUNC_newPageObject() and populates it with
  53.   * the array data
  54.   *
  55.   * @param array $row 
  56.   * @param boolean $debug 
  57.   *
  58.   * @returns mixed PAGE* object
  59.   *
  60.   * @since pk-04-07-30
  61.   * @version pk-05-09-01
  62.   *
  63.   ***/
  64.  
  65. function OCSPFUNC_getPageObjFromRow($row,$debug=FALSE{
  66.     if ($debugecho "<p><b>OCSPFUNC_getPageObjFromRow(\$row,...)</b> (PROJROOT/php/cms/page/function.phpinc)</p>";
  67.  
  68.     if (is_array($row)) // <pk-05-09-01>
  69.         if (empty($row['PAG_OBJCLASS'])) $row['PAG_OBJCLASS']=$GLOBALS['OCSP_CMS']['DEFAULTPAGETYPE'];
  70.  
  71.         if (!class_exists($row['PAG_OBJCLASS'])) {
  72.             $s_srcFile=$GLOBALS['OCSP_CMS']['PAGETYPE'][$row['PAG_OBJCLASS']]['OBJINC'];
  73.             if ((!empty($s_srcFile)) && (file_exists($s_srcFile))) {
  74.                 require_once $s_srcFile;
  75.             else {
  76.                 if ($debugecho "<p>Source File$s_srcFile NOT FOUND</p>";
  77.                 return NULL;
  78.             }
  79.         }
  80.         $pageObj=OCSPFUNC_newPageObject($row['PAG_OBJCLASS'],$debug);
  81.         $pageObj->setDBRow($row,TRUE,$debug);
  82.         return $pageObj;
  83.     else {
  84.         return NULL;
  85.     }
  86. }
  87.  
  88. /**
  89.   * creates a page object of type $classpageV2
  90.   *
  91.   * @param string $class 
  92.   * @param boolean $debug 
  93.   *
  94.   * @returns mixed PAGE* object
  95.   *
  96.   * @since pk-04-07-30
  97.   *
  98.   ***/
  99. function OCSPFUNC_newPageObject($class="",$debug=FALSE{
  100.     if ($debugecho "<p><b>OCSPFUNC_newPageObject($class,...)</b> (PROJROOT/php/cms/page/function.phpinc)</p>";
  101.  
  102.     if (empty($class|| empty($GLOBALS['OCSP_CMS']['PAGETYPE'][$class]['OBJINC'])) {
  103.         if ($debugecho "<p>USING DEFAULT (\$class=$class,ObjInc".$GLOBALS['OCSP_CMS']['PAGETYPE'][$class]['OBJINC'].")</p>";
  104.         $class="CMS_PAGE_V2";
  105.     }
  106.  
  107.     if (!file_exists($GLOBALS['OCSP_CMS']['PAGETYPE'][$class]['OBJINC'])) {
  108.         $GLOBALS['OCSP_CMS']['PAGETYPE'][$class]['OBJINC']=$GLOBALS['OCSP']['PHPINCPATH'].$GLOBALS['OCSP_CMS']['PAGETYPE'][$class]['OBJINC'];
  109.     }
  110.  
  111.     if (file_exists($GLOBALS['OCSP_CMS']['PAGETYPE'][$class]['OBJINC'])) {
  112.         if ($debug{echo "<blockquote>$class CONFIG ARRAY:<pre>";print_r($GLOBALS['OCSP_CMS']['PAGETYPE'][$class]);echo "</pre></blockquote>";}
  113.     else {
  114.         if ($debug{
  115.             echo "<blockquote>";
  116.             echo "<p><b>DEFAULT CLASS USED</binstead of$class<br /></pCONFIG ARRAY:<pre>";print_r($GLOBALS['OCSP_CMS']['PAGETYPE'][$class]);echo "</pre>";
  117.             echo "<p>PAGETYPES</p><pre style=\"font-size:10px;\">".print_r($GLOBALS['OCSP_CMS']['PAGETYPE'],TRUE)."</pre>";
  118.             echo "</blockquote>";
  119.         }
  120.         $class=$GLOBALS['OCSP_CMS']['PAG_DEFAULT_CLASS'];
  121.  
  122.     }
  123.  
  124.  
  125.     //if ($debug) echo "<h2>\$class: $class</h2><pre>".print_r($GLOBALS['OCSP_CMS']['PAGETYPE'],TRUE)."</pre>";
  126.     require_once $GLOBALS['OCSP_CMS']['PAGETYPE'][$class]['OBJINC'];
  127.  
  128.     $cmd="\$pageObj=new ".$class."();";
  129.     eval($cmd);
  130.     return $pageObj;
  131. }
  132.  
  133. /**
  134.   * checks if a page (as DB-ROW) is online
  135.   *
  136.   * @param array $pArr 
  137.   * @param boolean $directCall 
  138.   * @param boolean $debug 
  139.   *
  140.   * @returns boolean
  141.   *
  142.   * @since pk-04-12-14
  143.   * @version pk-04-12-21
  144.   *
  145.   ***/
  146. function OCSPFUNC_checkRowOnline($pArr,$directCall=FALSE,$debug=FALSE{
  147.     if ($debugecho "<p><b>OCSPFUNC_checkRowOnline(\$pArr,$directCall,...)</b> (PROJROOT/php/cms/page/function.phpinc)</p>";
  148.  
  149.     // check state:
  150.     if (!$GLOBALS['OCSP_CMS']['PAGESTATE'][intval($pArr['PAG_STATE'])]['SHOW']{
  151.         // page is not to show automaticaly due to editor setting
  152.         if (!($directCall && $GLOBALS['OCSP_CMS']['PAGESTATE'][intval($pArr['PAG_STATE'])]['DIRECTSHOW'])) {
  153.             // page is not to show online
  154.             if ($debug{
  155.                 echo "<blockquote><pre>".print_r($pArr,TRUE)."</pre>";
  156.                 echo "STATE:<pre>".print_r($GLOBALS['OCSP_CMS']['PAGESTATE'][intval($pArr['PAG_STATE'])],TRUE)."</pre>";
  157.                 echo "<p><b>PAGE NOT TO SHOW DUE TO STATE</b></p></blockquote>";
  158.             }
  159.             return FALSE;
  160.         }
  161.     }
  162.  
  163.     // check show from till dates
  164.     require_once $GLOBALS['PHPINCPATH']."common/pcf_Date.phpclass";
  165.     $aDate=new pcf_Date();
  166.  
  167.     $aDate->setDateStr($pArr['PAG_SHOWFROM']);
  168.     if ($aDate->isInFutur()) // the page show from is greater then now() -> don't show
  169.         if ($debugecho "<blockquote><p>".$pArr['PAG_SHOWFROM']." is in future</p></blockquote>";
  170.         return FALSE;
  171.     }
  172.  
  173.     $aDate->setDateStr($pArr['PAG_SHOWTILL'])// check if the show from date is in futur
  174.     if ($aDate->isInPast()) // the page show till is in past -> don't show
  175.        if ($debugecho "<blockquote><p>".$pArr['PAG_SHOWTILL']." is in past</p></blockquote>";
  176.        return FALSE;
  177.     }
  178.  
  179.     // now check rights
  180.     if (intval($pArr['PAG_SHOWGROUP'])) {
  181.         if ($GLOBALS['USER']->isGroupMember(intval($pArr['PAG_SHOWGROUP']))) {
  182.             return TRUE;
  183.         else {
  184.            if ($debugecho "<blockquote><p>You are not member of GRP_ID ".$pArr['PAG_SHOWGROUP']."</p></blockquote>";
  185.            return FALSE;
  186.         }
  187.     else {
  188.         // page is public
  189.         return TRUE;
  190.     }
  191. }
  192.  
  193. /**
  194.   * finds the page to show online
  195.   *
  196.   * - first checks if a page with $pParams['PAG_ID'] is to show
  197.   * - if $pParams['PAG_ID']=0 the first page of the menu with $pParams['MEN_ID'] is returned
  198.   * - if $pParams['MEN_ID'] has no page and $searchInMenu == TRUE the menparents are searched for
  199.   *   a page to show with the current user rights or if $enableLogin the user is asked to login
  200.   *
  201.   *
  202.   * $pParams is a array with the following keys:
  203.   *
  204.   * - PROJ_ID:  the currentproject id
  205.   * - MEN_ID:   the id of the current menu
  206.   * - LANG_ID:  the language id
  207.   * - PAG_ID:   the page id
  208.   *
  209.   * @param array $pParams 
  210.   * @param boolean $searchInMenu 
  211.   * @param boolean $enableLogin 
  212.   * @param boolean $debug 
  213.   *
  214.   * @returns CMS_PAGE
  215.   *
  216.   * @since pk-04-12-14
  217.   *
  218.   * @todo show login when enableLogin is TRUE
  219.   * @todo language support not fully implemented
  220.   *
  221.   ***/
  222. function OCSPFUNC_findPageOnline($pParams,$searchInMenu=FALSE,$enableLogin=FALSE,$debug=FALSE{
  223.     if ($debugecho "<p><b>OCSPFUNC_findPageOnline(</b>".print_r($pParams,TRUE).",$searchInMenu,$enableLogin ...<b>)</b>)<blockquote>";
  224.  
  225.     if (intval($pParams['PAG_ID'])) {
  226.         if ($pArr=$GLOBALS['USRDB']->quickQuery("SELECT * FROM T_CMS_PAGE WHERE PAG_ID=".intval($pParams['PAG_ID']))) {
  227.             if (OCSPFUNC_checkRowOnline($pArr,TRUE,$debug)) {
  228.                 return OCSPFUNC_getPageObjFromRow($pArr,$debug);
  229.             else {
  230.                 // set pParams according to the found page for the case they arn't set
  231.                 $pParams['MEN_ID'=intval($pArr['MEN_ID']);
  232.                 $pParams['PROJ_ID']=intval($pArr['PROJ_ID']);
  233.             }
  234.         }
  235.     }
  236.  
  237.     $pParams['PAG_ID']=0;   // unset the PAG_ID as it does not exist
  238.  
  239.     $query ="SELECT * FROM T_CMS_PAGE ";
  240.     $query.=" WHERE PROJ_ID=".intval($pParams['PROJ_ID']);
  241.     $query.="   AND MEN_ID=".intval($pParams['MEN_ID']);
  242.     $query.="   AND PAG_STATE IN (".OCSPFUNC_showStatesCSV().")";
  243.     $query.="   AND PAG_SHOWFROM <= ".$GLOBALS['USRDB']->qs_getNowStmt();
  244.     $query.="   AND PAG_SHOWTILL >= ".$GLOBALS['USRDB']->qs_getNowStmt();
  245.     $query.=" ORDER BY PAG_SORTORDER";
  246.  
  247.     if ($cursor=$GLOBALS['USRDB']->query($query)) {
  248.         while($pArr=$cursor->fetchArrayFld()) {
  249.             if (OCSPFUNC_checkRowOnline($pArr,FALSE,$debug)) {
  250.                 $cursor->free();
  251.                 return OCSPFUNC_getPageObjFromRow($pArr,$debug);
  252.             }
  253.         }
  254.     }
  255.  
  256.     // no page found
  257.     if ($searchInMenu{
  258.         require_once $GLOBALS['OCSP_CMS']['PHPINCPATH']."menu/CMS_MENU_NODE.phpclass";
  259.  
  260.         $query ="SELECT * FROM T_CMS_MENU ";
  261.         $query.=" WHERE PROJ_ID=".intval($pParams['PROJ_ID']);
  262.         $query.="   AND MEN_PARENT=".intval($pParams['MEN_ID']);
  263.         $query.="   AND MEN_SHOW=1";
  264.         $query.="   AND MEN_SHOWFROM <= ".$GLOBALS['USRDB']->qs_getNowStmt();
  265.         $query.="   AND MEN_SHOWTILL >= ".$GLOBALS['USRDB']->qs_getNowStmt();
  266.         $query.=" ORDER BY MEN_SORTORDER";
  267.  
  268.         if ($cursor=$GLOBALS['USRDB']->query($query)) {
  269.             while($mArr=$cursor->fetchArrayFld()) {
  270.                 $mObj=new CMS_MENU_NODE();
  271.                 $mObj->setDBRow($mArr,TRUE);
  272.                 if ($mObj->isToShow()) {
  273.                     $pParams['MEN_ID']=$mObj->getId();
  274.                     $cursor->free();
  275.                     return  OCSPFUNC_findPageOnline($pParams,$searchInMenu,$enableLogin,$debug);
  276.                 }
  277.             }
  278.         }
  279.  
  280.     }
  281.  
  282.     return FALSE;
  283. }
  284.  
  285. /**
  286.   * generates a comma seperated string with page states to show online
  287.   *
  288.   * @returns string
  289.   *
  290.   * @since pk-04-12-14
  291.   *
  292.   ***/
  293. function OCSPFUNC_showStatesCSV({
  294.     $sep="";
  295.     foreach($GLOBALS['OCSP_CMS']['PAGESTATE'as $key => $sArr// get a comma sep list of states to show
  296.         if ($sArr['SHOW']{
  297.             $ret.=$sep."$key";
  298.             $sep=",";
  299.         }
  300.     }
  301.  
  302.     return $ret;
  303. }

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