2 /***************************************************************************
3 * admin_forum_prune.php
5 * begin : Mon Jul 31, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_forum_prune.php,v 1.22.2.3 2002/12/18 14:14:07 psotfx Exp $
11 ****************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 ***************************************************************************/
22 define('IN_PHPBB', true);
24 if ( !empty($setmodules) )
26 $filename = basename(__FILE__);
27 $module['Forums']['Prune'] = $filename;
33 // Load default header
35 $phpbb_root_path = "./../";
36 require($phpbb_root_path . 'extension.inc');
37 require('./pagestart.' . $phpEx);
38 require($phpbb_root_path . 'includes/prune.'.$phpEx);
39 require($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
42 // Get the forum ID for pruning
44 if( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )
46 $forum_id = ( isset($HTTP_POST_VARS[POST_FORUM_URL]) ) ? $HTTP_POST_VARS[POST_FORUM_URL] : $HTTP_GET_VARS[POST_FORUM_URL];
54 $forum_id = intval($forum_id);
55 $forum_sql = "AND forum_id = $forum_id";
64 // Get a list of forum's or the data for the forum that we are pruning.
67 FROM " . FORUMS_TABLE . " f, " . CATEGORIES_TABLE . " c
68 WHERE c.cat_id = f.cat_id
70 ORDER BY c.cat_order ASC, f.forum_order ASC";
71 if( !($result = $db->sql_query($sql)) )
73 message_die(GENERAL_ERROR, 'Could not obtain list of forums for pruning', '', __LINE__, __FILE__, $sql);
76 $forum_rows = array();
77 while( $row = $db->sql_fetchrow($result) )
83 // Check for submit to be equal to Prune. If so then proceed with the pruning.
85 if( isset($HTTP_POST_VARS['doprune']) )
87 $prunedays = ( isset($HTTP_POST_VARS['prunedays']) ) ? intval($HTTP_POST_VARS['prunedays']) : 0;
89 // Convert days to seconds for timestamp functions...
90 $prunedate = time() - ( $prunedays * 86400 );
92 $template->set_filenames(array(
93 'body' => 'admin/forum_prune_result_body.tpl')
96 for($i = 0; $i < count($forum_rows); $i++)
98 $p_result = prune($forum_rows[$i]['forum_id'], $prunedate);
99 sync('forum', $forum_rows[$i]['forum_id']);
101 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
102 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
104 $template->assign_block_vars('prune_results', array(
105 'ROW_COLOR' => '#' . $row_color,
106 'ROW_CLASS' => $row_class,
107 'FORUM_NAME' => $forum_rows[$i]['forum_name'],
108 'FORUM_TOPICS' => $p_result['topics'],
109 'FORUM_POSTS' => $p_result['posts'])
113 $template->assign_vars(array(
114 'L_FORUM_PRUNE' => $lang['Forum_Prune'],
115 'L_FORUM' => $lang['Forum'],
116 'L_TOPICS_PRUNED' => $lang['Topics_pruned'],
117 'L_POSTS_PRUNED' => $lang['Posts_pruned'],
118 'L_PRUNE_RESULT' => $lang['Prune_success'])
124 // If they haven't selected a forum for pruning yet then
125 // display a select box to use for pruning.
127 if( empty($HTTP_POST_VARS[POST_FORUM_URL]) )
130 // Output a selection table if no forum id has been specified.
132 $template->set_filenames(array(
133 'body' => 'admin/forum_prune_select_body.tpl')
136 $select_list = '<select name="' . POST_FORUM_URL . '">';
137 $select_list .= '<option value="-1">' . $lang['All_Forums'] . '</option>';
139 for($i = 0; $i < count($forum_rows); $i++)
141 $select_list .= '<option value="' . $forum_rows[$i]['forum_id'] . '">' . $forum_rows[$i]['forum_name'] . '</option>';
143 $select_list .= '</select>';
146 // Assign the template variables.
148 $template->assign_vars(array(
149 'L_FORUM_PRUNE' => $lang['Forum_Prune'],
150 'L_SELECT_FORUM' => $lang['Select_a_Forum'],
151 'L_LOOK_UP' => $lang['Look_up_Forum'],
153 'S_FORUMPRUNE_ACTION' => append_sid("admin_forum_prune.$phpEx"),
154 'S_FORUMS_SELECT' => $select_list)
159 $forum_id = intval($HTTP_POST_VARS[POST_FORUM_URL]);
162 // Output the form to retrieve Prune information.
164 $template->set_filenames(array(
165 'body' => 'admin/forum_prune_body.tpl')
168 $forum_name = ( $forum_id == -1 ) ? $lang['All_Forums'] : $forum_rows[0]['forum_name'];
170 $prune_data = $lang['Prune_topics_not_posted'] . " ";
171 $prune_data .= '<input class="post" type="text" name="prunedays" size="4"> ' . $lang['Days'];
173 $hidden_input = '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
176 // Assign the template variables.
178 $template->assign_vars(array(
179 'FORUM_NAME' => $forum_name,
181 'L_FORUM' => $lang['Forum'],
182 'L_FORUM_PRUNE' => $lang['Forum_Prune'],
183 'L_FORUM_PRUNE_EXPLAIN' => $lang['Forum_Prune_explain'],
184 'L_DO_PRUNE' => $lang['Do_Prune'],
186 'S_FORUMPRUNE_ACTION' => append_sid("admin_forum_prune.$phpEx"),
187 'S_PRUNE_DATA' => $prune_data,
188 'S_HIDDEN_VARS' => $hidden_input)
193 // Actually output the page here.
195 $template->pparse('body');
197 include('./page_footer_admin.'.$phpEx);