ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
107 case 'ilbuddysystemgui':
108 if(!ilBuddySystem::getInstance()->isEnabled())
109 {
110 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
111 }
112
113 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemGUI.php';
114 $this->ctrl->saveParameter($this, 'search_crs');
115 $this->ctrl->setReturn($this, 'showMembers');
116 $this->ctrl->forwardCommand(new ilBuddySystemGUI());
117 break;
118
119 default:
120 if (!($cmd = $this->ctrl->getCmd()))
121 {
122 $cmd = "showMyCourses";
123 }
124
125 $this->$cmd();
126 break;
127 }
128 return true;
129 }
130
131 function mail()
132 {
133 if ($_GET["view"] == "mycourses")
134 {
135 $ids = ((int)$_GET['search_crs']) ? array((int)$_GET['search_crs']) : $_POST['search_crs'];
136
137 if ($ids)
138 {
139 $this->mailCourses();
140 }
141 else
142 {
143 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
144 $this->showMyCourses();
145 }
146 }
147 else if ($_GET["view"] == "crs_members")
148 {
149 $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
150 if ($ids)
151 {
152 $this->mailMembers();
153 }
154 else
155 {
156 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
157 $this->showMembers();
158 }
159 }
160 else
161 {
162 $this->showMyCourses();
163 }
164 }
165
166 function mailCourses()
167 {
168 $members = array();
169
170 if (!is_array($old_mail_data = $this->umail->getSavedData()))
171 {
172 $this->umail->savePostData(
173 $this->user->getId(),
174 array(),
175 "",
176 "",
177 "",
178 "",
179 "",
180 "",
181 "",
182 ""
183 );
184 }
185
186 require_once './Services/Object/classes/class.ilObject.php';
187 require_once 'Services/Mail/classes/Address/Type/class.ilMailRoleAddressType.php';
188 $ids = ((int)$_GET['search_crs']) ? array((int)$_GET['search_crs']) : $_POST['search_crs'];
189
190 foreach ($ids as $crs_id)
191 {
192 $ref_ids = ilObject::_getAllReferences($crs_id);
193
194 foreach ($ref_ids as $ref_id)
195 {
196 $roles = $this->rbacreview->getAssignableChildRoles($ref_id);
197 foreach ($roles as $role)
198 {
199 if (substr($role['title'], 0, 14) == 'il_crs_member_' ||
200 substr($role['title'], 0, 13) == 'il_crs_tutor_' ||
201 substr($role['title'], 0, 13) == 'il_crs_admin_')
202 {
203 if(isset($old_mail_data['rcp_to']) &&
204 trim($old_mail_data['rcp_to']) != '')
205 {
206 $rcpt = ilMailRoleAddressType::getRoleMailboxAddress($role['obj_id']);
207 if(!$this->umail->existsRecipient($rcpt, $old_mail_data['rcp_to']))
208 {
209 array_push($members, $rcpt);
210 }
211 }
212 else
213 {
214 array_push($members, ilMailRoleAddressType::getRoleMailboxAddress($role['obj_id']));
215 }
216 }
217 }
218 }
219 }
220
221 if(count($members))
222 $mail_data = $this->umail->appendSearchResult($members, 'to');
223 else
224 $mail_data = $this->umail->getSavedData();
225
226 $this->umail->savePostData(
227 $mail_data["user_id"],
228 $mail_data["attachments"],
229 $mail_data["rcp_to"],
230 $mail_data["rcp_cc"],
231 $mail_data["rcp_bcc"],
232 $mail_data["m_type"],
233 $mail_data["m_email"],
234 $mail_data["m_subject"],
235 $mail_data["m_message"],
236 $mail_data["use_placeholders"],
237 $mail_data['tpl_ctx_id'],
238 $mail_data['tpl_ctx_params']
239 );
240
241 #$this->ctrl->returnToParent($this);
242 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
243 }
244
245 function mailMembers()
246 {
247 $members = array();
248
249 if (!is_array($this->umail->getSavedData()))
250 {
251 $this->umail->savePostData(
252 $this->user->getId(),
253 array(),
254 "",
255 "",
256 "",
257 "",
258 "",
259 "",
260 "",
261 ""
262 );
263 }
264
265 $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
266
267 foreach ($ids as $member)
268 {
269 $login = ilObjUser::_lookupLogin($member);
270 array_push($members, $login);
271 }
272 $mail_data = $this->umail->appendSearchResult($members,"to");
273
274 $this->umail->savePostData(
275 $mail_data["user_id"],
276 $mail_data["attachments"],
277 $mail_data["rcp_to"],
278 $mail_data["rcp_cc"],
279 $mail_data["rcp_bcc"],
280 $mail_data["m_type"],
281 $mail_data["m_email"],
282 $mail_data["m_subject"],
283 $mail_data["m_message"],
284 $mail_data["use_placeholders"],
285 $mail_data['tpl_ctx_id'],
286 $mail_data['tpl_ctx_params']
287 );
288
289 #$this->ctrl->returnToParent($this);
290 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
291 }
292
296 function cancel()
297 {
298 if ($_GET["view"] == "mycourses" &&
299 $_GET["ref"] == "mail")
300 {
301 $this->ctrl->returnToParent($this);
302 }
303 else
304 {
305 $this->showMyCourses();
306 }
307 }
308
312 public function showMyCourses()
313 {
314 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
315
316 $this->tpl->setTitle($this->lng->txt('mail_addressbook') );
317
318 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
319
320 $_GET['view'] = 'mycourses';
321
322 $this->lng->loadLanguageModule('crs');
323
324 include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
325 $table = new ilMailSearchCoursesTableGUI($this, "crs", $_GET["ref"]);
326 $table->setId('search_crs_tbl');
327 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
328 $crs_ids = ilCourseParticipants::_getMembershipByType($this->user->getId(), 'crs');
329 $counter = 0;
330 $tableData = array();
331 if (is_array($crs_ids) && count($crs_ids) > 0)
332 {
333 $num_courses_hidden_members = 0;
334 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
335 foreach($crs_ids as $crs_id)
336 {
340 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
341
342 $isOffline = !$oTmpCrs->isActivated();
343 $hasUntrashedReferences = ilObject::_hasUntrashedReference($crs_id);
344 $showMemberListEnabled = (boolean)$oTmpCrs->getShowMembers();
345 $ref_ids = array_keys(ilObject::_getAllReferences($crs_id));
346 $isPrivilegedUser = $this->rbacsystem->checkAccess('write', $ref_ids[0]);
347
348 if($hasUntrashedReferences && ((!$isOffline && $showMemberListEnabled) || $isPrivilegedUser))
349 {
350 $oCrsParticipants = ilCourseParticipants::_getInstanceByObjId($crs_id);
351 $crs_members = $oCrsParticipants->getParticipants();
352
353 foreach($crs_members as $key => $member)
354 {
355 $tmp_usr = new ilObjUser($member);
356 if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
357 {
358 unset($crs_members[$key]);
359 }
360 }
361 unset($tmp_usr);
362
363 $hiddenMembers = false;
364 if((int)$oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
365 {
366 ++$num_courses_hidden_members;
367 $hiddenMembers = true;
368 }
369 unset($oTmpCrs);
370
371 $ref_ids = ilObject::_getAllReferences($crs_id);
372 $ref_id = current($ref_ids);
373 $path_arr = $this->tree->getPathFull($ref_id, $this->tree->getRootId());
374 $path_counter = 0;
375 $path = '';
376 foreach($path_arr as $data)
377 {
378 if($path_counter++)
379 {
380 $path .= " -> ";
381 }
382 $path .= $data['title'];
383 }
384 $path = $this->lng->txt('path').': '.$path;
385
386 $current_selection_list = new ilAdvancedSelectionListGUI();
387 $current_selection_list->setListTitle($this->lng->txt("actions"));
388 $current_selection_list->setId("act_".$counter);
389
390 $this->ctrl->setParameter($this, 'search_crs', $crs_id);
391 $this->ctrl->setParameter($this, 'view', 'mycourses');
392
393 if($_GET["ref"] == "mail")
394 {
395 if ($this->mailing_allowed)
396 $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
397 }
398 else if($_GET["ref"] == "wsp")
399 {
400 $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
401 }
402 $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
403
404 $this->ctrl->clearParameters($this);
405
406 $rowData = array
407 (
408 "CRS_ID" => $crs_id,
409 "CRS_NAME" => $this->cache->lookupTitle($crs_id),
410 "CRS_NO_MEMBERS" => count($crs_members),
411 "CRS_PATH" => $path,
412 'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
413 "hidden_members" => $hiddenMembers,
414 );
415 $counter++;
416 $tableData[] = $rowData;
417 }
418 }
419
420 if($num_courses_hidden_members > 0)
421 {
422 $searchTpl->setCurrentBlock('caption_block');
423 $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
424 $searchTpl->parseCurrentBlock();
425 }
426 }
427
428 $searchTpl->setVariable('TXT_MARKED_ENTRIES', $this->lng->txt('marked_entries'));
429
430 $table->setData($tableData);
431 if($_GET['ref'] == 'mail') $this->tpl->setVariable('BUTTON_CANCEL', $this->lng->txt('cancel'));
432
433 $searchTpl->setVariable('TABLE', $table->getHtml());
434 $this->tpl->setContent($searchTpl->get());
435
436 if($_GET["ref"] != "wsp")
437 {
438 $this->tpl->show();
439 }
440 }
441
445 public function showMembers()
446 {
447 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
448
449 if ($_GET["search_crs"] != "")
450 {
451 $_POST["search_crs"] = explode(",", $_GET["search_crs"]);
452 $_GET["search_crs"] = "";
453 }
454 else if ($_SESSION["search_crs"] != "")
455 {
456 $_POST["search_crs"] = explode(",", $_SESSION["search_crs"]);
457 $_SESSION["search_crs"] = "";
458 }
459
460 if(is_array($_POST['search_crs']))
461 {
462 $_POST['search_crs'] = array_filter(array_map('intval', $_POST['search_crs']));
463 }
464
465 if (!is_array($_POST["search_crs"]) ||
466 count($_POST["search_crs"]) == 0)
467 {
468 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
469 $this->showMyCourses();
470 }
471 else
472 {
473 foreach($_POST['search_crs'] as $crs_id)
474 {
475 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
476 if($oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
477 {
478 unset($_POST['search_crs']);
479 ilUtil::sendInfo($this->lng->txt('mail_crs_list_members_not_available_for_at_least_one_crs'));
480 return $this->showMyCourses();
481 }
482 unset($oTmpCrs);
483 }
484
485 $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
486
487 $this->ctrl->setParameter($this, "view", "crs_members");
488 if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
489 if (is_array($_POST["search_crs"])) $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
490 $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
491 $this->ctrl->clearParameters($this);
492
493 $this->lng->loadLanguageModule('crs');
494 include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
495 $context = $_GET["ref"] ? $_GET["ref"] : "mail";
496 $table = new ilMailSearchCoursesMembersTableGUI($this, 'crs', $context);
497 $tableData = array();
498 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
499 foreach($_POST["search_crs"] as $crs_id)
500 {
501 $members_obj = ilCourseParticipants::_getinstanceByObjId($crs_id);
502 $tmp_members = $members_obj->getParticipants();
503 $course_members = ilUtil::_sortIds($tmp_members, 'usr_data', 'lastname', 'usr_id');
504
505 foreach ($course_members as $member)
506 {
507 $tmp_usr = new ilObjUser($member);
508 if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
509 {
510 unset($tmp_usr);
511 continue;
512 }
513 unset($tmp_usr);
514
515 $name = ilObjUser::_lookupName($member);
516 $login = ilObjUser::_lookupLogin($member);
517
518 $fullname = "";
519 if(in_array(ilObjUser::_lookupPref($member, 'public_profile'), array("g", 'y')))
520 $fullname = $name['lastname'].', '.$name['firstname'];
521
522 $rowData = array(
523 'members_id' => $member,
524 'members_login' => $login,
525 'members_name' => $fullname,
526 'members_crs_grp' => $this->cache->lookupTitle($crs_id),
527 'search_crs' => $crs_id
528 );
529
530 if('mail' == $context && ilBuddySystem::getInstance()->isEnabled())
531 {
532 $relation = ilBuddyList::getInstanceByGlobalUser()->getRelationByUserId($member);
533 $state_name = ilStr::convertUpperCamelCaseToUnderscoreCase($relation->getState()->getName());
534 $rowData['status'] = '';
535 if($member != $this->user->getId())
536 {
537 if($relation->isOwnedByRequest())
538 {
539 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_a');
540 }
541 else
542 {
543 $rowData['status'] = $this->lng->txt('buddy_bs_state_' . $state_name . '_p');
544 }
545 }
546 }
547
548 $tableData[] = $rowData;
549 }
550 }
551 $table->setData($tableData);
552 if (count($tableData))
553 {
554 $searchTpl->setVariable("TXT_MARKED_ENTRIES", $this->lng->txt("marked_entries"));
555 }
556
557 $searchTpl->setVariable('TABLE', $table->getHtml());
558 $this->tpl->setContent($searchTpl->get());
559
560 if($_GET["ref"] != "wsp")
561 {
562 $this->tpl->show();
563 }
564 }
565 }
566
567 function share()
568 {
569 if ($_GET["view"] == "mycourses")
570 {
571 $ids = $_REQUEST["search_crs"];
572 if (sizeof($ids))
573 {
574 $this->addPermission($ids);
575 }
576 else
577 {
578 ilUtil::sendInfo($this->lng->txt("mail_select_course"));
579 $this->showMyCourses();
580 }
581 }
582 else if ($_GET["view"] == "crs_members")
583 {
584 $ids = $_REQUEST["search_members"];
585 if (sizeof($ids))
586 {
587 $this->addPermission($ids);
588 }
589 else
590 {
591 ilUtil::sendInfo($this->lng->txt("mail_select_one_entry"));
592 $this->showMembers();
593 }
594 }
595 else
596 {
597 $this->showMyCourses();
598 }
599 }
600
601 protected function addPermission($a_obj_ids)
602 {
603 if(!is_array($a_obj_ids))
604 {
605 $a_obj_ids = array($a_obj_ids);
606 }
607
608 $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
609 $added = false;
610 foreach($a_obj_ids as $object_id)
611 {
612 if(!in_array($object_id, $existing))
613 {
614 $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
615 }
616 }
617
618 if($added)
619 {
620 ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
621 }
622 $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
623 }
624}
user()
Definition: user.php:4
$path
Definition: aliased.php:25
$_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.
__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)
http redirect to other script
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$counter
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
global $DIC