index.php 5.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
 *
 * 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
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

define('INTERNAL', 1);
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection');
31
32
33
34
define('SECTION_PAGE', 'index');

require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
35
36
37
38
require_once('collection.php');

// offset and limit for pagination
$offset = param_integer('offset', 0);
39
$limit  = param_integer('limit', 5);
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
103
104
$owner = null;
$groupid = param_integer('group', 0);
$institutionname = param_alphanum('institution', false);
$urlparams = array();
if (!empty($groupid)) {
    define('MENUITEM', 'groups/collections');
    define('GROUP', $groupid);
    $group = group_current_group();
    // Check if user can edit group collections <-> user can edit group views
    $role = group_user_access($group->id);
    $canedit = $role && group_role_can_edit_views($group, $role);
    if (!$canedit) {
        throw new GroupAccessDeniedException(get_string('cantlistgroupcollections', 'collection'));
    }

    define('SUBTITLE', get_string('groupcollections', 'collection'));
    define('TITLE', $group->name);
    $urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
    if ($institutionname == 'mahara') {
        define('ADMIN', 1);
        define('MENUITEM', 'configsite/collections');
        define('TITLE', get_string('sitecollections', 'collection'));
        // Check if user is a site admin
        $canedit = $USER->get('admin');
        if (!$canedit) {
            throw new AccessDeniedException(get_string('cantlistinstitutioncollections', 'collection'));
        }
    }
    else {
        define('INSTITUTIONALADMIN', 1);
        define('MENUITEM', 'manageinstitutions/institutioncollections');
        define('TITLE', get_string('institutioncollections', 'collection'));
        // Check if user is a institution admin
        $canedit = $USER->get('admin') || $USER->is_institutional_admin();
        if (!$canedit) {
            throw new AccessDeniedException(get_string('cantlistinstitutioncollections', 'collection'));
        }
        require_once('institution.php');
        // Get list of availlable institutions
        $s = institution_selector_for_page($institutionname, get_config('wwwroot') . 'collection/index.php');
        $institutionname = $s['institution'];
        if ($institutionname === false) {
            $smarty = smarty();
            $smarty->display('admin/users/noinstitutions.tpl');
            exit;
        }
    }
    define('SUBTITLE', '');
    $urlparams['institution'] = $institutionname;
}
else {
    define('MENUITEM', 'myportfolio/collection');
    $owner = $USER->get('id');
    define('SUBTITLE', '');
    define('TITLE', get_string('Collections', 'collection'));
}
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
    $baseurl .= '?' . http_build_query($urlparams);
}

$data = Collection::get_mycollections_data($offset, $limit, $owner, $groupid, $institutionname);
Stacey Walker's avatar
Stacey Walker committed
105
106
107
108
109
110
111
foreach ($data->data as $value) {
    $collection = new Collection($value->id);
    $views = $collection->get('views');
    if (!empty($views)) {
        $value->views = $views['views'];
    }
}
112
113
114
115

$pagination = build_pagination(array(
    'id' => 'collectionslist_pagination',
    'class' => 'center',
116
    'url' => $baseurl,
117
118
119
120
121
122
123
124
125
126
127
    'count' => $data->count,
    'limit' => $data->limit,
    'offset' => $data->offset,
    'firsttext' => '',
    'previoustext' => '',
    'nexttext' => '',
    'lasttext' => '',
    'numbersincludefirstlast' => false,
    'resultcounttextsingular' => get_string('collection', 'collection'),
    'resultcounttextplural' => get_string('collections', 'collection'),
));
128
129

$smarty = smarty(array('paginator'));
130
131
132
133
134
135
136
137
138
139
140
141
$urlparamsstr = '';
if ($urlparams) {
    $urlparamsstr = '&' . http_build_query($urlparams);
}
$smarty->assign('addonelink', get_config('wwwroot') . 'collection/edit.php?new=1' . $urlparamsstr);

if (!empty($institutionname) && ($institutionname != 'mahara')) {
    $smarty->assign('institution', $institutionname);
    $smarty->assign('institutionselector', $s['institutionselector']);
    $smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
}
$smarty->assign('urlparamsstr', $urlparamsstr);
142
143
$smarty->assign('collections', $data->data);
$smarty->assign('pagination', $pagination['html']);
144
$smarty->assign('PAGEHEADING', TITLE);
145
$smarty->assign('PAGESUBHEADING', SUBTITLE);
146
$smarty->display('collection/index.tpl');