ILIAS  Release_4_4_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 
4 
17 {
18 
19  private $gui;
20 
29  {
30  $this->gui = $gui;
31  }
32 
39  public function executeDefault($method)
40  {
41  //include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
42  //ilChatroomSmilies::_initial();
43  $this->view();
44  }
45 
51  public function view()
52  {
53  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
54 
55  ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id );
56 
57  $this->gui->switchToVisibleMode();
58 
60 
61  $this->editSmiliesObject();
62  }
63 
73  {
74  global $rbacsystem, $tpl, $lng;
75 
76  $this->gui->switchToVisibleMode();
77 
78  if( !$rbacsystem->checkAccess( 'read', $this->gui->ref_id ) )
79  {
80  $this->ilias->raiseError(
81  $lng->txt( 'msg_no_perm_read' ), $this->ilias->error_obj->MESSAGE
82  );
83  }
84 
85  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
86 
87  $smiley = ilChatroomSmilies::_getSmiley( $_REQUEST["smiley_id"] );
88 
89  $form_data = array(
90  "chatroom_smiley_id" => $smiley["smiley_id"],
91  "chatroom_smiley_keywords" => $smiley["smiley_keywords"],
92  "chatroom_current_smiley_image_path" => $smiley["smiley_fullpath"],
93  );
94 
95  $form = $this->initSmiliesEditForm($form_data);
96 
97  $tpl_form = new ilTemplate(
98  "tpl.chatroom_edit_smilies.html", true, true, "Modules/Chatroom"
99  );
100 
101  $tpl_form->setVariable( "SMILEY_FORM", $form->getHTML() );
102 
103  $tpl->setContent( $tpl_form->get() );
104  }
105 
116  public function showDeleteSmileyFormObject()
117  {
118  global $rbacsystem, $lng, $ilCtrl, $tpl;
119 
120  $this->gui->switchToVisibleMode();
121 
122  if( !$rbacsystem->checkAccess( 'write', $this->gui->ref_id ) )
123  {
124  $this->ilias->raiseError(
125  $lng->txt( 'msg_no_perm_write' ), $this->ilias->error_obj->MESSAGE
126  );
127  }
128 
129  $tpl_form = new ilTemplate(
130  "tpl.chatroom_smiley_confirm_delete.html", true, true, "Modules/Chatroom"
131  );
132 
133  $tpl_form->setVariable(
134  "TXT_CONFIRM_DELETE_SMILEY", $lng->txt( 'chatroom_confirm_delete_smiley' )
135  );
136  $tpl_form->setVariable( "TXT_CONFIRM_DELETE", $lng->txt( 'confirm' ) );
137  $tpl_form->setVariable( "TXT_CANCEL_DELETE", $lng->txt( 'cancel' ) );
138  $tpl_form->setVariable( "SMILEY_ID", $_REQUEST["smiley_id"] );
139 
140  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
141 
142  $smiley = ilChatroomSmilies::_getSmiley( $_REQUEST["smiley_id"] );
143 
144  $tpl_form->setVariable( "SMILEY_PATH", $smiley["smiley_fullpath"] );
145  $tpl_form->setVariable( "SMILEY_KEYWORDS", $smiley["smiley_keywords"] );
146 
147  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
148 
149  $tpl_form->setVariable(
150  "FORMACTION", $ilCtrl->getFormAction( $this->gui ) . $table_nav
151  );
152 
153  $tpl_form->parseCurrentBlock();
154  $tpl->setContent( $tpl_form->get() );
155  }
156 
163  public function deleteSmileyObject()
164  {
165  global $rbacsystem, $ilCtrl, $lng;
166 
167  if( !$rbacsystem->checkAccess( 'write', $this->gui->ref_id ) )
168  {
169  $this->ilias->raiseError(
170  $lng->txt( 'msg_no_perm_write' ), $this->ilias->error_obj->MESSAGE
171  );
172  }
173 
174  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
175 
176  ilChatroomSmilies::_deleteSmiley( $_REQUEST["chatroom_smiley_id"] );
177 
178  $ilCtrl->redirect( $this->gui, "smiley" );
179  }
180 
190  public function editSmiliesObject()
191  {
192  global $rbacsystem, $lng, $tpl;
193 
194  if( !$rbacsystem->checkAccess( 'read', $this->gui->ref_id ) )
195  {
196  $this->ilias->raiseError(
197  $lng->txt( 'msg_no_perm_read' ), $this->gui->ilias->error_obj->MESSAGE
198  );
199  }
200 
201  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
202 
204 
205  if (!$this->form_gui) {
206  $form = $this->initSmiliesForm();
207  }
208  else {
209  $form = $this->form_gui;
210  }
211 
212  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesGUI.php";
213 
214  $table = ilChatroomSmiliesGUI::_getExistingSmiliesTable( $this->gui );
215 
216  $tpl_smilies = new ilTemplate(
217  "tpl.chatroom_edit_smilies.html", true, true, "Modules/Chatroom"
218  );
219  $tpl_smilies->setVariable( "SMILEY_TABLE", $table );
220  $tpl_smilies->setVariable( "SMILEY_FORM", $form->getHtml() );
221 
222  $tpl->setContent( $tpl_smilies->get() );
223  }
224 
234  public function updateSmiliesObject()
235  {
236  global $rbacsystem, $ilCtrl, $tpl, $lng;
237 
238  if( !$rbacsystem->checkAccess( 'write', $this->gui->ref_id ) )
239  {
240  $this->ilias->raiseError(
241  $lng->txt( 'msg_no_perm_write' ), $this->ilias->error_obj->MESSAGE
242  );
243  }
244 
245  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
246  $this->form_gui = new ilPropertyFormGUI();
247 
248  // $this->initSmiliesEditForm();
249 
250  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
251 
253  ilUtil::stripSlashes( $_REQUEST["chatroom_smiley_keywords"] )
254  );
255 
256  $keywordscheck = count( $keywords ) > 0;
257 
258  if( !$this->form_gui->checkInput() || !$keywordscheck )
259  {
260  $tpl->setContent( $this->form_gui->getHtml() );
261  ilUtil::sendFailure('test', true);
262  return $this->view();
263  }
264  else
265  {
266  $data = array();
267  $data["smiley_keywords"] = join( "\n", $keywords );
268  $data["smiley_id"] = $_REQUEST["smiley_id"];
269 
270  if( $_FILES["chatroom_image_path"] )
271  {
272  move_uploaded_file(
273  $_FILES["chatroom_image_path"]["tmp_name"],
275  $_FILES["chatroom_image_path"]["name"]
276  );
277 
278  $data["smiley_path"] = $_FILES["chatroom_image_path"]["name"];
279  }
280 
282  }
283 
284  $ilCtrl->redirect( $this->gui, "smiley" );
285  }
286 
294  public function initSmiliesForm()
295  {
296  global $ilCtrl, $lng;
297 
298  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
299 
300  $this->form_gui = new ilPropertyFormGUI();
301 
302  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
303  $this->form_gui->setFormAction(
304  $ilCtrl->getFormAction( $this->gui, 'smiley-uploadSmileyObject' ) . $table_nav
305  );
306 
307  // chat server settings
308  $sec_l = new ilFormSectionHeaderGUI();
309 
310  $sec_l->setTitle( $lng->txt( 'chatroom_add_smiley' ) );
311  $this->form_gui->addItem( $sec_l );
312 
313  $inp = new ilImageFileInputGUI(
314  $lng->txt( 'chatroom_image_path' ), 'chatroom_image_path'
315  );
316 
317  $inp->setRequired( true );
318  $this->form_gui->addItem( $inp );
319 
320  $inp = new ilTextAreaInputGUI(
321  $lng->txt( 'chatroom_smiley_keywords' ), 'chatroom_smiley_keywords'
322  );
323 
324  $inp->setRequired( true );
325  $inp->setUseRte( false );
326  $inp->setInfo( $lng->txt( 'chatroom_smiley_keywords_one_per_line_note' ) );
327  $this->form_gui->addItem( $inp );
328  $this->form_gui->addCommandButton(
329  'smiley-uploadSmileyObject', $lng->txt( 'chatroom_upload_smiley' )
330  );
331 
332  return $this->form_gui;
333  }
334 
345  public function deleteMultipleObject()
346  {
347  //global $rbacsystem, $ilSetting, $lng, $ilCtrl, $tpl;
348  global $rbacsystem, $lng, $ilCtrl, $tpl;
349 
350  $this->gui->switchToVisibleMode();
351 
352  if( !$rbacsystem->checkAccess( 'write', $this->gui->ref_id ) )
353  {
354  $this->ilias->raiseError(
355  $this->lng->txt( 'msg_no_perm_write' ), $this->ilias->error_obj->MESSAGE
356  );
357  }
358 
359  $items = $_REQUEST["smiley_id"];
360 
361  if( count( $items ) == 0 )
362  {
363  ilUtil::sendInfo( $lng->txt( 'select_one' ), true );
364  $ilCtrl->redirect( $this->gui, "smiley" );
365  }
366 
367  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
368 
369  $smilies = ilChatroomSmilies::_getSmiliesById( $items );
370 
371  $tpl_form = new ilTemplate(
372  "tpl.chatroom_smilies_delete_multiple_confirm.html", true, true, "Modules/Chatroom"
373  );
374 
375  $tpl_form->setVariable(
376  "SMILIES_DELETE_INTRO", $lng->txt( 'chatroom_confirm_delete_smiley' )
377  );
378  $tpl_form->setVariable( "TXT_SUBMIT", $lng->txt( 'confirm' ) );
379  $tpl_form->setVariable( "TXT_CANCEL", $lng->txt( 'cancel' ) );
380  $tpl_form->setVariable( "SMILIES_IDS", join( ",", $items ) );
381  $tpl_form->setVariable(
382  "FORMACTION", $ilCtrl->getFormAction( $this->gui, 'update' )
383  );
384 
385  $i = 0;
386 
387  foreach( $smilies as $s )
388  {
389  $tpl_form->setCurrentBlock( "smilies_list" );
390  $tpl_form->setVariable( "SMILEY_PATH", $s["smiley_fullpath"] );
391  $tpl_form->setVariable( "SMILEY_KEYWORDS", $s["smiley_keywords"] );
392  $tpl_form->setVariable( "ROW_CNT", ($i++ % 2) + 1 );
393  $tpl_form->parseCurrentBlock();
394  }
395 
396  $tpl->setContent( $tpl_form->get() );
397  }
398 
406  {
407  //global $rbacsystem, $ilSetting, $lng, $ilCtrl;
408  global $rbacsystem, $ilCtrl;
409 
410  if( !$rbacsystem->checkAccess( 'write', $this->gui->ref_id ) )
411  {
412  $this->ilias->raiseError(
413  $this->lng->txt( 'msg_no_perm_write' ), $this->ilias->error_obj->MESSAGE
414  );
415  }
416 
417  $ids = $_REQUEST["sel_ids"];
418  $parts = explode( ",", $ids );
419 
420  if( count( $parts ) == 0 )
421  {
422  $ilCtrl->redirect( $this->gui, "smiley" );
423  }
424 
425  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
426 
428 
429  $ilCtrl->redirect( $this->gui, "smiley" );
430  }
431 
439  public function initSmiliesEditForm($form_data)
440  {
441  global $ilCtrl, $lng;
442 
443  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
444 
445  $this->form_gui = new ilPropertyFormGUI();
446 
447  $this->form_gui->setValuesByArray( $form_data );
448 
449  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
450 
451  $ilCtrl->saveParameter($this->gui, 'smiley_id');
452 
453  $this->form_gui->setFormAction(
454  $ilCtrl->getFormAction( $this->gui, 'smiley-updateSmiliesObject' ) . $table_nav
455  );
456 
457  $sec_l = new ilFormSectionHeaderGUI();
458 
459  $sec_l->setTitle( $lng->txt( 'chatroom_edit_smiley' ) );
460  $this->form_gui->addItem( $sec_l );
461 
462  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesCurrentSmileyFormElement.php";
463 
465  $lng->txt( 'chatroom_current_smiley_image_path' ),
466  'chatroom_current_smiley_image_path'
467  );
468 
469  $inp->setValue($form_data['chatroom_current_smiley_image_path']);
470  $this->form_gui->addItem( $inp );
471 
472  $inp = new ilImageFileInputGUI(
473  $lng->txt( 'chatroom_image_path' ), 'chatroom_image_path'
474  );
475 
476  $inp->setRequired( false );
477  $inp->setInfo( $lng->txt( 'chatroom_smiley_image_only_if_changed' ) );
478  $this->form_gui->addItem( $inp );
479 
480  $inp = new ilTextAreaInputGUI(
481  $lng->txt( 'chatroom_smiley_keywords' ), 'chatroom_smiley_keywords'
482  );
483 
484  $inp->setValue($form_data['chatroom_smiley_keywords']);
485  $inp->setUseRte( false );
486  $inp->setRequired( true );
487  $inp->setInfo( $lng->txt( 'chatroom_smiley_keywords_one_per_line_note' ) );
488  $this->form_gui->addItem( $inp );
489 
490  $inp = new ilHiddenInputGUI( 'chatroom_smiley_id' );
491 
492  $this->form_gui->addItem( $inp );
493  $this->form_gui->addCommandButton(
494  'smiley-updateSmiliesObject', $lng->txt( 'submit' )
495  );
496  $this->form_gui->addCommandButton( 'smiley', $lng->txt( 'cancel' ) );
497  return $this->form_gui;
498  }
499 
507  public function uploadSmileyObject()
508  {
509  global $rbacsystem, $ilCtrl, $tpl, $lng;
510 
511  if( !$rbacsystem->checkAccess( 'write', $this->gui->ref_id ) )
512  {
513  $this->ilias->raiseError(
514  $lng->txt( 'msg_no_perm_write' ), $this->ilias->error_obj->MESSAGE
515  );
516  }
517 
518  $this->initSmiliesForm();
519 
520  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
521  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
522 
523  //$this->form_gui = new ilPropertyFormGUI();
524 
525  $this->form_gui->setValuesByPost();
526 
528  ilUtil::stripSlashes( $_REQUEST["chatroom_smiley_keywords"] )
529  );
530 
531  $keywordscheck = count( $keywords ) > 0;
532 
533  if( !$this->form_gui->checkInput() )
534  {
535  $tpl->setContent( $this->form_gui->getHtml() );
536  return $this->view();
537  }
538 
539  $pathinfo = pathinfo( $_FILES["chatroom_image_path"]["name"] );
540  $target_file = md5( time() + $pathinfo['basename'] ) . "." . $pathinfo['extension'];
541 
542  move_uploaded_file(
543  $_FILES["chatroom_image_path"]["tmp_name"],
545  );
546 
547  ilChatroomSmilies::_storeSmiley( join( "\n", $keywords ), $target_file );
548 
549  $ilCtrl->redirect( $this->gui, "smiley" );
550  }
551 
552 
553  private static function _insertDefaultValues()
554  {
555  global $ilDB;
556 
557  $values = array (
558  array("icon_smile.gif", ":)\n:-)\n:smile:"),
559  array("icon_wink.gif", ";)\n;-)\n:wink:"),
560  array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
561  array("icon_sad.gif", ":(\n:-(\n:sad:"),
562  array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
563  array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
564  array("icon_cool.gif", ":cool:"),
565  array("icon_eek.gif", ":eek:"),
566  array("icon_angry.gif", ":||\n:-||\n:angry:"),
567  array("icon_flush.gif", ":flush:"),
568  array("icon_idea.gif", ":idea:"),
569  array("icon_thumbup.gif", ":thumbup:"),
570  array("icon_thumbdown.gif", ":thumbdown:"),
571  );
572 
573  $stmt = $ilDB->prepare("
574  INSERT INTO chatroom_smilies (smiley_id, smiley_keywords, smiley_path)
575  VALUES (?, ?, ?)",
576  array( "integer", "text", "text" )
577  );
578 
579  foreach($values as $val)
580  {
581  $row = array(
582  $ilDB->nextID("chat_smilies"),
583  $val[1],
584  $val[0]
585  );
586  $stmt->execute($row);
587  }
588  }
589 
593  private static function _setupFolder()
594  {
596 
597  if( !is_dir($path) )
598  {
599  mkdir($path, 0755, true);
600  }
601  }
602 
606  public static function _getSmileyDir()
607  {
608  return ilUtil::getWebspaceDir().'/chatroom/smilies';
609  }
610 
611  public static function _checkSetup()
612  {
613  global $lng;
614 
616 
617  if( !is_dir($path) )
618  {
619  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_exists'));
621 
622  if( !is_dir($path) )
623  {
624  ilUtil::sendFailure($lng->txt('chat_smilies_dir_not_available'));
625  return false;
626  }
627  else
628  {
629  $smilies = array
630  (
631  "icon_smile.gif",
632  "icon_wink.gif",
633  "icon_laugh.gif",
634  "icon_sad.gif",
635  "icon_shocked.gif",
636  "icon_tongue.gif",
637  "icon_cool.gif",
638  "icon_eek.gif",
639  "icon_angry.gif",
640  "icon_flush.gif",
641  "icon_idea.gif",
642  "icon_thumbup.gif",
643  "icon_thumbdown.gif",
644  );
645 
646  foreach($smilies as $smiley)
647  {
648  copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
649  }
650 
652 
653  ilUtil::sendSuccess($lng->txt('chat_smilies_initialized'));
654  }
655 
656  }
657 
658  if (!is_writable($path))
659  {
660  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_writable'));
661  }
662 
663  return true;
664  }
665 }
666 
667 ?>