ILIAS  Release_3_10_x_branch Revision 61812
 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/Mail/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  public function __construct()
45  {
46  global $tpl, $ilCtrl, $lng, $ilUser;
47 
48  $this->tpl = $tpl;
49  $this->ctrl = $ilCtrl;
50  $this->lng = $lng;
51 
52  $this->ctrl->saveParameter($this, "mobj_id");
53 
54  $this->umail = new ilFormatMail($ilUser->getId());
55  $this->abook = new ilAddressbook($ilUser->getId());
56  }
57 
58  public function executeCommand()
59  {
60  $forward_class = $this->ctrl->getNextClass($this);
61  switch($forward_class)
62  {
63  default:
64  if (!($cmd = $this->ctrl->getCmd()))
65  {
66  $cmd = "showMyCourses";
67  }
68 
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
75  function mail()
76  {
77  global $ilUser, $lng;
78 
79  if ($_GET["view"] == "mycourses")
80  {
81  if (is_array($_POST["search_crs"]))
82  {
83  $this->mailCourses();
84  }
85  else
86  {
87  ilUtil::sendInfo($lng->txt("mail_select_course"));
88  $this->showMyCourses();
89  }
90  }
91  else if ($_GET["view"] == "crs_members")
92  {
93  if (is_array($_POST["search_members"]))
94  {
95  $this->mailMembers();
96  }
97  else
98  {
99  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
100  $this->showMembers();
101  }
102  }
103  else
104  {
105  $this->showMyCourses();
106  }
107  }
108 
109  function mailCourses()
110  {
111  global $ilUser, $lng, $rbacreview;
112 
113  $members = array();
114 
115  if (!is_array($old_mail_data = $this->umail->getSavedData()))
116  {
117  $this->umail->savePostData(
118  $ilUser->getId(),
119  array(),
120  "",
121  "",
122  "",
123  "",
124  "",
125  "",
126  "",
127  ""
128  );
129  }
130 
131  require_once 'classes/class.ilObject.php';
132  foreach ($_POST["search_crs"] as $crs_id)
133  {
134  $ref_ids = ilObject::_getAllReferences($crs_id);
135  foreach ($ref_ids as $ref_id)
136  {
137  $roles = $rbacreview->getAssignableChildRoles($ref_id);
138  foreach ($roles as $role)
139  {
140  if (substr($role['title'], 0, 14) == 'il_crs_member_' ||
141  substr($role['title'], 0, 13) == 'il_crs_tutor_' ||
142  substr($role['title'], 0, 13) == 'il_crs_admin_')
143  {
144  if(isset($old_mail_data['rcp_to']) &&
145  trim($old_mail_data['rcp_to']) != '')
146  {
147  $rcpt = $rbacreview->getRoleMailboxAddress($role['obj_id']);
148 
149  if(!$this->umail->doesRecipientStillExists($rcpt, $old_mail_data['rcp_to']))
150  array_push($members, $rcpt);
151 
152  unset($rcpt);
153  }
154  else
155  {
156  array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
157  }
158  }
159  }
160  }
161  }
162 
163  if(count($members))
164  $mail_data = $this->umail->appendSearchResult($members, 'to');
165  else
166  $mail_data = $this->umail->getSavedData();
167 
168  $this->umail->savePostData(
169  $mail_data["user_id"],
170  $mail_data["attachments"],
171  $mail_data["rcp_to"],
172  $mail_data["rcp_cc"],
173  $mail_data["rcp_bcc"],
174  $mail_data["m_type"],
175  $mail_data["m_email"],
176  $mail_data["m_subject"],
177  $mail_data["m_message"],
178  $mail_data["use_placeholders"]
179  );
180 
181  #$this->ctrl->returnToParent($this);
182  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
183  }
184 
185  function mailMembers()
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  foreach ($_POST["search_members"] as $member)
206  {
207  $login = ilObjUser::_lookupLogin($member);
208  array_push($members, $login);
209  }
210  $mail_data = $this->umail->appendSearchResult($members,"to");
211 
212  $this->umail->savePostData(
213  $mail_data["user_id"],
214  $mail_data["attachments"],
215  $mail_data["rcp_to"],
216  $mail_data["rcp_cc"],
217  $mail_data["rcp_bcc"],
218  $mail_data["m_type"],
219  $mail_data["m_email"],
220  $mail_data["m_subject"],
221  $mail_data["m_message"],
222  $mail_data["use_placeholders"]
223  );
224 
225  #$this->ctrl->returnToParent($this);
226  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
227  }
228 
232  public function adoptMembers()
233  {
234  global $lng;
235 
236  if (is_array($_POST["search_members"]))
237  {
238  $members = array();
239 
240  foreach ($_POST["search_members"] as $member)
241  {
242  $login = ilObjUser::_lookupLogin($member);
243 
244  if (!$this->abook->checkEntry($login))
245  {
246  $name = ilObjUser::_lookupName($member);
247  $email = '';
248  if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
249  {
250  $email = ilObjUser::_lookupEmail($member);
251  }
252  $this->abook->addEntry(
253  $login,
254  $name["firstname"],
255  $name["lastname"],
256  $email
257  );
258  }
259  }
260  ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
261  }
262  else
263  {
264  ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
265  }
266 
267  $this->showMembers();
268  }
269 
273  function cancel()
274  {
275  if ($_GET["view"] == "mycourses" &&
276  $_GET["ref"] == "mail")
277  {
278  $this->ctrl->returnToParent($this);
279  }
280  else
281  {
282  $this->showMyCourses();
283  }
284  }
285 
289  public function showMyCourses()
290  {
291  global $lng, $ilUser, $ilObjDataCache, $tree;
292 
293  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
294 
295  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail_addressbook_search.html', 'Services/Mail');
296  $this->tpl->setVariable('HEADER', $this->lng->txt('mail'));
297 
298  $_GET['view'] = 'mycourses';
299 
300  $this->ctrl->setParameter($this, 'view', 'mycourses');
301  if ($_GET['ref'] != '') $this->ctrl->setParameter($this, 'ref', $_GET['ref']);
302  if (is_array($_POST['search_crs'])) $this->ctrl->setParameter($this, 'search_crs', implode(',', $_POST['search_crs']));
303  $this->tpl->setVariable('ACTION', $this->ctrl->getFormAction($this));
304  $this->ctrl->clearParameters($this);
305 
306  $lng->loadLanguageModule('crs');
307 
308  //$user = new ilObjUser($ilUser->getId());
309  //$crs_ids = $user->getCourseMemberships();
310 
311  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
312  $crs_ids = ilCourseParticipants::_getMembershipByType($ilUser->getId(), 'crs');
313 
314  $counter = 0;
315  if (is_array($crs_ids) &&
316  count($crs_ids) > 0)
317  {
318 
319  $this->tpl->setVariable('CRS_TXT_COURSES', $lng->txt('mail_my_courses'));
320  $this->tpl->setVariable('CRS_TXT_COURSES_PATHS', $lng->txt('path'));
321  $this->tpl->setVariable('CRS_TXT_NO_MEMBERS', $lng->txt('crs_count_members'));
322 
323  $num_courses_hidden_members = 0;
324 
325  foreach($crs_ids as $crs_id)
326  {
328  {
329  $oCrsParticipants = ilCourseParticipants::_getInstanceByObjId($crs_id);
330  $crs_members = $oCrsParticipants->getParticipants();
331 
332  foreach($crs_members as $key => $member)
333  {
334  $tmp_usr = new ilObjUser($member);
335  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
336  {
337  unset($crs_members[$key]);
338  }
339  }
340  unset($tmp_usr);
341 
342  $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
343  if((int)$oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
344  {
345  ++$num_courses_hidden_members;
346 
347  $this->tpl->setCurrentBlock('caption_asterisk');
348  $this->tpl->touchBlock('caption_asterisk');
349  $this->tpl->parseCurrentBlock();
350  }
351  unset($oTmpCrs);
352 
353  $ref_ids = ilObject::_getAllReferences($crs_id);
354  $ref_id = current($ref_ids);
355  $path_arr = $tree->getPathFull($ref_id, $tree->getRootId());
356  $path_counter = 0;
357  $path = '';
358  foreach($path_arr as $data)
359  {
360  if($path_counter++)
361  {
362  $path .= " -> ";
363  }
364  $path .= $data['title'];
365  }
366  $path = $this->lng->txt('path').': '.$path;
367 
368  $this->tpl->setCurrentBlock('loop_crs');
369  $this->tpl->setVariable('LOOP_CRS_CSSROW', ++$counter % 2 ? 'tblrow1' : 'tblrow2');
370  $this->tpl->setVariable('LOOP_CRS_ID', $crs_id);
371  $this->tpl->setVariable('LOOP_CRS_NAME', $ilObjDataCache->lookupTitle($crs_id));
372  $this->tpl->setVariable('LOOP_CRS_NO_MEMBERS', count($crs_members));
373  $this->tpl->setVariable('LOOP_CRS_PATH', $path);
374  $this->tpl->parseCurrentBlock();
375  }
376  }
377 
378  if((int)$counter)
379  {
380  $this->tpl->setVariable('BUTTON_MAIL',$lng->txt('mail_members'));
381  $this->tpl->setVariable('BUTTON_LIST',$lng->txt('mail_list_members'));
382  }
383 
384  if($num_courses_hidden_members > 0)
385  {
386  $this->tpl->setCurrentBlock('caption_block');
387  $this->tpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
388  $this->tpl->parseCurrentBlock();
389  }
390  }
391 
392  if($counter == 0)
393  {
394  $this->tpl->setCurrentBlock('crs_not_found');
395  $this->tpl->setVariable('TXT_CRS_NOT_FOUND', $lng->txt('mail_search_courses_not_found'));
396  $this->tpl->parseCurrentBlock();
397 
398  $this->tpl->touchBlock('entries_not_found');
399  }
400  else
401  {
402  $this->tpl->setVariable('TXT_MARKED_ENTRIES', $lng->txt('marked_entries'));
403  }
404 
405  if($_GET['ref'] == 'mail') $this->tpl->setVariable('BUTTON_CANCEL', $lng->txt('cancel'));
406 
407  $this->tpl->show();
408  }
409 
413  public function showMembers()
414  {
415  global $lng, $ilUser, $ilObjDataCache;
416 
417  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
418 
419  if ($_GET["search_crs"] != "")
420  {
421  $_POST["search_crs"] = explode(",", $_GET["search_crs"]);
422  $_GET["search_crs"] = "";
423  }
424  else if ($_SESSION["search_crs"] != "")
425  {
426  $_POST["search_crs"] = explode(",", $_SESSION["search_crs"]);
427  $_SESSION["search_crs"] = "";
428  }
429 
430  if (!is_array($_POST["search_crs"]) ||
431  count($_POST["search_crs"]) == 0)
432  {
433  ilUtil::sendInfo($lng->txt("mail_select_course"));
434  $this->showMyCourses();
435  }
436  else
437  {
438  foreach($_POST['search_crs'] as $crs_id)
439  {
440  $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
441  if($oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
442  {
443  unset($_POST['search_crs']);
444  ilUtil::sendInfo($lng->txt('mail_crs_list_members_not_available_for_at_least_one_crs'));
445  return $this->showMyCourses();
446  }
447  unset($oTmpCrs);
448  }
449 
450  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_search.html", "Services/Mail");
451  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
452 
453  $this->ctrl->setParameter($this, "view", "crs_members");
454  if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
455  if (is_array($_POST["search_crs"])) $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
456  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
457  $this->ctrl->clearParameters($this);
458 
459  $lng->loadLanguageModule('crs');
460 
461  $this->tpl->setCurrentBlock("members_course");
462  $this->tpl->setVariable("MEMBERS_TXT_COURSE",$lng->txt("course"));
463  $this->tpl->parseCurrentBlock();
464  $this->tpl->setVariable("MEMBERS_TXT_LOGIN",$lng->txt("login"));
465  $this->tpl->setVariable("MEMBERS_TXT_NAME",$lng->txt("name"));
466  $this->tpl->setVariable("MEMBERS_TXT_IN_ADDRESSBOOK",$lng->txt("mail_in_addressbook"));
467 
468  $counter = 0;
469  foreach($_POST["search_crs"] as $crs_id)
470  {
471  $members_obj = ilCourseParticipants::_getinstanceByObjId($crs_id);
472  $tmp_members = $members_obj->getParticipants();
473  $course_members = ilUtil::_sortIds($tmp_members,'usr_data','lastname','usr_id');
474 
475  foreach ($course_members as $member)
476  {
477  $tmp_usr = new ilObjUser($member);
478  if($tmp_usr->checkTimeLimit()== false || $tmp_usr->getActive() == false )
479  {
480  unset($tmp_usr);
481  continue;
482  }
483  unset($tmp_usr);
484 
485  $name = ilObjUser::_lookupName($member);
486  $login = ilObjUser::_lookupLogin($member);
487 
488  $this->tpl->setCurrentBlock("loop_members");
489  $this->tpl->setVariable("LOOP_MEMBERS_CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
490  $this->tpl->setVariable("LOOP_MEMBERS_ID",$member);
491  $this->tpl->setVariable("LOOP_MEMBERS_LOGIN",$login);
492  if(ilObjUser::_lookupPref($member, 'public_profile') == 'y')
493  {
494  $this->tpl->setVariable('LOOP_MEMBERS_NAME', $name['lastname'].', '.$name['firstname']);
495  }
496  $this->tpl->setVariable("LOOP_MEMBERS_CRS_GRP", $ilObjDataCache->lookupTitle($crs_id));
497  $this->tpl->setVariable("LOOP_MEMBERS_IN_ADDRESSBOOK", $this->abook->checkEntryByLogin($login) ? $lng->txt("yes") : $lng->txt("no"));
498  $this->tpl->parseCurrentBlock();
499  }
500  }
501 
502  if ($counter == 0)
503  {
504  $this->tpl->setCurrentBlock("members_not_found");
505  $this->tpl->setVariable("TXT_MEMBERS_NOT_FOUND",$lng->txt("mail_search_members_not_found"));
506  $this->tpl->parseCurrentBlock();
507 
508  $this->tpl->touchBlock("entries_not_found");
509  }
510  else
511  {
512  $this->tpl->setVariable("BUTTON_MAIL",$lng->txt("grp_mem_send_mail"));
513  $this->tpl->setVariable("BUTTON_ADOPT",$lng->txt("mail_into_addressbook"));
514 
515  $this->tpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
516  }
517 
518  $this->tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
519 
520  $this->tpl->show();
521  }
522  }
523 
524 }
525 
526 ?>