Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
define('phorum_page','control');
20
 
21
include_once("./common.php");
22
 
23
phorum_require_login();
24
 
25
include_once("./include/email_functions.php");
26
include_once("./include/format_functions.php");
27
 
28
define("PHORUM_CONTROL_CENTER", 1);
29
 
30
// A user has to be logged in to use his control-center.
31
if (!$PHORUM["DATA"]["LOGGEDIN"]) {
32
    phorum_redirect_by_url(phorum_get_url(PHORUM_LIST_URL));
33
    exit();
34
}
35
 
36
// If the user is not fully logged in, send him to the login page.
37
if(!$PHORUM["DATA"]["FULLY_LOGGEDIN"]){
38
    phorum_redirect_by_url(phorum_get_url(PHORUM_LOGIN_URL, "redir=".PHORUM_CONTROLCENTER_URL));
39
    exit();
40
}
41
 
42
$error_msg = false;
43
 
44
// Generating the panel id of the page to use.
45
$panel = (!isset($PHORUM['args']['panel']) || empty($PHORUM["args"]['panel']))
46
       ? PHORUM_CC_SUMMARY : $PHORUM["args"]['panel'];
47
 
48
// Sometimes we set the panel id from a post-form.
49
if (isset($_POST['panel'])) {
50
    $panel = $_POST['panel'];
51
}
52
 
53
// Set all our URLs.
54
phorum_build_common_urls();
55
 
56
// Generate the control panel URLs.
57
$PHORUM['DATA']['URL']['CC0'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_SUMMARY);
58
$PHORUM['DATA']['URL']['CC1'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_SUBSCRIPTION_THREADS);
59
$PHORUM['DATA']['URL']['CC2'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_SUBSCRIPTION_FORUMS);
60
$PHORUM['DATA']['URL']['CC3'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_USERINFO);
61
$PHORUM['DATA']['URL']['CC4'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_SIGNATURE);
62
$PHORUM['DATA']['URL']['CC5'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_MAIL);
63
$PHORUM['DATA']['URL']['CC6'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_BOARD);
64
$PHORUM['DATA']['URL']['CC7'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_PASSWORD);
65
$PHORUM['DATA']['URL']['CC8'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_UNAPPROVED);
66
$PHORUM['DATA']['URL']['CC9'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_FILES);
67
$PHORUM['DATA']['URL']['CC10'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_USERS);
68
$PHORUM['DATA']['URL']['CC14'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_PRIVACY);
69
$PHORUM['DATA']['URL']['CC15'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MODERATION);
70
$PHORUM['DATA']['URL']['CC16'] = phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MEMBERSHIP);
71
 
72
// Determine if the user files functionality is available.
73
$PHORUM["DATA"]["MYFILES"] = ($PHORUM["file_uploads"] || $PHORUM["user"]["admin"]);
74
 
75
// Determine if the user is a moderator.
76
$PHORUM["DATA"]["MESSAGE_MODERATOR"] = (count(phorum_user_access_list(PHORUM_USER_ALLOW_MODERATE_MESSAGES)) > 0);
77
$PHORUM["DATA"]["USER_MODERATOR"] = phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_USERS);
78
$PHORUM["DATA"]["GROUP_MODERATOR"] = phorum_user_allow_moderate_group();
79
$PHORUM["DATA"]["MODERATOR"] = ($PHORUM["DATA"]["USER_MODERATOR"] + $PHORUM["DATA"]["MESSAGE_MODERATOR"] + $PHORUM["DATA"]["GROUP_MODERATOR"]) > 0;
80
 
81
// The form action for the common form.
82
$PHORUM["DATA"]["URL"]["ACTION"] = phorum_get_url(PHORUM_CONTROLCENTER_ACTION_URL);
83
 
84
$user = $PHORUM['user'];
85
 
86
// Security messures.
87
unset($user["password"]);
88
unset($user["password_temp"]);
89
unset($user["permissions"]);
90
 
91
// Format the user signature using standard message body formatting
92
// or  HTML escape it
93
$user["signature"] = htmlspecialchars($user["signature"]);
94
 
95
// Fake a message here so we can run the sig through format_message.
96
$fake_messages = array(array("author"=>"", "email"=>"", "subject"=>"", "body"=>$user["signature"]));
97
$fake_messages = phorum_format_messages( $fake_messages );
98
$user["signature_formatted"] = $fake_messages[0]["body"];
99
 
100
// Initialize any custom profile fields that are not present.
101
if (!empty($PHORUM["PROFILE_FIELDS"])) {
102
    foreach($PHORUM["PROFILE_FIELDS"] as $field) {
103
        if (!isset($user[$field['name']])) $user[$field['name']] = "";
104
    }
105
}
106
 
107
// Setup template data.
108
$PHORUM["DATA"]["PROFILE"] = $user;
109
$PHORUM["DATA"]["PROFILE"]["forum_id"] = isset($PHORUM["forum_id"]) ? $PHORUM['forum_id'] : 0;
110
$PHORUM["DATA"]["PROFILE"]["PANEL"] = $panel;
111
 
