• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/modules/pagelist.lib.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00027 class pagelist implements module {
00028 
00029         public function getHtml($userId, $moduleComponentId, $action) {
00030                 $this->userId = $userId;
00031                 $this->moduleComponentId = $moduleComponentId;
00032                 $this->action = $action;
00033 
00034                 if($action == "view")
00035                         return $this->actionView();
00036                 if ($this->action == "edit")
00037                         return $this->actionEdit();
00038         }
00039 
00040         public function actionView() {
00041                 global $sourceFolder; 
00042                 require_once("$sourceFolder/common.lib.php");
00043                 $pageid = getPageIdFromModuleComponentId("pagelist",$this->moduleComponentId);
00044                 $pageid=getParentPage($pageid);
00045                 $query = "SELECT `depth` FROM `list_prop` WHERE `page_modulecomponentid`=$this->moduleComponentId";
00046                 $result = mysql_query($query) or die(mysql_error());
00047                 $row = mysql_fetch_assoc($result);
00048                 $reqdepth=$row['depth'];
00049                 $out=$this->generatePagelist($pageid, $this->userId, 0, 'view',$reqdepth+1);
00050                 return $out;
00051         }
00052         function generatePagelist($pageId, $userId, $permId, $action = '',$depth) {
00053                 global $cmsFolder, $urlRequestRoot ,$templateFolder;
00054                 $treeData= '<div><ul id="sitemap">' ;
00055                 if($action != '') {
00056                         $treeData .= $this->getNodeHtmlforPagelist($pageId, $userId, '', $action, $urlRequestRoot.'/', $depth);
00057                 }
00058                 
00059                 else {
00060                         $permQuery = 'SELECT `page_module`, `perm_action` FROM `' . MYSQL_DATABASE_PREFIX . 'permissionlist` WHERE `perm_id` = ' . $permId;
00061                         $permResult = mysql_query($permQuery);
00062                         $permRow = mysql_fetch_row($permResult);
00063                         $module = $permRow[0];
00064                         $action = $permRow[1];
00065                         $treeData .= $this->getNodeHtmlforPagelist($pageId, $userId, $module, $action, $urlRequestRoot . '/', $depth);
00066                 }
00067                 
00068                 $treeData .= '</ul></div>';
00069                 return $treeData;
00070         }
00071 
00072         function getNodeHtmlforPagelist($pageId, $userId, $module, $action, $parentPath, $depth)
00073          {
00074                 global $cmsFolder, $urlRequestRoot ,$templateFolder;
00075                 $tempFolder="$urlRequestRoot/$cmsFolder/$templateFolder";
00076                 $imagesFolder = "$tempFolder/common/icons/32x32";
00077                 $imagesFolder2 = "$tempFolder/common/images/pagethumbs";
00078                 
00079                 $goimage="$tempFolder/common/icons/16x16/actions/media-skip-forward.png";
00080                 if($depth!=0){ 
00081                 $htmlOut = '';
00082                 
00083                 if(getPermissions($userId, $pageId, $action, $module)) {
00084                 
00085                 if(isset($_POST['hell']))
00086                 {               
00087                                 $pageId=escape($_POST['hell']);
00088                                 unset($_POST['hell']);
00089                                 $htmlOut.=$this->generatePagelist($pageId, $userId, $permId, $action = '',$depth);
00090                         
00091                 }
00092                 else
00093                 {
00094                         $pageInfo = getPageInfo($pageId);
00095                         if(isset($_POST['hell2']))
00096                         { 
00097                                 $pagePath=escape($_POST['hell2']);
00098                                 unset($_POST['hell2']);
00099 
00100                         }
00101                         else
00102                         { 
00103                                 $pagePath = $parentPath;
00104                                 if($pageInfo['page_name']!= '')
00105                                         $pagePath.=$pageInfo['page_name'].'/'; 
00106                         }
00107                         $pagename=$pageInfo['page_name'];
00108                         
00109                         $htmlOut .= "<li><form method ='POST' action='./'><input type='image' src=\"$goimage\" name='pagename' alt='Go' title='Click to list pages from here'><input type='hidden' name='hell' value='$pageId' /><input type='hidden' name='hell2' value='$pagePath' /><a href=\"$pagePath\">";
00120                         $thumbname="$imagesFolder/actions/go-home.png";
00121                         
00122                         $htmlOut.="<span class='list'><img src='$thumbname' alt=' !sorry! '>" . getPageTitle($pageId) . "</span></a>\n</form>";
00123 
00124                         $childrenQuery = 'SELECT `page_id`, `page_displayinmenu` FROM `' . MYSQL_DATABASE_PREFIX  . 'pages` WHERE `page_parentid` <> `page_id` AND `page_parentid` = ' . $pageId;
00125                         $childrenResult = mysql_query($childrenQuery);
00126                         $childrenHtml = '';
00127                         while($childrenRow = mysql_fetch_row($childrenResult)) {
00128                                 if($childrenRow[1] == 1&&$depth!=0) {
00129                                         $childrenHtml .= $this->getNodeHtmlforPagelist($childrenRow[0], $userId, $module, $action, $pagePath, $depth-1);
00130                                 
00131                                 }
00132                         }
00133                         if($childrenHtml != '') {
00134                                 $htmlOut .= "<ul>$childrenHtml</ul>\n";
00135                         }
00136 
00137                         $htmlOut .= "</li>\n";
00138                         }
00139                 }
00140                 return $htmlOut;
00141         }
00142         }
00143 
00144         public function actionEdit() {
00145         
00146                 if(isset($_POST['depth'])) 
00147                 {               
00148                         $query = "UPDATE `list_prop` SET `depth`=".escape($_POST['depth'])." WHERE `page_modulecomponentid`=$this->moduleComponentId";
00149                         $result = mysql_query($query);
00150                         if (mysql_affected_rows())       
00151                                 $ret.="<div class='cms-info'>Depth value updated.</div>";
00152                         else $ret.="<div class='cms-info'>ok. updated. (Its already set)</div>";         
00153                 }       
00154 
00155                 $query = "SELECT `depth` FROM `list_prop` WHERE `page_modulecomponentid`=$this->moduleComponentId";
00156                 $result = mysql_query($query) or die(mysql_error());
00157                 $row = mysql_fetch_assoc($result);
00158                 
00159                 $ret.="<form action='./+edit&subaction=submit' method=POST>
00160 <table>
00161 <caption>Edit the Depth of pagelisting:</caption>
00162 <tr>
00163 <td>Enter the Depth to be set:</td>
00164 <td><input type='text' name='depth' value={$row['depth']}></td>
00165 </tr>
00166 <tr>
00167 <td><input type='submit' value='Submit' name'submitdepth'></td>
00168 </tr>
00169 </table>
00170 </form>";
00171 
00172                 return $ret;
00173         }
00174                 
00175         public function createModule(&$moduleComponentId) {
00176                 
00177                 $query = "SELECT MAX(page_modulecomponentid) as MAX FROM `list_prop` ";
00178                 $result = mysql_query($query) or die(mysql_error() . "list.lib.php L:1");
00179                 $row = mysql_fetch_assoc($result);
00180                 $compId = $row['MAX'] + 1;
00181                 $defaultdepth=3;
00182                 $query = "INSERT INTO `list_prop` (`page_modulecomponentid`, `depth`) VALUES ('$compId', '$defaultdepth')";
00183                 $result = mysql_query($query) or die(mysql_error());
00184                 if (mysql_affected_rows()) {
00185                         $moduleComponentId = $compId;
00186                         return true;
00187                 } else
00188                         return false;
00189         }
00190         
00191         
00192         public function deleteModule($moduleComponentId) {
00193                 /*
00194                  * This is also a necessary function
00195                  * it'll be called when an instance of your module is going to get deleted
00196                  * you can do your clean up works for the module instance here
00197                  * return true in case of successful deletion, else false
00198                  */
00199                  return true;
00200         }
00201         
00202         public function copyModule($moduleComponentId) {
00203                 /*
00204                  * This is also a necessary function
00205                  * it'll be called when a module is to be copied
00206                  * return true when copied successfully, else false
00207                  */
00208                  return true;
00209         }
00210 }
00211 ?>

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1