PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/_Temp/dossier sans titre/pun_move_posts/move_posts.php

https://github.com/PanPan50/lesitedecuisine
PHP | 319 lines | 247 code | 55 blank | 17 comment | 27 complexity | c9060369e07aa455d651a694e6c5ff55 MD5 | raw file
  1. <?php
  2. /**
  3. * Pun Move Posts extension file
  4. *
  5. * @copyright Copyright (C) 2009 PunBB, partially based on code copyright (C) 2009 FluxBB.org
  6. * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  7. * @package pun_move_posts
  8. */
  9. $tid = intval($_GET['tid']);
  10. $fid = intval($_GET['fid']);
  11. if ($tid < 1)
  12. message($lang_common['Bad request']);
  13. // Fetch some info about the topic
  14. $query = array(
  15. 'SELECT' => 't.subject, t.poster, t.first_post_id, t.posted, t.num_replies',
  16. 'FROM' => 'topics AS t',
  17. 'WHERE' => 't.id='.$tid.' AND t.moved_to IS NULL'
  18. );
  19. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  20. if (!$forum_db->num_rows($result))
  21. message($lang_common['Bad request']);
  22. $cur_topic = $forum_db->fetch_assoc($result);
  23. $posts = isset($_POST['posts']) && !empty($_POST['posts']) ? $_POST['posts'] : array();
  24. $posts = array_map('intval', (is_array($posts) ? $posts : explode(',', $posts)));
  25. if (isset($_POST['move_posts']))
  26. {
  27. $posts = isset($_POST['posts']) && is_array($_POST['posts']) ? $_POST['posts'] : array();
  28. $posts = array_map('intval', $posts);
  29. if (empty($posts))
  30. message($lang_misc['No posts selected']);
  31. // Get topics we can move the posts into
  32. $query = array(
  33. 'SELECT' => 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name',
  34. 'FROM' => 'categories AS c',
  35. 'JOINS' => array(
  36. array(
  37. 'INNER JOIN' => 'forums AS f',
  38. 'ON' => 'c.id=f.cat_id'
  39. ),
  40. array(
  41. 'LEFT JOIN' => 'forum_perms AS fp',
  42. 'ON' => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
  43. )
  44. ),
  45. 'WHERE' => '(fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL AND f.num_topics!=0',
  46. 'ORDER BY' => 'c.disp_position, c.id, f.disp_position'
  47. );
  48. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  49. $forum_list = array();
  50. while ($cur_sel_forum = $forum_db->fetch_assoc($result))
  51. $forum_list[] = $cur_sel_forum;
  52. $forum_page['form_action'] = forum_link($forum_url['moderate_topic'], array($fid, $tid));
  53. $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
  54. $forum_page['hidden_fields'] = array(
  55. 'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />',
  56. 'posts' => '<input type="hidden" name="posts" value="'.implode(',', $posts).'" />',
  57. 'fid' => '<input type="hidden" name="fid" value="'.$fid.'" />',
  58. 'tid' => '<input type="hidden" name="fid" value="'.$tid.'" />',
  59. );
  60. $forum_page['crumbs'] = array(
  61. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  62. array($cur_forum['forum_name'], forum_link($forum_url['forum'], array($fid, sef_friendly($cur_forum['forum_name'])))),
  63. array($lang_misc['Moderate forum'], forum_link($forum_url['moderate_forum'], $fid)),
  64. $lang_pun_move_posts['Move posts']
  65. );
  66. //Setup main heading
  67. define('FORUM_PAGE', 'dialogue');
  68. require FORUM_ROOT.'header.php';
  69. // START SUBST - <!-- forum_main -->
  70. ob_start();
  71. ?>
  72. <div class="main-head">
  73. <h2 class="hn"><span><?php echo end($forum_page['crumbs']) ?></span></h2>
  74. </div>
  75. <div class="main-content main-frm">
  76. <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>">
  77. <div class="hidden">
  78. <?php echo implode("\n\t\t\t\t", $forum_page['hidden_fields'])."\n" ?>
  79. </div>
  80. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  81. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  82. <div class="sf-box select">
  83. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_pun_move_posts['Destination forum']?></span></label><br />
  84. <span class="fld-input"><select id="<?php echo $forum_page['fld_count'] ?>" name="move_to_forum">
  85. <?php
  86. $forum_page['cur_category'] = 0;
  87. foreach ($forum_list as $cur_forum)
  88. {
  89. if ($cur_forum['cid'] != $forum_page['cur_category']) // A new category since last iteration?
  90. {
  91. if ($forum_page['cur_category'])
  92. echo "\t\t\t\t".'</optgroup>'."\n";
  93. echo "\t\t\t\t".'<optgroup label="'.forum_htmlencode($cur_forum['cat_name']).'">'."\n";
  94. $forum_page['cur_category'] = $cur_forum['cid'];
  95. }
  96. echo "\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.forum_htmlencode($cur_forum['forum_name']).'</option>'."\n";
  97. }
  98. ?>
  99. </optgroup>
  100. </select></span>
  101. </div>
  102. </div>
  103. </fieldset>
  104. <div class="frm-buttons">
  105. <span class="submit"><input type="submit" name="move_posts_s" value="<?php echo $lang_common['Next'] ?>" /></span>
  106. <span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" /></span>
  107. </div>
  108. </form>
  109. </div>
  110. <?php
  111. $forum_id = $fid;
  112. $tpl_temp = forum_trim(ob_get_contents());
  113. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  114. ob_end_clean();
  115. // END SUBST - <!-- forum_main -->
  116. require FORUM_ROOT.'footer.php';
  117. }
  118. if (isset($_POST['move_posts_s']))
  119. {
  120. $posts = isset($_POST['posts']) && !empty($_POST['posts']) ? $_POST['posts'] : array();
  121. $posts = array_map('intval', (is_array($posts) ? $posts : explode(',', $posts)));
  122. $move_to_forum=isset($_POST['move_to_forum']) && !empty($_POST['move_to_forum']) ? $_POST['move_to_forum'] : array();
  123. if (empty($posts))
  124. message($lang_misc['No posts selected']);
  125. // Get topics we can move the posts into
  126. $query = array(
  127. 'SELECT' => 'f.id AS fid, f.forum_name as f_name, t.id AS tid, t.subject AS topic_subject',
  128. 'FROM' => 'forums AS f',
  129. 'JOINS' => array(
  130. array(
  131. 'INNER JOIN' => 'topics AS t',
  132. 'ON' => 'f.id=t.forum_id'
  133. ),
  134. ),
  135. 'WHERE' => 'f.id='.$move_to_forum.' AND t.id!='.$tid,
  136. 'ORDER BY' => 't.last_post DESC'
  137. );
  138. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  139. $forum_list = array();
  140. while ($cur_sel_forum = $forum_db->fetch_assoc($result))
  141. $forum_list[] = $cur_sel_forum;
  142. $forum_page['form_action'] = forum_link($forum_url['moderate_topic'], array($fid, $tid));
  143. $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
  144. $forum_page['hidden_fields'] = array(
  145. 'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />',
  146. 'posts' => '<input type="hidden" name="posts" value="'.implode(',', $posts).'" />',
  147. 'tid' => '<input type="hidden" name="tid" value="'.$tid.'" />',
  148. 'fid' => '<input type="hidden" name="tid" value="'.$fid.'" />',
  149. 'move_to_forum' => '<input type="hidden" name="tid" value="'.$move_to_forum.'" />'
  150. );
  151. $forum_page['crumbs'] = array(
  152. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  153. array($cur_forum['forum_name'], forum_link($forum_url['forum'], array($fid, sef_friendly($cur_forum['forum_name'])))),
  154. array($lang_misc['Moderate forum'], forum_link($forum_url['moderate_forum'], $fid)),
  155. $lang_pun_move_posts['Move posts']
  156. );
  157. //Setup main heading
  158. define('FORUM_PAGE', 'dialogue');
  159. require FORUM_ROOT.'header.php';
  160. // START SUBST - <!-- forum_main -->
  161. ob_start();
  162. ?>
  163. <div class="main-head">
  164. <h2 class="hn"><span><?php echo end($forum_page['crumbs']) ?></span></h2>
  165. </div>
  166. <div class="main-content main-frm">
  167. <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>">
  168. <div class="hidden">
  169. <?php echo implode("\n\t\t\t\t", $forum_page['hidden_fields'])."\n" ?>
  170. </div>
  171. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  172. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  173. <div class="sf-box select">
  174. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_pun_move_posts['Destination topic']?></span></label><br />
  175. <span class="fld-input"><select id="<?php echo $forum_page['fld_count'] ?>" name="move_to_topic">
  176. <?php
  177. $forum_page['cur_forum'] = 0;
  178. foreach ($forum_list as $cur_forum)
  179. {
  180. if ($cur_forum['fid'] != $forum_page['cur_forum']) // A new category since last iteration?
  181. {
  182. if ($forum_page['cur_forum'])
  183. echo "\t\t\t\t".'</optgroup>'."\n";
  184. echo "\t\t\t\t".'<optgroup label="'.forum_htmlencode($cur_forum['f_name']).'">'."\n";
  185. $forum_page['cur_forum'] = $cur_forum['fid'];
  186. }
  187. if ($cur_forum['tid'] != $tid)
  188. echo "\t\t\t\t".'<option value="'.$cur_forum['tid'].'">'.forum_htmlencode($cur_forum['topic_subject']).'</option>'."\n";
  189. }
  190. ?>
  191. </optgroup>
  192. </select></span>
  193. </div>
  194. </div>
  195. <div class="sf-set set2">
  196. <div class="sf-box checkbox">
  197. <span class="fld-input"><input type="checkbox" id="fld2" name="change_time" value="1" /></span>
  198. <label for="fld2"><span><?php echo $lang_pun_move_posts['Ignore dates']?></span> <?php echo $lang_pun_move_posts['Ignore text']?></label>
  199. </div>
  200. </div>
  201. </fieldset>
  202. <div class="frm-buttons">
  203. <span class="submit"><input type="submit" name="move_posts_to" value="<?php echo $lang_misc['Move'] ?>" /></span>
  204. <span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" /></span>
  205. </div>
  206. </form>
  207. </div>
  208. <?php
  209. $forum_id = $fid;
  210. $tpl_temp = forum_trim(ob_get_contents());
  211. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  212. ob_end_clean();
  213. // END SUBST - <!-- forum_main -->
  214. require FORUM_ROOT.'footer.php';
  215. }
  216. if (isset($_POST['move_posts_to']))
  217. {
  218. $posts = isset($_POST['posts']) && !empty($_POST['posts']) ? $_POST['posts'] : array();
  219. $posts = array_map('intval', (is_array($posts) ? $posts : explode(',', $posts)));
  220. $move_to_topic = isset($_POST['move_to_topic']) && !empty($_POST['move_to_topic']) ? $_POST['move_to_topic'] : array();
  221. if (empty($posts))
  222. message($lang_misc['No posts selected']);
  223. // Move the posts
  224. $query = array(
  225. 'UPDATE' => 'posts',
  226. 'SET' => 'topic_id='.$move_to_topic,
  227. 'WHERE' => 'id IN('.implode(',', $posts).')'
  228. );
  229. if (isset($_POST['change_time']))
  230. $query['SET'] .= ', posted='.time();
  231. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  232. $query = array(
  233. 'SELECT' => '*',
  234. 'FROM' => 'posts',
  235. 'WHERE' => 'id IN('.implode(',', $posts).')',
  236. 'ORDER BY' => 'posted'
  237. );
  238. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  239. while ($cur_sel_forum = $forum_db->fetch_assoc($result))
  240. {
  241. $values = array();
  242. foreach ($cur_sel_forum as $k => $v)
  243. {
  244. if (!(empty($v)||$k=='id'))
  245. $values[$k]='\''.$forum_db->escape($v).'\'';
  246. }
  247. $query = array(
  248. 'INSERT' => implode(',', array_keys($values)),
  249. 'INTO' => 'posts',
  250. 'VALUES' => implode(',', $values)
  251. );
  252. $forum_db->query_build($query);// or error(__FILE__, __LINE__);
  253. }
  254. $query = array(
  255. 'DELETE' => 'posts',
  256. 'WHERE' => 'id IN('.implode(',', $posts).')'
  257. );
  258. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  259. sync_topic($tid);
  260. sync_topic($move_to_topic);
  261. sync_forum($fid);
  262. redirect(forum_link($forum_url['topic'], array($tid, sef_friendly($cur_topic['subject']))), 'Move posts');
  263. }
  264. ?>