Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * prints the tabbed bar
19
 *
20
 * @package mod_questionnaire
21
 * @copyright  2016 Mike Churchward (mike.churchward@poetgroup.org)
22
 * @author     Mike Churchward
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
global $DB, $SESSION;
29
$tabs = array();
30
$row = array();
31
$inactive = array();
32
$activated = array();
33
if (!isset($SESSION->questionnaire)) {
34
    $SESSION->questionnaire = new stdClass();
35
}
36
$currenttab = $SESSION->questionnaire->current_tab;
37
 
38
// In a questionnaire instance created "using" a PUBLIC questionnaire, prevent anyone from editing settings, editing questions,
39
// viewing all responses...except in the course where that PUBLIC questionnaire was originally created.
40
 
41
$owner = $questionnaire->is_survey_owner();
42
if ($questionnaire->capabilities->manage  && $owner) {
43
    $row[] = new tabobject('settings', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/qsettings.php?'.
44
            'id='.$questionnaire->cm->id), get_string('advancedsettings'));
45
}
46
 
47
if ($questionnaire->capabilities->editquestions && $owner) {
48
    $row[] = new tabobject('questions', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/questions.php?'.
49
            'id='.$questionnaire->cm->id), get_string('questions', 'questionnaire'));
50
}
51
 
52
if ($questionnaire->capabilities->editquestions && $owner) {
53
    $row[] = new tabobject('feedback', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/feedback.php?'.
54
            'id='.$questionnaire->cm->id), get_string('feedback'));
55
}
56
 
57
if ($questionnaire->capabilities->preview && $owner) {
58
    if (!empty($questionnaire->questions)) {
59
        $row[] = new tabobject('preview', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/preview.php?'.
60
                        'id='.$questionnaire->cm->id), get_string('preview_label', 'questionnaire'));
61
    }
62
}
63
 
64
$usernumresp = $questionnaire->count_submissions($USER->id);
65
 
66
if ($questionnaire->capabilities->readownresponses && ($usernumresp > 0)) {
67
    $argstr = 'instance='.$questionnaire->id.'&user='.$USER->id.'&group='.$currentgroupid;
68
    if ($usernumresp == 1) {
69
        $argstr .= '&byresponse=1&action=vresp';
70
        $yourrespstring = get_string('yourresponse', 'questionnaire');
71
    } else {
72
        $yourrespstring = get_string('yourresponses', 'questionnaire');
73
    }
74
    $row[] = new tabobject('myreport', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/myreport.php?'.
75
                           $argstr), $yourrespstring);
76
 
77
    if ($usernumresp > 1 && in_array($currenttab, array('mysummary', 'mybyresponse', 'myvall', 'mydownloadcsv'))) {
78
        $inactive[] = 'myreport';
79
        $activated[] = 'myreport';
80
        $row2 = array();
81
        $argstr2 = $argstr.'&action=summary';
82
        $row2[] = new tabobject('mysummary', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/myreport.php?'.$argstr2),
83
                                get_string('summary', 'questionnaire'));
84
        $argstr2 = $argstr.'&byresponse=1&action=vresp';
85
        $row2[] = new tabobject('mybyresponse', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/myreport.php?'.$argstr2),
86
                                get_string('viewindividualresponse', 'questionnaire'));
87
        $argstr2 = $argstr.'&byresponse=0&action=vall&group='.$currentgroupid;
88
        $row2[] = new tabobject('myvall', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/myreport.php?'.$argstr2),
89
                                get_string('myresponses', 'questionnaire'));
90
        if ($questionnaire->capabilities->downloadresponses) {
91
            $argstr2 = $argstr.'&action=dwnpg';
92
            $link = $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2);
93
            $row2[] = new tabobject('mydownloadcsv', $link, get_string('downloadtextformat', 'questionnaire'));
94
        }
95
    } else if (in_array($currenttab, array('mybyresponse', 'mysummary'))) {
96
        $inactive[] = 'myreport';
97
        $activated[] = 'myreport';
98
    }
99
}
100
 
