ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailMemberSearchGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
10{
14 protected $mail_roles;
15
19 protected $gui;
20
28 protected $objParticipants = null;
29
33 protected $ctrl;
34
38 protected $tpl;
39
43 protected $lng;
44
48 protected $access;
49
57 {
58 global $DIC;
59
60 $this->ctrl = $DIC['ilCtrl'];
61 $this->tpl = $DIC['tpl'];
62 $this->lng = $DIC['lng'];
63 $this->access = $DIC['ilAccess'];
64
65 $this->lng->loadLanguageModule('mail');
66 $this->lng->loadLanguageModule('search');
67
68 $this->gui = $gui;
69 $this->ref_id = $ref_id;
70
71 $this->objMailMemberRoles = $objMailMemberRoles;
72 $this->mail_roles = $objMailMemberRoles->getMailRoles($ref_id);
73 }
74
78 public function executeCommand() : bool
79 {
80 $next_class = $this->ctrl->getNextClass($this);
81 $cmd = $this->ctrl->getCmd();
82
83 $this->ctrl->setReturn($this, '');
84
85 switch ($next_class) {
86 default:
87 switch ($cmd) {
88 case 'sendMailToSelectedUsers':
90 break;
91
92 case 'showSelectableUsers':
93 $this->showSelectableUsers();
94 break;
95
96 case 'nextMailForm':
97 $this->nextMailForm();
98 break;
99
100 case 'cancel':
102 break;
103
104 default:
105 if (isset($_GET['returned_from_mail']) && $_GET['returned_from_mail'] == '1') {
107 }
108 $this->showSearchForm();
109 break;
110 }
111 break;
112 }
113
114
115 return true;
116 }
117
118 private function redirectToParentReferer() : void
119 {
120 $url = $this->getStoredReferer();
121 $this->unsetStoredReferer();
122 $this->ctrl->redirectToURL($url);
123 }
124
125 public function storeReferer() : void
126 {
127 $referer = ilSession::get('referer');
128 ilSession::set('ilMailMemberSearchGUIReferer', $referer);
129 }
130
134 private function getStoredReferer() : string
135 {
136 return (string) ilSession::get('ilMailMemberSearchGUIReferer');
137 }
138
139 private function unsetStoredReferer() : void
140 {
141 ilSession::set('ilMailMemberSearchGUIReferer', '');
142 }
143
144 protected function nextMailForm() : void
145 {
146 $form = $this->initMailToMembersForm();
147 if ($form->checkInput()) {
148 if ($form->getInput('mail_member_type') === 'mail_member_roles') {
149 if (is_array($form->getInput('roles')) && count($form->getInput('roles')) > 0) {
150 $role_mail_boxes = [];
151 $roles = $form->getInput('roles');
152 foreach ($roles as $role_id) {
153 $mailbox = $this->objMailMemberRoles->getMailboxRoleAddress($role_id);
154 $role_mail_boxes[] = $mailbox;
155 }
156
157 $_SESSION['mail_roles'] = $role_mail_boxes;
158
159 $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
160 $this,
161 'showSearchForm',
162 ['type' => 'role'],
163 [
164 'type' => 'role',
165 'rcp_to' => implode(',', $role_mail_boxes),
166 'sig' => $this->gui->createMailSignature()
167 ],
168 $this->generateContextArray()
169 ));
170 } else {
171 $form->setValuesByPost();
172 ilUtil::sendFailure($this->lng->txt('no_checkbox'));
173 $this->showSearchForm();
174 return;
175 }
176 } else {
177 $this->showSelectableUsers();
178 return;
179 }
180 }
181
182 $form->setValuesByPost();
183 $this->showSearchForm();
184 }
185
189 protected function generateContextArray() : array
190 {
191 $contextParameters = [];
192
193 $type = ilObject::_lookupType($this->ref_id, true);
194 switch ($type) {
195 case 'grp':
196 case 'crs':
197 if ($this->access->checkAccess('write', '', $this->ref_id)) {
198 $contextParameters = [
199 'ref_id' => $this->ref_id,
200 'ts' => time(),
202 ilObject::_lookupObjId($this->ref_id),
204 ''
205 )
206 ];
207
208 if ('crs' === $type) {
210 }
211 }
212 break;
213
214 case 'sess':
215 if ($this->access->checkAccess('write', '', $this->ref_id)) {
216 $contextParameters = [
218 'ref_id' => $this->ref_id,
219 'ts' => time()
220 ];
221 }
222 break;
223 }
224
225 return $contextParameters;
226 }
227
228 protected function showSelectableUsers() : void
229 {
230 $this->tpl->loadStandardTemplate();
231 $tbl = new ilMailMemberSearchTableGUI($this, 'showSelectableUsers');
232 $provider = new ilMailMemberSearchDataProvider($this->getObjParticipants(), $this->ref_id);
233 $tbl->setData($provider->getData());
234
235 $this->tpl->setContent($tbl->getHTML());
236 }
237
241 protected function sendMailToSelectedUsers() : bool
242 {
243 if (!isset($_POST['user_ids']) || !is_array($_POST['user_ids']) || 0 === count($_POST['user_ids'])) {
244 ilUtil::sendFailure($this->lng->txt("no_checkbox"));
245 $this->showSelectableUsers();
246 return false;
247 }
248
249 $rcps = [];
250 foreach ($_POST['user_ids'] as $usr_id) {
251 $rcps[] = ilObjUser::_lookupLogin($usr_id);
252 }
253
254 if (!count(array_filter($rcps))) {
255 ilUtil::sendFailure($this->lng->txt("no_checkbox"));
256 $this->showSelectableUsers();
257 return false;
258 }
259
261
262 $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
263 $this,
264 'members',
265 [],
266 [
267 'type' => 'new',
268 'sig' => $this->gui->createMailSignature(),
269 ],
270 $this->generateContextArray()
271 ));
272
273 return true;
274 }
275
276 protected function showSearchForm() : void
277 {
278 $this->storeReferer();
279
280 $form = $this->initMailToMembersForm();
281 $this->tpl->setContent($form->getHTML());
282 }
283
287 protected function getObjParticipants() : ilParticipants
288 {
290 }
291
296 {
297 $this->objParticipants = $objParticipants;
298 }
299
304 {
305 $this->lng->loadLanguageModule('mail');
306
307 $form = new ilPropertyFormGUI();
308 $form->setTitle($this->lng->txt('mail_members'));
309
310 $form->setFormAction($this->ctrl->getFormAction($this, 'nextMailForm'));
311
312 $radio_grp = $this->getMailRadioGroup();
313
314 $form->addItem($radio_grp);
315 $form->addCommandButton('nextMailForm', $this->lng->txt('mail_members_search_continue'));
316 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
317
318 return $form;
319 }
320
324 private function getMailRoles()
325 {
326 return $this->mail_roles;
327 }
328
333 {
334 $mail_roles = $this->getMailRoles();
335
336 $radio_grp = new ilRadioGroupInputGUI($this->lng->txt('mail_sel_label'), 'mail_member_type');
337
338 $radio_sel_users = new ilRadioOption($this->lng->txt('mail_sel_users'), 'mail_sel_users');
339
340 $radio_roles = new ilRadioOption($this->objMailMemberRoles->getRadioOptionTitle(), 'mail_member_roles');
341 foreach ($mail_roles as $role) {
342 $chk_role = new ilCheckboxInputGUI($role['form_option_title'], 'roles[]');
343
344 if (array_key_exists('default_checked', $role) && $role['default_checked']) {
345 $chk_role->setChecked(true);
346 }
347 $chk_role->setValue($role['role_id']);
348 $chk_role->setInfo($role['mailbox']);
349 $radio_roles->addSubItem($chk_role);
350 }
351
352 $radio_grp->setValue('mail_member_roles');
353
354 $radio_grp->addOption($radio_sel_users);
355 $radio_grp->addOption($radio_roles);
356
357 return $radio_grp;
358 }
359}
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAbstractMailMemberRoles.
This class represents a checkbox property in a property form.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
const CONTEXT_KEY
Session parameter for the context.
static setRecipients(array $recipients, string $type='to')
Class ilMailMemberSearchDataProvider.
Class ilMailMemberSearchGUI.
__construct($gui, $ref_id, ilAbstractMailMemberRoles $objMailMemberRoles)
ilMailMemberSearchGUI constructor.
setObjParticipants(ilParticipants $objParticipants)
const PROP_CONTEXT_SUBJECT_PREFIX
static _lookupLogin($a_user_id)
lookup login
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
$type
$url