columns.php 3.56 KB
Newer Older
1
2
3
<?php
/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * 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.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @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
28
29
30
31
 *
 */

define('INTERNAL', 1);
define('MENUITEM', 'viewlayout');
require_once(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('view.php');
32
require_once(get_config('libroot') . 'group.php');
33
define('TITLE', get_string('changemyviewlayout', 'view'));
34
35
36
37
38
39

$id = param_integer('id');
$new = param_boolean('new');
$category = param_alpha('c', '');
$view = new View($id);
$numcolumns = $view->get('numcolumns');
40
$group = $view->get('group');
41
$institution = $view->get('institution');
42
$owner = $view->get('owner');
43

44
45
46
if ($group && !group_user_can_edit_views($group)
    || $institution && !$USER->can_edit_institution($institution)
    || $owner && $owner != $USER->get('id')) {
47
48
49
50
51
52
53
54
55
56
57
58
    throw new AccessDeniedException(get_string('canteditdontown', 'view'));
}

if ($USER->get_account_preference('addremovecolumns')) {
    redirect('/view/layout.php?id=' . $id . '&c=' . $category . '&new=' . $new);
}

$columnsform = pieform(array(
    'name' => 'viewcolumns',
    'elements' => array(
        'numcolumns' => array(
            'type' => 'select',
59
            'title' => get_string('numberofcolumns', 'view'),
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
            'options' => array( 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5'),
            'defaultvalue' => $numcolumns,
        ),
        'submit' => array(
            'type' => 'submitcancel',
            'value' => array(get_string('next'), get_string('cancel')),
            'goto' => get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new
        )
    )
));

$smarty = smarty();
$smarty->assign('heading', TITLE);
$smarty->assign('form', $columnsform);
$smarty->display('view/columns.tpl');

function viewcolumns_submit(Pieform $form, $values) {
    global $view, $SESSION, $category, $new;

    $oldcolumns = $view->get('numcolumns');
    $newcolumns = $values['numcolumns'];

    if ($oldcolumns > $newcolumns) {
        for ($i = $oldcolumns; $i > $newcolumns; $i--) {
            $view->removecolumn(array('column' => $i));
        }
    }
    else if ($oldcolumns < $newcolumns) {
        for ($i = $oldcolumns; $i < $newcolumns; $i++) {
            $view->addcolumn(array('before' => $i + 1, 'returndata' => false));
        }
    }

    if ($newcolumns > 1 && $newcolumns < 5) {
        redirect(get_config('wwwroot') . 'view/layout.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new);
    }
    else {
        $SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view'));
        redirect(get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new);
    }
}

?>