-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeywords.php
181 lines (136 loc) · 3.12 KB
/
keywords.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?
require_once("autoInclude.php");
require_once("sessionStart.php");
function getAction()
{
if (isset($_GET['action']))
{
return $_GET['action'];
}
else
{
return null;
}
}
if (getAction() == "add")
{
Keyword::add($sessionId);
header('location:keywords.php?update=true');
}
else if (getAction() == "remove")
{
Keyword::remove($sessionId);
header('location:keywords.php');
}
else if (getAction() == "enlist")
{
$keywords = Keyword::getKeywords($sessionId);
foreach ($keywords as $keyword)
{
//print "<tr><td>".$keyword["str"]."<td width='80px'><form method='post' action='keywords.php?action=remove' ><input type='hidden' name='_id' value='".$keyword["_id"]."'><button>Remove</button></form>";
print $keyword["str"]."\n";
}
exit();
}
else
{
$keywords = Keyword::getKeywords($sessionId);
}
require_once("header.php");
?>
<style>
#tableDiv{text-align:center;width:100%;margin-left:auto;margin-right:auto;}
#tableDiv table{text-align:center;width:100%;}
#keyword{width:100%;text-align:center;}
</style>
<script>
$(document).ready(function(){
});
</script>
<div style="text-align:center;">
Example keywords: mumbai, java, php
</div>
<div id="tableDiv">
<table border="1" width="400px">
<tr><td>
<form id="addKeywordForm" method="POST" action="keywords.php?action=add">
<input id="keyword" type="text" name="keyword"></input>
</td>
<td>
<button id="addKeyword">Add</button>
</form>
</td></tr>
<?
foreach ($keywords as $keyword)
{
print "<tr><td>".$keyword["str"]."<td width='80px'><form method='post' action='keywords.php?action=remove' ><input type='hidden' name='_id' value='".$keyword["_id"]."'><button>Remove</button></form>";
}
?>
</table>
</div>
<script>
/////////////////////
// Following part should be copied as it is from search.htm
/////////////////////
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setKeywordsArrayLocal(keywords)
{
var username = getCookie("username");
localStorage.setItem(username+".keywords", keywords);
localStorage.setItem(username+".lastUpdateDateTime", new Date());
}
// synchrounous http call
// wait for it
function updateKeywordsArray()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// making the call syncronous
xmlhttp.open("GET","keywords.php?action=enlist",false); // false
xmlhttp.send(null);
var lines = xmlhttp.responseText.split("\n");
var keywords = new Array();
for (var i=0;i<lines.length;i++)
{
var line = lines[i];
if (line.length > 0)
{
keywords.push(line);
}
}
setKeywordsArrayLocal(keywords);
return keywords;
}
<? if (isset($_GET["update"]) && $_GET["update"] == "true" )
{ ?>
updateKeywordsArray();
<?
}
?>
</script>
<?
require_once("footer.php");
?>