ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNoteGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
6 include_once ("Services/Notes/classes/class.ilNote.php");
7 
8 
18 class ilNoteGUI
19 {
21  var $repository_mode = false;
22 
31  function ilNoteGUI($a_rep_obj_id = "", $a_obj_id = "", $a_obj_type = "", $a_include_subobjects = false)
32  {
33  global $ilCtrl, $lng;
34 
35  $lng->loadLanguageModule("notes");
36 
37  $ilCtrl->saveParameter($this, "notes_only");
38  $this->only = $_GET["notes_only"];
39 
40  $this->rep_obj_id = $a_rep_obj_id;
41  $this->obj_id = $a_obj_id;
42  $this->obj_type = $a_obj_type;
43  $this->inc_sub = $a_include_subobjects;
44 
45  // auto-detect object type
46  if(!$this->obj_type && $a_rep_obj_id)
47  {
48  $this->obj_type = ilObject::_lookupType($a_rep_obj_id);
49  }
50 
51  $this->ajax = $ilCtrl->isAsynch();
52 
53  $this->ctrl =& $ilCtrl;
54  $this->lng =& $lng;
55 
56  $this->anchor_jump = true;
57  $this->add_note_form = false;
58  $this->edit_note_form = false;
59  $this->private_enabled = false;
60  $notes_settings = new ilSetting("notes");
61  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
62  //if ($notes_settings->get("activate_".$id))
63  if (ilNote::commentsActivated($this->rep_obj_id, $this->obj_id, $this->obj_type))
64  {
65  $this->public_enabled = true;
66  }
67  else
68  {
69  $this->public_enabled = false;
70  }
71  $this->enable_hiding = false;
72  $this->targets_enabled = false;
73  $this->multi_selection = false;
74  $this->export_html = false;
75  $this->print = false;
76  $this->comments_settings = false;
77 
78  $this->note_img = array(
79  IL_NOTE_UNLABELED => array(
80  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
81  "alt" => $lng->txt("note")),
82  IL_NOTE_IMPORTANT => array(
83  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
84  "alt" => $lng->txt("note").", ".$lng->txt("important")),
85  IL_NOTE_QUESTION => array(
86  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
87  "alt" => $lng->txt("note").", ".$lng->txt("question")),
88  IL_NOTE_PRO => array(
89  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
90  "alt" => $lng->txt("note").", ".$lng->txt("pro")),
91  IL_NOTE_CONTRA => array(
92  "img" => ilUtil::getImagePath("note_unlabeled.svg"),
93  "alt" => $lng->txt("note").", ".$lng->txt("contra"))
94  );
95 
96  $this->comment_img = array(
97  IL_NOTE_UNLABELED => array(
98  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
99  "alt" => $lng->txt("notes_comment")),
100  IL_NOTE_IMPORTANT => array(
101  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
102  "alt" => $lng->txt("notes_comment").", ".$lng->txt("important")),
103  IL_NOTE_QUESTION => array(
104  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
105  "alt" => $lng->txt("notes_comment").", ".$lng->txt("question")),
106  IL_NOTE_PRO => array(
107  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
108  "alt" => $lng->txt("notes_comment").", ".$lng->txt("pro")),
109  IL_NOTE_CONTRA => array(
110  "img" => ilUtil::getImagePath("comment_unlabeled.svg"),
111  "alt" => $lng->txt("notes_comment").", ".$lng->txt("contra"))
112  );
113 
114  // default: notes for repository objects
115  $this->setRepositoryMode(true);
116  }
117 
121  function &executeCommand()
122  {
123  $cmd = $this->ctrl->getCmd("getNotesHTML");
124  $next_class = $this->ctrl->getNextClass($this);
125 
126  switch($next_class)
127  {
128  default:
129  return $this->$cmd();
130  break;
131  }
132  }
133 
137  function enablePrivateNotes($a_enable = true)
138  {
139  $this->private_enabled = $a_enable;
140  }
141 
145  function enablePublicNotes($a_enable = true)
146  {
147  $this->public_enabled = $a_enable;
148  }
149 
153  function enableCommentsSettings($a_enable = true)
154  {
155  $this->comments_settings = $a_enable;
156  }
157 
161  function enablePublicNotesDeletion($a_enable = true)
162  {
163  $this->public_deletion_enabled = $a_enable;
164  }
165 
169  function enableHiding($a_enable = true)
170  {
171  $this->enable_hiding = $a_enable;
172  }
173 
177  function enableTargets($a_enable = true)
178  {
179  $this->targets_enabled = $a_enable;
180  }
181 
185  function enableMultiSelection($a_enable = true)
186  {
187  $this->multi_selection = $a_enable;
188  }
189 
193  function enableAnchorJump($a_enable = true)
194  {
195  $this->anchor_jump = $a_enable;
196  }
197 
203  function setRepositoryMode($a_value)
204  {
205  $this->repository_mode = (bool)$a_value;
206  }
207 
208 
215  function getOnlyNotesHTML()
216  {
217  global $ilCtrl;
218  $ilCtrl->setParameter($this, "notes_only", "notes");
219  $this->only = "notes";
220  return $this->getNotesHTML($a_init_form = true);
221  }
222 
230  {
231  global $ilCtrl;
232  $ilCtrl->setParameter($this, "notes_only", "comments");
233  $this->only = "comments";
234  return $this->getNotesHTML($a_init_form = true);
235  }
236 
237 
238  /***
239  * get note lists html code
240  */
241  function getNotesHTML($a_init_form = true)
242  {
243  global $ilUser, $lng, $ilCtrl, $ilSetting;
244 
245  $lng->loadLanguageModule("notes");
246 
247  $ntpl = new ilTemplate("tpl.notes_and_comments.html", true, true,
248  "Services/Notes");
249 
250  // check, whether column is hidden due to processing in other column
251  $hide_comments = ($this->only == "notes");
252  $hide_notes = ($this->only == "comments");
253  switch($ilCtrl->getCmd())
254  {
255  case "addNoteForm":
256  case "editNoteForm":
257  case "addNote":
258  case "updateNote":
259  if ($_GET["note_type"] == IL_NOTE_PRIVATE)
260  {
261  $hide_comments = true;
262  }
263  if ($_GET["note_type"] == IL_NOTE_PUBLIC)
264  {
265  $hide_notes = true;
266  }
267  break;
268  }
269 
270 
271 // temp workaround: only show comments (if both have been activated)
272 if ($this->private_enabled && $this->public_enabled
273  && $this->only != "notes")
274 {
275  $this->private_enabled = false;
276 }
277 
278  $nodes_col = false;
279  if ($this->private_enabled && ($ilUser->getId() != ANONYMOUS_USER_ID)
280  && !$hide_notes)
281  {
282  $ntpl->setCurrentBlock("notes_col");
283  $ntpl->setVariable("NOTES", $this->getNoteListHTML(IL_NOTE_PRIVATE, $a_init_form));
284  $ntpl->parseCurrentBlock();
285  $nodes_col = true;
286  }
287 
288  // #15948 - public enabled vs. comments_settings
289  $comments_col = false;
290  if ($this->public_enabled && (!$this->delete_note || $this->public_deletion_enabled || $ilSetting->get("comments_del_user", 0))
291  && !$hide_comments /* && $ilUser->getId() != ANONYMOUS_USER_ID */)
292  {
293  $ntpl->setVariable("COMMENTS", $this->getNoteListHTML(IL_NOTE_PUBLIC, $a_init_form));
294  $comments_col = true;
295  }
296 
297  // Comments Settings
298  if ($this->comments_settings && !$hide_comments && !$this->delete_note
299  && !$this->edit_note_form && !$this->add_note_form && $ilUser->getId() != ANONYMOUS_USER_ID)
300  {
301  $notes_settings = new ilSetting("notes");
302  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
303  //$active = $notes_settings->get("activate_".$id);
304  $active = ilNote::commentsActivated($this->rep_obj_id, $this->obj_id, $this->obj_type);
305 
306  if ($active)
307  {
308  $this->renderLink($ntpl, "comments_settings", $lng->txt("notes_deactivate_comments"),
309  "deactivateComments", "notes_top");
310  $ntpl->setCurrentBlock("comments_settings2");
311  }
312  else
313  {
314  $this->renderLink($ntpl, "comments_settings", $lng->txt("notes_activate_comments"),
315  "activateComments", "notes_top");
316  $ntpl->setCurrentBlock("comments_settings2");
317 
318  if ($this->ajax && !$comments_col)
319  {
320  $ntpl->setVariable("COMMENTS_MESS",
321  $ntpl->getMessageHTML($lng->txt("comments_feature_currently_not_activated_for_object"), "info"));
322  }
323  }
324  $ntpl->parseCurrentBlock();
325 
326  if (!$comments_col)
327  {
328  $ntpl->setVariable("COMMENTS", "");
329  }
330 
331  $comments_col = true;
332  }
333 
334  if ($comments_col)
335  {
336  $ntpl->setCurrentBlock("comments_col");
337  if ($nodes_col)
338  {
339 // $ntpl->touchBlock("comments_style");
340  }
341  $ntpl->parseCurrentBlock();
342  }
343 
344  if ($this->ajax)
345  {
346  echo $ntpl->get();
347  exit;
348  }
349 
350  return $ntpl->get();
351  }
352 
356  function activateComments()
357  {
358  global $ilCtrl;
359 
360  $notes_settings = new ilSetting("notes");
361 
362  if ($this->comments_settings)
363  {
364  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
365  //$notes_settings->set("activate_".$id, 1);
366  ilNote::activateComments($this->rep_obj_id, $this->obj_id, $this->obj_type, true);
367  }
368 
369  $ilCtrl->redirectByClass("ilnotegui", "showNotes", "", $this->ajax);
370 // $ilCtrl->redirectByClass("ilnotegui", "getNotesHtml", "", $this->ajax);
371  }
372 
377  {
378  global $ilCtrl;
379 
380  $notes_settings = new ilSetting("notes");
381 
382  if ($this->comments_settings)
383  {
384  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
385  //$notes_settings->set("activate_".$id, 0);
386  ilNote::activateComments($this->rep_obj_id, $this->obj_id, $this->obj_type, false);
387  }
388 
389  $ilCtrl->redirectByClass("ilnotegui", "showNotes", "", $this->ajax);
390  //$ilCtrl->redirectByClass("ilnotegui", "getNotesHtml", "", $this->ajax);
391  }
392 
396  function getNoteListHTML($a_type = IL_NOTE_PRIVATE, $a_init_form = true)
397  {
398  global $lng, $ilCtrl, $ilUser;
399 
400  include_once("./Services/User/classes/class.ilUserUtil.php");
401 
402  $suffix = ($a_type == IL_NOTE_PRIVATE)
403  ? "private"
404  : "public";
405 
406  /* user settings are deprecated
407  $user_setting_notes_public_all = $ilUser->getPref("notes_pub_all");
408  $user_setting_notes_by_type = $ilUser->getPref("notes_".$suffix);
409  */
410  $user_setting_notes_public_all = "y";
411  $user_setting_notes_by_type = "y";
412 
413  if ($this->delete_note || $this->export_html || $this->print)
414  {
415  if ($_GET["note_id"] != "")
416  {
417  $filter = $_GET["note_id"];
418  }
419  else
420  {
421  $filter = $_POST["note"];
422  }
423  }
424 
425  $notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
426  $this->obj_type, $a_type, $this->inc_sub, $filter,
427  $user_setting_notes_public_all, $this->repository_mode, (bool)$_SESSION["comments_sort_asc"]);
428 
429  $all_notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
430  $this->obj_type, $a_type, $this->inc_sub, $filter,
431  "", $this->repository_mode);
432 
433  $tpl = new ilTemplate("tpl.notes_list.html", true, true, "Services/Notes");
434 
435  if ($this->ajax)
436  {
437  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
438  $tpl->setCurrentBlock("close_img");
439  $tpl->setVariable("CLOSE_IMG", ilGlyphGUI::get(ilGlyphGUI::CLOSE));
440  $tpl->parseCurrentBlock();
441  }
442 
443  // show counter if notes are hidden
444  $cnt_str = (count($all_notes) > 0)
445  ? " (".count($all_notes).")"
446  : "";
447 
448  // title
449  if ($this->ajax)
450  {
451  switch($this->obj_type)
452  {
453  case "catr":
454  case "crsr":
455  include_once "Services/ContainerReference/classes/class.ilContainerReference.php";
456  $title = ilContainerReference::_lookupTitle($this->rep_obj_id);
457  break;
458 
459  default:
460  $title = ilObject::_lookupTitle($this->rep_obj_id);
461  break;
462  }
463 
464  $img = ilUtil::img(ilObject::_getIcon($this->rep_obj_id, "tiny"));
465 
466  // add sub-object if given
467  if($this->obj_id)
468  {
469  $sub_title = $this->getSubObjectTitle($this->rep_obj_id, $this->obj_id);
470  if($sub_title)
471  {
472  $title .= " - ".$sub_title;
473  }
474  }
475 
476  $tpl->setCurrentBlock("title");
477  $tpl->setVariable("TITLE", $img." ".$title);
478  $tpl->parseCurrentBlock();
479  }
480 
481  if ($this->delete_note)
482  {
483  $cnt_str = "";
484  }
485  if ($a_type == IL_NOTE_PRIVATE)
486  {
487  $tpl->setVariable("TXT_NOTES", $lng->txt("private_notes").$cnt_str);
488  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PRIVATE);
489  }
490  else
491  {
492  $tpl->setVariable("TXT_NOTES", $lng->txt("notes_public_comments").$cnt_str);
493  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PUBLIC);
494  }
495  $anch = $this->anchor_jump
496  ? "notes_top"
497  : "";
498  $tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this, "getNotesHTML", $anch));
499  if ($this->ajax)
500  {
501  $os = "onsubmit = \"ilNotes.cmdAjaxForm(event, '".
502  $ilCtrl->getFormActionByClass("ilnotegui", "", "", true).
503  "'); return false;\"";
504  $tpl->setVariable("ON_SUBMIT_FORM", $os);
505  $tpl->setVariable("FORM_ID", "Ajax");
506  }
507 
508  if ($this->export_html || $this->print)
509  {
510  $tpl->touchBlock("print_style");
511  }
512 
513  // show add new note button
514  if (!$this->add_note_form && !$this->edit_note_form && !$this->delete_note &&
515  !$this->export_html && !$this->print && $ilUser->getId() != ANONYMOUS_USER_ID)
516  {
517  if (!$this->inc_sub) // we cannot offer add button if aggregated notes
518  { // are displayed
519  if ($this->rep_obj_id > 0 || $a_type != IL_NOTE_PUBLIC)
520  {
521  $tpl->setCurrentBlock("add_note_btn");
522  if ($a_type == IL_NOTE_PUBLIC)
523  {
524  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("notes_add_comment"));
525  }
526  else
527  {
528  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("add_note"));
529  }
530  $tpl->setVariable("LINK_ADD_NOTE", $ilCtrl->getLinkTargetByClass("ilnotegui", "addNoteForm").
531  "#note_edit");
532  $tpl->parseCurrentBlock();
533  }
534  }
535  }
536 
537  // show show/hide button for note list
538  if (count($all_notes) > 0 && $this->enable_hiding && !$this->delete_note
539  && !$this->export_html && !$this->print && !$this->edit_note_form
540  && !$this->add_note_form)
541  {
542  if ($user_setting_notes_by_type == "n")
543  {
544  if ($a_type == IL_NOTE_PUBLIC)
545  {
546  $txt = $lng->txt("notes_show_comments");
547  }
548  else
549  {
550  $txt = $lng->txt("show_".$suffix."_notes");
551  }
552  $this->renderLink($tpl, "show_notes", $txt, "showNotes", "notes_top");
553  }
554  else
555  {
556  // never individually hide for anonymous users
557  if (($ilUser->getId() != ANONYMOUS_USER_ID))
558  {
559  if ($a_type == IL_NOTE_PUBLIC)
560  {
561  $txt = $lng->txt("notes_hide_comments");
562  }
563  else
564  {
565  $txt = $lng->txt("hide_".$suffix."_notes");
566  }
567  $this->renderLink($tpl, "hide_notes", $txt, "hideNotes", "notes_top");
568 
569  // show all public notes / my notes only switch
570  if ($a_type == IL_NOTE_PUBLIC)
571  {
572  if ($user_setting_notes_public_all == "n")
573  {
574  $this->renderLink($tpl, "all_pub_notes", $lng->txt("notes_all_comments"),
575  "showAllPublicNotes", "notes_top");
576  }
577  else
578  {
579  $this->renderLink($tpl, "my_pub_notes", $lng->txt("notes_my_comments"),
580  "showMyPublicNotes", "notes_top");
581  }
582  }
583  }
584  }
585  }
586 
587  // show add new note text area
588  if (!$this->edit_note_form && $user_setting_notes_by_type != "n" &&
589  !$this->delete_note && $ilUser->getId() != ANONYMOUS_USER_ID)
590  {
591  if ($a_init_form)
592  {
593  $this->initNoteForm("create", $a_type);
594  }
595 
596  $tpl->setCurrentBlock("edit_note_form");
597 // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
598  $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
599  $tpl->parseCurrentBlock();
600 
601  $tpl->parseCurrentBlock();
602  $tpl->setCurrentBlock("note_row");
603  $tpl->parseCurrentBlock();
604  }
605 
606  // list all notes
607  if ($user_setting_notes_by_type != "n" || !$this->enable_hiding)
608  {
611 
612  if(sizeof($notes))
613  {
614  if((int)$_SESSION["comments_sort_asc"] == 1)
615  {
616  $sort_txt = $lng->txt("notes_sort_desc");
617  $sort_cmd = "listSortDesc";
618  }
619  else
620  {
621  $sort_txt = $lng->txt("notes_sort_asc");
622  $sort_cmd = "listSortAsc";
623  }
624  $this->renderLink($tpl, "sort_list", $sort_txt, $sort_cmd, $anch);
625  }
626 
627  $notes_given = false;
628  foreach($notes as $note)
629  {
630  if ($this->edit_note_form && ($note->getId() == $_GET["note_id"])
631  && $a_type == $_GET["note_type"])
632  {
633  if ($a_init_form)
634  {
635  $this->initNoteForm("edit", $a_type, $note);
636  }
637  $tpl->setCurrentBlock("edit_note_form");
638 // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
639  $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
640  $tpl->parseCurrentBlock();
641  }
642  else
643  {
644  $cnt_col = 2;
645 
646  // delete note stuff for all private notes
647  if ($this->checkDeletion($note)
648  && !$this->delete_note
649  && !$this->export_html && !$this->print
650  && !$this->edit_note_form && !$this->add_note_form)
651  {
652  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
653  $this->renderLink($tpl, "delete_note", $lng->txt("delete"),
654  "deleteNote", "note_".$note->getId());
655  }
656 
657  // checkboxes in multiselection mode
658  if ($this->multi_selection && !$this->delete_note)
659  {
660  $tpl->setCurrentBlock("checkbox_col");
661  $tpl->setVariable("CHK_NOTE", "note[]");
662  $tpl->setVariable("CHK_NOTE_ID", $note->getId());
663  $tpl->parseCurrentBlock();
664  $cnt_col = 1;
665  }
666 
667  // edit note stuff for all private notes
668  if ($this->checkEdit($note))
669  {
670 
671  if (!$this->delete_note && !$this->export_html && !$this->print
672  && !$this->edit_note_form && !$this->add_note_form)
673  {
674  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
675  $this->renderLink($tpl, "edit_note", $lng->txt("edit"),
676  "editNoteForm", "note_edit");
677  }
678  }
679 
680  $tpl->setVariable("CNT_COL", $cnt_col);
681 
682  // output author account
683  if ($a_type == IL_NOTE_PUBLIC && ilObject::_exists($note->getAuthor()))
684  {
685  //$tpl->setCurrentBlock("author");
686  //$tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin($note->getAuthor()));
687  //$tpl->parseCurrentBlock();
688  $tpl->setCurrentBlock("user_img");
689  $tpl->setVariable("USR_IMG",
690  ilObjUser::_getPersonalPicturePath($note->getAuthor(), "xxsmall"));
691  $tpl->setVariable("USR_ALT", $lng->txt("user_image").": ".
692  ilObjUser::_lookupLogin($note->getAuthor()));
693  $tpl->parseCurrentBlock();
694  $tpl->setVariable("TXT_USR",
695  ilUserUtil::getNamePresentation($note->getAuthor(), false, false)." - ");
696  }
697 
698  // last edited
699  if ($note->getUpdateDate() != null)
700  {
701  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
702  $tpl->setVariable("DATE_LAST_EDIT",
703  ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME)));
704  }
705  else
706  {
707  $tpl->setVariable("VAL_DATE",
708  ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME)));
709  }
710 
711  // hidden note ids for deletion
712  if ($this->delete_note)
713  {
714  $tpl->setCurrentBlock("delete_ids");
715  $tpl->setVariable("HID_NOTE", "note[]");
716  $tpl->setVariable("HID_NOTE_ID", $note->getId());
717  $tpl->parseCurrentBlock();
718  }
719  $target = $note->getObject();
720 
721  // target objects
722  $this->showTargets($tpl, $this->rep_obj_id, $note->getId(),
723  $target["obj_type"], $target["obj_id"]);
724 
725  $rowclass = ($rowclass != "tblrow1")
726  ? "tblrow1"
727  : "tblrow2";
728  if (!$this->export_html && !$this->print)
729  {
730  $tpl->setCurrentBlock("note_img");
731  if ($a_type == IL_NOTE_PUBLIC)
732  {
733  $tpl->setVariable("IMG_NOTE", $this->comment_img[$note->getLabel()]["img"]);
734  $tpl->setVariable("ALT_NOTE", $this->comment_img[$note->getLabel()]["alt"]);
735  }
736  else
737  {
738  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
739  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
740  }
741  $tpl->parseCurrentBlock();
742  }
743  else
744  {
745  switch ($note->getLabel())
746  {
747  case IL_NOTE_UNLABELED:
748  $tpl->setVariable("EXP_ICON", "[&nbsp;]");
749  break;
750 
751  case IL_NOTE_IMPORTANT:
752  $tpl->setVariable("EXP_ICON", "[!]");
753  break;
754 
755  case IL_NOTE_QUESTION:
756  $tpl->setVariable("EXP_ICON", "[?]");
757  break;
758 
759  case IL_NOTE_PRO:
760  $tpl->setVariable("EXP_ICON", "[+]");
761  break;
762 
763  case IL_NOTE_CONTRA:
764  $tpl->setVariable("EXP_ICON", "[-]");
765  break;
766  }
767  }
768  $tpl->setCurrentBlock("note");
769  $tpl->setVariable("ROWCLASS", $rowclass);
770  $text = (trim($note->getText()) != "")
771  ? nl2br($note->getText())
772  : "<p class='subtitle'>".$lng->txt("note_content_removed")."</p>";
773  $tpl->setVariable("NOTE_TEXT", $text);
774  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
775  $tpl->setVariable("NOTE_ID", $note->getId());
776  $tpl->setVariable("CLASS", $a_type == IL_NOTE_PUBLIC
777  ? "ilComment"
778  : "ilNote");
779  $tpl->parseCurrentBlock();
780  }
781  $tpl->setCurrentBlock("note_row");
782  $tpl->parseCurrentBlock();
783  $notes_given = true;
784  }
785 
786  if (!$notes_given)
787  {
788  $tpl->setCurrentBlock("no_notes");
789  if ($a_type == IL_NOTE_PUBLIC)
790  {
791  $tpl->setVariable("NO_NOTES", $lng->txt("notes_no_comments"));
792  }
793 /* else
794  {
795  $tpl->setVariable("NO_NOTES", $lng->txt("notes_no_notes"));
796  }*/
797  $tpl->parseCurrentBlock();
798  }
799 
801 
802  // multiple items commands
803  if ($this->multi_selection && !$this->delete_note && !$this->edit_note_form
804  && count($notes) > 0)
805  {
806  if ($a_type == IL_NOTE_PRIVATE)
807  {
808  $tpl->setCurrentBlock("delete_cmd");
809  $tpl->setVariable("TXT_DELETE_NOTES", $this->lng->txt("delete"));
810  $tpl->parseCurrentBlock();
811  }
812 
813  $tpl->setCurrentBlock("multiple_commands");
814  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
815  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
816  $tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
817  $tpl->setVariable("TXT_PRINT_NOTES", $this->lng->txt("print"));
818  $tpl->setVariable("TXT_EXPORT_NOTES", $this->lng->txt("exp_html"));
819  $tpl->parseCurrentBlock();
820  }
821 
822  // delete / cancel row
823  if ($this->delete_note)
824  {
825  $tpl->setCurrentBlock("delete_cancel");
826  $tpl->setVariable("TXT_DEL_NOTES", $this->lng->txt("delete"));
827  $tpl->setVariable("TXT_CANCEL_DEL_NOTES", $this->lng->txt("cancel"));
828  $tpl->parseCurrentBlock();
829  }
830 
831  // print
832  if ($this->print)
833  {
834  $tpl->touchBlock("print_js");
835  $tpl->setCurrentBlock("print_back");
836  $tpl->setVariable("LINK_BACK", $this->ctrl->getLinkTarget($this, "showNotes"));
837  $tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
838  $tpl->parseCurrentBlock();
839  }
840  }
841 
842  // message
843  switch($_GET["note_mess"] != "" ? $_GET["note_mess"] : $this->note_mess)
844  {
845  case "mod":
846  $mtype = "success";
847  $mtxt = $lng->txt("msg_obj_modified");
848  break;
849 
850  case "ntsdel":
851  $mtype = "success";
852  $mtxt = ($a_type == IL_NOTE_PRIVATE)
853  ? $lng->txt("notes_notes_deleted")
854  : $lng->txt("notes_comments_deleted");
855  break;
856 
857  case "ntdel":
858  $mtype = "success";
859  $mtxt = ($a_type == IL_NOTE_PRIVATE)
860  ? $lng->txt("notes_note_deleted")
861  : $lng->txt("notes_comment_deleted");
862  break;
863 
864  case "frmfld":
865  $mtype = "failure";
866  $mtxt = $lng->txt("form_input_not_valid");
867  break;
868 
869  case "qdel":
870  $mtype = "question";
871  $mtxt = $lng->txt("info_delete_sure");
872  break;
873 
874  case "noc":
875  $mtype = "failure";
876  $mtxt = $lng->txt("no_checkbox");
877  break;
878  }
879  if ($mtxt != "")
880  {
881  $tpl->setVariable("MESS", $tpl->getMessageHTML($mtxt, $mtype));
882  }
883  else
884  {
885  $tpl->setVariable("MESS", "");
886  }
887 
888 
889 
890  if ($this->delete_note && count($notes) == 0)
891  {
892  return "";
893  }
894  else
895  {
896  return $tpl->get();
897  }
898  }
899 
907  protected function getSubObjectTitle($parent_obj_id, $sub_obj_id)
908  {
909  global $objDefinition, $ilCtrl;
910 
911  $parent_type = ilObject::_lookupType($parent_obj_id);
912  $parent_class = "ilObj".$objDefinition->getClassName($parent_type)."GUI";
913  $parent_path = $ilCtrl->lookupClassPath($parent_class);
914  include_once $parent_path;
915  if(method_exists($parent_class, "lookupSubObjectTitle"))
916  {
917  return call_user_func_array(array($parent_class, "lookupSubObjectTitle"), array($parent_obj_id, $sub_obj_id));
918  }
919  }
920 
924  function checkDeletion($a_note)
925  {
926  global $ilUser, $ilSetting;
927 
928  if ($ilUser->getId() == ANONYMOUS_USER_ID)
929  {
930  return false;
931  }
932 
933  $is_author = ($a_note->getAuthor() == $ilUser->getId());
934 
935  if ($a_note->getType() == IL_NOTE_PRIVATE && $is_author)
936  {
937  return true;
938  }
939 
940  if ($a_note->getType() == IL_NOTE_PUBLIC && $this->public_deletion_enabled)
941  {
942  return true;
943  }
944 
945  if ($a_note->getType() == IL_NOTE_PUBLIC && $is_author && $ilSetting->get("comments_del_user", 0))
946  {
947  return true;
948  }
949 
950  return false;
951  }
952 
956  function checkEdit($a_note)
957  {
958  global $ilUser;
959 
960  if ($a_note->getAuthor() == $ilUser->getId()
961  && ($ilUser->getId() != ANONYMOUS_USER_ID))
962  {
963  return true;
964  }
965  return false;
966  }
967 
968 
974  public function initNoteForm($a_mode = "edit", $a_type, $a_note = null)
975  {
976  global $lng, $ilCtrl;
977 
978  $this->form_tpl = new ilTemplate("tpl.notes_edit.html", true, true, "Services/Notes");
979  if ($a_note)
980  {
981  $this->form_tpl->setVariable("VAL_NOTE", ilUtil::prepareFormOutput($a_note->getText()));
982  $this->form_tpl->setVariable("NOTE_ID", $a_note->getId());
983  }
984 
985  if ($a_mode == "create")
986  {
987  $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
988  ? $lng->txt("note_add_comment")
989  : $lng->txt("note_add_note"));
990  $this->form_tpl->setVariable("CMD", "addNote");
991  }
992  else
993  {
994  $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
995  ? $lng->txt("note_update_comment")
996  : $lng->txt("note_update_note"));
997  $this->form_tpl->setVariable("CMD", "updateNote");
998  }
999 
1000 return;
1001  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1002  $this->form = new ilPropertyFormGUI();
1003  $this->form->setOpenTag(false);
1004  $this->form->setCloseTag(false);
1005  $this->form->setDisableStandardMessage(true);
1006 
1007  // subject
1008 /* $ti = new ilTextInputGUI($this->lng->txt("subject"), "sub_note");
1009  $ti->setRequired(true);
1010  $ti->setMaxLength(200);
1011  $ti->setSize(40);
1012  if ($a_note)
1013  {
1014  $ti->setValue($a_note->getSubject());
1015  }
1016  $this->form->addItem($ti);*/
1017 
1018  // text
1019 // $ta = new ilTextAreaInputGUI(($a_type == IL_NOTE_PUBLIC)
1020 // ? $lng->txt("notes_comment")
1021 // : $lng->txt("note"), "note");
1022  $ta = new ilTextAreaInputGUI("", "note");
1023  $ta->setCols(40);
1024  $ta->setRows(4);
1025  if ($a_note)
1026  {
1027  $ta->setValue($a_note->getText());
1028  }
1029  $this->form->addItem($ta);
1030 
1031  // label
1032 /* $options = array(
1033  IL_NOTE_UNLABELED => $lng->txt("unlabeled"),
1034  IL_NOTE_QUESTION => $lng->txt("question"),
1035  IL_NOTE_IMPORTANT => $lng->txt("important"),
1036  IL_NOTE_PRO => $lng->txt("pro"),
1037  IL_NOTE_CONTRA => $lng->txt("contra"),
1038  );
1039  $si = new ilSelectInputGUI($this->lng->txt("notes_label"), "note_label");
1040  $si->setOptions($options);
1041  if ($a_note)
1042  {
1043  $si->setValue($a_note->getLabel());
1044  }
1045  $this->form->addItem($si); */
1046 
1047  // hidden note id
1048  if ($a_note)
1049  {
1050  $hi = new ilHiddenInputGUI("note_id");
1051  $hi->setValue($_GET["note_id"]);
1052  $this->form->addItem($hi);
1053  }
1054 
1055  // save and cancel commands
1056  if ($a_mode == "create")
1057  {
1058  $this->form->addCommandButton("addNote", $lng->txt("save"));
1059 /* $this->form->addCommandButton("cancelAddNote", $lng->txt("cancel"));
1060  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1061  ? $lng->txt("notes_add_comment")
1062  : $lng->txt("notes_add_note"));*/
1063  }
1064  else
1065  {
1066  $this->form->addCommandButton("updateNote", $lng->txt("save"));
1067 /* $this->form->addCommandButton("cancelUpdateNote", $lng->txt("cancel"));
1068  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1069  ? $lng->txt("notes_edit_comment")
1070  : $lng->txt("notes_edit_note"));*/
1071  }
1072 
1073  $ilCtrl->setParameter($this, "note_type", $a_type);
1074  $this->form->setFormAction($this->ctrl->getFormAction($this));
1075 
1076  }
1077 
1081  function getPDNoteHTML($note_id)
1082  {
1083  global $lng, $ilCtrl, $ilUser;
1084 
1085  $tpl = new ilTemplate("tpl.pd_note.html", true, true, "Services/Notes");
1086  $note = new ilNote($note_id);
1087  $target = $note->getObject();
1088 
1089  if ($note->getAuthor() != $ilUser->getId())
1090  {
1091  return;
1092  }
1093 
1094  $tpl->setCurrentBlock("edit_note");
1095  $ilCtrl->setParameterByClass("ilnotegui", "rel_obj", $target["rep_obj_id"]);
1096  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note_id);
1097  $ilCtrl->setParameterByClass("ilnotegui", "note_type", $note->getType());
1098  $tpl->setVariable("LINK_EDIT_NOTE",
1099  $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilpdnotesgui", "ilnotegui"),
1100  "editNoteForm"));
1101  $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
1102  $tpl->parseCurrentBlock();
1103  $ilCtrl->clearParametersByClass("ilnotegui");
1104 
1105  $tpl->setCurrentBlock("note_img");
1106  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
1107  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
1108  $tpl->parseCurrentBlock();
1109 
1110  // last edited
1111  if ($note->getUpdateDate() != null)
1112  {
1113  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
1114  $tpl->setVariable("DATE_LAST_EDIT",
1115  ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME)));
1116  }
1117  else
1118  {
1119  //$tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
1120  $tpl->setVariable("VAL_DATE",
1121  ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME)));
1122  }
1123 
1124  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
1125  $text = (trim($note->getText()) != "")
1126  ? nl2br($note->getText())
1127  : "<p class='subtitle'>".$lng->txt("note_content_removed")."</p>";
1128  $tpl->setVariable("NOTE_TEXT", $text);
1129  $this->showTargets($tpl, $target["rep_obj_id"], $note_id, $target["obj_type"], $target["obj_id"]);
1130  return $tpl->get();
1131  }
1132 
1136  function showTargets(&$tpl, $a_rep_obj_id, $a_note_id, $a_obj_type, $a_obj_id)
1137  {
1138  global $tree, $ilAccess, $objDefinition, $ilUser;
1139 
1140  if ($this->targets_enabled)
1141  {
1142  if ($a_rep_obj_id > 0)
1143  {
1144  // get all visible references of target object
1145 
1146  // repository
1147  $ref_ids = ilObject::_getAllReferences($a_rep_obj_id);
1148  if($ref_ids)
1149  {
1150  $vis_ref_ids = array();
1151  foreach($ref_ids as $ref_id)
1152  {
1153  if ($ilAccess->checkAccess("visible", "", $ref_id))
1154  {
1155  $vis_ref_ids[] = $ref_id;
1156  }
1157  }
1158 
1159  // output links to targets
1160  if (count($vis_ref_ids) > 0)
1161  {
1162  foreach($vis_ref_ids as $vis_ref_id)
1163  {
1164  $type = ilObject::_lookupType($vis_ref_id, true);
1165  $sub_link = $sub_title = "";
1166  if ($type == "sahs") // bad hack, needs general procedure
1167  {
1168  $link = "goto.php?target=sahs_".$vis_ref_id;
1169  $title = ilObject::_lookupTitle($a_rep_obj_id);
1170  if ($a_obj_type == "sco" || $a_obj_type == "seqc" || $a_obj_type == "chap" || $a_obj_type == "pg")
1171  {
1172  $sub_link = "goto.php?target=sahs_".$vis_ref_id."_".$a_obj_id;
1173  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
1174  $sub_title = ilSCORM2004Node::_lookupTitle($a_obj_id);
1175  $sub_icon = ilUtil::getImagePath("icon_".$a_obj_type.".svg");
1176  }
1177  }
1178  else if ($type == "poll")
1179  {
1180  include_once "Services/Link/classes/class.ilLink.php";
1181  $title = ilObject::_lookupTitle($a_rep_obj_id);
1182  $link = ilLink::_getLink($vis_ref_id, "poll");
1183  }
1184  else if ($a_obj_type != "pg")
1185  {
1186  if (!is_object($this->item_list_gui[$type]))
1187  {
1188  $class = $objDefinition->getClassName($type);
1189  $location = $objDefinition->getLocation($type);
1190  $full_class = "ilObj".$class."ListGUI";
1191  include_once($location."/class.".$full_class.".php");
1192  $this->item_list_gui[$type] = new $full_class();
1193  }
1194 
1195  // for references, get original title
1196  // (link will lead to orignal, which basically is wrong though)
1197  if($a_obj_type == "crsr" || $a_obj_type == "catr")
1198  {
1199  include_once "Services/ContainerReference/classes/class.ilContainerReference.php";
1200  $tgt_obj_id = ilContainerReference::_lookupTargetId($a_rep_obj_id);
1201  $title = ilObject::_lookupTitle($tgt_obj_id);
1202  }
1203  else
1204  {
1205  $title = ilObject::_lookupTitle($a_rep_obj_id);
1206  }
1207  $this->item_list_gui[$type]->initItem($vis_ref_id, $a_rep_obj_id, $title);
1208  $link = $this->item_list_gui[$type]->getCommandLink("infoScreen");
1209 
1210  // workaround, because # anchor can't be passed through frameset
1211  $link = ilUtil::appendUrlParameterString($link, "anchor=note_".$a_note_id);
1212 
1213  $link = $this->item_list_gui[$type]->appendRepositoryFrameParameter($link)."#note_".$a_note_id;
1214  }
1215  else
1216  {
1217  $title = ilObject::_lookupTitle($a_rep_obj_id);
1218  $link = "goto.php?target=pg_".$a_obj_id."_".$vis_ref_id;
1219  }
1220 
1221  $par_id = $tree->getParentId($vis_ref_id);
1222 
1223  // sub object link
1224  if ($sub_link != "")
1225  {
1226  if ($this->export_html || $this->print)
1227  {
1228  $tpl->setCurrentBlock("exp_target_sub_object");
1229  }
1230  else
1231  {
1232  $tpl->setCurrentBlock("target_sub_object");
1233  $tpl->setVariable("LINK_SUB_TARGET", $sub_link);
1234  }
1235  $tpl->setVariable("TXT_SUB_TARGET", $sub_title);
1236  $tpl->setVariable("IMG_SUB_TARGET", $sub_icon);
1237  $tpl->parseCurrentBlock();
1238  }
1239 
1240  // container and object link
1241  if ($this->export_html || $this->print)
1242  {
1243  $tpl->setCurrentBlock("exp_target_object");
1244  }
1245  else
1246  {
1247  $tpl->setCurrentBlock("target_object");
1248  $tpl->setVariable("LINK_TARGET", $link);
1249  }
1250  $tpl->setVariable("TXT_CONTAINER",
1252  ilObject::_lookupObjId($par_id)));
1253  $tpl->setVariable("IMG_CONTAINER",
1255  ilObject::_lookupObjId($par_id), "tiny"));
1256  $tpl->setVariable("TXT_TARGET", $title);
1257  $tpl->setVariable("IMG_TARGET",
1258  ilObject::_getIcon($a_rep_obj_id, "tiny"));
1259 
1260  $tpl->parseCurrentBlock();
1261  }
1262  $tpl->touchBlock("target_objects");
1263  }
1264  }
1265  // personal workspace
1266  else
1267  {
1268  // we only need 1 instance
1269  if(!$this->wsp_tree)
1270  {
1271  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1272  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
1273  $this->wsp_tree = new ilWorkspaceTree($ilUser->getId());
1274  $this->wsp_access_handler = new ilWorkspaceAccessHandler($this->wsp_tree);
1275  }
1276  $node_id = $this->wsp_tree->lookupNodeId($a_rep_obj_id);
1277  if($this->wsp_access_handler->checkAccess("visible", "", $node_id))
1278  {
1279  $path = $this->wsp_tree->getPathFull($node_id);
1280  if($path)
1281  {
1282  $item = array_pop($path);
1283  $parent = array_pop($path);
1284 
1285  if(!$parent["title"])
1286  {
1287  $parent["title"] = $this->lng->txt("wsp_personal_workspace");
1288  }
1289 
1290  // sub-objects
1291  $additional = null;
1292  if($a_obj_id)
1293  {
1294  $sub_title = $this->getSubObjectTitle($a_rep_obj_id, $a_obj_id);
1295  if($sub_title)
1296  {
1297  $item["title"] .= " (".$sub_title.")";
1298  $additional = "_".$a_obj_id;
1299  }
1300  }
1301 
1302  $link = ilWorkspaceAccessHandler::getGotoLink($node_id, $a_rep_obj_id, $additional);
1303  }
1304  // shared resource
1305  else
1306  {
1307  $owner = ilObject::_lookupOwner($a_rep_obj_id);
1308  $parent["title"] = $this->lng->txt("wsp_tab_shared").
1309  " (".ilObject::_lookupOwnerName($owner).")";
1310  $item["title"] = ilObject::_lookupTitle($a_rep_obj_id);
1311  $link = "ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=".
1312  $owner;
1313  }
1314 
1315  // container and object link
1316  if ($this->export_html || $this->print)
1317  {
1318  $tpl->setCurrentBlock("exp_target_object");
1319  }
1320  else
1321  {
1322  $tpl->setCurrentBlock("target_object");
1323  $tpl->setVariable("LINK_TARGET", $link);
1324  }
1325 
1326 
1327  // :TODO: no images in template ?
1328 
1329  $tpl->setVariable("TXT_CONTAINER", $parent["title"]);
1330  $tpl->setVariable("IMG_CONTAINER",
1331  ilObject::_getIcon($parent["obj_id"], "tiny"));
1332 
1333  $tpl->setVariable("TXT_TARGET", $item["title"]);
1334  $tpl->setVariable("IMG_TARGET",
1335  ilObject::_getIcon($a_rep_obj_id, "tiny"));
1336 
1337  $tpl->parseCurrentBlock();
1338  }
1339  }
1340  }
1341  }
1342  }
1343 
1347  function addNoteForm($a_init_form = true)
1348  {
1349  global $ilUser;
1350 
1351  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1352  ? "private"
1353  : "public";
1354  $ilUser->setPref("notes_".$suffix, "y");
1355 
1356  $this->add_note_form = true;
1357  return $this->getNotesHTML($a_init_form);
1358  }
1359 
1363  function cancelAddNote()
1364  {
1365  return $this->getNotesHTML();
1366  }
1367 
1371  function cancelUpdateNote()
1372  {
1373  return $this->getNotesHTML();
1374  }
1375 
1379  function addNote()
1380  {
1381  global $ilUser, $lng, $ilCtrl;
1382 
1383  $this->initNoteForm("create", $_GET["note_type"]);
1384 
1385  //if ($this->form->checkInput())
1386  if ($_POST["note"] != "")
1387  {
1388  $note = new ilNote();
1389  $note->setObject($this->obj_type, $this->rep_obj_id, $this->obj_id);
1390  $note->setInRepository($this->repository_mode);
1391  $note->setType($_GET["note_type"]);
1392  $note->setAuthor($ilUser->getId());
1393  $note->setText(ilUtil::stripslashes($_POST["note"]));
1394 // $note->setSubject($_POST["sub_note"]);
1395 // $note->setLabel($_POST["note_label"]);
1396  $note->create();
1397 
1398  $this->notifyObserver("new", $note);
1399 
1400  $ilCtrl->setParameter($this, "note_mess", "mod");
1401 // $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1402  }
1403  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1404 // $this->note_mess = "frmfld";
1405 // $this->form->setValuesByPost();
1406 // return $this->addNoteForm(false);;
1407  }
1408 
1412  function updateNote()
1413  {
1414  global $ilUser, $lng, $ilCtrl;
1415 
1416  $note = new ilNote(ilUtil::stripSlashes($_POST["note_id"]));
1417  $this->initNoteForm("edit", $note->getType(),
1418  $note);
1419 
1420 // if ($this->form->checkInput())
1421 // if ($_POST["note"] != "")
1422 // {
1423  $note->setText(ilUtil::stripSlashes($_POST["note"]));
1424  $note->setSubject(ilUtil::stripSlashes($_POST["sub_note"]));
1425  $note->setLabel(ilUtil::stripSlashes($_POST["note_label"]));
1426  if ($this->checkEdit($note))
1427  {
1428  $note->update();
1429 
1430  $this->notifyObserver("update", $note);
1431 
1432  $ilCtrl->setParameter($this, "note_mess", "mod");
1433  }
1434  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1435 // }
1436 $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1437  $this->note_mess = "frmfld";
1438  $this->form->setValuesByPost();
1439  $_GET["note_id"] = $note->getId();
1440  $_GET["note_type"] = $note->getType();
1441  return $this->editNoteForm(false);
1442  }
1443 
1447  function editNoteForm($a_init_form = true)
1448  {
1449  $this->edit_note_form = true;
1450 
1451  return $this->getNotesHTML($a_init_form);
1452  }
1453 
1457  function deleteNote()
1458  {
1459  $this->delete_note = true;
1460  $this->note_mess = "qdel";
1461  return $this->getNotesHTML();
1462  }
1463 
1467  function deleteNotes()
1468  {
1469  global $lng;
1470 
1471  if (!$_POST["note"])
1472  {
1473  $this->note_mess = "noc";
1474  }
1475  else
1476  {
1477  $this->delete_note = true;
1478  $this->note_mess = "qdel";
1479  }
1480 
1481  return $this->getNotesHTML();
1482  }
1483 
1487  function cancelDelete()
1488  {
1489  return $this->getNotesHTML();
1490  }
1491 
1495  function confirmDelete()
1496  {
1497  global $ilCtrl, $lng, $ilUser;
1498 
1499  $cnt = 0;
1500  foreach($_POST["note"] as $id)
1501  {
1502  $note = new ilNote($id);
1503  if ($this->checkDeletion($note))
1504  {
1505  $note->delete();
1506  $cnt++;
1507  }
1508  }
1509  if ($cnt > 1)
1510  {
1511  $ilCtrl->setParameter($this, "note_mess", "ntsdel");
1512  }
1513  else
1514  {
1515  $ilCtrl->setParameter($this, "note_mess", "ntdel");
1516  }
1517  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1518  }
1519 
1523  function exportNotesHTML()
1524  {
1525  $tpl = new ilTemplate("tpl.main.html", true, true);
1526 
1527  $this->export_html = true;
1528  $this->multi_selection = false;
1529  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1530  ilUtil::deliverData($tpl->get(), "notes.html");
1531  }
1532 
1536  function printNotes()
1537  {
1538  $tpl = new ilTemplate("tpl.main.html", true, true);
1539 
1540  $this->print = true;
1541  $this->multi_selection = false;
1542  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1543  echo $tpl->get(); exit;
1544  }
1545 
1549  function showNotes()
1550  {
1551  global $ilUser;
1552 
1553  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1554  ? "private"
1555  : "public";
1556  $ilUser->writePref("notes_".$suffix, "y");
1557 
1558  return $this->getNotesHTML();
1559  }
1560 
1564  function hideNotes()
1565  {
1566  global $ilUser;
1567 
1568  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1569  ? "private"
1570  : "public";
1571  $ilUser->writePref("notes_".$suffix, "n");
1572 
1573  return $this->getNotesHTML();
1574  }
1575 
1580  {
1581  global $ilUser;
1582 
1583  $ilUser->writePref("notes_pub_all", "y");
1584 
1585  return $this->getNotesHTML();
1586  }
1587 
1592  {
1593  global $ilUser;
1594 
1595  $ilUser->writePref("notes_pub_all", "n");
1596 
1597  return $this->getNotesHTML();
1598  }
1599 
1603  function initJavascript($a_ajax_url)
1604  {
1605  global $tpl;
1606 
1607  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1609  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1611  $tpl->addJavascript("./Services/Notes/js/ilNotes.js");
1612 
1613  $tpl->addOnLoadCode("ilNotes.setAjaxUrl('".$a_ajax_url."');");
1614  }
1615 
1623  function getListNotesJSCall($a_hash, $a_update_code = null)
1624  {
1625  if ($a_update_code === null)
1626  {
1627  $a_update_code = "null";
1628  }
1629  else
1630  {
1631  $a_update_code = "'".$a_update_code."'";
1632  }
1633 
1634  return "ilNotes.listNotes(event, '".$a_hash."', ".$a_update_code.");";
1635  }
1636 
1644  function getListCommentsJSCall($a_hash, $a_update_code = null)
1645  {
1646  if ($a_update_code === null)
1647  {
1648  $a_update_code = "null";
1649  }
1650  else
1651  {
1652  $a_update_code = "'".$a_update_code."'";
1653  }
1654 
1655  return "ilNotes.listComments(event, '".$a_hash."', ".$a_update_code.");";
1656  }
1657 
1667  protected static function buildAjaxHash($a_node_type, $a_node_id, $a_sub_id, $a_sub_type)
1668  {
1669  return $a_node_type.";".$a_node_id.";".$a_sub_id.";".$a_sub_type;
1670  }
1671 
1675  function renderLink($a_tpl, $a_var, $a_txt, $a_cmd, $a_anchor = "")
1676  {
1677  global $ilCtrl;
1678 
1679  $low_var = strtolower($a_var);
1680  $up_var = strtoupper($a_var);
1681 
1682  if ($this->ajax)
1683  {
1684  $a_tpl->setVariable("LINK_".$up_var, "#");
1685  $oc = "onclick = \"ilNotes.cmdAjaxLink(event, '".
1686  $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, "", true).
1687  "');\"";
1688  $a_tpl->setVariable("ON_CLICK_".$up_var, $oc);
1689  }
1690  else
1691  {
1692  $a_tpl->setVariable("LINK_".$up_var,
1693  $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, $a_anchor));
1694  }
1695 
1696  $a_tpl->setCurrentBlock($low_var);
1697  $a_tpl->setVariable("TXT_".$up_var, $a_txt);
1698  $a_tpl->parseCurrentBlock();
1699  }
1700 
1706  function addObserver($a_callback)
1707  {
1708  $this->observer[] = $a_callback;
1709  }
1710 
1717  protected function notifyObserver($a_action, $a_note)
1718  {
1719  if(sizeof($this->observer))
1720  {
1721  foreach($this->observer as $item)
1722  {
1723  $param = $a_note->getObject();
1724  $param["action"] = $a_action;
1725  $param["note_id"] = $a_note->getId();
1726 
1727  call_user_func_array($item, $param);
1728  }
1729  }
1730  }
1731 
1732  protected function listSortAsc()
1733  {
1734  $_SESSION["comments_sort_asc"] = 1;
1735  return $this->getNotesHtml();
1736  }
1737 
1738  protected function listSortDesc()
1739  {
1740  $_SESSION["comments_sort_asc"] = 0;
1741  return $this->getNotesHtml();
1742  }
1743 }
1744 
1745 ?>