101
$numresp = $questionnaire->count_submissions();
102
// Number of responses in currently selected group (or all participants etc.).
103
if (isset($SESSION->questionnaire->numselectedresps)) {
104
    $numselectedresps = $SESSION->questionnaire->numselectedresps;
105
} else {
106
    $numselectedresps = $numresp;
107
}
108
 
109
// If questionnaire is set to separate groups, prevent user who is not member of any group
110
// to view All responses.
111
$canviewgroups = true;
112
$groupmode = groups_get_activity_groupmode($cm, $course);
113
if ($groupmode == 1) {
114
    $canviewgroups = groups_has_membership($cm, $USER->id);
115
}
116
$canviewallgroups = has_capability('moodle/site:accessallgroups', $context);
117
$grouplogic = $canviewallgroups || $canviewgroups;
118
$resplogic = ($numresp > 0) && ($numselectedresps > 0);
119
 
120
if ($questionnaire->can_view_all_responses_anytime($grouplogic, $resplogic)) {
121
    $argstr = 'instance='.$questionnaire->id;
122
    $row[] = new tabobject('allreport', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.
123
                           $argstr.'&action=vall'), get_string('viewallresponses', 'questionnaire'));
124
    if (in_array($currenttab, array('vall', 'vresp', 'valldefault', 'vallasort', 'vallarsort', 'deleteall', 'downloadcsv',
125
                                     'vrespsummary', 'individualresp', 'printresp', 'deleteresp'))) {
126
        $inactive[] = 'allreport';
127
        $activated[] = 'allreport';
128
        if ($currenttab == 'vrespsummary' || $currenttab == 'valldefault') {
129
            $inactive[] = 'vresp';
130
        }
131
        $row2 = array();
132
        $argstr2 = $argstr.'&action=vall&group='.$currentgroupid;
133
        $row2[] = new tabobject('vall', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
134
                                get_string('summary', 'questionnaire'));
135
        if ($questionnaire->capabilities->viewsingleresponse) {
136
            $argstr2 = $argstr.'&byresponse=1&action=vresp&group='.$currentgroupid;
137
            $row2[] = new tabobject('vrespsummary', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
138
                                get_string('viewbyresponse', 'questionnaire'));
139
            if ($currenttab == 'individualresp' || $currenttab == 'deleteresp') {
140
                $argstr2 = $argstr.'&byresponse=1&action=vresp';
141
                $row2[] = new tabobject('vresp', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
142
                        get_string('viewindividualresponse', 'questionnaire'));
143
            }
144
        }
145
    }
146
    if (in_array($currenttab, array('valldefault',  'vallasort', 'vallarsort', 'deleteall', 'downloadcsv'))) {
147
        $activated[] = 'vall';
148
        $row3 = array();
149
 
150
        $argstr2 = $argstr.'&action=vall&group='.$currentgroupid;
151
        $row3[] = new tabobject('valldefault', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
152
                                get_string('order_default', 'questionnaire'));
153
        if ($currenttab != 'downloadcsv' && $currenttab != 'deleteall') {
154
            $argstr2 = $argstr.'&action=vallasort&group='.$currentgroupid;
155
            $row3[] = new tabobject('vallasort', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
156
                                    get_string('order_ascending', 'questionnaire'));
157
            $argstr2 = $argstr.'&action=vallarsort&group='.$currentgroupid;
158
            $row3[] = new tabobject('vallarsort', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
159
                                    get_string('order_descending', 'questionnaire'));
160
        }
161
        if ($questionnaire->capabilities->deleteresponses) {
162
            $argstr2 = $argstr.'&action=delallresp&group='.$currentgroupid;
163
            $row3[] = new tabobject('deleteall', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
164
                                    get_string('deleteallresponses', 'questionnaire'));
165
        }
166
 
167
        if ($questionnaire->capabilities->downloadresponses) {
168
            $argstr2 = $argstr.'&action=dwnpg&group='.$currentgroupid;
169
            $link = $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2);
170
            $row3[] = new tabobject('downloadcsv', $link, get_string('downloadtextformat', 'questionnaire'));
171
        }
