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