Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
//                                                                            //
5
//   Copyright (C) 2006  Phorum Development Team                              //
6
//   http://www.phorum.org                                                    //
7
//                                                                            //
8
//   This program is free software. You can redistribute it and/or modify     //
9
//   it under the terms of either the current Phorum License (viewable at     //
10
//   phorum.org) or the Phorum License that was distributed with this file    //
11
//                                                                            //
12
//   This program is distributed in the hope that it will be useful,          //
13
//   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
14
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
15
//                                                                            //
16
//   You should have received a copy of the Phorum License                    //
17
//   along with this program.                                                 //
18
////////////////////////////////////////////////////////////////////////////////
19
define('phorum_page','moderation');
20
 
21
include_once("./common.php");
22
include_once("./include/moderation_functions.php");
23
include_once("./include/thread_info.php");
24
include_once("./include/email_functions.php");
25
 
26
if(!phorum_check_read_common()) {
27
  return;
28
}
29
 
30
$PHORUM["DATA"]["MODERATOR"] = phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
31
 
32
$msgthd_id = (isset($_POST["thread"])) ? (int)$_POST["thread"] : (int)$PHORUM['args'][2];
33
 
34
$mod_step = (isset($_POST["mod_step"])) ? (int)$_POST["mod_step"] : (int)$PHORUM['args'][1];
35
 
36
if(empty($msgthd_id) || !phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES)) {
37
   phorum_return_to_list();
38
}
39
 
40
// If the user is not fully logged in, send him to the login page.
41
// because moderation action can vary so much, the only safe bet is to send them
42
// to the referrer if they are not fully logged in
43
if(!$PHORUM["DATA"]["FULLY_LOGGEDIN"]){
44
    phorum_redirect_by_url(phorum_get_url(PHORUM_LOGIN_URL, "redir=".$_SERVER["HTTP_REFERER"]));
45
    exit();
46
}
47
 
48
 
49
$template="message";
50
// set all our URL's
51
phorum_build_common_urls();
52
 
53
// make it possible to override this var in a hook
54
$is_admin_user=$PHORUM["user"]["admin"];
55
 
56
// a hook for doing stuff in moderation, i.e. logging moderator-actions
57
phorum_hook("moderation",$mod_step);
58
 
59
 
60
switch ($mod_step) {
61
 
62
   case PHORUM_DELETE_MESSAGE: // this is a message delete
63
 
64
        // check that they're an admin if they want to delete an announcement
65
        $message = phorum_db_get_message($msgthd_id);
66
        if ($message["sort"] == PHORUM_SORT_ANNOUNCEMENT && !$is_admin_user){
67
            $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]["LANG"]["DeleteAnnouncementForbidden"];
68
            break;
69
        }
70
        $msg_ids=phorum_db_delete_message($msgthd_id, PHORUM_DELETE_MESSAGE);
71
        foreach($msg_ids as $id){
72
            $files=phorum_db_get_message_file_list($id);
73
            foreach($files as $file_id=>$data){
74
                phorum_db_file_delete($file_id);
75
            }
76
        }
77
        phorum_hook("delete", $msg_ids);
78
        $nummsgs=count($msg_ids);
79
        $PHORUM['DATA']['MESSAGE']=$nummsgs." ".$PHORUM["DATA"]['LANG']['MsgDeletedOk'];
80
        if(isset($PHORUM['args']["prepost"])) {
81
            $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
82
        } else {
83
            $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
84
        }
85
        break;
86
 
87
   case PHORUM_DELETE_TREE: // this is a message delete
88
        // check that they're an admin if they want to delete an announcement
89
        $message = phorum_db_get_message($msgthd_id);
90
        if ($message["sort"] == PHORUM_SORT_ANNOUNCEMENT && !$is_admin_user){
91
            $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]["LANG"]["DeleteAnnouncementForbidden"];
92
            break;
93
        }
94
 
95
        // Delete the message and all its replies.
96
        $msg_ids=phorum_db_delete_message($msgthd_id, PHORUM_DELETE_TREE);
97
 
98
        // Cleanup the attachments for all deleted messages.
