ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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/classes/class.ilAddressbook.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 $this->abook = new ilAddressbook($ilUser->getId());
49 }
50
51 public function executeCommand()
52 {
53 $forward_class = $this->ctrl->getNextClass($this);
54 switch($forward_class)
55 {
56 default:
57 if (!($cmd = $this->ctrl->getCmd()))
58 {
59 $cmd = "showMyCourses";
60 }
61
62 $this->$cmd();
63 break;
64 }
65 return true;
66 }
67
68 function mail()
69 {
70 global $ilUser, $lng;
71 if ($_GET["view"] == "mycourses")
72 {
73 $ids = ((int)$_GET['search_crs']) ? array((int)$_GET['search_crs']) : $_POST['search_crs'];
74
75 if ($ids)
76 {
77 $this->mailCourses();
78 }
79 else
80 {
81 ilUtil::sendInfo($lng->txt("mail_select_course"));
82 $this->showMyCourses();
83 }
84 }
85 else if ($_GET["view"] == "crs_members")
86 {
87 $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
88 if ($ids)
89 {
90 $this->mailMembers();
91 }
92 else
93 {
94 ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
95 $this->showMembers();
96 }
97 }
98 else
99 {
100 $this->showMyCourses();
101 }
102 }
103
104 function mailCourses()
105 {
106 global $ilUser, $lng, $rbacreview;
107
108 $members = array();
109
110 if (!is_array($old_mail_data = $this->umail->getSavedData()))
111 {
112 $this->umail->savePostData(
113 $ilUser->getId(),
114 array(),
115 "",
116 "",
117 "",
118 "",
119 "",
120 "",
121 "",
122 ""
123 );
124 }
125
126 require_once './Services/Object/classes/class.ilObject.php';
127
128 $ids = ((int)$_GET['search_crs']) ? array((int)$_GET['search_crs']) : $_POST['search_crs'];
129
130 foreach ($ids as $crs_id)
131 {
132 $ref_ids = ilObject::_getAllReferences($crs_id);
133
134 foreach ($ref_ids as $ref_id)
135 {
136 $roles = $rbacreview->getAssignableChildRoles($ref_id);
137 foreach ($roles as $role)
138 {
139 if (substr($role['title'], 0, 14) == 'il_crs_member_' ||
140 substr($role['title'], 0, 13) == 'il_crs_tutor_' ||
141 substr($role['title'], 0, 13) == 'il_crs_admin_')
142 {
143 if(isset($old_mail_data['rcp_to']) &&
144 trim($old_mail_data['rcp_to']) != '')
145 {
146 $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
147 if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
148 {
149 array_push($members, $rcpt);
150 }
151 }
152 else
153 {
154 array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
155 }
156 }
157 }
158 }
159 }
160
161 if(count($members))
162 $mail_data = $this->umail->appendSearchResult($members, 'to');
163 else
164 $mail_data = $this->umail->getSavedData();
165
166 $this->umail->savePostData(
167 $mail_data["user_id"],
168 $mail_data["attachments"],
169 $mail_data["rcp_to"],
170 $mail_data["rcp_cc"],
171 $mail_data["rcp_bcc"],
172 $mail_data["m_type"],
173 $mail_data["m_email"],
174 $mail_data["m_subject"],
175 $mail_data["m_message"],
176 $mail_data["use_placeholders"]
177 );
178
179 #$this->ctrl->returnToParent($this);
180 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
181 }
182
183 function mailMembers()
184 {
185 global $ilUser;
186
187 $members = array();
188
189 if (!is_array($this->umail->getSavedData()))
190 {
191 $this->umail->savePostData(
192 $ilUser->getId(),
193 array(),
194 "",
195 "",
196 "",
197 "",
198 "",
199 "",
200 "",
201 ""
202 );
203 }
204
205 $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
206
207 foreach ($ids as $member)
208 {
209 $login = ilObjUser::_lookupLogin($member);
210 array_push($members, $login);
211 }
212 $mail_data = $this->umail->appendSearchResult($members,"to");
213
214 $this->umail->savePostData(
215 $mail_data["user_id"],
216 $mail_data["attachments"],
217 $mail_data["rcp_to"],
218 $mail_data["rcp_cc"],
219 $mail_data["rcp_bcc"],
220 $mail_data["m_type"],
221 $mail_data["m_email"],
222 $mail_data["m_subject"],
223 $mail_data["m_message"],
224 $mail_data["use_placeholders"]
225 );
226
227 #$this->ctrl->returnToParent($this);
228 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
229 }
230
234 public function adoptMembers()
235 {
236 global $lng;
237 $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
238
239 if ((int)$ids && !is_array($ids))
240 $ids = array((int)$ids);
241
242 if ($ids )
243 {
244 $members = array();
245
246 foreach ($ids as $member)
247 {
248 $login = ilObjUser::_lookupLogin($member);
249
250 if (!$this->abook->checkEntry($login))
251 {
252 $name = ilObjUser::_lookupName($member);
253 $email = '';
254 if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
255 {
256 $email = ilObjUser::_lookupEmail($member);
257 }
258 $this->abook->addEntry(
259 $login,
260 $name["firstname"],
261 $name["lastname"],
262 $email
263 );
264 }
265 }
266 ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
267 }
268 else
269 {
270 ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
271 }
272
273 $this->showMembers();
274 }
275
279 function cancel()
280 {
281 if ($_GET["view"] == "mycourses" &&
282 $_GET["ref"] == "mail")
283 {
284 $this->ctrl->returnToParent($this);
285 }
286 else
287 {
288 $this->showMyCourses();
289 }
290 }
291
295 public function showMyCourses()
296 {
297 global $lng, $ilUser, $ilObjDataCache, $tree, $tpl, $rbacsystem;
298
299 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
300
301 $this->tpl->setTitle($this->lng->txt('mail_addressbook') );
302
303 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
304
305 $_GET['view'] = 'mycourses';
306
307 $lng->loadLanguageModule('crs');
308
309 include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
310 $table = new ilMailSearchCoursesTableGUI($this, "crs", $_GET["ref"]);
311 $table->setId('search_crs_tbl');
312 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
313 $crs_ids = ilCourseParticipants::_getMembershipByType($ilUser->getId(), 'crs');
314 $counter = 0;
315 $tableData = array();
316 if (is_array($crs_ids) && count($crs_ids) > 0)
317 {
318 $num_courses_hidden_members = 0;
319 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
320 foreach($crs_ids as $crs_id)
321 {
325 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
326
327 $isOffline = !$oTmpCrs->isActivated();
328 $hasUntrashedReferences = ilObject::_hasUntrashedReference($crs_id);
329 $showMemberListEnabled = (boolean)$oTmpCrs->getShowMembers();
330 $ref_ids = array_keys(ilObject::_getAllReferences($crs_id));
331 $isPrivilegedUser = $rbacsystem->checkAccess('write', $ref_ids[0]);
332
333 if($hasUntrashedReferences && ((!$isOffline && $showMemberListEnabled) || $isPrivilegedUser))
334 {
335 $oCrsParticipants = ilCourseParticipants::_getInstanceByObjId($crs_id);
336 $crs_members = $oCrsParticipants->getParticipants();
337
338 foreach($crs_members as $key => $member)
339 {
340 $tmp_usr = new ilObjUser($member);
341 if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
342 {
343 unset($crs_members[$key]);
344 }
345 }
346 unset($tmp_usr);
347
348 $hiddenMembers = false;
349 if((int)$oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
350 {
351 ++$num_courses_hidden_members;
352 $hiddenMembers = true;
353 }
354 unset($oTmpCrs);
355
356 $ref_ids = ilObject::_getAllReferences($crs_id);
357 $ref_id = current($ref_ids);
358 $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
359 $path_counter = 0;
360 $path = '';
361 foreach($path_arr as $data)
362 {
363 if($path_counter++)
364 {
365 $path .= " -> ";
366 }
367 $path .= $data['title'];
368 }
369 $path = $this->lng->txt('path').': '.$path;
370
371 $current_selection_list = new ilAdvancedSelectionListGUI();
372 $current_selection_list->setListTitle($this->lng->txt("actions"));
373 $current_selection_list->setId("act_".$counter);
374
375 $this->ctrl->setParameter($this, 'search_crs', $crs_id);
376 $this->ctrl->setParameter($this, 'view', 'mycourses');
377
378 if($_GET["ref"] == "mail")
379 {
380 if ($this->mailing_allowed)
381 $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
382 }
383 else if($_GET["ref"] == "wsp")
384 {
385 $current_selection_list->addItem($this->lng->txt("wsp_share_with_members"), '', $this->ctrl->getLinkTarget($this, "share"));
386 }
387 $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
388
389 $this->ctrl->clearParameters($this);
390
391 $rowData = array
392 (
393 "CRS_ID" => $crs_id,
394 "CRS_NAME" => $ilObjDataCache->lookupTitle($crs_id),
395 "CRS_NO_MEMBERS" => count($crs_members),
396 "CRS_PATH" => $path,
397 'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
398 "hidden_members" => $hiddenMembers,
399 );
400 $counter++;
401 $tableData[] = $rowData;
402 }
403 }
404
405 //if((int)$counter)
406 //{
407 // $table->addCommandButton('mail',$lng->txt('mail_members'));
408 // $table->addCommandButton('showMembers',$lng->txt('mail_list_members'));
409 //}
410
411 if($num_courses_hidden_members > 0)
412 {
413 $searchTpl->setCurrentBlock('caption_block');
414 $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
415 $searchTpl->parseCurrentBlock();
416 }
417 }
418
419 $searchTpl->setVariable('TXT_MARKED_ENTRIES', $lng->txt('marked_entries'));
420
421 $table->setData($tableData);
422 if($_GET['ref'] == 'mail') $this->tpl->setVariable('BUTTON_CANCEL', $lng->txt('cancel'));
423
424 $searchTpl->setVariable('TABLE', $table->getHtml());
425 $tpl->setContent($searchTpl->get());
426
427 if($_GET["ref"] != "wsp")
428 {
429 $tpl->show();
430 }
431 }
432
436 public function showMembers()
437 {
438 global $lng, $ilUser, $ilObjDataCache;
439
440 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
441
442 if ($_GET["search_crs"] != "")
443 {
444 $_POST["search_crs"] = explode(",", $_GET["search_crs"]);
445 $_GET["search_crs"] = "";
446 }
447 else if ($_SESSION["search_crs"] != "")
448 {
449 $_POST["search_crs"] = explode(",", $_SESSION["search_crs"]);
450 $_SESSION["search_crs"] = "";
451 }
452
453 if(is_array($_POST['search_crs']))
454 {
455 $_POST['search_crs'] = array_filter(array_map('intval', $_POST['search_crs']));
456 }
457
458 if (!is_array($_POST["search_crs"]) ||
459 count($_POST["search_crs"]) == 0)
460 {
461 ilUtil::sendInfo($lng->txt("mail_select_course"));
462 $this->showMyCourses();
463 }
464 else
465 {
466 foreach($_POST['search_crs'] as $crs_id)
467 {
468 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
469 if($oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
470 {
471 unset($_POST['search_crs']);
472 ilUtil::sendInfo($lng->txt('mail_crs_list_members_not_available_for_at_least_one_crs'));
473 return $this->showMyCourses();
474 }
475 unset($oTmpCrs);
476 }
477
478 $this->tpl->setTitle($this->lng->txt("mail_addressbook"));
479
480 $this->ctrl->setParameter($this, "view", "crs_members");
481 if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
482 if (is_array($_POST["search_crs"])) $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
483 $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
484 $this->ctrl->clearParameters($this);
485
486 $lng->loadLanguageModule('crs');
487 include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
488 $context = $_GET["ref"] ? $_GET["ref"] : "mail";
489 $table = new ilMailSearchCoursesMembersTableGUI($this, 'crs', $context);
490 $table->setId('show_crs_mmbrs_tbl');
491 $tableData = array();
492 $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
493 foreach($_POST["search_crs"] as $crs_id)
494 {
495 $members_obj = ilCourseParticipants::_getinstanceByObjId($crs_id);
496 $tmp_members = $members_obj->getParticipants();
497 $course_members = ilUtil::_sortIds($tmp_members, 'usr_data', 'lastname', 'usr_id');
498
499 foreach ($course_members as $member)
500 {
501 $tmp_usr = new ilObjUser($member);
502 if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
503 {
504 unset($tmp_usr);
505 continue;
506 }
507 unset($tmp_usr);
508
509 $name = ilObjUser::_lookupName($member);
510 $login = ilObjUser::_lookupLogin($member);
511
512 $fullname = "";
513 if(in_array(ilObjUser::_lookupPref($member, 'public_profile'), array("g", 'y')))
514 $fullname = $name['lastname'].', '.$name['firstname'];
515
516 $rowData = array(
517 'members_id' => $member,
518 'members_login' => $login,
519 'members_name' => $fullname,
520 'members_crs_grp' => $ilObjDataCache->lookupTitle($crs_id),
521 'members_in_addressbook' => $this->abook->checkEntryByLogin($login) ? $lng->txt("yes") : $lng->txt("no"),
522 'search_crs' => $crs_id
523 );
524
525 $tableData[] = $rowData;
526 }
527 }
528 $table->setData($tableData);
529 if (count($tableData))
530 {
531 $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
532 }
533
534 $searchTpl->setVariable('TABLE', $table->getHtml());
535 $this->tpl->setContent($searchTpl->get());
536
537 if($_GET["ref"] != "wsp")
538 {
539 $this->tpl->show();
540 }
541 }
542 }
543
544 function share()
545 {
546 global $lng;
547
548 if ($_GET["view"] == "mycourses")
549 {
550 $ids = $_REQUEST["search_crs"];
551 if (sizeof($ids))
552 {
553 $this->addPermission($ids);
554 }
555 else
556 {
557 ilUtil::sendInfo($lng->txt("mail_select_course"));
558 $this->showMyCourses();
559 }
560 }
561 else if ($_GET["view"] == "crs_members")
562 {
563 $ids = $_REQUEST["search_members"];
564 if (sizeof($ids))
565 {
566 $this->addPermission($ids);
567 }
568 else
569 {
570 ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
571 $this->showMembers();
572 }
573 }
574 else
575 {
576 $this->showMyCourses();
577 }
578 }
579
580 protected function addPermission($a_obj_ids)
581 {
582 if(!is_array($a_obj_ids))
583 {
584 $a_obj_ids = array($a_obj_ids);
585 }
586
587 $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
588 $added = false;
589 foreach($a_obj_ids as $object_id)
590 {
591 if(!in_array($object_id, $existing))
592 {
593 $added = $this->wsp_access_handler->addPermission($this->wsp_node_id, $object_id);
594 }
595 }
596
597 if($added)
598 {
599 ilUtil::sendSuccess($this->lng->txt("wsp_share_success"), true);
600 }
601 $this->ctrl->redirectByClass("ilworkspaceaccessgui", "share");
602 }
603}
604
605?>
$_GET["client_id"]
Mail Box class Base class for creating and handling mail boxes.
User interface class for advanced drop-down selection lists.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Class UserMail this class handles user mails.
__construct($wsp_access_handler=null, $wsp_node_id=null)
adoptMembers()
Take over course members to addressbook.
Class Mail this class handles base functions for mail handling.
_lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
_lookupEmail($a_user_id)
Lookup email.
_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
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
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
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