[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/include/admin/ -> newfolder.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  
  20      if(!defined("PHORUM_ADMIN")) return;
  21  
  22      $error="";
  23      $setvroot=false; // is this folder set as vroot?
  24  
  25      if(count($_POST)){
  26  
  27          // Post data preprocessing.
  28          foreach($_POST as $field=>$value){
  29  
  30              switch($field){
  31  
  32                  case "name":
  33                      $value = trim($value);
  34                      $_POST["name"] = $value;
  35                      if($value == ''){
  36                          $error="Please fill in Title";
  37                      }
  38                      break;
  39                  case "vroot":
  40                      // did we set this folder as vroot?
  41                      // existing folder new vroot for everything below
  42                      if($value > 0 && 
  43                          (isset($_POST['forum_id']) && $_POST['forum_id'])) {
  44                          $setvroot=true;   
  45                      // new folder which is vroot for everything below
  46                      } elseif($value > 0 && !defined("PHORUM_EDIT_FOLDER")) {
  47                          $setvroot=true;   
  48                      }
  49                      break;
  50              }
  51          }
  52  
  53          if(empty($error)){
  54              $_POST = phorum_hook("admin_editfolder_form_save", $_POST);
  55              if (isset($_POST["error"])) {
  56                  $error = $_POST["error"];
  57                  unset($_POST["error"]);
  58              }
  59          }
  60  
  61          // we need the old folder for vroots ... see below
  62          if(defined("PHORUM_EDIT_FOLDER")){
  63              $cur_folder_id=$_POST['forum_id'];
  64              $oldfolder_tmp=phorum_db_get_forums($cur_folder_id);
  65              $oldfolder=array_shift($oldfolder_tmp);
  66          } else {
  67              $oldfolder=array('vroot'=>0,'parent_id'=>0);
  68          }
  69  
  70          if(empty($error)){
  71              unset($_POST["module"]);
  72              unset($_POST["vroot"]); // we set it separately below
  73  
  74              // update the folder
  75              if(defined("PHORUM_EDIT_FOLDER")){
  76                  $cur_folder_id=$_POST['forum_id'];
  77                  $res=phorum_db_update_forum($_POST);
  78              // add the folder
  79              } else {
  80                  $res=phorum_db_add_forum($_POST);
  81                  $cur_folder_id=$res;
  82              }
  83  
  84              // other db-operations done, now doing the work for vroots
  85              if($res){
  86              
  87                  $cur_folder_tmp=phorum_db_get_forums($cur_folder_id);
  88                  $cur_folder=array_shift($cur_folder_tmp);
  89                                 
  90                  
  91                  if (!$setvroot && (
  92                      // we had a vroot before but now we removed it
  93                      ($oldfolder['vroot'] && $oldfolder['vroot'] == $cur_folder_id) ||
  94                      // or we moved this folder somewhere else
  95                      ($oldfolder['parent_id'] != $cur_folder['parent_id'])
  96                     )) { 
  97  
  98                      // get the parent_id and set its vroot (if its a folder)
  99                      // to the desc folders/forums
 100                      if($cur_folder['parent_id'] > 0) { // is it a real folder?
 101                          $parent_folder=phorum_db_get_forums($cur_folder['parent_id']);
 102                          
 103                          // then set the vroot to the vroot of the parent-folder (be it 0 or a real vroot)
 104                          phorum_admin_set_vroot($cur_folder_id,$parent_folder[$cur_folder['parent_id']]['vroot'],$cur_folder_id);
 105                          
 106                      } else { // just default root ... 
 107                          phorum_admin_set_vroot($cur_folder_id,0,$cur_folder_id);
 108                      }
 109                      
 110                      // need to clear announcements in this vroot
 111                      $PHORUM['forum_id']=$oldfolder['vroot'];
 112                      $GLOBALS['PHORUM']['forum_id']=$oldfolder['vroot'];
 113                      $msg_array=phorum_db_get_message(PHORUM_SORT_ANNOUNCEMENT,'sort');
 114                      while(count($msg_array)) {
 115                          // set announcements to forum-id=0 and hidden ...
 116                          $new_msg=array('forum_id'=>0,'status'=>PHORUM_STATUS_HIDDEN);
 117                          
 118                          phorum_db_update_message($msg_array['message_id'],$new_msg);
 119                          $msg_array=phorum_db_get_message(PHORUM_SORT_ANNOUNCEMENT,'sort');
 120                      }
 121                      
 122  
 123                  // we have now set this folder as vroot
 124                  } elseif($setvroot && ($oldfolder['vroot']==0 || $oldfolder['vroot'] != $cur_folder_id)) {    
 125                      if(!phorum_admin_set_vroot($cur_folder_id)) {
 126                          $error="Database error while setting virtual-root info.";
 127                      }            
 128                      
 129                  } // is there an else?
 130                  
 131              } else {
 132                  $error="Database error while adding/updating folder.";
 133              }
 134          }
 135  
 136          if(empty($error)) {
 137              phorum_redirect_by_url("{$PHORUM["admin_http_path"]}?parent_id={$cur_folder["parent_id"]}");
 138              exit();
 139          }
 140  
 141          foreach($_POST as $key=>$value){
 142              $$key=$value;
 143          }
 144  
 145          $forum_settings = $_POST;
 146  
 147          if ($setvroot) {
 148              $vroot = $_POST["forum_id"];
 149          } else {
 150              if ($_POST["forum_id"] != $oldfolder["vroot"]) {
 151                  $vroot = $oldfolder["vroot"];
 152              } else {
 153                  $vroot = 0;
 154              }
 155          }
 156          $forum_settings["vroot"] = $vroot;
 157  
 158      } elseif(defined("PHORUM_EDIT_FOLDER")) {
 159  
 160          $forums = phorum_db_get_forums($_REQUEST["forum_id"]);
 161          $forum_settings = $forums[$_REQUEST["forum_id"]];
 162          extract($forum_settings);
 163      }
 164  
 165      if($error){
 166          phorum_admin_error($error);
 167      }
 168  
 169      include_once  "./include/admin/PhorumInputForm.php";
 170  
 171      $frm = new PhorumInputForm ("", "post");
 172  
 173      $folder_data=phorum_get_folder_info();
 174  
 175      if(defined("PHORUM_EDIT_FOLDER")){
 176          $frm->hidden("module", "editfolder");
 177          $frm->hidden("forum_id", $forum_id);
 178          $title="Edit Folder";
 179  
 180          $this_folder=$folder_data[$_REQUEST["forum_id"]];
 181  
 182          foreach($folder_data as $folder_id=> $folder){
 183  
 184              // remove children from the list
 185              if($folder_id!=$_REQUEST["forum_id"] && substr($folder, 0, strlen($this_folder)+2)!="$this_folder::"){
 186                  $folders[$folder_id]=$folder;
 187              }
 188          }
 189          
 190          if($vroot == $forum_id) {
 191              $vroot=1;   
 192          } else {
 193              $foreign_vroot=$vroot;
 194              $vroot=0;
 195          }
 196  
 197      } else {
 198          $frm->hidden("module", "newfolder");
 199          $title="Add A Folder";
 200  
 201          $folders=$folder_data;
 202          $vroot=0;
 203          $active=1;
 204          $template="default";
 205      }
 206  
 207      $frm->hidden("folder_flag", "1");
 208  
 209      $frm->addbreak($title);
 210  
 211      $frm->addrow("Folder Title", $frm->text_box("name", $name, 30));
 212  
 213      $frm->addrow("Folder Description", $frm->textarea("description", $description, $cols=60, $rows=10, "style=\"width: 100%;\""), "top");
 214  
 215      $frm->addrow("Folder", $frm->select_tag("parent_id", $folders, $parent_id));
 216  
 217      $frm->addrow("Visible", $frm->select_tag("active", array("No", "Yes"), $active));
 218  
 219      $frm->addbreak("Display Settings");
 220  
 221      $frm->addrow("Template", $frm->select_tag("template", phorum_get_template_info(), $template));
 222  
 223      $frm->addrow("Language", $frm->select_tag("language", phorum_get_language_info(), $language));
 224      
 225      $frm->addrow("Virtual Root for descending forums/folders", $frm->checkbox("vroot","1","enabled",($vroot)?1:0));
 226      if($foreign_vroot > 0) {
 227          $frm->addrow("This folder is in the Virtual Root of:",$folders[$foreign_vroot]);
 228      } 
 229  
 230      phorum_hook("admin_editfolder_form", $frm, $forum_settings);
 231  
 232      $frm->show();
 233  
 234  ?>


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