blocks.php 10.5 KB
Newer Older
1
2
3
4
5
<?php
/**
 *
 * @package    mahara
 * @subpackage core
6
 * @author     Catalyst IT Ltd
7
8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
9
10
11
12
 *
 */

define('INTERNAL', 1);
13
14
15
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'blocks');
Richard Mansfield's avatar
Richard Mansfield committed
16

17
require(dirname(dirname(__FILE__)) . '/init.php');
Richard Mansfield's avatar
Richard Mansfield committed
18
19
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
20

21
22
$id = param_integer('id', 0); // if 0, we're editing our profile.
$profile = param_boolean('profile');
23
$dashboard = param_boolean('dashboard');
24
25
26
27

if (empty($id)) {
    if (!empty($profile)) {
        try {
28
            $view = $USER->get_profile_view();
29
30
31
            $id = $view->get('id');
        }
        catch (ViewNotFoundException $_e) {
32
            throw new ParameterException("Missing parameter id and couldn't find default user profile view");
33
34
        }
    }
35
36
37
    else {
        throw new ParameterException("Missing parameter id");
    }
38
39
40
41
42
}
if (!empty($id) && empty($view)) {
    $view = new View($id);
}

Richard Mansfield's avatar
Richard Mansfield committed
43
44
45
if (!$USER->can_edit_view($view)) {
    throw new AccessDeniedException();
}
46

47
48
49
50
// 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']));
51
52
}

Richard Mansfield's avatar
Richard Mansfield committed
53
54
$group = $view->get('group');
$institution = $view->get('institution');
55

56
57
58
59
if ($group && !group_within_edit_window($group)) {
    throw new AccessDeniedException();
}

60
61
62
63
// 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
64
    if (!param_exists('cancel_action_configureblockinstance_id_' . $blockid) || !param_integer('removeoncancel', 0) || param_integer('pieform_jssubmission', 0)) {
65
66
        require_once(get_config('docroot') . 'blocktype/lib.php');
        $bi = new BlockInstance($blockid);
67
68
69
70
        // Check if the block_instance belongs to this view
        if ($bi->get('view') != $view->get('id')) {
            throw new AccessDeniedException(get_string('blocknotinview', 'view', $bi->get('id')));
        }
71
        $bi->build_configure_form();
72
73
74
    }
}

75
$view->set_edit_nav();
76
$state = get_string('editcontent1', 'view');
Richard Mansfield's avatar
Richard Mansfield committed
77

78
79
if ($view->get('type') == 'profile') {
    $profile = true;
80
    $title = get_string('usersprofile', 'mahara', display_name($view->get('owner'), null, true));
Naomi Guyer's avatar
Naomi Guyer committed
81
    define('TITLE', $title);
82
}
83
84
85
else if ($view->get('type') == 'dashboard') {
    $dashboard = true;
    $title = get_string('usersdashboard', 'mahara', display_name($view->get('owner'), null, true));
Naomi Guyer's avatar
Naomi Guyer committed
86
    define('TITLE', $title );
87
}
88
else if ($view->get('type') == 'grouphomepage') {
89
    $title = get_string('Grouphomepage', 'view');
90
    if ($view->get('template') != View::SITE_TEMPLATE) {
91
        $groupurl = group_homepage_url(get_group_by_id($view->get('group'), true), false);
92
    }
Naomi Guyer's avatar
Naomi Guyer committed
93
    define('TITLE', $title);
94
}
Richard Mansfield's avatar
Richard Mansfield committed
95
else {
Naomi Guyer's avatar
Naomi Guyer committed
96
    define('TITLE', $view->get('title'));
97
    $editabletitle = true;
Richard Mansfield's avatar
Richard Mansfield committed
98
}
99
define('SUBSECTIONHEADING', TITLE);
100
// Make the default category the first tab if none is set
101
102
103
104
105
$category = '';
if (param_exists('c')) {
    $category = param_variable('c');
}
if (empty($category)) {
106
    $category = $view->get_default_category();
107
}
108

109
$view->process_changes($category, false);
110

111
112
$extraconfig = array(
    'sidebars'    => false,
113
114
);

115
// Set up theme
116
117
$viewtheme = $view->set_user_theme();

118
$allowedthemes = get_user_accessible_themes();
119
120

// Pull in cross-theme view stylesheet and file stylesheets
Naomi Guyer's avatar
Naomi Guyer committed
121
$stylesheets = array();
122
foreach (array_reverse($THEME->get_url('style/style.css', true, 'artefact/file')) as $sheet) {
123
    $stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number($sheet) . '">';
124
}
Naomi Guyer's avatar
Naomi Guyer committed
125

126
127
128
129
130
$issiteview = $view->get('institution') == 'mahara';
$issitetemplate = ($view->get('template') == View::SITE_TEMPLATE ? true : false);
$canedittitle = $view->can_edit_title();
$canuseskins = !$issitetemplate && can_use_skins(null, false, $issiteview);

131
$stylesheets = array_merge($stylesheets, $view->get_all_blocktype_css());
132
133
// Tell the user to change the view theme if the current one is no
// longer available to them.
134
if ($viewtheme && !isset($allowedthemes[$viewtheme])) {
135
    $smarty = smarty(array(), $stylesheets, false, $extraconfig);
136
    $smarty->assign('PAGEHEADING', get_string('choosetheme'));
137
138
139
140
141
142
143
144
145
    $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;
}

