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