/usr/share/otrs/Kernel/Modules/AgentAppointmentCalendarOverview.pm is in otrs2 6.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | # --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::Modules::AgentAppointmentCalendarOverview;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(:all);
our $ObjectManagerDisabled = 1;
sub new {
my ( $Type, %Param ) = @_;
my $Self = {%Param};
bless( $Self, $Type );
$Self->{OverviewScreen} = 'CalendarOverview';
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# get all user's valid calendars
my $ValidID = $Kernel::OM->Get('Kernel::System::Valid')->ValidLookup(
Valid => 'valid',
);
my $CalendarObject = $Kernel::OM->Get('Kernel::System::Calendar');
my @Calendars = $CalendarObject->CalendarList(
UserID => $Self->{UserID},
ValidID => $ValidID,
);
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
my $GroupObject = $Kernel::OM->Get('Kernel::System::Group');
# Get user's permissions to associated modules which are displayed as links.
for my $Module (qw(AdminAppointmentCalendarManage)) {
my $ModuleGroups = $Kernel::OM->Get('Kernel::Config')->Get('Frontend::Module')
->{$Module}->{Group} // [];
if ( IsArrayRefWithData($ModuleGroups) ) {
MODULE_GROUP:
for my $ModuleGroup ( @{$ModuleGroups} ) {
my $HasPermission = $GroupObject->PermissionCheck(
UserID => $Self->{UserID},
GroupName => $ModuleGroup,
Type => 'rw',
);
if ($HasPermission) {
$Param{ModulePermissions}->{$Module} = 1;
last MODULE_GROUP;
}
}
}
# Always allow links if no groups are specified.
else {
$Param{ModulePermissions}->{$Module} = 1;
}
}
# check if we found some
if (@Calendars) {
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');
# new appointment dialog
if ( $Self->{Subaction} eq 'AppointmentCreate' ) {
$LayoutObject->AddJSData(
Key => 'AppointmentCreate',
Value => {
Start => $ParamObject->GetParam( Param => 'Start' ) // undef,
End => $ParamObject->GetParam( Param => 'End' ) // undef,
PluginKey => $ParamObject->GetParam( Param => 'PluginKey' ) // undef,
Search => $ParamObject->GetParam( Param => 'Search' ) // undef,
ObjectID => $ParamObject->GetParam( Param => 'ObjectID' ) // undef,
},
);
}
# show settings dialog
elsif ( $Self->{Subaction} eq 'CalendarSettingsShow' ) {
$LayoutObject->AddJSData(
Key => 'CalendarSettingsShow',
Value => 1,
);
}
# edit appointment dialog
else {
$LayoutObject->AddJSData(
Key => 'AppointmentID',
Value => $ParamObject->GetParam( Param => 'AppointmentID' ) // undef,
);
}
# Trigger regular date picker initialization, used by AgentAppointmentEdit screen. This
# screen is initialized via AJAX, and then it's too late to output this configuration.
$LayoutObject->{HasDatepicker} = 1;
$LayoutObject->Block(
Name => 'AppointmentCreateButton',
);
$LayoutObject->Block(
Name => 'CalendarDiv',
Data => {
%Param,
CalendarWidth => 100,
},
);
$LayoutObject->Block(
Name => 'CalendarWidget',
);
# get user preferences
my %Preferences = $Kernel::OM->Get('Kernel::System::User')->GetPreferences(
UserID => $Self->{UserID},
);
# user preference key
my $ShownAppointmentsPrefKey = 'User' . $Self->{OverviewScreen} . 'ShownAppointments';
my $ShownAppointmentsPrefVal = $Preferences{$ShownAppointmentsPrefKey} || 1;
# Shown appointments selection box.
$LayoutObject->AddJSData(
Key => 'ShownAppointmentsStrg',
Value => $LayoutObject->BuildSelection(
Data => {
1 => $LayoutObject->{LanguageObject}->Translate('All appointments'),
2 => $LayoutObject->{LanguageObject}->Translate('Appointments assigned to me'),
},
Name => 'ShownAppointments',
ID => 'ShownAppointments',
Class => 'Modernize',
SelectedID => $ShownAppointmentsPrefVal,
PossibleNone => 0,
),
);
# show only assigned appointments to current user
if ( $ShownAppointmentsPrefVal == 2 ) {
$LayoutObject->AddJSData(
Key => 'ResourceID',
Value => $Self->{UserID},
);
# display notify line
$Param{NotifyLine} = {
Priority => 'Warning',
Data => $LayoutObject->{LanguageObject}
->Translate('Showing only appointments assigned to you! Change settings'),
Link =>
$LayoutObject->{Baselink}
. 'Action=AgentAppointmentCalendarOverview;Subaction=CalendarSettingsShow',
};
}
my $CalendarLimit = int $ConfigObject->Get('AppointmentCalendar::CalendarLimitOverview') || 10;
$LayoutObject->AddJSData(
Key => 'CalendarLimit',
Value => $CalendarLimit,
);
my $CalendarSelection = $Kernel::OM->Get('Kernel::System::JSON')->Decode(
Data => $Preferences{ 'User' . $Self->{OverviewScreen} . 'CalendarSelection' } || '[]',
);
my $CurrentCalendar = 1;
my @CalendarConfig;
for my $Calendar (@Calendars) {
# check the calendar if stored in preferences
if ( scalar @{$CalendarSelection} ) {
if ( grep { $_ == $Calendar->{CalendarID} } @{$CalendarSelection} ) {
$Calendar->{Checked} = 'checked="checked" ' if $CurrentCalendar <= $CalendarLimit;
}
}
# check calendar by default if limit is not yet reached
else {
$Calendar->{Checked} = 'checked="checked" ' if $CurrentCalendar <= $CalendarLimit;
}
# get access tokens
$Calendar->{AccessToken} = $CalendarObject->GetAccessToken(
CalendarID => $Calendar->{CalendarID},
UserLogin => $Self->{UserLogin},
);
# calendar checkbox in the widget
$LayoutObject->Block(
Name => 'CalendarSwitch',
Data => {
%{$Calendar},
%Param,
},
);
# Calculate best text color.
$Calendar->{TextColor} = $CalendarObject->GetTextColor(
Background => $Calendar->{Color},
) || '#FFFFFF';
# Define calendar configuration.
push @CalendarConfig, $Calendar;
$CurrentCalendar++;
}
$LayoutObject->AddJSData(
Key => 'CalendarConfig',
Value => \@CalendarConfig,
);
# Set initial view.
$LayoutObject->AddJSData(
Key => 'DefaultView',
Value => $Preferences{ 'User' . $Self->{OverviewScreen} . 'DefaultView' } || 'timelineWeek',
);
# check if team object is registered
if ( $Kernel::OM->Get('Kernel::System::Main')->Require( 'Kernel::System::Calendar::Team', Silent => 1 ) ) {
# show resource block in tooltips
$LayoutObject->AddJSData(
Key => 'TooltipTemplateResource',
Value => 1,
);
}
# get plugin list
$Param{PluginList} = $Kernel::OM->Get('Kernel::System::Calendar::Plugin')->PluginList();
$LayoutObject->AddJSData(
Key => 'PluginList',
Value => $Param{PluginList},
);
# get registered ticket appointment types
my %TicketAppointmentTypes = $CalendarObject->TicketAppointmentTypesGet();
# Output configured ticket appointment type mark and draggability.
my %TicketAppointmentConfig;
for my $Type ( sort keys %TicketAppointmentTypes ) {
my $NoDrag = 0;
# prevent dragging of ticket escalation appointments
if (
$Type eq 'FirstResponseTime'
|| $Type eq 'UpdateTime'
|| $Type eq 'SolutionTime'
)
{
$NoDrag = 1;
}
$TicketAppointmentConfig{$Type} = {
Mark => lc substr( $TicketAppointmentTypes{$Type}->{Mark}, 0, 1 ),
NoDrag => $NoDrag,
};
}
$LayoutObject->AddJSData(
Key => 'TicketAppointmentConfig',
Value => \%TicketAppointmentConfig,
);
# Get working hour appointments.
my @WorkingHours = $Self->_GetWorkingHours();
my @WorkingHoursConfig;
for my $Appointment (@WorkingHours) {
# Sort days of the week.
my @DoW = sort @{ $Appointment->{DoW} };
push @WorkingHoursConfig, {
id => 'workingHours',
start => $Appointment->{StartTime},
end => $Appointment->{EndTime},
color => '#D7D7D7',
rendering => 'inverse-background',
editable => '',
dow => \@DoW,
};
}
$LayoutObject->AddJSData(
Key => 'WorkingHoursConfig',
Value => \@WorkingHoursConfig,
);
}
# show no calendar found message
else {
$LayoutObject->Block(
Name => 'NoCalendar',
);
}
$LayoutObject->AddJSData(
Key => 'OverviewScreen',
Value => $Self->{OverviewScreen},
);
# Get text direction from language object.
my $TextDirection = $LayoutObject->{LanguageObject}->{TextDirection} || '';
$LayoutObject->AddJSData(
Key => 'IsRTLLanguage',
Value => ( $TextDirection eq 'rtl' ) ? '1' : '',
);
$LayoutObject->AddJSData(
Key => 'CalendarWeekDayStart',
Value => $Kernel::OM->Get('Kernel::Config')->Get('CalendarWeekDayStart') || 0,
);
# output page
my $Output = $LayoutObject->Header();
$Output .= $LayoutObject->NavigationBar();
if ( $Param{NotifyLine} ) {
$Output .= $LayoutObject->Notify(
%{ $Param{NotifyLine} },
);
}
$Output .= $LayoutObject->Output(
TemplateFile => 'AgentAppointmentCalendarOverview',
Data => {
%Param,
},
);
$Output .= $LayoutObject->Footer();
return $Output;
}
sub _GetWorkingHours {
my ( $Self, %Param ) = @_;
# get working hours from sysconfig
my $WorkingHoursConfig = $Kernel::OM->Get('Kernel::Config')->Get('TimeWorkingHours');
# create working hour appointments for each day
my @WorkingHours;
for my $DayName ( sort keys %{$WorkingHoursConfig} ) {
# day of the week
my $DoW = 0; # Sun
if ( $DayName eq 'Mon' ) {
$DoW = 1;
}
elsif ( $DayName eq 'Tue' ) {
$DoW = 2;
}
elsif ( $DayName eq 'Wed' ) {
$DoW = 3;
}
elsif ( $DayName eq 'Thu' ) {
$DoW = 4;
}
elsif ( $DayName eq 'Fri' ) {
$DoW = 5;
}
elsif ( $DayName eq 'Sat' ) {
$DoW = 6;
}
my $StartTime = 0;
my $EndTime = 0;
START_TIME:
for ( $StartTime = 0; $StartTime < 24; $StartTime++ ) {
# is this working hour?
if ( grep { $_ eq $StartTime } @{ $WorkingHoursConfig->{$DayName} } ) {
# go to the end of the working hours
for ( my $EndHour = $StartTime; $EndHour < 24; $EndHour++ ) {
if ( !grep { $_ eq $EndHour } @{ $WorkingHoursConfig->{$DayName} } ) {
$EndTime = $EndHour;
# add appointment
if ( $EndTime > $StartTime ) {
push @WorkingHours, {
StartTime => sprintf( '%02d:00:00', $StartTime ),
EndTime => sprintf( '%02d:00:00', $EndTime ),
DoW => [$DoW],
};
}
# skip some hours
$StartTime = $EndHour;
next START_TIME;
}
}
}
}
}
# collapse appointments with same start and end times
for my $AppointmentA (@WorkingHours) {
for my $AppointmentB (@WorkingHours) {
if (
$AppointmentA->{StartTime} && $AppointmentB->{StartTime}
&& $AppointmentA->{StartTime} eq $AppointmentB->{StartTime}
&& $AppointmentA->{EndTime} eq $AppointmentB->{EndTime}
&& $AppointmentA->{DoW} ne $AppointmentB->{DoW}
)
{
push @{ $AppointmentA->{DoW} }, @{ $AppointmentB->{DoW} };
$AppointmentB = undef;
}
}
}
# return only non-empty appointments
return grep { scalar keys %{$_} } @WorkingHours;
}
1;
|