ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  protected $form_gui;
18 
22  public function executeDefault($requestedMethod)
23  {
24  $this->view();
25  }
26 
31  public function view()
32  {
33  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
34 
35  ilChatroom::checkUserPermissions('read', $this->gui->ref_id);
36 
37  $this->gui->switchToVisibleMode();
38 
39  self::_checkSetup();
40 
41  $this->editSmiliesObject();
42  }
43 
44  public static function _checkSetup()
45  {
46  global $lng;
47 
48  $path = self::_getSmileyDir();
49 
50  if (!is_dir($path)) {
51  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_exists'));
53 
54  if (!is_dir($path)) {
55  ilUtil::sendFailure($lng->txt('chat_smilies_dir_not_available'));
56  return false;
57  } else {
58  $smilies = array(
59  "icon_smile.gif",
60  "icon_wink.gif",
61  "icon_laugh.gif",
62  "icon_sad.gif",
63  "icon_shocked.gif",
64  "icon_tongue.gif",
65  "icon_cool.gif",
66  "icon_eek.gif",
67  "icon_angry.gif",
68  "icon_flush.gif",
69  "icon_idea.gif",
70  "icon_thumbup.gif",
71  "icon_thumbdown.gif",
72  );
73 
74  foreach ($smilies as $smiley) {
75  copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
76  }
77 
78  self::_insertDefaultValues();
79 
80  ilUtil::sendSuccess($lng->txt('chat_smilies_initialized'));
81  }
82  }
83 
84  if (!is_writable($path)) {
85  ilUtil::sendInfo($lng->txt('chat_smilies_dir_not_writable'));
86  }
87 
88  return true;
89  }
90 
95  public static function _getSmileyDir($withBaseDir = true)
96  {
97  $path = 'chatroom/smilies';
98 
99  if ($withBaseDir) {
100  $path = ilUtil::getWebspaceDir() . '/' . $path;
101  }
102 
103  return $path;
104  }
105 
106  private static function _insertDefaultValues()
107  {
108  $values = array(
109  array("icon_smile.gif", ":)\n:-)\n:smile:"),
110  array("icon_wink.gif", ";)\n;-)\n:wink:"),
111  array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
112  array("icon_sad.gif", ":(\n:-(\n:sad:"),
113  array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
114  array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
115  array("icon_cool.gif", ":cool:"),
116  array("icon_eek.gif", ":eek:"),
117  array("icon_angry.gif", ":||\n:-||\n:angry:"),
118  array("icon_flush.gif", ":flush:"),
119  array("icon_idea.gif", ":idea:"),
120  array("icon_thumbup.gif", ":thumbup:"),
121  array("icon_thumbdown.gif", ":thumbdown:"),
122  );
123 
124  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
125  foreach ($values as $val) {
126  ilChatroomSmilies::_storeSmiley($val[1], $val[0]);
127  }
128  }
129 
137  public function editSmiliesObject()
138  {
139  global $rbacsystem, $lng, $tpl;
140 
141  if (!$rbacsystem->checkAccess('read', $this->gui->ref_id)) {
142  $this->ilias->raiseError(
143  $lng->txt('msg_no_perm_read'),
144  $this->gui->ilias->error_obj->MESSAGE
145  );
146  }
147 
148  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
149 
151 
152  if (!$this->form_gui) {
153  $form = $this->initSmiliesForm();
154  } else {
156  }
157 
158  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesGUI.php";
159 
161 
162  $tpl_smilies = new ilTemplate(
163  "tpl.chatroom_edit_smilies.html",
164  true,
165  true,
166  "Modules/Chatroom"
167  );
168  $tpl_smilies->setVariable("SMILEY_TABLE", $table);
169  $tpl_smilies->setVariable("SMILEY_FORM", $form->getHtml());
170 
171  $tpl->setContent($tpl_smilies->get());
172  }
173 
180  public function initSmiliesForm()
181  {
182  global $ilCtrl, $lng;
183 
184  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
185 
186  $this->form_gui = new ilPropertyFormGUI();
187 
188  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
189  $this->form_gui->setFormAction(
190  $ilCtrl->getFormAction($this->gui, 'smiley-uploadSmileyObject') . $table_nav
191  );
192 
193  // chat server settings
194  $sec_l = new ilFormSectionHeaderGUI();
195 
196  $sec_l->setTitle($lng->txt('chatroom_add_smiley'));
197  $this->form_gui->addItem($sec_l);
198 
199  $inp = new ilImageFileInputGUI(
200  $lng->txt('chatroom_image_path'),
201  'chatroom_image_path'
202  );
203  $inp->setSuffixes(array("jpg", "jpeg", "png", "gif", "svg"));
204 
205  $inp->setRequired(true);
206  $this->form_gui->addItem($inp);
207 
208  $inp = new ilTextAreaInputGUI(
209  $lng->txt('chatroom_smiley_keywords'),
210  'chatroom_smiley_keywords'
211  );
212 
213  $inp->setRequired(true);
214  $inp->setUseRte(false);
215  $inp->setInfo($lng->txt('chatroom_smiley_keywords_one_per_line_note'));
216  $this->form_gui->addItem($inp);
217  $this->form_gui->addCommandButton(
218  'smiley-uploadSmileyObject',
219  $lng->txt('chatroom_upload_smiley')
220  );
221 
222  return $this->form_gui;
223  }
224 
232  {
233  global $rbacsystem, $tpl, $lng;
234 
235  $this->gui->switchToVisibleMode();
236 
237  if (!$rbacsystem->checkAccess('read', $this->gui->ref_id)) {
238  $this->ilias->raiseError(
239  $lng->txt('msg_no_perm_read'),
240  $this->ilias->error_obj->MESSAGE
241  );
242  }
243 
244  if (!$this->form_gui) {
245  $form = $this->initSmiliesEditForm($this->getSmileyFormDataById((int) $_REQUEST['smiley_id']));
246  } else {
248  }
249 
250  $tpl_form = new ilTemplate(
251  "tpl.chatroom_edit_smilies.html",
252  true,
253  true,
254  "Modules/Chatroom"
255  );
256 
257  $tpl_form->setVariable("SMILEY_FORM", $form->getHTML());
258 
259  $tpl->setContent($tpl_form->get());
260  }
261 
267  protected function getSmileyFormDataById($smileyId)
268  {
269  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
270  $smiley = ilChatroomSmilies::_getSmiley($smileyId);
271 
272  $form_data = array(
273  'chatroom_smiley_id' => $smiley['smiley_id'],
274  'chatroom_smiley_keywords' => $smiley['smiley_keywords'],
275  'chatroom_current_smiley_image_path' => $smiley['smiley_fullpath'],
276  );
277 
278  return $form_data;
279  }
280 
287  public function initSmiliesEditForm($form_data)
288  {
289  global $ilCtrl, $lng;
290 
291  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
292 
293  $this->form_gui = new ilPropertyFormGUI();
294 
295  $this->form_gui->setValuesByArray($form_data);
296 
297  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
298 
299  $ilCtrl->saveParameter($this->gui, 'smiley_id');
300 
301  $this->form_gui->setFormAction(
302  $ilCtrl->getFormAction($this->gui, 'smiley-updateSmiliesObject') . $table_nav
303  );
304 
305  $sec_l = new ilFormSectionHeaderGUI();
306 
307  $sec_l->setTitle($lng->txt('chatroom_edit_smiley'));
308  $this->form_gui->addItem($sec_l);
309 
310  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesCurrentSmileyFormElement.php";
311 
313  $lng->txt('chatroom_current_smiley_image_path'),
314  'chatroom_current_smiley_image_path'
315  );
316 
317  $inp->setValue($form_data['chatroom_current_smiley_image_path']);
318  $this->form_gui->addItem($inp);
319 
320  $inp = new ilImageFileInputGUI(
321  $lng->txt('chatroom_image_path'),
322  'chatroom_image_path'
323  );
324  $inp->setSuffixes(array("jpg", "jpeg", "png", "gif", "svg"));
325 
326  $inp->setRequired(false);
327  $inp->setInfo($lng->txt('chatroom_smiley_image_only_if_changed'));
328  $this->form_gui->addItem($inp);
329 
330  $inp = new ilTextAreaInputGUI(
331  $lng->txt('chatroom_smiley_keywords'),
332  'chatroom_smiley_keywords'
333  );
334 
335  $inp->setValue($form_data['chatroom_smiley_keywords']);
336  $inp->setUseRte(false);
337  $inp->setRequired(true);
338  $inp->setInfo($lng->txt('chatroom_smiley_keywords_one_per_line_note'));
339  $this->form_gui->addItem($inp);
340 
341  $inp = new ilHiddenInputGUI('chatroom_smiley_id');
342 
343  $this->form_gui->addItem($inp);
344  $this->form_gui->addCommandButton(
345  'smiley-updateSmiliesObject',
346  $lng->txt('submit')
347  );
348  $this->form_gui->addCommandButton('smiley', $lng->txt('cancel'));
349  return $this->form_gui;
350  }
351 
356  public function showDeleteSmileyFormObject()
357  {
364  global $rbacsystem, $lng, $ilCtrl, $tpl;
365 
366  $this->gui->switchToVisibleMode();
367 
368  if (!$rbacsystem->checkAccess('write', $this->gui->ref_id)) {
369  $this->ilias->raiseError(
370  $lng->txt('msg_no_perm_write'),
371  $this->ilias->error_obj->MESSAGE
372  );
373  }
374 
375  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
376  $smiley = ilChatroomSmilies::_getSmiley((int) $_REQUEST['smiley_id']);
377 
378  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
379  $confirmation = new ilConfirmationGUI();
380  $confirmation->setFormAction($ilCtrl->getFormAction($this->gui, 'smiley'));
381  $confirmation->setHeaderText($lng->txt('chatroom_confirm_delete_smiley'));
382  $confirmation->addButton($lng->txt('confirm'), 'smiley-deleteSmileyObject');
383  $confirmation->addButton($lng->txt('cancel'), 'smiley');
384  $confirmation->addItem('chatroom_smiley_id', $smiley['smiley_id'], ilUtil::img($smiley['smiley_fullpath'], $smiley['smiley_keywords']) . ' ' . $smiley['smiley_keywords']);
385 
386  $tpl->setContent($confirmation->getHTML());
387  }
388 
394  public function deleteSmileyObject()
395  {
396  global $rbacsystem, $ilCtrl, $lng;
397 
398  if (!$rbacsystem->checkAccess('write', $this->gui->ref_id)) {
399  $this->ilias->raiseError(
400  $lng->txt('msg_no_perm_write'),
401  $this->ilias->error_obj->MESSAGE
402  );
403  }
404 
405  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
406 
407  ilChatroomSmilies::_deleteSmiley($_REQUEST["chatroom_smiley_id"]);
408 
409  $ilCtrl->redirect($this->gui, "smiley");
410  }
411 
417  public function updateSmiliesObject()
418  {
419  global $rbacsystem, $ilCtrl, $tpl, $lng;
420 
421  if (!$rbacsystem->checkAccess('write', $this->gui->ref_id)) {
422  $this->ilias->raiseError(
423  $lng->txt('msg_no_perm_write'),
424  $this->ilias->error_obj->MESSAGE
425  );
426  }
427 
428  $this->initSmiliesEditForm($this->getSmileyFormDataById((int) $_REQUEST['smiley_id']));
429 
430  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
432  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
433  );
434 
435  $keywordscheck = count($keywords) > 0;
436 
437  if (!($isFormValid = $this->form_gui->checkInput()) || !$keywordscheck) {
438  if ($isFormValid) {
439  \ilUtil::sendFailure($lng->txt('form_input_not_valid'));
440  }
441 
442  $this->form_gui->setValuesByPost();
443 
444  return $this->showEditSmileyEntryFormObject();
445  }
446 
447  $data = array();
448  $data["smiley_keywords"] = join("\n", $keywords);
449  $data["smiley_id"] = (int) $_REQUEST['smiley_id'];
450 
451  if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
452  $this->upload->process();
453 
455  $result = array_values($this->upload->getResults())[0];
457  $this->upload->moveOneFileTo(
458  $result,
460  \ILIAS\FileUpload\Location::WEB,
461  $result->getName(),
462  true
463  );
464 
465  $data['smiley_path'] = $result->getName();
466  }
467  }
468 
469  \ilChatroomSmilies::_updateSmiley($data);
470 
471  \ilUtil::sendSuccess($lng->txt('saved_successfully'), true);
472  $ilCtrl->redirect($this->gui, "smiley");
473  }
474 
479  public function deleteMultipleObject()
480  {
487  global $rbacsystem, $lng, $ilCtrl, $tpl;
488 
489  $this->gui->switchToVisibleMode();
490 
491  if (!$rbacsystem->checkAccess('write', $this->gui->ref_id)) {
492  $this->ilias->raiseError(
493  $this->lng->txt('msg_no_perm_write'),
494  $this->ilias->error_obj->MESSAGE
495  );
496  }
497 
498  $items = (array) $_REQUEST['smiley_id'];
499  if (count($items) == 0) {
500  ilUtil::sendInfo($lng->txt('select_one'), true);
501  $ilCtrl->redirect($this->gui, 'smiley');
502  }
503 
504  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
505  $smilies = ilChatroomSmilies::_getSmiliesById($items);
506  if (count($smilies) == 0) {
507  ilUtil::sendInfo($lng->txt('select_one'), true);
508  $ilCtrl->redirect($this->gui, 'smiley');
509  }
510 
511  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
512  $confirmation = new ilConfirmationGUI();
513  $confirmation->setFormAction($ilCtrl->getFormAction($this->gui, 'smiley'));
514  $confirmation->setHeaderText($lng->txt('chatroom_confirm_delete_smiley'));
515  $confirmation->addButton($lng->txt('confirm'), 'smiley-confirmedDeleteMultipleObject');
516  $confirmation->addButton($lng->txt('cancel'), 'smiley');
517 
518  foreach ($smilies as $s) {
519  $confirmation->addItem('sel_ids[]', $s['smiley_id'], ilUtil::img($s['smiley_fullpath'], $s['smiley_keywords']) . ' ' . $s['smiley_keywords']);
520  }
521 
522  $tpl->setContent($confirmation->getHTML());
523  }
524 
528  public function confirmedDeleteMultipleObject()
529  {
534  global $rbacsystem, $ilCtrl;
535 
536  if (!$rbacsystem->checkAccess('write', $this->gui->ref_id)) {
537  $this->ilias->raiseError(
538  $this->lng->txt('msg_no_perm_write'),
539  $this->ilias->error_obj->MESSAGE
540  );
541  }
542 
543  $parts = $_POST["sel_ids"];
544  if (count($parts) == 0) {
545  $ilCtrl->redirect($this->gui, "smiley");
546  }
547 
548  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
550 
551  $ilCtrl->redirect($this->gui, "smiley");
552  }
553 
558  public function uploadSmileyObject()
559  {
560  global $rbacsystem, $ilCtrl, $tpl, $lng;
561 
562  if (!$rbacsystem->checkAccess('write', $this->gui->ref_id)) {
563  $this->ilias->raiseError(
564  $lng->txt('msg_no_perm_write'),
565  $this->ilias->error_obj->MESSAGE
566  );
567  }
568 
569  $this->initSmiliesForm();
570 
571  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
573  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
574  );
575 
576  $keywordscheck = count($keywords) > 0;
577 
578  if (!($isFormValid = $this->form_gui->checkInput()) || !$keywordscheck) {
579  if ($isFormValid) {
580  \ilUtil::sendFailure($lng->txt('form_input_not_valid'));
581  }
582 
583  $this->form_gui->setValuesByPost();
584 
585  return $this->view();
586  }
587 
588  $pathinfo = pathinfo($_FILES["chatroom_image_path"]["name"]);
589  $target_file = md5(time() + $pathinfo['basename']) . "." . $pathinfo['extension'];
590 
591  if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
592  $this->upload->process();
593 
595  $result = array_values($this->upload->getResults())[0];
597  $this->upload->moveOneFileTo(
598  $result,
600  \ILIAS\FileUpload\Location::WEB,
601  $target_file,
602  true
603  );
604 
605  ilChatroomSmilies::_storeSmiley(join("\n", $keywords), $target_file);
606  }
607  }
608 
609  \ilUtil::sendSuccess($lng->txt('saved_successfully'), true);
610  $ilCtrl->redirect($this->gui, "smiley");
611  }
612 }
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.
$result
This class represents a property form user interface.
static _getExistingSmiliesTable($a_ref)
Constructor public.
$tpl
Definition: ilias.php:10
static _getSmileyDir($withBaseDir=true)
This class represents a section header in a property form.
Class BaseForm.
view()
Switches GUI to visible mode and calls editSmiliesObject method which prepares and displays the table...
setValue($a_value)
Set Value.
$s
Definition: pwgen.php:45
initSmiliesForm()
Initializes smilies form and returns it.
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.
if(isset($_POST['submit'])) $form
Class ilChatroomGUIHandler.
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
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 getSmiliesBasePath()
Returns smilies basepath.
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.
if(empty($password)) $table
Definition: pwgen.php:24
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.