ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilChatroomAdminSmileyGUI.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 {
17  private static function _setupFolder()
18  {
19  $path = self::_getSmileyDir();
20 
21  if(!is_dir($path))
22  {
23  mkdir($path, 0755, true);
24  }
25  }
26 
30  public function executeDefault($requestedMethod)
31  {
32  $this->view();
33  }
34 
39  public function view()
40  {
41  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
42 
43  ilChatroom::checkUserPermissions('read', $this->gui->ref_id);
44 
45  $this->gui->switchToVisibleMode();
46 
47  self::_checkSetup();
48 
49  $this->editSmiliesObject();
50  }
51 
52  public static function _checkSetup()
53  {
54  global $lng;
55 
56  $path = self::_getSmileyDir();
57 
58  if(!is_dir($path))
59  {
60  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_exists'));
62 
63  if(!is_dir($path))
64  {
65  ilUtil::sendFailure($lng->txt('chat_smilies_dir_not_available'));
66  return false;
67  }
68  else
69  {
70  $smilies = array
71  (
72  "icon_smile.gif",
73  "icon_wink.gif",
74  "icon_laugh.gif",
75  "icon_sad.gif",
76  "icon_shocked.gif",
77  "icon_tongue.gif",
78  "icon_cool.gif",
79  "icon_eek.gif",
80  "icon_angry.gif",
81  "icon_flush.gif",
82  "icon_idea.gif",
83  "icon_thumbup.gif",
84  "icon_thumbdown.gif",
85  );
86 
87  foreach($smilies as $smiley)
88  {
89  copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
90  }
91 
92  self::_insertDefaultValues();
93 
94  ilUtil::sendSuccess($lng->txt('chat_smilies_initialized'));
95  }
96 
97  }
98 
99  if(!is_writable($path))
100  {
101  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_writable'));
102  }
103 
104  return true;
105  }
106 
110  public static function _getSmileyDir()
111  {
112  return ilUtil::getWebspaceDir() . '/chatroom/smilies';
113  }
114 
115  private static function _insertDefaultValues()
116  {
117  $values = array(
118  array("icon_smile.gif", ":)\n:-)\n:smile:"),
119  array("icon_wink.gif", ";)\n;-)\n:wink:"),
120  array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
121  array("icon_sad.gif", ":(\n:-(\n:sad:"),
122  array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
123  array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
124  array("icon_cool.gif", ":cool:"),
125  array("icon_eek.gif", ":eek:"),
126  array("icon_angry.gif", ":||\n:-||\n:angry:"),
127  array("icon_flush.gif", ":flush:"),
128  array("icon_idea.gif", ":idea:"),
129  array("icon_thumbup.gif", ":thumbup:"),
130  array("icon_thumbdown.gif", ":thumbdown:"),
131  );
132 
133  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
134  foreach($values as $val)
135  {
136  ilChatroomSmilies::_storeSmiley($val[1], $val[0]);
137  }
138  }
139 
147  public function editSmiliesObject()
148  {
149  global $rbacsystem, $lng, $tpl;
150 
151  if(!$rbacsystem->checkAccess('read', $this->gui->ref_id))
152  {
153  $this->ilias->raiseError(
154  $lng->txt('msg_no_perm_read'), $this->gui->ilias->error_obj->MESSAGE
155  );
156  }
157 
158  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
159 
161 
162  if(!$this->form_gui)
163  {
164  $form = $this->initSmiliesForm();
165  }
166  else
167  {
168  $form = $this->form_gui;
169  }
170 
171  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesGUI.php";
172 
174 
175  $tpl_smilies = new ilTemplate(
176  "tpl.chatroom_edit_smilies.html", true, true, "Modules/Chatroom"
177  );
178  $tpl_smilies->setVariable("SMILEY_TABLE", $table);
179  $tpl_smilies->setVariable("SMILEY_FORM", $form->getHtml());
180 
181  $tpl->setContent($tpl_smilies->get());
182  }
183 
190  public function initSmiliesForm()
191  {
192  global $ilCtrl, $lng;
193 
194  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
195 
196  $this->form_gui = new ilPropertyFormGUI();
197 
198  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
199  $this->form_gui->setFormAction(
200  $ilCtrl->getFormAction($this->gui, 'smiley-uploadSmileyObject') . $table_nav
201  );
202 
203  // chat server settings
204  $sec_l = new ilFormSectionHeaderGUI();
205 
206  $sec_l->setTitle($lng->txt('chatroom_add_smiley'));
207  $this->form_gui->addItem($sec_l);
208 
209  $inp = new ilImageFileInputGUI(
210  $lng->txt('chatroom_image_path'), 'chatroom_image_path'
211  );
212  $inp->setSuffixes(array("jpg", "jpeg", "png", "gif", "svg"));
213 
214  $inp->setRequired(true);
215  $this->form_gui->addItem($inp);
216 
217  $inp = new ilTextAreaInputGUI(
218  $lng->txt('chatroom_smiley_keywords'), 'chatroom_smiley_keywords'
219  );
220 
221  $inp->setRequired(true);
222  $inp->setUseRte(false);
223  $inp->setInfo($lng->txt('chatroom_smiley_keywords_one_per_line_note'));
224  $this->form_gui->addItem($inp);
225  $this->form_gui->addCommandButton(
226  'smiley-uploadSmileyObject', $lng->txt('chatroom_upload_smiley')
227  );
228 
229  return $this->form_gui;
230  }
231 
239  {
240  global $rbacsystem, $tpl, $lng;
241 
242  $this->gui->switchToVisibleMode();
243 
244  if(!$rbacsystem->checkAccess('read', $this->gui->ref_id))
245  {
246  $this->ilias->raiseError(
247  $lng->txt('msg_no_perm_read'), $this->ilias->error_obj->MESSAGE
248  );
249  }
250 
251  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
252 
253  $smiley = ilChatroomSmilies::_getSmiley($_REQUEST["smiley_id"]);
254 
255  $form_data = array(
256  "chatroom_smiley_id" => $smiley["smiley_id"],
257  "chatroom_smiley_keywords" => $smiley["smiley_keywords"],
258  "chatroom_current_smiley_image_path" => $smiley["smiley_fullpath"],
259  );
260 
261  $form = $this->initSmiliesEditForm($form_data);
262 
263  $tpl_form = new ilTemplate(
264  "tpl.chatroom_edit_smilies.html", true, true, "Modules/Chatroom"
265  );
266 
267  $tpl_form->setVariable("SMILEY_FORM", $form->getHTML());
268 
269  $tpl->setContent($tpl_form->get());
270  }
271 
278  public function initSmiliesEditForm($form_data)
279  {
280  global $ilCtrl, $lng;
281 
282  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
283 
284  $this->form_gui = new ilPropertyFormGUI();
285 
286  $this->form_gui->setValuesByArray($form_data);
287 
288  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
289 
290  $ilCtrl->saveParameter($this->gui, 'smiley_id');
291 
292  $this->form_gui->setFormAction(
293  $ilCtrl->getFormAction($this->gui, 'smiley-updateSmiliesObject') . $table_nav
294  );
295 
296  $sec_l = new ilFormSectionHeaderGUI();
297 
298  $sec_l->setTitle($lng->txt('chatroom_edit_smiley'));
299  $this->form_gui->addItem($sec_l);
300 
301  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesCurrentSmileyFormElement.php";
302 
304  $lng->txt('chatroom_current_smiley_image_path'),
305  'chatroom_current_smiley_image_path'
306  );
307 
308  $inp->setValue($form_data['chatroom_current_smiley_image_path']);
309  $this->form_gui->addItem($inp);
310 
311  $inp = new ilImageFileInputGUI(
312  $lng->txt('chatroom_image_path'), 'chatroom_image_path'
313  );
314  $inp->setSuffixes(array("jpg", "jpeg", "png", "gif", "svg"));
315 
316  $inp->setRequired(false);
317  $inp->setInfo($lng->txt('chatroom_smiley_image_only_if_changed'));
318  $this->form_gui->addItem($inp);
319 
320  $inp = new ilTextAreaInputGUI(
321  $lng->txt('chatroom_smiley_keywords'), 'chatroom_smiley_keywords'
322  );
323 
324  $inp->setValue($form_data['chatroom_smiley_keywords']);
325  $inp->setUseRte(false);
326  $inp->setRequired(true);
327  $inp->setInfo($lng->txt('chatroom_smiley_keywords_one_per_line_note'));
328  $this->form_gui->addItem($inp);
329 
330  $inp = new ilHiddenInputGUI('chatroom_smiley_id');
331 
332  $this->form_gui->addItem($inp);
333  $this->form_gui->addCommandButton(
334  'smiley-updateSmiliesObject', $lng->txt('submit')
335  );
336  $this->form_gui->addCommandButton('smiley', $lng->txt('cancel'));
337  return $this->form_gui;
338  }
339 
344  public function showDeleteSmileyFormObject()
345  {
352  global $rbacsystem, $lng, $ilCtrl, $tpl;
353 
354  $this->gui->switchToVisibleMode();
355 
356  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
357  {
358  $this->ilias->raiseError(
359  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
360  );
361  }
362 
363  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
364  $smiley = ilChatroomSmilies::_getSmiley((int)$_REQUEST['smiley_id']);
365 
366  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
367  $confirmation = new ilConfirmationGUI();
368  $confirmation->setFormAction($ilCtrl->getFormAction($this->gui, 'smiley'));
369  $confirmation->setHeaderText($lng->txt('chatroom_confirm_delete_smiley'));
370  $confirmation->addButton($lng->txt('confirm'), 'smiley-deleteSmileyObject');
371  $confirmation->addButton($lng->txt('cancel'), 'smiley');
372  $confirmation->addItem('chatroom_smiley_id', $smiley['smiley_id'], ilUtil::img($smiley['smiley_fullpath'], $smiley['smiley_keywords']) . ' ' . $smiley['smiley_keywords']);
373 
374  $tpl->setContent($confirmation->getHTML());
375  }
376 
382  public function deleteSmileyObject()
383  {
384  global $rbacsystem, $ilCtrl, $lng;
385 
386  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
387  {
388  $this->ilias->raiseError(
389  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
390  );
391  }
392 
393  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
394 
395  ilChatroomSmilies::_deleteSmiley($_REQUEST["chatroom_smiley_id"]);
396 
397  $ilCtrl->redirect($this->gui, "smiley");
398  }
399 
407  public function updateSmiliesObject()
408  {
409  global $rbacsystem, $ilCtrl, $tpl, $lng;
410 
411  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
412  {
413  $this->ilias->raiseError(
414  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
415  );
416  }
417 
418  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
419  $this->form_gui = new ilPropertyFormGUI();
420 
421  // $this->initSmiliesEditForm();
422 
423  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
424 
426  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
427  );
428 
429  $keywordscheck = count($keywords) > 0;
430 
431  if(!$this->form_gui->checkInput() || !$keywordscheck)
432  {
433  $tpl->setContent($this->form_gui->getHtml());
434  ilUtil::sendFailure('test', true);
435  return $this->view();
436  }
437  else
438  {
439  $data = array();
440  $data["smiley_keywords"] = join("\n", $keywords);
441  $data["smiley_id"] = $_REQUEST["smiley_id"];
442 
443  if($_FILES["chatroom_image_path"])
444  {
446  $_FILES["chatroom_image_path"]["tmp_name"],
447  $_FILES["chatroom_image_path"]["name"],
448  ilChatroomSmilies::_getSmiliesBasePath() . $_FILES["chatroom_image_path"]["name"]
449  );
450 
451  $data["smiley_path"] = $_FILES["chatroom_image_path"]["name"];
452  }
453 
454  ilChatroomSmilies::_updateSmiley($data);
455  }
456 
457  $ilCtrl->redirect($this->gui, "smiley");
458  }
459 
464  public function deleteMultipleObject()
465  {
472  global $rbacsystem, $lng, $ilCtrl, $tpl;
473 
474  $this->gui->switchToVisibleMode();
475 
476  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
477  {
478  $this->ilias->raiseError(
479  $this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
480  );
481  }
482 
483  $items = (array)$_REQUEST['smiley_id'];
484  if(count($items) == 0)
485  {
486  ilUtil::sendInfo($lng->txt('select_one'), true);
487  $ilCtrl->redirect($this->gui, 'smiley');
488  }
489 
490  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
491  $smilies = ilChatroomSmilies::_getSmiliesById($items);
492  if(count($smilies) == 0)
493  {
494  ilUtil::sendInfo($lng->txt('select_one'), true);
495  $ilCtrl->redirect($this->gui, 'smiley');
496  }
497 
498  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
499  $confirmation = new ilConfirmationGUI();
500  $confirmation->setFormAction($ilCtrl->getFormAction($this->gui, 'smiley'));
501  $confirmation->setHeaderText($lng->txt('chatroom_confirm_delete_smiley'));
502  $confirmation->addButton($lng->txt('confirm'), 'smiley-confirmedDeleteMultipleObject');
503  $confirmation->addButton($lng->txt('cancel'), 'smiley');
504 
505  foreach($smilies as $s)
506  {
507  $confirmation->addItem('sel_ids[]', $s['smiley_id'], ilUtil::img($s['smiley_fullpath'], $s['smiley_keywords']) . ' ' . $s['smiley_keywords']);
508  }
509 
510  $tpl->setContent($confirmation->getHTML());
511  }
512 
516  public function confirmedDeleteMultipleObject()
517  {
522  global $rbacsystem, $ilCtrl;
523 
524  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
525  {
526  $this->ilias->raiseError(
527  $this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
528  );
529  }
530 
531  $parts = $_POST["sel_ids"];
532  if(count($parts) == 0)
533  {
534  $ilCtrl->redirect($this->gui, "smiley");
535  }
536 
537  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
539 
540  $ilCtrl->redirect($this->gui, "smiley");
541  }
542 
549  public function uploadSmileyObject()
550  {
551  global $rbacsystem, $ilCtrl, $tpl, $lng;
552 
553  if(!$rbacsystem->checkAccess('write', $this->gui->ref_id))
554  {
555  $this->ilias->raiseError(
556  $lng->txt('msg_no_perm_write'), $this->ilias->error_obj->MESSAGE
557  );
558  }
559 
560  $this->initSmiliesForm();
561 
562  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
563  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
564 
565  //$this->form_gui = new ilPropertyFormGUI();
566 
567  $this->form_gui->setValuesByPost();
568 
570  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
571  );
572 
573  $keywordscheck = count($keywords) > 0;
574 
575  if(!$this->form_gui->checkInput())
576  {
577  $tpl->setContent($this->form_gui->getHtml());
578  return $this->view();
579  }
580 
581  $pathinfo = pathinfo($_FILES["chatroom_image_path"]["name"]);
582  $target_file = md5(time() + $pathinfo['basename']) . "." . $pathinfo['extension'];
583 
585  $_FILES["chatroom_image_path"]["tmp_name"],
586  $target_file,
588  );
589 
590  ilChatroomSmilies::_storeSmiley(join("\n", $keywords), $target_file);
591 
592  $ilCtrl->redirect($this->gui, "smiley");
593  }
594 }
595 
596 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
deleteSmileyObject()
Deletes a smiley by $_REQUEST["chatroom_smiley_id"] ilRbacSystem $rbacsystem ilCtrl $ilCtrl...
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
This class represents a property form user interface.
static _getExistingSmiliesTable($a_ref)
Constructor public.
This class represents a section header in a property form.
view()
Switches GUI to visible mode and calls editSmiliesObject method which prepares and displays the table...
setValue($a_value)
Set Value.
initSmiliesForm()
Initializes smilies form and returns it.
uploadSmileyObject()
Uploads and stores a new smiley with keywords from $_REQUEST["chatroom_smiley_keywords"] ilRbacSyste...
global $tpl
Definition: ilias.php:8
setValue($a_value)
Sets given value as $this->value in ilChatroomSmiliesCurrentSmileyFormElement.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
initSmiliesEditForm($form_data)
Initializes SmiliesEditForm and returns it.
This class represents a hidden form property in a property form.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
updateSmiliesObject()
Updates a smiley and/or its keywords Updates a smiley icon and/or its keywords by $_REQUEST["chatroom...
Class ilChatroomGUIHandler.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
special template class to simplify handling of ITX/PEAR
redirection script todo: (a better solution should control the processing via a xml file) ...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _getSmiliesBasePath()
Returns smilies basepath.
Class ilChatroomSmiliesCurrentSmileyFormElement Class ilchatroomSmiliesCurrentSmileyFormElement simpl...
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static _checkSetup()
Checks if smiley folder is available; if not it will try to create folder and performs actions for an...
This class represents an image file property in a property form.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $lng
Definition: privfeed.php:17
This class represents a text area property in a property form.
static _prepareKeywords($words)
Trims given keywords and returns them in one array.
Class ilChatroomSmileyGUI Provides methods to show, add, edit and delete smilies consisting of icon a...
showEditSmileyEntryFormObject()
Shows EditSmileyEntryForm Prepares EditSmileyEntryForm and displays it.
editSmiliesObject()
Shows existing smilies table Prepares existing smilies table and displays it.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getWebspaceDir($mode="filesystem")
get webspace directory
setSuffixes($a_suffixes)
Set Accepted Suffixes.
$_POST["username"]
setRequired($a_required)
Set Required.
static _deleteMultipleSmilies($ids=array())
Deletes multiple smilies by given id array.
Confirmation screen class.