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