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