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 }
00016
00017
00018
00019
00020
00021
00022
00023
00024 function findMenuIndex($menuArray, $pageId) {
00025 for ($i = 0; $i < count($menuArray); ++$i)
00026 if ($menuArray[$i][0] == $pageId)
00027 return $i;
00028 return -1;
00029 }
00030
00042 function getMenu($userId, $pageIdArray) {
00043
00044
00048
00049 $hostURL = ".";
00050 $pageId = $pageIdArray[count($pageIdArray) - 1];
00051 $hostURL = hostURL();
00052
00054 $MYHOST = hostURL();
00055
00057 $pageRow = getPageInfo($pageId);
00058 $depth = $pageRow['page_menudepth'];
00059
00061 if ($depth == 0) $depth=1;
00062
00063 if ($pageRow['page_displaymenu'] == 0)
00064 return '';
00065 $menutype=$pageRow['page_menutype'];
00066
00067 $menuHtml = "";
00068
00070 if($menutype=="classic")
00071 {
00072 $pageId = $pageIdArray[count($pageIdArray) - 1];
00073 $depth = 1;
00074 $hostURL = strstr(selfURI(), '+', true);
00075
00077 $parentPage = getParentPage($pageId);
00078 $parentPageRow = getPageInfo($parentPage);
00079
00080 $childListGenerated = getChildList($pageId, $depth, hostURL(), $userId, 1);
00081
00083 if($pageRow['page_displaysiblingmenu']) {
00084 if($pageId != 0) {
00085 $imageTag = "";
00086 if($parentPageRow['page_displayicon'] == 1 && $parentPageRow['page_image'] != NULL) {
00088 $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$parentPageRow['page_image']}\" alt=\"{$parentPageRow['page_image']}\" />";
00089 }
00090 $menuHtml .= '<a href="'.$hostURL.'../"><div class="cms-menuhead">'.$imageTag.$parentPageRow["page_title"].'</div></a>';
00091 $siblingMenu = getChildList($parentPage,1,hostURL(),$userId,1);
00092 $menuHtml .= $siblingMenu;
00093 }
00094 }
00095
00097 if($pageRow['page_displaysiblingmenu']==0 && $childListGenerated == null) {
00098 $imageTag = "";
00099 $pageR = getPageInfo($pageId);
00100 if($pageR['page_displayicon'] == 1) {
00101 if($pageR['page_image'] != NULL)
00102 $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$pageR['page_image']}\" alt=\"{$pageR['page_image']}\" />";
00103 }
00104 $menuHtml .= <<<MENU
00105 <ul class="topnav">
00106 <li>
00107 <a href="./"><div class="cms-menuitem">{$imageTag} {$pageRow['page_title']}</div></a>
00108 </li>
00109 </ul>
00110 MENU;
00111 }
00112
00114 if($childListGenerated != "") {
00115 $imageTag = "";
00116 if($pageRow['page_displayicon'] == 1 && $pageRow['page_image'] != NULL) {
00117 $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$pageRow['page_image']}\" alt=\"{$pageRow['page_image']}\" />";
00118 }
00119 $menuHtml .= '<a href="'.$hostURL.'"><div class="cms-menuhead">'.$imageTag.$pageRow["page_title"].'</div></a>';
00120 $menuHtml .= $childListGenerated;
00121 }
00122 }
00123 else
00124 {
00126 if($menutype == "multidepth") {
00127 $pageId = $pageIdArray[count($pageIdArray) - 1];
00128 }
00129 else {
00130 $pageId = 0;
00131 }
00132
00133 $rootUri = hostURL();
00135 $pageRow = getPageInfo($pageId);
00136
00138 $childListGenerated = getChildList($pageId,$depth,$rootUri,$userId,1);
00139 if($childListGenerated != "")
00140 $menuHtml .= $childListGenerated;
00142 else {
00143 $imageTag = "";
00144 $pageR = getPageInfo($pageId);
00145 if($pageR['page_displayicon'] == 1) {
00146 if($pageR['page_image'] != NULL)
00147 $imageTag = "<img width=32 height=32 src=\"{$rootUri}/{$pageR['page_image']}\" alt=\"{$pageR['page_image']}\" />";
00148 }
00149 $menuHtml .= <<<MENU
00150 <ul class="topnav">
00151 <li>
00152 <a href="./"><div class="cms-menuitem">{$imageTag} {$pageRow['page_title']}</div></a>
00153 </li>
00154 </ul>
00155 MENU;
00156 }
00157 }
00158
00159
00160 return $menuHtml;
00161
00162 }
00163
00172 function getChildList($pageId,$depth,$rootUri,$userId,$curdepth) {
00173 if($depth>0 || $depth==-1) {
00174 if($curdepth==1 || $pageId==0) $classname="topnav";
00175 else $classname="subnav";
00176 $MYHOST = hostURL();
00177 $pageRow = getChildren($pageId,$userId);
00178
00179 $var = "<div class='div_{$classname}'><ul class='{$classname} depth{$curdepth}'>";
00180 for($i=0;$i<count($pageRow);$i+=1) {
00181 $query = "SELECT `page_openinnewtab` FROM `".MYSQL_DATABASE_PREFIX."pages` WHERE `page_id` = '{$pageRow[$i][0]}'";
00182 $result = mysql_query($query);
00183 $result = mysql_fetch_assoc($result);
00184 $opennewtab="";
00185 if($result['page_openinnewtab']=='1')
00186 $opennewtab = ' target="_blank" ';
00187
00188 $newdepth=$curdepth+1;
00189 $imageTag = '';
00190 if($pageRow[$i][4]) {
00191 if($pageRow[$i][3] != NULL)
00192 $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$pageRow[$i][3]}\" alt=\"{$pageRow[$i][1]}\" />";
00193
00194
00195
00196
00197
00198
00199
00200
00201 }
00202 $var .= "\n<li id=\"cms-menu-item$i\"><a href=\"".$rootUri.'/home'.getPagePath($pageRow[$i][0])."\" $opennewtab ><div class='cms-menuitem'>".$imageTag." ".$pageRow[$i][2]."</div></a>";
00203 $var .= getChildList($pageRow[$i][0],($depth==-1)?$depth:($depth-1),$rootUri,$userId,$newdepth,true);
00204 $var .= "</li>";
00205 }
00206 $var .= "</ul></div>";
00207 if(count($pageRow)==0) return "";
00208 return $var;
00209 }
00210 }
00211 function htmlMenuRenderer($menuArray, $currentIndex = -1, $linkPrefix = '') {
00212 $menuHtml = '';
00213 $hostURL=strstr(selfURI(),'+',true);
00214
00215 for ($i = 0; $i < count($menuArray); ++$i) {
00216 $query = "SELECT `page_openinnewtab` FROM `".MYSQL_DATABASE_PREFIX."pages` WHERE `page_id` = '{$menuArray[$i][0]}'";
00217 $result = mysql_query($query);
00218 $result = mysql_fetch_assoc($result);
00219
00220 if($result['page_openinnewtab']=='1') {
00221 $menuHtml .= "<a href=\"".$hostURL."{$linkPrefix}{$menuArray[$i][1]}/\" target=\"_blank\"";
00222 }
00223 else {
00224 $menuHtml .= "<a href=\"".$hostURL."{$linkPrefix}{$menuArray[$i][1]}/\"";
00225 }
00226 if ($i == $currentIndex)
00227 $menuHtml .= ' class="currentpage"';
00228 $menuHtml .= '>';
00229 if (($menuArray[$i][4]) && ($menuArray[$i][3] != ''))
00230 $menuHtml .= "<img src=\"{$menuArray[$i][3]}\" width=32 height=32 />";
00231 $menuHtml .= "<div class='cms-menuitem'> {$menuArray[$i][2]} </div></a>\n";
00232 }
00233
00234
00235 return $menuHtml;
00236 }
00237
00238 function imageMenuRenderer($menuArray, $currentIndex = -1, $linkPrefix = '') {
00239 $menuRows = array();
00240 $rowCount = -1;
00241 for ($i = 0; $i < count($menuArray); ++$i) {
00242 if ($i % 3 == 0) {
00243 if ($rowCount >= 0)
00244 $menuRows[$rowCount] .= '</div>';
00245 $menuRows[++$rowCount] = '<div class="menuitemrow">';
00246 }
00247 $menuRows[$rowCount] .= '<a href="' . $linkPrefix . $menuArray[$i][1] . '"><img src="' . $menuArray[$i][4] . '" alt="' . $menuArray[$i][2] . '"';
00248 if ($i == $currentIndex)
00249 $menuRows[$rowCount] .= ' class="currentpage"';
00250 $menuRows[$rowCount] .= ' /></a>';
00251 }
00252
00253 if (count($menuRows))
00254 $menuRows[count($menuRows) - 1] .= "</div>";
00255
00256 $menuHtml = '';
00257 for ($i = 0; $i < count($menuRows); ++$i) {
00258 if ($i % 3 == 0)
00259 $menuHtml .= '<div class="menuitemdescription"> </div>';
00260 $menuHtml .= $menuRows[$i];
00261 }
00262
00263 return $menuHtml;
00264 }
00265
00269 function getChildren($pageId, $userId) {
00270 $pageId=escape($pageId);
00271 $childrenQuery = 'SELECT `page_id`, `page_name`, `page_title`, `page_module`, `page_modulecomponentid`, `page_displayinmenu`, `page_image` , `page_displayicon` FROM `' . MYSQL_DATABASE_PREFIX . 'pages` WHERE `page_parentid` = ' . $pageId . ' AND `page_id` != ' . $pageId . ' AND `page_displayinmenu` = 1 ORDER BY `page_menurank`';
00272
00273 $childrenResult = mysql_query($childrenQuery);
00274 $children = array();
00275 while ($childrenRow = mysql_fetch_assoc($childrenResult))
00276 if ($childrenRow['page_displayinmenu'] == true && getPermissions($userId, $childrenRow['page_id'], 'view', $childrenRow['page_module']) == true)
00277 $children[] = array($childrenRow['page_id'], $childrenRow['page_name'], $childrenRow['page_title'], $childrenRow['page_image'],$childrenRow['page_displayicon']);
00278
00279
00280 return $children;
00281 }
00282
00283 ?>