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