ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
37  {
38  global $ilCtrl, $tpl, $lng;
39 
40  $this->ctrl = $ilCtrl;
41  $this->tpl = $tpl;
42  $this->lng = $lng;
43 
44  $this->lng->loadLanguageModule('mail');
45  $this->lng->loadLanguageModule('search');
46 
47  $this->gui = $gui;
48  $this->ref_id = $ref_id;
49 
50  $this->objMailMemberRoles = $objMailMemberRoles;
51  $this->mail_roles = $objMailMemberRoles->getMailRoles($ref_id);
52  }
53 
57  public function executeCommand()
58  {
59  $next_class = $this->ctrl->getNextClass($this);
60  $cmd = $this->ctrl->getCmd();
61 
62  $this->ctrl->setReturn($this,'');
63 
64  switch($next_class)
65  {
66  default:
67  switch($cmd)
68  {
69  case 'sendMailToSelectedUsers':
70  $this->sendMailToSelectedUsers();
71  break;
72 
73  case 'showSelectableUsers':
74  $this->showSelectableUsers();
75  break;
76 
77  case 'nextMailForm':
78  $this->nextMailForm();
79  break;
80 
81  case 'cancel':
82  $this->redirectToParentReferer();
83  break;
84 
85  default:
86  if(isset($_GET['returned_from_mail']) && $_GET['returned_from_mail'] == '1')
87  {
88  $this->redirectToParentReferer();
89  }
90  $this->showSearchForm();
91  break;
92  }
93  break;
94  }
95  return true;
96  }
97 
98  private function redirectToParentReferer()
99  {
100  $redirect_target = $this->getStoredReferer();
101  $this->unsetStoredReferer();
102  ilUtil::redirect($redirect_target);
103  }
104 
108  public function storeReferer()
109  {
110  $referer = ilSession::get('referer');
111  ilSession::set('ilMailMemberSearchGUIReferer', $referer);
112  }
113 
117  private function getStoredReferer()
118  {
119  $stored_referer = ilSession::get('ilMailMemberSearchGUIReferer');
120  return (strlen($stored_referer) ? $stored_referer : false);
121  }
122 
126  private function unsetStoredReferer()
127  {
128  ilSession::set('ilMailMemberSearchGUIReferer','');
129  }
130 
134  protected function nextMailForm()
135  {
136  global $lng;
137 
138  $form = $this->initMailToMembersForm();
139  if($form->checkInput())
140  {
141  if($form->getInput('mail_member_type') == 'mail_member_roles')
142  {
143  if(count($form->getInput('roles')) > 0)
144  {
145  $role_mail_boxes = array();
146  $roles = $form->getInput('roles');
147  foreach($roles as $role_id)
148  {
149  $mailbox = $this->objMailMemberRoles->getMailboxRoleAddress($role_id);
150  $role_mail_boxes[] = $mailbox;
151  }
152 
153  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
154  $_SESSION['mail_roles'] = $role_mail_boxes;
155 
157  $this, 'showSearchForm',
158  array('type' => 'role'),
159  array('type' => 'role',
160  'rcp_to' => implode(',', $role_mail_boxes),
161  'sig' => $this->gui->createMailSignature()),
162  $this->generateContextArray()
163  ));
164  }
165  else
166  {
167  $form->setValuesByPost();
168  ilUtil::sendFailure($lng->txt('no_checkbox'));
169  $this->showSearchForm();
170  return;
171  }
172  }
173  else
174  {
175  $this->showSelectableUsers();
176  return;
177  }
178  }
179 
180  $form->setValuesByPost();
181  $this->showSearchForm();
182  }
183 
187  protected function generateContextArray()
188  {
189  global $ilAccess;
190 
191  $context_array = array();
192  require_once 'Modules/Course/classes/class.ilCourseMailTemplateTutorContext.php';
193  if($ilAccess->checkAccess('write',"",$this->ref_id) )
194  {
196  'ref_id' => $this->ref_id,
197  'ts' => time());
198  }
199  return $context_array;
200  }
201 
205  protected function showSelectableUsers()
206  {
207  global $tpl;
208 
209  include_once './Services/Contact/classes/class.ilMailMemberSearchTableGUI.php';
210  include_once './Services/Contact/classes/class.ilMailMemberSearchDataProvider.php';
211 
212  $tpl->getStandardTemplate();
213  $tbl = new ilMailMemberSearchTableGUI($this, 'showSelectableUsers');
215  $tbl->setData($provider->getData());
216 
217  $tpl->setContent($tbl->getHTML());
218  }
219 
223  protected function sendMailToSelectedUsers()
224  {
225  if(!count($_POST['user_ids']))
226  {
227  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
228  $this->showSelectableUsers();
229  return false;
230  }
231 
232  $rcps = array();
233  foreach($_POST['user_ids'] as $usr_id)
234  {
235  $rcps[] = ilObjUser::_lookupLogin($usr_id);
236  }
237 
238  if(!count(array_filter($rcps)))
239  {
240  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
241  $this->showSelectableUsers();
242  return false;
243  }
244 
245  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
247 
249  $this, 'members',
250  array(),
251  array(
252  'type' => 'new',
253  'sig' => $this->gui->createMailSignature()
254  ),
255  $this->generateContextArray()
256  ));
257  return true;
258  }
259 
263  protected function showSearchForm()
264  {
265  global $tpl;
266 
267  $this->storeReferer();
268  $tpl->getStandardTemplate();
269 
270  $form = $this->initMailToMembersForm();
271  $tpl->setContent($form->getHTML());
272  }
273 
277  protected function getObjParticipants()
278  {
279  return $this->objParticipants;
280  }
281 
286  {
287  $this->objParticipants = $objParticipants;
288  }
289 
293  protected function initMailToMembersForm()
294  {
295  $this->lng->loadLanguageModule('mail');
296 
297  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
298  $form = new ilPropertyFormGUI();
299  $form->setTitle($this->lng->txt('mail_members'));
300 
301  $form->setFormAction($this->ctrl->getFormAction($this, 'nextMailForm'));
302 
303  $radio_grp = $this->getMailRadioGroup();
304 
305  $form->addItem($radio_grp);
306  $form->addCommandButton('nextMailForm', $this->lng->txt('mail_members_search_continue'));
307  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
308 
309  return $form;
310  }
311 
315  private function getMailRoles()
316  {
317  return $this->mail_roles;
318  }
319 
323  protected function getMailRadioGroup()
324  {
325  $mail_roles = $this->getMailRoles();
326 
327  $radio_grp = new ilRadioGroupInputGUI('', 'mail_member_type');
328  $radio_roles = new ilRadioOption($this->objMailMemberRoles->getRadioOptionTitle(), 'mail_member_roles');
329  foreach($mail_roles as $role)
330  {
331  $chk_role = new ilCheckboxInputGUI($role['form_option_title'], 'roles[]');
332  $chk_role->setValue($role['role_id']);
333  $chk_role->setInfo($role['mailbox']);
334  $radio_roles->addSubItem($chk_role);
335  }
336 
337  $radio_sel_users = new ilRadioOption($this->lng->txt('mail_sel_users'), 'mail_sel_users');
338 
339  $radio_grp->setValue('mail_member_roles');
340  $radio_grp->addOption($radio_roles);
341  $radio_grp->addOption($radio_sel_users);
342 
343  return $radio_grp;
344  }
345 }
static _lookupLogin($a_user_id)
lookup login
This class represents an option in a radio group.
$_POST['username']
Definition: cron.php:12
$_SESSION["AccountId"]
__construct($gui, $ref_id, ilAbstractMailMemberRoles $objMailMemberRoles)
ilMailMemberSearchGUI constructor.
This class represents a property form user interface.
$_GET["client_id"]
$tbl
Definition: example_048.php:81
$cmd
Definition: sahs_server.php:35
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.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
This class represents a property in a property form.
setValue($a_value)
Set Value.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const CONTEXT_KEY
Session parameter for the context.
$ref_id
Definition: sahs_server.php:39
static getRedirectTarget($gui, $cmd, array $gui_params=array(), array $mail_params=array(), array $context_params=array())
global $lng
Definition: privfeed.php:40
static setRecipients(array $recipients)
Class ilMailMemberSearchDataProvider.
static redirect($a_script)
http redirect to other script
Class ilAbstractMailMemberRoles.