ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjiLincCourseGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
18 include_once "./Services/Container/classes/class.ilContainerGUI.php";
19 
21 {
22  private $form_gui = null;
23 
28  public function ilObjiLincCourseGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = false)
29  {
30  $this->type = "icrs";
31  $this->ilContainerGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
32 
33  $this->ctrl->saveParameter($this,'ref_id');
34 
35  $this->lng->loadLanguageModule('ilinc');
36  }
37 
43  public function createObject()
44  {
45  global $rbacsystem;
46 
47  $new_type = $_POST['new_type'] ? $_POST['new_type'] : $_GET['new_type'];
48 
49  if(!$rbacsystem->checkAccess('create', $_GET['ref_id'], $new_type))
50  {
51  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
52  }
53 
54  $this->initSettingsForm('create');
55  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
56  }
57 
58  public function updateObject()
59  {
60  global $ilAccess;
61 
62  if(!$ilAccess->checkAccess('write', '', (int)$_GET['ref_id']))
63  {
64  $this->ilErr->raiseError($this->lng->txt('permission_denied'), $this->ilErr->MESSAGE);
65  }
66 
67  $this->initSettingsForm('edit');
68  if($this->form_gui->checkInput())
69  {
70  $_POST['Fobject']['title'] = $this->form_gui->getInput('title');
71  $_POST['Fobject']['desc'] = $this->form_gui->getInput('desc');
72  $_POST['Fobject']['activated'] = $this->form_gui->getInput('activated');
73  $_POST['Fobject']['akclassvalue1'] = $this->form_gui->getInput('akclassvalue1');
74  $_POST['Fobject']['akclassvalue2'] = $this->form_gui->getInput('akclassvalue2');
75 
76  $this->object->setTitle(ilUtil::prepareDBString($_POST['Fobject']['title']));
77  $this->object->setDescription(ilUtil::prepareDBString($_POST['Fobject']['desc']));
78  $this->object->activated = ilUtil::tf2yn($_POST['Fobject']['activated']);
79 
80  // update akclassvalues only if iLinc is active
81  if($this->ilias->getSetting('ilinc_akclassvalues_active'))
82  {
83  if($this->object->getAKClassValue1() != $_POST['Fobject']['akclassvalue1'])
84  {
85  $this->object->setAKClassValue1(ilUtil::prepareDBString($_POST['Fobject']['akclassvalue1']));
86  }
87 
88  if($this->object->getAKClassValue2() != $_POST['Fobject']['akclassvalue2'])
89  {
90  $this->object->setAKClassValue2(ilUtil::prepareDBString($_POST['Fobject']['akclassvalue2']));
91  }
92  }
93 
94  // save changes to ilinc server and ilias database
95  $success = $this->object->update();
96  if($success == false)
97  {
98  $this->ilErr->raiseError($this->object->getErrorMsg(), $this->ilErr->MESSAGE);
99  }
100 
101  // update all akclassvalues of classes if akclassvalues has changed
102  if(array_key_exists('akclassvalue1', $_POST['Fobject']) or
103  array_key_exists('akclassvalue2',$_POST['Fobject']))
104  {
105  if(!$this->object->updateClassrooms())
106  {
107  ilUtil::sendInfo($this->lng->txt($this->object->getErrorMsg()));
108  $this->form_gui->setValuesByPost();
109  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
110  }
111  }
112 
113  ilUtil::sendInfo($this->lng->txt('msg_obj_modified'));
114  $this->form_gui->setValuesByPost();
115  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
116  }
117  else
118  {
119  $this->form_gui->setValuesByPost();
120  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
121  }
122  }
123 
128  public function saveObject()
129  {
130  $this->initSettingsForm('create');
131  if($this->form_gui->checkInput())
132  {
133  $_POST['Fobject']['title'] = $this->form_gui->getInput('title');
134  $_POST['Fobject']['desc'] = $this->form_gui->getInput('desc');
135  $_POST['Fobject']['activated'] = $this->form_gui->getInput('activated');
136  $_POST['Fobject']['akclassvalue1'] = $this->form_gui->getInput('akclassvalue1');
137  $_POST['Fobject']['akclassvalue2'] = $this->form_gui->getInput('akclassvalue2');
138 
139  // when creating new ilinc course we first create it on ilinc server
140  include_once 'Modules/ILinc/classes/class.ilnetucateXMLAPI.php';
141  $ilinc = new ilnetucateXMLAPI();
142  $ilinc->addCourse($_POST['Fobject']);
143 
144  $response = $ilinc->sendRequest();
145  if($response->isError())
146  {
147  $this->ilErr->raiseError($response->getErrorMsg(), $this->ilErr->MESSAGE);
148  }
149 
150  // if everything ok, create and insert ilinc course in ILIAS
151  $icrsObj = parent::saveObject();
152 
153  // save ilinc_id in ILIAS and save data
154  $icrsObj->storeiLincId($response->getFirstID());
155  $icrsObj->saveActivationStatus(ilUtil::tf2yn((bool)$this->form_gui->getInput('activated')));
156  $icrsObj->saveAKClassValues(
157  $this->form_gui->getInput('akclassvalue1'),
158  $this->form_gui->getInput('akclassvalue2')
159  );
160 
161  // ...finally assign icrsadmin role to creator of icrs object
162  $success = $icrsObj->addMember($this->ilias->account, $icrsObj->getDefaultAdminRole(), true);
163 
164  if(!$success)
165  {
166  $this->ilErr->raiseError($icrsObj->getErrorMsg(), $this->ilErr->MESSAGE);
167  }
168 
169  // $icrsObj->setRegistrationFlag($_POST["enable_registration"]); //0=no registration, 1=registration enabled 2=passwordregistration
170  // $icrsObj->setPassword($_POST["password"]);
171  // $icrsObj->setExpirationDateTime($_POST["expirationdate"]." ".$_POST["expirationtime"].":00");
172 
173  $this->ilias->account->addDesktopItem($icrsObj->getRefId(), 'icrs');
174 
175  // always send a message
176  ilUtil::sendInfo($this->lng->txt('icrs_added'), true);
177  $this->redirectToRefId((int)$_GET['ref_id']);
178  }
179  else
180  {
181  $this->form_gui->setValuesByPost();
182  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
183  }
184  }
185 
191  public function getTabs(&$tabs_gui)
192  {
193  global $rbacsystem,$ilAccess;
194 
195  $this->ctrl->setParameter($this,'ref_id',$this->ref_id);
196 
197  if($rbacsystem->checkAccess('read',$this->ref_id))
198  {
199  $tabs_gui->addTarget('ilinc_classrooms',
200  $this->ctrl->getLinkTarget($this, ''),
201  array('', 'view', 'editClassroom', 'updateClassroom', 'removeClassroom')
202  );
203  }
204 
205  if($this->ilias->getSetting('ilinc_active'))
206  {
207  if($ilAccess->checkAccess('write', '', $this->ref_id))
208  {
209  $tabs_gui->addTarget('edit_properties',
210  $this->ctrl->getLinkTarget($this, 'edit'), array('edit', 'update', 'save'), get_class($this));
211  }
212 
213  /* if ($rbacsystem->checkAccess('read',$this->ref_id))
214  {
215  $tabs_gui->addTarget("ilinc_involved_users",
216  $this->ctrl->getLinkTarget($this, "members"), array("members","mailMembers","membersGallery","showProfile"), get_class($this));
217  }*/
218 
219  // member list
220  if($ilAccess->checkAccess('write','',$this->ref_id))
221  {
222  $tabs_gui->addTarget("ilinc_involved_users",
223  $this->ctrl->getLinkTarget($this, "members"),
224  array("members","mailMembers","membersGallery","showProfile",'changeMember', 'RemoveMember'),
225  get_class($this));
226  }
227  elseif ($ilAccess->checkAccess('read','',$this->ref_id))
228  {
229  $tabs_gui->addTarget("ilinc_involved_users",
230  $this->ctrl->getLinkTarget($this, "membersGallery"),
231  array("members","mailMembers","membersGallery","showProfile"),
232  get_class($this));
233  }
234 
235  if ($rbacsystem->checkAccess('write',$this->ref_id) and $this->object->isDocent($this->ilias->account))
236  {
237  // testing: display link to ilinc server directly
238  $tabs_gui->addTarget("ilinc_manage_course_documents",
239  $url = $this->object->userLogin($this->ilias->account), "agenda","","_blank");
240  // $tabs_gui->addTarget("ilinc_manage_course_documents",
241  // $this->ctrl->getLinkTarget($this, "agenda"), "agenda", get_class($this),"_blank");
242 
243  }
244  }
245 
246  /*$applications = $this->object->getNewRegistrations();
247 
248  if (is_array($applications) and $this->object->isAdmin($this->ilias->account->getId()))
249  {
250  $tabs_gui->addTarget("ilinc_new_registrations",
251  $this->ctrl->getLinkTarget($this, "ShownewRegistrations"), "ShownewRegistrations", get_class($this));
252  }*/
253 
254  if ($rbacsystem->checkAccess('edit_permission',$this->ref_id))
255  {
256  $tabs_gui->addTarget("perm_settings",
257  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
258  }
259 
260  // show clipboard in repository
261  if ($this->ctrl->getTargetScript() == "repository.php" and !empty($_SESSION['il_rep_clipboard']))
262  {
263  $tabs_gui->addTarget("clipboard",
264  $this->ctrl->getLinkTarget($this, "clipboard"), "clipboard", get_class($this));
265  }
266 
267  if ($this->ctrl->getTargetScript() == "adm_object.php")
268  {
269  if ($this->tree->getSavedNodeData($this->ref_id))
270  {
271  $tabs_gui->addTarget("trash",
272  $this->ctrl->getLinkTarget($this, "trash"), "trash", get_class($this));
273  }
274  }
275  }
276 
277  public function __unsetSessionVariables()
278  {
279  unset($_SESSION["grp_delete_member_ids"]);
280  unset($_SESSION["grp_delete_subscriber_ids"]);
281  unset($_SESSION["grp_search_str"]);
282  unset($_SESSION["grp_search_for"]);
283  unset($_SESSION["grp_role"]);
284  unset($_SESSION["grp_group"]);
285  unset($_SESSION["grp_archives"]);
286  }
287 
288  public function __search($a_search_string,$a_search_for)
289  {
290  include_once("./classes/class.ilSearch.php");
291 
292  $this->lng->loadLanguageModule("content");
293  $search =& new ilSearch($_SESSION["AccountId"]);
294  $search->setPerformUpdate(false);
295  $search->setSearchString(ilUtil::stripSlashes($a_search_string));
296  $search->setCombination("and");
297  $search->setSearchFor(array(0 => $a_search_for));
298  $search->setSearchType('new');
299 
300  if($search->validate($message))
301  {
302  $search->performSearch();
303  }
304  else
305  {
306  ilUtil::sendInfo($message,true);
307  $this->ctrl->redirect($this,"searchUserForm");
308  }
309 
310  return $search->getResultByType($a_search_for);
311  }
312 
313  public function __showSearchUserTable($a_result_set,$a_user_ids = NULL, $a_cmd = "search")
314  {
315  $return_to = "searchUserForm";
316 
317  if ($a_cmd == "listUsersRole" or $a_cmd == "listUsersGroup")
318  {
319  $return_to = "search";
320  }
321 
322  $tbl =& $this->__initTableGUI();
323  $tpl =& $tbl->getTemplateObject();
324 
325  // SET FORMACTION
326  $tpl->setCurrentBlock("tbl_form_header");
327  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
328  $tpl->parseCurrentBlock();
329 
330  $tpl->setCurrentBlock("tbl_action_btn");
331  $tpl->setVariable("BTN_NAME",$return_to);
332  $tpl->setVariable("BTN_VALUE",$this->lng->txt("back"));
333  $tpl->parseCurrentBlock();
334 
335  $tpl->setCurrentBlock("tbl_action_btn");
336  $tpl->setVariable("BTN_NAME","addUser");
337  $tpl->setVariable("BTN_VALUE",$this->lng->txt("add"));
338  $tpl->parseCurrentBlock();
339 
340  if (!empty($a_user_ids))
341  {
342  // set checkbox toggles
343  $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
344  $tpl->setVariable("JS_VARNAME","user");
345  $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_user_ids));
346  $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
347  $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
348  $tpl->parseCurrentBlock();
349  }
350 
351  $tpl->setCurrentBlock("tbl_action_row");
352  $tpl->setVariable("COLUMN_COUNTS",5);
353  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
354  $tpl->parseCurrentBlock();
355 
356  $tbl->setTitle($this->lng->txt("ilinc_header_edit_users"),"icon_usr_b.gif",$this->lng->txt("ilinc_header_edit_users"));
357  $tbl->setHeaderNames(array("",
358  $this->lng->txt("username"),
359  $this->lng->txt("firstname"),
360  $this->lng->txt("lastname"),
361  $this->lng->txt("last_visit")));
362  $tbl->setHeaderVars(array("",
363  "login",
364  "firstname",
365  "lastname",
366  "last_visit"),
367  array("ref_id" => $this->object->getRefId(),
368  "cmd" => $a_cmd,
369  "cmdClass" => "ilobjilinccoursegui",
370  "cmdNode" => $_GET["cmdNode"]));
371 
372  $tbl->setColumnWidth(array("","33%","33%","33%"));
373 
374  $this->__setTableGUIBasicData($tbl,$a_result_set);
375  $tbl->render();
376 
377  $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
378 
379  return true;
380  }
381 
382  public function __showSearchRoleTable($a_result_set,$a_role_ids = NULL)
383  {
384  $tbl =& $this->__initTableGUI();
385  $tpl =& $tbl->getTemplateObject();
386 
387  $tpl->setCurrentBlock("tbl_form_header");
388  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
389  $tpl->parseCurrentBlock();
390 
391  $tpl->setCurrentBlock("tbl_action_btn");
392  $tpl->setVariable("BTN_NAME","searchUserForm");
393  $tpl->setVariable("BTN_VALUE",$this->lng->txt("back"));
394  $tpl->parseCurrentBlock();
395 
396  $tpl->setCurrentBlock("tbl_action_btn");
397  $tpl->setVariable("BTN_NAME","listUsersRole");
398  $tpl->setVariable("BTN_VALUE",$this->lng->txt("grp_list_users"));
399  $tpl->parseCurrentBlock();
400 
401  if (!empty($a_role_ids))
402  {
403  // set checkbox toggles
404  $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
405  $tpl->setVariable("JS_VARNAME","role");
406  $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_role_ids));
407  $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
408  $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
409  $tpl->parseCurrentBlock();
410  }
411 
412  $tpl->setCurrentBlock("tbl_action_row");
413  $tpl->setVariable("COLUMN_COUNTS",5);
414  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
415  $tpl->parseCurrentBlock();
416 
417  $tbl->setTitle($this->lng->txt("ilinc_header_edit_users"),"icon_usr_b.gif",$this->lng->txt("ilinc_header_edit_users"));
418  $tbl->setHeaderNames(array("",
419  $this->lng->txt("obj_role"),
420  $this->lng->txt("grp_count_members")));
421  $tbl->setHeaderVars(array("",
422  "title",
423  "nr_members"),
424  array("ref_id" => $this->object->getRefId(),
425  "cmd" => "search",
426  "cmdClass" => "ilobjilincoursegui",
427  "cmdNode" => $_GET["cmdNode"]));
428 
429  $tbl->setColumnWidth(array("","80%","19%"));
430 
431 
432  $this->__setTableGUIBasicData($tbl,$a_result_set,"role");
433  $tbl->render();
434 
435  $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
436 
437  return true;
438  }
439 
440  public function __showSearchGroupTable($a_result_set,$a_grp_ids = NULL)
441  {
442  $tbl =& $this->__initTableGUI();
443  $tpl =& $tbl->getTemplateObject();
444 
445  $tpl->setCurrentBlock("tbl_form_header");
446  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
447  $tpl->parseCurrentBlock();
448 
449  $tpl->setCurrentBlock("tbl_action_btn");
450  $tpl->setVariable("BTN_NAME","searchUserForm");
451  $tpl->setVariable("BTN_VALUE",$this->lng->txt("back"));
452  $tpl->parseCurrentBlock();
453 
454  $tpl->setCurrentBlock("tbl_action_btn");
455  $tpl->setVariable("BTN_NAME","listUsersGroup");
456  $tpl->setVariable("BTN_VALUE",$this->lng->txt("grp_list_users"));
457  $tpl->parseCurrentBlock();
458 
459  if (!empty($a_grp_ids))
460  {
461  // set checkbox toggles
462  $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
463  $tpl->setVariable("JS_VARNAME","group");
464  $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_grp_ids));
465  $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
466  $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
467  $tpl->parseCurrentBlock();
468  }
469 
470  $tpl->setCurrentBlock("tbl_action_row");
471  $tpl->setVariable("COLUMN_COUNTS",5);
472  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
473  $tpl->parseCurrentBlock();
474 
475  $tbl->setTitle($this->lng->txt("ilinc_header_edit_users"),"icon_usr_b.gif",$this->lng->txt("ilinc_header_edit_users"));
476  $tbl->setHeaderNames(array("",
477  $this->lng->txt("obj_grp"),
478  $this->lng->txt("grp_count_members")));
479  $tbl->setHeaderVars(array("",
480  "title",
481  "nr_members"),
482  array("ref_id" => $this->object->getRefId(),
483  "cmd" => "search",
484  "cmdClass" => "ilobjilinccoursegui",
485  "cmdNode" => $_GET["cmdNode"]));
486 
487  $tbl->setColumnWidth(array("","80%","19%"));
488 
489 
490  $this->__setTableGUIBasicData($tbl,$a_result_set,"group");
491  $tbl->render();
492 
493  $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
494 
495  return true;
496  }
497 
498  public function &__initTableGUI()
499  {
500  include_once "./Services/Table/classes/class.ilTableGUI.php";
501 
502  return new ilTableGUI(0,false);
503  }
504 
505  public function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
506  {
507  switch($from)
508  {
509  case "subscribers":
510  $offset = $_GET["update_subscribers"] ? $_GET["offset"] : 0;
511  $order = $_GET["update_subscribers"] ? $_GET["sort_by"] : 'login';
512  $direction = $_GET["update_subscribers"] ? $_GET["sort_order"] : '';
513  break;
514 
515  case "group":
516  $offset = $_GET["offset"];
517  $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
518  $direction = $_GET["sort_order"];
519  break;
520 
521  case "role":
522  $offset = $_GET["offset"];
523  $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
524  $direction = $_GET["sort_order"];
525  break;
526 
527  default:
528  $offset = $_GET["offset"];
529  // init sort_by (unfortunatly sort_by is preset with 'title'
530  if ($_GET["sort_by"] == "title" or empty($_GET["sort_by"]))
531  {
532  $_GET["sort_by"] = "login";
533  }
534  $order = $_GET["sort_by"];
535  $direction = $_GET["sort_order"];
536  break;
537  }
538 
539  $tbl->setOrderColumn($order);
540  $tbl->setOrderDirection($direction);
541  $tbl->setOffset($offset);
542  $tbl->setLimit($_GET["limit"]);
543  //$tbl->setMaxCount(count($result_set));
544  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
545  $tbl->setData($result_set);
546  }
547 
548  public function listUsersRoleObject()
549  {
550  global $rbacsystem,$rbacreview;
551 
552  $_SESSION["grp_role"] = $_POST["role"] = $_POST["role"] ? $_POST["role"] : $_SESSION["grp_role"];
553 
554  // MINIMUM ACCESS LEVEL = 'administrate'
555  if(!$rbacsystem->checkAccess("write", $this->object->getRefId()))
556  {
557  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
558  }
559 
560  if(!is_array($_POST["role"]))
561  {
562  ilUtil::sendInfo($this->lng->txt("grp_no_roles_selected"));
563  $this->searchObject();
564 
565  return false;
566  }
567 
568  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.grp_usr_selection.html");
569  $this->__showButton("searchUserForm",$this->lng->txt("grp_new_search"));
570 
571  // GET ALL MEMBERS
572  $members = array();
573  foreach($_POST["role"] as $role_id)
574  {
575  $members = array_merge($rbacreview->assignedUsers($role_id),$members);
576  }
577 
578  $members = array_unique($members);
579 
580  // FORMAT USER DATA
581  $counter = 0;
582  $f_result = array();
583  foreach($members as $user)
584  {
585  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user,false))
586  {
587  continue;
588  }
589 
590  $user_ids[$counter] = $user;
591 
592  $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user);
593  $f_result[$counter][] = $tmp_obj->getLogin();
594  $f_result[$counter][] = $tmp_obj->getLastname();
595  $f_result[$counter][] = $tmp_obj->getFirstname();
596  $f_result[$counter][] = ilDatePresentation::formatDate(new ilDateTime($tmp_obj->getLastLogin(),IL_CAL_DATETIME));
597 
598  unset($tmp_obj);
599  ++$counter;
600  }
601  $this->__showSearchUserTable($f_result,$user_ids,"listUsersRole");
602 
603  return true;
604  }
605 
606  public function listUsersGroupObject()
607  {
608  global $rbacsystem,$rbacreview,$tree;
609 
610  $_SESSION["grp_group"] = $_POST["group"] = $_POST["group"] ? $_POST["group"] : $_SESSION["grp_group"];
611 
612  // MINIMUM ACCESS LEVEL = 'administrate'
613  if(!$rbacsystem->checkAccess("write", $this->object->getRefId()))
614  {
615  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
616  }
617 
618  if(!is_array($_POST["group"]))
619  {
620  ilUtil::sendInfo($this->lng->txt("grp_no_groups_selected"));
621  $this->searchObject();
622 
623  return false;
624  }
625 
626  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.grp_usr_selection.html");
627  $this->__showButton("searchUserForm",$this->lng->txt("grp_new_search"));
628 
629  // GET ALL MEMBERS
630  $members = array();
631  foreach($_POST["group"] as $group_id)
632  {
633  if (!$tree->isInTree($group_id))
634  {
635  continue;
636  }
637  if (!$tmp_obj = ilObjectFactory::getInstanceByRefId($group_id))
638  {
639  continue;
640  }
641 
642  $members = array_merge($tmp_obj->getGroupMemberIds(),$members);
643 
644  unset($tmp_obj);
645  }
646 
647  $members = array_unique($members);
648 
649  // FORMAT USER DATA
650  $counter = 0;
651  $f_result = array();
652  foreach($members as $user)
653  {
654  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user,false))
655  {
656  continue;
657  }
658 
659  $user_ids[$counter] = $user;
660 
661  $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user);
662  $f_result[$counter][] = $tmp_obj->getLogin();
663  $f_result[$counter][] = $tmp_obj->getLastname();
664  $f_result[$counter][] = $tmp_obj->getFirstname();
665  $f_result[$counter][] = ilDatePresentation::formatDate(new ilDateTime($tmp_obj->getLastLogin(),IL_CAL_DATETIME));
666 
667  unset($tmp_obj);
668  ++$counter;
669  }
670  $this->__showSearchUserTable($f_result,$user_ids,"listUsersGroup");
671 
672  return true;
673  }
674 
679  public function canceledObject()
680  {
681  $return_location = $_GET["cmd_return_location"];
682  if (strcmp($return_location, "") == 0)
683  {
684  $return_location = "members";
685  }
686 
687  ilUtil::sendInfo($this->lng->txt("action_aborted"),true);
688  $this->ctrl->redirect($this, $return_location);
689  }
690 
695  public function cancelMemberObject()
696  {
697  $return_location = "members";
698 
699  ilUtil::sendInfo($this->lng->txt("action_aborted"),true);
700  ilUtil::redirect($this->ctrl->getLinkTarget($this,$return_location,"",false,false));
701  }
702 
706  public function membersObject()
707  {
708  global $ilAccess, $ilBench, $lng, $ilToolbar, $ilUser;
709 
710  if(!$this->ilias->getSetting('ilinc_active'))
711  {
712  $this->ilias->raiseError($lng->txt('ilinc_server_not_active'), $this->ilias->error_obj->MESSAGE);
713  }
714 
715  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.icrs_members.html','Modules/ILinc');
716  $this->__setSubTabs('members');
717 
718  $this->lng->loadLanguageModule('ilinc');
719 
720  // display member search button
721  $is_admin = (bool)$ilAccess->checkAccess('write', '', $this->object->getRefId());
722  if($is_admin)
723  {
724  $ilToolbar->addButton($this->lng->txt('ilinc_add_user'), $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI', 'start'));
725  }
726 
727  //if current user is admin he is able to add new members to group
728  $val_contact = "<img src=\"".ilUtil::getImagePath("icon_pencil_b.gif")."\" alt=\"".$this->lng->txt("ilinc_mem_send_mail")."\" title=\"".$this->lng->txt("ilinc_mem_send_mail")."\" border=\"0\" vspace=\"0\"/>";
729  $val_change = "<img src=\"".ilUtil::getImagePath("icon_change_b.gif")."\" alt=\"".$this->lng->txt("ilinc_mem_change_status")."\" title=\"".$this->lng->txt("ilinc_mem_change_status")."\" border=\"0\" vspace=\"0\"/>";
730  $val_leave = "<img src=\"".ilUtil::getImagePath("icon_group_out_b.gif")."\" alt=\"".$this->lng->txt("ilinc_mem_leave")."\" title=\"".$this->lng->txt("ilinc_mem_leave")."\" border=\"0\" vspace=\"0\"/>";
731 
732  // store access checks to improve performance
733  $access_leave = $ilAccess->checkAccess('leave', '', $this->object->getRefId());
734  $access_write = $ilAccess->checkAccess('write', '', $this->object->getRefId());
735 
736  $member_ids = $this->object->getMemberIds();
737 
738  // fetch all user data in one shot to improve performance (from ILIAS db)
739  $members = $this->object->getMemberData($member_ids);
740 
741  // fetch docent or student assignment form all coursemembers from iLinc server
742  $docent_ids = $this->object->getiLincMemberIds(true);
743  $student_ids = $this->object->getiLincMemberIds(false);
744 
745  $counter = 0;
746  $result_set = array();
747  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
748  foreach($members as $mem)
749  {
750  $link_contact = ilMailFormCall::_getLinkTarget($this, 'members', array(), array('type' => 'new', 'rcp_to' => $mem['login']));
751  $link_change = $this->ctrl->getLinkTarget($this, 'changeMember').'&mem_id='.$mem['id'];
752  if(($mem['id'] == $ilUser->getId() && $access_leave) || $access_delete)
753  {
754  $link_leave = $this->ctrl->getLinkTarget($this, 'removeMember').'&mem_id='.$mem['id'];
755  }
756 
757  //build functions
758  $member_functions = '';
759  if($access_write)
760  {
761  $member_functions = "<a href=\"$link_change\">$val_change</a>";
762  }
763  if(($mem['id'] == $ilUser->getId() && $access_leave) || $access_write)
764  {
765  $link_leave = $this->ctrl->getLinkTarget($this, 'removeMember').'&mem_id='.$mem['id'];
766  $member_functions .="<a href=\"$link_leave\">$val_leave</a>";
767  }
768 
769  // this is twice as fast than the code above
770  $str_member_roles = $this->object->getMemberRolesTitle($mem['id']);
771 
772  if($access_write)
773  {
774  $result_set[$counter]['checkbox'] = ilUtil::formCheckBox(0, 'user_id[]', $mem['id']);
775  }
776 
777  $status = $this->object->checkiLincMemberStatus($mem['ilinc_id'], $docent_ids, $student_ids);
778  if($status == ILINC_MEMBER_NOTSET)
779  {
780  $status = "<span class='warning'>".$this->lng->txt($status)."</span>";
781  }
782  else
783  {
784  $status = $this->lng->txt($status);
785  }
786 
787  $result_set[$counter]['login'] = $mem['login'];
788  $result_set[$counter]['firstname'] = $mem['firstname'];
789  $result_set[$counter]['lastname'] = $mem['lastname'];
790  $result_set[$counter]['attending_as'] = $status;
791  $result_set[$counter]['role'] = $str_member_roles;
792  $result_set[$counter]['options'] = "<a href=\"$link_contact\">".$val_contact."</a>".$member_functions;
793 
794  ++$counter;
795 
796  unset($member_functions);
797  }
798 
799  include_once 'Modules/ILinc/classes/class.iliLinkMembersTableGUI.php';
800  $oTable = new iliLinkMembersTableGUI($this, $result_set, 'show', 'members', 'members');
801  $oTable->setTitle($this->lng->txt('ilinc_involved_users'), 'icon_usr_b.gif', $this->lng->txt('ilinc_involved_users'));
802 
803  return $this->tpl->setVariable('MEMBER_TABLE', $oTable->getHTML());
804  }
805 
806  public function &executeCommand()
807  {
808  global $ilUser,$rbacsystem,$ilAccess,$ilErr;
809 
810  $next_class = $this->ctrl->getNextClass($this);
811  $cmd = $this->ctrl->getCmd();
812  $this->prepareOutput();
813 
814  switch($next_class)
815  {
816  case "ilconditionhandlerinterface":
817  include_once './classes/class.ilConditionHandlerInterface.php';
818 
819  if($_GET['item_id'])
820  {
821  $new_gui =& new ilConditionHandlerInterface($this,(int) $_GET['item_id']);
822  $this->ctrl->saveParameter($this,'item_id',$_GET['item_id']);
823  $this->ctrl->forwardCommand($new_gui);
824  }
825  else
826  {
827  $new_gui =& new ilConditionHandlerInterface($this);
828  $this->ctrl->forwardCommand($new_gui);
829  }
830  break;
831 
832  case 'ilrepositorysearchgui':
833  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
834  $rep_search =& new ilRepositorySearchGUI();
835  $rep_search->setCallback($this,'addUserObject');
836 
837  // Set tabs
838  $this->tabs_gui->setTabActive('members');
839  $this->ctrl->setReturn($this,'members');
840  $ret =& $this->ctrl->forwardCommand($rep_search);
841  $this->__setSubTabs('members');
842  $this->tabs_gui->setSubTabActive('members');
843  break;
844 
845  case "ilobjilincclassroomgui":
846  include_once ('./Modules/ILinc/classes/class.ilObjiLincClassroomGUI.php');
847  $icla_gui = new ilObjiLincClassroomGUI($_GET['class_id'],$this->ref_id);
848  $ret =& $this->ctrl->forwardCommand($icla_gui);
849  break;
850 
851  case 'ilpermissiongui':
852  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
853  $perm_gui =& new ilPermissionGUI($this);
854  $ret =& $this->ctrl->forwardCommand($perm_gui);
855  break;
856 
857  case 'ilpublicuserprofilegui':
858  require_once './Services/User/classes/class.ilPublicUserProfileGUI.php';
859  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
860  $html = $this->ctrl->forwardCommand($profile_gui);
861  $this->__setSubTabs('members');
862  $this->tabs_gui->setTabActive('group_members');
863  $this->tabs_gui->setSubTabActive('grp_members_gallery');
864  $this->tpl->setVariable("ADM_CONTENT", $html);
865  break;
866 
867  default:
868  if (!$this->getCreationMode() and !$ilAccess->checkAccess('visible','',$this->object->getRefId(),'icrs'))
869  {
870  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
871  }
872 
873 
874  if(!$cmd)
875  {
876  $cmd = 'view';
877  }
878  $cmd .= 'Object';
879  $this->$cmd();
880  break;
881  }
882  }
883 
884  public function viewObject()
885  {
886  global $ilCtrl, $ilNavigationHistory, $ilAccess;
887 
888  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
889  {
890  $this->ilias->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilias->error_obj->MESSAGE);
891  }
892 
893  // add entry to navigation history
894  if(!$this->getCreationMode() &&
895  $ilAccess->checkAccess('read', '', $this->object->getRefId()))
896  {
897  $ilNavigationHistory->addItem($this->object->getRefId(),
898  'repository.php?cmd=view&ref_id='.$this->object->getRefId(), 'icrs');
899  }
900 
901  if(strtolower($_GET['baseClass']) == 'iladministrationgui')
902  {
904  return true;
905  }
906 
907  return $this->renderObject();
908  }
909 
910  public function agendaObject()
911  {
912  // user login
913  $url = $this->object->userLogin($this->ilias->account);
914 
915  if (!$url)
916  {
917  $this->ilias->raiseError($this->object->getErrorMsg(),$this->ilias->error_obj->FATAL);
918  }
919 
920  ilUtil::redirect(trim($url));
921  }
922 
923  public function searchUserFormObject()
924  {
925  global $rbacsystem;
926 
927  $this->lng->loadLanguageModule('search');
928 
929  // MINIMUM ACCESS LEVEL = 'administrate'
930  if(!$rbacsystem->checkAccess("write", $this->object->getRefId()))
931  {
932  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
933  }
934 
935  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.grp_members_search.html");
936 
937  $this->tpl->setVariable("F_ACTION",$this->ctrl->getFormAction($this));
938  $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("grp_search_members"));
939  $this->tpl->setVariable("SEARCH_SEARCH_TERM",$this->lng->txt("search_search_term"));
940  $this->tpl->setVariable("SEARCH_VALUE",$_SESSION["grp_search_str"] ? $_SESSION["grp_search_str"] : "");
941  $this->tpl->setVariable("SEARCH_FOR",$this->lng->txt("exc_search_for"));
942  $this->tpl->setVariable("SEARCH_ROW_TXT_USER",$this->lng->txt("exc_users"));
943  $this->tpl->setVariable("SEARCH_ROW_TXT_ROLE",$this->lng->txt("exc_roles"));
944  $this->tpl->setVariable("SEARCH_ROW_TXT_GROUP",$this->lng->txt("exc_groups"));
945  $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
946  $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
947 
948  $usr = ($_POST["search_for"] == "usr" || $_POST["search_for"] == "") ? 1 : 0;
949  $grp = ($_POST["search_for"] == "grp") ? 1 : 0;
950  $role = ($_POST["search_for"] == "role") ? 1 : 0;
951 
952  $this->tpl->setVariable("SEARCH_ROW_CHECK_USER",ilUtil::formRadioButton($usr,"search_for","usr"));
953  $this->tpl->setVariable("SEARCH_ROW_CHECK_ROLE",ilUtil::formRadioButton($role,"search_for","role"));
954  $this->tpl->setVariable("SEARCH_ROW_CHECK_GROUP",ilUtil::formRadioButton($grp,"search_for","grp"));
955 
956  $this->__unsetSessionVariables();
957  }
958 
959  function searchObject()
960  {
961  global $rbacsystem,$tree;
962 
963  $_SESSION["grp_search_str"] = $_POST["search_str"] = $_POST["search_str"] ? $_POST["search_str"] : $_SESSION["grp_search_str"];
964  $_SESSION["grp_search_for"] = $_POST["search_for"] = $_POST["search_for"] ? $_POST["search_for"] : $_SESSION["grp_search_for"];
965 
966  // MINIMUM ACCESS LEVEL = 'administrate'
967  if(!$rbacsystem->checkAccess("write", $this->object->getRefId()))
968  {
969  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
970  }
971 
972  if(!isset($_POST["search_for"]) or !isset($_POST["search_str"]))
973  {
974  ilUtil::sendInfo($this->lng->txt("grp_search_enter_search_string"));
975  $this->searchUserFormObject();
976 
977  return false;
978  }
979 
980  if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]),$_POST["search_for"])))
981  {
982  ilUtil::sendInfo($this->lng->txt("grp_no_results_found"));
983  $this->searchUserFormObject();
984 
985  return false;
986  }
987 
988  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.grp_usr_selection.html");
989  $this->__showButton("searchUserForm",$this->lng->txt("grp_new_search"));
990 
991  $counter = 0;
992  $f_result = array();
993 
994  switch($_POST["search_for"])
995  {
996  case "usr":
997  foreach($result as $user)
998  {
999  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
1000  {
1001  continue;
1002  }
1003 
1004  $user_ids[$counter] = $user["id"];
1005 
1006  $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user["id"]);
1007  $f_result[$counter][] = $tmp_obj->getLogin();
1008  $f_result[$counter][] = $tmp_obj->getFirstname();
1009  $f_result[$counter][] = $tmp_obj->getLastname();
1010  $f_result[$counter][] = ilDatePresentation::formatDate(new ilDateTime($tmp_obj->getLastLogin(),IL_CAL_DATETIME));
1011 
1012  unset($tmp_obj);
1013  ++$counter;
1014  }
1015  $this->__showSearchUserTable($f_result,$user_ids);
1016 
1017  return true;
1018 
1019  case "role":
1020  foreach($result as $role)
1021  {
1022  // exclude anonymous role
1023  if ($role["id"] == ANONYMOUS_ROLE_ID)
1024  {
1025  continue;
1026  }
1027 
1028  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($role["id"],false))
1029  {
1030  continue;
1031  }
1032 
1033  // exclude roles with no users assigned to
1034  if ($tmp_obj->getCountMembers() == 0)
1035  {
1036  continue;
1037  }
1038 
1039  $role_ids[$counter] = $role["id"];
1040 
1041  $f_result[$counter][] = ilUtil::formCheckbox(0,"role[]",$role["id"]);
1042  $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
1043  $f_result[$counter][] = $tmp_obj->getCountMembers();
1044 
1045  unset($tmp_obj);
1046  ++$counter;
1047  }
1048 
1049  $this->__showSearchRoleTable($f_result,$role_ids);
1050 
1051  return true;
1052 
1053  case "grp":
1054  foreach($result as $group)
1055  {
1056  if(!$tree->isInTree($group["id"]))
1057  {
1058  continue;
1059  }
1060 
1061  if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($group["id"],false))
1062  {
1063  continue;
1064  }
1065 
1066  // exclude myself :-)
1067  if ($tmp_obj->getId() == $this->object->getId())
1068  {
1069  continue;
1070  }
1071 
1072  $grp_ids[$counter] = $group["id"];
1073 
1074  $f_result[$counter][] = ilUtil::formCheckbox(0,"group[]",$group["id"]);
1075  $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
1076  $f_result[$counter][] = $tmp_obj->getCountMembers();
1077 
1078  unset($tmp_obj);
1079  ++$counter;
1080  }
1081 
1082  if(!count($f_result))
1083  {
1084  ilUtil::sendInfo($this->lng->txt("grp_no_results_found"));
1085  $this->searchUserFormObject();
1086 
1087  return false;
1088  }
1089 
1090  $this->__showSearchGroupTable($f_result,$grp_ids);
1091 
1092  return true;
1093  }
1094  }
1095 
1100  function addUserObject()
1101  {
1102  $user_ids = $_POST["user"];
1103 
1104  $mail = new ilMail($_SESSION["AccountId"]);
1105 
1106  if (empty($user_ids[0]))
1107  {
1108  // TODO: jumps back to grp content. go back to last search result
1109  $this->ilErr->raiseError($this->lng->txt("no_checkbox"),$this->ilErr->MESSAGE);
1110  }
1111 
1112  foreach ($user_ids as $new_member)
1113  {
1114  $user_obj = $this->ilias->obj_factory->getInstanceByObjId($new_member);
1115 
1116  if (!$this->object->addMember($user_obj,$this->object->getDefaultMemberRole(),false))
1117  {
1118  //var_dump($this->object->getErrorMsg());exit;
1119  $this->ilErr->raiseError($this->object->getErrorMsg(),$this->ilErr->MESSAGE);
1120  }
1121 
1122  $user_obj->addDesktopItem($this->object->getRefId(),"icrs");
1123  $mail->sendMail($user_obj->getLogin(),"","",$this->lng->txtlng("common","ilinc_mail_subj_new_subscription",$user_obj->getLanguage()).": ".$this->object->getTitle(),$this->lng->txtlng("common","ilinc_mail_body_new_subscription",$user_obj->getLanguage()),array(),array('normal'));
1124 
1125  unset($user_obj);
1126  }
1127 
1128  //echo "end";exit;
1129 
1130  unset($_SESSION["saved_post"]);
1131 
1132  ilUtil::sendInfo($this->lng->txt("ilinc_msg_member_assigned"),true);
1133  ilUtil::redirect($this->ctrl->getLinkTarget($this,"members","",false,false));
1134  }
1135 
1141  {
1142  global $ilUser, $rbacreview;
1143 
1144  $this->__setSubTabs('members');
1145 
1146  $user_ids = array();
1147 
1148  if(isset($_POST['user_id']))
1149  {
1150  $user_ids = $_POST['user_id'];
1151  }
1152  else if(isset($_GET['mem_id']))
1153  {
1154  $user_ids[] = $_GET['mem_id'];
1155  }
1156  else if(isset($_GET['mem_id_arr']))
1157  {
1158  $user_ids = explode(',', $_GET['mem_id_arr']);
1159  }
1160 
1161  if(empty($user_ids[0]))
1162  {
1163  $this->ilErr->raiseError($this->lng->txt("no_checkbox"), $this->ilErr->MESSAGE);
1164  }
1165 
1166  if(count($user_ids) == 1 && $ilUser->getId() != $user_ids[0])
1167  {
1168  if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID) &&
1169  !in_array($ilUser->getId(), $this->object->getAdminIds()))
1170  {
1171  $this->ilErr->raiseError($this->lng->txt("ilinc_err_no_permission"), $this->ilErr->MESSAGE);
1172  }
1173  }
1174 
1175  //bool value: says if $users_ids contains current user id
1176  $is_dismiss_me = array_search($this->ilias->account->getId(), $user_ids);
1177 
1178  $confirm = "confirmedRemoveMember";
1179  $cancel = "canceled";
1180  $info = ($is_dismiss_me !== false) ? "ilinc_dismiss_myself" : "ilinc_dismiss_member";
1181  $status = "";
1182  $return = "members";
1183 
1184  ilUtil::sendQuestion($this->lng->txt($info));
1185 
1186  $data = array();
1187  if(is_array($user_ids))
1188  {
1189  foreach($user_ids as $id)
1190  {
1191  $obj_data = ilObjectFactory::getInstanceByObjId($id);
1192  $data[$id] = array(
1193  'type' => ilUtil::getImageTagByType($obj_data->getType(), $this->tpl->tplPath),
1194  'title' => $obj_data->getTitle(),
1195  'desc' => $obj_data->getDescription(),
1196  'last_update' => $obj_data->getLastUpdateDate()
1197  );
1198  }
1199  }
1200  else
1201  {
1202  $obj_data = ilObjectFactory::getInstanceByObjId($user_ids);
1203  $data[$user_ids] = array(
1204  'type' => ilUtil::getImageTagByType($obj_data->getType(), $this->tpl->tplPath),
1205  'title' => $obj_data->getTitle(),
1206  'desc' => $obj_data->getDescription(),
1207  'last_update' => $obj_data->getLastUpdateDate(),
1208  );
1209  }
1210 
1211  //write in sessionvariables
1212  if(is_array($user_ids))
1213  {
1214  $_SESSION['saved_post']['user_id'] = $user_ids;
1215  }
1216  else
1217  {
1218  $_SESSION['saved_post']['user_id'][0] = $user_ids;
1219  }
1220 
1221  if(isset($status))
1222  {
1223  $_SESSION['saved_post']['status'] = $status;
1224  }
1225 
1226  include_once 'Modules/ILinc/classes/class.iliLinkConfirmationTableGUI.php';
1227  $this->ctrl->setParameter($this, 'cmd_return_location', $a_cmd_return_location);
1228  $this->ctrl->setParameter($this, 'mem_id_arr', implode(',', $user_ids));
1229  $oTable = new iliLinkConfirmationTableGUI($this, $data, 'removeMember', $return);
1230  $oTable->addCommandButton($cancel, $this->lng->txt('cancel'));
1231  $oTable->addCommandButton($confirm, $this->lng->txt('confirm'));
1232 
1233  return $this->tpl->setContent($oTable->getHTML());
1234  }
1235 
1240  function confirmationObject($user_id = '', $confirm = '', $cancel = '', $info = '', $status = '', $a_cmd_return_location = '', $invokeMethod = '')
1241  {
1242 
1243  }
1244 
1252  {
1253  $removed_self = false;
1254 
1255  $mail = new ilMail($_SESSION["AccountId"]);
1256 
1257  //User needs to have administrative rights to remove members...
1258  foreach($_SESSION["saved_post"]["user_id"] as $member_id)
1259  {
1260  $user_obj = new ilObjUser($member_id);
1261 
1262  if (!$this->object->removeMember($user_obj))
1263  {
1264  ilUtil::sendInfo($this->lng->txt($this->object->getErrorMsg()),true);
1265  ilUtil::redirect($this->ctrl->getLinkTarget($this,"members","",false,false));
1266  }
1267 
1268  $user_obj->dropDesktopItem($this->object->getRefId(), "icrs");
1269 
1270  if (!$removed_self and $user_obj->getId() == $this->ilias->account->getId())
1271  {
1272  $removed_self = true;
1273  }
1274  else
1275  {
1276  $mail->sendMail($user_obj->getLogin(),"","",$this->lng->txtlng("common","ilinc_mail_subj_subscription_cancelled",$user_obj->getLanguage()).": ".$this->object->getTitle(),$this->lng->txtlng("common","ilinc_mail_body_subscription_cancelled",$user_obj->getLanguage()),array(),array('normal'));
1277  }
1278  }
1279 
1280  unset($_SESSION["saved_post"]);
1281 
1282  ilUtil::sendInfo($this->lng->txt("ilinc_msg_membership_annulled"),true);
1283 
1284  if ($removed_self)
1285  {
1286  ilUtil::redirect("repository.php?ref_id=".$this->tree->getParentId($this->ref_id));
1287  }
1288 
1289  ilUtil::redirect($this->ctrl->getLinkTarget($this,"members","",false,false));
1290  }
1291 
1297  {
1298  global $rbacreview, $ilUser;
1299 
1300  $this->__setSubTabs('members');
1301 
1302  $member_ids = array();
1303 
1304  if(isset($_POST['user_id']))
1305  {
1306  $member_ids = $_POST['user_id'];
1307  }
1308  else if(isset($_GET['mem_id']))
1309  {
1310  $member_ids[0] = $_GET['mem_id'];
1311  }
1312  else if(isset($_GET['mem_id_arr']))
1313  {
1314  $member_ids = explode(',', $_GET['mem_id_arr']);
1315  }
1316 
1317  if(empty($member_ids[0]))
1318  {
1319  $this->ilErr->raiseError($this->lng->txt('no_checkbox'), $this->ilErr->MESSAGE);
1320  }
1321 
1322  if(!$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID) &&
1323  !in_array($ilUser->getId(), $this->object->getAdminIds()))
1324  {
1325  $this->ilErr->raiseError($this->lng->txt('grp_err_no_permission'), $this->ilErr->MESSAGE);
1326  }
1327 
1328  $stati = array_flip($this->object->getLocalRoles(true));
1329 
1330  // fetch docent or student assignment form all coursemembers from iLinc server
1331  $docent_ids = $this->object->getiLincMemberIds(true);
1332  $student_ids = $this->object->getiLincMemberIds(false);
1333 
1334  $data = array();
1335 
1336  //build data structure
1337  foreach($member_ids as $member_id)
1338  {
1339  $member = ilObjectFactory::getInstanceByObjId($member_id);
1340  $mem_status = $this->object->getMemberRoles($member_id);
1341 
1342  include_once 'Modules/ILinc/classes/class.ilObjiLincUser.php';
1343  $ilinc_user = new ilObjiLincUser($member);
1344 
1345  $ilinc_status = $this->object->checkiLincMemberStatus($ilinc_user->id, $docent_ids, $student_ids);
1346 
1347  $docent = 0; $student = 0;
1348 
1349  if($ilinc_status == ILINC_MEMBER_DOCENT)
1350  {
1351  $docent = 1;
1352  }
1353  else if($ilinc_status == ILINC_MEMBER_STUDENT)
1354  {
1355  $student = 1;
1356  }
1357 
1358  $radio1 = ilUtil::formRadioButton($docent, 'ilinc_member_status_select['.$member->getId().']['.$ilinc_user->id.']', ILINC_MEMBER_DOCENT);
1359  $radio2 = ilUtil::formRadioButton($student, 'ilinc_member_status_select['.$member->getId().']['.$ilinc_user->id.']', ILINC_MEMBER_STUDENT);
1360 
1361  $data[$member->getId()] = array(
1362  'login' => $member->getLogin(),
1363  'firstname' => $member->getFirstname(),
1364  'lastname' => $member->getLastname(),
1365  'attending_as' => $radio1.' '.$this->lng->txt('ilinc_docent').'<br/ '.$radio2.' '.$this->lng->txt('ilinc_student'),
1366  'grp_role' => ilUtil::formSelect($mem_status, 'member_status_select['.$member->getId().'][]', $stati, true, true, 3)
1367  );
1368  }
1369 
1370  unset($member);
1371  unset($ilinc_user);
1372 
1373  include_once 'Modules/ILinc/classes/class.iliLinkMembersTableGUI.php';
1374  $this->ctrl->setParameter($this, 'mem_id_arr', implode(',', $member_ids));
1375  $oTable = new iliLinkMembersTableGUI($this, $data, 'change', 'changeMember', 'changeMember');
1376  $oTable->setTitle($this->lng->txt('grp_mem_change_status'), 'icon_usr_b.gif', $this->lng->txt('grp_mem_change_status'));
1377 
1378  return $this->tpl->setContent($oTable->getHTML());
1379  }
1380 
1385  public function updateMemberStatusObject()
1386  {
1387  global $ilAccess;
1388 
1389  if(!$ilAccess->checkAccess('write', '', $this->object->getRefId()))
1390  {
1391  $this->ilErr->raiseError('permission_denied',$this->ilErr->MESSAGE);
1392  }
1393 
1394  if(isset($_POST['member_status_select']))
1395  {
1396  foreach($_POST['member_status_select'] as $key => $value)
1397  {
1398  $this->object->leave($key);
1399  $this->object->join($key,$value);
1400  }
1401  }
1402 
1403  if(isset($_POST['ilinc_member_status_select']))
1404  {
1405  $users_to_add = array();
1406  $users_to_register = array();
1407  $users_to_unregister = array();
1408 
1409  foreach($_POST['ilinc_member_status_select'] as $user_id => $ilinc_arr)
1410  {
1411  $ilinc_user_id = key($ilinc_arr);
1412  $ilinc_user_status = current($ilinc_arr);
1413  //var_dump($user_id,$ilinc_arr,$ilinc_user_id,$ilinc_user_status);
1414 
1415  // if no ilinc user id was passed, there are 3 options:
1416  // 1. user was added by roleassignment and is registered on iLinc server
1417  // 2. user was added by roleassignment and is registered NOT YET on iLinc server
1418  // 3. iLinc server returns an empty response which happens sometimes :-(
1419  if($ilinc_user_id == 0)
1420  {
1421  //echo '0';
1422 
1423  // check if user is already registered on iLinc server
1424  $user_obj = new ilObjUser($user_id);
1425 
1426  include_once 'Modules/ILinc/classes/class.ilObjiLincUser.php';
1427  $ilinc_user = new ilObjiLincUser($user_obj);
1428 
1429  if(!$ilinc_user->id)
1430  {
1431  // not registered. put user on 'add list'
1432  $users_to_add[] =& $user_obj;
1433  }
1434  else
1435  {
1436  $users_to_register[$ilinc_user->id] = ILINC_MEMBER_STUDENT;
1437  }
1438 
1439  continue;
1440  }
1441 
1442  //echo '1';
1443  $users_to_unregister[] = $ilinc_user_id;
1444  $users_to_register[$ilinc_user_id] = $ilinc_user_status;
1445  //var_dump($users_to_unregister,$users_to_register);
1446  }
1447 
1448  if(!$this->object->unregisterUsers($users_to_unregister))
1449  {
1450  //echo '2';
1451  //var_dump($this->object->getErrorMsg());exit;
1452  $this->ilErr->raiseError($this->object->getErrorMsg(),$this->ilErr->MESSAGE);
1453  }
1454 
1455  if(count($users_to_add) > 0)
1456  {
1457  //echo '3';
1458  foreach ($users_to_add as $user)
1459  {
1460  if (!$this->object->addUser($user))
1461  {
1462  //echo '4';
1463  //var_dump($this->object->getErrorMsg());exit;
1464  $this->ilErr->raiseError($this->object->getErrorMsg(),$this->ilErr->MESSAGE);
1465  }
1466  else
1467  {
1468  //echo '5';
1469  include_once 'Modules/ILinc/classes/class.ilObjiLincUser.php';
1470  $ilinc_user = new ilObjiLincUser($user);
1471  $users_to_register[$ilinc_user->id] = ILINC_MEMBER_STUDENT;
1472  }
1473  }
1474  }
1475 
1476  if(!$this->object->registerUsers($users_to_register))
1477  {
1478  //echo '6';
1479  //var_dump($this->object->getErrorMsg());exit;
1480  $this->ilErr->raiseError($this->object->getErrorMsg(),$this->ilErr->MESSAGE);
1481  }
1482  }
1483 
1484  ilUtil::sendInfo($this->lng->txt('msg_obj_modified'), true);
1485  ilUtil::redirect($this->ctrl->getLinkTarget($this, 'members', '', false, false));
1486  }
1487 
1488  public function editObject()
1489  {
1490  if(!$this->ilias->getSetting('ilinc_active'))
1491  {
1492  $this->ilias->raiseError($this->lng->txt('ilinc_server_not_active'), $this->ilias->error_obj->MESSAGE);
1493  }
1494 
1495  $this->initSettingsForm('edit');
1496  $this->getObjectValues();
1497  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
1498  }
1499 
1500  protected function getObjectValues()
1501  {
1502  $this->form_gui->setValuesByArray(array(
1503  'title' => $this->object->getTitle(),
1504  'desc' => $this->object->getDescription(),
1505  'activated' => (int)$this->object->activated,
1506  'akclassvalue1' => $this->object->getAKClassValue1(),
1507  'akclassvalue2' => $this->object->getAKClassValue2(),
1508  ));
1509  }
1510 
1511  protected function initSettingsForm($a_mode = 'create')
1512  {
1513  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1514 
1515  $this->form_gui = new ilPropertyFormGUI();
1516  $this->form_gui->setTableWidth('600');
1517  if($a_mode == 'create')
1518  {
1519  $this->form_gui->setTitle($this->lng->txt('icrs_new'));
1520  }
1521  else
1522  {
1523  $this->form_gui->setTitle($this->lng->txt('icrs_edit'));
1524  }
1525  $this->form_gui->setTitleIcon(ilUtil::getTypeIconPath('icrs', 0));
1526 
1527  // Title
1528  $text_input = new ilTextInputGUI($this->lng->txt('title'), 'title');
1529  $text_input->setRequired(true);
1530  $this->form_gui->addItem($text_input);
1531 
1532  // Description
1533  $text_area = new ilTextAreaInputGUI($this->lng->txt('desc'), 'desc');
1534  $this->form_gui->addItem($text_area);
1535 
1536  // Access
1537  $text_area = new ilCheckboxInputGUI($this->lng->txt('online'), 'activated');
1538  $this->form_gui->addItem($text_area);
1539 
1540  // AKClassValues
1541  if($this->ilias->getSetting('ilinc_akclassvalues_active'))
1542  {
1543  $section_header = new ilFormSectionHeaderGUI();
1544  $section_header->setTitle($this->lng->txt('akclassvalues'));
1545  $this->form_gui->addItem($section_header);
1546 
1547  $text_input = new ilTextInputGUI($this->lng->txt('akclassvalue1'), 'akclassvalue1');
1548  if($this->ilias->getSetting('ilinc_akclassvalues_required'))
1549  {
1550  $text_input->setRequired(true);
1551  }
1552  $this->form_gui->addItem($text_input);
1553 
1554  $text_input = new ilTextInputGUI($this->lng->txt('akclassvalue2'), 'akclassvalue2');
1555  $this->form_gui->addItem($text_input);
1556  }
1557 
1558  if($this->call_by_reference)
1559  {
1560  $this->ctrl->setParameter($this, 'obj_id', $this->obj_id);
1561  }
1562 
1563  // save and cancel commands
1564  if($a_mode == 'create')
1565  {
1566  $this->ctrl->setParameter($this, 'mode', 'create');
1567  $this->ctrl->setParameter($this, 'new_type', 'icrs');
1568 
1569  $this->form_gui->addCommandButton('save', $this->lng->txt('icrs_add'));
1570  $this->form_gui->addCommandButton('cancel', $this->lng->txt('cancel'));
1571  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
1572  }
1573  else
1574  {
1575  $this->form_gui->addCommandButton('update', $this->lng->txt('save'));
1576  $this->form_gui->addCommandButton('cancel', $this->lng->txt('cancel'));
1577  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'update'));
1578  }
1579  }
1580 
1581  public function joinObject()
1582  {
1583  global $ilAccess;
1584 
1585  if(!$ilAccess->checkAccess('join', '', (int)$_GET['ref_id']))
1586  {
1587  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
1588  }
1589 
1590  if(!$this->object->addMember($this->ilias->account, $this->object->getDefaultMemberRole(),false))
1591  {
1592  $this->ilErr->raiseError($this->object->getErrorMsg(), $this->ilErr->MESSAGE);
1593  }
1594 
1595  $this->ilias->account->addDesktopItem($this->object->getRefId(), "icrs");
1596 
1597  ilUtil::sendInfo($this->lng->txt("ilinc_msg_joined"), true);
1598  ilUtil::redirect($this->ctrl->getLinkTarget($this, "view", "", false, false));
1599  }
1600 
1602  {
1603  return false;
1604  }
1605 
1606  public function __setSubTabs($a_tab)
1607  {
1608  global $rbacsystem, $ilUser;
1609 
1610  switch($a_tab)
1611  {
1612  case 'members':
1613  //$this->tabs_gui->addSubTabTarget('ilinc_member_administration',
1614  $this->tabs_gui->addSubTabTarget('members', $this->ctrl->getLinkTarget($this, 'members'), array('members', 'changeMember', 'removeMember'), get_class($this));
1615  $this->tabs_gui->addSubTabTarget('icrs_members_gallery', $this->ctrl->getLinkTarget($this, 'membersGallery'), 'membersGallery', get_class($this));
1616  $this->tabs_gui->addSubTabTarget('mail_members', $this->ctrl->getLinkTarget($this, 'mailMembers'), 'mailMembers', get_class($this));
1617  break;
1618  }
1619  }
1620 
1621  public function mailMembersObject()
1622  {
1623  global $rbacreview, $ilObjDataCache;
1624 
1625  include_once 'Services/AccessControl/classes/class.ilObjRole.php';
1626 
1627  //$this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail_members.html', 'Services/Mail');
1628  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.mail_members.html','Services/Contact');
1629 
1630  $this->__setSubTabs('members');
1631 
1632  $link_data = $this->object->_getLinkToObject( $this->object->getRefId() );
1633  $link_to_seminar = ILIAS_HTTP_PATH.'/'.$link_data[0];
1634 
1635  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
1636  $this->tpl->setVariable("MAILACTION", ilMailFormCall::_getLinkTarget($this, 'mailMembers', array(), array('type' => 'role')));
1637  $this->tpl->setVariable('ADDITIONAL_MESSAGE_TEXT', $link_to_seminar);
1638  $this->tpl->setVariable('IMG_ARROW', ilUtil::getImagePath('arrow_downright.gif'));
1639  $this->tpl->setVariable('OK', $this->lng->txt('ok'));
1640 
1641  $role_folder = $rbacreview->getRoleFolderOfObject( $this->object->getRefId() );
1642  $role_ids = $rbacreview->getRolesOfRoleFolder($role_folder['ref_id'], false);
1643  foreach($role_ids as $role_id)
1644  {
1645  $this->tpl->setCurrentBlock('mailbox_row');
1646  $role_addr = $rbacreview->getRoleMailboxAddress( $role_id );
1647  $this->tpl->setVariable('CHECK_MAILBOX', ilUtil::formCheckbox(1, 'roles[]', htmlspecialchars($role_addr)));
1648  if (ilMail::_usePearMail())
1649  {
1650  // if pear mail is enabled, mailbox addresses are already localized in the language of the user
1651  $this->tpl->setVariable('MAILBOX', $role_addr);
1652  }
1653  else
1654  {
1655  // if pear mail is not enabled, we need to localize mailbox addresses in the language of the user
1656  $this->tpl->setVariable('MAILBOX', ilObjRole::_getTranslation( $ilObjDataCache->lookupTitle( $role_id ) ). ' (' . $role_addr . ')');
1657  }
1658 
1659  $this->tpl->parseCurrentBlock();
1660  }
1661  }
1662 
1668  public function membersGalleryObject()
1669  {
1670  global $rbacsystem;
1671 
1672  $is_admin = (bool) $rbacsystem->checkAccess('write', $this->object->getRefId());
1673 
1674  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.icrs_members_gallery.html','Modules/ILinc');
1675 
1676  $this->__setSubTabs('members');
1677 
1678  $this->lng->loadLanguageModule('ilinc');
1679 
1680  $member_ids = $this->object->getMemberIds();
1681 
1682  // fetch all user data in one shot to improve performance (from ILIAS db)
1683  $members = $this->object->getMemberData($member_ids);
1684 
1685  // fetch docent or student assignment form all coursemembers from iLinc server
1686  $admin_ids = $this->object->getiLincMemberIds(true);
1687 
1688  // MEMBERS
1689  if(count($members))
1690  {
1691  foreach($members as $member)
1692  {
1693  // get user object
1694  if(!($usr_obj = ilObjectFactory::getInstanceByObjId($member['id'],false)))
1695  {
1696  continue;
1697  }
1698 
1699  $public_profile = $usr_obj->getPref('public_profile');
1700 
1701  // SET LINK TARGET FOR USER PROFILE
1702  $this->ctrl->setParameterByClass('ilpublicuserprofilegui', 'user', $member['id']);
1703  $profile_target = $this->ctrl->getLinkTargetByClass('ilpublicuserprofilegui','getHTML');
1704 
1705  // GET USER IMAGE
1706  $file = $usr_obj->getPersonalPicturePath('xsmall');
1707 
1708  switch(in_array($member['ilinc_id'],$admin_ids))
1709  {
1710  //admins
1711  case 1:
1712  if($public_profile == 'y' || $public_profile == 'g')
1713  {
1714  $this->tpl->setCurrentBlock('tutor_linked');
1715  $this->tpl->setVariable('LINK_PROFILE', $profile_target);
1716  $this->tpl->setVariable('SRC_USR_IMAGE', $file);
1717  $this->tpl->parseCurrentBlock();
1718  }
1719  else
1720  {
1721  $this->tpl->setCurrentBlock('tutor_not_linked');
1722  $this->tpl->setVariable('SRC_USR_IMAGE', $file);
1723  $this->tpl->parseCurrentBlock();
1724  }
1725  $this->tpl->setCurrentBlock('tutor');
1726  break;
1727 
1728  case 0:
1729  if($public_profile == 'y' || $public_profile == 'g')
1730  {
1731  $this->tpl->setCurrentBlock('member_linked');
1732  $this->tpl->setVariable('LINK_PROFILE', $profile_target);
1733  $this->tpl->setVariable('SRC_USR_IMAGE', $file);
1734  $this->tpl->parseCurrentBlock();
1735  }
1736  else
1737  {
1738  $this->tpl->setCurrentBlock('member_not_linked');
1739  $this->tpl->setVariable('SRC_USR_IMAGE', $file);
1740  $this->tpl->parseCurrentBlock();
1741  }
1742  $this->tpl->setCurrentBlock('member');
1743  break;
1744  }
1745 
1746  // do not show name, if public profile is not activated
1747  if($public_profile == 'y' || $public_profile == 'g')
1748  {
1749  $this->tpl->setVariable('FIRSTNAME', $member['firstname']);
1750  $this->tpl->setVariable('LASTNAME', $member['lastname']);
1751  }
1752 
1753  $this->tpl->setVariable('LOGIN', $usr_obj->getLogin());
1754  $this->tpl->parseCurrentBlock();
1755  }
1756 
1757  $this->tpl->setCurrentBlock('members');
1758  $this->tpl->setVariable('MEMBERS_TABLE_HEADER',$this->lng->txt('ilinc_involved_users'));
1759  $this->tpl->parseCurrentBlock();
1760  }
1761 
1762  $this->tpl->setVariable('TITLE', $this->lng->txt('icrs_members_print_title'));
1763  $this->tpl->setVariable('CSS_PATH', ilUtil::getStyleSheetLocation());
1764 
1765  $headline = $this->object->getTitle().'<br />'.$this->object->getDescription();
1766  $this->tpl->setVariable('HEADLINE', $headline);
1767 
1768  $this->tpl->show();
1769  exit();
1770  }
1771 
1773  {
1774 
1775  }
1776 
1777  public function showAdministrationPanel($tpl)
1778  {
1779  }
1780 
1781  public static function _goto($a_target)
1782  {
1783  global $ilAccess, $ilErr, $lng;
1784 
1785  if ($ilAccess->checkAccess('read', '', $a_target))
1786  {
1787  $_GET['cmd'] = 'frameset';
1788  $_GET['ref_id'] = $a_target;
1789  }
1790  else
1791  {
1792  $ilErr->raiseError($lng->txt('msg_no_perm_read'), $ilErr->FATAL);
1793  }
1794 
1795  include 'repository.php';
1796  exit();
1797  }
1798 }
1799 ?>