access.php 8.44 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
28
29
30
31
32
33
34
 *
 */

define('INTERNAL', 1);
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'editaccess');

require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('pieforms/pieform/elements/calendar.php');
35
36
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
37
38

$view = new View(param_integer('id'));
39
$group = $view->get('group');
40
$institution = $view->get('institution');
41
View::set_nav($group, $institution);
42
43
$new = param_boolean('new');

44
45
46
47
48
49
50
if ($new) {
    define('TITLE', get_string('createviewstepthree', 'view'));
}
else {
    define('TITLE', get_string('editaccessforview', 'view', $view->get('title')));
}

51
if (!$USER->can_edit_view($view)) {
52
53
54
    throw new AccessDeniedException();
}

55
56
$smarty = smarty(array('tablerenderer'), pieform_element_calendar_get_headdata(pieform_element_calendar_configure(array())), array('mahara' => array('From', 'To')));

57
58
$artefacts = $view->get_artefact_metadata();
if (empty($artefacts)) {
59
    $confirmmessage = get_string('reallyaddaccesstoemptyview', 'view');
60
61
62
63
64
65
66
67
68
69
70
71
72
    $js = <<<EOF
addLoadEvent(function() {
    connect('editaccess_submit', 'onclick', function () {
        var accesslistrows = getElementsByTagAndClassName('tr', null, 'accesslistitems');
        if (accesslistrows.length > 0 && !confirm('{$confirmmessage}')) {
            replaceChildNodes('accesslistitems', []);
        }
    });
});
EOF;
    $smarty->assign('INLINEJAVASCRIPT', $js);
}

73
// @todo need a rule here that prevents stopdate being smaller than startdate
74
75
$form = array(
    'name' => 'editaccess',
76
    'renderer' => 'div',
77
78
    'plugintype' => 'core',
    'pluginname' => 'view',
79
80
81
82
83
84
85
86
87
    'elements' => array(
        'id' => array(
            'type' => 'hidden',
            'value' => $view->get('id'),
        ),
        'new' => array(
            'type' => 'hidden',
            'value' => $new,
        ),
88
89
        'template' => array(
            'type'         => 'checkbox',
90
            'title'        => get_string('allowcopying', 'view'),
91
92
93
            'description'  => get_string('templatedescription', 'view'),
            'defaultvalue' => $view->get('template'),
        ),
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    )
);

if ($institution) {
    if ($institution == 'mahara') {
        $form['elements']['copynewuser'] = array(
            'type'         => 'checkbox',
            'title'        => get_string('copyfornewusers', 'view'),
            'description'  => get_string('copyfornewusersdescription', 'view'),
            'defaultvalue' => $view->get('copynewuser'),
        );
        $form['elements']['copyfornewgroups'] = array(
            'type'         => 'html',
            'value'        => '<label>' . get_string('copyfornewgroups', 'view') . '</label>',
        );
        $form['elements']['copyfornewgroupsdescription'] = array(
            'type'         => 'html',
            'value'        => '<div class="description">' . get_string('copyfornewgroupsdescription', 'view') . '</div>',
        );
        $createfor = $view->get_autocreate_grouptypes();
        foreach (group_get_grouptypes() as $grouptype) {
            safe_require('grouptype', $grouptype);
            $form['elements']['copyfornewgroups_'.$grouptype] = array(
                'type'         => 'checkbox',
                'title'        => get_string('name', 'grouptype.' . $grouptype),
                'defaultvalue' => in_array($grouptype, $createfor),
            );
        }
    }
    else {
        $form['elements']['copynewuser'] = array(
            'type'         => 'checkbox',
            'title'        => get_string('copyfornewmembers', 'view'),
            'description'  => get_string('copyfornewmembersdescription', 'view', get_field('institution', 'displayname', 'name', $institution)),
            'defaultvalue' => $view->get('copynewuser'),
        );
    }
}

$form['elements']['accesslist'] = array(
    'type'         => 'viewacl',
    'defaultvalue' => isset($view) ? $view->get_access() : null
);

