ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailFormCall.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
15 const SESSION_KEY = 'mail_transport';
16
20 const REFERER_KEY = 'r';
21
25 const SIGNATURE_KEY = 'sig';
26
30 const CONTEXT_PREFIX = 'ctx';
31
35 const CONTEXT_KEY = 'ctx_template';
36
45 public static function getLinkTarget(
46 $gui,
47 string $cmd,
48 array $gui_params = [],
49 array $mail_params = [],
50 $context_params = []
51 ) : string {
52 return self::getTargetUrl('&', $gui, $cmd, $gui_params, $mail_params, $context_params);
53 }
54
63 public static function getRedirectTarget(
64 $gui,
65 string $cmd,
66 array $gui_params = [],
67 array $mail_params = [],
68 array $context_params = []
69 ) : string {
70 return self::getTargetUrl('&', $gui, $cmd, $gui_params, $mail_params, $context_params);
71 }
72
82 protected static function getTargetUrl(
83 string $argument_separator,
84 $gui,
85 string $cmd,
86 array $gui_params = [],
87 array $mail_params = [],
88 array $context_params = []
89 ) : string {
90 global $DIC;
91
92 $mparams = '';
93 $referer = '';
94
95 foreach ($mail_params as $key => $value) {
96 $mparams .= $argument_separator . $key . '=' . urlencode($value);
97 }
98
99 foreach ($context_params as $key => $value) {
100 if ($key == self::CONTEXT_KEY) {
101 $mparams .= $argument_separator . $key . '=' . urlencode($value);
102 } else {
103 $mparams .= $argument_separator . self::CONTEXT_PREFIX . '_' . $key . '=' . urlencode($value);
104 }
105 }
106
107 if (is_object($gui)) {
108 $ilCtrlTmp = clone $DIC->ctrl();
109 foreach ($gui_params as $key => $value) {
110 $ilCtrlTmp->setParameter($gui, $key, $value);
111 }
112 $referer = $ilCtrlTmp->getLinkTarget($gui, $cmd, '', false, false);
113 } elseif (is_string($gui)) {
114 $referer = $gui;
115 }
116
117 $referer = $argument_separator . self::REFERER_KEY . '=' . rawurlencode(base64_encode($referer));
118
119 return 'ilias.php?baseClass=ilMailGUI' . $referer . $mparams;
120 }
121
125 public static function storeReferer(array $queryParameters) : void
126 {
127 $session = ilSession::get(self::SESSION_KEY);
128
129 if (isset($queryParameters[self::REFERER_KEY])) {
130 $session[self::REFERER_KEY] = base64_decode(rawurldecode($queryParameters[self::REFERER_KEY]));
131 $session[self::SIGNATURE_KEY] = base64_decode(rawurldecode($queryParameters[self::SIGNATURE_KEY] ?? ''));
132
133 $contextParameters = [];
134 foreach ($queryParameters as $key => $value) {
135 $prefix = substr($key, 0, strlen(self::CONTEXT_PREFIX));
136 if ($prefix == self::CONTEXT_PREFIX) {
137 if ($key == self::CONTEXT_KEY) {
138 $contextParameters[$key] = $value;
139 } else {
140 $contextParameters[substr($key, strlen(self::CONTEXT_PREFIX . '_'))] = $value;
141 }
142 }
143 }
144 $session[self::CONTEXT_PREFIX] = $contextParameters;
145 } else {
146 if (isset($session[self::REFERER_KEY])) {
147 unset($session[self::REFERER_KEY]);
148 }
149 if (isset($session[self::SIGNATURE_KEY])) {
150 unset($session[self::SIGNATURE_KEY]);
151 }
152 if (isset($session[self::CONTEXT_PREFIX])) {
153 unset($session[self::CONTEXT_PREFIX]);
154 }
155 }
156
157 ilSession::set(self::SESSION_KEY, $session);
158 }
159
163 public static function getSignature() : string
164 {
165 $sig = '';
166 $session = ilSession::get(self::SESSION_KEY);
167
168 if (isset($session[self::SIGNATURE_KEY])) {
169 $sig = $session[self::SIGNATURE_KEY];
170
171 unset($session[self::SIGNATURE_KEY]);
172 ilSession::set(self::SESSION_KEY, $session);
173 }
174
175 return $sig;
176 }
177
181 public static function getRefererRedirectUrl() : string
182 {
183 $url = '';
184 $session = ilSession::get(self::SESSION_KEY);
185
186 if (isset($session[self::REFERER_KEY])) {
187 $url = $session[self::REFERER_KEY];
188 if (is_string($url) && $url !== '') {
189 $parts = parse_url($url);
190 if (isset($parts['query']) && $parts['query'] !== '') {
191 $url .= '&returned_from_mail=1';
192 } else {
193 $url .= '?returned_from_mail=1';
194 }
195
196 $ilias_url_parts = parse_url(ilUtil::_getHttpPath());
197 if (isset($parts['host']) && $ilias_url_parts['host'] !== $parts['host']) {
198 $url = 'ilias.php?baseClass=ilMailGUI';
199 }
200 }
201
202 unset($session[self::REFERER_KEY]);
203 ilSession::set(self::SESSION_KEY, $session);
204 }
205
206 return $url;
207 }
208
212 public static function isRefererStored() : bool
213 {
214 $session = ilSession::get(self::SESSION_KEY);
215
216 return (
217 isset($session[self::REFERER_KEY]) &&
218 is_string($session[self::REFERER_KEY]) &&
219 $session[self::REFERER_KEY] !== ''
220 );
221 }
222
226 public static function getContextId() : ?string
227 {
228 $session = ilSession::get(self::SESSION_KEY);
229 return (
230 isset($session[self::CONTEXT_PREFIX][self::CONTEXT_KEY]) &&
231 is_string($session[self::CONTEXT_PREFIX][self::CONTEXT_KEY]) ?
232 $session[self::CONTEXT_PREFIX][self::CONTEXT_KEY] : null
233 );
234 }
235
239 public static function setContextId(?string $id) : void
240 {
241 $session = ilSession::get(self::SESSION_KEY);
242 $session[self::CONTEXT_KEY] = $id;
243 ilSession::set(self::SESSION_KEY, $session);
244 }
245
249 public static function getContextParameters() : array
250 {
251 $session = ilSession::get(self::SESSION_KEY);
252 if (isset($session[self::CONTEXT_PREFIX]) && is_array($session[self::CONTEXT_PREFIX])) {
253 return $session[self::CONTEXT_PREFIX];
254 }
255
256 return [];
257 }
258
263 public static function setContextParameters(array $parameters) : void
264 {
265 $session = ilSession::get(self::SESSION_KEY);
266 $session[self::CONTEXT_PREFIX] = $parameters;
267 ilSession::set(self::SESSION_KEY, $session);
268 }
269
273 public static function setRecipients(array $recipients, string $type = 'to') : void
274 {
275 $session = ilSession::get(self::SESSION_KEY) ?? [];
276 $session['rcp_' . $type] = array_map('strval', array_values($recipients));
277 ilSession::set(self::SESSION_KEY, $session);
278 }
279
283 public static function getRecipients(string $type = 'to') : array
284 {
285 $session = ilSession::get(self::SESSION_KEY) ?? [];
286 $key = 'rcp_' . $type;
287 if (isset($session[$key]) && is_array($session[$key])) {
288 return array_map('strval', array_values($session[$key]));
289 }
290
291 return [];
292 }
293}
An exception for terminatinating execution or to throw for unit testing.
Statically used helper class for generating links to the mail form user interface.
const REFERER_KEY
HTTP-GET parameter for the referer url.
static getLinkTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], $context_params=[])
const CONTEXT_PREFIX
Session parameter for the context.
static storeReferer(array $queryParameters)
static setContextId(?string $id)
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
const SIGNATURE_KEY
Session parameter for the hash.
const CONTEXT_KEY
Session parameter for the context.
static getTargetUrl(string $argument_separator, $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
static setContextParameters(array $parameters)
static getRecipients(string $type='to')
static setRecipients(array $recipients, string $type='to')
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
static _getHttpPath()
global $DIC
Definition: goto.php:24
$type
$session
$url