ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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()
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 return true;
114 }
115
116 private function redirectToParentReferer()
117 {
118 $redirect_target = $this->getStoredReferer();
119 $this->unsetStoredReferer();
120 ilUtil::redirect($redirect_target);
121 }
122
126 public function storeReferer()
127 {
128 $referer = ilSession::get('referer');
129 ilSession::set('ilMailMemberSearchGUIReferer', $referer);
130 }
131
135 private function getStoredReferer()
136 {
137 $stored_referer = ilSession::get('ilMailMemberSearchGUIReferer');
138 return (strlen($stored_referer) ? $stored_referer : false);
139 }
140
144 private function unsetStoredReferer()
145 {
146 ilSession::set('ilMailMemberSearchGUIReferer', '');
147 }
148
152 protected function nextMailForm()
153 {
154 $form = $this->initMailToMembersForm();
155 if ($form->checkInput()) {
156 if ($form->getInput('mail_member_type') == 'mail_member_roles') {
157 if (is_array($form->getInput('roles')) && count($form->getInput('roles')) > 0) {
158 $role_mail_boxes = array();
159 $roles = $form->getInput('roles');
160 foreach ($roles as $role_id) {
161 $mailbox = $this->objMailMemberRoles->getMailboxRoleAddress($role_id);
162 $role_mail_boxes[] = $mailbox;
163 }
164
165 require_once 'Services/Mail/classes/class.ilMailFormCall.php';
166 $_SESSION['mail_roles'] = $role_mail_boxes;
167
169 $this,
170 'showSearchForm',
171 array('type' => 'role'),
172 array(
173 'type' => 'role',
174 'rcp_to' => implode(',', $role_mail_boxes),
175 'sig' => $this->gui->createMailSignature()
176 ),
177 $this->generateContextArray()
178 ));
179 } else {
180 $form->setValuesByPost();
181 ilUtil::sendFailure($this->lng->txt('no_checkbox'));
182 $this->showSearchForm();
183 return;
184 }
185 } else {
186 $this->showSelectableUsers();
187 return;
188 }
189 }
190
191 $form->setValuesByPost();
192 $this->showSearchForm();
193 }
194
198 protected function generateContextArray()
199 {
200 $context_array = [];
201
202 $type = ilObject::_lookupType($this->ref_id, true);
203 switch ($type) {
204 case 'crs':
205 if ($this->access->checkAccess('write', "", $this->ref_id)) {
206 $context_array = array(
208 'ref_id' => $this->ref_id,
209 'ts' => time()
210 );
211 }
212 break;
213
214 case 'sess':
215 if ($this->access->checkAccess('write', "", $this->ref_id)) {
216 $context_array = array(
218 'ref_id' => $this->ref_id,
219 'ts' => time()
220 );
221 }
222 break;
223 }
224 return $context_array;
225 }
226
230 protected function showSelectableUsers()
231 {
232 include_once './Services/Contact/classes/class.ilMailMemberSearchTableGUI.php';
233 include_once './Services/Contact/classes/class.ilMailMemberSearchDataProvider.php';
234
235 $this->tpl->getStandardTemplate();
236 $tbl = new ilMailMemberSearchTableGUI($this, 'showSelectableUsers');
237 $provider = new ilMailMemberSearchDataProvider($this->getObjParticipants(), $this->ref_id);
238 $tbl->setData($provider->getData());
239
240 $this->tpl->setContent($tbl->getHTML());
241 }
242
246 protected function sendMailToSelectedUsers()
247 {
248 if (!is_array($_POST['user_ids']) || 0 === count($_POST['user_ids'])) {
249 ilUtil::sendFailure($this->lng->txt("no_checkbox"));
250 $this->showSelectableUsers();
251 return false;
252 }
253
254 $rcps = array();
255 foreach ($_POST['user_ids'] as $usr_id) {
256 $rcps[] = ilObjUser::_lookupLogin($usr_id);
257 }
258
259 if (!count(array_filter($rcps))) {
260 ilUtil::sendFailure($this->lng->txt("no_checkbox"));
261 $this->showSelectableUsers();
262 return false;
263 }
264
265 require_once 'Services/Mail/classes/class.ilMailFormCall.php';
267
269 $this,
270 'members',
271 array(),
272 array(
273 'type' => 'new',
274 'sig' => $this->gui->createMailSignature()
275 ),
276 $this->generateContextArray()
277 ));
278
279 return true;
280 }
281
285 protected function showSearchForm()
286 {
287 $this->storeReferer();
288
289 $form = $this->initMailToMembersForm();
290 $this->tpl->setContent($form->getHTML());
291 }
292
296 protected function getObjParticipants()
297 {
299 }
300
305 {
306 $this->objParticipants = $objParticipants;
307 }
308
312 protected function initMailToMembersForm()
313 {
314 $this->lng->loadLanguageModule('mail');
315
316 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
317 $form = new ilPropertyFormGUI();
318 $form->setTitle($this->lng->txt('mail_members'));
319
320 $form->setFormAction($this->ctrl->getFormAction($this, 'nextMailForm'));
321
322 $radio_grp = $this->getMailRadioGroup();
323
324 $form->addItem($radio_grp);
325 $form->addCommandButton('nextMailForm', $this->lng->txt('mail_members_search_continue'));
326 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
327
328 return $form;
329 }
330
334 private function getMailRoles()
335 {
336 return $this->mail_roles;
337 }
338
342 protected function getMailRadioGroup()
343 {
344 $mail_roles = $this->getMailRoles();
345
346 $radio_grp = new ilRadioGroupInputGUI($this->lng->txt('mail_sel_label'), 'mail_member_type');
347
348 $radio_sel_users = new ilRadioOption($this->lng->txt('mail_sel_users'), 'mail_sel_users');
349
350 $radio_roles = new ilRadioOption($this->objMailMemberRoles->getRadioOptionTitle(), 'mail_member_roles');
351 foreach ($mail_roles as $role) {
352 $chk_role = new ilCheckboxInputGUI($role['form_option_title'], 'roles[]');
353
354 if (array_key_exists('default_checked', $role) && $role['default_checked']) {
355 $chk_role->setChecked(true);
356 }
357 $chk_role->setValue($role['role_id']);
358 $chk_role->setInfo($role['mailbox']);
359 $radio_roles->addSubItem($chk_role);
360 }
361
362 $radio_grp->setValue('mail_member_roles');
363
364 $radio_grp->addOption($radio_sel_users);
365 $radio_grp->addOption($radio_roles);
366
367 return $radio_grp;
368 }
369}
$_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 getRedirectTarget($gui, $cmd, array $gui_params=array(), array $mail_params=array(), array $context_params=array())
static setRecipients(array $recipients)
const CONTEXT_KEY
Session parameter for the context.
Class ilMailMemberSearchDataProvider.
Class ilMailMemberSearchGUI.
__construct($gui, $ref_id, ilAbstractMailMemberRoles $objMailMemberRoles)
ilMailMemberSearchGUI constructor.
static _lookupLogin($a_user_id)
lookup login
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 redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$tbl
Definition: example_048.php:81
$type
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7