PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/legacy/includes/forums/split.php

http://novaboard.googlecode.com/
PHP | 101 lines | 56 code | 32 blank | 13 comment | 8 complexity | 0e2ecc63aed006d0560ae59ca3b738cc MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------------
  4. | NovaBoard
  5. | ========================================
  6. | By The NovaBoard team
  7. | Released under the Artistic License 2.0
  8. | http://www.novaboard.net
  9. | ======================================== |+--------------------------------------------------------------------------
  10. | split.php - split topic in two
  11. */
  12. if (!defined('NOVA_RUN')){
  13. echo "<h1>ACCESS DENIED</h1>You cannot access this file directly.";
  14. exit();
  15. }
  16. if ($can_split_topics=='0'){
  17. nova_redirect("index.php?page=error&error=10","error/10");
  18. }
  19. else{
  20. if ($_POST['title']==''){
  21. $token_id = md5(microtime());
  22. $token = md5(uniqid(rand(),true));
  23. $post=$_GET['post'];
  24. $post=escape_string($post);
  25. $token_name = "token_split_$post$token_id";
  26. $_SESSION[$token_name] = $token;
  27. template_hook("forums/split.template.php", "1");
  28. }
  29. else{
  30. $post=$_POST['post'];
  31. $post=escape_string($post);
  32. $token_id = $_POST['token_id'];
  33. $token_id = escape_string($token_id);
  34. $token_name = "token_split_$post$token_id";
  35. if (isset($_POST[$token_name]) && isset($_SESSION[$token_name]) && $_SESSION[$token_name] == $_POST[$token_name]){
  36. // Move all posts to new topic...
  37. // Get last topic ID...
  38. $query2 = "select TOPIC_ID from {$db_prefix}posts WHERE TITLE!='' ORDER BY TOPIC_ID desc LIMIT 1" ;
  39. $result2 = mysql_query($query2) or die("split.php - Error in query: $query2") ;
  40. while ($results2 = mysql_fetch_array($result2)){
  41. $topic_id = $results2['TOPIC_ID'];
  42. $topic_id=$topic_id+1;
  43. }
  44. $query21 = "select TOPIC_ID from {$db_prefix}posts WHERE ID='$post'" ;
  45. $result21 = mysql_query($query21) or die("split.php - Error in query: $query21") ;
  46. $old_topic_id = mysql_result($result21, 0);
  47. $time=time();
  48. $title=$_POST['title'];
  49. $title=escape_string($title);
  50. $post=$_POST['post'];
  51. $post=escape_string($post);
  52. $description=$_POST['description'];
  53. $description=escape_string($description);
  54. mysql_query("UPDATE {$db_prefix}posts SET title='$title', description='$description', topic_id='$topic_id', last_post_time='$time' WHERE id = '$post'");
  55. mysql_query("UPDATE {$db_prefix}posts SET topic_id='$topic_id' WHERE id > '$post' AND topic_id='$old_topic_id'");
  56. mysql_query("UPDATE {$db_prefix}settings SET stats_topics=stats_topics+1, stats_posts = stats_posts-1");
  57. $redirect=$topic_id;
  58. // perform auto-cache
  59. include "scripts/php/auto_cache.php";
  60. template_hook("forums/split.template.php", "form");
  61. $topic_title = topic_title($redirect);
  62. nova_redirect("index.php?topic=$redirect","topic/$topic_title-$redirect");
  63. }
  64. else{
  65. nova_redirect("index.php?page=error&error=28","error/28");
  66. }
  67. }
  68. }
  69. ?>