ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailSearchCoursesGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once './Services/User/classes/class.ilObjUser.php';
25 require_once "Services/Mail/classes/class.ilMailbox.php";
26 require_once "Services/Mail/classes/class.ilFormatMail.php";
27 require_once "Services/Contact/classes/class.ilAddressbook.php";
28 
36 {
37  private $tpl = null;
38  private $ctrl = null;
39  private $lng = null;
40 
41  private $umail = null;
42  private $abook = null;
43 
44  protected $mailing_allowed;
45 
46  public function __construct()
47  {
48  global $tpl, $ilCtrl, $lng, $ilUser, $rbacsystem;
49 
50  $this->tpl = $tpl;
51  $this->ctrl = $ilCtrl;
52  $this->lng = $lng;
53 
54  // check if current user may send mails
55  include_once "Services/Mail/classes/class.ilMail.php";
56  $mail = new ilMail($_SESSION["AccountId"]);
57  $this->mailing_allowed = $rbacsystem->checkAccess('mail_visible',$mail->getMailObjectReferenceId());
58 
59  $this->ctrl->saveParameter($this, "mobj_id");
60 
61  $this->umail = new ilFormatMail($ilUser->getId());
62  $this->abook = new ilAddressbook($ilUser->getId());
63  }
64 
65  public function executeCommand()
66  {
67  $forward_class = $this->ctrl->getNextClass($this);
68  switch($forward_class)
69  {
70  default:
71  if (!($cmd = $this->ctrl->getCmd()))
72  {
73  $cmd = "showMyCourses";
74  }
75 
76  $this->$cmd();
77  break;
78  }
79  return true;
80  }
81 
82  function mail()
83  {
84  global $ilUser, $lng;
85  if ($_GET["view"] == "mycourses")
86  {
87  $ids = ((int)$_GET['search_crs']) ? array((int)$_GET['search_crs']) : $_POST['search_crs'];
88 
89  if ($ids)
90  {
91  $this->mailCourses();
92  }
93  else
94  {
95  ilUtil::sendInfo($lng->txt("mail_select_course"));
96  $this->showMyCourses();
97  }
98  }
99  else if ($_GET["view"] == "crs_members")
100  {
101  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
102  if ($ids)
103  {
104  $this->mailMembers();
105  }
106  else
107  {
108  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
109  $this->showMembers();
110  }
111  }
112  else
113  {
114  $this->showMyCourses();
115  }
116  }
117 
118  function mailCourses()
119  {
120  global $ilUser, $lng, $rbacreview;
121 
122  $members = array();
123 
124  if (!is_array($old_mail_data = $this->umail->getSavedData()))
125  {
126  $this->umail->savePostData(
127  $ilUser->getId(),
128  array(),
129  "",
130  "",
131  "",
132  "",
133  "",
134  "",
135  "",
136  ""
137  );
138  }
139 
140  require_once 'classes/class.ilObject.php';
141 
142  $ids = ((int)$_GET['search_crs']) ? array((int)$_GET['search_crs']) : $_POST['search_crs'];
143 
144  foreach ($ids as $crs_id)
145  {
146  $ref_ids = ilObject::_getAllReferences($crs_id);
147 
148  foreach ($ref_ids as $ref_id)
149  {
150  $roles = $rbacreview->getAssignableChildRoles($ref_id);
151  foreach ($roles as $role)
152  {
153  if (substr($role['title'], 0, 14) == 'il_crs_member_' ||
154  substr($role['title'], 0, 13) == 'il_crs_tutor_' ||
155  substr($role['title'], 0, 13) == 'il_crs_admin_')
156  {
157  if(isset($old_mail_data['rcp_to']) &&
158  trim($old_mail_data['rcp_to']) != '')
159  {
160  $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
161 
162  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
163  array_push($members, $rcpt);
164 
165  unset($rcpt);
166  }
167  else
168  {
169  array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
170  }
171  }
172  }
173  }
174  }
175 
176  if(count($members))
177  $mail_data = $this->umail->appendSearchResult($members, 'to');
178  else
179  $mail_data = $this->umail->getSavedData();
180 
181  $this->umail->savePostData(
182  $mail_data["user_id"],
183  $mail_data["attachments"],
184  $mail_data["rcp_to"],
185  $mail_data["rcp_cc"],
186  $mail_data["rcp_bcc"],
187  $mail_data["m_type"],
188  $mail_data["m_email"],
189  $mail_data["m_subject"],
190  $mail_data["m_message"],
191  $mail_data["use_placeholders"]
192  );
193 
194  #$this->ctrl->returnToParent($this);
195  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
196  }
197 
198  function mailMembers()
199  {
200  $members = array();
201 
202  if (!is_array($this->umail->getSavedData()))
203  {
204  $this->umail->savePostData(
205  $ilUser->getId(),
206  array(),
207  "",
208  "",
209  "",
210  "",
211  "",
212  "",
213  "",
214  ""
215  );
216  }
217 
218  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
219 
220  foreach ($ids as $member)
221  {
222  $login = ilObjUser::_lookupLogin($member);
223  array_push($members, $login);
224  }
225  $mail_data = $this->umail->appendSearchResult($members,"to");
226 
227  $this->umail->savePostData(
228  $mail_data["user_id"],
229  $mail_data["attachments"],
230  $mail_data["rcp_to"],
231  $mail_data["rcp_cc"],
232  $mail_data["rcp_bcc"],
233  $mail_data["m_type"],
234  $mail_data["m_email"],
235  $mail_data["m_subject"],
236  $mail_data["m_message"],
237  $mail_data["use_placeholders"]
238  );
239 
240  #$this->ctrl->returnToParent($this);
241  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
242  }
243 
247  public function adoptMembers()
248  {
249  global $lng;
250  $ids = ((int)$_GET['search_members']) ? array((int)$_GET['search_members']) : $_POST['search_members'];
251 
252  if ((int)$ids && !is_array($ids))
253  $ids = array((int)$ids);
254 
255  if ($ids )
256  {
257  $members = array();
258 
259  foreach ($ids as $member)
260  {
261  $login = ilObjUser::_lookupLogin($member);
262 
263  if (!$this->abook->checkEntry($login))
264  {
265  $name = ilObjUser::_lookupName($member);
266  $email = '';
267  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
268  {
269  $email = ilObjUser::_lookupEmail($member);
270  }
271  $this->abook->addEntry(
272  $login,
273  $name["firstname"],
274  $name["lastname"],
275  $email
276  );
277  }
278  }
279  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
280  }
281  else
282  {
283  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
284  }
285 
286  $this->showMembers();
287  }
288 
292  function cancel()
293  {
294  if ($_GET["view"] == "mycourses" &&
295  $_GET["ref"] == "mail")
296  {
297  $this->ctrl->returnToParent($this);
298  }
299  else
300  {
301  $this->showMyCourses();
302  }
303  }
304 
308  public function showMyCourses()
309  {
310  global $lng, $ilUser, $ilObjDataCache, $tree, $tpl;
311 
312  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
313 
314  $this->tpl->setVariable('HEADER', $this->lng->txt('mail') );
315 
316  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
317 
318  $_GET['view'] = 'mycourses';
319 
320  $lng->loadLanguageModule('crs');
321 
322  include_once 'Services/Contact/classes/class.ilMailSearchCoursesTableGUI.php';
323  $table = new ilMailSearchCoursesTableGUI($this);
324  $table->setId('search_crs_tbl');
325  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
326  $crs_ids = ilCourseParticipants::_getMembershipByType($ilUser->getId(), 'crs');
327  $counter = 0;
328  $tableData = array();
329  if (is_array($crs_ids) && count($crs_ids) > 0)
330  {
331  $num_courses_hidden_members = 0;
332  include_once("./Services/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
333  foreach($crs_ids as $crs_id)
334  {
336  {
337  $oCrsParticipants = ilCourseParticipants::_getInstanceByObjId($crs_id);
338  $crs_members = $oCrsParticipants->getParticipants();
339 
340  foreach($crs_members as $key => $member)
341  {
342  $tmp_usr = new ilObjUser($member);
343  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
344  {
345  unset($crs_members[$key]);
346  }
347  }
348  unset($tmp_usr);
349 
350  $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
351  $hiddenMembers = false;
352  if((int)$oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
353  {
354  ++$num_courses_hidden_members;
355  $hiddenMembers = true;
356  }
357  unset($oTmpCrs);
358 
359  $ref_ids = ilObject::_getAllReferences($crs_id);
360  $ref_id = current($ref_ids);
361  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
362  $path_counter = 0;
363  $path = '';
364  foreach($path_arr as $data)
365  {
366  if($path_counter++)
367  {
368  $path .= " -> ";
369  }
370  $path .= $data['title'];
371  }
372  $path = $this->lng->txt('path').': '.$path;
373 
374  $current_selection_list = new ilAdvancedSelectionListGUI();
375  $current_selection_list->setListTitle($this->lng->txt("actions"));
376  $current_selection_list->setId("act_".$counter);
377 
378  $this->ctrl->setParameter($this, 'search_crs', $crs_id);
379  $this->ctrl->setParameter($this, 'view', 'mycourses');
380 
381  if ($this->mailing_allowed)
382  $current_selection_list->addItem($this->lng->txt("mail_members"), '', $this->ctrl->getLinkTarget($this, "mail"));
383  $current_selection_list->addItem($this->lng->txt("mail_list_members"), '', $this->ctrl->getLinkTarget($this, "showMembers"));
384 
385  $this->ctrl->clearParameters($this);
386 
387  $rowData = array
388  (
389  "CRS_ID" => $crs_id,
390  "CRS_NAME" => $ilObjDataCache->lookupTitle($crs_id),
391  "CRS_NO_MEMBERS" => count($crs_members),
392  "CRS_PATH" => $path,
393  'COMMAND_SELECTION_LIST' => $current_selection_list->getHTML(),
394  "hidden_members" => $hiddenMembers,
395  );
396  $counter++;
397  $tableData[] = $rowData;
398  }
399  }
400 
401  //if((int)$counter)
402  //{
403  // $table->addCommandButton('mail',$lng->txt('mail_members'));
404  // $table->addCommandButton('showMembers',$lng->txt('mail_list_members'));
405  //}
406 
407  if($num_courses_hidden_members > 0)
408  {
409  $searchTpl->setCurrentBlock('caption_block');
410  $searchTpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
411  $searchTpl->parseCurrentBlock();
412  }
413  }
414 
415  $searchTpl->setVariable('TXT_MARKED_ENTRIES', $lng->txt('marked_entries'));
416 
417  $table->setData($tableData);
418  if($_GET['ref'] == 'mail') $this->tpl->setVariable('BUTTON_CANCEL', $lng->txt('cancel'));
419 
420  $searchTpl->setVariable('TABLE', $table->getHtml());
421  $tpl->setContent($searchTpl->get());
422  $tpl->show();
423  }
424 
428  public function showMembers()
429  {
430  global $lng, $ilUser, $ilObjDataCache;
431 
432  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
433 
434  if ($_GET["search_crs"] != "")
435  {
436  $_POST["search_crs"] = explode(",", $_GET["search_crs"]);
437  $_GET["search_crs"] = "";
438  }
439  else if ($_SESSION["search_crs"] != "")
440  {
441  $_POST["search_crs"] = explode(",", $_SESSION["search_crs"]);
442  $_SESSION["search_crs"] = "";
443  }
444 
445  if (!is_array($_POST["search_crs"]) ||
446  count($_POST["search_crs"]) == 0)
447  {
448  ilUtil::sendInfo($lng->txt("mail_select_course"));
449  $this->showMyCourses();
450  }
451  else
452  {
453  foreach($_POST['search_crs'] as $crs_id)
454  {
455  $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
456  if($oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
457  {
458  unset($_POST['search_crs']);
459  ilUtil::sendInfo($lng->txt('mail_crs_list_members_not_available_for_at_least_one_crs'));
460  return $this->showMyCourses();
461  }
462  unset($oTmpCrs);
463  }
464 
465  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
466 
467  $this->ctrl->setParameter($this, "view", "crs_members");
468  if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
469  if (is_array($_POST["search_crs"])) $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
470  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
471  $this->ctrl->clearParameters($this);
472 
473  $lng->loadLanguageModule('crs');
474  include_once 'Services/Contact/classes/class.ilMailSearchCoursesMembersTableGUI.php';
475  $table = new ilMailSearchCoursesMembersTableGUI($this, 'crs');
476  $table->setId('show_crs_mmbrs_tbl');
477  $tableData = array();
478  $searchTpl = new ilTemplate('tpl.mail_search_template.html', true, true, 'Services/Contact');
479  foreach($_POST["search_crs"] as $crs_id)
480  {
481  $members_obj = ilCourseParticipants::_getinstanceByObjId($crs_id);
482  $tmp_members = $members_obj->getParticipants();
483  $course_members = ilUtil::_sortIds($tmp_members,'usr_data','lastname','usr_id');
484 
485  foreach ($course_members as $member)
486  {
487  $tmp_usr = new ilObjUser($member);
488  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
489  {
490  unset($tmp_usr);
491  continue;
492  }
493  unset($tmp_usr);
494 
495  $name = ilObjUser::_lookupName($member);
496  $login = ilObjUser::_lookupLogin($member);
497 
498  $fullname = "";
499  if(in_array(ilObjUser::_lookupPref($member, 'public_profile'), array("g", 'y')))
500  $fullname = $name['lastname'].', '.$name['firstname'];
501 
502  $rowData = array(
503  'MEMBERS_ID' => $member,
504  'MEMBERS_LOGIN' => $login,
505  'MEMBERS_NAME' => $fullname,
506  'MEMBERS_CRS_GRP' => $ilObjDataCache->lookupTitle($crs_id),
507  'MEMBERS_IN_ADDRESSBOOK' => $this->abook->checkEntryByLogin($login) ? $lng->txt("yes") : $lng->txt("no"),
508  'search_crs' => $crs_id
509  );
510  $tableData[] = $rowData;
511  }
512  }
513  $table->setData($tableData);
514  if (count($tableData))
515  {
516  //$table->addCommandButton('mail', $lng->txt("grp_mem_send_mail"));
517  //$table->addCommandButton('adoptMembers', $lng->txt("mail_into_addressbook"));
518 
519  $searchTpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
520  }
521 
522  $searchTpl->setVariable('TABLE', $table->getHtml());
523  $this->tpl->setContent($searchTpl->get());
524  $this->tpl->show();
525  }
526  }
527 
528 }
529 
530 ?>