choosetemplate.php 5.71 KB
Newer Older
Richard Mansfield's avatar
Richard Mansfield committed
1
2
3
<?php
/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
Richard Mansfield's avatar
Richard Mansfield committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * 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
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
Richard Mansfield's avatar
Richard Mansfield committed
25
26
27
28
29
30
31
32
33
 *
 */

define('INTERNAL', 1);

require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');

34
35
$owner = param_integer('owner', 0);;
$groupid = param_integer('group', null);
Richard Mansfield's avatar
Richard Mansfield committed
36
$institution = param_alphanum('institution', null);
37
38

View::set_nav($groupid, $institution);
Richard Mansfield's avatar
Richard Mansfield committed
39

40
41
42
if ($usetemplate = param_integer('usetemplate', null)) {
    // If a form has been submitted, build it now and pieforms will
    // call the submit function straight away
43
    pieform(create_view_form($groupid, $institution, $usetemplate, param_integer('copycollection', null)));
44
45
}

46
if ($groupid && !group_user_can_edit_views($groupid) || $institution && !$USER->can_edit_institution($institution)) {
Richard Mansfield's avatar
Richard Mansfield committed
47
48
49
    throw new AccessDeniedException();
}

50
51
52
53
54
55
56
57
58
59
if (!empty($groupid)) {
    $group = group_current_group();
    define('TITLE', $group->name);
}
else {
    $owner = $USER->get('id');
    define('TITLE', get_string('copyvieworcollection', 'view'));
}

define('SUBTITLE', get_string('copyvieworcollection', 'view'));
Richard Mansfield's avatar
Richard Mansfield committed
60

61
$views = new StdClass;
62
63
64
65
$views->query      = trim(param_variable('viewquery', ''));
$views->ownerquery = trim(param_variable('ownerquery', ''));
$views->offset     = param_integer('viewoffset', 0);
$views->limit      = param_integer('viewlimit', 10);
66
67
68
$views->copyableby = (object) array('group' => $groupid, 'institution' => $institution, 'owner' => null);
if ($groupid) {
    $views->group = $groupid;
69
    $helptext = get_string('choosetemplategrouppageandcollectiondescription', 'view');
70
71
72
}
else if ($institution) {
    $views->institution = $institution;
73
74
75
76
77
78
    if ($institution == 'mahara') {
        $helptext = get_string('choosetemplatesitepageandcollectiondescription', 'view');
    }
    else {
        $helptext = get_string('choosetemplateinstitutionpageandcollectiondescription', 'view');
    }
79
80
}
else {
81
    $views->copyableby->owner = $USER->get('id');
82
    $helptext = get_string('choosetemplatepageandcollectiondescription', 'view');
83
84
}
View::get_templatesearch_data($views);
Richard Mansfield's avatar
Richard Mansfield committed
85

86
$strpreview = json_encode(get_string('Preview','view'));
87
$strclose = json_encode(get_string('Close'));
88
$js = <<<EOF
89

90
templatelist = new SearchTable('templatesearch');
91

92
addLoadEvent(function() {
93

94
95
  templatelist.rewriteOther = function () {
    forEach(getElementsByTagAndClassName('a', 'grouplink', 'templatesearch'), function(i) {
96
97
98
99
      connect(i, 'onclick', function (e) {
        e.stop();
        var href = getNodeAttribute(this, 'href');
        var params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
100
        sendjsonrequest(config.wwwroot + 'group/groupinfo.json.php', params, 'POST', partial(showPreview, 'small'));
101
102
      });
    });
103
    forEach(getElementsByTagAndClassName('a', 'userlink', 'templatesearch'), function(i) {
104
105
106
107
      connect(i, 'onclick', function (e) {
        e.stop();
        var href = getNodeAttribute(this, 'href');
        var params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
108
        sendjsonrequest(config.wwwroot + 'user/userdetail.json.php', params, 'POST', partial(showPreview, 'small'));
109
110
      });
    });
111
112
    forEach(getElementsByTagAndClassName('a', 'viewlink', 'templatesearch'), function(i) {
      disconnectAll(i);
113
      setNodeAttribute(i, 'title', {$strpreview});
114
115
116
117
      connect(i, 'onclick', function (e) {
        e.stop();
        var href = getNodeAttribute(this, 'href');
        var params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
118
        sendjsonrequest('viewcontent.json.php', params, 'POST', partial(showPreview, 'big'));
119
120
      });
    });
121
122
123
124
125
126
127
128
129
130
    forEach(getElementsByTagAndClassName('a', 'collectionlink', 'templatesearch'), function(i) {
      disconnectAll(i);
      setNodeAttribute(i, 'title', {$strpreview});
      connect(i, 'onclick', function (e) {
        e.stop();
        var href = getNodeAttribute(this, 'href');
        var params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
        sendjsonrequest('../collection/viewcontent.json.php', params, 'POST', partial(showPreview, 'big'));
      });
    });
131
  };
132

133
  templatelist.rewriteOther();
134

135
136
});
EOF;
137

138
$smarty = smarty(
139
    array('js/preview.js', 'searchtable'),
140
141
142
143
    array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
    array(),
    array('stylesheets' => array('style/views.css'))
);
144
$smarty->assign('INLINEJAVASCRIPT', $js);
145
146
147
148
149
150
151
152
if (!empty($groupid)) {
    $smarty->assign('PAGESUBHEADING', SUBTITLE);
    $smarty->assign('PAGEHELPNAME', '0');
    $smarty->assign('SUBPAGEHELPNAME', '1');
}
else {
    $smarty->assign('PAGEHEADING', SUBTITLE);
}
153
$smarty->assign('helptext', $helptext);
154
$smarty->assign('views', $views);
Richard Mansfield's avatar
Richard Mansfield committed
155
$smarty->display('view/choosetemplate.tpl');