ILIAS  Release_4_1_x_branch Revision 61804
 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->anchor_jump = true;
63  $this->add_note_form = false;
64  $this->edit_note_form = false;
65  $this->private_enabled = false;
66  $notes_settings = new ilSetting("notes");
67  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
68  if ($notes_settings->get("activate_".$id))
69  {
70  $this->public_enabled = true;
71  }
72  else
73  {
74  $this->public_enabled = false;
75  }
76  $this->enable_hiding = true;
77  $this->targets_enabled = false;
78  $this->multi_selection = false;
79  $this->export_html = false;
80  $this->print = false;
81  $this->comments_settings = false;
82 
83  $this->note_img = array(
84  IL_NOTE_UNLABELED => array(
85  "img" => ilUtil::getImagePath("note_unlabeled.gif"),
86  "alt" => $lng->txt("note")),
87  IL_NOTE_IMPORTANT => array(
88  "img" => ilUtil::getImagePath("note_important.gif"),
89  "alt" => $lng->txt("note").", ".$lng->txt("important")),
90  IL_NOTE_QUESTION => array(
91  "img" => ilUtil::getImagePath("note_question.gif"),
92  "alt" => $lng->txt("note").", ".$lng->txt("question")),
93  IL_NOTE_PRO => array(
94  "img" => ilUtil::getImagePath("note_pro.gif"),
95  "alt" => $lng->txt("note").", ".$lng->txt("pro")),
96  IL_NOTE_CONTRA => array(
97  "img" => ilUtil::getImagePath("note_contra.gif"),
98  "alt" => $lng->txt("note").", ".$lng->txt("contra"))
99  );
100 
101  $this->comment_img = array(
102  IL_NOTE_UNLABELED => array(
103  "img" => ilUtil::getImagePath("comment_unlabeled.gif"),
104  "alt" => $lng->txt("notes_comment")),
105  IL_NOTE_IMPORTANT => array(
106  "img" => ilUtil::getImagePath("comment_important.gif"),
107  "alt" => $lng->txt("notes_comment").", ".$lng->txt("important")),
108  IL_NOTE_QUESTION => array(
109  "img" => ilUtil::getImagePath("comment_question.gif"),
110  "alt" => $lng->txt("notes_comment").", ".$lng->txt("question")),
111  IL_NOTE_PRO => array(
112  "img" => ilUtil::getImagePath("comment_pro.gif"),
113  "alt" => $lng->txt("notes_comment").", ".$lng->txt("pro")),
114  IL_NOTE_CONTRA => array(
115  "img" => ilUtil::getImagePath("comment_contra.gif"),
116  "alt" => $lng->txt("notes_comment").", ".$lng->txt("contra"))
117  );
118  }
119 
123  function &executeCommand()
124  {
125  $cmd = $this->ctrl->getCmd("getNotesHTML");
126  $next_class = $this->ctrl->getNextClass($this);
127 
128  switch($next_class)
129  {
130  default:
131  return $this->$cmd();
132  break;
133  }
134  }
135 
139  function enablePrivateNotes($a_enable = true)
140  {
141  $this->private_enabled = $a_enable;
142  }
143 
147  function enablePublicNotes($a_enable = true)
148  {
149  $this->public_enabled = $a_enable;
150  }
151 
155  function enableCommentsSettings($a_enable = true)
156  {
157  $this->comments_settings = $a_enable;
158  }
159 
163  function enablePublicNotesDeletion($a_enable = true)
164  {
165  $this->public_deletion_enabled = $a_enable;
166  }
167 
171  function enableHiding($a_enable = true)
172  {
173  $this->enable_hiding = $a_enable;
174  }
175 
179  function enableTargets($a_enable = true)
180  {
181  $this->targets_enabled = $a_enable;
182  }
183 
187  function enableMultiSelection($a_enable = true)
188  {
189  $this->multi_selection = $a_enable;
190  }
191 
195  function enableAnchorJump($a_enable = true)
196  {
197  $this->anchor_jump = $a_enable;
198  }
199 
200  /***
201  * get note lists html code
202  */
203  function getNotesHTML($a_init_form = true)
204  {
205  global $ilUser, $lng, $ilCtrl;
206 
207  $lng->loadLanguageModule("notes");
208 
209  $ntpl = new ilTemplate("tpl.notes_and_comments.html", true, true,
210  "Services/Notes");
211 
212  // check, whether column is hidden due to processing in other column
213  $hide_notes = $hide_comments = false;
214  switch($ilCtrl->getCmd())
215  {
216  case "addNoteForm":
217  case "editNoteForm":
218  case "addNote":
219  case "updateNote":
220  if ($_GET["note_type"] == IL_NOTE_PRIVATE)
221  {
222  $hide_comments = true;
223  }
224  if ($_GET["note_type"] == IL_NOTE_PUBLIC)
225  {
226  $hide_notes = true;
227  }
228  break;
229  }
230 
231  $nodes_col = false;
232  if ($this->private_enabled && ($ilUser->getId() != ANONYMOUS_USER_ID)
233  && !$hide_notes)
234  {
235  $ntpl->setCurrentBlock("notes_col");
236  $ntpl->setVariable("NOTES", $this->getNoteListHTML(IL_NOTE_PRIVATE, $a_init_form));
237  $ntpl->parseCurrentBlock();
238  $nodes_col = true;
239  }
240 
241  $comments_col = false;
242  if ($this->public_enabled && (!$this->delete_note || $this->public_deletion_enabled)
243  && !$hide_comments)
244 // if ($this->public_enabled && ($ilUser->getId() != ANONYMOUS_USER_ID)
245 // && !$hide_comments)
246  {
247  $ntpl->setVariable("COMMENTS", $this->getNoteListHTML(IL_NOTE_PUBLIC, $a_init_form));
248  $comments_col = true;
249  }
250 
251  // Comments Settings
252  if ($this->comments_settings && !$hide_comments && !$this->delete_note
253  && !$this->edit_note_form && !$this->add_note_form)
254  {
255  $notes_settings = new ilSetting("notes");
256  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
257  $active = $notes_settings->get("activate_".$id);
258 
259  $ntpl->setCurrentBlock("comments_settings");
260  if ($active)
261  {
262  $ntpl->setVariable("TXT_COMMENTS_SETTINGS", $lng->txt("notes_deactivate_comments"));
263  $ntpl->setVariable("HREF_COMMENTS_SETTINGS",
264  $ilCtrl->getLinkTargetByClass("ilnotegui", "deactivateComments", "notes_top"));
265  }
266  else
267  {
268  $ntpl->setVariable("TXT_COMMENTS_SETTINGS", $lng->txt("notes_activate_comments"));
269  $ntpl->setVariable("HREF_COMMENTS_SETTINGS",
270  $ilCtrl->getLinkTargetByClass("ilnotegui", "activateComments", "notes_top"));
271  }
272  $ntpl->parseCurrentBlock();
273  $comments_col = true;
274  }
275 
276  if ($comments_col)
277  {
278  $ntpl->setCurrentBlock("comments_col");
279  // scorm2004-start
280  if ($nodes_col)
281  {
282  $ntpl->touchBlock("comments_style");
283  }
284  // scorm2004-end
285  $ntpl->parseCurrentBlock();
286  }
287 
288  switch($_GET["note_mess"] != "" ? $_GET["note_mess"] : $this->note_mess)
289  {
290  case "mod":
291  $mtype = "success";
292  $mtxt = $lng->txt("msg_obj_modified");
293  break;
294 
295  case "ntsdel":
296  $mtype = "success";
297  $mtxt = $lng->txt("notes_notes_deleted");
298  break;
299 
300  case "ntdel":
301  $mtype = "success";
302  $mtxt = $lng->txt("notes_note_deleted");
303  break;
304 
305  case "frmfld":
306  $mtype = "failure";
307  $mtxt = $lng->txt("form_input_not_valid");
308  break;
309 
310  case "qdel":
311  $mtype = "question";
312  $mtxt = $lng->txt("info_delete_sure");
313  break;
314 
315  case "noc":
316  $mtype = "failure";
317  $mtxt = $lng->txt("no_checkbox");
318  break;
319  }
320 
321  if ($mtxt != "")
322  {
323  $ntpl->setVariable("NOTE_MESS", $ntpl->getMessageHTML($mtxt, $mtype));
324  }
325 
326  return $ntpl->get();
327  }
328 
332  function activateComments()
333  {
334  global $ilCtrl;
335 
336  $notes_settings = new ilSetting("notes");
337 
338  if ($this->comments_settings)
339  {
340  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
341  $notes_settings->set("activate_".$id, 1);
342  }
343 
344  $ilCtrl->redirectByClass("ilnotegui", "getNotesHtml");
345  }
346 
351  {
352  global $ilCtrl;
353 
354  $notes_settings = new ilSetting("notes");
355 
356  if ($this->comments_settings)
357  {
358  $id = $this->rep_obj_id."_".$this->obj_id."_".$this->obj_type;
359  $notes_settings->set("activate_".$id, 0);
360  }
361 
362  $ilCtrl->redirectByClass("ilnotegui", "getNotesHtml");
363  }
364 
368  function getNoteListHTML($a_type = IL_NOTE_PRIVATE, $a_init_form = true)
369  {
370  global $lng, $ilCtrl, $ilUser, $ilAccess, $tree, $objDefinition;
371 
372  $suffix = ($a_type == IL_NOTE_PRIVATE)
373  ? "private"
374  : "public";
375 
376  if ($this->delete_note || $this->export_html || $this->print)
377  {
378  if ($_GET["note_id"] != "")
379  {
380  $filter = $_GET["note_id"];
381  }
382  else
383  {
384  $filter = $_POST["note"];
385  }
386  }
387  $notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
388  $this->obj_type, $a_type, $this->inc_sub, $filter,
389  $ilUser->getPref("notes_pub_all"), $this->public_deletion_enabled);
390  $all_notes = ilNote::_getNotesOfObject($this->rep_obj_id, $this->obj_id,
391  $this->obj_type, $a_type, $this->inc_sub, $filter,
392  "", $this->public_deletion_enabled);
393 
394  $tpl = new ilTemplate("tpl.notes_list.html", true, true, "Services/Notes");
395 
396  // show counter if notes are hidden
397  $cnt_str = (count($all_notes) > 0)
398  ? " (".count($all_notes).")"
399  : "";
400 
401  if (!$this->export_html)
402  {
403  $tpl->setCurrentBlock("notes_img");
404  if ($a_type == IL_NOTE_PUBLIC)
405  {
406  $tpl->setVariable("IMG_NOTES", ilUtil::getImagePath("icon_comment.gif"));
407  $tpl->setVariable("ALT_NOTES", $lng->txt("icon")." ".$lng->txt("notes_public_comments"));
408  }
409  else
410  {
411  $tpl->setVariable("IMG_NOTES", ilUtil::getImagePath("icon_note.gif"));
412  $tpl->setVariable("ALT_NOTES", $lng->txt("icon")." ".$lng->txt("private_notes"));
413  }
414  $tpl->parseCurrentBlock();
415  }
416 
417  if ($this->delete_note)
418  {
419  $cnt_str = "";
420  }
421  if ($a_type == IL_NOTE_PRIVATE)
422  {
423  $tpl->setVariable("TXT_NOTES", $lng->txt("private_notes").$cnt_str);
424  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PRIVATE);
425  }
426  else
427  {
428  $tpl->setVariable("TXT_NOTES", $lng->txt("notes_public_comments").$cnt_str);
429  $ilCtrl->setParameterByClass("ilnotegui", "note_type", IL_NOTE_PUBLIC);
430  }
431  $anch = $this->anchor_jump
432  ? "notes_top"
433  : "";
434  $tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this, "getNotesHTML", $anch));
435 
436  if ($this->export_html || $this->print)
437  {
438  $tpl->touchBlock("print_style");
439  }
440 
441  // show add new note button
442  if (!$this->add_note_form && !$this->edit_note_form && !$this->delete_note &&
443  !$this->export_html && !$this->print &&
444  ($ilUser->getId() != ANONYMOUS_USER_ID))
445  {
446  if (!$this->inc_sub) // we cannot offer add button if aggregated notes
447  { // are displayed
448  if ($this->rep_obj_id > 0 || $a_type != IL_NOTE_PUBLIC)
449  {
450  $tpl->setCurrentBlock("add_note_btn");
451  if ($a_type == IL_NOTE_PUBLIC)
452  {
453  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("notes_add_comment"));
454  }
455  else
456  {
457  $tpl->setVariable("TXT_ADD_NOTE", $lng->txt("add_note"));
458  }
459  $tpl->setVariable("LINK_ADD_NOTE", $ilCtrl->getLinkTargetByClass("ilnotegui", "addNoteForm").
460  "#note_edit");
461  $tpl->parseCurrentBlock();
462  }
463  }
464  }
465 
466  // show show/hide button for note list
467  if (count($all_notes) > 0 && $this->enable_hiding && !$this->delete_note
468  && !$this->export_html && !$this->print && !$this->edit_note_form
469  && !$this->add_note_form)
470  {
471  if ($ilUser->getPref("notes_".$suffix) == "n")
472  {
473  $tpl->setCurrentBlock("show_notes");
474  $tpl->setVariable("LINK_SHOW_NOTES",
475  $this->ctrl->getLinkTargetByClass("ilnotegui", "showNotes", "notes_top"));
476  if ($a_type == IL_NOTE_PUBLIC)
477  {
478  $tpl->setVariable("TXT_SHOW_NOTES", $lng->txt("notes_show_comments"));
479  }
480  else
481  {
482  $tpl->setVariable("TXT_SHOW_NOTES", $lng->txt("show_".$suffix."_notes"));
483  }
484  $tpl->parseCurrentBlock();
485  }
486  else
487  {
488  // never individually hide for anonymous users
489  if (($ilUser->getId() != ANONYMOUS_USER_ID))
490  {
491  $tpl->setCurrentBlock("hide_notes");
492  $tpl->setVariable("LINK_HIDE_NOTES",
493  $this->ctrl->getLinkTargetByClass("ilnotegui", "hideNotes", "notes_top"));
494  if ($a_type == IL_NOTE_PUBLIC)
495  {
496  $tpl->setVariable("TXT_HIDE_NOTES", $lng->txt("notes_hide_comments"));
497  }
498  else
499  {
500  $tpl->setVariable("TXT_HIDE_NOTES", $lng->txt("hide_".$suffix."_notes"));
501  }
502  $tpl->parseCurrentBlock();
503 
504  // show all public notes / my notes only switch
505  if ($a_type == IL_NOTE_PUBLIC)
506  {
507  if ($ilUser->getPref("notes_pub_all") == "n")
508  {
509  $tpl->setCurrentBlock("all_pub_notes");
510  $tpl->setVariable("LINK_ALL_PUB_NOTES",
511  $this->ctrl->getLinkTargetByClass("ilnotegui", "showAllPublicNotes", "notes_top"));
512  $tpl->setVariable("TXT_ALL_PUB_NOTES", $lng->txt("notes_all_comments"));
513  $tpl->parseCurrentBlock();
514  }
515  else
516  {
517  $tpl->setCurrentBlock("my_pub_notes");
518  $tpl->setVariable("LINK_MY_PUB_NOTES",
519  $this->ctrl->getLinkTargetByClass("ilnotegui", "showMyPublicNotes", "notes_top"));
520  $tpl->setVariable("TXT_MY_PUB_NOTES", $lng->txt("notes_my_comments"));
521  $tpl->parseCurrentBlock();
522  }
523  }
524  }
525  }
526  }
527 
528  // show add new note text area
529  if ($this->add_note_form && $a_type == $_GET["note_type"])
530  {
531  if ($a_init_form)
532  {
533  $this->initNoteForm("create", $a_type);
534  }
535 
536  $tpl->setCurrentBlock("edit_note_form");
537  $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
538  $tpl->parseCurrentBlock();
539 
540  $tpl->parseCurrentBlock();
541  $tpl->setCurrentBlock("note_row");
542  $tpl->parseCurrentBlock();
543  }
544 
545  // list all notes
546  if ($ilUser->getPref("notes_".$suffix) != "n" || !$this->enable_hiding)
547  {
548  foreach($notes as $note)
549  {
550  if ($this->edit_note_form && ($note->getId() == $_GET["note_id"])
551  && $a_type == $_GET["note_type"])
552  {
553  if ($a_init_form)
554  {
555  $this->initNoteForm("edit", $a_type, $note);
556  }
557  $tpl->setCurrentBlock("edit_note_form");
558  $tpl->setVariable("EDIT_FORM", $this->form->getHTML());
559  $tpl->parseCurrentBlock();
560  }
561  else
562  {
563  $cnt_col = 2;
564 
565  // delete note stuff for all private notes
566  if ($this->checkDeletion($note)
567  && !$this->delete_note
568  && !$this->export_html && !$this->print
569  && !$this->edit_note_form && !$this->add_note_form)
570  {
571  $tpl->setCurrentBlock("delete_note");
572  $tpl->setVariable("TXT_DELETE_NOTE", $lng->txt("delete"));
573  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
574  $tpl->setVariable("LINK_DELETE_NOTE",
575  $ilCtrl->getLinkTargetByClass("ilnotegui", "deleteNote")
576  ."#note_".$note->getId());
577  $tpl->parseCurrentBlock();
578  }
579 
580  // checkboxes in multiselection mode
581  if ($this->multi_selection && !$this->delete_note)
582  {
583  $tpl->setCurrentBlock("checkbox_col");
584  $tpl->setVariable("CHK_NOTE", "note[]");
585  $tpl->setVariable("CHK_NOTE_ID", $note->getId());
586  $tpl->parseCurrentBlock();
587  $cnt_col = 1;
588  }
589 
590  // edit note stuff for all private notes
591  if ($this->checkEdit($note))
592  {
593 
594  if (!$this->delete_note && !$this->export_html && !$this->print
595  && !$this->edit_note_form && !$this->add_note_form)
596  {
597  $tpl->setCurrentBlock("edit_note");
598  $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
599  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note->getId());
600  $tpl->setVariable("LINK_EDIT_NOTE",
601  $ilCtrl->getLinkTargetByClass("ilnotegui", "editNoteForm")
602  ."#note_edit");
603  $tpl->parseCurrentBlock();
604  }
605  }
606 
607  $tpl->setVariable("CNT_COL", $cnt_col);
608 
609  // output author account
610  if ($a_type == IL_NOTE_PUBLIC && ilObject::_exists($note->getAuthor()))
611  {
612  $tpl->setCurrentBlock("author");
613  $tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin($note->getAuthor()));
614  $tpl->parseCurrentBlock();
615  $tpl->setCurrentBlock("user_img");
616  $tpl->setVariable("USR_IMG",
617  ilObjUser::_getPersonalPicturePath($note->getAuthor(), "xxsmall"));
618  $tpl->setVariable("USR_ALT", $lng->txt("user_image").": ".
619  ilObjUser::_lookupLogin($note->getAuthor()));
620  $tpl->setVariable("TXT_USR",
621  ilObjUser::_lookupLogin($note->getAuthor()));
622  $tpl->parseCurrentBlock();
623  }
624 
625  // last edited
626  if ($note->getUpdateDate() != null)
627  {
628  $tpl->setCurrentBlock("last_edit");
629  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
630  $tpl->setVariable("DATE_LAST_EDIT",
631  ilDatePresentation::formatDate(new ilDateTime($note->getUpdateDate(), IL_CAL_DATETIME)));
632  $tpl->parseCurrentBlock();
633  }
634 
635  // hidden note ids for deletion
636  if ($this->delete_note)
637  {
638  $tpl->setCurrentBlock("delete_ids");
639  $tpl->setVariable("HID_NOTE", "note[]");
640  $tpl->setVariable("HID_NOTE_ID", $note->getId());
641  $tpl->parseCurrentBlock();
642  }
643  $target = $note->getObject();
644 
645  // target objects
646  $this->showTargets($tpl, $this->rep_obj_id, $note->getId(),
647  $target["obj_type"], $target["obj_id"]);
648 
649  $rowclass = ($rowclass != "tblrow1")
650  ? "tblrow1"
651  : "tblrow2";
652  if (!$this->export_html && !$this->print)
653  {
654  $tpl->setCurrentBlock("note_img");
655  if ($a_type == IL_NOTE_PUBLIC)
656  {
657  $tpl->setVariable("IMG_NOTE", $this->comment_img[$note->getLabel()]["img"]);
658  $tpl->setVariable("ALT_NOTE", $this->comment_img[$note->getLabel()]["alt"]);
659  }
660  else
661  {
662  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
663  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
664  }
665  $tpl->parseCurrentBlock();
666  }
667  else
668  {
669  switch ($note->getLabel())
670  {
671  case IL_NOTE_UNLABELED:
672  $tpl->setVariable("EXP_ICON", "[&nbsp;]");
673  break;
674 
675  case IL_NOTE_IMPORTANT:
676  $tpl->setVariable("EXP_ICON", "[!]");
677  break;
678 
679  case IL_NOTE_QUESTION:
680  $tpl->setVariable("EXP_ICON", "[?]");
681  break;
682 
683  case IL_NOTE_PRO:
684  $tpl->setVariable("EXP_ICON", "[+]");
685  break;
686 
687  case IL_NOTE_CONTRA:
688  $tpl->setVariable("EXP_ICON", "[-]");
689  break;
690  }
691  }
692  $tpl->setCurrentBlock("note");
693  $tpl->setVariable("ROWCLASS", $rowclass);
694  $tpl->setVariable("TXT_DATE", $lng->txt("date"));
695  $tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
696  $tpl->setVariable("VAL_DATE",
697  ilDatePresentation::formatDate(new ilDateTime($note->getCreationDate(), IL_CAL_DATETIME)));
698  $tpl->setVariable("NOTE_TEXT", nl2br($note->getText()));
699  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
700  $tpl->setVariable("NOTE_ID", $note->getId());
701  $tpl->parseCurrentBlock();
702  }
703  $tpl->setCurrentBlock("note_row");
704  $tpl->parseCurrentBlock();
705  }
706 
707  // multiple items commands
708  if ($this->multi_selection && !$this->delete_note && !$this->edit_note_form
709  && count($notes) > 0)
710  {
711  if ($a_type == IL_NOTE_PRIVATE)
712  {
713  $tpl->setCurrentBlock("delete_cmd");
714  $tpl->setVariable("TXT_DELETE_NOTES", $this->lng->txt("delete"));
715  $tpl->parseCurrentBlock();
716  }
717 
718  $tpl->setCurrentBlock("multiple_commands");
719  $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
720  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
721  $tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
722  $tpl->setVariable("TXT_PRINT_NOTES", $this->lng->txt("print"));
723  $tpl->setVariable("TXT_EXPORT_NOTES", $this->lng->txt("exp_html"));
724  $tpl->parseCurrentBlock();
725  }
726 
727  // delete / cancel row
728  if ($this->delete_note)
729  {
730  $tpl->setCurrentBlock("delete_cancel");
731  $tpl->setVariable("TXT_DEL_NOTES", $this->lng->txt("delete"));
732  $tpl->setVariable("TXT_CANCEL_DEL_NOTES", $this->lng->txt("cancel"));
733  $tpl->parseCurrentBlock();
734  }
735 
736  // print
737  if ($this->print)
738  {
739  $tpl->touchBlock("print_js");
740  $tpl->setCurrentBlock("print_back");
741  $tpl->setVariable("LINK_BACK", $this->ctrl->getLinkTarget($this, "showNotes"));
742  $tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
743  $tpl->parseCurrentBlock();
744  }
745  }
746 
747  if ($this->delete_note && count($notes) == 0)
748  {
749  return "";
750  }
751  else
752  {
753  return $tpl->get();
754  }
755  }
756 
760  function checkDeletion($a_note)
761  {
762  global $ilUser;
763 
764  if ($ilUser->getId() == ANONYMOUS_USER_ID)
765  {
766  return false;
767  }
768 
769  // delete note stuff for all private notes
770  if (($a_note->getType() == IL_NOTE_PRIVATE && $a_note->getAuthor() == $ilUser->getId()) ||
771  ($a_note->getType() == IL_NOTE_PUBLIC &&
773  )
774  {
775  return true;
776  }
777 
778  return false;
779  }
780 
784  function checkEdit($a_note)
785  {
786  global $ilUser;
787 
788  if ($a_note->getAuthor() == $ilUser->getId()
789  && ($ilUser->getId() != ANONYMOUS_USER_ID))
790  {
791  return true;
792  }
793  return false;
794  }
795 
796 
802  public function initNoteForm($a_mode = "edit", $a_type, $a_note = null)
803  {
804  global $lng, $ilCtrl;
805 
806  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
807  $this->form = new ilPropertyFormGUI();
808  $this->form->setOpenTag(false);
809  $this->form->setCloseTag(false);
810  $this->form->setDisableStandardMessage(true);
811 
812  // subject
813  $ti = new ilTextInputGUI($this->lng->txt("subject"), "sub_note");
814  $ti->setRequired(true);
815  $ti->setMaxLength(200);
816  $ti->setSize(40);
817  if ($a_note)
818  {
819  $ti->setValue($a_note->getSubject());
820  }
821  $this->form->addItem($ti);
822 
823  // text
824  $ta = new ilTextAreaInputGUI(($a_type == IL_NOTE_PUBLIC)
825  ? $lng->txt("notes_comment")
826  : $lng->txt("note"), "note");
827  $ta->setCols(40);
828  $ta->setRows(4);
829  if ($a_note)
830  {
831  $ta->setValue($a_note->getText());
832  }
833  $this->form->addItem($ta);
834 
835  // label
836  $options = array(
837  IL_NOTE_UNLABELED => $lng->txt("unlabeled"),
838  IL_NOTE_QUESTION => $lng->txt("question"),
839  IL_NOTE_IMPORTANT => $lng->txt("important"),
840  IL_NOTE_PRO => $lng->txt("pro"),
841  IL_NOTE_CONTRA => $lng->txt("contra"),
842  );
843  $si = new ilSelectInputGUI($this->lng->txt("notes_label"), "note_label");
844  $si->setOptions($options);
845  if ($a_note)
846  {
847  $si->setValue($a_note->getLabel());
848  }
849  $this->form->addItem($si);
850 
851  // hidden note id
852  if ($a_note)
853  {
854  $hi = new ilHiddenInputGUI("note_id");
855  $hi->setValue($_GET["note_id"]);
856  $this->form->addItem($hi);
857  }
858 
859  // save and cancel commands
860  if ($a_mode == "create")
861  {
862  $this->form->addCommandButton("addNote", $lng->txt("save"));
863  $this->form->addCommandButton("cancelAddNote", $lng->txt("cancel"));
864  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
865  ? $lng->txt("notes_add_comment")
866  : $lng->txt("notes_add_note"));
867  }
868  else
869  {
870  $this->form->addCommandButton("updateNote", $lng->txt("save"));
871  $this->form->addCommandButton("cancelUpdateNote", $lng->txt("cancel"));
872  $this->form->setTitle($a_type == IL_NOTE_PUBLIC
873  ? $lng->txt("notes_edit_comment")
874  : $lng->txt("notes_edit_note"));
875  }
876 
877  $ilCtrl->setParameter($this, "note_type", $a_type);
878  $this->form->setFormAction($this->ctrl->getFormAction($this));
879 
880  }
881 
885  function getPDNoteHTML($note_id)
886  {
887  global $lng, $ilCtrl, $ilUser;
888 
889  $tpl = new ilTemplate("tpl.pd_note.html", true, true, "Services/Notes");
890  $note = new ilNote($note_id);
891  $target = $note->getObject();
892 
893  if ($note->getAuthor() != $ilUser->getId())
894  {
895  return;
896  }
897 
898  $img = ilUtil::getImagePath("note_".$note->getLabel().".gif");
899  $alt = $lng->txt("note");
900 
901  $tpl->setCurrentBlock("edit_note");
902  $ilCtrl->setParameterByClass("ilnotegui", "rel_obj", $target["rep_obj_id"]);
903  $ilCtrl->setParameterByClass("ilnotegui", "note_id", $note_id);
904  $ilCtrl->setParameterByClass("ilnotegui", "note_type", $note->getType());
905  $tpl->setVariable("LINK_EDIT_NOTE",
906  $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilpdnotesgui", "ilnotegui"),
907  "editNoteForm"));
908  $tpl->setVariable("TXT_EDIT_NOTE", $lng->txt("edit"));
909  $tpl->parseCurrentBlock();
910  $ilCtrl->clearParametersByClass("ilnotegui");
911 
912  $tpl->setCurrentBlock("note_img");
913  $tpl->setVariable("IMG_NOTE", $this->note_img[$note->getLabel()]["img"]);
914  $tpl->setVariable("ALT_NOTE", $this->note_img[$note->getLabel()]["alt"]);
915  $tpl->parseCurrentBlock();
916 
917  // last edited
918  if ($note->getUpdateDate() != null)
919  {
920  $tpl->setCurrentBlock("last_edit");
921  $tpl->setVariable("TXT_LAST_EDIT", $lng->txt("last_edited_on"));
922  $tpl->setVariable("DATE_LAST_EDIT",
923  ilDatePresentation::formatDate(new ilDateTime($note->getUpdateDate(), IL_CAL_DATETIME)));
924  $tpl->parseCurrentBlock();
925  }
926 
927  $tpl->setVariable("TXT_CREATED", $lng->txt("create_date"));
928  $tpl->setVariable("VAL_DATE",
929  ilDatePresentation::formatDate(new ilDateTime($note->getCreationDate(), IL_CAL_DATETIME)));
930  $tpl->setVariable("VAL_SUBJECT", $note->getSubject());
931  $tpl->setVariable("NOTE_TEXT", nl2br($note->getText()));
932  $this->showTargets($tpl, $target["rep_obj_id"], $note_id, $target["obj_type"], $target["obj_id"]);
933  return $tpl->get();
934  }
935 
939  function showTargets(&$tpl, $a_rep_obj_id, $a_note_id, $a_obj_type, $a_obj_id)
940  {
941  global $tree, $ilAccess, $objDefinition;
942 
943  if ($this->targets_enabled)
944  {
945  if ($a_rep_obj_id > 0)
946  {
947 
948  // get all visible references of target object
949  $ref_ids = ilObject::_getAllReferences($a_rep_obj_id);
950  $vis_ref_ids = array();
951 
952  foreach($ref_ids as $ref_id)
953  {
954  if ($ilAccess->checkAccess("visible", "", $ref_id))
955  {
956  $vis_ref_ids[] = $ref_id;
957  }
958  }
959 
960  // output links to targets
961  if (count($vis_ref_ids) > 0)
962  {
963  foreach($vis_ref_ids as $vis_ref_id)
964  {
965  $type = ilObject::_lookupType($vis_ref_id, true);
966  $sub_link = $sub_title = "";
967  if ($type == "sahs") // bad hack, needs general procedure
968  {
969  $link = "goto.php?target=sahs_".$vis_ref_id;
970  $title = ilObject::_lookupTitle($a_rep_obj_id);
971  if ($a_obj_type == "sco" || $a_obj_type == "seqc" || $a_obj_type == "chap" || $a_obj_type == "pg")
972  {
973  $sub_link = "goto.php?target=sahs_".$vis_ref_id."_".$a_obj_id;
974  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
975  $sub_title = ilSCORM2004Node::_lookupTitle($a_obj_id);
976  $sub_icon = ilUtil::getImagePath("icon_".$a_obj_type."_s.gif");
977  }
978  }
979  else if ($a_obj_type != "pg")
980  {
981  if (!is_object($this->item_list_gui[$type]))
982  {
983  $class = $objDefinition->getClassName($type);
984  $location = $objDefinition->getLocation($type);
985  $full_class = "ilObj".$class."ListGUI";
986  include_once($location."/class.".$full_class.".php");
987  $this->item_list_gui[$type] = new $full_class();
988  }
989  $title = ilObject::_lookupTitle($a_rep_obj_id);
990  $this->item_list_gui[$type]->initItem($vis_ref_id, $a_rep_obj_id, $title);
991  $link = $this->item_list_gui[$type]->getCommandLink("infoScreen");
992 
993  // workaround, because # anchor can't be passed through frameset
994  $link = ilUtil::appendUrlParameterString($link, "anchor=note_".$a_note_id);
995 
996  $link = $this->item_list_gui[$type]->appendRepositoryFrameParameter($link)."#note_".$a_note_id;
997  }
998  else
999  {
1000  $title = ilObject::_lookupTitle($a_rep_obj_id);
1001  $link = "goto.php?target=pg_".$a_obj_id."_".$vis_ref_id;
1002  }
1003 
1004  $par_id = $tree->getParentId($vis_ref_id);
1005 
1006  // sub object link
1007  if ($sub_link != "")
1008  {
1009  if ($this->export_html || $this->print)
1010  {
1011  $tpl->setCurrentBlock("exp_target_sub_object");
1012  }
1013  else
1014  {
1015  $tpl->setCurrentBlock("target_sub_object");
1016  $tpl->setVariable("LINK_SUB_TARGET", $sub_link);
1017  }
1018  $tpl->setVariable("TXT_SUB_TARGET", $sub_title);
1019  $tpl->setVariable("IMG_SUB_TARGET", $sub_icon);
1020  $tpl->parseCurrentBlock();
1021  }
1022 
1023  // container and object link
1024  if ($this->export_html || $this->print)
1025  {
1026  $tpl->setCurrentBlock("exp_target_object");
1027  }
1028  else
1029  {
1030  $tpl->setCurrentBlock("target_object");
1031  $tpl->setVariable("LINK_TARGET", $link);
1032  }
1033  $tpl->setVariable("TXT_CONTAINER",
1035  ilObject::_lookupObjId($par_id)));
1036  $tpl->setVariable("IMG_CONTAINER",
1038  ilObject::_lookupObjId($par_id), "tiny"));
1039  $tpl->setVariable("TXT_TARGET", $title);
1040  $tpl->setVariable("IMG_TARGET",
1041  ilObject::_getIcon($a_rep_obj_id, "tiny"));
1042 
1043  $tpl->parseCurrentBlock();
1044  }
1045  $tpl->touchBlock("target_objects");
1046  }
1047  }
1048  }
1049  }
1050 
1054  function addNoteForm($a_init_form = true)
1055  {
1056  global $ilUser;
1057 
1058  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1059  ? "private"
1060  : "public";
1061  $ilUser->setPref("notes_".$suffix, "y");
1062 
1063  $this->add_note_form = true;
1064  return $this->getNotesHTML($a_init_form);
1065  }
1066 
1070  function cancelAddNote()
1071  {
1072  return $this->getNotesHTML();
1073  }
1074 
1078  function cancelUpdateNote()
1079  {
1080  return $this->getNotesHTML();
1081  }
1082 
1086  function addNote()
1087  {
1088  global $ilUser, $lng, $ilCtrl;
1089 
1090  $this->initNoteForm("create", $_GET["note_type"]);
1091 
1092  if ($this->form->checkInput())
1093  {
1094  $note = new ilNote();
1095  $note->setObject($this->obj_type, $this->rep_obj_id, $this->obj_id);
1096  $note->setType($_GET["note_type"]);
1097  $note->setAuthor($ilUser->getId());
1098  $note->setText($_POST["note"]);
1099  $note->setSubject($_POST["sub_note"]);
1100  $note->setLabel($_POST["note_label"]);
1101  $note->create();
1102  $ilCtrl->setParameter($this, "note_mess", "mod");
1103  $ilCtrl->redirect($this, "showNotes", "notes_top");
1104  }
1105 
1106  $this->note_mess = "frmfld";
1107  $this->form->setValuesByPost();
1108  return $this->addNoteForm(false);;
1109  }
1110 
1114  function updateNote()
1115  {
1116  global $ilUser, $lng, $ilCtrl;
1117 
1118  $note = new ilNote(ilUtil::stripSlashes($_POST["note_id"]));
1119  $this->initNoteForm("edit", $note->getType(),
1120  $note);
1121 
1122  if ($this->form->checkInput())
1123  {
1124  $note->setText($_POST["note"]);
1125  $note->setSubject($_POST["sub_note"]);
1126  $note->setLabel($_POST["note_label"]);
1127  if ($this->checkEdit($note))
1128  {
1129  $note->update();
1130  $ilCtrl->setParameter($this, "note_mess", "mod");
1131  }
1132  $ilCtrl->redirect($this, "showNotes", "notes_top");
1133  }
1134 
1135  $this->note_mess = "frmfld";
1136  $this->form->setValuesByPost();
1137  $_GET["note_id"] = $note->getId();
1138  $_GET["note_type"] = $note->getType();
1139  return $this->editNoteForm(false);
1140  }
1141 
1145  function editNoteForm($a_init_form = true)
1146  {
1147  $this->edit_note_form = true;
1148 
1149  return $this->getNotesHTML($a_init_form);
1150  }
1151 
1155  function deleteNote()
1156  {
1157  $this->delete_note = true;
1158  $this->note_mess = "qdel";
1159  return $this->getNotesHTML();
1160  }
1161 
1165  function deleteNotes()
1166  {
1167  global $lng;
1168 
1169  if (!$_POST["note"])
1170  {
1171  $this->note_mess = "noc";
1172  }
1173  else
1174  {
1175  $this->delete_note = true;
1176  $this->note_mess = "qdel";
1177  }
1178 
1179  return $this->getNotesHTML();
1180  }
1181 
1185  function cancelDelete()
1186  {
1187  return $this->getNotesHTML();
1188  }
1189 
1193  function confirmDelete()
1194  {
1195  global $ilCtrl, $lng, $ilUser;
1196 
1197  $cnt = 0;
1198  foreach($_POST["note"] as $id)
1199  {
1200  $note = new ilNote($id);
1201  if ($this->checkDeletion($note))
1202  {
1203  $note->delete();
1204  $cnt++;
1205  }
1206  }
1207  if ($cnt > 1)
1208  {
1209  $ilCtrl->setParameter($this, "note_mess", "ntsdel");
1210  }
1211  else
1212  {
1213  $ilCtrl->setParameter($this, "note_mess", "ntdel");
1214  }
1215  $ilCtrl->redirect($this, "showNotes", "notes_top");
1216  }
1217 
1221  function exportNotesHTML()
1222  {
1223  $tpl = new ilTemplate("tpl.main.html", true, true);
1224 
1225  $this->export_html = true;
1226  $this->multi_selection = false;
1227  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1228  ilUtil::deliverData($tpl->get(), "notes.html");
1229  }
1230 
1234  function printNotes()
1235  {
1236  $tpl = new ilTemplate("tpl.main.html", true, true);
1237 
1238  $this->print = true;
1239  $this->multi_selection = false;
1240  $tpl->setVariable("CONTENT", $this->getNotesHTML());
1241  echo $tpl->get(); exit;
1242  }
1243 
1247  function showNotes()
1248  {
1249  global $ilUser;
1250 
1251  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1252  ? "private"
1253  : "public";
1254  $ilUser->writePref("notes_".$suffix, "y");
1255 
1256  return $this->getNotesHTML();
1257  }
1258 
1262  function hideNotes()
1263  {
1264  global $ilUser;
1265 
1266  $suffix = ($_GET["note_type"] == IL_NOTE_PRIVATE)
1267  ? "private"
1268  : "public";
1269  $ilUser->writePref("notes_".$suffix, "n");
1270 
1271  return $this->getNotesHTML();
1272  }
1273 
1278  {
1279  global $ilUser;
1280 
1281  $ilUser->writePref("notes_pub_all", "y");
1282 
1283  return $this->getNotesHTML();
1284  }
1285 
1290  {
1291  global $ilUser;
1292 
1293  $ilUser->writePref("notes_pub_all", "n");
1294 
1295  return $this->getNotesHTML();
1296  }
1297 }
1298 ?>