forked from itamart/moodle-mod_dataform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.php
More file actions
182 lines (154 loc) · 7.42 KB
/
Copy pathimport.php
File metadata and controls
182 lines (154 loc) · 7.42 KB
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
31
32
33
34
35
36
37
38
39
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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
// This file is part of Moodle - http://moodle.org/.
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod
* @subpackage dataform
* @copyright 2011 Itamar Tzadok
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('mod_class.php');
$urlparams = new object();
$urlparams->d = optional_param('d', 0, PARAM_INT); // dataform id
$urlparams->id = optional_param('id', 0, PARAM_INT); // module id
$urlparams->vid = optional_param('vid', 0, PARAM_INT); // view id
$urlparams->vedit = optional_param('vedit', 0, PARAM_INT); // view id to edit
$urlparams->import = optional_param('import', 0, PARAM_INT); // import
// views list actions
$urlparams->reset = optional_param('reset', 0, PARAM_SEQUENCE); // ids (comma delimited) of views to delete
$urlparams->delete = optional_param('delete', 0, PARAM_SEQUENCE); // ids (comma delimited) of views to delete
$urlparams->duplicate = optional_param('duplicate', 0, PARAM_SEQUENCE); // ids (comma delimited) of views to duplicate
$urlparams->confirmed = optional_param('confirmed', 0, PARAM_INT);
// Set a dataform object
$df = new dataform($urlparams->d, $urlparams->id);
// require capability
if (!has_capability('mod/dataform:manageentries', $df->context)
or !has_capability('mod/dataform:managetemplates', $df->context)) {
throw new required_capability_exception($df->context, 'mod/dataform:manageentries', 'nopermissions', '');
}
$df->set_page('import', array('modjs' => true, 'urlparams' => $urlparams));
// activate navigation node
navigation_node::override_active_url(new moodle_url('/mod/dataform/import.php', array('id' => $df->cm->id)));
// DATA PROCESSING
// import
if ($urlparams->vid and confirm_sesskey()) {
$view = $df->get_view_from_id($urlparams->vid);
// process import
if ($urlparams->import and confirm_sesskey()) {
if ($view->process_data()) {
redirect(new moodle_url('/mod/dataform/view.php', array('d' => $urlparams->d)));
} else {
// proceed to display list of import views
}
// or display form
} else {
// print header
$df->print_header(array('tab' => 'import', 'urlparams' => $urlparams));
$mform = $view->get_import_form();
$mform->set_data(null);
$mform->display();
$df->print_footer();
die;
}
}
// view actions
if ($urlparams->duplicate and confirm_sesskey()) { // Duplicate any requested views
$df->process_views('duplicate', $urlparams->duplicate, true);
} else if ($urlparams->reset and confirm_sesskey()) { // Reset to default any requested views
$df->process_views('reset', $urlparams->reset, true);
} else if ($urlparams->delete and confirm_sesskey()) { // Delete any requested views
$df->process_views('delete', $urlparams->delete, true);
}
// any notifications?
$df->notifications['bad']['defaultview'] = '';
$df->notifications['bad']['getstartedviews'] = '';
if (!$views = $df->get_views_by_type('import', false, true)) {
$df->notifications['bad'][] = get_string('importnoneindataform','dataform'); // nothing in database
}
// print header
$df->print_header(array('tab' => 'import', 'urlparams' => $urlparams));
// print add import link
$addimporturl = new moodle_url('/mod/dataform/view/view_edit.php',
array('d' => $df->id(), 'type' => 'import', 'sesskey' => sesskey()));
$addimportlink = html_writer::link($addimporturl, get_string('importadd','dataform'));
$br = html_writer::empty_tag('br');
echo html_writer::tag('div', $addimportlink. $br. $br, array('class'=>'mdl-align'));
// if there are import views print admin style list of them
if ($views) {
$viewbaseurl = '/mod/dataform/import.php';
$editbaseurl = '/mod/dataform/view/view_edit.php';
$actionbaseurl = '/mod/dataform/import.php';
$linkparams = array('d' => $df->id(), 'sesskey' => sesskey());
// table headings
$strviews = get_string('views', 'dataform');
$strdescription = get_string('description');
$stredit = get_string('edit');
$strdelete = get_string('delete');
$strreset = get_string('reset');
$strduplicate = get_string('duplicate');
$selectallnone = html_writer::checkbox(null, null, false, null, array('onclick' => 'select_allnone(\'view\',this.checked)'));
$multidelete = html_writer::tag('button',
$OUTPUT->pix_icon('t/delete', get_string('multidelete', 'dataform')),
array('name' => 'multidelete',
'onclick' => 'bulk_action(\'view\', \''. htmlspecialchars_decode(new moodle_url($actionbaseurl, $linkparams)). '\', \'delete\')'));
$table = new html_table();
$table->head = array($strviews,
$strdescription,
$stredit,
$strduplicate,
$strreset,
$multidelete,
$selectallnone);
$table->align = array('left',
'left',
'center',
'center',
'center',
'center',
'center');
$table->wrap = array(false,
false,
false,
false,
false,
false,
false);
$table->attributes['align'] = 'center';
foreach ($views as $viewid => $view) {
$viewname = html_writer::link(new moodle_url($viewbaseurl, $linkparams + array('vid' => $viewid)), $view->name());
$viewdescription = shorten_text($view->view->description, 30);
$viewedit = html_writer::link(new moodle_url($editbaseurl, $linkparams + array('vedit' => $viewid)),
$OUTPUT->pix_icon('t/edit', $stredit));
$viewduplicate = html_writer::link(new moodle_url($actionbaseurl, $linkparams + array('duplicate' => $viewid)),
$OUTPUT->pix_icon('t/copy', $strduplicate));
$viewreset = html_writer::link(new moodle_url($actionbaseurl, $linkparams + array('reset' => $viewid)),
$OUTPUT->pix_icon('t/reload', $strreset));
$viewdelete = html_writer::link(new moodle_url($actionbaseurl, $linkparams + array('delete' => $viewid)),
$OUTPUT->pix_icon('t/delete', $strdelete));
$viewselector = html_writer::checkbox('viewselector', $viewid, false);
$table->data[] = array(
$viewname,
$viewdescription,
$viewedit,
$viewduplicate,
$viewreset,
$viewdelete,
$viewselector
);
}
echo html_writer::table($table);
}
$df->print_footer();