|
1 | 1 | <?php |
2 | 2 | /** |
3 | 3 | * @package pragyan |
| 4 | + * @author Sriram Sundarraj (srirams6) |
4 | 5 | * @copyright (c) 2010 Pragyan Team |
5 | 6 | * @license http://www.gnu.org/licenses/ GNU Public License |
6 | 7 | * For more details, see README |
7 | 8 | */ |
8 | | -if(!defined('__PRAGYAN_CMS')) |
9 | | -{ |
10 | | - header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden'); |
11 | | - echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>"; |
12 | | - echo '<hr/>'.$_SERVER['SERVER_SIGNATURE']; |
13 | | - exit(1); |
| 9 | +if (!defined('__PRAGYAN_CMS')) { |
| 10 | + header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden'); |
| 11 | + echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>"; |
| 12 | + echo '<hr/>'.$_SERVER['SERVER_SIGNATURE']; |
| 13 | + exit(1); |
14 | 14 | } |
15 | 15 |
|
16 | 16 | /** |
|
19 | 19 | * |
20 | 20 | * @return $searchbar The search bar for tags. |
21 | 21 | */ |
22 | | -function getSearchbar($userId, $pageId){ |
23 | | - if(isset($_GET['searchbar']) && isset($_GET['searchContents'])){ |
24 | | - $searchQuery="SELECT DISTINCT `page_id` FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `tag_text` LIKE '%{$_GET['searchContents']}%';"; |
25 | | - $searchResult=mysql_query($searchQuery); |
26 | | - $suggestions=""; |
27 | | - while($row=mysql_fetch_assoc($searchResult)){ |
28 | | - $suggestions.="<a href=".hostURL().getPagePath($row['page_id']).">"; |
29 | | - $pageInfo=getPageInfo($row['page_id']); |
30 | | - $suggestions.=$pageInfo['page_title']."</a><br/>"; |
31 | | - } |
32 | | - echo $suggestions; |
33 | | - exit(0); |
34 | | - } |
35 | | - $allPageQuery="SELECT `page_id`, `page_module` FROM `". MYSQL_DATABASE_PREFIX ."pages`"; |
36 | | - $allPageResult=mysql_query($allPageQuery); |
37 | | - $pagesIdList=array(); |
38 | | - while ($row=mysql_fetch_assoc($allPageResult)){ |
39 | | - if(getPermissions($userId, $row['page_id'], $action="view", $module=$row['page_module'])) |
40 | | - array_push($pagesIdList, intval($row['page_id'])); |
41 | | - } |
42 | | - $tagsWithPermsQuery="SELECT * FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `page_id` IN ("; |
43 | | - foreach ($pagesIdList as $key => $value) { |
44 | | - $tagsWithPermsQuery.=$value.","; |
45 | | - } |
46 | | - $tagsWithPermsQuery=substr($tagsWithPermsQuery,0,-1).");"; |
47 | | - $tagsWithPermsResult= mysql_query($tagsWithPermsQuery); |
48 | | - $searchbar=<<<SEARCHSCRIPT |
49 | | - <script> |
50 | | - function showResult(searchstr) { |
51 | | - if (searchstr.length==0) { |
52 | | - document.getElementById("tagSuggestions").innerHTML=""; |
53 | | - document.getElementById("tagSuggestions").style.border="0px"; |
54 | | - return; |
55 | | - } |
56 | | - if (window.XMLHttpRequest) { |
57 | | - // code for IE7+, Firefox, Chrome, Opera, Safari |
58 | | - xmlhttp=new XMLHttpRequest(); |
59 | | - }else { // code for IE6, IE5 |
60 | | - xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); |
61 | | - } |
62 | | - xmlhttp.onreadystatechange=function() { |
63 | | - if (xmlhttp.readyState==4 && xmlhttp.status==200) { |
64 | | - if(xmlhttp.responseText != ""){ |
65 | | - console.log(xmlhttp.responseText); |
66 | | - document.getElementById("tagSuggestions").innerHTML=xmlhttp.responseText; |
67 | | - document.getElementById("tagSuggestions").style.border="1px solid #A5ACB2"; |
68 | | - } |
69 | | - else{ |
70 | | - document.getElementById("tagSuggestions").innerHTML=""; |
71 | | - document.getElementById("tagSuggestions").style.border="0px"; |
72 | | - } |
73 | | - } |
74 | | - } |
75 | | - xmlhttp.open("GET","./&searchbar=1&searchContents="+searchstr,true); |
76 | | - xmlhttp.send(); |
77 | | - } |
78 | | - </script> |
| 22 | +function getSearchbar($userId, $pageId) { |
| 23 | + if(isset($_GET['searchbar']) && isset($_GET['searchContents'])) { |
| 24 | + $_GET['searchbar'] = escape($_GET['searchbar']); |
| 25 | + $_GET['searchContents'] = escape($_GET['searchContents']); |
| 26 | + |
| 27 | + $allPageQuery="SELECT `page_id`, `page_module` FROM `". MYSQL_DATABASE_PREFIX ."pages`"; |
| 28 | + $allPageResult=mysql_query($allPageQuery); |
| 29 | + $pagesIdList=array(); //Contains all pages for which the user has view permission |
| 30 | + while ($row=mysql_fetch_assoc($allPageResult)) { |
| 31 | + if(getPermissions($userId, $row['page_id'], $action="view", $module=$row['page_module'])) |
| 32 | + array_push($pagesIdList, intval($row['page_id'])); |
| 33 | + } |
| 34 | + $searchQueryParams=""; |
| 35 | + foreach ($pagesIdList as $key => $value) { |
| 36 | + $searchQueryParams.=$value.","; |
| 37 | + } |
| 38 | + $searchQueryParams=substr($searchQueryParams,0,-1); |
| 39 | + $searchQuery="SELECT * FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `tag_text` LIKE '%{$_GET['searchContents']}%' AND `page_id` IN (".$searchQueryParams.");"; |
| 40 | + $tagsWithPermsResult= mysql_query($searchQuery); |
| 41 | + |
| 42 | + $searchResult=mysql_query($searchQuery); |
| 43 | + $suggestions=""; |
| 44 | + while ($row=mysql_fetch_assoc($searchResult)) { |
| 45 | + $suggestions.="<a href=".hostURL().getPagePath($row['page_id']).">"; |
| 46 | + $pageInfo=getPageInfo($row['page_id']); |
| 47 | + $suggestions.=$pageInfo['page_title']."</a><br/>"; |
| 48 | + } |
| 49 | + echo $suggestions; |
| 50 | + exit(0); |
| 51 | + } |
| 52 | + $searchbar=<<<SEARCHSCRIPT |
| 53 | + <script> |
| 54 | + function showResult(searchstr) { |
| 55 | + if (searchstr.length==0) { |
| 56 | + document.getElementById("tagSuggestions").innerHTML=""; |
| 57 | + document.getElementById("tagSuggestions").style.border="0px"; |
| 58 | + return; |
| 59 | + } |
| 60 | + if (window.XMLHttpRequest) { |
| 61 | + // code for IE7+, Firefox, Chrome, Opera, Safari |
| 62 | + xmlhttp=new XMLHttpRequest(); |
| 63 | + }else { // code for IE6, IE5 |
| 64 | + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); |
| 65 | + } |
| 66 | + xmlhttp.onreadystatechange=function() { |
| 67 | + if (xmlhttp.readyState==4 && xmlhttp.status==200) { |
| 68 | + if(xmlhttp.responseText != "") { |
| 69 | + console.log(xmlhttp.responseText); |
| 70 | + document.getElementById("tagSuggestions").innerHTML=xmlhttp.responseText; |
| 71 | + document.getElementById("tagSuggestions").style.border="1px solid #A5ACB2"; |
| 72 | + } |
| 73 | + else { |
| 74 | + document.getElementById("tagSuggestions").innerHTML=""; |
| 75 | + document.getElementById("tagSuggestions").style.border="0px"; |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + xmlhttp.open("GET","./&searchbar=1&searchContents="+searchstr,true); |
| 80 | + xmlhttp.send(); |
| 81 | + } |
| 82 | + </script> |
79 | 83 | SEARCHSCRIPT; |
80 | | - $searchbar.="<div id=\"cms-searchbar\">"; |
81 | | - $searchbar.="<input type=\"text\" size=\"30\" onkeyup=\"showResult(this.value)\">"; |
82 | | - $searchbar.="<div id=\"tagSuggestions\"></div>"; |
83 | | - $searchbar.="</div>"; |
84 | | - return $searchbar; |
| 84 | + $searchbar.="<div id='cms-searchbar'>"; |
| 85 | + $searchbar.="<input type='text' size='30' onkeyup='showResult(this.value)'>"; |
| 86 | + $searchbar.="<div id='tagSuggestions'></div>"; |
| 87 | + $searchbar.="</div>"; |
| 88 | + return $searchbar; |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * @param $pageId The page on which the permissible action for the user is computed |
| 93 | + * |
| 94 | + * @return $pagetags The tags for the page. |
| 95 | + */ |
| 96 | +function getPagetags($pageId) { |
| 97 | + $pageTagQuery="SELECT `tag_text` FROM `". MYSQL_DATABASE_PREFIX ."pagetags` WHERE `page_id` = {$pageId}"; |
| 98 | + $pageTagResult=mysql_query($pageTagQuery); |
| 99 | + $pagetags=[]; |
| 100 | + while ($row=mysql_fetch_assoc($pageTagResult)) { |
| 101 | + array_push($pagetags, $row['tag_text']); |
| 102 | + } |
| 103 | + $pagetags = implode(" , ", $pagetags); |
| 104 | + return $pagetags; |
85 | 105 | } |
0 commit comments