172
    }
173
 
174
    if (in_array($currenttab, array('individualresp', 'deleteresp'))) {
175
        $inactive[] = 'vresp';
176
        if ($currenttab != 'deleteresp') {
177
            $activated[] = 'vresp';
178
        }
179
        if ($questionnaire->capabilities->deleteresponses) {
180
            $argstr2 = $argstr.'&action=dresp&rid='.$rid.'&individualresponse=1';
181
            $row2[] = new tabobject('deleteresp', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
182
                            get_string('deleteresp', 'questionnaire'));
183
        }
184
 
185
    }
186
} else if ($questionnaire->can_view_all_responses_with_restrictions($usernumresp, $grouplogic, $resplogic)) {
187
    $argstr = 'instance='.$questionnaire->id.'&sid='.$questionnaire->sid;
188
    $row[] = new tabobject('allreport', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.
189
                           $argstr.'&action=vall&group='.$currentgroupid), get_string('viewallresponses', 'questionnaire'));
190
    if (in_array($currenttab, array('valldefault',  'vallasort', 'vallarsort', 'deleteall', 'downloadcsv'))) {
191
        $inactive[] = 'vall';
192
        $activated[] = 'vall';
193
        $row2 = array();
194
        $argstr2 = $argstr.'&action=vall&group='.$currentgroupid;
195
        $row2[] = new tabobject('valldefault', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
196
                                get_string('summary', 'questionnaire'));
197
        $inactive[] = $currenttab;
198
        $activated[] = $currenttab;
199
        $row3 = array();
200
        $argstr2 = $argstr.'&action=vall&group='.$currentgroupid;
201
        $row3[] = new tabobject('valldefault', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
202
                                get_string('order_default', 'questionnaire'));
203
        $argstr2 = $argstr.'&action=vallasort&group='.$currentgroupid;
204
        $row3[] = new tabobject('vallasort', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
205
                                get_string('order_ascending', 'questionnaire'));
206
        $argstr2 = $argstr.'&action=vallarsort&group='.$currentgroupid;
207
        $row3[] = new tabobject('vallarsort', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
208
                                get_string('order_descending', 'questionnaire'));
209
        if ($questionnaire->capabilities->deleteresponses) {
210
            $argstr2 = $argstr.'&action=delallresp';
211
            $row2[] = new tabobject('deleteall', $CFG->wwwroot.htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2),
212
                                    get_string('deleteallresponses', 'questionnaire'));
213
        }
214
 
215
        if ($questionnaire->capabilities->downloadresponses) {
216
            $argstr2 = $argstr.'&action=dwnpg';
217
            $link = htmlspecialchars('/mod/questionnaire/report.php?'.$argstr2);
218
            $row2[] = new tabobject('downloadcsv', $link, get_string('downloadtextformat', 'questionnaire'));
219
        }
220
        if (count($row2) <= 1) {
221
            $currenttab = 'allreport';
222
        }
223
    }
224
}
225
 
226
if ($questionnaire->capabilities->viewsingleresponse && ($canviewallgroups || $canviewgroups)) {
227
    $nonrespondenturl = new moodle_url('/mod/questionnaire/show_nonrespondents.php', array('id' => $questionnaire->cm->id));
228
    $row[] = new tabobject('nonrespondents',
229
                    $nonrespondenturl->out(),
230
                    get_string('show_nonrespondents', 'questionnaire'));
231
}
232
 
233
if ((count($row) > 1) || (!empty($row2) && (count($row2) > 1))) {
234
    $tabs[] = $row;
235
 
236
    if (!empty($row2) && (count($row2) > 1)) {
237
        $tabs[] = $row2;
238
    }
239
 
240
    if (!empty($row3) && (count($row3) > 1)) {
241
        $tabs[] = $row3;
242
    }
243
 
244
    $questionnaire->page->add_to_page('tabsarea', print_tabs($tabs, $currenttab, $inactive, $activated, true));
245
}