ILIAS  Release_4_4_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.png"),
81  "alt" => $lng->txt("note")),
82  IL_NOTE_IMPORTANT => array(
83  "img" => ilUtil::getImagePath("note_important.png"),
84  "alt" => $lng->txt("note").", ".$lng->txt("important")),
85  IL_NOTE_QUESTION => array(
86  "img" => ilUtil::getImagePath("note_question.png"),
87  "alt" => $lng->txt("note").", ".$lng->txt("question")),
88  IL_NOTE_PRO => array(
89  "img" => ilUtil::getImagePath("note_pro.png"),
90  "alt" => $lng->txt("note").", ".$lng->txt("pro")),
91  IL_NOTE_CONTRA => array(
92  "img" => ilUtil::getImagePath("note_contra.png"),
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.png"),
99  "alt" => $lng->txt("notes_comment")),
100  IL_NOTE_IMPORTANT => array(
101  "img" => ilUtil::getImagePath("comment_important.png"),
102  "alt" => $lng->txt("notes_comment").", ".$lng->txt("important")),
103  IL_NOTE_QUESTION => array(
104  "img" => ilUtil::getImagePath("comment_question.png"),
105  "alt" => $lng->txt("notes_comment").", ".$lng->txt("question")),
106  IL_NOTE_PRO => array(
107  "img" => ilUtil::getImagePath("comment_pro.png"),
108  "alt" => $lng->txt("notes_comment").", ".$lng->txt("pro")),
109  IL_NOTE_CONTRA => array(
110  "img" => ilUtil::getImagePath("comment_contra.png"),
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;
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  $comments_col = false;
289  if ($this->public_enabled && (!$this->delete_note || $this->public_deletion_enabled)
290  && !$hide_comments /* && $ilUser->getId() != ANONYMOUS_USER_ID */)
291  {
292  $ntpl->setVariable("COMMENTS", $this->getNoteListHTML(IL_NOTE_PUBLIC, $a_init_form));
293  $comments_col = true;
294  }
295 
296  // Comments Settings
297  if ($this->comments_settings && !$hide_comments && !$this->delete_note
298  && !$this->edit_note_form && !$this->add_note_form && $ilUser->getId() != ANONYMOUS_USER_ID)
299  {
300  $notes_settings = new ilSetting("notes");
301  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
302  //$active = $notes_settings->get("activate_".$id);
303  $active = ilNote::commentsActivated($this->rep_obj_id, $this->obj_id, $this->obj_type);
304 
305  if ($active)
306  {
307  $this->renderLink($ntpl, "comments_settings", $lng->txt("notes_deactivate_comments"),
308  "deactivateComments", "notes_top");
309  $ntpl->setCurrentBlock("comments_settings2");
310  }
311  else
312  {
313  $this->renderLink($ntpl, "comments_settings", $lng->txt("notes_activate_comments"),
314  "activateComments", "notes_top");
315  $ntpl->setCurrentBlock("comments_settings2");
316 
317  if ($this->ajax && !$comments_col)
318  {
319  $ntpl->setVariable("COMMENTS_MESS",
320  $ntpl->getMessageHTML($lng->txt("comments_feature_currently_not_activated_for_object"), "info"));
321  }
322  }
323  $ntpl->parseCurrentBlock();
324 
325  if (!$comments_col)
326  {
327  $ntpl->setVariable("COMMENTS", "");
328  }
329 
330  $comments_col = true;
331  }
332 
333  if ($comments_col)
334  {
335  $ntpl->setCurrentBlock("comments_col");
336  if ($nodes_col)
337  {
338 // $ntpl->touchBlock("comments_style");
339  }
340  $ntpl->parseCurrentBlock();
341  }
342 
343  if ($this->ajax)
344  {
345  echo $ntpl->get();
346  exit;
347  }
348 
349  return $ntpl->get();
350  }
351 
355  function activateComments()
356  {
357  global $ilCtrl;
358 
359  $notes_settings = new ilSetting("notes");
360 
361  if ($this->comments_settings)
362  {
363  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
364  //$notes_settings->set("activate_".$id, 1);
365  ilNote::activateComments($this->rep_obj_id, $this->obj_id, $this->obj_type, true);
366  }
367 
368  $ilCtrl->redirectByClass("ilnotegui", "showNotes", "", $this->ajax);
369 // $ilCtrl->redirectByClass("ilnotegui", "getNotesHtml", "", $this->ajax);
370  }
371 
376  {
377  global $ilCtrl;
378 
379  $notes_settings = new ilSetting("notes");
380 
381  if ($this->comments_settings)
382  {
383  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
384  //$notes_settings->set("activate_".$id, 0);
385  ilNote::activateComments($this->rep_obj_id, $this->obj_id, $this->obj_type, false);
386  }
387 
388  $ilCtrl->redirectByClass("ilnotegui", "showNotes", "", $this->ajax);
389  //$ilCtrl->redirectByClass("ilnotegui", "getNotesHtml", "", $this->ajax);
390  }
391 
395  function getNoteListHTML($a_type = IL_NOTE_PRIVATE, $a_init_form = true)
396  {
397  global $lng, $ilCtrl, $ilUser;
398 
399  include_once("./Services/User/classes/class.ilUserUtil.php");
400 
401  $suffix = ($a_type == IL_NOTE_PRIVATE)
402  ? "private"
403  : "public";
404 
405  /* user settings are deprecated
406  $user_setting_notes_public_all = $ilUser->getPref("notes_pub_all");
407  $user_setting_notes_by_type = $ilUser->getPref("notes_".$suffix);
408  */
409  $user_setting_notes_public_all = "y";
410  $user_setting_notes_by_type = "y";
411 
412  if ($this->delete_note || $this->export_html || $this->print)
413  {
414  if ($_GET["note_id"] != "")
415  {
416  $filter = $_GET["note_id"];
417  }
418  else
419  {
420  $filter = $_POST["note"];
421  }
422  }
423  $notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
424  $this->obj_type, $a_type, $this->inc_sub, $filter,
425  $user_setting_notes_public_all, $this->repository_mode);
426  $all_notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
427  $this->obj_type, $a_type, $this->inc_sub, $filter,
428  "", $this->repository_mode);
429 
430  $tpl = new ilTemplate("tpl.notes_list.html", true, true, "Services/Notes");
431 
432  // show counter if notes are hidden
433  $cnt_str = (count($all_notes) > 0)
434  ? " (".count($all_notes).")"
435  : "";
436 
437  if (!$this->export_html)
438  {
439  $tpl->setCurrentBlock("notes_img");
440  if ($a_type == IL_NOTE_PUBLIC)
441  {
442  $tpl->setVariable("IMG_NOTES", ilUtil::getImagePath("icon_comment.png"));
443  $tpl->setVariable("ALT_NOTES", $lng->txt("icon")." ".$lng->txt("notes_public_comments"));
444  }
445  else
446  {
447  $tpl->setVariable("IMG_NOTES", ilUtil::getImagePath("icon_note.png"));
448  $tpl->setVariable("ALT_NOTES", $lng->txt("icon")." ".$lng->txt("private_notes"));
449  }
450  $tpl->parseCurrentBlock();
451  }
452 
453  // title
454  if ($this->ajax)
455  {
456  switch($this->obj_type)
457  {
458  case "catr":
459  case "crsr":
460  include_once "Services/ContainerReference/classes/class.ilContainerReference.php";
461  $title = ilContainerReference::_lookupTitle($this->rep_obj_id);
462  break;
463 
464  default:
465  $title = ilObject::_lookupTitle($this->rep_obj_id);
466  break;
467  }
468 
469  $img = ilUtil::img(ilObject::_getIcon($this->rep_obj_id, "tiny"));
470 
471  // add sub-object if given
472  if($this->obj_id)
473  {
474  $sub_title = $this->getSubObjectTitle($this->rep_obj_id, $this->obj_id);
475  if($sub_title)
476  {
477  $title .= " - ".$sub_title;
478  }
479  }
480 
481  $tpl->setCurrentBlock("title");
482  $tpl->setVariable("TITLE", $img." ".$title);
483  $tpl->parseCurrentBlock();
484  }
485 
486  if ($this->delete_note)
487  {
488  $cnt_str = "";
489  }
490  if ($a_type == IL_NOTE_PRIVATE)
491  {
492  $tpl->setVariable("TXT_NOTES", $lng->txt("private_notes").$cnt_str);
493  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PRIVATE);
494  }
495  else
496  {
497  $tpl->setVariable("TXT_NOTES", $lng->txt("notes_public_comments").$cnt_str);
498  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PUBLIC);
499  }
500  $anch = $this->anchor_jump
501  ? "notes_top"
502  : "";
503  $tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this, "getNotesHTML", $anch));
504  if ($this->ajax)
505  {
506  $os = "onsubmit = \"ilNotes.cmdAjaxForm(event, '".
507  $ilCtrl->getFormActionByClass("ilnotegui", "", "", true).
508  "'); return false;\"";
509  $tpl->setVariable("ON_SUBMIT_FORM", $os);
510  $tpl->setVariable("FORM_ID", "Ajax");
511  }
512 
513  if ($this->export_html || $this->print)
514  {
515  $tpl->touchBlock("print_style");
516  }
517 
518  // show add new note button
519  if (!$this->add_note_form && !$this->edit_note_form && !$this->delete_note &&
520  !$this->export_html && !$this->print && $ilUser->getId() != ANONYMOUS_USER_ID)
521  {
522  if (!$this->inc_sub) // we cannot offer add button if aggregated notes
523  { // are displayed
524  if ($this->rep_obj_id > 0 || $a_type != IL_NOTE_PUBLIC)
525  {
526  $tpl->setCurrentBlock("add_note_btn");
527  if ($a_type == IL_NOTE_PUBLIC)
528  {
529  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("notes_add_comment"));
530  }
531  else
532  {
533  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("add_note"));
534  }
535  $tpl->setVariable("LINK_ADD_NOTE", $ilCtrl->getLinkTargetByClass("ilnotegui", "addNoteForm").
536  "#note_edit");
537  $tpl->parseCurrentBlock();
538  }
539  }
540  }
541 
542  // show show/hide button for note list
543  if (count($all_notes) > 0 && $this->enable_hiding && !$this->delete_note
544  && !$this->export_html && !$this->print && !$this->edit_note_form
545  && !$this->add_note_form)
546  {
547  if ($user_setting_notes_by_type == "n")
548  {
549  if ($a_type == IL_NOTE_PUBLIC)
550  {
551  $txt = $lng->txt("notes_show_comments");
552  }
553  else
554  {
555  $txt = $lng->txt("show_".$suffix."_notes");
556  }
557  $this->renderLink($tpl, "show_notes", $txt, "showNotes", "notes_top");
558  }
559  else
560  {
561  // never individually hide for anonymous users
562  if (($ilUser->getId() != ANONYMOUS_USER_ID))
563  {
564  if ($a_type == IL_NOTE_PUBLIC)
565  {
566  $txt = $lng->txt("notes_hide_comments");
567  }
568  else
569  {
570  $txt = $lng->txt("hide_".$suffix."_notes");
571  }
572  $this->renderLink($tpl, "hide_notes", $txt, "hideNotes", "notes_top");
573 
574  // show all public notes / my notes only switch
575  if ($a_type == IL_NOTE_PUBLIC)
576  {
577  if ($user_setting_notes_public_all == "n")
578  {
579  $this->renderLink($tpl, "all_pub_notes", $lng->txt("notes_all_comments"),
580  "showAllPublicNotes", "notes_top");
581  }
582  else
583  {
584  $this->renderLink($tpl, "my_pub_notes", $lng->txt("notes_my_comments"),
585  "showMyPublicNotes", "notes_top");
586  }
587  }
588  }
589  }
590  }
591 
592  // show add new note text area
593  if (!$this->edit_note_form && $user_setting_notes_by_type != "n" &&
594  !$this->delete_note && $ilUser->getId() != ANONYMOUS_USER_ID)
595  {
596  if ($a_init_form)
597  {
598  $this->initNoteForm("create", $a_type);
599  }
600 
601  $tpl->setCurrentBlock("edit_note_form");
602 // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
603  $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
604  $tpl->parseCurrentBlock();
605 
606  $tpl->parseCurrentBlock();
607  $tpl->setCurrentBlock("note_row");
608  $tpl->parseCurrentBlock();
609  }
610 
611  // list all notes
612  if ($user_setting_notes_by_type != "n" || !$this->enable_hiding)
613  {
616 
617  $notes_given = false;
618  foreach($notes as $note)
619  {
620  if ($this->edit_note_form && ($note->getId() == $_GET["note_id"])
621  && $a_type == $_GET["note_type"])
622  {
623  if ($a_init_form)
624  {
625  $this->initNoteForm("edit", $a_type, $note);
626  }
627  $tpl->setCurrentBlock("edit_note_form");
628 // $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
629  $tpl->setVariable("EDIT_FORM", $this->form_tpl->get());
630  $tpl->parseCurrentBlock();
631  }
632  else
633  {
634  $cnt_col = 2;
635 
636  // delete note stuff for all private notes
637  if ($this->checkDeletion($note)
638  && !$this->delete_note
639  && !$this->export_html && !$this->print
640  && !$this->edit_note_form && !$this->add_note_form)
641  {
642  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
643  $this->renderLink($tpl, "delete_note", $lng->txt("delete"),
644  "deleteNote", "note_".$note->getId());
645  }
646 
647  // checkboxes in multiselection mode
648  if ($this->multi_selection && !$this->delete_note)
649  {
650  $tpl->setCurrentBlock("checkbox_col");
651  $tpl->setVariable("CHK_NOTE", "note[]");
652  $tpl->setVariable("CHK_NOTE_ID", $note->getId());
653  $tpl->parseCurrentBlock();
654  $cnt_col = 1;
655  }
656 
657  // edit note stuff for all private notes
658  if ($this->checkEdit($note))
659  {
660 
661  if (!$this->delete_note && !$this->export_html && !$this->print
662  && !$this->edit_note_form && !$this->add_note_form)
663  {
664  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
665  $this->renderLink($tpl, "edit_note", $lng->txt("edit"),
666  "editNoteForm", "note_edit");
667  }
668  }
669 
670  $tpl->setVariable("CNT_COL", $cnt_col);
671 
672  // output author account
673  if ($a_type == IL_NOTE_PUBLIC && ilObject::_exists($note->getAuthor()))
674  {
675  //$tpl->setCurrentBlock("author");
676  //$tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin($note->getAuthor()));
677  //$tpl->parseCurrentBlock();
678  $tpl->setCurrentBlock("user_img");
679  $tpl->setVariable("USR_IMG",
680  ilObjUser::_getPersonalPicturePath($note->getAuthor(), "xxsmall"));
681  $tpl->setVariable("USR_ALT", $lng->txt("user_image").": ".
682  ilObjUser::_lookupLogin($note->getAuthor()));
683  $tpl->parseCurrentBlock();
684  $tpl->setVariable("TXT_USR",
685  ilUserUtil::getNamePresentation($note->getAuthor(), false, false)." - ");
686  }
687 
688  // last edited
689  if ($note->getUpdateDate() != null)
690  {
691  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
692  $tpl->setVariable("DATE_LAST_EDIT",
693  ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME)));
694  }
695  else
696  {
697  $tpl->setVariable("VAL_DATE",
698  ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME)));
699  }
700 
701  // hidden note ids for deletion
702  if ($this->delete_note)
703  {
704  $tpl->setCurrentBlock("delete_ids");
705  $tpl->setVariable("HID_NOTE", "note[]");
706  $tpl->setVariable("HID_NOTE_ID", $note->getId());
707  $tpl->parseCurrentBlock();
708  }
709  $target = $note->getObject();
710 
711  // target objects
712  $this->showTargets($tpl, $this->rep_obj_id, $note->getId(),
713  $target["obj_type"], $target["obj_id"]);
714 
715  $rowclass = ($rowclass != "tblrow1")
716  ? "tblrow1"
717  : "tblrow2";
718  if (!$this->export_html && !$this->print)
719  {
720  $tpl->setCurrentBlock("note_img");
721  if ($a_type == IL_NOTE_PUBLIC)
722  {
723  $tpl->setVariable("IMG_NOTE", $this->comment_img[$note->getLabel()]["img"]);
724  $tpl->setVariable("ALT_NOTE", $this->comment_img[$note->getLabel()]["alt"]);
725  }
726  else
727  {
728  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
729  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
730  }
731  $tpl->parseCurrentBlock();
732  }
733  else
734  {
735  switch ($note->getLabel())
736  {
737  case IL_NOTE_UNLABELED:
738  $tpl->setVariable("EXP_ICON", "[&nbsp;]");
739  break;
740 
741  case IL_NOTE_IMPORTANT:
742  $tpl->setVariable("EXP_ICON", "[!]");
743  break;
744 
745  case IL_NOTE_QUESTION:
746  $tpl->setVariable("EXP_ICON", "[?]");
747  break;
748 
749  case IL_NOTE_PRO:
750  $tpl->setVariable("EXP_ICON", "[+]");
751  break;
752 
753  case IL_NOTE_CONTRA:
754  $tpl->setVariable("EXP_ICON", "[-]");
755  break;
756  }
757  }
758  $tpl->setCurrentBlock("note");
759  $tpl->setVariable("ROWCLASS", $rowclass);
760  $text = (trim($note->getText()) != "")
761  ? nl2br($note->getText())
762  : "<p class='subtitle'>".$lng->txt("note_content_removed")."</p>";
763  $tpl->setVariable("NOTE_TEXT", $text);
764  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
765  $tpl->setVariable("NOTE_ID", $note->getId());
766  $tpl->setVariable("CLASS", $a_type == IL_NOTE_PUBLIC
767  ? "ilComment"
768  : "ilNote");
769  $tpl->parseCurrentBlock();
770  }
771  $tpl->setCurrentBlock("note_row");
772  $tpl->parseCurrentBlock();
773  $notes_given = true;
774  }
775 
776  if (!$notes_given)
777  {
778  $tpl->setCurrentBlock("no_notes");
779  if ($a_type == IL_NOTE_PUBLIC)
780  {
781  $tpl->setVariable("NO_NOTES", $lng->txt("notes_no_comments"));
782  }
783 /* else
784  {
785  $tpl->setVariable("NO_NOTES", $lng->txt("notes_no_notes"));
786  }*/
787  $tpl->parseCurrentBlock();
788  }
789 
791 
792  // multiple items commands
793  if ($this->multi_selection && !$this->delete_note && !$this->edit_note_form
794  && count($notes) > 0)
795  {
796  if ($a_type == IL_NOTE_PRIVATE)
797  {
798  $tpl->setCurrentBlock("delete_cmd");
799  $tpl->setVariable("TXT_DELETE_NOTES", $this->lng->txt("delete"));
800  $tpl->parseCurrentBlock();
801  }
802 
803  $tpl->setCurrentBlock("multiple_commands");
804  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
805  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
806  $tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
807  $tpl->setVariable("TXT_PRINT_NOTES", $this->lng->txt("print"));
808  $tpl->setVariable("TXT_EXPORT_NOTES", $this->lng->txt("exp_html"));
809  $tpl->parseCurrentBlock();
810  }
811 
812  // delete / cancel row
813  if ($this->delete_note)
814  {
815  $tpl->setCurrentBlock("delete_cancel");
816  $tpl->setVariable("TXT_DEL_NOTES", $this->lng->txt("delete"));
817  $tpl->setVariable("TXT_CANCEL_DEL_NOTES", $this->lng->txt("cancel"));
818  $tpl->parseCurrentBlock();
819  }
820 
821  // print
822  if ($this->print)
823  {
824  $tpl->touchBlock("print_js");
825  $tpl->setCurrentBlock("print_back");
826  $tpl->setVariable("LINK_BACK", $this->ctrl->getLinkTarget($this, "showNotes"));
827  $tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
828  $tpl->parseCurrentBlock();
829  }
830  }
831 
832  // message
833  switch($_GET["note_mess"] != "" ? $_GET["note_mess"] : $this->note_mess)
834  {
835  case "mod":
836  $mtype = "success";
837  $mtxt = $lng->txt("msg_obj_modified");
838  break;
839 
840  case "ntsdel":
841  $mtype = "success";
842  $mtxt = $lng->txt("notes_notes_deleted");
843  break;
844 
845  case "ntdel":
846  $mtype = "success";
847  $mtxt = $lng->txt("notes_note_deleted");
848  break;
849 
850  case "frmfld":
851  $mtype = "failure";
852  $mtxt = $lng->txt("form_input_not_valid");
853  break;
854 
855  case "qdel":
856  $mtype = "question";
857  $mtxt = $lng->txt("info_delete_sure");
858  break;
859 
860  case "noc":
861  $mtype = "failure";
862  $mtxt = $lng->txt("no_checkbox");
863  break;
864  }
865  if ($mtxt != "")
866  {
867  $tpl->setVariable("MESS", $tpl->getMessageHTML($mtxt, $mtype));
868  }
869  else
870  {
871  $tpl->setVariable("MESS", "");
872  }
873 
874 
875 
876  if ($this->delete_note && count($notes) == 0)
877  {
878  return "";
879  }
880  else
881  {
882  return $tpl->get();
883  }
884  }
885 
893  protected function getSubObjectTitle($parent_obj_id, $sub_obj_id)
894  {
895  global $objDefinition, $ilCtrl;
896 
897  $parent_type = ilObject::_lookupType($parent_obj_id);
898  $parent_class = "ilObj".$objDefinition->getClassName($parent_type)."GUI";
899  $parent_path = $ilCtrl->lookupClassPath($parent_class);
900  include_once $parent_path;
901  if(method_exists($parent_class, "lookupSubObjectTitle"))
902  {
903  return call_user_func_array(array($parent_class, "lookupSubObjectTitle"), array($parent_obj_id, $sub_obj_id));
904  }
905  }
906 
910  function checkDeletion($a_note)
911  {
912  global $ilUser;
913 
914  if ($ilUser->getId() == ANONYMOUS_USER_ID)
915  {
916  return false;
917  }
918 
919  // delete note stuff for all private notes
920  if (($a_note->getType() == IL_NOTE_PRIVATE && $a_note->getAuthor() == $ilUser->getId()) ||
921  ($a_note->getType() == IL_NOTE_PUBLIC &&
923  )
924  {
925  return true;
926  }
927 
928  return false;
929  }
930 
934  function checkEdit($a_note)
935  {
936  global $ilUser;
937 
938  if ($a_note->getAuthor() == $ilUser->getId()
939  && ($ilUser->getId() != ANONYMOUS_USER_ID))
940  {
941  return true;
942  }
943  return false;
944  }
945 
946 
952  public function initNoteForm($a_mode = "edit", $a_type, $a_note = null)
953  {
954  global $lng, $ilCtrl;
955 
956  $this->form_tpl = new ilTemplate("tpl.notes_edit.html", true, true, "Services/Notes");
957  if ($a_note)
958  {
959  $this->form_tpl->setVariable("VAL_NOTE", ilUtil::prepareFormOutput($a_note->getText()));
960  $this->form_tpl->setVariable("NOTE_ID", $a_note->getId());
961  }
962 
963  if ($a_mode == "create")
964  {
965  $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
966  ? $lng->txt("note_add_comment")
967  : $lng->txt("note_add_note"));
968  $this->form_tpl->setVariable("CMD", "addNote");
969  }
970  else
971  {
972  $this->form_tpl->setVariable("TXT_CMD", ($a_type == IL_NOTE_PUBLIC)
973  ? $lng->txt("note_update_comment")
974  : $lng->txt("note_update_note"));
975  $this->form_tpl->setVariable("CMD", "updateNote");
976  }
977 
978 return;
979  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
980  $this->form = new ilPropertyFormGUI();
981  $this->form->setOpenTag(false);
982  $this->form->setCloseTag(false);
983  $this->form->setDisableStandardMessage(true);
984 
985  // subject
986 /* $ti = new ilTextInputGUI($this->lng->txt("subject"), "sub_note");
987  $ti->setRequired(true);
988  $ti->setMaxLength(200);
989  $ti->setSize(40);
990  if ($a_note)
991  {
992  $ti->setValue($a_note->getSubject());
993  }
994  $this->form->addItem($ti);*/
995 
996  // text
997 // $ta = new ilTextAreaInputGUI(($a_type == IL_NOTE_PUBLIC)
998 // ? $lng->txt("notes_comment")
999 // : $lng->txt("note"), "note");
1000  $ta = new ilTextAreaInputGUI("", "note");
1001  $ta->setCols(40);
1002  $ta->setRows(4);
1003  if ($a_note)
1004  {
1005  $ta->setValue($a_note->getText());
1006  }
1007  $this->form->addItem($ta);
1008 
1009  // label
1010 /* $options = array(
1011  IL_NOTE_UNLABELED => $lng->txt("unlabeled"),
1012  IL_NOTE_QUESTION => $lng->txt("question"),
1013  IL_NOTE_IMPORTANT => $lng->txt("important"),
1014  IL_NOTE_PRO => $lng->txt("pro"),
1015  IL_NOTE_CONTRA => $lng->txt("contra"),
1016  );
1017  $si = new ilSelectInputGUI($this->lng->txt("notes_label"), "note_label");
1018  $si->setOptions($options);
1019  if ($a_note)
1020  {
1021  $si->setValue($a_note->getLabel());
1022  }
1023  $this->form->addItem($si); */
1024 
1025  // hidden note id
1026  if ($a_note)
1027  {
1028  $hi = new ilHiddenInputGUI("note_id");
1029  $hi->setValue($_GET["note_id"]);
1030  $this->form->addItem($hi);
1031  }
1032 
1033  // save and cancel commands
1034  if ($a_mode == "create")
1035  {
1036  $this->form->addCommandButton("addNote", $lng->txt("save"));
1037 /* $this->form->addCommandButton("cancelAddNote", $lng->txt("cancel"));
1038  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1039  ? $lng->txt("notes_add_comment")
1040  : $lng->txt("notes_add_note"));*/
1041  }
1042  else
1043  {
1044  $this->form->addCommandButton("updateNote", $lng->txt("save"));
1045 /* $this->form->addCommandButton("cancelUpdateNote", $lng->txt("cancel"));
1046  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
1047  ? $lng->txt("notes_edit_comment")
1048  : $lng->txt("notes_edit_note"));*/
1049  }
1050 
1051  $ilCtrl->setParameter($this, "note_type", $a_type);
1052  $this->form->setFormAction($this->ctrl->getFormAction($this));
1053 
1054  }
1055 
1059  function getPDNoteHTML($note_id)
1060  {
1061  global $lng, $ilCtrl, $ilUser;
1062 
1063  $tpl = new ilTemplate("tpl.pd_note.html", true, true, "Services/Notes");
1064  $note = new ilNote($note_id);
1065  $target = $note->getObject();
1066 
1067  if ($note->getAuthor() != $ilUser->getId())
1068  {
1069  return;
1070  }
1071 
1072  $img = ilUtil::getImagePath("note_".$note->getLabel().".png");
1073  $alt = $lng->txt("note");
1074 
1075  $tpl->setCurrentBlock("edit_note");
1076  $ilCtrl->setParameterByClass("ilnotegui", "rel_obj", $target["rep_obj_id"]);
1077  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note_id);
1078  $ilCtrl->setParameterByClass("ilnotegui", "note_type", $note->getType());
1079  $tpl->setVariable("LINK_EDIT_NOTE",
1080  $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilpdnotesgui", "ilnotegui"),
1081  "editNoteForm"));
1082  $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
1083  $tpl->parseCurrentBlock();
1084  $ilCtrl->clearParametersByClass("ilnotegui");
1085 
1086  $tpl->setCurrentBlock("note_img");
1087  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
1088  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
1089  $tpl->parseCurrentBlock();
1090 
1091  // last edited
1092  if ($note->getUpdateDate() != null)
1093  {
1094  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
1095  $tpl->setVariable("DATE_LAST_EDIT",
1096  ilDatePresentation::formatDate(new ilDate($note->getUpdateDate(), IL_CAL_DATETIME)));
1097  }
1098  else
1099  {
1100  //$tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
1101  $tpl->setVariable("VAL_DATE",
1102  ilDatePresentation::formatDate(new ilDate($note->getCreationDate(), IL_CAL_DATETIME)));
1103  }
1104 
1105  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
1106  $text = (trim($note->getText()) != "")
1107  ? nl2br($note->getText())
1108  : "<p class='subtitle'>".$lng->txt("note_content_removed")."</p>";
1109  $tpl->setVariable("NOTE_TEXT", $text);
1110  $this->showTargets($tpl, $target["rep_obj_id"], $note_id, $target["obj_type"], $target["obj_id"]);
1111  return $tpl->get();
1112  }
1113 
1117  function showTargets(&$tpl, $a_rep_obj_id, $a_note_id, $a_obj_type, $a_obj_id)
1118  {
1119  global $tree, $ilAccess, $objDefinition, $ilUser;
1120 
1121  if ($this->targets_enabled)
1122  {
1123  if ($a_rep_obj_id > 0)
1124  {
1125  // get all visible references of target object
1126 
1127  // repository
1128  $ref_ids = ilObject::_getAllReferences($a_rep_obj_id);
1129  if($ref_ids)
1130  {
1131  $vis_ref_ids = array();
1132  foreach($ref_ids as $ref_id)
1133  {
1134  if ($ilAccess->checkAccess("visible", "", $ref_id))
1135  {
1136  $vis_ref_ids[] = $ref_id;
1137  }
1138  }
1139 
1140  // output links to targets
1141  if (count($vis_ref_ids) > 0)
1142  {
1143  foreach($vis_ref_ids as $vis_ref_id)
1144  {
1145  $type = ilObject::_lookupType($vis_ref_id, true);
1146  $sub_link = $sub_title = "";
1147  if ($type == "sahs") // bad hack, needs general procedure
1148  {
1149  $link = "goto.php?target=sahs_".$vis_ref_id;
1150  $title = ilObject::_lookupTitle($a_rep_obj_id);
1151  if ($a_obj_type == "sco" || $a_obj_type == "seqc" || $a_obj_type == "chap" || $a_obj_type == "pg")
1152  {
1153  $sub_link = "goto.php?target=sahs_".$vis_ref_id."_".$a_obj_id;
1154  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
1155  $sub_title = ilSCORM2004Node::_lookupTitle($a_obj_id);
1156  $sub_icon = ilUtil::getImagePath("icon_".$a_obj_type."_s.png");
1157  }
1158  }
1159  else if ($a_obj_type != "pg")
1160  {
1161  if (!is_object($this->item_list_gui[$type]))
1162  {
1163  $class = $objDefinition->getClassName($type);
1164  $location = $objDefinition->getLocation($type);
1165  $full_class = "ilObj".$class."ListGUI";
1166  include_once($location."/class.".$full_class.".php");
1167  $this->item_list_gui[$type] = new $full_class();
1168  }
1169 
1170  // for references, get original title
1171  // (link will lead to orignal, which basically is wrong though)
1172  if($a_obj_type == "crsr" || $a_obj_type == "catr")
1173  {
1174  include_once "Services/ContainerReference/classes/class.ilContainerReference.php";
1175  $tgt_obj_id = ilContainerReference::_lookupTargetId($a_rep_obj_id);
1176  $title = ilObject::_lookupTitle($tgt_obj_id);
1177  }
1178  else
1179  {
1180  $title = ilObject::_lookupTitle($a_rep_obj_id);
1181  }
1182  $this->item_list_gui[$type]->initItem($vis_ref_id, $a_rep_obj_id, $title);
1183  $link = $this->item_list_gui[$type]->getCommandLink("infoScreen");
1184 
1185  // workaround, because # anchor can't be passed through frameset
1186  $link = ilUtil::appendUrlParameterString($link, "anchor=note_".$a_note_id);
1187 
1188  $link = $this->item_list_gui[$type]->appendRepositoryFrameParameter($link)."#note_".$a_note_id;
1189  }
1190  else
1191  {
1192  $title = ilObject::_lookupTitle($a_rep_obj_id);
1193  $link = "goto.php?target=pg_".$a_obj_id."_".$vis_ref_id;
1194  }
1195 
1196  $par_id = $tree->getParentId($vis_ref_id);
1197 
1198  // sub object link
1199  if ($sub_link != "")
1200  {
1201  if ($this->export_html || $this->print)
1202  {
1203  $tpl->setCurrentBlock("exp_target_sub_object");
1204  }
1205  else
1206  {
1207  $tpl->setCurrentBlock("target_sub_object");
1208  $tpl->setVariable("LINK_SUB_TARGET", $sub_link);
1209  }
1210  $tpl->setVariable("TXT_SUB_TARGET", $sub_title);
1211  $tpl->setVariable("IMG_SUB_TARGET", $sub_icon);
1212  $tpl->parseCurrentBlock();
1213  }
1214 
1215  // container and object link
1216  if ($this->export_html || $this->print)
1217  {
1218  $tpl->setCurrentBlock("exp_target_object");
1219  }
1220  else
1221  {
1222  $tpl->setCurrentBlock("target_object");
1223  $tpl->setVariable("LINK_TARGET", $link);
1224  }
1225  $tpl->setVariable("TXT_CONTAINER",
1227  ilObject::_lookupObjId($par_id)));
1228  $tpl->setVariable("IMG_CONTAINER",
1230  ilObject::_lookupObjId($par_id), "tiny"));
1231  $tpl->setVariable("TXT_TARGET", $title);
1232  $tpl->setVariable("IMG_TARGET",
1233  ilObject::_getIcon($a_rep_obj_id, "tiny"));
1234 
1235  $tpl->parseCurrentBlock();
1236  }
1237  $tpl->touchBlock("target_objects");
1238  }
1239  }
1240  // personal workspace
1241  else
1242  {
1243  // we only need 1 instance
1244  if(!$this->wsp_tree)
1245  {
1246  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1247  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
1248  $this->wsp_tree = new ilWorkspaceTree($ilUser->getId());
1249  $this->wsp_access_handler = new ilWorkspaceAccessHandler($this->wsp_tree);
1250  }
1251  $node_id = $this->wsp_tree->lookupNodeId($a_rep_obj_id);
1252  if($this->wsp_access_handler->checkAccess("visible", "", $node_id))
1253  {
1254  $path = $this->wsp_tree->getPathFull($node_id);
1255  if($path)
1256  {
1257  $item = array_pop($path);
1258  $parent = array_pop($path);
1259 
1260  if(!$parent["title"])
1261  {
1262  $parent["title"] = $this->lng->txt("wsp_personal_workspace");
1263  }
1264 
1265  // sub-objects
1266  $additional = null;
1267  if($a_obj_id)
1268  {
1269  $sub_title = $this->getSubObjectTitle($a_rep_obj_id, $a_obj_id);
1270  if($sub_title)
1271  {
1272  $item["title"] .= " (".$sub_title.")";
1273  $additional = "_".$a_obj_id;
1274  }
1275  }
1276 
1277  $link = ilWorkspaceAccessHandler::getGotoLink($node_id, $a_rep_obj_id, $additional);
1278  }
1279  // shared resource
1280  else
1281  {
1282  $owner = ilObject::_lookupOwner($a_rep_obj_id);
1283  $parent["title"] = $this->lng->txt("wsp_tab_shared").
1284  " (".ilObject::_lookupOwnerName($owner).")";
1285  $item["title"] = ilObject::_lookupTitle($a_rep_obj_id);
1286  $link = "ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=".
1287  $owner;
1288  }
1289 
1290  // container and object link
1291  if ($this->export_html || $this->print)
1292  {
1293  $tpl->setCurrentBlock("exp_target_object");
1294  }
1295  else
1296  {
1297  $tpl->setCurrentBlock("target_object");
1298  $tpl->setVariable("LINK_TARGET", $link);
1299  }
1300 
1301 
1302  // :TODO: no images in template ?
1303 
1304  $tpl->setVariable("TXT_CONTAINER", $parent["title"]);
1305  $tpl->setVariable("IMG_CONTAINER",
1306  ilObject::_getIcon($parent["obj_id"], "tiny"));
1307 
1308  $tpl->setVariable("TXT_TARGET", $item["title"]);
1309  $tpl->setVariable("IMG_TARGET",
1310  ilObject::_getIcon($a_rep_obj_id, "tiny"));
1311 
1312  $tpl->parseCurrentBlock();
1313  }
1314  }
1315  }
1316  }
1317  }
1318 
1322  function addNoteForm($a_init_form = true)
1323  {
1324  global $ilUser;
1325 
1326  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1327  ? "private"
1328  : "public";
1329  $ilUser->setPref("notes_".$suffix, "y");
1330 
1331  $this->add_note_form = true;
1332  return $this->getNotesHTML($a_init_form);
1333  }
1334 
1338  function cancelAddNote()
1339  {
1340  return $this->getNotesHTML();
1341  }
1342 
1346  function cancelUpdateNote()
1347  {
1348  return $this->getNotesHTML();
1349  }
1350 
1354  function addNote()
1355  {
1356  global $ilUser, $lng, $ilCtrl;
1357 
1358  $this->initNoteForm("create", $_GET["note_type"]);
1359 
1360  //if ($this->form->checkInput())
1361  if ($_POST["note"] != "")
1362  {
1363  $note = new ilNote();
1364  $note->setObject($this->obj_type, $this->rep_obj_id, $this->obj_id);
1365  $note->setInRepository($this->repository_mode);
1366  $note->setType($_GET["note_type"]);
1367  $note->setAuthor($ilUser->getId());
1368  $note->setText(ilUtil::stripslashes($_POST["note"]));
1369 // $note->setSubject($_POST["sub_note"]);
1370 // $note->setLabel($_POST["note_label"]);
1371  $note->create();
1372 
1373  $this->notifyObserver("new", $note);
1374 
1375  $ilCtrl->setParameter($this, "note_mess", "mod");
1376 // $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1377  }
1378  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1379 // $this->note_mess = "frmfld";
1380 // $this->form->setValuesByPost();
1381 // return $this->addNoteForm(false);;
1382  }
1383 
1387  function updateNote()
1388  {
1389  global $ilUser, $lng, $ilCtrl;
1390 
1391  $note = new ilNote(ilUtil::stripSlashes($_POST["note_id"]));
1392  $this->initNoteForm("edit", $note->getType(),
1393  $note);
1394 
1395 // if ($this->form->checkInput())
1396 // if ($_POST["note"] != "")
1397 // {
1398  $note->setText(ilUtil::stripSlashes($_POST["note"]));
1399  $note->setSubject(ilUtil::stripSlashes($_POST["sub_note"]));
1400  $note->setLabel(ilUtil::stripSlashes($_POST["note_label"]));
1401  if ($this->checkEdit($note))
1402  {
1403  $note->update();
1404 
1405  $this->notifyObserver("update", $note);
1406 
1407  $ilCtrl->setParameter($this, "note_mess", "mod");
1408  }
1409  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1410 // }
1411 $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1412  $this->note_mess = "frmfld";
1413  $this->form->setValuesByPost();
1414  $_GET["note_id"] = $note->getId();
1415  $_GET["note_type"] = $note->getType();
1416  return $this->editNoteForm(false);
1417  }
1418 
1422  function editNoteForm($a_init_form = true)
1423  {
1424  $this->edit_note_form = true;
1425 
1426  return $this->getNotesHTML($a_init_form);
1427  }
1428 
1432  function deleteNote()
1433  {
1434  $this->delete_note = true;
1435  $this->note_mess = "qdel";
1436  return $this->getNotesHTML();
1437  }
1438 
1442  function deleteNotes()
1443  {
1444  global $lng;
1445 
1446  if (!$_POST["note"])
1447  {
1448  $this->note_mess = "noc";
1449  }
1450  else
1451  {
1452  $this->delete_note = true;
1453  $this->note_mess = "qdel";
1454  }
1455 
1456  return $this->getNotesHTML();
1457  }
1458 
1462  function cancelDelete()
1463  {
1464  return $this->getNotesHTML();
1465  }
1466 
1470  function confirmDelete()
1471  {
1472  global $ilCtrl, $lng, $ilUser;
1473 
1474  $cnt = 0;
1475  foreach($_POST["note"] as $id)
1476  {
1477  $note = new ilNote($id);
1478  if ($this->checkDeletion($note))
1479  {
1480  $note->delete();
1481  $cnt++;
1482  }
1483  }
1484  if ($cnt > 1)
1485  {
1486  $ilCtrl->setParameter($this, "note_mess", "ntsdel");
1487  }
1488  else
1489  {
1490  $ilCtrl->setParameter($this, "note_mess", "ntdel");
1491  }
1492  $ilCtrl->redirect($this, "showNotes", "notes_top", $this->ajax);
1493  }
1494 
1498  function exportNotesHTML()
1499  {
1500  $tpl = new ilTemplate("tpl.main.html", true, true);
1501 
1502  $this->export_html = true;
1503  $this->multi_selection = false;
1504  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1505  ilUtil::deliverData($tpl->get(), "notes.html");
1506  }
1507 
1511  function printNotes()
1512  {
1513  $tpl = new ilTemplate("tpl.main.html", true, true);
1514 
1515  $this->print = true;
1516  $this->multi_selection = false;
1517  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1518  echo $tpl->get(); exit;
1519  }
1520 
1524  function showNotes()
1525  {
1526  global $ilUser;
1527 
1528  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1529  ? "private"
1530  : "public";
1531  $ilUser->writePref("notes_".$suffix, "y");
1532 
1533  return $this->getNotesHTML();
1534  }
1535 
1539  function hideNotes()
1540  {
1541  global $ilUser;
1542 
1543  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1544  ? "private"
1545  : "public";
1546  $ilUser->writePref("notes_".$suffix, "n");
1547 
1548  return $this->getNotesHTML();
1549  }
1550 
1555  {
1556  global $ilUser;
1557 
1558  $ilUser->writePref("notes_pub_all", "y");
1559 
1560  return $this->getNotesHTML();
1561  }
1562 
1567  {
1568  global $ilUser;
1569 
1570  $ilUser->writePref("notes_pub_all", "n");
1571 
1572  return $this->getNotesHTML();
1573  }
1574 
1578  function initJavascript($a_ajax_url)
1579  {
1580  global $tpl;
1581 
1582  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1584  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1586  $tpl->addJavascript("./Services/Notes/js/ilNotes.js");
1587 
1588  $tpl->addOnLoadCode("ilNotes.setAjaxUrl('".$a_ajax_url."');");
1589  }
1590 
1598  function getListNotesJSCall($a_hash, $a_update_code = null)
1599  {
1600  if ($a_update_code === null)
1601  {
1602  $a_update_code = "null";
1603  }
1604  else
1605  {
1606  $a_update_code = "'".$a_update_code."'";
1607  }
1608 
1609  return "ilNotes.listNotes(event, '".$a_hash."', ".$a_update_code.");";
1610  }
1611 
1619  function getListCommentsJSCall($a_hash, $a_update_code = null)
1620  {
1621  if ($a_update_code === null)
1622  {
1623  $a_update_code = "null";
1624  }
1625  else
1626  {
1627  $a_update_code = "'".$a_update_code."'";
1628  }
1629 
1630  return "ilNotes.listComments(event, '".$a_hash."', ".$a_update_code.");";
1631  }
1632 
1642  protected static function buildAjaxHash($a_node_type, $a_node_id, $a_sub_id, $a_sub_type)
1643  {
1644  return $a_node_type.";".$a_node_id.";".$a_sub_id.";".$a_sub_type;
1645  }
1646 
1650  function renderLink($a_tpl, $a_var, $a_txt, $a_cmd, $a_anchor = "")
1651  {
1652  global $ilCtrl;
1653 
1654  $low_var = strtolower($a_var);
1655  $up_var = strtoupper($a_var);
1656 
1657  if ($this->ajax)
1658  {
1659  $a_tpl->setVariable("LINK_".$up_var, "#");
1660  $oc = "onclick = \"ilNotes.cmdAjaxLink(event, '".
1661  $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, "", true).
1662  "');\"";
1663  $a_tpl->setVariable("ON_CLICK_".$up_var, $oc);
1664  }
1665  else
1666  {
1667  $a_tpl->setVariable("LINK_".$up_var,
1668  $ilCtrl->getLinkTargetByClass("ilnotegui", $a_cmd, $a_anchor));
1669  }
1670 
1671  $a_tpl->setCurrentBlock($low_var);
1672  $a_tpl->setVariable("TXT_".$up_var, $a_txt);
1673  $a_tpl->parseCurrentBlock();
1674  }
1675 
1681  function addObserver($a_callback)
1682  {
1683  $this->observer[] = $a_callback;
1684  }
1685 
1692  protected function notifyObserver($a_action, $a_note)
1693  {
1694  if(sizeof($this->observer))
1695  {
1696  foreach($this->observer as $item)
1697  {
1698  $param = $a_note->getObject();
1699  $param["action"] = $a_action;
1700  $param["note_id"] = $a_note->getId();
1701 
1702  call_user_func_array($item, $param);
1703  }
1704  }
1705  }
1706 }
1707 
1708 ?>