ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDNotesGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
25 include_once("Services/Notes/classes/class.ilNote.php");
26 
39 {
40 
46  var $ilias;
47  var $tpl;
48  var $lng;
49 
50  const PUBLIC_COMMENTS = "publiccomments";
51  const PRIVATE_NOTES = "privatenotes";
52 
58  function ilPDNotesGUI()
59  {
60  global $ilias, $tpl, $lng, $ilCtrl, $ilUser, $ilTabs;
61 
62  // initiate variables
63  $this->ilias =& $ilias;
64  $this->tpl =& $tpl;
65  $this->lng =& $lng;
66  $this->ctrl =& $ilCtrl;
67 
68  // link from ilPDNotesBlockGUI
69  if($_GET["rel_obj"])
70  {
71  $mode = ($_GET["note_type"] == IL_NOTE_PRIVATE) ? self::PRIVATE_NOTES : self::PUBLIC_COMMENTS;
72  $ilUser->writePref("pd_notes_mode", $mode);
73  $ilUser->writePref("pd_notes_rel_obj".$mode, $_GET["rel_obj"]);
74  }
75  // edit link
76  else if($_REQUEST["note_id"])
77  {
78  $note = new ilNote($_REQUEST["note_id"]);
79  $mode = ($note->getType() == IL_NOTE_PRIVATE) ? self::PRIVATE_NOTES : self::PUBLIC_COMMENTS;
80  $obj = $note->getObject();
81  $ilUser->writePref("pd_notes_mode", $mode);
82  $ilUser->writePref("pd_notes_rel_obj".$mode, $obj["rep_obj_id"]);
83  }
84  }
85 
89  function &executeCommand()
90  {
91  $next_class = $this->ctrl->getNextClass();
92 
93  switch($next_class)
94  {
95  case "ilnotegui":
96  // scorm2004-start
97  $this->setTabs();
98  // scorm2004-end
99  $this->displayHeader();
100  $this->view(); // forwardCommand is invoked in view() method
101  break;
102 
103  default:
104  // scorm2004-start
105  $this->setTabs();
106  // scorm2004-end
107  $cmd = $this->ctrl->getCmd("view");
108  $this->displayHeader();
109  $this->$cmd();
110  break;
111  }
112  $this->tpl->show(true);
113  return true;
114  }
115 
119  function displayHeader()
120  {
121  //$this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
122  // $this->lng->txt("personal_desktop"));
123 // $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
124 // "");
125  $this->tpl->setTitle($this->lng->txt("notes"));
126 
127  // catch feedback message
128  // display infopanel if something happened
130 
131  }
132 
133  /*
134  * display notes
135  */
136  function view()
137  {
138  global $ilUser, $lng;
139 
140  //$this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.table.html")
141  include_once("Services/Notes/classes/class.ilNoteGUI.php");
142 
143  // output related item selection (if more than one)
144  include_once("Services/Notes/classes/class.ilNote.php");
145  $rel_objs = ilNote::_getRelatedObjectsOfUser($this->getMode());
146 
147  // prepend personal dektop, if first object
148  if ($rel_objs[0]["rep_obj_id"] > 0 && $this->getMode() == ilPDNotesGUI::PRIVATE_NOTES)
149  {
150  $rel_objs = array_merge(array(0), $rel_objs);
151  }
152 
153  // #9410
154  if(!$rel_objs && $this->getMode() == ilPDNotesGUI::PUBLIC_COMMENTS)
155  {
156  $lng->loadLanguageModule("notes");
157  ilUtil::sendInfo($lng->txt("msg_no_search_result"));
158  return;
159  }
160 
161  $first = true;
162  foreach ($rel_objs as $r)
163  {
164  if ($first) // take first one as default
165  {
166  $this->current_rel_obj = $r["rep_obj_id"];
167  }
168  if ($r["rep_obj_id"] == $ilUser->getPref("pd_notes_rel_obj".$this->getMode()))
169  {
170  $this->current_rel_obj = $r["rep_obj_id"];
171  }
172  $first = false;
173  }
174  if ($this->current_rel_obj > 0)
175  {
176  $notes_gui = new ilNoteGUI($this->current_rel_obj, 0,
177  ilObject::_lookupType($this->current_rel_obj),true);
178  }
179  else
180  {
181  $notes_gui = new ilNoteGUI(0, $ilUser->getId(), "pd");
182  }
183 
184  if ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES)
185  {
186  $notes_gui->enablePrivateNotes(true);
187  $notes_gui->enablePublicNotes(false);
188  }
189  else
190  {
191  $notes_gui->enablePrivateNotes(false);
192  $notes_gui->enablePublicNotes(true);
193  }
194  $notes_gui->enableHiding(false);
195  $notes_gui->enableTargets(true);
196  $notes_gui->enableMultiSelection(true);
197  $notes_gui->enableAnchorJump(false);
198 
199  $next_class = $this->ctrl->getNextClass($this);
200 
201  if ($next_class == "ilnotegui")
202  {
203  $html = $this->ctrl->forwardCommand($notes_gui);
204  }
205  else
206  {
207  $html = $notes_gui->getNotesHTML();
208  }
209 
210  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.pd_notes.html", "Services/Notes");
211 
212  if (count($rel_objs) > 1 ||
213  ($rel_objs[0]["rep_obj_id"] > 0))
214  {
215  foreach($rel_objs as $obj)
216  {
217  $this->tpl->setCurrentBlock("related_option");
218  $this->tpl->setVariable("VAL_RELATED",
219  $obj["rep_obj_id"]);
220 //echo "-".$obj["rep_obj_id"]."-".$obj["obj_type"]."-";
221  if ($obj["rep_obj_id"] > 0)
222  {
223  $type = ilObject::_lookupType($obj["rep_obj_id"]);
224  $type_str = (in_array($type, array("lm", "htlm", "sahs", "dbk")))
225  ? $lng->txt("learning_resource")
226  : $lng->txt("obj_".$type);
227  $this->tpl->setVariable("TXT_RELATED", $type_str.": ".
228  ilObject::_lookupTitle($obj["rep_obj_id"]));
229  }
230  else
231  {
232  $this->tpl->setVariable("TXT_RELATED",
233  $lng->txt("personal_desktop"));
234  }
235  if ($obj["rep_obj_id"] == $this->current_rel_obj)
236  {
237  $this->tpl->setVariable("SEL", 'selected="selected"');
238  }
239  $this->tpl->parseCurrentBlock();
240  }
241 
242  $this->tpl->setCurrentBlock("related_selection");
243  $this->tpl->setVariable("TXT_CHANGE", $lng->txt("change"));
244  $this->tpl->setVariable("TXT_RELATED_TO", $lng->txt("related_to"));
245  $this->tpl->setVariable("TXT_FILTER", $lng->txt("filter"));
246  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
247  $this->tpl->parseCurrentBlock();
248  }
249 
250  $this->tpl->setCurrentBlock("adm_content");
251  // output notes
252  $this->tpl->setVariable("NOTES", $html);
253  $this->tpl->parseCurrentBlock();
254 
255  }
256 
261  {
262  global $ilUser;
263 
264  $ilUser->writePref("pd_notes_rel_obj".$this->getMode(), $_POST["rel_obj"]);
265  $this->ctrl->redirect($this);
266  }
267 
268  // scorm2004-start
272  function setTabs()
273  {
274  global $ilTabs, $ilSetting, $ilCtrl;
275 
276  $ilTabs->addTarget("private_notes",
277  $ilCtrl->getLinkTarget($this, "showPrivateNotes"), "", "", "",
278  ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES));
279  if(!$ilSetting->get("disable_comments"))
280  {
281  $ilTabs->addTarget("notes_public_comments",
282  $ilCtrl->getLinkTarget($this, "showPublicComments"), "", "", "",
283  ($this->getMode() == ilPDNotesGUI::PUBLIC_COMMENTS));
284  }
285  }
286 
290  function showPrivateNotes()
291  {
292  global $ilUser, $ilCtrl;
293 
294  $ilUser->writePref("pd_notes_mode", ilPDNotesGUI::PRIVATE_NOTES);
295  $ilCtrl->redirect($this, "");
296  }
297 
302  {
303  global $ilUser, $ilCtrl, $ilSetting;
304 
305  if($ilSetting->get("disable_comments"))
306  {
307  $ilCtrl->redirect($this, "showPrivateNotes");
308  }
309 
310  $ilUser->writePref("pd_notes_mode", ilPDNotesGUI::PUBLIC_COMMENTS);
311  $ilCtrl->redirect($this, "");
312  }
313 
317  function getMode()
318  {
319  global $ilUser, $ilSetting;
320 
321  if ($ilUser->getPref("pd_notes_mode") == ilPDNotesGUI::PUBLIC_COMMENTS &&
322  !$ilSetting->get("disable_comments"))
323  {
325  }
326  else
327  {
329  }
330  }
331 }
332 ?>