-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheditstep.php
162 lines (137 loc) · 5.98 KB
/
editstep.php
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
<?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/>.
/**
* Script to create or update an existing step
*
* @package block_workflow
* @copyright 2011 Lancaster University Network Services Limited
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once(dirname(__FILE__) . '/editstep_form.php');
require_once($CFG->libdir . '/adminlib.php');
// Get the submitted paramaters.
$stepid = optional_param('stepid', 0, PARAM_INT);
// This is an admin page.
admin_externalpage_setup('blocksettingworkflow');
// Require login.
require_login();
// Require the workflow:editdefinitions capability.
require_capability('block/workflow:editdefinitions', context_system::instance());
if ($stepid) {
// If we've been given an existing workflow.
$step = new block_workflow_step($stepid);
$returnurl = new moodle_url('/blocks/workflow/editsteps.php', array('workflowid' => $step->workflowid));
$todos = $step->todos(false);
$doers = $step->roles();
$roles = block_workflow_contextlevel_roles($step->workflow()->context());
$title = get_string('editstepname', 'block_workflow', $step->name);
$PAGE->set_url('/blocks/workflow/editstep.php', array('stepid' => $stepid));
// Add the breadcrumbs.
$PAGE->navbar->add($step->workflow()->name, $returnurl);
$PAGE->navbar->add(get_string('editstep', 'block_workflow'));
$appliesto = $DB->get_field('block_workflow_workflows', 'appliesto', array('id' => $step->workflowid));
} else {
// We're creating a new step.
$workflowid = required_param('workflowid', PARAM_INT);
$workflow = new block_workflow_workflow($workflowid);
$returnurl = new moodle_url('/blocks/workflow/editsteps.php', array('workflowid' => $workflowid));
$title = get_string('createstepname', 'block_workflow', $workflow->name);
$beforeafter = optional_param('beforeafter', 0, PARAM_INT);
$PAGE->set_url('/blocks/workflow/editstep.php', array('workflowid' => $workflowid));
// Add the breadcrumbs.
$PAGE->navbar->add($workflow->name, $returnurl);
$PAGE->navbar->add(get_string('createstep', 'block_workflow'));
$appliesto = $workflow->appliesto;
}
// Set various page settings.
$PAGE->set_title($title);
$PAGE->set_heading($title);
// Moodle form to create/edit step.
$stepedit = new step_edit('editstep.php', array('appliesto' => $appliesto));
if ($stepedit->is_cancelled()) {
// Form was cancelled.
redirect($returnurl);
} else if ($data = $stepedit->get_data()) {
// Form has been submitted.
$formdata = new stdClass();
$formdata->id = $data->stepid;
$formdata->name = $data->name;
$formdata->instructions = $data->instructions_editor['text'];
$formdata->instructionsformat = $data->instructions_editor['format'];
$formdata->onactivescript = $data->onactivescript;
$formdata->oncompletescript = $data->oncompletescript;
$formdata->autofinish = isset($data->autofinish) ? $data->autofinish : '';
$formdata->autofinishoffset = $data->autofinishoffset;
$formdata->extranotify = isset($data->extranotify) ? $data->extranotify : '';
$formdata->extranotifyoffset = $data->extranotifyoffset;
$formdata->onextranotifyscript = $data->onextranotifyscript;
if (isset($step)) {
// We're editing an existing step.
$step->update_step($formdata);
} else {
// Creating a new step.
$step = new block_workflow_step();
$formdata->workflowid = $data->workflowid;
$step->create_step($formdata, $data->beforeafter);
}
// Redirect to the editsteps.php page.
redirect($returnurl);
}
$data = new stdClass();
if (isset($beforeafter)) {
// If we're creating the step in a specific location.
$data->beforeafter = $beforeafter;
}
if (isset($step)) {
// Retrieve the current step data for the form.
$data->stepid = $step->id;
$data->name = $step->name;
$data->instructions = $step->instructions;
$data->instructionsformat = $step->instructionsformat;
$data->onactivescript = $step->onactivescript;
$data->oncompletescript = $step->oncompletescript;
$data->autofinish = $step->autofinish;
$data->autofinishoffset = $step->autofinishoffset;
$data->extranotify = $step->extranotify;
$data->extranotifyoffset = $step->extranotifyoffset;
$data->onextranotifyscript = $step->onextranotifyscript;
$data = file_prepare_standard_editor($data, 'instructions', array('noclean' => true));
$stepedit->set_data($data);
} else {
// Otherwise, this is a new step belonging to $workflowid.
$data->workflowid = $workflow->id;
$stepedit->set_data($data);
}
// Grab the renderer.
$renderer = $PAGE->get_renderer('block_workflow');
// Display the page.
echo $OUTPUT->header();
if (isset($step)) {
echo $renderer->edit_step_instructions($step);
} else {
echo $renderer->create_step_instructions($workflow);
}
// The edit step form.
$stepedit->display();
if (isset($step)) {
// The list of to-do actions.
echo $renderer->step_todolist($todos, $step);
// The list of actors (doers).
echo $renderer->step_doers($roles, $doers, $stepid);
}
echo $OUTPUT->footer();