99
        foreach($msg_ids as $id){
100
            $files=phorum_db_get_message_file_list($id);
101
            foreach($files as $file_id=>$data){
102
                phorum_db_file_delete($file_id);
103
            }
104
        }
105
 
106
        // Check if we have moved threads to delete.
107
        // We unset the forum id, so phorum_db_get_messages()
108
        // will return messages with the same thread id in
109
        // other forums as well (those are the move notifications).
110
        $forum_id = $PHORUM["forum_id"];
111
        $PHORUM["forum_id"] = 0;
112
        $moved = phorum_db_get_messages($msgthd_id);
113
        $PHORUM["forum_id"] = $forum_id;
114
        foreach ($moved as $id => $data) {
115
            if (isset($data["meta"]["moved"])) {
116
                phorum_db_delete_message($id, PHORUM_DELETE_MESSAGE);
117
            }
118
        }
119
 
120
        // Run a hook for performing custom cleanup actions.
121
        phorum_hook("delete", $msg_ids);
122
 
123
        $nummsgs=count($msg_ids);
124
        $PHORUM['DATA']['MESSAGE']=$nummsgs." ".$PHORUM["DATA"]["LANG"]['MsgDeletedOk'];
125
        if(isset($PHORUM['args']["prepost"])) {
126
            $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
127
        } else {
128
            $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
129
        }
130
        break;
131
 
132
   case PHORUM_MOVE_THREAD: // this is the first step of a message move
133
        // check if the thread to move is an announcement thread
134
        $message = phorum_db_get_message($msgthd_id);
135
        if ($message["sort"] == PHORUM_SORT_ANNOUNCEMENT) {
136
            $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]["LANG"]["MoveAnnouncementForbidden"];
137
            break;
138
        }
139
        $PHORUM['DATA']['URL']["ACTION"]=phorum_get_url(PHORUM_MODERATION_ACTION_URL);
140
        $PHORUM['DATA']["FORM"]["forum_id"]=$PHORUM["forum_id"];
141
        $PHORUM['DATA']["FORM"]["thread_id"]=$msgthd_id;
142
        $PHORUM['DATA']["FORM"]["mod_step"]=PHORUM_DO_THREAD_MOVE;
143
 
144
        // get all the forums the moderator may move to
145
        $PHORUM['DATA']["MoveForumsOption"]="";
146
 
147
 
148
        $forums=phorum_db_get_forums(0,-1,$PHORUM['vroot']);
149
        asort($forums);
150
 
151
        foreach($forums as $id=>$forum){
152
            if ($id == $PHORUM["forum_id"]) continue;
153
            // add  && phorum_user_moderate_allowed($id) if the mod should only be able
154
            // to move to forums he also moderates
155
            if($forum["folder_flag"]==0){
156
                 // it makes no sense to move to the forum we are in already
157
                 if($forum['forum_id'] != $PHORUM['forum_id']) {
158
                    $forum_data[strtolower($forum["name"])]=array("forum_id"=>$id, "name"=>$forum["name"]);
159
                 }
160
            }
161
        }
162
 
163
        $PHORUM['DATA']['FRM']=1;
164
        $PHORUM['DATA']['FORUMS']=$forum_data;
165
        $output=true;
166
 
167
        $template="move_form";
168
 
169
        break;
170
 
171
   case PHORUM_DO_THREAD_MOVE: // this is the last step of a message move
172
 
173
        $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['MsgMoveOk'];
174
        $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
175
        $message = phorum_db_get_message($msgthd_id);
176
 
177
        // find out if we have a notification-message already in this
178
        // target-forum for this thread ... it doesn't make sense to keep this
179
        // message any longer as the thread has reappeared on its original location
180
        $temp_forum_id=$PHORUM['forum_id'];
181
        $PHORUM['forum_id']=$_POST['moveto'];
182
        $check_messages=phorum_db_get_messages($msgthd_id);
183
 
184
        unset($check_messages['users']);
185
 
186
        // ok, we found exactly one message of this thread in the target forum
