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 }
00019 class DirectoryTreeNode {
00020 private $pageId;
00021 private $pageName;
00022 private $children;
00023 private $pageTitle;
00024
00025 private $permission;
00026 private $isRequired;
00027
00028
00029
00038 private function computePermission(& $userid, & $groups, & $permId, & $permSet) {
00039 $pid = $this->pageId;
00041
00046
00047 $permListTable = MYSQL_DATABASE_PREFIX . 'permissionlist';
00048 $pagepermTable = MYSQL_DATABASE_PREFIX . 'userpageperm';
00049
00050 $permQuery = "SELECT `perm_permission`, `usergroup_id` FROM `$pagepermTable` WHERE " .
00051 "((`usergroup_id` IN (" . join($groups, ', ') . ") AND `perm_type` = 'group') OR " .
00052 "(`usergroup_id` = $userid AND `perm_type` = 'user')) " .
00053 "AND `page_id` = $pid AND `perm_id` = $permId";
00054
00057 $permResult = mysql_query($permQuery) or die($permQuery . "<br />" . mysql_error());
00058 $groupCount = count($groups);
00059
00060 while ($permResultRow = mysql_fetch_row($permResult)) {
00061 $index = array_search($permResultRow[1], $groups);
00062
00063 if($index === false) {
00064 if($permResultRow[1] == $userid) {
00065 $index = $groupCount;
00066 }
00067 }
00068
00069 if($index !== false) {
00070 if ($permResultRow[0] == 'Y') {
00071 if ($permSet[$index] == 'U') {
00072 $permSet[$index] = 'Y';
00073 }
00074 }
00075 elseif ($permResultRow[0] == 'N') {
00076 $permSet[$index] = 'N';
00077 }
00078 }
00079 }
00080
00081 $permission = false;
00082 for ($i = 0; $i <= $groupCount && !$permission; $i++) {
00083 $permission = ($permission || ($permSet[$i] == 'Y' ? true : false));
00084 }
00085
00086 return $permission;
00087 }
00088
00089
00090
00100 public function __construct(& $pageId, & $userid, & $groups, &$permId, $permSet, $retrieveLinks = false) {
00101 $pageNameQuery = "SELECT `page_name`, `page_title` FROM `" . MYSQL_DATABASE_PREFIX . "pages` WHERE `page_id` = $pageId";
00102 $pageNameResult = mysql_query($pageNameQuery);
00103 $pageNameResultRow = mysql_fetch_row($pageNameResult);
00104
00105 $this->pageId = $pageId;
00106 $this->pageName = $pageNameResultRow[0];
00107 $this->pageTitle = $pageNameResultRow[1];
00108
00109 $this->permission = $this->computePermission($userid, $groups, $permId, $permSet);
00110 $this->isRequired = $this->permission;
00111
00112 $this->children = array ();
00113
00114 $childQuery = "SELECT `page_id`, `page_module` FROM `" . MYSQL_DATABASE_PREFIX . "pages` WHERE `page_parentid` = $pageId and `page_parentid` != `page_id` ORDER BY `page_menurank`";
00115 $childResult = mysql_query($childQuery);
00116
00117 while ($childResultRow = mysql_fetch_assoc($childResult)) {
00118 if($childResultRow['page_module'] != "link" || $retrieveLinks == true) {
00119 $a = new DirectoryTreeNode($childResultRow['page_id'], $userid, $groups, $permId, $permSet);
00120
00121 if($a->isRequired) {
00122 $this->isRequired = true;
00123 }
00124
00125 $this->children[] = $a;
00126 }
00127 }
00128 }
00129
00130 public function getPageId() {
00131 return $this->pageId;
00132 }
00133
00134 public function getPageName() {
00135 return $this->pageName;
00136 }
00137
00138 public function getPageTitle() {
00139 return $this->pageTitle;
00140 }
00141
00142 public function getChild($index) {
00143 if ($index < count($this->children) && $index >= 0)
00144 return $this->children[$index];
00145 }
00146
00147 public function getChildrenCount() {
00148 return count($this->children);
00149 }
00150
00151 public function getPermission() {
00152 return $this->permission;
00153 }
00154
00155 public function isRequired() {
00156 return $this->isRequired;
00157 }
00158 }
00159
00160 class DirectoryTree {
00161 private $rootNode;
00162
00163 private static function getTreeAsArray(DirectoryTreeNode $node) {
00164 $a = array ();
00165 $a[$node->getPageId()] = array ();
00166
00167 $l = $node->getChildrenCount();
00168
00169 for ($i = 0; $i < $l; $i++) {
00170 $tempNode = $node->getChild($i);
00171 $a[] = DirectoryTree :: getTreeAsArray($tempNode);
00172 }
00173
00174 return $a;
00175 }
00176
00177 private static function getTreeAsString(DirectoryTreeNode $node, $parentPath) {
00178 if(!$node->isRequired()) {
00179 return '';
00180 }
00181
00182 $c = $node->getChildrenCount();
00183 $parentPath .= $node->getPageName() . '/';
00184 $perm = $node->getPermission() == true ? 'ddtree_accessible' : 'ddtree_inaccessible';
00185
00186 $html = "<li><span title=\"$parentPath\" class=\"$perm\">" . $node->getPageTitle() . '</span>';
00187
00188 if($c > 0) {
00189 $html .= "<ul>\n";
00190 }
00191
00192 for ($i = 0; $i < $c; $i++) {
00193 $html .= DirectoryTree :: getTreeAsString($node->getChild($i), $parentPath) . "\n";
00194 }
00195
00196 if($c > 0) {
00197 $html .= "</ul>\n";
00198 }
00199
00200 return $html . "</li>\n";
00201 }
00202
00203 public function __construct($pageId, $userId, $action, $module, $showLinks = false) {
00204 $groups = getGroupIds($userId);
00205 $permSet = array_fill(0, count($groups) + 1, 'U');
00206
00207 $permId = getPermissionId($module, $action);
00208 if($permId < 0)
00209 return;
00210
00211 $this->rootNode = new DirectoryTreeNode($pageId, $userId, $groups, $permId, $permSet, $showLinks);
00212 }
00213
00214 public function toArray() {
00215 return DirectoryTree :: getTreeAsArray($this->rootNode);
00216 }
00217
00224 public function toHtml($treeContainerId, $treeId, $inputBoxId = "") {
00225 $script = '';
00226 if($inputBoxId=="") {
00227 $inputBoxId = "directoryBrowserPagePath";
00228 $script = '<input type="text" id="directoryBrowserPagePath" style="width: 100%" value="" />';
00229 }
00230
00231 global $cmsFolder;
00232 global $urlRequestRoot;
00233 global $templateFolder;
00234 $imagesFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/images";
00235 $scriptsFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/common/scripts";
00236
00237 $script .= '<script type="text/javascript" language="javascript" src="' . $scriptsFolder . '/treemenu.js"></script>';
00238
00239 $activateScript = <<<ACTIVATESCRIPT
00240 <script type="text/javascript" language="javascript">
00241 <!--
00242 ddtreemenu = new JSTreeMenu('$treeId', '$inputBoxId', '$imagesFolder', false);
00243
00244
00245
00246
00247
00248
00249
00250 -->
00251 </script>
00252 ACTIVATESCRIPT;
00253
00254 return $script . '<div id="' . $treeContainerId . '"><ul class="treeview" id="' . $treeId . '">' . DirectoryTree :: getTreeAsString($this->rootNode, '') . '</ul></div>'. $activateScript;
00255 }
00256 }
00257
00258