public function actionView() { global $sourceFolder; require_once "{$sourceFolder}/common.lib.php"; $pageid = getPageIdFromModuleComponentId("pagelist", $this->moduleComponentId); $pageid = getParentPage($pageid); $query = "SELECT `depth` FROM `list_prop` WHERE `page_modulecomponentid`='{$this->moduleComponentId}'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); $reqdepth = $row['depth']; $out = $this->generatePagelist($pageid, $this->userId, 0, 'view', $reqdepth + 1); return $out; }
function getContent($pageId, $action, $userId, $permission, $recursed = 0) { if ($action == "login") { if ($userId == 0) { ///Commented the requirement of login.lib.php because it is already included in /index.php //require_once("login.lib.php"); $newUserId = login(); if (is_numeric($newUserId)) { return getContent($pageId, "view", $newUserId, getPermissions($newUserId, $pageId, "view"), 0); } else { return $newUserId; } ///<The login page } else { displayinfo("You are logged in as " . getUserName($userId) . "! Click <a href=\"./+logout\">here</a> to logout."); } return getContent($pageId, "view", $userId, getPermissions($userId, $pageId, "view"), $recursed = 0); } if ($action == "profile") { if ($userId != 0) { require_once "profile.lib.php"; return profile($userId); } else { displayinfo("You need to <a href=\"./+login\">login</a> to view your profile.!"); } } if ($action == "logout") { if ($userId != 0) { $newUserId = resetAuth(); displayinfo("You have been logged out!"); global $openid_enabled; if ($openid_enabled == 'true') { displaywarning("If you logged in via Open ID, make sure you also log out from your Open ID service provider's website. Until then your session in this website will remain active !"); } return getContent($pageId, "view", $newUserId, getPermissions($newUserId, $pageId, "view"), 0); } else { displayinfo("You need to <a href=\"./+login\">login</a> first to logout!"); } } if ($action == "search") { require_once "search.lib.php"; $ret = getSearchBox(); if (isset($_POST['query'])) { $ret .= getSearchResultString($_POST['query']); } elseif (isset($_GET['query'])) { $ret .= getSearchResultString($_GET['query']); } return $ret; } if (isset($_GET['subaction']) && $_GET['subaction'] == 'getchildren') { if (isset($_GET['parentpath'])) { global $urlRequestRoot; require_once 'menu.lib.php'; $pidarr = array(); parseUrlReal(escape($_GET['parentpath']), $pidarr); $pid = $pidarr[count($pidarr) - 1]; $children = getChildren($pid, $userId); $response = array(); $response['path'] = escape($_GET['parentpath']); $response['items'] = array(); foreach ($children as $child) { $response['items'][] = array($urlRequestRoot . '/home' . escape($_GET['parentpath']) . $child[1], $child[2]); } //echo json_encode($response); exit; } } if ($permission != true) { if ($userId == 0) { $suggestion = "(Try <a href=\"./+login\">logging in?</a>)"; } else { $suggestion = ""; } displayerror("You do not have the permissions to view this page. {$suggestion}<br /><input type=\"button\" onclick=\"history.go(-1)\" value=\"Go back\" />"); return ''; } if ($action == "admin") { require_once "admin.lib.php"; return admin($pageId, $userId); } ///default actions also to be defined here (and not outside) /// Coz work to be done after these actions do involve the page $pagetype_query = "SELECT page_module, page_modulecomponentid FROM " . MYSQL_DATABASE_PREFIX . "pages WHERE page_id='" . escape($pageId) . "'"; $pagetype_result = mysql_query($pagetype_query); $pagetype_values = mysql_fetch_assoc($pagetype_result); if (!$pagetype_values) { displayerror("The requested page does not exist."); return ""; } $moduleType = $pagetype_values['page_module']; $moduleComponentId = $pagetype_values['page_modulecomponentid']; if ($action == "settings") { ///<done here because we needed to check if the page exists for sure. require_once "pagesettings.lib.php"; return pagesettings($pageId, $userId); } if ($action == "widgets") { return handleWidgetPageSettings($pageId); } if ($recursed == 0) { $pagetypeupdate_query = "UPDATE " . MYSQL_DATABASE_PREFIX . "pages SET page_lastaccesstime=NOW() WHERE page_id='" . escape($pageId) . "'"; $pagetypeupdate_result = mysql_query($pagetypeupdate_query); if (!$pagetypeupdate_result) { return '<div class="cms-error">Error No. 563 - An error has occured. Contact the site administators.</div>'; } } if ($moduleType == "link") { return getContent($moduleComponentId, $action, $userId, true, 1); } if ($action == "grant") { return grantPermissions($userId, $pageId); } if ($moduleType == "menu") { return getContent(getParentPage($pageId), $action, $userId, true, 1); } if ($moduleType == "external") { $query = "SELECT `page_extlink` FROM `" . MYSQL_DATABASE_PREFIX . "external` WHERE `page_modulecomponentid` =\n\t\t\t\t\t(SELECT `page_modulecomponentid` FROM `" . MYSQL_DATABASE_PREFIX . "pages` WHERE `page_id`= '" . escape($pageId) . "')"; $result = mysql_query($query); $values = mysql_fetch_array($result); $link = $values[0]; header("Location: {$link}"); } global $sourceFolder; global $moduleFolder; require_once $sourceFolder . "/" . $moduleFolder . "/" . $moduleType . ".lib.php"; $page = new $moduleType(); if (!$page instanceof module) { displayerror("The module \"{$moduleType}\" does not implement the inteface module</div>"); return ""; } $createperms_query = " SELECT * FROM " . MYSQL_DATABASE_PREFIX . "permissionlist where perm_action = 'create' AND page_module = '" . $moduleType . "'"; $createperms_result = mysql_query($createperms_query); if (mysql_num_rows($createperms_result) < 1) { displayerror("The action \"create\" does not exist in the module \"{$moduleType}\"</div>"); return ""; } $availableperms_query = "SELECT * FROM " . MYSQL_DATABASE_PREFIX . "permissionlist where perm_action != 'create' AND page_module = '" . $moduleType . "'"; $availableperms_result = mysql_query($availableperms_query); $permlist = array(); while ($value = mysql_fetch_assoc($availableperms_result)) { array_push($permlist, $value['perm_action']); } array_push($permlist, "view"); $class_methods = get_class_methods($moduleType); foreach ($permlist as $perm) { if (!in_array("action" . ucfirst($perm), $class_methods)) { displayerror("The action \"{$perm}\" does not exist in the module \"{$moduleType}\"</div>"); return ""; } } if ($action == "pdf") { if (isset($_GET['depth'])) { $depth = $_GET['depth']; } else { $depth = 0; } if (!is_numeric($depth)) { $depth = 0; } global $TITLE; global $sourceFolder; require_once "{$sourceFolder}/modules/pdf/html2fpdf.php"; $pdf = new HTML2FPDF(); $pdf->setModuleComponentId($moduleComponentId); $pdf->AddPage(); $pdf->WriteHTML($page->getHtml($userId, $moduleComponentId, "view")); $cp = array(); $j = 0; if ($depth == -1) { $cp = child($pageId, $userId, $depth); if ($cp[0][0]) { for ($i = 0; $cp[$i][0] != NULL; $i++) { require_once $sourceFolder . "/" . $moduleFolder . "/" . $cp[$i][2] . ".lib.php"; $page1 = new $cp[$i][2](); $modCompId = $cp[$i][5]; $pdf->setModuleComponentId($modCompId); $pdf->AddPage(); $pdf->WriteHTML($page1->getHtml($userId, $modCompId, "view")); } } } else { if ($depth > 0) { $cp = child($pageId, $userId, $depth); --$depth; while ($depth > 0) { $count = count($cp); for ($j; $j < $count; $j++) { $cp = array_merge((array) $cp, (array) child($cp[$j][0], $userId, $depth)); } --$depth; } if ($cp[0][0]) { for ($i = 0; isset($cp[$i]); $i++) { require_once $sourceFolder . "/" . $moduleFolder . "/" . $cp[$i][2] . ".lib.php"; $page1 = new $cp[$i][2](); $modCompId = $cp[$i][5]; $pdf->setModuleComponentId($modCompId); $pdf->AddPage(); $pdf->WriteHTML($page1->getHtml($userId, $modCompId, "view")); } } } } $filePath = $sourceFolder . "/uploads/temp/" . $TITLE . ".pdf"; while (file_exists($filePath)) { $filePath = $sourceFolder . "/uploads/temp/" . $TITLE . "-" . rand() . ".pdf"; } $pdf->Output($filePath); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=\"" . basename($filePath) . "\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($filePath)); @readfile("{$filePath}"); unlink($filePath); } return $page->getHtml($userId, $moduleComponentId, $action); }
/** * Function getMenu * @param userId user Id of the current user logged in. * @param pageIdArray generate menu for the request page. * @return HTML element of the menu. An unordered list. **/ function getMenu($userId, $pageIdArray) { ///This hostURL is to replace all ".(dot)s" with the current address, making the link absolute. ///@functions hostURL() common.lib.php - http://pragyan.org/11 ///@functions selfURI() common.lib.php - http://pragyan.org/11/home/how_to_use/mypage/mypage2 $hostURL = "."; $pageId = $pageIdArray[count($pageIdArray) - 1]; $hostURL = hostURL(); /// A duplicate entry just a fix for changing $hostURL. $MYHOST = hostURL(); /// Returns an array $pageRow = getPageInfo($pageId); $depth = $pageRow['page_menudepth']; /// Default depth is 1 - Should always show atleast one level of sub menu to enable navigation within site. if ($depth == 0) { $depth = 1; } if ($pageRow['page_displaymenu'] == 0) { return ''; } $menutype = $pageRow['page_menutype']; $menuHtml = ""; /// Classic Menu type - No branches are displayed in this type if ($menutype == "classic") { $pageId = $pageIdArray[count($pageIdArray) - 1]; $depth = 1; $hostURL = strstr(selfURI(), '+', true); /// Get parent page details $parentPage = getParentPage($pageId); $parentPageRow = getPageInfo($parentPage); $childListGenerated = getChildList($pageId, $depth, hostURL(), $userId, 1); /// Display the sibling menu of the same depth if ($pageRow['page_displaysiblingmenu']) { if ($pageId != 0) { $imageTag = ""; if ($parentPageRow['page_displayicon'] == 1 && $parentPageRow['page_image'] != NULL) { /// Icon for the menu if present $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$parentPageRow['page_image']}\" alt=\"{$parentPageRow['page_image']}\" />"; } $menuHtml .= '<a href="' . $hostURL . '../"><div class="cms-menuhead">' . $imageTag . $parentPageRow["page_title"] . '</div></a>'; $siblingMenu = getChildList($parentPage, 1, hostURL(), $userId, 1); $menuHtml .= $siblingMenu; } } /// If nothing is generated, then display atleast one item - the current Menu if ($pageRow['page_displaysiblingmenu'] == 0 && $childListGenerated == null) { $imageTag = ""; $pageR = getPageInfo($pageId); if ($pageR['page_displayicon'] == 1) { if ($pageR['page_image'] != NULL) { $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$pageR['page_image']}\" alt=\"{$pageR['page_image']}\" />"; } } $menuHtml .= <<<MENU \t\t\t\t<ul class="topnav"> \t\t\t\t<li> \t\t\t\t\t<a href="./"><div class="cms-menuitem">{$imageTag} {$pageRow['page_title']}</div></a> \t\t\t\t</li> \t\t\t\t</ul> MENU; } ///If the childList is generated, then display the child items if ($childListGenerated != "") { $imageTag = ""; if ($pageRow['page_displayicon'] == 1 && $pageRow['page_image'] != NULL) { $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$pageRow['page_image']}\" alt=\"{$pageRow['page_image']}\" />"; } $menuHtml .= '<a href="' . $hostURL . '"><div class="cms-menuhead">' . $imageTag . $pageRow["page_title"] . '</div></a>'; $menuHtml .= $childListGenerated; } } else { ///Multi Depth Menu Code starts from here if ($menutype == "multidepth") { $pageId = $pageIdArray[count($pageIdArray) - 1]; } else { $pageId = 0; } $rootUri = hostURL(); ///Get page information through pageId $pageRow = getPageInfo($pageId); ///Get the Children of the page. $childListGenerated = getChildList($pageId, $depth, $rootUri, $userId, 1); if ($childListGenerated != "") { $menuHtml .= $childListGenerated; } else { $imageTag = ""; $pageR = getPageInfo($pageId); if ($pageR['page_displayicon'] == 1) { if ($pageR['page_image'] != NULL) { $imageTag = "<img width=32 height=32 src=\"{$rootUri}/{$pageR['page_image']}\" alt=\"{$pageR['page_image']}\" />"; } } $menuHtml .= <<<MENU \t\t\t\t<ul class="topnav"> \t\t\t\t<li> \t\t\t\t\t<a href="./"><div class="cms-menuitem">{$imageTag} {$pageRow['page_title']}</div></a> \t\t\t\t</li> \t\t\t\t</ul> MENU; } } // return the final generated HTML return $menuHtml; }
// get comment list $result = $db->select(array('page'), array('page_id', 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'page_latest'), $sqlWhere, __METHOD__, array('ORDER BY' => 'page_id ASC')); $commentList = array(); while ($row = $db->fetchObject($result)) { $commentList[$row->page_id] = $row; } $db->freeResult($result); // collect and insert data foreach ($commentList as $comment) { $cnt++; echo "{$cnt} [{$fromId}-{$toId}]: ID {$comment->page_id}(NS {$comment->page_namespace}): {$comment->page_title}"; $title = F::build('Title', array($comment), 'newFromRow'); $articleComment = F::build('ArticleComment', array($title), 'newFromTitle'); $articleComment->load(); // parent page id $parentPageId = getParentPage($articleComment); if (empty($parentPageId)) { echo ".....Parent page NOT found.\n"; $failed++; continue; } // get parent comment id $parentCommentObj = $articleComment->getTopParentObj(); if ($parentCommentObj instanceof ArticleComment) { // posts/replies $parentCommentId = $parentCommentObj->getTitle()->getArticleID(); $lastChildCommentId = 0; } else { // main comments $parentCommentId = 0; $lastChildCommentId = getLastChildCommentId($articleComment);
function _requiredAuthorityForPagename($access, $pagename) { static $permcache = array(); if (array_key_exists($pagename, $permcache) and array_key_exists($access, $permcache[$pagename])) { return $permcache[$pagename][$access]; } global $request; $page = $request->getPage($pagename); // Page not found; check against default permissions if (!$page->exists()) { $perm = new PagePermission(); $result = $perm->isAuthorized($access, $request->_user) === true; $permcache[$pagename][$access] = $result; return $result; } // no ACL defined; check for special dotfile or walk down if (!($perm = getPagePermissions($page))) { if ($pagename == '.') { $perm = new PagePermission(); if ($perm->isAuthorized('change', $request->_user)) { // warn the user to set ACL of ".", if he has permissions to do so. trigger_error(". (dotpage == rootpage for inheriting pageperm ACLs) exists without any ACL!\n" . "Please do ?action=setacl&pagename=.", E_USER_WARNING); } $result = $perm->isAuthorized($access, $request->_user) === true; $permcache[$pagename][$access] = $result; return $result; } elseif ($pagename[0] == '.') { $perm = new PagePermission(PagePermission::dotPerms()); $result = $perm->isAuthorized($access, $request->_user) === true; $permcache[$pagename][$access] = $result; return $result; } return _requiredAuthorityForPagename($access, getParentPage($pagename)); } // ACL defined; check if isAuthorized returns true or false or undecided $authorized = $perm->isAuthorized($access, $request->_user); if ($authorized !== -1) { // interestingly true is also -1 $permcache[$pagename][$access] = $authorized; return $authorized; } elseif ($pagename == '.') { return false; } else { return _requiredAuthorityForPagename($access, getParentPage($pagename)); } }
function getPermissions($userid, $pageid, $action, $module = "") { if ($action != "admin" && getPermissions($userid, 0, "admin")) { return true; } if ($module == "") { $query = "SELECT 1 FROM `" . MYSQL_DATABASE_PREFIX . "permissionlist` WHERE page_module=\"page\" AND perm_action=\"{$action}\""; $result = mysql_query($query); if (mysql_num_rows($result) >= 1) { $module = 'page'; } else { $module = getEffectivePageModule($pageid); } } $permission = false; if ($module == "menu" || $module == "external") { return getPermissions($userid, getParentPage($pageid), $action); } /// Find all groups the user belongs to, ordered by priority /// For each group, starting with lowest priority, get permission for the page $pagePath = array(); parseUrlDereferenced($pageid, $pagePath); foreach (getGroupIds($userid) as $groupid) { if ($permission === true) { break; } $permission = getPagePermission($pagePath, $groupid, $action, $module); } if ($permission === false) { $permission = getPagePermission($pagePath, $userid, $action, $module, 'user'); } return $permission; }
/** * parseUrlDereferenced: Takes a url as string, and retrieves the path to the page, dereferencing any links. * * @param $pageid Page id of the requested page. * @param $pageids An array to hold the list of page ids. */ function parseUrlDereferenced($pageid, &$pageids) { $dereferencedPageId = getDereferencedPageId($pageid); $parentId = getParentPage($dereferencedPageId); $pageids = array($dereferencedPageId); while ($parentId != $dereferencedPageId) { $pageids[] = $parentId; $dereferencedPageId = getDereferencedPageId($parentId); $parentId = getParentPage($dereferencedPageId); if ($dereferencedPageId == 0) { break; } } if ($parentId != 0) { displayerror("Looping condition detected!!"); } $pageids = array_reverse($pageids); }
/** * Gets the information about all the widgets which are inherited to a page via any parent page. * @param $pageId Page Id of the given page * @return Array of widgets containing widgets information */ function getInheritedWidgets($pageId) { $parentId = getParentPage($pageId); if ($parentId == $pageId) { return array(); } $query = "SELECT t1.`widget_id` AS 'id', t1.`widget_instanceid` AS 'instanceid', t1.`widget_location` AS 'location', t2.`widget_name` AS 'name', t2.`widget_description` AS 'description', t2.`widget_author` AS 'author', t2.`widget_version` AS 'version', t2.`widget_classname` AS 'classname', t2.`widget_foldername` AS 'foldername' FROM `" . MYSQL_DATABASE_PREFIX . "widgets` AS t1, `" . MYSQL_DATABASE_PREFIX . "widgetsinfo` AS t2 WHERE t1.`page_id`='{$parentId}' AND t1.`widget_propagate`=1 AND t2.`widget_id`=t1.`widget_id` ORDER BY t1.`widget_location` ASC"; $result = mysql_query($query); $return = array(); while ($row = mysql_fetch_array($result)) { $row['source'] = getPagePath($parentId); $return[] = $row; } $more = getInheritedWidgets($parentId); $return = array_merge($return, $more); return $return; }
function submitRegistrationForm($moduleCompId, $userId, $silent = false, $disableCaptcha = false) { ///-------------------------Get anonymous unique negative user id--------------- if ($userId == 0) { $useridQuery = "SELECT MIN(`user_id`) - 1 AS MIN FROM `form_regdata` WHERE 1"; $useridResult = mysql_query($useridQuery); if (mysql_num_rows($useridResult) > 0) { $useridRow = mysql_fetch_assoc($useridResult); $userId = $useridRow['MIN']; } else { $userId = -1; } } ///-----------------------------Anonymous user id ends------------------------------- ///---------------------------- CAPTCHA Validation ---------------------------------- if (!$disableCaptcha) { $captchaQuery = 'SELECT `form_usecaptcha` FROM `form_desc` WHERE `page_modulecomponentid` = \'' . $moduleCompId . "'"; $captchaResult = mysql_query($captchaQuery); $captchaRow = mysql_fetch_row($captchaResult); if ($captchaRow[0] == 1) { if (!submitCaptcha()) { return false; } } } ///------------------------ CAPTCHA Validation Ends Here ---------------------------- $query = "SELECT `form_elementid`,`form_elementtype` FROM `form_elementdesc` WHERE `page_modulecomponentid`='{$moduleCompId}'"; $result = mysql_query($query); $allFieldsUpdated = true; while ($elementRow = mysql_fetch_assoc($result)) { $type = $elementRow['form_elementtype']; $elementId = $elementRow['form_elementid']; $postVarName = "form_" . $moduleCompId . "_element_" . $elementRow['form_elementid']; $functionName = "submitRegistrationForm" . ucfirst(strtolower($type)); $elementDescQuery = "SELECT `form_elementname`,`form_elementsize`,`form_elementtypeoptions`,`form_elementmorethan`," . "`form_elementlessthan`,`form_elementcheckint`,`form_elementisrequired` FROM `form_elementdesc` " . "WHERE `page_modulecomponentid`='{$moduleCompId}' AND `form_elementid` ='{$elementId}'"; $elementDescResult = mysql_query($elementDescQuery); if (!$elementDescResult) { displayerror('E69 : Invalid query: ' . mysql_error()); return false; } $elementDescRow = mysql_fetch_assoc($elementDescResult); $elementName = $elementDescRow['form_elementname']; $elementSize = $elementDescRow['form_elementsize']; $elementTypeOptions = $elementDescRow['form_elementtypeoptions']; $elementMoreThan = $elementDescRow['form_elementmorethan']; $elementLessThan = $elementDescRow['form_elementlessthan']; $elementCheckInt = $elementDescRow['form_elementcheckint'] == 1 ? true : false; $elementIsRequired = $elementDescRow['form_elementisrequired'] == 1 ? true : false; if ($functionName($moduleCompId, $elementId, $userId, $postVarName, $elementName, $elementSize, $elementTypeOptions, $elementMoreThan, $elementLessThan, $elementCheckInt, $elementIsRequired) == false) { // displayerror("Error in inputting data in function $functionName."); $allFieldsUpdated = false; break; } } if (!$allFieldsUpdated) { if ($userId < 0) { unregisterUser($moduleCompId, $userId); } else { if (!verifyUserRegistered($moduleCompId, $userId)) { $deleteelementdata_query = "DELETE FROM `form_elementdata` WHERE `user_id` = '{$userId}' AND `page_modulecomponentid` ='{$moduleCompId}' "; $deleteelementdata_result = mysql_query($deleteelementdata_query); } return false; } } else { if (!verifyUserRegistered($moduleCompId, $userId)) { registerUser($moduleCompId, $userId); } else { updateUser($moduleCompId, $userId); } if (!$silent) { $footerQuery = "SELECT `form_footertext`, `form_sendconfirmation` FROM `form_desc` WHERE `page_modulecomponentid` = '{$moduleCompId}'"; $footerResult = mysql_query($footerQuery); $footerRow = mysql_fetch_row($footerResult); $footerText = $footerRow[0]; $footerTextLength = strlen($footerText); if ($footerTextLength > 7) { if (substr($footerText, 0, 4) == '<!--' && substr($footerText, $footerTextLength - 3) == '-->') { $footerText = substr($footerText, 4, $footerTextLength - 7); } else { $footerText = ''; } } else { $footerText = ''; } displayinfo($footerText == '' ? "User successfully registered!" : $footerText); // send mail code starts here - see common.lib.php for more if ($footerRow[1]) { $from = ''; // Default CMS email will be added automatically if this is left blank $to = getUserEmail($userId); $pageId = getPageIdFromModuleComponentId('form', $moduleCompId); $parentPage = getParentPage($pageId); $formname = getPageTitle($parentPage); $keyid = $finalName = str_pad($userId, 5, '0', STR_PAD_LEFT); $key = ''; $mailtype = "form_registration_mail"; $messenger = new messenger(false); global $onlineSiteUrl; $messenger->assign_vars(array('FORMNAME' => "{$formname}", 'KEY' => "{$key}", 'WEBSITE' => CMS_TITLE, 'DOMAIN' => $onlineSiteUrl, 'NAME' => getUserFullName($userId))); if ($messenger->mailer($to, $mailtype, $key, $from)) { displayinfo("You have been succesfully registered to {$formname} and a registration confirmation mail has been sent. Kindly check your e-mail."); } else { displayerror("Registration confirmation mail sending failure. Kindly contact webadmin@pragyan.org"); } } // send mail code ends here } } return true; }
/** *@author boopathi *@description returns the depth of the page - 0 if the page is a child of /home *@param pageId *@return pageDepth **/ function getPageDepth($pageId) { $depth = 1; if (getParentPage($pageId) == 0) { return 0; } else { return $depth + getPageDepth(getParentPage($pageId)); } }
public function actionReports() { global $userId, $urlRequestRoot; $query = "SELECT `page_id`, `page_modulecomponentid` FROM `" . MYSQL_DATABASE_PREFIX . "pages` WHERE `page_module`='form'"; $resource = mysql_query($query); $report = <<<CSS \t\t <style type="text/css"> \t\t #reports tbody tr.even td { background-color: #f0f8ff; color: #000; } #reports tbody tr td a, a:link, a:visited { \tcolor: #000; } #reports tbody tr.odd td { background-color: #fff;color: #000; } </style> CSS; $report .= '<table id="reports"><tbody><tr><td>Form</td><td>No. of registrants</td></tr>'; $class = 'even'; while ($result = mysql_fetch_assoc($resource)) { $permission = getPermissions($userId, $result[page_id], 'viewRegistrant', 'form'); if ($permission) { $pageId = $result['page_id']; $parentPageId = getParentPage($pageId); $parentTitle = getPageTitle($parentPageId); $formTitle = getPageTitle($pageId); $formInfo = $parentTitle . '_' . $formTitle; $formPath = getPagePath($pageId); $query = "SELECT count(distinct(`user_id`)) FROM `form_regdata` WHERE `page_modulecomponentid`='{$result['page_modulecomponentid']}'"; $resource2 = mysql_query($query); //or die(mysql_error()); $result2 = mysql_fetch_row($resource2); if (!strpos($formPath, 'qaos')) { if ($class == 'even') { $class = 'odd'; } else { $class = 'even'; } $report .= "<tr class=\"{$class}\"><td><a href=\"{$urlRequestRoot}{$formPath}\">{$formInfo}</a></td><td>{$result2['0']}</td></tr>"; } } } $report .= '</tbody></table>'; return $report; }