3 * http://fusionforge.org
5 * This file is part of FusionForge. FusionForge is free software;
6 * you can redistribute it and/or modify it under the terms of the
7 * GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the Licence, or (at your option)
11 * FusionForge is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 require_once('../env.inc.php');
22 require_once $gfcommon.'include/pre.php';
23 require_once $gfcommon.'include/preplugins.php';
24 require_once $gfcommon.'include/plugins_utils.php';
25 require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
26 require_once $gfcommon.'widget/Widget.class.php';
28 $request =& HTTPRequest::instance();
30 $lm = new WidgetLayoutManager();
33 $owner = $request->get('owner');
36 $owner_id = (int)substr($owner, 1);
37 $owner_type = substr($owner, 0, 1);
39 case WidgetLayoutManager::OWNER_TYPE_USER:
40 $owner_id = user_getid();
41 $layout_id =(int)$request->get('layout_id');
45 case WidgetLayoutManager::OWNER_TYPE_GROUP:
46 $pm = ProjectManager::instance();
47 if ($project = $pm->getProject($owner_id)) {
48 $group_id = $owner_id;
49 $_REQUEST['group_id'] = $_GET['group_id'] = $group_id;
50 $request->params['group_id'] = $group_id; //bad!
51 $redirect = '/projects/'. $project->getUnixName().'/';
52 if (!forge_check_perm('project_admin', $group_id) &&
53 !forge_check_global_perm('forge_admin')) {
54 $GLOBALS['Response']->redirect($redirect);
63 if (($layout_id = (int)$request->get('layout_id')) || $request->get('action') == 'preferences') {
65 if ($request->exist('name')) {
66 $param = $request->get('name');
67 $name = array_pop(array_keys($param));
68 $instance_id = (int)$param[$name];
70 switch($request->get('action')) {
72 if ($name && $request->exist('layout_id')) {
73 if ($widget = Widget::getInstance($name)) {
74 if ($widget->isAvailable()) {
75 $action = array_pop(array_keys($param[$name]));
78 $instance_id = (int)$param[$name][$action];
79 if ($owner_type == WidgetLayoutManager::OWNER_TYPE_GROUP) {
80 if (forge_check_perm ('project_admin', $owner_id, NULL)) {
81 $lm->removeWidget($owner_id, $owner_type, $layout_id, $name, $instance_id, $widget);
84 $lm->removeWidget($owner_id, $owner_type, $layout_id, $name, $instance_id, $widget);
89 $redirect ='/widgets/widgets.php?owner='. $owner_type.$owner_id.'&layout_id='. $layout_id.'#filter-widget-categ-'.$widget->getCategory();
90 $lm->addWidget($owner_id, $owner_type, $layout_id, $name, $widget, $request);
99 $lm->mimizeWidget($owner_id, $owner_type, $layout_id, $name, $instance_id);
104 $lm->maximizeWidget($owner_id, $owner_type, $layout_id, $name, $instance_id);
109 $lm->displayWidgetPreferences($owner_id, $owner_type, $layout_id, $name, $instance_id);
113 $lm->updateLayout($owner_id, $owner_type, $request->get('layout_id'), $request->get('new_layout'));
116 $lm->reorderLayout($owner_id, $owner_type, $layout_id, $request);
122 if (!$request->isAjax()) {
123 htmlRedirect($redirect);