blocks.php 8.41 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
6
 *
Francois Marier's avatar
Francois Marier committed
7
8
9
10
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
11
 *
Francois Marier's avatar
Francois Marier committed
12
13
14
15
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
16
 *
Francois Marier's avatar
Francois Marier committed
17
18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21
 *
 * @package    mahara
 * @subpackage core
22
 * @author     Catalyst IT Ltd
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
25
26
27
28
 *
 */

define('INTERNAL', 1);
29
30
31
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'blocks');
Richard Mansfield's avatar
Richard Mansfield committed
32

33
require(dirname(dirname(__FILE__)) . '/init.php');
Richard Mansfield's avatar
Richard Mansfield committed
34
35
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
36

37
38
39
// Emulate IE7 compatibility mode for IE8 - views js doesn't work with ie8
header('X-UA-Compatible: IE=EmulateIE7');

40
$id = param_integer('id', 0); // if 0, we're editing our profile.
Richard Mansfield's avatar
Richard Mansfield committed
41
$new = param_boolean('new', false);
42
$profile = param_boolean('profile');
43
$dashboard = param_boolean('dashboard');
44
45
46
47

if (empty($id)) {
    if (!empty($profile)) {
        try {
48
            $view = $USER->get_profile_view();
49
50
51
            $id = $view->get('id');
        }
        catch (ViewNotFoundException $_e) {
52
            throw new ParameterException("Missing parameter id and couldn't find default user profile view");
53
54
        }
    }
55
56
57
    else {
        throw new ParameterException("Missing parameter id");
    }
58
59
60
61
62
}
if (!empty($id) && empty($view)) {
    $view = new View($id);
}

Richard Mansfield's avatar
Richard Mansfield committed
63
64
65
if (!$USER->can_edit_view($view)) {
    throw new AccessDeniedException();
}
66

67
68
69
70
// If the view has been submitted, disallow editing
if ($view->is_submitted()) {
    $submittedto = $view->submitted_to();
    throw new AccessDeniedException(get_string('canteditsubmitted', 'view', $submittedto['name']));
71
72
}

Richard Mansfield's avatar
Richard Mansfield committed
73
74
$group = $view->get('group');
$institution = $view->get('institution');
75

76
77
78
79
// If a block was configured & submitted, build the form now so it can
// be processed without having to render the other blocks.
if ($blockid = param_integer('blockconfig', 0)) {
    // However, if removing a newly placed block, let it fall through to process_changes
80
    if (!isset($_POST['cancel_action_configureblockinstance_id_' . $blockid]) || !param_integer('removeoncancel', 0) || param_integer('pieform_jssubmission', 0)) {
81
82
83
84
85
86
        require_once(get_config('docroot') . 'blocktype/lib.php');
        $bi = new BlockInstance($blockid);
        $bi->build_configure_form();
    }
}

87
$view->set_edit_nav();
Richard Mansfield's avatar
Richard Mansfield committed
88

89
90
if ($view->get('type') == 'profile') {
    $profile = true;
91
    $title = get_string('usersprofile', 'mahara', display_name($view->get('owner'), null, true));
92
    define('TITLE', $title . ': ' . get_string('editcontent', 'view'));
93
}
94
95
96
else if ($view->get('type') == 'dashboard') {
    $dashboard = true;
    $title = get_string('usersdashboard', 'mahara', display_name($view->get('owner'), null, true));
97
    define('TITLE', $title . ': ' . get_string('editcontent', 'view'));
98
}
99
100
else if ($view->get('type') == 'grouphomepage') {
    $title = get_string('grouphomepage', 'view');
101
    $groupurl = group_homepage_url(get_record('group', 'id', $view->get('group')), false);
102
    define('TITLE', $title . ': ' . get_string('editcontent', 'view'));
103
}
104
else if ($new) {
105
    define('TITLE', get_string('editcontent', 'view'));
Richard Mansfield's avatar
Richard Mansfield committed
106
107
}
else {
108
    define('TITLE', $view->get('title') . ': ' . get_string('editcontent', 'view'));
109
    $editabletitle = true;
Richard Mansfield's avatar
Richard Mansfield committed
110
111
}

112
113
114
$category = param_alpha('c', '');
// Make the default category the first tab if none is set
if ($category === '') {
115
    $category = $view->get_default_category();
116
}
117
118
119

$view->process_changes($category, $new);

120
121
122
$extraconfig = array(
    'stylesheets' => array('style/views.css'),
    'sidebars'    => false,
123
124
);

