831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
4 |
// //
|
|
|
5 |
// Copyright (C) 2006 Phorum Development Team //
|
|
|
6 |
// http://www.phorum.org //
|
|
|
7 |
// //
|
|
|
8 |
// This program is free software. You can redistribute it and/or modify //
|
|
|
9 |
// it under the terms of either the current Phorum License (viewable at //
|
|
|
10 |
// phorum.org) or the Phorum License that was distributed with this file //
|
|
|
11 |
// //
|
|
|
12 |
// This program is distributed in the hope that it will be useful, //
|
|
|
13 |
// but WITHOUT ANY WARRANTY, without even the implied warranty of //
|
|
|
14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
|
|
|
15 |
// //
|
|
|
16 |
// You should have received a copy of the Phorum License //
|
|
|
17 |
// along with this program. //
|
|
|
18 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
19 |
|
|
|
20 |
// Phorum 5 Admin
|
|
|
21 |
|
|
|
22 |
define("PHORUM_ADMIN", 1);
|
|
|
23 |
|
|
|
24 |
// set a sane error level for our admin.
|
|
|
25 |
// this will make the coding time faster and
|
|
|
26 |
// the code run faster.
|
|
|
27 |
error_reporting (E_ERROR | E_WARNING | E_PARSE);
|
|
|
28 |
|
|
|
29 |
include_once "./common.php";
|
|
|
30 |
include_once "./include/users.php";
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
// if we are installing or upgrading, we don't need to check for a session
|
|
|
34 |
// 2005081000 was the internal version that introduced the installed flag
|
|
|
35 |
if(!isset($PHORUM['internal_version']) || (!isset($PHORUM['installed']) && $PHORUM['internal_version']>='2005081000')) {
|
|
|
36 |
|
|
|
37 |
// this is an install
|
|
|
38 |
$module="install";
|
|
|
39 |
|
|
|
40 |
} elseif (isset($PHORUM['internal_version']) && $PHORUM['internal_version'] < PHORUMINTERNAL) {
|
|
|
41 |
|
|
|
42 |
// this is an upgrade
|
|
|
43 |
$module="upgrade";
|
|
|
44 |
|
|
|
45 |
} else {
|
|
|
46 |
|
|
|
47 |
// check for a session
|
|
|
48 |
phorum_user_check_session("phorum_admin_session");
|
|
|
49 |
|
|
|
50 |
if(!isset($GLOBALS["PHORUM"]["user"]) || !$GLOBALS["PHORUM"]["user"]["admin"]){
|
|
|
51 |
// if not an admin
|
|
|
52 |
unset($GLOBALS["PHORUM"]["user"]);
|
|
|
53 |
$module="login";
|
|
|
54 |
} else {
|
|
|
55 |
// load the default module if none is specified
|
|
|
56 |
if(!empty($_REQUEST["module"])){
|
|
|
57 |
$module = basename($_REQUEST["module"]);
|
|
|
58 |
} else {
|
|
|
59 |
$module = "default";
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
ob_start();
|
|
|
67 |
if($module!="help") include_once "./include/admin/header.php";
|
|
|
68 |
@include_once "./include/admin/$module.php";
|
|
|
69 |
if($module!="help") include_once "./include/admin/footer.php";
|
|
|
70 |
ob_end_flush();
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
/////////////////////////////////////////////////
|
|
|
74 |
|
|
|
75 |
function phorum_admin_error($error)
|
|
|
76 |
{
|
|
|
77 |
echo "<div class=\"PhorumAdminError\">$error</div>\n";
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
function phorum_admin_okmsg($error)
|
|
|
81 |
{
|
|
|
82 |
echo "<div class=\"PhorumAdminOkMsg\">$error</div>\n";
|
|
|
83 |
}
|
|
|
84 |
// phorum_get_language_info and phorum_get_template_info moved to common.php (used in the cc too)
|
|
|
85 |
|
|
|
86 |
function phorum_get_folder_info()
|
|
|
87 |
{
|
|
|
88 |
$folders=array();
|
|
|
89 |
$folder_data=array();
|
|
|
90 |
|
|
|
91 |
$forums = phorum_db_get_forums();
|
|
|
92 |
|
|
|
93 |
foreach($forums as $forum){
|
|
|
94 |
if($forum["folder_flag"]){
|
|
|
95 |
$path = $forum["name"];
|
|
|
96 |
$parent_id=$forum["parent_id"];
|
|
|
97 |
while($parent_id!=0 && $parent_id!=$forum["forum_id"]){
|
|
|
98 |
$path=$forums[$parent_id]["name"]."::$path";
|
|
|
99 |
$parent_id=$forums[$parent_id]["parent_id"];
|
|
|
100 |
}
|
|
|
101 |
$folders[$forum["forum_id"]]=$path;
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
asort($folders);
|
|
|
106 |
|
|
|
107 |
$tmp=array("--None--");
|
|
|
108 |
|
|
|
109 |
foreach($folders as $id => $folder){
|
|
|
110 |
$tmp[$id]=$folder;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
$folders=$tmp;
|
|
|
114 |
|
|
|
115 |
return $folders;
|
|
|
116 |
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
function phorum_get_forum_info($forums_only=0)
|
|
|
120 |
{
|
|
|
121 |
$folders=array();
|
|
|
122 |
$folder_data=array();
|
|
|
123 |
|
|
|
124 |
$forums = phorum_db_get_forums();
|
|
|
125 |
|
|
|
126 |
foreach($forums as $forum){
|
|
|
127 |
if($forums_only == 0 || $forum['folder_flag']==0 || ($forums_only=2 && $forum['vroot'] && $forum['vroot'] == $forum['forum_id'])) {
|
|
|
128 |
$path = $forum["name"];
|
|
|
129 |
$parent_id=$forum["parent_id"];
|
|
|
130 |
while($parent_id!=0){
|
|
|
131 |
$path=$forums[$forum["parent_id"]]["name"]."::$path";
|
|
|
132 |
|
|
|
133 |
$parent_id=$forums[$parent_id]["parent_id"];
|
|
|
134 |
}
|
|
|
135 |
if($forum['vroot'] && $forum['vroot']==$forum['forum_id']) {
|
|
|
136 |
$path.=" (Virtual Root)";
|
|
|
137 |
}
|
|
|
138 |
$folders[$forum["forum_id"]]=$path;
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
asort($folders);
|
|
|
143 |
|
|
|
144 |
return $folders;
|
|
|
145 |
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
/*
|
|
|
149 |
* Sets the given vroot for the descending forums / folders
|
|
|
150 |
* which are not yet in another descending vroot
|
|
|
151 |
*
|
|
|
152 |
* $folder = folder from which we should go down
|
|
|
153 |
* $vroot = virtual root we set the folders/forums to
|
|
|
154 |
* $old_vroot = virtual root which should be overrideen with the new value
|
|
|
155 |
*
|
|
|
156 |
*/
|
|
|
157 |
function phorum_admin_set_vroot($folder,$vroot=-1,$old_vroot=0) {
|
|
|
158 |
// which vroot
|
|
|
159 |
if($vroot == -1) {
|
|
|
160 |
$vroot=$folder;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
// get the desc forums/folders
|
|
|
164 |
$descending=phorum_admin_get_descending($folder);
|
|
|
165 |
$valid=array();
|
|
|
166 |
|
|
|
167 |
// collecting vroots
|
|
|
168 |
$vroots=array();
|
|
|
169 |
foreach($descending as $id => $data) {
|
|
|
170 |
if($data['folder_flag'] == 1 && $data['vroot'] != 0 && $data['forum_id'] == $data['vroot']) {
|
|
|
171 |
$vroots[$data['vroot']]=true;
|
|
|
172 |
}
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
// getting forums which are not in a vroot or not in *this* vroot
|
|
|
176 |
foreach($descending as $id => $data) {
|
|
|
177 |
if($data['vroot'] == $old_vroot || !isset($vroots[$data['vroot']])) {
|
|
|
178 |
$valid[$id]=$data;
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
// $valid = forums/folders which are not in another vroot
|
|
|
183 |
$set_ids=array_keys($valid);
|
|
|
184 |
$set_ids[]=$folder;
|
|
|
185 |
|
|
|
186 |
$new_forum_data=array('forum_id'=>$set_ids,'vroot'=>$vroot);
|
|
|
187 |
$returnval=phorum_db_update_forum($new_forum_data);
|
|
|
188 |
|
|
|
189 |
return $returnval;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
function phorum_admin_get_descending($parent) {
|
|
|
193 |
|
|
|
194 |
$ret_data=array();
|
|
|
195 |
$arr_data=phorum_db_get_forums(0,$parent);
|
|
|
196 |
foreach($arr_data as $key => $val) {
|
|
|
197 |
$ret_data[$key]=$val;
|
|
|
198 |
if($val['folder_flag'] == 1) {
|
|
|
199 |
$more_data=phorum_db_get_forums(0,$val['forum_id']);
|
|
|
200 |
$ret_data=$ret_data + $more_data; // array_merge reindexes the array
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
return $ret_data;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
function phorum_upgrade_tables($fromversion,$toversion) {
|
|
|
207 |
|
|
|
208 |
$PHORUM=$GLOBALS['PHORUM'];
|
|
|
209 |
|
|
|
210 |
if(empty($fromversion) || empty($toversion)){
|
|
|
211 |
die("Something is wrong with the upgrade script. Please contact the Phorum Dev Team. ($fromversion,$toversion)");
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
$msg="";
|
|
|
215 |
$upgradepath="./include/db/upgrade/{$PHORUM['DBCONFIG']['type']}/";
|
|
|
216 |
|
|
|
217 |
// read in all existing files
|
|
|
218 |
$dh=opendir($upgradepath);
|
|
|
219 |
$upgradefiles=array();
|
|
|
220 |
while ($file = readdir ($dh)) {
|
|
|
221 |
if (substr($file,-4,4) == ".php") {
|
|
|
222 |
$upgradefiles[]=$file;
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
unset($file);
|
|
|
226 |
closedir($dh);
|
|
|
227 |
|
|
|
228 |
// sorting by number
|
|
|
229 |
sort($upgradefiles,SORT_NUMERIC);
|
|
|
230 |
reset($upgradefiles);
|
|
|
231 |
|
|
|
232 |
// advance to current version
|
|
|
233 |
while(list($key,$val)=each($upgradefiles)) {
|
|
|
234 |
if($val == $fromversion.".php")
|
|
|
235 |
break;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
// get the file for the next version (which we will upgrade to)
|
|
|
241 |
list($dump,$file) = each($upgradefiles);
|
|
|
242 |
|
|
|
243 |
// extract the pure version, needed as internal version
|
|
|
244 |
$pure_version = basename($file,".php");
|
|
|
245 |
|
|
|
246 |
if(empty($pure_version)){
|
|
|
247 |
die("Something is wrong with the upgrade script. Please contact the Phorum Dev Team. ($fromversion,$toversion)");
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
$upgradefile=$upgradepath.$file;
|
|
|
252 |
|
|
|
253 |
if(file_exists($upgradefile)) {
|
|
|
254 |
if (! is_readable($upgradefile))
|
|
|
255 |
die("$upgradefile is not readable. Make sure the file has got the neccessary permissions and try again.");
|
|
|
256 |
|
|
|
257 |
$msg.="Upgrading from db-version $fromversion to $pure_version ... ";
|
|
|
258 |
$upgrade_queries=array();
|
|
|
259 |
include($upgradefile);
|
|
|
260 |
$err=phorum_db_run_queries($upgrade_queries);
|
|
|
261 |
if($err){
|
|
|
262 |
$msg.= "an error occured: $err ... try to continue.<br />\n";
|
|
|
263 |
} else {
|
|
|
264 |
$msg.= "done.<br />\n";
|
|
|
265 |
}
|
|
|
266 |
$GLOBALS["PHORUM"]["internal_version"]=$pure_version;
|
|
|
267 |
phorum_db_update_settings(array("internal_version"=>$pure_version));
|
|
|
268 |
} else {
|
|
|
269 |
$msg="Ooops, the upgradefile is missing. How could this happen?";
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
return $msg;
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
function phorum_admin_gen_compare($txt) {
|
|
|
276 |
$func = 0;
|
|
|
277 |
if($txt == "gt") {
|
|
|
278 |
$func = create_function('$a, $b', 'return $a > $b;');
|
|
|
279 |
} elseif($txt == "gte") {
|
|
|
280 |
$func = create_function('$a, $b', 'return $a >= $b;');
|
|
|
281 |
} elseif($txt == "lt") {
|
|
|
282 |
$func = create_function('$a, $b', 'return $a < $b;');
|
|
|
283 |
} elseif($txt == "lte") {
|
|
|
284 |
$func = create_function('$a, $b', 'return $a <= $b;');
|
|
|
285 |
} elseif($txt == "eq") {
|
|
|
286 |
$func = create_function('$a, $b', 'return $a == $b;');
|
|
|
287 |
}
|
|
|
288 |
if(!$func) {
|
|
|
289 |
phorum_admin_error("Invalid posts comparison operator.");
|
|
|
290 |
return NULL;
|
|
|
291 |
}
|
|
|
292 |
return $func;
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
function phorum_admin_filter_arr($arr,$field,$value,$cmpfn) {
|
|
|
296 |
$new = array();
|
|
|
297 |
foreach($arr as $item){
|
|
|
298 |
if(isset($item[$field]) && $cmpfn($item[$field],$value)) {
|
|
|
299 |
array_push($new,$item);
|
|
|
300 |
}
|
|
|
301 |
}
|
|
|
302 |
return $new;
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
?>
|