146
$javascript = array('views', 'tinymce', 'paginator', 'js/jquery/jquery-ui/js/jquery-ui.min.js',
147
                    'js/jquery/jquery-ui/js/jquery-ui.touch-punch.min.js', 'tablerenderer', 'artefact/file/js/filebrowser.js',
148
                    'lib/pieforms/static/core/pieforms.js', 'js/switchbox.js');
149
150
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
151
if (is_plugin_active('externalvideo', 'blocktype')) {
152
153
    $javascript = array_merge($javascript, array((is_https() ? 'https:' : 'http:') . '//cdn.embedly.com/widgets/platform.js'));
}
154
$inlinejs = "jQuery( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
155
156
require_once('pieforms/pieform/elements/select.php');
$inlinejs .= pieform_element_select_get_inlinejs();
157
$inlinejs .= "jQuery(window).on('pageupdated', {}, function() { dock.init(jQuery(document)); });";
158
159
// The form for adding blocks via the keyboard
$addform = pieform(array(
160
    'name' => 'newblock',
161
162
    'method' => 'post',
    'jsform' => true,
Naomi Guyer's avatar
Naomi Guyer committed
163
    'renderer' => 'div',
164
    'autofocus' => false,
165
    'class' => 'cell-radios',
166
    'elements' => array(
167
168
169
170
171
172
173
174
175
176
177
178
179
180
        'blocklegend' => array(
            'type' => 'fieldset',
            'elements' => array(
                'celltitle' => array(
                    'type' => 'markup',
                    'value'=> '<legend>' . get_string('celltitle', 'view') . '</legend>',
                ),
                'cellchooser' => array(
                    'type' => 'radio',
                    'class' => 'fullwidth',
                    'rowsize' => 2,
                    'options' => array('R1C1', 'R1C2', 'R2C1'),
                ),
            ),
181
182
183
184
185
186
187
188
        ),
        'position' => array(
            'type' => 'select',
            'title' => get_string('blockorder', 'view'),
            'options' => array('Top', 'After 1', 'After 2'),
        ),
        'submit' => array(
            'type' => 'submitcancel',
189
            'class' => 'btn-secondary',
190
            'value' => array(get_string('add'), get_string('cancel')),
191
192
193
194
        ),
    ),
));

195
196
// Build content before initialising smarty in case pieform elements define headers.
$viewcontent = $view->build_rows(true);
197

198
199
200
201
$smarty = smarty($javascript, $stylesheets, array(
    'view' => array(
        'addblock',
        'cellposition',
202
        'blockordertopcell',
203
204
205
206
207
208
        'blockorderafter',
        'moveblock',
    ),
), $extraconfig);

$smarty->assign('addform', $addform);
209
210

// The list of categories for the tabbed interface
211
$smarty->assign('category_list', $view->build_category_list($category, false));
212

213
214
215
// The list of shortcut blocks
$smarty->assign('shortcut_list', $view->build_blocktype_list('shortcut'));

216
// The list of blocktypes for the default category
217
$smarty->assign('blocktype_list', $view->build_blocktype_list($category));
218
219
220
221

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

Aaron Wells's avatar
Aaron Wells committed
222
223
// 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
224
225
226
227
// 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')) {
Aaron Wells's avatar
Aaron Wells committed
228
            // When configuring a blockinstance and the search tab is open,
229
230
231
232
233
234
235
236
237
238
239
            // 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;
    }
}

240
$viewid = $view->get('id');
241
$displaylink = $view->get_url();
242
243
$smarty->assign('edittitle', $canedittitle);
$smarty->assign('canuseskins', $canuseskins);
244
$smarty->assign('displaylink', $displaylink);
245
$smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php');
246
$smarty->assign('category', $category);
247
$smarty->assign('profile', $profile);
248
$smarty->assign('dashboard', $dashboard);
249
if (get_config('blockeditormaxwidth')) {
250
    $inlinejs .= 'config.blockeditormaxwidth = true;';
251
}
252
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
253
254
255
$viewtype = $view->get('type');
$viewtitle = $view->get('title');
$owner = $view->get('owner');
256
257
258
if ($owner &&  $viewtype == 'profile') {
    $viewtitle = get_string('usersprofile', 'mahara', display_name($view->get('owner'), null, true));
}
259
$smarty->assign('accesssuspended', View::access_override_pending(array('id' => $viewid)));
260
$smarty->assign('viewtype', $viewtype);
261
$smarty->assign('view', $view->get('id'));
262
$smarty->assign('groupid', $group);
263
264
265
if (isset($groupurl)) {
    $smarty->assign('groupurl', $groupurl);
}
266
$smarty->assign('institution', $institution);
267

268
if (get_config('userscanchooseviewthemes') && $view->is_themeable()) {
269
270
271
    $smarty->assign('viewtheme', $viewtheme);
    $smarty->assign('viewthemes', $allowedthemes);
}
272
273

$smarty->assign('viewid', $view->get('id'));
274
275
276
277
278
$collectionid = false;
if ($collection = $view->get('collection')) {
    $collectionid = $collection->get('id');
}
$smarty->assign('collectionid', $collectionid);
279

280
281
282
283
284
285
286
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
287
    $columns = $viewcontent;
288
289
    $smarty->assign('columns', $columns);
}
290
$smarty->assign('issiteview', isset($institution) && ($institution == 'mahara'));
291

292
$smarty->assign('issitetemplate', $view->is_site_template());
Naomi Guyer's avatar
Naomi Guyer committed
293
$smarty->assign('PAGEHEADING', $state);
294
295
$smarty->assign('instructions', $view->get('instructions'));
$smarty->assign('instructionscollapsed', $view->get('instructionscollapsed'));
296
$smarty->display('view/blocks.tpl');