ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilNoteGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
6 include_once("Services/Notes/classes/class.ilNote.php");
7 
8 
18 class ilNoteGUI
19 {
23  protected $ctrl;
24 
28  protected $lng;
29 
33  protected $user;
34 
38  protected $settings;
39 
43  protected $obj_definition;
44 
48  protected $tree;
49 
53  protected $access;
54 
55  public $public_deletion_enabled = false;
56  public $repository_mode = false;
57  public $old = false;
58 
59  protected $default_command = "getNotesHTML";
60 
62  protected $observer = [];
63 
67  protected $ui;
68 
72  protected $news_id = 0;
73 
78  protected $hide_new_form = false;
79 
84  protected $only_latest = false;
85 
89  protected $widget_header = "";
90 
95  protected $no_actions = false;
96 
105  public function __construct(
106  $a_rep_obj_id = "",
107  $a_obj_id = "",
108  $a_obj_type = "",
109  $a_include_subobjects = false,
110  $a_news_id = 0
111  ) {
112  global $DIC;
113 
114  $this->user = $DIC->user();
115  $this->settings = $DIC->settings();
116  $this->obj_definition = $DIC["objDefinition"];
117  $this->tree = $DIC->repositoryTree();
118  $this->access = $DIC->access();
119  $this->ui = $DIC->ui();
120  $ilCtrl = $DIC->ctrl();
121  $lng = $DIC->language();
122 
123  $lng->loadLanguageModule("notes");
124 
125  $ilCtrl->saveParameter($this, "notes_only");
126  $this->only = $_GET["notes_only"];
127 
128  $this->rep_obj_id = $a_rep_obj_id;
129  $this->obj_id = $a_obj_id;
130  $this->obj_type = $a_obj_type;
131  $this->inc_sub = $a_include_subobjects;
132  $this->news_id = $a_news_id;
133 
134  // auto-detect object type
135  if (!$this->obj_type && $a_rep_obj_id) {
136  $this->obj_type = ilObject::_lookupType($a_rep_obj_id);
137  }
138 
139  $this->ajax = $ilCtrl->isAsynch();
140 
141  $this->ctrl = $ilCtrl;
142  $this->lng = $lng;
143 
144  $this->anchor_jump = true;
145  $this->add_note_form = false;
146  $this->edit_note_form = false;
147  $this->private_enabled = false;
148 
149  if (ilNote::commentsActivated($this->rep_obj_id, $this->obj_id, $this->obj_type, $this->news_id)) {
150  $this->public_enabled = true;
151  } else {
152  $this->public_enabled = false;
153  }
154  $this->enable_hiding = false;
155  $this->targets_enabled = false;
156  $this->multi_selection = false;
157  $this->export_html = false;
158  $this->print = false;
159  $this->comments_settings = false;
160 
161  $this->note_img = array(
162  IL_NOTE_UNLABELED => array(
163  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
164  "alt" => $lng->txt("note")),
165  IL_NOTE_IMPORTANT => array(
166  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
167  "alt" => $lng->txt("note") . ", " . $lng->txt("important")),
168  IL_NOTE_QUESTION => array(
169  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
170  "alt" => $lng->txt("note") . ", " . $lng->txt("question")),
171  IL_NOTE_PRO => array(
172  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
173  "alt" => $lng->txt("note") . ", " . $lng->txt("pro")),
174  IL_NOTE_CONTRA => array(
175  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
176  "alt" => $lng->txt("note") . ", " . $lng->txt("contra"))
177  );
178 
179  $this->comment_img = array(
180  IL_NOTE_UNLABELED => array(
181  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
182  "alt" => $lng->txt("notes_comment")),
183  IL_NOTE_IMPORTANT => array(
184  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
185  "alt" => $lng->txt("notes_comment") . ", " . $lng->txt("important")),
186  IL_NOTE_QUESTION => array(
187  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
188  "alt" => $lng->txt("notes_comment") . ", " . $lng->txt("question")),
189  IL_NOTE_PRO => array(
190  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
191  "alt" => $lng->txt("notes_comment") . ", " . $lng->txt("pro")),
192  IL_NOTE_CONTRA => array(
193  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
194  "alt" => $lng->txt("notes_comment") . ", " . $lng->txt("contra"))
195  );
196 
197  // default: notes for repository objects
198  $this->setRepositoryMode(true);
199  }
200 
206  public function setDefaultCommand($a_val)
207  {
208  $this->default_command = $a_val;
209  }
210 
216  public function getDefaultCommand()
217  {
218  return $this->default_command;
219  }
220 
224  public function executeCommand()
225  {
226  $cmd = $this->ctrl->getCmd($this->getDefaultCommand());
227  $next_class = $this->ctrl->getNextClass($this);
228 
229  switch ($next_class) {
230  default:
231  return $this->$cmd();
232  break;
233  }
234  }
235 
239  public function enablePrivateNotes($a_enable = true)
240  {
241  $this->private_enabled = $a_enable;
242  }
243 
247  public function enablePublicNotes($a_enable = true)
248  {
249  $this->public_enabled = $a_enable;
250  }
251 
255  public function enableCommentsSettings($a_enable = true)
256  {
257  $this->comments_settings = $a_enable;
258  }
259 
263  public function enablePublicNotesDeletion($a_enable = true)
264  {
265  $this->public_deletion_enabled = $a_enable;
266  }
267 
271  public function enableHiding($a_enable = true)
272  {
273  $this->enable_hiding = $a_enable;
274  }
275 
279  public function enableTargets($a_enable = true)
280  {
281  $this->targets_enabled = $a_enable;
282  }
283 
287  public function enableMultiSelection($a_enable = true)
288  {
289  $this->multi_selection = $a_enable;
290  }
291 
295  public function enableAnchorJump($a_enable = true)
296  {
297  $this->anchor_jump = $a_enable;
298  }
299 
305  public function setRepositoryMode($a_value)
306  {
307  $this->repository_mode = (bool) $a_value;
308  }
309 
310 
317  public function getOnlyNotesHTML()
318  {
320  $ilCtrl->setParameter($this, "notes_only", "notes");
321  $this->only = "notes";
322  return $this->getNotesHTML($a_init_form = true);
323  }
324 
331  public function getOnlyCommentsHTML()
332  {
334  $ilCtrl->setParameter($this, "notes_only", "comments");
335  $this->only = "comments";
336  return $this->getNotesHTML($a_init_form = true);
337  }
338 
339 
340  /***
341  * get note lists html code
342  */
343  public function getNotesHTML($a_init_form = true)
344  {
346  $lng = $this->lng;
349 
350  $lng->loadLanguageModule("notes");
351 
352  $ntpl = new ilTemplate(
353  "tpl.notes_and_comments.html",
354  true,
355  true,
356  "Services/Notes"
357  );
358 
359  // check, whether column is hidden due to processing in other column
360  $hide_comments = ($this->only == "notes");
361  $hide_notes = ($this->only == "comments");
362  switch ($ilCtrl->getCmd()) {
363  case "addNoteForm":
364  case "editNoteForm":
365  case "addNote":
366  case "updateNote":
367  if ($_GET["note_type"] == IL_NOTE_PRIVATE) {
368  $hide_comments = true;
369  }
370  if ($_GET["note_type"] == IL_NOTE_PUBLIC) {
371  $hide_notes = true;
372  }
373  break;
374  }
375 
376 
377  // temp workaround: only show comments (if both have been activated)
378  if ($this->private_enabled && $this->public_enabled
379  && $this->only != "notes") {
380  $this->private_enabled = false;
381  }
382 
383  $nodes_col = false;
384  if ($this->private_enabled && ($ilUser->getId() != ANONYMOUS_USER_ID)
385  && !$hide_notes) {
386  $ntpl->setCurrentBlock("notes_col");
387  $ntpl->setVariable("NOTES", $this->getNoteListHTML(IL_NOTE_PRIVATE, $a_init_form));
388  $ntpl->parseCurrentBlock();
389  $nodes_col = true;
390  }
391 
392  // #15948 - public enabled vs. comments_settings
393  $comments_col = false;
394  if ($this->public_enabled && (!$this->delete_note || $this->public_deletion_enabled || $ilSetting->get("comments_del_user", 0))
395  && !$hide_comments /* && $ilUser->getId() != ANONYMOUS_USER_ID */) {
396  $ntpl->setVariable("COMMENTS", $this->getNoteListHTML(IL_NOTE_PUBLIC, $a_init_form));
397  $comments_col = true;
398  }
399 
400  // Comments Settings
401  if ($this->comments_settings && !$hide_comments && !$this->delete_note
402  && !$this->edit_note_form && !$this->add_note_form && $ilUser->getId() != ANONYMOUS_USER_ID) {
403  //$active = $notes_settings->get("activate_".$id);
404  $active = ilNote::commentsActivated($this->rep_obj_id, $this->obj_id, $this->obj_type);
405 
406  if ($active) {
407  if ($this->news_id == 0) {
408  $this->renderLink(
409  $ntpl,
410  "comments_settings",
411  $lng->txt("notes_deactivate_comments"),
412  "deactivateComments",
413  "notes_top"
414  );
415  }
416  $ntpl->setCurrentBlock("comments_settings2");
417  } else {
418  $this->renderLink(
419  $ntpl,
420  "comments_settings",
421  $lng->txt("notes_activate_comments"),
422  "activateComments",
423  "notes_top"
424  );
425  $ntpl->setCurrentBlock("comments_settings2");
426 
427  if ($this->ajax && !$comments_col) {
428  $ntpl->setVariable(
429  "COMMENTS_MESS",
430  ilUtil::getSystemMessageHTML($lng->txt("comments_feature_currently_not_activated_for_object"), "info")
431  );
432  }
433  }
434  $ntpl->parseCurrentBlock();
435 
436  if (!$comments_col) {
437  $ntpl->setVariable("COMMENTS", "");
438  }
439 
440  $comments_col = true;
441  }
442 
443  if ($comments_col) {
444  $ntpl->setCurrentBlock("comments_col");
445  if ($nodes_col) {
446  // $ntpl->touchBlock("comments_style");
447  }
448  $ntpl->parseCurrentBlock();
449  }
450 
451  if ($this->ajax) {
452  echo $ntpl->get();
453  exit;
454  }
455 
456  return $ntpl->get();
457  }
458 
462  public function activateComments()
463  {
465 
466  if ($this->comments_settings) {
467  ilNote::activateComments($this->rep_obj_id, $this->obj_id, $this->obj_type, true);
468  }
469 
470  $ilCtrl->redirectByClass("ilnotegui", "showNotes", "", $this->ajax);
471  }
472 
476  public function deactivateComments()
477  {
479 
480  if ($this->comments_settings) {
481  ilNote::activateComments($this->rep_obj_id, $this->obj_id, $this->obj_type, false);
482  }
483 
484  $ilCtrl->redirectByClass("ilnotegui", "showNotes", "", $this->ajax);
485  }
486 
490  public function getNoteListHTML($a_type = IL_NOTE_PRIVATE, $a_init_form = true)
491  {
492  $lng = $this->lng;
495 
496  include_once("./Services/User/classes/class.ilUserUtil.php");
497 
498  $suffix = ($a_type == IL_NOTE_PRIVATE)
499  ? "private"
500  : "public";
501 
502  $user_setting_notes_public_all = "y";
503  $user_setting_notes_by_type = "y";
504 
505  if ($this->delete_note || $this->export_html || $this->print) {
506  if ($_GET["note_id"] != "") {
507  $filter = $_GET["note_id"];
508  } else {
509  $filter = $_POST["note"];
510  }
511  }
512 
513  $order = (bool) $_SESSION["comments_sort_asc"];
514  if ($this->only_latest) {
515  $order = false;
516  }
517 
518 
519  $notes = ilNote::_getNotesOfObject(
520  $this->rep_obj_id,
521  $this->obj_id,
522  $this->obj_type,
523  $a_type,
524  $this->inc_sub,
525  $filter,
526  $user_setting_notes_public_all,
527  $this->repository_mode,
528  $order,
529  $this->news_id
530  );
531 
532  $tpl = new ilTemplate("tpl.notes_list.html", true, true, "Services/Notes");
533 
534  if ($this->ajax) {
535  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
536  $tpl->setCurrentBlock("close_img");
537  $tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
538  $tpl->parseCurrentBlock();
539  }
540 
541  // show counter if notes are hidden
542  $cnt_str = (count($notes) > 0)
543  ? " (" . count($notes) . ")"
544  : "";
545 
546  // title
547  if ($this->ajax && !$this->only_latest) {
548  switch ($this->obj_type) {
549  case "grpr":
550  case "catr":
551  case "crsr":
552  include_once "Services/ContainerReference/classes/class.ilContainerReference.php";
553  $title = ilContainerReference::_lookupTitle($this->rep_obj_id);
554  break;
555 
556  default:
557  $title = ilObject::_lookupTitle($this->rep_obj_id);
558  break;
559  }
560 
561  $img = ilUtil::img(ilObject::_getIcon($this->rep_obj_id, "tiny"));
562 
563  // add sub-object if given
564  if ($this->obj_id) {
565  $sub_title = $this->getSubObjectTitle($this->rep_obj_id, $this->obj_id);
566  if ($sub_title) {
567  $title .= " - " . $sub_title;
568  }
569  }
570 
571  $tpl->setCurrentBlock("title");
572  $tpl->setVariable("TITLE", $img . " " . $title);
573  $tpl->parseCurrentBlock();
574  }
575 
576  if ($this->delete_note) {
577  $cnt_str = "";
578  }
579  if ($a_type == IL_NOTE_PRIVATE) {
580  $tpl->setVariable("TXT_NOTES", $lng->txt("private_notes") . $cnt_str);
581  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PRIVATE);
582  } else {
583  $tpl->setVariable("TXT_NOTES", $lng->txt("notes_public_comments") . $cnt_str);
584  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PUBLIC);
585  }
586  $anch = $this->anchor_jump
587  ? "notes_top"
588  : "";
589  if (!$this->only_latest) {
590  $tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this, "getNotesHTML", $anch));
591  if ($this->ajax) {
592  $os = "onsubmit = \"ilNotes.cmdAjaxForm(event, '" .
593  $ilCtrl->getFormActionByClass("ilnotegui", "", "", true) .
594  "'); return false;\"";
595  $tpl->setVariable("ON_SUBMIT_FORM", $os);
596  $tpl->setVariable("FORM_ID", "id='ilNoteFormAjax'");
597  }
598  }
599 
600 
601  if ($this->export_html || $this->print) {
602  $tpl->touchBlock("print_style");
603  }
604 
605  // show add new note button
606  /*
607  if (!$this->add_note_form && !$this->edit_note_form && !$this->delete_note &&
608  !$this->export_html && !$this->print && $ilUser->getId() != ANONYMOUS_USER_ID && !$this->hide_new_form) {
609  if (!$this->inc_sub) { // we cannot offer add button if aggregated notes
610  // are displayed
611  if ($this->rep_obj_id > 0 || $a_type != IL_NOTE_PUBLIC) {
612  $tpl->setCurrentBlock("add_note_btn");
613  if ($a_type == IL_NOTE_PUBLIC) {
614  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("notes_add_comment"));
615  } else {
616  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("add_note"));
617  }
618  $tpl->setVariable("LINK_ADD_NOTE", $ilCtrl->getLinkTargetByClass("ilnotegui", "addNoteForm") .
619  "#note_edit");
620  $tpl->parseCurrentBlock();
621  }
622  }
623  }*/
624 
625  // show show/hide button for note list
626  if (count($notes) > 0 && $this->enable_hiding && !$this->delete_note
627  && !$this->export_html && !$this->print && !$this->edit_note_form
628  && !$this->add_note_form) {
629  if ($user_setting_notes_by_type == "n") {
630  if ($a_type == IL_NOTE_PUBLIC) {
631  $txt = $lng->txt("notes_show_comments");
632  } else {
633  $txt = $lng->txt("show_" . $suffix . "_notes");
634  }
635  $this->renderLink($tpl, "show_notes", $txt, "showNotes", "notes_top");
636  } else {
637  // never individually hide for anonymous users
638  if (($ilUser->getId() != ANONYMOUS_USER_ID)) {
639  if ($a_type == IL_NOTE_PUBLIC) {
640  $txt = $lng->txt("notes_hide_comments");
641  } else {
642  $txt = $lng->txt("hide_" . $suffix . "_notes");
643  }
644  $this->renderLink($tpl, "hide_notes", $txt, "hideNotes", "notes_top");
645 
646  // show all public notes / my notes only switch
647  if ($a_type == IL_NOTE_PUBLIC) {
648  if ($user_setting_notes_public_all == "n") {
649  $this->renderLink(
650  $tpl,
651  "all_pub_notes",
652  $lng->txt("notes_all_comments"),
653  "showAllPublicNotes",
654  "notes_top"
655  );
656  } else {
657  $this->renderLink(
658  $tpl,
659  "my_pub_notes",
660  $lng->txt("notes_my_comments"),
661  "showMyPublicNotes",
662  "notes_top"
663  );
664  }
665  }
666  }
667  }
668  }
669 
670  // show add new note text area
671  if (!$this->edit_note_form && $user_setting_notes_by_type != "n" &&
672  !$this->delete_note && $ilUser->getId() != ANONYMOUS_USER_ID && !$this->hide_new_form) {
673  if ($a_init_form) {
674  $this->initNoteForm("create", $a_type);
675  }
676 
677  $tpl->setCurrentBlock("edit_note_form");
678  // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
679  $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
680  $tpl->parseCurrentBlock();
681 
682  $tpl->parseCurrentBlock();
683  $tpl->setCurrentBlock("note_row");
684  $tpl->parseCurrentBlock();
685  }
686 
687  // list all notes
688  if ($user_setting_notes_by_type != "n" || !$this->enable_hiding) {
691 
692  if (sizeof($notes) && !$this->only_latest) {
693  if ((int) $_SESSION["comments_sort_asc"] == 1) {
694  $sort_txt = $lng->txt("notes_sort_desc");
695  $sort_cmd = "listSortDesc";
696  } else {
697  $sort_txt = $lng->txt("notes_sort_asc");
698  $sort_cmd = "listSortAsc";
699  }
700  $this->renderLink($tpl, "sort_list", $sort_txt, $sort_cmd, $anch);
701  }
702 
703  $notes_given = false;
704  foreach ($notes as $note) {
705  if ($this->only_latest && $notes_given) {
706  continue;
707  }
708 
709 
710  if ($this->edit_note_form && ($note->getId() == $_GET["note_id"])
711  && $a_type == $_GET["note_type"]) {
712  if ($a_init_form) {
713  $this->initNoteForm("edit", $a_type, $note);
714  }
715  $tpl->setCurrentBlock("edit_note_form");
716  // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
717  $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
718  $tpl->parseCurrentBlock();
719  } else {
720  $cnt_col = 2;
721 
722  // delete note stuff for all private notes
723  if ($this->checkDeletion($note)
724  && !$this->delete_note
725  && !$this->export_html && !$this->print
726  && !$this->edit_note_form && !$this->add_note_form && !$this->no_actions) {
727  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
728  $this->renderLink(
729  $tpl,
730  "delete_note",
731  $lng->txt("delete"),
732  "deleteNote",
733  "note_" . $note->getId()
734  );
735  }
736 
737  // checkboxes in multiselection mode
738  if ($this->multi_selection && !$this->delete_note) {
739  $tpl->setVariable("CHECKBOX_CLASS", "ilNotesCheckboxes");
740  $tpl->setCurrentBlock("checkbox_col");
741  $tpl->setVariable("CHK_NOTE", "note[]");
742  $tpl->setVariable("CHK_NOTE_ID", $note->getId());
743  $tpl->parseCurrentBlock();
744  $cnt_col = 1;
745  }
746 
747  // edit note stuff for all private notes
748  if ($this->checkEdit($note)) {
749  if (!$this->delete_note && !$this->export_html && !$this->print
750  && !$this->edit_note_form && !$this->add_note_form && !$this->no_actions) {
751  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
752  $this->renderLink(
753  $tpl,
754  "edit_note",
755  $lng->txt("edit"),
756  "editNoteForm",
757  "note_edit"
758  );
759  }
760  }
761 
762  $tpl->setVariable("CNT_COL", $cnt_col);
763 
764  // output author account
765  if ($a_type == IL_NOTE_PUBLIC && ilObject::_exists($note->getAuthor())) {
766  //$tpl->setCurrentBlock("author");
767  //$tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin($note->getAuthor()));
768  //$tpl->parseCurrentBlock();
769  $tpl->setCurrentBlock("user_img");
770  $tpl->setVariable(
771  "USR_IMG",
772  ilObjUser::_getPersonalPicturePath($note->getAuthor(), "xsmall")
773  );
774  $tpl->setVariable("USR_ALT", $lng->txt("user_image") . ": " .
775  ilObjUser::_lookupLogin($note->getAuthor()));
776  $tpl->parseCurrentBlock();
777  $tpl->setVariable(
778  "TXT_USR",
779  ilUserUtil::getNamePresentation($note->getAuthor(), false, false) . " - "
780  );
781  }
782 
783  // last edited
784  if ($note->getUpdateDate() != null) {
785  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
786  $tpl->setVariable(
787  "DATE_LAST_EDIT",
788  ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME))
789  );
790  } else {
791  $tpl->setVariable(
792  "VAL_DATE",
793  ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME))
794  );
795  }
796 
797  // hidden note ids for deletion
798  if ($this->delete_note) {
799  $tpl->setCurrentBlock("delete_ids");
800  $tpl->setVariable("HID_NOTE", "note[]");
801  $tpl->setVariable("HID_NOTE_ID", $note->getId());
802  $tpl->parseCurrentBlock();
803  }
804  $target = $note->getObject();
805 
806 
807  $tpl->setCurrentBlock("note");
808  $text = (trim($note->getText()) != "")
809  ? nl2br($note->getText())
810  : "<p class='subtitle'>" . $lng->txt("note_content_removed") . "</p>";
811  $tpl->setVariable("NOTE_TEXT", $text);
812  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
813  $tpl->setVariable("NOTE_ID", $note->getId());
814 
815  // target objects
816  $tpl->setVariable(
817  "TARGET_OBJECTS",
818  $this->renderTargets($note)
819  );
820 
821  $tpl->parseCurrentBlock();
822  }
823  $tpl->setCurrentBlock("note_row");
824  $tpl->parseCurrentBlock();
825  $notes_given = true;
826  }
827 
828  if (!$notes_given) {
829  $tpl->setCurrentBlock("no_notes");
830  if ($a_type == IL_NOTE_PUBLIC && !$this->only_latest) {
831  $tpl->setVariable("NO_NOTES", $lng->txt("notes_no_comments"));
832  }
833  $tpl->parseCurrentBlock();
834  }
835 
837 
838  // multiple items commands
839  if ($this->multi_selection && !$this->delete_note && !$this->edit_note_form
840  && count($notes) > 0) {
841  if ($a_type == IL_NOTE_PRIVATE) {
842  $tpl->setCurrentBlock("delete_cmd");
843  $tpl->setVariable("TXT_DELETE_NOTES", $this->lng->txt("delete"));
844  $tpl->parseCurrentBlock();
845  }
846 
847  $tpl->setCurrentBlock("multiple_commands");
848  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
849  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
850  $tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
851  $tpl->setVariable("TXT_PRINT_NOTES", $this->lng->txt("print"));
852  $tpl->setVariable("TXT_EXPORT_NOTES", $this->lng->txt("exp_html"));
853  $tpl->parseCurrentBlock();
854  }
855 
856  // delete / cancel row
857  if ($this->delete_note) {
858  $tpl->setCurrentBlock("delete_cancel");
859  $tpl->setVariable("TXT_DEL_NOTES", $this->lng->txt("delete"));
860  $tpl->setVariable("TXT_CANCEL_DEL_NOTES", $this->lng->txt("cancel"));
861  $tpl->parseCurrentBlock();
862  }
863 
864  // print
865  if ($this->print) {
866  $tpl->touchBlock("print_js");
867  $tpl->setCurrentBlock("print_back");
868  $tpl->setVariable("LINK_BACK", $this->ctrl->getLinkTarget($this, "showNotes"));
869  $tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
870  $tpl->parseCurrentBlock();
871  }
872  }
873 
874  // message
875  switch ($_GET["note_mess"] != "" ? $_GET["note_mess"] : $this->note_mess) {
876  case "mod":
877  $mtype = "success";
878  $mtxt = $lng->txt("msg_obj_modified");
879  break;
880 
881  case "ntsdel":
882  $mtype = "success";
883  $mtxt = ($a_type == IL_NOTE_PRIVATE)
884  ? $lng->txt("notes_notes_deleted")
885  : $lng->txt("notes_comments_deleted");
886  break;
887 
888  case "ntdel":
889  $mtype = "success";
890  $mtxt = ($a_type == IL_NOTE_PRIVATE)
891  ? $lng->txt("notes_note_deleted")
892  : $lng->txt("notes_comment_deleted");
893  break;
894 
895  case "frmfld":
896  $mtype = "failure";
897  $mtxt = $lng->txt("form_input_not_valid");
898  break;
899 
900  case "qdel":
901  $mtype = "question";
902  $mtxt = $lng->txt("info_delete_sure");
903  break;
904 
905  case "noc":
906  $mtype = "failure";
907  $mtxt = $lng->txt("no_checkbox");
908  break;
909  }
910  if ($mtxt != "") {
911  $tpl->setVariable("MESS", ilUtil::getSystemMessageHTML($mtxt, $mtype));
912  } else {
913  $tpl->setVariable("MESS", "");
914  }
915 
916  if ($this->widget_header != "") {
917  $tpl->setVariable("WIDGET_HEADER", $this->widget_header);
918  }
919 
920 
921  if ($this->delete_note && count($notes) == 0) {
922  return "";
923  } else {
924  return $tpl->get();
925  }
926  }
927 
935  protected function getSubObjectTitle($parent_obj_id, $sub_obj_id)
936  {
937  $objDefinition = $this->obj_definition;
939 
940  $parent_type = ilObject::_lookupType($parent_obj_id);
941  $parent_class = "ilObj" . $objDefinition->getClassName($parent_type) . "GUI";
942  $parent_path = $ilCtrl->lookupClassPath($parent_class);
943  include_once $parent_path;
944  if (method_exists($parent_class, "lookupSubObjectTitle")) {
945  return call_user_func_array(array($parent_class, "lookupSubObjectTitle"), array($parent_obj_id, $sub_obj_id));
946  }
947  }
948 
952  public function checkDeletion($a_note)
953  {
956 
957  if ($ilUser->getId() == ANONYMOUS_USER_ID) {
958  return false;
959  }
960 
961  $is_author = ($a_note->getAuthor() == $ilUser->getId());
962 
963  if ($a_note->getType() == IL_NOTE_PRIVATE && $is_author) {
964  return true;
965  }
966 
967  if ($a_note->getType() == IL_NOTE_PUBLIC && $this->public_deletion_enabled) {
968  return true;
969  }
970 
971  if ($a_note->getType() == IL_NOTE_PUBLIC && $is_author && $ilSetting->get("comments_del_user", 0)) {
972  return true;
973  }
974 
975  return false;
976  }
977 
981  public function checkEdit($a_note)
982  {
984 
985  if ($a_note->getAuthor() == $ilUser->getId()
986  && ($ilUser->getId() != ANONYMOUS_USER_ID)) {
987  return true;
988  }
989  return false;
990  }
991 
992 
998  public function initNoteForm($a_mode = "edit", $a_type, $a_note = null)
999  {
1000  $lng = $this->lng;
1001  $ilCtrl = $this->ctrl;
1002 
1003  $this->form_tpl = new ilTemplate("tpl.notes_edit.html", true, true, "Services/Notes");
1004  $this->form_tpl->setVariable("LABEL", ($a_type == IL_NOTE_PUBLIC)
1005  ? $lng->txt("comment")
1006  : $lng->txt("note"));
1007 
1008  if ($a_note) {
1009  $this->form_tpl->setVariable("VAL_NOTE", ilUtil::prepareFormOutput($a_note->getText()));
1010  $this->form_tpl->setVariable("NOTE_ID", $a_note->getId());
1011  }
1012 
1013  if ($a_mode == "create") {
1014  $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
1015  ? $lng->txt("note_add_comment")
1016  : $lng->txt("note_add_note"));
1017  $this->form_tpl->setVariable("CMD", "addNote");
1018  } else {
1019  $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
1020  ? $lng->txt("note_update_comment")
1021  : $lng->txt("note_update_note"));
1022  $this->form_tpl->setVariable("CMD", "updateNote");
1023  }
1024 
1025  return;
1026  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1027  $this->form = new ilPropertyFormGUI();
1028  $this->form->setOpenTag(false);
1029  $this->form->setCloseTag(false);
1030  $this->form->setDisableStandardMessage(true);
1031 
1032  // subject
1033  /* $ti = new ilTextInputGUI($this->lng->txt("subject"), "sub_note");
1034  $ti->setRequired(true);
1035  $ti->setMaxLength(200);
1036  $ti->setSize(40);
1037  if ($a_note)
1038  {
1039  $ti->setValue($a_note->getSubject());
1040  }
1041  $this->form->addItem($ti);*/
1042 
1043  // text
1044  // $ta = new ilTextAreaInputGUI(($a_type == IL_NOTE_PUBLIC)
1045  // ? $lng->txt("notes_comment")
1046  // : $lng->txt("note"), "note");
1047  $ta = new ilTextAreaInputGUI("", "note");
1048  $ta->setCols(40);
1049  $ta->setRows(4);
1050  if ($a_note) {
1051  $ta->setValue($a_note->getText());
1052  }
1053  $this->form->addItem($ta);
1054 
1055  // label
1056  /* $options = array(
1057  IL_NOTE_UNLABELED => $lng->txt("unlabeled"),
1058  IL_NOTE_QUESTION => $lng->txt("question"),
1059  IL_NOTE_IMPORTANT => $lng->txt("important"),
1060  IL_NOTE_PRO => $lng->txt("pro"),
1061  IL_NOTE_CONTRA => $lng->txt("contra"),
1062  );
1063  $si = new ilSelectInputGUI($this->lng->txt("notes_label"), "note_label");
1064  $si->setOptions($options);
1065  if ($a_note)
1066  {
1067  $si->setValue($a_note->getLabel());
1068  }
1069  $this->form->addItem($si); */
1070 
1071  // hidden note id
1072  if ($a_note) {
1073  $hi = new ilHiddenInputGUI("note_id");
1074  $hi->setValue($_GET["note_id"]);
1075  $this->form->addItem($hi);
1076  }
1077 
1078  // save and cancel commands
1079  if ($a_mode == "create") {
1080  $this->form->addCommandButton("addNote", $lng->txt("save"));
1081  /* $this->form->addCommandButton("cancelAddNote", $lng->txt("cancel"));
1082  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1083  ? $lng->txt("notes_add_comment")
1084  : $lng->txt("notes_add_note"));*/
1085  } else {
1086  $this->form->addCommandButton("updateNote", $lng->txt("save"));
1087  /* $this->form->addCommandButton("cancelUpdateNote", $lng->txt("cancel"));
1088  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1089  ? $lng->txt("notes_edit_comment")
1090  : $lng->txt("notes_edit_note"));*/
1091  }
1092 
1093  $ilCtrl->setParameter($this, "note_type", $a_type);
1094  $this->form->setFormAction($this->ctrl->getFormAction($this));
1095  }
1096 
1100  public function getPDNoteHTML($note_id)
1101  {
1102  $lng = $this->lng;
1103  $ilCtrl = $this->ctrl;
1104  $ilUser = $this->user;
1105 
1106  $tpl = new ilTemplate("tpl.pd_note.html", true, true, "Services/Notes");
1107  $note = new ilNote($note_id);
1108  $target = $note->getObject();
1109 
1110  if ($note->getAuthor() != $ilUser->getId()) {
1111  return;
1112  }
1113 
1114  $tpl->setCurrentBlock("edit_note");
1115  $ilCtrl->setParameterByClass("ilnotegui", "rel_obj", $target["rep_obj_id"]);
1116  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note_id);
1117  $ilCtrl->setParameterByClass("ilnotegui", "note_type", $note->getType());
1118  $tpl->setVariable(
1119  "LINK_EDIT_NOTE",
1120  $ilCtrl->getLinkTargetByClass(
1121  array("ildashboardgui", "ilpdnotesgui", "ilnotegui"),
1122  "editNoteForm"
1123  )
1124  );
1125  $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
1126  $tpl->parseCurrentBlock();
1127  $ilCtrl->clearParametersByClass("ilnotegui");
1128 
1129  // last edited
1130  if ($note->getUpdateDate() != null) {
1131  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
1132  $tpl->setVariable(
1133  "DATE_LAST_EDIT",
1134  ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME))
1135  );
1136  } else {
1137  //$tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
1138  $tpl->setVariable(
1139  "VAL_DATE",
1140  ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME))
1141  );
1142  }
1143 
1144  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
1145  $text = (trim($note->getText()) != "")
1146  ? nl2br($note->getText())
1147  : "<p class='subtitle'>" . $lng->txt("note_content_removed") . "</p>";
1148  $tpl->setVariable("NOTE_TEXT", $text);
1149  $tpl->setVariable("TARGET_OBJECTS", $this->renderTargets($note));
1150  return $tpl->get();
1151  }
1152 
1156  public function renderTargets($a_note)
1157  {
1158  $tree = $this->tree;
1159  $ilAccess = $this->access;
1160  $objDefinition = $this->obj_definition;
1161  $ilUser = $this->user;
1162 
1163  if (!$this->targets_enabled) {
1164  return "";
1165  }
1166 
1167  $a_note_id = $a_note->getId();
1168  $target = $a_note->getObject();
1169  $a_obj_type = $target["obj_type"];
1170  $a_obj_id = $target["obj_id"];
1171 
1172  $target_tpl = new ilTemplate("tpl.note_target_object.html", true, true, "Services/Notes");
1173 
1174  if ($target["rep_obj_id"] > 0) {
1175  // get all visible references of target object
1176 
1177  // repository
1178  $ref_ids = ilObject::_getAllReferences($target["rep_obj_id"]);
1179  if ($ref_ids) {
1180  $vis_ref_ids = array();
1181  foreach ($ref_ids as $ref_id) {
1182  if ($ilAccess->checkAccess("visible", "", $ref_id)) {
1183  $vis_ref_ids[] = $ref_id;
1184  }
1185  }
1186 
1187  // output links to targets
1188  if (count($vis_ref_ids) > 0) {
1189  foreach ($vis_ref_ids as $vis_ref_id) {
1190  $type = ilObject::_lookupType($vis_ref_id, true);
1191  $title = ilObject::_lookupTitle($target["rep_obj_id"]);
1192 
1193  $sub_link = $sub_title = "";
1194  if ($type == "sahs") { // bad hack, needs general procedure
1195  $link = "goto.php?target=sahs_" . $vis_ref_id;
1196  if ($a_obj_type == "sco" || $a_obj_type == "seqc" || $a_obj_type == "chap" || $a_obj_type == "pg") {
1197  $sub_link = "goto.php?target=sahs_" . $vis_ref_id . "_" . $a_obj_id;
1198  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
1199  $sub_title = ilSCORM2004Node::_lookupTitle($a_obj_id);
1200  }
1201  } elseif ($type == "poll") {
1202  include_once "Services/Link/classes/class.ilLink.php";
1203  $link = ilLink::_getLink($vis_ref_id, "poll");
1204  } elseif ($a_obj_type != "pg") {
1205  if (!is_object($this->item_list_gui[$type])) {
1206  $class = $objDefinition->getClassName($type);
1207  $location = $objDefinition->getLocation($type);
1208  $full_class = "ilObj" . $class . "ListGUI";
1209  include_once($location . "/class." . $full_class . ".php");
1210  $this->item_list_gui[$type] = new $full_class();
1211  }
1212 
1213  // for references, get original title
1214  // (link will lead to orignal, which basically is wrong though)
1215  if ($a_obj_type == "crsr" || $a_obj_type == "catr" || $a_obj_type == "grpr") {
1216  include_once "Services/ContainerReference/classes/class.ilContainerReference.php";
1217  $tgt_obj_id = ilContainerReference::_lookupTargetId($target["rep_obj_id"]);
1218  $title = ilObject::_lookupTitle($tgt_obj_id);
1219  }
1220  $this->item_list_gui[$type]->initItem($vis_ref_id, $target["rep_obj_id"], $title, $a_obj_type);
1221  $link = $this->item_list_gui[$type]->getCommandLink("infoScreen");
1222 
1223  // workaround, because # anchor can't be passed through frameset
1224  $link = ilUtil::appendUrlParameterString($link, "anchor=note_" . $a_note_id);
1225 
1226  $link = $this->item_list_gui[$type]->appendRepositoryFrameParameter($link) . "#note_" . $a_note_id;
1227  } else {
1228  $title = ilObject::_lookupTitle($target["rep_obj_id"]);
1229  $link = "goto.php?target=pg_" . $a_obj_id . "_" . $vis_ref_id;
1230  }
1231 
1232  $par_id = $tree->getParentId($vis_ref_id);
1233 
1234  // sub object link
1235  if ($sub_link != "") {
1236  if ($this->export_html || $this->print) {
1237  $target_tpl->setCurrentBlock("exp_target_sub_object");
1238  } else {
1239  $target_tpl->setCurrentBlock("target_sub_object");
1240  $target_tpl->setVariable("LINK_SUB_TARGET", $sub_link);
1241  }
1242  $target_tpl->setVariable("TXT_SUB_TARGET", $sub_title);
1243  $target_tpl->parseCurrentBlock();
1244  }
1245 
1246  // container and object link
1247  if ($this->export_html || $this->print) {
1248  $target_tpl->setCurrentBlock("exp_target_object");
1249  } else {
1250  $target_tpl->setCurrentBlock("target_object");
1251  $target_tpl->setVariable("LINK_TARGET", $link);
1252  }
1253  $target_tpl->setVariable(
1254  "TXT_CONTAINER",
1256  ilObject::_lookupObjId($par_id)
1257  )
1258  );
1259  $target_tpl->setVariable("TXT_TARGET", $title);
1260 
1261  $target_tpl->parseCurrentBlock();
1262  }
1263  $target_tpl->touchBlock("target_objects");
1264  }
1265  }
1266  // personal workspace
1267  else {
1268  // we only need 1 instance
1269  if (!$this->wsp_tree) {
1270  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1271  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
1272  $this->wsp_tree = new ilWorkspaceTree($ilUser->getId());
1273  $this->wsp_access_handler = new ilWorkspaceAccessHandler($this->wsp_tree);
1274  }
1275  $node_id = $this->wsp_tree->lookupNodeId($target["rep_obj_id"]);
1276  if ($this->wsp_access_handler->checkAccess("visible", "", $node_id)) {
1277  $path = $this->wsp_tree->getPathFull($node_id);
1278  if ($path) {
1279  $item = array_pop($path);
1280  $parent = array_pop($path);
1281 
1282  if (!$parent["title"]) {
1283  $parent["title"] = $this->lng->txt("personal_resources");
1284  }
1285 
1286  // sub-objects
1287  $additional = null;
1288  if ($a_obj_id) {
1289  $sub_title = $this->getSubObjectTitle($target["rep_obj_id"], $a_obj_id);
1290  if ($sub_title) {
1291  $item["title"] .= " (" . $sub_title . ")";
1292  $additional = "_" . $a_obj_id;
1293  }
1294  }
1295 
1296  $link = ilWorkspaceAccessHandler::getGotoLink($node_id, $target["rep_obj_id"], $additional);
1297  }
1298  // shared resource
1299  else {
1300  $owner = ilObject::_lookupOwner($target["rep_obj_id"]);
1301  $parent["title"] = $this->lng->txt("wsp_tab_shared") .
1302  " (" . ilObject::_lookupOwnerName($owner) . ")";
1303  $item["title"] = ilObject::_lookupTitle($target["rep_obj_id"]);
1304  $link = "ilias.php?baseClass=ilDashboardGUI&cmd=jumpToWorkspace&dsh=" .
1305  $owner;
1306  }
1307 
1308  // container and object link
1309  if ($this->export_html || $this->print) {
1310  $target_tpl->setCurrentBlock("exp_target_object");
1311  } else {
1312  $target_tpl->setCurrentBlock("target_object");
1313  $target_tpl->setVariable("LINK_TARGET", $link);
1314  }
1315 
1316 
1317  // :TODO: no images in template ?
1318 
1319  $target_tpl->setVariable("TXT_CONTAINER", $parent["title"]);
1320 
1321  $target_tpl->setVariable("TXT_TARGET", $item["title"]);
1322 
1323  $target_tpl->parseCurrentBlock();
1324  }
1325  }
1326  }
1327  return $target_tpl->get();
1328  }
1329 
1333  public function addNoteForm($a_init_form = true)
1334  {
1335  $ilUser = $this->user;
1336 
1337  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1338  ? "private"
1339  : "public";
1340  $ilUser->setPref("notes_" . $suffix, "y");
1341 
1342  $this->add_note_form = true;
1343  return $this->getNotesHTML($a_init_form);
1344  }
1345 
1349  public function cancelAddNote()
1350  {
1351  return $this->getNotesHTML();
1352  }
1353 
1357  public function cancelUpdateNote()
1358  {
1359  return $this->getNotesHTML();
1360  }
1361 
1365  public function addNote()
1366  {
1367  $ilUser = $this->user;
1368  $lng = $this->lng;
1369  $ilCtrl = $this->ctrl;
1370  //ilLoggerFactory::getLogger("root")->notice("addNote");
1371  $this->initNoteForm("create", $_GET["note_type"]);
1372 
1373  //if ($this->form->checkInput())
1374  if ($_POST["note"] != "") {
1375  $note = new ilNote();
1376  $note->setObject($this->obj_type, $this->rep_obj_id, $this->obj_id, $this->news_id);
1377  $note->setInRepository($this->repository_mode);
1378  $note->setType($_GET["note_type"]);
1379  $note->setAuthor($ilUser->getId());
1380  $note->setText(ilUtil::stripslashes($_POST["note"]));
1381  // $note->setSubject($_POST["sub_note"]);
1382  // $note->setLabel($_POST["note_label"]);
1383  $note->create();
1384 
1385  $this->notifyObserver("new", $note);
1386 
1387  $ilCtrl->setParameter($this, "note_mess", "mod");
1388  // $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1389  }
1390  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1391  // $this->note_mess = "frmfld";
1392 // $this->form->setValuesByPost();
1393 // return $this->addNoteForm(false);;
1394  }
1395 
1399  public function updateNote()
1400  {
1401  $ilUser = $this->user;
1402  $lng = $this->lng;
1403  $ilCtrl = $this->ctrl;
1404 
1405  $note = new ilNote(ilUtil::stripSlashes($_POST["note_id"]));
1406  $this->initNoteForm(
1407  "edit",
1408  $note->getType(),
1409  $note
1410  );
1411 
1412  // if ($this->form->checkInput())
1413  // if ($_POST["note"] != "")
1414  // {
1415  $note->setText(ilUtil::stripSlashes($_POST["note"]));
1416  $note->setSubject(ilUtil::stripSlashes($_POST["sub_note"]));
1417  $note->setLabel(ilUtil::stripSlashes($_POST["note_label"]));
1418  if ($this->checkEdit($note)) {
1419  $note->update();
1420 
1421  $this->notifyObserver("update", $note);
1422 
1423  $ilCtrl->setParameter($this, "note_mess", "mod");
1424  }
1425  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1426  // }
1427  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1428  $this->note_mess = "frmfld";
1429  $this->form->setValuesByPost();
1430  $_GET["note_id"] = $note->getId();
1431  $_GET["note_type"] = $note->getType();
1432  return $this->editNoteForm(false);
1433  }
1434 
1438  public function editNoteForm($a_init_form = true)
1439  {
1440  $this->edit_note_form = true;
1441 
1442  return $this->getNotesHTML($a_init_form);
1443  }
1444 
1448  public function deleteNote()
1449  {
1450  $this->delete_note = true;
1451  $this->note_mess = "qdel";
1452  return $this->getNotesHTML();
1453  }
1454 
1458  public function deleteNotes()
1459  {
1460  $lng = $this->lng;
1461 
1462  if (!$_POST["note"]) {
1463  $this->note_mess = "noc";
1464  } else {
1465  $this->delete_note = true;
1466  $this->note_mess = "qdel";
1467  }
1468 
1469  return $this->getNotesHTML();
1470  }
1471 
1475  public function cancelDelete()
1476  {
1477  return $this->getNotesHTML();
1478  }
1479 
1483  public function confirmDelete()
1484  {
1485  $ilCtrl = $this->ctrl;
1486  $lng = $this->lng;
1487  $ilUser = $this->user;
1488 
1489  $cnt = 0;
1490  foreach ($_POST["note"] as $id) {
1491  $note = new ilNote($id);
1492  if ($this->checkDeletion($note)) {
1493  $note->delete();
1494  $cnt++;
1495  }
1496  }
1497  if ($cnt > 1) {
1498  $ilCtrl->setParameter($this, "note_mess", "ntsdel");
1499  } else {
1500  $ilCtrl->setParameter($this, "note_mess", "ntdel");
1501  }
1502  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1503  }
1504 
1508  public function exportNotesHTML()
1509  {
1510  $tpl = new ilGlobalTemplate("tpl.main.html", true, true);
1511 
1512  $this->export_html = true;
1513  $this->multi_selection = false;
1514  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1515  ilUtil::deliverData($tpl->get(), "notes.html");
1516  }
1517 
1521  public function printNotes()
1522  {
1523  $tpl = new ilTemplate("tpl.main.html", true, true);
1524 
1525  $this->print = true;
1526  $this->multi_selection = false;
1527  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1528  echo $tpl->get();
1529  exit;
1530  }
1531 
1535  public function showNotes()
1536  {
1537  $ilUser = $this->user;
1538 
1539  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1540  ? "private"
1541  : "public";
1542  $ilUser->writePref("notes_" . $suffix, "y");
1543 
1544  return $this->getNotesHTML();
1545  }
1546 
1550  public function hideNotes()
1551  {
1552  $ilUser = $this->user;
1553 
1554  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1555  ? "private"
1556  : "public";
1557  $ilUser->writePref("notes_" . $suffix, "n");
1558 
1559  return $this->getNotesHTML();
1560  }
1561 
1565  public function showAllPublicNotes()
1566  {
1567  $ilUser = $this->user;
1568 
1569  $ilUser->writePref("notes_pub_all", "y");
1570 
1571  return $this->getNotesHTML();
1572  }
1573 
1577  public function showMyPublicNotes()
1578  {
1579  $ilUser = $this->user;
1580 
1581  $ilUser->writePref("notes_pub_all", "n");
1582 
1583  return $this->getNotesHTML();
1584  }
1585 
1589  public static function initJavascript($a_ajax_url, $a_type = IL_NOTE_PRIVATE, ilGlobalTemplateInterface $a_main_tpl = null)
1590  {
1591  global $DIC;
1592 
1593  if ($a_main_tpl != null) {
1594  $tpl = $a_main_tpl;
1595  } else {
1596  $tpl = $DIC["tpl"];
1597  }
1598  $lng = $DIC->language();
1599 
1600  $lng->loadLanguageModule("notes");
1601 
1602  include_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
1604 
1605  $lng->toJs(array("private_notes", "notes_public_comments"), $tpl);
1606 
1607  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1608  ilYuiUtil::initPanel(false, $tpl);
1609  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1611  $tpl->addJavascript("./Services/Notes/js/ilNotes.js");
1612 
1613  $tpl->addOnLoadCode("ilNotes.setAjaxUrl('" . $a_ajax_url . "');");
1614  }
1615 
1623  public static function getListNotesJSCall($a_hash, $a_update_code = null)
1624  {
1625  if ($a_update_code === null) {
1626  $a_update_code = "null";
1627  } else {
1628  $a_update_code = "'" . $a_update_code . "'";
1629  }
1630 
1631  return "ilNotes.listNotes(event, '" . $a_hash . "', " . $a_update_code . ");";
1632  }
1633 
1641  public static function getListCommentsJSCall($a_hash, $a_update_code = null)
1642  {
1643  if ($a_update_code === null) {
1644  $a_update_code = "null";
1645  } else {
1646  $a_update_code = "'" . $a_update_code . "'";
1647  }
1648 
1649  return "ilNotes.listComments(event, '" . $a_hash . "', " . $a_update_code . ");";
1650  }
1651 
1661  protected static function buildAjaxHash($a_node_type, $a_node_id, $a_sub_id, $a_sub_type)
1662  {
1663  return $a_node_type . ";" . $a_node_id . ";" . $a_sub_id . ";" . $a_sub_type;
1664  }
1665 
1669  public function renderLink($a_tpl, $a_var, $a_txt, $a_cmd, $a_anchor = "")
1670  {
1671  $ilCtrl = $this->ctrl;
1672 
1673  $low_var = strtolower($a_var);
1674  $up_var = strtoupper($a_var);
1675 
1676  if ($this->ajax) {
1677  $a_tpl->setVariable("LINK_" . $up_var, "#");
1678  $oc = "onclick = \"ilNotes.cmdAjaxLink(event, '" .
1679  $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, "", true) .
1680  "');\"";
1681  $a_tpl->setVariable("ON_CLICK_" . $up_var, $oc);
1682  } else {
1683  $a_tpl->setVariable(
1684  "LINK_" . $up_var,
1685  $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, $a_anchor)
1686  );
1687  }
1688 
1689  $a_tpl->setCurrentBlock($low_var);
1690  $a_tpl->setVariable("TXT_" . $up_var, $a_txt);
1691  $a_tpl->parseCurrentBlock();
1692  }
1693 
1699  public function addObserver($a_callback)
1700  {
1701  $this->observer[] = $a_callback;
1702  }
1703 
1710  protected function notifyObserver($a_action, $a_note)
1711  {
1712  if (is_array($this->observer) && count($this->observer) > 0) {
1713  foreach ($this->observer as $item) {
1714  $param = $a_note->getObject();
1715  //TODO refactor this, check what is this news_id from getObject
1716  unset($param['news_id']);
1717  $param["action"] = $a_action;
1718  $param["note_id"] = $a_note->getId();
1719 
1720  call_user_func_array($item, $param);
1721  }
1722  }
1723 
1724  //ajax calls don't have callbacks in the observer. (modals)
1725  if ($this->ajax) {
1726  $ref = (int) $_GET['ref_id'];
1727  if (in_array($ref, ilObject::_getAllReferences($this->rep_obj_id))) {
1728  if ($this->obj_type == "pg") {
1729  $gui = new ilLMPresentationGUI(
1730  "",
1731  false,
1732  "",
1733  false
1734  );
1735  $gui->observeNoteAction($this->rep_obj_id, $this->obj_id, $this->obj_type, $a_action, $a_note->getId());
1736  }
1737 
1738  if ($this->obj_type == "wpg") {
1739  $gui = new ilWikiPageGUI($this->obj_id, 0, $ref);
1740  $gui->observeNoteAction($this->obj_id, $this->obj_id, $this->obj_type, $a_action, $a_note->getId());
1741  }
1742  }
1743  }
1744  }
1745 
1746  protected function listSortAsc()
1747  {
1748  $_SESSION["comments_sort_asc"] = 1;
1749  return $this->getNotesHtml();
1750  }
1751 
1752  protected function listSortDesc()
1753  {
1754  $_SESSION["comments_sort_asc"] = 0;
1755  return $this->getNotesHtml();
1756  }
1757 
1764  public function getHTML()
1765  {
1766  return $this->getCommentsWidget();
1767  }
1768 
1769 
1776  protected function getCommentsWidget()
1777  {
1778  $f = $this->ui->factory();
1779  $r = $this->ui->renderer();
1780 
1781  $lng = $this->lng;
1782  $ctrl = $this->ctrl;
1783  $ctrl->setParameter($this, "news_id", $this->news_id);
1786  null,
1787  ilObject::_lookupType($this->rep_obj_id),
1788  $this->rep_obj_id,
1789  $this->obj_type,
1790  $this->obj_id,
1791  $this->news_id
1792  );
1793 
1794  $cnt = ilNote::_countNotesAndComments($this->rep_obj_id, $this->obj_id, $this->obj_type, $this->news_id);
1795  $cnt = $cnt[$this->rep_obj_id][IL_NOTE_PUBLIC];
1796 
1797  $tpl = new ilTemplate("tpl.note_widget_header.html", true, true, "Services/Notes");
1798  $widget_el_id = "notew_" . str_replace(";", "_", $hash);
1799  $ctrl->setParameter($this, "hash", $hash);
1800  $update_url = $ctrl->getLinkTarget($this, "updateWidget", "", true, false);
1801  $comps = array();
1802  if ($cnt > 0) {
1803  $c = $f->counter()->status((int) $cnt);
1804  $comps[] = $f->symbol()->glyph()->comment()->withCounter($c)->withAdditionalOnLoadCode(function ($id) use ($hash, $update_url, $widget_el_id) {
1805  return "$(\"#$id\").click(function(event) { " . self::getListCommentsJSCall($hash, "ilNotes.updateWidget(\"" . $widget_el_id . "\",\"" . $update_url . "\");") . "});";
1806  });
1807  $comps[] = $f->divider()->vertical();
1808  $tpl->setVariable("GLYPH", $r->render($comps));
1809  $tpl->setVariable("TXT_LATEST", $lng->txt("notes_latest_comment"));
1810  }
1811 
1812 
1813  $b = $f->button()->shy($lng->txt("notes_add_edit_comment"), "#")->withAdditionalOnLoadCode(function ($id) use ($hash,$update_url,$widget_el_id) {
1814  return "$(\"#$id\").click(function(event) { " . self::getListCommentsJSCall($hash, "ilNotes.updateWidget(\"" . $widget_el_id . "\",\"" . $update_url . "\");") . "});";
1815  });
1816  if ($ctrl->isAsynch()) {
1817  $tpl->setVariable("SHY_BUTTON", $r->renderAsync($b));
1818  } else {
1819  $tpl->setVariable("SHY_BUTTON", $r->render($b));
1820  }
1821 
1822  $this->widget_header = $tpl->get();
1823 
1824  $this->hide_new_form = true;
1825  $this->only_latest = true;
1826  $this->no_actions = true;
1827  $html = "<div id='" . $widget_el_id . "'>" . $this->getNoteListHTML(IL_NOTE_PUBLIC) . "</div>";
1828  $ctrl->setParameter($this, "news_id", $_GET["news_id"]);
1829  return $html;
1830  }
1831 
1838  protected function updateWidget()
1839  {
1840  echo $this->getCommentsWidget();
1841  exit;
1842  }
1843 }
static _lookupLogin($a_user_id)
lookup login
checkDeletion($a_note)
Check whether deletion is allowed.
getOnlyCommentsHTML()
Get only comments html.
static _lookupTitle($a_obj_id)
Lookup Title.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
const IL_NOTE_CONTRA
getNotesHTML($a_init_form=true)
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
enableCommentsSettings($a_enable=true)
enable private notes
getNoteListHTML($a_type=IL_NOTE_PRIVATE, $a_init_form=true)
get notes/comments list as html code
exit
Definition: login.php:29
settings()
Definition: settings.php:2
initNoteForm($a_mode="edit", $a_type, $a_note=null)
Init note form.
setRepositoryMode($a_value)
Set repository mode.
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_news_id=0)
Are comments activated for object?
enableMultiSelection($a_enable=true)
enable multi selection (checkboxes and commands)
const IL_NOTE_PRO
const IL_NOTE_PRIVATE
Definition: class.ilNote.php:5
const IL_CAL_DATETIME
enableAnchorJump($a_enable=true)
enable anchor for form jump
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$_SESSION["AccountId"]
This class represents a property form user interface.
special template class to simplify handling of ITX/PEAR
$type
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
$_GET["client_id"]
$location
Definition: buildRTE.php:44
updateNote()
update note
getPDNoteHTML($note_id)
Note display for personal desktop.
getOnlyNotesHTML()
Get only notes html.
static getSystemMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
static initJS(ilGlobalTemplateInterface $a_main_tpl=null)
Init javascript.
executeCommand()
execute command
static get($a_glyph, $a_text="")
Get glyph html.
getDefaultCommand()
Get default command.
Access handler for personal workspace.
renderLink($a_tpl, $a_var, $a_txt, $a_cmd, $a_anchor="")
Render a link.
static setUseRelativeDates($a_status)
set use relative dates
static _lookupTitle($a_id)
lookup object title
static _getNotesOfObject( $a_rep_obj_id, $a_obj_id, $a_obj_type, $a_type=IL_NOTE_PRIVATE, $a_incl_sub=false, $a_filter="", $a_all_public="y", $a_repository_mode=true, $a_sort_ascending=false, $a_news_id=0)
get all notes related to a specific object
deactivateComments()
Deactivate Comments.
checkEdit($a_note)
Check edit.
static initPanel($a_resize=false, ilGlobalTemplateInterface $a_main_tpl=null)
Init yui panel.
enablePublicNotes($a_enable=true)
enable public notes
static initJavascript($a_ajax_url, $a_type=IL_NOTE_PRIVATE, ilGlobalTemplateInterface $a_main_tpl=null)
Init javascript.
showNotes()
show notes
editNoteForm($a_init_form=true)
get notes list including add note area
activateComments()
Activate Comments.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
enableTargets($a_enable=true)
enable target objects
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
static getListNotesJSCall($a_hash, $a_update_code=null)
Get list notes js call.
Tree handler for personal workspace.
Note class.
static useRelativeDates()
check if relative dates are used
Notes GUI class.
global $ilCtrl
Definition: ilias.php:18
getSubObjectTitle($parent_obj_id, $sub_obj_id)
Get sub object title if available with callback.
Class ilLMPresentationGUI.
$a_type
Definition: workflow.php:92
exportNotesHTML()
export selected notes to html
This class represents a hidden form property in a property form.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
deleteNote()
delete note confirmation
Class for single dates.
static _lookupTitle($a_obj_id)
Overwitten from base class.
static getGotoLink($a_node_id, $a_obj_id, $a_additional=null)
enableHiding($a_enable=true)
enable hiding
static _countNotesAndComments( $a_rep_obj_id, $a_sub_obj_id=null, $a_obj_type="", $a_news_id=0)
Get all notes related to a specific object.
addNote()
add note
const IL_NOTE_PUBLIC
Definition: class.ilNote.php:6
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _lookupObjId($a_id)
updateWidget()
Update widget.
$param
Definition: xapitoken.php:31
showAllPublicNotes()
show all public notes to user
addObserver($a_callback)
Add observer.
cancelUpdateNote()
cancel edit note
Class ilWikiPage GUI class.
$ilUser
Definition: imgupload.php:18
ui()
Definition: ui.php:5
static _lookupOwner($a_id)
lookup object owner
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
$txt
Definition: error.php:13
$additional
Definition: goto.php:50
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static buildAjaxHash( $a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type=null, $a_sub_id=null, $a_news_id=0)
Build ajax hash.
static _lookupType($a_id, $a_reference=false)
lookup object type
cancelDelete()
cancel deletion of note
static getListCommentsJSCall($a_hash, $a_update_code=null)
Get list comments js call.
notifyObserver($a_action, $a_note)
Notify observers on update/create.
renderTargets($a_note)
show related objects as links
showMyPublicNotes()
show only public notes of user
printNotes()
notes print view screen
const IL_NOTE_UNLABELED
Definition: class.ilNote.php:8
hideNotes()
hide notes
enablePublicNotesDeletion($a_enable=true)
enable public notes
confirmDelete()
cancel deletion of note
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
static activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate=true)
Activate notes feature.
global $ilSetting
Definition: privfeed.php:17
This class represents a text area property in a property form.
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
const IL_NOTE_QUESTION
getHTML()
Get HTML.
$DIC
Definition: xapitoken.php:46
addNoteForm($a_init_form=true)
get notes list including add note area
enablePrivateNotes($a_enable=true)
enable private notes
const IL_NOTE_IMPORTANT
Definition: class.ilNote.php:9
static buildAjaxHash($a_node_type, $a_node_id, $a_sub_id, $a_sub_type)
Combine properties to hash.
deleteNotes()
delete notes confirmation
static _lookupOwnerName($a_owner_id)
lookup owner name for owner id
cancelAddNote()
cancel add note
$_POST["username"]
static _lookupTargetId($a_obj_id)
lookup target id
getCommentsWidget()
Get widget.
setDefaultCommand($a_val)
Set default command.
__construct( $a_rep_obj_id="", $a_obj_id="", $a_obj_type="", $a_include_subobjects=false, $a_news_id=0)
constructor, specifies notes set