decir/functions.php
changeset 3 88b85b9b9272
parent 2 253118325c65
child 6 3f66ec435f08
equal deleted inserted replaced
2:253118325c65 3:88b85b9b9272
   208   
   208   
   209   if ( !is_int($topic_id) )
   209   if ( !is_int($topic_id) )
   210     return false;
   210     return false;
   211   
   211   
   212   // Obtain a list of posts in the topic
   212   // Obtain a list of posts in the topic
   213   $q = $db->sql_query('SELECT post_id FROM '.table_prefix.'decir_posts WHERE topic_id = ' . $topic_id . ';');
   213   $q = $db->sql_query('SELECT post_id, post_deleted FROM '.table_prefix.'decir_posts WHERE topic_id = ' . $topic_id . ';');
   214   if ( !$q )
   214   if ( !$q )
   215     $db->_die('Decir functions.php in decir_delete_topic()');
   215     $db->_die('Decir functions.php in decir_delete_topic()');
   216   if ( $db->numrows() < 1 )
   216   if ( $db->numrows() < 1 )
   217     return false;
   217     return false;
   218   $posts = array();
   218   $posts = array();
       
   219   $del_count = 0;
   219   while ( $row = $db->fetchrow() )
   220   while ( $row = $db->fetchrow() )
   220   {
   221   {
       
   222     if ( $row['post_deleted'] == 1 )
       
   223       // Don't decrement the post count for deleted posts
       
   224       $del_count++;
   221     $posts[] = $row['post_id'];
   225     $posts[] = $row['post_id'];
   222   }
   226   }
   223   
   227   
   224   // Obtain forum ID
   228   // Obtain forum ID
   225   $q = $db->sql_query('SELECT forum_id FROM '.table_prefix."decir_topics WHERE topic_id = $topic_id;");
   229   $q = $db->sql_query('SELECT forum_id FROM '.table_prefix."decir_topics WHERE topic_id = $topic_id;");
   250     $topic_deletor = $session->user_id;
   254     $topic_deletor = $session->user_id;
   251     $q = $db->sql_query('UPDATE ' . table_prefix . "decir_topics SET topic_deleted = 1, topic_deletor = $topic_deletor, topic_delete_reason = '$reason' WHERE topic_id = $topic_id;");
   255     $q = $db->sql_query('UPDATE ' . table_prefix . "decir_topics SET topic_deleted = 1, topic_deletor = $topic_deletor, topic_delete_reason = '$reason' WHERE topic_id = $topic_id;");
   252   }
   256   }
   253   
   257   
   254   // Update forum stats
   258   // Update forum stats
   255   $post_count = count($posts);
   259   $post_count = count($posts) - $del_count;
   256   $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_topics = num_topics - 1, num_posts = num_posts - $post_count WHERE forum_id = $forum_id;");
   260   $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_topics = num_topics - 1, num_posts = num_posts - $post_count WHERE forum_id = $forum_id;");
   257   if ( !$q )
   261   if ( !$q )
   258     $db->_die('Decir functions.php in decir_delete_topic()');
   262     $db->_die('Decir functions.php in decir_delete_topic()');
   259   decir_update_forum_stats($forum_id);
   263   decir_update_forum_stats($forum_id);
   260   
   264   
   356   
   360   
   357   if ( !is_int($topic_id) )
   361   if ( !is_int($topic_id) )
   358     return false;
   362     return false;
   359   
   363   
   360   // Obtain a list of posts in the topic
   364   // Obtain a list of posts in the topic
   361   $q = $db->sql_query('SELECT post_id FROM '.table_prefix.'decir_posts WHERE topic_id = ' . $topic_id . ';');
   365   $q = $db->sql_query('SELECT post_id, post_deleted FROM '.table_prefix.'decir_posts WHERE topic_id = ' . $topic_id . ';');
   362   if ( !$q )
   366   if ( !$q )
   363     $db->_die('Decir functions.php in decir_delete_topic()');
   367     $db->_die('Decir functions.php in decir_delete_topic()');
   364   if ( $db->numrows() < 1 )
   368   if ( $db->numrows() < 1 )
   365     return false;
   369     return false;
   366   $posts = array();
   370   $posts = array();
       
   371   $del_count = 0;
   367   while ( $row = $db->fetchrow() )
   372   while ( $row = $db->fetchrow() )
   368   {
   373   {
       
   374     if ( $row['post_deleted'] == 1 )
       
   375       // Don't decrement the post count for deleted posts
       
   376       $del_count++;
   369     $posts[] = $row['post_id'];
   377     $posts[] = $row['post_id'];
   370   }
   378   }
   371   
   379   
   372   // Obtain forum ID
   380   // Obtain forum ID
   373   $q = $db->sql_query('SELECT forum_id FROM '.table_prefix."decir_topics WHERE topic_id = $topic_id;");
   381   $q = $db->sql_query('SELECT forum_id FROM '.table_prefix."decir_topics WHERE topic_id = $topic_id;");
   377   $db->free_result();
   385   $db->free_result();
   378   
   386   
   379   $q = $db->sql_query('UPDATE ' . table_prefix . "decir_topics SET topic_deleted = 0, topic_deletor = NULL, topic_delete_reason = NULL WHERE topic_id = $topic_id;");
   387   $q = $db->sql_query('UPDATE ' . table_prefix . "decir_topics SET topic_deleted = 0, topic_deletor = NULL, topic_delete_reason = NULL WHERE topic_id = $topic_id;");
   380   
   388   
   381   // Update forum stats
   389   // Update forum stats
   382   $post_count = count($posts);
   390   $post_count = count($posts) - $del_count;
   383   $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_topics = num_topics + 1, num_posts = num_posts + $post_count WHERE forum_id = $forum_id;");
   391   $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_topics = num_topics + 1, num_posts = num_posts + $post_count WHERE forum_id = $forum_id;");
   384   if ( !$q )
   392   if ( !$q )
   385     $db->_die('Decir functions.php in decir_restore_topic()');
   393     $db->_die('Decir functions.php in decir_restore_topic()');
   386   decir_update_forum_stats($forum_id);
   394   decir_update_forum_stats($forum_id);
   387   
   395