Avatar

Move the first Posting to an answer (Bugs)

by Micha ⌂, Sunday, January 17, 2010, 18:24 (5185 days ago)
edited by Micha, Monday, January 18, 2010, 07:17

Hi Alex,

today, one of my mods moves the first posting to an answer of the same thread and produce an error. I could fix it in the database. Maybe, it is better to check the pid while moving the first posting.

Proposal for solution

posting.inc.php, between line 140/141 (original):

mysql_free_result($move_result);
      @mysql_query("UPDATE ".$db_settings['forum_table']." SET pid=".intval($_POST['move_to']).", tid=".intval($data['tid']).", time=time, last_reply=last_reply, edited=edited WHERE id=".intval($_POST['move_posting']), $connid);

change to

 
if ( intval($o_data['pid']) == 0 && intval($o_data['tid']) == intval($data['tid']) ) {
  $errors[] = 'invalid_posting_to_move';
}
else {
 ...
 

in line 136 the pid must be selected, too.

Regards Micha


full changes:

 
  if(isset($_POST['move_mode']) && $_POST['move_mode']==1 && isset($_POST['move_to']))
   {
    // move posting:
    list($count) = @mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM ".$db_settings['forum_table']." WHERE id=".intval($_POST['move_to']), $connid));
    if($count!=1 || intval($_POST['move_posting'])==intval($_POST['move_to'])) $errors[] = 'invalid_posting_to_move';
    if(empty($errors))
     {
//PID mit abfragen
      $child_ids = get_child_ids($_POST['move_posting']);
      $move_result = @mysql_query("SELECT tid, pid 
                                   FROM ".$db_settings['forum_table']." 
                                   WHERE id = ".intval($_POST['move_to'])." LIMIT 1", $connid);
      $data = mysql_fetch_array($move_result);
      mysql_free_result($move_result);
// Prüfe, ob 1. Eintrag an eine Antwort des selben Thread verschoben werden soll.   
   if ( intval($o_data['pid']) == 0 && intval($o_data['tid']) == intval($data['tid']) ) {
  $errors[] = 'invalid_posting_to_move';
   }
// Wenn nicht, schieben...
   else
   {
      @mysql_query("UPDATE ".$db_settings['forum_table']." SET pid=".intval($_POST['move_to']).", tid=".intval($data['tid']).", time=time, last_reply=last_reply, edited=edited WHERE id=".intval($_POST['move_posting']), $connid);
      if(is_array($child_ids))
       {
        foreach($child_ids as $id)
         {
          @mysql_query("UPDATE ".$db_settings['forum_table']." SET tid=".intval($data['tid']).", time=time, last_reply=last_reply, edited=edited WHERE id=".intval($id), $connid);
         }
       }
      // set last reply of original thread:
      $last_reply_result = @mysql_query("SELECT time FROM ".$db_settings['forum_table']." WHERE tid = ".intval($o_data['tid'])." ORDER BY time DESC LIMIT 1", $connid);
      $field = mysql_fetch_array($last_reply_result);
      mysql_free_result($last_reply_result);
      @mysql_query("UPDATE ".$db_settings['forum_table']." SET time=time, edited=edited, last_reply='".$field['time']."' WHERE tid=".intval($o_data['tid']), $connid);
      // set last reply of new thread:
      $last_reply_result = @mysql_query("SELECT time FROM ".$db_settings['forum_table']." WHERE tid = ".intval($data['tid'])." ORDER BY time DESC LIMIT 1", $connid);
      $field = mysql_fetch_array($last_reply_result);
      mysql_free_result($last_reply_result);
      @mysql_query("UPDATE ".$db_settings['forum_table']." SET time=time, edited=edited, last_reply='".$field['time']."' WHERE tid=".intval($data['tid']), $connid);
      // set category of new thread:
      $last_reply_result = @mysql_query("SELECT category FROM ".$db_settings['forum_table']." WHERE id = ".intval($data['tid']), $connid);
      $field = mysql_fetch_array($last_reply_result);
      mysql_free_result($last_reply_result);
      @mysql_query("UPDATE ".$db_settings['forum_table']." SET category=".$field['category'].", time=time, edited=edited, last_reply=last_reply WHERE tid=".intval($data['tid']), $connid);
      if(isset($back) && $back=='thread') header('Location: index.php?mode=thread&id='.intval($_POST['move_posting']));
      else header('Location: index.php?id='.intval($_POST['move_posting']));
      exit;
   }
     } // Neuer ELSE-Zweig
    // statt ELSE nun If, da Fehlermeldungen auch zwischendurch erzeugt werden (können)
    if(!empty($errors))
     {
      $smarty->assign('errors',$errors);
      $action = 'move_posting';
     } 

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences


Complete thread:

 RSS Feed of thread