Move existing threads into an other thread (General)

by StevieS, Wednesday, January 06, 2010, 22:09 (5239 days ago)
edited by StevieS, Wednesday, January 06, 2010, 22:17

Hello,

i wrote a little hack to move existing threads into an other thread. This would probably neccessary, if you users post a new thread when the same topic already exists.

I have made this as follows:

I made a function (like the lock function) in the forum_entry.php, which is only accessible for administrators and moderators.

forum_entry.php ~ line 210

 
if (isset($_SESSION[$settings['session_prefix'].'user_id']) && $_SESSION[$settings['session_prefix'].'user_type'] == "admin" && $entrydata['pid'] == 0 || isset($_SESSION[$settings['session_prefix'].'user_id']) && $_SESSION[$settings['session_prefix'].'user_type'] == "mod" && $entrydata['pid'] == 0) 
 
{ ?> 
<span class="small"><a href="posting.php?action=move&amp;id=<?php echo $entrydata["id"]; ?>&amp;page=<?php echo $page; ?>&amp;order=<?php echo $order; ?>&amp;category=<?php echo urlencode($category); ?>" title="verschieben"><img src="img/move.gif" alt="" width="12" height="12" /><font color="#000">move</a>
</span>
<?php 
} ?>
 


The function call the posting.php which list up the thread with an dropdown menue to select the thread where to move the existing one. But first I wrote an separate form in the posting.php (called the form "move")

posting.php ~ line 227

 
case "move":
      if ($move_authorization == 1)
 
       { 
  $show = "move form";
  }
      else $show = "no authorization";
     break;
 

Here is now the form to select the thread where the old thread should get moved to.

posting.php ~ line 1150

 
 // start of the form
   case "move form":?>
    <h2>Move a thread</h2>
    <p>Following entries have the thread which should get moved:</p>
 
    <table width="100%" border="0">
    <tr>
    <td><strong>user:</strong></td>
    <td><strong>entry name:</strong></td>
    <td><strong>date:</strong></td>
    <td><strong>entry type:</strong></td>
    </tr>
 
    <?php
    $movethreadnumber=$_REQUEST['id'];
 
 $getmovedentries=mysql_query("SELECT * from forum_entries WHERE tid = $movethreadnumber order by time asc");
 
  while ($resultentries=mysql_fetch_assoc($getmovedentries))
  {
 // start  
   ?>
 
    <tr>
    <td><?php echo $resultentries['name']; ?></td>
    <td><?php echo $resultentries['subject']; ?></td>
    <td><?php echo $resultentries['time']; ?></td>
    <td><?php if($resultentries['pid']==0)
   { echo 'start entry';}
   else
   { echo 'reply';}?></td>
    </tr>
     <?php
  }
 
   ?>
   </table>
 
    <p>&nbsp;</p>   
    <p>Please select now the thread where the existing thread should get moved to:</p>
 
    <form action="posting.php" method="post"> 
 
    <?php 
 
 // Query for the existing thread
 
    $getexistingthreads=mysql_query("SELECT * from forum_entries WHERE pid = 0 and tid <> $movethreadnumber ORDER BY time DESC");
 
 echo "<select class='select01' name='newthread'>";
 
 while ($resultthreads=mysql_fetch_assoc($getexistingthreads))
  {
   echo '<option value="'.$resultthreads['tid'].'">'.$resultthreads['subject'].' - '.$resultthreads['name'].' - '.$resultthreads['time'].'</option>';
  }
 
 echo '</select>';
 
 ?>
    <br />
    <p>Notice: The selection menue is in the form : thread title -  thread starter - date and time</p>
    <input type="hidden" name="action" value="move ok" />
    <input type="hidden" name="id" value="<?php echo $movethreadnumber; ?>" />
    <?php if (isset($view)) { ?><input type="hidden" name="view" value="<?php echo $view; ?>" /><?php } ?>
    <?php if (isset($page)) { ?><input type="hidden" name="page" value="<?php echo $page; ?>" /><?php } ?>
    <?php if (isset($order)) { ?><input type="hidden" name="order" value="<?php echo $order; ?>" /><?php } ?>
    <?php if (isset($descasc)) { ?><input type="hidden" name="descasc" value="<?php echo $descasc; ?>" /><?php } ?>
    <?php if (isset($category)) { ?><input type="hidden" name="category" value="<?php echo $category; ?>" /><?php } ?>
    <input type="submit" name="move" value="Thread jetzt verschieben" />
    </form><p>&nbsp;</p><?php
 
   break;
 
    // End of the form
  }
 


