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 ;-)

Avatar

Move existing threads into an other thread

by Auge ⌂, Thursday, January 07, 2010, 05:41 (5238 days ago) @ StevieS

Hello

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.

Please explain again, why the messages must be deleted before saving again only with different (t)id's. IMHO only these informations have to be rewrited.

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

Nobody did it because nobody did it. ;-)

My questions to you: Why you use this annoying red bold text all the way?

Tschö, Auge

Avatar

Move existing threads into an other thread

by Alfie ⌂, Vienna, Austria, Thursday, January 07, 2010, 13:38 (5238 days ago) @ StevieS
edited by Alfie, Thursday, January 07, 2010, 13:47

Hi Stevie!

My question is: Why didn't wrote somebody else this before?

You re-invented the wheel. This function is available since the earliest beta-versions. Admins/Mods may move single posts/entire threads. Click on '[image] move' in the bottom right hand corner of the post. You have two options:

  • Make a new thread
  • Link to another post (you have to know the id of the post you want to link to beforehand)

--
Cheers,
Alfie (Helmut Schütz)
BEBA-Forum (v1.8β)

Move existing threads into an other thread

by StevieS, Friday, January 08, 2010, 18:06 (5237 days ago) @ Alfie

Oh, I'm sorry i post into the wrong category. My code is for version 1.x not for version 2.x. Could an admin please move my thread? ;-)

Avatar

Move existing threads into an other thread

by Auge ⌂, Sunday, January 10, 2010, 14:00 (5235 days ago) @ StevieS

Hello

Oh, I'm sorry i post into the wrong category. My code is for version 1.x not for version 2.x. Could an admin please move my thread? ;-)

Here you will not find a category for mlf1. There are two other forums (english/international and german) for mlf1. But there (especially in the english forum) is not much activity.

As the new maintainer for mlf1 I am interested in your code. I will look through the code and make a test implementation.

The test forum is located at my domain. It is in german language but you can post in english too (after registration (because of avoiding spam)).

Tschö, Auge

Move existing threads into an other thread

by StevieS, Thursday, January 14, 2010, 10:14 (5231 days ago) @ Auge

Na dann können wir ja auch Deutsch reden :-D

RSS Feed of thread