187
        if(is_array($check_messages) && count($check_messages) == 1) {
188
            // ... going to delete it
189
            $tmp_message=array_shift($check_messages);
190
            $retval=phorum_db_delete_message($tmp_message['message_id']);
191
        }
192
 
193
        $PHORUM['forum_id']=$temp_forum_id;
194
 
195
        // Move the thread to another forum.
196
        phorum_db_move_thread($msgthd_id, $_POST['moveto']);
197
 
198
        // Create a new message in place of the old one to notify
199
        // visitors that the thread was moved.
200
        if(isset($_POST['create_notification']) && $_POST['create_notification']) {
201
            $newmessage = $message;
202
            $newmessage['body']=" -- moved topic -- ";
203
            $newmessage['meta']=array('moved' => 1);
204
            $newmessage['sort']=PHORUM_SORT_DEFAULT;
205
            unset($newmessage['message_id']);
206
 
207
            phorum_db_post_message($newmessage);
208
        }
209
        phorum_hook("move_thread", $msgthd_id);
210
        break;
211
 
212
   case PHORUM_CLOSE_THREAD: // we have to close a thread
213
 
214
        $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['ThreadClosedOk'];
215
        $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
216
        phorum_db_close_thread($msgthd_id);
217
        phorum_hook("close_thread", $msgthd_id);
218
        break;
219
 
220
    case PHORUM_REOPEN_THREAD: // we have to reopen a thread
221
 
222
        $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['ThreadReopenedOk'];
223
        $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
224
        phorum_db_reopen_thread($msgthd_id);
225
        phorum_hook("reopen_thread", $msgthd_id);
226
        break;
227
 
228
    case PHORUM_APPROVE_MESSAGE: // approving a message
229
 
230
        $PHORUM['DATA']['MESSAGE']="1 ".$PHORUM["DATA"]['LANG']['MsgApprovedOk'];
231
 
232
        $old_message = phorum_db_get_message($msgthd_id);
233
        $newpost=array("status"=>PHORUM_STATUS_APPROVED);
234
 
235
        // setting the new status
236
        phorum_db_update_message($msgthd_id, $newpost);
237
 
238
        // updating the thread-info
239
        phorum_update_thread_info($old_message['thread']);
240
 
241
        // updating the forum-stats
242
        phorum_db_update_forum_stats(false, 1, $old_message["datestamp"]);
243
 
244
        if($old_message['status'] != PHORUM_STATUS_HIDDEN ) {
245
          phorum_email_notice($old_message);
246
        }
247
 
248
        if(isset($PHORUM['args']['old_forum']) && is_numeric($PHORUM['args']['old_forum']) && $PHORUM['folder_flag'] && $old_message['sort'] == PHORUM_SORT_ANNOUNCEMENT) {
249
            $PHORUM['forum_id']=(int)$PHORUM['args']['old_forum'];
250
        }
251
 
252
 
253
        if(isset($PHORUM['args']["prepost"])) {
254
            $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
255
        } else {
256
            $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
257
        }
258
        break;
259
 
260
    case PHORUM_APPROVE_MESSAGE_TREE: // approve a message and all answers to it
261
 
262
        $old_message = phorum_db_get_message($msgthd_id);
263
        $newpost=array("status"=>PHORUM_STATUS_APPROVED);
264
 
265
        $mids = phorum_db_get_messagetree($msgthd_id, $old_message["forum_id"]);
266
        // make an array from the string
267
        $mids_arr=explode(",",$mids);
268
 
269
        // count the entries for later use
270
        $num_approved=count($mids_arr);
271
        foreach($mids_arr as $key => $mid) {
272
            // setting the new status
273
            phorum_db_update_message($mid, $newpost);
274
 
275
        }
276
 
277
        // updating the thread-info
278
        phorum_update_thread_info($old_message['thread']);
279
 
280
        // updating the forum-stats
281
        phorum_db_update_forum_stats(false, "+$num_approved", $old_message["datestamp"]);
282
 
283
        if(isset($PHORUM['args']['old_forum']) && is_numeric($PHORUM['args']['old_forum']) && $PHORUM['folder_flag'] && $old_message['sort'] == PHORUM_SORT_ANNOUNCEMENT) {
284
            $PHORUM['forum_id']=(int)$PHORUM['args']['old_forum'];
285
        }