112
// Set the back-URL and -message.
113
if ($PHORUM['forum_id'] > 0 && $PHORUM['folder_flag'] == 0) {
114
    $PHORUM['DATA']['URL']['BACK'] = phorum_get_url(PHORUM_LIST_URL);
115
    $PHORUM['DATA']['URL']['BACKTITLE'] = $PHORUM['DATA']['LANG']['BacktoForum'];
116
} else {
117
    if(isset($PHORUM['forum_id'])) {
118
        $PHORUM['DATA']['URL']['BACK'] = phorum_get_url(PHORUM_INDEX_URL,$PHORUM['forum_id']);
119
    } else {
120
        $PHORUM['DATA']['URL']['BACK'] = phorum_get_url(PHORUM_INDEX_URL);
121
    }
122
    $PHORUM['DATA']['URL']['BACKTITLE'] = $PHORUM['DATA']['LANG']['BackToForumList'];
123
}
124
 
125
// Load the include file for the current panel.
126
$panel = basename($panel);
127
if (file_exists("./include/controlcenter/$panel.php")) {
128
    include "./include/controlcenter/$panel.php";
129
} else {
130
    include "./include/controlcenter/summary.php";
131
}
132
 
133
// The include file can set the template we have to use for
134
// displaying the main part of the control panel screen
135
// in the $template variable.
136
if (isset($template)) {
137
    $PHORUM['DATA']['content_template'] = $template;
138
}
139
 
140
// The include file can also set an error message to show
141
// in the $error variable and a success message in $okmsg.
142
if (isset($error) && !empty($error)) $PHORUM['DATA']['ERROR'] = $error;
143
if (isset($okmsg) && !empty($okmsg)) $PHORUM['DATA']['OKMSG'] = $okmsg;
144
 
145
// Display the control panel page.
146
include phorum_get_template("header");
147
phorum_hook("after_header");
148
if ($error_msg) { // Possibly set from the panel include file.
149
    include phorum_get_template("message");
150
} else {
151
    include phorum_get_template("cc_index");
152
}
153
phorum_hook("before_footer");
154
include phorum_get_template("footer");
155
 
156
// ============================================================================
157
 
158
/**
159
 * A common function which is used to save the userdata from the post-data.
160
 * @param panel - The panel for which to save data.
161
 * @return array - An array containing $error and $okmsg.
162
 */
163
function phorum_controlcenter_user_save($panel)
164
{
165
    $PHORUM = $GLOBALS['PHORUM'];
166
    $error = "";
167
    $okmsg = "";
168
 
169
    // Setup the default userdata fields that may be changed
170
    // from the control panel interface.
171
    $userdata = array(
172
        'signature'       => NULL,
173
        'hide_email'      => NULL,
174
        'hide_activity'   => NULL,
175
        'password'        => NULL,
176
        'tz_offset'       => NULL,
177
        'is_dst'          => NULL,
178
        'user_language'   => NULL,
179
        'threaded_list'   => NULL,
180
        'threaded_read'   => NULL,
181
        'email_notify'    => NULL,
182
        'show_signature'  => NULL,
183
        'pm_email_notify' => NULL,
184
        'email'           => NULL,
185
        'email_temp'      => NULL,
186
        'user_template'   => NULL,
187
        'moderation_email'=> NULL,
188
    );
189
    // Add custom profile fields as acceptable fields.
190
    foreach ($PHORUM["PROFILE_FIELDS"] as $field) {
191
        $userdata[$field["name"]] = NULL;
192
    }
193
    // Update userdata with $_POST information.
194
    foreach ($_POST as $key => $val) {
195
       if (array_key_exists($key, $userdata)) {
196
           $userdata[$key] = $val;
197
       }
198
    }
199
    // Remove unused profile fields.
200
    foreach ($userdata as $key => $val) {
201
        if (is_null($val)) {
202
            unset($userdata[$key]);
203
        }
204
    }
205
 
206
    // Set static userdata.
207
    $userdata["user_id"] = $PHORUM["user"]["user_id"];
208
 
209
    // Run a hook, so module writers can update and check the userdata.
210
    $userdata = phorum_hook("cc_save_user", $userdata);
211
 
212
    // Set $error, in case the before_register hook did set an error.
213
    if (isset($userdata['error'])) {
214
        $error=$userdata['error'];
215
        unset($userdata['error']);
216
    // Try to update the userdata in the database.
217
    } elseif (!phorum_user_save($userdata)) {
218
        // Updating the user failed.
219
        $error = $PHORUM["DATA"]["LANG"]["ErrUserAddUpdate"];
220
    } else {
221
        // Updating the user was successful.
222
        $okmsg = $PHORUM["DATA"]["LANG"]["ProfileUpdatedOk"];
223
 
224
        // Let the userdata be reloaded.
225
        phorum_user_set_current_user($userdata["user_id"]);
226
 
227
        // If a new password was set, let's create a new session.
228
        if (isset($userdata["password"]) && !empty($userdata["password"])) {
229
            phorum_user_create_session();
230
        }
231
 
232
        // Copy data from the updated user back into the template data.
233
        // Leave PANEL and forum_id alone (these are injected into the
234
        // userdata in the template from this script).
235
        foreach ($GLOBALS["PHORUM"]["DATA"]["PROFILE"] as $key => $val) {
236
            if ($key == "PANEL" || $key == "forum_id") continue;
237
            if (isset($GLOBALS["PHORUM"]["user"][$key])) {
238
                $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = $GLOBALS["PHORUM"]["user"][$key];
239
            } else {
240
                $GLOBALS["PHORUM"]["DATA"]["PROFILE"][$key] = "";
241
            }
242
        }
243
    }
244
 
245
    return array($error, $okmsg);
246
}
247
 
248
?>