-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_profile.php
110 lines (87 loc) · 3.56 KB
/
edit_profile.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
<?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/>.
/**
* short_description
*
* long_description
*
* @package package_subpackage
* @copyright 2023 Jonas Rehkopp jonas.rehkopp@polizei.nrw.de
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot. '/mod/upc/classes/form/form_profile.php');
$cmid = optional_param('cmid', 0, PARAM_INT);
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/mod/upc/edit_profile.php', ['cmid' => $cmid]));
$PAGE->set_pagelayout('standard');
$PAGE->set_title(get_string('pluginname', 'mod_upc'));
$PAGE->set_heading(get_string('pluginname', 'mod_upc'));
$cm = get_coursemodule_from_id('upc', $cmid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
$filemanageropts = array(
'subdirs' => 0,
'maxbytes' => 26214400,
'areamaxbytes' => 26214400,
'maxfiles' => 1,
'context' => $context,
'accepted_types' => array('.jpg', '.jpeg', '.png'),
);
$itemid = $USER->id;
$draftupcpicture = file_get_submitted_draft_itemid('upcpicture');
file_prepare_draft_area($draftupcpicture, $context->id, 'mod_upc', 'upcpicture', $itemid, $filemanageropts);
$check_data = $DB->get_record('userdata', ['userid' => $USER->id, 'activityid' => $context->instanceid]);
if (empty($check_data->textfield)) {
$description = '';
} else {
$description = $check_data->textfield;
}
$customdesc = $DB->get_field('upc', 'customdesc', array('id' => $cm->instance), '*', MUST_EXIST);
$customdata = array(
'newcard' => empty($check_data),
'filemanageropts' => $filemanageropts,
'cmid' => $cmid,
'picture' => $draftupcpicture,
'description' => $description,
'customdesc' => $customdesc
);
$mform = new form_profile(null, $customdata);
// Form processing and displaying is done here.
if ($mform->is_cancelled()) {
redirect(new moodle_url('/mod/upc/view.php', array('id' => $cmid)));
} else if ($fromform = $mform->get_data()) {
file_save_draft_area_files($draftupcpicture, $context->id, 'mod_upc', 'upcpicture', $itemid, $filemanageropts);
$msg = "";
if (empty($check_data)) {
$DB->insert_record('userdata', ['usermodified' => $USER->id, 'userid' => $USER->id, 'activityid' => $context->instanceid, 'timecreated' => time(), 'timemodified' => time(), 'textfield' => $fromform->description]);
$msg = get_string('success_insert', 'mod_upc');
} else {
$check_data->usermodified = $USER->id;
$check_data->timemodified = time();
$check_data->textfield = $fromform->description;
$DB->update_record('userdata', $check_data);
$msg = get_string('success_update', 'mod_upc');
}
$message = $msg;
$url = new moodle_url('/mod/upc/view.php', array('id' => $cmid));
redirect($url, $message);
} else {
echo $OUTPUT->header();
// Display the form.
$mform->display();
echo $OUTPUT->footer();
}