-
Notifications
You must be signed in to change notification settings - Fork 2
/
deal_with_request.php
253 lines (226 loc) · 11.5 KB
/
deal_with_request.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'group.php');
include(mnminclude.'smartyvariables.php');
include_once(mnminclude.'user.php');
//added by Jason
include_once realpath(dirname(__FILE__)) . '/DAL/NotificationDAO.php';
global $current_user, $globals, $the_template, $smarty, $db;
$timestamp = date("Y-m-d H:i:m");
//get the values from other page
$Sid = $_GET['id'];
$rollback = $_GET['rollback']; //true or false
if(isset($_GET['date'])) {$modified_date = $_GET['date'];} else {$modified_date=null;}
if(isset($_GET['modifieduser'])) {$modified_user = $_GET['modifieduser'];} else {$modified_user=null;}
//echo $modified_user;
if(isset($_GET['titlestr'])) {$title = $_GET['titlestr'];$title_noti= $_GET['titlenoti'];} else {$title=null;}
if(isset($_GET['desstr'])) {$description = $_GET['desstr'];$des_noti= $_GET['desnoti'];} else {$description=null;}
if(isset($_GET['category'])) {$category = $_GET['category'];$category_noti = $_GET['categorynoti'];} else {$category=0;}
if(isset($_GET['tagsstr'])) {$tags = $_GET['tagsstr'];$tags_noti= $_GET['tagsnoti'];} else {$tags="000";}
$s = $db->get_row("SELECT link_id, UserId, Title, link_tags, link_category, link_title, link_content, link_summary FROM ".table_prefix."sourceinfo s inner join colfusion_links l on s.sid = l.link_id WHERE Sid = $Sid");
$link_id = $s->link_id;
$userId = $s->UserId;
//$link_tags = $s->link_tags;
// title is going to be modified
// if the modified text is different from original text($title!=null), import into database
if ($title != null) {
//echo "here";
//update the title from input
$title= \mysql_real_escape_string($title);
$sql_update = "UPDATE colfusion_sourceinfo ";
$sql_update .="SET Title = '{$title}' ";
$sql_update .="WHERE Sid = {$link_id}";
if($db->query($sql_update)) {
//update the link_title
$sql_update = "UPDATE colfusion_links ";
$sql_update .="SET link_title = '{$title}' ";
$sql_update .="WHERE link_id = {$link_id}";
if($db->query($sql_update)) {
//set previous checked to false
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = false ";
$sql_update .="WHERE sid = {$link_id} and field = 'title' and checked = true";
$db->query($sql_update);
// update the wiki history
//rollback==0 means normal modification
if ($rollback==0) {
$title_noti = \mysql_real_escape_string($title_noti);
$sql_insert = "INSERT INTO wiki_history (sid,user_id,timestamp,field,value,notification,checked)
VALUES ('{$link_id}','{$userId}','{$timestamp}','title','{$title}','{$title_noti}',true)";
$db->query($sql_insert);
} else {
//if rollback, I should change the default checked radio button
//find userid
$target_user = $db->get_row("SELECT user_id FROM colfusion_users WHERE user_login = '{$modified_user}'");
$target_user_id = $target_user->user_id;
//echo $target_user_id;
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = true ";
$sql_update .="WHERE sid = {$link_id} and field = 'title' and timestamp = '{$modified_date}' and user_id = {$target_user_id} ";
$db->query($sql_update);
}
}
}
}
// description is going to be modified
// if the modified text is different from original text, import into database
if ($description !=null) {
//update the link_content from input
$description= \mysql_real_escape_string($description);
$sql_update = "UPDATE colfusion_links ";
$sql_update .="SET link_content = '{$description}' ";
$sql_update .="WHERE link_id = {$link_id}";
if($db->query($sql_update)) {
//update the link_summary
$sql_update = "UPDATE colfusion_links ";
$sql_update .="SET link_summary = '{$description}' ";
$sql_update .="WHERE link_id = {$link_id}";
if ($db->query($sql_update)){
//set previous checked to false
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = false ";
$sql_update .="WHERE sid = {$link_id} and field = 'description' and checked = true";
$db->query($sql_update);
if ($rollback==0) {
// update the wiki history
$des_noti = \mysql_real_escape_string($des_noti);
$sql_insert = "INSERT INTO wiki_history (sid,user_id,timestamp,field,value,notification,checked)
VALUES ('{$link_id}','{$userId}','{$timestamp}','description','{$description}','{$des_noti}',true)";
$db->query($sql_insert);
} else {
//if rollback, I should change the default checked radio button
//find userid
$target_user = $db->get_row("SELECT user_id FROM colfusion_users WHERE user_login = '{$modified_user}'");
$target_user_id = $target_user->user_id;
//echo $target_user_id;
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = true ";
$sql_update .="WHERE sid = {$link_id} and field = 'description' and timestamp = '{$modified_date}' and user_id = {$target_user_id} ";
$db->query($sql_update);
}
}
}
}
// category is going to be modified
// if the option is different from original one, import into database
if ($category!=0) {
//update the category
$sql_update = "UPDATE colfusion_links ";
$sql_update .="SET link_category = '{$category}' ";
$sql_update .="WHERE link_id = {$link_id}";
if($db->query($sql_update)) {
//set previous checked to false
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = false ";
$sql_update .="WHERE sid = {$link_id} and field = 'category' and checked = true";
$db->query($sql_update);
switch ($category) {
case 1:
$category = "News";
break;
case 2:
$category = "Bussiness";
break;
case 3:
$category = "History";
break;
default:
break;
}
if ($rollback==0) {
// update the wiki history
$sql_insert = "INSERT INTO wiki_history (sid,user_id,timestamp,field,value,notification,checked)
VALUES ('{$link_id}','{$userId}','{$timestamp}','category','{$category}','{$category_noti}',true)";
$db->query($sql_insert);
} else {
//if rollback, I should change the default checked radio button
//find userid
$target_user = $db->get_row("SELECT user_id FROM colfusion_users WHERE user_login = '{$modified_user}'");
$target_user_id = $target_user->user_id;
//echo $target_user_id;
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = true ";
$sql_update .="WHERE sid = {$link_id} and field = 'category' and timestamp = '{$modified_date}' and user_id = {$target_user_id} ";
$db->query($sql_update);
}
}
}
// tags is going to be modified
// if the modified text is different from original text, import into database
if ($tags != "000") {
//echo "here";
//update the tags from input
//update the link_tags
$tags= \mysql_real_escape_string($tags);
$sql_update = "UPDATE colfusion_links ";
$sql_update .="SET link_tags = '{$tags}' ";
$sql_update .="WHERE link_id = {$link_id}";
if($db->query($sql_update)) {
//set previous checked to false
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = false ";
$sql_update .="WHERE sid = {$link_id} and field = 'tags' and checked = true";
$db->query($sql_update);
if ($rollback==0) {
// update the wiki history
$tags_noti = \mysql_real_escape_string($tags_noti);
$sql_insert = "INSERT INTO wiki_history (sid,user_id,timestamp,field,value,notification,checked)
VALUES ('{$link_id}','{$userId}','{$timestamp}','tags','{$tags}','{$tags_noti}',true)";
if($db->query($sql_insert)) {
$sql_update = "UPDATE colfusion_tags ";
$sql_update .="SET tag_words = '{$tags}' ";
$sql_update .="WHERE tag_link_id = {$link_id}";
$db->query($sql_update);
}
} else {
//if rollback, I should change the default checked radio button
//find userid
$target_user = $db->get_row("SELECT user_id FROM colfusion_users WHERE user_login = '{$modified_user}'");
$target_user_id = $target_user->user_id;
//echo $target_user_id;
$sql_update = "UPDATE wiki_history ";
$sql_update .="SET checked = true ";
$sql_update .="WHERE sid = {$link_id} and field = 'tags' and timestamp = '{$modified_date}' and user_id = {$target_user_id} ";
$db->query($sql_update);
}
}
}
//added by Jason
$notificationDAO = new NotificationDAO();
$notificationDAO->addEditNTFtoDB($link_id);
//echo $str."<br/>";
/*
error_reporting(E_ALL ^ E_DEPRECATED);
$con = mysql_connect($servername,$username,$password);
if (!$con){
die('Could not connect: ' . mysql_error());
//echo 'fail to connect';
} else {
mysql_select_db($database,$con);
$sql_select = " SELECT content
FROM description
WHERE id=(SELECT MAX(id)
FROM description)";
if (!mysql_query($sql_select,$con)) {
die('Error: ' . mysql_error());
} else {
$result = mysql_query($sql_select,$con);
$row = mysql_fetch_array($result);
}
if ($row['content']!=$str) {
$str= \mysql_real_escape_string($str);
$sql="INSERT INTO description (content) VALUES('{$str}')";
//mysql_query($create_table,$con);
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
} else {
echo "insert succeeded";
}
}
}
*/
?>