ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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':
89  $this->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':
101  $this->redirectToParentReferer();
102  break;
103 
104  default:
105  if (isset($_GET['returned_from_mail']) && $_GET['returned_from_mail'] == '1') {
106  $this->redirectToParentReferer();
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 (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 = array();
201  require_once 'Modules/Course/classes/class.ilCourseMailTemplateTutorContext.php';
202  if ($this->access->checkAccess('write', "", $this->ref_id)) {
203  $context_array = array(
205  'ref_id' => $this->ref_id,
206  'ts' => time()
207  );
208  }
209 
210  return $context_array;
211  }
212 
216  protected function showSelectableUsers()
217  {
218  include_once './Services/Contact/classes/class.ilMailMemberSearchTableGUI.php';
219  include_once './Services/Contact/classes/class.ilMailMemberSearchDataProvider.php';
220 
221  $this->tpl->getStandardTemplate();
222  $tbl = new ilMailMemberSearchTableGUI($this);
224  $tbl->setData($provider->getData());
225 
226  $this->tpl->setContent($tbl->getHTML());
227  }
228 
232  protected function sendMailToSelectedUsers()
233  {
234  if (!count($_POST['user_ids'])) {
235  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
236  $this->showSelectableUsers();
237  return false;
238  }
239 
240  $rcps = array();
241  foreach ($_POST['user_ids'] as $usr_id) {
242  $rcps[] = ilObjUser::_lookupLogin($usr_id);
243  }
244 
245  if (!count(array_filter($rcps))) {
246  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
247  $this->showSelectableUsers();
248  return false;
249  }
250 
251  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
253 
255  $this,
256  'members',
257  array(),
258  array(
259  'type' => 'new',
260  'sig' => $this->gui->createMailSignature()
261  ),
262  $this->generateContextArray()
263  ));
264 
265  return true;
266  }
267 
271  protected function showSearchForm()
272  {
273  $this->storeReferer();
274 
275  $form = $this->initMailToMembersForm();
276  $this->tpl->setContent($form->getHTML());
277  }
278 
282  protected function getObjParticipants()
283  {
284  return $this->objParticipants;
285  }
286 
291  {
292  $this->objParticipants = $objParticipants;
293  }
294 
298  protected function initMailToMembersForm()
299  {
300  $this->lng->loadLanguageModule('mail');
301 
302  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
303  $form = new ilPropertyFormGUI();
304  $form->setTitle($this->lng->txt('mail_members'));
305 
306  $form->setFormAction($this->ctrl->getFormAction($this, 'nextMailForm'));
307 
308  $radio_grp = $this->getMailRadioGroup();
309 
310  $form->addItem($radio_grp);
311  $form->addCommandButton('nextMailForm', $this->lng->txt('mail_members_search_continue'));
312  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
313 
314  return $form;
315  }
316 
320  private function getMailRoles()
321  {
322  return $this->mail_roles;
323  }
324 
328  protected function getMailRadioGroup()
329  {
330  $mail_roles = $this->getMailRoles();
331 
332  $radio_grp = new ilRadioGroupInputGUI('', 'mail_member_type');
333 
334  $radio_sel_users = new ilRadioOption($this->lng->txt('mail_sel_users'), 'mail_sel_users');
335 
336  $radio_roles = new ilRadioOption($this->objMailMemberRoles->getRadioOptionTitle(), 'mail_member_roles');
337  foreach ($mail_roles as $role) {
338  $chk_role = new ilCheckboxInputGUI($role['form_option_title'], 'roles[]');
339  $chk_role->setValue($role['role_id']);
340  $chk_role->setInfo($role['mailbox']);
341  $radio_roles->addSubItem($chk_role);
342  }
343 
344  $radio_grp->setValue('mail_member_roles');
345 
346  $radio_grp->addOption($radio_sel_users);
347  $radio_grp->addOption($radio_roles);
348 
349  return $radio_grp;
350  }
351 }
static _lookupLogin($a_user_id)
lookup login
This class represents an option in a radio group.
$_SESSION["AccountId"]
__construct($gui, $ref_id, ilAbstractMailMemberRoles $objMailMemberRoles)
ilMailMemberSearchGUI constructor.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$tbl
Definition: example_048.php:81
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
This class represents a checkbox property in a property form.
Class ilMailMemberSearchGUI.
This class represents a property in a property form.
if(isset($_POST['submit'])) $form
addSubItem($a_item)
Add Subitem.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const CONTEXT_KEY
Session parameter for the context.
static getRedirectTarget($gui, $cmd, array $gui_params=array(), array $mail_params=array(), array $context_params=array())
static setRecipients(array $recipients)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
Class ilMailMemberSearchDataProvider.
static redirect($a_script)
Class ilAbstractMailMemberRoles.
$_POST["username"]