ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
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 {
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 {
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 $ntpl->getMessageHTML($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 {
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
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", "Ajax");
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 if (!$this->add_note_form && !$this->edit_note_form && !$this->delete_note &&
607 !$this->export_html && !$this->print && $ilUser->getId() != ANONYMOUS_USER_ID && !$this->hide_new_form) {
608 if (!$this->inc_sub) { // we cannot offer add button if aggregated notes
609 // are displayed
610 if ($this->rep_obj_id > 0 || $a_type != IL_NOTE_PUBLIC) {
611 $tpl->setCurrentBlock("add_note_btn");
612 if ($a_type == IL_NOTE_PUBLIC) {
613 $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("notes_add_comment"));
614 } else {
615 $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("add_note"));
616 }
617 $tpl->setVariable("LINK_ADD_NOTE", $ilCtrl->getLinkTargetByClass("ilnotegui", "addNoteForm") .
618 "#note_edit");
619 $tpl->parseCurrentBlock();
620 }
621 }
622 }
623
624 // show show/hide button for note list
625 if (count($notes) > 0 && $this->enable_hiding && !$this->delete_note
626 && !$this->export_html && !$this->print && !$this->edit_note_form
627 && !$this->add_note_form) {
628 if ($user_setting_notes_by_type == "n") {
629 if ($a_type == IL_NOTE_PUBLIC) {
630 $txt = $lng->txt("notes_show_comments");
631 } else {
632 $txt = $lng->txt("show_" . $suffix . "_notes");
633 }
634 $this->renderLink($tpl, "show_notes", $txt, "showNotes", "notes_top");
635 } else {
636 // never individually hide for anonymous users
637 if (($ilUser->getId() != ANONYMOUS_USER_ID)) {
638 if ($a_type == IL_NOTE_PUBLIC) {
639 $txt = $lng->txt("notes_hide_comments");
640 } else {
641 $txt = $lng->txt("hide_" . $suffix . "_notes");
642 }
643 $this->renderLink($tpl, "hide_notes", $txt, "hideNotes", "notes_top");
644
645 // show all public notes / my notes only switch
646 if ($a_type == IL_NOTE_PUBLIC) {
647 if ($user_setting_notes_public_all == "n") {
648 $this->renderLink(
649 $tpl,
650 "all_pub_notes",
651 $lng->txt("notes_all_comments"),
652 "showAllPublicNotes",
653 "notes_top"
654 );
655 } else {
656 $this->renderLink(
657 $tpl,
658 "my_pub_notes",
659 $lng->txt("notes_my_comments"),
660 "showMyPublicNotes",
661 "notes_top"
662 );
663 }
664 }
665 }
666 }
667 }
668
669 // show add new note text area
670 if (!$this->edit_note_form && $user_setting_notes_by_type != "n" &&
671 !$this->delete_note && $ilUser->getId() != ANONYMOUS_USER_ID && !$this->hide_new_form) {
672 if ($a_init_form) {
673 $this->initNoteForm("create", $a_type);
674 }
675
676 $tpl->setCurrentBlock("edit_note_form");
677 // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
678 $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
679 $tpl->parseCurrentBlock();
680
681 $tpl->parseCurrentBlock();
682 $tpl->setCurrentBlock("note_row");
683 $tpl->parseCurrentBlock();
684 }
685
686 // list all notes
687 if ($user_setting_notes_by_type != "n" || !$this->enable_hiding) {
690
691 if (sizeof($notes) && !$this->only_latest) {
692 if ((int) $_SESSION["comments_sort_asc"] == 1) {
693 $sort_txt = $lng->txt("notes_sort_desc");
694 $sort_cmd = "listSortDesc";
695 } else {
696 $sort_txt = $lng->txt("notes_sort_asc");
697 $sort_cmd = "listSortAsc";
698 }
699 $this->renderLink($tpl, "sort_list", $sort_txt, $sort_cmd, $anch);
700 }
701
702 $notes_given = false;
703 foreach ($notes as $note) {
704 if ($this->only_latest && $notes_given) {
705 continue;
706 }
707
708
709 if ($this->edit_note_form && ($note->getId() == $_GET["note_id"])
710 && $a_type == $_GET["note_type"]) {
711 if ($a_init_form) {
712 $this->initNoteForm("edit", $a_type, $note);
713 }
714 $tpl->setCurrentBlock("edit_note_form");
715 // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
716 $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
717 $tpl->parseCurrentBlock();
718 } else {
719 $cnt_col = 2;
720
721 // delete note stuff for all private notes
722 if ($this->checkDeletion($note)
723 && !$this->delete_note
724 && !$this->export_html && !$this->print
725 && !$this->edit_note_form && !$this->add_note_form && !$this->no_actions) {
726 $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
727 $this->renderLink(
728 $tpl,
729 "delete_note",
730 $lng->txt("delete"),
731 "deleteNote",
732 "note_" . $note->getId()
733 );
734 }
735
736 // checkboxes in multiselection mode
737 if ($this->multi_selection && !$this->delete_note) {
738 $tpl->setVariable("CHECKBOX_CLASS", "ilNotesCheckboxes");
739 $tpl->setCurrentBlock("checkbox_col");
740 $tpl->setVariable("CHK_NOTE", "note[]");
741 $tpl->setVariable("CHK_NOTE_ID", $note->getId());
742 $tpl->parseCurrentBlock();
743 $cnt_col = 1;
744 }
745
746 // edit note stuff for all private notes
747 if ($this->checkEdit($note)) {
748 if (!$this->delete_note && !$this->export_html && !$this->print
749 && !$this->edit_note_form && !$this->add_note_form && !$this->no_actions) {
750 $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
751 $this->renderLink(
752 $tpl,
753 "edit_note",
754 $lng->txt("edit"),
755 "editNoteForm",
756 "note_edit"
757 );
758 }
759 }
760
761 $tpl->setVariable("CNT_COL", $cnt_col);
762
763 // output author account
764 if ($a_type == IL_NOTE_PUBLIC && ilObject::_exists($note->getAuthor())) {
765 //$tpl->setCurrentBlock("author");
766 //$tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin($note->getAuthor()));
767 //$tpl->parseCurrentBlock();
768 $tpl->setCurrentBlock("user_img");
769 $tpl->setVariable(
770 "USR_IMG",
771 ilObjUser::_getPersonalPicturePath($note->getAuthor(), "xxsmall")
772 );
773 $tpl->setVariable("USR_ALT", $lng->txt("user_image") . ": " .
774 ilObjUser::_lookupLogin($note->getAuthor()));
775 $tpl->parseCurrentBlock();
776 $tpl->setVariable(
777 "TXT_USR",
778 ilUserUtil::getNamePresentation($note->getAuthor(), false, false) . " - "
779 );
780 }
781
782 // last edited
783 if ($note->getUpdateDate() != null) {
784 $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
785 $tpl->setVariable(
786 "DATE_LAST_EDIT",
787 ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME))
788 );
789 } else {
790 $tpl->setVariable(
791 "VAL_DATE",
792 ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME))
793 );
794 }
795
796 // hidden note ids for deletion
797 if ($this->delete_note) {
798 $tpl->setCurrentBlock("delete_ids");
799 $tpl->setVariable("HID_NOTE", "note[]");
800 $tpl->setVariable("HID_NOTE_ID", $note->getId());
801 $tpl->parseCurrentBlock();
802 }
803 $target = $note->getObject();
804
805
806 $tpl->setCurrentBlock("note");
807 $text = (trim($note->getText()) != "")
808 ? nl2br($note->getText())
809 : "<p class='subtitle'>" . $lng->txt("note_content_removed") . "</p>";
810 $tpl->setVariable("NOTE_TEXT", $text);
811 $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
812 $tpl->setVariable("NOTE_ID", $note->getId());
813
814 // target objects
815 $tpl->setVariable(
816 "TARGET_OBJECTS",
817 $this->renderTargets($note)
818 );
819
820 $tpl->parseCurrentBlock();
821 }
822 $tpl->setCurrentBlock("note_row");
823 $tpl->parseCurrentBlock();
824 $notes_given = true;
825 }
826
827 if (!$notes_given) {
828 $tpl->setCurrentBlock("no_notes");
829 if ($a_type == IL_NOTE_PUBLIC && !$this->only_latest) {
830 $tpl->setVariable("NO_NOTES", $lng->txt("notes_no_comments"));
831 }
832 $tpl->parseCurrentBlock();
833 }
834
836
837 // multiple items commands
838 if ($this->multi_selection && !$this->delete_note && !$this->edit_note_form
839 && count($notes) > 0) {
840 if ($a_type == IL_NOTE_PRIVATE) {
841 $tpl->setCurrentBlock("delete_cmd");
842 $tpl->setVariable("TXT_DELETE_NOTES", $this->lng->txt("delete"));
843 $tpl->parseCurrentBlock();
844 }
845
846 $tpl->setCurrentBlock("multiple_commands");
847 $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
848 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
849 $tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
850 $tpl->setVariable("TXT_PRINT_NOTES", $this->lng->txt("print"));
851 $tpl->setVariable("TXT_EXPORT_NOTES", $this->lng->txt("exp_html"));
852 $tpl->parseCurrentBlock();
853 }
854
855 // delete / cancel row
856 if ($this->delete_note) {
857 $tpl->setCurrentBlock("delete_cancel");
858 $tpl->setVariable("TXT_DEL_NOTES", $this->lng->txt("delete"));
859 $tpl->setVariable("TXT_CANCEL_DEL_NOTES", $this->lng->txt("cancel"));
860 $tpl->parseCurrentBlock();
861 }
862
863 // print
864 if ($this->print) {
865 $tpl->touchBlock("print_js");
866 $tpl->setCurrentBlock("print_back");
867 $tpl->setVariable("LINK_BACK", $this->ctrl->getLinkTarget($this, "showNotes"));
868 $tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
869 $tpl->parseCurrentBlock();
870 }
871 }
872
873 // message
874 switch ($_GET["note_mess"] != "" ? $_GET["note_mess"] : $this->note_mess) {
875 case "mod":
876 $mtype = "success";
877 $mtxt = $lng->txt("msg_obj_modified");
878 break;
879
880 case "ntsdel":
881 $mtype = "success";
882 $mtxt = ($a_type == IL_NOTE_PRIVATE)
883 ? $lng->txt("notes_notes_deleted")
884 : $lng->txt("notes_comments_deleted");
885 break;
886
887 case "ntdel":
888 $mtype = "success";
889 $mtxt = ($a_type == IL_NOTE_PRIVATE)
890 ? $lng->txt("notes_note_deleted")
891 : $lng->txt("notes_comment_deleted");
892 break;
893
894 case "frmfld":
895 $mtype = "failure";
896 $mtxt = $lng->txt("form_input_not_valid");
897 break;
898
899 case "qdel":
900 $mtype = "question";
901 $mtxt = $lng->txt("info_delete_sure");
902 break;
903
904 case "noc":
905 $mtype = "failure";
906 $mtxt = $lng->txt("no_checkbox");
907 break;
908 }
909 if ($mtxt != "") {
910 $tpl->setVariable("MESS", $tpl->getMessageHTML($mtxt, $mtype));
911 } else {
912 $tpl->setVariable("MESS", "");
913 }
914
915 if ($this->widget_header != "") {
916 $tpl->setVariable("WIDGET_HEADER", $this->widget_header);
917 }
918
919
920 if ($this->delete_note && count($notes) == 0) {
921 return "";
922 } else {
923 return $tpl->get();
924 }
925 }
926
934 protected function getSubObjectTitle($parent_obj_id, $sub_obj_id)
935 {
936 $objDefinition = $this->obj_definition;
938
939 $parent_type = ilObject::_lookupType($parent_obj_id);
940 $parent_class = "ilObj" . $objDefinition->getClassName($parent_type) . "GUI";
941 $parent_path = $ilCtrl->lookupClassPath($parent_class);
942 include_once $parent_path;
943 if (method_exists($parent_class, "lookupSubObjectTitle")) {
944 return call_user_func_array(array($parent_class, "lookupSubObjectTitle"), array($parent_obj_id, $sub_obj_id));
945 }
946 }
947
951 public function checkDeletion($a_note)
952 {
955
956 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
957 return false;
958 }
959
960 $is_author = ($a_note->getAuthor() == $ilUser->getId());
961
962 if ($a_note->getType() == IL_NOTE_PRIVATE && $is_author) {
963 return true;
964 }
965
966 if ($a_note->getType() == IL_NOTE_PUBLIC && $this->public_deletion_enabled) {
967 return true;
968 }
969
970 if ($a_note->getType() == IL_NOTE_PUBLIC && $is_author && $ilSetting->get("comments_del_user", 0)) {
971 return true;
972 }
973
974 return false;
975 }
976
980 public function checkEdit($a_note)
981 {
983
984 if ($a_note->getAuthor() == $ilUser->getId()
985 && ($ilUser->getId() != ANONYMOUS_USER_ID)) {
986 return true;
987 }
988 return false;
989 }
990
991
997 public function initNoteForm($a_mode = "edit", $a_type, $a_note = null)
998 {
1001
1002 $this->form_tpl = new ilTemplate("tpl.notes_edit.html", true, true, "Services/Notes");
1003 if ($a_note) {
1004 $this->form_tpl->setVariable("VAL_NOTE", ilUtil::prepareFormOutput($a_note->getText()));
1005 $this->form_tpl->setVariable("NOTE_ID", $a_note->getId());
1006 }
1007
1008 if ($a_mode == "create") {
1009 $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
1010 ? $lng->txt("note_add_comment")
1011 : $lng->txt("note_add_note"));
1012 $this->form_tpl->setVariable("CMD", "addNote");
1013 } else {
1014 $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
1015 ? $lng->txt("note_update_comment")
1016 : $lng->txt("note_update_note"));
1017 $this->form_tpl->setVariable("CMD", "updateNote");
1018 }
1019
1020 return;
1021 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1022 $this->form = new ilPropertyFormGUI();
1023 $this->form->setOpenTag(false);
1024 $this->form->setCloseTag(false);
1025 $this->form->setDisableStandardMessage(true);
1026
1027 // subject
1028 /* $ti = new ilTextInputGUI($this->lng->txt("subject"), "sub_note");
1029 $ti->setRequired(true);
1030 $ti->setMaxLength(200);
1031 $ti->setSize(40);
1032 if ($a_note)
1033 {
1034 $ti->setValue($a_note->getSubject());
1035 }
1036 $this->form->addItem($ti);*/
1037
1038 // text
1039 // $ta = new ilTextAreaInputGUI(($a_type == IL_NOTE_PUBLIC)
1040 // ? $lng->txt("notes_comment")
1041 // : $lng->txt("note"), "note");
1042 $ta = new ilTextAreaInputGUI("", "note");
1043 $ta->setCols(40);
1044 $ta->setRows(4);
1045 if ($a_note) {
1046 $ta->setValue($a_note->getText());
1047 }
1048 $this->form->addItem($ta);
1049
1050 // label
1051 /* $options = array(
1052 IL_NOTE_UNLABELED => $lng->txt("unlabeled"),
1053 IL_NOTE_QUESTION => $lng->txt("question"),
1054 IL_NOTE_IMPORTANT => $lng->txt("important"),
1055 IL_NOTE_PRO => $lng->txt("pro"),
1056 IL_NOTE_CONTRA => $lng->txt("contra"),
1057 );
1058 $si = new ilSelectInputGUI($this->lng->txt("notes_label"), "note_label");
1059 $si->setOptions($options);
1060 if ($a_note)
1061 {
1062 $si->setValue($a_note->getLabel());
1063 }
1064 $this->form->addItem($si); */
1065
1066 // hidden note id
1067 if ($a_note) {
1068 $hi = new ilHiddenInputGUI("note_id");
1069 $hi->setValue($_GET["note_id"]);
1070 $this->form->addItem($hi);
1071 }
1072
1073 // save and cancel commands
1074 if ($a_mode == "create") {
1075 $this->form->addCommandButton("addNote", $lng->txt("save"));
1076 /* $this->form->addCommandButton("cancelAddNote", $lng->txt("cancel"));
1077 $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1078 ? $lng->txt("notes_add_comment")
1079 : $lng->txt("notes_add_note"));*/
1080 } else {
1081 $this->form->addCommandButton("updateNote", $lng->txt("save"));
1082 /* $this->form->addCommandButton("cancelUpdateNote", $lng->txt("cancel"));
1083 $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1084 ? $lng->txt("notes_edit_comment")
1085 : $lng->txt("notes_edit_note"));*/
1086 }
1087
1088 $ilCtrl->setParameter($this, "note_type", $a_type);
1089 $this->form->setFormAction($this->ctrl->getFormAction($this));
1090 }
1091
1095 public function getPDNoteHTML($note_id)
1096 {
1097 $lng = $this->lng;
1100
1101 $tpl = new ilTemplate("tpl.pd_note.html", true, true, "Services/Notes");
1102 $note = new ilNote($note_id);
1103 $target = $note->getObject();
1104
1105 if ($note->getAuthor() != $ilUser->getId()) {
1106 return;
1107 }
1108
1109 $tpl->setCurrentBlock("edit_note");
1110 $ilCtrl->setParameterByClass("ilnotegui", "rel_obj", $target["rep_obj_id"]);
1111 $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note_id);
1112 $ilCtrl->setParameterByClass("ilnotegui", "note_type", $note->getType());
1113 $tpl->setVariable(
1114 "LINK_EDIT_NOTE",
1115 $ilCtrl->getLinkTargetByClass(
1116 array("ilpersonaldesktopgui", "ilpdnotesgui", "ilnotegui"),
1117 "editNoteForm"
1118 )
1119 );
1120 $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
1121 $tpl->parseCurrentBlock();
1122 $ilCtrl->clearParametersByClass("ilnotegui");
1123
1124 // last edited
1125 if ($note->getUpdateDate() != null) {
1126 $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
1127 $tpl->setVariable(
1128 "DATE_LAST_EDIT",
1129 ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME))
1130 );
1131 } else {
1132 //$tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
1133 $tpl->setVariable(
1134 "VAL_DATE",
1135 ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME))
1136 );
1137 }
1138
1139 $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
1140 $text = (trim($note->getText()) != "")
1141 ? nl2br($note->getText())
1142 : "<p class='subtitle'>" . $lng->txt("note_content_removed") . "</p>";
1143 $tpl->setVariable("NOTE_TEXT", $text);
1144 $tpl->setVariable("TARGET_OBJECTS", $this->renderTargets($note));
1145 return $tpl->get();
1146 }
1147
1151 public function renderTargets($a_note)
1152 {
1154 $ilAccess = $this->access;
1155 $objDefinition = $this->obj_definition;
1157
1158 if (!$this->targets_enabled) {
1159 return "";
1160 }
1161
1162 $a_note_id = $a_note->getId();
1163 $target = $a_note->getObject();
1164 $a_obj_type = $target["obj_type"];
1165 $a_obj_id = $target["obj_id"];
1166
1167 $target_tpl = new ilTemplate("tpl.note_target_object.html", true, true, "Services/Notes");
1168
1169 if ($target["rep_obj_id"] > 0) {
1170 // get all visible references of target object
1171
1172 // repository
1173 $ref_ids = ilObject::_getAllReferences($target["rep_obj_id"]);
1174 if ($ref_ids) {
1175 $vis_ref_ids = array();
1176 foreach ($ref_ids as $ref_id) {
1177 if ($ilAccess->checkAccess("visible", "", $ref_id)) {
1178 $vis_ref_ids[] = $ref_id;
1179 }
1180 }
1181
1182 // output links to targets
1183 if (count($vis_ref_ids) > 0) {
1184 foreach ($vis_ref_ids as $vis_ref_id) {
1185 $type = ilObject::_lookupType($vis_ref_id, true);
1186 $title = ilObject::_lookupTitle($target["rep_obj_id"]);
1187
1188 $sub_link = $sub_title = "";
1189 if ($type == "sahs") { // bad hack, needs general procedure
1190 $link = "goto.php?target=sahs_" . $vis_ref_id;
1191 if ($a_obj_type == "sco" || $a_obj_type == "seqc" || $a_obj_type == "chap" || $a_obj_type == "pg") {
1192 $sub_link = "goto.php?target=sahs_" . $vis_ref_id . "_" . $a_obj_id;
1193 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
1194 $sub_title = ilSCORM2004Node::_lookupTitle($a_obj_id);
1195 }
1196 } elseif ($type == "poll") {
1197 include_once "Services/Link/classes/class.ilLink.php";
1198 $link = ilLink::_getLink($vis_ref_id, "poll");
1199 } elseif ($a_obj_type != "pg") {
1200 if (!is_object($this->item_list_gui[$type])) {
1201 $class = $objDefinition->getClassName($type);
1202 $location = $objDefinition->getLocation($type);
1203 $full_class = "ilObj" . $class . "ListGUI";
1204 include_once($location . "/class." . $full_class . ".php");
1205 $this->item_list_gui[$type] = new $full_class();
1206 }
1207
1208 // for references, get original title
1209 // (link will lead to orignal, which basically is wrong though)
1210 if ($a_obj_type == "crsr" || $a_obj_type == "catr" || $a_obj_type == "grpr") {
1211 include_once "Services/ContainerReference/classes/class.ilContainerReference.php";
1212 $tgt_obj_id = ilContainerReference::_lookupTargetId($target["rep_obj_id"]);
1213 $title = ilObject::_lookupTitle($tgt_obj_id);
1214 }
1215 $this->item_list_gui[$type]->initItem($vis_ref_id, $target["rep_obj_id"], $title);
1216 $link = $this->item_list_gui[$type]->getCommandLink("infoScreen");
1217
1218 // workaround, because # anchor can't be passed through frameset
1219 $link = ilUtil::appendUrlParameterString($link, "anchor=note_" . $a_note_id);
1220
1221 $link = $this->item_list_gui[$type]->appendRepositoryFrameParameter($link) . "#note_" . $a_note_id;
1222 } else {
1223 $title = ilObject::_lookupTitle($target["rep_obj_id"]);
1224 $link = "goto.php?target=pg_" . $a_obj_id . "_" . $vis_ref_id;
1225 }
1226
1227 $par_id = $tree->getParentId($vis_ref_id);
1228
1229 // sub object link
1230 if ($sub_link != "") {
1231 if ($this->export_html || $this->print) {
1232 $target_tpl->setCurrentBlock("exp_target_sub_object");
1233 } else {
1234 $target_tpl->setCurrentBlock("target_sub_object");
1235 $target_tpl->setVariable("LINK_SUB_TARGET", $sub_link);
1236 }
1237 $target_tpl->setVariable("TXT_SUB_TARGET", $sub_title);
1238 $target_tpl->parseCurrentBlock();
1239 }
1240
1241 // container and object link
1242 if ($this->export_html || $this->print) {
1243 $target_tpl->setCurrentBlock("exp_target_object");
1244 } else {
1245 $target_tpl->setCurrentBlock("target_object");
1246 $target_tpl->setVariable("LINK_TARGET", $link);
1247 }
1248 $target_tpl->setVariable(
1249 "TXT_CONTAINER",
1251 ilObject::_lookupObjId($par_id)
1252 )
1253 );
1254 $target_tpl->setVariable("TXT_TARGET", $title);
1255
1256 $target_tpl->parseCurrentBlock();
1257 }
1258 $target_tpl->touchBlock("target_objects");
1259 }
1260 }
1261 // personal workspace
1262 else {
1263 // we only need 1 instance
1264 if (!$this->wsp_tree) {
1265 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1266 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
1267 $this->wsp_tree = new ilWorkspaceTree($ilUser->getId());
1268 $this->wsp_access_handler = new ilWorkspaceAccessHandler($this->wsp_tree);
1269 }
1270 $node_id = $this->wsp_tree->lookupNodeId($target["rep_obj_id"]);
1271 if ($this->wsp_access_handler->checkAccess("visible", "", $node_id)) {
1272 $path = $this->wsp_tree->getPathFull($node_id);
1273 if ($path) {
1274 $item = array_pop($path);
1275 $parent = array_pop($path);
1276
1277 if (!$parent["title"]) {
1278 $parent["title"] = $this->lng->txt("wsp_personal_workspace");
1279 }
1280
1281 // sub-objects
1282 $additional = null;
1283 if ($a_obj_id) {
1284 $sub_title = $this->getSubObjectTitle($target["rep_obj_id"], $a_obj_id);
1285 if ($sub_title) {
1286 $item["title"] .= " (" . $sub_title . ")";
1287 $additional = "_" . $a_obj_id;
1288 }
1289 }
1290
1291 $link = ilWorkspaceAccessHandler::getGotoLink($node_id, $target["rep_obj_id"], $additional);
1292 }
1293 // shared resource
1294 else {
1295 $owner = ilObject::_lookupOwner($target["rep_obj_id"]);
1296 $parent["title"] = $this->lng->txt("wsp_tab_shared") .
1297 " (" . ilObject::_lookupOwnerName($owner) . ")";
1298 $item["title"] = ilObject::_lookupTitle($target["rep_obj_id"]);
1299 $link = "ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=" .
1300 $owner;
1301 }
1302
1303 // container and object link
1304 if ($this->export_html || $this->print) {
1305 $target_tpl->setCurrentBlock("exp_target_object");
1306 } else {
1307 $target_tpl->setCurrentBlock("target_object");
1308 $target_tpl->setVariable("LINK_TARGET", $link);
1309 }
1310
1311
1312 // :TODO: no images in template ?
1313
1314 $target_tpl->setVariable("TXT_CONTAINER", $parent["title"]);
1315
1316 $target_tpl->setVariable("TXT_TARGET", $item["title"]);
1317
1318 $target_tpl->parseCurrentBlock();
1319 }
1320 }
1321 }
1322 return $target_tpl->get();
1323 }
1324
1328 public function addNoteForm($a_init_form = true)
1329 {
1331
1332 $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1333 ? "private"
1334 : "public";
1335 $ilUser->setPref("notes_" . $suffix, "y");
1336
1337 $this->add_note_form = true;
1338 return $this->getNotesHTML($a_init_form);
1339 }
1340
1344 public function cancelAddNote()
1345 {
1346 return $this->getNotesHTML();
1347 }
1348
1352 public function cancelUpdateNote()
1353 {
1354 return $this->getNotesHTML();
1355 }
1356
1360 public function addNote()
1361 {
1363 $lng = $this->lng;
1365 //ilLoggerFactory::getLogger("root")->notice("addNote");
1366 $this->initNoteForm("create", $_GET["note_type"]);
1367
1368 //if ($this->form->checkInput())
1369 if ($_POST["note"] != "") {
1370 $note = new ilNote();
1371 $note->setObject($this->obj_type, $this->rep_obj_id, $this->obj_id, $this->news_id);
1372 $note->setInRepository($this->repository_mode);
1373 $note->setType($_GET["note_type"]);
1374 $note->setAuthor($ilUser->getId());
1375 $note->setText(ilUtil::stripslashes($_POST["note"]));
1376 // $note->setSubject($_POST["sub_note"]);
1377 // $note->setLabel($_POST["note_label"]);
1378 $note->create();
1379
1380 $this->notifyObserver("new", $note);
1381
1382 $ilCtrl->setParameter($this, "note_mess", "mod");
1383 // $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1384 }
1385 $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1386 // $this->note_mess = "frmfld";
1387// $this->form->setValuesByPost();
1388// return $this->addNoteForm(false);;
1389 }
1390
1394 public function updateNote()
1395 {
1397 $lng = $this->lng;
1399
1400 $note = new ilNote(ilUtil::stripSlashes($_POST["note_id"]));
1401 $this->initNoteForm(
1402 "edit",
1403 $note->getType(),
1404 $note
1405 );
1406
1407 // if ($this->form->checkInput())
1408 // if ($_POST["note"] != "")
1409 // {
1410 $note->setText(ilUtil::stripSlashes($_POST["note"]));
1411 $note->setSubject(ilUtil::stripSlashes($_POST["sub_note"]));
1412 $note->setLabel(ilUtil::stripSlashes($_POST["note_label"]));
1413 if ($this->checkEdit($note)) {
1414 $note->update();
1415
1416 $this->notifyObserver("update", $note);
1417
1418 $ilCtrl->setParameter($this, "note_mess", "mod");
1419 }
1420 $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1421 // }
1422 $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1423 $this->note_mess = "frmfld";
1424 $this->form->setValuesByPost();
1425 $_GET["note_id"] = $note->getId();
1426 $_GET["note_type"] = $note->getType();
1427 return $this->editNoteForm(false);
1428 }
1429
1433 public function editNoteForm($a_init_form = true)
1434 {
1435 $this->edit_note_form = true;
1436
1437 return $this->getNotesHTML($a_init_form);
1438 }
1439
1443 public function deleteNote()
1444 {
1445 $this->delete_note = true;
1446 $this->note_mess = "qdel";
1447 return $this->getNotesHTML();
1448 }
1449
1453 public function deleteNotes()
1454 {
1455 $lng = $this->lng;
1456
1457 if (!$_POST["note"]) {
1458 $this->note_mess = "noc";
1459 } else {
1460 $this->delete_note = true;
1461 $this->note_mess = "qdel";
1462 }
1463
1464 return $this->getNotesHTML();
1465 }
1466
1470 public function cancelDelete()
1471 {
1472 return $this->getNotesHTML();
1473 }
1474
1478 public function confirmDelete()
1479 {
1481 $lng = $this->lng;
1483
1484 $cnt = 0;
1485 foreach ($_POST["note"] as $id) {
1486 $note = new ilNote($id);
1487 if ($this->checkDeletion($note)) {
1488 $note->delete();
1489 $cnt++;
1490 }
1491 }
1492 if ($cnt > 1) {
1493 $ilCtrl->setParameter($this, "note_mess", "ntsdel");
1494 } else {
1495 $ilCtrl->setParameter($this, "note_mess", "ntdel");
1496 }
1497 $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1498 }
1499
1503 public function exportNotesHTML()
1504 {
1505 $tpl = new ilTemplate("tpl.main.html", true, true);
1506
1507 $this->export_html = true;
1508 $this->multi_selection = false;
1509 $tpl->setVariable("CONTENT", $this->getNotesHTML());
1510 ilUtil::deliverData($tpl->get(), "notes.html");
1511 }
1512
1516 public function printNotes()
1517 {
1518 $tpl = new ilTemplate("tpl.main.html", true, true);
1519
1520 $this->print = true;
1521 $this->multi_selection = false;
1522 $tpl->setVariable("CONTENT", $this->getNotesHTML());
1523 echo $tpl->get();
1524 exit;
1525 }
1526
1530 public function showNotes()
1531 {
1533
1534 $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1535 ? "private"
1536 : "public";
1537 $ilUser->writePref("notes_" . $suffix, "y");
1538
1539 return $this->getNotesHTML();
1540 }
1541
1545 public function hideNotes()
1546 {
1548
1549 $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1550 ? "private"
1551 : "public";
1552 $ilUser->writePref("notes_" . $suffix, "n");
1553
1554 return $this->getNotesHTML();
1555 }
1556
1560 public function showAllPublicNotes()
1561 {
1563
1564 $ilUser->writePref("notes_pub_all", "y");
1565
1566 return $this->getNotesHTML();
1567 }
1568
1572 public function showMyPublicNotes()
1573 {
1575
1576 $ilUser->writePref("notes_pub_all", "n");
1577
1578 return $this->getNotesHTML();
1579 }
1580
1584 public static function initJavascript($a_ajax_url, $a_type = IL_NOTE_PRIVATE, ilTemplate $a_main_tpl = null)
1585 {
1586 global $DIC;
1587
1588 if ($a_main_tpl != null) {
1589 $tpl = $a_main_tpl;
1590 } else {
1591 $tpl = $DIC["tpl"];
1592 }
1593 $lng = $DIC->language();
1594
1595 $lng->loadLanguageModule("notes");
1596
1597 include_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
1599
1600 $lng->toJs(array("private_notes", "notes_public_comments"), $tpl);
1601
1602 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1603 ilYuiUtil::initPanel(false, $tpl);
1604 include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1606 $tpl->addJavascript("./Services/Notes/js/ilNotes.js");
1607
1608 $tpl->addOnLoadCode("ilNotes.setAjaxUrl('" . $a_ajax_url . "');");
1609 }
1610
1618 public static function getListNotesJSCall($a_hash, $a_update_code = null)
1619 {
1620 if ($a_update_code === null) {
1621 $a_update_code = "null";
1622 } else {
1623 $a_update_code = "'" . $a_update_code . "'";
1624 }
1625
1626 return "ilNotes.listNotes(event, '" . $a_hash . "', " . $a_update_code . ");";
1627 }
1628
1636 public static function getListCommentsJSCall($a_hash, $a_update_code = null)
1637 {
1638 if ($a_update_code === null) {
1639 $a_update_code = "null";
1640 } else {
1641 $a_update_code = "'" . $a_update_code . "'";
1642 }
1643
1644 return "ilNotes.listComments(event, '" . $a_hash . "', " . $a_update_code . ");";
1645 }
1646
1656 protected static function buildAjaxHash($a_node_type, $a_node_id, $a_sub_id, $a_sub_type)
1657 {
1658 return $a_node_type . ";" . $a_node_id . ";" . $a_sub_id . ";" . $a_sub_type;
1659 }
1660
1664 public function renderLink($a_tpl, $a_var, $a_txt, $a_cmd, $a_anchor = "")
1665 {
1667
1668 $low_var = strtolower($a_var);
1669 $up_var = strtoupper($a_var);
1670
1671 if ($this->ajax) {
1672 $a_tpl->setVariable("LINK_" . $up_var, "#");
1673 $oc = "onclick = \"ilNotes.cmdAjaxLink(event, '" .
1674 $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, "", true) .
1675 "');\"";
1676 $a_tpl->setVariable("ON_CLICK_" . $up_var, $oc);
1677 } else {
1678 $a_tpl->setVariable(
1679 "LINK_" . $up_var,
1680 $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, $a_anchor)
1681 );
1682 }
1683
1684 $a_tpl->setCurrentBlock($low_var);
1685 $a_tpl->setVariable("TXT_" . $up_var, $a_txt);
1686 $a_tpl->parseCurrentBlock();
1687 }
1688
1694 public function addObserver($a_callback)
1695 {
1696 $this->observer[] = $a_callback;
1697 }
1698
1705 protected function notifyObserver($a_action, $a_note)
1706 {
1707 if (is_array($this->observer) && count($this->observer) > 0) {
1708 foreach ($this->observer as $item) {
1709 $param = $a_note->getObject();
1710 $param["action"] = $a_action;
1711 $param["note_id"] = $a_note->getId();
1712
1713 call_user_func_array($item, $param);
1714 }
1715 }
1716 }
1717
1718 protected function listSortAsc()
1719 {
1720 $_SESSION["comments_sort_asc"] = 1;
1721 return $this->getNotesHtml();
1722 }
1723
1724 protected function listSortDesc()
1725 {
1726 $_SESSION["comments_sort_asc"] = 0;
1727 return $this->getNotesHtml();
1728 }
1729
1736 public function getHTML()
1737 {
1738 return $this->getCommentsWidget();
1739 }
1740
1741
1748 protected function getCommentsWidget()
1749 {
1750 $f = $this->ui->factory();
1751 $r = $this->ui->renderer();
1752
1753 $lng = $this->lng;
1755 $ctrl->setParameter($this, "news_id", $this->news_id);
1758 null,
1759 ilObject::_lookupType($this->rep_obj_id),
1760 $this->rep_obj_id,
1761 $this->obj_type,
1762 $this->obj_id,
1763 $this->news_id
1764 );
1765
1766 $cnt = ilNote::_countNotesAndComments($this->rep_obj_id, $this->obj_id, $this->obj_type, $this->news_id);
1767 $cnt = $cnt[$this->rep_obj_id][IL_NOTE_PUBLIC];
1768
1769 $tpl = new ilTemplate("tpl.note_widget_header.html", true, true, "Services/Notes");
1770 $widget_el_id = "notew_" . str_replace(";", "_", $hash);
1771 $ctrl->setParameter($this, "hash", $hash);
1772 $update_url = $ctrl->getLinkTarget($this, "updateWidget", "", true, false);
1773 $comps = array();
1774 if ($cnt > 0) {
1775 $c = $f->counter()->status((int) $cnt);
1776 $comps[] = $f->glyph()->comment()->withCounter($c)->withAdditionalOnLoadCode(function ($id) use ($hash, $update_url, $widget_el_id) {
1777 return "$(\"#$id\").click(function(event) { " . self::getListCommentsJSCall($hash, "ilNotes.updateWidget(\"" . $widget_el_id . "\",\"" . $update_url . "\");") . "});";
1778 });
1779 $comps[] = $f->divider()->vertical();
1780 $tpl->setVariable("GLYPH", $r->render($comps));
1781 $tpl->setVariable("TXT_LATEST", $lng->txt("notes_latest_comment"));
1782 }
1783
1784
1785 $b = $f->button()->shy($lng->txt("notes_add_edit_comment"), "#")->withAdditionalOnLoadCode(function ($id) use ($hash,$update_url,$widget_el_id) {
1786 return "$(\"#$id\").click(function(event) { " . self::getListCommentsJSCall($hash, "ilNotes.updateWidget(\"" . $widget_el_id . "\",\"" . $update_url . "\");") . "});";
1787 });
1788 if ($ctrl->isAsynch()) {
1789 $tpl->setVariable("SHY_BUTTON", $r->renderAsync($b));
1790 } else {
1791 $tpl->setVariable("SHY_BUTTON", $r->render($b));
1792 }
1793
1794 $this->widget_header = $tpl->get();
1795
1796 $this->hide_new_form = true;
1797 $this->only_latest = true;
1798 $this->no_actions = true;
1799 $html = "<div id='" . $widget_el_id . "'>" . $this->getNoteListHTML(IL_NOTE_PUBLIC) . "</div>";
1800 $ctrl->setParameter($this, "news_id", $_GET["news_id"]);
1801 return $html;
1802 }
1803
1810 protected function updateWidget()
1811 {
1812 echo $this->getCommentsWidget();
1813 exit;
1814 }
1815}
user()
Definition: user.php:4
$tpl
Definition: ilias.php:10
if(! $in) print
$path
Definition: aliased.php:25
exit
Definition: backend.php:16
$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.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a hidden form property in a property form.
static initJS(ilTemplate $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
addNote()
add note
confirmDelete()
cancel deletion of note
getOnlyNotesHTML()
Get only notes html.
__construct( $a_rep_obj_id="", $a_obj_id="", $a_obj_type="", $a_include_subobjects=false, $a_news_id=0)
constructor, specifies notes set
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.
getOnlyCommentsHTML()
Get only comments html.
cancelDelete()
cancel deletion of note
editNoteForm($a_init_form=true)
get notes list including add note area
exportNotesHTML()
export selected notes to html
cancelAddNote()
cancel add note
getDefaultCommand()
Get default command.
enableAnchorJump($a_enable=true)
enable anchor for form jump
static initJavascript($a_ajax_url, $a_type=IL_NOTE_PRIVATE, ilTemplate $a_main_tpl=null)
Init javascript.
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 _lookupOwnerName($a_owner_id)
lookup owner name for owner id
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
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 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, ilTemplate $a_main_tpl=null)
Init yui panel.
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$txt
Definition: error.php:11
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach( $metaentries[ 'hosted'] as $index=> $entity) foreach($metaentries['remote'] as $key=> $set) $mtype
$additional
Definition: goto.php:50
global $ilCtrl
Definition: ilias.php:18
$target
Definition: test.php:19
global $ilSetting
Definition: privfeed.php:17
$type
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92
$text
Definition: errorreport.php:18