decir/delete.php
author Dan
Wed, 17 Oct 2007 20:23:51 -0400
changeset 1 6f8b7c6fac02
child 3 88b85b9b9272
permissions -rw-r--r--
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     1
<?php
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     2
/*
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     3
 * Decir
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     4
 * Version 0.1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     5
 * Copyright (C) 2007 Dan Fuhry
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     6
 * edit.php - edit posts that already exist
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     7
 *
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    10
 *
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    13
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    14
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    15
require('common.php');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    16
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    17
$pid = $paths->getParam(1);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    18
if ( strval(intval($pid)) !== $pid )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    19
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    20
  die_friendly('Error', '<p>Invalid post ID</p>');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    21
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    22
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    23
$pid = intval($pid);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    24
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    25
// Obtain post info
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    26
$q = $db->sql_query('SELECT p.post_id, p.topic_id, p.post_subject, t.post_text, t.bbcode_uid, p.poster_id, p.post_deleted FROM '.table_prefix."decir_posts AS p
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    27
                       LEFT JOIN ".table_prefix."decir_posts_text AS t
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    28
                         ON (t.post_id = p.post_id)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    29
                       WHERE p.post_id = $pid;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    30
if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    31
  $db->_die('Decir delete.php');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    32
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    33
if ( $db->numrows() < 1 )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    34
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    35
  die_friendly('Error', '<p>The post you requested does not exist.</p>');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    36
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    37
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    38
$row = $db->fetchrow();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    39
$db->free_result();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    40
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    41
$tid = intval($row['topic_id']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    42
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    43
$acl_type = ( $row['poster_id'] == $session->user_id && $session->user_logged_in ) ? 'decir_edit_own' : 'decir_edit_other';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    44
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    45
$post_perms = $session->fetch_page_acl(strval($pid), 'DecirPost');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    46
if ( !$post_perms->get_permissions($acl_type) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    47
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    48
  die_friendly('Error', '<p>You do not have permission to edit this post.</p>');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    49
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    50
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    51
$edit_reason = '';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    52
if ( isset($_GET['act']) && $_GET['act'] == 'submit' )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    53
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    54
  if ( isset($_POST['do']['delete']) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    55
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    56
    // Nuke it
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    57
    $result = decir_delete_post($pid, $_POST['edit_reason'], ( $_POST['delete_method'] == 'hard' ));
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    58
    if ( $result )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    59
    {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    60
      $url = makeUrlNS('Special', 'Forum/Topic/' . $tid, false, true) . '#post' . $pid;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    61
      redirect($url, 'Post deleted', 'The selected post has been deleted.', 4);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    62
    }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    63
    $edit_reason = htmlspecialchars($_POST['edit_reason']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    64
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    65
  else if ( isset($_POST['do']['restore']) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    66
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    67
    $result = decir_restore_post($pid);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    68
    if ( $result )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    69
    {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    70
      $url = makeUrlNS('Special', 'Forum/Topic/' . $tid, false, true) . '#post' . $pid;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    71
      redirect($url, 'Post restored', 'The selected post has been restored.', 4);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    72
    }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    73
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    74
  else if ( isset($_POST['do']['noop']) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    75
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    76
    $url = makeUrlNS('Special', 'Forum/Post/' . $pid, false, true) . '#post' . $pid;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    77
    redirect($url, '', '', 0);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    78
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    79
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    80
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    81
$template->header(true);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    82
$form_submit_url = makeUrlNS('Special', 'Forum/Delete/' . $pid, 'act=submit', true);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    83
?>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    84
<form action="<?php echo $form_submit_url; ?>" method="post" enctype="multipart/form-data">
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    85
  <?php if ( $row['post_deleted'] == 1 ):
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    86
  if ( isset($_GET['act']) && $_GET['act'] == 'restore' ): ?>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    87
  <p>Are you sure you want to restore this post so that it is visible to the public?</p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    88
  <p><input type="submit" name="do[restore]" value="Restore post" tabindex="3" /> <input tabindex="4" type="submit" name="do[noop]" value="Cancel" /></p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    89
  <?php else: ?>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    90
  <p>Are you sure you want to permanently delete this post?</p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    91
  <p><input type="hidden" name="delete_method" value="hard" /><input type="submit" name="do[delete]" value="Delete post" tabindex="3" /> <input tabindex="4" type="submit" name="do[noop]" value="Cancel" /></p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    92
  <?php endif;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    93
        else: ?>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    94
  <p>To delete this post, please enter a reason for deletion and click the appropriate button below.</p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    95
  <p>Please note that if this the first post in the thread, the entire thread will be removed.</p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    96
  <p><label><input type="radio" name="delete_method" value="soft" onclick="document.getElementById('decir_reason_box').style.display = 'inline';" checked="checked" tabindex="1" /> Soft delete</label> - <small>Post is replaced with the message you enter here. The original post is not removed from the database and is still visible to administrators.</small></p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    97
  <p><input type="text" name="edit_reason" value="<?php echo $edit_reason; ?>" tabindex="2" style="width: 97%;" id="decir_reason_box" /></p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    98
  <p><label><input type="radio" name="delete_method" value="hard" onclick="document.getElementById('decir_reason_box').style.display = 'none';" /> Physically remove post</label> - <small>Irreversibly removes the post from the database.</small></p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    99
  <p><input type="submit" name="do[delete]" value="Delete post" tabindex="3" /> <input tabindex="4" type="submit" name="do[noop]" value="Cancel" /></p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   100
  <?php endif; ?>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   101
</form>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   102
<?php
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   103
$template->footer(true);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   104
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   105
?>