blocks.php 4.54 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * 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.
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * 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.
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
 *
 * @package    mahara
 * @subpackage core
21
 * @author     Catalyst IT Ltd
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
24
25
26
27
 *
 */

define('INTERNAL', 1);
28
define('MENUITEM', 'myportfolio/views');
29
30
31
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'blocks');
32
33
require(dirname(dirname(__FILE__)) . '/init.php');
require('view.php');
34
require_once(get_config('docroot') . 'lib/group.php');
35
36

$view = new View(param_integer('id'));
37
$group = $view->get('group');
38
$institution = $view->get('institution');
39

40
41
42
43
44
45
// If the view has been submitted to a group, disallow editing
$submittedto = $view->get('submittedto');
if ($submittedto) {
    throw new AccessDeniedException(get_string('canteditsubmitted', 'view', get_field('group', 'name', 'id', $submittedto)));
}

46
$new = param_boolean('new');
47

48
49
50
51
52
53
54
if ($new) {
    define('TITLE', get_string('createviewsteptwo', 'view'));
}
else {
    define('TITLE', get_string('editblocksforview', 'view', $view->get('title')));
}

55
56
if ($group && !group_user_can_edit_views($group)
    || $institution && !$USER->can_edit_institution($institution)) {
57
58
59
    throw new AccessDeniedException();
}

60
61
62
// check if cancel was selected
if ($new && isset($_POST['cancel'])) {
    $view->delete();
63
64
65
    if ($group) {
        redirect(get_config('wwwroot') . '/view/groupviews.php?group='.$group);
    }
66
67
68
    if ($group) {
        redirect(get_config('wwwroot') . '/view/institutionviews.php?institution='.$institution);
    }
69
70
71
    redirect(get_config('wwwroot') . '/view/');
}

72
73
74
75
76
$category = param_alpha('c', '');
// Make the default category the first tab if none is set
if ($category === '') {
    $category = get_field_sql('SELECT "name" FROM {blocktype_category} ORDER BY "name" LIMIT 1');
}
77
78
79
80
81
82
83

$view->process_changes($category, $new);
$columns = $view->build_columns(true);

$extraconfig = array(
    'stylesheets' => array('style/views.css'),
);
84
$smarty = smarty(array('views', 'tinytinymce', 'paginator', 'tablerenderer'), array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'), false, $extraconfig);
85
86
87
88
89
90
91
92
93
94
95
96
97
98


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

// The list of blocktypes for the default category
$smarty->assign('blocktype_list', View::build_blocktype_list($category));

// The HTML for the columns in the view
$smarty->assign('columns', $columns);

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

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// 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;
    }
}

117
$smarty->assign('heading', TITLE);
118
$smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php');
119
$smarty->assign('category', $category);
120
121
$smarty->assign('new', $new);
$smarty->assign('view', $view->get('id'));
122
123
$smarty->assign('groupid', $group);
$smarty->assign('institution', $institution);
124
$smarty->assign('can_change_layout', (!$USER->get_account_preference('addremovecolumns') || ($view->get('numcolumns') > 1 && $view->get('numcolumns') < 5)));
125
126
127
$smarty->display('view/blocks.tpl');

?>