286
 
287
 
288
        $PHORUM['DATA']['MESSAGE']="$num_approved ".$PHORUM['DATA']['LANG']['MsgApprovedOk'];
289
        if(isset($PHORUM['args']["prepost"])) {
290
            $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
291
        } else {
292
            $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
293
        }
294
        break;
295
 
296
    case PHORUM_HIDE_POST: // hiding a message (and its replies)
297
 
298
        $old_message = phorum_db_get_message($msgthd_id);
299
        $newpost=array("status"=>PHORUM_STATUS_HIDDEN);
300
 
301
        $mids = phorum_db_get_messagetree($msgthd_id, $old_message["forum_id"]);
302
        // make an array from the string
303
        $mids_arr=explode(",",$mids);
304
 
305
        // count the entries for later use
306
        $num_hidden=count($mids_arr);
307
        foreach($mids_arr as $key => $mid) {
308
            // setting the new status
309
            phorum_db_update_message($mid, $newpost);
310
 
311
        }
312
 
313
        phorum_hook("hide", $msgthd_id);
314
 
315
        // updating the thread-info
316
        phorum_update_thread_info($old_message['thread']);
317
 
318
        // updating the forum-stats
319
        phorum_db_update_forum_stats(false, "-$num_hidden", $old_message["datestamp"]);
320
 
321
        $PHORUM['DATA']['MESSAGE']="$num_hidden ".$PHORUM['DATA']['LANG']['MsgHiddenOk'];
322
        if(isset($PHORUM['args']["prepost"])) {
323
            $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
324
        } else {
325
            $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
326
        }
327
        break;
328
 
329
   case PHORUM_MERGE_THREAD: // this is the first step of a thread merge
330
 
331
        $template="merge_form";
332
        $PHORUM['DATA']['URL']["ACTION"]     = phorum_get_url(PHORUM_MODERATION_ACTION_URL);
333
        $PHORUM['DATA']["FORM"]["forum_id"]  = $PHORUM["forum_id"];
334
        $PHORUM['DATA']["FORM"]["thread_id"] = $msgthd_id;
335
        $PHORUM['DATA']["FORM"]["mod_step"]  = PHORUM_DO_THREAD_MERGE;
336
 
337
        // the moderator selects the target thread to merge to
338
        $merge_t1 = phorum_moderator_data_get('merge_t1');
339
        if( !$merge_t1 || $merge_t1==$msgthd_id ) {
340
            phorum_moderator_data_put('merge_t1', $msgthd_id);
341
            $PHORUM['DATA']["FORM"]["merge_none"] =true;
342
        }
343
        // the moderator selects the source thread to merge from