Then the posting.php make an query for the data of the existing threads and delete them and write them into the new thread. Delete is neccessary first because the id is a primary value of the table. Here the complete code now:

posting.php ~ line 292

 
 case "move ok":
 
       if ($move_authorization == 1)
        {
   $movingthread=$_REQUEST['id'];
   $movingthread_newthread=$_REQUEST['newthread'];
 
   // intialize the variables for the fiels in the new thread
   $value_parent_category=0;
   $value_parent_email_notify=0; 
   $value_parent_marked=0;  
   $value_parent_locked=0;  
   $value_parent_fixed=0; 
 
 
   // get the fields of the old existing thread
   $getparententriesnow=mysql_query("SELECT * from forum_entries WHERE id = $movingthread_newthread");
 
   while ($resultparententries=mysql_fetch_assoc($getparententriesnow))
    {
      $value_parent_category=$resultparententries['category']; 
      $value_parent_marked=$resultparententries['marked'];  
      $value_parent_locked=$resultparententries['locked'];  
      $value_parent_fixed=$resultparententries['fixed']; 
    }
 
   // get the fields of the old existing thread
   $getmoveentriesnow=mysql_query("SELECT * from forum_entries WHERE tid = $movingthread order by time asc");
 
    while ($resultoldentries=mysql_fetch_assoc($getmoveentriesnow))
    {
 
      $value_id=$resultoldentries['id']; 
      $value_pid=$resultoldentries['pid'];
 
      // if the entry have no parent, make them to an child of the new already exisitign thread. In this case we got the old startentry.
      if ($value_pid==0)
      {$value_pid=$movingthread_newthread;}
 
      // make the entries to an entry of the new thread
      $value_tid=$movingthread_newthread;
 
      // the other fields
 
      $value_uniqid=$resultoldentries['uniqid'];  
      $value_time=$resultoldentries['time']; 
      $value_last_answer=$resultoldentries['last_answer']; 
      $value_edited=$resultoldentries['edited']; 
      $value_edited_by=$resultoldentries['edited_by'];  
      $value_user_id=$resultoldentries['user_id'];  
      $value_name=$resultoldentries['name'];  
      $value_subject=$resultoldentries['subject']; 
      $value_email=$resultoldentries['email'];  
      $value_hp=$resultoldentries['hp'];  
      $value_place=$resultoldentries['place'];  
      $value_ip=$resultoldentries['ip'];  
      $value_text=$resultoldentries['text'];  
      $value_show_signature=$resultoldentries['show_signature'];
      $value_email_notify=$resultoldentries['email_notify'];
      $value_views=$resultoldentries['views']; 
 
 
      // delete the old entries
      $delete=mysql_query("DELETE FROM forum_entries where id = $value_id");
 
      // write the new entries
      $write=mysql_query("INSERT INTO forum_entries VALUES ('$value_id', '$value_pid', '$value_tid', '$value_uniqid', '$value_time', '$value_last_answer', '$value_edited', '$value_edited_by', '$value_user_id', '$value_name', '$value_subject', '$value_parent_category', '$value_email', '$value_hp', '$value_place', '$value_ip', '$value_text', '$value_show_signature', '$value_email_notify', '$value_parent_marked', '$value_parent_locked', '$value_parent_fixed', '$value_views')");
 
 
    }
 
    // here you get redirectet to the old startthread
 
    header("Location: http://www.example.org/forum_entry.php?id=$movingthread");
 
    }
  else $show = "no authorization";
  break;
 


My question is: Why didn't wrote somebody else this before? Because it works perfect ;-)


Complete thread:

 RSS Feed of thread