/
ticket.lib.php
194 lines (164 loc) · 6.44 KB
/
ticket.lib.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/* Copyright (C) 2013-2018 Jean-François FERRY <hello@librethic.io>
* Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file core/lib/ticket.lib.php
* \ingroup ticket
* \brief This file is a library for Ticket module
*/
/**
* Build tabs for admin page
*
* @return array
*/
function ticketAdminPrepareHead()
{
global $langs, $conf;
$langs->load("ticket");
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/admin/ticket.php';
$head[$h][1] = $langs->trans("TicketSettings");
$head[$h][2] = 'settings';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/admin/ticket_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsTicket");
$head[$h][2] = 'attributes';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
//$this->tabs = array(
// 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
//); // to add new tab
//$this->tabs = array(
// 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
//); // to remove a tab
complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticketadmin');
return $head;
}
/**
* Build tabs for a Ticket object
*
* @param Ticket $object Object Ticket
* @return array Array of tabs
*/
function ticket_prepare_head($object)
{
global $db, $langs, $conf, $user;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/ticket/card.php?action=view&track_id=' . $object->track_id;
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'tabTicket';
$h++;
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && empty($user->socid))
{
$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
$head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
$head[$h][1] = $langs->trans('ContactsAddresses');
if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
$head[$h][2] = 'contact';
$h++;
}
complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket');
// Attached files
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$upload_dir = $conf->ticket->dir_output . "/" . $object->track_id;
$nbFiles = count(dol_dir_list($upload_dir, 'files'));
$head[$h][0] = dol_buildpath('/ticket/document.php', 1) . '?track_id=' . $object->track_id;
$head[$h][1] = $langs->trans("Documents");
if ($nbFiles > 0) {
$head[$h][1] .= ' <span class="badge">' . $nbFiles . '</span>';
}
$head[$h][2] = 'tabTicketDocument';
$h++;
// History
$head[$h][0] = DOL_URL_ROOT.'/ticket/history.php?track_id=' . $object->track_id;
$head[$h][1] = $langs->trans('Events');
if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
{
$head[$h][1].= '/';
$head[$h][1].= $langs->trans("Agenda");
}
$head[$h][2] = 'tabTicketLogs';
$h++;
complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket','remove');
return $head;
}
/**
* Generate a random id
*
* @param string $car Char to generate key
* @return void
*/
function generate_random_id($car=16)
{
$string = "";
$chaine = "abcdefghijklmnopqrstuvwxyz123456789";
srand((double) microtime() * 1000000);
for ($i = 0; $i < $car; $i++) {
$string .= $chaine[rand() % strlen($chaine)];
}
return $string;
}
/**
* Show header for public pages
*
* @param string $title Title
* @param string $head Head array
* @param int $disablejs More content into html header
* @param int $disablehead More content into html header
* @param array $arrayofjs Array of complementary js files
* @param array $arrayofcss Array of complementary css files
* @return void
*/
function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
{
global $user, $conf, $langs, $mysoc;
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
print '<body id="mainbody" class="publicnewticketform" style="margin-top: 10px;">';
if (! empty($conf->global->TICKET_SHOW_COMPANY_LOGO)) {
// Print logo
$urllogo = DOL_URL_ROOT . '/theme/login_logo.png';
if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
$urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=companylogo&file=' . urlencode('thumbs/' . $mysoc->logo_small);
} elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
$urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=companylogo&file=' . urlencode($mysoc->logo);
$width = 128;
} elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.png')) {
$urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
}
print '<center>';
print '<a href="' . ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE : dol_buildpath('/public/ticket/index.php', 1)) . '"><img alt="Logo" id="logosubscribe" title="" src="' . $urllogo . '" style="max-width: 440px" /></a><br>';
print '<strong>' . ($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC ? $conf->global->TICKET_PUBLIC_INTERFACE_TOPIC : $langs->trans("TicketSystem")) . '</strong>';
print '</center><br>';
}
print '<div style="margin-left: 50px; margin-right: 50px;">';
}
/**
* Show footer for new member
*
* @return void
*/
function llxFooterTicket()
{
print '</div>';
printCommonFooter('public');
dol_htmloutput_events();
print "</body>\n";
print "</html>\n";
}