ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMailSearchCoursesGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once './Services/User/classes/class.ilObjUser.php';
6require_once "Services/Mail/classes/class.ilMailbox.php";
7require_once "Services/Mail/classes/class.ilFormatMail.php";
8require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
9
17{
21 protected $tpl;
22
26 protected $ctrl;
27
31 protected $lng;
32
36 protected $user;
37
41 protected $error;
42
46 protected $rbacsystem;
47
51 protected $rbacreview;
52
56 protected $tree;
57
61 protected $cache;
62
66 protected $umail;
67
72
73 public function __construct($wsp_access_handler = null, $wsp_node_id = null)
74 {
75 global $DIC;
76
77 $this->tpl = $DIC['tpl'];
78 $this->ctrl = $DIC['ilCtrl'];
79 $this->lng = $DIC['lng'];
80 $this->user = $DIC['ilUser'];
81 $this->error = $DIC['ilErr'];
82 $this->rbacsystem = $DIC['rbacsystem'];
83 $this->rbacreview = $DIC['rbacreview'];
84 $this->tree = $DIC['tree'];
85 $this->cache = $DIC['ilObjDataCache'];
86
87 // personal workspace
88 $this->wsp_access_handler = $wsp_access_handler;
89 $this->wsp_node_id = $wsp_node_id;
90
91 // check if current user may send mails
92 include_once "Services/Mail/classes/class.ilMail.php";
93 $mail = new ilMail($this->user->getId());
94 $this->mailing_allowed = $this->rbacsystem->checkAccess('internal_mail', $mail->getMailObjectReferenceId());
95
96 $this->ctrl->saveParameter($this, "mobj_id");
97 $this->ctrl->saveParameter($this, "ref");
98
99 $this->umail = new ilFormatMail($this->user->getId());
100 }
101
102 public function executeCommand()
103 {
104 $forward_class = $this->ctrl->getNextClass($this);
105 switch ($forward_class) {
106 case 'ilbuddysystemgui':
107 if (!ilBuddySystem::getInstance()->isEnabled()) {
108 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
109 }
110
111 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
112 $this->ctrl->saveParameter($this, 'search_crs');
113 $this->ctrl->setReturn($this, 'showMembers');
114 $this->ctrl->forwardCommand(new ilBuddySystemGUI());
115 break;
116
117 default:
118 if (!($cmd = $this->ctrl->getCmd())) {
119 $cmd = "showMyCourses";
120 }
121
122 $this->$cmd();
123 break;
124 }
125 return true;
126 }
127
128 public function mail()
129 {
130 if ($_GET["view"] == "mycourses") {
131 $ids = ((int) $_GET['search_crs']) ? array((int) $_GET['search_crs']) : $_POST['search_crs'];
132
133 if ($ids) {
134 $this->mailCourses();
135 } else {
136 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
137 $this->showMyCourses();
138 }
139 } elseif ($_GET["view"] == "crs_members") {
140 $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
141 if ($ids) {
142 $this->mailMembers();
143 } else {
144 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
145 $this->showMembers();
146 }
147 } else {
148 $this->showMyCourses();
149 }
150 }
151
152 public function mailCourses()
153 {
154 $members = array();
155
156 if (!is_array($old_mail_data = $this->umail->getSavedData())) {
157 $this->umail->savePostData(
158 $this->user->getId(),
159 array(),
160 "",
161 "",
162 "",
163 "",
164 "",
165 "",
166 "",
167 ""
168 );
169 }
170
171 require_once './Services/Object/classes/class.ilObject.php';
172 require_once 'Services/Mail/classes/Address/Type/class.ilMailRoleAddressType.php';
173 $ids = ((int) $_GET['search_crs']) ? array((int) $_GET['search_crs']) : $_POST['search_crs'];
174
175 foreach ($ids as $crs_id) {
176 $ref_ids = ilObject::_getAllReferences($crs_id);
177
178 foreach ($ref_ids as $ref_id) {
179 $roles = $this->rbacreview->getAssignableChildRoles($ref_id);
180 foreach ($roles as $role) {
181 if (substr($role['title'], 0, 14) == 'il_crs_member_' ||
182 substr($role['title'], 0, 13) == 'il_crs_tutor_' ||
183 substr($role['title'], 0, 13) == 'il_crs_admin_') {
184 if (isset($old_mail_data['rcp_to']) &&
185 trim($old_mail_data['rcp_to']) != '') {
186 $rcpt = ilMailRoleAddressType::getRoleMailboxAddress($role['obj_id']);
187 if (!$this->umail->existsRecipient($rcpt, $old_mail_data['rcp_to'])) {
188 array_push($members, $rcpt);
189 }
190 } else {
191 array_push($members, ilMailRoleAddressType::getRoleMailboxAddress($role['obj_id']));
192 }
193 }
194 }
195 }
196 }
197
198 if (count($members)) {
199 $mail_data = $this->umail->appendSearchResult($members, 'to');
200 } else {
201 $mail_data = $this->umail->getSavedData();
202 }
203
204 $this->umail->savePostData(
205 $mail_data["user_id"],
206 $mail_data["attachments"],
207 $mail_data["rcp_to"],
208 $mail_data["rcp_cc"],
209 $mail_data["rcp_bcc"],
210 $mail_data["m_type"],
211 $mail_data["m_email"],
212 $mail_data["m_subject"],
213 $mail_data["m_message"],
214 $mail_data["use_placeholders"],
215 $mail_data['tpl_ctx_id'],
216 $mail_data['tpl_ctx_params']
217 );
218
219 #$this->ctrl->returnToParent($this);
220 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
221 }
222
223 public function mailMembers()
224 {
225 $members = array();
226
227 if (!is_array($this->umail->getSavedData())) {
228 $this->umail->savePostData(
229 $this->user->getId(),
230 array(),
231 "",
232 "",
233 "",
234 "",
235 "",
236 "",
237 "",
238 ""
239 );
240 }
241
242 $ids = ((int) $_GET['search_members']) ? array((int) $_GET['search_members']) : $_POST['search_members'];
243
244 foreach ($ids as $member) {
245 $login = ilObjUser::_lookupLogin($member);
246 array_push($members, $login);
247 }
248 $mail_data = $this->umail->appendSearchResult($members, "to");
249
250 $this->umail->savePostData(
251 $mail_data["user_id"],
252 $mail_data["attachments"],
253 $mail_data["rcp_to"],
254 $mail_data["rcp_cc"],
255 $mail_data["rcp_bcc"],
256 $mail_data["m_type"],
257 $mail_data["m_email"],
258 $mail_data["m_subject"],
259 $mail_data["m_message"],
260 $mail_data["use_placeholders"],
261 $mail_data['tpl_ctx_id'],
262 $mail_data['tpl_ctx_params']
263 );
264
265 #$this->ctrl->returnToParent($this);
266 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
267 }
268
272 public function cancel()
273 {
274 if ($_GET["view"] == "mycourses" &&
275 $_GET["ref"] == "mail") {
276 $this->ctrl->returnToParent($this);
277 } else {
278 $this->showMyCourses();
279 }
280 }
281
285 public function showMyCourses()
286 {
287 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
288
289 $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
290
291 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
292
293 $_GET['view'] = 'mycourses';
294
295 $this->lng->loadLanguageModule('crs');
296
297 include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
298 $table = new ilMailSearchCoursesTableGUI($this, "crs", $_GET["ref"]);
299 $table->setId('search_crs_tbl');
300 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
301 $crs_ids = ilCourseParticipants::_getMembershipByType($this->user->getId(), 'crs');
302 $counter = 0;
303 $tableData = array();
304 if (is_array($crs_ids) && count($crs_ids) > 0) {
305 $num_courses_hidden_members = 0;
306 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
307 foreach ($crs_ids as $crs_id) {
311 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
312
313 $isOffline = !$oTmpCrs->isActivated();
314 $hasUntrashedReferences = ilObject::_hasUntrashedReference($crs_id);
315 $showMemberListEnabled = (boolean) $oTmpCrs->getShowMembers();
316 $ref_ids = array_keys(ilObject::_getAllReferences($crs_id));
317 $isPrivilegedUser = $this->rbacsystem->checkAccess('write', $ref_ids[0]);
318
319 if ($hasUntrashedReferences && ((!$isOffline && $showMemberListEnabled) || $isPrivilegedUser)) {
320 $oCrsParticipants = ilCourseParticipants::_getInstanceByObjId($crs_id);
321 $crs_members = $oCrsParticipants->getParticipants();
322
323 foreach ($crs_members as $key => $member) {
324 $tmp_usr = new ilObjUser($member);
325 if ($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false) {
326 unset($crs_members[$key]);
327 }
328 }
329 unset($tmp_usr);
330
331 $hiddenMembers = false;
332 if ((int) $oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED) {
333 ++$num_courses_hidden_members;
334 $hiddenMembers = true;
335 }
336 unset($oTmpCrs);
337
338 $ref_ids = ilObject::_getAllReferences($crs_id);
339 $ref_id = current($ref_ids);
340 $path_arr = $this->tree->getPathFull($ref_id, $this->tree->getRootId());
341 $path_counter = 0;
342 $path = '';
343 foreach ($path_arr as $data) {
344 if ($path_counter++) {
345 $path .= " -> ";
346 }
347 $path .= $data['title'];
348 }
349 $path = $this->lng->txt('path') . ': ' . $path;
350
351 $current_selection_list = new ilAdvancedSelectionListGUI();
352 $current_selection_list->setListTitle($this->lng->txt("actions"));
353 $current_selection_list->setId("act_" . $counter);
354
355 $this->ctrl->setParameter($this, 'search_crs', $crs_id);
356 $this->ctrl->setParameter($this, 'view', 'mycourses');
357
358 if ($_GET["ref"] == "mail") {
359 if ($this->mailing_allowed) {
360 $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
361 }
362 } elseif ($_GET["ref"] == "wsp") {
363 $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
364 }
365 $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
366
367 $this->ctrl->clearParameters($this);
368
369 $rowData = array(
370 "CRS_ID" => $crs_id,
371 "CRS_NAME" => $this->cache->lookupTitle($crs_id),
372 "CRS_NO_MEMBERS" => count($crs_members),
373 "CRS_PATH" => $path,
374 'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
375 "hidden_members" => $hiddenMembers,
376 );
377 $counter++;
378 $tableData[] = $rowData;
379 }
380 }
381
382 if ($num_courses_hidden_members > 0) {
383 $searchTpl->setCurrentBlock('caption_block');
384 $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
385 $searchTpl->parseCurrentBlock();
386 }
387 }
388
389 $searchTpl->setVariable('TXT_MARKED_ENTRIES', $this->lng->txt('marked_entries'));
390
391 $table->setData($tableData);
392 if ($_GET['ref'] == 'mail') {
393 $this->tpl->setVariable('BUTTON_CANCEL', $this->lng->txt('cancel'));
394 }
395
396 $searchTpl->setVariable('TABLE', $table->getHtml());
397 $this->tpl->setContent($searchTpl->get());
398
399 if ($_GET["ref"] != "wsp") {
400 $this->tpl->show();
401 }
402 }
403
407 public function showMembers()
408 {
409 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
410
411 if ($_GET["search_crs"] != "") {
412 $_POST["search_crs"] = explode(",", $_GET["search_crs"]);
413 $_GET["search_crs"] = "";
414 } elseif ($_SESSION["search_crs"] != "") {
415 $_POST["search_crs"] = explode(",", $_SESSION["search_crs"]);
416 $_SESSION["search_crs"] = "";
417 }
418
419 if (is_array($_POST['search_crs'])) {
420 $_POST['search_crs'] = array_filter(array_map('intval', $_POST['search_crs']));
421 }
422
423 if (!is_array($_POST["search_crs"]) ||
424 count($_POST["search_crs"]) == 0) {
425 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
426 $this->showMyCourses();
427 } else {
428 foreach ($_POST['search_crs'] as $crs_id) {
429 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
430 if ($oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED) {
431 unset($_POST['search_crs']);
432 ilUtil::sendInfo($this->lng->txt('mail_crs_list_members_not_available_for_at_least_one_crs'));
433 return $this->showMyCourses();
434 }
435 unset($oTmpCrs);
436 }
437
438 $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
439
440 $this->ctrl->setParameter($this, "view", "crs_members");
441 if ($_GET["ref"] != "") {
442 $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
443 }
444 if (is_array($_POST["search_crs"])) {
445 $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
446 }
447 $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
448 $this->ctrl->clearParameters($this);
449
450 $this->lng->loadLanguageModule('crs');
451 include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
452 $context = $_GET["ref"] ? $_GET["ref"] : "mail";
453 $table = new ilMailSearchCoursesMembersTableGUI($this, 'crs', $context, $_POST["search_crs"]);
454 $tableData = array();
455 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
456 foreach ($_POST["search_crs"] as $crs_id) {
457 $members_obj = ilCourseParticipants::_getinstanceByObjId($crs_id);
458 $tmp_members = $members_obj->getParticipants();
459 $course_members = ilUtil::_sortIds($tmp_members, 'usr_data', 'lastname', 'usr_id');
460
461 foreach ($course_members as $member) {
462 $tmp_usr = new ilObjUser($member);
463 if ($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false) {
464 unset($tmp_usr);
465 continue;
466 }
467 unset($tmp_usr);
468
469 $name = ilObjUser::_lookupName($member);
470 $login = ilObjUser::_lookupLogin($member);
471
472 $fullname = "";
473 if (in_array(ilObjUser::_lookupPref($member, 'public_profile'), array("g", 'y'))) {
474 $fullname = $name['lastname'] . ', ' . $name['firstname'];
475 }
476
477 $rowData = array(
478 'members_id' => $member,
479 'members_login' => $login,
480 'members_name' => $fullname,
481 'members_crs_grp' => $this->cache->lookupTitle($crs_id),
482 'search_crs' => $crs_id
483 );
484
485 if ('mail' == $context && ilBuddySystem::getInstance()->isEnabled()) {
486 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($member);
487 $state_name = ilStr::convertUpperCamelCaseToUnderscoreCase($relation->getState()->getName());
488 $rowData['status'] = '';
489 if ($member != $this->user->getId()) {
490 if ($relation->isOwnedByRequest()) {
491 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_a');
492 } else {
493 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_p');
494 }
495 }
496 }
497
498 $tableData[] = $rowData;
499 }
500 }
501 $table->setData($tableData);
502
503 if (count($tableData)) {
504 $searchTpl->setVariable("TXT_MARKED_ENTRIES", $this->lng->txt("marked_entries"));
505 }
506
507 $searchTpl->setVariable('TABLE', $table->getHtml());
508 $this->tpl->setContent($searchTpl->get());
509
510 if ($_GET["ref"] != "wsp") {
511 $this->tpl->show();
512 }
513 }
514 }
515
516 public function share()
517 {
518 if ($_GET["view"] == "mycourses") {
519 $ids = $_REQUEST["search_crs"];
520 if (sizeof($ids)) {
521 $this->addPermission($ids);
522 } else {
523 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
524 $this->showMyCourses();
525 }
526 } elseif ($_GET["view"] == "crs_members") {
527 $ids = $_REQUEST["search_members"];
528 if (sizeof($ids)) {
529 $this->addPermission($ids);
530 } else {
531 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
532 $this->showMembers();
533 }
534 } else {
535 $this->showMyCourses();
536 }
537 }
538
539 protected function addPermission($a_obj_ids)
540 {
541 if (!is_array($a_obj_ids)) {
542 $a_obj_ids = array($a_obj_ids);
543 }
544
545 $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
546 $added = false;
547 foreach ($a_obj_ids as $object_id) {
548 if (!in_array($object_id, $existing)) {
549 $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
550 }
551 }
552
553 if ($added) {
554 ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
555 }
556 $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
557 }
558}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
User interface class for advanced drop-down selection lists.
static getInstanceByGlobalUser()
Class ilBuddySystemGUI.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Class UserMail this class handles user mails.
static getRoleMailboxAddress( $a_role_id, $is_localize=true, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
Returns the mailbox address of a role.
__construct($wsp_access_handler=null, $wsp_node_id=null)
This class handles base functions for mail handling.
static _lookupPref($a_usr_id, $a_keyword)
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _getAllReferences($a_id)
get all reference ids of object
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
static convertUpperCamelCaseToUnderscoreCase($value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
special template class to simplify handling of ITX/PEAR
static _sortIds($a_ids, $a_table, $a_field, $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,...
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static redirect($a_script)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$counter
$key
Definition: croninfo.php:18
if($format !==null) $name
Definition: metadata.php:146
if(empty($password)) $table
Definition: pwgen.php:24
global $DIC
Definition: saml.php:7