344
        else {
345
            $PHORUM['DATA']["FORM"]["merge_t1"] =$merge_t1;
346
            $message = phorum_db_get_message($merge_t1, "message_id", true);
347
            $PHORUM['DATA']["FORM"]["merge_subject1"] =htmlentities($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
348
            $message = phorum_db_get_message($msgthd_id);
349
            $PHORUM['DATA']["FORM"]["thread_subject"] =htmlentities($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
350
        }
351
        break;
352
 
353
   case PHORUM_DO_THREAD_MERGE: // this is the last step of a thread merge
354
 
355
        if( isset($_POST['thread1']) && $_POST['thread1']) {
356
            // Commit Thread Merge
357
            settype($_POST['thread1'], "int");
358
            settype($_POST['thread'], "int"); // Thread 2
359
            $PHORUM['DATA']['MESSAGE'] = $PHORUM["DATA"]['LANG']['MsgMergeOk'];
360
            $PHORUM['DATA']["URL"]["REDIRECT"] = $PHORUM["DATA"]["URL"]["TOP"];
361
            $PHORUM["reverse_threading"] = 0;
362
 
363
            // Get the target thread.
364
            $target =phorum_db_get_message($_POST['thread1'], "message_id", true);
365
            if (!$target) die("Can't retrieve target thread " . $_POST['thread1']);
366
 
367
            // Get all messages from the thread that we have to merge.
368
            $merge_messages=phorum_db_get_messages($_POST['thread']);
369
            unset($merge_messages['users']);
370
 
371
            // Create new messages in the target thread for
372
            // all messages that have to be merged.
373
            $msgid_translation=array();
374
            foreach($merge_messages as $msg)
375
            {
376
                $oldid=$msg['message_id'];
377
 
378
                $msg['thread']   = $target['thread'];   // the thread we merge with
379
                $msg['forum_id'] = $target['forum_id']; // the forum_id of the new thread
380
                $msg['sort']     = $target['sort'];     // the sort type of the new thread
381
 
382
                if($msg['message_id'] == $msg['thread']) {
383
                    $msg['parent_id']=$target['thread'];
384
                } elseif(isset($msgid_translation[$msg['parent_id']])) {
385
                    $msg['parent_id']=$msgid_translation[$msg['parent_id']];
386
                } else {
387
                    $msg['parent_id']=$msg['thread'];
388
                }
389
 
390
                unset($msg['message_id']);
391
                unset($msg['modifystamp']);
392
 
393
                phorum_db_post_message($msg,true);
394
 
395
                // save the new message-id for later use
396
                $msgid_translation[$oldid]=$msg['message_id'];
397
            }
398
 
399
            // deleting messages which are now doubled
400
            phorum_db_delete_message($_POST['thread'], PHORUM_DELETE_TREE);
401
 
402
            // update message count / stats
403
            phorum_db_update_forum_stats(true);
404
            // change forum_id for the following calls to update the right forum
405
            $PHORUM["forum_id"] =$target['forum_id'];
406
            // update message count / stats
407
            phorum_update_thread_info($target['thread']);
408
            phorum_db_update_forum_stats(true);
409
        } else {
410
            // Cancel Thread Merge
411
            $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['MsgMergeCancel'];
412
            $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
413
        }
414
 
415
        // unset temporary moderator_data
416
        phorum_moderator_data_remove('merge_t1');
417
 
418
        break;
419
 
420
   case PHORUM_SPLIT_THREAD: // this is the first step of a thread split
421
 
422
           $PHORUM['DATA']['URL']["ACTION"]=phorum_get_url(PHORUM_MODERATION_ACTION_URL);
423
           $PHORUM['DATA']["FORM"]["forum_id"]=$PHORUM["forum_id"];
424
           $message =phorum_db_get_message($msgthd_id);
425
           $PHORUM['DATA']["FORM"]["thread_id"]=$message["thread"];
426
           $PHORUM['DATA']["FORM"]["message_id"]=$msgthd_id;
427
           $PHORUM['DATA']["FORM"]["message_subject"]=htmlentities($message["subject"],  ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
428
           $PHORUM['DATA']["FORM"]["mod_step"]=PHORUM_DO_THREAD_SPLIT;
429
           $template="split_form";
430
           break;
431
 
432
   case PHORUM_DO_THREAD_SPLIT: // this is the last step of a thread split
433
 
434
           $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['MsgSplitOk'];
435
           $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
436
           settype($_POST['forum_id'], "int");
437
           settype($_POST['message'], "int");
438
           settype($_POST['thread'], "int");
439
           phorum_db_split_thread($_POST['message'],$_POST['forum_id']);
440
           // update message count / stats
441
           phorum_update_thread_info($_POST['thread']);
442
           phorum_update_thread_info($_POST['message']);
443
           phorum_db_update_forum_stats(true);
444
           break;
445
 
446
    default:
447
 
448
        if(!isset($PHORUM['DATA']['MESSAGE'])) $PHORUM['DATA']['MESSAGE']="";
449
        $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
450
}
451
 
452
if(!isset($PHORUM['DATA']['BACKMSG'])) {
453
    $PHORUM['DATA']["BACKMSG"]=$PHORUM['DATA']["LANG"]["BackToList"];
454
}
455
 
456
include phorum_get_template("header");
457
phorum_hook("after_header");
458
include phorum_get_template($template);
459
phorum_hook("before_footer");
460
include phorum_get_template("footer");
461
 
462
?>