ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomSmileyTask.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14 
15  private $gui;
16 
23  {
24  $this->gui = $gui;
25  }
26 
32  public function executeDefault($method)
33  {
34  //include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
35  //ilChatroomSmilies::_initial();
36  $this->view();
37  }
38 
44  public function view()
45  {
46  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
47 
48  ilChatroom::checkUserPermissions('read', $this->gui->ref_id);
49 
50  $this->gui->switchToVisibleMode();
51 
53 
54  $this->editSmiliesObject();
55  }
56 
64  {
65  global $rbacsystem, $tpl, $lng;
66 
67  $this->gui->switchToVisibleMode();
68 
69  if(!$rbacsystem->checkAccess('read', $this->gui->ref_id))
70  {
71  $this->ilias->raiseError(
72  $lng->txt('msg_no_perm_read'), $this->ilias->error_obj->MESSAGE
73  );
74  }
75 
76  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
77 
78  $smiley = ilChatroomSmilies::_getSmiley($_REQUEST["smiley_id"]);
79 
80  $form_data = array(
81  "chatroom_smiley_id" => $smiley["smiley_id"],
82  "chatroom_smiley_keywords" => $smiley["smiley_keywords"],
83  "chatroom_current_smiley_image_path" => $smiley["smiley_fullpath"],
84  );
85 
86  $form = $this->initSmiliesEditForm($form_data);
87 
88  $tpl_form = new ilTemplate(
89  "tpl.chatroom_edit_smilies.html", true, true, "Modules/Chatroom"
90  );
91 
92  $tpl_form->setVariable("SMILEY_FORM", $form->getHTML());
93 
94  $tpl->setContent($tpl_form->get());
95  }
96 
101  public function showDeleteSmileyFormObject()
102  {
109  global $rbacsystem, $lng, $ilCtrl, $tpl;
110 
111  $this->gui->switchToVisibleMode();
112 
113  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
114  {
115  $this->ilias->raiseError(
116  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
117  );
118  }
119 
120  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
121  $smiley = ilChatroomSmilies::_getSmiley((int)$_REQUEST['smiley_id']);
122 
123  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
124  $confirmation = new ilConfirmationGUI();
125  $confirmation->setFormAction($ilCtrl->getFormAction($this->gui, 'smiley'));
126  $confirmation->setHeaderText($lng->txt('chatroom_confirm_delete_smiley'));
127  $confirmation->addButton($lng->txt('confirm'), 'smiley-deleteSmileyObject');
128  $confirmation->addButton($lng->txt('cancel'), 'smiley');
129  $confirmation->addItem('chatroom_smiley_id', $smiley['smiley_id'], ilUtil::img($smiley['smiley_fullpath'], $smiley['smiley_keywords']) . ' ' . $smiley['smiley_keywords']);
130 
131  $tpl->setContent($confirmation->getHTML());
132  }
133 
139  public function deleteSmileyObject()
140  {
141  global $rbacsystem, $ilCtrl, $lng;
142 
143  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
144  {
145  $this->ilias->raiseError(
146  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
147  );
148  }
149 
150  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
151 
152  ilChatroomSmilies::_deleteSmiley($_REQUEST["chatroom_smiley_id"]);
153 
154  $ilCtrl->redirect($this->gui, "smiley");
155  }
156 
164  public function editSmiliesObject()
165  {
166  global $rbacsystem, $lng, $tpl;
167 
168  if(!$rbacsystem->checkAccess('read', $this->gui->ref_id))
169  {
170  $this->ilias->raiseError(
171  $lng->txt('msg_no_perm_read'), $this->gui->ilias->error_obj->MESSAGE
172  );
173  }
174 
175  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
176 
178 
179  if(!$this->form_gui)
180  {
181  $form = $this->initSmiliesForm();
182  }
183  else
184  {
185  $form = $this->form_gui;
186  }
187 
188  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesGUI.php";
189 
191 
192  $tpl_smilies = new ilTemplate(
193  "tpl.chatroom_edit_smilies.html", true, true, "Modules/Chatroom"
194  );
195  $tpl_smilies->setVariable("SMILEY_TABLE", $table);
196  $tpl_smilies->setVariable("SMILEY_FORM", $form->getHtml());
197 
198  $tpl->setContent($tpl_smilies->get());
199  }
200 
208  public function updateSmiliesObject()
209  {
210  global $rbacsystem, $ilCtrl, $tpl, $lng;
211 
212  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
213  {
214  $this->ilias->raiseError(
215  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
216  );
217  }
218 
219  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
220  $this->form_gui = new ilPropertyFormGUI();
221 
222  // $this->initSmiliesEditForm();
223 
224  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
225 
227  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
228  );
229 
230  $keywordscheck = count($keywords) > 0;
231 
232  if(!$this->form_gui->checkInput() || !$keywordscheck)
233  {
234  $tpl->setContent($this->form_gui->getHtml());
235  ilUtil::sendFailure('test', true);
236  return $this->view();
237  }
238  else
239  {
240  $data = array();
241  $data["smiley_keywords"] = join("\n", $keywords);
242  $data["smiley_id"] = $_REQUEST["smiley_id"];
243 
244  if($_FILES["chatroom_image_path"])
245  {
246  move_uploaded_file(
247  $_FILES["chatroom_image_path"]["tmp_name"],
249  $_FILES["chatroom_image_path"]["name"]
250  );
251 
252  $data["smiley_path"] = $_FILES["chatroom_image_path"]["name"];
253  }
254 
256  }
257 
258  $ilCtrl->redirect($this->gui, "smiley");
259  }
260 
267  public function initSmiliesForm()
268  {
269  global $ilCtrl, $lng;
270 
271  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
272 
273  $this->form_gui = new ilPropertyFormGUI();
274 
275  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
276  $this->form_gui->setFormAction(
277  $ilCtrl->getFormAction($this->gui, 'smiley-uploadSmileyObject') . $table_nav
278  );
279 
280  // chat server settings
281  $sec_l = new ilFormSectionHeaderGUI();
282 
283  $sec_l->setTitle($lng->txt('chatroom_add_smiley'));
284  $this->form_gui->addItem($sec_l);
285 
286  $inp = new ilImageFileInputGUI(
287  $lng->txt('chatroom_image_path'), 'chatroom_image_path'
288  );
289 
290  $inp->setRequired(true);
291  $this->form_gui->addItem($inp);
292 
293  $inp = new ilTextAreaInputGUI(
294  $lng->txt('chatroom_smiley_keywords'), 'chatroom_smiley_keywords'
295  );
296 
297  $inp->setRequired(true);
298  $inp->setUseRte(false);
299  $inp->setInfo($lng->txt('chatroom_smiley_keywords_one_per_line_note'));
300  $this->form_gui->addItem($inp);
301  $this->form_gui->addCommandButton(
302  'smiley-uploadSmileyObject', $lng->txt('chatroom_upload_smiley')
303  );
304 
305  return $this->form_gui;
306  }
307 
312  public function deleteMultipleObject()
313  {
320  global $rbacsystem, $lng, $ilCtrl, $tpl;
321 
322  $this->gui->switchToVisibleMode();
323 
324  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
325  {
326  $this->ilias->raiseError(
327  $this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
328  );
329  }
330 
331  $items = (array)$_REQUEST['smiley_id'];
332  if(count($items) == 0)
333  {
334  ilUtil::sendInfo($lng->txt('select_one'), true);
335  $ilCtrl->redirect($this->gui, 'smiley');
336  }
337 
338  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
339  $smilies = ilChatroomSmilies::_getSmiliesById($items);
340  if(count($smilies) == 0)
341  {
342  ilUtil::sendInfo($lng->txt('select_one'), true);
343  $ilCtrl->redirect($this->gui, 'smiley');
344  }
345 
346  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
347  $confirmation = new ilConfirmationGUI();
348  $confirmation->setFormAction($ilCtrl->getFormAction($this->gui, 'smiley'));
349  $confirmation->setHeaderText($lng->txt('chatroom_confirm_delete_smiley'));
350  $confirmation->addButton($lng->txt('confirm'), 'smiley-confirmedDeleteMultipleObject');
351  $confirmation->addButton($lng->txt('cancel'), 'smiley');
352 
353  foreach($smilies as $s)
354  {
355  $confirmation->addItem('sel_ids[]', $s['smiley_id'], ilUtil::img($s['smiley_fullpath'], $s['smiley_keywords']) . ' ' . $s['smiley_keywords']);
356  }
357 
358  $tpl->setContent($confirmation->getHTML());
359  }
360 
364  public function confirmedDeleteMultipleObject()
365  {
370  global $rbacsystem, $ilCtrl;
371 
372  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
373  {
374  $this->ilias->raiseError(
375  $this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
376  );
377  }
378 
379  $parts = $_POST["sel_ids"];
380  if(count($parts) == 0)
381  {
382  $ilCtrl->redirect($this->gui, "smiley");
383  }
384 
385  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
387 
388  $ilCtrl->redirect($this->gui, "smiley");
389  }
390 
397  public function initSmiliesEditForm($form_data)
398  {
399  global $ilCtrl, $lng;
400 
401  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
402 
403  $this->form_gui = new ilPropertyFormGUI();
404 
405  $this->form_gui->setValuesByArray($form_data);
406 
407  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
408 
409  $ilCtrl->saveParameter($this->gui, 'smiley_id');
410 
411  $this->form_gui->setFormAction(
412  $ilCtrl->getFormAction($this->gui, 'smiley-updateSmiliesObject') . $table_nav
413  );
414 
415  $sec_l = new ilFormSectionHeaderGUI();
416 
417  $sec_l->setTitle($lng->txt('chatroom_edit_smiley'));
418  $this->form_gui->addItem($sec_l);
419 
420  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesCurrentSmileyFormElement.php";
421 
423  $lng->txt('chatroom_current_smiley_image_path'),
424  'chatroom_current_smiley_image_path'
425  );
426 
427  $inp->setValue($form_data['chatroom_current_smiley_image_path']);
428  $this->form_gui->addItem($inp);
429 
430  $inp = new ilImageFileInputGUI(
431  $lng->txt('chatroom_image_path'), 'chatroom_image_path'
432  );
433 
434  $inp->setRequired(false);
435  $inp->setInfo($lng->txt('chatroom_smiley_image_only_if_changed'));
436  $this->form_gui->addItem($inp);
437 
438  $inp = new ilTextAreaInputGUI(
439  $lng->txt('chatroom_smiley_keywords'), 'chatroom_smiley_keywords'
440  );
441 
442  $inp->setValue($form_data['chatroom_smiley_keywords']);
443  $inp->setUseRte(false);
444  $inp->setRequired(true);
445  $inp->setInfo($lng->txt('chatroom_smiley_keywords_one_per_line_note'));
446  $this->form_gui->addItem($inp);
447 
448  $inp = new ilHiddenInputGUI('chatroom_smiley_id');
449 
450  $this->form_gui->addItem($inp);
451  $this->form_gui->addCommandButton(
452  'smiley-updateSmiliesObject', $lng->txt('submit')
453  );
454  $this->form_gui->addCommandButton('smiley', $lng->txt('cancel'));
455  return $this->form_gui;
456  }
457 
464  public function uploadSmileyObject()
465  {
466  global $rbacsystem, $ilCtrl, $tpl, $lng;
467 
468  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
469  {
470  $this->ilias->raiseError(
471  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
472  );
473  }
474 
475  $this->initSmiliesForm();
476 
477  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
478  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
479 
480  //$this->form_gui = new ilPropertyFormGUI();
481 
482  $this->form_gui->setValuesByPost();
483 
485  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
486  );
487 
488  $keywordscheck = count($keywords) > 0;
489 
490  if(!$this->form_gui->checkInput())
491  {
492  $tpl->setContent($this->form_gui->getHtml());
493  return $this->view();
494  }
495 
496  $pathinfo = pathinfo($_FILES["chatroom_image_path"]["name"]);
497  $target_file = md5(time() + $pathinfo['basename']) . "." . $pathinfo['extension'];
498 
499  move_uploaded_file(
500  $_FILES["chatroom_image_path"]["tmp_name"],
502  );
503 
504  ilChatroomSmilies::_storeSmiley(join("\n", $keywords), $target_file);
505 
506  $ilCtrl->redirect($this->gui, "smiley");
507  }
508 
509  private static function _insertDefaultValues()
510  {
511  global $ilDB;
512 
513  $values = array(
514  array("icon_smile.gif", ":)\n:-)\n:smile:"),
515  array("icon_wink.gif", ";)\n;-)\n:wink:"),
516  array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
517  array("icon_sad.gif", ":(\n:-(\n:sad:"),
518  array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
519  array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
520  array("icon_cool.gif", ":cool:"),
521  array("icon_eek.gif", ":eek:"),
522  array("icon_angry.gif", ":||\n:-||\n:angry:"),
523  array("icon_flush.gif", ":flush:"),
524  array("icon_idea.gif", ":idea:"),
525  array("icon_thumbup.gif", ":thumbup:"),
526  array("icon_thumbdown.gif", ":thumbdown:"),
527  );
528 
529  $stmt = $ilDB->prepare("
530  INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
531  VALUES (?, ?, ?)",
532  array("integer", "text", "text")
533  );
534 
535  foreach($values as $val)
536  {
537  $row = array(
538  $ilDB->nextID("chat_smilies"),
539  $val[1],
540  $val[0]
541  );
542  $stmt->execute($row);
543  }
544  }
545 
549  private static function _setupFolder()
550  {
552 
553  if(!is_dir($path))
554  {
555  mkdir($path, 0755, true);
556  }
557  }
558 
562  public static function _getSmileyDir()
563  {
564  return ilUtil::getWebspaceDir() . '/chatroom/smilies';
565  }
566 
567  public static function _checkSetup()
568  {
569  global $lng;
570 
572 
573  if(!is_dir($path))
574  {
575  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_exists'));
577 
578  if(!is_dir($path))
579  {
580  ilUtil::sendFailure($lng->txt('chat_smilies_dir_not_available'));
581  return false;
582  }
583  else
584  {
585  $smilies = array
586  (
587  "icon_smile.gif",
588  "icon_wink.gif",
589  "icon_laugh.gif",
590  "icon_sad.gif",
591  "icon_shocked.gif",
592  "icon_tongue.gif",
593  "icon_cool.gif",
594  "icon_eek.gif",
595  "icon_angry.gif",
596  "icon_flush.gif",
597  "icon_idea.gif",
598  "icon_thumbup.gif",
599  "icon_thumbdown.gif",
600  );
601 
602  foreach($smilies as $smiley)
603  {
604  copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
605  }
606 
608 
609  ilUtil::sendSuccess($lng->txt('chat_smilies_initialized'));
610  }
611 
612  }
613 
614  if(!is_writable($path))
615  {
616  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_writable'));
617  }
618 
619  return true;
620  }
621 }
622 
623 ?>