[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> control.php (source)

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


Généré le : Thu Nov 29 12:22:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics