Просмотр файла includes/functions_admin.php

Размер файла: 5.74Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. function make_forum_select($box_name, $ignore_forum = false, $select_forum = '')
  7. {
  8. global $db, $userdata, $lang;
  9.  
  10. $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
  11.  
  12. $sql = 'SELECT f.forum_id, f.forum_name
  13. FROM ' . CATEGORIES_TABLE . ' c, ' . FORUMS_TABLE . ' f
  14. WHERE f.cat_id = c.cat_id
  15. ORDER BY c.cat_order, f.forum_order';
  16. if ( !($result = $db->sql_query($sql)) )
  17. {
  18. message_die(GENERAL_ERROR, 'Couldn not obtain forums information', '', __LINE__, __FILE__, $sql);
  19. }
  20.  
  21. $forum_list = '';
  22. while( $row = $db->sql_fetchrow($result) )
  23. {
  24. if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] )
  25. {
  26. $selected = ( $select_forum == $row['forum_id'] ) ? ' selected="selected"' : '';
  27. $forum_list .= '<option value="' . $row['forum_id'] . '"' . $selected .'>' . $row['forum_name'] . '</option>';
  28. }
  29. }
  30.  
  31. $forum_list = ( $forum_list == '' ) ? $lang['No_forums'] : '<select name="' . $box_name . '">' . $forum_list . '</select>';
  32.  
  33. return $forum_list;
  34. }
  35.  
  36. function sync($type, $id = false)
  37. {
  38. global $db;
  39.  
  40. switch($type)
  41. {
  42. case 'all forums':
  43. $sql = "SELECT forum_id
  44. FROM " . FORUMS_TABLE;
  45. if ( !($result = $db->sql_query($sql)) )
  46. {
  47. message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
  48. }
  49.  
  50. while( $row = $db->sql_fetchrow($result) )
  51. {
  52. sync('forum', $row['forum_id']);
  53. }
  54. break;
  55.  
  56. case 'all topics':
  57. $sql = "SELECT topic_id
  58. FROM " . TOPICS_TABLE;
  59. if ( !($result = $db->sql_query($sql)) )
  60. {
  61. message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
  62. }
  63.  
  64. while( $row = $db->sql_fetchrow($result) )
  65. {
  66. sync('topic', $row['topic_id']);
  67. }
  68. break;
  69.  
  70. case 'forum':
  71. $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total
  72. FROM " . POSTS_TABLE . "
  73. WHERE forum_id = $id";
  74. if ( !($result = $db->sql_query($sql)) )
  75. {
  76. message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  77. }
  78.  
  79. if ( $row = $db->sql_fetchrow($result) )
  80. {
  81. $last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
  82. $total_posts = ($row['total']) ? $row['total'] : 0;
  83. }
  84. else
  85. {
  86. $last_post = 0;
  87. $total_posts = 0;
  88. }
  89.  
  90. $sql = "SELECT COUNT(topic_id) AS total
  91. FROM " . TOPICS_TABLE . "
  92. WHERE forum_id = $id";
  93. if ( !($result = $db->sql_query($sql)) )
  94. {
  95. message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
  96. }
  97.  
  98. $total_topics = ( $row = $db->sql_fetchrow($result) ) ? ( ( $row['total'] ) ? $row['total'] : 0 ) : 0;
  99.  
  100. $sql = "UPDATE " . FORUMS_TABLE . "
  101. SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
  102. WHERE forum_id = $id";
  103. if ( !$db->sql_query($sql) )
  104. {
  105. message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
  106. }
  107. global $board_config;
  108.  
  109. if ($board_config['reputation_enabled'] || $board_config['warnings_enabled'])
  110. {
  111. $result = db_query('SELECT r.id, r.forum_id AS review_forum_id, p.post_id, p.forum_id AS post_forum_id
  112. FROM {REPUTATION_TABLE} r LEFT JOIN {POSTS_TABLE} p ON r.post_id = p.post_id
  113. WHERE r.forum_id = %d
  114. AND (p.forum_id <> r.forum_id OR (r.post_id <> {NO_ID} AND p.post_id IS NULL))', $id);
  115.  
  116. $no_post = ''; $wrong_forum = array();
  117.  
  118. while ($row = $db->sql_fetchrow($result))
  119. {
  120. if (!$row['post_id'])
  121. {
  122. $no_post .= ($no_post ? ',' : '') . $row['id'];
  123. }
  124. elseif ($row['review_forum_id'] != $row['post_forum_id'])
  125. {
  126. if (isset($wrong_forum[$row['post_forum_id']]))
  127. {
  128. $wrong_forum[$row['post_forum_id']] .= ',' . $row['id'];
  129. }
  130. else
  131. {
  132. $wrong_forum[$row['post_forum_id']] = $row['id'];
  133. }
  134. }
  135. }
  136.  
  137. if ($no_post)
  138. {
  139. db_query('UPDATE {REPUTATION_TABLE} SET post_id = {NO_ID} WHERE id IN(%s)', $no_post);
  140. }
  141. foreach ($wrong_forum as $forum_id => $review_ids)
  142. {
  143. db_query('UPDATE {REPUTATION_TABLE} SET forum_id = %d WHERE id IN(%s)', $forum_id, $review_ids);
  144. }
  145. }
  146.  
  147. break;
  148.  
  149. case 'topic':
  150. $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
  151. FROM " . POSTS_TABLE . "
  152. WHERE topic_id = $id";
  153. if ( !($result = $db->sql_query($sql)) )
  154. {
  155. message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  156. }
  157.  
  158. if ( $row = $db->sql_fetchrow($result) )
  159. {
  160. if ($row['total_posts'])
  161. {
  162. $sql = 'UPDATE ' . TOPICS_TABLE . '
  163. SET topic_replies = ' . ($row['total_posts'] - 1) . ', topic_first_post_id = ' . $row['first_post'] . ', topic_last_post_id = ' . $row['last_post'] . "
  164. WHERE topic_id = $id";
  165.  
  166. if (!$db->sql_query($sql))
  167. {
  168. message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
  169. }
  170. }
  171. else
  172. {
  173. $sql = 'SELECT topic_moved_id
  174. FROM ' . TOPICS_TABLE . "
  175. WHERE topic_id = $id";
  176.  
  177. if (!($result = $db->sql_query($sql)))
  178. {
  179. message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
  180. }
  181.  
  182. if ($row = $db->sql_fetchrow($result))
  183. {
  184. if (!$row['topic_moved_id'])
  185. {
  186. $sql = 'DELETE FROM ' . TOPICS_TABLE . " WHERE topic_id = $id";
  187. if (!$db->sql_query($sql))
  188. {
  189. message_die(GENERAL_ERROR, 'Could not remove topic', '', __LINE__, __FILE__, $sql);
  190. }
  191. }
  192. }
  193.  
  194. $db->sql_freeresult($result);
  195. }
  196. attachment_sync_topic($id);
  197. }
  198. break;
  199. }
  200. return true;
  201. }
  202.  
  203. ?>