1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the customcert module for 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 |
* Handles position elements on the PDF via drag and drop.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_customcert
|
|
|
21 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once('../../config.php');
|
|
|
26 |
|
|
|
27 |
// The page of the customcert we are editing.
|
|
|
28 |
$pid = required_param('pid', PARAM_INT);
|
|
|
29 |
|
|
|
30 |
$page = $DB->get_record('customcert_pages', ['id' => $pid], '*', MUST_EXIST);
|
|
|
31 |
$template = $DB->get_record('customcert_templates', ['id' => $page->templateid], '*', MUST_EXIST);
|
|
|
32 |
$elements = $DB->get_records('customcert_elements', ['pageid' => $pid], 'sequence');
|
|
|
33 |
|
|
|
34 |
// Set the template.
|
|
|
35 |
$template = new \mod_customcert\template($template);
|
|
|
36 |
// Perform checks.
|
|
|
37 |
if ($cm = $template->get_cm()) {
|
|
|
38 |
require_login($cm->course, false, $cm);
|
|
|
39 |
} else {
|
|
|
40 |
require_login();
|
|
|
41 |
}
|
|
|
42 |
// Make sure the user has the required capabilities.
|
|
|
43 |
$template->require_manage();
|
|
|
44 |
|
|
|
45 |
if ($template->get_context()->contextlevel == CONTEXT_MODULE) {
|
|
|
46 |
$customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
|
|
47 |
$title = $customcert->name;
|
|
|
48 |
$heading = format_string($title);
|
|
|
49 |
} else {
|
|
|
50 |
$title = $SITE->fullname;
|
|
|
51 |
$heading = $title;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
// Set the $PAGE settings.
|
|
|
55 |
$pageurl = new moodle_url('/mod/customcert/rearrange.php', ['pid' => $pid]);
|
|
|
56 |
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title);
|
|
|
57 |
$PAGE->activityheader->set_attrs(['hidecompletion' => true,
|
|
|
58 |
'description' => '']);
|
|
|
59 |
|
|
|
60 |
// Add more links to the navigation.
|
|
|
61 |
if (!$cm = $template->get_cm()) {
|
|
|
62 |
$str = get_string('managetemplates', 'customcert');
|
|
|
63 |
$link = new moodle_url('/mod/customcert/manage_templates.php');
|
|
|
64 |
$PAGE->navbar->add($str, new \action_link($link, $str));
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
$str = get_string('editcustomcert', 'customcert');
|
|
|
68 |
$link = new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]);
|
|
|
69 |
$PAGE->navbar->add($str, new \action_link($link, $str));
|
|
|
70 |
|
|
|
71 |
$PAGE->navbar->add(get_string('rearrangeelements', 'customcert'));
|
|
|
72 |
|
|
|
73 |
// Include the JS we need.
|
|
|
74 |
$PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'Y.M.mod_customcert.rearrange.init',
|
|
|
75 |
[$template->get_id(),
|
|
|
76 |
$page,
|
|
|
77 |
$elements]);
|
|
|
78 |
|
|
|
79 |
// Create the buttons to save the position of the elements.
|
|
|
80 |
$html = html_writer::start_tag('div', ['class' => 'buttons']);
|
|
|
81 |
$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]),
|
|
|
82 |
get_string('saveandclose', 'customcert'), 'get', ['class' => 'savepositionsbtn']);
|
|
|
83 |
$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/rearrange.php', ['pid' => $pid]),
|
|
|
84 |
get_string('saveandcontinue', 'customcert'), 'get', ['class' => 'applypositionsbtn']);
|
|
|
85 |
$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]),
|
|
|
86 |
get_string('cancel'), 'get', ['class' => 'cancelbtn']);
|
|
|
87 |
$html .= html_writer::end_tag('div');
|
|
|
88 |
|
|
|
89 |
// Create the div that represents the PDF.
|
|
|
90 |
$style = 'height: ' . $page->height . 'mm; line-height: normal; width: ' . $page->width . 'mm;';
|
|
|
91 |
$marginstyle = 'height: ' . $page->height . 'mm; width:1px; float:left; position:relative;';
|
|
|
92 |
$html .= html_writer::start_tag('div', [
|
|
|
93 |
'data-templateid' => $template->get_id(),
|
|
|
94 |
'data-contextid' => $template->get_contextid(),
|
|
|
95 |
'id' => 'pdf',
|
|
|
96 |
'style' => $style]
|
|
|
97 |
);
|
|
|
98 |
if ($page->leftmargin) {
|
|
|
99 |
$position = 'left:' . $page->leftmargin . 'mm;';
|
|
|
100 |
$html .= "<div id='leftmargin' style='$position $marginstyle'></div>";
|
|
|
101 |
}
|
|
|
102 |
if ($elements) {
|
|
|
103 |
foreach ($elements as $element) {
|
|
|
104 |
// Get an instance of the element class.
|
|
|
105 |
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
|
|
106 |
switch ($element->refpoint) {
|
|
|
107 |
case \mod_customcert\element_helper::CUSTOMCERT_REF_POINT_TOPRIGHT:
|
|
|
108 |
$class = 'element refpoint-right';
|
|
|
109 |
break;
|
|
|
110 |
case \mod_customcert\element_helper::CUSTOMCERT_REF_POINT_TOPCENTER:
|
|
|
111 |
$class = 'element refpoint-center';
|
|
|
112 |
break;
|
|
|
113 |
case \mod_customcert\element_helper::CUSTOMCERT_REF_POINT_TOPLEFT:
|
|
|
114 |
default:
|
|
|
115 |
$class = 'element refpoint-left';
|
|
|
116 |
}
|
|
|
117 |
switch ($element->alignment) {
|
|
|
118 |
case \mod_customcert\element::ALIGN_CENTER:
|
|
|
119 |
$class .= ' align-center';
|
|
|
120 |
break;
|
|
|
121 |
case \mod_customcert\element::ALIGN_RIGHT:
|
|
|
122 |
$class .= ' align-right';
|
|
|
123 |
break;
|
|
|
124 |
case \mod_customcert\element::ALIGN_LEFT:
|
|
|
125 |
default:
|
|
|
126 |
$class .= ' align-left';
|
|
|
127 |
break;
|
|
|
128 |
}
|
|
|
129 |
$html .= html_writer::tag('div', $e->render_html(), ['class' => $class,
|
|
|
130 |
'data-refpoint' => $element->refpoint, 'id' => 'element-' . $element->id]);
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
if ($page->rightmargin) {
|
|
|
135 |
$position = 'left:' . ($page->width - $page->rightmargin) . 'mm;';
|
|
|
136 |
$html .= "<div id='rightmargin' style='$position $marginstyle'></div>";
|
|
|
137 |
}
|
|
|
138 |
$html .= html_writer::end_tag('div');
|
|
|
139 |
|
|
|
140 |
echo $OUTPUT->header();
|
|
|
141 |
echo $OUTPUT->heading(get_string('rearrangeelementsheading', 'customcert'), 3);
|
|
|
142 |
echo $OUTPUT->notification(get_string('exampledatawarning', 'customcert'), \core\output\notification::NOTIFY_WARNING);
|
|
|
143 |
echo $html;
|
|
|
144 |
$PAGE->requires->js_call_amd('mod_customcert/rearrange-area', 'init', ['#pdf']);
|
|
|
145 |
echo $OUTPUT->footer();
|