forked from sauruscms/Saurus-CMS-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcom_del.php
More file actions
204 lines (167 loc) · 6.7 KB
/
com_del.php
File metadata and controls
204 lines (167 loc) · 6.7 KB
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
<?php
/**
* This source file is is part of Saurus CMS content management software.
* It is licensed under MPL 1.1 (http://www.opensource.org/licenses/mozilla1.1.php).
* Copyright (C) 2000-2010 Saurused Ltd (http://www.saurus.info/).
* Redistribution of this file must retain the above copyright notice.
*
* Please note that the original authors never thought this would turn out
* such a great piece of software when the work started using Perl in year 2000.
* Due to organic growth, you may find parts of the software being
* a bit (well maybe more than a bit) old fashioned and here's where you can help.
* Good luck and keep your open source minds open!
*
* @package SaurusCMS
* @copyright 2000-2010 Saurused Ltd (http://www.saurus.info/)
* @license Mozilla Public License 1.1 (http://www.opensource.org/licenses/mozilla1.1.php)
*
*/
##############################
# Deletes a comment from database - for registered users deleting their own comments
# : opens popup window, asks for confirmation and deletes a comment
# : will refresh the calling page
# : is independent script, not for including, new Site is generated
##############################
# CURRENT FILE WAS "kommentaaride_kustutamine.php" in ver 3
global $site;
preg_match('/\/(admin|editor)\//i', $_SERVER["REQUEST_URI"], $matches);
$class_path = $matches[1] == "editor" ? "../classes/" : "./classes/";
include($class_path."port.inc.php");
$site = new Site(array(
on_debug=>0,
on_admin_keel => 1
));
$objekt = new Objekt(array(
objekt_id => $site->fdat['id']
));
if (!$site->CONF['users_can_delete_comment']) {
?>
<SCRIPT LANGUAGE="JavaScript"><!--
window.opener.location = window.opener.location;
window.close();
//--></SCRIPT>
<?
}
if ($site->fdat['op2'] == 'deleteconfirmed') {
/*-------------------------------------
//Valime kasutaja_id kelle oma see kommentaar on
--------------------------------------*/
$sql = $site->db->prepare("SELECT kasutaja_id FROM obj_kommentaar WHERE objekt_id = ?",$site->fdat[id]);
$sth = new SQL($sql);
$site->debug->msg($sth->debug->get_msgs());
$kommenteerija_id = $sth->fetchsingle();
$curr_obj = new Objekt(array(
objekt_id => $site->fdat['id'],
));
$parent_obj = new Objekt(array(
objekt_id => $curr_obj->parent_id,
));
# $alamlist_count - kui palju üldse kommentaare on, parent jaoks
$alamlist_count = new Alamlist(array(
parent => $curr_obj->parent_id,
klass => "kommentaar",
asukoht => 0,
on_counter => 1
));
# Siin valime viimane kommentaar, parent jaoks
$alamlist = new Alamlist(array(
parent => $curr_obj->parent_id,
klass => "kommentaar",
start =>$alamlist_count->rows-1,
limit =>1,
asukoht => 0,
order => " objekt.aeg, objekt.objekt_id ASC ",
));
# $alamlist_count - kui palju child kommentaare on, kui neid on, siis kustutada ei tohi
$alamlist_count2 = new Alamlist(array(
parent => $site->fdat['id'],
klass => "kommentaar",
asukoht => 0,
on_counter => 1
));
$obj_from_alamlist = $alamlist->next();
/*--------------------------------------------------------
//Juhul kui sisselooginud kasutaja_id = kommenteerija_id
//ja see kommentaar on viimane järjekorras, artiklite kommentaarides või
//kui sellele kirjale ei ole veel ühtegi vastust foorumis
// kustutame ära :(
-----------------------------------------------------------*/
#echo "1.".$obj_from_alamlist->objekt_id."<BR>2.".$obj_from_alamlist2->objekt_id."<BR>index1: ".$alamlist->index."<BR>index 2:".$alamlist_count2->rows;
$allow_delete=true;
if($parent_obj->all['klass'] != "teema"){
$allow_delete = ($obj_from_alamlist->objekt_id==$site->fdat['id'] && $alamlist->index == 0?true:false);
} else {
$allow_delete = ($alamlist_count2->rows == 0?true:false);
}
if ($kommenteerija_id == $site->user->user_id && $site->user->user_id && $allow_delete) {
$sql = $site->db->prepare("DELETE FROM objekt WHERE objekt_id=?", $site->fdat['id']);
$sth = new SQL($sql);
$sql = $site->db->prepare("DELETE FROM objekt_objekt WHERE objekt_id=?", $site->fdat['id']);
$sth = new SQL($sql);
$sql = $site->db->prepare("DELETE FROM obj_kommentaar WHERE objekt_id=?", $site->fdat['id']);
$sth = new SQL($sql);
#####################
# UPDATE LAST_COMMENTED_TIME, COMMENT_COUNT
# get comment count for object:
$alamlist_count = new Alamlist(array(
parent => $curr_obj->parent_id,
klass => "kommentaar",
asukoht => 0,
on_counter => 1
));
$comment_count = $alamlist_count->rows;
$sql = $site->db->prepare("UPDATE objekt SET last_commented_time=".$site->db->unix2db_datetime(time()).", comment_count=? WHERE objekt_id=?",
$comment_count,
$curr_obj->parent_id
);
$sth = new SQL($sql);
$site->debug->msg($sth->debug->get_msgs());
?>
<SCRIPT LANGUAGE="JavaScript"><!--
window.opener.location = window.opener.location;
window.close();
//--></SCRIPT>
<?
}
}
######################
# DELETE CONFIRMATION WINDOW
else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?=$site->title?> <?= $site->cms_version ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$site->encoding ?>">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="stylesheet" href="<?=$site->CONF['wwwroot'].$site->CONF['styles_path']?>/scms_general.css">
<SCRIPT LANGUAGE="JavaScript" SRC="<?=$site->CONF['wwwroot'].$site->CONF['js_path']?>/yld.js"></SCRIPT>
</head>
<body class="popup_body" onLoad="this.focus()">
<form name="editform" action="<?=$site->self ?>" method=get>
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
<tr>
<td valign="top" width="100%" class="scms_confirm_delete_cell" height="100%">
<?
$objekt->load_sisu();
echo $site->sys_sona(array(sona => "kustuta", tyyp=>"editor"))." \"<b>".substr($objekt->all['text'],0,20).(strlen($objekt->all['text'])>20?'...':'')."</b>\"? ";
echo $site->sys_sona(array(sona => "are you sure?", tyyp=>"admin"));
?>
</td>
</tr>
<tr align="right">
<td valign="top" colspan=2 >
<input type="button" value="<?=$site->sys_sona(array(sona => "kustuta", tyyp=>"editor")) ?>" onclick="javascript:document.getElementById('op2').value='deleteconfirmed';document.forms['editform'].submit();">
<input type="button" value="<?=$site->sys_sona(array(sona => "close", tyyp=>"editor")) ?>" onclick="javascript:window.close();">
</td>
</tr>
</table>
<input type=hidden id=id name=id value="<?=$objekt->objekt_id?>">
<input type=hidden id=op2 name=op2 value="">
</form>
</body>
</html>
<?php
}
# / DELETE CONFIRMATION WINDOW
######################