-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnew.php
120 lines (104 loc) · 3.77 KB
/
new.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
<?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/>.
/**
* This script is for creating new tickets and handling the UI and entry level
* functions of this task.
*
* @package block_helpdesk
* @copyright 2010
* @author Jonathan Doane <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// We are moodle, so we should get necessary stuff.
require_once('../../config.php');
require_once($CFG->libdir . '/blocklib.php');
require_once($CFG->libdir . '/weblib.php');
require_once($CFG->libdir . '/datalib.php');
require_once($CFG->libdir . '/formslib.php');
// We are the helpdesk, so we need the core library.
require_once($CFG->dirroot . '/blocks/helpdesk/lib.php');
require_login(0, false);
// User should be logged in, no guests.
$nav = array (
array ('name' => get_string('helpdesk', 'block_helpdesk')),
array ('name' => get_string('newticket', 'block_helpdesk'))
);
// We may have some special tags included in GET.
$tags = optional_param('tags', null, PARAM_TAGLIST);
$tagslist = array();
if (!empty($tags)) {
$tags = explode(',', $tags);
foreach($tags as $tag) {
if (!($rval = optional_param($tag, null, PARAM_TEXT))) {
notify(get_string('missingnewtickettag', 'block_helpdesk') . ": $tag");
}
$taglist[$tag] = $rval;
}
}
// Require a minimum of asker capability on the current user.
helpdesk_is_capable(HELPDESK_CAP_ASK, true);
$title = get_string('helpdesknewticket', 'block_helpdesk');
helpdesk_print_header(build_navigation($nav), $title);
print_heading(get_string('helpdesk', 'block_helpdesk'));
// Meat and potatoes of the new ticket.
// Get plugin helpdesk.
$hd = helpdesk::get_helpdesk();
// Get new ticket form to get data or the form itself.
if (!empty($taglist)) {
$form = $hd->new_ticket_form(array('tags' => $taglist));
} else {
$form = $hd->new_ticket_form(array('tags' => array()));
}
// If the form is submitted (or not) we gotta do stuff.
if (!$form->is_submitted() or !($data = $form->get_data())) {
$form->display();
print_footer();
exit;
}
// At this point we know that we have a ticket to add.
$ticket = $hd->new_ticket();
if (!$ticket->parse($data)) {
error(get_string("cannotparsedata", 'block_helpdesk'));
}
if (!$ticket->store()) {
error(get_string('unabletostoreticket', 'block_helpdesk'));
}
$id = $ticket->get_idstring();
if (!empty($data->tags)) {
$taglist = array();
$tags = explode(',', $data->tags);
foreach($tags as $tag) {
if (!($rval = $data->$tag)) {
notify(get_string('missingnewtickettag', 'block_helpdesk') . ": $tag");
} else {
$taglist[$tag] = $rval;
}
}
foreach($taglist as $key => $value) {
$tagobject = new stdClass;
$tagobject->ticketid = $id;
$tagobject->name = $key;
$tagobject->value = $value;
if (!$ticket->add_tag($tagobject)) {
notify(get_string('cannotaddtag', 'block_helpdesk') . ": $key");
}
}
}
$url = new moodle_url("$CFG->wwwroot/blocks/helpdesk/view.php");
$url->param('id', $id);
$url = $url->out();
redirect($url, get_string('newticketmsg', 'block_helpdesk'));
?>