ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNoteGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2005 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once ("Services/Notes/classes/class.ilNote.php");
25 
26 
36 class ilNoteGUI
37 {
39 
48  function ilNoteGUI($a_rep_obj_id = "", $a_obj_id = "", $a_obj_type = "", $a_include_subobjects = false)
49  {
50  global $ilCtrl, $lng;
51 
52  $lng->loadLanguageModule("notes");
53 
54  $this->rep_obj_id = $a_rep_obj_id;
55  $this->obj_id = $a_obj_id;
56  $this->obj_type = $a_obj_type;
57  $this->inc_sub = $a_include_subobjects;
58 
59  $this->ctrl =& $ilCtrl;
60  $this->lng =& $lng;
61 
62  $this->add_note_form = false;
63  $this->edit_note_form = false;
64  $this->private_enabled = false;
65  $notes_settings = new ilSetting("notes");
66  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
67  if ($notes_settings->get("activate_".$id))
68  {
69  $this->public_enabled = true;
70  }
71  else
72  {
73  $this->public_enabled = false;
74  }
75  $this->enable_hiding = true;
76  $this->targets_enabled = false;
77  $this->multi_selection = false;
78  $this->export_html = false;
79  $this->print = false;
80  $this->comments_settings = false;
81 
82  $this->note_img = array(
83  IL_NOTE_UNLABELED => array(
84  "img" => ilUtil::getImagePath("note_unlabeled.gif"),
85  "alt" => $lng->txt("note")),
86  IL_NOTE_IMPORTANT => array(
87  "img" => ilUtil::getImagePath("note_important.gif"),
88  "alt" => $lng->txt("note").", ".$lng->txt("important")),
89  IL_NOTE_QUESTION => array(
90  "img" => ilUtil::getImagePath("note_question.gif"),
91  "alt" => $lng->txt("note").", ".$lng->txt("question")),
92  IL_NOTE_PRO => array(
93  "img" => ilUtil::getImagePath("note_pro.gif"),
94  "alt" => $lng->txt("note").", ".$lng->txt("pro")),
95  IL_NOTE_CONTRA => array(
96  "img" => ilUtil::getImagePath("note_contra.gif"),
97  "alt" => $lng->txt("note").", ".$lng->txt("contra"))
98  );
99 
100  $this->comment_img = array(
101  IL_NOTE_UNLABELED => array(
102  "img" => ilUtil::getImagePath("comment_unlabeled.gif"),
103  "alt" => $lng->txt("notes_comment")),
104  IL_NOTE_IMPORTANT => array(
105  "img" => ilUtil::getImagePath("comment_important.gif"),
106  "alt" => $lng->txt("notes_comment").", ".$lng->txt("important")),
107  IL_NOTE_QUESTION => array(
108  "img" => ilUtil::getImagePath("comment_question.gif"),
109  "alt" => $lng->txt("notes_comment").", ".$lng->txt("question")),
110  IL_NOTE_PRO => array(
111  "img" => ilUtil::getImagePath("comment_pro.gif"),
112  "alt" => $lng->txt("notes_comment").", ".$lng->txt("pro")),
113  IL_NOTE_CONTRA => array(
114  "img" => ilUtil::getImagePath("comment_contra.gif"),
115  "alt" => $lng->txt("notes_comment").", ".$lng->txt("contra"))
116  );
117  }
118 
122  function &executeCommand()
123  {
124  $cmd = $this->ctrl->getCmd("getNotesHTML");
125  $next_class = $this->ctrl->getNextClass($this);
126 
127  switch($next_class)
128  {
129  default:
130  return $this->$cmd();
131  break;
132  }
133  }
134 
138  function enablePrivateNotes($a_enable = true)
139  {
140  $this->private_enabled = $a_enable;
141  }
142 
146  function enablePublicNotes($a_enable = true)
147  {
148  $this->public_enabled = $a_enable;
149  }
150 
154  function enableCommentsSettings($a_enable = true)
155  {
156  $this->comments_settings = $a_enable;
157  }
158 
162  function enablePublicNotesDeletion($a_enable = true)
163  {
164  $this->public_deletion_enabled = $a_enable;
165  }
166 
170  function enableHiding($a_enable = true)
171  {
172  $this->enable_hiding = $a_enable;
173  }
174 
178  function enableTargets($a_enable = true)
179  {
180  $this->targets_enabled = $a_enable;
181  }
182 
186  function enableMultiSelection($a_enable = true)
187  {
188  $this->multi_selection = $a_enable;
189  }
190 
191  /***
192  * get note lists html code
193  */
194  function getNotesHTML()
195  {
196  global $ilUser, $lng, $ilCtrl;
197 
198  $lng->loadLanguageModule("notes");
199 
200  $ntpl = new ilTemplate("tpl.notes_and_comments.html", true, true,
201  "Services/Notes");
202 
203  if ($this->private_enabled && ($ilUser->getId() != ANONYMOUS_USER_ID))
204  {
205  $ntpl->setVariable("NOTES", $this->getNoteListHTML(IL_NOTE_PRIVATE));
206  }
207 
208  $comments_col = false;
209  if ($this->public_enabled && (!$this->delete_note || $this->public_deletion_enabled))
210  {
211  $ntpl->setVariable("COMMENTS", $this->getNoteListHTML(IL_NOTE_PUBLIC));
212  $comments_col = true;
213  }
214 
215  // Comments Settings
216  if ($this->comments_settings)
217  {
218  $notes_settings = new ilSetting("notes");
219  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
220  $active = $notes_settings->get("activate_".$id);
221 
222  $ntpl->setCurrentBlock("comments_settings");
223  if ($active)
224  {
225  $ntpl->setVariable("TXT_COMMENTS_SETTINGS", $lng->txt("notes_deactivate_comments"));
226  $ntpl->setVariable("HREF_COMMENTS_SETTINGS",
227  $ilCtrl->getLinkTargetByClass("ilnotegui", "deactivateComments", "notes_top"));
228  }
229  else
230  {
231  $ntpl->setVariable("TXT_COMMENTS_SETTINGS", $lng->txt("notes_activate_comments"));
232  $ntpl->setVariable("HREF_COMMENTS_SETTINGS",
233  $ilCtrl->getLinkTargetByClass("ilnotegui", "activateComments", "notes_top"));
234  }
235  $ntpl->parseCurrentBlock();
236  $comments_col = true;
237  }
238 
239  if ($comments_col)
240  {
241  $ntpl->setCurrentBlock("comments_col");
242  $ntpl->parseCurrentBlock();
243  }
244 
245  return $ntpl->get();
246  }
247 
251  function activateComments()
252  {
253  global $ilCtrl;
254 
255  $notes_settings = new ilSetting("notes");
256 
257  if ($this->comments_settings)
258  {
259  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
260  $notes_settings->set("activate_".$id, 1);
261  }
262 
263  $ilCtrl->redirectByClass("ilnotegui", "getNotesHtml");
264  }
265 
270  {
271  global $ilCtrl;
272 
273  $notes_settings = new ilSetting("notes");
274 
275  if ($this->comments_settings)
276  {
277  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
278  $notes_settings->set("activate_".$id, 0);
279  }
280 
281  $ilCtrl->redirectByClass("ilnotegui", "getNotesHtml");
282  }
283 
287  function getNoteListHTML($a_type = IL_NOTE_PRIVATE)
288  {
289  global $lng, $ilCtrl, $ilUser, $ilAccess, $tree, $objDefinition;
290 
291  $suffix = ($a_type == IL_NOTE_PRIVATE)
292  ? "private"
293  : "public";
294 
295  if ($this->delete_note || $this->export_html || $this->print)
296  {
297  if ($_GET["note_id"] != "")
298  {
299  $filter = $_GET["note_id"];
300  }
301  else
302  {
303  $filter = $_POST["note"];
304  }
305  }
306 
307  $notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
308  $this->obj_type, $a_type, $this->inc_sub, $filter,
309  $ilUser->getPref("notes_pub_all"), $this->public_deletion_enabled);
310 
311  $all_notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
312  $this->obj_type, $a_type, $this->inc_sub, $filter,
313  "", $this->public_deletion_enabled);
314 
315  $tpl = new ilTemplate("tpl.notes_list.html", true, true, "Services/Notes");
316 
317  // show counter if notes are hidden
318  $cnt_str = (count($all_notes) > 0)
319  ? " (".count($all_notes).")"
320  : "";
321 
322  if ($a_type == IL_NOTE_PUBLIC)
323  {
324  $tpl->setVariable("IMG_NOTES", ilUtil::getImagePath("icon_comment.gif"));
325  }
326  else
327  {
328  $tpl->setVariable("IMG_NOTES", ilUtil::getImagePath("icon_note.gif"));
329  }
330  if ($this->delete_note)
331  {
332  $tpl->setVariable("TXT_NOTES", $lng->txt("info_delete_sure"));
333  }
334  else if ($a_type == IL_NOTE_PRIVATE)
335  {
336  $tpl->setVariable("TXT_NOTES", $lng->txt("private_notes").$cnt_str);
337  $tpl->setVariable("A_NAME", "notes_top");
338  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PRIVATE);
339  }
340  else
341  {
342  $tpl->setVariable("TXT_NOTES", $lng->txt("notes_public_comments").$cnt_str);
343  $tpl->setVariable("A_NAME", "comments_top");
344  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PUBLIC);
345  }
346  $tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this, "getNotesHTML", "notes_top"));
347 
348  if ($this->export_html || $this->print)
349  {
350  $tpl->touchBlock("print_style");
351  }
352 
353  // show add new note button
354  if (!$this->add_note_form && !$this->edit_note_form && !$this->delete_note &&
355  !$this->export_html && !$this->print &&
356  ($ilUser->getId() != ANONYMOUS_USER_ID))
357  {
358  if (!$this->inc_sub) // we cannot offer add button if aggregated notes
359  { // are displayed
360  $tpl->setCurrentBlock("add_note_btn");
361  if ($a_type == IL_NOTE_PUBLIC)
362  {
363  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("notes_add_comment"));
364  }
365  else
366  {
367  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("add_note"));
368  }
369  $tpl->setVariable("LINK_ADD_NOTE", $ilCtrl->getLinkTargetByClass("ilnotegui", "addNoteForm").
370  "#note_edit");
371  $tpl->parseCurrentBlock();
372  }
373  }
374 
375  // show show/hide button for note list
376  if (count($all_notes) > 0 && $this->enable_hiding && !$this->delete_note
377  && !$this->export_html && !$this->print)
378  {
379  if ($ilUser->getPref("notes_".$suffix) == "n")
380  {
381  $tpl->setCurrentBlock("show_notes");
382  $tpl->setVariable("LINK_SHOW_NOTES",
383  $this->ctrl->getLinkTargetByClass("ilnotegui", "showNotes", "notes_top"));
384  if ($a_type == IL_NOTE_PUBLIC)
385  {
386  $tpl->setVariable("TXT_SHOW_NOTES", $lng->txt("notes_show_comments"));
387  }
388  else
389  {
390  $tpl->setVariable("TXT_SHOW_NOTES", $lng->txt("show_".$suffix."_notes"));
391  }
392  $tpl->parseCurrentBlock();
393  }
394  else
395  {
396  // never individually hide for anonymous users
397  if (($ilUser->getId() != ANONYMOUS_USER_ID))
398  {
399  $tpl->setCurrentBlock("hide_notes");
400  $tpl->setVariable("LINK_HIDE_NOTES",
401  $this->ctrl->getLinkTargetByClass("ilnotegui", "hideNotes", "notes_top"));
402  if ($a_type == IL_NOTE_PUBLIC)
403  {
404  $tpl->setVariable("TXT_HIDE_NOTES", $lng->txt("notes_hide_comments"));
405  }
406  else
407  {
408  $tpl->setVariable("TXT_HIDE_NOTES", $lng->txt("hide_".$suffix."_notes"));
409  }
410  $tpl->parseCurrentBlock();
411 
412  // show all public notes / my notes only switch
413  if ($a_type == IL_NOTE_PUBLIC)
414  {
415  if ($ilUser->getPref("notes_pub_all") == "n")
416  {
417  $tpl->setCurrentBlock("all_pub_notes");
418  $tpl->setVariable("LINK_ALL_PUB_NOTES",
419  $this->ctrl->getLinkTargetByClass("ilnotegui", "showAllPublicNotes", "notes_top"));
420  $tpl->setVariable("TXT_ALL_PUB_NOTES", $lng->txt("notes_all_comments"));
421  $tpl->parseCurrentBlock();
422  }
423  else
424  {
425  $tpl->setCurrentBlock("my_pub_notes");
426  $tpl->setVariable("LINK_MY_PUB_NOTES",
427  $this->ctrl->getLinkTargetByClass("ilnotegui", "showMyPublicNotes", "notes_top"));
428  $tpl->setVariable("TXT_MY_PUB_NOTES", $lng->txt("notes_my_comments"));
429  $tpl->parseCurrentBlock();
430  }
431  }
432  }
433  }
434  }
435 
436  // show add new note text area
437  if ($this->add_note_form && $a_type == $_GET["note_type"])
438  {
439  $tpl->setCurrentBlock("edit_note");
440  $tpl->setVariable("TXT_SUBJECT", $lng->txt("subject"));
441  if ($a_type == IL_NOTE_PUBLIC)
442  {
443  $tpl->setVariable("TXT_NOTE", $lng->txt("notes_comment"));
444  }
445  else
446  {
447  $tpl->setVariable("TXT_NOTE", $lng->txt("note"));
448  }
449  $tpl->setVariable("NOTE_SUBJECT", "");
450  $tpl->setVariable("SUB_NOTE", "sub_note");
451  $tpl->setVariable("TA_NOTE", "note");
452  $tpl->setVariable("NOTE_CONTENT", "");
453  $tpl->setVariable("BTN_ADD_NOTE", "addNote");
454  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("add"));
455  $tpl->setVariable("BTN_CANCEL_ADD_NOTE", "cancelAddNote");
456  $tpl->setVariable("TXT_CANCEL_ADD_NOTE", $lng->txt("cancel"));
457  $tpl->setVariable("VAL_LABEL_NONE", IL_NOTE_UNLABELED);
458  $tpl->setVariable("TXT_LABEL_NONE", $lng->txt("unlabeled"));
459  $tpl->setVariable("VAL_LABEL_QUESTION", IL_NOTE_QUESTION);
460  $tpl->setVariable("TXT_LABEL_QUESTION", $lng->txt("question"));
461  $tpl->setVariable("VAL_LABEL_IMPORTANT", IL_NOTE_IMPORTANT);
462  $tpl->setVariable("TXT_LABEL_IMPORTANT", $lng->txt("important"));
463  $tpl->setVariable("VAL_LABEL_PRO", IL_NOTE_PRO);
464  $tpl->setVariable("TXT_LABEL_PRO", $lng->txt("pro"));
465  $tpl->setVariable("VAL_LABEL_CONTRA", IL_NOTE_CONTRA);
466  $tpl->setVariable("TXT_LABEL_CONTRA", $lng->txt("contra"));
467  $tpl->parseCurrentBlock();
468  $tpl->setCurrentBlock("note_row");
469  $tpl->parseCurrentBlock();
470  }
471 
472  // list all notes
473  if ($ilUser->getPref("notes_".$suffix) != "n" || !$this->enable_hiding)
474  {
475  foreach($notes as $note)
476  {
477  if ($this->edit_note_form && ($note->getId() == $_GET["note_id"])
478  && $a_type == $_GET["note_type"])
479  {
480  $tpl->setCurrentBlock("edit_note_form");
481  $tpl->setVariable("TXT_SUBJECT", $lng->txt("subject"));
482  if ($a_type == IL_NOTE_PUBLIC)
483  {
484  $tpl->setVariable("TXT_NOTE", $lng->txt("notes_comment"));
485  }
486  else
487  {
488  $tpl->setVariable("TXT_NOTE", $lng->txt("note"));
489  }
490  $tpl->setVariable("NOTE_SUBJECT",
491  ilUtil::prepareFormOutput($note->getSubject()));
492  $tpl->setVariable("SUB_NOTE", "sub_note");
493  $tpl->setVariable("TA_NOTE", "note");
494  $tpl->setVariable("NOTE_CONTENT",
495  ilUtil::prepareFormOutput($note->getText()));
496  $tpl->setVariable("BTN_ADD_NOTE", "updateNote");
497  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("save"));
498  $tpl->setVariable("BTN_CANCEL_ADD_NOTE", "cancelUpdateNote");
499  $tpl->setVariable("TXT_CANCEL_ADD_NOTE", $lng->txt("cancel"));
500  $tpl->setVariable("VAL_LABEL_NONE", IL_NOTE_UNLABELED);
501  $tpl->setVariable("TXT_LABEL_NONE", $lng->txt("unlabeled"));
502  $tpl->setVariable("VAL_LABEL_QUESTION", IL_NOTE_QUESTION);
503  $tpl->setVariable("TXT_LABEL_QUESTION", $lng->txt("question"));
504  $tpl->setVariable("VAL_LABEL_IMPORTANT", IL_NOTE_IMPORTANT);
505  $tpl->setVariable("TXT_LABEL_IMPORTANT", $lng->txt("important"));
506  $tpl->setVariable("VAL_LABEL_PRO", IL_NOTE_PRO);
507  $tpl->setVariable("TXT_LABEL_PRO", $lng->txt("pro"));
508  $tpl->setVariable("VAL_LABEL_CONTRA", IL_NOTE_CONTRA);
509  $tpl->setVariable("TXT_LABEL_CONTRA", $lng->txt("contra"));
510  $tpl->setVariable("VAL_NOTE_ID", $_GET["note_id"]);
511  switch($note->getLabel())
512  {
513  case IL_NOTE_UNLABELED:
514  $tpl->setVariable("SEL_NONE", 'selected="selected"');
515  break;
516 
517  case IL_NOTE_IMPORTANT:
518  $tpl->setVariable("SEL_IMPORTANT", 'selected="selected"');
519  break;
520 
521  case IL_NOTE_QUESTION:
522  $tpl->setVariable("SEL_QUESTION", 'selected="selected"');
523  break;
524 
525  case IL_NOTE_PRO:
526  $tpl->setVariable("SEL_PRO", 'selected="selected"');
527  break;
528 
529  case IL_NOTE_CONTRA:
530  $tpl->setVariable("SEL_CONTRA", 'selected="selected"');
531  break;
532  }
533  $tpl->parseCurrentBlock();
534  }
535  else
536  {
537  $cnt_col = 2;
538 
539  // delete note stuff for all private notes
540  if (($note->getAuthor() == $ilUser->getId() ||
542  && ($ilUser->getId() != ANONYMOUS_USER_ID))
543  {
544  // only private notes can be deleted by the user
545  // public notes can be deleted if flag set (outside permission checking)
546  if (($a_type == IL_NOTE_PRIVATE || $this->public_deletion_enabled)
547  && !$this->delete_note
548  && !$this->export_html && !$this->print)
549  {
550  $tpl->setCurrentBlock("delete_note");
551  $tpl->setVariable("TXT_DELETE_NOTE", $lng->txt("delete"));
552  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
553  $tpl->setVariable("LINK_DELETE_NOTE",
554  $ilCtrl->getLinkTargetByClass("ilnotegui", "deleteNote")
555  ."#note_".$note->getId());
556  $tpl->parseCurrentBlock();
557  }
558  }
559 
560  // edit note stuff for all private notes
561  if ($note->getAuthor() == $ilUser->getId()
562  && ($ilUser->getId() != ANONYMOUS_USER_ID))
563  {
564  // checkboxes in multiselection mode
565  if ($this->multi_selection && !$this->delete_note)
566  {
567  $tpl->setCurrentBlock("checkbox_col");
568  $tpl->setVariable("CHK_NOTE", "note[]");
569  $tpl->setVariable("CHK_NOTE_ID", $note->getId());
570  $tpl->parseCurrentBlock();
571  $cnt_col = 1;
572  }
573 
574  if (!$this->delete_note && !$this->export_html && !$this->print)
575  {
576  $tpl->setCurrentBlock("edit_note");
577  $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
578  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
579  $tpl->setVariable("LINK_EDIT_NOTE",
580  $ilCtrl->getLinkTargetByClass("ilnotegui", "editNoteForm")
581  ."#note_edit");
582  $tpl->parseCurrentBlock();
583  }
584  }
585 
586  $tpl->setVariable("CNT_COL", $cnt_col);
587 
588  // output author account
589  if ($a_type == IL_NOTE_PUBLIC && ilObject::_exists($note->getAuthor()))
590  {
591  $tpl->setCurrentBlock("author");
592  $tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin($note->getAuthor()));
593  $tpl->parseCurrentBlock();
594  $tpl->setCurrentBlock("user_img");
595  $tpl->setVariable("USR_IMG",
596  ilObjUser::_getPersonalPicturePath($note->getAuthor(), "xxsmall"));
597  $tpl->setVariable("USR_ALT",
598  ilObjUser::_lookupLogin($note->getAuthor()));
599  $tpl->parseCurrentBlock();
600  }
601 
602  // last edited
603  if ($note->getUpdateDate() != "0000-00-00 00:00:00")
604  {
605  $tpl->setCurrentBlock("last_edit");
606  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
607  $tpl->setVariable("DATE_LAST_EDIT",
608  ilDatePresentation::formatDate(new ilDateTime($note->getUpdateDate(), IL_CAL_DATETIME)));
609  $tpl->parseCurrentBlock();
610  }
611 
612  // hidden note ids for deletion
613  if ($this->delete_note)
614  {
615  $tpl->setCurrentBlock("delete_ids");
616  $tpl->setVariable("HID_NOTE", "note[]");
617  $tpl->setVariable("HID_NOTE_ID", $note->getId());
618  $tpl->parseCurrentBlock();
619  }
620  $target = $note->getObject();
621 
622  // target objects
623  $this->showTargets($tpl, $this->rep_obj_id, $note->getId(),
624  $target["obj_type"], $target["obj_id"]);
625 
626  $rowclass = ($rowclass != "tblrow1")
627  ? "tblrow1"
628  : "tblrow2";
629  if (!$this->export_html && !$this->print)
630  {
631  $tpl->setCurrentBlock("note_img");
632  if ($a_type == IL_NOTE_PUBLIC)
633  {
634  $tpl->setVariable("IMG_NOTE", $this->comment_img[$note->getLabel()]["img"]);
635  $tpl->setVariable("ALT_NOTE", $this->comment_img[$note->getLabel()]["alt"]);
636  }
637  else
638  {
639  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
640  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
641  }
642  $tpl->parseCurrentBlock();
643  }
644  else
645  {
646  switch ($note->getLabel())
647  {
648  case IL_NOTE_UNLABELED:
649  $tpl->setVariable("EXP_ICON", "[&nbsp;]");
650  break;
651 
652  case IL_NOTE_IMPORTANT:
653  $tpl->setVariable("EXP_ICON", "[!]");
654  break;
655 
656  case IL_NOTE_QUESTION:
657  $tpl->setVariable("EXP_ICON", "[?]");
658  break;
659 
660  case IL_NOTE_PRO:
661  $tpl->setVariable("EXP_ICON", "[+]");
662  break;
663 
664  case IL_NOTE_CONTRA:
665  $tpl->setVariable("EXP_ICON", "[-]");
666  break;
667  }
668  }
669  $tpl->setCurrentBlock("note");
670  $tpl->setVariable("ROWCLASS", $rowclass);
671  $tpl->setVariable("TXT_DATE", $lng->txt("date"));
672  $tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
673  $tpl->setVariable("VAL_DATE",
674  ilDatePresentation::formatDate(new ilDateTime($note->getCreationDate(), IL_CAL_DATETIME)));
675  $tpl->setVariable("NOTE_TEXT", nl2br($note->getText()));
676  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
677  $tpl->setVariable("NOTE_ID", $note->getId());
678  $tpl->parseCurrentBlock();
679  }
680  $tpl->setCurrentBlock("note_row");
681  $tpl->parseCurrentBlock();
682  }
683 
684  // multiple items commands
685  if ($this->multi_selection && !$this->delete_note && !$this->edit_note_form)
686  {
687  $tpl->setCurrentBlock("multiple_commands");
688  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
689  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
690  $tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
691  $tpl->setVariable("TXT_DELETE_NOTES", $this->lng->txt("delete"));
692  $tpl->setVariable("TXT_PRINT_NOTES", $this->lng->txt("print"));
693  $tpl->setVariable("TXT_EXPORT_NOTES", $this->lng->txt("exp_html"));
694  $tpl->parseCurrentBlock();
695  }
696 
697  // delete / cancel row
698  if ($this->delete_note)
699  {
700  $tpl->setCurrentBlock("delete_cancel");
701  $tpl->setVariable("TXT_DEL_NOTES", $this->lng->txt("delete"));
702  $tpl->setVariable("TXT_CANCEL_DEL_NOTES", $this->lng->txt("cancel"));
703  $tpl->parseCurrentBlock();
704  }
705 
706  // print
707  if ($this->print)
708  {
709  $tpl->touchBlock("print_js");
710  $tpl->setCurrentBlock("print_back");
711  $tpl->setVariable("LINK_BACK", $this->ctrl->getLinkTarget($this, "showNotes"));
712  $tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
713  $tpl->parseCurrentBlock();
714  }
715  }
716 
717  if ($this->delete_note && count($notes) == 0)
718  {
719  return "";
720  }
721  else
722  {
723  return $tpl->get();
724  }
725  }
726 
730  function getPDNoteHTML($note_id)
731  {
732  global $lng, $ilCtrl, $ilUser;
733 
734  $tpl = new ilTemplate("tpl.pd_note.html", true, true, "Services/Notes");
735  $note = new ilNote($note_id);
736  $target = $note->getObject();
737 
738  if ($note->getAuthor() != $ilUser->getId())
739  {
740  return;
741  }
742 
743  $img = ilUtil::getImagePath("note_".$note->getLabel().".gif");
744  $alt = $lng->txt("note");
745 
746  $tpl->setCurrentBlock("edit_note");
747  $ilCtrl->setParameterByClass("ilnotegui", "rel_obj", $target["rep_obj_id"]);
748  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note_id);
749  $ilCtrl->setParameterByClass("ilnotegui", "note_type", $note->getType());
750  $tpl->setVariable("LINK_EDIT_NOTE",
751  $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilpdnotesgui", "ilnotegui"),
752  "editNoteForm"));
753  $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
754  $tpl->parseCurrentBlock();
755  $ilCtrl->clearParametersByClass("ilnotegui");
756 
757  $tpl->setCurrentBlock("note_img");
758  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
759  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
760  $tpl->parseCurrentBlock();
761 
762  // last edited
763  if ($note->getUpdateDate() != "0000-00-00 00:00:00")
764  {
765  $tpl->setCurrentBlock("last_edit");
766  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
767  $tpl->setVariable("DATE_LAST_EDIT",
768  ilDatePresentation::formatDate(new ilDateTime($note->getUpdateDate(), IL_CAL_DATETIME)));
769  $tpl->parseCurrentBlock();
770  }
771 
772  $tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
773  $tpl->setVariable("VAL_DATE",
774  ilDatePresentation::formatDate(new ilDateTime($note->getCreationDate(), IL_CAL_DATETIME)));
775  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
776  $tpl->setVariable("NOTE_TEXT", nl2br($note->getText()));
777  $this->showTargets($tpl, $target["rep_obj_id"], $note_id, $target["obj_type"], $target["obj_id"]);
778  return $tpl->get();
779  }
780 
784  function showTargets(&$tpl, $a_rep_obj_id, $a_note_id, $a_obj_type, $a_obj_id)
785  {
786  global $tree, $ilAccess, $objDefinition;
787 
788  if ($this->targets_enabled)
789  {
790  if ($a_rep_obj_id > 0)
791  {
792 
793  // get all visible references of target object
794  $ref_ids = ilObject::_getAllReferences($a_rep_obj_id);
795  $vis_ref_ids = array();
796 
797  foreach($ref_ids as $ref_id)
798  {
799  if ($ilAccess->checkAccess("visible", "", $ref_id))
800  {
801  $vis_ref_ids[] = $ref_id;
802  }
803  }
804 
805  // output links to targets
806  if (count($vis_ref_ids) > 0)
807  {
808  foreach($vis_ref_ids as $vis_ref_id)
809  {
810  $type = ilObject::_lookupType($vis_ref_id, true);
811 
812  if ($a_obj_type != "pg")
813  {
814  if (!is_object($this->item_list_gui[$type]))
815  {
816  $class = $objDefinition->getClassName($type);
817  $location = $objDefinition->getLocation($type);
818  $full_class = "ilObj".$class."ListGUI";
819  include_once($location."/class.".$full_class.".php");
820  $this->item_list_gui[$type] = new $full_class();
821  }
822  $title = ilObject::_lookupTitle($a_rep_obj_id);
823  $this->item_list_gui[$type]->initItem($vis_ref_id, $a_rep_obj_id, $title);
824  $link = $this->item_list_gui[$type]->getCommandLink("infoScreen");
825 
826  // workaround, because # anchor can't be passed through frameset
827  $link = ilUtil::appendUrlParameterString($link, "anchor=note_".$a_note_id);
828 
829  $link = $this->item_list_gui[$type]->appendRepositoryFrameParameter($link)."#note_".$a_note_id;
830  }
831  else
832  {
833  $title = ilObject::_lookupTitle($a_rep_obj_id);
834  $link = "goto.php?target=pg_".$a_obj_id."_".$vis_ref_id;
835  }
836 
837  $par_id = $tree->getParentId($vis_ref_id);
838  if ($this->export_html || $this->print)
839  {
840  $tpl->setCurrentBlock("exp_target_object");
841  }
842  else
843  {
844  $tpl->setCurrentBlock("target_object");
845  $tpl->setVariable("LINK_TARGET", $link);
846  }
847  $tpl->setVariable("TXT_CONTAINER",
849  ilObject::_lookupObjId($par_id)));
850  $tpl->setVariable("TXT_TARGET",
851  $title);
852  $tpl->parseCurrentBlock();
853  }
854  $tpl->touchBlock("target_objects");
855  }
856  }
857  }
858  }
859 
863  function addNoteForm()
864  {
865  global $ilUser;
866 
867  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
868  ? "private"
869  : "public";
870  $ilUser->setPref("notes_".$suffix, "y");
871 
872  $this->add_note_form = true;
873  return $this->getNotesHTML();
874  }
875 
879  function cancelAddNote()
880  {
881  return $this->getNotesHTML();
882  }
883 
887  function cancelUpdateNote()
888  {
889  return $this->getNotesHTML();
890  }
891 
895  function addNote()
896  {
897  global $ilUser;
898 
899  if($_POST["note"] != "" || $_POST["sub_note"] != "")
900  {
901  $note = new ilNote();
902  $note->setObject($this->obj_type, $this->rep_obj_id, $this->obj_id);
903  $note->setType($_GET["note_type"]);
904  $note->setAuthor($ilUser->getId());
905  $note->setText(ilUtil::stripSlashes($_POST["note"]));
906  $note->setSubject(ilUtil::stripSlashes($_POST["sub_note"]));
907  $note->setLabel($_POST["note_label"]);
908  $note->create();
909  }
910 
911  return $this->getNotesHTML();
912  }
913 
917  function updateNote()
918  {
919  global $ilUser;
920 
921  $note = new ilNote($_POST["note_id"]);
922  //$note->setObject($this->obj_type, $this->rep_obj_id, $this->obj_id);
923  //$note->setType(IL_NOTE_PRIVATE);
924  //$note->setAuthor($ilUser->getId());
925  $note->setText(ilUtil::stripSlashes($_POST["note"]));
926  $note->setSubject(ilUtil::stripSlashes($_POST["sub_note"]));
927  $note->setLabel($_POST["note_label"]);
928  $note->update();
929 
930  return $this->getNotesHTML();
931  }
932 
936  function editNoteForm()
937  {
938  $this->edit_note_form = true;
939  return $this->getNotesHTML();
940  }
941 
945  function deleteNote()
946  {
947  $this->delete_note = true;
948  return $this->getNotesHTML();
949  }
950 
954  function deleteNotes()
955  {
956  global $lng;
957 
958  if (!$_POST["note"])
959  {
960  ilUtil::sendInfo($lng->txt("no_checkbox"));
961  }
962  else
963  {
964  $this->delete_note = true;
965  }
966  return $this->getNotesHTML();
967  }
968 
972  function cancelDelete()
973  {
974  return $this->getNotesHTML();
975  }
976 
980  function confirmDelete()
981  {
982  foreach($_POST["note"] as $id)
983  {
984  $note = new ilNote($id);
985  $note->delete();
986  }
987  return $this->getNotesHTML();
988  }
989 
993  function exportNotesHTML()
994  {
995  $tpl = new ilTemplate("tpl.main.html", true, true);
996 
997  $this->export_html = true;
998  $this->multi_selection = false;
999  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1000  ilUtil::deliverData($tpl->get(), "notes.html");
1001  }
1002 
1006  function printNotes()
1007  {
1008  $tpl = new ilTemplate("tpl.main.html", true, true);
1009 
1010  $this->print = true;
1011  $this->multi_selection = false;
1012  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1013  echo $tpl->get(); exit;
1014  }
1015 
1019  function showNotes()
1020  {
1021  global $ilUser;
1022 
1023  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1024  ? "private"
1025  : "public";
1026  $ilUser->writePref("notes_".$suffix, "y");
1027 
1028  return $this->getNotesHTML();
1029  }
1030 
1034  function hideNotes()
1035  {
1036  global $ilUser;
1037 
1038  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1039  ? "private"
1040  : "public";
1041  $ilUser->writePref("notes_".$suffix, "n");
1042 
1043  return $this->getNotesHTML();
1044  }
1045 
1050  {
1051  global $ilUser;
1052 
1053  $ilUser->writePref("notes_pub_all", "y");
1054 
1055  return $this->getNotesHTML();
1056  }
1057 
1062  {
1063  global $ilUser;
1064 
1065  $ilUser->writePref("notes_pub_all", "n");
1066 
1067  return $this->getNotesHTML();
1068  }
1069 }
1070 ?>