125
// Set up theme
126
127
$viewtheme = $view->set_user_theme();

128
$allowedthemes = get_user_accessible_themes();
129
130

// Pull in cross-theme view stylesheet and file stylesheets
131
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');
132
foreach (array_reverse($THEME->get_url('style/style.css', true, 'artefact/file')) as $sheet) {
133
134
135
    $stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . $sheet . '">';
}

136
137
// Tell the user to change the view theme if the current one is no
// longer available to them.
138
if ($viewtheme && !isset($allowedthemes[$viewtheme])) {
139
    $smarty = smarty(array(), $stylesheets, false, $extraconfig);
140
    $smarty->assign('maintitle', TITLE);
141
142
143
144
145
146
147
148
149
    $smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php');
    $smarty->assign('view', $view->get('id'));
    $smarty->assign('viewtitle', $view->get('title'));
    $smarty->assign('viewtheme', $viewtheme);
    $smarty->assign('viewthemes', $allowedthemes);
    $smarty->display('view/changetheme.tpl');
    exit;
}

150
$javascript = array('views', 'tinymce', 'paginator', 'tablerenderer', 'artefact/file/js/filebrowser.js', 'lib/pieforms/static/core/pieforms.js');
151
152
153
$javascript = array_merge($javascript, $view->get_blocktype_javascript());

$smarty = smarty($javascript, $stylesheets, false, $extraconfig);
154
155

// The list of categories for the tabbed interface
156
$smarty->assign('category_list', $view->build_category_list($category, $new));
157
158

// The list of blocktypes for the default category
159
$smarty->assign('blocktype_list', $view->build_blocktype_list($category));
160
161
162
163

// Tell smarty we're editing rather than just rendering
$smarty->assign('editing', true);

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Work out what action is being performed. This is used to put a hidden submit 
// button right at the very start of the form, so that hitting enter in any 
// form fields will cause the correct action to be performed
foreach (array_keys($_POST + $_GET) as $key) {
    if (substr($key, 0, 7) == 'action_') {
        if (param_boolean('s')) {
            // When configuring a blockinstance and the search tab is open, 
            // pressing enter should search
            $key = str_replace('configureblockinstance', 'acsearch', $key);
            if (substr($key, -2) == '_x') {
                $key = substr($key, 0, -2);
            }
        }
        $smarty->assign('action_name', $key);
        break;
    }
}

182
$viewid = $view->get('id');
183
$smarty->assign('edittitle', $view->can_edit_title());
184
$smarty->assign('displaylink', $view->get_url());
185
$smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php');
186
$smarty->assign('category', $category);
187
$smarty->assign('new', $new);
188
$smarty->assign('profile', $profile);
189
$smarty->assign('dashboard', $dashboard);
190
191
192
if (get_config('blockeditormaxwidth')) {
    $smarty->assign('INLINEJAVASCRIPT', 'config.blockeditormaxwidth = true;');
}
193
194
195
$viewtype = $view->get('type');
$viewtitle = $view->get('title');
$owner = $view->get('owner');
196
197
198
199
200
201
if ($owner &&  $viewtype == 'profile') {
    $viewtitle = get_string('usersprofile', 'mahara', display_name($view->get('owner'), null, true));
}

if (get_config('viewmicroheaders')) {
    $smarty->assign('microheaders', true);
202
    $smarty->assign('microheadertitle', $view->display_title(true, false, false));
203
}
204

205
$smarty->assign('viewtype', $viewtype);
206
$smarty->assign('view', $view->get('id'));
207
$smarty->assign('groupid', $group);
208
209
210
if (isset($groupurl)) {
    $smarty->assign('groupurl', $groupurl);
}
211
$smarty->assign('institution', $institution);
212

213
214
if (get_config('userscanchooseviewthemes')
    && $view->is_themeable()) {
215
216
217
    $smarty->assign('viewtheme', $viewtheme);
    $smarty->assign('viewthemes', $allowedthemes);
}
218
219

$smarty->assign('viewid', $view->get('id'));
220
$smarty->assign('viewtitle', $viewtitle);
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
$blockid = $view->get_blockinstance_currently_being_configured();
if (!$blockid) {
    $blockid = param_integer('block', 0);
}
if ($blockid) {
    // Configuring a single block
    $bi = new BlockInstance($blockid);
    $smarty->assign('block', $bi->render_editing(true));
}
else {
    // The HTML for the columns in the view
    $columns = $view->build_columns(true);
    $smarty->assign('columns', $columns);
}

237
$smarty->display('view/blocks.tpl');