$form['elements']['overrides'] = array(
    'type' => 'fieldset',
    'legend' => get_string('overridingstartstopdate', 'view'),
    'elements' => array(
        'description' => array(
            'type' => 'html',
            'value' => get_string('overridingstartstopdatesdescription', 'view'),
145
        ),
146
147
148
149
150
151
152
        'startdate'        => array(
            'type'         => 'calendar',
            'title'        => get_string('startdate','view'),
            'defaultvalue' => isset($view) ? strtotime($view->get('startdate')) : null,
            'caloptions'   => array(
                'showsTime'      => true,
                'ifFormat'       => '%Y/%m/%d %H:%M'
153
            ),
154
            'help'         => true,
155
        ),
156
157
158
159
160
161
162
163
164
        'stopdate'  => array(
            'type'         => 'calendar',
            'title'        => get_string('stopdate','view'),
            'defaultvalue' => isset($view) ? strtotime($view->get('stopdate')) : null,
            'caloptions'   => array(
                'showsTime'      => true,
                'ifFormat'       => '%Y/%m/%d %H:%M'
            ),
            'help'         => true,
165
        ),
166
167
168
169
170
171
172
173
174
    ),
);

$form['elements']['submit'] = array(
    'type'  => !empty($new) ? 'cancelbackcreate' : 'submitcancel',
    'value' => !empty($new) 
        ? array(get_string('cancel'), get_string('back','view'), get_string('save'))
        : array(get_string('save'), get_string('cancel')),
    'confirm' => !empty($new) ? array(get_string('confirmcancelcreatingview', 'view'), null, null) : null,
175
176
);

177
178
179
180
181
182
function editaccess_validate(Pieform $form, $values) {
    if ($values['startdate'] && $values['stopdate'] && $values['startdate'] > $values['stopdate']) {
        $form->set_error('startdate', get_string('startdatemustbebeforestopdate', 'view'));
    }
}

183
function editaccess_cancel_submit() {
184
185
186
187
188
189
190
191
    global $view, $new, $group, $institution;
    if ($new) {
        $view->delete();
    }
    if ($group) {
        redirect('/view/groupviews.php?group='.$group);
    }
    if ($institution) {
192
        redirect('/view/institutionviews.php?institution='.$institution);
193
    }
194
    redirect('/view');
195
196
197
198
}


function editaccess_submit(Pieform $form, $values) {
199
    global $SESSION, $view, $new, $group, $institution;
200
201
202
203
204
205

    if (param_boolean('back')) {
        redirect('/view/blocks.php?id=' . $view->get('id') . '&new=' . $new);
    }

    $view->set_access($values['accesslist']);
206
207
208

    $view->set('startdate', $values['startdate']);
    $view->set('stopdate', $values['stopdate']);
209
    $view->set('template', (int) $values['template']);
210
211
212
    if (isset($values['copynewuser'])) {
        $view->set('copynewuser', (int) $values['copynewuser']);
    }
213
214
215
216
217
218
219
220
221
222
    if ($institution == 'mahara') {
        $createfor = array();
        foreach (group_get_grouptypes() as $grouptype) {
            if ($values['copyfornewgroups_'.$grouptype]) {
                $createfor[] = $grouptype;
            }
        }
        $view->set('copynewgroups', $createfor);
    }

223
224
    $view->commit();

225
226
227
228
229
230
231
    if ($values['new']) {
        $str = get_string('viewcreatedsuccessfully', 'view');
    }
    else {
        $str = get_string('viewaccesseditedsuccessfully', 'view');
    }
    $SESSION->add_ok_msg($str);
232
233
234
    if ($group) {
        redirect('/view/groupviews.php?group='.$group);
    }
235
    if ($institution) {
236
        redirect('/view/institutionviews.php?institution='.$institution);
237
    }
238
    redirect('/view/');
239

240
241
242
}


243
$smarty->assign('pagetitle', TITLE);
244
$smarty->assign('heading', TITLE);
245
246
247
248
$smarty->assign('form', pieform($form));
$smarty->display('view/access.tpl');

?>